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