[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

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

   1  <?php
   2  
   3  /**
   4   * bbPress Admin Actions
   5   *
   6   * This file contains the actions that are used through-out bbPress Admin. They
   7   * are consolidated here to make searching for them easier, and to help developers
   8   * understand at a glance the order in which things occur.
   9   *
  10   * There are a few common places that additional actions can currently be found
  11   *
  12   *  - bbPress: In {@link bbPress::setup_actions()} in bbpress.php
  13   *  - Admin: More in {@link BBP_Admin::setup_actions()} in class-bbp-admin.php
  14   *
  15   * @package bbPress
  16   * @subpackage Administration
  17   *
  18   * @see bbp-core-actions.php
  19   * @see bbp-core-filters.php
  20   */
  21  
  22  // Exit if accessed directly
  23  defined( 'ABSPATH' ) || exit;
  24  
  25  /**
  26   * Attach bbPress to WordPress
  27   *
  28   * bbPress uses its own internal actions to help aid in third-party plugin
  29   * development, and to limit the amount of potential future code changes when
  30   * updates to WordPress core occur.
  31   *
  32   * These actions exist to create the concept of 'plugin dependencies'. They
  33   * provide a safe way for plugins to execute code *only* when bbPress is
  34   * installed and activated, without needing to do complicated guesswork.
  35   *
  36   * For more information on how this works, see the 'Plugin Dependency' section
  37   * near the bottom of this file.
  38   *
  39   *           v--WordPress Actions       v--bbPress Sub-actions
  40   */
  41  add_action( 'wpmu_new_blog',           'bbp_new_site',               10, 6 );
  42  add_action( 'current_screen',          'bbp_current_screen'                );
  43  add_action( 'tool_box',                'bbp_admin_tool_box'                );
  44  add_action( 'admin_menu',              'bbp_admin_menu'                    );
  45  add_action( 'admin_init',              'bbp_admin_init'                    );
  46  add_action( 'admin_head',              'bbp_admin_head'                    );
  47  add_action( 'admin_notices',           'bbp_admin_notices'                 );
  48  add_action( 'menu_order',              'bbp_admin_menu_order'              );
  49  add_filter( 'custom_menu_order',       'bbp_admin_custom_menu_order'       );
  50  
  51  // Hook on to admin_init
  52  add_action( 'bbp_admin_init', 'bbp_setup_updater',          999 );
  53  add_action( 'bbp_admin_init', 'bbp_register_importers'          );
  54  add_action( 'bbp_admin_init', 'bbp_register_admin_styles'       );
  55  add_action( 'bbp_admin_init', 'bbp_register_admin_scripts'      );
  56  add_action( 'bbp_admin_init', 'bbp_register_admin_settings'     );
  57  
  58  // Hook on to current_screen
  59  add_action( 'bbp_current_screen', 'bbp_admin_forums'  );
  60  add_action( 'bbp_current_screen', 'bbp_admin_topics'  );
  61  add_action( 'bbp_current_screen', 'bbp_admin_replies' );
  62  
  63  // Initialize the admin area
  64  add_action( 'bbp_init', 'bbp_setup_admin' );
  65  
  66  // Reset the menu order
  67  add_action( 'bbp_admin_menu', 'bbp_admin_separator' );
  68  
  69  // Activation
  70  add_action( 'bbp_activation',   'bbp_setup_new_site'              );
  71  add_action( 'bbp_activation',   'bbp_add_activation_redirect'     );
  72  add_action( 'bbp_activation',   'bbp_delete_rewrite_rules'        );
  73  add_action( 'bbp_activation',   'bbp_make_current_user_keymaster' );
  74  add_action( 'load-plugins.php', 'bbp_do_activation_redirect'      );
  75  
  76  // Deactivation
  77  add_action( 'bbp_deactivation', 'bbp_remove_caps'          );
  78  add_action( 'bbp_deactivation', 'bbp_delete_rewrite_rules' );
  79  
  80  // New Site
  81  add_action( 'bbp_new_site', 'bbp_setup_new_site', 8 );
  82  
  83  // Load the default repair tools
  84  add_action( 'load-tools_page_bbp-repair',  'bbp_register_default_repair_tools' );
  85  add_action( 'load-tools_page_bbp-upgrade', 'bbp_register_default_repair_tools' );
  86  
  87  // Contextual Helpers
  88  add_action( 'load-settings_page_bbpress',    'bbp_admin_settings_help'        );
  89  add_action( 'load-tools_page_bbp-repair',    'bbp_admin_tools_repair_help'    );
  90  add_action( 'load-tools_page_bbp-upgrade',   'bbp_admin_tools_repair_help'    );
  91  add_action( 'load-tools_page_bbp-converter', 'bbp_admin_tools_converter_help' );
  92  add_action( 'load-tools_page_bbp-reset',     'bbp_admin_tools_reset_help'     );
  93  
  94  // Handle submission of Tools pages
  95  add_action( 'load-tools_page_bbp-repair',  'bbp_admin_repair_handler' );
  96  add_action( 'load-tools_page_bbp-upgrade', 'bbp_admin_repair_handler' );
  97  add_action( 'load-tools_page_bbp-reset',   'bbp_admin_reset_handler'  );
  98  add_action( 'bbp_admin_tool_box',          'bbp_admin_tools_box'      );
  99  
 100  // Add sample permalink filter
 101  add_filter( 'post_type_link', 'bbp_filter_sample_permalink', 10, 4 );
 102  
 103  // Add quick stats to dashboard glance elements
 104  add_filter( 'dashboard_glance_items', 'bbp_filter_dashboard_glance_items', -99 );
 105  
 106  // Maybe use icons for column headers
 107  add_filter( 'bbp_admin_forums_column_headers',  'bbp_filter_column_headers' );
 108  add_filter( 'bbp_admin_topics_column_headers',  'bbp_filter_column_headers' );
 109  add_filter( 'bbp_admin_replies_column_headers', 'bbp_filter_column_headers' );
 110  
 111  // Load the converter early (page and AJAX)
 112  add_action( 'load-tools_page_bbp-converter', 'bbp_setup_converter', 2 );
 113  add_action( 'wp_ajax_bbp_converter_process', 'bbp_setup_converter', 2 );
 114  
 115  // Add New User
 116  add_action( 'user_new_form', 'bbp_add_user_form_role_field', 10, 1 );
 117  
 118  /**
 119   * Setup bbPress admin
 120   *
 121   * @since 2.0.0 bbPress (r1000)
 122   * @since 2.6.0 bbPress (r6598) Moved to actions.php
 123   */
 124  function bbp_admin() {
 125      return bbp_setup_admin();
 126  }
 127  
 128  /**
 129   * When a new site is created in a multisite installation, run the activation
 130   * routine on that site
 131   *
 132   * @since 2.0.0 bbPress (r3283)
 133   *
 134   * @param int $blog_id
 135   * @param int $user_id
 136   * @param string $domain
 137   * @param string $path
 138   * @param int $site_id
 139   * @param array() $meta
 140   */
 141  function bbp_new_site( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
 142  
 143      // Bail if plugin is not network activated
 144      if ( ! is_plugin_active_for_network( bbpress()->basename ) ) {
 145          return;
 146      }
 147  
 148      // Switch to the new site
 149      bbp_switch_to_site( $blog_id );
 150  
 151      // Do the bbPress activation routine
 152      do_action( 'bbp_new_site', $blog_id, $user_id, $domain, $path, $site_id, $meta );
 153  
 154      // Restore original site
 155      bbp_restore_current_site();
 156  }
 157  
 158  /**
 159   * Show icons in list-table column headers instead of strings
 160   *
 161   * @since 2.6.0 bbPress (r5833)
 162   *
 163   * @param  array $columns Column headers fed into list-table objects
 164   *
 165   * @return array Possibly altered column headers
 166   */
 167  function bbp_filter_column_headers( $columns = array() ) {
 168  
 169      // Do not filter column headers by default - maybe we'll turn it on later
 170      if ( ! apply_filters( 'bbp_filter_column_headers', false ) ) {
 171          return $columns;
 172      }
 173  
 174      /** Forums ****************************************************************/
 175  
 176      // Forum topic count
 177      if ( isset( $columns[ 'bbp_forum_topic_count' ] ) ) {
 178          $columns[ 'bbp_forum_topic_count' ] = '<span class="vers bbp_topics_column"  title="' . esc_attr__( 'Topics', 'bbpress' ) . '"><span class="screen-reader-text">' . esc_html__( 'Topics', 'bbpress' ) . '</span></span>';
 179      }
 180  
 181      // Forum reply count
 182      if ( isset( $columns[ 'bbp_forum_reply_count' ] ) ) {
 183          $columns[ 'bbp_forum_reply_count' ] = '<span class="vers bbp_replies_column"  title="' . esc_attr__( 'Replies', 'bbpress' ) . '"><span class="screen-reader-text">' . esc_html__( 'Replies', 'bbpress' ) . '</span></span>';
 184      }
 185  
 186      /** Topics ****************************************************************/
 187  
 188      // Topic forum
 189      if ( isset( $columns[ 'bbp_topic_forum' ] ) ) {
 190          $columns[ 'bbp_topic_forum' ] = '<span class="vers bbp_forums_column"  title="' . esc_attr__( 'Forum', 'bbpress' ) . '"><span class="screen-reader-text">' . esc_html__( 'Forum', 'bbpress' ) . '</span></span>';
 191      }
 192  
 193      // Topic reply count
 194      if ( isset( $columns[ 'bbp_topic_reply_count' ] ) ) {
 195          $columns[ 'bbp_topic_reply_count' ] = '<span class="vers bbp_replies_column"  title="' . esc_attr__( 'Replies', 'bbpress' ) . '"><span class="screen-reader-text">' . esc_html__( 'Replies', 'bbpress' ) . '</span></span>';
 196      }
 197  
 198      /** Replies ***************************************************************/
 199  
 200      // Reply forum
 201      if ( isset( $columns[ 'bbp_reply_forum' ] ) ) {
 202          $columns[ 'bbp_reply_forum' ] = '<span class="vers bbp_forums_column"  title="' . esc_attr__( 'Forum', 'bbpress' ) . '"><span class="screen-reader-text">' . esc_html__( 'Forum', 'bbpress' ) . '</span></span>';
 203      }
 204  
 205      // Reply topic
 206      if ( isset( $columns[ 'bbp_reply_topic' ] ) ) {
 207          $columns[ 'bbp_reply_topic' ] = '<span class="vers bbp_topics_column"  title="' . esc_attr__( 'Topic', 'bbpress' ) . '"><span class="screen-reader-text">' . esc_html__( 'Topic', 'bbpress' ) . '</span></span>';
 208      }
 209  
 210      return $columns;
 211  }
 212  
 213  /**
 214   * Filter sample permalinks so that certain languages display properly.
 215   *
 216   * @since 2.0.0 bbPress (r3336)
 217   *
 218   * @param string $post_link Custom post type permalink
 219   * @param object $_post Post data object
 220   * @param bool $leavename Optional, defaults to false. Whether to keep post name or page name.
 221   * @param bool $sample Optional, defaults to false. Is it a sample permalink.
 222   *
 223   * @return string The custom post type permalink
 224   */
 225  function bbp_filter_sample_permalink( $post_link, $_post, $leavename = false, $sample = false ) {
 226  
 227      // Bail if not on an admin page and not getting a sample permalink
 228      if ( ! empty( $sample ) && is_admin() && bbp_is_custom_post_type() ) {
 229          return urldecode( $post_link );
 230      }
 231  
 232      // Return post link
 233      return $post_link;
 234  }
 235  
 236  /** Sub-Actions ***************************************************************/
 237  
 238  /**
 239   * Piggy back admin_init action
 240   *
 241   * @since 2.1.0 bbPress (r3766)
 242   */
 243  function bbp_admin_init() {
 244      do_action( 'bbp_admin_init' );
 245  }
 246  
 247  /**
 248   * Piggy back admin_menu action
 249   *
 250   * @since 2.1.0 bbPress (r3766)
 251   */
 252  function bbp_admin_menu() {
 253      do_action( 'bbp_admin_menu' );
 254  }
 255  
 256  /**
 257   * Piggy back admin_head action
 258   *
 259   * @since 2.1.0 bbPress (r3766)
 260   */
 261  function bbp_admin_head() {
 262      do_action( 'bbp_admin_head' );
 263  }
 264  
 265  /**
 266   * Piggy back admin_notices action
 267   *
 268   * @since 2.1.0 bbPress (r3766)
 269   */
 270  function bbp_admin_notices() {
 271      do_action( 'bbp_admin_notices' );
 272  }
 273  
 274  /**
 275   * Dedicated action to register bbPress importers
 276   *
 277   * @since 2.1.0 bbPress (r3766)
 278   */
 279  function bbp_register_importers() {
 280      do_action( 'bbp_register_importers' );
 281  }
 282  
 283  /**
 284   * Dedicated action to register admin styles
 285   *
 286   * @since 2.6.0 bbPress (r6912)
 287   */
 288  function bbp_register_admin_styles() {
 289  
 290      /**
 291       * Action used to register the admin styling
 292       *
 293       * @since 2.1.0
 294       * @deprecated 2.6.0
 295       */
 296      do_action( 'bbp_register_admin_style' );
 297  
 298      /**
 299       * Action used to register all admin styling
 300       *
 301       * @since 2.6.0
 302       */
 303      do_action( 'bbp_register_admin_styles' );
 304  }
 305  
 306  /**
 307   * Dedicated action to register admin scripts
 308   *
 309   * @since 2.6.0 bbPress (r6912)
 310   */
 311  function bbp_register_admin_scripts() {
 312      do_action( 'bbp_register_admin_scripts' );
 313  }
 314  
 315  /**
 316   * Dedicated action to register admin settings
 317   *
 318   * @since 2.1.0 bbPress (r3766)
 319   */
 320  function bbp_register_admin_settings() {
 321      do_action( 'bbp_register_admin_settings' );
 322  }
 323  
 324  /**
 325   * Dedicated action to output admin tools.php sections
 326   *
 327   * @since 2.6.0 bbPress (r6273)
 328   */
 329  function bbp_admin_tool_box() {
 330      do_action( 'bbp_admin_tool_box' );
 331  }
 332  
 333  /**
 334   * Dedicated action to hook into the current screen
 335   *
 336   * @since 2.6.0 bbPress (r6185)
 337   *
 338   * @param WP_Screen $current_screen
 339   */
 340  function bbp_current_screen( $current_screen = '' ) {
 341      do_action( 'bbp_current_screen', $current_screen );
 342  }


Generated: Sat Apr 4 01:01:22 2020 Cross-referenced by PHPXref 0.7.1