[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

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

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


Generated: Sat Dec 21 01:00:52 2024 Cross-referenced by PHPXref 0.7.1