Skip to:
Content

BuddyPress.org

Ticket #7335: 7335-anonymous-actions.2.diff

File 7335-anonymous-actions.2.diff, 15.1 KB (added by tw2113, 8 years ago)
  • src/bp-core/bp-core-actions.php

    diff --git src/bp-core/bp-core-actions.php src/bp-core/bp-core-actions.php
    index d8fc1d6..9ea81fe 100644
    defined( 'ABSPATH' ) || exit; 
    3030 *
    3131 *           v--WordPress Actions       v--BuddyPress Sub-actions
    3232 */
    33 add_action( 'plugins_loaded',          'bp_loaded',                 10    );
    34 add_action( 'init',                    'bp_init',                   10    );
    35 add_action( 'rest_api_init',           'bp_rest_api_init',          20    ); // After WP core.
    36 add_action( 'customize_register',      'bp_customize_register',     20    ); // After WP core.
     33add_action( 'plugins_loaded',          function() {
     34
     35        /**
     36         * Fires on the 'plugins_loaded' hook, which fires after BP's core plugin files have been loaded.
     37         *
     38         * @since 1.2.5
     39         */
     40        do_action( 'bp_loaded' );
     41}, 10 );
     42add_action( 'init',                    function() {
     43
     44        /**
     45         * Fires on the 'init' hook, BuddyPress' main initialization hook.
     46         *
     47         * @since 1.2.0
     48         */
     49        do_action( 'bp_init' );
     50}, 10 );
     51add_action( 'rest_api_init',           function() {
     52
     53        /**
     54         * Fires on the 'rest_api_init' hook, where BuddyPress registers REST API endpoints.
     55         *
     56         * @since 2.6.0
     57         */
     58        do_action( 'bp_rest_api_init' );
     59}, 20 ); // After WP core.
     60add_action( 'customize_register',      function( WP_Customize_Manager $customizer ) {
     61
     62        /**
     63         * Fires once the Customizer has loaded, allow scripts and styles to be initialized.
     64         *
     65         * @since 2.5.0
     66         *
     67         * @param WP_Customize_Manager $customizer Customizer instance.
     68         */
     69        do_action( 'bp_customize_register', $customizer );
     70}, 20 ); // After WP core.
    3771add_action( 'parse_query',             'bp_parse_query',            2     ); // Early for overrides.
    38 add_action( 'wp',                      'bp_ready',                  10    );
    39 add_action( 'set_current_user',        'bp_setup_current_user',     10    );
    40 add_action( 'setup_theme',             'bp_setup_theme',            10    );
    41 add_action( 'after_setup_theme',       'bp_after_setup_theme',      100   ); // After WP themes.
    42 add_action( 'wp_enqueue_scripts',      'bp_enqueue_scripts',        10    );
    43 add_action( 'enqueue_embed_scripts',   'bp_enqueue_embed_scripts',  10    );
    44 add_action( 'admin_bar_menu',          'bp_setup_admin_bar',        20    ); // After WP core.
    45 add_action( 'template_redirect',       'bp_template_redirect',      10    );
    46 add_action( 'widgets_init',            'bp_widgets_init',           10    );
    47 add_action( 'generate_rewrite_rules',  'bp_generate_rewrite_rules', 10    );
     72add_action( 'wp',                      function() {
     73
     74        /**
     75         * Fires on the 'wp' hook, which runs after BP is set up and the page is about to render.
     76         *
     77         * @since 1.6.0
     78         */
     79        do_action( 'bp_ready' );
     80}, 10 );
     81add_action( 'set_current_user',        function() {
     82
     83        /**
     84         * Fires on the set_current_user hook for the current user setup process.
     85         *
     86         * @since 1.7.0
     87         */
     88        do_action( 'bp_setup_current_user' );
     89}, 10 );
     90add_action( 'setup_theme',             function() {
     91
     92        /**
     93         * Fires on the 'setup_theme' hook.
     94         *
     95         * @since 1.6.0
     96         */
     97        do_action( 'bp_setup_theme' );
     98}, 10 );
     99add_action( 'after_setup_theme',       function() {
     100
     101        /**
     102         * Fires on the 'after_setup_theme' hook.
     103         *
     104         * @since 1.7.0
     105         */
     106        do_action( 'bp_after_setup_theme' );
     107}, 100 ); // After WP themes.
     108add_action( 'wp_enqueue_scripts',      function() {
     109
     110        /**
     111         * Fires on the 'wp_enqueue_scripts' hook, where BP enqueues its CSS and JS.
     112         *
     113         * @since 1.6.0
     114         */
     115        do_action( 'bp_enqueue_scripts' );
     116}, 10 );
     117add_action( 'enqueue_embed_scripts',   function() {
     118
     119        if ( ! is_buddypress() ) {
     120                return;
     121        }
     122
     123        /**
     124         * Enqueue CSS and JS files for BuddyPress embeds.
     125         *
     126         * @since 2.6.0
     127         */
     128        do_action( 'bp_enqueue_embed_scripts' );
     129}, 10 );
     130add_action( 'admin_bar_menu',          function() {
     131        if ( bp_use_wp_admin_bar() ) {
     132
     133                /**
     134                 * Fires on the 'admin_bar_menu' hook, where plugins should add items to the WP admin bar.
     135                 *
     136                 * This hook will only fire if bp_use_wp_admin_bar() returns true.
     137                 *
     138                 * @since 1.5.0
     139                 */
     140                do_action( 'bp_setup_admin_bar' );
     141        }
     142}, 20 ); // After WP core.
     143add_action( 'template_redirect',       function() {
     144
     145        /**
     146         * Fires on the 'template_redirect' hook.
     147         *
     148         * @since 1.6.0
     149         */
     150        do_action( 'bp_template_redirect' );
     151}, 10 );
     152add_action( 'widgets_init',            function() {
     153
     154        /**
     155         * Fires on the 'widgets_init' hook, which runs after widgets have been set up.
     156         *
     157         * Hooked to 'widgets_init'.
     158         *
     159         * @since 1.6.0
     160         */
     161        do_action( 'bp_widgets_init' );
     162}, 10 );
     163add_action( 'generate_rewrite_rules',  function( $wp_rewrite ) {
     164
     165        /**
     166         * Fires on the 'generate_rewrite_rules' hook.
     167         *
     168         * @since 1.7.0
     169         *
     170         * @param WP_Rewrite $wp_rewrite WP_Rewrite object. Passed by reference.
     171         */
     172        do_action_ref_array( 'bp_generate_rewrite_rules', array( &$wp_rewrite ) );
     173}, 10 );
    48174
    49175/**
    50176 * The bp_loaded hook - Attached to 'plugins_loaded' above.
    add_action( 'generate_rewrite_rules', 'bp_generate_rewrite_rules', 10 ); 
    53179 * The load order helps to execute code at the correct time.
    54180 *                                                      v---Load order
    55181 */
    56 add_action( 'bp_loaded', 'bp_setup_components',         2  );
    57 add_action( 'bp_loaded', 'bp_include',                  4  );
    58 add_action( 'bp_loaded', 'bp_setup_cache_groups',       5  );
    59 add_action( 'bp_loaded', 'bp_setup_widgets',            6  );
    60 add_action( 'bp_loaded', 'bp_register_theme_packages',  12 );
    61 add_action( 'bp_loaded', 'bp_register_theme_directory', 14 );
     182add_action( 'bp_loaded', function() {
     183
     184        /**
     185         * Fires on the 'bp_loaded' action, where plugins should initialize components.
     186         *
     187         * @since 1.6.0
     188         */
     189        do_action( 'bp_setup_components' );
     190}, 2 );
     191
     192add_action( 'bp_loaded', function() {
     193
     194        /**
     195         * Fires on the 'bp_loaded' action, where plugins should include files.
     196         *
     197         * @since 1.2.5
     198         */
     199         do_action( 'bp_include' );
     200}, 4 );
     201add_action( 'bp_loaded', function() {
     202
     203        /**
     204         * Fires on the 'bp_loaded' hook, where cache groups are registered.
     205         *
     206         * @since 2.2.0
     207         */
     208        do_action( 'bp_setup_cache_groups' );
     209}, 5 );
     210add_action( 'bp_loaded', function() {
     211
     212        /**
     213         * Fires on the 'bp_loaded' hook, where plugins should register widgets.
     214         *
     215         * @since 1.2.0
     216         */
     217        do_action( 'bp_register_widgets' );
     218}, 6 );
     219add_action( 'bp_loaded', function() {
     220
     221        /**
     222         * Fires on the 'bp_loaded' hook.
     223         *
     224         * @since 1.7.0
     225         */
     226        do_action( 'bp_register_theme_packages' );
     227}, 12 );
     228add_action( 'bp_loaded', function() {
     229
     230        /**
     231         * Fires on the 'bp_loaded' function.
     232         *
     233         * The main action used registering theme directories.
     234         *
     235         * @since 1.7.0
     236         */
     237        do_action( 'bp_register_theme_directory' );
     238}, 14 );
    62239
    63240/**
    64241 * The bp_init hook - Attached to 'init' above.
    add_action( 'bp_loaded', 'bp_register_theme_directory', 14 ); 
    67244 * The load order helps to execute code at the correct time.
    68245 *                                                   v---Load order
    69246 */
    70 add_action( 'bp_init', 'bp_register_post_types',     2  );
    71 add_action( 'bp_init', 'bp_register_taxonomies',     2  );
     247add_action( 'bp_init', function() {
     248
     249        /**
     250         * Fires on the 'bp_init' hook, where plugins should register post types.
     251         *
     252         * @since 2.5.0
     253         */
     254        do_action( 'bp_register_post_types' );
     255}, 2 );
     256
     257add_action( 'bp_init', function() {
     258
     259        /**
     260         * Fires on the 'bp_init' hook, where plugins should register taxonomies.
     261         *
     262         * @since 2.2.0
     263         */
     264        do_action( 'bp_register_taxonomies' );
     265}, 2 );
     266
    72267add_action( 'bp_init', 'bp_core_set_uri_globals',    2  );
    73 add_action( 'bp_init', 'bp_setup_globals',           4  );
    74 add_action( 'bp_init', 'bp_setup_canonical_stack',   5  );
    75 add_action( 'bp_init', 'bp_setup_nav',               6  );
    76 add_action( 'bp_init', 'bp_setup_title',             8  );
     268add_action( 'bp_init', function() {
     269
     270        /**
     271         * Fires on the 'bp_init' hook, where plugins should initialize global settings.
     272         *
     273         * @since 1.2.0
     274         */
     275        do_action( 'bp_setup_globals' );
     276}, 4 );
     277add_action( 'bp_init', function() {
     278
     279        /**
     280         * Fires on the 'bp_init' hook, where plugins should set up their canonical URL.
     281         *
     282         * @since 2.1.0
     283         */
     284        do_action( 'bp_setup_canonical_stack' );
     285}, 5 );
     286add_action( 'bp_init', function() {
     287
     288        /**
     289         * Fires on the 'bp_init' hook, where plugins should register their navigation items.
     290         *
     291         * @since 1.2.0
     292         */
     293        do_action( 'bp_setup_nav' );
     294}, 6 );
     295add_action( 'bp_init', function() {
     296
     297        /**
     298         * Fires on the 'bp_init' hook, where plugins should modify the page title.
     299         *
     300         * @since 1.5.0
     301         */
     302        do_action( 'bp_setup_title' );
     303}, 8 );
    77304add_action( 'bp_init', 'bp_core_load_admin_bar_css', 12 );
    78 add_action( 'bp_init', 'bp_add_rewrite_tags',        20 );
    79 add_action( 'bp_init', 'bp_add_rewrite_rules',       30 );
    80 add_action( 'bp_init', 'bp_add_permastructs',        40 );
     305add_action( 'bp_init', function() {
     306
     307        /**
     308         * Fires on the 'bp_init' hook, where BP adds its custom rewrite tags.
     309         *
     310         * @since 1.8.0
     311         */
     312        do_action( 'bp_add_rewrite_tags' );
     313}, 20 );
     314add_action( 'bp_init', function() {
     315
     316        /**
     317         * Fires on the 'bp_init' hook, where BP adds its custom rewrite rules.
     318         *
     319         * @since 1.9.0
     320         */
     321        do_action( 'bp_add_rewrite_rules' );
     322}, 30 );
     323add_action( 'bp_init', function() {
     324
     325        /**
     326         * Fires on the 'bp_init' hook, where BP adds its BP-specific permalink structure.
     327         *
     328         * @since 1.9.0
     329         */
     330        do_action( 'bp_add_permastructs' );
     331}, 40 );
    81332
    82333/**
    83334 * The bp_register_taxonomies hook - Attached to 'bp_init' @ priority 2 above.
    84335 */
    85 add_action( 'bp_register_taxonomies', 'bp_register_member_types' );
     336add_action( 'bp_register_taxonomies', function() {
     337
     338        /**
     339         * Fires on the bp_register_taxonomies hook, so plugins can register member types.
     340         *
     341         * @since 2.3.0
     342         */
     343        do_action( 'bp_register_member_types' );
     344} );
    86345
    87346/**
    88347 * The bp_template_redirect hook - Attached to 'template_redirect' above.
    add_action( 'bp_register_taxonomies', 'bp_register_member_types' ); 
    96355 *                                                           v---Load order
    97356 */
    98357add_action( 'bp_template_redirect', 'bp_redirect_canonical', 2  );
    99 add_action( 'bp_template_redirect', 'bp_actions',            4  );
    100 add_action( 'bp_template_redirect', 'bp_screens',            6  );
    101 add_action( 'bp_template_redirect', 'bp_post_request',       10 );
    102 add_action( 'bp_template_redirect', 'bp_get_request',        10 );
     358add_action( 'bp_template_redirect', function() {
     359
     360        /**
     361         * Fires on the 'bp_actions' hook, which runs just before rendering.
     362         *
     363         * @since 1.5.0
     364         */
     365        do_action( 'bp_actions' );
     366}, 4 );
     367add_action( 'bp_template_redirect', function() {
     368
     369        /**
     370         * Fires on the 'bp_template_redirect' hook, which runs just before rendering.
     371         *
     372         * Runs just after 'bp_actions'. Use this hook to attach your template loaders.
     373         *
     374         * @since 1.5.0
     375         */
     376        do_action( 'bp_screens' );
     377}, 6 );
     378add_action( 'bp_template_redirect', function() {
     379
     380        // Bail if not a POST action.
     381        if ( ! bp_is_post_request() ) {
     382                return;
     383        }
     384
     385        // Bail if no action.
     386        if ( empty( $_POST['action'] ) ) {
     387                return;
     388        }
     389
     390        // Sanitize the POST action.
     391        $action = sanitize_key( $_POST['action'] );
     392
     393        /**
     394         * Fires at the end of the bp_template_redirect callback for BuddyPress.
     395         *
     396         * This dynamic action is probably the one you want to use. It narrows down
     397         * the scope of the 'action' without needing to check it in your function.
     398         *
     399         * @since 1.9.0
     400         */
     401        do_action( 'bp_post_request_' . $action );
     402
     403        /**
     404         * Fires at the end of the bp_template_redirect callback for BuddyPress.
     405         *
     406         * Use this static action if you don't mind checking the 'action' yourself.
     407         *
     408         * @since 1.9.0
     409         *
     410         * @param string $action The action being run.
     411         */
     412        do_action( 'bp_post_request', $action );
     413}, 10 );
     414add_action( 'bp_template_redirect', function() {
     415
     416        // Bail if not a POST action.
     417        if ( ! bp_is_get_request() ) {
     418                return;
     419        }
     420
     421        // Bail if no action.
     422        if ( empty( $_GET['action'] ) ) {
     423                return;
     424        }
     425
     426        // Sanitize the GET action.
     427        $action = sanitize_key( $_GET['action'] );
     428
     429        /**
     430         * Fires at the end of the bp_template_redirect callback for BuddyPress.
     431         *
     432         * This dynamic action is probably the one you want to use. It narrows down
     433         * the scope of the 'action' without needing to check it in your function.
     434         *
     435         * @since 1.9.0
     436         */
     437        do_action( 'bp_get_request_' . $action );
     438
     439        /**
     440         * Fires at the end of the bp_template_redirect callback for BuddyPress.
     441         *
     442         * Use this static action if you don't mind checking the 'action' yourself.
     443         *
     444         * @since 1.9.0
     445         *
     446         * @param string $action The action being run.
     447         */
     448        do_action( 'bp_get_request', $action );
     449}, 10 );
    103450
    104451/**
    105452 * Add the BuddyPress functions file and the Theme Compat Default features.
  • src/bp-core/bp-core-filters.php

    diff --git src/bp-core/bp-core-filters.php src/bp-core/bp-core-filters.php
    index ff6bf80..0788788 100644
    defined( 'ABSPATH' ) || exit; 
    4040 *
    4141 *           v--WordPress Actions       v--BuddyPress Sub-actions
    4242 */
    43 add_filter( 'request',                 'bp_request',             10    );
    44 add_filter( 'template_include',        'bp_template_include',    10    );
    45 add_filter( 'login_redirect',          'bp_login_redirect',      10, 3 );
     43add_filter( 'request',                 function( $query_vars = array() ) {
     44
     45        /**
     46         * Filters the query_vars for the current request.
     47         *
     48         * @since 1.7.0
     49         *
     50         * @param array $query_vars Array of query variables.
     51         */
     52        return apply_filters( 'bp_request', $query_vars );
     53}, 10 );
     54add_filter( 'template_include',        function( $template = '' ) {
     55
     56        /**
     57         * Filters the template to use with template_include.
     58         *
     59         * @since 1.6.0
     60         *
     61         * @param string $template The path of the template to include.
     62         */
     63        return apply_filters( 'bp_template_include', $template );
     64}, 10 );
     65add_filter( 'login_redirect',          function( $redirect_to = '', $redirect_to_raw = '', $user = false ) {
     66
     67        /**
     68         * Filters the URL to redirect to after login.
     69         *
     70         * @since 1.7.0
     71         *
     72         * @param string           $redirect_to     The redirect destination URL.
     73         * @param string           $redirect_to_raw The requested redirect destination URL passed as a parameter.
     74         * @param WP_User|WP_Error $user            WP_User object if login was successful, WP_Error object otherwise.
     75         */
     76        return apply_filters( 'bp_login_redirect', $redirect_to, $redirect_to_raw, $user );
     77}, 10, 3 );
    4678add_filter( 'map_meta_cap',            'bp_map_meta_caps',       10, 4 );
    4779
    4880// Add some filters to feedback messages.
  • src/bp-core/bp-core-theme-compatibility.php

    diff --git src/bp-core/bp-core-theme-compatibility.php src/bp-core/bp-core-theme-compatibility.php
    index 117d158..4cc5ad9 100644
    function bp_template_include_theme_compat( $template = '' ) { 
    720720
    721721                // Add BuddyPress's head action to wp_head.
    722722                if ( ! has_action( 'wp_head', 'bp_head' ) ) {
    723                         add_action( 'wp_head', 'bp_head' );
     723                        add_action( 'wp_head', function() {
     724
     725                                /**
     726                                 * Fires on the 'wp_head' hook, which runs on 'wp_head'.
     727                                 *
     728                                 * @since 1.6.0
     729                                 */
     730                                do_action( 'bp_head' );
     731                        } );
    724732                }
    725733        }
    726734