PluginProbe
bbPress / 2.1.3
bbPress v2.1.3
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 / bbp-admin / bbp-forums.php

bbp-forums.php in bbPress 2.1.3, at bbp-admin/bbp-forums.php

595 lines 22.0 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 if ( !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 bbPress (r2464)
20 */
21 class BBP_Forums_Admin {
22
23 /** Variables *************************************************************/
24
25 /**
26 * @var The post type of this admin component
27 */
28 private $post_type = '';
29
30 /** Functions *************************************************************/
31
32 /**
33 * The main bbPress forums admin loader
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
40 */
41 public function __construct() {
42 $this->setup_globals();
43 $this->setup_actions();
44 }
45
46 /**
47 * Setup the admin hooks, actions and filters
48 *
49 * @since bbPress (r2646)
50 * @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 */
58 private function setup_actions() {
59
60 // Add some general styling to the admin area
61 add_action( 'bbp_admin_head', array( $this, 'admin_head' ) );
62
63 // Messages
64 add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) );
65
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.
71 add_filter( 'manage_' . $this->post_type . '_posts_columns', array( $this, 'column_headers' ) );
72
73 // Columns (in page row)
74 add_action( 'manage_' . $this->post_type . '_posts_custom_column', array( $this, 'column_data' ), 10, 2 );
75 add_filter( 'page_row_actions', array( $this, 'row_actions' ), 10, 2 );
76
77 // Contextual Help
78 add_action( 'load-edit.php', array( $this, 'edit_help' ) );
79 add_action( 'load-post-new.php', array( $this, 'new_help' ) );
80 }
81
82 /**
83 * Should we bail out of this method?
84 *
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
97 *
98 * @since bbPress (r2646)
99 * @access private
100 */
101 private function setup_globals() {
102 $this->post_type = bbp_get_forum_post_type();
103 }
104
105 /** Contextual Help *******************************************************/
106
107 /**
108 * Contextual help for bbPress forum edit page
109 *
110 * @since bbPress (r3119)
111 * @uses get_current_screen()
112 */
113 public function edit_help() {
114
115 if ( $this->bail() ) return;
116
117 // Overview
118 get_current_screen()->add_help_tab( array(
119 'id' => 'overview',
120 'title' => __( 'Overview', 'bbpress' ),
121 'content' =>
122 '<p>' . __( 'This screen displays the individual forums on your site. You can customize the display of this screen to suit your workflow.', 'bbpress' ) . '</p>'
123 ) );
124
125 // Screen Content
126 get_current_screen()->add_help_tab( array(
127 'id' => 'screen-content',
128 'title' => __( 'Screen Content', 'bbpress' ),
129 'content' =>
130 '<p>' . __( 'You can customize the display of this screen&#8217;s contents in a number of ways:', 'bbpress' ) . '</p>' .
131 '<ul>' .
132 '<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>' .
133 '<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>' .
134 '<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>' .
135 '</ul>'
136 ) );
137
138 // Available Actions
139 get_current_screen()->add_help_tab( array(
140 'id' => 'action-links',
141 'title' => __( 'Available Actions', 'bbpress' ),
142 'content' =>
143 '<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 '<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>' .
148 '</ul>'
149 ) );
150
151 // Bulk Actions
152 get_current_screen()->add_help_tab( array(
153 'id' => 'bulk-actions',
154 'title' => __( 'Bulk Actions', 'bbpress' ),
155 'content' =>
156 '<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>' .
157 '<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>'
158 ) );
159
160 // Help Sidebar
161 get_current_screen()->set_help_sidebar(
162 '<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>'
165 );
166 }
167
168 /**
169 * Contextual help for bbPress forum edit page
170 *
171 * @since bbPress (r3119)
172 * @uses get_current_screen()
173 */
174 public function new_help() {
175
176 if ( $this->bail() ) return;
177
178 $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
180 get_current_screen()->add_help_tab( array(
181 'id' => 'customize-display',
182 'title' => __( 'Customizing This Display', 'bbpress' ),
183 'content' => $customize_display,
184 ) );
185
186 get_current_screen()->add_help_tab( array(
187 'id' => 'title-forum-editor',
188 'title' => __( 'Title and Forum Editor', 'bbpress' ),
189 'content' =>
190 '<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>' .
191 '<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>'
192 ) );
193
194 $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
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' ) ) {
201 $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 }
203
204 get_current_screen()->add_help_tab( array(
205 'id' => 'forum-attributes',
206 'title' => __( 'Forum Attributes', 'bbpress' ),
207 'content' =>
208 '<p>' . __( 'Select the attributes that your forum should have:', 'bbpress' ) . '</p>' .
209 '<ul>' .
210 '<li>' . __( '<strong>Type</strong> indicates if the forum is a category or forum. Categories generally contain other forums.', 'bbpress' ) . '</li>' .
211 '<li>' . __( '<strong>Status</strong> allows you to close a forum to new topics and forums.', 'bbpress' ) . '</li>' .
212 '<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>' .
214 '<li>' . __( '<strong>Order</strong> allows you to order your forums numerically.', 'bbpress' ) . '</li>' .
215 '</ul>'
216 ) );
217
218 get_current_screen()->add_help_tab( array(
219 'id' => 'publish-box',
220 'title' => __( 'Publish Box', 'bbpress' ),
221 'content' => $publish_box,
222 ) );
223
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 get_current_screen()->set_help_sidebar(
233 '<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>'
236 );
237 }
238
239 /**
240 * Add the forum attributes metabox
241 *
242 * @since bbPress (r2746)
243 *
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'
247 */
248 public function attributes_metabox() {
249
250 if ( $this->bail() ) return;
251
252 add_meta_box (
253 'bbp_forum_attributes',
254 __( 'Forum Attributes', 'bbpress' ),
255 'bbp_forum_metabox',
256 $this->post_type,
257 'side',
258 'high'
259 );
260
261 do_action( 'bbp_forum_attributes_metabox' );
262 }
263
264 /**
265 * Pass the forum attributes for processing
266 *
267 * @since bbPress (r2746)
268 *
269 * @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 * @return int Forum id
285 */
286 public function attributes_metabox_save( $forum_id ) {
287
288 if ( $this->bail() ) return $forum_id;
289
290 // Bail if doing an autosave
291 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
292 return $forum_id;
293
294 // Bail if not a post request
295 if ( 'POST' != strtoupper( $_SERVER['REQUEST_METHOD'] ) )
296 return $forum_id;
297
298 // Nonce check
299 if ( empty( $_POST['bbp_forum_metabox'] ) || !wp_verify_nonce( $_POST['bbp_forum_metabox'], 'bbp_forum_metabox_save' ) )
300 return $forum_id;
301
302 // Only save for forum post-types
303 if ( ! bbp_is_forum( $forum_id ) )
304 return $forum_id;
305
306 // Bail if current user cannot edit this forum
307 if ( !current_user_can( 'edit_forum', $forum_id ) )
308 return $forum_id;
309
310 // Parent ID
311 $parent_id = ( !empty( $_POST['parent_id'] ) && is_numeric( $_POST['parent_id'] ) ) ? (int) $_POST['parent_id'] : 0;
312
313 // Update the forum meta bidness
314 bbp_update_forum( array(
315 'forum_id' => $forum_id,
316 'post_parent' => (int) $parent_id
317 ) );
318
319 do_action( 'bbp_forum_attributes_metabox_save', $forum_id );
320
321 return $forum_id;
322 }
323
324 /**
325 * Add some general styling to the admin area
326 *
327 * @since bbPress (r2464)
328 *
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'
334 */
335 public function admin_head() {
336
337 if ( $this->bail() ) return;
338
339 ?>
340
341 <style type="text/css" media="screen">
342 /*<![CDATA[*/
343
344 #misc-publishing-actions,
345 #save-post {
346 display: none;
347 }
348
349 strong.label {
350 display: inline-block;
351 width: 60px;
352 }
353
354 #bbp_forum_attributes hr {
355 border-style: solid;
356 border-width: 1px;
357 border-color: #ccc #fff #fff #ccc;
358 }
359
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 }
366
367 .column-author,
368 .column-bbp_reply_author,
369 .column-bbp_topic_author {
370 width: 10% !important;
371 }
372
373 .column-bbp_topic_forum,
374 .column-bbp_reply_forum,
375 .column-bbp_reply_topic {
376 width: 10% !important;
377 }
378
379 .column-bbp_forum_freshness,
380 .column-bbp_topic_freshness {
381 width: 10% !important;
382 }
383
384 .column-bbp_forum_created,
385 .column-bbp_topic_created,
386 .column-bbp_reply_created {
387 width: 15% !important;
388 }
389
390 .status-closed {
391 background-color: #eaeaea;
392 }
393
394 .status-spam {
395 background-color: #faeaea;
396 }
397
398 /*]]>*/
399 </style>
400
401 <?php
402 }
403
404 /**
405 * Manage the column headers for the forums page
406 *
407 * @since bbPress (r2485)
408 *
409 * @param array $columns The columns
410 * @uses apply_filters() Calls 'bbp_admin_forums_column_headers' with
411 * the columns
412 * @return array $columns bbPress forum columns
413 */
414 public function column_headers( $columns ) {
415
416 if ( $this->bail() ) return $columns;
417
418 $columns = array (
419 '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' )
426 );
427
428 return apply_filters( 'bbp_admin_forums_column_headers', $columns );
429 }
430
431 /**
432 * Print extra columns for the forums page
433 *
434 * @since bbPress (r2485)
435 *
436 * @param string $column Column
437 * @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 */
448 public function column_data( $column, $forum_id ) {
449
450 if ( $this->bail() ) return;
451
452 switch ( $column ) {
453 case 'bbp_forum_topic_count' :
454 bbp_forum_topic_count( $forum_id );
455 break;
456
457 case 'bbp_forum_reply_count' :
458 bbp_forum_reply_count( $forum_id );
459 break;
460
461 case 'bbp_forum_created':
462 printf( __( '%1$s <br /> %2$s', 'bbpress' ),
463 get_the_date(),
464 esc_attr( get_the_time() )
465 );
466
467 break;
468
469 case 'bbp_forum_freshness' :
470 $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' );
475
476 break;
477
478 default:
479 do_action( 'bbp_admin_forums_column_data', $column, $forum_id );
480 break;
481 }
482 }
483
484 /**
485 * Forum Row actions
486 *
487 * Remove the quick-edit action link and display the description under
488 * the forum title
489 *
490 * @since bbPress (r2577)
491 *
492 * @param array $actions Actions
493 * @param array $forum Forum object
494 * @uses the_content() To output forum description
495 * @return array $actions Actions
496 */
497 public function row_actions( $actions, $forum ) {
498
499 if ( $this->bail() ) return $actions;
500
501 unset( $actions['inline hide-if-no-js'] );
502
503 // simple hack to show the forum description under the title
504 bbp_forum_content( $forum->ID );
505
506 return $actions;
507 }
508
509 /**
510 * Custom user feedback messages for forum post type
511 *
512 * @since bbPress (r3080)
513 *
514 * @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 *
520 * @param array $messages
521 *
522 * @return array
523 */
524 public function updated_messages( $messages ) {
525 global $post_ID;
526
527 if ( $this->bail() ) return $messages;
528
529 // URL for the current forum
530 $forum_url = bbp_get_forum_permalink( $post_ID );
531
532 // Current forum's post_date
533 $post_date = bbp_get_global_post_field( 'post_date', 'raw' );
534
535 // Messages array
536 $messages[$this->post_type] = array(
537 0 => '', // Left empty on purpose
538
539 // Updated
540 1 => sprintf( __( 'Forum updated. <a href="%s">View forum</a>', 'bbpress' ), $forum_url ),
541
542 // Custom field updated
543 2 => __( 'Custom field updated.', 'bbpress' ),
544
545 // Custom field deleted
546 3 => __( 'Custom field deleted.', 'bbpress' ),
547
548 // Forum updated
549 4 => __( 'Forum updated.', 'bbpress' ),
550
551 // Restored from revision
552 // translators: %s: date and time of the revision
553 5 => isset( $_GET['revision'] )
554 ? sprintf( __( 'Forum restored to revision from %s', 'bbpress' ), wp_post_revision_title( (int) $_GET['revision'], false ) )
555 : false,
556
557 // Forum created
558 6 => sprintf( __( 'Forum created. <a href="%s">View forum</a>', 'bbpress' ), $forum_url ),
559
560 // Forum saved
561 7 => __( 'Forum saved.', 'bbpress' ),
562
563 // 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 ) ) ),
565
566 // Forum scheduled
567 9 => sprintf( __( 'Forum scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview forum</a>', 'bbpress' ),
568 // 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 ),
572
573 // 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 ) ) ),
575 );
576
577 return $messages;
578 }
579 }
580 endif; // class_exists check
581
582 /**
583 * Setup bbPress Forums Admin
584 *
585 * This is currently here to make hooking and unhooking of the admin UI easy.
586 * It could use dependency injection in the future, but for now this is easier.
587 *
588 * @since bbPress (r2596)
589 *
590 * @uses BBP_Forums_Admin
591 */
592 function bbp_admin_forums() {
593 bbpress()->admin->forums = new BBP_Forums_Admin();
594 }
595