| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* bbPress Topics Admin Class |
| 5 |
* |
| 6 |
* @package bbPress |
| 7 |
* @subpackage Administration |
| 8 |
*/ |
| 9 |
|
| 10 |
// Exit if accessed directly |
| 11 |
if ( !defined( 'ABSPATH' ) ) exit; |
| 12 |
|
| 13 |
if ( !class_exists( 'BBP_Topics_Admin' ) ) : |
| 14 |
/** |
| 15 |
* Loads bbPress topics admin area |
| 16 |
* |
| 17 |
* @package bbPress |
| 18 |
* @subpackage Administration |
| 19 |
* @since bbPress (r2464) |
| 20 |
*/ |
| 21 |
class BBP_Topics_Admin { |
| 22 |
|
| 23 |
/** Variables *************************************************************/ |
| 24 |
|
| 25 |
/** |
| 26 |
* @var The post type of this admin component |
| 27 |
*/ |
| 28 |
var $post_type = ''; |
| 29 |
|
| 30 |
/** Functions *************************************************************/ |
| 31 |
|
| 32 |
/** |
| 33 |
* The main bbPress topics admin loader |
| 34 |
* |
| 35 |
* @since bbPress (r2515) |
| 36 |
* |
| 37 |
* @uses BBP_Topics_Admin::setup_globals() Setup the globals needed |
| 38 |
* @uses BBP_Topics_Admin::setup_actions() Setup the hooks and actions |
| 39 |
* @uses BBP_Topics_Admin::setup_help() Setup the help text |
| 40 |
*/ |
| 41 |
function __construct() { |
| 42 |
$this->setup_globals(); |
| 43 |
$this->setup_actions(); |
| 44 |
$this->setup_help(); |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Setup the admin hooks, actions and filters |
| 49 |
* |
| 50 |
* @since bbPress (r2646) |
| 51 |
* @access private |
| 52 |
* |
| 53 |
* @uses add_action() To add various actions |
| 54 |
* @uses add_filter() To add various filters |
| 55 |
* @uses bbp_get_forum_post_type() To get the forum post type |
| 56 |
* @uses bbp_get_topic_post_type() To get the topic post type |
| 57 |
* @uses bbp_get_reply_post_type() To get the reply post type |
| 58 |
*/ |
| 59 |
function setup_actions() { |
| 60 |
|
| 61 |
// Add some general styling to the admin area |
| 62 |
add_action( 'admin_head', array( $this, 'admin_head' ) ); |
| 63 |
|
| 64 |
// Messages |
| 65 |
add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) ); |
| 66 |
|
| 67 |
// Topic column headers. |
| 68 |
add_filter( 'manage_' . $this->post_type . '_posts_columns', array( $this, 'topics_column_headers' ) ); |
| 69 |
|
| 70 |
// Topic columns (in post row) |
| 71 |
add_action( 'manage_' . $this->post_type . '_posts_custom_column', array( $this, 'topics_column_data' ), 10, 2 ); |
| 72 |
add_filter( 'post_row_actions', array( $this, 'topics_row_actions' ), 10, 2 ); |
| 73 |
|
| 74 |
// Topic metabox actions |
| 75 |
add_action( 'add_meta_boxes', array( $this, 'topic_attributes_metabox' ) ); |
| 76 |
add_action( 'save_post', array( $this, 'topic_attributes_metabox_save' ) ); |
| 77 |
|
| 78 |
// Check if there are any bbp_toggle_topic_* requests on admin_init, also have a message displayed |
| 79 |
add_action( 'bbp_admin_init', array( $this, 'toggle_topic' ) ); |
| 80 |
add_action( 'admin_notices', array( $this, 'toggle_topic_notice' ) ); |
| 81 |
|
| 82 |
// Anonymous metabox actions |
| 83 |
add_action( 'add_meta_boxes', array( $this, 'author_metabox' ) ); |
| 84 |
add_action( 'save_post', array( $this, 'author_metabox_save' ) ); |
| 85 |
|
| 86 |
// Add ability to filter topics and replies per forum |
| 87 |
add_filter( 'restrict_manage_posts', array( $this, 'filter_dropdown' ) ); |
| 88 |
add_filter( 'request', array( $this, 'filter_post_rows' ) ); |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Admin globals |
| 93 |
* |
| 94 |
* @since bbPress (r2646) |
| 95 |
* @access private |
| 96 |
*/ |
| 97 |
function setup_globals() { |
| 98 |
|
| 99 |
// Setup the post type for this admin component |
| 100 |
$this->post_type = bbp_get_topic_post_type(); |
| 101 |
} |
| 102 |
|
| 103 |
/** |
| 104 |
* Contextual help for topics |
| 105 |
* |
| 106 |
* @since bbPress (r3119) |
| 107 |
* @access private |
| 108 |
*/ |
| 109 |
function setup_help() { |
| 110 |
|
| 111 |
// Define local variable(s) |
| 112 |
$contextual_help = array(); |
| 113 |
|
| 114 |
/** New/Edit **********************************************************/ |
| 115 |
|
| 116 |
$bbp_contextual_help[] = __( 'The topic title field and the big topic 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 the box. Use the Screen Options tab to unhide more boxes (Topic Tags, Topic Attributes, or Slug) or to choose a 1- or 2-column layout for this screen.', 'bbpress' ); |
| 117 |
$bbp_contextual_help[] = __( '<strong>Title</strong> - Enter a title for your topic. After you enter a title, you will see the permalink below, which you can edit.', 'bbpress' ); |
| 118 |
$bbp_contextual_help[] = __( '<strong>Post editor</strong> - Enter the text for your topic. 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 screen icon just before that allows you to expand the edit box to full screen. 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 post editor and following the directions.', 'bbpress' ); |
| 119 |
$bbp_contextual_help[] = __( '<strong>Topic Attributes</strong> - Select the attributes that your topic should have. The Forum dropdown determines the parent forum that the topic belongs to. Select the forum or category from the dropdown, or leave the default (No Forum) to post the topic without an assigned forum.', 'bbpress' ); |
| 120 |
$bbp_contextual_help[] = __( '<strong>Publish</strong> - The Publish box will allow you to save your topic as Draft or Pending Review. You may Preview your topic before it is published as well. The Visibility will determine whether the topic is Public, Password protected (requiring a password on the site to view) or Private (only the author will have access to it). Topics may be published immediately by clicking the dropdown, or at a specific date and time by clicking the Edit link.', 'bbpress' ); |
| 121 |
$bbp_contextual_help[] = __( '<strong>Topic Tags</strong> - You can assign keywords to your topics using Topic Tags. Unlike categories, tags have no hierarchy, meaning there is no relationship from one tag to another. Topics can be added and modified further from the Topic Tags screen.', 'bbpress' ); |
| 122 |
$bbp_contextual_help[] = __( '<strong>Revisions</strong> - Revisions show past versions of the saved topic. Each revision can be compared to the current version, or another revision. Revisions can also be restored to the current version.', 'bbpress' ); |
| 123 |
$bbp_contextual_help[] = __( '<strong>For more information:</strong>', 'bbpress' ); |
| 124 |
$bbp_contextual_help[] = |
| 125 |
'<ul>' . |
| 126 |
'<li>' . __( '<a href="http://bbpress.org/documentation/">bbPress Documentation</a>', 'bbpress' ) . '</li>' . |
| 127 |
'<li>' . __( '<a href="http://bbpress.org/forums/">bbPress Support Forums</a>', 'bbpress' ) . '</li>' . |
| 128 |
'</ul>'; |
| 129 |
|
| 130 |
// Wrap each help item in paragraph tags |
| 131 |
foreach( $bbp_contextual_help as $paragraph ) |
| 132 |
$contextual_help .= '<p>' . $paragraph . '</p>'; |
| 133 |
|
| 134 |
// Add help |
| 135 |
add_contextual_help( bbp_get_topic_post_type(), $contextual_help ); |
| 136 |
|
| 137 |
// Reset |
| 138 |
$contextual_help = $bbp_contextual_help = ''; |
| 139 |
|
| 140 |
/** Post Rows *********************************************************/ |
| 141 |
|
| 142 |
$bbp_contextual_help[] = __( 'This screen displays the topics created on your site.', 'bbpress' ); |
| 143 |
$bbp_contextual_help[] = __( 'You can customize the display of this screen in a number of ways:', 'bbpress' ); |
| 144 |
$bbp_contextual_help[] = |
| 145 |
'<ul>' . |
| 146 |
'<li>' . __( 'You can hide/display columns based on your needs and decide how many topics to list per screen using the Screen Options tab.', 'bbpress' ) . '</li>' . |
| 147 |
'<li>' . __( 'You can filter the list of topics by topics status using the text links in the upper left to show All, Published, Pending Review, Draft, or Trashed topics. The default view is to show all topics.', 'bbpress' ) . '</li>' . |
| 148 |
'<li>' . __( 'You can view topics 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>' . |
| 149 |
'<li>' . __( 'You can refine the list to show only topics from a specific month by using the dropdown menus above the topics list. Click the Filter button after making your selection.', 'bbpress' ) . '</li>' . |
| 150 |
'<li>' . __( 'You can also show only topics from a specific parent forum by using the parent forum dropdown above the topics list and selecting the parent forum. Click the Filter button after making your selection.', 'bbpress' ) . '</li>' . |
| 151 |
'<li>' . __( 'You can refine the list by clicking on the topic creator in the topics list.', 'bbpress' ) . '</li>' . |
| 152 |
'</ul>' . |
| 153 |
|
| 154 |
$bbp_contextual_help[] = __( 'Hovering over a row in the topics list will display action links that allow you to manage your topic. You can perform the following actions:', 'bbpress' ); |
| 155 |
$bbp_contextual_help[] = |
| 156 |
'<ul>' . |
| 157 |
'<li>' . __( 'Edit takes you to the editing screen for that topic. You can also reach that screen by clicking on the topic title.', 'bbpress' ) . '</li>' . |
| 158 |
'<li>' . __( 'Trash removes your topic from this list and places it in the trash, from which you can permanently delete it.', 'bbpress' ) . '</li>' . |
| 159 |
'<li>' . __( 'View will take you to your live topic to view the topic.', 'bbpress' ) . '</li>' . |
| 160 |
'<li>' . __( 'Close will close your topic, disabling new replies within it. It will remain viewable to users, but replies will not be allowed.', 'bbpress' ) . '</li>' . |
| 161 |
'<li>' . __( 'Stick (to front) will pin the topic to the front page of the forum that it’s in. New topics will begin beneath the list of "stuck" topics, which will always sit at the top of the list.', 'bbpress' ) . '</li>' . |
| 162 |
'<li>' . __( 'Spam will mark the topic as spam, closing the post to new replies and removing it from the public view.', 'bbpress' ) . '</li>' . |
| 163 |
'</ul>' . |
| 164 |
|
| 165 |
$bbp_contextual_help[] = __( 'You can also edit multiple topics at once. Select the topics you want to edit using the checkboxes, select Edit from the Bulk Actions menu and click Apply. You will be able to change the metadata for all selected topics at once. To remove a topic from the grouping, just click the x next to its name in the Bulk Edit area that appears.', 'bbpress' ); |
| 166 |
$bbp_contextual_help[] = __( 'The Bulk Actions menu may also be used to delete multiple topics at once. Select Delete from the dropdown after making your selection.', 'bbpress' ); |
| 167 |
$bbp_contextual_help[] = __( '<strong>For more information:</strong>', 'bbpress' ); |
| 168 |
$bbp_contextual_help[] = |
| 169 |
'<ul>' . |
| 170 |
'<li>' . __( '<a href="http://bbpress.org/documentation/">bbPress Documentation</a>', 'bbpress' ) . '</li>' . |
| 171 |
'<li>' . __( '<a href="http://bbpress.org/forums/">bbPress Support Forums</a>' , 'bbpress' ) . '</li>' . |
| 172 |
'</ul>'; |
| 173 |
|
| 174 |
// Wrap each help item in paragraph tags |
| 175 |
foreach( $bbp_contextual_help as $paragraph ) |
| 176 |
$contextual_help .= '<p>' . $paragraph . '</p>'; |
| 177 |
|
| 178 |
// Add help |
| 179 |
add_contextual_help( bbp_get_topic_post_type(), $contextual_help ); |
| 180 |
|
| 181 |
// Reset |
| 182 |
$contextual_help = $bbp_contextual_help = ''; |
| 183 |
|
| 184 |
/** Topic Tags **********************************************************/ |
| 185 |
|
| 186 |
$bbp_contextual_help[] = __( 'You can change the display of this screen using the Screen Options tab to set how many items are displayed per screen (20 by default) and to display/hide columns in the table (Description, Slug, and Topics).', 'bbpress' ); |
| 187 |
$bbp_contextual_help[] = __( 'You can assign keywords to your topics using Topic Tags. Unlike categories, tags have no hierarchy, meaning there is no relationship from one tag to another.', 'bbpress' ); |
| 188 |
$bbp_contextual_help[] = __( 'Normally, tags are ad-hoc keywords that identify important information in your topic (names, subjects, etc) that may or may not recur in other topics. If you think of your forum like a book, the tags are like the terms in the index.', 'bbpress' ); |
| 189 |
$bbp_contextual_help[] = __( 'When editing a topic tag on this screen, you will fill in the following fields:', 'bbpress' ); |
| 190 |
$bbp_contextual_help[] = |
| 191 |
'<ul>' . |
| 192 |
'<li>' . __( '<strong>Name</strong> - The name is how it appears on your site.', 'bbpress' ) . '</li>' . |
| 193 |
'<li>' . __( '<strong>Slug</strong> - The Slug is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.', 'bbpress' ) . '</li>' . |
| 194 |
'<li>' . __( '<strong>Description</strong> - The description is not prominent by default; however, some forum themes may display it.', 'bbpress' ) . '</li>' . |
| 195 |
'</ul>' ; |
| 196 |
|
| 197 |
// Wrap each help item in paragraph tags |
| 198 |
foreach( $bbp_contextual_help as $paragraph ) |
| 199 |
$contextual_help .= '<p>' . $paragraph . '</p>'; |
| 200 |
|
| 201 |
// Add help |
| 202 |
global $bbp; |
| 203 |
add_contextual_help( 'edit-' . bbp_get_topic_tag_tax_id(), $contextual_help ); |
| 204 |
} |
| 205 |
|
| 206 |
/** |
| 207 |
* Add the topic attributes metabox |
| 208 |
* |
| 209 |
* @since bbPress (r2744) |
| 210 |
* |
| 211 |
* @uses bbp_get_topic_post_type() To get the topic post type |
| 212 |
* @uses add_meta_box() To add the metabox |
| 213 |
* @uses do_action() Calls 'bbp_topic_attributes_metabox' |
| 214 |
*/ |
| 215 |
function topic_attributes_metabox() { |
| 216 |
add_meta_box ( |
| 217 |
'bbp_topic_attributes', |
| 218 |
__( 'Topic Attributes', 'bbpress' ), |
| 219 |
'bbp_topic_metabox', |
| 220 |
$this->post_type, |
| 221 |
'side', |
| 222 |
'high' |
| 223 |
); |
| 224 |
|
| 225 |
do_action( 'bbp_topic_attributes_metabox' ); |
| 226 |
} |
| 227 |
|
| 228 |
/** |
| 229 |
* Pass the topic attributes for processing |
| 230 |
* |
| 231 |
* @since bbPress (r2746) |
| 232 |
* |
| 233 |
* @param int $topic_id Topic id |
| 234 |
* @uses current_user_can() To check if the current user is capable of |
| 235 |
* editing the topic |
| 236 |
* @uses do_action() Calls 'bbp_topic_attributes_metabox_save' with the |
| 237 |
* topic id and parent id |
| 238 |
* @return int Parent id |
| 239 |
*/ |
| 240 |
function topic_attributes_metabox_save( $topic_id ) { |
| 241 |
|
| 242 |
// Bail if doing an autosave |
| 243 |
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) |
| 244 |
return $topic_id; |
| 245 |
|
| 246 |
// Bail if not a post request |
| 247 |
if ( 'POST' != strtoupper( $_SERVER['REQUEST_METHOD'] ) ) |
| 248 |
return $topic_id; |
| 249 |
|
| 250 |
// Bail if post_type is not a topic |
| 251 |
if ( get_post_type( $topic_id ) != $this->post_type ) |
| 252 |
return; |
| 253 |
|
| 254 |
// Bail if current user cannot edit this topic |
| 255 |
if ( !current_user_can( 'edit_topic', $topic_id ) ) |
| 256 |
return $topic_id; |
| 257 |
|
| 258 |
// Get the forum ID |
| 259 |
$forum_id = !empty( $_POST['parent_id'] ) ? (int) $_POST['parent_id'] : 0; |
| 260 |
|
| 261 |
// Formally update the topic |
| 262 |
bbp_update_topic( $topic_id, $forum_id ); |
| 263 |
|
| 264 |
// Allow other fun things to happen |
| 265 |
do_action( 'bbp_topic_attributes_metabox_save', $topic_id, $forum_id ); |
| 266 |
|
| 267 |
return $topic_id; |
| 268 |
} |
| 269 |
|
| 270 |
/** |
| 271 |
* Add the author info metabox |
| 272 |
* |
| 273 |
* @since bbPress (r2828) |
| 274 |
* |
| 275 |
* @uses bbp_get_topic() To get the topic |
| 276 |
* @uses bbp_get_reply() To get the reply |
| 277 |
* @uses bbp_get_topic_post_type() To get the topic post type |
| 278 |
* @uses bbp_get_reply_post_type() To get the reply post type |
| 279 |
* @uses add_meta_box() To add the metabox |
| 280 |
* @uses do_action() Calls 'bbp_author_metabox' with the topic/reply |
| 281 |
* id |
| 282 |
*/ |
| 283 |
function author_metabox() { |
| 284 |
global $current_screen; |
| 285 |
|
| 286 |
// Bail if post_type is not a topic |
| 287 |
if ( ( empty( $_GET['action'] ) || ( 'edit' != $_GET['action'] ) ) || ( get_post_type() != $this->post_type ) ) |
| 288 |
return; |
| 289 |
|
| 290 |
// Add the metabox |
| 291 |
add_meta_box( |
| 292 |
'bbp_author_metabox', |
| 293 |
__( 'Author Information', 'bbpress' ), |
| 294 |
'bbp_author_metabox', |
| 295 |
$this->post_type, |
| 296 |
'side', |
| 297 |
'high' |
| 298 |
); |
| 299 |
|
| 300 |
do_action( 'bbp_author_metabox', get_the_ID() ); |
| 301 |
} |
| 302 |
|
| 303 |
/** |
| 304 |
* Save the author information for the topic |
| 305 |
* |
| 306 |
* @since bbPress (r2828) |
| 307 |
* |
| 308 |
* @param int $post_id Topic or reply id |
| 309 |
* @uses bbp_get_topic() To get the topic |
| 310 |
* @uses bbp_get_reply() To get the reply |
| 311 |
* @uses current_user_can() To check if the current user can edit the |
| 312 |
* topic or reply |
| 313 |
* @uses bbp_filter_author_post_data() To filter the author data |
| 314 |
* @uses update_post_meta() To update the anonymous user data |
| 315 |
* @uses do_action() Calls 'bbp_author_metabox_save' with the topic id and |
| 316 |
* anonymous data |
| 317 |
* @return int Topic or reply id |
| 318 |
*/ |
| 319 |
function author_metabox_save( $post_id ) { |
| 320 |
|
| 321 |
// Bail if no post_id |
| 322 |
if ( empty( $post_id ) ) |
| 323 |
return $post_id; |
| 324 |
|
| 325 |
// Bail if doing an autosave |
| 326 |
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) |
| 327 |
return $post_id; |
| 328 |
|
| 329 |
// Bail if not a post request |
| 330 |
if ( 'POST' != strtoupper( $_SERVER['REQUEST_METHOD'] ) ) |
| 331 |
return $post_id; |
| 332 |
|
| 333 |
// Bail if post_type is not a topic or reply |
| 334 |
if ( get_post_type( $post_id ) != $this->post_type ) |
| 335 |
return; |
| 336 |
|
| 337 |
// Bail if user cannot edit replies |
| 338 |
if ( !current_user_can( 'edit_topic', $post_id ) ) |
| 339 |
return $post_id; |
| 340 |
|
| 341 |
$anonymous_data = bbp_filter_anonymous_post_data(); |
| 342 |
|
| 343 |
update_post_meta( $post_id, '_bbp_anonymous_name', $anonymous_data['bbp_anonymous_name'] ); |
| 344 |
update_post_meta( $post_id, '_bbp_anonymous_email', $anonymous_data['bbp_anonymous_email'] ); |
| 345 |
update_post_meta( $post_id, '_bbp_anonymous_website', $anonymous_data['bbp_anonymous_website'] ); |
| 346 |
|
| 347 |
do_action( 'bbp_author_metabox_save', $post_id, $anonymous_data ); |
| 348 |
|
| 349 |
return $post_id; |
| 350 |
} |
| 351 |
|
| 352 |
/** |
| 353 |
* Add some general styling to the admin area |
| 354 |
* |
| 355 |
* @since bbPress (r2464) |
| 356 |
* |
| 357 |
* @uses bbp_get_forum_post_type() To get the forum post type |
| 358 |
* @uses bbp_get_topic_post_type() To get the topic post type |
| 359 |
* @uses bbp_get_reply_post_type() To get the reply post type |
| 360 |
* @uses sanitize_html_class() To sanitize the classes |
| 361 |
* @uses do_action() Calls 'bbp_admin_head' |
| 362 |
*/ |
| 363 |
function admin_head() { |
| 364 |
|
| 365 |
if ( get_post_type() == $this->post_type ) : ?> |
| 366 |
|
| 367 |
<style type="text/css" media="screen"> |
| 368 |
/*<![CDATA[*/ |
| 369 |
|
| 370 |
.column-bbp_forum_topic_count, |
| 371 |
.column-bbp_forum_reply_count, |
| 372 |
.column-bbp_topic_reply_count, |
| 373 |
.column-bbp_topic_voice_count { |
| 374 |
width: 8% !important; |
| 375 |
} |
| 376 |
|
| 377 |
.column-author, |
| 378 |
.column-bbp_reply_author, |
| 379 |
.column-bbp_topic_author { |
| 380 |
width: 10% !important; |
| 381 |
} |
| 382 |
|
| 383 |
.column-bbp_topic_forum, |
| 384 |
.column-bbp_reply_forum, |
| 385 |
.column-bbp_reply_topic { |
| 386 |
width: 10% !important; |
| 387 |
} |
| 388 |
|
| 389 |
.column-bbp_forum_freshness, |
| 390 |
.column-bbp_topic_freshness { |
| 391 |
width: 10% !important; |
| 392 |
} |
| 393 |
|
| 394 |
.column-bbp_forum_created, |
| 395 |
.column-bbp_topic_created, |
| 396 |
.column-bbp_reply_created { |
| 397 |
width: 15% !important; |
| 398 |
} |
| 399 |
|
| 400 |
.status-closed { |
| 401 |
background-color: #eaeaea; |
| 402 |
} |
| 403 |
|
| 404 |
.status-spam { |
| 405 |
background-color: #faeaea; |
| 406 |
} |
| 407 |
|
| 408 |
/*]]>*/ |
| 409 |
</style> |
| 410 |
|
| 411 |
<?php endif; |
| 412 |
|
| 413 |
} |
| 414 |
|
| 415 |
/** |
| 416 |
* Toggle topic |
| 417 |
* |
| 418 |
* Handles the admin-side opening/closing, sticking/unsticking and |
| 419 |
* spamming/unspamming of topics |
| 420 |
* |
| 421 |
* @since bbPress (r2727) |
| 422 |
* |
| 423 |
* @uses bbp_get_topic() To get the topic |
| 424 |
* @uses current_user_can() To check if the user is capable of editing |
| 425 |
* the topic |
| 426 |
* @uses wp_die() To die if the user isn't capable or the post wasn't |
| 427 |
* found |
| 428 |
* @uses check_admin_referer() To verify the nonce and check referer |
| 429 |
* @uses bbp_is_topic_open() To check if the topic is open |
| 430 |
* @uses bbp_close_topic() To close the topic |
| 431 |
* @uses bbp_open_topic() To open the topic |
| 432 |
* @uses bbp_is_topic_sticky() To check if the topic is a sticky or |
| 433 |
* super sticky |
| 434 |
* @uses bbp_unstick_topic() To unstick the topic |
| 435 |
* @uses bbp_stick_topic() To stick the topic |
| 436 |
* @uses bbp_is_topic_spam() To check if the topic is marked as spam |
| 437 |
* @uses bbp_unspam_topic() To unmark the topic as spam |
| 438 |
* @uses bbp_spam_topic() To mark the topic as spam |
| 439 |
* @uses do_action() Calls 'bbp_toggle_topic_admin' with success, post |
| 440 |
* data, action and message |
| 441 |
* @uses add_query_arg() To add custom args to the url |
| 442 |
* @uses wp_redirect() Redirect the page to custom url |
| 443 |
*/ |
| 444 |
function toggle_topic() { |
| 445 |
|
| 446 |
// Only proceed if GET is a topic toggle action |
| 447 |
if ( 'GET' == $_SERVER['REQUEST_METHOD'] && !empty( $_GET['action'] ) && in_array( $_GET['action'], array( 'bbp_toggle_topic_close', 'bbp_toggle_topic_stick', 'bbp_toggle_topic_spam' ) ) && !empty( $_GET['topic_id'] ) ) { |
| 448 |
$action = $_GET['action']; // What action is taking place? |
| 449 |
$topic_id = (int) $_GET['topic_id']; // What's the topic id? |
| 450 |
$success = false; // Flag |
| 451 |
$post_data = array( 'ID' => $topic_id ); // Prelim array |
| 452 |
|
| 453 |
if ( !$topic = bbp_get_topic( $topic_id ) ) // Which topic? |
| 454 |
wp_die( __( 'The topic was not found!', 'bbpress' ) ); |
| 455 |
|
| 456 |
if ( !current_user_can( 'moderate', $topic->ID ) ) // What is the user doing here? |
| 457 |
wp_die( __( 'You do not have the permission to do that!', 'bbpress' ) ); |
| 458 |
|
| 459 |
switch ( $action ) { |
| 460 |
case 'bbp_toggle_topic_close' : |
| 461 |
check_admin_referer( 'close-topic_' . $topic_id ); |
| 462 |
|
| 463 |
$is_open = bbp_is_topic_open( $topic_id ); |
| 464 |
$message = true == $is_open ? 'closed' : 'opened'; |
| 465 |
$success = true == $is_open ? bbp_close_topic( $topic_id ) : bbp_open_topic( $topic_id ); |
| 466 |
|
| 467 |
break; |
| 468 |
|
| 469 |
case 'bbp_toggle_topic_stick' : |
| 470 |
check_admin_referer( 'stick-topic_' . $topic_id ); |
| 471 |
|
| 472 |
$is_sticky = bbp_is_topic_sticky( $topic_id ); |
| 473 |
$is_super = ( empty( $is_sticky ) && !empty( $_GET['super'] ) && 1 == (int) $_GET['super'] ) ? true : false; |
| 474 |
$message = true == $is_sticky ? 'unsticked' : 'sticked'; |
| 475 |
$message = true == $is_super ? 'super_sticked' : $message; |
| 476 |
$success = true == $is_sticky ? bbp_unstick_topic( $topic_id ) : bbp_stick_topic( $topic_id, $is_super ); |
| 477 |
|
| 478 |
break; |
| 479 |
|
| 480 |
case 'bbp_toggle_topic_spam' : |
| 481 |
check_admin_referer( 'spam-topic_' . $topic_id ); |
| 482 |
|
| 483 |
$is_spam = bbp_is_topic_spam( $topic_id ); |
| 484 |
$message = true == $is_spam ? 'unspammed' : 'spammed'; |
| 485 |
$success = true == $is_spam ? bbp_unspam_topic( $topic_id ) : bbp_spam_topic( $topic_id ); |
| 486 |
|
| 487 |
break; |
| 488 |
} |
| 489 |
|
| 490 |
$message = array( 'bbp_topic_toggle_notice' => $message, 'topic_id' => $topic->ID ); |
| 491 |
|
| 492 |
if ( false == $success || is_wp_error( $success ) ) |
| 493 |
$message['failed'] = '1'; |
| 494 |
|
| 495 |
// Do additional topic toggle actions (admin side) |
| 496 |
do_action( 'bbp_toggle_topic_admin', $success, $post_data, $action, $message ); |
| 497 |
|
| 498 |
// Redirect back to the topic |
| 499 |
$redirect = add_query_arg( $message, remove_query_arg( array( 'action', 'topic_id' ) ) ); |
| 500 |
wp_redirect( $redirect ); |
| 501 |
|
| 502 |
// For good measure |
| 503 |
exit(); |
| 504 |
} |
| 505 |
} |
| 506 |
|
| 507 |
/** |
| 508 |
* Toggle topic notices |
| 509 |
* |
| 510 |
* Display the success/error notices from |
| 511 |
* {@link BBP_Admin::toggle_topic()} |
| 512 |
* |
| 513 |
* @since bbPress (r2727) |
| 514 |
* |
| 515 |
* @uses bbp_get_topic() To get the topic |
| 516 |
* @uses bbp_get_topic_title() To get the topic title of the topic |
| 517 |
* @uses esc_html() To sanitize the topic title |
| 518 |
* @uses apply_filters() Calls 'bbp_toggle_topic_notice_admin' with |
| 519 |
* message, topic id, notice and is it a failure |
| 520 |
*/ |
| 521 |
function toggle_topic_notice() { |
| 522 |
|
| 523 |
// Only proceed if GET is a topic toggle action |
| 524 |
if ( 'GET' == $_SERVER['REQUEST_METHOD'] && !empty( $_GET['bbp_topic_toggle_notice'] ) && in_array( $_GET['bbp_topic_toggle_notice'], array( 'opened', 'closed', 'super_sticked', 'sticked', 'unsticked', 'spammed', 'unspammed' ) ) && !empty( $_GET['topic_id'] ) ) { |
| 525 |
$notice = $_GET['bbp_topic_toggle_notice']; // Which notice? |
| 526 |
$topic_id = (int) $_GET['topic_id']; // What's the topic id? |
| 527 |
$is_failure = !empty( $_GET['failed'] ) ? true : false; // Was that a failure? |
| 528 |
|
| 529 |
// Empty? No topic? |
| 530 |
if ( empty( $notice ) || empty( $topic_id ) || !$topic = bbp_get_topic( $topic_id ) ) |
| 531 |
return; |
| 532 |
|
| 533 |
$topic_title = esc_html( bbp_get_topic_title( $topic->ID ) ); |
| 534 |
|
| 535 |
switch ( $notice ) { |
| 536 |
case 'opened' : |
| 537 |
$message = $is_failure == true ? sprintf( __( 'There was a problem opening the topic "%1$s".', 'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully opened.', 'bbpress' ), $topic_title ); |
| 538 |
break; |
| 539 |
|
| 540 |
case 'closed' : |
| 541 |
$message = $is_failure == true ? sprintf( __( 'There was a problem closing the topic "%1$s".', 'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully closed.', 'bbpress' ), $topic_title ); |
| 542 |
break; |
| 543 |
|
| 544 |
case 'super_sticked' : |
| 545 |
$message = $is_failure == true ? sprintf( __( 'There was a problem sticking the topic "%1$s" to front.', 'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully sticked to front.', 'bbpress' ), $topic_title ); |
| 546 |
break; |
| 547 |
|
| 548 |
case 'sticked' : |
| 549 |
$message = $is_failure == true ? sprintf( __( 'There was a problem sticking the topic "%1$s".', 'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully sticked.', 'bbpress' ), $topic_title ); |
| 550 |
break; |
| 551 |
|
| 552 |
case 'unsticked' : |
| 553 |
$message = $is_failure == true ? sprintf( __( 'There was a problem unsticking the topic "%1$s".', 'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully unsticked.', 'bbpress' ), $topic_title ); |
| 554 |
break; |
| 555 |
|
| 556 |
case 'spammed' : |
| 557 |
$message = $is_failure == true ? sprintf( __( 'There was a problem marking the topic "%1$s" as spam.', 'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully marked as spam.', 'bbpress' ), $topic_title ); |
| 558 |
break; |
| 559 |
|
| 560 |
case 'unspammed' : |
| 561 |
$message = $is_failure == true ? sprintf( __( 'There was a problem unmarking the topic "%1$s" as spam.', 'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully unmarked as spam.', 'bbpress' ), $topic_title ); |
| 562 |
break; |
| 563 |
} |
| 564 |
|
| 565 |
// Do additional topic toggle notice filters (admin side) |
| 566 |
$message = apply_filters( 'bbp_toggle_topic_notice_admin', $message, $topic->ID, $notice, $is_failure ); |
| 567 |
|
| 568 |
?> |
| 569 |
|
| 570 |
<div id="message" class="<?php echo $is_failure == true ? 'error' : 'updated'; ?> fade"> |
| 571 |
<p style="line-height: 150%"><?php echo $message; ?></p> |
| 572 |
</div> |
| 573 |
|
| 574 |
<?php |
| 575 |
} |
| 576 |
} |
| 577 |
|
| 578 |
/** |
| 579 |
* Manage the column headers for the topics page |
| 580 |
* |
| 581 |
* @since bbPress (r2485) |
| 582 |
* |
| 583 |
* @param array $columns The columns |
| 584 |
* @uses apply_filters() Calls 'bbp_admin_topics_column_headers' with |
| 585 |
* the columns |
| 586 |
* @return array $columns bbPress topic columns |
| 587 |
*/ |
| 588 |
function topics_column_headers( $columns ) { |
| 589 |
$columns = array( |
| 590 |
'cb' => '<input type="checkbox" />', |
| 591 |
'title' => __( 'Topics', 'bbpress' ), |
| 592 |
'bbp_topic_forum' => __( 'Forum', 'bbpress' ), |
| 593 |
'bbp_topic_reply_count' => __( 'Replies', 'bbpress' ), |
| 594 |
'bbp_topic_voice_count' => __( 'Voices', 'bbpress' ), |
| 595 |
'bbp_topic_author' => __( 'Author', 'bbpress' ), |
| 596 |
'bbp_topic_created' => __( 'Created', 'bbpress' ), |
| 597 |
'bbp_topic_freshness' => __( 'Freshness', 'bbpress' ) |
| 598 |
); |
| 599 |
|
| 600 |
return apply_filters( 'bbp_admin_topics_column_headers', $columns ); |
| 601 |
} |
| 602 |
|
| 603 |
/** |
| 604 |
* Print extra columns for the topics page |
| 605 |
* |
| 606 |
* @since bbPress (r2485) |
| 607 |
* |
| 608 |
* @param string $column Column |
| 609 |
* @param int $topic_id Topic id |
| 610 |
* @uses bbp_get_topic_forum_id() To get the forum id of the topic |
| 611 |
* @uses bbp_forum_title() To output the topic's forum title |
| 612 |
* @uses apply_filters() Calls 'topic_forum_row_actions' with an array |
| 613 |
* of topic forum actions |
| 614 |
* @uses bbp_get_forum_permalink() To get the forum permalink |
| 615 |
* @uses admin_url() To get the admin url of post.php |
| 616 |
* @uses add_query_arg() To add custom args to the url |
| 617 |
* @uses bbp_topic_reply_count() To output the topic reply count |
| 618 |
* @uses bbp_topic_voice_count() To output the topic voice count |
| 619 |
* @uses bbp_topic_author_display_name() To output the topic author name |
| 620 |
* @uses get_the_date() Get the topic creation date |
| 621 |
* @uses get_the_time() Get the topic creation time |
| 622 |
* @uses esc_attr() To sanitize the topic creation time |
| 623 |
* @uses bbp_get_topic_last_active_time() To get the time when the topic was |
| 624 |
* last active |
| 625 |
* @uses do_action() Calls 'bbp_admin_topics_column_data' with the |
| 626 |
* column and topic id |
| 627 |
*/ |
| 628 |
function topics_column_data( $column, $topic_id ) { |
| 629 |
|
| 630 |
// Get topic forum ID |
| 631 |
$forum_id = bbp_get_topic_forum_id( $topic_id ); |
| 632 |
|
| 633 |
// Populate column data |
| 634 |
switch ( $column ) { |
| 635 |
|
| 636 |
// Forum |
| 637 |
case 'bbp_topic_forum' : |
| 638 |
|
| 639 |
// Output forum name |
| 640 |
if ( !empty( $forum_id ) ) { |
| 641 |
|
| 642 |
// Forum Title |
| 643 |
if ( !$forum_title = bbp_get_forum_title( $forum_id ) ) |
| 644 |
$forum_title = __( 'No Forum', 'bbpress' ); |
| 645 |
|
| 646 |
// Output the title |
| 647 |
echo $forum_title; |
| 648 |
|
| 649 |
} else { |
| 650 |
_e( '(No Forum)', 'bbpress' ); |
| 651 |
} |
| 652 |
|
| 653 |
break; |
| 654 |
|
| 655 |
// Reply Count |
| 656 |
case 'bbp_topic_reply_count' : |
| 657 |
bbp_topic_reply_count( $topic_id ); |
| 658 |
break; |
| 659 |
|
| 660 |
// Reply Count |
| 661 |
case 'bbp_topic_voice_count' : |
| 662 |
bbp_topic_voice_count( $topic_id ); |
| 663 |
break; |
| 664 |
|
| 665 |
// Author |
| 666 |
case 'bbp_topic_author' : |
| 667 |
bbp_topic_author_display_name( $topic_id ); |
| 668 |
break; |
| 669 |
|
| 670 |
// Freshness |
| 671 |
case 'bbp_topic_created': |
| 672 |
printf( __( '%1$s <br /> %2$s', 'bbpress' ), |
| 673 |
get_the_date(), |
| 674 |
esc_attr( get_the_time() ) |
| 675 |
); |
| 676 |
|
| 677 |
break; |
| 678 |
|
| 679 |
// Freshness |
| 680 |
case 'bbp_topic_freshness' : |
| 681 |
if ( $last_active = bbp_get_topic_last_active_time( $topic_id, false ) ) |
| 682 |
printf( __( '%s ago', 'bbpress' ), $last_active ); |
| 683 |
else |
| 684 |
_e( 'No Replies', 'bbpress' ); // This should never happen |
| 685 |
|
| 686 |
break; |
| 687 |
|
| 688 |
// Do an action for anything else |
| 689 |
default : |
| 690 |
do_action( 'bbp_admin_topics_column_data', $column, $topic_id ); |
| 691 |
break; |
| 692 |
} |
| 693 |
} |
| 694 |
|
| 695 |
/** |
| 696 |
* Topic Row actions |
| 697 |
* |
| 698 |
* Remove the quick-edit action link under the topic title and add the |
| 699 |
* content and close/stick/spam links |
| 700 |
* |
| 701 |
* @since bbPress (r2485) |
| 702 |
* |
| 703 |
* @param array $actions Actions |
| 704 |
* @param array $topic Topic object |
| 705 |
* @uses bbp_get_topic_post_type() To get the topic post type |
| 706 |
* @uses bbp_topic_content() To output topic content |
| 707 |
* @uses bbp_get_topic_permalink() To get the topic link |
| 708 |
* @uses bbp_get_topic_title() To get the topic title |
| 709 |
* @uses current_user_can() To check if the current user can edit or |
| 710 |
* delete the topic |
| 711 |
* @uses bbp_is_topic_open() To check if the topic is open |
| 712 |
* @uses bbp_is_topic_spam() To check if the topic is marked as spam |
| 713 |
* @uses bbp_is_topic_sticky() To check if the topic is a sticky or a |
| 714 |
* super sticky |
| 715 |
* @uses get_post_type_object() To get the topic post type object |
| 716 |
* @uses add_query_arg() To add custom args to the url |
| 717 |
* @uses remove_query_arg() To remove custom args from the url |
| 718 |
* @uses wp_nonce_url() To nonce the url |
| 719 |
* @uses get_delete_post_link() To get the delete post link of the topic |
| 720 |
* @return array $actions Actions |
| 721 |
*/ |
| 722 |
function topics_row_actions( $actions, $topic ) { |
| 723 |
global $bbp; |
| 724 |
|
| 725 |
if ( $topic->post_type == $this->post_type ) { |
| 726 |
unset( $actions['inline hide-if-no-js'] ); |
| 727 |
|
| 728 |
// Show view link if it's not set, the topic is trashed and the user can view trashed topics |
| 729 |
if ( empty( $actions['view'] ) && 'trash' == $topic->post_status && current_user_can( 'view_trash' ) ) |
| 730 |
$actions['view'] = '<a href="' . bbp_get_topic_permalink( $topic->ID ) . '" title="' . esc_attr( sprintf( __( 'View “%s”', 'bbpress' ), bbp_get_topic_title( $topic->ID ) ) ) . '" rel="permalink">' . __( 'View', 'bbpress' ) . '</a>'; |
| 731 |
|
| 732 |
// Only show the actions if the user is capable of viewing them :) |
| 733 |
if ( current_user_can( 'moderate', $topic->ID ) ) { |
| 734 |
|
| 735 |
// Close |
| 736 |
// Show the 'close' and 'open' link on published and closed posts only |
| 737 |
if ( in_array( $topic->post_status, array( 'publish', $bbp->closed_status_id ) ) ) { |
| 738 |
$close_uri = esc_url( wp_nonce_url( add_query_arg( array( 'topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_close' ), remove_query_arg( array( 'bbp_topic_toggle_notice', 'topic_id', 'failed', 'super' ) ) ), 'close-topic_' . $topic->ID ) ); |
| 739 |
if ( bbp_is_topic_open( $topic->ID ) ) |
| 740 |
$actions['closed'] = '<a href="' . $close_uri . '" title="' . esc_attr__( 'Close this topic', 'bbpress' ) . '">' . __( 'Close', 'bbpress' ) . '</a>'; |
| 741 |
else |
| 742 |
$actions['closed'] = '<a href="' . $close_uri . '" title="' . esc_attr__( 'Open this topic', 'bbpress' ) . '">' . __( 'Open', 'bbpress' ) . '</a>'; |
| 743 |
} |
| 744 |
|
| 745 |
// Dont show sticky if topic links is spam or trash |
| 746 |
if ( !bbp_is_topic_spam( $topic->ID ) && !bbp_is_topic_trash( $topic->ID ) ) { |
| 747 |
|
| 748 |
// Sticky |
| 749 |
$stick_uri = esc_url( wp_nonce_url( add_query_arg( array( 'topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_stick' ), remove_query_arg( array( 'bbp_topic_toggle_notice', 'topic_id', 'failed', 'super' ) ) ), 'stick-topic_' . $topic->ID ) ); |
| 750 |
if ( bbp_is_topic_sticky( $topic->ID ) ) { |
| 751 |
$actions['stick'] = '<a href="' . $stick_uri . '" title="' . esc_attr__( 'Unstick this topic', 'bbpress' ) . '">' . __( 'Unstick', 'bbpress' ) . '</a>'; |
| 752 |
} else { |
| 753 |
$super_uri = esc_url( wp_nonce_url( add_query_arg( array( 'topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_stick', 'super' => '1' ), remove_query_arg( array( 'bbp_topic_toggle_notice', 'topic_id', 'failed', 'super' ) ) ), 'stick-topic_' . $topic->ID ) ); |
| 754 |
$actions['stick'] = '<a href="' . $stick_uri . '" title="' . esc_attr__( 'Stick this topic to its forum', 'bbpress' ) . '">' . __( 'Stick', 'bbpress' ) . '</a> (<a href="' . $super_uri . '" title="' . esc_attr__( 'Stick this topic to front', 'bbpress' ) . '">' . __( 'to front', 'bbpress' ) . '</a>)'; |
| 755 |
} |
| 756 |
} |
| 757 |
|
| 758 |
// Spam |
| 759 |
$spam_uri = esc_url( wp_nonce_url( add_query_arg( array( 'topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_spam' ), remove_query_arg( array( 'bbp_topic_toggle_notice', 'topic_id', 'failed', 'super' ) ) ), 'spam-topic_' . $topic->ID ) ); |
| 760 |
if ( bbp_is_topic_spam( $topic->ID ) ) |
| 761 |
$actions['spam'] = '<a href="' . $spam_uri . '" title="' . esc_attr__( 'Mark the topic as not spam', 'bbpress' ) . '">' . __( 'Not spam', 'bbpress' ) . '</a>'; |
| 762 |
else |
| 763 |
$actions['spam'] = '<a href="' . $spam_uri . '" title="' . esc_attr__( 'Mark this topic as spam', 'bbpress' ) . '">' . __( 'Spam', 'bbpress' ) . '</a>'; |
| 764 |
|
| 765 |
} |
| 766 |
|
| 767 |
// Do not show trash links for spam topics, or spam links for trashed topics |
| 768 |
if ( current_user_can( 'delete_topic', $topic->ID ) ) { |
| 769 |
if ( $bbp->trash_status_id == $topic->post_status ) { |
| 770 |
$post_type_object = get_post_type_object( bbp_get_topic_post_type() ); |
| 771 |
$actions['untrash'] = "<a title='" . esc_attr( __( 'Restore this item from the Trash', 'bbpress' ) ) . "' href='" . wp_nonce_url( add_query_arg( array( '_wp_http_referer' => add_query_arg( array( 'post_type' => bbp_get_topic_post_type() ), admin_url( 'edit.php' ) ) ), admin_url( sprintf( $post_type_object->_edit_link . '&action=untrash', $topic->ID ) ) ), 'untrash-' . $topic->post_type . '_' . $topic->ID ) . "'>" . __( 'Restore', 'bbpress' ) . "</a>"; |
| 772 |
} elseif ( EMPTY_TRASH_DAYS ) { |
| 773 |
$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_topic_post_type() ), admin_url( 'edit.php' ) ) ), get_delete_post_link( $topic->ID ) ) . "'>" . __( 'Trash', 'bbpress' ) . "</a>"; |
| 774 |
} |
| 775 |
|
| 776 |
if ( $bbp->trash_status_id == $topic->post_status || !EMPTY_TRASH_DAYS ) { |
| 777 |
$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_topic_post_type() ), admin_url( 'edit.php' ) ) ), get_delete_post_link( $topic->ID, '', true ) ) . "'>" . __( 'Delete Permanently', 'bbpress' ) . "</a>"; |
| 778 |
} elseif ( $bbp->spam_status_id == $topic->post_status ) { |
| 779 |
unset( $actions['trash'] ); |
| 780 |
} |
| 781 |
} |
| 782 |
} |
| 783 |
|
| 784 |
return $actions; |
| 785 |
} |
| 786 |
|
| 787 |
/** |
| 788 |
* Add forum dropdown to topic and reply list table filters |
| 789 |
* |
| 790 |
* @since bbPress (r2991) |
| 791 |
* |
| 792 |
* @uses bbp_get_reply_post_type() To get the reply post type |
| 793 |
* @uses bbp_get_topic_post_type() To get the topic post type |
| 794 |
* @uses bbp_dropdown() To generate a forum dropdown |
| 795 |
* @return bool False. If post type is not topic or reply |
| 796 |
*/ |
| 797 |
function filter_dropdown() { |
| 798 |
|
| 799 |
// Bail if not viewing the topics list |
| 800 |
if ( |
| 801 |
// post_type exists in _GET |
| 802 |
empty( $_GET['post_type'] ) || |
| 803 |
|
| 804 |
// post_type is not topic type |
| 805 |
( $_GET['post_type'] != $this->post_type ) |
| 806 |
) |
| 807 |
return; |
| 808 |
|
| 809 |
// Add Empty Spam button |
| 810 |
if ( !empty( $_GET['post_status'] ) && ( 'spam' == $_GET['post_status'] ) && current_user_can( 'moderate' ) ) { |
| 811 |
wp_nonce_field( 'bulk-destroy', '_destroy_nonce' ); |
| 812 |
$title = esc_attr__( 'Empty Spam', 'bbpress' ); |
| 813 |
submit_button( $title, 'button-secondary apply', 'delete_all', false ); |
| 814 |
} |
| 815 |
|
| 816 |
// Get which forum is selected |
| 817 |
$selected = !empty( $_GET['bbp_forum_id'] ) ? $_GET['bbp_forum_id'] : ''; |
| 818 |
|
| 819 |
// Show the forums dropdown |
| 820 |
bbp_dropdown( array( |
| 821 |
'selected' => $selected, |
| 822 |
'show_none' => __( 'In all forums', 'bbpress' ) |
| 823 |
) ); |
| 824 |
} |
| 825 |
|
| 826 |
/** |
| 827 |
* Adjust the request query and include the forum id |
| 828 |
* |
| 829 |
* @since bbPress (r2991) |
| 830 |
* |
| 831 |
* @param array $query_vars Query variables from {@link WP_Query} |
| 832 |
* @uses is_admin() To check if it's the admin section |
| 833 |
* @uses bbp_get_topic_post_type() To get the topic post type |
| 834 |
* @uses bbp_get_reply_post_type() To get the reply post type |
| 835 |
* @return array Processed Query Vars |
| 836 |
*/ |
| 837 |
function filter_post_rows( $query_vars ) { |
| 838 |
global $pagenow; |
| 839 |
|
| 840 |
// Avoid poisoning other requests |
| 841 |
if ( |
| 842 |
// Only look in admin |
| 843 |
!is_admin() || |
| 844 |
|
| 845 |
// Make sure the current page is for post rows |
| 846 |
( 'edit.php' != $pagenow ) || |
| 847 |
|
| 848 |
// Make sure we're looking for a post_type |
| 849 |
empty( $_GET['post_type'] ) || |
| 850 |
|
| 851 |
// Make sure we're looking at bbPress topics |
| 852 |
( $_GET['post_type'] != $this->post_type ) |
| 853 |
) |
| 854 |
|
| 855 |
// We're in no shape to filter anything, so return |
| 856 |
return $query_vars; |
| 857 |
|
| 858 |
// Add post_parent query_var if one is present |
| 859 |
if ( !empty( $_GET['bbp_forum_id'] ) ) { |
| 860 |
$query_vars['meta_key'] = '_bbp_forum_id'; |
| 861 |
$query_vars['meta_value'] = $_GET['bbp_forum_id']; |
| 862 |
} |
| 863 |
|
| 864 |
// Return manipulated query_vars |
| 865 |
return $query_vars; |
| 866 |
} |
| 867 |
|
| 868 |
/** |
| 869 |
* Custom user feedback messages for topic post type |
| 870 |
* |
| 871 |
* @since bbPress (r3080) |
| 872 |
* |
| 873 |
* @global WP_Query $post |
| 874 |
* @global int $post_ID |
| 875 |
* @uses get_post_type() |
| 876 |
* @uses bbp_get_topic_permalink() |
| 877 |
* @uses wp_post_revision_title() |
| 878 |
* @uses esc_url() |
| 879 |
* @uses add_query_arg() |
| 880 |
* |
| 881 |
* @param array $messages |
| 882 |
* |
| 883 |
* @return array |
| 884 |
*/ |
| 885 |
function updated_messages( $messages ) { |
| 886 |
global $post, $post_ID; |
| 887 |
|
| 888 |
if ( get_post_type( $post_ID ) != $this->post_type ) |
| 889 |
return $messages; |
| 890 |
|
| 891 |
// URL for the current topic |
| 892 |
$topic_url = bbp_get_topic_permalink( $post_ID ); |
| 893 |
|
| 894 |
// Messages array |
| 895 |
$messages[$this->post_type] = array( |
| 896 |
0 => '', // Left empty on purpose |
| 897 |
|
| 898 |
// Updated |
| 899 |
1 => sprintf( __( 'Topic updated. <a href="%s">View topic</a>' ), $topic_url ), |
| 900 |
|
| 901 |
// Custom field updated |
| 902 |
2 => __( 'Custom field updated.', 'bbpress' ), |
| 903 |
|
| 904 |
// Custom field deleted |
| 905 |
3 => __( 'Custom field deleted.', 'bbpress' ), |
| 906 |
|
| 907 |
// Topic updated |
| 908 |
4 => __( 'Topic updated.', 'bbpress' ), |
| 909 |
|
| 910 |
// Restored from revision |
| 911 |
// translators: %s: date and time of the revision |
| 912 |
5 => isset( $_GET['revision'] ) |
| 913 |
? sprintf( __( 'Topic restored to revision from %s', 'bbpress' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) |
| 914 |
: false, |
| 915 |
|
| 916 |
// Topic created |
| 917 |
6 => sprintf( __( 'Topic created. <a href="%s">View topic</a>', 'bbpress' ), $topic_url ), |
| 918 |
|
| 919 |
// Topic saved |
| 920 |
7 => __( 'Topic saved.', 'bbpress' ), |
| 921 |
|
| 922 |
// Topic submitted |
| 923 |
8 => sprintf( __( 'Topic submitted. <a target="_blank" href="%s">Preview topic</a>', 'bbpress' ), esc_url( add_query_arg( 'preview', 'true', $topic_url ) ) ), |
| 924 |
|
| 925 |
// Topic scheduled |
| 926 |
9 => sprintf( __( 'Topic scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview topic</a>', 'bbpress' ), |
| 927 |
// translators: Publish box date format, see http://php.net/date |
| 928 |
date_i18n( __( 'M j, Y @ G:i' ), |
| 929 |
strtotime( $post->post_date ) ), |
| 930 |
$topic_url ), |
| 931 |
|
| 932 |
// Topic draft updated |
| 933 |
10 => sprintf( __( 'Topic draft updated. <a target="_blank" href="%s">Preview topic</a>', 'bbpress' ), esc_url( add_query_arg( 'preview', 'true', $topic_url ) ) ), |
| 934 |
); |
| 935 |
|
| 936 |
return $messages; |
| 937 |
} |
| 938 |
} |
| 939 |
endif; // class_exists check |
| 940 |
|
| 941 |
/** |
| 942 |
* Setup bbPress Topics Admin |
| 943 |
* |
| 944 |
* @since bbPress (r2596) |
| 945 |
* |
| 946 |
* @uses BBP_Forums_Admin |
| 947 |
*/ |
| 948 |
function bbp_admin_topics() { |
| 949 |
global $bbp; |
| 950 |
|
| 951 |
$bbp->admin->topics = new BBP_Topics_Admin(); |
| 952 |
} |
| 953 |
|
| 954 |
?> |
| 955 |
|