Skip to:
Content

BuddyPress.org

Changeset 13461


Ignore:
Timestamp:
04/24/2023 02:32:27 AM (4 years 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

Location:
trunk
Files:
24 edited

Legend:

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

    r13123 r13461  
    5555add_action( 'bp_admin_init', 'bp_register_admin_style'         );
    5656add_action( 'bp_admin_init', 'bp_register_admin_settings'      );
    57 add_action( 'bp_admin_init', 'bp_do_activation_redirect', 1    );
     57add_action( 'bp_admin_init', 'bp_do_activation_redirect',    1 );
     58add_action( 'bp_admin_init', 'bp_core_set_ajax_uri_globals', 2 );
    5859
    5960// Add a new separator.
  • 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/**
  • trunk/src/bp-core/bp-core-catchuri.php

    r13436 r13461  
    386386        // Reset the keys by merging with an empty array.
    387387        $bp->action_variables = array_merge( array(), $bp->action_variables );
     388}
     389
     390/**
     391 * Sets BuddyPress globals for Ajax requests using the BP Rewrites API.
     392 *
     393 * @since 12.0.0
     394 */
     395function bp_core_set_ajax_uri_globals() {
     396        if ( ! wp_doing_ajax() || 'rewrites' !== bp_core_get_query_parser() ) {
     397                return;
     398        }
     399
     400        $action = '';
     401        if ( isset( $_REQUEST['action'] ) ) {
     402                $action = wp_unslash( sanitize_text_field( $_REQUEST['action'] ) );
     403        }
     404
     405        // Only set BuddyPress URI globals for registered Ajax actions.
     406        if ( ! bp_ajax_action_is_registered( $action ) ) {
     407                return;
     408        }
     409
     410        bp_reset_query( bp_get_referer_path(), $GLOBALS['wp_query'] );
    388411}
    389412
    … …  
    808831         * @param bool $value Whether or not to do canonical redirects. Default true.
    809832         */
    810         if ( !bp_is_blog_page() && apply_filters( 'bp_do_redirect_canonical', true ) ) {
     833        if ( ! bp_is_blog_page() && apply_filters( 'bp_do_redirect_canonical', true ) ) {
    811834                // If this is a POST request, don't do a canonical redirect.
    812835                // This is for backward compatibility with plugins that submit form requests to
    813836                // non-canonical URLs. Plugin authors should do their best to use canonical URLs in
    814837                // their form actions.
    815                 if ( !empty( $_POST ) ) {
     838                if ( ! empty( $_POST ) ) {
    816839                        return;
    817840                }
    … …  
    819842                // Build the URL in the address bar.
    820843                $requested_url  = bp_get_requested_url();
     844                $query_args     = '';
    821845
    822846                // Stash query args.
    823                 $url_stack      = explode( '?', $requested_url );
    824                 $req_url_clean  = $url_stack[0];
    825                 $query_args     = isset( $url_stack[1] ) ? $url_stack[1] : '';
    826 
    827                 $canonical_url  = bp_get_canonical_url();
     847                if ( bp_has_pretty_urls() ) {
     848                        $query_args    = wp_parse_url( $requested_url, PHP_URL_QUERY );
     849                        $req_url_clean = str_replace( '?' . $query_args, '', $requested_url );
     850                } else {
     851                        $req_url_clean = $requested_url;
     852                }
     853
     854                $canonical_url = bp_get_canonical_url();
    828855
    829856                // Only redirect if we've assembled a URL different from the request.
    830                 if ( $canonical_url !== $req_url_clean ) {
    831 
     857                if ( esc_url( $canonical_url ) !== esc_url( $req_url_clean ) ) {
    832858                        $bp = buddypress();
    833859
    … …  
    841867                        }
    842868
    843                         if ( !empty( $query_args ) ) {
     869                        if ( ! empty( $query_args ) ) {
    844870                                $canonical_url .= '?' . $query_args;
    845871                        }
    … …  
    891917                $defaults
    892918        );
    893 
    894         extract( $r );
    895919
    896920        // Special case: when a BuddyPress directory (eg example.com/members)
    … …  
    929953                // Build the URL in the address bar.
    930954                $requested_url  = bp_get_requested_url();
    931 
    932                 // Stash query args.
    933                 $url_stack      = explode( '?', $requested_url );
     955                $base_url       = '';
     956                $path_chunks    = array();
     957                $component_id   = '';
     958
     959                // Get query args.
     960                $query_string = wp_parse_url( $requested_url, PHP_URL_QUERY );
     961                $query_args   = wp_parse_args( $query_string, array() );
    934962
    935963                // Build the canonical URL out of the redirect stack.
    936                 if ( isset( $bp->canonical_stack['base_url'] ) )
    937                         $url_stack[0] = $bp->canonical_stack['base_url'];
    938 
    939                 if ( isset( $bp->canonical_stack['component'] ) )
    940                         $url_stack[0] = trailingslashit( $url_stack[0] . $bp->canonical_stack['component'] );
    941 
    942                 if ( isset( $bp->canonical_stack['action'] ) )
    943                         $url_stack[0] = trailingslashit( $url_stack[0] . $bp->canonical_stack['action'] );
    944 
    945                 if ( !empty( $bp->canonical_stack['action_variables'] ) ) {
    946                         foreach( (array) $bp->canonical_stack['action_variables'] as $av ) {
    947                                 $url_stack[0] = trailingslashit( $url_stack[0] . $av );
    948                         }
    949                 }
    950 
    951                 // Add trailing slash.
    952                 $url_stack[0] = trailingslashit( $url_stack[0] );
    953 
    954                 // Stash in the $bp global.
    955                 $bp->canonical_stack['canonical_url'] = implode( '?', $url_stack );
     964                if ( isset( $bp->canonical_stack['base_url'] ) ) {
     965                        $base_url = $bp->canonical_stack['base_url'];
     966                } else {
     967                        $base_url = $requested_url;
     968
     969                        if ( bp_has_pretty_urls() ) {
     970                                $base_url = str_replace( '?' . $query_string, '', $requested_url );
     971                        }
     972                }
     973
     974                // This is a BP Members URL.
     975                if ( isset( $bp->canonical_stack['component'] ) ) {
     976                        $component_id  = 'members';
     977                        $path_chunks[] = $bp->canonical_stack['component'];
     978
     979                        if ( $query_args ) {
     980                                $query_args = array_diff_key(
     981                                        $query_args,
     982                                        array_fill_keys(
     983                                                array( 'bp_members', 'bp_member', 'bp_member_component' ),
     984                                                true
     985                                        )
     986                                );
     987                        }
     988                } else {
     989                        $component_id = 'groups';
     990                }
     991
     992                if ( isset( $bp->canonical_stack['action'] ) ) {
     993                        $path_chunks[]        = $bp->canonical_stack['action'];
     994                        $action_key           = 'bp_member_action';
     995                        $action_variables_key = 'bp_member_action_variables';
     996
     997                        if ( 'groups' === $component_id ) {
     998                                $action_key           = 'bp_group_action';
     999                                $action_variables_key = 'bp_group_action_variables';
     1000                        }
     1001
     1002                        if ( ! empty( $bp->canonical_stack['action_variables'] ) ) {
     1003                                $path_chunks = array_merge( $path_chunks, (array) $bp->canonical_stack['action_variables'] );
     1004                        } elseif ( isset( $query_args[ $action_variables_key ] ) ) {
     1005                                unset( $query_args[ $action_variables_key ] );
     1006                        }
     1007
     1008                        if ( $query_args ) {
     1009                                $query_args = array_diff_key(
     1010                                        $query_args,
     1011                                        array_fill_keys(
     1012                                                array( $action_key, $action_variables_key ),
     1013                                                true
     1014                                        )
     1015                                );
     1016                        }
     1017                } elseif ( isset( $query_args['bp_member_action'] ) && 'members' === $component_id ) {
     1018                        unset( $query_args['bp_member_action'] );
     1019                } elseif( isset( $query_args['bp_group_action'] ) && 'groups' === $component_id ) {
     1020                        unset( $query_args['bp_group_action'] );
     1021                }
     1022
     1023                if ( $path_chunks ) {
     1024                        if ( 'groups' === $component_id ) {
     1025                                $bp->canonical_stack['canonical_url'] = bp_get_group_url(
     1026                                        groups_get_current_group(),
     1027                                        bp_groups_get_path_chunks( $path_chunks )
     1028                                );
     1029                        } else {
     1030                                $bp->canonical_stack['canonical_url'] = bp_displayed_user_url( bp_members_get_path_chunks( $path_chunks ) );
     1031                        }
     1032                } else {
     1033                        $bp->canonical_stack['canonical_url'] = $base_url;
     1034                }
    9561035        }
    9571036
    9581037        $canonical_url = $bp->canonical_stack['canonical_url'];
    9591038
    960         if ( !$include_query_args ) {
    961                 $canonical_url = array_reverse( explode( '?', $canonical_url ) );
    962                 $canonical_url = array_pop( $canonical_url );
     1039        if ( $r['include_query_args'] && $query_args ) {
     1040                $canonical_url = add_query_arg( $query_args, $canonical_url );
    9631041        }
    9641042
    … …  
    10141092                remove_action( 'template_redirect', 'redirect_canonical' );
    10151093}
    1016 add_action( 'bp_init', '_bp_maybe_remove_redirect_canonical' );
    10171094
    10181095/**
  • 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
  • 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.
  • trunk/src/bp-core/bp-core-template-loader.php

    r13455 r13461  
    579579
    580580/**
     581 * Parse the query for the Ajax context.
     582 *
     583 * @since 12.0.0
     584 *
     585 * @param WP_Query $referer_query WP_Query object.
     586 */
     587function bp_parse_ajax_referer_query( $referer_query ) {
     588        if ( ! wp_doing_ajax() || 'rewrites' !== bp_core_get_query_parser() ) {
     589                return;
     590        }
     591
     592        /**
     593         * Fires at the end of the bp_parse_ajax_referer_query function.
     594         *
     595         * Allow BuddyPress components to parse the ajax referer query.
     596         *
     597         * @since 12.0.0
     598         *
     599         * @param WP_Query $posts_query WP_Query instance. Passed by reference.
     600         */
     601        do_action_ref_array( 'bp_parse_query', array( &$referer_query ) );
     602}
     603
     604/**
    581605 * Resets the query to fit our permalink structure if needed.
    582606 *
    … …  
    601625        }
    602626
    603         // Temporarly override the request uri.
    604         if ( isset( $wp->request ) ) {
     627        // Use the BP Rewrites API to parse the ajax referer request.
     628        if ( wp_doing_ajax() ) {
     629                if ( ! bp_has_pretty_urls() ) {
     630                        $matched_query = wp_parse_url( $bp_request, PHP_URL_QUERY );
     631                } else {
     632                        // Temporarly override the request uri.
     633                        $_SERVER['REQUEST_URI'] = $bp_request;
     634
     635                        $wp_ajax = new WP();
     636                        $wp_ajax->parse_request();
     637
     638                        // Extra step to check for root profiles.
     639                        $member = bp_rewrites_get_member_data( $wp_ajax->request );
     640                        if ( isset( $member['object'] ) && $member['object'] ) {
     641                                $_SERVER['REQUEST_URI'] = trailingslashit( $bp->members->root_slug ) . $wp_ajax->request;
     642
     643                                // Reparse the request.
     644                                $wp_ajax->parse_request();
     645                        }
     646
     647                        $matched_query = $wp_ajax->matched_query;
     648                }
     649
     650                // Use a specific function to fire the `bp_parse_query` hook.
     651                add_action( 'parse_query', 'bp_parse_ajax_referer_query', 2 );
     652
     653                // Parse the matched query.
     654                $query->parse_query( $matched_query );
     655
     656                // Use to requery in case of root profiles.
     657        } elseif ( isset( $wp->request ) ) {
     658                // Temporarly override the request uri.
    605659                $_SERVER['REQUEST_URI'] = str_replace( $wp->request, $bp_request, $reset_server_request_uri );
    606660
  • trunk/src/bp-core/classes/class-bp-component.php

    r13455 r13461  
    578578
    579579                // Allow components to parse the main query.
    580                 if ( ! bp_has_pretty_urls() ) {
     580                if ( 'rewrites' === bp_core_get_query_parser() ) {
    581581                        /**
    582582                         * Only fire this hook when pretty links are disabled.
    … …  
    12731273                        // Only include the queried directory post into returned posts.
    12741274                        $retval = array( $queried_object );
     1275
     1276                        // Reset some query flags.
     1277                        $query->is_home       = false;
     1278                        $query->is_front_page = false;
     1279                        $query->is_page       = false;
     1280                        $query->is_single     = true;
     1281                        $query->is_archive    = false;
     1282                        $query->is_tax        = false;
    12751283                }
    12761284
  • trunk/src/bp-members/classes/class-bp-members-component.php

    r13455 r13461  
    235235                $bp->loggedin_user->domain = bp_members_get_user_url( bp_loggedin_user_id() );
    236236
    237                 /** Displayed user ***************************************************
     237                /**
     238                 * Set the Displayed user for the classic BuddyPress. This should only be the case when the
     239                 * legacy parser is on. When BP Rewrites are on, the displayed user is set in
     240                 * `BP_Members_Component::parse_query()`.
    238241                 */
    239 
    240                 // The core userdata of the user who is currently being displayed.
    241                 $bp->displayed_user->userdata = bp_core_get_core_userdata( bp_displayed_user_id() );
    242 
    243                 // Fetch the full name displayed user.
    244                 $bp->displayed_user->fullname = isset( $bp->displayed_user->userdata->display_name ) ? $bp->displayed_user->userdata->display_name : '';
    245 
    246                 // The domain for the user currently being displayed.
    247                 $bp->displayed_user->domain = bp_members_get_user_url( bp_displayed_user_id() );
    248 
    249                 // If A user is displayed, check if there is a front template
    250                 if ( bp_get_displayed_user() ) {
    251                         $bp->displayed_user->front_template = bp_displayed_user_get_front_template();
     242                if ( bp_displayed_user_id() ) {
     243                        // The core userdata of the user who is currently being displayed.
     244                        $bp->displayed_user->userdata = bp_core_get_core_userdata( bp_displayed_user_id() );
     245
     246                        // Fetch the full name displayed user.
     247                        $bp->displayed_user->fullname = isset( $bp->displayed_user->userdata->display_name ) ? $bp->displayed_user->userdata->display_name : '';
     248
     249                        // The domain for the user currently being displayed.
     250                        $bp->displayed_user->domain = bp_members_get_user_url( bp_displayed_user_id() );
     251
     252                        // If A user is displayed, check if there is a front template
     253                        if ( bp_get_displayed_user() ) {
     254                                $bp->displayed_user->front_template = bp_displayed_user_get_front_template();
     255                        }
    252256                }
    253257
    … …  
    394398                        }
    395399
    396                         if ( !empty( $bp->action_variables ) ) {
     400                        if ( ! empty( $bp->action_variables ) ) {
    397401                                $bp->canonical_stack['action_variables'] = bp_action_variables();
    398402                        }
    … …  
    855859                                }
    856860
    857                                 // If A user is displayed, check if there is a front template.
     861                                // If a user is displayed, check if there is a front template and reset navigation.
    858862                                if ( bp_get_displayed_user() ) {
    859863                                        $bp->displayed_user->front_template = bp_displayed_user_get_front_template();
     864
     865                                        // Reset the nav for the members component.
     866                                        $this->nav = new BP_Core_Nav();
    860867                                }
    861868
  • trunk/src/bp-templates/bp-legacy/buddypress-functions.php

    r13449 r13461  
    185185                 */
    186186                foreach( $actions as $name => $function ) {
     187                        bp_ajax_register_action( $name );
    187188                        add_action( 'wp_ajax_'        . $name, $function );
    188189                        add_action( 'wp_ajax_nopriv_' . $name, $function );
  • trunk/src/bp-templates/bp-nouveau/buddypress-functions.php

    r13372 r13461  
    55 * @since 3.0.0
    66 * @package BuddyPress
    7  * @version 10.0.0
     7 * @version 12.0.0
    88 *
    99 * @buddypress-template-pack {
    … …  
    177177                add_action( 'bp_actions', array( $this, 'neutralize_core_template_notices' ), 6 );
    178178
    179                 // Scripts & Styles.
    180                 $registration_params = array(
    181                         'hook'     => 'bp_enqueue_community_scripts',
    182                         'priority' => 2,
    183                 );
    184 
    185                 /*
    186                  * The WordPress Full Site Editing feature needs Scripts
    187                  * and Styles to be registered earlier.
    188                  */
    189                 if ( current_theme_supports( 'block-templates' ) ) {
    190                         $registration_params['hook']     = 'bp_init';
    191                         $registration_params['priority'] = 20;
    192                 }
    193 
    194                 // Register theme JS.
    195                 add_action( $registration_params['hook'], array( $this, 'register_scripts' ), $registration_params['priority'] );
     179                // Register scripts & styles.
     180                add_action( 'bp_enqueue_community_scripts', array( $this, 'register_scripts' ), 2 );
    196181
    197182                // Enqueue theme CSS.
  • trunk/src/bp-templates/bp-nouveau/includes/activity/functions.php

    r13442 r13461  
    569569}
    570570add_filter( 'bp_activity_excerpt_append_text', 'bp_nouveau_activity_excerpt_append_text', 10, 1 );
     571
     572/**
     573 * Register Activity Ajax actions.
     574 *
     575 * @since 12.0.0
     576 */
     577function bp_nouveau_register_activity_ajax_actions() {
     578        $ajax_actions = array( 'activity_filter', 'get_single_activity_content', 'activity_mark_fav', 'activity_mark_unfav', 'activity_clear_new_mentions', 'delete_activity', 'new_activity_comment', 'bp_nouveau_get_activity_objects', 'post_update', 'bp_spam_activity' );
     579
     580        foreach ( $ajax_actions as $ajax_action ) {
     581                bp_ajax_register_action( $ajax_action );
     582        }
     583}
  • trunk/src/bp-templates/bp-nouveau/includes/activity/loader.php

    r13414 r13461  
    44 *
    55 * @since 3.0.0
    6  * @version 8.0.0
     6 * @version 12.0.0
    77 */
    88
    … …  
    9191         */
    9292        protected function setup_actions() {
     93                add_action( 'bp_init', 'bp_nouveau_register_activity_ajax_actions' );
    9394                add_action( 'bp_nouveau_enqueue_scripts', 'bp_nouveau_activity_enqueue_scripts' );
    9495                add_action( 'bp_nouveau_notifications_init_filters', 'bp_nouveau_activity_notification_filters' );
  • trunk/src/bp-templates/bp-nouveau/includes/blogs/functions.php

    r13442 r13461  
    44 *
    55 * @since 3.0.0
    6  * @version 3.1.0
     6 * @version 12.0.0
    77 */
    88
    … …  
    226226}
    227227add_filter( 'bp_get_blog_class', 'bp_nouveau_blog_loop_item_has_lastest_post' );
     228
     229/**
     230 * Register Blogs Ajax actions.
     231 *
     232 * @since 12.0.0
     233 */
     234function bp_nouveau_register_blogs_ajax_actions() {
     235        bp_ajax_register_action( 'blogs_filter' );
     236}
  • trunk/src/bp-templates/bp-nouveau/includes/blogs/loader.php

    r13414 r13461  
    44 *
    55 * @since 3.0.0
    6  * @version 6.1.0
     6 * @version 12.0.0
    77 */
    88
    … …  
    6767         */
    6868        protected function setup_actions() {
     69                add_action( 'bp_init', 'bp_nouveau_register_blogs_ajax_actions' );
     70
    6971                if ( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
    7072                        // Avoid Notices for BuddyPress Legacy Backcompat
  • trunk/src/bp-templates/bp-nouveau/includes/friends/loader.php

    r13414 r13461  
    44 *
    55 * @since 3.0.0
    6  * @version 6.1.0
     6 * @version 12.0.0
    77 */
    88
    … …  
    6969                // Register the friends Notifications filters
    7070                add_action( 'bp_nouveau_notifications_init_filters', array( $this, 'notification_filters' ) );
     71
     72                add_action( 'bp_init', array( $this, 'register_ajax_actions' ) );
    7173        }
    7274
    … …  
    118120                }
    119121        }
     122
     123        /**
     124         * Register Friends Ajax actions.
     125         *
     126         * @since 12.0.0
     127         */
     128        public function register_ajax_actions() {
     129                $ajax_actions = array( 'friends_remove_friend', 'friends_add_friend', 'friends_withdraw_friendship', 'friends_accept_friendship', 'friends_reject_friendship' );
     130
     131                foreach ( $ajax_actions as $ajax_action ) {
     132                        bp_ajax_register_action( $ajax_action );
     133                }
     134        }
    120135}
    121136
  • trunk/src/bp-templates/bp-nouveau/includes/groups/functions.php

    r13449 r13461  
    12851285}
    12861286add_filter( 'bp_rest_group_invites_get_items_permissions_check', 'bp_nouveau_rest_group_invites_get_items_permissions_check', 10, 2 );
     1287
     1288/**
     1289 * Register Groups Ajax actions.
     1290 *
     1291 * @since 12.0.0
     1292 */
     1293function bp_nouveau_register_groups_ajax_actions() {
     1294        $ajax_actions = array( 'groups_filter', 'groups_join_group', 'groups_leave_group', 'groups_accept_invite', 'groups_reject_invite', 'groups_request_membership', 'groups_get_group_potential_invites', 'groups_send_group_invites', 'groups_delete_group_invite' );
     1295
     1296        foreach ( $ajax_actions as $ajax_action ) {
     1297                bp_ajax_register_action( $ajax_action );
     1298        }
     1299}
  • trunk/src/bp-templates/bp-nouveau/includes/groups/loader.php

    r13414 r13461  
    44 *
    55 * @since 3.0.0
    6  * @version 6.1.0
     6 * @version 12.0.0
    77 */
    88
    … …  
    6969         */
    7070        protected function setup_actions() {
     71                add_action( 'bp_init', 'bp_nouveau_register_groups_ajax_actions' );
     72
    7173                if ( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
    7274                        add_action( 'groups_setup_nav', 'bp_nouveau_group_setup_nav' );
  • trunk/src/bp-templates/bp-nouveau/includes/members/loader.php

    r13414 r13461  
    6666                foreach ( $ajax_actions as $ajax_action ) {
    6767                        $action = key( $ajax_action );
     68
     69                        bp_ajax_register_action( $action );
    6870
    6971                        add_action( 'wp_ajax_' . $action, $ajax_action[ $action ]['function'] );
  • trunk/src/bp-templates/bp-nouveau/includes/messages/functions.php

    r13442 r13461  
    44 *
    55 * @since 3.0.0
    6  * @version 10.3.0
     6 * @version 12.0.0
    77 */
    88
    … …  
    513513        return $content;
    514514}
     515
     516/**
     517 * Register Messages Ajax actions.
     518 *
     519 * @since 12.0.0
     520 */
     521function bp_nouveau_register_messages_ajax_actions() {
     522        $ajax_actions = array( 'messages_send_message', 'messages_send_reply', 'messages_get_user_message_threads', 'messages_thread_read', 'messages_get_thread_messages', 'messages_delete', 'messages_exit', 'messages_unstar', 'messages_star', 'messages_unread', 'messages_read', 'messages_dismiss_sitewide_notice' );
     523
     524        foreach ( $ajax_actions as $ajax_action ) {
     525                bp_ajax_register_action( $ajax_action );
     526        }
     527}
  • trunk/src/bp-templates/bp-nouveau/includes/messages/loader.php

    r13414 r13461  
    44 *
    55 * @since 3.0.0
    6  * @version 10.0.0
     6 * @version 12.0.0
    77 */
    88
    … …  
    6767         */
    6868        protected function setup_actions() {
     69                add_action( 'bp_init', 'bp_nouveau_register_messages_ajax_actions' );
     70
    6971                // Notices
    7072                add_action( 'widgets_init', 'bp_nouveau_unregister_notices_widget' );
    71                 add_action( 'bp_init', 'bp_nouveau_push_sitewide_notices', 99 );
     73
     74                $hook = 'bp_parse_query';
     75                if ( 'rewrites' !== bp_core_get_query_parser() ) {
     76                        $hook = 'bp_init';
     77                }
     78
     79                add_action( $hook, 'bp_nouveau_push_sitewide_notices', 99 );
    7280
    7381                // Messages
  • trunk/src/bp-templates/bp-nouveau/includes/notifications/loader.php

    r13414 r13461  
    5656         */
    5757        protected function setup_actions() {
    58                 add_action( 'bp_init', 'bp_nouveau_notifications_init_filters', 20 );
     58                $hook = 'bp_parse_query';
     59                if ( 'rewrites' !== bp_core_get_query_parser() ) {
     60                        $hook = 'bp_init';
     61                }
     62
     63                add_action( $hook, 'bp_nouveau_notifications_init_filters', 20 );
    5964                add_action( 'bp_nouveau_enqueue_scripts', 'bp_nouveau_notifications_enqueue_scripts' );
    6065
  • trunk/src/class-buddypress.php

    r13435 r13461  
    200200         */
    201201        public $profile;
     202
     203        /**
     204         * BuddyPress Ajax actions.
     205         *
     206         * @since 12.0.0
     207         *
     208         * @var array The list of registered Ajax actions.
     209         */
     210        public $ajax_actions = array();
    202211
    203212        /** Option Overload *******************************************************/
  • trunk/tests/phpunit/testcases/routing/core.php

    r13314 r13461  
    66class BP_Tests_Routing_Core extends BP_UnitTestCase {
    77        protected $old_current_user = 0;
     8        protected $permalink_structure = '';
    89
    910        public function set_up() {
    … …  
    1213                $this->old_current_user = get_current_user_id();
    1314                $this->set_current_user( self::factory()->user->create( array( 'role' => 'subscriber' ) ) );
     15                $this->permalink_structure = get_option( 'permalink_structure', '' );
    1416        }
    1517
    … …  
    1719                parent::tear_down();
    1820                $this->set_current_user( $this->old_current_user );
     21                $this->set_permalink_structure( $this->permalink_structure );
    1922        }
    2023        function test_wordpress_page() {
     24                $this->set_permalink_structure( '/%postname%/' );
    2125                $this->go_to( '/' );
    2226                $this->assertEmpty( bp_current_component() );
    … …  
    2731         */
    2832        function test_nav_menu() {
     33                $this->set_permalink_structure( '/%postname%/' );
    2934                $this->go_to( '/' );
    3035                $this->assertTrue( isset( buddypress()->bp_nav['activity'] ) );
  • trunk/tests/phpunit/testcases/routing/root-profiles.php

    r13431 r13461  
    88        protected $old_current_user = 0;
    99        protected $u;
     10        protected $permalink_structure = '';
    1011
    1112        public function set_up() {
    … …  
    2122                $this->u = new WP_User( $uid );
    2223                $this->set_current_user( $uid );
     24                $this->permalink_structure = get_option( 'permalink_structure', '' );
    2325        }
    2426
    … …  
    2628                parent::tear_down();
    2729                $this->set_current_user( $this->old_current_user );
     30                $this->set_permalink_structure( $this->permalink_structure );
    2831                remove_filter( 'bp_core_enable_root_profiles', '__return_true' );
    2932        }
    3033
    3134        public function test_members_directory() {
     35                $this->set_permalink_structure( '/%postname%/' );
    3236                $this->go_to( home_url( bp_get_members_root_slug() ) );
    3337
    … …  
    3943
    4044        public function test_member_permalink() {
     45                $this->set_permalink_structure( '/%postname%/' );
    4146                $domain = home_url( $this->u->user_nicename );
    4247                $this->go_to( $domain );
    … …  
    5156         */
    5257        public function test_member_permalink_when_members_page_is_nested_under_wp_page() {
     58                $this->set_permalink_structure( '/%postname%/' );
    5359                $p = self::factory()->post->create( array(
    5460                        'post_type' => 'page',
    … …  
    7177
    7278        public function test_member_activity_page() {
     79                $this->set_permalink_structure( '/%postname%/' );
    7380                $url = home_url( $this->u->user_nicename ) . '/' . bp_get_activity_slug();
    7481                $this->go_to( $url );
Note: See TracChangeset for help on using the changeset viewer.