BBP_Replies_Admin

Loads bbPress replies admin area.

Defined (1)

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

/includes/admin/replies.php  
  1. class BBP_Replies_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 admin loader 
  14. * @since bbPress (r2515) 
  15. * @uses BBP_Replies_Admin::setup_globals() Setup the globals needed 
  16. * @uses BBP_Replies_Admin::setup_actions() Setup the hooks and actions 
  17. * @uses BBP_Replies_Admin::setup_actions() 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. // Reply column headers. 
  42. add_filter( 'manage_' . $this->post_type . '_posts_columns', array( $this, 'column_headers' ) ); 
  43.  
  44. // Reply columns (in post row) 
  45. add_action( 'manage_' . $this->post_type . '_posts_custom_column', array( $this, 'column_data' ), 10, 2 ); 
  46. add_filter( 'post_row_actions', array( $this, 'row_actions' ), 10, 2 ); 
  47.  
  48. // Reply metabox actions 
  49. add_action( 'add_meta_boxes', array( $this, 'attributes_metabox' ) ); 
  50. add_action( 'save_post', array( $this, 'attributes_metabox_save' ) ); 
  51.  
  52. // Check if there are any bbp_toggle_reply_* requests on admin_init, also have a message displayed 
  53. add_action( 'load-edit.php', array( $this, 'toggle_reply' ) ); 
  54. add_action( 'admin_notices', array( $this, 'toggle_reply_notice' ) ); 
  55.  
  56. // Anonymous metabox actions 
  57. add_action( 'add_meta_boxes', array( $this, 'author_metabox' ) ); 
  58.  
  59. // Add ability to filter topics and replies per forum 
  60. add_filter( 'restrict_manage_posts', array( $this, 'filter_dropdown' ) ); 
  61. add_filter( 'bbp_request', array( $this, 'filter_post_rows' ) ); 
  62.  
  63. // Contextual Help 
  64. add_action( 'load-edit.php', array( $this, 'edit_help' ) ); 
  65. add_action( 'load-post.php', array( $this, 'new_help' ) ); 
  66. add_action( 'load-post-new.php', array( $this, 'new_help' ) ); 
  67.  
  68. /** 
  69. * Should we bail out of this method? 
  70. * @since bbPress (r4067) 
  71. * @return boolean 
  72. */ 
  73. private function bail() { 
  74. if ( !isset( get_current_screen()->post_type ) || ( $this->post_type !== get_current_screen()->post_type ) ) 
  75. return true; 
  76.  
  77. return false; 
  78.  
  79. /** 
  80. * Admin globals 
  81. * @since bbPress (r2646) 
  82. * @access private 
  83. */ 
  84. private function setup_globals() { 
  85. $this->post_type = bbp_get_reply_post_type(); 
  86.  
  87. /** Contextual Help *******************************************************/ 
  88.  
  89. /** 
  90. * Contextual help for bbPress reply edit page 
  91. * @since bbPress (r3119) 
  92. * @uses get_current_screen() 
  93. */ 
  94. public function edit_help() { 
  95.  
  96. if ( $this->bail() ) return; 
  97.  
  98. // Overview 
  99. get_current_screen()->add_help_tab( array( 
  100. 'id' => 'overview',  
  101. 'title' => __( 'Overview', 'bbpress' ),  
  102. 'content' => 
  103. '<p>' . __( 'This screen provides access to all of your replies. You can customize the display of this screen to suit your workflow.', 'bbpress' ) . '</p>' 
  104. ) ); 
  105.  
  106. // Screen Content 
  107. get_current_screen()->add_help_tab( array( 
  108. 'id' => 'screen-content',  
  109. 'title' => __( 'Screen Content', 'bbpress' ),  
  110. 'content' => 
  111. '<p>' . __( 'You can customize the display of this screen’s contents in a number of ways:', 'bbpress' ) . '</p>' . 
  112. '<ul>' . 
  113. '<li>' . __( 'You can hide/display columns based on your needs and decide how many replies to list per screen using the Screen Options tab.', 'bbpress' ) . '</li>' . 
  114. '<li>' . __( 'You can filter the list of replies by reply status using the text links in the upper left to show All, Published, Draft, or Trashed replies. The default view is to show all replies.', 'bbpress' ) . '</li>' . 
  115. '<li>' . __( 'You can view replies in a simple title list or with an excerpt. Choose the view you prefer by clicking on the icons at the top of the list on the right.', 'bbpress' ) . '</li>' . 
  116. '<li>' . __( 'You can refine the list to show only replies in a specific category or from a specific month by using the dropdown menus above the replies list. Click the Filter button after making your selection. You also can refine the list by clicking on the reply author, category or tag in the replies list.', 'bbpress' ) . '</li>' . 
  117. '</ul>' 
  118. ) ); 
  119.  
  120. // Available Actions 
  121. get_current_screen()->add_help_tab( array( 
  122. 'id' => 'action-links',  
  123. 'title' => __( 'Available Actions', 'bbpress' ),  
  124. 'content' => 
  125. '<p>' . __( 'Hovering over a row in the replies list will display action links that allow you to manage your reply. You can perform the following actions:', 'bbpress' ) . '</p>' . 
  126. '<ul>' . 
  127. '<li>' . __( '<strong>Edit</strong> takes you to the editing screen for that reply. You can also reach that screen by clicking on the reply title.', 'bbpress' ) . '</li>' . 
  128. //'<li>' . __( '<strong>Quick Edit</strong> provides inline access to the metadata of your reply, allowing you to update reply details without leaving this screen.', 'bbpress' ) . '</li>' . 
  129. '<li>' . __( '<strong>Trash</strong> removes your reply from this list and places it in the trash, from which you can permanently delete it.', 'bbpress' ) . '</li>' . 
  130. '<li>' . __( '<strong>Spam</strong> removes your reply from this list and places it in the spam queue, from which you can permanently delete it.', 'bbpress' ) . '</li>' . 
  131. '<li>' . __( '<strong>Preview</strong> will show you what your draft reply will look like if you publish it. View will take you to your live site to view the reply. Which link is available depends on your reply’s status.', 'bbpress' ) . '</li>' . 
  132. '</ul>' 
  133. ) ); 
  134.  
  135. // Bulk Actions 
  136. get_current_screen()->add_help_tab( array( 
  137. 'id' => 'bulk-actions',  
  138. 'title' => __( 'Bulk Actions', 'bbpress' ),  
  139. 'content' => 
  140. '<p>' . __( 'You can also edit or move multiple replies to the trash at once. Select the replies 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>' . 
  141. '<p>' . __( 'When using Bulk Edit, you can change the metadata (categories, author, etc.) for all selected replies at once. To remove a reply from the grouping, just click the x next to its name in the Bulk Edit area that appears.', 'bbpress' ) . '</p>' 
  142. ) ); 
  143.  
  144. // Help Sidebar 
  145. get_current_screen()->set_help_sidebar( 
  146. '<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' . 
  147. '<p>' . __( '<a href="http://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' . 
  148. '<p>' . __( '<a href="http://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>' 
  149. ); 
  150.  
  151. /** 
  152. * Contextual help for bbPress reply edit page 
  153. * @since bbPress (r3119) 
  154. * @uses get_current_screen() 
  155. */ 
  156. public function new_help() { 
  157.  
  158. if ( $this->bail() ) return; 
  159.  
  160. $customize_display = '<p>' . __( 'The title field and the big reply 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>'; 
  161.  
  162. get_current_screen()->add_help_tab( array( 
  163. 'id' => 'customize-display',  
  164. 'title' => __( 'Customizing This Display', 'bbpress' ),  
  165. 'content' => $customize_display,  
  166. ) ); 
  167.  
  168. get_current_screen()->add_help_tab( array( 
  169. 'id' => 'title-reply-editor',  
  170. 'title' => __( 'Title and Reply Editor', 'bbpress' ),  
  171. 'content' => 
  172. '<p>' . __( '<strong>Title</strong> - Enter a title for your reply. After you enter a title, you’ll see the permalink below, which you can edit.', 'bbpress' ) . '</p>' . 
  173. '<p>' . __( '<strong>Reply Editor</strong> - Enter the text for your reply. 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 reply text. You can insert media files by clicking the icons above the reply 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 reply editor.', 'bbpress' ) . '</p>' 
  174. ) ); 
  175.  
  176. $publish_box = '<p>' . __( '<strong>Publish</strong> - You can set the terms of publishing your reply 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 reply 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 reply to be published in the future or backdate a reply.', 'bbpress' ) . '</p>'; 
  177.  
  178. if ( current_theme_supports( 'reply-thumbnails' ) && post_type_supports( 'reply', 'thumbnail' ) ) { 
  179. $publish_box .= '<p>' . __( '<strong>Featured Image</strong> - This allows you to associate an image with your reply without inserting it. This is usually useful only if your theme makes use of the featured image as a reply thumbnail on the home page, a custom header, etc.', 'bbpress' ) . '</p>'; 
  180.  
  181. get_current_screen()->add_help_tab( array( 
  182. 'id' => 'reply-attributes',  
  183. 'title' => __( 'Reply Attributes', 'bbpress' ),  
  184. 'content' => 
  185. '<p>' . __( 'Select the attributes that your reply should have:', 'bbpress' ) . '</p>' . 
  186. '<ul>' . 
  187. '<li>' . __( '<strong>Forum</strong> dropdown determines the parent forum that the reply belongs to. Select the forum, or leave the default (Use Forum of Topic) to post the reply in forum of the topic.', 'bbpress' ) . '</li>' . 
  188. '<li>' . __( '<strong>Topic</strong> determines the parent topic that the reply belongs to.', 'bbpress' ) . '</li>' . 
  189. '<li>' . __( '<strong>Reply To</strong> determines the threading of the reply.', 'bbpress' ) . '</li>' . 
  190. '</ul>' 
  191. ) ); 
  192.  
  193. get_current_screen()->add_help_tab( array( 
  194. 'id' => 'publish-box',  
  195. 'title' => __( 'Publish Box', 'bbpress' ),  
  196. 'content' => $publish_box,  
  197. ) ); 
  198.  
  199. get_current_screen()->set_help_sidebar( 
  200. '<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' . 
  201. '<p>' . __( '<a href="http://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' . 
  202. '<p>' . __( '<a href="http://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>' 
  203. ); 
  204.  
  205. /** 
  206. * Add the reply attributes metabox 
  207. * @since bbPress (r2746) 
  208. * @uses bbp_get_reply_post_type() To get the reply post type 
  209. * @uses add_meta_box() To add the metabox 
  210. * @uses do_action() Calls 'bbp_reply_attributes_metabox' 
  211. */ 
  212. public function attributes_metabox() { 
  213.  
  214. if ( $this->bail() ) return; 
  215.  
  216. add_meta_box ( 
  217. 'bbp_reply_attributes',  
  218. __( 'Reply Attributes', 'bbpress' ),  
  219. 'bbp_reply_metabox',  
  220. $this->post_type,  
  221. 'side',  
  222. 'high' 
  223. ); 
  224.  
  225. do_action( 'bbp_reply_attributes_metabox' ); 
  226.  
  227. /** 
  228. * Pass the reply attributes for processing 
  229. * @since bbPress (r2746) 
  230. * @param int $reply_id Reply id 
  231. * @uses current_user_can() To check if the current user is capable of 
  232. * editing the reply 
  233. * @uses do_action() Calls 'bbp_reply_attributes_metabox_save' with the 
  234. * reply id and parent id 
  235. * @return int Parent id 
  236. */ 
  237. public function attributes_metabox_save( $reply_id ) { 
  238.  
  239. if ( $this->bail() ) return $reply_id; 
  240.  
  241. // Bail if doing an autosave 
  242. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 
  243. return $reply_id; 
  244.  
  245. // Bail if not a post request 
  246. if ( ! bbp_is_post_request() ) 
  247. return $reply_id; 
  248.  
  249. // Check action exists 
  250. if ( empty( $_POST['action'] ) ) 
  251. return $reply_id; 
  252.  
  253. // Nonce check 
  254. if ( empty( $_POST['bbp_reply_metabox'] ) || !wp_verify_nonce( $_POST['bbp_reply_metabox'], 'bbp_reply_metabox_save' ) ) 
  255. return $reply_id; 
  256.  
  257. // Current user cannot edit this reply 
  258. if ( !current_user_can( 'edit_reply', $reply_id ) ) 
  259. return $reply_id; 
  260.  
  261. // Get the reply meta post values 
  262. $topic_id = !empty( $_POST['parent_id'] ) ? (int) $_POST['parent_id'] : 0; 
  263. $forum_id = !empty( $_POST['bbp_forum_id'] ) ? (int) $_POST['bbp_forum_id'] : bbp_get_topic_forum_id( $topic_id ); 
  264. $reply_to = !empty( $_POST['bbp_reply_to'] ) ? (int) $_POST['bbp_reply_to'] : 0; 
  265.  
  266. // Get reply author data 
  267. $anonymous_data = bbp_filter_anonymous_post_data(); 
  268. $author_id = bbp_get_reply_author_id( $reply_id ); 
  269. $is_edit = (bool) isset( $_POST['save'] ); 
  270.  
  271. // Formally update the reply 
  272. bbp_update_reply( $reply_id, $topic_id, $forum_id, $anonymous_data, $author_id, $is_edit, $reply_to ); 
  273.  
  274. // Allow other fun things to happen 
  275. do_action( 'bbp_reply_attributes_metabox_save', $reply_id, $topic_id, $forum_id, $reply_to ); 
  276. do_action( 'bbp_author_metabox_save', $reply_id, $anonymous_data ); 
  277.  
  278. return $reply_id; 
  279.  
  280. /** 
  281. * Add the author info metabox 
  282. * Allows editing of information about an author 
  283. * @since bbPress (r2828) 
  284. * @uses bbp_get_topic() To get the topic 
  285. * @uses bbp_get_reply() To get the reply 
  286. * @uses bbp_get_topic_post_type() To get the topic post type 
  287. * @uses bbp_get_reply_post_type() To get the reply post type 
  288. * @uses add_meta_box() To add the metabox 
  289. * @uses do_action() Calls 'bbp_author_metabox' with the topic/reply 
  290. * id 
  291. */ 
  292. public function author_metabox() { 
  293.  
  294. if ( $this->bail() ) return; 
  295.  
  296. // Bail if post_type is not a reply 
  297. if ( empty( $_GET['action'] ) || ( 'edit' !== $_GET['action'] ) ) 
  298. return; 
  299.  
  300. // Add the metabox 
  301. add_meta_box( 
  302. 'bbp_author_metabox',  
  303. __( 'Author Information', 'bbpress' ),  
  304. 'bbp_author_metabox',  
  305. $this->post_type,  
  306. 'side',  
  307. 'high' 
  308. ); 
  309.  
  310. do_action( 'bbp_author_metabox', get_the_ID() ); 
  311.  
  312. /** 
  313. * Add some general styling to the admin area 
  314. * @since bbPress (r2464) 
  315. * @uses bbp_get_forum_post_type() To get the forum post type 
  316. * @uses bbp_get_topic_post_type() To get the topic post type 
  317. * @uses bbp_get_reply_post_type() To get the reply post type 
  318. * @uses sanitize_html_class() To sanitize the classes 
  319. * @uses do_action() Calls 'bbp_admin_head' 
  320. */ 
  321. public function admin_head() { 
  322.  
  323. if ( $this->bail() ) return; 
  324.  
  325. ?> 
  326.  
  327. <style type="text/css" media="screen"> 
  328. /*<![CDATA[*/ 
  329.  
  330. strong.label { 
  331. display: inline-block; 
  332. width: 60px; 
  333.  
  334. .column-bbp_forum_topic_count,  
  335. .column-bbp_forum_reply_count,  
  336. .column-bbp_topic_reply_count,  
  337. .column-bbp_topic_voice_count { 
  338. width: 8% !important; 
  339.  
  340. .column-author,  
  341. .column-bbp_reply_author,  
  342. .column-bbp_topic_author { 
  343. width: 10% !important; 
  344.  
  345. .column-bbp_topic_forum,  
  346. .column-bbp_reply_forum,  
  347. .column-bbp_reply_topic { 
  348. width: 10% !important; 
  349.  
  350. .column-bbp_forum_freshness,  
  351. .column-bbp_topic_freshness { 
  352. width: 10% !important; 
  353.  
  354. .column-bbp_forum_created,  
  355. .column-bbp_topic_created,  
  356. .column-bbp_reply_created { 
  357. width: 15% !important; 
  358.  
  359. .status-closed { 
  360. background-color: #eaeaea; 
  361.  
  362. .status-spam { 
  363. background-color: #faeaea; 
  364.  
  365. /*]]>*/ 
  366. </style> 
  367.  
  368. <?php 
  369.  
  370. /** 
  371. * Toggle reply 
  372. * Handles the admin-side spamming/unspamming of replies 
  373. * @since bbPress (r2740) 
  374. * @uses bbp_get_reply() To get the reply 
  375. * @uses current_user_can() To check if the user is capable of editing 
  376. * the reply 
  377. * @uses wp_die() To die if the user isn't capable or the post wasn't 
  378. * found 
  379. * @uses check_admin_referer() To verify the nonce and check referer 
  380. * @uses bbp_is_reply_spam() To check if the reply is marked as spam 
  381. * @uses bbp_unspam_reply() To unmark the reply as spam 
  382. * @uses bbp_spam_reply() To mark the reply as spam 
  383. * @uses do_action() Calls 'bbp_toggle_reply_admin' with success, post 
  384. * data, action and message 
  385. * @uses add_query_arg() To add custom args to the url 
  386. * @uses wp_safe_redirect() Redirect the page to custom url 
  387. */ 
  388. public function toggle_reply() { 
  389.  
  390. if ( $this->bail() ) return; 
  391.  
  392. // Only proceed if GET is a reply toggle action 
  393. if ( bbp_is_get_request() && !empty( $_GET['action'] ) && in_array( $_GET['action'], array( 'bbp_toggle_reply_spam' ) ) && !empty( $_GET['reply_id'] ) ) { 
  394. $action = $_GET['action']; // What action is taking place? 
  395. $reply_id = (int) $_GET['reply_id']; // What's the reply id? 
  396. $success = false; // Flag 
  397. $post_data = array( 'ID' => $reply_id ); // Prelim array 
  398.  
  399. // Get reply and die if empty 
  400. $reply = bbp_get_reply( $reply_id ); 
  401. if ( empty( $reply ) ) // Which reply? 
  402. wp_die( __( 'The reply was not found!', 'bbpress' ) ); 
  403.  
  404. if ( !current_user_can( 'moderate', $reply->ID ) ) // What is the user doing here? 
  405. wp_die( __( 'You do not have the permission to do that!', 'bbpress' ) ); 
  406.  
  407. switch ( $action ) { 
  408. case 'bbp_toggle_reply_spam' : 
  409. check_admin_referer( 'spam-reply_' . $reply_id ); 
  410.  
  411. $is_spam = bbp_is_reply_spam( $reply_id ); 
  412. $message = $is_spam ? 'unspammed' : 'spammed'; 
  413. $success = $is_spam ? bbp_unspam_reply( $reply_id ) : bbp_spam_reply( $reply_id ); 
  414.  
  415. break; 
  416.  
  417. $success = wp_update_post( $post_data ); 
  418. $message = array( 'bbp_reply_toggle_notice' => $message, 'reply_id' => $reply->ID ); 
  419.  
  420. if ( false === $success || is_wp_error( $success ) ) 
  421. $message['failed'] = '1'; 
  422.  
  423. // Do additional reply toggle actions (admin side) 
  424. do_action( 'bbp_toggle_reply_admin', $success, $post_data, $action, $message ); 
  425.  
  426. // Redirect back to the reply 
  427. $redirect = add_query_arg( $message, remove_query_arg( array( 'action', 'reply_id' ) ) ); 
  428. wp_safe_redirect( $redirect ); 
  429.  
  430. // For good measure 
  431. exit(); 
  432.  
  433. /** 
  434. * Toggle reply notices 
  435. * Display the success/error notices from 
  436. * {@link BBP_Admin::toggle_reply()} 
  437. * @since bbPress (r2740) 
  438. * @uses bbp_get_reply() To get the reply 
  439. * @uses bbp_get_reply_title() To get the reply title of the reply 
  440. * @uses esc_html() To sanitize the reply title 
  441. * @uses apply_filters() Calls 'bbp_toggle_reply_notice_admin' with 
  442. * message, reply id, notice and is it a failure 
  443. */ 
  444. public function toggle_reply_notice() { 
  445.  
  446. if ( $this->bail() ) return; 
  447.  
  448. // Only proceed if GET is a reply toggle action 
  449. if ( bbp_is_get_request() && !empty( $_GET['bbp_reply_toggle_notice'] ) && in_array( $_GET['bbp_reply_toggle_notice'], array( 'spammed', 'unspammed' ) ) && !empty( $_GET['reply_id'] ) ) { 
  450. $notice = $_GET['bbp_reply_toggle_notice']; // Which notice? 
  451. $reply_id = (int) $_GET['reply_id']; // What's the reply id? 
  452. $is_failure = !empty( $_GET['failed'] ) ? true : false; // Was that a failure? 
  453.  
  454. // Empty? No reply? 
  455. if ( empty( $notice ) || empty( $reply_id ) ) 
  456. return; 
  457.  
  458. // Get reply and bail if empty 
  459. $reply = bbp_get_reply( $reply_id ); 
  460. if ( empty( $reply ) ) 
  461. return; 
  462.  
  463. $reply_title = bbp_get_reply_title( $reply->ID ); 
  464.  
  465. switch ( $notice ) { 
  466. case 'spammed' : 
  467. $message = $is_failure === true ? sprintf( __( 'There was a problem marking the reply "%1$s" as spam.', 'bbpress' ), $reply_title ) : sprintf( __( 'Reply "%1$s" successfully marked as spam.', 'bbpress' ), $reply_title ); 
  468. break; 
  469.  
  470. case 'unspammed' : 
  471. $message = $is_failure === true ? sprintf( __( 'There was a problem unmarking the reply "%1$s" as spam.', 'bbpress' ), $reply_title ) : sprintf( __( 'Reply "%1$s" successfully unmarked as spam.', 'bbpress' ), $reply_title ); 
  472. break; 
  473.  
  474. // Do additional reply toggle notice filters (admin side) 
  475. $message = apply_filters( 'bbp_toggle_reply_notice_admin', $message, $reply->ID, $notice, $is_failure ); 
  476.  
  477. ?> 
  478.  
  479. <div id="message" class="<?php echo $is_failure === true ? 'error' : 'updated'; ?> fade"> 
  480. <p style="line-height: 150%"><?php echo esc_html( $message ); ?></p> 
  481. </div> 
  482.  
  483. <?php 
  484.  
  485. /** 
  486. * Manage the column headers for the replies page 
  487. * @since bbPress (r2577) 
  488. * @param array $columns The columns 
  489. * @uses apply_filters() Calls 'bbp_admin_replies_column_headers' with 
  490. * the columns 
  491. * @return array $columns bbPress reply columns 
  492. */ 
  493. public function column_headers( $columns ) { 
  494.  
  495. if ( $this->bail() ) return $columns; 
  496.  
  497. $columns = array( 
  498. 'cb' => '<input type="checkbox" />',  
  499. 'title' => __( 'Title', 'bbpress' ),  
  500. 'bbp_reply_forum' => __( 'Forum', 'bbpress' ),  
  501. 'bbp_reply_topic' => __( 'Topic', 'bbpress' ),  
  502. 'bbp_reply_author' => __( 'Author', 'bbpress' ),  
  503. 'bbp_reply_created' => __( 'Created', 'bbpress' ),  
  504. ); 
  505.  
  506. return apply_filters( 'bbp_admin_replies_column_headers', $columns ); 
  507.  
  508. /** 
  509. * Print extra columns for the replies page 
  510. * @since bbPress (r2577) 
  511. * @param string $column Column 
  512. * @param int $reply_id reply id 
  513. * @uses bbp_get_reply_topic_id() To get the topic id of the reply 
  514. * @uses bbp_topic_title() To output the reply's topic title 
  515. * @uses apply_filters() Calls 'reply_topic_row_actions' with an array 
  516. * of reply topic actions 
  517. * @uses bbp_get_topic_permalink() To get the topic permalink 
  518. * @uses bbp_get_topic_forum_id() To get the forum id of the topic of 
  519. * the reply 
  520. * @uses bbp_get_forum_permalink() To get the forum permalink 
  521. * @uses admin_url() To get the admin url of post.php 
  522. * @uses apply_filters() Calls 'reply_topic_forum_row_actions' with an 
  523. * array of reply topic forum actions 
  524. * @uses bbp_reply_author_display_name() To output the reply author name 
  525. * @uses get_the_date() Get the reply creation date 
  526. * @uses get_the_time() Get the reply creation time 
  527. * @uses esc_attr() To sanitize the reply creation time 
  528. * @uses bbp_get_reply_last_active_time() To get the time when the reply was 
  529. * last active 
  530. * @uses do_action() Calls 'bbp_admin_replies_column_data' with the 
  531. * column and reply id 
  532. */ 
  533. public function column_data( $column, $reply_id ) { 
  534.  
  535. if ( $this->bail() ) return; 
  536.  
  537. // Get topic ID 
  538. $topic_id = bbp_get_reply_topic_id( $reply_id ); 
  539.  
  540. // Populate Column Data 
  541. switch ( $column ) { 
  542.  
  543. // Topic 
  544. case 'bbp_reply_topic' : 
  545.  
  546. // Output forum name 
  547. if ( !empty( $topic_id ) ) { 
  548.  
  549. // Topic Title 
  550. $topic_title = bbp_get_topic_title( $topic_id ); 
  551. if ( empty( $topic_title ) ) { 
  552. $topic_title = esc_html__( 'No Topic', 'bbpress' ); 
  553.  
  554. // Output the title 
  555. echo $topic_title; 
  556.  
  557. // Reply has no topic 
  558. } else { 
  559. esc_html_e( 'No Topic', 'bbpress' ); 
  560.  
  561. break; 
  562.  
  563. // Forum 
  564. case 'bbp_reply_forum' : 
  565.  
  566. // Get Forum ID's 
  567. $reply_forum_id = bbp_get_reply_forum_id( $reply_id ); 
  568. $topic_forum_id = bbp_get_topic_forum_id( $topic_id ); 
  569.  
  570. // Output forum name 
  571. if ( !empty( $reply_forum_id ) ) { 
  572.  
  573. // Forum Title 
  574. $forum_title = bbp_get_forum_title( $reply_forum_id ); 
  575. if ( empty( $forum_title ) ) { 
  576. $forum_title = esc_html__( 'No Forum', 'bbpress' ); 
  577.  
  578. // Alert capable users of reply forum mismatch 
  579. if ( $reply_forum_id !== $topic_forum_id ) { 
  580. if ( current_user_can( 'edit_others_replies' ) || current_user_can( 'moderate' ) ) { 
  581. $forum_title .= '<div class="attention">' . esc_html__( '(Mismatch)', 'bbpress' ) . '</div>'; 
  582.  
  583. // Output the title 
  584. echo $forum_title; 
  585.  
  586. // Reply has no forum 
  587. } else { 
  588. _e( 'No Forum', 'bbpress' ); 
  589.  
  590. break; 
  591.  
  592. // Author 
  593. case 'bbp_reply_author' : 
  594. bbp_reply_author_display_name ( $reply_id ); 
  595. break; 
  596.  
  597. // Freshness 
  598. case 'bbp_reply_created': 
  599.  
  600. // Output last activity time and date 
  601. printf( '%1$s <br /> %2$s',  
  602. get_the_date(),  
  603. esc_attr( get_the_time() ) 
  604. ); 
  605.  
  606. break; 
  607.  
  608. // Do action for anything else 
  609. default : 
  610. do_action( 'bbp_admin_replies_column_data', $column, $reply_id ); 
  611. break; 
  612.  
  613. /** 
  614. * Reply Row actions 
  615. * Remove the quick-edit action link under the reply title and add the 
  616. * content and spam link 
  617. * @since bbPress (r2577) 
  618. * @param array $actions Actions 
  619. * @param array $reply Reply object 
  620. * @uses bbp_get_reply_post_type() To get the reply post type 
  621. * @uses bbp_reply_content() To output reply content 
  622. * @uses bbp_get_reply_permalink() To get the reply link 
  623. * @uses bbp_get_reply_title() To get the reply title 
  624. * @uses current_user_can() To check if the current user can edit or 
  625. * delete the reply 
  626. * @uses bbp_is_reply_spam() To check if the reply is marked as spam 
  627. * @uses get_post_type_object() To get the reply post type object 
  628. * @uses add_query_arg() To add custom args to the url 
  629. * @uses remove_query_arg() To remove custom args from the url 
  630. * @uses wp_nonce_url() To nonce the url 
  631. * @uses get_delete_post_link() To get the delete post link of the reply 
  632. * @return array $actions Actions 
  633. */ 
  634. public function row_actions( $actions, $reply ) { 
  635.  
  636. if ( $this->bail() ) return $actions; 
  637.  
  638. unset( $actions['inline hide-if-no-js'] ); 
  639.  
  640. // Reply view links to topic 
  641. $actions['view'] = '<a href="' . esc_url( bbp_get_reply_url( $reply->ID ) ) . '" title="' . esc_attr( sprintf( __( 'View “%s”', 'bbpress' ), bbp_get_reply_title( $reply->ID ) ) ) . '" rel="permalink">' . esc_html__( 'View', 'bbpress' ) . '</a>'; 
  642.  
  643. // User cannot view replies in trash 
  644. if ( ( bbp_get_trash_status_id() === $reply->post_status ) && !current_user_can( 'view_trash' ) ) 
  645. unset( $actions['view'] ); 
  646.  
  647. // Only show the actions if the user is capable of viewing them 
  648. if ( current_user_can( 'moderate', $reply->ID ) ) { 
  649. if ( in_array( $reply->post_status, array( bbp_get_public_status_id(), bbp_get_spam_status_id() ) ) ) { 
  650. $spam_uri = wp_nonce_url( add_query_arg( array( 'reply_id' => $reply->ID, 'action' => 'bbp_toggle_reply_spam' ), remove_query_arg( array( 'bbp_reply_toggle_notice', 'reply_id', 'failed', 'super' ) ) ), 'spam-reply_' . $reply->ID ); 
  651. if ( bbp_is_reply_spam( $reply->ID ) ) { 
  652. $actions['spam'] = '<a href="' . esc_url( $spam_uri ) . '" title="' . esc_attr__( 'Mark the reply as not spam', 'bbpress' ) . '">' . esc_html__( 'Not spam', 'bbpress' ) . '</a>'; 
  653. } else { 
  654. $actions['spam'] = '<a href="' . esc_url( $spam_uri ) . '" title="' . esc_attr__( 'Mark this reply as spam', 'bbpress' ) . '">' . esc_html__( 'Spam', 'bbpress' ) . '</a>'; 
  655.  
  656. // Trash 
  657. if ( current_user_can( 'delete_reply', $reply->ID ) ) { 
  658. if ( bbp_get_trash_status_id() === $reply->post_status ) { 
  659. $post_type_object = get_post_type_object( bbp_get_reply_post_type() ); 
  660. $actions['untrash'] = "<a title='" . esc_attr__( 'Restore this item from the Trash', 'bbpress' ) . "' href='" . esc_url( add_query_arg( array( '_wp_http_referer' => add_query_arg( array( 'post_type' => bbp_get_reply_post_type() ), admin_url( 'edit.php' ) ) ), wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&action=untrash', $reply->ID ) ), 'untrash-' . $reply->post_type . '_' . $reply->ID ) ) ) . "'>" . esc_html__( 'Restore', 'bbpress' ) . "</a>"; 
  661. } elseif ( EMPTY_TRASH_DAYS ) { 
  662. $actions['trash'] = "<a class='submitdelete' title='" . esc_attr__( 'Move this item to the Trash', 'bbpress' ) . "' href='" . esc_url( add_query_arg( array( '_wp_http_referer' => add_query_arg( array( 'post_type' => bbp_get_reply_post_type() ), admin_url( 'edit.php' ) ) ), get_delete_post_link( $reply->ID ) ) ) . "'>" . esc_html__( 'Trash', 'bbpress' ) . "</a>"; 
  663.  
  664. if ( bbp_get_trash_status_id() === $reply->post_status || !EMPTY_TRASH_DAYS ) { 
  665. $actions['delete'] = "<a class='submitdelete' title='" . esc_attr__( 'Delete this item permanently', 'bbpress' ) . "' href='" . esc_url( add_query_arg( array( '_wp_http_referer' => add_query_arg( array( 'post_type' => bbp_get_reply_post_type() ), admin_url( 'edit.php' ) ) ), get_delete_post_link( $reply->ID, '', true ) ) ) . "'>" . esc_html__( 'Delete Permanently', 'bbpress' ) . "</a>"; 
  666. } elseif ( bbp_get_spam_status_id() === $reply->post_status ) { 
  667. unset( $actions['trash'] ); 
  668.  
  669. return $actions; 
  670.  
  671. /** 
  672. * Add forum dropdown to topic and reply list table filters 
  673. * @since bbPress (r2991) 
  674. * @uses bbp_get_reply_post_type() To get the reply post type 
  675. * @uses bbp_get_topic_post_type() To get the topic post type 
  676. * @uses bbp_dropdown() To generate a forum dropdown 
  677. * @return bool False. If post type is not topic or reply 
  678. */ 
  679. public function filter_dropdown() { 
  680.  
  681. if ( $this->bail() ) return; 
  682.  
  683. // Add Empty Spam button 
  684. if ( !empty( $_GET['post_status'] ) && ( bbp_get_spam_status_id() === $_GET['post_status'] ) && current_user_can( 'moderate' ) ) { 
  685. wp_nonce_field( 'bulk-destroy', '_destroy_nonce' ); 
  686. $title = esc_attr__( 'Empty Spam', 'bbpress' ); 
  687. submit_button( $title, 'button-secondary apply', 'delete_all', false ); 
  688.  
  689. // Get which forum is selected 
  690. $selected = !empty( $_GET['bbp_forum_id'] ) ? $_GET['bbp_forum_id'] : ''; 
  691.  
  692. // Show the forums dropdown 
  693. bbp_dropdown( array( 
  694. 'selected' => $selected,  
  695. 'show_none' => __( 'In all forums', 'bbpress' ) 
  696. ) ); 
  697.  
  698. /** 
  699. * Adjust the request query and include the forum id 
  700. * @since bbPress (r2991) 
  701. * @param array $query_vars Query variables from {@link WP_Query} 
  702. * @uses is_admin() To check if it's the admin section 
  703. * @uses bbp_get_topic_post_type() To get the topic post type 
  704. * @uses bbp_get_reply_post_type() To get the reply post type 
  705. * @return array Processed Query Vars 
  706. */ 
  707. public function filter_post_rows( $query_vars ) { 
  708.  
  709. if ( $this->bail() ) return $query_vars; 
  710.  
  711. // Add post_parent query_var if one is present 
  712. if ( !empty( $_GET['bbp_forum_id'] ) ) { 
  713. $query_vars['meta_key'] = '_bbp_forum_id'; 
  714. $query_vars['meta_value'] = $_GET['bbp_forum_id']; 
  715.  
  716. // Return manipulated query_vars 
  717. return $query_vars; 
  718.  
  719. /** 
  720. * Custom user feedback messages for reply post type 
  721. * @since bbPress (r3080) 
  722. * @global int $post_ID 
  723. * @uses bbp_get_topic_permalink() 
  724. * @uses wp_post_revision_title() 
  725. * @uses esc_url() 
  726. * @uses add_query_arg() 
  727. * @param array $messages 
  728. * @return array 
  729. */ 
  730. public function updated_messages( $messages ) { 
  731. global $post_ID; 
  732.  
  733. if ( $this->bail() ) return $messages; 
  734.  
  735. // URL for the current topic 
  736. $topic_url = bbp_get_topic_permalink( bbp_get_reply_topic_id( $post_ID ) ); 
  737.  
  738. // Current reply's post_date 
  739. $post_date = bbp_get_global_post_field( 'post_date', 'raw' ); 
  740.  
  741. // Messages array 
  742. $messages[$this->post_type] = array( 
  743. 0 => '', // Left empty on purpose 
  744.  
  745. // Updated 
  746. 1 => sprintf( __( 'Reply updated. <a href="%s">View topic</a>', 'bbpress' ), $topic_url ),  
  747.  
  748. // Custom field updated 
  749. 2 => __( 'Custom field updated.', 'bbpress' ),  
  750.  
  751. // Custom field deleted 
  752. 3 => __( 'Custom field deleted.', 'bbpress' ),  
  753.  
  754. // Reply updated 
  755. 4 => __( 'Reply updated.', 'bbpress' ),  
  756.  
  757. // Restored from revision 
  758. // translators: %s: date and time of the revision 
  759. 5 => isset( $_GET['revision'] ) 
  760. ? sprintf( __( 'Reply restored to revision from %s', 'bbpress' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) 
  761. : false,  
  762.  
  763. // Reply created 
  764. 6 => sprintf( __( 'Reply created. <a href="%s">View topic</a>', 'bbpress' ), $topic_url ),  
  765.  
  766. // Reply saved 
  767. 7 => __( 'Reply saved.', 'bbpress' ),  
  768.  
  769. // Reply submitted 
  770. 8 => sprintf( __( 'Reply submitted. <a target="_blank" href="%s">Preview topic</a>', 'bbpress' ), esc_url( add_query_arg( 'preview', 'true', $topic_url ) ) ),  
  771.  
  772. // Reply scheduled 
  773. 9 => sprintf( __( 'Reply scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview topic</a>', 'bbpress' ),  
  774. // translators: Publish box date format, see http://php.net/date 
  775. date_i18n( __( 'M j, Y @ G:i', 'bbpress' ),  
  776. strtotime( $post_date ) ),  
  777. $topic_url ),  
  778.  
  779. // Reply draft updated 
  780. 10 => sprintf( __( 'Reply draft updated. <a target="_blank" href="%s">Preview topic</a>', 'bbpress' ), esc_url( add_query_arg( 'preview', 'true', $topic_url ) ) ),  
  781. ); 
  782.  
  783. return $messages;