Changeset 6186 for trunk/src/includes/admin/replies.php
- Timestamp:
- 12/27/2016 10:45:16 PM (9 years ago)
- File:
-
- 1 edited
-
trunk/src/includes/admin/replies.php (modified) (31 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/admin/replies.php
r6178 r6186 28 28 private $post_type = ''; 29 29 30 /**31 * @var WP_Screen The current screen object32 */33 private $screen;34 35 30 /** Functions *************************************************************/ 36 31 … … 88 83 add_action( 'add_meta_boxes', array( $this, 'attributes_metabox' ) ); 89 84 add_action( 'add_meta_boxes', array( $this, 'author_metabox' ) ); 85 add_action( 'add_meta_boxes', array( $this, 'comments_metabox' ) ); 90 86 add_action( 'save_post', array( $this, 'save_meta_boxes' ) ); 91 87 … … 105 101 106 102 /** 107 * Should we bail out of this method?108 *109 * @since 2.1.0 bbPress (r4067)110 *111 * @return boolean112 */113 private function bail() {114 115 // Not for a post type116 if ( empty( $this->screen->post_type ) ) {117 return true;118 }119 120 // Not this post type121 if ( $this->post_type != $this->screen->post_type ) {122 return true;123 }124 125 return false;126 }127 128 /**129 103 * Admin globals 130 104 * … … 134 108 */ 135 109 private function setup_globals() { 136 $this->post_type = bbp_get_forum_post_type(); 137 $this->screen = $this->screen; 110 $this->post_type = bbp_get_reply_post_type(); 138 111 } 139 112 … … 149 122 public function edit_help() { 150 123 151 if ( $this->bail() ) {152 return;153 }154 155 124 // Overview 156 $this->screen->add_help_tab( array(125 get_current_screen()->add_help_tab( array( 157 126 'id' => 'overview', 158 127 'title' => __( 'Overview', 'bbpress' ), … … 162 131 163 132 // Screen Content 164 $this->screen->add_help_tab( array(133 get_current_screen()->add_help_tab( array( 165 134 'id' => 'screen-content', 166 135 'title' => __( 'Screen Content', 'bbpress' ), … … 176 145 177 146 // Available Actions 178 $this->screen->add_help_tab( array(147 get_current_screen()->add_help_tab( array( 179 148 'id' => 'action-links', 180 149 'title' => __( 'Available Actions', 'bbpress' ), … … 192 161 193 162 // Bulk Actions 194 $this->screen->add_help_tab( array(163 get_current_screen()->add_help_tab( array( 195 164 'id' => 'bulk-actions', 196 165 'title' => __( 'Bulk Actions', 'bbpress' ), … … 201 170 202 171 // Help Sidebar 203 $this->screen->set_help_sidebar(172 get_current_screen()->set_help_sidebar( 204 173 '<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' . 205 174 '<p>' . __( '<a href="https://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' . … … 213 182 * @since 2.0.0 bbPress (r3119) 214 183 * 215 * @uses $this->screen184 * @uses get_current_screen() 216 185 */ 217 186 public function new_help() { 218 187 219 if ( $this->bail() ) {220 return;221 }222 223 188 $customize_display = '<p>' . __( 'The title field and the big reply editing Area are fixed in place, but you can reposition all the other boxes using drag and drop, and can minimize or expand them by clicking the title bar of each box. Use the Screen Options tab to unhide more boxes (Excerpt, Send Trackbacks, Custom Fields, Discussion, Slug, Author) or to choose a 1- or 2-column layout for this screen.', 'bbpress' ) . '</p>'; 224 189 225 $this->screen->add_help_tab( array(190 get_current_screen()->add_help_tab( array( 226 191 'id' => 'customize-display', 227 192 'title' => __( 'Customizing This Display', 'bbpress' ), … … 229 194 ) ); 230 195 231 $this->screen->add_help_tab( array(196 get_current_screen()->add_help_tab( array( 232 197 'id' => 'title-reply-editor', 233 198 'title' => __( 'Title and Reply Editor', 'bbpress' ), … … 243 208 } 244 209 245 $this->screen->add_help_tab( array(210 get_current_screen()->add_help_tab( array( 246 211 'id' => 'reply-attributes', 247 212 'title' => __( 'Reply Attributes', 'bbpress' ), … … 255 220 ) ); 256 221 257 $this->screen->add_help_tab( array(222 get_current_screen()->add_help_tab( array( 258 223 'id' => 'publish-box', 259 224 'title' => __( 'Publish Box', 'bbpress' ), … … 261 226 ) ); 262 227 263 $this->screen->set_help_sidebar(228 get_current_screen()->set_help_sidebar( 264 229 '<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' . 265 230 '<p>' . __( '<a href="https://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' . … … 277 242 */ 278 243 public function bulk_actions( $actions ) { 279 280 if ( $this->bail() ) {281 return $actions;282 }283 244 284 245 if ( current_user_can( 'moderate' ) ) { … … 303 264 public function bulk_post_updated_messages( $bulk_messages, $bulk_counts ) { 304 265 305 if ( $this->bail() ) {306 return $bulk_messages;307 }308 309 266 $bulk_messages['reply']['updated'] = _n( '%s reply updated.', '%s replies updated.', $bulk_counts['updated'], 'bbpress' ); 310 267 $bulk_messages['reply']['locked'] = ( 1 === $bulk_counts['locked'] ) ? __( '1 reply not updated, somebody is editing it.', 'bbpress' ) : … … 325 282 public function handle_bulk_actions( $sendback, $doaction, $post_ids ) { 326 283 327 if ( $this->bail() ) {328 return $sendback;329 }330 331 284 $sendback = remove_query_arg( array( 'spam', 'unspam' ), $sendback ); 332 285 $updated = $locked = 0; … … 388 341 */ 389 342 public function attributes_metabox() { 390 391 if ( $this->bail() ) {392 return;393 }394 343 395 344 add_meta_box( … … 406 355 407 356 /** 408 * Pass the reply attributes for processing409 *410 * @since 2.0.0 bbPress (r2746)411 *412 * @param int $reply_id Reply id413 * @uses current_user_can() To check if the current user is capable of414 * editing the reply415 * @uses do_action() Calls 'bbp_reply_attributes_metabox_save' with the416 * reply id and parent id417 * @return int Parent id418 */419 public function save_meta_boxes( $reply_id ) {420 421 if ( $this->bail() ) {422 return $reply_id;423 }424 425 // Bail if doing an autosave426 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {427 return $reply_id;428 }429 430 // Bail if not a post request431 if ( ! bbp_is_post_request() ) {432 return $reply_id;433 }434 435 // Check action exists436 if ( empty( $_POST['action'] ) ) {437 return $reply_id;438 }439 440 // Nonce check441 if ( empty( $_POST['bbp_reply_metabox'] ) || ! wp_verify_nonce( $_POST['bbp_reply_metabox'], 'bbp_reply_metabox_save' ) ) {442 return $reply_id;443 }444 445 // Current user cannot edit this reply446 if ( !current_user_can( 'edit_reply', $reply_id ) ) {447 return $reply_id;448 }449 450 // Get the reply meta post values451 $topic_id = ! empty( $_POST['parent_id'] ) ? (int) $_POST['parent_id'] : 0;452 $forum_id = ! empty( $_POST['bbp_forum_id'] ) ? (int) $_POST['bbp_forum_id'] : bbp_get_topic_forum_id( $topic_id );453 $reply_to = ! empty( $_POST['bbp_reply_to'] ) ? (int) $_POST['bbp_reply_to'] : 0;454 455 // Get reply author data456 $anonymous_data = bbp_filter_anonymous_post_data();457 $author_id = bbp_get_reply_author_id( $reply_id );458 $is_edit = ( isset( $_POST['hidden_post_status'] ) && ( $_POST['hidden_post_status'] !== 'draft' ) );459 460 // Formally update the reply461 bbp_update_reply( $reply_id, $topic_id, $forum_id, $anonymous_data, $author_id, $is_edit, $reply_to );462 463 // Allow other fun things to happen464 do_action( 'bbp_reply_attributes_metabox_save', $reply_id, $topic_id, $forum_id, $reply_to );465 do_action( 'bbp_author_metabox_save', $reply_id, $anonymous_data );466 467 return $reply_id;468 }469 470 /**471 357 * Add the author info metabox 472 358 * … … 484 370 */ 485 371 public function author_metabox() { 486 487 if ( $this->bail() ) {488 return;489 }490 372 491 373 // Bail if post_type is not a reply … … 508 390 509 391 /** 392 * Remove comments & discussion metaboxes if comments are not supported 393 * 394 * @since 2.6.0 bbPress 395 */ 396 public function comments_metabox() { 397 if ( ! post_type_supports( $this->post_type, 'comments' ) ) { 398 remove_meta_box( 'commentstatusdiv', $this->post_type, 'normal' ); 399 remove_meta_box( 'commentsdiv', $this->post_type, 'normal' ); 400 } 401 } 402 403 /** 404 * Pass the reply attributes for processing 405 * 406 * @since 2.0.0 bbPress (r2746) 407 * 408 * @param int $reply_id Reply id 409 * @uses current_user_can() To check if the current user is capable of 410 * editing the reply 411 * @uses do_action() Calls 'bbp_reply_attributes_metabox_save' with the 412 * reply id and parent id 413 * @return int Parent id 414 */ 415 public function save_meta_boxes( $reply_id ) { 416 417 // Bail if doing an autosave 418 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { 419 return $reply_id; 420 } 421 422 // Bail if not a post request 423 if ( ! bbp_is_post_request() ) { 424 return $reply_id; 425 } 426 427 // Check action exists 428 if ( empty( $_POST['action'] ) ) { 429 return $reply_id; 430 } 431 432 // Nonce check 433 if ( empty( $_POST['bbp_reply_metabox'] ) || ! wp_verify_nonce( $_POST['bbp_reply_metabox'], 'bbp_reply_metabox_save' ) ) { 434 return $reply_id; 435 } 436 437 // Current user cannot edit this reply 438 if ( !current_user_can( 'edit_reply', $reply_id ) ) { 439 return $reply_id; 440 } 441 442 // Get the reply meta post values 443 $topic_id = ! empty( $_POST['parent_id'] ) ? (int) $_POST['parent_id'] : 0; 444 $forum_id = ! empty( $_POST['bbp_forum_id'] ) ? (int) $_POST['bbp_forum_id'] : bbp_get_topic_forum_id( $topic_id ); 445 $reply_to = ! empty( $_POST['bbp_reply_to'] ) ? (int) $_POST['bbp_reply_to'] : 0; 446 447 // Get reply author data 448 $anonymous_data = bbp_filter_anonymous_post_data(); 449 $author_id = bbp_get_reply_author_id( $reply_id ); 450 $is_edit = ( isset( $_POST['hidden_post_status'] ) && ( $_POST['hidden_post_status'] !== 'draft' ) ); 451 452 // Formally update the reply 453 bbp_update_reply( $reply_id, $topic_id, $forum_id, $anonymous_data, $author_id, $is_edit, $reply_to ); 454 455 // Allow other fun things to happen 456 do_action( 'bbp_reply_attributes_metabox_save', $reply_id, $topic_id, $forum_id, $reply_to ); 457 do_action( 'bbp_author_metabox_save', $reply_id, $anonymous_data ); 458 459 return $reply_id; 460 } 461 462 /** 510 463 * Add some general styling to the admin area 511 464 * … … 519 472 */ 520 473 public function admin_head() { 521 522 if ( $this->bail() ) { 523 return; 524 } ?> 474 ?> 525 475 526 476 <style type="text/css" media="screen"> … … 603 553 public function toggle_reply() { 604 554 605 if ( $this->bail() ) {606 return;607 }608 609 555 // Only proceed if GET is a reply toggle action 610 556 if ( bbp_is_get_request() && ! empty( $_GET['action'] ) && in_array( $_GET['action'], array( 'bbp_toggle_reply_spam', 'bbp_toggle_reply_approve' ) ) && ! empty( $_GET['reply_id'] ) ) { … … 676 622 public function toggle_reply_notice() { 677 623 678 if ( $this->bail() ) {679 return;680 }681 682 624 // Only proceed if GET is a reply toggle action 683 625 if ( bbp_is_get_request() && ! empty( $_GET['bbp_reply_toggle_notice'] ) && in_array( $_GET['bbp_reply_toggle_notice'], array( 'spammed', 'unspammed', 'approved', 'unapproved' ) ) && ! empty( $_GET['reply_id'] ) ) { … … 749 691 */ 750 692 public function column_headers( $columns ) { 751 752 if ( $this->bail() ) {753 return $columns;754 }755 756 693 $columns = array( 757 694 'cb' => '<input type="checkbox" />', … … 795 732 public function column_data( $column, $reply_id ) { 796 733 797 if ( $this->bail() ) {798 return;799 }800 801 734 // Get topic ID 802 735 $topic_id = bbp_get_reply_topic_id( $reply_id ); … … 909 842 public function row_actions( $actions, $reply ) { 910 843 911 if ( $this->bail() ) {912 return $actions;913 }914 915 844 unset( $actions['inline hide-if-no-js'] ); 916 845 … … 975 904 */ 976 905 public function filter_dropdown() { 977 978 if ( $this->bail() ) {979 return;980 }981 906 982 907 // Add "Empty Spam" button for moderators … … 1016 941 public function filter_post_rows( $query_vars ) { 1017 942 1018 if ( $this->bail() ) {1019 return $query_vars;1020 }1021 1022 943 // Add post_parent query_var if one is present 1023 944 if ( ! empty( $_GET['bbp_forum_id'] ) ) { … … 1048 969 public function updated_messages( $messages ) { 1049 970 global $post_ID; 1050 1051 if ( $this->bail() ) {1052 return $messages;1053 }1054 971 1055 972 // URL for the current topic … … 1141 1058 * @uses BBP_Replies_Admin 1142 1059 */ 1143 function bbp_admin_replies() { 1060 function bbp_admin_replies( $current_screen ) { 1061 1062 // Bail if not a forum screen 1063 if ( empty( $current_screen->post_type ) || ( bbp_get_reply_post_type() !== $current_screen->post_type ) ) { 1064 return; 1065 } 1066 1067 // Init the replies admin 1144 1068 bbpress()->admin->replies = new BBP_Replies_Admin(); 1145 1069 }
Note: See TracChangeset
for help on using the changeset viewer.