PluginProbe
bbPress / 2.0-beta-3
bbPress v2.0-beta-3
2.6.17 trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 2.2 2.2.1 All 72 releases
bbpress / bbp-admin / bbp-replies.php

bbp-replies.php in bbPress 2.0-beta-3, at bbp-admin/bbp-replies.php

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