[ 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 (only in Site admin, not Network or User)
  59  if ( is_blog_admin() ) {
  60      add_action( 'bbp_current_screen', 'bbp_admin_forums'  );
  61      add_action( 'bbp_current_screen', 'bbp_admin_topics'  );
  62      add_action( 'bbp_current_screen', 'bbp_admin_replies' );
  63  }
  64  
  65  // Initialize the admin area
  66  add_action( 'bbp_init', 'bbp_setup_admin' );
  67  
  68  // Reset the menu order
  69  add_action( 'bbp_admin_menu', 'bbp_admin_separator' );
  70  
  71  // Activation
  72  add_action( 'bbp_activation',   'bbp_setup_new_site'              );
  73  add_action( 'bbp_activation',   'bbp_add_activation_redirect'     );
  74  add_action( 'bbp_activation',   'bbp_delete_rewrite_rules'        );
  75  add_action( 'bbp_activation',   'bbp_make_current_user_keymaster' );
  76  add_action( 'load-plugins.php', 'bbp_do_activation_redirect'      );
  77  
  78  // Deactivation
  79  add_action( 'bbp_deactivation', 'bbp_remove_caps'          );
  80  add_action( 'bbp_deactivation', 'bbp_delete_rewrite_rules' );
  81  
  82  // New Site
  83  add_action( 'bbp_new_site', 'bbp_setup_new_site', 8 );
  84  
  85  // Load the default repair tools
  86  add_action( 'load-tools_page_bbp-repair',  'bbp_register_default_repair_tools' );
  87  add_action( 'load-tools_page_bbp-upgrade', 'bbp_register_default_repair_tools' );
  88  
  89  // Contextual Helpers
  90  add_action( 'load-settings_page_bbpress',    'bbp_admin_settings_help'        );
  91  add_action( 'load-tools_page_bbp-repair',    'bbp_admin_tools_repair_help'    );
  92  add_action( 'load-tools_page_bbp-upgrade',   'bbp_admin_tools_repair_help'    );
  93  add_action( 'load-tools_page_bbp-converter', 'bbp_admin_tools_converter_help' );
  94  add_action( 'load-tools_page_bbp-reset',     'bbp_admin_tools_reset_help'     );
  95  
  96  // Handle submission of Tools pages
  97  add_action( 'load-tools_page_bbp-repair',  'bbp_admin_repair_handler' );
  98  add_action( 'load-tools_page_bbp-upgrade', 'bbp_admin_repair_handler' );
  99  add_action( 'load-tools_page_bbp-reset',   'bbp_admin_reset_handler'  );
 100  add_action( 'bbp_admin_tool_box',          'bbp_admin_tools_box'      );
 101  
 102  // Add sample permalink filter
 103  add_filter( 'post_type_link', 'bbp_filter_sample_permalink', 10, 4 );
 104  
 105  // Add quick stats to dashboard glance elements
 106  add_filter( 'dashboard_glance_items', 'bbp_filter_dashboard_glance_items', -99 );
 107  
 108  // Maybe use icons for column headers
 109  add_filter( 'bbp_admin_forums_column_headers',  'bbp_filter_column_headers' );
 110  add_filter( 'bbp_admin_topics_column_headers',  'bbp_filter_column_headers' );
 111  add_filter( 'bbp_admin_replies_column_headers', 'bbp_filter_column_headers' );
 112  
 113  // Load the converter early (page and AJAX)
 114  add_action( 'load-tools_page_bbp-converter', 'bbp_setup_converter', 2 );
 115  add_action( 'wp_ajax_bbp_converter_process', 'bbp_setup_converter', 2 );
 116  
 117  // Add New User
 118  add_action( 'user_new_form', 'bbp_add_user_form_role_field', 10, 1 );
 119  
 120  /**
 121   * Setup bbPress admin
 122   *
 123   * @since 2.0.0 bbPress (r1000)
 124   * @since 2.6.0 bbPress (r6598) Moved to actions.php
 125   */
 126  function bbp_admin() {
 127      return bbp_setup_admin();
 128  }
 129  
 130  /**
 131   * When a new site is created in a multisite installation, run the activation
 132   * routine on that site
 133   *
 134   * @since 2.0.0 bbPress (r3283)
 135   *
 136   * @param int $blog_id
 137   * @param int $user_id
 138   * @param string $domain
 139   * @param string $path
 140   * @param int $site_id
 141   * @param array() $meta
 142   */
 143  function bbp_new_site( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
 144  
 145      // Bail if plugin is not network activated
 146      if ( ! is_plugin_active_for_network( bbpress()->basename ) ) {
 147          return;
 148      }
 149  
 150      // Switch to the new site
 151      bbp_switch_to_site( $blog_id );
 152  
 153      // Do the bbPress activation routine
 154      do_action( 'bbp_new_site', $blog_id, $user_id, $domain, $path, $site_id, $meta );
 155  
 156      // Restore original site
 157      bbp_restore_current_site();
 158  }
 159  
 160  /**
 161   * Show icons in list-table column headers instead of strings
 162   *
 163   * @since 2.6.0 bbPress (r5833)
 164   *
 165   * @param  array $columns Column headers fed into list-table objects
 166   *
 167   * @return array Possibly altered column headers
 168   */
 169  function bbp_filter_column_headers( $columns = array() ) {
 170  
 171      // Do not filter column headers by default - maybe we'll turn it on later
 172      if ( ! apply_filters( 'bbp_filter_column_headers', false ) ) {
 173          return $columns;
 174      }
 175  
 176      /** Forums ****************************************************************/
 177  
 178      // Forum topic count
 179      if ( isset( $columns[ 'bbp_forum_topic_count' ] ) ) {
 180          $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>';
 181      }
 182  
 183      // Forum reply count
 184      if ( isset( $columns[ 'bbp_forum_reply_count' ] ) ) {
 185          $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>';
 186      }
 187  
 188      /** Topics ****************************************************************/
 189  
 190      // Topic forum
 191      if ( isset( $columns[ 'bbp_topic_forum' ] ) ) {
 192          $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>';
 193      }
 194  
 195      // Topic reply count
 196      if ( isset( $columns[ 'bbp_topic_reply_count' ] ) ) {
 197          $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>';
 198      }
 199  
 200      /** Replies ***************************************************************/
 201  
 202      // Reply forum
 203      if ( isset( $columns[ 'bbp_reply_forum' ] ) ) {
 204          $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>';
 205      }
 206  
 207      // Reply topic
 208      if ( isset( $columns[ 'bbp_reply_topic' ] ) ) {
 209          $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>';
 210      }
 211  
 212      return $columns;
 213  }
 214  
 215  /**
 216   * Filter sample permalinks so that certain languages display properly.
 217   *
 218   * @since 2.0.0 bbPress (r3336)
 219   *
 220   * @param string $post_link Custom post type permalink
 221   * @param object $_post Post data object
 222   * @param bool $leavename Optional, defaults to false. Whether to keep post name or page name.
 223   * @param bool $sample Optional, defaults to false. Is it a sample permalink.
 224   *
 225   * @return string The custom post type permalink
 226   */
 227  function bbp_filter_sample_permalink( $post_link, $_post, $leavename = false, $sample = false ) {
 228  
 229      // Bail if not on an admin page and not getting a sample permalink
 230      if ( ! empty( $sample ) && is_admin() && bbp_is_custom_post_type() ) {
 231          return urldecode( $post_link );
 232      }
 233  
 234      // Return post link
 235      return $post_link;
 236  }
 237  
 238  /** Sub-Actions ***************************************************************/
 239  
 240  /**
 241   * Piggy back admin_init action
 242   *
 243   * @since 2.1.0 bbPress (r3766)
 244   */
 245  function bbp_admin_init() {
 246      do_action( 'bbp_admin_init' );
 247  }
 248  
 249  /**
 250   * Piggy back admin_menu action
 251   *
 252   * @since 2.1.0 bbPress (r3766)
 253   */
 254  function bbp_admin_menu() {
 255      do_action( 'bbp_admin_menu' );
 256  }
 257  
 258  /**
 259   * Piggy back admin_head action
 260   *
 261   * @since 2.1.0 bbPress (r3766)
 262   */
 263  function bbp_admin_head() {
 264      do_action( 'bbp_admin_head' );
 265  }
 266  
 267  /**
 268   * Piggy back admin_notices action
 269   *
 270   * @since 2.1.0 bbPress (r3766)
 271   */
 272  function bbp_admin_notices() {
 273      do_action( 'bbp_admin_notices' );
 274  }
 275  
 276  /**
 277   * Dedicated action to register bbPress importers
 278   *
 279   * @since 2.1.0 bbPress (r3766)
 280   */
 281  function bbp_register_importers() {
 282      do_action( 'bbp_register_importers' );
 283  }
 284  
 285  /**
 286   * Dedicated action to register admin styles
 287   *
 288   * @since 2.6.0 bbPress (r6912)
 289   */
 290  function bbp_register_admin_styles() {
 291  
 292      /**
 293       * Action used to register the admin styling
 294       *
 295       * @since 2.1.0
 296       * @deprecated 2.6.0
 297       */
 298      do_action( 'bbp_register_admin_style' );
 299  
 300      /**
 301       * Action used to register all admin styling
 302       *
 303       * @since 2.6.0
 304       */
 305      do_action( 'bbp_register_admin_styles' );
 306  }
 307  
 308  /**
 309   * Dedicated action to register admin scripts
 310   *
 311   * @since 2.6.0 bbPress (r6912)
 312   */
 313  function bbp_register_admin_scripts() {
 314      do_action( 'bbp_register_admin_scripts' );
 315  }
 316  
 317  /**
 318   * Dedicated action to register admin settings
 319   *
 320   * @since 2.1.0 bbPress (r3766)
 321   */
 322  function bbp_register_admin_settings() {
 323      do_action( 'bbp_register_admin_settings' );
 324  }
 325  
 326  /**
 327   * Dedicated action to output admin tools.php sections
 328   *
 329   * @since 2.6.0 bbPress (r6273)
 330   */
 331  function bbp_admin_tool_box() {
 332      do_action( 'bbp_admin_tool_box' );
 333  }
 334  
 335  /**
 336   * Dedicated action to hook into the current screen
 337   *
 338   * @since 2.6.0 bbPress (r6185)
 339   *
 340   * @param WP_Screen $current_screen
 341   */
 342  function bbp_current_screen( $current_screen = '' ) {
 343      do_action( 'bbp_current_screen', $current_screen );
 344  }


Generated: Fri Apr 19 01:01:01 2024 Cross-referenced by PHPXref 0.7.1