BBP_Forums_Admin

Loads bbPress forums admin area.

Defined (1)

The class is defined in the following location(s).

/includes/admin/forums.php  
  1. class BBP_Forums_Admin { 
  2.  
  3. /** Variables *************************************************************/ 
  4.  
  5. /** 
  6. * @var The post type of this admin component 
  7. */ 
  8. private $post_type = ''; 
  9.  
  10. /** Functions *************************************************************/ 
  11.  
  12. /** 
  13. * The main bbPress forums admin loader 
  14. * @since bbPress (r2515) 
  15. * @uses BBP_Forums_Admin::setup_globals() Setup the globals needed 
  16. * @uses BBP_Forums_Admin::setup_actions() Setup the hooks and actions 
  17. * @uses BBP_Forums_Admin::setup_help() Setup the help text 
  18. */ 
  19. public function __construct() { 
  20. $this->setup_globals(); 
  21. $this->setup_actions(); 
  22.  
  23. /** 
  24. * Setup the admin hooks, actions and filters 
  25. * @since bbPress (r2646) 
  26. * @access private 
  27. * @uses add_action() To add various actions 
  28. * @uses add_filter() To add various filters 
  29. * @uses bbp_get_forum_post_type() To get the forum post type 
  30. * @uses bbp_get_topic_post_type() To get the topic post type 
  31. * @uses bbp_get_reply_post_type() To get the reply post type 
  32. */ 
  33. private function setup_actions() { 
  34.  
  35. // Add some general styling to the admin area 
  36. add_action( 'bbp_admin_head', array( $this, 'admin_head' ) ); 
  37.  
  38. // Messages 
  39. add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) ); 
  40.  
  41. // Metabox actions 
  42. add_action( 'add_meta_boxes', array( $this, 'attributes_metabox' ) ); 
  43. add_action( 'save_post', array( $this, 'attributes_metabox_save' ) ); 
  44.  
  45. // Column headers. 
  46. add_filter( 'manage_' . $this->post_type . '_posts_columns', array( $this, 'column_headers' ) ); 
  47.  
  48. // Columns (in page row) 
  49. add_action( 'manage_' . $this->post_type . '_posts_custom_column', array( $this, 'column_data' ), 10, 2 ); 
  50. add_filter( 'page_row_actions', array( $this, 'row_actions' ), 10, 2 ); 
  51.  
  52. // Contextual Help 
  53. add_action( 'load-edit.php', array( $this, 'edit_help' ) ); 
  54. add_action( 'load-post.php', array( $this, 'new_help' ) ); 
  55. add_action( 'load-post-new.php', array( $this, 'new_help' ) ); 
  56.  
  57. /** 
  58. * Should we bail out of this method? 
  59. * @since bbPress (r4067) 
  60. * @return boolean 
  61. */ 
  62. private function bail() { 
  63. if ( !isset( get_current_screen()->post_type ) || ( $this->post_type != get_current_screen()->post_type ) ) 
  64. return true; 
  65.  
  66. return false; 
  67.  
  68. /** 
  69. * Admin globals 
  70. * @since bbPress (r2646) 
  71. * @access private 
  72. */ 
  73. private function setup_globals() { 
  74. $this->post_type = bbp_get_forum_post_type(); 
  75.  
  76. /** Contextual Help *******************************************************/ 
  77.  
  78. /** 
  79. * Contextual help for bbPress forum edit page 
  80. * @since bbPress (r3119) 
  81. * @uses get_current_screen() 
  82. */ 
  83. public function edit_help() { 
  84.  
  85. if ( $this->bail() ) return; 
  86.  
  87. // Overview 
  88. get_current_screen()->add_help_tab( array( 
  89. 'id' => 'overview',  
  90. 'title' => __( 'Overview', 'bbpress' ),  
  91. 'content' => 
  92. '<p>' . __( 'This screen displays the individual forums on your site. You can customize the display of this screen to suit your workflow.', 'bbpress' ) . '</p>' 
  93. ) ); 
  94.  
  95. // Screen Content 
  96. get_current_screen()->add_help_tab( array( 
  97. 'id' => 'screen-content',  
  98. 'title' => __( 'Screen Content', 'bbpress' ),  
  99. 'content' => 
  100. '<p>' . __( 'You can customize the display of this screen’s contents in a number of ways:', 'bbpress' ) . '</p>' . 
  101. '<ul>' . 
  102. '<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>' . 
  103. '<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>' . 
  104. '<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>' . 
  105. '</ul>' 
  106. ) ); 
  107.  
  108. // Available Actions 
  109. get_current_screen()->add_help_tab( array( 
  110. 'id' => 'action-links',  
  111. 'title' => __( 'Available Actions', 'bbpress' ),  
  112. 'content' => 
  113. '<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>' . 
  114. '<ul>' . 
  115. '<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>' . 
  116. '<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>' . 
  117. '<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’s status.', 'bbpress' ) . '</li>' . 
  118. '</ul>' 
  119. ) ); 
  120.  
  121. // Bulk Actions 
  122. get_current_screen()->add_help_tab( array( 
  123. 'id' => 'bulk-actions',  
  124. 'title' => __( 'Bulk Actions', 'bbpress' ),  
  125. 'content' => 
  126. '<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>' . 
  127. '<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>' 
  128. ) ); 
  129.  
  130. // Help Sidebar 
  131. get_current_screen()->set_help_sidebar( 
  132. '<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' . 
  133. '<p>' . __( '<a href="http://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' . 
  134. '<p>' . __( '<a href="http://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>' 
  135. ); 
  136.  
  137. /** 
  138. * Contextual help for bbPress forum edit page 
  139. * @since bbPress (r3119) 
  140. * @uses get_current_screen() 
  141. */ 
  142. public function new_help() { 
  143.  
  144. if ( $this->bail() ) return; 
  145.  
  146. $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>'; 
  147.  
  148. get_current_screen()->add_help_tab( array( 
  149. 'id' => 'customize-display',  
  150. 'title' => __( 'Customizing This Display', 'bbpress' ),  
  151. 'content' => $customize_display,  
  152. ) ); 
  153.  
  154. get_current_screen()->add_help_tab( array( 
  155. 'id' => 'title-forum-editor',  
  156. 'title' => __( 'Title and Forum Editor', 'bbpress' ),  
  157. 'content' => 
  158. '<p>' . __( '<strong>Title</strong> - Enter a title for your forum. After you enter a title, you’ll see the permalink below, which you can edit.', 'bbpress' ) . '</p>' . 
  159. '<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>' 
  160. ) ); 
  161.  
  162. $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>'; 
  163.  
  164. if ( current_theme_supports( 'forum-thumbnails' ) && post_type_supports( 'forum', 'thumbnail' ) ) { 
  165. $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>'; 
  166.  
  167. get_current_screen()->add_help_tab( array( 
  168. 'id' => 'forum-attributes',  
  169. 'title' => __( 'Forum Attributes', 'bbpress' ),  
  170. 'content' => 
  171. '<p>' . __( 'Select the attributes that your forum should have:', 'bbpress' ) . '</p>' . 
  172. '<ul>' . 
  173. '<li>' . __( '<strong>Type</strong> indicates if the forum is a category or forum. Categories generally contain other forums.', 'bbpress' ) . '</li>' . 
  174. '<li>' . __( '<strong>Status</strong> allows you to close a forum to new topics and forums.', 'bbpress' ) . '</li>' . 
  175. '<li>' . __( '<strong>Visibility</strong> lets you pick the scope of each forum and what users are allowed to access it.', 'bbpress' ) . '</li>' . 
  176. '<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>' . 
  177. '<li>' . __( '<strong>Order</strong> allows you to order your forums numerically.', 'bbpress' ) . '</li>' . 
  178. '</ul>' 
  179. ) ); 
  180.  
  181. get_current_screen()->add_help_tab( array( 
  182. 'id' => 'publish-box',  
  183. 'title' => __( 'Publish Box', 'bbpress' ),  
  184. 'content' => $publish_box,  
  185. ) ); 
  186.  
  187. get_current_screen()->set_help_sidebar( 
  188. '<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' . 
  189. '<p>' . __( '<a href="http://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' . 
  190. '<p>' . __( '<a href="http://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>' 
  191. ); 
  192.  
  193. /** 
  194. * Add the forum attributes metabox 
  195. * @since bbPress (r2746) 
  196. * @uses bbp_get_forum_post_type() To get the forum post type 
  197. * @uses add_meta_box() To add the metabox 
  198. * @uses do_action() Calls 'bbp_forum_attributes_metabox' 
  199. */ 
  200. public function attributes_metabox() { 
  201.  
  202. if ( $this->bail() ) return; 
  203.  
  204. add_meta_box ( 
  205. 'bbp_forum_attributes',  
  206. __( 'Forum Attributes', 'bbpress' ),  
  207. 'bbp_forum_metabox',  
  208. $this->post_type,  
  209. 'side',  
  210. 'high' 
  211. ); 
  212.  
  213. do_action( 'bbp_forum_attributes_metabox' ); 
  214.  
  215. /** 
  216. * Pass the forum attributes for processing 
  217. * @since bbPress (r2746) 
  218. * @param int $forum_id Forum id 
  219. * @uses current_user_can() To check if the current user is capable of 
  220. * editing the forum 
  221. * @uses bbp_get_forum() To get the forum 
  222. * @uses bbp_is_forum_closed() To check if the forum is closed 
  223. * @uses bbp_is_forum_category() To check if the forum is a category 
  224. * @uses bbp_is_forum_private() To check if the forum is private 
  225. * @uses bbp_close_forum() To close the forum 
  226. * @uses bbp_open_forum() To open the forum 
  227. * @uses bbp_categorize_forum() To make the forum a category 
  228. * @uses bbp_normalize_forum() To make the forum normal (not category) 
  229. * @uses bbp_privatize_forum() To mark the forum as private 
  230. * @uses bbp_publicize_forum() To mark the forum as public 
  231. * @uses do_action() Calls 'bbp_forum_attributes_metabox_save' with the 
  232. * forum id 
  233. * @return int Forum id 
  234. */ 
  235. public function attributes_metabox_save( $forum_id ) { 
  236.  
  237. if ( $this->bail() ) return $forum_id; 
  238.  
  239. // Bail if doing an autosave 
  240. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 
  241. return $forum_id; 
  242.  
  243. // Bail if not a post request 
  244. if ( ! bbp_is_post_request() ) 
  245. return $forum_id; 
  246.  
  247. // Nonce check 
  248. if ( empty( $_POST['bbp_forum_metabox'] ) || !wp_verify_nonce( $_POST['bbp_forum_metabox'], 'bbp_forum_metabox_save' ) ) 
  249. return $forum_id; 
  250.  
  251. // Only save for forum post-types 
  252. if ( ! bbp_is_forum( $forum_id ) ) 
  253. return $forum_id; 
  254.  
  255. // Bail if current user cannot edit this forum 
  256. if ( !current_user_can( 'edit_forum', $forum_id ) ) 
  257. return $forum_id; 
  258.  
  259. // Parent ID 
  260. $parent_id = ( !empty( $_POST['parent_id'] ) && is_numeric( $_POST['parent_id'] ) ) ? (int) $_POST['parent_id'] : 0; 
  261.  
  262. // Update the forum meta bidness 
  263. bbp_update_forum( array( 
  264. 'forum_id' => $forum_id,  
  265. 'post_parent' => (int) $parent_id 
  266. ) ); 
  267.  
  268. do_action( 'bbp_forum_attributes_metabox_save', $forum_id ); 
  269.  
  270. return $forum_id; 
  271.  
  272. /** 
  273. * Add some general styling to the admin area 
  274. * @since bbPress (r2464) 
  275. * @uses bbp_get_forum_post_type() To get the forum post type 
  276. * @uses bbp_get_topic_post_type() To get the topic post type 
  277. * @uses bbp_get_reply_post_type() To get the reply post type 
  278. * @uses sanitize_html_class() To sanitize the classes 
  279. * @uses do_action() Calls 'bbp_admin_head' 
  280. */ 
  281. public function admin_head() { 
  282.  
  283. if ( $this->bail() ) return; 
  284.  
  285. ?> 
  286.  
  287. <style type="text/css" media="screen"> 
  288. /*<![CDATA[*/ 
  289.  
  290. #misc-publishing-actions,  
  291. #save-post { 
  292. display: none; 
  293.  
  294. strong.label { 
  295. display: inline-block; 
  296. width: 60px; 
  297.  
  298. #bbp_forum_attributes hr { 
  299. border-style: solid; 
  300. border-width: 1px; 
  301. border-color: #ccc #fff #fff #ccc; 
  302.  
  303. .column-bbp_forum_topic_count,  
  304. .column-bbp_forum_reply_count,  
  305. .column-bbp_topic_reply_count,  
  306. .column-bbp_topic_voice_count { 
  307. width: 8% !important; 
  308.  
  309. .column-author,  
  310. .column-bbp_reply_author,  
  311. .column-bbp_topic_author { 
  312. width: 10% !important; 
  313.  
  314. .column-bbp_topic_forum,  
  315. .column-bbp_reply_forum,  
  316. .column-bbp_reply_topic { 
  317. width: 10% !important; 
  318.  
  319. .column-bbp_forum_freshness,  
  320. .column-bbp_topic_freshness { 
  321. width: 10% !important; 
  322.  
  323. .column-bbp_forum_created,  
  324. .column-bbp_topic_created,  
  325. .column-bbp_reply_created { 
  326. width: 15% !important; 
  327.  
  328. .status-closed { 
  329. background-color: #eaeaea; 
  330.  
  331. .status-spam { 
  332. background-color: #faeaea; 
  333.  
  334. /*]]>*/ 
  335. </style> 
  336.  
  337. <?php 
  338.  
  339. /** 
  340. * Manage the column headers for the forums page 
  341. * @since bbPress (r2485) 
  342. * @param array $columns The columns 
  343. * @uses apply_filters() Calls 'bbp_admin_forums_column_headers' with 
  344. * the columns 
  345. * @return array $columns bbPress forum columns 
  346. */ 
  347. public function column_headers( $columns ) { 
  348.  
  349. if ( $this->bail() ) return $columns; 
  350.  
  351. $columns = array ( 
  352. 'cb' => '<input type="checkbox" />',  
  353. 'title' => __( 'Forum', 'bbpress' ),  
  354. 'bbp_forum_topic_count' => __( 'Topics', 'bbpress' ),  
  355. 'bbp_forum_reply_count' => __( 'Replies', 'bbpress' ),  
  356. 'author' => __( 'Creator', 'bbpress' ),  
  357. 'bbp_forum_created' => __( 'Created' , 'bbpress' ),  
  358. 'bbp_forum_freshness' => __( 'Freshness', 'bbpress' ) 
  359. ); 
  360.  
  361. return apply_filters( 'bbp_admin_forums_column_headers', $columns ); 
  362.  
  363. /** 
  364. * Print extra columns for the forums page 
  365. * @since bbPress (r2485) 
  366. * @param string $column Column 
  367. * @param int $forum_id Forum id 
  368. * @uses bbp_forum_topic_count() To output the forum topic count 
  369. * @uses bbp_forum_reply_count() To output the forum reply count 
  370. * @uses get_the_date() Get the forum creation date 
  371. * @uses get_the_time() Get the forum creation time 
  372. * @uses esc_attr() To sanitize the forum creation time 
  373. * @uses bbp_get_forum_last_active_time() To get the time when the forum was 
  374. * last active 
  375. * @uses do_action() Calls 'bbp_admin_forums_column_data' with the 
  376. * column and forum id 
  377. */ 
  378. public function column_data( $column, $forum_id ) { 
  379.  
  380. if ( $this->bail() ) return; 
  381.  
  382. switch ( $column ) { 
  383. case 'bbp_forum_topic_count' : 
  384. bbp_forum_topic_count( $forum_id ); 
  385. break; 
  386.  
  387. case 'bbp_forum_reply_count' : 
  388. bbp_forum_reply_count( $forum_id ); 
  389. break; 
  390.  
  391. case 'bbp_forum_created': 
  392. printf( '%1$s <br /> %2$s',  
  393. get_the_date(),  
  394. esc_attr( get_the_time() ) 
  395. ); 
  396.  
  397. break; 
  398.  
  399. case 'bbp_forum_freshness' : 
  400. $last_active = bbp_get_forum_last_active_time( $forum_id, false ); 
  401. if ( !empty( $last_active ) ) 
  402. echo esc_html( $last_active ); 
  403. else 
  404. esc_html_e( 'No Topics', 'bbpress' ); 
  405.  
  406. break; 
  407.  
  408. default: 
  409. do_action( 'bbp_admin_forums_column_data', $column, $forum_id ); 
  410. break; 
  411.  
  412. /** 
  413. * Forum Row actions 
  414. * Remove the quick-edit action link and display the description under 
  415. * the forum title 
  416. * @since bbPress (r2577) 
  417. * @param array $actions Actions 
  418. * @param array $forum Forum object 
  419. * @uses bbp_forum_content() To output forum description 
  420. * @return array $actions Actions 
  421. */ 
  422. public function row_actions( $actions, $forum ) { 
  423.  
  424. if ( $this->bail() ) return $actions; 
  425.  
  426. unset( $actions['inline hide-if-no-js'] ); 
  427.  
  428. // simple hack to show the forum description under the title 
  429. bbp_forum_content( $forum->ID ); 
  430.  
  431. return $actions; 
  432.  
  433. /** 
  434. * Custom user feedback messages for forum post type 
  435. * @since bbPress (r3080) 
  436. * @global int $post_ID 
  437. * @uses bbp_get_forum_permalink() 
  438. * @uses wp_post_revision_title() 
  439. * @uses esc_url() 
  440. * @uses add_query_arg() 
  441. * @param array $messages 
  442. * @return array 
  443. */ 
  444. public function updated_messages( $messages ) { 
  445. global $post_ID; 
  446.  
  447. if ( $this->bail() ) return $messages; 
  448.  
  449. // URL for the current forum 
  450. $forum_url = bbp_get_forum_permalink( $post_ID ); 
  451.  
  452. // Current forum's post_date 
  453. $post_date = bbp_get_global_post_field( 'post_date', 'raw' ); 
  454.  
  455. // Messages array 
  456. $messages[$this->post_type] = array( 
  457. 0 => '', // Left empty on purpose 
  458.  
  459. // Updated 
  460. 1 => sprintf( __( 'Forum updated. <a href="%s">View forum</a>', 'bbpress' ), $forum_url ),  
  461.  
  462. // Custom field updated 
  463. 2 => __( 'Custom field updated.', 'bbpress' ),  
  464.  
  465. // Custom field deleted 
  466. 3 => __( 'Custom field deleted.', 'bbpress' ),  
  467.  
  468. // Forum updated 
  469. 4 => __( 'Forum updated.', 'bbpress' ),  
  470.  
  471. // Restored from revision 
  472. // translators: %s: date and time of the revision 
  473. 5 => isset( $_GET['revision'] ) 
  474. ? sprintf( __( 'Forum restored to revision from %s', 'bbpress' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) 
  475. : false,  
  476.  
  477. // Forum created 
  478. 6 => sprintf( __( 'Forum created. <a href="%s">View forum</a>', 'bbpress' ), $forum_url ),  
  479.  
  480. // Forum saved 
  481. 7 => __( 'Forum saved.', 'bbpress' ),  
  482.  
  483. // Forum submitted 
  484. 8 => sprintf( __( 'Forum submitted. <a target="_blank" href="%s">Preview forum</a>', 'bbpress' ), esc_url( add_query_arg( 'preview', 'true', $forum_url ) ) ),  
  485.  
  486. // Forum scheduled 
  487. 9 => sprintf( __( 'Forum scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview forum</a>', 'bbpress' ),  
  488. // translators: Publish box date format, see http://php.net/date 
  489. date_i18n( __( 'M j, Y @ G:i', 'bbpress' ),  
  490. strtotime( $post_date ) ),  
  491. $forum_url ),  
  492.  
  493. // Forum draft updated 
  494. 10 => sprintf( __( 'Forum draft updated. <a target="_blank" href="%s">Preview forum</a>', 'bbpress' ), esc_url( add_query_arg( 'preview', 'true', $forum_url ) ) ),  
  495. ); 
  496.  
  497. return $messages;