Skip to:
Content

BuddyPress.org

Changeset 13471


Ignore:
Timestamp:
05/07/2023 11:36:50 AM (13 months ago)
Author:
imath
Message:

BP Rewrites merge process, final touches

This commit is closing the main ticket about migrating our Legacy URL parser to using the WP Rewrite API. Please open next possible issues in new tickets.

The final touches:

  • Make sure BP Activity Embeds are fully supported when using the BP Rewrites API.
  • Make sure BuddyPress directories are fetched into the Site Editor's Navigation block.
  • Deprecate bp_admin_display_directory_states() and move the BP Page directory states feature into the BP Classic backcompat plugin.
  • Remove the Page settings Admin help tab & move it into BP Classic
  • Introduce the bp_core_include_directory_on_front() in order to maintain the possibility to use a BP Directory page as the site's home page.

Props r-a-y, johnjamesjacoby, boonebgorges

Closes https://github.com/buddypress/buddypress/pull/95
Fixes #4954

Location:
trunk/src
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/bp-activity-embeds.php

    r12757 r13471  
    348348    do_action( 'bp_activity_embed_after_media' );
    349349}
     350
     351/**
     352 * Make sure the Activity embed template will be used if neded.
     353 *
     354 * @since 12.0.0
     355 *
     356 * @param WP_Query $query Required.
     357 */
     358function bp_activity_parse_embed_query( $query ) {
     359    if ( bp_is_single_activity() && $query->get( 'embed' ) ) {
     360        $query->is_embed = true;
     361    }
     362}
     363add_action( 'bp_members_parse_query', 'bp_activity_parse_embed_query', 10, 1 );
  • trunk/src/bp-activity/classes/class-bp-activity-component.php

    r13464 r13471  
    578578        parent::blocks_init( $blocks );
    579579    }
    580 
    581     /**
    582      * Add the Activity directory state.
    583      *
    584      * @since 10.0.0
    585      *
    586      * @param array   $states Optional. See BP_Component::admin_directory_states() for description.
    587      * @param WP_Post $post   Optional. See BP_Component::admin_directory_states() for description.
    588      * @return array          See BP_Component::admin_directory_states() for description.
    589      */
    590     public function admin_directory_states( $states = array(), $post = null ) {
    591         $bp = buddypress();
    592 
    593         if ( isset( $bp->pages->activity->id ) && (int) $bp->pages->activity->id === (int) $post->ID ) {
    594             $states['page_for_activity_directory'] = _x( 'BP Activity Page', 'page label', 'buddypress' );
    595         }
    596 
    597         return parent::admin_directory_states( $states, $post );
    598     }
    599580}
  • trunk/src/bp-blogs/classes/class-bp-blogs-component.php

    r13464 r13471  
    528528        parent::blocks_init( $blocks );
    529529    }
    530 
    531     /**
    532      * Add the Sites directory states.
    533      *
    534      * @since 10.0.0
    535      *
    536      * @param array   $states Optional. See BP_Component::admin_directory_states() for description.
    537      * @param WP_Post $post   Optional. See BP_Component::admin_directory_states() for description.
    538      * @return array          See BP_Component::admin_directory_states() for description.
    539      */
    540     public function admin_directory_states( $states = array(), $post = null ) {
    541         $bp = buddypress();
    542 
    543         if ( isset( $bp->pages->blogs->id ) && (int) $bp->pages->blogs->id === (int) $post->ID ) {
    544             $states['page_for_sites_directory'] = _x( 'BP Sites Page', 'page label', 'buddypress' );
    545         }
    546 
    547         return parent::admin_directory_states( $states, $post );
    548     }
    549530}
  • trunk/src/bp-core/admin/bp-core-admin-actions.php

    r13461 r13471  
    6161add_action( 'bp_admin_menu', 'bp_admin_separator' );
    6262
    63 // Add a filter to include BP Components directory pages display states.
    64 add_filter( 'display_post_states', 'bp_admin_display_directory_states', 10, 2 );
    65 
    6663/**
    6764 * When a new site is created in a multisite installation, run the activation
     
    239236    do_action( 'bp_register_admin_settings' );
    240237}
    241 
    242 /**
    243  * Dedicated filter to inform about BP components directory page states.
    244  *
    245  * @since 10.0.0
    246  *
    247  * @param string[] $post_states An array of post display states.
    248  * @param WP_Post  $post        The current post object.
    249  */
    250 function bp_admin_display_directory_states( $post_states = array(), $post = null ) {
    251     /**
    252      * Filter here to add BP Directory pages.
    253      *
    254      * Used internaly by BP_Component->admin_directory_states(). Please use the dynamic
    255      * filter in BP_Component->admin_directory_states() to edit the directory state
    256      * according to the component's ID.
    257      *
    258      * @since 10.0.0
    259      *
    260      * @param array    $value An empty array.
    261      * @param WP_Post  $post  The current post object.
    262      */
    263     $directory_page_states = apply_filters( 'bp_admin_display_directory_states', array(), $post );
    264 
    265     if ( $directory_page_states ) {
    266         $post_states = array_merge( $post_states, $directory_page_states );
    267     }
    268 
    269     return $post_states;
    270 }
  • trunk/src/bp-core/admin/bp-core-admin-functions.php

    r13469 r13471  
    670670            break;
    671671
    672         // Pages page.
    673         case 'settings_page_bp-page-settings':
    674             // Help tabs.
    675             $screen->add_help_tab(
    676                 array(
    677                     'id'      => 'bp-page-overview',
    678                     'title'   => __( 'Overview', 'buddypress' ),
    679                     'content' => bp_core_add_contextual_help_content( 'bp-page-overview' ),
    680                 )
    681             );
    682 
    683             // Help panel - sidebar links.
    684             $screen->set_help_sidebar(
    685                 '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' .
    686                 '<p>' . __( '<a href="https://codex.buddypress.org/getting-started/configure-components/#settings-buddypress-pages">Managing Pages</a>', 'buddypress' ) . '</p>' .
    687                 '<p>' . __( '<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>'
    688             );
    689 
    690             break;
    691 
    692672        // Settings page.
    693673        case 'settings_page_bp-settings':
     
    732712}
    733713add_action( 'load-settings_page_bp-components', 'bp_core_add_contextual_help' );
    734 add_action( 'load-settings_page_bp-page-settings', 'bp_core_add_contextual_help' );
    735714add_action( 'load-settings_page_bp-settings', 'bp_core_add_contextual_help' );
    736715add_action( 'load-users_page_bp-profile-setup', 'bp_core_add_contextual_help' );
     
    749728        case 'bp-comp-overview':
    750729            $retval = __( 'By default, all but four of the BuddyPress components are enabled. You can selectively enable or disable any of the components by using the form below. Your BuddyPress installation will continue to function. However, the features of the disabled components will no longer be accessible to anyone using the site.', 'buddypress' );
    751             break;
    752 
    753         case 'bp-page-overview':
    754             $retval = __( 'BuddyPress Components use WordPress Pages for their root directory/archive pages. You can change the page associations for each active component by using the form below.', 'buddypress' );
    755730            break;
    756731
     
    14931468 *
    14941469 * @since 8.0.0
     1470 * @since 12.0.0 This category is left for third party plugin but not used anymmore.
     1471 *
     1472 * @todo deprecate.
    14951473 */
    14961474function bp_block_init_category_filter() {
  • trunk/src/bp-core/bp-core-catchuri.php

    r13468 r13471  
    130130        $wp_query->is_singular = true;
    131131        $wp_query->is_404      = false;
     132
     133        // Check if a BuddyPress component's direcory is set as homepage.
     134        $wp_query->is_home = bp_is_directory_homepage( bp_current_component() );
    132135
    133136        /**
     
    172175            $wp_query->is_singular = true;
    173176            $wp_query->is_404      = false;
     177
     178            // Check if a BuddyPress component's direcory is set as homepage.
     179            $wp_query->is_home = bp_is_directory_homepage( bp_current_component() );
    174180        }
    175181
  • trunk/src/bp-core/bp-core-filters.php

    r13436 r13471  
    948948
    949949/**
     950 * Eventually append BuddyPress directories to WP Dropdown's pages control.
     951 *
     952 * @since 12.0.0
     953 *
     954 * @param WP_Post[] $pages Array of page objects.
     955 * @param array     $args  Array of get_pages() arguments.
     956 * @return WP_Post[]       Array of page objects, potentially including BP directories.
     957 */
     958function bp_core_include_directory_on_front( $pages = array(), $args = array() ) {
     959    $is_page_on_front_dropdown = false;
     960
     961    if ( isset( $args['name'] ) ) {
     962        $is_page_on_front_dropdown = 'page_on_front' === $args['name'];
     963
     964        if ( is_customize_preview() ) {
     965            $is_page_on_front_dropdown = '_customize-dropdown-pages-page_on_front' === $args['name'];
     966        }
     967    }
     968
     969    if ( $is_page_on_front_dropdown ) {
     970        $directories = bp_core_get_directory_pages();
     971        $null        = '0000-00-00 00:00:00';
     972
     973        foreach ( (array) $directories as $component => $directory ) {
     974            if ( 'activate' === $component || 'register' === $component ) {
     975                continue;
     976            }
     977
     978            $post = (object) array(
     979                'ID'                    => $directory->id,
     980                'post_author'           => 0,
     981                'post_date'             => $null,
     982                'post_date_gmt'         => $null,
     983                'post_content'          => '',
     984                'post_title'            => $directory->title,
     985                'post_excerpt'          => '',
     986                'post_status'           => 'publish',
     987                'comment_status'        => 'closed',
     988                'ping_status'           => 'closed',
     989                'post_password'         => '',
     990                'post_name'             => $directory->slug,
     991                'pinged'                => '',
     992                'to_ping'               => '',
     993                'post_modified'         => $null,
     994                'post_modified_gmt'     => $null,
     995                'post_content_filtered' => '',
     996                'post_parent'           => 0,
     997                'guid'                  => bp_rewrites_get_url(
     998                    array(
     999                        'component_id' => $component,
     1000                    )
     1001                ),
     1002                'menu_order'            => 0,
     1003                'post_type'             => 'buddypress',
     1004                'post_mime_type'        => '',
     1005                'comment_count'         => 0,
     1006                'filter'                => 'raw',
     1007            );
     1008
     1009            $pages[] = get_post( $post );
     1010        }
     1011
     1012        $pages = bp_alpha_sort_by_key( $pages, 'post_title' );
     1013    }
     1014
     1015    return $pages;
     1016}
     1017add_filter( 'get_pages', 'bp_core_include_directory_on_front', 10, 2 );
     1018
     1019/**
    9501020 * Filter SQL query strings to swap out the 'meta_id' column.
    9511021 *
     
    13361406}
    13371407add_filter( 'subdirectory_reserved_names', 'bp_core_components_subdirectory_reserved_names' );
     1408
     1409/**
     1410 * Make sure `buddypress` post type links are built using BP Rewrites.
     1411 *
     1412 * @since 12.0.0
     1413 *
     1414 * @param string       $link The post type link.
     1415 * @param WP_Post|null $post The post type object.
     1416 * @return string            The post type link.
     1417 */
     1418function bp_get_post_type_link( $link = '', $post = null ) {
     1419    if (  'rewrites' === bp_core_get_query_parser() && 'buddypress' === get_post_type( $post ) ) {
     1420        $bp_pages = (array) buddypress()->pages;
     1421
     1422        $bp_current_page = wp_list_filter( $bp_pages, array( 'id' => $post->ID ) );
     1423        if ( $bp_current_page ) {
     1424            $args = array(
     1425                'component_id' => key( $bp_current_page ),
     1426            );
     1427
     1428            if ( 'register' === $args['component_id'] || 'activate' === $args['component_id'] ) {
     1429                $key_action           = 'member_' . $args['component_id'];
     1430                $args['component_id'] = 'members';
     1431                $args[ $key_action ]  = 1;
     1432            }
     1433
     1434            $link = bp_rewrites_get_url( $args );
     1435        }
     1436    }
     1437
     1438    return $link;
     1439}
     1440add_filter( 'post_type_link', 'bp_get_post_type_link', 10, 2 );
  • trunk/src/bp-core/classes/class-bp-component.php

    r13468 r13471  
    600600        }
    601601
    602         // Set directory page states.
    603         add_filter( 'bp_admin_display_directory_states', array( $this, 'admin_directory_states' ), 10, 2 );
    604 
    605602        /**
    606603         * Fires at the end of the setup_actions method inside BP_Component.
     
    12781275            $query->is_front_page = false;
    12791276            $query->is_page       = false;
    1280             $query->is_single     = true;
    12811277            $query->is_archive    = false;
    12821278            $query->is_tax        = false;
     1279
     1280            if ( ! is_embed() ) {
     1281                $query->is_single = true;
     1282            }
    12831283        }
    12841284
     
    13901390     *
    13911391     * @since 10.0.0
     1392     * @deprecated 12.0.0
    13921393     *
    13931394     * @param string[] $states An array of post display states.
     
    13961397     */
    13971398    public function admin_directory_states( $states = array(), $post = null ) {
    1398         if ( $this->has_directory ) {
    1399             /**
    1400              * Filter here to edit the component's directory states.
    1401              *
    1402              * This is a dynamic hook that is based on the component string ID.
    1403              *
    1404              * @since 10.0.0
    1405              *
    1406              * @param string[] $states An array of post display states.
    1407              * @param WP_Post  $post   The current post object.
    1408              */
    1409             return apply_filters( 'bp_' . $this->id . '_admin_directory_states', $states, $post );
    1410         }
    1411 
     1399        _deprecated_function( __METHOD__, '12.0.0' );
    14121400        return $states;
    14131401    }
  • trunk/src/bp-core/classes/class-bp-core.php

    r13464 r13471  
    348348                    ),
    349349                    'description'         => __( 'The BuddyPress Post Type used for component directories.', 'buddypress' ),
    350                     'public'              => false,
     350                    'public'              => true,
    351351                    'hierarchical'        => true,
    352352                    'exclude_from_search' => true,
     
    354354                    'show_ui'             => false,
    355355                    'show_in_nav_menus'   => true,
    356                     'show_in_rest'        => false,
     356                    'show_in_rest'        => true,
    357357                    'supports'            => array( 'title' ),
    358358                    'has_archive'         => false,
  • trunk/src/bp-core/deprecated/12.0.php

    r13468 r13471  
    626626    do_action_deprecated( 'bp_blogs_blog_tabs', array(), '12.0.0' );
    627627}
     628
     629/**
     630 * Dedicated filter to inform about BP components directory page states.
     631 *
     632 * @since 10.0.0
     633 * @deprecated 12.0.0
     634 *
     635 * @param string[] $post_states An array of post display states.
     636 * @param WP_Post  $post        The current post object.
     637 */
     638function bp_admin_display_directory_states( $post_states = array(), $post = null ) {
     639    $states = array();
     640
     641    /**
     642     * Filter here to add BP Directory pages.
     643     *
     644     * Used internaly by BP_Component->admin_directory_states(). Please use the dynamic
     645     * filter in BP_Component->admin_directory_states() to edit the directory state
     646     * according to the component's ID.
     647     *
     648     * @since 10.0.0
     649     * @deprecated 12.0.0
     650     *
     651     * @param array    $states An empty array.
     652     * @param WP_Post  $post   The current post object.
     653     */
     654    $directory_page_states = apply_filters_deprecated( 'bp_admin_display_directory_states', array( $states, $post ), '12.0.0' );
     655
     656    if ( $directory_page_states ) {
     657        $post_states = array_merge( $post_states, $directory_page_states );
     658    }
     659
     660    return $post_states;
     661}
  • trunk/src/bp-groups/classes/class-bp-groups-component.php

    r13468 r13471  
    12601260        );
    12611261    }
    1262 
    1263     /**
    1264      * Add the Groups directory states.
    1265      *
    1266      * @since 10.0.0
    1267      *
    1268      * @param array   $states Optional. See BP_Component::admin_directory_states() for description.
    1269      * @param WP_Post $post   Optional. See BP_Component::admin_directory_states() for description.
    1270      * @return array          See BP_Component::admin_directory_states() for description.
    1271      */
    1272     public function admin_directory_states( $states = array(), $post = null ) {
    1273         $bp = buddypress();
    1274 
    1275         if ( isset( $bp->pages->groups->id ) && (int) $bp->pages->groups->id === (int) $post->ID ) {
    1276             $states['page_for_groups_directory'] = _x( 'BP Groups Page', 'page label', 'buddypress' );
    1277         }
    1278 
    1279         return parent::admin_directory_states( $states, $post );
    1280     }
    12811262}
  • trunk/src/bp-members/classes/class-bp-members-component.php

    r13468 r13471  
    10301030        );
    10311031    }
    1032 
    1033     /**
    1034      * Add the Members directory states.
    1035      *
    1036      * @since 10.0.0
    1037      *
    1038      * @param array   $states Optional. See BP_Component::admin_directory_states() for description.
    1039      * @param WP_Post $post   Optional. See BP_Component::admin_directory_states() for description.
    1040      * @return array          See BP_Component::admin_directory_states() for description.
    1041      */
    1042     public function admin_directory_states( $states = array(), $post = null ) {
    1043         $bp = buddypress();
    1044 
    1045         if ( isset( $bp->pages->members->id ) && (int) $bp->pages->members->id === (int) $post->ID ) {
    1046             $states['page_for_members_directory'] = _x( 'BP Members Page', 'page label', 'buddypress' );
    1047         }
    1048 
    1049         if ( bp_get_signup_allowed() || bp_get_members_invitations_allowed() ) {
    1050             if ( isset( $bp->pages->register->id ) && (int) $bp->pages->register->id === (int) $post->ID ) {
    1051                 $states['page_for_bp_registration'] = _x( 'BP Registration Page', 'page label', 'buddypress' );
    1052             }
    1053 
    1054             if ( isset( $bp->pages->activate->id ) && (int) $bp->pages->activate->id === (int) $post->ID ) {
    1055                 $states['page_for_bp_activation'] = _x( 'BP Activation Page', 'page label', 'buddypress' );
    1056             }
    1057         }
    1058 
    1059         return parent::admin_directory_states( $states, $post );
    1060     }
    10611032}
  • trunk/src/bp-templates/bp-nouveau/includes/template-tags.php

    r13443 r13471  
    44 *
    55 * @since 3.0.0
    6  * @version 10.0.0
     6 * @version 12.0.0
    77 */
    88
     
    10371037
    10381038        if ( 'directory' === $bp_nouveau->displayed_nav ) {
    1039             $scope = array( 'data-bp-scope' => $nav_item->slug );
     1039            $scope = array(
     1040                'data-bp-scope' => $nav_item->slug
     1041            );
    10401042
    10411043        } elseif ( 'personal' === $bp_nouveau->displayed_nav && ! empty( $nav_item->secondary ) ) {
    1042             $scope = array( 'data-bp-user-scope' => $nav_item->slug );
     1044            $rewrite_id = bp_rewrites_get_custom_slug_rewrite_id( 'members', $nav_item->slug, bp_current_component() );
     1045            $user_scope = $nav_item->slug;
     1046
     1047            if ( $rewrite_id ) {
     1048                $user_scope = str_replace(
     1049                    array( 'bp_member_' . bp_current_component() . '_', '_' ),
     1050                    array( '', '-' ),
     1051                    $rewrite_id
     1052                );
     1053            }
     1054
     1055            $scope = array(
     1056                'data-bp-user-scope' => $nav_item->slug
     1057            );
    10431058
    10441059        } else {
  • trunk/src/bp-xprofile/bp-xprofile-functions.php

    r13395 r13471  
    757757    }
    758758}
    759 add_action( 'bp_setup_globals', 'xprofile_override_user_fullnames', 100 );
     759add_action( 'bp_parse_query', 'xprofile_override_user_fullnames', 100 );
    760760
    761761/**
Note: See TracChangeset for help on using the changeset viewer.