[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

/src/includes/admin/ -> topics.php (source)

   1  <?php
   2  
   3  /**
   4   * bbPress Topics Admin Class
   5   *
   6   * @package bbPress
   7   * @subpackage Administration
   8   */
   9  
  10  // Exit if accessed directly
  11  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 2.0.0 bbPress (r2464)
  20   */
  21  class BBP_Topics_Admin {
  22  
  23      /** Variables *************************************************************/
  24  
  25      /**
  26       * @var The post type of this admin component
  27       */
  28      private $post_type = '';
  29  
  30      /** Functions *************************************************************/
  31  
  32      /**
  33       * The main bbPress topics admin loader
  34       *
  35       * @since 2.0.0 bbPress (r2515)
  36       */
  37  	public function __construct() {
  38          $this->setup_globals();
  39          $this->setup_actions();
  40      }
  41  
  42      /**
  43       * Setup the admin hooks, actions and filters
  44       *
  45       * @since 2.0.0 bbPress (r2646)
  46       * @since 2.6.0 bbPress (r6101) Added bulk actions
  47       *
  48       * @access private
  49       */
  50  	private function setup_actions() {
  51  
  52          // Messages
  53          add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) );
  54  
  55          // Topic bulk actions, added in WordPress 4.7, see #WP16031.
  56          if ( bbp_get_major_wp_version() >= 4.7 ) {
  57              add_filter( 'bulk_actions-edit-topic',        array( $this, 'bulk_actions' ) );
  58              add_filter( 'handle_bulk_actions-edit-topic', array( $this, 'handle_bulk_actions' ), 10, 3 );
  59              add_filter( 'bulk_post_updated_messages',     array( $this, 'bulk_post_updated_messages' ), 10, 2 );
  60          }
  61  
  62          // Topic column headers.
  63          add_filter( 'manage_' . $this->post_type . '_posts_columns',        array( $this, 'column_headers' ) );
  64  
  65          // Topic columns (in post row)
  66          add_action( 'manage_' . $this->post_type . '_posts_custom_column',  array( $this, 'column_data' ), 10, 2 );
  67          add_filter( 'post_row_actions',                                     array( $this, 'row_actions' ), 10, 2 );
  68  
  69          // Topic meta-box actions
  70          add_action( 'add_meta_boxes', array( $this, 'attributes_metabox'    ) );
  71          add_action( 'add_meta_boxes', array( $this, 'author_metabox'        ) );
  72          add_action( 'add_meta_boxes', array( $this, 'replies_metabox'       ) );
  73          add_action( 'add_meta_boxes', array( $this, 'engagements_metabox'   ) );
  74          add_action( 'add_meta_boxes', array( $this, 'favorites_metabox'     ) );
  75          add_action( 'add_meta_boxes', array( $this, 'subscriptions_metabox' ) );
  76          add_action( 'add_meta_boxes', array( $this, 'comments_metabox'      ) );
  77          add_action( 'save_post',      array( $this, 'save_meta_boxes'       ) );
  78  
  79          // Check if there are any bbp_toggle_topic_* requests on admin_init, also have a message displayed
  80          add_action( 'load-edit.php',  array( $this, 'toggle_topic'        ) );
  81          add_action( 'load-edit.php',  array( $this, 'toggle_topic_notice' ) );
  82  
  83          // Add ability to filter topics and replies per forum
  84          add_filter( 'restrict_manage_posts', array( $this, 'filter_dropdown'  ) );
  85          add_filter( 'bbp_request',           array( $this, 'filter_post_rows' ) );
  86  
  87          // Empty spam
  88          add_filter( 'manage_posts_extra_tablenav', array( $this, 'filter_empty_spam' ) );
  89  
  90          // Contextual Help
  91          add_action( 'load-edit.php',     array( $this, 'edit_help' ) );
  92          add_action( 'load-post.php',     array( $this, 'new_help'  ) );
  93          add_action( 'load-post-new.php', array( $this, 'new_help'  ) );
  94      }
  95  
  96      /**
  97       * Admin globals
  98       *
  99       * @since 2.0.0 bbPress (r2646)
 100       *
 101       * @access private
 102       */
 103  	private function setup_globals() {
 104          $this->post_type = bbp_get_topic_post_type();
 105      }
 106  
 107      /** Contextual Help *******************************************************/
 108  
 109      /**
 110       * Contextual help for bbPress topic edit page
 111       *
 112       * @since 2.0.0 bbPress (r3119)
 113       */
 114  	public function edit_help() {
 115  
 116          // Overview
 117          get_current_screen()->add_help_tab( array(
 118              'id'        => 'overview',
 119              'title'        => __( 'Overview', 'bbpress' ),
 120              'content'    =>
 121                  '<p>' . __( 'This screen displays the individual topics on your site. You can customize the display of this screen to suit your workflow.', 'bbpress' ) . '</p>'
 122          ) );
 123  
 124          // Screen Content
 125          get_current_screen()->add_help_tab( array(
 126              'id'        => 'screen-content',
 127              'title'        => __( 'Screen Content', 'bbpress' ),
 128              'content'    =>
 129                  '<p>' . __( 'You can customize the display of this screen&#8217;s contents in a number of ways:', 'bbpress' ) . '</p>' .
 130                  '<ul>' .
 131                      '<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>' .
 132                      '<li>' . __( 'You can filter the list of topics by topic status using the text links in the upper left to show All, Published, Draft, Pending, Trashed, Closed, or Spam  topics. The default view is to show all topics.', 'bbpress' ) . '</li>' .
 133                      '<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>' .
 134                      '<li>' . __( 'You can refine the list to show only topics in a specific forum or from a specific month by using the dropdown menus above the topics list. Click the Filter button after making your selection.',                 'bbpress' ) . '</li>' .
 135                  '</ul>'
 136          ) );
 137  
 138          // 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 topics list will display action links that allow you to manage your topic. You can perform the following actions:', 'bbpress' ) . '</p>' .
 144                  '<ul>' .
 145                      '<li>' . __( '<strong>Edit</strong> takes you to the editing screen for that topic. You can also reach that screen by clicking on the topic title.',                            'bbpress' ) . '</li>' .
 146                      '<li>' . __( '<strong>Stick</strong> will keep the selected topic &#8217;pinned&#8217; to the top the parent forum topic list.',                                                'bbpress' ) . '</li>' .
 147                      '<li>' . __( '<strong>Stick <em>(to front)</em></strong> will keep the selected topic &#8217;pinned&#8217; to the top of ALL forums and be visable in any forums topics list.', 'bbpress' ) . '</li>' .
 148                      '<li>' . __( '<strong>Approve</strong> will change the status from pending to publish.',                                                                                        'bbpress' ) . '</li>' .
 149                      '<li>' . __( '<strong>Close</strong> will mark the selected topic as &#8217;closed&#8217; and disable the ability to post new replies to it.',                                  'bbpress' ) . '</li>' .
 150                      '<li>' . __( '<strong>Spam</strong> removes your topic from this list and places it in the spam queue, from which you can permanently delete it.',                              'bbpress' ) . '</li>' .
 151                      '<li>' . __( '<strong>Trash</strong> removes your topic from this list and places it in the trash, from which you can permanently delete it.',                                  'bbpress' ) . '</li>' .
 152                      '<li>' . __( '<strong>View</strong> will take you to your live site to view the topic.',                                                                                        'bbpress' ) . '</li>' .
 153                  '</ul>'
 154          ) );
 155  
 156          // Bulk Actions
 157          get_current_screen()->add_help_tab( array(
 158              'id'        => 'bulk-actions',
 159              'title'        => __( 'Bulk Actions', 'bbpress' ),
 160              'content'    =>
 161                  '<p>' . __( 'You can also edit, spam, or move multiple topics to the trash at once. Select the topics 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>' .
 162                  '<p>' . __( 'When using Bulk Edit, you can change the metadata (categories, author, etc.) 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' ) . '</p>'
 163          ) );
 164  
 165          // Help Sidebar
 166          get_current_screen()->set_help_sidebar(
 167              '<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' .
 168              '<p>' . __( '<a href="https://codex.bbpress.org" target="_blank">bbPress Documentation</a>',     'bbpress' ) . '</p>' .
 169              '<p>' . __( '<a href="https://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>',  'bbpress' ) . '</p>'
 170          );
 171      }
 172  
 173      /**
 174       * Contextual help for bbPress topic edit page
 175       *
 176       * @since 2.0.0 bbPress (r3119)
 177       */
 178  	public function new_help() {
 179  
 180          $customize_display = '<p>' . __( 'The 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 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>';
 181  
 182          get_current_screen()->add_help_tab( array(
 183              'id'      => 'customize-display',
 184              'title'   => __( 'Customizing This Display', 'bbpress' ),
 185              'content' => $customize_display,
 186          ) );
 187  
 188          get_current_screen()->add_help_tab( array(
 189              'id'      => 'title-topic-editor',
 190              'title'   => __( 'Title and Topic Editor', 'bbpress' ),
 191              'content' =>
 192                  '<p>' . __( '<strong>Title</strong> - Enter a title for your topic. After you enter a title, you&#8217;ll see the permalink below, which you can edit.', 'bbpress' ) . '</p>' .
 193                  '<p>' . __( '<strong>Topic 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 HTML mode allows you to enter raw HTML along with your topic text. You can insert media files by clicking the icons above the topic 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 topic editor.', 'bbpress' ) . '</p>'
 194          ) );
 195  
 196          $publish_box = '<p>' . __( '<strong>Publish</strong> - You can set the terms of publishing your topic 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 topic 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 topic to be published in the future or backdate a topic.', 'bbpress' ) . '</p>';
 197  
 198          if ( current_theme_supports( 'topic-thumbnails' ) && post_type_supports( bbp_get_topic_post_type(), 'thumbnail' ) ) {
 199              $publish_box .= '<p>' . __( '<strong>Featured Image</strong> - This allows you to associate an image with your topic without inserting it. This is usually useful only if your theme makes use of the featured image as a topic thumbnail on the home page, a custom header, etc.', 'bbpress' ) . '</p>';
 200          }
 201  
 202          get_current_screen()->add_help_tab( array(
 203              'id'      => 'topic-attributes',
 204              'title'   => __( 'Topic Attributes', 'bbpress' ),
 205              'content' =>
 206                  '<p>' . __( 'Select the attributes that your topic should have:', 'bbpress' ) . '</p>' .
 207                  '<ul>' .
 208                      '<li>' . __( '<strong>Forum</strong> 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' ) . '</li>' .
 209                      '<li>' . __( '<strong>Topic Type</strong> dropdown indicates the sticky status of the topic. Selecting the super sticky option would stick the topic to the front of your forums, i.e. the topic index, sticky option would stick the topic to its respective forum. Selecting normal would not stick the topic anywhere.', 'bbpress' ) . '</li>' .
 210                  '</ul>'
 211          ) );
 212  
 213          get_current_screen()->add_help_tab( array(
 214              'id'      => 'publish-box',
 215              'title'   => __( 'Publish Box', 'bbpress' ),
 216              'content' => $publish_box,
 217          ) );
 218  
 219          get_current_screen()->set_help_sidebar(
 220              '<p><strong>' . __( 'For more information:', 'bbpress' ) . '</strong></p>' .
 221              '<p>' . __( '<a href="https://codex.bbpress.org" target="_blank">bbPress Documentation</a>',    'bbpress' ) . '</p>' .
 222              '<p>' . __( '<a href="https://bbpress.org/forums/" target="_blank">bbPress Support Forums</a>', 'bbpress' ) . '</p>'
 223          );
 224      }
 225  
 226      /**
 227       * Add spam/unspam bulk actions to the bulk action dropdown.
 228       *
 229       * @since 2.6.0 bbPress (r6101)
 230       *
 231       * @param array $actions The list of bulk actions.
 232       * @return array The filtered list of bulk actions.
 233       */
 234  	public function bulk_actions( $actions ) {
 235  
 236          if ( current_user_can( 'moderate' ) ) {
 237              if ( bbp_get_spam_status_id() === get_query_var( 'post_status' ) ) {
 238                  $actions['unspam'] = esc_html__( 'Unspam', 'bbpress' );
 239              } else {
 240                  $actions['spam'] = esc_html__( 'Spam', 'bbpress' );
 241              }
 242          }
 243  
 244          return $actions;
 245      }
 246  
 247      /**
 248       * Add custom bulk action updated messages for topics.
 249       *
 250       * @since 2.6.0 bbPress (r6101)
 251       *
 252       * @param array $bulk_messages Arrays of messages, each keyed by the corresponding post type.
 253       * @param array $bulk_counts   Array of item counts for each message, used to build internationalized strings.
 254       */
 255  	public function bulk_post_updated_messages( $bulk_messages, $bulk_counts ) {
 256          $bulk_messages['topic']['updated'] = _n( '%s topic updated.', '%s topics updated.', $bulk_counts['updated'], 'bbpress' );
 257          $bulk_messages['topic']['locked']  = ( 1 === $bulk_counts['locked'] )
 258              ? __( '1 topic not updated, somebody is editing it.', 'bbpress' )
 259              : _n( '%s topic not updated, somebody is editing it.', '%s topics not updated, somebody is editing them.', $bulk_counts['locked'], 'bbpress' );
 260  
 261          return $bulk_messages;
 262      }
 263  
 264      /**
 265       * Handle spam/unspam bulk actions.
 266       *
 267       * @since 2.6.0 bbPress (r6101)
 268       *
 269       * @param string $sendback The sendback URL.
 270       * @param string $doaction The action to be taken.
 271       * @param array  $post_ids The post IDS to take the action on.
 272       * @return string The sendback URL.
 273       */
 274  	public function handle_bulk_actions( $sendback, $doaction, $post_ids ) {
 275  
 276          $sendback = remove_query_arg( array( 'spam', 'unspam' ), $sendback );
 277          $updated  = $locked = 0;
 278  
 279          if ( 'spam' === $doaction ) {
 280  
 281              foreach ( (array) $post_ids as $post_id ) {
 282                  if ( ! current_user_can( 'moderate', $post_id ) ) {
 283                      wp_die( esc_html__( 'Sorry, you are not allowed to spam this item.', 'bbpress' ) );
 284                  }
 285  
 286                  if ( wp_check_post_lock( $post_id ) ) {
 287                      $locked++;
 288                      continue;
 289                  }
 290  
 291                  if ( ! bbp_spam_topic( $post_id ) ) {
 292                      wp_die( esc_html__( 'Error in spamming topic.', 'bbpress' ) );
 293                  }
 294  
 295                  $updated++;
 296              }
 297  
 298              $sendback = add_query_arg( array(
 299                  'updated' => $updated,
 300                  'ids'     => implode( ',', $post_ids ),
 301                  'locked'  => $locked
 302              ), $sendback );
 303  
 304          } elseif ( 'unspam' === $doaction ) {
 305  
 306              foreach ( (array) $post_ids as $post_id ) {
 307                  if ( ! current_user_can( 'moderate', $post_id ) ) {
 308                      wp_die( esc_html__( 'Sorry, you are not allowed to unspam this topic.', 'bbpress' ) );
 309                  }
 310  
 311                  if ( wp_check_post_lock( $post_id ) ) {
 312                      $locked++;
 313                      continue;
 314                  }
 315  
 316                  if ( ! bbp_unspam_topic( $post_id ) ) {
 317                      wp_die( esc_html__( 'Error in unspamming topic.', 'bbpress' ) );
 318                  }
 319  
 320                  $updated++;
 321              }
 322  
 323              $sendback = add_query_arg( array(
 324                  'updated' => $updated,
 325                  'ids'     => implode( ',', $post_ids ),
 326                  'locked'  => $locked
 327              ), $sendback );
 328          }
 329  
 330          return $sendback;
 331      }
 332  
 333      /**
 334       * Add the topic attributes meta-box
 335       *
 336       * @since 2.0.0 bbPress (r2744)
 337       */
 338  	public function attributes_metabox() {
 339          add_meta_box(
 340              'bbp_topic_attributes',
 341              esc_html__( 'Topic Attributes', 'bbpress' ),
 342              'bbp_topic_metabox',
 343              $this->post_type,
 344              'side',
 345              'high'
 346          );
 347      }
 348  
 349      /**
 350       * Add the author info meta-box
 351       *
 352       * @since 2.0.0 bbPress (r2828)
 353       */
 354  	public function author_metabox() {
 355  
 356          // Bail if post_type is not a topic
 357          if ( empty( $_GET['action'] ) || ( 'edit' !== $_GET['action'] ) ) {
 358              return;
 359          }
 360  
 361          // Add the meta-box
 362          add_meta_box(
 363              'bbp_author_metabox',
 364              esc_html__( 'Author Information', 'bbpress' ),
 365              'bbp_author_metabox',
 366              $this->post_type,
 367              'side',
 368              'high'
 369          );
 370      }
 371  
 372      /**
 373       * Add the replies meta-box
 374       *
 375       * Allows viewing & moderating of replies to a topic, based on the way
 376       * comments are visible on a blog post.
 377       *
 378       * @since 2.6.0 bbPress (r5886)
 379       */
 380  	public function replies_metabox() {
 381  
 382          // Bail if post_type is not a reply
 383          if ( empty( $_GET['action'] ) || ( 'edit' !== $_GET['action'] ) ) {
 384              return;
 385          }
 386  
 387          // Add the meta-box
 388          add_meta_box(
 389              'bbp_topic_replies_metabox',
 390              esc_html__( 'Replies', 'bbpress' ),
 391              'bbp_topic_replies_metabox',
 392              $this->post_type,
 393              'normal',
 394              'high'
 395          );
 396      }
 397  
 398      /**
 399       * Add the engagements meta-box
 400       *
 401       * Allows viewing of users who have engaged in a topic.
 402       *
 403       * @since 2.6.0 bbPress (r6333)
 404       */
 405  	public function engagements_metabox() {
 406  
 407          // Bail when creating a new topic
 408          if ( empty( $_GET['action'] ) || ( 'edit' !== $_GET['action'] ) ) {
 409              return;
 410          }
 411  
 412          // Bail if no engagements
 413          if ( ! bbp_is_engagements_active() ) {
 414              return;
 415          }
 416  
 417          // Add the meta-box
 418          add_meta_box(
 419              'bbp_topic_engagements_metabox',
 420              esc_html__( 'Engagements', 'bbpress' ),
 421              'bbp_topic_engagements_metabox',
 422              $this->post_type,
 423              'side',
 424              'low'
 425          );
 426      }
 427  
 428      /**
 429       * Add the favorites meta-box
 430       *
 431       * Allows viewing of users who have favorited a topic.
 432       *
 433       * @since 2.6.0 bbPress (r6197)
 434       */
 435  	public function favorites_metabox() {
 436  
 437          // Bail if post_type is not a reply
 438          if ( empty( $_GET['action'] ) || ( 'edit' !== $_GET['action'] ) ) {
 439              return;
 440          }
 441  
 442          // Bail if no favorites
 443          if ( ! bbp_is_favorites_active() ) {
 444              return;
 445          }
 446  
 447          // Add the meta-box
 448          add_meta_box(
 449              'bbp_topic_favorites_metabox',
 450              esc_html__( 'Favorites', 'bbpress' ),
 451              'bbp_topic_favorites_metabox',
 452              $this->post_type,
 453              'normal',
 454              'high'
 455          );
 456      }
 457  
 458      /**
 459       * Add the subscriptions meta-box
 460       *
 461       * Allows viewing of users who have subscribed to a topic.
 462       *
 463       * @since 2.6.0 bbPress (r6197)
 464       */
 465  	public function subscriptions_metabox() {
 466  
 467          // Bail if post_type is not a reply
 468          if ( empty( $_GET['action'] ) || ( 'edit' !== $_GET['action'] ) ) {
 469              return;
 470          }
 471  
 472          // Bail if no subscriptions
 473          if ( ! bbp_is_subscriptions_active() ) {
 474              return;
 475          }
 476  
 477          // Add the meta-box
 478          add_meta_box(
 479              'bbp_topic_subscriptions_metabox',
 480              esc_html__( 'Subscriptions', 'bbpress' ),
 481              'bbp_topic_subscriptions_metabox',
 482              $this->post_type,
 483              'normal',
 484              'high'
 485          );
 486      }
 487  
 488      /**
 489       * Remove comments & discussion meta-boxes if comments are not supported
 490       *
 491       * @since 2.6.0 bbPress (r6186)
 492       */
 493  	public function comments_metabox() {
 494          if ( ! post_type_supports( $this->post_type, 'comments' ) ) {
 495              remove_meta_box( 'commentstatusdiv', $this->post_type, 'normal' );
 496              remove_meta_box( 'commentsdiv',      $this->post_type, 'normal' );
 497          }
 498      }
 499  
 500      /**
 501       * Pass the topic attributes for processing
 502       *
 503       * @since 2.0.0 bbPress (r2746)
 504       *
 505       * @param int $topic_id Topic id
 506       * @return int Parent id
 507       */
 508  	public function save_meta_boxes( $topic_id ) {
 509  
 510          // Bail if doing an autosave
 511          if ( bbp_doing_autosave() ) {
 512              return $topic_id;
 513          }
 514  
 515          // Bail if not a post request
 516          if ( ! bbp_is_post_request() ) {
 517              return $topic_id;
 518          }
 519  
 520          // Check action exists
 521          if ( empty( $_POST['action'] ) ) {
 522              return $topic_id;
 523          }
 524  
 525          // Nonce check
 526          if ( empty( $_POST['bbp_topic_metabox'] ) || ! wp_verify_nonce( $_POST['bbp_topic_metabox'], 'bbp_topic_metabox_save' ) ) {
 527              return $topic_id;
 528          }
 529  
 530          // Bail if current user cannot edit this topic
 531          if ( ! current_user_can( 'edit_topic', $topic_id ) ) {
 532              return $topic_id;
 533          }
 534  
 535          // Get the forum ID
 536          $forum_id = ! empty( $_POST['parent_id'] ) ? (int) $_POST['parent_id'] : 0;
 537  
 538          // Get topic author data
 539          $anonymous_data = bbp_filter_anonymous_post_data();
 540          $author_id      = bbp_get_topic_author_id( $topic_id );
 541          $is_edit        = ( isset( $_POST['hidden_post_status'] ) && ( $_POST['hidden_post_status'] !== 'draft' ) );
 542  
 543          // Formally update the topic
 544          bbp_update_topic( $topic_id, $forum_id, $anonymous_data, $author_id, $is_edit );
 545  
 546          // Allow other fun things to happen
 547          do_action( 'bbp_topic_attributes_metabox_save', $topic_id, $forum_id       );
 548          do_action( 'bbp_author_metabox_save',           $topic_id, $anonymous_data );
 549  
 550          return $topic_id;
 551      }
 552  
 553      /**
 554       * Toggle topic
 555       *
 556       * Handles the admin-side opening/closing, sticking/unsticking and
 557       * spamming/unspamming of topics
 558       *
 559       * @since 2.0.0 bbPress (r2727)
 560       */
 561  	public function toggle_topic() {
 562  
 563          // Bail if not a topic toggle action
 564          if ( ! bbp_is_get_request() || empty( $_GET['action'] ) || empty( $_GET['topic_id'] ) ) {
 565              return;
 566          }
 567  
 568          // Bail if not an allowed action
 569          $action = sanitize_key( $_GET['action'] );
 570          if ( empty( $action ) || ! in_array( $action, $this->get_allowed_action_toggles(), true ) ) {
 571              return;
 572          }
 573  
 574          // Bail if topic is missing
 575          $topic_id = bbp_get_topic_id( $_GET['topic_id'] );
 576          if ( ! bbp_get_topic( $topic_id ) ) {
 577              wp_die( esc_html__( 'The topic was not found.', 'bbpress' ) );
 578          }
 579  
 580          // What is the user doing here?
 581          if ( ! current_user_can( 'moderate', $topic_id ) ) {
 582              wp_die( esc_html__( 'You do not have permission to do that.', 'bbpress' ) );
 583          }
 584  
 585          // Defaults
 586          $post_data = array( 'ID' => $topic_id );
 587          $message   = '';
 588          $success   = false;
 589  
 590          switch ( $action ) {
 591              case 'bbp_toggle_topic_approve' :
 592                  check_admin_referer( 'approve-topic_' . $topic_id );
 593  
 594                  $is_approve = bbp_is_topic_public( $topic_id );
 595                  $message    = ( true === $is_approve )
 596                      ? 'unapproved'
 597                      : 'approved';
 598                  $success    = ( true === $is_approve )
 599                      ? bbp_unapprove_topic( $topic_id )
 600                      : bbp_approve_topic( $topic_id );
 601  
 602                  break;
 603  
 604              case 'bbp_toggle_topic_close' :
 605                  check_admin_referer( 'close-topic_' . $topic_id );
 606  
 607                  $is_open = bbp_is_topic_open( $topic_id );
 608                  $message = ( true === $is_open )
 609                      ? 'closed'
 610                      : 'opened';
 611                  $success = ( true === $is_open )
 612                      ? bbp_close_topic( $topic_id )
 613                      : bbp_open_topic( $topic_id );
 614  
 615                  break;
 616  
 617              case 'bbp_toggle_topic_stick' :
 618                  check_admin_referer( 'stick-topic_' . $topic_id );
 619  
 620                  $is_sticky = bbp_is_topic_sticky( $topic_id );
 621                  $is_super  = ( false === $is_sticky ) && ! empty( $_GET['super'] ) && ( '1' === $_GET['super'] )
 622                      ? true
 623                      : false;
 624                  $message   = ( true  === $is_sticky )
 625                      ? 'unstuck'
 626                      : 'stuck';
 627                  $message   = ( true  === $is_super )
 628                      ? 'super_sticky'
 629                      : $message;
 630                  $success   = ( true  === $is_sticky )
 631                      ? bbp_unstick_topic( $topic_id )
 632                      : bbp_stick_topic( $topic_id, $is_super );
 633  
 634                  break;
 635  
 636              case 'bbp_toggle_topic_spam'  :
 637                  check_admin_referer( 'spam-topic_' . $topic_id );
 638  
 639                  $is_spam = bbp_is_topic_spam( $topic_id );
 640                  $message = ( true === $is_spam )
 641                      ? 'unspammed'
 642                      : 'spammed';
 643                  $success = ( true === $is_spam )
 644                      ? bbp_unspam_topic( $topic_id )
 645                      : bbp_spam_topic( $topic_id );
 646  
 647                  break;
 648          }
 649  
 650          // Setup the message
 651          $retval = array(
 652              'bbp_topic_toggle_notice' => $message,
 653              'topic_id'                => $topic_id
 654          );
 655  
 656          // Prepare for failure
 657          if ( ( false === $success ) || is_wp_error( $success ) ) {
 658              $retval['failed'] = '1';
 659          }
 660  
 661          // Filter all message args
 662          $retval = apply_filters( 'bbp_toggle_topic_action_admin', $retval, $topic_id, $action );
 663  
 664          // Do additional topic toggle actions (admin side)
 665          do_action( 'bbp_toggle_topic_admin', $success, $post_data, $action, $retval );
 666  
 667          // Redirect back to the topic
 668          $redirect = add_query_arg( $retval, remove_query_arg( array( 'action', 'topic_id' ) ) );
 669          bbp_redirect( $redirect );
 670      }
 671  
 672      /**
 673       * Toggle topic notices
 674       *
 675       * Display the success/error notices from
 676       * {@link BBP_Admin::toggle_topic()}
 677       *
 678       * @since 2.0.0 bbPress (r2727)
 679       */
 680  	public function toggle_topic_notice() {
 681  
 682          // Bail if missing topic toggle action
 683          if ( ! bbp_is_get_request() || empty( $_GET['topic_id'] ) || empty( $_GET['bbp_topic_toggle_notice'] ) ) {
 684              return;
 685          }
 686  
 687          // Bail if not an allowed notice
 688          $notice = sanitize_key( $_GET['bbp_topic_toggle_notice'] );
 689          if ( empty( $notice ) || ! in_array( $notice, $this->get_allowed_notice_toggles(), true ) ) {
 690              return;
 691          }
 692  
 693          // Bail if no topic_id or notice
 694          $topic_id = bbp_get_topic_id( $_GET['topic_id'] );
 695          if ( empty( $topic_id ) ) {
 696              return;
 697          }
 698  
 699          // Bail if topic is missing
 700          if ( ! bbp_get_topic( $topic_id ) ) {
 701              return;
 702          }
 703  
 704          // Use the title in the responses
 705          $topic_title = bbp_get_topic_title( $topic_id );
 706          $is_failure  = ! empty( $_GET['failed'] );
 707          $message     = '';
 708  
 709          // Which notice?
 710          switch ( $notice ) {
 711              case 'opened'    :
 712                  $message = ( $is_failure === true )
 713                      ? sprintf( esc_html__( 'There was a problem opening the topic "%1$s".', 'bbpress' ), $topic_title )
 714                      : sprintf( esc_html__( 'Topic "%1$s" successfully opened.',             'bbpress' ), $topic_title );
 715                  break;
 716  
 717              case 'closed'    :
 718                  $message = ( $is_failure === true )
 719                      ? sprintf( esc_html__( 'There was a problem closing the topic "%1$s".', 'bbpress' ), $topic_title )
 720                      : sprintf( esc_html__( 'Topic "%1$s" successfully closed.',             'bbpress' ), $topic_title );
 721                  break;
 722  
 723              case 'super_sticky' :
 724                  $message = ( $is_failure === true )
 725                      ? sprintf( esc_html__( 'There was a problem sticking the topic "%1$s" to front.', 'bbpress' ), $topic_title )
 726                      : sprintf( esc_html__( 'Topic "%1$s" successfully stuck to front.',               'bbpress' ), $topic_title );
 727                  break;
 728  
 729              case 'stuck'   :
 730                  $message = ( $is_failure === true )
 731                      ? sprintf( esc_html__( 'There was a problem sticking the topic "%1$s".', 'bbpress' ), $topic_title )
 732                      : sprintf( esc_html__( 'Topic "%1$s" successfully stuck.',               'bbpress' ), $topic_title );
 733                  break;
 734  
 735              case 'unstuck' :
 736                  $message = ( $is_failure === true )
 737                      ? sprintf( esc_html__( 'There was a problem unsticking the topic "%1$s".', 'bbpress' ), $topic_title )
 738                      : sprintf( esc_html__( 'Topic "%1$s" successfully unstuck.',               'bbpress' ), $topic_title );
 739                  break;
 740  
 741              case 'spammed'   :
 742                  $message = ( $is_failure === true )
 743                      ? sprintf( esc_html__( 'There was a problem marking the topic "%1$s" as spam.', 'bbpress' ), $topic_title )
 744                      : sprintf( esc_html__( 'Topic "%1$s" successfully marked as spam.',             'bbpress' ), $topic_title );
 745                  break;
 746  
 747              case 'unspammed' :
 748                  $message = ( $is_failure === true )
 749                      ? sprintf( esc_html__( 'There was a problem unmarking the topic "%1$s" as spam.', 'bbpress' ), $topic_title )
 750                      : sprintf( esc_html__( 'Topic "%1$s" successfully unmarked as spam.',             'bbpress' ), $topic_title );
 751                  break;
 752  
 753              case 'approved'   :
 754                  $message = ( $is_failure === true )
 755                      ? sprintf( esc_html__( 'There was a problem approving the topic "%1$s".', 'bbpress' ), $topic_title )
 756                      : sprintf( esc_html__( 'Topic "%1$s" successfully approved.',             'bbpress' ), $topic_title );
 757                  break;
 758  
 759              case 'unapproved' :
 760                  $message = ( $is_failure === true )
 761                      ? sprintf( esc_html__( 'There was a problem unapproving the topic "%1$s".', 'bbpress' ), $topic_title )
 762                      : sprintf( esc_html__( 'Topic "%1$s" successfully unapproved.',             'bbpress' ), $topic_title );
 763                  break;
 764          }
 765  
 766          // Do additional topic toggle notice filters (admin side)
 767          $message = apply_filters( 'bbp_toggle_topic_notice_admin', $message, $topic_id, $notice, $is_failure );
 768          $class   = ( $is_failure === true )
 769              ? 'error'
 770              : 'updated';
 771  
 772          // Add the notice
 773          bbp_admin()->add_notice( $message, $class, true );
 774      }
 775  
 776      /**
 777       * Returns an array of keys used to sort row actions
 778       *
 779       * @since 2.6.0 bbPress (r6771)
 780       *
 781       * @return array
 782       */
 783  	private function get_row_action_sort_order() {
 784  
 785          // Filter & return
 786          return (array) apply_filters( 'bbp_admin_topics_row_action_sort_order', array(
 787              'edit',
 788              'stick',
 789              'approved',
 790              'unapproved',
 791              'closed',
 792              'spam',
 793              'unspam',
 794              'trash',
 795              'untrash',
 796              'delete',
 797              'view'
 798          ) );
 799      }
 800  
 801      /**
 802       * Returns an array of notice toggles
 803       *
 804       * @since 2.6.0 bbPress (r6396)
 805       *
 806       * @return array
 807       */
 808  	private function get_allowed_notice_toggles() {
 809  
 810          // Filter & return
 811          return (array) apply_filters( 'bbp_admin_topics_allowed_notice_toggles', array(
 812              'opened',
 813              'closed',
 814              'super_sticky',
 815              'stuck',
 816              'unstuck',
 817              'spammed',
 818              'unspammed',
 819              'approved',
 820              'unapproved'
 821          ) );
 822      }
 823  
 824      /**
 825       * Returns an array of notice toggles
 826       *
 827       * @since 2.6.0 bbPress (r6396)
 828       *
 829       * @return array
 830       */
 831  	private function get_allowed_action_toggles() {
 832  
 833          // Filter & return
 834          return (array) apply_filters( 'bbp_admin_topics_allowed_action_toggles', array(
 835              'bbp_toggle_topic_close',
 836              'bbp_toggle_topic_stick',
 837              'bbp_toggle_topic_spam',
 838              'bbp_toggle_topic_approve'
 839          ) );
 840      }
 841  
 842      /**
 843       * Manage the column headers for the topics page
 844       *
 845       * @since 2.0.0 bbPress (r2485)
 846       *
 847       * @param array $columns The columns
 848       *
 849       * @return array $columns bbPress topic columns
 850       */
 851  	public function column_headers( $columns ) {
 852          $columns = array(
 853              'cb'                    => '<input type="checkbox" />',
 854              'title'                 => esc_html__( 'Topics',    'bbpress' ),
 855              'bbp_topic_forum'       => esc_html__( 'Forum',     'bbpress' ),
 856              'bbp_topic_reply_count' => esc_html__( 'Replies',   'bbpress' ),
 857              'bbp_topic_voice_count' => esc_html__( 'Voices',    'bbpress' ),
 858              'bbp_topic_author'      => esc_html__( 'Author',    'bbpress' ),
 859              'bbp_topic_created'     => esc_html__( 'Created',   'bbpress' ),
 860              'bbp_topic_freshness'   => esc_html__( 'Last Post', 'bbpress' )
 861          );
 862  
 863          // Filter & return
 864          return (array) apply_filters( 'bbp_admin_topics_column_headers', $columns );
 865      }
 866  
 867      /**
 868       * Print extra columns for the topics page
 869       *
 870       * @since 2.0.0 bbPress (r2485)
 871       *
 872       * @param string $column Column
 873       * @param int $topic_id Topic id
 874       */
 875  	public function column_data( $column, $topic_id ) {
 876  
 877          // Get topic forum ID
 878          $forum_id = bbp_get_topic_forum_id( $topic_id );
 879  
 880          // Populate column data
 881          switch ( $column ) {
 882  
 883              // Forum
 884              case 'bbp_topic_forum' :
 885  
 886                  // Get title
 887                  $forum_title = ! empty( $forum_id )
 888                      ? bbp_get_forum_title( $forum_id )
 889                      : '';
 890  
 891                  // Output forum name
 892                  if ( ! empty( $forum_title ) ) {
 893                      echo $forum_title;
 894  
 895                  // Output dash
 896                  } else {
 897                      ?>
 898                      <span aria-hidden="true">&mdash;</span>
 899                      <span class="screen-reader-text"><?php esc_html_e( 'No forum', 'bbpress' ); ?></span>
 900                      <?php
 901                  }
 902  
 903                  break;
 904  
 905              // Reply Count
 906              case 'bbp_topic_reply_count' :
 907                  bbp_topic_reply_count( $topic_id );
 908                  break;
 909  
 910              // Reply Count
 911              case 'bbp_topic_voice_count' :
 912                  bbp_topic_voice_count( $topic_id );
 913                  break;
 914  
 915              // Author
 916              case 'bbp_topic_author' :
 917                  bbp_topic_author_display_name( $topic_id );
 918                  break;
 919  
 920              // Freshness
 921              case 'bbp_topic_created':
 922                  printf( '%1$s <br /> %2$s',
 923                      get_the_date(),
 924                      esc_attr( get_the_time() )
 925                  );
 926  
 927                  break;
 928  
 929              // Freshness
 930              case 'bbp_topic_freshness' :
 931                  $last_active = bbp_get_topic_last_active_time( $topic_id, false );
 932                  if ( ! empty( $last_active ) ) {
 933                      echo esc_html( $last_active );
 934                  } else {
 935                      esc_html_e( 'No Replies', 'bbpress' ); // This should never happen
 936                  }
 937  
 938                  break;
 939  
 940              // Do an action for anything else
 941              default :
 942                  do_action( 'bbp_admin_topics_column_data', $column, $topic_id );
 943                  break;
 944          }
 945      }
 946  
 947      /**
 948       * Topic Row actions
 949       *
 950       * Remove the quick-edit action link under the topic title and add the
 951       * content and close/stick/spam links
 952       *
 953       * @since 2.0.0 bbPress (r2485)
 954       *
 955       * @param array  $actions Actions
 956       * @param object $topic   Topic object
 957       *
 958       * @return array $actions Actions
 959       */
 960  	public function row_actions( $actions = array(), $topic = false ) {
 961  
 962          // Disable quick edit (too much to do here)
 963          unset( $actions['inline hide-if-no-js'] );
 964  
 965          // View link
 966          $view_link = bbp_get_topic_permalink( $topic->ID );
 967  
 968          // Maybe add view=all
 969          if ( ! in_array( $topic->post_status, array( bbp_get_closed_status_id(), bbp_get_public_status_id() ), true ) ) {
 970              $view_link = bbp_add_view_all( $view_link, true );
 971          }
 972  
 973          // Show view link if it's not set, the topic is trashed and the user can view trashed topics
 974          if ( empty( $actions['view'] ) && ( bbp_get_trash_status_id() === $topic->post_status ) && current_user_can( 'view_trash' ) ) {
 975              $actions['view'] = '<a href="' . esc_url( $view_link ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;', 'bbpress' ), bbp_get_topic_title( $topic->ID ) ) ) . '" rel="permalink">' . esc_html__( 'View', 'bbpress' ) . '</a>';
 976          }
 977  
 978          // Only show the actions if the user is capable of viewing them :)
 979          if ( current_user_can( 'moderate', $topic->ID ) ) {
 980  
 981              // Pending
 982              // Show the 'approve' and 'view' link on pending posts only and 'unapprove' on published posts only
 983              $approve_uri = wp_nonce_url( add_query_arg( array( 'topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_approve' ), remove_query_arg( array( 'bbp_topic_toggle_notice', 'topic_id', 'failed', 'super' ) ) ), 'approve-topic_' . $topic->ID );
 984              if ( bbp_is_topic_public( $topic->ID ) ) {
 985                  $actions['unapproved'] = '<a href="' . esc_url( $approve_uri ) . '" title="' . esc_attr__( 'Unapprove this topic', 'bbpress' ) . '">' . _x( 'Unapprove', 'Unapprove Topic', 'bbpress' ) . '</a>';
 986              } else {
 987  
 988                  // Do not show 'approve' if already public
 989                  if ( ! bbp_is_topic_public( $topic->ID ) ) {
 990                      $actions['approved'] = '<a href="' . esc_url( $approve_uri ) . '" title="' . esc_attr__( 'Approve this topic',   'bbpress' ) . '">' . _x( 'Approve',   'Approve Topic',   'bbpress' ) . '</a>';
 991                  }
 992  
 993                  // Modify the view link
 994                  $actions['view'] = '<a href="' . esc_url( $view_link   ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;', 'bbpress' ), bbp_get_topic_title( $topic->ID ) ) ) . '" rel="permalink">' . esc_html__( 'View', 'bbpress' ) . '</a>';
 995              }
 996  
 997              // Close
 998              // Show the 'close' and 'open' link on published and closed posts only
 999              if ( bbp_is_topic_public( $topic->ID ) ) {
1000                  $close_uri = 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 );
1001                  if ( bbp_is_topic_open( $topic->ID ) ) {
1002                      $actions['closed'] = '<a href="' . esc_url( $close_uri ) . '" title="' . esc_attr__( 'Close this topic', 'bbpress' ) . '">' . _x( 'Close', 'Close a Topic', 'bbpress' ) . '</a>';
1003                  } else {
1004                      $actions['closed'] = '<a href="' . esc_url( $close_uri ) . '" title="' . esc_attr__( 'Open this topic',  'bbpress' ) . '">' . _x( 'Open',  'Open a Topic',  'bbpress' ) . '</a>';
1005                  }
1006              }
1007  
1008              // Sticky
1009              // Dont show sticky if topic is spam, trash or pending
1010              if ( ! bbp_is_topic_spam( $topic->ID ) && ! bbp_is_topic_trash( $topic->ID ) && ! bbp_is_topic_pending( $topic->ID ) ) {
1011                  $stick_uri = 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 );
1012                  if ( bbp_is_topic_sticky( $topic->ID ) ) {
1013                      $actions['stick'] = '<a href="' . esc_url( $stick_uri ) . '" title="' . esc_attr__( 'Unstick this topic', 'bbpress' ) . '">' . esc_html__( 'Unstick', 'bbpress' ) . '</a>';
1014                  } else {
1015                      $super_uri        = 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 );
1016                      $actions['stick'] = '<a href="' . esc_url( $stick_uri ) . '" title="' . esc_attr__( 'Stick this topic to its forum', 'bbpress' ) . '">' . esc_html__( 'Stick', 'bbpress' ) . '</a> <a href="' . esc_url( $super_uri ) . '" title="' . esc_attr__( 'Stick this topic to front', 'bbpress' ) . '">' . esc_html__( '(to front)', 'bbpress' ) . '</a>';
1017                  }
1018              }
1019  
1020              // Spam
1021              $spam_uri = 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 );
1022              if ( ! bbp_is_topic_spam( $topic->ID ) ) {
1023                  $actions['spam'] = '<a href="' . esc_url( $spam_uri ) . '" title="' . esc_attr__( 'Mark this topic as spam',    'bbpress' ) . '">' . esc_html__( 'Spam',     'bbpress' ) . '</a>';
1024              } else {
1025                  $actions['unspam'] = '<a href="' . esc_url( $spam_uri ) . '" title="' . esc_attr__( 'Mark the topic as not spam', 'bbpress' ) . '">' . esc_html__( 'Not Spam', 'bbpress' ) . '</a>';
1026              }
1027          }
1028  
1029          // Do not show trash links for spam topics, or spam links for trashed topics
1030          if ( current_user_can( 'delete_topic', $topic->ID ) ) {
1031              $trash_days = bbp_get_trash_days( bbp_get_topic_post_type() );
1032  
1033              if ( bbp_get_trash_status_id() === $topic->post_status ) {
1034                  $post_type_object   = get_post_type_object( bbp_get_topic_post_type() );
1035                  $actions['untrash'] = "<a title='" . esc_attr__( 'Restore this item from the Trash', 'bbpress' ) . "' href='" . esc_url( wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $topic->ID ) ), 'untrash-post_' . $topic->ID ) ) . "'>" . esc_html__( 'Restore', 'bbpress' ) . '</a>';
1036              } elseif ( ! empty( $trash_days ) ) {
1037                  $actions['trash'] = "<a class='submitdelete' title='" . esc_attr__( 'Move this item to the Trash', 'bbpress' ) . "' href='" . esc_url( get_delete_post_link( $topic->ID ) ) . "'>" . esc_html__( 'Trash', 'bbpress' ) . '</a>';
1038              }
1039  
1040              if ( ( bbp_get_trash_status_id() === $topic->post_status ) || empty( $trash_days ) ) {
1041                  $actions['delete'] = "<a class='submitdelete' title='" . esc_attr__( 'Delete this item permanently', 'bbpress' ) . "' href='" . esc_url( get_delete_post_link( $topic->ID, '', true ) ) . "'>" . esc_html__( 'Delete Permanently', 'bbpress' ) . '</a>';
1042              }
1043          }
1044  
1045          // Sort & return
1046          return $this->sort_row_actions( $actions );
1047      }
1048  
1049      /**
1050       * Sort row actions by key
1051       *
1052       * @since 2.6.0
1053       *
1054       * @param array $actions
1055       *
1056       * @return array
1057       */
1058  	private function sort_row_actions( $actions = array() ) {
1059  
1060          // Return value
1061          $retval = array();
1062  
1063          // Known row actions, in sort order
1064          $known_actions = $this->get_row_action_sort_order();
1065  
1066          // Sort known actions, and keep any unknown ones
1067          foreach ( $known_actions as $key ) {
1068              if ( isset( $actions[ $key ] ) ) {
1069                  $retval[ $key ] = $actions[ $key ];
1070                  unset( $actions[ $key ] );
1071              }
1072          }
1073  
1074          // Combine & return
1075          return $retval + $actions;
1076      }
1077  
1078      /**
1079       * Add forum dropdown to topic and reply list table filters
1080       *
1081       * @since 2.0.0 bbPress (r2991)
1082       *
1083       * @return bool False. If post type is not topic or reply
1084       */
1085  	public function filter_dropdown() {
1086  
1087          // Get which forum is selected
1088          $selected = ! empty( $_GET['bbp_forum_id'] )
1089              ? (int) $_GET['bbp_forum_id']
1090              : 0;
1091  
1092          // Show the forums dropdown
1093          bbp_dropdown( array(
1094              'selected'  => $selected,
1095              'show_none' => esc_html__( 'In all forums', 'bbpress' )
1096          ) );
1097      }
1098  
1099      /**
1100       * Add "Empty Spam" button for moderators
1101       *
1102       * @since 2.6.0 bbPress (r6791)
1103       */
1104  	public function filter_empty_spam() {
1105  
1106          // Bail if not viewing spam
1107          if ( empty( $_GET['post_status'] ) || ( bbp_get_spam_status_id() !== $_GET['post_status'] ) && current_user_can( 'moderate' ) ) {
1108              return;
1109          }
1110  
1111          ?>
1112  
1113          <div class="alignleft actions"><?php
1114  
1115              // Output the nonce & button
1116              wp_nonce_field( 'bulk-destroy', '_destroy_nonce' );
1117              submit_button(
1118                  esc_attr__( 'Empty Spam', 'bbpress' ),
1119                  'button-secondary apply',
1120                  'delete_all',
1121                  false
1122              );
1123  
1124          ?></div><?php
1125      }
1126  
1127      /**
1128       * Adjust the request query and include the forum id
1129       *
1130       * @since 2.0.0 bbPress (r2991)
1131       *
1132       * @param array $query_vars Query variables from {@link WP_Query}
1133       * @return array Processed Query Vars
1134       */
1135  	function filter_post_rows( $query_vars ) {
1136  
1137          // Add post_parent query_var if one is present
1138          if ( ! empty( $_GET['bbp_forum_id'] ) ) {
1139              $query_vars['meta_key']   = '_bbp_forum_id';
1140              $query_vars['meta_type']  = 'NUMERIC';
1141              $query_vars['meta_value'] = $_GET['bbp_forum_id'];
1142          }
1143  
1144          // Return manipulated query_vars
1145          return $query_vars;
1146      }
1147  
1148      /**
1149       * Custom user feedback messages for topic post type
1150       *
1151       * @since 2.0.0 bbPress (r3080)
1152       *
1153       * @global int $post_ID
1154       *
1155       * @param array $messages
1156       *
1157       * @return array
1158       */
1159  	public function updated_messages( $messages ) {
1160          global $post_ID;
1161  
1162          // URL for the current topic
1163          $topic_url = bbp_get_topic_permalink( $post_ID );
1164  
1165          // Current topic's post_date
1166          $post_date = bbp_get_global_post_field( 'post_date', 'raw' );
1167  
1168          // Messages array
1169          $messages[ $this->post_type ] = array(
1170              0 => '', // Left empty on purpose
1171  
1172              // Updated
1173              1 => sprintf(
1174                  '%1$s <a href="%2$s">%3$s</a>',
1175                  esc_html__( 'Topic updated.', 'bbpress' ),
1176                  $topic_url,
1177                  esc_html__( 'View topic', 'bbpress' )
1178              ),
1179  
1180              // Custom field updated
1181              2 => esc_html__( 'Custom field updated.', 'bbpress' ),
1182  
1183              // Custom field deleted
1184              3 => esc_html__( 'Custom field deleted.', 'bbpress' ),
1185  
1186              // Topic updated
1187              4 => esc_html__( 'Topic updated.', 'bbpress' ),
1188  
1189              // Restored from revision
1190              // translators: %s: date and time of the revision
1191              5 => isset( $_GET['revision'] )
1192                      ? sprintf( esc_html__( 'Topic restored to revision from %s', 'bbpress' ), wp_post_revision_title( (int) $_GET['revision'], false ) )
1193                      : false,
1194  
1195              // Topic created
1196              6 => sprintf(
1197                  '%1$s <a href="%2$s">%3$s</a>',
1198                  esc_html__( 'Topic created.', 'bbpress' ),
1199                  $topic_url,
1200                  esc_html__( 'View topic', 'bbpress' )
1201              ),
1202  
1203              // Topic saved
1204              7 => esc_html__( 'Topic saved.', 'bbpress' ),
1205  
1206              // Topic submitted
1207              8 => sprintf(
1208                  '%1$s <a href="%2$s" target="_blank">%3$s</a>',
1209                  esc_html__( 'Topic submitted.', 'bbpress' ),
1210                  esc_url( add_query_arg( 'preview', 'true', $topic_url ) ),
1211                  esc_html__( 'Preview topic', 'bbpress' )
1212              ),
1213  
1214              // Topic scheduled
1215              9 => sprintf(
1216                  '%1$s <a target="_blank" href="%2$s">%3$s</a>',
1217                  sprintf(
1218                      esc_html__( 'Topic scheduled for: %s.', 'bbpress' ),
1219                      // translators: Publish box date format, see http://php.net/date
1220                      '<strong>' . date_i18n( __( 'M j, Y @ G:i', 'bbpress' ), strtotime( $post_date ) ) . '</strong>'
1221                  ),
1222                  $topic_url,
1223                  esc_html__( 'Preview topic', 'bbpress' )
1224              ),
1225  
1226              // Topic draft updated
1227              10 => sprintf(
1228                  '%1$s <a href="%2$s" target="_blank">%3$s</a>',
1229                  esc_html__( 'Topic draft updated.', 'bbpress' ),
1230                  esc_url( add_query_arg( 'preview', 'true', $topic_url ) ),
1231                  esc_html__( 'Preview topic', 'bbpress' )
1232              ),
1233          );
1234  
1235          return $messages;
1236      }
1237  }
1238  endif; // class_exists check
1239  
1240  /**
1241   * Setup bbPress Topics Admin
1242   *
1243   * This is currently here to make hooking and unhooking of the admin UI easy.
1244   * It could use dependency injection in the future, but for now this is easier.
1245   *
1246   * @since 2.0.0 bbPress (r2596)
1247   *
1248   * @param WP_Screen $current_screen Current screen object
1249   */
1250  function bbp_admin_topics( $current_screen ) {
1251  
1252      // Bail if not a forum screen
1253      if ( empty( $current_screen->post_type ) || ( bbp_get_topic_post_type() !== $current_screen->post_type ) ) {
1254          return;
1255      }
1256  
1257      // Init the topics admin
1258      bbp_admin()->topics = new BBP_Topics_Admin();
1259  }


Generated: Wed Nov 6 01:00:51 2024 Cross-referenced by PHPXref 0.7.1