Skip to:
Content

bbPress.org


Ignore:
Timestamp:
07/29/2013 01:41:36 AM (13 years ago)
Author:
johnjamesjacoby
Message:

Switch some wp_insert_post() usages to wp_update_post(). Use bbp_get_forum(), bbp_get_topic(), and bbp_get_reply() where appropriate, and use objects instead of arrays to avoid escaping issues with wp_update_post().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/replies/functions.php

    r5036 r5055  
    169169
    170170        // Topic does not exist
    171         } elseif ( ! get_post( $posted_topic_id ) ) {
     171        } elseif ( ! bbp_get_topic( $posted_topic_id ) ) {
    172172            bbp_add_error( 'bbp_reply_topic_id', __( '<strong>ERROR</strong>: Topic does not exist.', 'bbpress' ) );
    173173
     
    210210
    211211            // Forum does not exist
    212             } elseif ( ! get_post( $posted_forum_id ) ) {
     212            } elseif ( ! bbp_get_forum( $posted_forum_id ) ) {
    213213                bbp_add_error( 'bbp_topic_forum_id', __( '<strong>ERROR</strong>: Forum does not exist.', 'bbpress' ) );
    214214
     
    16261626 *
    16271627 * @param int $reply_id Reply id
    1628  * @uses get_post() To get the reply
     1628 * @uses bbp_get_reply() To get the reply
    16291629 * @uses do_action() Calls 'bbp_spam_reply' with the reply ID
    16301630 * @uses add_post_meta() To add the previous status to a meta
    1631  * @uses wp_insert_post() To insert the updated post
     1631 * @uses wp_update_post() To insert the updated post
    16321632 * @uses do_action() Calls 'bbp_spammed_reply' with the reply ID
    16331633 * @return mixed False or {@link WP_Error} on failure, reply id on success
     
    16361636
    16371637    // Get reply
    1638     $reply = get_post( $reply_id, ARRAY_A );
     1638    $reply = bbp_get_reply( $reply_id );
    16391639    if ( empty( $reply ) )
    16401640        return $reply;
    16411641
    16421642    // Bail if already spam
    1643     if ( bbp_get_spam_status_id() === $reply['post_status'] )
     1643    if ( bbp_get_spam_status_id() === $reply->post_status )
    16441644        return false;
    16451645
     
    16481648
    16491649    // Add the original post status as post meta for future restoration
    1650     add_post_meta( $reply_id, '_bbp_spam_meta_status', $reply['post_status'] );
     1650    add_post_meta( $reply_id, '_bbp_spam_meta_status', $reply->post_status );
    16511651
    16521652    // Set post status to spam
    1653     $reply['post_status'] = bbp_get_spam_status_id();
     1653    $reply->post_status = bbp_get_spam_status_id();
    16541654
    16551655    // No revisions
     
    16571657
    16581658    // Update the reply
    1659     $reply_id = wp_insert_post( $reply );
     1659    $reply_id = wp_update_post( $reply );
    16601660
    16611661    // Execute post spam code
     
    16721672 *
    16731673 * @param int $reply_id Reply id
    1674  * @uses get_post() To get the reply
     1674 * @uses bbp_get_reply() To get the reply
    16751675 * @uses do_action() Calls 'bbp_unspam_reply' with the reply ID
    16761676 * @uses get_post_meta() To get the previous status meta
    16771677 * @uses delete_post_meta() To delete the previous status meta
    1678  * @uses wp_insert_post() To insert the updated post
     1678 * @uses wp_update_post() To insert the updated post
    16791679 * @uses do_action() Calls 'bbp_unspammed_reply' with the reply ID
    16801680 * @return mixed False or {@link WP_Error} on failure, reply id on success
     
    16831683
    16841684    // Get reply
    1685     $reply = get_post( $reply_id, ARRAY_A );
     1685    $reply = bbp_get_reply( $reply_id );
    16861686    if ( empty( $reply ) )
    16871687        return $reply;
    16881688
    16891689    // Bail if already not spam
    1690     if ( bbp_get_spam_status_id() !== $reply['post_status'] )
     1690    if ( bbp_get_spam_status_id() !== $reply->post_status )
    16911691        return false;
    16921692
     
    16951695
    16961696    // Get pre spam status
    1697     $reply['post_status'] = get_post_meta( $reply_id, '_bbp_spam_meta_status', true );
     1697    $reply->post_status = get_post_meta( $reply_id, '_bbp_spam_meta_status', true );
    16981698
    16991699    // If no previous status, default to publish
    1700     if ( empty( $reply['post_status'] ) ) {
    1701         $reply['post_status'] = bbp_get_public_status_id();
     1700    if ( empty( $reply->post_status ) ) {
     1701        $reply->post_status = bbp_get_public_status_id();
    17021702    }
    17031703
     
    17091709
    17101710    // Update the reply
    1711     $reply_id = wp_insert_post( $reply );
     1711    $reply_id = wp_update_post( $reply );
    17121712
    17131713    // Execute post unspam code
Note: See TracChangeset for help on using the changeset viewer.