Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/12/2023 03:38:26 AM (3 years 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/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.