Skip to:
Content

BuddyPress.org


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

File:
1 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        }
Note: See TracChangeset for help on using the changeset viewer.