Changeset 6186 for trunk/src/includes/admin/topics.php
- Timestamp:
- 12/27/2016 10:45:16 PM (9 years ago)
- File:
-
- 1 edited
-
trunk/src/includes/admin/topics.php (modified) (33 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/admin/topics.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 … … 89 84 add_action( 'add_meta_boxes', array( $this, 'author_metabox' ) ); 90 85 add_action( 'add_meta_boxes', array( $this, 'replies_metabox' ) ); 86 add_action( 'add_meta_boxes', array( $this, 'comments_metabox' ) ); 91 87 add_action( 'save_post', array( $this, 'save_meta_boxes' ) ); 92 88 … … 106 102 107 103 /** 108 * Should we bail out of this method?109 *110 * @since 2.1.0 bbPress (r4067)111 *112 * @return boolean113 */114 private function bail() {115 116 // Not for a post type117 if ( empty( $this->screen->post_type ) ) {118 return true;119 }120 121 // Not this post type122 if ( $this->post_type != $this->screen->post_type ) {123 return true;124 }125 126 return false;127 }128 129 /**130 104 * Admin globals 131 105 * … … 135 109 */ 136 110 private function setup_globals() { 137 $this->post_type = bbp_get_forum_post_type(); 138 $this->screen = get_current_screen(); 111 $this->post_type = bbp_get_topic_post_type(); 139 112 } 140 113 … … 150 123 public function edit_help() { 151 124 152 if ( $this->bail() ) {153 return;154 }155 156 125 // Overview 157 $this->screen->add_help_tab( array(126 get_current_screen()->add_help_tab( array( 158 127 'id' => 'overview', 159 128 'title' => __( 'Overview', 'bbpress' ), … … 163 132 164 133 // Screen Content 165 $this->screen->add_help_tab( array(134 get_current_screen()->add_help_tab( array( 166 135 'id' => 'screen-content', 167 136 'title' => __( 'Screen Content', 'bbpress' ), … … 177 146 178 147 // Available Actions 179 $this->screen->add_help_tab( array(148 get_current_screen()->add_help_tab( array( 180 149 'id' => 'action-links', 181 150 'title' => __( 'Available Actions', 'bbpress' ), … … 195 164 196 165 // Bulk Actions 197 $this->screen->add_help_tab( array(166 get_current_screen()->add_help_tab( array( 198 167 'id' => 'bulk-actions', 199 168 'title' => __( 'Bulk Actions', 'bbpress' ), … … 204 173 205 174 // Help Sidebar 206 $this->screen->set_help_sidebar(175 get_current_screen()->set_help_sidebar( 207 176 '<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' . 208 177 '<p>' . __( '<a href="https://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' . … … 216 185 * @since 2.0.0 bbPress (r3119) 217 186 * 218 * @uses $this->screen187 * @uses get_current_screen() 219 188 */ 220 189 public function new_help() { 221 190 222 if ( $this->bail() ) {223 return;224 }225 226 191 $customize_display = '<p>' . __( 'The title field and the big topic 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>'; 227 192 228 $this->screen->add_help_tab( array(193 get_current_screen()->add_help_tab( array( 229 194 'id' => 'customize-display', 230 195 'title' => __( 'Customizing This Display', 'bbpress' ), … … 232 197 ) ); 233 198 234 $this->screen->add_help_tab( array(199 get_current_screen()->add_help_tab( array( 235 200 'id' => 'title-topic-editor', 236 201 'title' => __( 'Title and Topic Editor', 'bbpress' ), … … 246 211 } 247 212 248 $this->screen->add_help_tab( array(213 get_current_screen()->add_help_tab( array( 249 214 'id' => 'topic-attributes', 250 215 'title' => __( 'Topic Attributes', 'bbpress' ), … … 257 222 ) ); 258 223 259 $this->screen->add_help_tab( array(224 get_current_screen()->add_help_tab( array( 260 225 'id' => 'publish-box', 261 226 'title' => __( 'Publish Box', 'bbpress' ), … … 263 228 ) ); 264 229 265 $this->screen->set_help_sidebar(230 get_current_screen()->set_help_sidebar( 266 231 '<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' . 267 232 '<p>' . __( '<a href="https://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' . … … 279 244 */ 280 245 public function bulk_actions( $actions ) { 281 282 if ( $this->bail() ) {283 return $actions;284 }285 246 286 247 if ( current_user_can( 'moderate' ) ) { … … 305 266 public function bulk_post_updated_messages( $bulk_messages, $bulk_counts ) { 306 267 307 if ( $this->bail() ) {308 return $bulk_messages;309 }310 311 268 $bulk_messages['topic']['updated'] = _n( '%s topic updated.', '%s topics updated.', $bulk_counts['updated'], 'bbpress' ); 312 269 $bulk_messages['topic']['locked'] = ( 1 === $bulk_counts['locked'] ) ? __( '1 topic not updated, somebody is editing it.', 'bbpress' ) : … … 327 284 public function handle_bulk_actions( $sendback, $doaction, $post_ids ) { 328 285 329 if ( $this->bail() ) {330 return $sendback;331 }332 333 286 $sendback = remove_query_arg( array( 'spam', 'unspam' ), $sendback ); 334 287 $updated = $locked = 0; … … 379 332 return $sendback; 380 333 } 334 381 335 /** 382 336 * Add the topic attributes metabox … … 389 343 */ 390 344 public function attributes_metabox() { 391 392 if ( $this->bail() ) {393 return;394 }395 345 396 346 add_meta_box( … … 407 357 408 358 /** 409 * Pass the topic attributes for processing410 *411 * @since 2.0.0 bbPress (r2746)412 *413 * @param int $topic_id Topic id414 * @uses current_user_can() To check if the current user is capable of415 * editing the topic416 * @uses do_action() Calls 'bbp_topic_attributes_metabox_save' with the417 * topic id and parent id418 * @return int Parent id419 */420 public function save_meta_boxes( $topic_id ) {421 422 if ( $this->bail() ) {423 return $topic_id;424 }425 426 // Bail if doing an autosave427 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {428 return $topic_id;429 }430 431 // Bail if not a post request432 if ( ! bbp_is_post_request() ) {433 return $topic_id;434 }435 436 // Nonce check437 if ( empty( $_POST['bbp_topic_metabox'] ) || ! wp_verify_nonce( $_POST['bbp_topic_metabox'], 'bbp_topic_metabox_save' ) ) {438 return $topic_id;439 }440 441 // Bail if current user cannot edit this topic442 if ( !current_user_can( 'edit_topic', $topic_id ) ) {443 return $topic_id;444 }445 446 // Get the forum ID447 $forum_id = ! empty( $_POST['parent_id'] ) ? (int) $_POST['parent_id'] : 0;448 449 // Get topic author data450 $anonymous_data = bbp_filter_anonymous_post_data();451 $author_id = bbp_get_topic_author_id( $topic_id );452 $is_edit = ( isset( $_POST['hidden_post_status'] ) && ( $_POST['hidden_post_status'] !== 'draft' ) );453 454 // Formally update the topic455 bbp_update_topic( $topic_id, $forum_id, $anonymous_data, $author_id, $is_edit );456 457 // Allow other fun things to happen458 do_action( 'bbp_topic_attributes_metabox_save', $topic_id, $forum_id );459 do_action( 'bbp_author_metabox_save', $topic_id, $anonymous_data );460 461 return $topic_id;462 }463 464 /**465 359 * Add the author info metabox 466 360 * … … 476 370 */ 477 371 public function author_metabox() { 478 479 if ( $this->bail() ) {480 return;481 }482 372 483 373 // Bail if post_type is not a topic … … 517 407 public function replies_metabox() { 518 408 519 if ( $this->bail() ) {520 return;521 }522 523 409 // Bail if post_type is not a reply 524 410 if ( empty( $_GET['action'] ) || ( 'edit' !== $_GET['action'] ) ) { … … 540 426 541 427 /** 428 * Remove comments & discussion metaboxes if comments are not supported 429 * 430 * @since 2.6.0 bbPress 431 */ 432 public function comments_metabox() { 433 if ( ! post_type_supports( $this->post_type, 'comments' ) ) { 434 remove_meta_box( 'commentstatusdiv', $this->post_type, 'normal' ); 435 remove_meta_box( 'commentsdiv', $this->post_type, 'normal' ); 436 } 437 } 438 439 /** 440 * Pass the topic attributes for processing 441 * 442 * @since 2.0.0 bbPress (r2746) 443 * 444 * @param int $topic_id Topic id 445 * @uses current_user_can() To check if the current user is capable of 446 * editing the topic 447 * @uses do_action() Calls 'bbp_topic_attributes_metabox_save' with the 448 * topic id and parent id 449 * @return int Parent id 450 */ 451 public function save_meta_boxes( $topic_id ) { 452 453 // Bail if doing an autosave 454 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { 455 return $topic_id; 456 } 457 458 // Bail if not a post request 459 if ( ! bbp_is_post_request() ) { 460 return $topic_id; 461 } 462 463 // Nonce check 464 if ( empty( $_POST['bbp_topic_metabox'] ) || ! wp_verify_nonce( $_POST['bbp_topic_metabox'], 'bbp_topic_metabox_save' ) ) { 465 return $topic_id; 466 } 467 468 // Bail if current user cannot edit this topic 469 if ( !current_user_can( 'edit_topic', $topic_id ) ) { 470 return $topic_id; 471 } 472 473 // Get the forum ID 474 $forum_id = ! empty( $_POST['parent_id'] ) ? (int) $_POST['parent_id'] : 0; 475 476 // Get topic author data 477 $anonymous_data = bbp_filter_anonymous_post_data(); 478 $author_id = bbp_get_topic_author_id( $topic_id ); 479 $is_edit = ( isset( $_POST['hidden_post_status'] ) && ( $_POST['hidden_post_status'] !== 'draft' ) ); 480 481 // Formally update the topic 482 bbp_update_topic( $topic_id, $forum_id, $anonymous_data, $author_id, $is_edit ); 483 484 // Allow other fun things to happen 485 do_action( 'bbp_topic_attributes_metabox_save', $topic_id, $forum_id ); 486 do_action( 'bbp_author_metabox_save', $topic_id, $anonymous_data ); 487 488 return $topic_id; 489 } 490 491 /** 542 492 * Add some general styling to the admin area 543 493 * … … 551 501 */ 552 502 public function admin_head() { 553 554 if ( $this->bail() ) { 555 return; 556 } ?> 503 ?> 557 504 558 505 <style type="text/css" media="screen"> … … 654 601 public function toggle_topic() { 655 602 656 if ( $this->bail() ) {657 return;658 }659 660 603 // Only proceed if GET is a topic toggle action 661 604 if ( bbp_is_get_request() && ! empty( $_GET['action'] ) && in_array( $_GET['action'], array( 'bbp_toggle_topic_close', 'bbp_toggle_topic_stick', 'bbp_toggle_topic_spam', 'bbp_toggle_topic_approve' ) ) && ! empty( $_GET['topic_id'] ) ) { … … 767 710 public function toggle_topic_notice() { 768 711 769 if ( $this->bail() ) {770 return;771 }772 773 712 // Only proceed if GET is a topic toggle action 774 713 if ( bbp_is_get_request() && ! empty( $_GET['bbp_topic_toggle_notice'] ) && in_array( $_GET['bbp_topic_toggle_notice'], array( 'opened', 'closed', 'super_sticky', 'stuck', 'unstuck', 'spammed', 'unspammed', 'approved', 'unapproved' ) ) && ! empty( $_GET['topic_id'] ) ) { … … 870 809 */ 871 810 public function column_headers( $columns ) { 872 873 if ( $this->bail() ) {874 return $columns;875 }876 877 811 $columns = array( 878 812 'cb' => '<input type="checkbox" />', … … 915 849 public function column_data( $column, $topic_id ) { 916 850 917 if ( $this->bail() ) {918 return;919 }920 921 851 // Get topic forum ID 922 852 $forum_id = bbp_get_topic_forum_id( $topic_id ); … … 1017 947 public function row_actions( $actions, $topic ) { 1018 948 1019 if ( $this->bail() ) {1020 return $actions;1021 }1022 1023 949 unset( $actions['inline hide-if-no-js'] ); 1024 950 … … 1104 1030 public function filter_dropdown() { 1105 1031 1106 if ( $this->bail() ) {1107 return;1108 }1109 1110 1032 // Add "Empty Spam" button for moderators 1111 1033 if ( ! empty( $_GET['post_status'] ) && ( bbp_get_spam_status_id() === $_GET['post_status'] ) && current_user_can( 'moderate' ) ) { … … 1144 1066 function filter_post_rows( $query_vars ) { 1145 1067 1146 if ( $this->bail() ) {1147 return $query_vars;1148 }1149 1150 1068 // Add post_parent query_var if one is present 1151 1069 if ( ! empty( $_GET['bbp_forum_id'] ) ) { … … 1176 1094 public function updated_messages( $messages ) { 1177 1095 global $post_ID; 1178 1179 if ( $this->bail() ) {1180 return $messages;1181 }1182 1096 1183 1097 // URL for the current topic … … 1269 1183 * @uses BBP_Forums_Admin 1270 1184 */ 1271 function bbp_admin_topics() { 1185 function bbp_admin_topics( $current_screen ) { 1186 1187 // Bail if not a forum screen 1188 if ( empty( $current_screen->post_type ) || ( bbp_get_topic_post_type() !== $current_screen->post_type ) ) { 1189 return; 1190 } 1191 1192 // Init the topics admin 1272 1193 bbpress()->admin->topics = new BBP_Topics_Admin(); 1273 1194 }
Note: See TracChangeset
for help on using the changeset viewer.