Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/01/2016 09:00:21 PM (8 years ago)
Author:
r-a-y
Message:

Activity: Introduce error handling to the BP_Activity_Activity class.

To support frontend user messages for activity failures, we need the
ability to add errors.

This commit:

  • Introduces the $errors object and $error_type property to the BP_Activity_Activity class.
  • Adds an 'error_type' parameter to all applicable, activity functions.
  • Modifies bp-legacy to output an error message for activity failures.

See #6719.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-templates/bp-legacy/buddypress-functions.php

    r10825 r10858  
    920920
    921921    if ( ! $object && bp_is_active( 'activity' ) ) {
    922         $activity_id = bp_activity_post_update( array( 'content' => $_POST['content'] ) );
     922        $activity_id = bp_activity_post_update( array( 'content' => $_POST['content'], 'error_type' => 'wp_error' ) );
    923923
    924924    } elseif ( 'groups' === $object ) {
    925925        if ( $item_id && bp_is_active( 'groups' ) )
    926             $activity_id = groups_post_update( array( 'content' => $_POST['content'], 'group_id' => $item_id ) );
     926            $activity_id = groups_post_update( array( 'content' => $_POST['content'], 'group_id' => $item_id, 'error_type' => 'wp_error' ) );
    927927
    928928    } else {
     
    932932    }
    933933
    934     if ( empty( $activity_id ) )
     934    if ( false === $activity_id ) {
    935935        exit( '-1<div id="message" class="error bp-ajax-message"><p>' . __( 'There was a problem posting your update. Please try again.', 'buddypress' ) . '</p></div>' );
     936    } elseif ( is_wp_error( $activity_id ) && $activity_id->get_error_code() ) {
     937        exit( '-1<div id="message" class="error bp-ajax-message"><p>' . $activity_id->get_error_message() . '</p></div>' );
     938    }
    936939
    937940    $last_recorded = ! empty( $_POST['since'] ) ? date( 'Y-m-d H:i:s', intval( $_POST['since'] ) ) : 0;
     
    9981001        'content'     => $_POST['content'],
    9991002        'parent_id'   => $_POST['comment_id'],
     1003        'error_type'  => 'wp_error'
    10001004    ) );
    10011005
    1002     if ( ! $comment_id ) {
    1003         if ( ! empty( $bp->activity->errors['new_comment'] ) && is_wp_error( $bp->activity->errors['new_comment'] ) ) {
    1004             $feedback = $bp->activity->errors['new_comment']->get_error_message();
    1005             unset( $bp->activity->errors['new_comment'] );
    1006         }
    1007 
    1008         exit( '-1<div id="message" class="error bp-ajax-message"><p>' . esc_html( $feedback ) . '</p></div>' );
     1006    if ( is_wp_error( $comment_id ) ) {
     1007        exit( '-1<div id="message" class="error bp-ajax-message"><p>' . esc_html( $comment_id->get_error_message() ) . '</p></div>' );
    10091008    }
    10101009
Note: See TracChangeset for help on using the changeset viewer.