Skip to:
Content

bbPress.org

Changeset 6499


Ignore:
Timestamp:
06/08/2017 04:06:24 AM (9 years ago)
Author:
johnjamesjacoby
Message:

General: Audit wp_insert_post() usages.

Return a WP_Error object in some instances, and explicitly do not in others.

Where possible, use the error message in the user feedback response.

Fixes #2817.

Location:
trunk/src/includes
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/admin/classes/class-bbp-converter-base.php

    r6490 r6499  
    596596
    597597                            default:
    598                                 $post_id = wp_insert_post( $insert_post );
     598                                $post_id = wp_insert_post( $insert_post, true );
    599599
    600600                                if ( is_numeric( $post_id ) ) {
  • trunk/src/includes/forums/functions.php

    r6498 r6499  
    4343
    4444    // Insert forum
    45     $forum_id = wp_insert_post( $forum_data );
     45    $forum_id = wp_insert_post( $forum_data, false );
    4646
    4747    // Bail if no forum was added
     
    118118 * @uses apply_filters() Calls 'bbp_new_forum_pre_content' with the content
    119119 * @uses bbPress::errors::get_error_codes() To get the {@link WP_Error} errors
    120  * @uses wp_insert_post() To insert the forum
    121120 * @uses do_action() Calls 'bbp_new_forum' with the forum id, forum id,
    122121 *                    anonymous data and reply author
    123  * @uses bbp_stick_forum() To stick or super stick the forum
    124  * @uses bbp_unstick_forum() To unstick the forum
    125122 * @uses bbp_get_forum_permalink() To get the forum permalink
    126123 * @uses bbp_redirect() To redirect to the forum link
     
    280277
    281278    // Insert forum
    282     $forum_id = wp_insert_post( $forum_data );
     279    $forum_id = wp_insert_post( $forum_data, true );
    283280
    284281    /** No Errors *************************************************************/
     
    355352        bbp_redirect( $redirect_url );
    356353
    357     // Errors
     354    /** Errors ****************************************************************/
     355
     356    // WP_Error
     357    } elseif ( is_wp_error( $forum_id ) ) {
     358        bbp_add_error( 'bbp_forum_error', sprintf( __( '<strong>ERROR</strong>: The following problem(s) occurred: %s', 'bbpress' ), $forum_id->get_error_message() ) );
     359
     360    // Generic error
    358361    } else {
    359         $append_error = ( is_wp_error( $forum_id ) && $forum_id->get_error_message() ) ? $forum_id->get_error_message() . ' ' : '';
    360         bbp_add_error( 'bbp_forum_error', __( '<strong>ERROR</strong>: The following problem(s) have been found with your forum:' . $append_error, 'bbpress' ) );
     362        bbp_add_error( 'bbp_forum_error', __( '<strong>ERROR</strong>: The forum was not created.', 'bbpress' ) );
    361363    }
    362364}
  • trunk/src/includes/replies/functions.php

    r6477 r6499  
    4343
    4444    // Insert reply
    45     $reply_id = wp_insert_post( $reply_data );
     45    $reply_id = wp_insert_post( $reply_data, false );
    4646
    4747    // Bail if no reply was added
     
    404404
    405405    // Insert reply
    406     $reply_id = wp_insert_post( $reply_data );
     406    $reply_id = wp_insert_post( $reply_data, true );
    407407
    408408    /** No Errors *************************************************************/
     
    492492    /** Errors ****************************************************************/
    493493
     494    // WP_Error
     495    } elseif ( is_wp_error( $reply_id ) ) {
     496        bbp_add_error( 'bbp_reply_error', sprintf( __( '<strong>ERROR</strong>: The following problem(s) occurred: %s', 'bbpress' ), $reply_id->get_error_message() ) );
     497
     498    // Generic error
    494499    } else {
    495         $append_error = ( is_wp_error( $reply_id ) && $reply_id->get_error_message() ) ? $reply_id->get_error_message() . ' ' : '';
    496         bbp_add_error( 'bbp_reply_error', __( '<strong>ERROR</strong>: The following problem(s) have been found with your reply:' . $append_error . 'Please try again.', 'bbpress' ) );
     500        bbp_add_error( 'bbp_reply_error', __( '<strong>ERROR</strong>: The reply was not created.', 'bbpress' ) );
    497501    }
    498502}
  • trunk/src/includes/topics/functions.php

    r6497 r6499  
    4343
    4444    // Insert topic
    45     $topic_id = wp_insert_post( $topic_data );
     45    $topic_id = wp_insert_post( $topic_data, false );
    4646
    4747    // Bail if no topic was added
     
    125125 * @uses do_action() Calls 'bbp_new_topic' with the topic id, forum id,
    126126 *                    anonymous data and reply author
    127  * @uses bbp_stick_topic() To stick or super stick the topic
    128  * @uses bbp_unstick_topic() To unstick the topic
    129127 * @uses bbp_get_topic_permalink() To get the topic permalink
    130128 * @uses bbp_redirect() To redirect to the topic link
     
    352350
    353351    // Insert topic
    354     $topic_id = wp_insert_post( $topic_data );
     352    $topic_id = wp_insert_post( $topic_data, true );
    355353
    356354    /** No Errors *************************************************************/
     
    427425        bbp_redirect( $redirect_url );
    428426
    429     // Errors
     427    /** Errors ****************************************************************/
     428
     429    // WP_Error
     430    } elseif ( is_wp_error( $topic_id ) ) {
     431        bbp_add_error( 'bbp_topic_error', sprintf( __( '<strong>ERROR</strong>: The following problem(s) occurred: %s', 'bbpress' ), $topic_id->get_error_message() ) );
     432
     433    // Generic error
    430434    } else {
    431         $append_error = ( is_wp_error( $topic_id ) && $topic_id->get_error_message() ) ? $topic_id->get_error_message() . ' ' : '';
    432         bbp_add_error( 'bbp_topic_error', __( '<strong>ERROR</strong>: The following problem(s) have been found with your topic:' . $append_error, 'bbpress' ) );
     435        bbp_add_error( 'bbp_topic_error', __( '<strong>ERROR</strong>: The topic was not created.', 'bbpress' ) );
    433436    }
    434437}
Note: See TracChangeset for help on using the changeset viewer.