Skip to:
Content

BuddyPress.org

Changeset 9054


Ignore:
Timestamp:
09/28/2014 06:20:35 PM (10 years ago)
Author:
boonebgorges
Message:

Better error message when attempting to reply to an activity item that has been deleted

Fixes #5907

Props imath

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/bp-activity-functions.php

    r9052 r9054  
    13301330 */
    13311331function bp_activity_new_comment( $args = '' ) {
     1332    $bp       = buddypress();
     1333    $errors   = new WP_Error();
     1334    $feedback = __( 'There was an error posting your reply. Please try again.', 'buddypress' );
     1335
     1336    if ( empty( $bp->activity->errors ) ) {
     1337        $bp->activity->errors = array();
     1338    }
    13321339
    13331340    $r = wp_parse_args( $args, array(
     
    13411348    // Bail if missing necessary data
    13421349    if ( empty( $r['content'] ) || empty( $r['user_id'] ) || empty( $r['activity_id'] ) ) {
     1350        $errors->add( 'missing_data', $feedback );
     1351        $bp->activity->errors['new_comment'] = $errors;
     1352
    13431353        return false;
    13441354    }
     
    13561366    // Bail if the parent activity does not exist
    13571367    if ( empty( $activity->date_recorded ) ) {
     1368        $errors->add( 'missing_activity', __( 'Sorry, the item you are replying to no longer exists.', 'buddypress' ) );
     1369        $bp->activity->errors['new_comment'] = $errors;
     1370
    13581371        return false;
    13591372    }
     
    13871400
    13881401    do_action( 'bp_activity_comment_posted', $comment_id, $r, $activity );
     1402
     1403    if ( empty( $comment_id ) ) {
     1404        $errors->add( 'comment_failed', $feedback );
     1405        $bp->activity->errors['new_comment'] = $errors;
     1406    }
    13891407
    13901408    return $comment_id;
  • trunk/src/bp-templates/bp-legacy/buddypress-functions.php

    r8989 r9054  
    756756    global $activities_template;
    757757
    758     // Bail if not a POST action
    759     if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    760         return;
     758    $bp = buddypress();
     759
     760    // Bail if not a POST action
     761    if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
     762        return;
     763    }
    761764
    762765    // Check the nonce
    763766    check_admin_referer( 'new_activity_comment', '_wpnonce_new_activity_comment' );
    764767
    765     if ( ! is_user_logged_in() )
     768    if ( ! is_user_logged_in() ) {
    766769        exit( '-1' );
    767 
    768     if ( empty( $_POST['content'] ) )
    769         exit( '-1<div id="message" class="error"><p>' . __( 'Please do not leave the comment area blank.', 'buddypress' ) . '</p></div>' );
    770 
    771     if ( empty( $_POST['form_id'] ) || empty( $_POST['comment_id'] ) || ! is_numeric( $_POST['form_id'] ) || ! is_numeric( $_POST['comment_id'] ) )
    772         exit( '-1<div id="message" class="error"><p>' . __( 'There was an error posting that reply, please try again.', 'buddypress' ) . '</p></div>' );
     770    }
     771
     772    $feedback = __( 'There was an error posting your reply. Please try again.', 'buddypress' );
     773
     774    if ( empty( $_POST['content'] ) ) {
     775        exit( '-1<div id="message" class="error"><p>' . esc_html__( 'Please do not leave the comment area blank.', 'buddypress' ) . '</p></div>' );
     776    }
     777
     778    if ( empty( $_POST['form_id'] ) || empty( $_POST['comment_id'] ) || ! is_numeric( $_POST['form_id'] ) || ! is_numeric( $_POST['comment_id'] ) ) {
     779        exit( '-1<div id="message" class="error"><p>' . esc_html( $feedback ) . '</p></div>' );
     780    }
    773781
    774782    $comment_id = bp_activity_new_comment( array(
     
    778786    ) );
    779787
    780     if ( ! $comment_id )
    781         exit( '-1<div id="message" class="error"><p>' . __( 'There was an error posting that reply, please try again.', 'buddypress' ) . '</p></div>' );
     788    if ( ! $comment_id ) {
     789        if ( ! empty( $bp->activity->errors['new_comment'] ) && is_wp_error( $bp->activity->errors['new_comment'] ) ) {
     790            $feedback = $bp->activity->errors['new_comment']->get_error_message();
     791            unset( $bp->activity->errors['new_comment'] );
     792        }
     793
     794        exit( '-1<div id="message" class="error"><p>' . esc_html( $feedback ) . '</p></div>' );
     795    }
    782796
    783797    // Load the new activity item into the $activities_template global
Note: See TracChangeset for help on using the changeset viewer.