Skip to:
Content

BuddyPress.org

Changeset 13514


Ignore:
Timestamp:
07/12/2023 03:38:26 AM (14 months ago)
Author:
imath
Message:

Improve automatic third party component directory page association

  1. the buddypress()->loaded_components array uses component slug as keys (not the component ID). Avoid potential problems when a component slug is very different than the component ID by looping into this array the right way when looking for components requiring a page association.
  2. Make sure to use the component $root_slug and $directory_title when automatically creating a buddypress post type for orphaned components.
  3. Improve the user feedback once 2. is achieved by informing they may need to refresh the site permalink settings.

Fixes #8918
Closes https://github.com/buddypress/buddypress/pull/127

Location:
trunk/src/bp-core
Files:
2 edited

Legend:

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

    r13502 r13514  
    260260
    261261    // Only components with 'has_directory' require a WP page to function.
    262     foreach ( array_keys( $bp->loaded_components ) as $component_id ) {
     262    foreach ( $bp->loaded_components as $component_slug => $component_id ) {
    263263        if ( ! empty( $bp->{$component_id}->has_directory ) ) {
    264264            $wp_page_components[] = array(
     
    291291    foreach ( $wp_page_components as $component ) {
    292292        if ( ! isset( $bp->pages->{$component['id']} ) ) {
    293             $orphaned_components[ $component['id'] ] = $component['name'];
     293            $component_props = $component;
     294            if ( isset( $bp->{$component['id']}->directory_title ) ) {
     295                $component_props['title'] = $bp->{$component['id']}->directory_title;
     296            } else {
     297                $component_props['title'] = $component_props['name'];
     298            }
     299
     300            if ( isset( $bp->{$component['id']}->root_slug ) ) {
     301                $component_props['name'] = $bp->{$component['id']}->root_slug;
     302            }
     303
     304            $orphaned_components[ $component['id'] ] = $component_props;
    294305        }
    295306    }
     
    300311            // Translators: %s is the comma separated list of components needing a directory page.
    301312            __( 'The following active BuddyPress Components do not have associated BuddyPress Pages: %s.', 'buddypress' ),
    302             '<strong>' . implode( '</strong>, <strong>', array_map( 'esc_html', $orphaned_components ) ) . '</strong>'
     313            '<strong>' . implode( '</strong>, <strong>', array_map( 'esc_html', wp_list_pluck( $orphaned_components, 'title' ) ) ) . '</strong>'
    303314        );
    304315
     
    310321            $notice      = sprintf(
    311322                // Translators: %s is the comma separated list of components needing a directory page.
    312                 __( 'A BuddyPress page has been added for the following active BuddyPress Components which did not have associated BuddyPress Pages yet: %s.', 'buddypress' ),
    313                 '<strong>' . implode( '</strong>, <strong>', array_map( 'esc_html', $orphaned_components ) ) . '</strong>'
     323                __( 'A BuddyPress page has been added for the following active BuddyPress Components which did not have associated BuddyPress Pages yet: %s. You may need to refresh your permalink settings.', 'buddypress' ),
     324                '<strong>' . implode( '</strong>, <strong>', array_map( 'esc_html', wp_list_pluck( $orphaned_components, 'title' ) ) ) . '</strong>'
    314325            );
    315326        }
  • trunk/src/bp-core/bp-core-functions.php

    r13503 r13514  
    851851    $page_titles = bp_core_get_directory_page_default_titles();
    852852    if ( $return_pages ) {
     853        $components_title = wp_list_pluck( $components, 'title' );
     854        if ( ! $components_title ) {
     855            $components_title = $components;
     856        }
     857
    853858        // In this case the `$components` array uses Page titles as values.
    854         $page_titles = bp_parse_args( $page_titles, $components );
     859        $page_titles = bp_parse_args( $page_titles, $components_title );
    855860    }
    856861
     
    883888
    884889    // Create the pages.
    885     foreach ( $pages_to_create as $component_name => $page_name ) {
     890    foreach ( $pages_to_create as $component_name => $page_title ) {
    886891        $existing_id = bp_core_get_directory_page_id( $component_name );
    887892
     
    890895            $pages[ $component_name ] = (int) $existing_id;
    891896        } else {
    892             $pages[ $component_name ] = wp_insert_post( array(
     897            $postarr = array(
    893898                'comment_status' => 'closed',
    894899                'ping_status'    => 'closed',
    895900                'post_status'    => 'publish',
    896                 'post_title'     => $page_name,
     901                'post_title'     => $page_title,
    897902                'post_type'      => bp_core_get_directory_post_type(),
    898             ) );
     903            );
     904
     905            if ( isset( $components[ $component_name ]['name'] ) ) {
     906                $postarr['post_name'] = $components[ $component_name ]['name'];
     907            }
     908
     909            $pages[ $component_name ] = wp_insert_post( $postarr );
    899910        }
    900911    }
Note: See TracChangeset for help on using the changeset viewer.