Skip to:
Content

BuddyPress.org

Ticket #5907: 5907.message.patch

File 5907.message.patch, 4.3 KB (added by imath, 12 years ago)
  • src/bp-activity/bp-activity-functions.php

    diff --git src/bp-activity/bp-activity-functions.php src/bp-activity/bp-activity-functions.php
    index 8070864..5db4612 100644
    function bp_activity_post_update( $args = '' ) {  
    13291329 * @return int|bool The ID of the comment on success, otherwise false.
    13301330 */
    13311331function bp_activity_new_comment( $args = '' ) {
     1332        $bp       = buddypress();
     1333        $errors   = new WP_Error();
     1334        $feedback = __( 'There was an error posting that 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(
    13341341                'id'          => false,
    function bp_activity_new_comment( $args = '' ) {  
    13401347
    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        }
    13451355
    function bp_activity_new_comment( $args = '' ) {  
    13551365
    13561366        // Bail if the parent activity does not exist
    13571367        if ( empty( $activity->date_recorded ) ) {
     1368                $errors->add( 'missing_activity', __( 'Sorry, the update you are replying to does not exist anymore.', 'buddypress' ) );
     1369                $bp->activity->errors['new_comment'] = $errors;
     1370
    13581371                return false;
    13591372        }
    13601373
    function bp_activity_new_comment( $args = '' ) {  
    13871400
    13881401        do_action( 'bp_activity_comment_posted', $comment_id, $r, $activity );
    13891402
     1403        if ( empty( $comment_id ) ) {
     1404                $errors->add( 'comment_failed', $feedback );
     1405                $bp->activity->errors['new_comment'] = $errors;
     1406        }
     1407
    13901408        return $comment_id;
    13911409}
    13921410
  • src/bp-templates/bp-legacy/buddypress-functions.php

    diff --git src/bp-templates/bp-legacy/buddypress-functions.php src/bp-templates/bp-legacy/buddypress-functions.php
    index 98f7901..bfa462d 100644
    function bp_legacy_theme_post_update() {  
    754754 */
    755755function bp_legacy_theme_new_activity_comment() {
    756756        global $activities_template;
     757        $bp = buddypress();
    757758
    758759        // Bail if not a POST action
    759         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     760        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
    760761                return;
     762        }
    761763
    762764        // Check the nonce
    763765        check_admin_referer( 'new_activity_comment', '_wpnonce_new_activity_comment' );
    764766
    765         if ( ! is_user_logged_in() )
     767        if ( ! is_user_logged_in() ) {
    766768                exit( '-1' );
     769        }
    767770
    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>' );
     771        $feedback = __( 'There was an error posting that reply, please try again.', 'buddypress' );
    770772
    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>' );
     773        if ( empty( $_POST['content'] ) ) {
     774                exit( '-1<div id="message" class="error"><p>' . esc_html__( 'Please do not leave the comment area blank.', 'buddypress' ) . '</p></div>' );
     775        }
     776
     777        if ( empty( $_POST['form_id'] ) || empty( $_POST['comment_id'] ) || ! is_numeric( $_POST['form_id'] ) || ! is_numeric( $_POST['comment_id'] ) ) {
     778                exit( '-1<div id="message" class="error"><p>' . esc_html( $feedback ) . '</p></div>' );
     779        }
    773780
    774781        $comment_id = bp_activity_new_comment( array(
    775782                'activity_id' => $_POST['form_id'],
    function bp_legacy_theme_new_activity_comment() {  
    777784                'parent_id'   => $_POST['comment_id'],
    778785        ) );
    779786
    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>' );
     787        if ( ! $comment_id ) {
     788                if ( ! empty( $bp->activity->errors['new_comment'] ) && is_wp_error( $bp->activity->errors['new_comment'] ) ) {
     789                        $feedback = $bp->activity->errors['new_comment']->get_error_message();
     790                        unset( $bp->activity->errors['new_comment'] );
     791                }
     792
     793                exit( '-1<div id="message" class="error"><p>' . esc_html( $feedback ) . '</p></div>' );
     794        }
    782795
    783796        // Load the new activity item into the $activities_template global
    784797        bp_has_activities( 'display_comments=stream&hide_spam=false&show_hidden=true&include=' . $comment_id );