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-functions.php

    r13455 r13461  
    141141
    142142/** Functions *****************************************************************/
     143
     144/**
     145 * Get the BuddyPress parser in use.
     146 *
     147 * @since 12.0.0
     148 *
     149 * @return string The name of the parser in use.
     150 */
     151function bp_core_get_query_parser() {
     152    /**
     153     * Which parser is in use? `rewrites` or `legacy`?
     154     *
     155     * @todo Remove the Pretty URLs check used during BP Rewrites merge process.
     156     *
     157     * @since 12.0.0
     158     *
     159     * @param string $parser The parser to use to decide the hook to attach key actions to.
     160     *                       Possible values are `rewrites` or `legacy`.
     161     */
     162    return apply_filters( 'bp_core_get_query_parser', bp_has_pretty_urls() ? 'legacy' : 'rewrites' );
     163}
    143164
    144165/**
     
    25882609    bp_core_redirect( apply_filters( 'bp_core_search_site', home_url( $slug . $query_string . urlencode( $search_terms ) ), $search_terms ) );
    25892610}
    2590 add_action( 'bp_parse_query', 'bp_core_action_search_site', 13, 0 );
    25912611
    25922612/**
     
    26072627    remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10 );
    26082628}
    2609 add_action( 'bp_init', 'bp_remove_adjacent_posts_rel_link' );
    26102629
    26112630/**
     
    29792998     */
    29802999    return apply_filters( 'bp_core_get_suggestions', $retval, $args );
     3000}
     3001
     3002/**
     3003 * Register Ajax actions needing the BP URI globals to be set.
     3004 *
     3005 * @since 12.0.0
     3006 *
     3007 * @param string $ajax_action The ajax action needing the BP URI globals to be set.
     3008 * @return boolean            True if the ajax action was registered. False otherwise.
     3009 */
     3010function bp_ajax_register_action( $ajax_action = '' ) {
     3011    // Checks the ajax action is registered.
     3012    if ( bp_ajax_action_is_registered( $ajax_action ) ) {
     3013        return false;
     3014    }
     3015
     3016    buddypress()->ajax_actions[] = $ajax_action;
     3017    return true;
     3018}
     3019
     3020/**
     3021 * Is the requested ajax action registered?
     3022 *
     3023 * @since 12.0.0
     3024 *
     3025 * @param string $ajax_action The ajax action to check.
     3026 * @return boolean            True if the ajax action is registered. False otherwise
     3027 */
     3028function bp_ajax_action_is_registered( $ajax_action = '' ) {
     3029    $registered_ajax_actions = buddypress()->ajax_actions;
     3030
     3031    return in_array( $ajax_action, $registered_ajax_actions, true );
    29813032}
    29823033
Note: See TracChangeset for help on using the changeset viewer.