web/wp-content/plugins/bbpress/includes/core/actions.php
changeset 196 5e8dcbe22c24
equal deleted inserted replaced
195:c7c0fbc09788 196:5e8dcbe22c24
       
     1 <?php
       
     2 
       
     3 /**
       
     4  * bbPress Actions
       
     5  *
       
     6  * @package bbPress
       
     7  * @subpackage Core
       
     8  *
       
     9  * This file contains the actions that are used through-out bbPress. They are
       
    10  * consolidated here to make searching for them easier, and to help developers
       
    11  * understand at a glance the order in which things occur.
       
    12  *
       
    13  * There are a few common places that additional actions can currently be found
       
    14  *
       
    15  *  - bbPress: In {@link bbPress::setup_actions()} in bbpress.php
       
    16  *  - Admin: More in {@link BBP_Admin::setup_actions()} in admin.php
       
    17  *
       
    18  * @see /core/filters.php
       
    19  */
       
    20 
       
    21 // Exit if accessed directly
       
    22 if ( !defined( 'ABSPATH' ) ) exit;
       
    23 
       
    24 /**
       
    25  * Attach bbPress to WordPress
       
    26  *
       
    27  * bbPress uses its own internal actions to help aid in third-party plugin
       
    28  * development, and to limit the amount of potential future code changes when
       
    29  * updates to WordPress core occur.
       
    30  *
       
    31  * These actions exist to create the concept of 'plugin dependencies'. They
       
    32  * provide a safe way for plugins to execute code *only* when bbPress is
       
    33  * installed and activated, without needing to do complicated guesswork.
       
    34  *
       
    35  * For more information on how this works, see the 'Plugin Dependency' section
       
    36  * near the bottom of this file.
       
    37  *
       
    38  *           v--WordPress Actions        v--bbPress Sub-actions
       
    39  */
       
    40 add_action( 'plugins_loaded',           'bbp_loaded',                   10    );
       
    41 add_action( 'init',                     'bbp_init',                     0     ); // Early for bbp_register
       
    42 add_action( 'parse_query',              'bbp_parse_query',              2     ); // Early for overrides
       
    43 add_action( 'widgets_init',             'bbp_widgets_init',             10    );
       
    44 add_action( 'generate_rewrite_rules',   'bbp_generate_rewrite_rules',   10    );
       
    45 add_action( 'wp_enqueue_scripts',       'bbp_enqueue_scripts',          10    );
       
    46 add_action( 'wp_head',                  'bbp_head',                     10    );
       
    47 add_action( 'wp_footer',                'bbp_footer',                   10    );
       
    48 add_action( 'set_current_user',         'bbp_setup_current_user',       10    );
       
    49 add_action( 'setup_theme',              'bbp_setup_theme',              10    );
       
    50 add_action( 'after_setup_theme',        'bbp_after_setup_theme',        10    );
       
    51 add_action( 'template_redirect',        'bbp_template_redirect',        10    );
       
    52 add_action( 'login_form_login',         'bbp_login_form_login',         10    );
       
    53 add_action( 'profile_update',           'bbp_profile_update',           10, 2 ); // user_id and old_user_data
       
    54 add_action( 'user_register',            'bbp_user_register',            10    );
       
    55 
       
    56 /**
       
    57  * bbp_loaded - Attached to 'plugins_loaded' above
       
    58  *
       
    59  * Attach various loader actions to the bbp_loaded action.
       
    60  * The load order helps to execute code at the correct time.
       
    61  *                                                         v---Load order
       
    62  */
       
    63 add_action( 'bbp_loaded', 'bbp_constants',                 2  );
       
    64 add_action( 'bbp_loaded', 'bbp_boot_strap_globals',        4  );
       
    65 add_action( 'bbp_loaded', 'bbp_includes',                  6  );
       
    66 add_action( 'bbp_loaded', 'bbp_setup_globals',             8  );
       
    67 add_action( 'bbp_loaded', 'bbp_setup_option_filters',      10 );
       
    68 add_action( 'bbp_loaded', 'bbp_setup_user_option_filters', 12 );
       
    69 add_action( 'bbp_loaded', 'bbp_register_theme_packages',   14 );
       
    70 add_action( 'bbp_loaded', 'bbp_filter_user_roles_option',  16 );
       
    71 
       
    72 /**
       
    73  * bbp_init - Attached to 'init' above
       
    74  *
       
    75  * Attach various initialization actions to the init action.
       
    76  * The load order helps to execute code at the correct time.
       
    77  *                                              v---Load order
       
    78  */
       
    79 add_action( 'bbp_init', 'bbp_register',         0   );
       
    80 add_action( 'bbp_init', 'bbp_load_textdomain',  10  );
       
    81 add_action( 'bbp_init', 'bbp_add_rewrite_tags', 20  );
       
    82 add_action( 'bbp_init', 'bbp_ready',            999 );
       
    83 
       
    84 /**
       
    85  * There is no action API for roles to use, so hook in immediately after the
       
    86  * $wp_roles global is set, which is the 'setup_theme' action.
       
    87  *
       
    88  * This is kind of lame, but is all we have for now.
       
    89  */
       
    90 add_action( 'bbp_setup_theme', 'bbp_add_forums_roles', 1 );
       
    91 
       
    92 /**
       
    93  * When switching to a new blog, a users mapped role will get wiped out by
       
    94  * WP_User::for_blog() and WP_User::_init_caps().
       
    95  *
       
    96  * This happens naturally in multisite setups during WP_Admin_Bar::initialize(),
       
    97  * which is annoying because it will happen on each page-load.
       
    98  *
       
    99  * Resetting the role on blog-switch enables us to maintain the user's dynamic
       
   100  * role between sites. Note that if a user already has a role on that site, no
       
   101  * mapping will occur.
       
   102  *
       
   103  * We also hook to 'bbp_setup_current_user' -- naturally.
       
   104  */
       
   105 add_action( 'switch_blog',            'bbp_set_current_user_default_role' );
       
   106 add_action( 'bbp_setup_current_user', 'bbp_set_current_user_default_role' );
       
   107 
       
   108 /**
       
   109  * bbp_register - Attached to 'init' above on 0 priority
       
   110  *
       
   111  * Attach various initialization actions early to the init action.
       
   112  * The load order helps to execute code at the correct time.
       
   113  *                                                         v---Load order
       
   114  */
       
   115 add_action( 'bbp_register', 'bbp_register_post_types',     2  );
       
   116 add_action( 'bbp_register', 'bbp_register_post_statuses',  4  );
       
   117 add_action( 'bbp_register', 'bbp_register_taxonomies',     6  );
       
   118 add_action( 'bbp_register', 'bbp_register_views',          8  );
       
   119 add_action( 'bbp_register', 'bbp_register_shortcodes',     10 );
       
   120 
       
   121 // Autoembeds
       
   122 add_action( 'bbp_init', 'bbp_reply_content_autoembed', 8   );
       
   123 add_action( 'bbp_init', 'bbp_topic_content_autoembed', 8   );
       
   124 
       
   125 /**
       
   126  * bbp_ready - attached to end 'bbp_init' above
       
   127  *
       
   128  * Attach actions to the ready action after bbPress has fully initialized.
       
   129  * The load order helps to execute code at the correct time.
       
   130  *                                                v---Load order
       
   131  */
       
   132 add_action( 'bbp_ready',  'bbp_setup_akismet',    2  ); // Spam prevention for topics and replies
       
   133 add_action( 'bp_include', 'bbp_setup_buddypress', 10 ); // Social network integration
       
   134 
       
   135 // Try to load the bbpress-functions.php file from the active themes
       
   136 add_action( 'bbp_after_setup_theme', 'bbp_load_theme_functions', 10 );
       
   137 
       
   138 // Widgets
       
   139 add_action( 'bbp_widgets_init', array( 'BBP_Login_Widget',   'register_widget' ), 10 );
       
   140 add_action( 'bbp_widgets_init', array( 'BBP_Views_Widget',   'register_widget' ), 10 );
       
   141 add_action( 'bbp_widgets_init', array( 'BBP_Forums_Widget',  'register_widget' ), 10 );
       
   142 add_action( 'bbp_widgets_init', array( 'BBP_Topics_Widget',  'register_widget' ), 10 );
       
   143 add_action( 'bbp_widgets_init', array( 'BBP_Replies_Widget', 'register_widget' ), 10 );
       
   144 
       
   145 // Template - Head, foot, errors and messages
       
   146 add_action( 'bbp_loaded',           'bbp_login_notices'    );
       
   147 add_action( 'bbp_head',             'bbp_topic_notices'    );
       
   148 add_action( 'bbp_template_notices', 'bbp_template_notices' );
       
   149 
       
   150 // Always exclude private/hidden forums if needed
       
   151 add_action( 'pre_get_posts', 'bbp_pre_get_posts_exclude_forums', 4 );
       
   152 
       
   153 // Profile Page Messages
       
   154 add_action( 'bbp_template_notices', 'bbp_notice_edit_user_success'           );
       
   155 add_action( 'bbp_template_notices', 'bbp_notice_edit_user_is_super_admin', 2 );
       
   156 
       
   157 // Before Delete/Trash/Untrash Topic
       
   158 add_action( 'wp_trash_post', 'bbp_trash_forum'   );
       
   159 add_action( 'trash_post',    'bbp_trash_forum'   );
       
   160 add_action( 'untrash_post',  'bbp_untrash_forum' );
       
   161 add_action( 'delete_post',   'bbp_delete_forum'  );
       
   162 
       
   163 // After Deleted/Trashed/Untrashed Topic
       
   164 add_action( 'trashed_post',   'bbp_trashed_forum'   );
       
   165 add_action( 'untrashed_post', 'bbp_untrashed_forum' );
       
   166 add_action( 'deleted_post',   'bbp_deleted_forum'   );
       
   167 
       
   168 // Auto trash/untrash/delete a forums topics
       
   169 add_action( 'bbp_delete_forum',  'bbp_delete_forum_topics',  10 );
       
   170 add_action( 'bbp_trash_forum',   'bbp_trash_forum_topics',   10 );
       
   171 add_action( 'bbp_untrash_forum', 'bbp_untrash_forum_topics', 10 );
       
   172 
       
   173 // New/Edit Forum
       
   174 add_action( 'bbp_new_forum',  'bbp_update_forum', 10 );
       
   175 add_action( 'bbp_edit_forum', 'bbp_update_forum', 10 );
       
   176 
       
   177 // Save forum extra metadata
       
   178 add_action( 'bbp_new_forum_post_extras',         'bbp_save_forum_extras', 2 );
       
   179 add_action( 'bbp_edit_forum_post_extras',        'bbp_save_forum_extras', 2 );
       
   180 add_action( 'bbp_forum_attributes_metabox_save', 'bbp_save_forum_extras', 2 );
       
   181 
       
   182 // New/Edit Reply
       
   183 add_action( 'bbp_new_reply',  'bbp_update_reply', 10, 6 );
       
   184 add_action( 'bbp_edit_reply', 'bbp_update_reply', 10, 6 );
       
   185 
       
   186 // Before Delete/Trash/Untrash Reply
       
   187 add_action( 'wp_trash_post', 'bbp_trash_reply'   );
       
   188 add_action( 'trash_post',    'bbp_trash_reply'   );
       
   189 add_action( 'untrash_post',  'bbp_untrash_reply' );
       
   190 add_action( 'delete_post',   'bbp_delete_reply'  );
       
   191 
       
   192 // After Deleted/Trashed/Untrashed Reply
       
   193 add_action( 'trashed_post',   'bbp_trashed_reply'   );
       
   194 add_action( 'untrashed_post', 'bbp_untrashed_reply' );
       
   195 add_action( 'deleted_post',   'bbp_deleted_reply'   );
       
   196 
       
   197 // New/Edit Topic
       
   198 add_action( 'bbp_new_topic',  'bbp_update_topic', 10, 5 );
       
   199 add_action( 'bbp_edit_topic', 'bbp_update_topic', 10, 5 );
       
   200 
       
   201 // Split/Merge Topic
       
   202 add_action( 'bbp_merged_topic',     'bbp_merge_topic_count', 1, 3 );
       
   203 add_action( 'bbp_post_split_topic', 'bbp_split_topic_count', 1, 3 );
       
   204 
       
   205 // Before Delete/Trash/Untrash Topic
       
   206 add_action( 'wp_trash_post', 'bbp_trash_topic'   );
       
   207 add_action( 'trash_post',    'bbp_trash_topic'   );
       
   208 add_action( 'untrash_post',  'bbp_untrash_topic' );
       
   209 add_action( 'delete_post',   'bbp_delete_topic'  );
       
   210 
       
   211 // After Deleted/Trashed/Untrashed Topic
       
   212 add_action( 'trashed_post',   'bbp_trashed_topic'   );
       
   213 add_action( 'untrashed_post', 'bbp_untrashed_topic' );
       
   214 add_action( 'deleted_post',   'bbp_deleted_topic'   );
       
   215 
       
   216 // Favorites
       
   217 add_action( 'bbp_trash_topic',  'bbp_remove_topic_from_all_favorites' );
       
   218 add_action( 'bbp_delete_topic', 'bbp_remove_topic_from_all_favorites' );
       
   219 
       
   220 // Subscriptions
       
   221 add_action( 'bbp_trash_topic',  'bbp_remove_topic_from_all_subscriptions'      );
       
   222 add_action( 'bbp_delete_topic', 'bbp_remove_topic_from_all_subscriptions'      );
       
   223 add_action( 'bbp_new_reply',    'bbp_notify_subscribers',                 1, 5 );
       
   224 
       
   225 // Sticky
       
   226 add_action( 'bbp_trash_topic',  'bbp_unstick_topic' );
       
   227 add_action( 'bbp_delete_topic', 'bbp_unstick_topic' );
       
   228 
       
   229 // Update topic branch
       
   230 add_action( 'bbp_trashed_topic',   'bbp_update_topic_walker' );
       
   231 add_action( 'bbp_untrashed_topic', 'bbp_update_topic_walker' );
       
   232 add_action( 'bbp_deleted_topic',   'bbp_update_topic_walker' );
       
   233 add_action( 'bbp_spammed_topic',   'bbp_update_topic_walker' );
       
   234 add_action( 'bbp_unspammed_topic', 'bbp_update_topic_walker' );
       
   235 
       
   236 // Update reply branch
       
   237 add_action( 'bbp_trashed_reply',   'bbp_update_reply_walker' );
       
   238 add_action( 'bbp_untrashed_reply', 'bbp_update_reply_walker' );
       
   239 add_action( 'bbp_deleted_reply',   'bbp_update_reply_walker' );
       
   240 add_action( 'bbp_spammed_reply',   'bbp_update_reply_walker' );
       
   241 add_action( 'bbp_unspammed_reply', 'bbp_update_reply_walker' );
       
   242 
       
   243 // User status
       
   244 // @todo make these sub-actions
       
   245 add_action( 'make_ham_user',  'bbp_make_ham_user'  );
       
   246 add_action( 'make_spam_user', 'bbp_make_spam_user' );
       
   247 
       
   248 // User role
       
   249 add_action( 'bbp_profile_update', 'bbp_profile_update_role' );
       
   250 
       
   251 // Hook WordPress admin actions to bbPress profiles on save
       
   252 add_action( 'bbp_user_edit_after', 'bbp_user_edit_after' );
       
   253 
       
   254 // Caches
       
   255 add_action( 'bbp_new_forum_pre_extras',  'bbp_clean_post_cache' );
       
   256 add_action( 'bbp_new_forum_post_extras', 'bbp_clean_post_cache' );
       
   257 add_action( 'bbp_new_topic_pre_extras',  'bbp_clean_post_cache' );
       
   258 add_action( 'bbp_new_topic_post_extras', 'bbp_clean_post_cache' );
       
   259 add_action( 'bbp_new_reply_pre_extras',  'bbp_clean_post_cache' );
       
   260 add_action( 'bbp_new_reply_post_extras', 'bbp_clean_post_cache' );
       
   261 
       
   262 /**
       
   263  * bbPress needs to redirect the user around in a few different circumstances:
       
   264  *
       
   265  * 1. Form submission within a theme (new and edit)
       
   266  * 2. Accessing private or hidden content (forums/topics/replies)
       
   267  * 3. Editing forums, topics, replies, users, and tags
       
   268  */
       
   269 add_action( 'bbp_template_redirect', 'bbp_forum_enforce_blocked',   -1 );
       
   270 add_action( 'bbp_template_redirect', 'bbp_forum_enforce_hidden',    -1 );
       
   271 add_action( 'bbp_template_redirect', 'bbp_forum_enforce_private',   -1 );
       
   272 add_action( 'bbp_template_redirect', 'bbp_new_forum_handler',       10 );
       
   273 add_action( 'bbp_template_redirect', 'bbp_new_reply_handler',       10 );
       
   274 add_action( 'bbp_template_redirect', 'bbp_new_topic_handler',       10 );
       
   275 add_action( 'bbp_template_redirect', 'bbp_edit_topic_tag_handler',  1  );
       
   276 add_action( 'bbp_template_redirect', 'bbp_edit_user_handler',       1  );
       
   277 add_action( 'bbp_template_redirect', 'bbp_edit_forum_handler',      1  );
       
   278 add_action( 'bbp_template_redirect', 'bbp_edit_reply_handler',      1  );
       
   279 add_action( 'bbp_template_redirect', 'bbp_edit_topic_handler',      1  );
       
   280 add_action( 'bbp_template_redirect', 'bbp_merge_topic_handler',     1  );
       
   281 add_action( 'bbp_template_redirect', 'bbp_split_topic_handler',     1  );
       
   282 add_action( 'bbp_template_redirect', 'bbp_toggle_topic_handler',    1  );
       
   283 add_action( 'bbp_template_redirect', 'bbp_toggle_reply_handler',    1  );
       
   284 add_action( 'bbp_template_redirect', 'bbp_favorites_handler',       1  );
       
   285 add_action( 'bbp_template_redirect', 'bbp_subscriptions_handler',   1  );
       
   286 add_action( 'bbp_template_redirect', 'bbp_check_user_edit',         10 );
       
   287 add_action( 'bbp_template_redirect', 'bbp_check_forum_edit',        10 );
       
   288 add_action( 'bbp_template_redirect', 'bbp_check_topic_edit',        10 );
       
   289 add_action( 'bbp_template_redirect', 'bbp_check_reply_edit',        10 );
       
   290 add_action( 'bbp_template_redirect', 'bbp_check_topic_tag_edit',    10 );
       
   291 
       
   292 // Maybe convert the users password
       
   293 add_action( 'bbp_login_form_login', 'bbp_user_maybe_convert_pass' );
       
   294 
       
   295 add_action( 'bbp_activation', 'bbp_add_activation_redirect' );