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 / forums.php

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

858 lines 27.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress Forum 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_Forums_Admin' ) ) :
14 /**
15 * Loads bbPress forums admin area
16 *
17 * @package bbPress
18 * @subpackage Administration
19 * @since 2.0.0 bbPress (r2464)
20 */
21 class BBP_Forums_Admin {
22
23 /** Variables *************************************************************/
24
25 /**
26 * @var string The post type of this admin component
27 */
28 private $post_type = '';
29
30 /** Functions *************************************************************/
31
32 /**
33 * The main bbPress forums 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 *
47 * @access private
48 */
49 private function setup_actions() {
50
51 // Messages
52 add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) );
53
54 // Forum Column headers.
55 add_filter( 'manage_' . $this->post_type . '_posts_columns', array( $this, 'column_headers' ) );
56
57 // Forum Columns (in page row)
58 add_action( 'manage_' . $this->post_type . '_posts_custom_column', array( $this, 'column_data' ), 10, 2 );
59 add_filter( 'page_row_actions', array( $this, 'row_actions' ), 10, 2 );
60
61 // Metabox actions
62 add_action( 'add_meta_boxes', array( $this, 'attributes_metabox' ) );
63 add_action( 'add_meta_boxes', array( $this, 'moderators_metabox' ) );
64 add_action( 'add_meta_boxes', array( $this, 'subscriptions_metabox' ) );
65 add_action( 'add_meta_boxes', array( $this, 'comments_metabox' ) );
66 add_action( 'save_post', array( $this, 'save_meta_boxes' ) );
67
68 // Check if there are any bbp_toggle_forum_* requests on admin_init, also have a message displayed
69 add_action( 'load-edit.php', array( $this, 'toggle_forum' ) );
70 add_action( 'load-edit.php', array( $this, 'toggle_forum_notice' ) );
71
72 // Contextual Help
73 add_action( 'load-edit.php', array( $this, 'edit_help' ) );
74 add_action( 'load-post.php', array( $this, 'new_help' ) );
75 add_action( 'load-post-new.php', array( $this, 'new_help' ) );
76 }
77
78 /**
79 * Admin globals
80 *
81 * @since 2.0.0 bbPress (r2646)
82 *
83 * @access private
84 */
85 private function setup_globals() {
86 $this->post_type = bbp_get_forum_post_type();
87 }
88
89 /** Contextual Help *******************************************************/
90
91 /**
92 * Contextual help for bbPress forum edit page
93 *
94 * @since 2.0.0 bbPress (r3119)
95 */
96 public function edit_help() {
97
98 // Overview
99 get_current_screen()->add_help_tab(
100 array(
101 'id' => 'overview',
102 'title' => __( 'Overview', 'bbpress' ),
103 'content' =>
104 '<p>' . __( 'This screen displays the individual forums on your site. You can customize the display of this screen to suit your workflow.', 'bbpress' ) . '</p>'
105 )
106 );
107
108 // Screen Content
109 get_current_screen()->add_help_tab(
110 array(
111 'id' => 'screen-content',
112 'title' => __( 'Screen Content', 'bbpress' ),
113 'content' =>
114 '<p>' . __( 'You can customize the display of this screen&#8217;s contents in a number of ways:', 'bbpress' ) . '</p>' .
115 '<ul>' .
116 '<li>' . __( 'You can hide/display columns based on your needs and decide how many forums to list per screen using the Screen Options tab.', 'bbpress' ) . '</li>' .
117 '<li>' . __( 'You can filter the list of forums by forum status using the text links in the upper left to show All, Published, or Trashed forums. The default view is to show all forums.', 'bbpress' ) . '</li>' .
118 '<li>' . __( 'You can refine the list to show only forums from a specific month by using the dropdown menus above the forums list. Click the Filter button after making your selection. You also can refine the list by clicking on the forum creator in the forums list.', 'bbpress' ) . '</li>' .
119 '</ul>'
120 )
121 );
122
123 // Available Actions
124 get_current_screen()->add_help_tab(
125 array(
126 'id' => 'action-links',
127 'title' => __( 'Available Actions', 'bbpress' ),
128 'content' =>
129 '<p>' . __( 'Hovering over a row in the forums list will display action links that allow you to manage your forum. You can perform the following actions:', 'bbpress' ) . '</p>' .
130 '<ul>' .
131 '<li>' . __( '<strong>Edit</strong> takes you to the editing screen for that forum. You can also reach that screen by clicking on the forum title.', 'bbpress' ) . '</li>' .
132 '<li>' . __( '<strong>Close</strong> will mark the selected forum as &#8217;closed&#8217; and disable the ability to post new topics and replies in it.', 'bbpress' ) . '</li>' .
133 '<li>' . __( '<strong>Trash</strong> removes your forum from this list and places it in the trash, from which you can permanently delete it.', 'bbpress' ) . '</li>' .
134 '<li>' . __( '<strong>View</strong> will either show you what your draft forum will look like if you publish it, or take you to your live site to view it. Which link depends on your forum&#8217;s status.', 'bbpress' ) . '</li>' .
135 '</ul>'
136 )
137 );
138
139 // Bulk Actions
140 get_current_screen()->add_help_tab(
141 array(
142 'id' => 'bulk-actions',
143 'title' => __( 'Bulk Actions', 'bbpress' ),
144 'content' =>
145 '<p>' . __( 'You can also edit or move multiple forums to the trash at once. Select the forums 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>' .
146 '<p>' . __( 'When using Bulk Edit, you can change the metadata (categories, author, etc.) for all selected forums at once. To remove a forum from the grouping, just click the x next to its name in the Bulk Edit area that appears.', 'bbpress' ) . '</p>'
147 )
148 );
149
150 // Help Sidebar
151 get_current_screen()->set_help_sidebar(
152 '<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' .
153 '<p>' . __( '<a href="https://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' .
154 '<p>' . __( '<a href="https://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>'
155 );
156 }
157
158 /**
159 * Contextual help for bbPress forum edit page
160 *
161 * @since 2.0.0 bbPress (r3119)
162 */
163 public function new_help() {
164
165 $customize_display = '<p>' . __( 'The title field and the big forum 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>';
166
167 get_current_screen()->add_help_tab(
168 array(
169 'id' => 'customize-display',
170 'title' => __( 'Customizing This Display', 'bbpress' ),
171 'content' => $customize_display,
172 )
173 );
174
175 get_current_screen()->add_help_tab(
176 array(
177 'id' => 'title-forum-editor',
178 'title' => __( 'Title and Forum Editor', 'bbpress' ),
179 'content' =>
180 '<p>' . __( '<strong>Title</strong> - Enter a title for your forum. After you enter a title, you&#8217;ll see the permalink below, which you can edit.', 'bbpress' ) . '</p>' .
181 '<p>' . __( '<strong>Forum Editor</strong> - Enter the text for your forum. 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 forum text. You can insert media files by clicking the icons above the forum 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 forum editor.', 'bbpress' ) . '</p>'
182 )
183 );
184
185 $publish_box = '<p>' . __( '<strong>Publish</strong> - You can set the terms of publishing your forum 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 forum 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 forum to be published in the future or backdate a forum.', 'bbpress' ) . '</p>';
186
187 if ( current_theme_supports( 'forum-thumbnails' ) && post_type_supports( 'forum', 'thumbnail' ) ) {
188 $publish_box .= '<p>' . __( '<strong>Featured Image</strong> - This allows you to associate an image with your forum without inserting it. This is usually useful only if your theme makes use of the featured image as a forum thumbnail on the home page, a custom header, etc.', 'bbpress' ) . '</p>';
189 }
190
191 get_current_screen()->add_help_tab(
192 array(
193 'id' => 'forum-attributes',
194 'title' => __( 'Forum Attributes', 'bbpress' ),
195 'content' =>
196 '<p>' . __( 'Select the attributes that your forum should have:', 'bbpress' ) . '</p>' .
197 '<ul>' .
198 '<li>' . __( '<strong>Type</strong> indicates if the forum is a category or forum. Categories generally contain other forums.', 'bbpress' ) . '</li>' .
199 '<li>' . __( '<strong>Status</strong> allows you to close a forum to new topics and forums.', 'bbpress' ) . '</li>' .
200 '<li>' . __( '<strong>Visibility</strong> lets you pick the scope of each forum and what users are allowed to access it.', 'bbpress' ) . '</li>' .
201 '<li>' . __( '<strong>Parent</strong> dropdown determines the parent forum. Select the forum or category from the dropdown, or leave the default "No parent" to create the forum at the root of your forums.', 'bbpress' ) . '</li>' .
202 '<li>' . __( '<strong>Order</strong> allows you to order your forums numerically.', 'bbpress' ) . '</li>' .
203 '</ul>'
204 )
205 );
206
207 get_current_screen()->add_help_tab(
208 array(
209 'id' => 'publish-box',
210 'title' => __( 'Publish Box', 'bbpress' ),
211 'content' => $publish_box,
212 )
213 );
214
215 get_current_screen()->set_help_sidebar(
216 '<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' .
217 '<p>' . __( '<a href="https://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' .
218 '<p>' . __( '<a href="https://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>'
219 );
220 }
221
222 /**
223 * Add the forum attributes meta-box
224 *
225 * @since 2.0.0 bbPress (r2746)
226 */
227 public function attributes_metabox() {
228
229 // Bail if the current user cannot edit forum structure
230 if ( ! current_user_can( 'assign_moderators' ) ) {
231 return;
232 }
233
234 add_meta_box(
235 'bbp_forum_attributes',
236 esc_html__( 'Forum Attributes', 'bbpress' ),
237 'bbp_forum_metabox',
238 $this->post_type,
239 'side',
240 'high'
241 );
242 }
243
244 /**
245 * Add the forum moderators meta-box
246 *
247 * @since 2.6.0 bbPress
248 */
249 public function moderators_metabox() {
250
251 // Bail if feature not active or user cannot assign moderators
252 if ( ! bbp_allow_forum_mods() || ! current_user_can( 'assign_moderators' ) ) {
253 return;
254 }
255
256 // Moderators
257 add_meta_box(
258 'bbp_moderator_assignment_metabox',
259 esc_html__( 'Forum Moderators', 'bbpress' ),
260 'bbp_moderator_assignment_metabox',
261 $this->post_type,
262 'side',
263 'high'
264 );
265 }
266
267 /**
268 * Add the subscriptions meta-box
269 *
270 * Allows viewing of users who have subscribed to a forum.
271 *
272 * @since 2.6.0 bbPress (r6197)
273 */
274 public function subscriptions_metabox() {
275
276 // Bail if post_type is not a reply
277 if ( empty( $_GET['action'] ) || ( 'edit' !== $_GET['action'] ) ) {
278 return;
279 }
280
281 // Bail if no subscriptions
282 if ( ! bbp_is_subscriptions_active() ) {
283 return;
284 }
285
286 // Add the meta-box
287 add_meta_box(
288 'bbp_forum_subscriptions_metabox',
289 esc_html__( 'Subscriptions', 'bbpress' ),
290 'bbp_forum_subscriptions_metabox',
291 $this->post_type,
292 'normal',
293 'high'
294 );
295 }
296
297 /**
298 * Remove comments & discussion meta-boxes if comments are not supported
299 *
300 * @since 2.6.0 bbPress (r6186)
301 */
302 public function comments_metabox() {
303 if ( ! post_type_supports( $this->post_type, 'comments' ) ) {
304 remove_meta_box( 'commentstatusdiv', $this->post_type, 'normal' );
305 remove_meta_box( 'commentsdiv', $this->post_type, 'normal' );
306 }
307 }
308
309 /**
310 * Pass the forum attributes for processing
311 *
312 * @since 2.0.0 bbPress (r2746)
313 *
314 * @param int $forum_id Forum id
315 * @return int Forum id
316 */
317 public function save_meta_boxes( $forum_id ) {
318
319 // Bail if doing an autosave
320 if ( bbp_doing_autosave() ) {
321 return $forum_id;
322 }
323
324 // Bail if not a post request
325 if ( ! bbp_is_post_request() ) {
326 return $forum_id;
327 }
328
329 // Nonce check
330 if ( empty( $_POST['bbp_forum_metabox'] ) || ! wp_verify_nonce( $_POST['bbp_forum_metabox'], 'bbp_forum_metabox_save' ) ) {
331 return $forum_id;
332 }
333
334 // Only save for forum post-types
335 if ( ! bbp_is_forum( $forum_id ) ) {
336 return $forum_id;
337 }
338
339 // Bail if current user cannot edit this forum
340 if ( ! current_user_can( 'edit_forum', $forum_id ) ) {
341 return $forum_id;
342 }
343
344 // Bail if current user cannot edit forum structure
345 if ( ! current_user_can( 'assign_moderators' ) ) {
346 return $forum_id;
347 }
348
349 // Parent ID
350 $parent_id = ( ! empty( $_POST['parent_id'] ) && is_numeric( $_POST['parent_id'] ) )
351 ? (int) $_POST['parent_id']
352 : 0;
353
354 // Update the forum meta bidness
355 bbp_update_forum(
356 array(
357 'forum_id' => $forum_id,
358 'post_parent' => $parent_id
359 )
360 );
361
362 do_action( 'bbp_forum_attributes_metabox_save', $forum_id );
363
364 return $forum_id;
365 }
366
367 /**
368 * Toggle forum
369 *
370 * Handles the admin-side opening/closing of forums
371 *
372 * @since 2.6.0 bbPress (r5254)
373 */
374 public function toggle_forum() {
375
376 // Bail if not a forum toggle action
377 if ( ! bbp_is_get_request() || empty( $_GET['action'] ) || empty( $_GET['forum_id'] ) ) {
378 return;
379 }
380
381 // Bail if not an allowed action
382 $action = sanitize_key( $_GET['action'] );
383 if ( empty( $action ) || ! in_array( $action, $this->get_allowed_action_toggles(), true ) ) {
384 return;
385 }
386
387 // Bail if forum is missing
388 $forum_id = bbp_get_forum_id( $_GET['forum_id'] );
389 if ( ! bbp_get_forum( $forum_id ) ) {
390 wp_die( esc_html__( 'The forum was not found.', 'bbpress' ) );
391 }
392
393 // What is the user doing here?
394 if ( ! current_user_can( 'manage_forum_attributes', $forum_id ) ) {
395 wp_die( esc_html__( 'You do not have permission to do that.', 'bbpress' ) );
396 }
397
398 // Defaults
399 $post_data = array( 'ID' => $forum_id );
400 $message = '';
401 $success = false;
402
403 switch ( $action ) {
404 case 'bbp_toggle_forum_close' :
405 check_admin_referer( 'close-forum_' . $forum_id );
406
407 $is_open = bbp_is_forum_open( $forum_id );
408 $message = ( true === $is_open )
409 ? 'closed'
410 : 'opened';
411 $success = ( true === $is_open )
412 ? bbp_close_forum( $forum_id )
413 : bbp_open_forum( $forum_id );
414
415 break;
416 }
417
418 // Setup the message
419 $retval = array(
420 'bbp_forum_toggle_notice' => $message,
421 'forum_id' => $forum_id
422 );
423
424 // Prepare for failure
425 if ( ( false === $success ) || is_wp_error( $success ) ) {
426 $retval['failed'] = '1';
427 }
428
429 // Filter all message args
430 $retval = apply_filters( 'bbp_toggle_forum_action_admin', $retval, $forum_id, $action );
431
432 // Do additional forum toggle actions (admin side)
433 do_action( 'bbp_toggle_forum_admin', $success, $post_data, $action, $retval );
434
435 // Redirect back to the forum
436 $redirect = add_query_arg( $retval, remove_query_arg( array( 'action', 'forum_id' ) ) );
437 bbp_redirect( $redirect );
438 }
439
440 /**
441 * Toggle forum notices
442 *
443 * Display the success/error notices from
444 * {@link BBP_Admin::toggle_forum()}
445 *
446 * @since 2.6.0 bbPress (r5254)
447 */
448 public function toggle_forum_notice() {
449
450 // Bail if missing forum toggle action
451 if ( ! bbp_is_get_request() || empty( $_GET['forum_id'] ) || empty( $_GET['bbp_forum_toggle_notice'] ) ) {
452 return;
453 }
454
455 // Bail if not an allowed notice
456 $notice = sanitize_key( $_GET['bbp_forum_toggle_notice'] );
457 if ( empty( $notice ) || ! in_array( $notice, $this->get_allowed_notice_toggles(), true ) ) {
458 return;
459 }
460
461 // Bail if no forum_id or notice
462 $forum_id = bbp_get_forum_id( $_GET['forum_id'] );
463 if ( empty( $forum_id ) ) {
464 return;
465 }
466
467 // Bail if forum is missing
468 if ( ! bbp_get_forum( $forum_id ) ) {
469 return;
470 }
471
472 // Use the title in the responses
473 $forum_title = bbp_get_forum_title( $forum_id );
474 $is_failure = ! empty( $_GET['failed'] );
475 $message = '';
476
477 switch ( $notice ) {
478 case 'opened' :
479 $message = ( true === $is_failure )
480 /* translators: %1$s: Forum title */
481 ? sprintf( esc_html__( 'There was a problem opening the forum "%1$s".', 'bbpress' ), $forum_title )
482 /* translators: %1$s: Forum title */
483 : sprintf( esc_html__( 'Forum "%1$s" successfully opened.', 'bbpress' ), $forum_title );
484 break;
485
486 case 'closed' :
487 $message = ( true === $is_failure )
488 /* translators: %1$s: Forum title */
489 ? sprintf( esc_html__( 'There was a problem closing the forum "%1$s".', 'bbpress' ), $forum_title )
490 /* translators: %1$s: Forum title */
491 : sprintf( esc_html__( 'Forum "%1$s" successfully closed.', 'bbpress' ), $forum_title );
492 break;
493 }
494
495 // Do additional forum toggle notice filters (admin side)
496 $message = apply_filters( 'bbp_toggle_forum_notice_admin', $message, $forum_id, $notice, $is_failure );
497 $class = ( true === $is_failure )
498 ? 'error'
499 : 'updated';
500
501 // Add the notice
502 bbp_admin()->add_notice( $message, $class, true );
503 }
504
505 /**
506 * Returns an array of keys used to sort row actions
507 *
508 * @since 2.6.0 bbPress (r6771)
509 *
510 * @return array
511 */
512 private function get_row_action_sort_order() {
513
514 /**
515 * Filters the row action sort order.
516 *
517 * @since 2.6.0 bbPress (r6771)
518 *
519 * @param array $order The default sort order.
520 */
521 return (array) apply_filters(
522 'bbp_admin_forum_row_action_sort_order',
523 array(
524 'edit',
525 'closed',
526 'trash',
527 'untrash',
528 'delete',
529 'view'
530 )
531 );
532 }
533
534 /**
535 * Returns an array of notice toggles
536 *
537 * @since 2.6.0 bbPress (r6396)
538 *
539 * @return array
540 */
541 private function get_allowed_notice_toggles() {
542
543 // Filter & return
544 return apply_filters(
545 'bbp_admin_forums_allowed_notice_toggles',
546 array(
547 'opened',
548 'closed'
549 )
550 );
551 }
552
553 /**
554 * Returns an array of notice toggles
555 *
556 * @since 2.6.0 bbPress (r6396)
557 *
558 * @return array
559 */
560 private function get_allowed_action_toggles() {
561
562 /**
563 * Filters the allowed action toggles.
564 *
565 * @since 2.6.0 bbPress (r6396)
566 *
567 * @param array $toggles The default action toggles.
568 */
569 return apply_filters(
570 'bbp_admin_forums_allowed_action_toggles',
571 array(
572 'bbp_toggle_forum_close'
573 )
574 );
575 }
576
577 /**
578 * Manage the column headers for the forums page
579 *
580 * @since 2.0.0 bbPress (r2485)
581 *
582 * @param array $columns The columns
583 *
584 * @return array $columns bbPress forum columns
585 */
586 public function column_headers( $columns ) {
587
588 // Set list table column headers
589 $columns = array(
590 'cb' => '<input type="checkbox" />',
591 'title' => esc_html__( 'Forum', 'bbpress' ),
592 'bbp_forum_topic_count' => esc_html__( 'Topics', 'bbpress' ),
593 'bbp_forum_reply_count' => esc_html__( 'Replies', 'bbpress' ),
594 'bbp_forum_mods' => esc_html__( 'Moderators', 'bbpress' ),
595 'author' => esc_html__( 'Creator', 'bbpress' ),
596 'bbp_forum_created' => esc_html__( 'Created', 'bbpress' ),
597 'bbp_forum_freshness' => esc_html__( 'Last Post', 'bbpress' )
598 );
599
600 // Remove forum mods column if not enabled
601 if ( ! bbp_allow_forum_mods() ) {
602 unset( $columns['bbp_forum_mods'] );
603 }
604
605 // Filter & return
606 return apply_filters( 'bbp_admin_forums_column_headers', $columns );
607 }
608
609 /**
610 * Print extra columns for the forums page
611 *
612 * @since 2.0.0 bbPress (r2485)
613 *
614 * @param string $column Column
615 * @param int $forum_id Forum id
616 */
617 public function column_data( $column, $forum_id ) {
618
619 switch ( $column ) {
620 case 'bbp_forum_topic_count' :
621 bbp_forum_topic_count( $forum_id );
622 break;
623
624 case 'bbp_forum_reply_count' :
625 bbp_forum_reply_count( $forum_id );
626 break;
627
628 case 'bbp_forum_mods' :
629 bbp_moderator_list(
630 $forum_id,
631 array(
632 'before' => '',
633 'after' => '',
634 'none' => esc_html__( '&mdash;', 'bbpress' )
635 )
636 );
637 break;
638
639 case 'bbp_forum_created':
640 printf(
641 '%1$s <br /> %2$s',
642 get_the_date(),
643 esc_attr( get_the_time() )
644 );
645
646 break;
647
648 case 'bbp_forum_freshness' :
649 $last_active = bbp_get_forum_last_active_time( $forum_id, false );
650 if ( ! empty( $last_active ) ) {
651 echo esc_html( $last_active );
652 } else {
653 esc_html_e( 'No Topics', 'bbpress' );
654 }
655
656 break;
657
658 default:
659 do_action( 'bbp_admin_forums_column_data', $column, $forum_id );
660 break;
661 }
662 }
663
664 /**
665 * Forum Row actions
666 *
667 * Remove the quick-edit action link and display the description under
668 * the forum title and add the open/close links
669 *
670 * @since 2.0.0 bbPress (r2577)
671 *
672 * @param array $actions Actions
673 * @param object $forum Forum object
674 *
675 * @return array $actions Actions
676 */
677 public function row_actions( $actions = array(), $forum = false ) {
678
679 // Disable quick edit (too much to do here)
680 unset( $actions['inline hide-if-no-js'] );
681
682 // Only show the actions if the user is capable of viewing them :)
683 if ( current_user_can( 'edit_forum', $forum->ID ) ) {
684
685 // Show the 'close' and 'open' link on published, private, hidden and closed posts only
686 if ( in_array( $forum->post_status, array( bbp_get_public_status_id(), bbp_get_private_status_id(), bbp_get_hidden_status_id(), bbp_get_closed_status_id() ), true ) ) {
687 $args = array(
688 'forum_id' => $forum->ID,
689 'action' => 'bbp_toggle_forum_close'
690 );
691 $close_uri = wp_nonce_url( add_query_arg( $args, remove_query_arg( array( 'bbp_forum_toggle_notice', 'forum_id', 'failed', 'super' ) ) ), 'close-forum_' . $forum->ID );
692 if ( bbp_is_forum_open( $forum->ID ) ) {
693 $actions['closed'] = '<a href="' . esc_url( $close_uri ) . '" title="' . esc_attr__( 'Close this forum', 'bbpress' ) . '">' . _x( 'Close', 'Close a Forum', 'bbpress' ) . '</a>';
694 } else {
695 $actions['closed'] = '<a href="' . esc_url( $close_uri ) . '" title="' . esc_attr__( 'Open this forum', 'bbpress' ) . '">' . _x( 'Open', 'Open a Forum', 'bbpress' ) . '</a>';
696 }
697 }
698 }
699
700 // Only show content if user can read it and there is no password
701 if ( current_user_can( 'read_forum', $forum->ID ) && ! post_password_required( $forum ) ) {
702
703 // Get the forum description
704 $content = bbp_get_forum_content( $forum->ID );
705
706 // Only proceed if there is a description
707 if ( ! empty( $content ) ) {
708 echo '<div class="bbp-escaped-content">' . esc_html( wp_trim_excerpt( $content, $forum ) ) . '</div>';
709 }
710 }
711
712 // Sort & return
713 return $this->sort_row_actions( $actions );
714 }
715
716 /**
717 * Sort row actions by key
718 *
719 * @since 2.6.0
720 *
721 * @param array $actions
722 *
723 * @return array
724 */
725 private function sort_row_actions( $actions = array() ) {
726
727 // Return value
728 $retval = array();
729
730 // Known row actions, in sort order
731 $known_actions = $this->get_row_action_sort_order();
732
733 // Sort known actions, and keep any unknown ones
734 foreach ( $known_actions as $key ) {
735 if ( isset( $actions[ $key ] ) ) {
736 $retval[ $key ] = $actions[ $key ];
737 unset( $actions[ $key ] );
738 }
739 }
740
741 // Combine & return
742 return $retval + $actions;
743 }
744
745 /**
746 * Custom user feedback messages for forum post type
747 *
748 * @since 2.0.0 bbPress (r3080)
749 *
750 * @global int $post_ID
751 *
752 * @param array $messages
753 *
754 * @return array
755 */
756 public function updated_messages( $messages ) {
757 global $post_ID;
758
759 // URL for the current forum
760 $forum_url = bbp_get_forum_permalink( $post_ID );
761
762 // Current forum's post_date
763 $post_date = bbp_get_global_post_field( 'post_date', 'raw' );
764
765 // Messages array
766 $messages[ $this->post_type ] = array(
767 0 => '', // Left empty on purpose
768
769 // Updated
770 1 => sprintf(
771 '%1$s <a href="%2$s">%3$s</a>',
772 esc_html__( 'Forum updated.', 'bbpress' ),
773 $forum_url,
774 esc_html__( 'View forum', 'bbpress' )
775 ),
776
777 // Custom field updated
778 2 => esc_html__( 'Custom field updated.', 'bbpress' ),
779
780 // Custom field deleted
781 3 => esc_html__( 'Custom field deleted.', 'bbpress' ),
782
783 // Forum updated
784 4 => esc_html__( 'Forum updated.', 'bbpress' ),
785
786 // Restored from revision
787 /* translators: %s: date and time of the revision */
788 5 => isset( $_GET['revision'] )
789 /* translators: %s: Date and time of the revision */
790 ? sprintf( esc_html__( 'Forum restored to revision from %s', 'bbpress' ), wp_post_revision_title( (int) $_GET['revision'], false ) )
791 : false,
792
793 // Forum created
794 6 => sprintf(
795 '%1$s <a href="%2$s">%3$s</a>',
796 esc_html__( 'Forum created.', 'bbpress' ),
797 $forum_url,
798 esc_html__( 'View forum', 'bbpress' )
799 ),
800
801 // Forum saved
802 7 => esc_html__( 'Forum saved.', 'bbpress' ),
803
804 // Forum submitted
805 8 => sprintf(
806 '%1$s <a href="%2$s" target="_blank">%3$s</a>',
807 esc_html__( 'Forum submitted.', 'bbpress' ),
808 esc_url( add_query_arg( 'preview', 'true', $forum_url ) ),
809 esc_html__( 'Preview forum', 'bbpress' )
810 ),
811
812 // Forum scheduled
813 9 => sprintf(
814 '%1$s <a target="_blank" href="%2$s">%3$s</a>',
815 sprintf(
816 /* translators: %s: Publish box date format, see http://php.net/date */
817 esc_html__( 'Forum scheduled for: %s.', 'bbpress' ),
818 '<strong>' . date_i18n( __( 'M j, Y @ G:i', 'bbpress' ), strtotime( $post_date ) ) . '</strong>'
819 ),
820 $forum_url,
821 __( 'Preview forum', 'bbpress' )
822 ),
823
824 // Forum draft updated
825 10 => sprintf(
826 '%1$s <a href="%2$s" target="_blank">%3$s</a>',
827 esc_html__( 'Forum draft updated.', 'bbpress' ),
828 esc_url( add_query_arg( 'preview', 'true', $forum_url ) ),
829 esc_html__( 'Preview forum', 'bbpress' )
830 ),
831 );
832
833 return $messages;
834 }
835 }
836 endif; // class_exists check
837
838 /**
839 * Setup bbPress Forums Admin
840 *
841 * This is currently here to make hooking and unhooking of the admin UI easy.
842 * It could use dependency injection in the future, but for now this is easier.
843 *
844 * @since 2.0.0 bbPress (r2596)
845 *
846 * @param WP_Screen $current_screen Current screen object
847 */
848 function bbp_admin_forums( $current_screen ) {
849
850 // Bail if not a forum screen
851 if ( empty( $current_screen->post_type ) || ( bbp_get_forum_post_type() !== $current_screen->post_type ) ) {
852 return;
853 }
854
855 // Init the forums admin
856 bbp_admin()->forums = new BBP_Forums_Admin();
857 }
858