Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
05/07/2023 11:36:50 AM (15 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 );
Note: See TracChangeset for help on using the changeset viewer.