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

    r13455 r13461  
    7979 */
    8080function bp_rewrites_get_slug( $component_id = '', $rewrite_id = '', $default_slug = '' ) {
     81    $using_legacy = 'legacy' === bp_core_get_query_parser();
     82
    8183    /**
    82      * This filter is used by the BP Classic plugin to force `$default_slug` usage.
    83      *
    84      * Using the "Classic" BuddyPress means deprecated functions building URL concatening
    85      * URL chunks are available, we cannot use the BP Rewrites API in this case & as a result
    86      * slug customization is bypassed.
    87      *
    88      * The BP Classic plugin is simply returning the `$default_slug` to bypass slug customization.
     84     * This filter is used to simply return the `$default_slug` to bypass slug customization
     85     * when the query parser is the legacy one.
    8986     *
    9087     * @since 12.0.0
    9188     *
    92      * @param string $value        An empty string to use as to know whether slug customization should be used.
    93      * @param string $default_slug The screen default slug, used as a fallback.
    94      * @param string $rewrite_id   The screen rewrite ID, used to find the custom slugs.
    95      * @param string $component_id The BuddyPress component's ID.
     89     * @param boolean $using_legacy Whether the legacy URL parser is in use.
     90     *                              In this case, slug customization is not supported.
     91     * @param string  $default_slug The screen default slug, used as a fallback.
     92     * @param string  $rewrite_id   The screen rewrite ID, used to find the custom slugs.
     93     * @param string  $component_id The BuddyPress component's ID.
    9694     */
    97     $classic_slug = apply_filters( 'bp_rewrites_pre_get_slug', '', $default_slug, $rewrite_id, $component_id );
    98     if ( $classic_slug ) {
    99         return $classic_slug;
     95    $use_default_slug = apply_filters( 'bp_rewrites_pre_get_slug', $using_legacy, $default_slug, $rewrite_id, $component_id );
     96    if ( $use_default_slug ) {
     97        return $default_slug;
    10098    }
    10199
     
    211209            }
    212210
    213             $url = add_query_arg( $qv, $url );
     211            $url = add_query_arg( $qv, trailingslashit( $url ) );
    214212
    215213            // Using pretty URLs.
Note: See TracChangeset for help on using the changeset viewer.