PluginProbe
bbPress / trunk
bbPress vtrunk
trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.2.2 All 71 releases
bbpress / includes / admin / topics.php

topics.php in bbPress trunk, at includes/admin/topics.php

1,350 lines 44.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress Topics Admin Class.
5 *
6 * @package bbPress
7 * @subpackage Administration
8 */
9
10 // Exit if accessed directly
11 defined( 'ABSPATH' ) || exit;
12
13 if ( ! class_exists( 'BBP_Topics_Admin' ) ) :
14 /**
15 * Loads bbPress topics admin area.
16 *
17 * @package bbPress
18 * @subpackage Administration
19 * @since 2.0.0 bbPress (r2464)
20 */
21 class BBP_Topics_Admin {
22
23 /** Variables *************************************************************/
24
25 /**
26 * @var The post type of this admin component.
27 */
28 private $post_type = '';
29
30 /** Functions *************************************************************/
31
32 /**
33 * The main bbPress topics admin loader.
34 *
35 * @since 2.0.0 bbPress (r2515)
36 */
37 public function __construct() {
38 $this->setup_globals();
39 $this->setup_actions();
40 }
41
42 /**
43 * Setup the admin hooks, actions and filters.
44 *
45 * @since 2.0.0 bbPress (r2646)
46 * @since 2.6.0 bbPress (r6101) Added bulk actions
47 *
48 * @access private
49 */
50 private function setup_actions() {
51
52 // Messages
53 add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) );
54
55 // Topic bulk actions, added in WordPress 4.7, see #WP16031.
56 if ( bbp_get_major_wp_version() >= 4.7 ) {
57 add_filter( 'bulk_actions-edit-topic', array( $this, 'bulk_actions' ) );
58 add_filter( 'handle_bulk_actions-edit-topic', array( $this, 'handle_bulk_actions' ), 10, 3 );
59 add_filter( 'bulk_post_updated_messages', array( $this, 'bulk_post_updated_messages' ), 10, 2 );
60 }
61
62 // Topic column headers.
63 add_filter( 'manage_' . $this->post_type . '_posts_columns', array( $this, 'column_headers' ) );
64
65 // Topic columns (in post row)
66 add_action( 'manage_' . $this->post_type . '_posts_custom_column', array( $this, 'column_data' ), 10, 2 );
67 add_filter( 'post_row_actions', array( $this, 'row_actions' ), 10, 2 );
68
69 // Topic meta-box actions
70 add_action( 'add_meta_boxes', array( $this, 'attributes_metabox' ) );
71 add_action( 'add_meta_boxes', array( $this, 'author_metabox' ) );
72 add_action( 'add_meta_boxes', array( $this, 'replies_metabox' ) );
73 add_action( 'add_meta_boxes', array( $this, 'engagements_metabox' ) );
74 add_action( 'add_meta_boxes', array( $this, 'favorites_metabox' ) );
75 add_action( 'add_meta_boxes', array( $this, 'subscriptions_metabox' ) );
76 add_action( 'add_meta_boxes', array( $this, 'comments_metabox' ) );
77 add_action( 'save_post', array( $this, 'save_meta_boxes' ) );
78
79 // Check if there are any bbp_toggle_topic_* requests on admin_init, also have a message displayed
80 add_action( 'load-edit.php', array( $this, 'toggle_topic' ) );
81 add_action( 'load-edit.php', array( $this, 'toggle_topic_notice' ) );
82
83 // Add ability to filter topics and replies per forum
84 add_filter( 'restrict_manage_posts', array( $this, 'filter_dropdown' ) );
85 add_filter( 'bbp_request', array( $this, 'filter_post_rows' ) );
86
87 // Empty spam
88 add_filter( 'manage_posts_extra_tablenav', array( $this, 'filter_empty_spam' ) );
89
90 // Contextual Help
91 add_action( 'load-edit.php', array( $this, 'edit_help' ) );
92 add_action( 'load-post.php', array( $this, 'new_help' ) );
93 add_action( 'load-post-new.php', array( $this, 'new_help' ) );
94
95 /** Dependencies ******************************************************/
96
97 // Allow plugins to modify these actions
98 do_action_ref_array( 'bbp_admin_topics_loaded', array( &$this ) );
99 }
100
101 /**
102 * Admin globals.
103 *
104 * @since 2.0.0 bbPress (r2646)
105 *
106 * @access private
107 */
108 private function setup_globals() {
109 $this->post_type = bbp_get_topic_post_type();
110 }
111
112 /** Contextual Help *******************************************************/
113
114 /**
115 * Contextual help for bbPress topic edit page.
116 *
117 * @since 2.0.0 bbPress (r3119)
118 */
119 public function edit_help() {
120
121 // Overview
122 get_current_screen()->add_help_tab(
123 array(
124 'id' => 'overview',
125 'title' => __( 'Overview', 'bbpress' ),
126 'content' =>
127 '<p>' . __( 'This screen displays the individual topics on your site. You can customize the display of this screen to suit your workflow.', 'bbpress' ) . '</p>'
128 )
129 );
130
131 // Screen Content
132 get_current_screen()->add_help_tab(
133 array(
134 'id' => 'screen-content',
135 'title' => __( 'Screen Content', 'bbpress' ),
136 'content' =>
137 '<p>' . __( 'You can customize the display of this screen&#8217;s contents in a number of ways:', 'bbpress' ) . '</p>' .
138 '<ul>' .
139 '<li>' . __( 'You can hide/display columns based on your needs and decide how many topics to list per screen using the Screen Options tab.', 'bbpress' ) . '</li>' .
140 '<li>' . __( 'You can filter the list of topics by topic status using the text links in the upper left to show All, Published, Draft, Pending, Trashed, Closed, or Spam topics. The default view is to show all topics.', 'bbpress' ) . '</li>' .
141 '<li>' . __( 'You can view topics in a simple title list or with an excerpt. Choose the view you prefer by clicking on the icons at the top of the list on the right.', 'bbpress' ) . '</li>' .
142 '<li>' . __( 'You can refine the list to show only topics in a specific forum or from a specific month by using the dropdown menus above the topics list. Click the Filter button after making your selection.', 'bbpress' ) . '</li>' .
143 '</ul>'
144 )
145 );
146
147 // Available Actions
148 get_current_screen()->add_help_tab(
149 array(
150 'id' => 'action-links',
151 'title' => __( 'Available Actions', 'bbpress' ),
152 'content' =>
153 '<p>' . __( 'Hovering over a row in the topics list will display action links that allow you to manage your topic. You can perform the following actions:', 'bbpress' ) . '</p>' .
154 '<ul>' .
155 '<li>' . __( '<strong>Edit</strong> takes you to the editing screen for that topic. You can also reach that screen by clicking on the topic title.', 'bbpress' ) . '</li>' .
156 '<li>' . __( '<strong>Stick</strong> will keep the selected topic &#8217;pinned&#8217; to the top the parent forum topic list.', 'bbpress' ) . '</li>' .
157 '<li>' . __( '<strong>Stick <em>(to front)</em></strong> will keep the selected topic &#8217;pinned&#8217; to the top of ALL forums and be visable in any forums topics list.', 'bbpress' ) . '</li>' .
158 '<li>' . __( '<strong>Approve</strong> will change the status from pending to publish.', 'bbpress' ) . '</li>' .
159 '<li>' . __( '<strong>Close</strong> will mark the selected topic as &#8217;closed&#8217; and disable the ability to post new replies to it.', 'bbpress' ) . '</li>' .
160 '<li>' . __( '<strong>Spam</strong> removes your topic from this list and places it in the spam queue, from which you can permanently delete it.', 'bbpress' ) . '</li>' .
161 '<li>' . __( '<strong>Trash</strong> removes your topic from this list and places it in the trash, from which you can permanently delete it.', 'bbpress' ) . '</li>' .
162 '<li>' . __( '<strong>View</strong> will take you to your live site to view the topic.', 'bbpress' ) . '</li>' .
163 '</ul>'
164 )
165 );
166
167 // Bulk Actions
168 get_current_screen()->add_help_tab(
169 array(
170 'id' => 'bulk-actions',
171 'title' => __( 'Bulk Actions', 'bbpress' ),
172 'content' =>
173 '<p>' . __( 'You can also edit, spam, or move multiple topics to the trash at once. Select the topics you want to act on using the checkboxes, then select the action you want to take from the Bulk Actions menu and click Apply.', 'bbpress' ) . '</p>' .
174 '<p>' . __( 'When using Bulk Edit, you can change the metadata (categories, author, etc.) for all selected topics at once. To remove a topic from the grouping, just click the x next to its name in the Bulk Edit area that appears.', 'bbpress' ) . '</p>'
175 )
176 );
177
178 // Help Sidebar
179 get_current_screen()->set_help_sidebar(
180 '<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' .
181 '<p>' . __( '<a href="https://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' .
182 '<p>' . __( '<a href="https://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>'
183 );
184 }
185
186 /**
187 * Contextual help for bbPress topic edit page.
188 *
189 * @since 2.0.0 bbPress (r3119)
190 */
191 public function new_help() {
192
193 $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>';
194
195 get_current_screen()->add_help_tab(
196 array(
197 'id' => 'customize-display',
198 'title' => __( 'Customizing This Display', 'bbpress' ),
199 'content' => $customize_display,
200 )
201 );
202
203 get_current_screen()->add_help_tab(
204 array(
205 'id' => 'title-topic-editor',
206 'title' => __( 'Title and Topic Editor', 'bbpress' ),
207 'content' =>
208 '<p>' . __( '<strong>Title</strong> - Enter a title for your topic. After you enter a title, you&#8217;ll see the permalink below, which you can edit.', 'bbpress' ) . '</p>' .
209 '<p>' . __( '<strong>Topic Editor</strong> - Enter the text for your topic. There are two modes of editing: Visual and HTML. Choose the mode by clicking on the appropriate tab. Visual mode gives you a WYSIWYG editor. Click the last icon in the row to get a second row of controls. The HTML mode allows you to enter raw HTML along with your topic text. You can insert media files by clicking the icons above the topic editor and following the directions. You can go to the distraction-free writing screen via the Fullscreen icon in Visual mode (second to last in the top row) or the Fullscreen button in HTML mode (last in the row). Once there, you can make buttons visible by hovering over the top area. Exit Fullscreen back to the regular topic editor.', 'bbpress' ) . '</p>'
210 )
211 );
212
213 $publish_box = '<p>' . __( '<strong>Publish</strong> - You can set the terms of publishing your topic in the Publish box. For Status, Visibility, and Publish (immediately), click on the Edit link to reveal more options. Visibility includes options for password-protecting a topic or making it stay at the top of your blog indefinitely (sticky). Publish (immediately) allows you to set a future or past date and time, so you can schedule a topic to be published in the future or backdate a topic.', 'bbpress' ) . '</p>';
214
215 if ( current_theme_supports( 'topic-thumbnails' ) && post_type_supports( bbp_get_topic_post_type(), 'thumbnail' ) ) {
216 $publish_box .= '<p>' . __( '<strong>Featured Image</strong> - This allows you to associate an image with your topic without inserting it. This is usually useful only if your theme makes use of the featured image as a topic thumbnail on the home page, a custom header, etc.', 'bbpress' ) . '</p>';
217 }
218
219 get_current_screen()->add_help_tab(
220 array(
221 'id' => 'topic-attributes',
222 'title' => __( 'Topic Attributes', 'bbpress' ),
223 'content' =>
224 '<p>' . __( 'Select the attributes that your topic should have:', 'bbpress' ) . '</p>' .
225 '<ul>' .
226 '<li>' . __( '<strong>Forum</strong> dropdown determines the parent forum that the topic belongs to. Select the forum or category from the dropdown, or leave the default "No forum" to post the topic without an assigned forum.', 'bbpress' ) . '</li>' .
227 '<li>' . __( '<strong>Topic Type</strong> dropdown indicates the sticky status of the topic. Selecting the super sticky option would stick the topic to the front of your forums, i.e. the topic index, sticky option would stick the topic to its respective forum. Selecting normal would not stick the topic anywhere.', 'bbpress' ) . '</li>' .
228 '</ul>'
229 )
230 );
231
232 get_current_screen()->add_help_tab(
233 array(
234 'id' => 'publish-box',
235 'title' => __( 'Publish Box', 'bbpress' ),
236 'content' => $publish_box,
237 )
238 );
239
240 get_current_screen()->set_help_sidebar(
241 '<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' .
242 '<p>' . __( '<a href="https://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' .
243 '<p>' . __( '<a href="https://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>'
244 );
245 }
246
247 /**
248 * Add spam/unspam bulk actions to the bulk action dropdown.
249 *
250 * @since 2.6.0 bbPress (r6101)
251 *
252 * @param array $actions The list of bulk actions.
253 * @return array The filtered list of bulk actions.
254 */
255 public function bulk_actions( $actions ) {
256
257 if ( current_user_can( 'moderate' ) ) {
258 if ( bbp_get_spam_status_id() === get_query_var( 'post_status' ) ) {
259 $actions['unspam'] = esc_html__( 'Unspam', 'bbpress' );
260 } else {
261 $actions['spam'] = esc_html__( 'Spam', 'bbpress' );
262 }
263 }
264
265 return $actions;
266 }
267
268 /**
269 * Add custom bulk action updated messages for topics.
270 *
271 * @since 2.6.0 bbPress (r6101)
272 *
273 * @param array $bulk_messages Arrays of messages, each keyed by the corresponding post type.
274 * @param array $bulk_counts Array of item counts for each message, used to build internationalized strings.
275 */
276 public function bulk_post_updated_messages( $bulk_messages, $bulk_counts ) {
277 /* translators: %s: Number of topics */
278 $bulk_messages['topic']['updated'] = _n( '%s topic updated.', '%s topics updated.', $bulk_counts['updated'], 'bbpress' );
279 $bulk_messages['topic']['locked'] = ( 1 === $bulk_counts['locked'] )
280 ? __( '1 topic not updated, somebody is editing it.', 'bbpress' )
281 /* translators: %s: Number of topics */
282 : _n( '%s topic not updated, somebody is editing it.', '%s topics not updated, somebody is editing them.', $bulk_counts['locked'], 'bbpress' );
283
284 return $bulk_messages;
285 }
286
287 /**
288 * Handle spam/unspam bulk actions.
289 *
290 * @since 2.6.0 bbPress (r6101)
291 *
292 * @param string $sendback The sendback URL.
293 * @param string $doaction The action to be taken.
294 * @param array $post_ids The post IDS to take the action on.
295 * @return string The sendback URL.
296 */
297 public function handle_bulk_actions( $sendback, $doaction, $post_ids ) {
298
299 $sendback = remove_query_arg( array( 'spam', 'unspam' ), $sendback );
300 $updated = $locked = 0;
301
302 if ( 'spam' === $doaction ) {
303
304 foreach ( (array) $post_ids as $post_id ) {
305 if ( ! current_user_can( 'moderate', $post_id ) ) {
306 wp_die( esc_html__( 'Sorry, you are not allowed to spam this item.', 'bbpress' ) );
307 }
308
309 if ( wp_check_post_lock( $post_id ) ) {
310 ++$locked;
311 continue;
312 }
313
314 if ( ! bbp_spam_topic( $post_id ) ) {
315 wp_die( esc_html__( 'Error in spamming topic.', 'bbpress' ) );
316 }
317
318 ++$updated;
319 }
320
321 $sendback = add_query_arg(
322 array(
323 'updated' => $updated,
324 'ids' => implode( ',', $post_ids ),
325 'locked' => $locked
326 ),
327 $sendback
328 );
329
330 } elseif ( 'unspam' === $doaction ) {
331
332 foreach ( (array) $post_ids as $post_id ) {
333 if ( ! current_user_can( 'moderate', $post_id ) ) {
334 wp_die( esc_html__( 'Sorry, you are not allowed to unspam this topic.', 'bbpress' ) );
335 }
336
337 if ( wp_check_post_lock( $post_id ) ) {
338 ++$locked;
339 continue;
340 }
341
342 if ( ! bbp_unspam_topic( $post_id ) ) {
343 wp_die( esc_html__( 'Error in unspamming topic.', 'bbpress' ) );
344 }
345
346 ++$updated;
347 }
348
349 $sendback = add_query_arg(
350 array(
351 'updated' => $updated,
352 'ids' => implode( ',', $post_ids ),
353 'locked' => $locked
354 ),
355 $sendback
356 );
357 }
358
359 return $sendback;
360 }
361
362 /**
363 * Add the topic attributes meta-box.
364 *
365 * @since 2.0.0 bbPress (r2744)
366 */
367 public function attributes_metabox() {
368 add_meta_box(
369 'bbp_topic_attributes',
370 esc_html__( 'Attributes', 'bbpress' ),
371 'bbp_topic_metabox',
372 $this->post_type,
373 'side',
374 'high'
375 );
376 }
377
378 /**
379 * Add the author info meta-box.
380 *
381 * @since 2.0.0 bbPress (r2828)
382 */
383 public function author_metabox() {
384
385 // Bail if post_type is not a topic
386 if ( empty( $_GET['action'] ) || ( 'edit' !== $_GET['action'] ) ) {
387 return;
388 }
389
390 // Add the meta-box
391 add_meta_box(
392 'bbp_author_metabox',
393 esc_html__( 'Author', 'bbpress' ),
394 'bbp_author_metabox',
395 $this->post_type,
396 'side',
397 'high'
398 );
399 }
400
401 /**
402 * Add the replies meta-box.
403 *
404 * Allows viewing & moderating of replies to a topic, based on the way
405 * comments are visible on a blog post.
406 *
407 * @since 2.6.0 bbPress (r5886)
408 */
409 public function replies_metabox() {
410
411 // Bail if post_type is not a reply
412 if ( empty( $_GET['action'] ) || ( 'edit' !== $_GET['action'] ) ) {
413 return;
414 }
415
416 // Add the meta-box
417 add_meta_box(
418 'bbp_topic_replies_metabox',
419 esc_html__( 'Replies', 'bbpress' ),
420 'bbp_topic_replies_metabox',
421 $this->post_type,
422 'normal',
423 'high'
424 );
425 }
426
427 /**
428 * Add the engagements meta-box.
429 *
430 * Allows viewing of users who have engaged in a topic.
431 *
432 * @since 2.6.0 bbPress (r6333)
433 */
434 public function engagements_metabox() {
435
436 // Bail when creating a new topic
437 if ( empty( $_GET['action'] ) || ( 'edit' !== $_GET['action'] ) ) {
438 return;
439 }
440
441 // Bail if no engagements
442 if ( ! bbp_is_engagements_active() ) {
443 return;
444 }
445
446 // Add the meta-box
447 add_meta_box(
448 'bbp_topic_engagements_metabox',
449 esc_html__( 'Engagements', 'bbpress' ),
450 'bbp_topic_engagements_metabox',
451 $this->post_type,
452 'side',
453 'low'
454 );
455 }
456
457 /**
458 * Add the favorites meta-box.
459 *
460 * Allows viewing of users who have favorited a topic.
461 *
462 * @since 2.6.0 bbPress (r6197)
463 */
464 public function favorites_metabox() {
465
466 // Bail if post_type is not a reply
467 if ( empty( $_GET['action'] ) || ( 'edit' !== $_GET['action'] ) ) {
468 return;
469 }
470
471 // Bail if no favorites
472 if ( ! bbp_is_favorites_active() ) {
473 return;
474 }
475
476 // Add the meta-box
477 add_meta_box(
478 'bbp_topic_favorites_metabox',
479 esc_html__( 'Favorites', 'bbpress' ),
480 'bbp_topic_favorites_metabox',
481 $this->post_type,
482 'normal',
483 'high'
484 );
485 }
486
487 /**
488 * Add the subscriptions meta-box.
489 *
490 * Allows viewing of users who have subscribed to a topic.
491 *
492 * @since 2.6.0 bbPress (r6197)
493 */
494 public function subscriptions_metabox() {
495
496 // Bail if post_type is not a reply
497 if ( empty( $_GET['action'] ) || ( 'edit' !== $_GET['action'] ) ) {
498 return;
499 }
500
501 // Bail if no subscriptions
502 if ( ! bbp_is_subscriptions_active() ) {
503 return;
504 }
505
506 // Add the meta-box
507 add_meta_box(
508 'bbp_topic_subscriptions_metabox',
509 esc_html__( 'Subscriptions', 'bbpress' ),
510 'bbp_topic_subscriptions_metabox',
511 $this->post_type,
512 'normal',
513 'high'
514 );
515 }
516
517 /**
518 * Remove comments & discussion meta-boxes if comments are not supported.
519 *
520 * @since 2.6.0 bbPress (r6186)
521 */
522 public function comments_metabox() {
523 if ( ! post_type_supports( $this->post_type, 'comments' ) ) {
524 remove_meta_box( 'commentstatusdiv', $this->post_type, 'normal' );
525 remove_meta_box( 'commentsdiv', $this->post_type, 'normal' );
526 }
527 }
528
529 /**
530 * Pass the topic attributes for processing.
531 *
532 * @since 2.0.0 bbPress (r2746)
533 *
534 * @param int $topic_id Topic id.
535 * @return int Parent id.
536 */
537 public function save_meta_boxes( $topic_id ) {
538
539 // Bail if doing an autosave
540 if ( bbp_doing_autosave() ) {
541 return $topic_id;
542 }
543
544 // Bail if not a post request
545 if ( ! bbp_is_post_request() ) {
546 return $topic_id;
547 }
548
549 // Check action exists
550 if ( empty( $_POST['action'] ) ) {
551 return $topic_id;
552 }
553
554 // Nonce check
555 if ( empty( $_POST['bbp_topic_metabox'] ) || ! wp_verify_nonce( $_POST['bbp_topic_metabox'], 'bbp_topic_metabox_save' ) ) {
556 return $topic_id;
557 }
558
559 // Bail if current user cannot edit this topic
560 if ( ! current_user_can( 'edit_topic', $topic_id ) ) {
561 return $topic_id;
562 }
563
564 // Get the forum ID
565 $forum_id = ! empty( $_POST['parent_id'] ) ? (int) $_POST['parent_id'] : 0;
566
567 // Get topic author data
568 $anonymous_data = bbp_filter_anonymous_post_data();
569 $author_id = bbp_get_topic_author_id( $topic_id );
570 $is_edit = ( isset( $_POST['hidden_post_status'] ) && ( 'draft' !== $_POST['hidden_post_status'] ) );
571
572 // Formally update the topic
573 bbp_update_topic( $topic_id, $forum_id, $anonymous_data, $author_id, $is_edit );
574
575 // Allow other fun things to happen
576 do_action( 'bbp_topic_attributes_metabox_save', $topic_id, $forum_id );
577 do_action( 'bbp_author_metabox_save', $topic_id, $anonymous_data );
578
579 return $topic_id;
580 }
581
582 /**
583 * Toggle topic.
584 *
585 * Handles the admin-side opening/closing, sticking/unsticking and
586 * spamming/unspamming of topics.
587 *
588 * @since 2.0.0 bbPress (r2727)
589 */
590 public function toggle_topic() {
591
592 // Bail if not a topic toggle action
593 if ( ! bbp_is_get_request() || empty( $_GET['action'] ) || empty( $_GET['topic_id'] ) ) {
594 return;
595 }
596
597 // Bail if not an allowed action
598 $action = sanitize_key( $_GET['action'] );
599 if ( empty( $action ) || ! in_array( $action, $this->get_allowed_action_toggles(), true ) ) {
600 return;
601 }
602
603 // Bail if topic is missing
604 $topic_id = bbp_get_topic_id( $_GET['topic_id'] );
605 if ( ! bbp_get_topic( $topic_id ) ) {
606 wp_die( esc_html__( 'The topic was not found.', 'bbpress' ) );
607 }
608
609 // What is the user doing here?
610 if ( ! current_user_can( 'moderate', $topic_id ) ) {
611 wp_die( esc_html__( 'You do not have permission to do that.', 'bbpress' ) );
612 }
613
614 // Defaults
615 $post_data = array( 'ID' => $topic_id );
616 $message = '';
617 $success = false;
618
619 switch ( $action ) {
620 case 'bbp_toggle_topic_approve' :
621 check_admin_referer( 'approve-topic_' . $topic_id );
622
623 $is_approve = bbp_is_topic_public( $topic_id );
624 $message = ( true === $is_approve )
625 ? 'unapproved'
626 : 'approved';
627 $success = ( true === $is_approve )
628 ? bbp_unapprove_topic( $topic_id )
629 : bbp_approve_topic( $topic_id );
630
631 break;
632
633 case 'bbp_toggle_topic_close' :
634 check_admin_referer( 'close-topic_' . $topic_id );
635
636 $is_open = bbp_is_topic_open( $topic_id );
637 $message = ( true === $is_open )
638 ? 'closed'
639 : 'opened';
640 $success = ( true === $is_open )
641 ? bbp_close_topic( $topic_id )
642 : bbp_open_topic( $topic_id );
643
644 break;
645
646 case 'bbp_toggle_topic_stick' :
647 check_admin_referer( 'stick-topic_' . $topic_id );
648
649 $is_sticky = bbp_is_topic_sticky( $topic_id );
650 $is_super = ( false === $is_sticky ) && ! empty( $_GET['super'] ) && ( '1' === $_GET['super'] )
651 ? true
652 : false;
653 $message = ( true === $is_sticky )
654 ? 'unstuck'
655 : 'stuck';
656 $message = ( true === $is_super )
657 ? 'super_sticky'
658 : $message;
659 $success = ( true === $is_sticky )
660 ? bbp_unstick_topic( $topic_id )
661 : bbp_stick_topic( $topic_id, $is_super );
662
663 break;
664
665 case 'bbp_toggle_topic_spam' :
666 check_admin_referer( 'spam-topic_' . $topic_id );
667
668 $is_spam = bbp_is_topic_spam( $topic_id );
669 $message = ( true === $is_spam )
670 ? 'unspammed'
671 : 'spammed';
672 $success = ( true === $is_spam )
673 ? bbp_unspam_topic( $topic_id )
674 : bbp_spam_topic( $topic_id );
675
676 break;
677 }
678
679 // Setup the message
680 $retval = array(
681 'bbp_topic_toggle_notice' => $message,
682 'topic_id' => $topic_id
683 );
684
685 // Prepare for failure
686 if ( ( false === $success ) || is_wp_error( $success ) ) {
687 $retval['failed'] = '1';
688 }
689
690 // Filter all message args
691 $retval = apply_filters( 'bbp_toggle_topic_action_admin', $retval, $topic_id, $action );
692
693 // Do additional topic toggle actions (admin side)
694 do_action( 'bbp_toggle_topic_admin', $success, $post_data, $action, $retval );
695
696 // Redirect back to the topic
697 $redirect = add_query_arg( $retval, remove_query_arg( array( 'action', 'topic_id' ) ) );
698 bbp_redirect( $redirect );
699 }
700
701 /**
702 * Toggle topic notices.
703 *
704 * Display the success/error notices from
705 * {@link BBP_Admin::toggle_topic()}
706 *
707 * @since 2.0.0 bbPress (r2727)
708 */
709 public function toggle_topic_notice() {
710
711 // Bail if missing topic toggle action
712 if ( ! bbp_is_get_request() || empty( $_GET['topic_id'] ) || empty( $_GET['bbp_topic_toggle_notice'] ) ) {
713 return;
714 }
715
716 // Bail if not an allowed notice
717 $notice = sanitize_key( $_GET['bbp_topic_toggle_notice'] );
718 if ( empty( $notice ) || ! in_array( $notice, $this->get_allowed_notice_toggles(), true ) ) {
719 return;
720 }
721
722 // Bail if no topic_id or notice
723 $topic_id = bbp_get_topic_id( $_GET['topic_id'] );
724 if ( empty( $topic_id ) ) {
725 return;
726 }
727
728 // Bail if topic is missing
729 if ( ! bbp_get_topic( $topic_id ) ) {
730 return;
731 }
732
733 // Use the title in the responses
734 $topic_title = bbp_get_topic_title( $topic_id );
735 $is_failure = ! empty( $_GET['failed'] );
736 $message = '';
737
738 // Which notice?
739 switch ( $notice ) {
740 case 'opened' :
741 $message = ( true === $is_failure )
742 /* translators: %1$s: Topic title */
743 ? sprintf( esc_html__( 'There was a problem opening the topic "%1$s".', 'bbpress' ), $topic_title )
744 /* translators: %1$s: Topic title */
745 : sprintf( esc_html__( 'Topic "%1$s" successfully opened.', 'bbpress' ), $topic_title );
746 break;
747
748 case 'closed' :
749 $message = ( true === $is_failure )
750 /* translators: %1$s: Topic title */
751 ? sprintf( esc_html__( 'There was a problem closing the topic "%1$s".', 'bbpress' ), $topic_title )
752 /* translators: %1$s: Topic title */
753 : sprintf( esc_html__( 'Topic "%1$s" successfully closed.', 'bbpress' ), $topic_title );
754 break;
755
756 case 'super_sticky' :
757 $message = ( true === $is_failure )
758 /* translators: %1$s: Topic title */
759 ? sprintf( esc_html__( 'There was a problem sticking the topic "%1$s" to front.', 'bbpress' ), $topic_title )
760 /* translators: %1$s: Topic title */
761 : sprintf( esc_html__( 'Topic "%1$s" successfully stuck to front.', 'bbpress' ), $topic_title );
762 break;
763
764 case 'stuck' :
765 $message = ( true === $is_failure )
766 /* translators: %1$s: Topic title */
767 ? sprintf( esc_html__( 'There was a problem sticking the topic "%1$s".', 'bbpress' ), $topic_title )
768 /* translators: %1$s: Topic title */
769 : sprintf( esc_html__( 'Topic "%1$s" successfully stuck.', 'bbpress' ), $topic_title );
770 break;
771
772 case 'unstuck' :
773 $message = ( true === $is_failure )
774 /* translators: %1$s: Topic title */
775 ? sprintf( esc_html__( 'There was a problem unsticking the topic "%1$s".', 'bbpress' ), $topic_title )
776 /* translators: %1$s: Topic title */
777 : sprintf( esc_html__( 'Topic "%1$s" successfully unstuck.', 'bbpress' ), $topic_title );
778 break;
779
780 case 'spammed' :
781 $message = ( true === $is_failure )
782 /* translators: %1$s: Topic title */
783 ? sprintf( esc_html__( 'There was a problem marking the topic "%1$s" as spam.', 'bbpress' ), $topic_title )
784 /* translators: %1$s: Topic title */
785 : sprintf( esc_html__( 'Topic "%1$s" successfully marked as spam.', 'bbpress' ), $topic_title );
786 break;
787
788 case 'unspammed' :
789 $message = ( true === $is_failure )
790 /* translators: %1$s: Topic title */
791 ? sprintf( esc_html__( 'There was a problem unmarking the topic "%1$s" as spam.', 'bbpress' ), $topic_title )
792 /* translators: %1$s: Topic title */
793 : sprintf( esc_html__( 'Topic "%1$s" successfully unmarked as spam.', 'bbpress' ), $topic_title );
794 break;
795
796 case 'approved' :
797 $message = ( true === $is_failure )
798 /* translators: %1$s: Topic title */
799 ? sprintf( esc_html__( 'There was a problem approving the topic "%1$s".', 'bbpress' ), $topic_title )
800 /* translators: %1$s: Topic title */
801 : sprintf( esc_html__( 'Topic "%1$s" successfully approved.', 'bbpress' ), $topic_title );
802 break;
803
804 case 'unapproved' :
805 $message = ( true === $is_failure )
806 /* translators: %1$s: Topic title */
807 ? sprintf( esc_html__( 'There was a problem unapproving the topic "%1$s".', 'bbpress' ), $topic_title )
808 /* translators: %1$s: Topic title */
809 : sprintf( esc_html__( 'Topic "%1$s" successfully unapproved.', 'bbpress' ), $topic_title );
810 break;
811 }
812
813 // Do additional topic toggle notice filters (admin side)
814 $message = apply_filters( 'bbp_toggle_topic_notice_admin', $message, $topic_id, $notice, $is_failure );
815 $class = ( true === $is_failure )
816 ? 'error'
817 : 'updated';
818
819 // Add the notice
820 bbp_admin()->add_notice( $message, $class, true );
821 }
822
823 /**
824 * Returns an array of keys used to sort row actions.
825 *
826 * @since 2.6.0 bbPress (r6771)
827 *
828 * @return array
829 */
830 private function get_row_action_sort_order() {
831
832 // Filter & return
833 return (array) apply_filters(
834 'bbp_admin_topics_row_action_sort_order',
835 array(
836 'edit',
837 'stick',
838 'approved',
839 'unapproved',
840 'closed',
841 'spam',
842 'unspam',
843 'trash',
844 'untrash',
845 'delete',
846 'view'
847 )
848 );
849 }
850
851 /**
852 * Returns an array of notice toggles.
853 *
854 * @since 2.6.0 bbPress (r6396)
855 *
856 * @return array
857 */
858 private function get_allowed_notice_toggles() {
859
860 // Filter & return
861 return (array) apply_filters(
862 'bbp_admin_topics_allowed_notice_toggles',
863 array(
864 'opened',
865 'closed',
866 'super_sticky',
867 'stuck',
868 'unstuck',
869 'spammed',
870 'unspammed',
871 'approved',
872 'unapproved'
873 )
874 );
875 }
876
877 /**
878 * Returns an array of notice toggles.
879 *
880 * @since 2.6.0 bbPress (r6396)
881 *
882 * @return array
883 */
884 private function get_allowed_action_toggles() {
885
886 // Filter & return
887 return (array) apply_filters(
888 'bbp_admin_topics_allowed_action_toggles',
889 array(
890 'bbp_toggle_topic_close',
891 'bbp_toggle_topic_stick',
892 'bbp_toggle_topic_spam',
893 'bbp_toggle_topic_approve'
894 )
895 );
896 }
897
898 /**
899 * Manage the column headers for the topics page.
900 *
901 * @since 2.0.0 bbPress (r2485)
902 *
903 * @param array $columns The columns.
904 *
905 * @return array $columns bbPress topic columns.
906 */
907 public function column_headers( $columns ) {
908 $columns = array(
909 'cb' => '<input type="checkbox" />',
910 'title' => esc_html__( 'Topics', 'bbpress' ),
911 'bbp_topic_forum' => esc_html__( 'Forum', 'bbpress' ),
912 'bbp_topic_reply_count' => esc_html__( 'Replies', 'bbpress' ),
913 'bbp_topic_voice_count' => esc_html__( 'Voices', 'bbpress' ),
914 'bbp_topic_author' => esc_html__( 'Author', 'bbpress' ),
915 'bbp_topic_created' => esc_html__( 'Created', 'bbpress' ),
916 'bbp_topic_freshness' => esc_html__( 'Last Post', 'bbpress' )
917 );
918
919 // Filter & return
920 return (array) apply_filters( 'bbp_admin_topics_column_headers', $columns );
921 }
922
923 /**
924 * Print extra columns for the topics page.
925 *
926 * @since 2.0.0 bbPress (r2485)
927 *
928 * @param string $column Column.
929 * @param int $topic_id Topic id.
930 */
931 public function column_data( $column, $topic_id ) {
932
933 // Get topic forum ID
934 $forum_id = bbp_get_topic_forum_id( $topic_id );
935
936 // Populate column data
937 switch ( $column ) {
938
939 // Forum
940 case 'bbp_topic_forum' :
941
942 // Get title
943 $forum_title = ! empty( $forum_id )
944 ? bbp_get_forum_title( $forum_id )
945 : '';
946
947 // Output forum name
948 if ( ! empty( $forum_title ) ) {
949 echo $forum_title;
950
951 // Output dash
952 } else {
953 ?>
954 <span aria-hidden="true">&mdash;</span>
955 <span class="screen-reader-text"><?php esc_html_e( 'No forum', 'bbpress' ); ?></span>
956 <?php
957 }
958
959 break;
960
961 // Reply Count
962 case 'bbp_topic_reply_count' :
963 bbp_topic_reply_count( $topic_id );
964 break;
965
966 // Reply Count
967 case 'bbp_topic_voice_count' :
968 bbp_topic_voice_count( $topic_id );
969 break;
970
971 // Author
972 case 'bbp_topic_author' :
973 bbp_topic_author_display_name( $topic_id );
974 break;
975
976 // Freshness
977 case 'bbp_topic_created':
978 printf( '%1$s <br /> %2$s',
979 get_the_date(),
980 esc_attr( get_the_time() )
981 );
982
983 break;
984
985 // Freshness
986 case 'bbp_topic_freshness' :
987 $last_active = bbp_get_topic_last_active_time( $topic_id, false );
988 if ( ! empty( $last_active ) ) {
989 echo esc_html( $last_active );
990 } else {
991 esc_html_e( 'No Replies', 'bbpress' ); // This should never happen
992 }
993
994 break;
995
996 // Do an action for anything else
997 default :
998 do_action( 'bbp_admin_topics_column_data', $column, $topic_id );
999 break;
1000 }
1001 }
1002
1003 /**
1004 * Topic Row actions.
1005 *
1006 * Remove the quick-edit action link under the topic title and add the
1007 * content and close/stick/spam links.
1008 *
1009 * @since 2.0.0 bbPress (r2485)
1010 *
1011 * @param array $actions Actions.
1012 * @param object $topic Topic object.
1013 *
1014 * @return array $actions Actions.
1015 */
1016 public function row_actions( $actions = array(), $topic = false ) {
1017
1018 // Disable quick edit (too much to do here)
1019 unset( $actions['inline hide-if-no-js'] );
1020
1021 // View link
1022 $view_link = bbp_get_topic_permalink( $topic->ID );
1023
1024 // Maybe add view=all
1025 if ( ! in_array( $topic->post_status, array( bbp_get_closed_status_id(), bbp_get_public_status_id() ), true ) ) {
1026 $view_link = bbp_add_view_all( $view_link, true );
1027 }
1028
1029 // Show view link if it's not set, the topic is trashed and the user can view trashed topics
1030 if ( empty( $actions['view'] ) && ( bbp_get_trash_status_id() === $topic->post_status ) && current_user_can( 'view_trash' ) ) {
1031 /* translators: %s: Topic title */
1032 $actions['view'] = '<a href="' . esc_url( $view_link ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;', 'bbpress' ), bbp_get_topic_title( $topic->ID ) ) ) . '" rel="permalink">' . esc_html__( 'View', 'bbpress' ) . '</a>';
1033 }
1034
1035 // Only show the actions if the user is capable of viewing them :)
1036 if ( current_user_can( 'moderate', $topic->ID ) ) {
1037
1038 // Pending
1039 // Show the 'approve' and 'view' link on pending posts only and 'unapprove' on published posts only
1040 $args = array(
1041 'topic_id' => $topic->ID,
1042 'action' => 'bbp_toggle_topic_approve'
1043 );
1044 $approve_uri = wp_nonce_url( add_query_arg( $args, remove_query_arg( array( 'bbp_topic_toggle_notice', 'topic_id', 'failed', 'super' ) ) ), 'approve-topic_' . $topic->ID );
1045 if ( bbp_is_topic_public( $topic->ID ) ) {
1046 $actions['unapproved'] = '<a href="' . esc_url( $approve_uri ) . '" title="' . esc_attr__( 'Unapprove this topic', 'bbpress' ) . '">' . _x( 'Unapprove', 'Unapprove Topic', 'bbpress' ) . '</a>';
1047 } else {
1048
1049 // Do not show 'approve' if already public
1050 if ( ! bbp_is_topic_public( $topic->ID ) ) {
1051 $actions['approved'] = '<a href="' . esc_url( $approve_uri ) . '" title="' . esc_attr__( 'Approve this topic', 'bbpress' ) . '">' . _x( 'Approve', 'Approve Topic', 'bbpress' ) . '</a>';
1052 }
1053
1054 // Modify the view link
1055 /* translators: %s: Topic title */
1056 $actions['view'] = '<a href="' . esc_url( $view_link ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;', 'bbpress' ), bbp_get_topic_title( $topic->ID ) ) ) . '" rel="permalink">' . esc_html__( 'View', 'bbpress' ) . '</a>';
1057 }
1058
1059 // Close
1060 // Show the 'close' and 'open' link on published and closed posts only
1061 if ( bbp_is_topic_public( $topic->ID ) ) {
1062 $args = array(
1063 'topic_id' => $topic->ID,
1064 'action' => 'bbp_toggle_topic_close'
1065 );
1066 $close_uri = wp_nonce_url( add_query_arg( $args, remove_query_arg( array( 'bbp_topic_toggle_notice', 'topic_id', 'failed', 'super' ) ) ), 'close-topic_' . $topic->ID );
1067 if ( bbp_is_topic_open( $topic->ID ) ) {
1068 $actions['closed'] = '<a href="' . esc_url( $close_uri ) . '" title="' . esc_attr__( 'Close this topic', 'bbpress' ) . '">' . _x( 'Close', 'Close a Topic', 'bbpress' ) . '</a>';
1069 } else {
1070 $actions['closed'] = '<a href="' . esc_url( $close_uri ) . '" title="' . esc_attr__( 'Open this topic', 'bbpress' ) . '">' . _x( 'Open', 'Open a Topic', 'bbpress' ) . '</a>';
1071 }
1072 }
1073
1074 // Sticky
1075 // Dont show sticky if topic is spam, trash or pending
1076 if ( ! bbp_is_topic_spam( $topic->ID ) && ! bbp_is_topic_trash( $topic->ID ) && ! bbp_is_topic_pending( $topic->ID ) ) {
1077 $args = array(
1078 'topic_id' => $topic->ID,
1079 'action' => 'bbp_toggle_topic_stick'
1080 );
1081 $stick_uri = wp_nonce_url( add_query_arg( $args, remove_query_arg( array( 'bbp_topic_toggle_notice', 'topic_id', 'failed', 'super' ) ) ), 'stick-topic_' . $topic->ID );
1082 if ( bbp_is_topic_sticky( $topic->ID ) ) {
1083 $actions['stick'] = '<a href="' . esc_url( $stick_uri ) . '" title="' . esc_attr__( 'Unstick this topic', 'bbpress' ) . '">' . esc_html__( 'Unstick', 'bbpress' ) . '</a>';
1084 } else {
1085 $args = array(
1086 'topic_id' => $topic->ID,
1087 'action' => 'bbp_toggle_topic_stick',
1088 'super' => '1'
1089 );
1090 $super_uri = wp_nonce_url( add_query_arg( $args, remove_query_arg( array( 'bbp_topic_toggle_notice', 'topic_id', 'failed', 'super' ) ) ), 'stick-topic_' . $topic->ID );
1091 $actions['stick'] = '<a href="' . esc_url( $stick_uri ) . '" title="' . esc_attr__( 'Stick this topic to its forum', 'bbpress' ) . '">' . esc_html__( 'Stick', 'bbpress' ) . '</a> <a href="' . esc_url( $super_uri ) . '" title="' . esc_attr__( 'Stick this topic to front', 'bbpress' ) . '">' . esc_html__( '(to front)', 'bbpress' ) . '</a>';
1092 }
1093 }
1094
1095 // Spam
1096 $args = array(
1097 'topic_id' => $topic->ID,
1098 'action' => 'bbp_toggle_topic_spam'
1099 );
1100 $spam_uri = wp_nonce_url( add_query_arg( $args, remove_query_arg( array( 'bbp_topic_toggle_notice', 'topic_id', 'failed', 'super' ) ) ), 'spam-topic_' . $topic->ID );
1101 if ( ! bbp_is_topic_spam( $topic->ID ) ) {
1102 $actions['spam'] = '<a href="' . esc_url( $spam_uri ) . '" title="' . esc_attr__( 'Mark this topic as spam', 'bbpress' ) . '">' . esc_html__( 'Spam', 'bbpress' ) . '</a>';
1103 } else {
1104 $actions['unspam'] = '<a href="' . esc_url( $spam_uri ) . '" title="' . esc_attr__( 'Mark the topic as not spam', 'bbpress' ) . '">' . esc_html__( 'Not Spam', 'bbpress' ) . '</a>';
1105 }
1106 }
1107
1108 // Do not show trash links for spam topics, or spam links for trashed topics
1109 if ( current_user_can( 'delete_topic', $topic->ID ) ) {
1110 $trash_days = bbp_get_trash_days( bbp_get_topic_post_type() );
1111
1112 if ( bbp_get_trash_status_id() === $topic->post_status ) {
1113 $post_type_object = get_post_type_object( bbp_get_topic_post_type() );
1114 $actions['untrash'] = "<a title='" . esc_attr__( 'Restore this item from the Trash', 'bbpress' ) . "' href='" . esc_url( wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $topic->ID ) ), 'untrash-post_' . $topic->ID ) ) . "'>" . esc_html__( 'Restore', 'bbpress' ) . '</a>';
1115 } elseif ( ! empty( $trash_days ) ) {
1116 $actions['trash'] = "<a class='submitdelete' title='" . esc_attr__( 'Move this item to the Trash', 'bbpress' ) . "' href='" . esc_url( get_delete_post_link( $topic->ID ) ) . "'>" . esc_html__( 'Trash', 'bbpress' ) . '</a>';
1117 }
1118
1119 if ( ( bbp_get_trash_status_id() === $topic->post_status ) || empty( $trash_days ) ) {
1120 $actions['delete'] = "<a class='submitdelete' title='" . esc_attr__( 'Delete this item permanently', 'bbpress' ) . "' href='" . esc_url( get_delete_post_link( $topic->ID, '', true ) ) . "'>" . esc_html__( 'Delete Permanently', 'bbpress' ) . '</a>';
1121 }
1122 }
1123
1124 // Sort & return
1125 return $this->sort_row_actions( $actions );
1126 }
1127
1128 /**
1129 * Sort row actions by key.
1130 *
1131 * @since 2.6.0
1132 *
1133 * @param array $actions
1134 *
1135 * @return array
1136 */
1137 private function sort_row_actions( $actions = array() ) {
1138
1139 // Return value
1140 $retval = array();
1141
1142 // Known row actions, in sort order
1143 $known_actions = $this->get_row_action_sort_order();
1144
1145 // Sort known actions, and keep any unknown ones
1146 foreach ( $known_actions as $key ) {
1147 if ( isset( $actions[ $key ] ) ) {
1148 $retval[ $key ] = $actions[ $key ];
1149 unset( $actions[ $key ] );
1150 }
1151 }
1152
1153 // Combine & return
1154 return $retval + $actions;
1155 }
1156
1157 /**
1158 * Add forum dropdown to topic and reply list table filters.
1159 *
1160 * @since 2.0.0 bbPress (r2991)
1161 *
1162 * @return bool False. If post type is not topic or reply.
1163 */
1164 public function filter_dropdown() {
1165
1166 // Get which forum is selected
1167 $selected = ! empty( $_GET['bbp_forum_id'] )
1168 ? (int) $_GET['bbp_forum_id']
1169 : 0;
1170
1171 // Show the forums dropdown
1172 bbp_dropdown(
1173 array(
1174 'selected' => $selected,
1175 'show_none' => esc_html__( 'In all forums', 'bbpress' )
1176 )
1177 );
1178 }
1179
1180 /**
1181 * Add "Empty Spam" button for moderators.
1182 *
1183 * @since 2.6.0 bbPress (r6791)
1184 */
1185 public function filter_empty_spam() {
1186
1187 // Bail if not viewing spam
1188 if (
1189 empty( $_GET['post_status'] )
1190 ||
1191 (
1192 ( bbp_get_spam_status_id() !== $_GET['post_status'] )
1193 &&
1194 current_user_can( 'moderate' )
1195 )
1196 ) {
1197 return;
1198 }
1199
1200 ?>
1201
1202 <div class="alignleft actions"><?php
1203
1204 // Output the nonce & button
1205 wp_nonce_field( 'bulk-destroy', '_destroy_nonce' );
1206 submit_button(
1207 esc_attr__( 'Empty Spam', 'bbpress' ),
1208 'button-secondary apply',
1209 'delete_all',
1210 false
1211 );
1212
1213 ?></div><?php
1214 }
1215
1216 /**
1217 * Adjust the request query and include the forum id.
1218 *
1219 * @since 2.0.0 bbPress (r2991)
1220 *
1221 * @param array $query_vars Query variables from {@link WP_Query}.
1222 * @return array Processed Query Vars.
1223 */
1224 public function filter_post_rows( $query_vars ) {
1225
1226 // Add post_parent query_var if one is present
1227 if ( ! empty( $_GET['bbp_forum_id'] ) ) {
1228 $query_vars['meta_key'] = '_bbp_forum_id';
1229 $query_vars['meta_type'] = 'NUMERIC';
1230 $query_vars['meta_value'] = $_GET['bbp_forum_id'];
1231 }
1232
1233 // Return manipulated query_vars
1234 return $query_vars;
1235 }
1236
1237 /**
1238 * Custom user feedback messages for topic post type.
1239 *
1240 * @since 2.0.0 bbPress (r3080)
1241 *
1242 * @global int $post_ID
1243 *
1244 * @param array $messages
1245 *
1246 * @return array
1247 */
1248 public function updated_messages( $messages ) {
1249 global $post_ID;
1250
1251 // URL for the current topic
1252 $topic_url = bbp_get_topic_permalink( $post_ID );
1253
1254 // Current topic's post_date
1255 $post_date = bbp_get_global_post_field( 'post_date', 'raw' );
1256
1257 // Messages array
1258 $messages[ $this->post_type ] = array(
1259 0 => '', // Left empty on purpose
1260
1261 // Updated
1262 1 => sprintf(
1263 '%1$s <a href="%2$s">%3$s</a>',
1264 esc_html__( 'Topic updated.', 'bbpress' ),
1265 $topic_url,
1266 esc_html__( 'View topic', 'bbpress' )
1267 ),
1268
1269 // Custom field updated
1270 2 => esc_html__( 'Custom field updated.', 'bbpress' ),
1271
1272 // Custom field deleted
1273 3 => esc_html__( 'Custom field deleted.', 'bbpress' ),
1274
1275 // Topic updated
1276 4 => esc_html__( 'Topic updated.', 'bbpress' ),
1277
1278 // Restored from revision
1279 /* translators: %s: date and time of the revision */
1280 5 => isset( $_GET['revision'] )
1281 /* translators: %s: Date and time of the revision */
1282 ? sprintf( esc_html__( 'Topic restored to revision from %s', 'bbpress' ), wp_post_revision_title( (int) $_GET['revision'], false ) )
1283 : false,
1284
1285 // Topic created
1286 6 => sprintf(
1287 '%1$s <a href="%2$s">%3$s</a>',
1288 esc_html__( 'Topic created.', 'bbpress' ),
1289 $topic_url,
1290 esc_html__( 'View topic', 'bbpress' )
1291 ),
1292
1293 // Topic saved
1294 7 => esc_html__( 'Topic saved.', 'bbpress' ),
1295
1296 // Topic submitted
1297 8 => sprintf(
1298 '%1$s <a href="%2$s" target="_blank">%3$s</a>',
1299 esc_html__( 'Topic submitted.', 'bbpress' ),
1300 esc_url( add_query_arg( 'preview', 'true', $topic_url ) ),
1301 esc_html__( 'Preview topic', 'bbpress' )
1302 ),
1303
1304 // Topic scheduled
1305 9 => sprintf(
1306 '%1$s <a target="_blank" href="%2$s">%3$s</a>',
1307 sprintf(
1308 /* translators: Publish box date format, see http://php.net/date */
1309 esc_html__( 'Topic scheduled for: %s.', 'bbpress' ),
1310 '<strong>' . date_i18n( __( 'M j, Y @ G:i', 'bbpress' ), strtotime( $post_date ) ) . '</strong>'
1311 ),
1312 $topic_url,
1313 esc_html__( 'Preview topic', 'bbpress' )
1314 ),
1315
1316 // Topic draft updated
1317 10 => sprintf(
1318 '%1$s <a href="%2$s" target="_blank">%3$s</a>',
1319 esc_html__( 'Topic draft updated.', 'bbpress' ),
1320 esc_url( add_query_arg( 'preview', 'true', $topic_url ) ),
1321 esc_html__( 'Preview topic', 'bbpress' )
1322 ),
1323 );
1324
1325 return $messages;
1326 }
1327 }
1328 endif; // class_exists check
1329
1330 /**
1331 * Setup bbPress Topics Admin.
1332 *
1333 * This is currently here to make hooking and unhooking of the admin UI easy.
1334 * It could use dependency injection in the future, but for now this is easier.
1335 *
1336 * @since 2.0.0 bbPress (r2596)
1337 *
1338 * @param WP_Screen $current_screen Current screen object.
1339 */
1340 function bbp_admin_topics( $current_screen ) {
1341
1342 // Bail if not a forum screen
1343 if ( empty( $current_screen->post_type ) || ( bbp_get_topic_post_type() !== $current_screen->post_type ) ) {
1344 return;
1345 }
1346
1347 // Init the topics admin
1348 bbp_admin()->topics = new BBP_Topics_Admin();
1349 }
1350