Changeset 5503 for trunk/src/includes/topics/functions.php
- Timestamp:
- 09/11/2014 02:46:07 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/topics/functions.php
r5492 r5503 2102 2102 'bbp_toggle_topic_stick', 2103 2103 'bbp_toggle_topic_spam', 2104 'bbp_toggle_topic_trash' 2104 'bbp_toggle_topic_trash', 2105 'bbp_toggle_topic_approve' 2105 2106 ); 2106 2107 … … 2131 2132 // What action are we trying to perform? 2132 2133 switch ( $action ) { 2134 2135 // Toggle approve/unapprove 2136 case 'bbp_toggle_topic_approve' : 2137 check_ajax_referer( 'approve-topic_' . $topic_id ); 2138 2139 $is_pending = bbp_is_topic_pending( $topic_id ); 2140 $success = true === $is_pending ? bbp_approve_topic( $topic_id ) : bbp_unapprove_topic( $topic_id ); 2141 $failure = true === $is_pending ? __( '<strong>ERROR</strong>: There was a problem approving the topic.', 'bbpress' ) : __( '<strong>ERROR</strong>: There was a problem unapproving the topic.', 'bbpress' ); 2142 2143 break; 2133 2144 2134 2145 // Toggle open/close … … 2344 2355 * @param int $difference Optional. Default 1 2345 2356 * @uses bbp_get_topic_id() To get the topic id 2357 * @uses bbp_get_topic_reply_count_hidden To get the topic's hidden reply count 2346 2358 * @uses update_post_meta() To update the topic's reply count meta 2347 2359 * @uses apply_filters() Calls 'bbp_bump_topic_reply_count_hidden' with the … … 2455 2467 2456 2468 /** 2457 * Adjust the total hidden reply count of a topic (hidden includes trashed and spammed replies) 2469 * Adjust the total hidden reply count of a topic (hidden includes trashed, 2470 * spammed and pending replies) 2458 2471 * 2459 2472 * @since bbPress (r2740) … … 2464 2477 * @uses bbp_get_reply_topic_id() To get the reply topic id 2465 2478 * @uses bbp_get_topic_id() To get the topic id 2479 * @uses bbp_get_trash_status_id() To get the trash status id 2480 * @uses bbp_get_spam_status_id() To get the spam status id 2481 * @uses bbp_get_pending_status_id() To get the pending status id 2466 2482 * @uses bbp_get_reply_post_type() To get the reply post type 2467 2483 * @uses wpdb::prepare() To prepare our sql query … … 2484 2500 // Get replies of topic 2485 2501 if ( empty( $reply_count ) ) { 2486 $post_status = "'" . implode( "','", array( bbp_get_trash_status_id(), bbp_get_spam_status_id() ) ) . "'";2502 $post_status = "'" . implode( "','", array( bbp_get_trash_status_id(), bbp_get_spam_status_id(), bbp_get_pending_status_id() ) ) . "'"; 2487 2503 $reply_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s';", $topic_id, bbp_get_reply_post_type() ) ); 2488 2504 } … … 3161 3177 3162 3178 return (bool) $success; 3179 } 3180 3181 /** 3182 * Approves a pending topic 3183 * 3184 * @since bbPress (r5503) 3185 * 3186 * @param int $topic_id Topic id 3187 * @uses bbp_get_topic() To get the topic 3188 * @uses do_action() Calls 'bbp_approve_topic' with the topic id 3189 /* @uses add_post_meta() To add the previous status to a meta 3190 /* @uses delete_post_meta() To delete the previous status meta 3191 * @uses wp_update_post() To update the topic with the new status 3192 * @uses do_action() Calls 'bbp_approved_topic' with the topic id 3193 * @return mixed False or {@link WP_Error} on failure, topic id on success 3194 */ 3195 function bbp_approve_topic( $topic_id = 0 ) { 3196 3197 // Get topic 3198 $topic = bbp_get_topic( $topic_id ); 3199 if ( empty( $topic ) ) { 3200 return $topic; 3201 } 3202 3203 // Bail if already approved 3204 if ( bbp_get_pending_status_id() !== $topic->post_status ) { 3205 return false; 3206 } 3207 3208 // Execute pre pending code 3209 do_action( 'bbp_approve_topic', $topic_id ); 3210 3211 // Set publish status 3212 $topic->post_status = bbp_get_public_status_id(); 3213 3214 // No revisions 3215 remove_action( 'pre_post_update', 'wp_save_post_revision' ); 3216 3217 // Update topic 3218 $topic_id = wp_update_post( $topic ); 3219 3220 // Execute post pending code 3221 do_action( 'bbp_approved_topic', $topic_id ); 3222 3223 // Return topic_id 3224 return $topic_id; 3225 } 3226 3227 /** 3228 * Unapproves a topic 3229 * 3230 * @since bbPress (r5503) 3231 * 3232 * @param int $topic_id Topic id 3233 * @uses bbp_get_topic() To get the topic 3234 * @uses do_action() Calls 'bbp_unapprove_topic' with the topic id 3235 /* @uses get_post_meta() To get the previous status 3236 /* @uses delete_post_meta() To delete the previous status meta 3237 * @uses wp_update_post() To update the topic with the new status 3238 * @uses do_action() Calls 'bbp_unapproved_topic' with the topic id 3239 * @return mixed False or {@link WP_Error} on failure, topic id on success 3240 */ 3241 function bbp_unapprove_topic( $topic_id = 0 ) { 3242 3243 // Get topic 3244 $topic = bbp_get_topic( $topic_id ); 3245 if ( empty( $topic ) ) { 3246 return $topic; 3247 } 3248 3249 // Bail if already pending 3250 if ( bbp_get_pending_status_id() === $topic->post_status ) { 3251 return false; 3252 } 3253 3254 // Execute pre open code 3255 do_action( 'bbp_unapprove_topic', $topic_id ); 3256 3257 // Set pending status 3258 $topic->post_status = bbp_get_pending_status_id(); 3259 3260 // No revisions 3261 remove_action( 'pre_post_update', 'wp_save_post_revision' ); 3262 3263 // Update topic 3264 $topic_id = wp_update_post( $topic ); 3265 3266 // Execute post open code 3267 do_action( 'bbp_unapproved_topic', $topic_id ); 3268 3269 // Return topic_id 3270 return $topic_id; 3163 3271 } 3164 3272
Note: See TracChangeset
for help on using the changeset viewer.