| @@ -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_Forums_Admin' ) ) : | |
| 13 | +if ( ! class_exists( 'BBP_Forums_Admin' ) ) : | |
| 14 | 14 | /** |
| 15 | 15 | * Loads bbPress forums 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_Forums_Admin { |
| 22 | 22 | |
| 23 | 23 | /** Variables *************************************************************/ |
| @@ -22,9 +22,9 @@ | ||
| 22 | 22 | |
| 23 | 23 | /** Variables *************************************************************/ |
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | - * @var The post type of this admin component | |
| 26 | + * @var string The post type of this admin component | |
| 27 | 27 | */ |
| 28 | 28 | private $post_type = ''; |
| 29 | 29 | |
| 30 | 30 | /** Functions *************************************************************/ |
| @@ -31,13 +31,9 @@ | ||
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * The main bbPress forums admin loader |
| 34 | 34 | * |
| 35 | - * @since bbPress (r2515) | |
| 36 | - * | |
| 37 | - * @uses BBP_Forums_Admin::setup_globals() Setup the globals needed | |
| 38 | - * @uses BBP_Forums_Admin::setup_actions() Setup the hooks and actions | |
| 39 | - * @uses BBP_Forums_Admin::setup_help() Setup the help text | |
| 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,58 +41,46 @@ | ||
| 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 | + * | |
| 50 | 47 | * @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 | 48 | */ |
| 58 | 49 | private function setup_actions() { |
| 59 | 50 | |
| 60 | - // Add some general styling to the admin area | |
| 61 | - add_action( 'bbp_admin_head', array( $this, 'admin_head' ) ); | |
| 62 | - | |
| 63 | 51 | // Messages |
| 64 | 52 | add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) ); |
| 65 | 53 | |
| 66 | - // Metabox actions | |
| 67 | - add_action( 'add_meta_boxes', array( $this, 'attributes_metabox' ) ); | |
| 68 | - add_action( 'save_post', array( $this, 'attributes_metabox_save' ) ); | |
| 69 | - | |
| 70 | - // Column headers. | |
| 54 | + // Forum Column headers. | |
| 71 | 55 | add_filter( 'manage_' . $this->post_type . '_posts_columns', array( $this, 'column_headers' ) ); |
| 72 | 56 | |
| 73 | - // Columns (in page row) | |
| 57 | + // Forum Columns (in page row) | |
| 74 | 58 | add_action( 'manage_' . $this->post_type . '_posts_custom_column', array( $this, 'column_data' ), 10, 2 ); |
| 75 | 59 | add_filter( 'page_row_actions', array( $this, 'row_actions' ), 10, 2 ); |
| 76 | 60 | |
| 61 | + // Metabox actions | |
| 62 | + add_action( 'add_meta_boxes', array( $this, 'attributes_metabox' ) ); | |
| 63 | + add_action( 'add_meta_boxes', array( $this, 'moderators_metabox' ) ); | |
| 64 | + add_action( 'add_meta_boxes', array( $this, 'subscriptions_metabox' ) ); | |
| 65 | + add_action( 'add_meta_boxes', array( $this, 'comments_metabox' ) ); | |
| 66 | + add_action( 'save_post', array( $this, 'save_meta_boxes' ) ); | |
| 67 | + | |
| 68 | + // Check if there are any bbp_toggle_forum_* requests on admin_init, also have a message displayed | |
| 69 | + add_action( 'load-edit.php', array( $this, 'toggle_forum' ) ); | |
| 70 | + add_action( 'load-edit.php', array( $this, 'toggle_forum_notice' ) ); | |
| 71 | + | |
| 77 | 72 | // Contextual Help |
| 78 | 73 | add_action( 'load-edit.php', array( $this, 'edit_help' ) ); |
| 74 | + add_action( 'load-post.php', array( $this, 'new_help' ) ); | |
| 79 | 75 | add_action( 'load-post-new.php', array( $this, 'new_help' ) ); |
| 80 | 76 | } |
| 81 | 77 | |
| 82 | 78 | /** |
| 83 | - * Should we bail out of this method? | |
| 79 | + * Admin globals | |
| 84 | 80 | * |
| 85 | - * @since bbPress (r4067) | |
| 86 | - * @return boolean | |
| 87 | - */ | |
| 88 | - private function bail() { | |
| 89 | - if ( !isset( get_current_screen()->post_type ) || ( $this->post_type != get_current_screen()->post_type ) ) | |
| 90 | - return true; | |
| 91 | - | |
| 92 | - return false; | |
| 93 | - } | |
| 94 | - | |
| 95 | - /** | |
| 96 | - * Admin globals | |
| 81 | + * @since 2.0.0 bbPress (r2646) | |
| 97 | 82 | * |
| 98 | - * @since bbPress (r2646) | |
| 99 | 83 | * @access private |
| 100 | 84 | */ |
| 101 | 85 | private function setup_globals() { |
| 102 | 86 | $this->post_type = bbp_get_forum_post_type(); |
| @@ -106,63 +90,69 @@ | ||
| 106 | 90 | |
| 107 | 91 | /** |
| 108 | 92 | * Contextual help for bbPress forum edit page |
| 109 | 93 | * |
| 110 | - * @since bbPress (r3119) | |
| 111 | - * @uses get_current_screen() | |
| 94 | + * @since 2.0.0 bbPress (r3119) | |
| 112 | 95 | */ |
| 113 | 96 | public function edit_help() { |
| 114 | 97 | |
| 115 | - if ( $this->bail() ) return; | |
| 116 | - | |
| 117 | 98 | // Overview |
| 118 | - get_current_screen()->add_help_tab( array( | |
| 119 | - 'id' => 'overview', | |
| 120 | - 'title' => __( 'Overview', 'bbpress' ), | |
| 121 | - 'content' => | |
| 122 | - '<p>' . __( 'This screen displays the individual forums on your site. You can customize the display of this screen to suit your workflow.', 'bbpress' ) . '</p>' | |
| 123 | - ) ); | |
| 99 | + get_current_screen()->add_help_tab( | |
| 100 | + array( | |
| 101 | + 'id' => 'overview', | |
| 102 | + 'title' => __( 'Overview', 'bbpress' ), | |
| 103 | + 'content' => | |
| 104 | + '<p>' . __( 'This screen displays the individual forums on your site. You can customize the display of this screen to suit your workflow.', 'bbpress' ) . '</p>' | |
| 105 | + ) | |
| 106 | + ); | |
| 124 | 107 | |
| 125 | 108 | // Screen Content |
| 126 | - get_current_screen()->add_help_tab( array( | |
| 127 | - 'id' => 'screen-content', | |
| 128 | - 'title' => __( 'Screen Content', 'bbpress' ), | |
| 129 | - 'content' => | |
| 130 | - '<p>' . __( 'You can customize the display of this screen’s contents in a number of ways:', 'bbpress' ) . '</p>' . | |
| 131 | - '<ul>' . | |
| 132 | - '<li>' . __( 'You can hide/display columns based on your needs and decide how many forums to list per screen using the Screen Options tab.', 'bbpress' ) . '</li>' . | |
| 133 | - '<li>' . __( 'You can filter the list of forums by forum status using the text links in the upper left to show All, Published, or Trashed forums. The default view is to show all forums.', 'bbpress' ) . '</li>' . | |
| 134 | - '<li>' . __( 'You can refine the list to show only forums from a specific month by using the dropdown menus above the forums list. Click the Filter button after making your selection. You also can refine the list by clicking on the forum creator in the forums list.', 'bbpress' ) . '</li>' . | |
| 135 | - '</ul>' | |
| 136 | - ) ); | |
| 109 | + get_current_screen()->add_help_tab( | |
| 110 | + array( | |
| 111 | + 'id' => 'screen-content', | |
| 112 | + 'title' => __( 'Screen Content', 'bbpress' ), | |
| 113 | + 'content' => | |
| 114 | + '<p>' . __( 'You can customize the display of this screen’s contents in a number of ways:', 'bbpress' ) . '</p>' . | |
| 115 | + '<ul>' . | |
| 116 | + '<li>' . __( 'You can hide/display columns based on your needs and decide how many forums to list per screen using the Screen Options tab.', 'bbpress' ) . '</li>' . | |
| 117 | + '<li>' . __( 'You can filter the list of forums by forum status using the text links in the upper left to show All, Published, or Trashed forums. The default view is to show all forums.', 'bbpress' ) . '</li>' . | |
| 118 | + '<li>' . __( 'You can refine the list to show only forums from a specific month by using the dropdown menus above the forums list. Click the Filter button after making your selection. You also can refine the list by clicking on the forum creator in the forums list.', 'bbpress' ) . '</li>' . | |
| 119 | + '</ul>' | |
| 120 | + ) | |
| 121 | + ); | |
| 137 | 122 | |
| 138 | 123 | // Available Actions |
| 139 | - get_current_screen()->add_help_tab( array( | |
| 140 | - 'id' => 'action-links', | |
| 141 | - 'title' => __( 'Available Actions', 'bbpress' ), | |
| 142 | - 'content' => | |
| 143 | - '<p>' . __( 'Hovering over a row in the forums list will display action links that allow you to manage your forum. You can perform the following actions:', 'bbpress' ) . '</p>' . | |
| 144 | - '<ul>' . | |
| 145 | - '<li>' . __( '<strong>Edit</strong> takes you to the editing screen for that forum. You can also reach that screen by clicking on the forum title.', 'bbpress' ) . '</li>' . | |
| 146 | - '<li>' . __( '<strong>Trash</strong> removes your forum from this list and places it in the trash, from which you can permanently delete it.', 'bbpress' ) . '</li>' . | |
| 147 | - '<li>' . __( '<strong>View</strong> will show you what your draft forum will look like if you publish it. View will take you to your live site to view the forum. Which link is available depends on your forum’s status.', 'bbpress' ) . '</li>' . | |
| 148 | - '</ul>' | |
| 149 | - ) ); | |
| 124 | + get_current_screen()->add_help_tab( | |
| 125 | + array( | |
| 126 | + 'id' => 'action-links', | |
| 127 | + 'title' => __( 'Available Actions', 'bbpress' ), | |
| 128 | + 'content' => | |
| 129 | + '<p>' . __( 'Hovering over a row in the forums list will display action links that allow you to manage your forum. You can perform the following actions:', 'bbpress' ) . '</p>' . | |
| 130 | + '<ul>' . | |
| 131 | + '<li>' . __( '<strong>Edit</strong> takes you to the editing screen for that forum. You can also reach that screen by clicking on the forum title.', 'bbpress' ) . '</li>' . | |
| 132 | + '<li>' . __( '<strong>Close</strong> will mark the selected forum as ’closed’ and disable the ability to post new topics and replies in it.', 'bbpress' ) . '</li>' . | |
| 133 | + '<li>' . __( '<strong>Trash</strong> removes your forum from this list and places it in the trash, from which you can permanently delete it.', 'bbpress' ) . '</li>' . | |
| 134 | + '<li>' . __( '<strong>View</strong> will either show you what your draft forum will look like if you publish it, or take you to your live site to view it. Which link depends on your forum’s status.', 'bbpress' ) . '</li>' . | |
| 135 | + '</ul>' | |
| 136 | + ) | |
| 137 | + ); | |
| 150 | 138 | |
| 151 | 139 | // Bulk Actions |
| 152 | - get_current_screen()->add_help_tab( array( | |
| 153 | - 'id' => 'bulk-actions', | |
| 154 | - 'title' => __( 'Bulk Actions', 'bbpress' ), | |
| 155 | - 'content' => | |
| 156 | - '<p>' . __( 'You can also edit or move multiple forums to the trash at once. Select the forums you want to act on using the checkboxes, then select the action you want to take from the Bulk Actions menu and click Apply.', 'bbpress' ) . '</p>' . | |
| 157 | - '<p>' . __( 'When using Bulk Edit, you can change the metadata (categories, author, etc.) for all selected forums at once. To remove a forum from the grouping, just click the x next to its name in the Bulk Edit area that appears.', 'bbpress' ) . '</p>' | |
| 158 | - ) ); | |
| 140 | + get_current_screen()->add_help_tab( | |
| 141 | + array( | |
| 142 | + 'id' => 'bulk-actions', | |
| 143 | + 'title' => __( 'Bulk Actions', 'bbpress' ), | |
| 144 | + 'content' => | |
| 145 | + '<p>' . __( 'You can also edit or move multiple forums to the trash at once. Select the forums you want to act on using the checkboxes, then select the action you want to take from the Bulk Actions menu and click Apply.', 'bbpress' ) . '</p>' . | |
| 146 | + '<p>' . __( 'When using Bulk Edit, you can change the metadata (categories, author, etc.) for all selected forums at once. To remove a forum from the grouping, just click the x next to its name in the Bulk Edit area that appears.', 'bbpress' ) . '</p>' | |
| 147 | + ) | |
| 148 | + ); | |
| 159 | 149 | |
| 160 | 150 | // Help Sidebar |
| 161 | 151 | get_current_screen()->set_help_sidebar( |
| 162 | 152 | '<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' . |
| 163 | - '<p>' . __( '<a href="http://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' . | |
| 164 | - '<p>' . __( '<a href="http://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>' | |
| 153 | + '<p>' . __( '<a href="https://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' . | |
| 154 | + '<p>' . __( '<a href="https://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>' | |
| 165 | 155 | ); |
| 166 | 156 | } |
| 167 | 157 | |
| 168 | 158 | /** |
| @@ -167,155 +157,208 @@ | ||
| 167 | 157 | |
| 168 | 158 | /** |
| 169 | 159 | * Contextual help for bbPress forum edit page |
| 170 | 160 | * |
| 171 | - * @since bbPress (r3119) | |
| 172 | - * @uses get_current_screen() | |
| 161 | + * @since 2.0.0 bbPress (r3119) | |
| 173 | 162 | */ |
| 174 | 163 | public function new_help() { |
| 175 | 164 | |
| 176 | - if ( $this->bail() ) return; | |
| 177 | - | |
| 178 | 165 | $customize_display = '<p>' . __( 'The title field and the big forum editing Area are fixed in place, but you can reposition all the other boxes using drag and drop, and can minimize or expand them by clicking the title bar of each box. Use the Screen Options tab to unhide more boxes (Excerpt, Send Trackbacks, Custom Fields, Discussion, Slug, Author) or to choose a 1- or 2-column layout for this screen.', 'bbpress' ) . '</p>'; |
| 179 | 166 | |
| 180 | - get_current_screen()->add_help_tab( array( | |
| 181 | - 'id' => 'customize-display', | |
| 182 | - 'title' => __( 'Customizing This Display', 'bbpress' ), | |
| 183 | - 'content' => $customize_display, | |
| 184 | - ) ); | |
| 167 | + get_current_screen()->add_help_tab( | |
| 168 | + array( | |
| 169 | + 'id' => 'customize-display', | |
| 170 | + 'title' => __( 'Customizing This Display', 'bbpress' ), | |
| 171 | + 'content' => $customize_display, | |
| 172 | + ) | |
| 173 | + ); | |
| 185 | 174 | |
| 186 | - get_current_screen()->add_help_tab( array( | |
| 187 | - 'id' => 'title-forum-editor', | |
| 188 | - 'title' => __( 'Title and Forum Editor', 'bbpress' ), | |
| 189 | - 'content' => | |
| 190 | - '<p>' . __( '<strong>Title</strong> - Enter a title for your forum. After you enter a title, you’ll see the permalink below, which you can edit.', 'bbpress' ) . '</p>' . | |
| 191 | - '<p>' . __( '<strong>Forum Editor</strong> - Enter the text for your forum. There are two modes of editing: Visual and HTML. Choose the mode by clicking on the appropriate tab. Visual mode gives you a WYSIWYG editor. Click the last icon in the row to get a second row of controls. The HTML mode allows you to enter raw HTML along with your forum text. You can insert media files by clicking the icons above the forum editor and following the directions. You can go to the distraction-free writing screen via the Fullscreen icon in Visual mode (second to last in the top row) or the Fullscreen button in HTML mode (last in the row). Once there, you can make buttons visible by hovering over the top area. Exit Fullscreen back to the regular forum editor.', 'bbpress' ) . '</p>' | |
| 192 | - ) ); | |
| 175 | + get_current_screen()->add_help_tab( | |
| 176 | + array( | |
| 177 | + 'id' => 'title-forum-editor', | |
| 178 | + 'title' => __( 'Title and Forum Editor', 'bbpress' ), | |
| 179 | + 'content' => | |
| 180 | + '<p>' . __( '<strong>Title</strong> - Enter a title for your forum. After you enter a title, you’ll see the permalink below, which you can edit.', 'bbpress' ) . '</p>' . | |
| 181 | + '<p>' . __( '<strong>Forum Editor</strong> - Enter the text for your forum. There are two modes of editing: Visual and HTML. Choose the mode by clicking on the appropriate tab. Visual mode gives you a WYSIWYG editor. Click the last icon in the row to get a second row of controls. The HTML mode allows you to enter raw HTML along with your forum text. You can insert media files by clicking the icons above the forum editor and following the directions. You can go to the distraction-free writing screen via the Fullscreen icon in Visual mode (second to last in the top row) or the Fullscreen button in HTML mode (last in the row). Once there, you can make buttons visible by hovering over the top area. Exit Fullscreen back to the regular forum editor.', 'bbpress' ) . '</p>' | |
| 182 | + ) | |
| 183 | + ); | |
| 193 | 184 | |
| 194 | 185 | $publish_box = '<p>' . __( '<strong>Publish</strong> - You can set the terms of publishing your forum in the Publish box. For Status, Visibility, and Publish (immediately), click on the Edit link to reveal more options. Visibility includes options for password-protecting a forum or making it stay at the top of your blog indefinitely (sticky). Publish (immediately) allows you to set a future or past date and time, so you can schedule a forum to be published in the future or backdate a forum.', 'bbpress' ) . '</p>'; |
| 195 | 186 | |
| 196 | - if ( current_theme_supports( 'forum-formats' ) && forum_type_supports( 'forum', 'forum-formats' ) ) { | |
| 197 | - $publish_box .= '<p>' . __( '<strong>forum Format</strong> - This designates how your theme will display a specific forum. For example, you could have a <em>standard</em> blog forum with a title and paragraphs, or a short <em>aside</em> that omits the title and contains a short text blurb. Please refer to the Codex for <a href="http://codex.wordpress.org/Post_Formats#Supported_Formats">descriptions of each forum format</a>. Your theme could enable all or some of 10 possible formats.', 'bbpress' ) . '</p>'; | |
| 198 | - } | |
| 199 | - | |
| 200 | - if ( current_theme_supports( 'forum-thumbnails' ) && forum_type_supports( 'forum', 'thumbnail' ) ) { | |
| 187 | + if ( current_theme_supports( 'forum-thumbnails' ) && post_type_supports( 'forum', 'thumbnail' ) ) { | |
| 201 | 188 | $publish_box .= '<p>' . __( '<strong>Featured Image</strong> - This allows you to associate an image with your forum without inserting it. This is usually useful only if your theme makes use of the featured image as a forum thumbnail on the home page, a custom header, etc.', 'bbpress' ) . '</p>'; |
| 202 | 189 | } |
| 203 | 190 | |
| 204 | - get_current_screen()->add_help_tab( array( | |
| 205 | - 'id' => 'forum-attributes', | |
| 206 | - 'title' => __( 'Forum Attributes', 'bbpress' ), | |
| 207 | - 'content' => | |
| 208 | - '<p>' . __( 'Select the attributes that your forum should have:', 'bbpress' ) . '</p>' . | |
| 209 | - '<ul>' . | |
| 210 | - '<li>' . __( '<strong>Type</strong> indicates if the forum is a category or forum. Categories generally contain other forums.', 'bbpress' ) . '</li>' . | |
| 211 | - '<li>' . __( '<strong>Status</strong> allows you to close a forum to new topics and forums.', 'bbpress' ) . '</li>' . | |
| 212 | - '<li>' . __( '<strong>Visibility</strong> lets you pick the scope of each forum and what users are allowed to access it.', 'bbpress' ) . '</li>' . | |
| 213 | - '<li>' . __( '<strong>Parent</strong> dropdown determines the parent forum. Select the forum or category from the dropdown, or leave the default (No Parent) to create the forum at the root of your forums.', 'bbpress' ) . '</li>' . | |
| 214 | - '<li>' . __( '<strong>Order</strong> allows you to order your forums numerically.', 'bbpress' ) . '</li>' . | |
| 215 | - '</ul>' | |
| 216 | - ) ); | |
| 191 | + get_current_screen()->add_help_tab( | |
| 192 | + array( | |
| 193 | + 'id' => 'forum-attributes', | |
| 194 | + 'title' => __( 'Forum Attributes', 'bbpress' ), | |
| 195 | + 'content' => | |
| 196 | + '<p>' . __( 'Select the attributes that your forum should have:', 'bbpress' ) . '</p>' . | |
| 197 | + '<ul>' . | |
| 198 | + '<li>' . __( '<strong>Type</strong> indicates if the forum is a category or forum. Categories generally contain other forums.', 'bbpress' ) . '</li>' . | |
| 199 | + '<li>' . __( '<strong>Status</strong> allows you to close a forum to new topics and forums.', 'bbpress' ) . '</li>' . | |
| 200 | + '<li>' . __( '<strong>Visibility</strong> lets you pick the scope of each forum and what users are allowed to access it.', 'bbpress' ) . '</li>' . | |
| 201 | + '<li>' . __( '<strong>Parent</strong> dropdown determines the parent forum. Select the forum or category from the dropdown, or leave the default "No parent" to create the forum at the root of your forums.', 'bbpress' ) . '</li>' . | |
| 202 | + '<li>' . __( '<strong>Order</strong> allows you to order your forums numerically.', 'bbpress' ) . '</li>' . | |
| 203 | + '</ul>' | |
| 204 | + ) | |
| 205 | + ); | |
| 217 | 206 | |
| 218 | - get_current_screen()->add_help_tab( array( | |
| 219 | - 'id' => 'publish-box', | |
| 220 | - 'title' => __( 'Publish Box', 'bbpress' ), | |
| 221 | - 'content' => $publish_box, | |
| 222 | - ) ); | |
| 207 | + get_current_screen()->add_help_tab( | |
| 208 | + array( | |
| 209 | + 'id' => 'publish-box', | |
| 210 | + 'title' => __( 'Publish Box', 'bbpress' ), | |
| 211 | + 'content' => $publish_box, | |
| 212 | + ) | |
| 213 | + ); | |
| 223 | 214 | |
| 224 | - get_current_screen()->add_help_tab( array( | |
| 225 | - 'id' => 'discussion-settings', | |
| 226 | - 'title' => __( 'Discussion Settings', 'bbpress' ), | |
| 227 | - 'content' => | |
| 228 | - '<p>' . __( '<strong>Send Trackbacks</strong> - Trackbacks are a way to notify legacy blog systems that you’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>' . | |
| 229 | - '<p>' . __( '<strong>Discussion</strong> - You can turn comments and pings on or off, and if there are comments on the forum, you can see them here and moderate them.', 'bbpress' ) . '</p>' | |
| 230 | - ) ); | |
| 231 | - | |
| 232 | 215 | get_current_screen()->set_help_sidebar( |
| 233 | 216 | '<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' . |
| 234 | - '<p>' . __( '<a href="http://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' . | |
| 235 | - '<p>' . __( '<a href="http://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>' | |
| 217 | + '<p>' . __( '<a href="https://codex.bbpress.org" target="_blank">bbPress Documentation</a>', 'bbpress' ) . '</p>' . | |
| 218 | + '<p>' . __( '<a href="https://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>' | |
| 236 | 219 | ); |
| 237 | 220 | } |
| 238 | 221 | |
| 239 | 222 | /** |
| 240 | - * Add the forum attributes metabox | |
| 223 | + * Add the forum attributes meta-box | |
| 241 | 224 | * |
| 242 | - * @since bbPress (r2746) | |
| 243 | - * | |
| 244 | - * @uses bbp_get_forum_post_type() To get the forum post type | |
| 245 | - * @uses add_meta_box() To add the metabox | |
| 246 | - * @uses do_action() Calls 'bbp_forum_attributes_metabox' | |
| 225 | + * @since 2.0.0 bbPress (r2746) | |
| 247 | 226 | */ |
| 248 | 227 | public function attributes_metabox() { |
| 249 | 228 | |
| 250 | - if ( $this->bail() ) return; | |
| 229 | + // Bail if the current user cannot edit forum structure | |
| 230 | + if ( ! current_user_can( 'assign_moderators' ) ) { | |
| 231 | + return; | |
| 232 | + } | |
| 251 | 233 | |
| 252 | - add_meta_box ( | |
| 234 | + add_meta_box( | |
| 253 | 235 | 'bbp_forum_attributes', |
| 254 | - __( 'Forum Attributes', 'bbpress' ), | |
| 236 | + esc_html__( 'Forum Attributes', 'bbpress' ), | |
| 255 | 237 | 'bbp_forum_metabox', |
| 256 | 238 | $this->post_type, |
| 257 | 239 | 'side', |
| 258 | 240 | 'high' |
| 259 | 241 | ); |
| 242 | + } | |
| 260 | 243 | |
| 261 | - do_action( 'bbp_forum_attributes_metabox' ); | |
| 244 | + /** | |
| 245 | + * Add the forum moderators meta-box | |
| 246 | + * | |
| 247 | + * @since 2.6.0 bbPress | |
| 248 | + */ | |
| 249 | + public function moderators_metabox() { | |
| 250 | + | |
| 251 | + // Bail if feature not active or user cannot assign moderators | |
| 252 | + if ( ! bbp_allow_forum_mods() || ! current_user_can( 'assign_moderators' ) ) { | |
| 253 | + return; | |
| 254 | + } | |
| 255 | + | |
| 256 | + // Moderators | |
| 257 | + add_meta_box( | |
| 258 | + 'bbp_moderator_assignment_metabox', | |
| 259 | + esc_html__( 'Forum Moderators', 'bbpress' ), | |
| 260 | + 'bbp_moderator_assignment_metabox', | |
| 261 | + $this->post_type, | |
| 262 | + 'side', | |
| 263 | + 'high' | |
| 264 | + ); | |
| 262 | 265 | } |
| 263 | 266 | |
| 264 | 267 | /** |
| 268 | + * Add the subscriptions meta-box | |
| 269 | + * | |
| 270 | + * Allows viewing of users who have subscribed to a forum. | |
| 271 | + * | |
| 272 | + * @since 2.6.0 bbPress (r6197) | |
| 273 | + */ | |
| 274 | + public function subscriptions_metabox() { | |
| 275 | + | |
| 276 | + // Bail if post_type is not a reply | |
| 277 | + if ( empty( $_GET['action'] ) || ( 'edit' !== $_GET['action'] ) ) { | |
| 278 | + return; | |
| 279 | + } | |
| 280 | + | |
| 281 | + // Bail if no subscriptions | |
| 282 | + if ( ! bbp_is_subscriptions_active() ) { | |
| 283 | + return; | |
| 284 | + } | |
| 285 | + | |
| 286 | + // Add the meta-box | |
| 287 | + add_meta_box( | |
| 288 | + 'bbp_forum_subscriptions_metabox', | |
| 289 | + esc_html__( 'Subscriptions', 'bbpress' ), | |
| 290 | + 'bbp_forum_subscriptions_metabox', | |
| 291 | + $this->post_type, | |
| 292 | + 'normal', | |
| 293 | + 'high' | |
| 294 | + ); | |
| 295 | + } | |
| 296 | + | |
| 297 | + /** | |
| 298 | + * Remove comments & discussion meta-boxes if comments are not supported | |
| 299 | + * | |
| 300 | + * @since 2.6.0 bbPress (r6186) | |
| 301 | + */ | |
| 302 | + public function comments_metabox() { | |
| 303 | + if ( ! post_type_supports( $this->post_type, 'comments' ) ) { | |
| 304 | + remove_meta_box( 'commentstatusdiv', $this->post_type, 'normal' ); | |
| 305 | + remove_meta_box( 'commentsdiv', $this->post_type, 'normal' ); | |
| 306 | + } | |
| 307 | + } | |
| 308 | + | |
| 309 | + /** | |
| 265 | 310 | * Pass the forum attributes for processing |
| 266 | 311 | * |
| 267 | - * @since bbPress (r2746) | |
| 312 | + * @since 2.0.0 bbPress (r2746) | |
| 268 | 313 | * |
| 269 | 314 | * @param int $forum_id Forum id |
| 270 | - * @uses current_user_can() To check if the current user is capable of | |
| 271 | - * editing the forum | |
| 272 | - * @uses bbp_get_forum() To get the forum | |
| 273 | - * @uses bbp_is_forum_closed() To check if the forum is closed | |
| 274 | - * @uses bbp_is_forum_category() To check if the forum is a category | |
| 275 | - * @uses bbp_is_forum_private() To check if the forum is private | |
| 276 | - * @uses bbp_close_forum() To close the forum | |
| 277 | - * @uses bbp_open_forum() To open the forum | |
| 278 | - * @uses bbp_categorize_forum() To make the forum a category | |
| 279 | - * @uses bbp_normalize_forum() To make the forum normal (not category) | |
| 280 | - * @uses bbp_privatize_forum() To mark the forum as private | |
| 281 | - * @uses bbp_publicize_forum() To mark the forum as public | |
| 282 | - * @uses do_action() Calls 'bbp_forum_attributes_metabox_save' with the | |
| 283 | - * forum id | |
| 284 | 315 | * @return int Forum id |
| 285 | 316 | */ |
| 286 | - public function attributes_metabox_save( $forum_id ) { | |
| 317 | + public function save_meta_boxes( $forum_id ) { | |
| 287 | 318 | |
| 288 | - if ( $this->bail() ) return $forum_id; | |
| 289 | - | |
| 290 | 319 | // Bail if doing an autosave |
| 291 | - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) | |
| 320 | + if ( bbp_doing_autosave() ) { | |
| 292 | 321 | return $forum_id; |
| 322 | + } | |
| 293 | 323 | |
| 294 | 324 | // Bail if not a post request |
| 295 | - if ( 'POST' != strtoupper( $_SERVER['REQUEST_METHOD'] ) ) | |
| 325 | + if ( ! bbp_is_post_request() ) { | |
| 296 | 326 | return $forum_id; |
| 327 | + } | |
| 297 | 328 | |
| 298 | 329 | // Nonce check |
| 299 | - if ( empty( $_POST['bbp_forum_metabox'] ) || !wp_verify_nonce( $_POST['bbp_forum_metabox'], 'bbp_forum_metabox_save' ) ) | |
| 330 | + if ( empty( $_POST['bbp_forum_metabox'] ) || ! wp_verify_nonce( $_POST['bbp_forum_metabox'], 'bbp_forum_metabox_save' ) ) { | |
| 300 | 331 | return $forum_id; |
| 332 | + } | |
| 301 | 333 | |
| 302 | 334 | // Only save for forum post-types |
| 303 | - if ( ! bbp_is_forum( $forum_id ) ) | |
| 335 | + if ( ! bbp_is_forum( $forum_id ) ) { | |
| 304 | 336 | return $forum_id; |
| 337 | + } | |
| 305 | 338 | |
| 306 | 339 | // Bail if current user cannot edit this forum |
| 307 | - if ( !current_user_can( 'edit_forum', $forum_id ) ) | |
| 340 | + if ( ! current_user_can( 'edit_forum', $forum_id ) ) { | |
| 308 | 341 | return $forum_id; |
| 342 | + } | |
| 309 | 343 | |
| 344 | + // Bail if current user cannot edit forum structure | |
| 345 | + if ( ! current_user_can( 'assign_moderators' ) ) { | |
| 346 | + return $forum_id; | |
| 347 | + } | |
| 348 | + | |
| 310 | 349 | // Parent ID |
| 311 | - $parent_id = ( !empty( $_POST['parent_id'] ) && is_numeric( $_POST['parent_id'] ) ) ? (int) $_POST['parent_id'] : 0; | |
| 350 | + $parent_id = ( ! empty( $_POST['parent_id'] ) && is_numeric( $_POST['parent_id'] ) ) | |
| 351 | + ? (int) $_POST['parent_id'] | |
| 352 | + : 0; | |
| 312 | 353 | |
| 313 | 354 | // Update the forum meta bidness |
| 314 | - bbp_update_forum( array( | |
| 315 | - 'forum_id' => $forum_id, | |
| 316 | - 'post_parent' => (int) $parent_id | |
| 317 | - ) ); | |
| 355 | + bbp_update_forum( | |
| 356 | + array( | |
| 357 | + 'forum_id' => $forum_id, | |
| 358 | + 'post_parent' => $parent_id | |
| 359 | + ) | |
| 360 | + ); | |
| 318 | 361 | |
| 319 | 362 | do_action( 'bbp_forum_attributes_metabox_save', $forum_id ); |
| 320 | 363 | |
| 321 | 364 | return $forum_id; |
| @@ -321,111 +364,246 @@ | ||
| 321 | 364 | return $forum_id; |
| 322 | 365 | } |
| 323 | 366 | |
| 324 | 367 | /** |
| 325 | - * Add some general styling to the admin area | |
| 368 | + * Toggle forum | |
| 326 | 369 | * |
| 327 | - * @since bbPress (r2464) | |
| 370 | + * Handles the admin-side opening/closing of forums | |
| 328 | 371 | * |
| 329 | - * @uses bbp_get_forum_post_type() To get the forum post type | |
| 330 | - * @uses bbp_get_topic_post_type() To get the topic post type | |
| 331 | - * @uses bbp_get_reply_post_type() To get the reply post type | |
| 332 | - * @uses sanitize_html_class() To sanitize the classes | |
| 333 | - * @uses do_action() Calls 'bbp_admin_head' | |
| 372 | + * @since 2.6.0 bbPress (r5254) | |
| 334 | 373 | */ |
| 335 | - public function admin_head() { | |
| 374 | + public function toggle_forum() { | |
| 336 | 375 | |
| 337 | - if ( $this->bail() ) return; | |
| 376 | + // Bail if not a forum toggle action | |
| 377 | + if ( ! bbp_is_get_request() || empty( $_GET['action'] ) || empty( $_GET['forum_id'] ) ) { | |
| 378 | + return; | |
| 379 | + } | |
| 338 | 380 | |
| 339 | - ?> | |
| 381 | + // Bail if not an allowed action | |
| 382 | + $action = sanitize_key( $_GET['action'] ); | |
| 383 | + if ( empty( $action ) || ! in_array( $action, $this->get_allowed_action_toggles(), true ) ) { | |
| 384 | + return; | |
| 385 | + } | |
| 340 | 386 | |
| 341 | - <style type="text/css" media="screen"> | |
| 342 | - /*<![CDATA[*/ | |
| 387 | + // Bail if forum is missing | |
| 388 | + $forum_id = bbp_get_forum_id( $_GET['forum_id'] ); | |
| 389 | + if ( ! bbp_get_forum( $forum_id ) ) { | |
| 390 | + wp_die( esc_html__( 'The forum was not found.', 'bbpress' ) ); | |
| 391 | + } | |
| 343 | 392 | |
| 344 | - #misc-publishing-actions, | |
| 345 | - #save-post { | |
| 346 | - display: none; | |
| 347 | - } | |
| 393 | + // What is the user doing here? | |
| 394 | + if ( ! current_user_can( 'manage_forum_attributes', $forum_id ) ) { | |
| 395 | + wp_die( esc_html__( 'You do not have permission to do that.', 'bbpress' ) ); | |
| 396 | + } | |
| 348 | 397 | |
| 349 | - strong.label { | |
| 350 | - display: inline-block; | |
| 351 | - width: 60px; | |
| 352 | - } | |
| 398 | + // Defaults | |
| 399 | + $post_data = array( 'ID' => $forum_id ); | |
| 400 | + $message = ''; | |
| 401 | + $success = false; | |
| 353 | 402 | |
| 354 | - #bbp_forum_attributes hr { | |
| 355 | - border-style: solid; | |
| 356 | - border-width: 1px; | |
| 357 | - border-color: #ccc #fff #fff #ccc; | |
| 358 | - } | |
| 403 | + switch ( $action ) { | |
| 404 | + case 'bbp_toggle_forum_close' : | |
| 405 | + check_admin_referer( 'close-forum_' . $forum_id ); | |
| 359 | 406 | |
| 360 | - .column-bbp_forum_topic_count, | |
| 361 | - .column-bbp_forum_reply_count, | |
| 362 | - .column-bbp_topic_reply_count, | |
| 363 | - .column-bbp_topic_voice_count { | |
| 364 | - width: 8% !important; | |
| 365 | - } | |
| 407 | + $is_open = bbp_is_forum_open( $forum_id ); | |
| 408 | + $message = ( true === $is_open ) | |
| 409 | + ? 'closed' | |
| 410 | + : 'opened'; | |
| 411 | + $success = ( true === $is_open ) | |
| 412 | + ? bbp_close_forum( $forum_id ) | |
| 413 | + : bbp_open_forum( $forum_id ); | |
| 366 | 414 | |
| 367 | - .column-author, | |
| 368 | - .column-bbp_reply_author, | |
| 369 | - .column-bbp_topic_author { | |
| 370 | - width: 10% !important; | |
| 371 | - } | |
| 415 | + break; | |
| 416 | + } | |
| 372 | 417 | |
| 373 | - .column-bbp_topic_forum, | |
| 374 | - .column-bbp_reply_forum, | |
| 375 | - .column-bbp_reply_topic { | |
| 376 | - width: 10% !important; | |
| 377 | - } | |
| 418 | + // Setup the message | |
| 419 | + $retval = array( | |
| 420 | + 'bbp_forum_toggle_notice' => $message, | |
| 421 | + 'forum_id' => $forum_id | |
| 422 | + ); | |
| 378 | 423 | |
| 379 | - .column-bbp_forum_freshness, | |
| 380 | - .column-bbp_topic_freshness { | |
| 381 | - width: 10% !important; | |
| 382 | - } | |
| 424 | + // Prepare for failure | |
| 425 | + if ( ( false === $success ) || is_wp_error( $success ) ) { | |
| 426 | + $retval['failed'] = '1'; | |
| 427 | + } | |
| 383 | 428 | |
| 384 | - .column-bbp_forum_created, | |
| 385 | - .column-bbp_topic_created, | |
| 386 | - .column-bbp_reply_created { | |
| 387 | - width: 15% !important; | |
| 388 | - } | |
| 429 | + // Filter all message args | |
| 430 | + $retval = apply_filters( 'bbp_toggle_forum_action_admin', $retval, $forum_id, $action ); | |
| 389 | 431 | |
| 390 | - .status-closed { | |
| 391 | - background-color: #eaeaea; | |
| 392 | - } | |
| 432 | + // Do additional forum toggle actions (admin side) | |
| 433 | + do_action( 'bbp_toggle_forum_admin', $success, $post_data, $action, $retval ); | |
| 393 | 434 | |
| 394 | - .status-spam { | |
| 395 | - background-color: #faeaea; | |
| 396 | - } | |
| 435 | + // Redirect back to the forum | |
| 436 | + $redirect = add_query_arg( $retval, remove_query_arg( array( 'action', 'forum_id' ) ) ); | |
| 437 | + bbp_redirect( $redirect ); | |
| 438 | + } | |
| 397 | 439 | |
| 398 | - /*]]>*/ | |
| 399 | - </style> | |
| 440 | + /** | |
| 441 | + * Toggle forum notices | |
| 442 | + * | |
| 443 | + * Display the success/error notices from | |
| 444 | + * {@link BBP_Admin::toggle_forum()} | |
| 445 | + * | |
| 446 | + * @since 2.6.0 bbPress (r5254) | |
| 447 | + */ | |
| 448 | + public function toggle_forum_notice() { | |
| 400 | 449 | |
| 401 | - <?php | |
| 450 | + // Bail if missing forum toggle action | |
| 451 | + if ( ! bbp_is_get_request() || empty( $_GET['forum_id'] ) || empty( $_GET['bbp_forum_toggle_notice'] ) ) { | |
| 452 | + return; | |
| 453 | + } | |
| 454 | + | |
| 455 | + // Bail if not an allowed notice | |
| 456 | + $notice = sanitize_key( $_GET['bbp_forum_toggle_notice'] ); | |
| 457 | + if ( empty( $notice ) || ! in_array( $notice, $this->get_allowed_notice_toggles(), true ) ) { | |
| 458 | + return; | |
| 459 | + } | |
| 460 | + | |
| 461 | + // Bail if no forum_id or notice | |
| 462 | + $forum_id = bbp_get_forum_id( $_GET['forum_id'] ); | |
| 463 | + if ( empty( $forum_id ) ) { | |
| 464 | + return; | |
| 465 | + } | |
| 466 | + | |
| 467 | + // Bail if forum is missing | |
| 468 | + if ( ! bbp_get_forum( $forum_id ) ) { | |
| 469 | + return; | |
| 470 | + } | |
| 471 | + | |
| 472 | + // Use the title in the responses | |
| 473 | + $forum_title = bbp_get_forum_title( $forum_id ); | |
| 474 | + $is_failure = ! empty( $_GET['failed'] ); | |
| 475 | + $message = ''; | |
| 476 | + | |
| 477 | + switch ( $notice ) { | |
| 478 | + case 'opened' : | |
| 479 | + $message = ( true === $is_failure ) | |
| 480 | + /* translators: %1$s: Forum title */ | |
| 481 | + ? sprintf( esc_html__( 'There was a problem opening the forum "%1$s".', 'bbpress' ), $forum_title ) | |
| 482 | + /* translators: %1$s: Forum title */ | |
| 483 | + : sprintf( esc_html__( 'Forum "%1$s" successfully opened.', 'bbpress' ), $forum_title ); | |
| 484 | + break; | |
| 485 | + | |
| 486 | + case 'closed' : | |
| 487 | + $message = ( true === $is_failure ) | |
| 488 | + /* translators: %1$s: Forum title */ | |
| 489 | + ? sprintf( esc_html__( 'There was a problem closing the forum "%1$s".', 'bbpress' ), $forum_title ) | |
| 490 | + /* translators: %1$s: Forum title */ | |
| 491 | + : sprintf( esc_html__( 'Forum "%1$s" successfully closed.', 'bbpress' ), $forum_title ); | |
| 492 | + break; | |
| 493 | + } | |
| 494 | + | |
| 495 | + // Do additional forum toggle notice filters (admin side) | |
| 496 | + $message = apply_filters( 'bbp_toggle_forum_notice_admin', $message, $forum_id, $notice, $is_failure ); | |
| 497 | + $class = ( true === $is_failure ) | |
| 498 | + ? 'error' | |
| 499 | + : 'updated'; | |
| 500 | + | |
| 501 | + // Add the notice | |
| 502 | + bbp_admin()->add_notice( $message, $class, true ); | |
| 402 | 503 | } |
| 403 | 504 | |
| 404 | 505 | /** |
| 506 | + * Returns an array of keys used to sort row actions | |
| 507 | + * | |
| 508 | + * @since 2.6.0 bbPress (r6771) | |
| 509 | + * | |
| 510 | + * @return array | |
| 511 | + */ | |
| 512 | + private function get_row_action_sort_order() { | |
| 513 | + | |
| 514 | + /** | |
| 515 | + * Filters the row action sort order. | |
| 516 | + * | |
| 517 | + * @since 2.6.0 bbPress (r6771) | |
| 518 | + * | |
| 519 | + * @param array $order The default sort order. | |
| 520 | + */ | |
| 521 | + return (array) apply_filters( | |
| 522 | + 'bbp_admin_forum_row_action_sort_order', | |
| 523 | + array( | |
| 524 | + 'edit', | |
| 525 | + 'closed', | |
| 526 | + 'trash', | |
| 527 | + 'untrash', | |
| 528 | + 'delete', | |
| 529 | + 'view' | |
| 530 | + ) | |
| 531 | + ); | |
| 532 | + } | |
| 533 | + | |
| 534 | + /** | |
| 535 | + * Returns an array of notice toggles | |
| 536 | + * | |
| 537 | + * @since 2.6.0 bbPress (r6396) | |
| 538 | + * | |
| 539 | + * @return array | |
| 540 | + */ | |
| 541 | + private function get_allowed_notice_toggles() { | |
| 542 | + | |
| 543 | + // Filter & return | |
| 544 | + return apply_filters( | |
| 545 | + 'bbp_admin_forums_allowed_notice_toggles', | |
| 546 | + array( | |
| 547 | + 'opened', | |
| 548 | + 'closed' | |
| 549 | + ) | |
| 550 | + ); | |
| 551 | + } | |
| 552 | + | |
| 553 | + /** | |
| 554 | + * Returns an array of notice toggles | |
| 555 | + * | |
| 556 | + * @since 2.6.0 bbPress (r6396) | |
| 557 | + * | |
| 558 | + * @return array | |
| 559 | + */ | |
| 560 | + private function get_allowed_action_toggles() { | |
| 561 | + | |
| 562 | + /** | |
| 563 | + * Filters the allowed action toggles. | |
| 564 | + * | |
| 565 | + * @since 2.6.0 bbPress (r6396) | |
| 566 | + * | |
| 567 | + * @param array $toggles The default action toggles. | |
| 568 | + */ | |
| 569 | + return apply_filters( | |
| 570 | + 'bbp_admin_forums_allowed_action_toggles', | |
| 571 | + array( | |
| 572 | + 'bbp_toggle_forum_close' | |
| 573 | + ) | |
| 574 | + ); | |
| 575 | + } | |
| 576 | + | |
| 577 | + /** | |
| 405 | 578 | * Manage the column headers for the forums page |
| 406 | 579 | * |
| 407 | - * @since bbPress (r2485) | |
| 580 | + * @since 2.0.0 bbPress (r2485) | |
| 408 | 581 | * |
| 409 | 582 | * @param array $columns The columns |
| 410 | - * @uses apply_filters() Calls 'bbp_admin_forums_column_headers' with | |
| 411 | - * the columns | |
| 583 | + * | |
| 412 | 584 | * @return array $columns bbPress forum columns |
| 413 | 585 | */ |
| 414 | 586 | public function column_headers( $columns ) { |
| 415 | 587 | |
| 416 | - if ( $this->bail() ) return $columns; | |
| 417 | - | |
| 418 | - $columns = array ( | |
| 588 | + // Set list table column headers | |
| 589 | + $columns = array( | |
| 419 | 590 | 'cb' => '<input type="checkbox" />', |
| 420 | - 'title' => __( 'Forum', 'bbpress' ), | |
| 421 | - 'bbp_forum_topic_count' => __( 'Topics', 'bbpress' ), | |
| 422 | - 'bbp_forum_reply_count' => __( 'Replies', 'bbpress' ), | |
| 423 | - 'author' => __( 'Creator', 'bbpress' ), | |
| 424 | - 'bbp_forum_created' => __( 'Created' , 'bbpress' ), | |
| 425 | - 'bbp_forum_freshness' => __( 'Freshness', 'bbpress' ) | |
| 591 | + 'title' => esc_html__( 'Forum', 'bbpress' ), | |
| 592 | + 'bbp_forum_topic_count' => esc_html__( 'Topics', 'bbpress' ), | |
| 593 | + 'bbp_forum_reply_count' => esc_html__( 'Replies', 'bbpress' ), | |
| 594 | + 'bbp_forum_mods' => esc_html__( 'Moderators', 'bbpress' ), | |
| 595 | + 'author' => esc_html__( 'Creator', 'bbpress' ), | |
| 596 | + 'bbp_forum_created' => esc_html__( 'Created', 'bbpress' ), | |
| 597 | + 'bbp_forum_freshness' => esc_html__( 'Last Post', 'bbpress' ) | |
| 426 | 598 | ); |
| 427 | 599 | |
| 600 | + // Remove forum mods column if not enabled | |
| 601 | + if ( ! bbp_allow_forum_mods() ) { | |
| 602 | + unset( $columns['bbp_forum_mods'] ); | |
| 603 | + } | |
| 604 | + | |
| 605 | + // Filter & return | |
| 428 | 606 | return apply_filters( 'bbp_admin_forums_column_headers', $columns ); |
| 429 | 607 | } |
| 430 | 608 | |
| 431 | 609 | /** |
| @@ -430,26 +608,15 @@ | ||
| 430 | 608 | |
| 431 | 609 | /** |
| 432 | 610 | * Print extra columns for the forums page |
| 433 | 611 | * |
| 434 | - * @since bbPress (r2485) | |
| 612 | + * @since 2.0.0 bbPress (r2485) | |
| 435 | 613 | * |
| 436 | 614 | * @param string $column Column |
| 437 | 615 | * @param int $forum_id Forum id |
| 438 | - * @uses bbp_forum_topic_count() To output the forum topic count | |
| 439 | - * @uses bbp_forum_reply_count() To output the forum reply count | |
| 440 | - * @uses get_the_date() Get the forum creation date | |
| 441 | - * @uses get_the_time() Get the forum creation time | |
| 442 | - * @uses esc_attr() To sanitize the forum creation time | |
| 443 | - * @uses bbp_get_forum_last_active_time() To get the time when the forum was | |
| 444 | - * last active | |
| 445 | - * @uses do_action() Calls 'bbp_admin_forums_column_data' with the | |
| 446 | - * column and forum id | |
| 447 | 616 | */ |
| 448 | 617 | public function column_data( $column, $forum_id ) { |
| 449 | 618 | |
| 450 | - if ( $this->bail() ) return; | |
| 451 | - | |
| 452 | 619 | switch ( $column ) { |
| 453 | 620 | case 'bbp_forum_topic_count' : |
| 454 | 621 | bbp_forum_topic_count( $forum_id ); |
| 455 | 622 | break; |
| @@ -457,10 +624,22 @@ | ||
| 457 | 624 | case 'bbp_forum_reply_count' : |
| 458 | 625 | bbp_forum_reply_count( $forum_id ); |
| 459 | 626 | break; |
| 460 | 627 | |
| 628 | + case 'bbp_forum_mods' : | |
| 629 | + bbp_moderator_list( | |
| 630 | + $forum_id, | |
| 631 | + array( | |
| 632 | + 'before' => '', | |
| 633 | + 'after' => '', | |
| 634 | + 'none' => esc_html__( '—', 'bbpress' ) | |
| 635 | + ) | |
| 636 | + ); | |
| 637 | + break; | |
| 638 | + | |
| 461 | 639 | case 'bbp_forum_created': |
| 462 | - printf( __( '%1$s <br /> %2$s', 'bbpress' ), | |
| 640 | + printf( | |
| 641 | + '%1$s <br /> %2$s', | |
| 463 | 642 | get_the_date(), |
| 464 | 643 | esc_attr( get_the_time() ) |
| 465 | 644 | ); |
| 466 | 645 | |
| @@ -467,12 +646,13 @@ | ||
| 467 | 646 | break; |
| 468 | 647 | |
| 469 | 648 | case 'bbp_forum_freshness' : |
| 470 | 649 | $last_active = bbp_get_forum_last_active_time( $forum_id, false ); |
| 471 | - if ( !empty( $last_active ) ) | |
| 472 | - echo $last_active; | |
| 473 | - else | |
| 474 | - _e( 'No Topics', 'bbpress' ); | |
| 650 | + if ( ! empty( $last_active ) ) { | |
| 651 | + echo esc_html( $last_active ); | |
| 652 | + } else { | |
| 653 | + esc_html_e( 'No Topics', 'bbpress' ); | |
| 654 | + } | |
| 475 | 655 | |
| 476 | 656 | break; |
| 477 | 657 | |
| 478 | 658 | default: |
| @@ -484,39 +664,91 @@ | ||
| 484 | 664 | /** |
| 485 | 665 | * Forum Row actions |
| 486 | 666 | * |
| 487 | 667 | * Remove the quick-edit action link and display the description under |
| 488 | - * the forum title | |
| 668 | + * the forum title and add the open/close links | |
| 489 | 669 | * |
| 490 | - * @since bbPress (r2577) | |
| 670 | + * @since 2.0.0 bbPress (r2577) | |
| 491 | 671 | * |
| 492 | - * @param array $actions Actions | |
| 493 | - * @param array $forum Forum object | |
| 494 | - * @uses the_content() To output forum description | |
| 672 | + * @param array $actions Actions | |
| 673 | + * @param object $forum Forum object | |
| 674 | + * | |
| 495 | 675 | * @return array $actions Actions |
| 496 | 676 | */ |
| 497 | - public function row_actions( $actions, $forum ) { | |
| 677 | + public function row_actions( $actions = array(), $forum = false ) { | |
| 498 | 678 | |
| 499 | - if ( $this->bail() ) return $actions; | |
| 679 | + // Disable quick edit (too much to do here) | |
| 680 | + unset( $actions['inline hide-if-no-js'] ); | |
| 500 | 681 | |
| 501 | - unset( $actions['inline hide-if-no-js'] ); | |
| 682 | + // Only show the actions if the user is capable of viewing them :) | |
| 683 | + if ( current_user_can( 'edit_forum', $forum->ID ) ) { | |
| 502 | 684 | |
| 503 | - // simple hack to show the forum description under the title | |
| 504 | - bbp_forum_content( $forum->ID ); | |
| 685 | + // Show the 'close' and 'open' link on published, private, hidden and closed posts only | |
| 686 | + if ( in_array( $forum->post_status, array( bbp_get_public_status_id(), bbp_get_private_status_id(), bbp_get_hidden_status_id(), bbp_get_closed_status_id() ), true ) ) { | |
| 687 | + $args = array( | |
| 688 | + 'forum_id' => $forum->ID, | |
| 689 | + 'action' => 'bbp_toggle_forum_close' | |
| 690 | + ); | |
| 691 | + $close_uri = wp_nonce_url( add_query_arg( $args, remove_query_arg( array( 'bbp_forum_toggle_notice', 'forum_id', 'failed', 'super' ) ) ), 'close-forum_' . $forum->ID ); | |
| 692 | + if ( bbp_is_forum_open( $forum->ID ) ) { | |
| 693 | + $actions['closed'] = '<a href="' . esc_url( $close_uri ) . '" title="' . esc_attr__( 'Close this forum', 'bbpress' ) . '">' . _x( 'Close', 'Close a Forum', 'bbpress' ) . '</a>'; | |
| 694 | + } else { | |
| 695 | + $actions['closed'] = '<a href="' . esc_url( $close_uri ) . '" title="' . esc_attr__( 'Open this forum', 'bbpress' ) . '">' . _x( 'Open', 'Open a Forum', 'bbpress' ) . '</a>'; | |
| 696 | + } | |
| 697 | + } | |
| 698 | + } | |
| 505 | 699 | |
| 506 | - return $actions; | |
| 700 | + // Only show content if user can read it and there is no password | |
| 701 | + if ( current_user_can( 'read_forum', $forum->ID ) && ! post_password_required( $forum ) ) { | |
| 702 | + | |
| 703 | + // Get the forum description | |
| 704 | + $content = bbp_get_forum_content( $forum->ID ); | |
| 705 | + | |
| 706 | + // Only proceed if there is a description | |
| 707 | + if ( ! empty( $content ) ) { | |
| 708 | + echo '<div class="bbp-escaped-content">' . esc_html( wp_trim_excerpt( $content, $forum ) ) . '</div>'; | |
| 709 | + } | |
| 710 | + } | |
| 711 | + | |
| 712 | + // Sort & return | |
| 713 | + return $this->sort_row_actions( $actions ); | |
| 507 | 714 | } |
| 508 | 715 | |
| 509 | 716 | /** |
| 717 | + * Sort row actions by key | |
| 718 | + * | |
| 719 | + * @since 2.6.0 | |
| 720 | + * | |
| 721 | + * @param array $actions | |
| 722 | + * | |
| 723 | + * @return array | |
| 724 | + */ | |
| 725 | + private function sort_row_actions( $actions = array() ) { | |
| 726 | + | |
| 727 | + // Return value | |
| 728 | + $retval = array(); | |
| 729 | + | |
| 730 | + // Known row actions, in sort order | |
| 731 | + $known_actions = $this->get_row_action_sort_order(); | |
| 732 | + | |
| 733 | + // Sort known actions, and keep any unknown ones | |
| 734 | + foreach ( $known_actions as $key ) { | |
| 735 | + if ( isset( $actions[ $key ] ) ) { | |
| 736 | + $retval[ $key ] = $actions[ $key ]; | |
| 737 | + unset( $actions[ $key ] ); | |
| 738 | + } | |
| 739 | + } | |
| 740 | + | |
| 741 | + // Combine & return | |
| 742 | + return $retval + $actions; | |
| 743 | + } | |
| 744 | + | |
| 745 | + /** | |
| 510 | 746 | * Custom user feedback messages for forum post type |
| 511 | 747 | * |
| 512 | - * @since bbPress (r3080) | |
| 748 | + * @since 2.0.0 bbPress (r3080) | |
| 513 | 749 | * |
| 514 | 750 | * @global int $post_ID |
| 515 | - * @uses bbp_get_forum_permalink() | |
| 516 | - * @uses wp_post_revision_title() | |
| 517 | - * @uses esc_url() | |
| 518 | - * @uses add_query_arg() | |
| 519 | 751 | * |
| 520 | 752 | * @param array $messages |
| 521 | 753 | * |
| 522 | 754 | * @return array |
| @@ -523,10 +755,8 @@ | ||
| 523 | 755 | */ |
| 524 | 756 | public function updated_messages( $messages ) { |
| 525 | 757 | global $post_ID; |
| 526 | 758 | |
| 527 | - if ( $this->bail() ) return $messages; | |
| 528 | - | |
| 529 | 759 | // URL for the current forum |
| 530 | 760 | $forum_url = bbp_get_forum_permalink( $post_ID ); |
| 531 | 761 | |
| 532 | 762 | // Current forum's post_date |
| @@ -532,47 +762,73 @@ | ||
| 532 | 762 | // Current forum's post_date |
| 533 | 763 | $post_date = bbp_get_global_post_field( 'post_date', 'raw' ); |
| 534 | 764 | |
| 535 | 765 | // Messages array |
| 536 | - $messages[$this->post_type] = array( | |
| 537 | - 0 => '', // Left empty on purpose | |
| 766 | + $messages[ $this->post_type ] = array( | |
| 767 | + 0 => '', // Left empty on purpose | |
| 538 | 768 | |
| 539 | 769 | // Updated |
| 540 | - 1 => sprintf( __( 'Forum updated. <a href="%s">View forum</a>', 'bbpress' ), $forum_url ), | |
| 770 | + 1 => sprintf( | |
| 771 | + '%1$s <a href="%2$s">%3$s</a>', | |
| 772 | + esc_html__( 'Forum updated.', 'bbpress' ), | |
| 773 | + $forum_url, | |
| 774 | + esc_html__( 'View forum', 'bbpress' ) | |
| 775 | + ), | |
| 541 | 776 | |
| 542 | 777 | // Custom field updated |
| 543 | - 2 => __( 'Custom field updated.', 'bbpress' ), | |
| 778 | + 2 => esc_html__( 'Custom field updated.', 'bbpress' ), | |
| 544 | 779 | |
| 545 | 780 | // Custom field deleted |
| 546 | - 3 => __( 'Custom field deleted.', 'bbpress' ), | |
| 781 | + 3 => esc_html__( 'Custom field deleted.', 'bbpress' ), | |
| 547 | 782 | |
| 548 | 783 | // Forum updated |
| 549 | - 4 => __( 'Forum updated.', 'bbpress' ), | |
| 784 | + 4 => esc_html__( 'Forum updated.', 'bbpress' ), | |
| 550 | 785 | |
| 551 | 786 | // Restored from revision |
| 552 | - // translators: %s: date and time of the revision | |
| 787 | + /* translators: %s: date and time of the revision */ | |
| 553 | 788 | 5 => isset( $_GET['revision'] ) |
| 554 | - ? sprintf( __( 'Forum restored to revision from %s', 'bbpress' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) | |
| 555 | - : false, | |
| 789 | + /* translators: %s: Date and time of the revision */ | |
| 790 | + ? sprintf( esc_html__( 'Forum restored to revision from %s', 'bbpress' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) | |
| 791 | + : false, | |
| 556 | 792 | |
| 557 | 793 | // Forum created |
| 558 | - 6 => sprintf( __( 'Forum created. <a href="%s">View forum</a>', 'bbpress' ), $forum_url ), | |
| 794 | + 6 => sprintf( | |
| 795 | + '%1$s <a href="%2$s">%3$s</a>', | |
| 796 | + esc_html__( 'Forum created.', 'bbpress' ), | |
| 797 | + $forum_url, | |
| 798 | + esc_html__( 'View forum', 'bbpress' ) | |
| 799 | + ), | |
| 559 | 800 | |
| 560 | 801 | // Forum saved |
| 561 | - 7 => __( 'Forum saved.', 'bbpress' ), | |
| 802 | + 7 => esc_html__( 'Forum saved.', 'bbpress' ), | |
| 562 | 803 | |
| 563 | 804 | // Forum submitted |
| 564 | - 8 => sprintf( __( 'Forum submitted. <a target="_blank" href="%s">Preview forum</a>', 'bbpress' ), esc_url( add_query_arg( 'preview', 'true', $forum_url ) ) ), | |
| 805 | + 8 => sprintf( | |
| 806 | + '%1$s <a href="%2$s" target="_blank">%3$s</a>', | |
| 807 | + esc_html__( 'Forum submitted.', 'bbpress' ), | |
| 808 | + esc_url( add_query_arg( 'preview', 'true', $forum_url ) ), | |
| 809 | + esc_html__( 'Preview forum', 'bbpress' ) | |
| 810 | + ), | |
| 565 | 811 | |
| 566 | 812 | // Forum scheduled |
| 567 | - 9 => sprintf( __( 'Forum scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview forum</a>', 'bbpress' ), | |
| 568 | - // translators: Publish box date format, see http://php.net/date | |
| 569 | - date_i18n( __( 'M j, Y @ G:i', 'bbpress' ), | |
| 570 | - strtotime( $post_date ) ), | |
| 571 | - $forum_url ), | |
| 813 | + 9 => sprintf( | |
| 814 | + '%1$s <a target="_blank" href="%2$s">%3$s</a>', | |
| 815 | + sprintf( | |
| 816 | + /* translators: %s: Publish box date format, see http://php.net/date */ | |
| 817 | + esc_html__( 'Forum scheduled for: %s.', 'bbpress' ), | |
| 818 | + '<strong>' . date_i18n( __( 'M j, Y @ G:i', 'bbpress' ), strtotime( $post_date ) ) . '</strong>' | |
| 819 | + ), | |
| 820 | + $forum_url, | |
| 821 | + __( 'Preview forum', 'bbpress' ) | |
| 822 | + ), | |
| 572 | 823 | |
| 573 | 824 | // Forum draft updated |
| 574 | - 10 => sprintf( __( 'Forum draft updated. <a target="_blank" href="%s">Preview forum</a>', 'bbpress' ), esc_url( add_query_arg( 'preview', 'true', $forum_url ) ) ), | |
| 825 | + 10 => sprintf( | |
| 826 | + '%1$s <a href="%2$s" target="_blank">%3$s</a>', | |
| 827 | + esc_html__( 'Forum draft updated.', 'bbpress' ), | |
| 828 | + esc_url( add_query_arg( 'preview', 'true', $forum_url ) ), | |
| 829 | + esc_html__( 'Preview forum', 'bbpress' ) | |
| 830 | + ), | |
| 575 | 831 | ); |
| 576 | 832 | |
| 577 | 833 | return $messages; |
| 578 | 834 | } |
| @@ -584,11 +840,18 @@ | ||
| 584 | 840 | * |
| 585 | 841 | * This is currently here to make hooking and unhooking of the admin UI easy. |
| 586 | 842 | * It could use dependency injection in the future, but for now this is easier. |
| 587 | 843 | * |
| 588 | - * @since bbPress (r2596) | |
| 844 | + * @since 2.0.0 bbPress (r2596) | |
| 589 | 845 | * |
| 590 | - * @uses BBP_Forums_Admin | |
| 846 | + * @param WP_Screen $current_screen Current screen object | |
| 591 | 847 | */ |
| 592 | -function bbp_admin_forums() { | |
| 593 | - bbpress()->admin->forums = new BBP_Forums_Admin(); | |
| 848 | +function bbp_admin_forums( $current_screen ) { | |
| 849 | + | |
| 850 | + // Bail if not a forum screen | |
| 851 | + if ( empty( $current_screen->post_type ) || ( bbp_get_forum_post_type() !== $current_screen->post_type ) ) { | |
| 852 | + return; | |
| 853 | + } | |
| 854 | + | |
| 855 | + // Init the forums admin | |
| 856 | + bbp_admin()->forums = new BBP_Forums_Admin(); | |
| 594 | 857 | } |