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

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

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