PluginProbe
bbPress / 2.6.17
bbPress v2.6.17
2.6.17 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 All 72 releases
← All changes | includes/admin/replies.php +700 -531 2.2.12.6.17 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_Replies_Admin' ) ) :
13 +if ( ! class_exists( 'BBP_Replies_Admin' ) ) :
14 14 /**
15 15 * Loads bbPress replies 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_Replies_Admin {
22 22
23 23 /** Variables *************************************************************/
@@ -31,13 +31,9 @@
31 31
32 32 /**
33 33 * The main bbPress admin loader
34 34 *
35 - * @since bbPress (r2515)
36 - *
37 - * @uses BBP_Replies_Admin::setup_globals() Setup the globals needed
38 - * @uses BBP_Replies_Admin::setup_actions() Setup the hooks and actions
39 - * @uses BBP_Replies_Admin::setup_actions() 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,70 +41,60 @@
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 + * @since 2.6.0 bbPress (r6101) Added bulk actions
47 + *
50 48 * @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 49 */
58 50 private function setup_actions() {
59 51
60 - // Add some general styling to the admin area
61 - add_action( 'bbp_admin_head', array( $this, 'admin_head' ) );
62 -
63 52 // Messages
64 53 add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) );
65 54
55 + // Reply bulk actions, added in WordPress 4.7, see #WP16031
56 + if ( bbp_get_major_wp_version() >= 4.7 ) {
57 + add_filter( 'bulk_actions-edit-reply', array( $this, 'bulk_actions' ) );
58 + add_filter( 'handle_bulk_actions-edit-reply', array( $this, 'handle_bulk_actions' ), 10, 3 );
59 + add_filter( 'bulk_post_updated_messages', array( $this, 'bulk_post_updated_messages' ), 10, 2 );
60 + }
61 +
66 62 // Reply column headers.
67 - add_filter( 'manage_' . $this->post_type . '_posts_columns', array( $this, 'replies_column_headers' ) );
63 + add_filter( 'manage_' . $this->post_type . '_posts_columns', array( $this, 'column_headers' ) );
68 64
69 65 // Reply columns (in post row)
70 - add_action( 'manage_' . $this->post_type . '_posts_custom_column', array( $this, 'replies_column_data' ), 10, 2 );
71 - add_filter( 'post_row_actions', array( $this, 'replies_row_actions' ), 10, 2 );
66 + add_action( 'manage_' . $this->post_type . '_posts_custom_column', array( $this, 'column_data' ), 10, 2 );
67 + add_filter( 'post_row_actions', array( $this, 'row_actions' ), 10, 2 );
72 68
73 - // Reply metabox actions
74 - add_action( 'add_meta_boxes', array( $this, 'reply_attributes_metabox' ) );
75 - add_action( 'save_post', array( $this, 'reply_attributes_metabox_save' ) );
69 + // Reply meta-box actions
70 + add_action( 'add_meta_boxes', array( $this, 'attributes_metabox' ) );
71 + add_action( 'add_meta_boxes', array( $this, 'author_metabox' ) );
72 + add_action( 'add_meta_boxes', array( $this, 'comments_metabox' ) );
73 + add_action( 'save_post', array( $this, 'save_meta_boxes' ) );
76 74
77 75 // Check if there are any bbp_toggle_reply_* requests on admin_init, also have a message displayed
78 - add_action( 'load-edit.php', array( $this, 'toggle_reply' ) );
79 - add_action( 'admin_notices', array( $this, 'toggle_reply_notice' ) );
76 + add_action( 'load-edit.php', array( $this, 'toggle_reply' ) );
77 + add_action( 'load-edit.php', array( $this, 'toggle_reply_notice' ) );
80 78
81 - // Anonymous metabox actions
82 - add_action( 'add_meta_boxes', array( $this, 'author_metabox' ) );
83 - add_action( 'save_post', array( $this, 'author_metabox_save' ) );
84 -
85 79 // Add ability to filter topics and replies per forum
86 80 add_filter( 'restrict_manage_posts', array( $this, 'filter_dropdown' ) );
87 81 add_filter( 'bbp_request', array( $this, 'filter_post_rows' ) );
88 82
83 + // Empty spam
84 + add_filter( 'manage_posts_extra_tablenav', array( $this, 'filter_empty_spam' ) );
85 +
89 86 // Contextual Help
90 87 add_action( 'load-edit.php', array( $this, 'edit_help' ) );
88 + add_action( 'load-post.php', array( $this, 'new_help' ) );
91 89 add_action( 'load-post-new.php', array( $this, 'new_help' ) );
92 90 }
93 91
94 92 /**
95 - * Should we bail out of this method?
93 + * Admin globals
96 94 *
97 - * @since bbPress (r4067)
98 - * @return boolean
99 - */
100 - private function bail() {
101 - if ( !isset( get_current_screen()->post_type ) || ( $this->post_type != get_current_screen()->post_type ) )
102 - return true;
103 -
104 - return false;
105 - }
106 -
107 - /**
108 - * Admin globals
95 + * @since 2.0.0 bbPress (r2646)
109 96 *
110 - * @since bbPress (r2646)
111 97 * @access private
112 98 */
113 99 private function setup_globals() {
114 100 $this->post_type = bbp_get_reply_post_type();
@@ -118,66 +104,72 @@
118 104
119 105 /**
120 106 * Contextual help for bbPress reply edit page
121 107 *
122 - * @since bbPress (r3119)
123 - * @uses get_current_screen()
108 + * @since 2.0.0 bbPress (r3119)
124 109 */
125 110 public function edit_help() {
126 111
127 - if ( $this->bail() ) return;
128 -
129 112 // Overview
130 - get_current_screen()->add_help_tab( array(
131 - 'id' => 'overview',
132 - 'title' => __( 'Overview', 'bbpress' ),
133 - 'content' =>
134 - '<p>' . __( 'This screen provides access to all of your replies. You can customize the display of this screen to suit your workflow.', 'bbpress' ) . '</p>'
135 - ) );
113 + get_current_screen()->add_help_tab(
114 + array(
115 + 'id' => 'overview',
116 + 'title' => __( 'Overview', 'bbpress' ),
117 + 'content' =>
118 + '<p>' . __( 'This screen provides access to all of your replies. You can customize the display of this screen to suit your workflow.', 'bbpress' ) . '</p>'
119 + )
120 + );
136 121
137 122 // Screen Content
138 - get_current_screen()->add_help_tab( array(
139 - 'id' => 'screen-content',
140 - 'title' => __( 'Screen Content', 'bbpress' ),
141 - 'content' =>
142 - '<p>' . __( 'You can customize the display of this screen&#8217;s contents in a number of ways:', 'bbpress' ) . '</p>' .
143 - '<ul>' .
144 - '<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>' .
145 - '<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>' .
146 - '<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>' .
147 - '<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>' .
148 - '</ul>'
149 - ) );
123 + get_current_screen()->add_help_tab(
124 + array(
125 + 'id' => 'screen-content',
126 + 'title' => __( 'Screen Content', 'bbpress' ),
127 + 'content' =>
128 + '<p>' . __( 'You can customize the display of this screen&#8217;s contents in a number of ways:', 'bbpress' ) . '</p>' .
129 + '<ul>' .
130 + '<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>' .
131 + '<li>' . __( 'You can filter the list of replies by reply status using the text links in the upper left to show All, Published, Draft, Pending, Trashed, or Spam replies. The default view is to show all replies.', 'bbpress' ) . '</li>' .
132 + '<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>' .
133 + '<li>' . __( 'You can refine the list to show only replies in a specific forum or from a specific month by using the dropdown menus above the replies list. Click the Filter button after making your selection.', 'bbpress' ) . '</li>' .
134 + '</ul>'
135 + )
136 + );
150 137
151 138 // Available Actions
152 - get_current_screen()->add_help_tab( array(
153 - 'id' => 'action-links',
154 - 'title' => __( 'Available Actions', 'bbpress' ),
155 - 'content' =>
156 - '<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>' .
157 - '<ul>' .
158 - '<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>' .
159 - //'<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>' .
160 - '<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>' .
161 - '<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>' .
162 - '<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&#8217;s status.', 'bbpress' ) . '</li>' .
163 - '</ul>'
164 - ) );
139 + get_current_screen()->add_help_tab(
140 + array(
141 + 'id' => 'action-links',
142 + 'title' => __( 'Available Actions', 'bbpress' ),
143 + 'content' =>
144 + '<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>' .
145 + '<ul>' .
146 + '<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>' .
147 + //'<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>' .
148 + '<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>' .
149 + '<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>' .
150 + '<li>' . __( '<strong>View</strong> will take you to your live site to view the reply.', 'bbpress' ) . '</li>' .
151 + '<li>' . __( '<strong>Approve</strong> will change the status from pending to publish.', 'bbpress' ) . '</li>' .
152 + '</ul>'
153 + )
154 + );
165 155
166 156 // Bulk Actions
167 - get_current_screen()->add_help_tab( array(
168 - 'id' => 'bulk-actions',
169 - 'title' => __( 'Bulk Actions', 'bbpress' ),
170 - 'content' =>
171 - '<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>' .
172 - '<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>'
173 - ) );
157 + get_current_screen()->add_help_tab(
158 + array(
159 + 'id' => 'bulk-actions',
160 + 'title' => __( 'Bulk Actions', 'bbpress' ),
161 + 'content' =>
162 + '<p>' . __( 'You can also edit, spam, 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>' .
163 + '<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>'
164 + )
165 + );
174 166
175 167 // Help Sidebar
176 168 get_current_screen()->set_help_sidebar(
177 169 '<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' .
178 - '<p>' . __( '<a href="http://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' .
179 - '<p>' . __( '<a href="http://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>'
170 + '<p>' . __( '<a href="https://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' .
171 + '<p>' . __( '<a href="https://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>'
180 172 );
181 173 }
182 174
183 175 /**
@@ -182,449 +174,549 @@
182 174
183 175 /**
184 176 * Contextual help for bbPress reply edit page
185 177 *
186 - * @since bbPress (r3119)
187 - * @uses get_current_screen()
178 + * @since 2.0.0 bbPress (r3119)
188 179 */
189 180 public function new_help() {
190 181
191 - if ( $this->bail() ) return;
192 -
193 182 $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>';
194 183
195 - get_current_screen()->add_help_tab( array(
196 - 'id' => 'customize-display',
197 - 'title' => __( 'Customizing This Display', 'bbpress' ),
198 - 'content' => $customize_display,
199 - ) );
184 + get_current_screen()->add_help_tab(
185 + array(
186 + 'id' => 'customize-display',
187 + 'title' => __( 'Customizing This Display', 'bbpress' ),
188 + 'content' => $customize_display,
189 + )
190 + );
200 191
201 - get_current_screen()->add_help_tab( array(
202 - 'id' => 'title-reply-editor',
203 - 'title' => __( 'Title and Reply Editor', 'bbpress' ),
204 - 'content' =>
205 - '<p>' . __( '<strong>Title</strong> - Enter a title for your reply. After you enter a title, you&#8217;ll see the permalink below, which you can edit.', 'bbpress' ) . '</p>' .
206 - '<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>'
207 - ) );
192 + get_current_screen()->add_help_tab(
193 + array(
194 + 'id' => 'title-reply-editor',
195 + 'title' => __( 'Title and Reply Editor', 'bbpress' ),
196 + 'content' =>
197 + '<p>' . __( '<strong>Title</strong> - Enter a title for your reply. After you enter a title, you&#8217;ll see the permalink below, which you can edit.', 'bbpress' ) . '</p>' .
198 + '<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>'
199 + )
200 + );
208 201
209 202 $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>';
210 203
211 - if ( current_theme_supports( 'reply-formats' ) && reply_type_supports( 'reply', 'reply-formats' ) ) {
212 - $publish_box .= '<p>' . __( '<strong>reply Format</strong> - This designates how your theme will display a specific reply. For example, you could have a <em>standard</em> blog reply 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 reply format</a>. Your theme could enable all or some of 10 possible formats.', 'bbpress' ) . '</p>';
213 - }
214 -
215 - if ( current_theme_supports( 'reply-thumbnails' ) && reply_type_supports( 'reply', 'thumbnail' ) ) {
204 + if ( current_theme_supports( 'reply-thumbnails' ) && post_type_supports( bbp_get_reply_post_type(), 'thumbnail' ) ) {
216 205 $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>';
217 206 }
218 207
219 - get_current_screen()->add_help_tab( array(
220 - 'id' => 'reply-attributes',
221 - 'title' => __( 'Reply Attributes', 'bbpress' ),
222 - 'content' =>
223 - '<p>' . __( 'Select the attributes that your reply should have:', 'bbpress' ) . '</p>' .
224 - '<ul>' .
225 - '<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>' .
226 - '<li>' . __( '<strong>Topic</strong> determines the parent topic that the reply belongs to.', 'bbpress' ) . '</li>' .
227 - '</ul>'
228 - ) );
208 + get_current_screen()->add_help_tab(
209 + array(
210 + 'id' => 'reply-attributes',
211 + 'title' => __( 'Reply Attributes', 'bbpress' ),
212 + 'content' =>
213 + '<p>' . __( 'Select the attributes that your reply should have:', 'bbpress' ) . '</p>' .
214 + '<ul>' .
215 + '<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>' .
216 + '<li>' . __( '<strong>Topic</strong> determines the parent topic that the reply belongs to.', 'bbpress' ) . '</li>' .
217 + '<li>' . __( '<strong>Reply To</strong> determines the threading of the reply.', 'bbpress' ) . '</li>' .
218 + '</ul>'
219 + )
220 + );
229 221
230 - get_current_screen()->add_help_tab( array(
231 - 'id' => 'publish-box',
232 - 'title' => __( 'Publish Box', 'bbpress' ),
233 - 'content' => $publish_box,
234 - ) );
222 + get_current_screen()->add_help_tab(
223 + array(
224 + 'id' => 'publish-box',
225 + 'title' => __( 'Publish Box', 'bbpress' ),
226 + 'content' => $publish_box,
227 + )
228 + );
235 229
236 - get_current_screen()->add_help_tab( array(
237 - 'id' => 'discussion-settings',
238 - 'title' => __( 'Discussion Settings', 'bbpress' ),
239 - 'content' =>
240 - '<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>' .
241 - '<p>' . __( '<strong>Discussion</strong> - You can turn comments and pings on or off, and if there are comments on the reply, you can see them here and moderate them.', 'bbpress' ) . '</p>'
242 - ) );
243 -
244 230 get_current_screen()->set_help_sidebar(
245 231 '<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' .
246 - '<p>' . __( '<a href="http://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' .
247 - '<p>' . __( '<a href="http://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>'
232 + '<p>' . __( '<a href="https://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' .
233 + '<p>' . __( '<a href="https://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>'
248 234 );
249 235 }
250 236
251 237 /**
252 - * Add the reply attributes metabox
238 + * Add spam/unspam bulk actions to the bulk action dropdown.
253 239 *
254 - * @since bbPress (r2746)
240 + * @since 2.6.0 bbPress (r6101)
255 241 *
256 - * @uses bbp_get_reply_post_type() To get the reply post type
257 - * @uses add_meta_box() To add the metabox
258 - * @uses do_action() Calls 'bbp_reply_attributes_metabox'
242 + * @param array $actions The list of bulk actions.
243 + * @return array The filtered list of bulk actions.
259 244 */
260 - public function reply_attributes_metabox() {
245 + public function bulk_actions( $actions ) {
261 246
262 - if ( $this->bail() ) return;
247 + if ( current_user_can( 'moderate' ) ) {
248 + if ( bbp_get_spam_status_id() === get_query_var( 'post_status' ) ) {
249 + $actions['unspam'] = esc_html__( 'Unspam', 'bbpress' );
250 + } else {
251 + $actions['spam'] = esc_html__( 'Spam', 'bbpress' );
252 + }
253 + }
263 254
264 - add_meta_box (
265 - 'bbp_reply_attributes',
266 - __( 'Reply Attributes', 'bbpress' ),
267 - 'bbp_reply_metabox',
268 - $this->post_type,
269 - 'side',
270 - 'high'
271 - );
255 + return $actions;
256 + }
272 257
273 - do_action( 'bbp_reply_attributes_metabox' );
258 + /**
259 + * Add custom bulk action updated messages for replies.
260 + *
261 + * @since 2.6.0 bbPress (r6101)
262 + *
263 + * @param array $bulk_messages Arrays of messages, each keyed by the corresponding post type.
264 + * @param array $bulk_counts Array of item counts for each message, used to build internationalized strings.
265 + */
266 + public function bulk_post_updated_messages( $bulk_messages, $bulk_counts ) {
267 + /* translators: %s: Number of replies */
268 + $bulk_messages['reply']['updated'] = _n( '%s reply updated.', '%s replies updated.', $bulk_counts['updated'], 'bbpress');
269 + $bulk_messages['reply']['locked'] = ( 1 === $bulk_counts['locked'] )
270 + ? __( '1 reply not updated, somebody is editing it.', 'bbpress' )
271 + /* translators: %s: Number of replies */
272 + : _n( '%s reply not updated, somebody is editing it.', '%s replies not updated, somebody is editing them.', $bulk_counts['locked'], 'bbpress' );
273 +
274 + return $bulk_messages;
274 275 }
275 276
276 277 /**
277 - * Pass the reply attributes for processing
278 + * Handle spam/unspam bulk actions.
278 279 *
279 - * @since bbPress (r2746)
280 + * @since 2.6.0 bbPress (r6101)
280 281 *
281 - * @param int $reply_id Reply id
282 - * @uses current_user_can() To check if the current user is capable of
283 - * editing the reply
284 - * @uses do_action() Calls 'bbp_reply_attributes_metabox_save' with the
285 - * reply id and parent id
286 - * @return int Parent id
282 + * @param string $sendback The sendback URL.
283 + * @param string $doaction The action to be taken.
284 + * @param array $post_ids The post IDS to take the action on.
285 + * @return string The sendback URL.
287 286 */
288 - public function reply_attributes_metabox_save( $reply_id ) {
287 + public function handle_bulk_actions( $sendback, $doaction, $post_ids ) {
289 288
290 - if ( $this->bail() ) return $reply_id;
289 + $sendback = remove_query_arg( array( 'spam', 'unspam' ), $sendback );
290 + $updated = $locked = 0;
291 291
292 - // Bail if doing an autosave
293 - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
294 - return $reply_id;
292 + if ( 'spam' === $doaction ) {
295 293
296 - // Bail if not a post request
297 - if ( 'POST' != strtoupper( $_SERVER['REQUEST_METHOD'] ) )
298 - return $reply_id;
294 + foreach ( (array) $post_ids as $post_id ) {
295 + if ( ! current_user_can( 'moderate', $post_id ) ) {
296 + wp_die( esc_html__( 'Sorry, you are not allowed to spam this item.', 'bbpress' ) );
297 + }
299 298
300 - // Check action exists
301 - if ( empty( $_POST['action'] ) )
302 - return $reply_id;
299 + if ( wp_check_post_lock( $post_id ) ) {
300 + $locked++;
301 + continue;
302 + }
303 303
304 - // Nonce check
305 - if ( empty( $_POST['bbp_reply_metabox'] ) || !wp_verify_nonce( $_POST['bbp_reply_metabox'], 'bbp_reply_metabox_save' ) )
306 - return $reply_id;
304 + if ( ! bbp_spam_reply( $post_id ) ) {
305 + wp_die( esc_html__( 'Error in spamming reply.', 'bbpress' ) );
306 + }
307 307
308 - // Current user cannot edit this reply
309 - if ( !current_user_can( 'edit_reply', $reply_id ) )
310 - return $reply_id;
308 + ++$updated;
309 + }
311 310
312 - // Get the reply meta post values
313 - $topic_id = !empty( $_POST['parent_id'] ) ? (int) $_POST['parent_id'] : 0;
314 - $forum_id = !empty( $_POST['bbp_forum_id'] ) ? (int) $_POST['bbp_forum_id'] : bbp_get_topic_forum_id( $topic_id );
311 + $sendback = add_query_arg(
312 + array(
313 + 'updated' => $updated,
314 + 'ids' => implode( ',', $post_ids ),
315 + 'locked' => $locked
316 + ),
317 + $sendback
318 + );
315 319
316 - // Formally update the reply
317 - bbp_update_reply( $reply_id, $topic_id, $forum_id );
320 + } elseif ( 'unspam' === $doaction ) {
318 321
319 - // Allow other fun things to happen
320 - do_action( 'bbp_reply_attributes_metabox_save', $reply_id, $topic_id, $forum_id );
322 + foreach ( (array) $post_ids as $post_id ) {
323 + if ( ! current_user_can( 'moderate', $post_id ) ) {
324 + wp_die( esc_html__( 'Sorry, you are not allowed to unspam this reply.', 'bbpress' ) );
325 + }
321 326
322 - return $reply_id;
327 + if ( wp_check_post_lock( $post_id ) ) {
328 + $locked++;
329 + continue;
330 + }
331 +
332 + if ( ! bbp_unspam_reply( $post_id ) ) {
333 + wp_die( esc_html__( 'Error in unspamming reply.', 'bbpress' ) );
334 + }
335 +
336 + ++$updated;
337 + }
338 +
339 + $sendback = add_query_arg(
340 + array(
341 + 'updated' => $updated,
342 + 'ids' => implode( ',', $post_ids ),
343 + 'locked' => $locked
344 + ),
345 + $sendback
346 + );
347 + }
348 +
349 + return $sendback;
323 350 }
324 351
325 352 /**
326 - * Add the author info metabox
353 + * Add the reply attributes meta-box
327 354 *
355 + * @since 2.0.0 bbPress (r2746)
356 + */
357 + public function attributes_metabox() {
358 + add_meta_box(
359 + 'bbp_reply_attributes',
360 + esc_html__( 'Reply Attributes', 'bbpress' ),
361 + 'bbp_reply_metabox',
362 + $this->post_type,
363 + 'side',
364 + 'high'
365 + );
366 + }
367 +
368 + /**
369 + * Add the author info meta-box
370 + *
328 371 * Allows editing of information about an author
329 372 *
330 - * @since bbPress (r2828)
331 - *
332 - * @uses bbp_get_topic() To get the topic
333 - * @uses bbp_get_reply() To get the reply
334 - * @uses bbp_get_topic_post_type() To get the topic post type
335 - * @uses bbp_get_reply_post_type() To get the reply post type
336 - * @uses add_meta_box() To add the metabox
337 - * @uses do_action() Calls 'bbp_author_metabox' with the topic/reply
338 - * id
373 + * @since 2.0.0 bbPress (r2828)
339 374 */
340 375 public function author_metabox() {
341 376
342 - if ( $this->bail() ) return;
343 -
344 377 // Bail if post_type is not a reply
345 - if ( empty( $_GET['action'] ) || ( 'edit' != $_GET['action'] ) )
378 + if ( empty( $_GET['action'] ) || ( 'edit' !== $_GET['action'] ) ) {
346 379 return;
380 + }
347 381
348 - // Add the metabox
382 + // Add the meta-box
349 383 add_meta_box(
350 384 'bbp_author_metabox',
351 - __( 'Author Information', 'bbpress' ),
385 + esc_html__( 'Author Information', 'bbpress' ),
352 386 'bbp_author_metabox',
353 387 $this->post_type,
354 388 'side',
355 389 'high'
356 390 );
391 + }
357 392
358 - do_action( 'bbp_author_metabox', get_the_ID() );
393 + /**
394 + * Remove comments & discussion meta-boxes if comments are not supported
395 + *
396 + * @since 2.6.0 bbPress (r6186)
397 + */
398 + public function comments_metabox() {
399 + if ( ! post_type_supports( $this->post_type, 'comments' ) ) {
400 + remove_meta_box( 'commentstatusdiv', $this->post_type, 'normal' );
401 + remove_meta_box( 'commentsdiv', $this->post_type, 'normal' );
402 + }
359 403 }
360 404
361 405 /**
362 - * Save the author information for the topic/reply
406 + * Pass the reply attributes for processing
363 407 *
364 - * @since bbPress (r2828)
408 + * @since 2.0.0 bbPress (r2746)
365 409 *
366 - * @param int $post_id Topic or reply id
367 - * @uses bbp_get_topic() To get the topic
368 - * @uses bbp_get_reply() To get the reply
369 - * @uses current_user_can() To check if the current user can edit the
370 - * topic or reply
371 - * @uses bbp_filter_anonymous_post_data() To filter the anonymous user data
372 - * @uses update_post_meta() To update the anonymous user data
373 - * @uses do_action() Calls 'bbp_author_metabox_save' with the reply id and
374 - * anonymous data
375 - * @return int Topic or reply id
410 + * @param int $reply_id Reply id
411 + * @return int Parent id
376 412 */
377 - public function author_metabox_save( $post_id ) {
413 + public function save_meta_boxes( $reply_id ) {
378 414
379 - if ( $this->bail() ) return $post_id;
415 + // Bail if doing an autosave
416 + if ( bbp_doing_autosave() ) {
417 + return $reply_id;
418 + }
380 419
381 - // Bail if no post_id
382 - if ( empty( $post_id ) )
383 - return $post_id;
420 + // Bail if not a post request
421 + if ( ! bbp_is_post_request() ) {
422 + return $reply_id;
423 + }
384 424
385 - // Bail if not a post request
386 - if ( 'POST' != strtoupper( $_SERVER['REQUEST_METHOD'] ) )
387 - return $post_id;
425 + // Check action exists
426 + if ( empty( $_POST['action'] ) ) {
427 + return $reply_id;
428 + }
388 429
389 - // Bail if doing an autosave
390 - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
391 - return $post_id;
430 + // Nonce check
431 + if ( empty( $_POST['bbp_reply_metabox'] ) || ! wp_verify_nonce( $_POST['bbp_reply_metabox'], 'bbp_reply_metabox_save' ) ) {
432 + return $reply_id;
433 + }
392 434
393 - // Bail if user cannot edit replies or reply is not anonymous
394 - if ( !current_user_can( 'edit_reply', $post_id ) )
395 - return $post_id;
435 + // Bail if current user cannot edit this reply
436 + if ( ! current_user_can( 'edit_reply', $reply_id ) ) {
437 + return $reply_id;
438 + }
396 439
440 + // Get the reply meta post values
441 + $topic_id = ! empty( $_POST['parent_id'] ) ? (int) $_POST['parent_id'] : 0;
442 + $forum_id = ! empty( $_POST['bbp_forum_id'] ) ? (int) $_POST['bbp_forum_id'] : bbp_get_topic_forum_id( $topic_id );
443 + $reply_to = ! empty( $_POST['bbp_reply_to'] ) ? (int) $_POST['bbp_reply_to'] : 0;
444 +
445 + // Get reply author data
397 446 $anonymous_data = bbp_filter_anonymous_post_data();
447 + $author_id = bbp_get_reply_author_id( $reply_id );
448 + $is_edit = ( isset( $_POST['hidden_post_status'] ) && ( 'draft' !== $_POST['hidden_post_status'] ) );
398 449
399 - update_post_meta( $post_id, '_bbp_anonymous_name', $anonymous_data['bbp_anonymous_name'] );
400 - update_post_meta( $post_id, '_bbp_anonymous_email', $anonymous_data['bbp_anonymous_email'] );
401 - update_post_meta( $post_id, '_bbp_anonymous_website', $anonymous_data['bbp_anonymous_website'] );
450 + // Formally update the reply
451 + bbp_update_reply( $reply_id, $topic_id, $forum_id, $anonymous_data, $author_id, $is_edit, $reply_to );
402 452
403 - do_action( 'bbp_author_metabox_save', $post_id, $anonymous_data );
453 + // Allow other fun things to happen
454 + do_action( 'bbp_reply_attributes_metabox_save', $reply_id, $topic_id, $forum_id, $reply_to );
455 + do_action( 'bbp_author_metabox_save', $reply_id, $anonymous_data );
404 456
405 - return $post_id;
457 + return $reply_id;
406 458 }
407 459
408 460 /**
409 - * Add some general styling to the admin area
461 + * Toggle reply
410 462 *
411 - * @since bbPress (r2464)
463 + * Handles the admin-side spamming/unspamming of replies
412 464 *
413 - * @uses bbp_get_forum_post_type() To get the forum post type
414 - * @uses bbp_get_topic_post_type() To get the topic post type
415 - * @uses bbp_get_reply_post_type() To get the reply post type
416 - * @uses sanitize_html_class() To sanitize the classes
417 - * @uses do_action() Calls 'bbp_admin_head'
465 + * @since 2.0.0 bbPress (r2740)
418 466 */
419 - public function admin_head() {
467 + public function toggle_reply() {
420 468
421 - if ( $this->bail() ) return;
469 + // Bail if not a topic toggle action
470 + if ( ! bbp_is_get_request() || empty( $_GET['action'] ) || empty( $_GET['reply_id'] ) ) {
471 + return;
472 + }
422 473
423 - ?>
474 + // Bail if not an allowed action
475 + $action = sanitize_key( $_GET['action'] );
476 + if ( empty( $action ) || ! in_array( $action, $this->get_allowed_action_toggles(), true ) ) {
477 + return;
478 + }
424 479
425 - <style type="text/css" media="screen">
426 - /*<![CDATA[*/
480 + // Get reply and die if empty
481 + $reply_id = bbp_get_reply_id( $_GET['reply_id'] );
482 + if ( ! bbp_get_reply( $reply_id ) ) {
483 + wp_die( esc_html__( 'The reply was not found.', 'bbpress' ) );
484 + }
427 485
428 - strong.label {
429 - display: inline-block;
430 - width: 60px;
431 - }
486 + // What is the user doing here?
487 + if ( ! current_user_can( 'moderate', $reply_id ) ) {
488 + wp_die( esc_html__( 'You do not have permission to do that.', 'bbpress' ) );
489 + }
432 490
433 - .column-bbp_forum_topic_count,
434 - .column-bbp_forum_reply_count,
435 - .column-bbp_topic_reply_count,
436 - .column-bbp_topic_voice_count {
437 - width: 8% !important;
438 - }
491 + // Defaults
492 + $post_data = array( 'ID' => $reply_id );
493 + $message = '';
494 + $success = false;
439 495
440 - .column-author,
441 - .column-bbp_reply_author,
442 - .column-bbp_topic_author {
443 - width: 10% !important;
444 - }
496 + switch ( $action ) {
497 + case 'bbp_toggle_reply_approve' :
498 + check_admin_referer( 'approve-reply_' . $reply_id );
445 499
446 - .column-bbp_topic_forum,
447 - .column-bbp_reply_forum,
448 - .column-bbp_reply_topic {
449 - width: 10% !important;
450 - }
500 + $is_approve = bbp_is_reply_public( $reply_id );
501 + $message = ( true === $is_approve )
502 + ? 'unpproved'
503 + : 'approved';
504 + $success = ( true === $is_approve )
505 + ? bbp_unapprove_reply( $reply_id )
506 + : bbp_approve_reply( $reply_id );
451 507
452 - .column-bbp_forum_freshness,
453 - .column-bbp_topic_freshness {
454 - width: 10% !important;
455 - }
508 + break;
456 509
457 - .column-bbp_forum_created,
458 - .column-bbp_topic_created,
459 - .column-bbp_reply_created {
460 - width: 15% !important;
461 - }
510 + case 'bbp_toggle_reply_spam' :
511 + check_admin_referer( 'spam-reply_' . $reply_id );
462 512
463 - .status-closed {
464 - background-color: #eaeaea;
465 - }
513 + $is_spam = bbp_is_reply_spam( $reply_id );
514 + $message = ( true === $is_spam )
515 + ? 'unspammed'
516 + : 'spammed';
517 + $success = ( true === $is_spam )
518 + ? bbp_unspam_reply( $reply_id )
519 + : bbp_spam_reply( $reply_id );
466 520
467 - .status-spam {
468 - background-color: #faeaea;
469 - }
521 + break;
522 + }
470 523
471 - /*]]>*/
472 - </style>
524 + // Setup the message
525 + $retval = array(
526 + 'bbp_reply_toggle_notice' => $message,
527 + 'reply_id' => $reply_id
528 + );
473 529
474 - <?php
530 + // Prepare for failure
531 + if ( ( false === $success ) || is_wp_error( $success ) ) {
532 + $retval['failed'] = '1';
533 + }
534 +
535 + // Filter all message args
536 + $retval = apply_filters( 'bbp_toggle_reply_action_admin', $retval, $reply_id, $action );
537 +
538 + // Do additional reply toggle actions (admin side)
539 + do_action( 'bbp_toggle_reply_admin', $success, $post_data, $action, $retval );
540 +
541 + // Redirect back to the reply
542 + $redirect = add_query_arg( $retval, remove_query_arg( array( 'action', 'reply_id' ) ) );
543 + bbp_redirect( $redirect );
475 544 }
476 545
477 546 /**
478 - * Toggle reply
547 + * Toggle reply notices
479 548 *
480 - * Handles the admin-side spamming/unspamming of replies
549 + * Display the success/error notices from
550 + * {@link BBP_Admin::toggle_reply()}
481 551 *
482 - * @since bbPress (r2740)
483 - *
484 - * @uses bbp_get_reply() To get the reply
485 - * @uses current_user_can() To check if the user is capable of editing
486 - * the reply
487 - * @uses wp_die() To die if the user isn't capable or the post wasn't
488 - * found
489 - * @uses check_admin_referer() To verify the nonce and check referer
490 - * @uses bbp_is_reply_spam() To check if the reply is marked as spam
491 - * @uses bbp_unspam_reply() To unmark the reply as spam
492 - * @uses bbp_spam_reply() To mark the reply as spam
493 - * @uses do_action() Calls 'bbp_toggle_reply_admin' with success, post
494 - * data, action and message
495 - * @uses add_query_arg() To add custom args to the url
496 - * @uses wp_safe_redirect() Redirect the page to custom url
552 + * @since 2.0.0 bbPress (r2740)
497 553 */
498 - public function toggle_reply() {
554 + public function toggle_reply_notice() {
499 555
500 - if ( $this->bail() ) return;
556 + // Bail if missing reply toggle action
557 + if ( ! bbp_is_get_request() || empty( $_GET['reply_id'] ) || empty( $_GET['bbp_reply_toggle_notice'] ) ) {
558 + return;
559 + }
501 560
502 - // Only proceed if GET is a reply toggle action
503 - if ( 'GET' == $_SERVER['REQUEST_METHOD'] && !empty( $_GET['action'] ) && in_array( $_GET['action'], array( 'bbp_toggle_reply_spam' ) ) && !empty( $_GET['reply_id'] ) ) {
504 - $action = $_GET['action']; // What action is taking place?
505 - $reply_id = (int) $_GET['reply_id']; // What's the reply id?
506 - $success = false; // Flag
507 - $post_data = array( 'ID' => $reply_id ); // Prelim array
561 + // Bail if not an allowed notice
562 + $notice = sanitize_key( $_GET['bbp_reply_toggle_notice'] );
563 + if ( empty( $notice ) || ! in_array( $notice, $this->get_allowed_notice_toggles(), true ) ) {
564 + return;
565 + }
508 566
509 - // Get reply and die if empty
510 - $reply = bbp_get_reply( $reply_id );
511 - if ( empty( $reply ) ) // Which reply?
512 - wp_die( __( 'The reply was not found!', 'bbpress' ) );
567 + // Bail if no reply_id or notice
568 + $reply_id = bbp_get_reply_id( $_GET['reply_id'] );
569 + if ( empty( $reply_id ) ) {
570 + return;
571 + }
513 572
514 - if ( !current_user_can( 'moderate', $reply->ID ) ) // What is the user doing here?
515 - wp_die( __( 'You do not have the permission to do that!', 'bbpress' ) );
573 + // Bail if reply is missing
574 + if ( ! bbp_get_reply( $reply_id ) ) {
575 + return;
576 + }
516 577
517 - switch ( $action ) {
518 - case 'bbp_toggle_reply_spam' :
519 - check_admin_referer( 'spam-reply_' . $reply_id );
578 + // Use the title in the responses
579 + $reply_title = bbp_get_reply_title( $reply_id );
580 + $is_failure = ! empty( $_GET['failed'] );
581 + $message = '';
520 582
521 - $is_spam = bbp_is_reply_spam( $reply_id );
522 - $message = $is_spam ? 'unspammed' : 'spammed';
523 - $success = $is_spam ? bbp_unspam_reply( $reply_id ) : bbp_spam_reply( $reply_id );
583 + switch ( $notice ) {
584 + case 'spammed' :
585 + $message = ( true === $is_failure )
586 + /* translators: %s: Reply title */
587 + ? sprintf( esc_html__( 'There was a problem marking the reply "%1$s" as spam.', 'bbpress' ), $reply_title )
588 + /* translators: %s: Reply title */
589 + : sprintf( esc_html__( 'Reply "%1$s" successfully marked as spam.', 'bbpress' ), $reply_title );
590 + break;
524 591
525 - break;
526 - }
592 + case 'unspammed' :
593 + $message = ( true === $is_failure )
594 + /* translators: %s: Reply title */
595 + ? sprintf( esc_html__( 'There was a problem unmarking the reply "%1$s" as spam.', 'bbpress' ), $reply_title )
596 + /* translators: %s: Reply title */
597 + : sprintf( esc_html__( 'Reply "%1$s" successfully unmarked as spam.', 'bbpress' ), $reply_title );
598 + break;
527 599
528 - $success = wp_update_post( $post_data );
529 - $message = array( 'bbp_reply_toggle_notice' => $message, 'reply_id' => $reply->ID );
600 + case 'approved' :
601 + $message = ( true === $is_failure )
602 + /* translators: %s: Reply title */
603 + ? sprintf( esc_html__( 'There was a problem approving the reply "%1$s".', 'bbpress' ), $reply_title )
604 + /* translators: %s: Reply title */
605 + : sprintf( esc_html__( 'Reply "%1$s" successfully approved.', 'bbpress' ), $reply_title );
606 + break;
530 607
531 - if ( false == $success || is_wp_error( $success ) )
532 - $message['failed'] = '1';
608 + case 'unapproved' :
609 + $message = ( true === $is_failure )
610 + /* translators: %s: Reply title */
611 + ? sprintf( esc_html__( 'There was a problem unapproving the reply "%1$s".', 'bbpress' ), $reply_title )
612 + /* translators: %s: Reply title */
613 + : sprintf( esc_html__( 'Reply "%1$s" successfully unapproved.', 'bbpress' ), $reply_title );
614 + break;
615 + }
533 616
534 - // Do additional reply toggle actions (admin side)
535 - do_action( 'bbp_toggle_reply_admin', $success, $post_data, $action, $message );
617 + // Do additional reply toggle notice filters (admin side)
618 + $message = apply_filters( 'bbp_toggle_reply_notice_admin', $message, $reply_id, $notice, $is_failure );
619 + $class = ( true === $is_failure )
620 + ? 'error'
621 + : 'updated';
536 622
537 - // Redirect back to the reply
538 - $redirect = add_query_arg( $message, remove_query_arg( array( 'action', 'reply_id' ) ) );
539 - wp_safe_redirect( $redirect );
540 -
541 - // For good measure
542 - exit();
543 - }
623 + // Add the notice
624 + bbp_admin()->add_notice( $message, $class, true );
544 625 }
545 626
546 627 /**
547 - * Toggle reply notices
628 + * Returns an array of keys used to sort row actions
548 629 *
549 - * Display the success/error notices from
550 - * {@link BBP_Admin::toggle_reply()}
630 + * @since 2.6.0 bbPress (r6771)
551 631 *
552 - * @since bbPress (r2740)
553 - *
554 - * @uses bbp_get_reply() To get the reply
555 - * @uses bbp_get_reply_title() To get the reply title of the reply
556 - * @uses esc_html() To sanitize the reply title
557 - * @uses apply_filters() Calls 'bbp_toggle_reply_notice_admin' with
558 - * message, reply id, notice and is it a failure
632 + * @return array
559 633 */
560 - public function toggle_reply_notice() {
634 + private function get_row_action_sort_order() {
561 635
562 - if ( $this->bail() ) return;
636 + /**
637 + * Filters the row action sort order for replies.
638 + *
639 + * @since 2.6.0 bbPress (r6771)
640 + *
641 + * @param array $order The default sort order.
642 + */
643 + return (array) apply_filters(
644 + 'bbp_admin_reply_row_action_sort_order',
645 + array(
646 + 'edit',
647 + 'approved',
648 + 'unapproved',
649 + 'spam',
650 + 'unspam',
651 + 'trash',
652 + 'untrash',
653 + 'delete',
654 + 'view'
655 + )
656 + );
657 + }
563 658
564 - // Only proceed if GET is a reply toggle action
565 - if ( 'GET' == $_SERVER['REQUEST_METHOD'] && !empty( $_GET['bbp_reply_toggle_notice'] ) && in_array( $_GET['bbp_reply_toggle_notice'], array( 'spammed', 'unspammed' ) ) && !empty( $_GET['reply_id'] ) ) {
566 - $notice = $_GET['bbp_reply_toggle_notice']; // Which notice?
567 - $reply_id = (int) $_GET['reply_id']; // What's the reply id?
568 - $is_failure = !empty( $_GET['failed'] ) ? true : false; // Was that a failure?
659 + /**
660 + * Returns an array of notice toggles
661 + *
662 + * @since 2.6.0 bbPress (r6396)
663 + *
664 + * @return array
665 + */
666 + private function get_allowed_notice_toggles() {
569 667
570 - // Empty? No reply?
571 - if ( empty( $notice ) || empty( $reply_id ) )
572 - return;
668 + // Filter & return
669 + return apply_filters(
670 + 'bbp_admin_replies_allowed_notice_toggles',
671 + array(
672 + 'spammed',
673 + 'unspammed',
674 + 'approved',
675 + 'unapproved'
676 + )
677 + );
678 + }
573 679
574 - // Get reply and bail if empty
575 - $reply = bbp_get_reply( $reply_id );
576 - if ( empty( $reply ) )
577 - return;
680 + /**
681 + * Returns an array of notice toggles
682 + *
683 + * @since 2.6.0 bbPress (r6396)
684 + *
685 + * @return array
686 + */
687 + private function get_allowed_action_toggles() {
578 688
579 - $reply_title = esc_html( bbp_get_reply_title( $reply->ID ) );
580 -
581 - switch ( $notice ) {
582 - case 'spammed' :
583 - $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 );
584 - break;
585 -
586 - case 'unspammed' :
587 - $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 );
588 - break;
589 - }
590 -
591 - // Do additional reply toggle notice filters (admin side)
592 - $message = apply_filters( 'bbp_toggle_reply_notice_admin', $message, $reply->ID, $notice, $is_failure );
593 -
594 - ?>
595 -
596 - <div id="message" class="<?php echo $is_failure == true ? 'error' : 'updated'; ?> fade">
597 - <p style="line-height: 150%"><?php echo $message; ?></p>
598 - </div>
599 -
600 - <?php
601 - }
689 + // Filter & return
690 + return apply_filters(
691 + 'bbp_admin_replies_allowed_action_toggles',
692 + array(
693 + 'bbp_toggle_reply_spam',
694 + 'bbp_toggle_reply_approve'
695 + )
696 + );
602 697 }
603 698
604 699 /**
605 700 * Manage the column headers for the replies page
606 701 *
607 - * @since bbPress (r2577)
702 + * @since 2.0.0 bbPress (r2577)
608 703 *
609 704 * @param array $columns The columns
610 - * @uses apply_filters() Calls 'bbp_admin_replies_column_headers' with
611 - * the columns
705 + *
612 706 * @return array $columns bbPress reply columns
613 707 */
614 - public function replies_column_headers( $columns ) {
615 -
616 - if ( $this->bail() ) return $columns;
617 -
708 + public function column_headers( $columns ) {
618 709 $columns = array(
619 710 'cb' => '<input type="checkbox" />',
620 - 'title' => __( 'Title', 'bbpress' ),
621 - 'bbp_reply_forum' => __( 'Forum', 'bbpress' ),
622 - 'bbp_reply_topic' => __( 'Topic', 'bbpress' ),
623 - 'bbp_reply_author' => __( 'Author', 'bbpress' ),
624 - 'bbp_reply_created' => __( 'Created', 'bbpress' ),
711 + 'title' => esc_html__( 'Title', 'bbpress' ),
712 + 'bbp_reply_forum' => esc_html__( 'Forum', 'bbpress' ),
713 + 'bbp_reply_topic' => esc_html__( 'Topic', 'bbpress' ),
714 + 'bbp_reply_author' => esc_html__( 'Author', 'bbpress' ),
715 + 'bbp_reply_created' => esc_html__( 'Created', 'bbpress' ),
625 716 );
626 717
718 + // Filter & return
627 719 return apply_filters( 'bbp_admin_replies_column_headers', $columns );
628 720 }
629 721
630 722 /**
@@ -629,37 +721,15 @@
629 721
630 722 /**
631 723 * Print extra columns for the replies page
632 724 *
633 - * @since bbPress (r2577)
725 + * @since 2.0.0 bbPress (r2577)
634 726 *
635 727 * @param string $column Column
636 728 * @param int $reply_id reply id
637 - * @uses bbp_get_reply_topic_id() To get the topic id of the reply
638 - * @uses bbp_topic_title() To output the reply's topic title
639 - * @uses apply_filters() Calls 'reply_topic_row_actions' with an array
640 - * of reply topic actions
641 - * @uses bbp_get_topic_permalink() To get the topic permalink
642 - * @uses bbp_get_topic_forum_id() To get the forum id of the topic of
643 - * the reply
644 - * @uses bbp_get_forum_permalink() To get the forum permalink
645 - * @uses admin_url() To get the admin url of post.php
646 - * @uses add_query_arg() To add custom args to the url
647 - * @uses apply_filters() Calls 'reply_topic_forum_row_actions' with an
648 - * array of reply topic forum actions
649 - * @uses bbp_reply_author_display_name() To output the reply author name
650 - * @uses get_the_date() Get the reply creation date
651 - * @uses get_the_time() Get the reply creation time
652 - * @uses esc_attr() To sanitize the reply creation time
653 - * @uses bbp_get_reply_last_active_time() To get the time when the reply was
654 - * last active
655 - * @uses do_action() Calls 'bbp_admin_replies_column_data' with the
656 - * column and reply id
657 729 */
658 - public function replies_column_data( $column, $reply_id ) {
730 + public function column_data( $column, $reply_id ) {
659 731
660 - if ( $this->bail() ) return;
661 -
662 732 // Get topic ID
663 733 $topic_id = bbp_get_reply_topic_id( $reply_id );
664 734
665 735 // Populate Column Data
@@ -667,23 +737,23 @@
667 737
668 738 // Topic
669 739 case 'bbp_reply_topic' :
670 740
671 - // Output forum name
672 - if ( !empty( $topic_id ) ) {
741 + // Get title
742 + $topic_title = ! empty( $topic_id )
743 + ? bbp_get_topic_title( $topic_id )
744 + : '';
673 745
674 - // Topic Title
675 - $topic_title = bbp_get_topic_title( $topic_id );
676 - if ( empty( $topic_title ) ) {
677 - $topic_title = __( 'No Topic', 'bbpress' );
678 - }
679 -
680 - // Output the title
746 + // Output topic name
747 + if ( ! empty( $topic_title ) ) {
681 748 echo $topic_title;
682 749
683 - // Reply has no topic
750 + // Output dash
684 751 } else {
685 - _e( 'No Topic', 'bbpress' );
752 + ?>
753 + <span aria-hidden="true">&mdash;</span>
754 + <span class="screen-reader-text"><?php esc_html_e( 'No topic', 'bbpress' ); ?></span>
755 + <?php
686 756 }
687 757
688 758 break;
689 759
@@ -693,30 +763,30 @@
693 763 // Get Forum ID's
694 764 $reply_forum_id = bbp_get_reply_forum_id( $reply_id );
695 765 $topic_forum_id = bbp_get_topic_forum_id( $topic_id );
696 766
697 - // Output forum name
698 - if ( !empty( $reply_forum_id ) ) {
767 + // Forum Title
768 + $forum_title = ! empty( $reply_forum_id )
769 + ? bbp_get_forum_title( $reply_forum_id )
770 + : '';
699 771
700 - // Forum Title
701 - $forum_title = bbp_get_forum_title( $reply_forum_id );
702 - if ( empty( $forum_title ) ) {
703 - $forum_title = __( 'No Forum', 'bbpress' );
772 + // Alert capable users of reply forum mismatch
773 + if ( $reply_forum_id !== $topic_forum_id ) {
774 + if ( current_user_can( 'edit_others_replies' ) || current_user_can( 'moderate', $reply_id ) ) {
775 + $forum_title .= '<div class="attention">' . esc_html__( '(Mismatch)', 'bbpress' ) . '</div>';
704 776 }
777 + }
705 778
706 - // Alert capable users of reply forum mismatch
707 - if ( $reply_forum_id != $topic_forum_id ) {
708 - if ( current_user_can( 'edit_others_replies' ) || current_user_can( 'moderate' ) ) {
709 - $forum_title .= '<div class="attention">' . __( '(Mismatch)', 'bbpress' ) . '</div>';
710 - }
711 - }
712 -
713 - // Output the title
779 + // Output forum name
780 + if ( ! empty( $forum_title ) ) {
714 781 echo $forum_title;
715 782
716 783 // Reply has no forum
717 784 } else {
718 - _e( 'No Forum', 'bbpress' );
785 + ?>
786 + <span aria-hidden="true">&mdash;</span>
787 + <span class="screen-reader-text"><?php esc_html_e( 'No forum', 'bbpress' ); ?></span>
788 + <?php
719 789 }
720 790
721 791 break;
722 792
@@ -721,9 +791,9 @@
721 791 break;
722 792
723 793 // Author
724 794 case 'bbp_reply_author' :
725 - bbp_reply_author_display_name ( $reply_id );
795 + bbp_reply_author_display_name( $reply_id );
726 796 break;
727 797
728 798 // Freshness
729 799 case 'bbp_reply_created':
@@ -728,9 +798,9 @@
728 798 // Freshness
729 799 case 'bbp_reply_created':
730 800
731 801 // Output last activity time and date
732 - printf( __( '%1$s <br /> %2$s', 'bbpress' ),
802 + printf( '%1$s <br /> %2$s',
733 803 get_the_date(),
734 804 esc_attr( get_the_time() )
735 805 );
736 806
@@ -748,47 +818,73 @@
748 818 *
749 819 * Remove the quick-edit action link under the reply title and add the
750 820 * content and spam link
751 821 *
752 - * @since bbPress (r2577)
822 + * @since 2.0.0 bbPress (r2577)
753 823 *
754 - * @param array $actions Actions
755 - * @param array $reply Reply object
756 - * @uses bbp_get_reply_post_type() To get the reply post type
757 - * @uses bbp_reply_content() To output reply content
758 - * @uses bbp_get_reply_permalink() To get the reply link
759 - * @uses bbp_get_reply_title() To get the reply title
760 - * @uses current_user_can() To check if the current user can edit or
761 - * delete the reply
762 - * @uses bbp_is_reply_spam() To check if the reply is marked as spam
763 - * @uses get_post_type_object() To get the reply post type object
764 - * @uses add_query_arg() To add custom args to the url
765 - * @uses remove_query_arg() To remove custom args from the url
766 - * @uses wp_nonce_url() To nonce the url
767 - * @uses get_delete_post_link() To get the delete post link of the reply
824 + * @param array $actions Actions
825 + * @param object $reply Reply object
826 + *
768 827 * @return array $actions Actions
769 828 */
770 - public function replies_row_actions( $actions, $reply ) {
829 + public function row_actions( $actions = array(), $reply = false ) {
771 830
772 - if ( $this->bail() ) return $actions;
831 + // Disable quick edit (too much to do here)
832 + unset( $actions['inline hide-if-no-js'] );
773 833
774 - unset( $actions['inline hide-if-no-js'] );
834 + // View link
835 + $view_link = bbp_get_reply_url( $reply->ID );
775 836
837 + // Maybe add view=all
838 + if ( ! in_array( $reply->post_status, array( bbp_get_closed_status_id(), bbp_get_public_status_id() ), true ) ) {
839 + $view_link = bbp_add_view_all( $view_link, true );
840 + }
841 +
776 842 // Reply view links to topic
777 - $actions['view'] = '<a href="' . bbp_get_reply_url( $reply->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;', 'bbpress' ), bbp_get_reply_title( $reply->ID ) ) ) . '" rel="permalink">' . __( 'View', 'bbpress' ) . '</a>';
843 + $view_title = sprintf(
844 + /* translators: %s: Reply title */
845 + __( 'View &#8220;%s&#8221;', 'bbpress' ),
846 + bbp_get_reply_title( $reply->ID )
847 + );
778 848
849 + $actions['view'] = sprintf(
850 + '<a href="%1$s" title="%2$s" rel="permalink">%3$s</a>',
851 + esc_url( $view_link ),
852 + esc_attr( $view_title ),
853 + esc_html__( 'View', 'bbpress' )
854 + );
855 +
779 856 // User cannot view replies in trash
780 - if ( ( bbp_get_trash_status_id() == $reply->post_status ) && !current_user_can( 'view_trash' ) )
857 + if ( ( bbp_get_trash_status_id() === $reply->post_status ) && ! current_user_can( 'view_trash' ) ) {
781 858 unset( $actions['view'] );
859 + }
782 860
783 861 // Only show the actions if the user is capable of viewing them
784 862 if ( current_user_can( 'moderate', $reply->ID ) ) {
785 - if ( in_array( $reply->post_status, array( bbp_get_public_status_id(), bbp_get_spam_status_id() ) ) ) {
786 - $spam_uri = esc_url( 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 ) );
787 - if ( bbp_is_reply_spam( $reply->ID ) ) {
788 - $actions['spam'] = '<a href="' . $spam_uri . '" title="' . esc_attr__( 'Mark the reply as not spam', 'bbpress' ) . '">' . __( 'Not spam', 'bbpress' ) . '</a>';
863 +
864 + // Show the 'approve' link on non-published posts only and 'unapprove' on published posts only
865 + $args = array(
866 + 'reply_id' => $reply->ID,
867 + 'action' => 'bbp_toggle_reply_approve'
868 + );
869 + $approve_uri = wp_nonce_url( add_query_arg( $args, remove_query_arg( array( 'bbp_reply_toggle_notice', 'reply_id', 'failed', 'super' ) ) ), 'approve-reply_' . $reply->ID );
870 + if ( bbp_is_reply_public( $reply->ID ) ) {
871 + $actions['unapproved'] = '<a href="' . esc_url( $approve_uri ) . '" title="' . esc_attr__( 'Unapprove this reply', 'bbpress' ) . '">' . _x( 'Unapprove', 'Unapprove reply', 'bbpress' ) . '</a>';
872 + } else {
873 + $actions['approved'] = '<a href="' . esc_url( $approve_uri ) . '" title="' . esc_attr__( 'Approve this reply', 'bbpress' ) . '">' . _x( 'Approve', 'Approve reply', 'bbpress' ) . '</a>';
874 + }
875 +
876 + // Show the 'spam' link on published and pending replies and 'not spam' on spammed replies
877 + if ( in_array( $reply->post_status, array( bbp_get_public_status_id(), bbp_get_trash_status_id(), bbp_get_pending_status_id(), bbp_get_spam_status_id() ), true ) ) {
878 + $args = array(
879 + 'reply_id' => $reply->ID,
880 + 'action' => 'bbp_toggle_reply_spam'
881 + );
882 + $spam_uri = wp_nonce_url( add_query_arg( $args, remove_query_arg( array( 'bbp_reply_toggle_notice', 'reply_id', 'failed', 'super' ) ) ), 'spam-reply_' . $reply->ID );
883 + if ( ! bbp_is_reply_spam( $reply->ID ) ) {
884 + $actions['spam'] = '<a href="' . esc_url( $spam_uri ) . '" title="' . esc_attr__( 'Mark this reply as spam', 'bbpress' ) . '">' . esc_html__( 'Spam', 'bbpress' ) . '</a>';
789 885 } else {
790 - $actions['spam'] = '<a href="' . $spam_uri . '" title="' . esc_attr__( 'Mark this reply as spam', 'bbpress' ) . '">' . __( 'Spam', 'bbpress' ) . '</a>';
886 + $actions['unspam'] = '<a href="' . esc_url( $spam_uri ) . '" title="' . esc_attr__( 'Mark the reply as not spam', 'bbpress' ) . '">' . esc_html__( 'Not Spam', 'bbpress' ) . '</a>';
791 887 }
792 888 }
793 889 }
794 890
@@ -793,75 +889,121 @@
793 889 }
794 890
795 891 // Trash
796 892 if ( current_user_can( 'delete_reply', $reply->ID ) ) {
797 - if ( bbp_get_trash_status_id() == $reply->post_status ) {
798 - $post_type_object = get_post_type_object( bbp_get_reply_post_type() );
799 - $actions['untrash'] = "<a title='" . esc_attr__( 'Restore this item from the Trash', 'bbpress' ) . "' href='" . 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 . '&amp;action=untrash', $reply->ID ) ), 'untrash-' . $reply->post_type . '_' . $reply->ID ) ) . "'>" . __( 'Restore', 'bbpress' ) . "</a>";
800 - } elseif ( EMPTY_TRASH_DAYS ) {
801 - $actions['trash'] = "<a class='submitdelete' title='" . esc_attr__( 'Move this item to the Trash', 'bbpress' ) . "' href='" . 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 ) ) . "'>" . __( 'Trash', 'bbpress' ) . "</a>";
893 + $trash_days = bbp_get_trash_days( bbp_get_reply_post_type() );
894 +
895 + if ( bbp_get_trash_status_id() === $reply->post_status ) {
896 + $post_type_object = get_post_type_object( bbp_get_reply_post_type() );
897 + $actions['untrash'] = "<a title='" . esc_attr__( 'Restore this item from the Trash', 'bbpress' ) . "' href='" . esc_url( wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $reply->ID ) ), 'untrash-post_' . $reply->ID ) ) . "'>" . esc_html__( 'Restore', 'bbpress' ) . '</a>';
898 + } elseif ( ! empty( $trash_days ) ) {
899 + $actions['trash'] = "<a class='submitdelete' title='" . esc_attr__( 'Move this item to the Trash', 'bbpress' ) . "' href='" . esc_url( get_delete_post_link( $reply->ID ) ) . "'>" . esc_html__( 'Trash', 'bbpress' ) . '</a>';
802 900 }
803 901
804 - if ( bbp_get_trash_status_id() == $reply->post_status || !EMPTY_TRASH_DAYS ) {
805 - $actions['delete'] = "<a class='submitdelete' title='" . esc_attr__( 'Delete this item permanently', 'bbpress' ) . "' href='" . 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 ) ) . "'>" . __( 'Delete Permanently', 'bbpress' ) . "</a>";
806 - } elseif ( bbp_get_spam_status_id() == $reply->post_status ) {
807 - unset( $actions['trash'] );
902 + if ( ( bbp_get_trash_status_id() === $reply->post_status ) || empty( $trash_days ) ) {
903 + $actions['delete'] = "<a class='submitdelete' title='" . esc_attr__( 'Delete this item permanently', 'bbpress' ) . "' href='" . esc_url( get_delete_post_link( $reply->ID, '', true ) ) . "'>" . esc_html__( 'Delete Permanently', 'bbpress' ) . '</a>';
808 904 }
809 905 }
810 906
811 - return $actions;
907 + // Sort & return
908 + return $this->sort_row_actions( $actions );
812 909 }
813 910
814 911 /**
912 + * Sort row actions by key
913 + *
914 + * @since 2.6.0
915 + *
916 + * @param array $actions
917 + *
918 + * @return array
919 + */
920 + private function sort_row_actions( $actions = array() ) {
921 +
922 + // Return value
923 + $retval = array();
924 +
925 + // Known row actions, in sort order
926 + $known_actions = $this->get_row_action_sort_order();
927 +
928 + // Sort known actions, and keep any unknown ones
929 + foreach ( $known_actions as $key ) {
930 + if ( isset( $actions[ $key ] ) ) {
931 + $retval[ $key ] = $actions[ $key ];
932 + unset( $actions[ $key ] );
933 + }
934 + }
935 +
936 + // Combine & return
937 + return $retval + $actions;
938 + }
939 +
940 + /**
815 941 * Add forum dropdown to topic and reply list table filters
816 942 *
817 - * @since bbPress (r2991)
943 + * @since 2.0.0 bbPress (r2991)
818 944 *
819 - * @uses bbp_get_reply_post_type() To get the reply post type
820 - * @uses bbp_get_topic_post_type() To get the topic post type
821 - * @uses bbp_dropdown() To generate a forum dropdown
822 945 * @return bool False. If post type is not topic or reply
823 946 */
824 947 public function filter_dropdown() {
825 948
826 - if ( $this->bail() ) return;
949 + // Get which forum is selected
950 + $selected = ! empty( $_GET['bbp_forum_id'] )
951 + ? (int) $_GET['bbp_forum_id']
952 + : 0;
827 953
828 - // Add Empty Spam button
829 - if ( !empty( $_GET['post_status'] ) && ( bbp_get_spam_status_id() == $_GET['post_status'] ) && current_user_can( 'moderate' ) ) {
830 - wp_nonce_field( 'bulk-destroy', '_destroy_nonce' );
831 - $title = esc_attr__( 'Empty Spam', 'bbpress' );
832 - submit_button( $title, 'button-secondary apply', 'delete_all', false );
954 + // Show the forums dropdown
955 + bbp_dropdown(
956 + array(
957 + 'selected' => $selected,
958 + 'show_none' => esc_html__( 'In all forums', 'bbpress' )
959 + )
960 + );
961 + }
962 +
963 + /**
964 + * Add "Empty Spam" button for moderators
965 + *
966 + * @since 2.6.0 bbPress (r6791)
967 + */
968 + public function filter_empty_spam() {
969 +
970 + // Bail if not viewing spam
971 + if ( empty( $_GET['post_status'] ) || ( bbp_get_spam_status_id() !== $_GET['post_status'] ) && current_user_can( 'moderate' ) ) {
972 + return;
833 973 }
834 974
835 - // Get which forum is selected
836 - $selected = !empty( $_GET['bbp_forum_id'] ) ? $_GET['bbp_forum_id'] : '';
975 + ?>
837 976
838 - // Show the forums dropdown
839 - bbp_dropdown( array(
840 - 'selected' => $selected,
841 - 'show_none' => __( 'In all forums', 'bbpress' )
842 - ) );
977 + <div class="alignleft actions"><?php
978 +
979 + // Output the nonce & button
980 + wp_nonce_field( 'bulk-destroy', '_destroy_nonce' );
981 + submit_button(
982 + esc_attr__( 'Empty Spam', 'bbpress' ),
983 + 'button-secondary apply',
984 + 'delete_all',
985 + false
986 + );
987 +
988 + ?></div><?php
843 989 }
844 990
845 991 /**
846 992 * Adjust the request query and include the forum id
847 993 *
848 - * @since bbPress (r2991)
994 + * @since 2.0.0 bbPress (r2991)
849 995 *
850 996 * @param array $query_vars Query variables from {@link WP_Query}
851 - * @uses is_admin() To check if it's the admin section
852 - * @uses bbp_get_topic_post_type() To get the topic post type
853 - * @uses bbp_get_reply_post_type() To get the reply post type
854 997 * @return array Processed Query Vars
855 998 */
856 999 public function filter_post_rows( $query_vars ) {
857 1000
858 - if ( $this->bail() ) return $query_vars;
859 -
860 1001 // Add post_parent query_var if one is present
861 - if ( !empty( $_GET['bbp_forum_id'] ) ) {
1002 + if ( ! empty( $_GET['bbp_forum_id'] ) ) {
862 1003 $query_vars['meta_key'] = '_bbp_forum_id';
863 - $query_vars['meta_value'] = $_GET['bbp_forum_id'];
1004 + $query_vars['meta_type'] = 'NUMERIC';
1005 + $query_vars['meta_value'] = (int) $_GET['bbp_forum_id'];
864 1006 }
865 1007
866 1008 // Return manipulated query_vars
867 1009 return $query_vars;
@@ -869,15 +1011,11 @@
869 1011
870 1012 /**
871 1013 * Custom user feedback messages for reply post type
872 1014 *
873 - * @since bbPress (r3080)
1015 + * @since 2.0.0 bbPress (r3080)
874 1016 *
875 1017 * @global int $post_ID
876 - * @uses bbp_get_topic_permalink()
877 - * @uses wp_post_revision_title()
878 - * @uses esc_url()
879 - * @uses add_query_arg()
880 1018 *
881 1019 * @param array $messages
882 1020 *
883 1021 * @return array
@@ -884,10 +1022,8 @@
884 1022 */
885 1023 public function updated_messages( $messages ) {
886 1024 global $post_ID;
887 1025
888 - if ( $this->bail() ) return $messages;
889 -
890 1026 // URL for the current topic
891 1027 $topic_url = bbp_get_topic_permalink( bbp_get_reply_topic_id( $post_ID ) );
892 1028
893 1029 // Current reply's post_date
@@ -893,47 +1029,73 @@
893 1029 // Current reply's post_date
894 1030 $post_date = bbp_get_global_post_field( 'post_date', 'raw' );
895 1031
896 1032 // Messages array
897 - $messages[$this->post_type] = array(
898 - 0 => '', // Left empty on purpose
1033 + $messages[ $this->post_type ] = array(
1034 + 0 => '', // Left empty on purpose
899 1035
900 1036 // Updated
901 - 1 => sprintf( __( 'Reply updated. <a href="%s">View topic</a>', 'bbpress' ), $topic_url ),
1037 + 1 => sprintf(
1038 + '%1$s <a href="%2$s">%3$s</a>',
1039 + esc_html__( 'Reply updated.', 'bbpress' ),
1040 + $topic_url,
1041 + esc_html__( 'View topic', 'bbpress' )
1042 + ),
902 1043
903 1044 // Custom field updated
904 - 2 => __( 'Custom field updated.', 'bbpress' ),
1045 + 2 => esc_html__( 'Custom field updated.', 'bbpress' ),
905 1046
906 1047 // Custom field deleted
907 - 3 => __( 'Custom field deleted.', 'bbpress' ),
1048 + 3 => esc_html__( 'Custom field deleted.', 'bbpress' ),
908 1049
909 1050 // Reply updated
910 - 4 => __( 'Reply updated.', 'bbpress' ),
1051 + 4 => esc_html__( 'Reply updated.', 'bbpress' ),
911 1052
912 1053 // Restored from revision
913 - // translators: %s: date and time of the revision
1054 + /* translators: %s: date and time of the revision */
914 1055 5 => isset( $_GET['revision'] )
915 - ? sprintf( __( 'Reply restored to revision from %s', 'bbpress' ), wp_post_revision_title( (int) $_GET['revision'], false ) )
1056 + /* translators: %s: Date and time of the revision */
1057 + ? sprintf( esc_html__( 'Reply restored to revision from %s', 'bbpress' ), wp_post_revision_title( (int) $_GET['revision'], false ) )
916 1058 : false,
917 1059
918 1060 // Reply created
919 - 6 => sprintf( __( 'Reply created. <a href="%s">View topic</a>', 'bbpress' ), $topic_url ),
1061 + 6 => sprintf(
1062 + '%1$s <a href="%2$s">%3$s</a>',
1063 + esc_html__( 'Reply created.', 'bbpress' ),
1064 + $topic_url,
1065 + esc_html__( 'View topic', 'bbpress' )
1066 + ),
920 1067
921 1068 // Reply saved
922 - 7 => __( 'Reply saved.', 'bbpress' ),
1069 + 7 => esc_html__( 'Reply saved.', 'bbpress' ),
923 1070
924 1071 // Reply submitted
925 - 8 => sprintf( __( 'Reply submitted. <a target="_blank" href="%s">Preview topic</a>', 'bbpress' ), esc_url( add_query_arg( 'preview', 'true', $topic_url ) ) ),
1072 + 8 => sprintf(
1073 + '%1$s <a href="%2$s" target="_blank">%3$s</a>',
1074 + esc_html__( 'Reply submitted.', 'bbpress' ),
1075 + esc_url( add_query_arg( 'preview', 'true', $topic_url ) ),
1076 + esc_html__( 'Preview topic', 'bbpress' )
1077 + ),
926 1078
927 1079 // Reply scheduled
928 - 9 => sprintf( __( 'Reply scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview topic</a>', 'bbpress' ),
929 - // translators: Publish box date format, see http://php.net/date
930 - date_i18n( __( 'M j, Y @ G:i', 'bbpress' ),
931 - strtotime( $post_date ) ),
932 - $topic_url ),
1080 + 9 => sprintf(
1081 + '%1$s <a target="_blank" href="%2$s">%3$s</a>',
1082 + sprintf(
1083 + /* translators: Publish box date format, see http://php.net/date */
1084 + esc_html__( 'Reply scheduled for: %s.', 'bbpress' ),
1085 + '<strong>' . date_i18n( __( 'M j, Y @ G:i', 'bbpress' ), strtotime( $post_date ) ) . '</strong>'
1086 + ),
1087 + $topic_url,
1088 + esc_html__( 'Preview topic', 'bbpress' )
1089 + ),
933 1090
934 1091 // Reply draft updated
935 - 10 => sprintf( __( 'Reply draft updated. <a target="_blank" href="%s">Preview topic</a>', 'bbpress' ), esc_url( add_query_arg( 'preview', 'true', $topic_url ) ) ),
1092 + 10 => sprintf(
1093 + '%1$s <a href="%2$s" target="_blank">%3$s</a>',
1094 + esc_html__( 'Reply draft updated.', 'bbpress' ),
1095 + esc_url( add_query_arg( 'preview', 'true', $topic_url ) ),
1096 + esc_html__( 'Preview topic', 'bbpress' )
1097 + ),
936 1098 );
937 1099
938 1100 return $messages;
939 1101 }
@@ -945,11 +1107,18 @@
945 1107 *
946 1108 * This is currently here to make hooking and unhooking of the admin UI easy.
947 1109 * It could use dependency injection in the future, but for now this is easier.
948 1110 *
949 - * @since bbPress (r2596)
1111 + * @since 2.0.0 bbPress (r2596)
950 1112 *
951 - * @uses BBP_Replies_Admin
1113 + * @param WP_Screen $current_screen Current screen object
952 1114 */
953 -function bbp_admin_replies() {
954 - bbpress()->admin->replies = new BBP_Replies_Admin();
1115 +function bbp_admin_replies( $current_screen ) {
1116 +
1117 + // Bail if not a forum screen
1118 + if ( empty( $current_screen->post_type ) || ( bbp_get_reply_post_type() !== $current_screen->post_type ) ) {
1119 + return;
1120 + }
1121 +
1122 + // Init the replies admin
1123 + bbp_admin()->replies = new BBP_Replies_Admin();
955 1124 }