Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/24/2023 02:32:27 AM (12 months ago)
Author:
imath
Message:

Make canonical redirection & Ajax requesting BP Rewrites ready

  • Introduces bp_core_setup_query_parser() to decide when to postpone some key hooks firing to bp_parse_query.
  • Introduces bp_core_get_query_parser() to get the query parser in use. It contains a filter BP Classic will be able to use to force the Legacy URL parser. So far it uses legacy for pretty links and rewrites for plain links.
  • Edit bp_redirect_canonical() & bp_get_canonical_url() so that they use the BP Rewrites API.
  • Introduces bp_core_set_ajax_uri_globals() to set the BuddyPress URI globales using the BP Rewrites API inside the Ajax context thanks to the updated bp_reset_query() function.
  • To avoid using WP() at each Ajax call, introduces a simple Ajax actions registration process thanks to the new bp_ajax_register_action().
  • Update Legacy & Nouveau template packs so that they use this logic. As BP Default will require the legacy URL parser and will be moved inside BP Classic, the theme can stay the way it is.
  • Improve the bp_rewrites_pre_get_slug filter logic making it depends on the bp_core_get_query_parser() function.
  • Make sure to reset the Members navigation to a new BP_Core_Nav based on the displayed user once the user is available in the component's parse_query() method.

Props r-a-y, johnjamesjacoby, boonebgorges

Closes https://github.com/buddypress/buddypress/pull/91
See #4954

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-actions.php

    r13431 r13461  
    7272add_action( 'bp_init', 'bp_register_post_statuses',  2  );
    7373add_action( 'bp_init', 'bp_register_taxonomies',     2  );
    74 add_action( 'bp_init', 'bp_core_set_uri_globals',    2  );
    7574add_action( 'bp_init', 'bp_setup_globals',           4  );
    76 add_action( 'bp_init', 'bp_setup_canonical_stack',   5  );
    77 add_action( 'bp_init', 'bp_setup_nav',               6  );
    78 add_action( 'bp_init', 'bp_setup_title',             8  );
    7975add_action( 'bp_init', 'bp_blocks_init',             10 );
    8076add_action( 'bp_init', 'bp_core_load_admin_bar_css', 12 );
     
    8278add_action( 'bp_init', 'bp_add_rewrite_rules',       30 );
    8379add_action( 'bp_init', 'bp_add_permastructs',        40 );
     80
     81/**
     82 * Adapt BuddyPress key actions starting point according to the request parser in use.
     83 *
     84 * The legacy request parser needs key actions to hook at `bp_init`, while the BP Rewrites API
     85 * needs key actions to hook at `bp_parse_query`.
     86 *
     87 * @since 12.0.0
     88 */
     89function bp_core_setup_query_parser() {
     90    $parser = bp_core_get_query_parser();
     91    $hook   = 'bp_parse_query';
     92    if ( 'legacy' === $parser ) {
     93        $hook = 'bp_init';
     94    }
     95
     96    $key_actions = array(
     97        'bp_setup_canonical_stack'            => 11,
     98        'bp_setup_nav'                        => 12,
     99        'bp_core_action_search_site'          => 13,
     100        'bp_setup_title'                      => 14,
     101        '_bp_maybe_remove_redirect_canonical' => 20,
     102        'bp_remove_adjacent_posts_rel_link'   => 20,
     103    );
     104
     105    if ( 'bp_init' === $hook ) {
     106        $key_actions['bp_setup_canonical_stack']            = 5;
     107        $key_actions['bp_setup_nav']                        = 6;
     108        $key_actions['bp_core_action_search_site']          = 7;
     109        $key_actions['bp_setup_title']                      = 8;
     110        $key_actions['_bp_maybe_remove_redirect_canonical'] = 10;
     111        $key_actions['bp_remove_adjacent_posts_rel_link']   = 10;
     112
     113        /**
     114         *
     115         * @todo This code should be moved to BP Classic.
     116         *
     117         */
     118        add_action( $hook, 'bp_core_set_uri_globals', 2 );
     119    }
     120
     121    foreach ( $key_actions as $action => $priority ) {
     122        $arguments = 1;
     123
     124        if ( 'bp_core_action_search_site' === $action ) {
     125            $arguments = 0;
     126        }
     127
     128        add_action( $hook, $action, $priority, $arguments );
     129    }
     130}
     131add_action( 'bp_init', 'bp_core_setup_query_parser', 1 );
    84132
    85133/**
Note: See TracChangeset for help on using the changeset viewer.