PluginProbe
bbPress / 2.6.6
bbPress v2.6.6
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
← All changes | includes/admin/forums.php +430 -230 2.22.6.6 View file →
@@ -7,17 +7,17 @@
7 7 * @subpackage Administration
8 8 */
9 9
10 10 // Exit if accessed directly
11 -if ( !defined( 'ABSPATH' ) ) exit;
11 +defined( 'ABSPATH' ) || exit;
12 12
13 -if ( !class_exists( 'BBP_Forums_Admin' ) ) :
13 +if ( ! class_exists( 'BBP_Forums_Admin' ) ) :
14 14 /**
15 15 * Loads bbPress forums admin area
16 16 *
17 17 * @package bbPress
18 18 * @subpackage Administration
19 - * @since bbPress (r2464)
19 + * @since 2.0.0 bbPress (r2464)
20 20 */
21 21 class BBP_Forums_Admin {
22 22
23 23 /** Variables *************************************************************/
@@ -22,9 +22,9 @@
22 22
23 23 /** Variables *************************************************************/
24 24
25 25 /**
26 - * @var The post type of this admin component
26 + * @var string The post type of this admin component
27 27 */
28 28 private $post_type = '';
29 29
30 30 /** Functions *************************************************************/
@@ -31,13 +31,9 @@
31 31
32 32 /**
33 33 * The main bbPress forums admin loader
34 34 *
35 - * @since bbPress (r2515)
36 - *
37 - * @uses BBP_Forums_Admin::setup_globals() Setup the globals needed
38 - * @uses BBP_Forums_Admin::setup_actions() Setup the hooks and actions
39 - * @uses BBP_Forums_Admin::setup_help() Setup the help text
35 + * @since 2.0.0 bbPress (r2515)
40 36 */
41 37 public function __construct() {
42 38 $this->setup_globals();
43 39 $this->setup_actions();
@@ -45,58 +41,46 @@
45 41
46 42 /**
47 43 * Setup the admin hooks, actions and filters
48 44 *
49 - * @since bbPress (r2646)
45 + * @since 2.0.0 bbPress (r2646)
46 + *
50 47 * @access private
51 - *
52 - * @uses add_action() To add various actions
53 - * @uses add_filter() To add various filters
54 - * @uses bbp_get_forum_post_type() To get the forum post type
55 - * @uses bbp_get_topic_post_type() To get the topic post type
56 - * @uses bbp_get_reply_post_type() To get the reply post type
57 48 */
58 49 private function setup_actions() {
59 50
60 - // Add some general styling to the admin area
61 - add_action( 'bbp_admin_head', array( $this, 'admin_head' ) );
62 -
63 51 // Messages
64 52 add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) );
65 53
66 - // Metabox actions
67 - add_action( 'add_meta_boxes', array( $this, 'attributes_metabox' ) );
68 - add_action( 'save_post', array( $this, 'attributes_metabox_save' ) );
69 -
70 - // Column headers.
54 + // Forum Column headers.
71 55 add_filter( 'manage_' . $this->post_type . '_posts_columns', array( $this, 'column_headers' ) );
72 56
73 - // Columns (in page row)
57 + // Forum Columns (in page row)
74 58 add_action( 'manage_' . $this->post_type . '_posts_custom_column', array( $this, 'column_data' ), 10, 2 );
75 59 add_filter( 'page_row_actions', array( $this, 'row_actions' ), 10, 2 );
76 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 +
77 72 // Contextual Help
78 73 add_action( 'load-edit.php', array( $this, 'edit_help' ) );
74 + add_action( 'load-post.php', array( $this, 'new_help' ) );
79 75 add_action( 'load-post-new.php', array( $this, 'new_help' ) );
80 76 }
81 77
82 78 /**
83 - * Should we bail out of this method?
79 + * Admin globals
84 80 *
85 - * @since bbPress (r4067)
86 - * @return boolean
87 - */
88 - private function bail() {
89 - if ( !isset( get_current_screen()->post_type ) || ( $this->post_type != get_current_screen()->post_type ) )
90 - return true;
91 -
92 - return false;
93 - }
94 -
95 - /**
96 - * Admin globals
81 + * @since 2.0.0 bbPress (r2646)
97 82 *
98 - * @since bbPress (r2646)
99 83 * @access private
100 84 */
101 85 private function setup_globals() {
102 86 $this->post_type = bbp_get_forum_post_type();
@@ -106,15 +90,12 @@
106 90
107 91 /**
108 92 * Contextual help for bbPress forum edit page
109 93 *
110 - * @since bbPress (r3119)
111 - * @uses get_current_screen()
94 + * @since 2.0.0 bbPress (r3119)
112 95 */
113 96 public function edit_help() {
114 97
115 - if ( $this->bail() ) return;
116 -
117 98 // Overview
118 99 get_current_screen()->add_help_tab( array(
119 100 'id' => 'overview',
120 101 'title' => __( 'Overview', 'bbpress' ),
@@ -141,11 +122,12 @@
141 122 'title' => __( 'Available Actions', 'bbpress' ),
142 123 'content' =>
143 124 '<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>' .
144 125 '<ul>' .
145 - '<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>' .
146 - '<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>' .
147 - '<li>' . __( '<strong>View</strong> will show you what your draft forum will look like if you publish it. View will take you to your live site to view the forum. Which link is available depends on your forum&#8217;s status.', 'bbpress' ) . '</li>' .
126 + '<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>' .
127 + '<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>' .
128 + '<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>' .
129 + '<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>' .
148 130 '</ul>'
149 131 ) );
150 132
151 133 // Bulk Actions
@@ -159,10 +141,10 @@
159 141
160 142 // Help Sidebar
161 143 get_current_screen()->set_help_sidebar(
162 144 '<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' .
163 - '<p>' . __( '<a href="http://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' .
164 - '<p>' . __( '<a href="http://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>'
145 + '<p>' . __( '<a href="https://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' .
146 + '<p>' . __( '<a href="https://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>'
165 147 );
166 148 }
167 149
168 150 /**
@@ -167,15 +149,12 @@
167 149
168 150 /**
169 151 * Contextual help for bbPress forum edit page
170 152 *
171 - * @since bbPress (r3119)
172 - * @uses get_current_screen()
153 + * @since 2.0.0 bbPress (r3119)
173 154 */
174 155 public function new_help() {
175 156
176 - if ( $this->bail() ) return;
177 -
178 157 $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>';
179 158
180 159 get_current_screen()->add_help_tab( array(
181 160 'id' => 'customize-display',
@@ -192,13 +171,9 @@
192 171 ) );
193 172
194 173 $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>';
195 174
196 - if ( current_theme_supports( 'forum-formats' ) && forum_type_supports( 'forum', 'forum-formats' ) ) {
197 - $publish_box .= '<p>' . __( '<strong>forum Format</strong> - This designates how your theme will display a specific forum. For example, you could have a <em>standard</em> blog forum with a title and paragraphs, or a short <em>aside</em> that omits the title and contains a short text blurb. Please refer to the Codex for <a href="http://codex.wordpress.org/Post_Formats#Supported_Formats">descriptions of each forum format</a>. Your theme could enable all or some of 10 possible formats.', 'bbpress' ) . '</p>';
198 - }
199 -
200 - if ( current_theme_supports( 'forum-thumbnails' ) && forum_type_supports( 'forum', 'thumbnail' ) ) {
175 + if ( current_theme_supports( 'forum-thumbnails' ) && post_type_supports( 'forum', 'thumbnail' ) ) {
201 176 $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>';
202 177 }
203 178
204 179 get_current_screen()->add_help_tab( array(
@@ -209,9 +184,9 @@
209 184 '<ul>' .
210 185 '<li>' . __( '<strong>Type</strong> indicates if the forum is a category or forum. Categories generally contain other forums.', 'bbpress' ) . '</li>' .
211 186 '<li>' . __( '<strong>Status</strong> allows you to close a forum to new topics and forums.', 'bbpress' ) . '</li>' .
212 187 '<li>' . __( '<strong>Visibility</strong> lets you pick the scope of each forum and what users are allowed to access it.', 'bbpress' ) . '</li>' .
213 - '<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>' .
188 + '<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>' .
214 189 '<li>' . __( '<strong>Order</strong> allows you to order your forums numerically.', 'bbpress' ) . '</li>' .
215 190 '</ul>'
216 191 ) );
217 192
@@ -220,101 +195,140 @@
220 195 'title' => __( 'Publish Box', 'bbpress' ),
221 196 'content' => $publish_box,
222 197 ) );
223 198
224 - get_current_screen()->add_help_tab( array(
225 - 'id' => 'discussion-settings',
226 - 'title' => __( 'Discussion Settings', 'bbpress' ),
227 - 'content' =>
228 - '<p>' . __( '<strong>Send Trackbacks</strong> - Trackbacks are a way to notify legacy blog systems that you&#8217;ve linked to them. Enter the URL(s) you want to send trackbacks. If you link to other WordPress sites they&#8217;ll be notified automatically using pingbacks, and this field is unnecessary.', 'bbpress' ) . '</p>' .
229 - '<p>' . __( '<strong>Discussion</strong> - You can turn comments and pings on or off, and if there are comments on the forum, you can see them here and moderate them.', 'bbpress' ) . '</p>'
230 - ) );
231 -
232 199 get_current_screen()->set_help_sidebar(
233 200 '<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' .
234 - '<p>' . __( '<a href="http://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' .
235 - '<p>' . __( '<a href="http://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>'
201 + '<p>' . __( '<a href="https://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' .
202 + '<p>' . __( '<a href="https://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>'
236 203 );
237 204 }
238 205
239 206 /**
240 - * Add the forum attributes metabox
207 + * Add the forum attributes meta-box
241 208 *
242 - * @since bbPress (r2746)
209 + * @since 2.0.0 bbPress (r2746)
210 + */
211 + public function attributes_metabox() {
212 + add_meta_box(
213 + 'bbp_forum_attributes',
214 + esc_html__( 'Forum Attributes', 'bbpress' ),
215 + 'bbp_forum_metabox',
216 + $this->post_type,
217 + 'side',
218 + 'high'
219 + );
220 + }
221 +
222 + /**
223 + * Add the forum moderators meta-box
243 224 *
244 - * @uses bbp_get_forum_post_type() To get the forum post type
245 - * @uses add_meta_box() To add the metabox
246 - * @uses do_action() Calls 'bbp_forum_attributes_metabox'
225 + * @since 2.6.0 bbPress
247 226 */
248 - public function attributes_metabox() {
227 + public function moderators_metabox() {
249 228
250 - if ( $this->bail() ) return;
229 + // Bail if feature not active or user cannot assign moderators
230 + if ( ! bbp_allow_forum_mods() || ! current_user_can( 'assign_moderators' ) ) {
231 + return;
232 + }
251 233
252 - add_meta_box (
253 - 'bbp_forum_attributes',
254 - __( 'Forum Attributes', 'bbpress' ),
255 - 'bbp_forum_metabox',
234 + // Moderators
235 + add_meta_box(
236 + 'bbp_moderator_assignment_metabox',
237 + esc_html__( 'Forum Moderators', 'bbpress' ),
238 + 'bbp_moderator_assignment_metabox',
256 239 $this->post_type,
257 240 'side',
258 241 'high'
259 242 );
243 + }
260 244
261 - do_action( 'bbp_forum_attributes_metabox' );
245 + /**
246 + * Add the subscriptions meta-box
247 + *
248 + * Allows viewing of users who have subscribed to a forum.
249 + *
250 + * @since 2.6.0 bbPress (r6197)
251 + */
252 + public function subscriptions_metabox() {
253 +
254 + // Bail if post_type is not a reply
255 + if ( empty( $_GET['action'] ) || ( 'edit' !== $_GET['action'] ) ) {
256 + return;
257 + }
258 +
259 + // Bail if no subscriptions
260 + if ( ! bbp_is_subscriptions_active() ) {
261 + return;
262 + }
263 +
264 + // Add the meta-box
265 + add_meta_box(
266 + 'bbp_forum_subscriptions_metabox',
267 + esc_html__( 'Subscriptions', 'bbpress' ),
268 + 'bbp_forum_subscriptions_metabox',
269 + $this->post_type,
270 + 'normal',
271 + 'high'
272 + );
262 273 }
263 274
264 275 /**
276 + * Remove comments & discussion meta-boxes if comments are not supported
277 + *
278 + * @since 2.6.0 bbPress (r6186)
279 + */
280 + public function comments_metabox() {
281 + if ( ! post_type_supports( $this->post_type, 'comments' ) ) {
282 + remove_meta_box( 'commentstatusdiv', $this->post_type, 'normal' );
283 + remove_meta_box( 'commentsdiv', $this->post_type, 'normal' );
284 + }
285 + }
286 +
287 + /**
265 288 * Pass the forum attributes for processing
266 289 *
267 - * @since bbPress (r2746)
290 + * @since 2.0.0 bbPress (r2746)
268 291 *
269 292 * @param int $forum_id Forum id
270 - * @uses current_user_can() To check if the current user is capable of
271 - * editing the forum
272 - * @uses bbp_get_forum() To get the forum
273 - * @uses bbp_is_forum_closed() To check if the forum is closed
274 - * @uses bbp_is_forum_category() To check if the forum is a category
275 - * @uses bbp_is_forum_private() To check if the forum is private
276 - * @uses bbp_close_forum() To close the forum
277 - * @uses bbp_open_forum() To open the forum
278 - * @uses bbp_categorize_forum() To make the forum a category
279 - * @uses bbp_normalize_forum() To make the forum normal (not category)
280 - * @uses bbp_privatize_forum() To mark the forum as private
281 - * @uses bbp_publicize_forum() To mark the forum as public
282 - * @uses do_action() Calls 'bbp_forum_attributes_metabox_save' with the
283 - * forum id
284 293 * @return int Forum id
285 294 */
286 - public function attributes_metabox_save( $forum_id ) {
295 + public function save_meta_boxes( $forum_id ) {
287 296
288 - if ( $this->bail() ) return $forum_id;
289 -
290 297 // Bail if doing an autosave
291 - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
298 + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
292 299 return $forum_id;
300 + }
293 301
294 302 // Bail if not a post request
295 - if ( 'POST' != strtoupper( $_SERVER['REQUEST_METHOD'] ) )
303 + if ( ! bbp_is_post_request() ) {
296 304 return $forum_id;
305 + }
297 306
298 307 // Nonce check
299 - if ( empty( $_POST['bbp_forum_metabox'] ) || !wp_verify_nonce( $_POST['bbp_forum_metabox'], 'bbp_forum_metabox_save' ) )
308 + if ( empty( $_POST['bbp_forum_metabox'] ) || ! wp_verify_nonce( $_POST['bbp_forum_metabox'], 'bbp_forum_metabox_save' ) ) {
300 309 return $forum_id;
310 + }
301 311
302 312 // Only save for forum post-types
303 - if ( ! bbp_is_forum( $forum_id ) )
313 + if ( ! bbp_is_forum( $forum_id ) ) {
304 314 return $forum_id;
315 + }
305 316
306 317 // Bail if current user cannot edit this forum
307 - if ( !current_user_can( 'edit_forum', $forum_id ) )
318 + if ( ! current_user_can( 'edit_forum', $forum_id ) ) {
308 319 return $forum_id;
320 + }
309 321
310 322 // Parent ID
311 - $parent_id = ( !empty( $_POST['parent_id'] ) && is_numeric( $_POST['parent_id'] ) ) ? (int) $_POST['parent_id'] : 0;
323 + $parent_id = ( ! empty( $_POST['parent_id'] ) && is_numeric( $_POST['parent_id'] ) )
324 + ? (int) $_POST['parent_id']
325 + : 0;
312 326
313 327 // Update the forum meta bidness
314 328 bbp_update_forum( array(
315 329 'forum_id' => $forum_id,
316 - 'post_parent' => (int) $parent_id
330 + 'post_parent' => $parent_id
317 331 ) );
318 332
319 333 do_action( 'bbp_forum_attributes_metabox_save', $forum_id );
320 334
@@ -321,111 +335,221 @@
321 335 return $forum_id;
322 336 }
323 337
324 338 /**
325 - * Add some general styling to the admin area
339 + * Toggle forum
326 340 *
327 - * @since bbPress (r2464)
341 + * Handles the admin-side opening/closing of forums
328 342 *
329 - * @uses bbp_get_forum_post_type() To get the forum post type
330 - * @uses bbp_get_topic_post_type() To get the topic post type
331 - * @uses bbp_get_reply_post_type() To get the reply post type
332 - * @uses sanitize_html_class() To sanitize the classes
333 - * @uses do_action() Calls 'bbp_admin_head'
343 + * @since 2.6.0 bbPress (r5254)
334 344 */
335 - public function admin_head() {
345 + public function toggle_forum() {
336 346
337 - if ( $this->bail() ) return;
347 + // Bail if not a forum toggle action
348 + if ( ! bbp_is_get_request() || empty( $_GET['action'] ) || empty( $_GET['forum_id'] ) ) {
349 + return;
350 + }
338 351
339 - ?>
352 + // Bail if not an allowed action
353 + $action = sanitize_key( $_GET['action'] );
354 + if ( empty( $action ) || ! in_array( $action, $this->get_allowed_action_toggles(), true ) ) {
355 + return;
356 + }
340 357
341 - <style type="text/css" media="screen">
342 - /*<![CDATA[*/
358 + // Bail if forum is missing
359 + $forum_id = bbp_get_forum_id( $_GET['forum_id'] );
360 + if ( ! bbp_get_forum( $forum_id ) ) {
361 + wp_die( esc_html__( 'The forum was not found.', 'bbpress' ) );
362 + }
343 363
344 - #misc-publishing-actions,
345 - #save-post {
346 - display: none;
347 - }
364 + // What is the user doing here?
365 + if ( ! current_user_can( 'edit_forum', $forum_id ) ) {
366 + wp_die( esc_html__( 'You do not have permission to do that.', 'bbpress' ) );
367 + }
348 368
349 - strong.label {
350 - display: inline-block;
351 - width: 60px;
352 - }
369 + // Defaults
370 + $post_data = array( 'ID' => $forum_id );
371 + $message = '';
372 + $success = false;
353 373
354 - #bbp_forum_attributes hr {
355 - border-style: solid;
356 - border-width: 1px;
357 - border-color: #ccc #fff #fff #ccc;
358 - }
374 + switch ( $action ) {
375 + case 'bbp_toggle_forum_close' :
376 + check_admin_referer( 'close-forum_' . $forum_id );
359 377
360 - .column-bbp_forum_topic_count,
361 - .column-bbp_forum_reply_count,
362 - .column-bbp_topic_reply_count,
363 - .column-bbp_topic_voice_count {
364 - width: 8% !important;
365 - }
378 + $is_open = bbp_is_forum_open( $forum_id );
379 + $message = ( true === $is_open )
380 + ? 'closed'
381 + : 'opened';
382 + $success = ( true === $is_open )
383 + ? bbp_close_forum( $forum_id )
384 + : bbp_open_forum( $forum_id );
366 385
367 - .column-author,
368 - .column-bbp_reply_author,
369 - .column-bbp_topic_author {
370 - width: 10% !important;
371 - }
386 + break;
387 + }
372 388
373 - .column-bbp_topic_forum,
374 - .column-bbp_reply_forum,
375 - .column-bbp_reply_topic {
376 - width: 10% !important;
377 - }
389 + // Setup the message
390 + $retval = array(
391 + 'bbp_forum_toggle_notice' => $message,
392 + 'forum_id' => $forum_id
393 + );
378 394
379 - .column-bbp_forum_freshness,
380 - .column-bbp_topic_freshness {
381 - width: 10% !important;
382 - }
395 + // Prepare for failure
396 + if ( ( false === $success ) || is_wp_error( $success ) ) {
397 + $retval['failed'] = '1';
398 + }
383 399
384 - .column-bbp_forum_created,
385 - .column-bbp_topic_created,
386 - .column-bbp_reply_created {
387 - width: 15% !important;
388 - }
400 + // Filter all message args
401 + $retval = apply_filters( 'bbp_toggle_forum_action_admin', $retval, $forum_id, $action );
389 402
390 - .status-closed {
391 - background-color: #eaeaea;
392 - }
403 + // Do additional forum toggle actions (admin side)
404 + do_action( 'bbp_toggle_forum_admin', $success, $post_data, $action, $retval );
393 405
394 - .status-spam {
395 - background-color: #faeaea;
396 - }
406 + // Redirect back to the forum
407 + $redirect = add_query_arg( $retval, remove_query_arg( array( 'action', 'forum_id' ) ) );
408 + bbp_redirect( $redirect );
409 + }
397 410
398 - /*]]>*/
399 - </style>
411 + /**
412 + * Toggle forum notices
413 + *
414 + * Display the success/error notices from
415 + * {@link BBP_Admin::toggle_forum()}
416 + *
417 + * @since 2.6.0 bbPress (r5254)
418 + */
419 + public function toggle_forum_notice() {
400 420
401 - <?php
421 + // Bail if missing forum toggle action
422 + if ( ! bbp_is_get_request() || empty( $_GET['forum_id'] ) || empty( $_GET['bbp_forum_toggle_notice'] ) ) {
423 + return;
424 + }
425 +
426 + // Bail if not an allowed notice
427 + $notice = sanitize_key( $_GET['bbp_forum_toggle_notice'] );
428 + if ( empty( $notice ) || ! in_array( $notice, $this->get_allowed_notice_toggles(), true ) ) {
429 + return;
430 + }
431 +
432 + // Bail if no forum_id or notice
433 + $forum_id = bbp_get_forum_id( $_GET['forum_id'] );
434 + if ( empty( $forum_id ) ) {
435 + return;
436 + }
437 +
438 + // Bail if forum is missing
439 + if ( ! bbp_get_forum( $forum_id ) ) {
440 + return;
441 + }
442 +
443 + // Use the title in the responses
444 + $forum_title = bbp_get_forum_title( $forum_id );
445 + $is_failure = ! empty( $_GET['failed'] );
446 + $message = '';
447 +
448 + switch ( $notice ) {
449 + case 'opened' :
450 + $message = ( $is_failure === true )
451 + ? sprintf( esc_html__( 'There was a problem opening the forum "%1$s".', 'bbpress' ), $forum_title )
452 + : sprintf( esc_html__( 'Forum "%1$s" successfully opened.', 'bbpress' ), $forum_title );
453 + break;
454 +
455 + case 'closed' :
456 + $message = ( $is_failure === true )
457 + ? sprintf( esc_html__( 'There was a problem closing the forum "%1$s".', 'bbpress' ), $forum_title )
458 + : sprintf( esc_html__( 'Forum "%1$s" successfully closed.', 'bbpress' ), $forum_title );
459 + break;
460 + }
461 +
462 + // Do additional forum toggle notice filters (admin side)
463 + $message = apply_filters( 'bbp_toggle_forum_notice_admin', $message, $forum_id, $notice, $is_failure );
464 + $class = ( $is_failure === true )
465 + ? 'error'
466 + : 'updated';
467 +
468 + // Add the notice
469 + bbp_admin()->add_notice( $message, $class, true );
402 470 }
403 471
404 472 /**
473 + * Returns an array of keys used to sort row actions
474 + *
475 + * @since 2.6.0 bbPress (r6771)
476 + *
477 + * @return array
478 + */
479 + private function get_row_action_sort_order() {
480 +
481 + // Filter & return
482 + return (array) apply_filters( 'bbp_admin_forum_row_action_sort_order', array(
483 + 'edit',
484 + 'closed',
485 + 'trash',
486 + 'untrash',
487 + 'delete',
488 + 'view'
489 + ) );
490 + }
491 +
492 + /**
493 + * Returns an array of notice toggles
494 + *
495 + * @since 2.6.0 bbPress (r6396)
496 + *
497 + * @return array
498 + */
499 + private function get_allowed_notice_toggles() {
500 +
501 + // Filter & return
502 + return apply_filters( 'bbp_admin_forums_allowed_notice_toggles', array(
503 + 'opened',
504 + 'closed'
505 + ) );
506 + }
507 +
508 + /**
509 + * Returns an array of notice toggles
510 + *
511 + * @since 2.6.0 bbPress (r6396)
512 + *
513 + * @return array
514 + */
515 + private function get_allowed_action_toggles() {
516 +
517 + // Filter & return
518 + return apply_filters( 'bbp_admin_forums_allowed_action_toggles', array(
519 + 'bbp_toggle_forum_close'
520 + ) );
521 + }
522 +
523 + /**
405 524 * Manage the column headers for the forums page
406 525 *
407 - * @since bbPress (r2485)
526 + * @since 2.0.0 bbPress (r2485)
408 527 *
409 528 * @param array $columns The columns
410 - * @uses apply_filters() Calls 'bbp_admin_forums_column_headers' with
411 - * the columns
529 + *
412 530 * @return array $columns bbPress forum columns
413 531 */
414 532 public function column_headers( $columns ) {
415 533
416 - if ( $this->bail() ) return $columns;
417 -
418 - $columns = array (
534 + // Set list table column headers
535 + $columns = array(
419 536 'cb' => '<input type="checkbox" />',
420 - 'title' => __( 'Forum', 'bbpress' ),
421 - 'bbp_forum_topic_count' => __( 'Topics', 'bbpress' ),
422 - 'bbp_forum_reply_count' => __( 'Replies', 'bbpress' ),
423 - 'author' => __( 'Creator', 'bbpress' ),
424 - 'bbp_forum_created' => __( 'Created' , 'bbpress' ),
425 - 'bbp_forum_freshness' => __( 'Freshness', 'bbpress' )
537 + 'title' => esc_html__( 'Forum', 'bbpress' ),
538 + 'bbp_forum_topic_count' => esc_html__( 'Topics', 'bbpress' ),
539 + 'bbp_forum_reply_count' => esc_html__( 'Replies', 'bbpress' ),
540 + 'bbp_forum_mods' => esc_html__( 'Moderators', 'bbpress' ),
541 + 'author' => esc_html__( 'Creator', 'bbpress' ),
542 + 'bbp_forum_created' => esc_html__( 'Created' , 'bbpress' ),
543 + 'bbp_forum_freshness' => esc_html__( 'Last Post', 'bbpress' )
426 544 );
427 545
546 + // Remove forum mods column if not enabled
547 + if ( ! bbp_allow_forum_mods() ) {
548 + unset( $columns['bbp_forum_mods'] );
549 + }
550 +
551 + // Filter & return
428 552 return apply_filters( 'bbp_admin_forums_column_headers', $columns );
429 553 }
430 554
431 555 /**
@@ -430,26 +554,15 @@
430 554
431 555 /**
432 556 * Print extra columns for the forums page
433 557 *
434 - * @since bbPress (r2485)
558 + * @since 2.0.0 bbPress (r2485)
435 559 *
436 560 * @param string $column Column
437 561 * @param int $forum_id Forum id
438 - * @uses bbp_forum_topic_count() To output the forum topic count
439 - * @uses bbp_forum_reply_count() To output the forum reply count
440 - * @uses get_the_date() Get the forum creation date
441 - * @uses get_the_time() Get the forum creation time
442 - * @uses esc_attr() To sanitize the forum creation time
443 - * @uses bbp_get_forum_last_active_time() To get the time when the forum was
444 - * last active
445 - * @uses do_action() Calls 'bbp_admin_forums_column_data' with the
446 - * column and forum id
447 562 */
448 563 public function column_data( $column, $forum_id ) {
449 564
450 - if ( $this->bail() ) return;
451 -
452 565 switch ( $column ) {
453 566 case 'bbp_forum_topic_count' :
454 567 bbp_forum_topic_count( $forum_id );
455 568 break;
@@ -457,10 +570,18 @@
457 570 case 'bbp_forum_reply_count' :
458 571 bbp_forum_reply_count( $forum_id );
459 572 break;
460 573
574 + case 'bbp_forum_mods' :
575 + bbp_moderator_list( $forum_id, array(
576 + 'before' => '',
577 + 'after' => '',
578 + 'none' => esc_html__( '&mdash;', 'bbpress' )
579 + ) );
580 + break;
581 +
461 582 case 'bbp_forum_created':
462 - printf( __( '%1$s <br /> %2$s', 'bbpress' ),
583 + printf( '%1$s <br /> %2$s',
463 584 get_the_date(),
464 585 esc_attr( get_the_time() )
465 586 );
466 587
@@ -467,12 +588,13 @@
467 588 break;
468 589
469 590 case 'bbp_forum_freshness' :
470 591 $last_active = bbp_get_forum_last_active_time( $forum_id, false );
471 - if ( !empty( $last_active ) )
472 - echo $last_active;
473 - else
474 - _e( 'No Topics', 'bbpress' );
592 + if ( ! empty( $last_active ) ) {
593 + echo esc_html( $last_active );
594 + } else {
595 + esc_html_e( 'No Topics', 'bbpress' );
596 + }
475 597
476 598 break;
477 599
478 600 default:
@@ -484,39 +606,87 @@
484 606 /**
485 607 * Forum Row actions
486 608 *
487 609 * Remove the quick-edit action link and display the description under
488 - * the forum title
610 + * the forum title and add the open/close links
489 611 *
490 - * @since bbPress (r2577)
612 + * @since 2.0.0 bbPress (r2577)
491 613 *
492 - * @param array $actions Actions
493 - * @param array $forum Forum object
494 - * @uses the_content() To output forum description
614 + * @param array $actions Actions
615 + * @param object $forum Forum object
616 + *
495 617 * @return array $actions Actions
496 618 */
497 - public function row_actions( $actions, $forum ) {
619 + public function row_actions( $actions = array(), $forum = false ) {
498 620
499 - if ( $this->bail() ) return $actions;
621 + // Disable quick edit (too much to do here)
622 + unset( $actions['inline hide-if-no-js'] );
500 623
501 - unset( $actions['inline hide-if-no-js'] );
624 + // Only show the actions if the user is capable of viewing them :)
625 + if ( current_user_can( 'edit_forum', $forum->ID ) ) {
502 626
503 - // simple hack to show the forum description under the title
504 - bbp_forum_content( $forum->ID );
627 + // Show the 'close' and 'open' link on published, private, hidden and closed posts only
628 + 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 ) ) {
629 + $close_uri = wp_nonce_url( add_query_arg( array( 'forum_id' => $forum->ID, 'action' => 'bbp_toggle_forum_close' ), remove_query_arg( array( 'bbp_forum_toggle_notice', 'forum_id', 'failed', 'super' ) ) ), 'close-forum_' . $forum->ID );
630 + if ( bbp_is_forum_open( $forum->ID ) ) {
631 + $actions['closed'] = '<a href="' . esc_url( $close_uri ) . '" title="' . esc_attr__( 'Close this forum', 'bbpress' ) . '">' . _x( 'Close', 'Close a Forum', 'bbpress' ) . '</a>';
632 + } else {
633 + $actions['closed'] = '<a href="' . esc_url( $close_uri ) . '" title="' . esc_attr__( 'Open this forum', 'bbpress' ) . '">' . _x( 'Open', 'Open a Forum', 'bbpress' ) . '</a>';
634 + }
635 + }
636 + }
505 637
506 - return $actions;
638 + // Only show content if user can read it and there is no password
639 + if ( current_user_can( 'read_forum', $forum->ID ) && ! post_password_required( $forum ) ) {
640 +
641 + // Get the forum description
642 + $content = bbp_get_forum_content( $forum->ID );
643 +
644 + // Only proceed if there is a description
645 + if ( ! empty( $content ) ) {
646 + echo '<div class="bbp-escaped-content">' . esc_html( wp_trim_excerpt( $content, $forum ) ) . '</div>';
647 + }
648 + }
649 +
650 + // Sort & return
651 + return $this->sort_row_actions( $actions );
507 652 }
508 653
509 654 /**
655 + * Sort row actions by key
656 + *
657 + * @since 2.6.0
658 + *
659 + * @param array $actions
660 + *
661 + * @return array
662 + */
663 + private function sort_row_actions( $actions = array() ) {
664 +
665 + // Return value
666 + $retval = array();
667 +
668 + // Known row actions, in sort order
669 + $known_actions = $this->get_row_action_sort_order();
670 +
671 + // Sort known actions, and keep any unknown ones
672 + foreach ( $known_actions as $key ) {
673 + if ( isset( $actions[ $key ] ) ) {
674 + $retval[ $key ] = $actions[ $key ];
675 + unset( $actions[ $key ] );
676 + }
677 + }
678 +
679 + // Combine & return
680 + return $retval + $actions;
681 + }
682 +
683 + /**
510 684 * Custom user feedback messages for forum post type
511 685 *
512 - * @since bbPress (r3080)
686 + * @since 2.0.0 bbPress (r3080)
513 687 *
514 688 * @global int $post_ID
515 - * @uses bbp_get_forum_permalink()
516 - * @uses wp_post_revision_title()
517 - * @uses esc_url()
518 - * @uses add_query_arg()
519 689 *
520 690 * @param array $messages
521 691 *
522 692 * @return array
@@ -523,10 +693,8 @@
523 693 */
524 694 public function updated_messages( $messages ) {
525 695 global $post_ID;
526 696
527 - if ( $this->bail() ) return $messages;
528 -
529 697 // URL for the current forum
530 698 $forum_url = bbp_get_forum_permalink( $post_ID );
531 699
532 700 // Current forum's post_date
@@ -532,47 +700,72 @@
532 700 // Current forum's post_date
533 701 $post_date = bbp_get_global_post_field( 'post_date', 'raw' );
534 702
535 703 // Messages array
536 - $messages[$this->post_type] = array(
704 + $messages[ $this->post_type ] = array(
537 705 0 => '', // Left empty on purpose
538 706
539 707 // Updated
540 - 1 => sprintf( __( 'Forum updated. <a href="%s">View forum</a>', 'bbpress' ), $forum_url ),
708 + 1 => sprintf(
709 + '%1$s <a href="%2$s">%3$s</a>',
710 + esc_html__( 'Forum updated.', 'bbpress' ),
711 + $forum_url,
712 + esc_html__( 'View forum', 'bbpress' )
713 + ),
541 714
542 715 // Custom field updated
543 - 2 => __( 'Custom field updated.', 'bbpress' ),
716 + 2 => esc_html__( 'Custom field updated.', 'bbpress' ),
544 717
545 718 // Custom field deleted
546 - 3 => __( 'Custom field deleted.', 'bbpress' ),
719 + 3 => esc_html__( 'Custom field deleted.', 'bbpress' ),
547 720
548 721 // Forum updated
549 - 4 => __( 'Forum updated.', 'bbpress' ),
722 + 4 => esc_html__( 'Forum updated.', 'bbpress' ),
550 723
551 724 // Restored from revision
552 725 // translators: %s: date and time of the revision
553 726 5 => isset( $_GET['revision'] )
554 - ? sprintf( __( 'Forum restored to revision from %s', 'bbpress' ), wp_post_revision_title( (int) $_GET['revision'], false ) )
555 - : false,
727 + ? sprintf( esc_html__( 'Forum restored to revision from %s', 'bbpress' ), wp_post_revision_title( (int) $_GET['revision'], false ) )
728 + : false,
556 729
557 730 // Forum created
558 - 6 => sprintf( __( 'Forum created. <a href="%s">View forum</a>', 'bbpress' ), $forum_url ),
731 + 6 => sprintf(
732 + '%1$s <a href="%2$s">%3$s</a>',
733 + esc_html__( 'Forum created.', 'bbpress' ),
734 + $forum_url,
735 + esc_html__( 'View forum', 'bbpress' )
736 + ),
559 737
560 738 // Forum saved
561 - 7 => __( 'Forum saved.', 'bbpress' ),
739 + 7 => esc_html__( 'Forum saved.', 'bbpress' ),
562 740
563 741 // Forum submitted
564 - 8 => sprintf( __( 'Forum submitted. <a target="_blank" href="%s">Preview forum</a>', 'bbpress' ), esc_url( add_query_arg( 'preview', 'true', $forum_url ) ) ),
742 + 8 => sprintf(
743 + '%1$s <a href="%2$s" target="_blank">%3$s</a>',
744 + esc_html__( 'Forum submitted.', 'bbpress' ),
745 + esc_url( add_query_arg( 'preview', 'true', $forum_url ) ),
746 + esc_html__( 'Preview forum', 'bbpress' )
747 + ),
565 748
566 749 // Forum scheduled
567 - 9 => sprintf( __( 'Forum scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview forum</a>', 'bbpress' ),
750 + 9 => sprintf(
751 + '%1$s <a target="_blank" href="%2$s">%3$s</a>',
752 + sprintf(
753 + esc_html__( 'Forum scheduled for: %s.', 'bbpress' ),
568 754 // translators: Publish box date format, see http://php.net/date
569 - date_i18n( __( 'M j, Y @ G:i', 'bbpress' ),
570 - strtotime( $post_date ) ),
571 - $forum_url ),
755 + '<strong>' . date_i18n( __( 'M j, Y @ G:i', 'bbpress' ), strtotime( $post_date ) ) . '</strong>'
756 + ),
757 + $forum_url,
758 + __( 'Preview forum', 'bbpress' )
759 + ),
572 760
573 761 // Forum draft updated
574 - 10 => sprintf( __( 'Forum draft updated. <a target="_blank" href="%s">Preview forum</a>', 'bbpress' ), esc_url( add_query_arg( 'preview', 'true', $forum_url ) ) ),
762 + 10 => sprintf(
763 + '%1$s <a href="%2$s" target="_blank">%3$s</a>',
764 + esc_html__( 'Forum draft updated.', 'bbpress' ),
765 + esc_url( add_query_arg( 'preview', 'true', $forum_url ) ),
766 + esc_html__( 'Preview forum', 'bbpress' )
767 + ),
575 768 );
576 769
577 770 return $messages;
578 771 }
@@ -584,11 +777,18 @@
584 777 *
585 778 * This is currently here to make hooking and unhooking of the admin UI easy.
586 779 * It could use dependency injection in the future, but for now this is easier.
587 780 *
588 - * @since bbPress (r2596)
781 + * @since 2.0.0 bbPress (r2596)
589 782 *
590 - * @uses BBP_Forums_Admin
783 + * @param WP_Screen $current_screen Current screen object
591 784 */
592 -function bbp_admin_forums() {
593 - bbpress()->admin->forums = new BBP_Forums_Admin();
785 +function bbp_admin_forums( $current_screen ) {
786 +
787 + // Bail if not a forum screen
788 + if ( empty( $current_screen->post_type ) || ( bbp_get_forum_post_type() !== $current_screen->post_type ) ) {
789 + return;
790 + }
791 +
792 + // Init the forums admin
793 + bbp_admin()->forums = new BBP_Forums_Admin();
594 794 }