PluginProbe
bbPress / 2.6.17
bbPress v2.6.17
2.6.17 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 All 72 releases
bbpress / includes / admin / topics.php

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

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