Skip to:
Content

BuddyPress.org

Changeset 13502


Ignore:
Timestamp:
06/13/2023 02:50:47 AM (14 months ago)
Author:
imath
Message:

buddypress post type dynamic creation for has_directory components

12.0 introduces a buddypress post type which is used to store the components directory pages into the database & replace the page post type that was used so far. It also replaced the Page association WP Admin screen with another WP Admin screen to customize all BP URLs.

In case a custom component is using a directory page and is not taking care of generating the corresponding buddypress post type entry, instead of asking for a page association in an admin notice, this entry is dynamically generated. If users are not happy with the title or slug of this entry, they can use the BP URLs settings tab to customize these afterwards.

Fixes #8918
See #4954
Closes https://github.com/buddypress/buddypress/pull/116

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

Legend:

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

    r13497 r13502  
    291291    foreach ( $wp_page_components as $component ) {
    292292        if ( ! isset( $bp->pages->{$component['id']} ) ) {
    293             $orphaned_components[] = $component['name'];
     293            $orphaned_components[ $component['id'] ] = $component['name'];
    294294        }
    295295    }
    296296
    297297    if ( ! empty( $orphaned_components ) ) {
    298         $notice = sprintf(
     298        $notice_type = 'error';
     299        $notice      = sprintf(
    299300            // Translators: %s is the comma separated list of components needing a directory page.
    300301            __( 'The following active BuddyPress Components do not have associated BuddyPress Pages: %s.', 'buddypress' ),
     
    302303        );
    303304
    304         bp_core_add_admin_notice( $notice );
     305        if ( 'buddypress' === bp_core_get_directory_post_type() ) {
     306            $pages               = bp_core_add_page_mappings( $orphaned_components, 'keep', true );
     307            $orphaned_components = array_intersect_key( $orphaned_components, $pages );
     308
     309            $notice_type = 'updated';
     310            $notice      = sprintf(
     311                // 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>'
     314            );
     315        }
     316
     317        bp_core_add_admin_notice( $notice, $notice_type );
    305318    }
    306319
     
    321334    // If there are duplicates, post a message about them.
    322335    if ( ! empty( $dupe_names ) ) {
    323         $notice = ssprintf(
     336        $notice = sprintf(
    324337            // Translators: %s is the list of directory pages associated to more than one component.
    325338            __( 'Each BuddyPress Component needs its own BuddyPress page. The following BuddyPress Pages have more than one component associated with them: %s.', 'buddypress' ),
     
    327340        );
    328341
    329         bp_core_add_admin_notice( $notice );
     342        bp_core_add_admin_notice( $notice, 'error' );
    330343    }
    331344}
  • trunk/src/bp-core/bp-core-functions.php

    r13490 r13502  
    816816 *
    817817 * @since 1.7.0
    818  *
    819  * @param array  $components Components to create pages for.
    820  * @param string $existing   'delete' if you want to delete existing page mappings
    821  *                           and replace with new ones. Otherwise existing page mappings
    822  *                           are kept, and the gaps filled in with new pages. Default: 'keep'.
    823  */
    824 function bp_core_add_page_mappings( $components, $existing = 'keep' ) {
     818 * @since 12.0.0 Adds the `$return_pages` parameter.
     819 *
     820 * @param array   $components   Components to create pages for.
     821 * @param string  $existing     'delete' if you want to delete existing page mappings
     822 *                              and replace with new ones. Otherwise existing page mappings
     823 *                              are kept, and the gaps filled in with new pages. Default: 'keep'.
     824 * @param boolean $return_pages Whether to return the page mapping or not.
     825 * @return void|array
     826 */
     827function bp_core_add_page_mappings( $components, $existing = 'keep', $return_pages = false ) {
    825828
    826829    // If no value is passed, there's nothing to do.
     
    847850
    848851    $page_titles = bp_core_get_directory_page_default_titles();
     852    if ( $return_pages ) {
     853        // In this case the `$components` array uses Page titles as values.
     854        $page_titles = bp_parse_args( $page_titles, $components );
     855    }
    849856
    850857    $pages_to_create = array();
     
    899906    if ( ! bp_is_root_blog() ) {
    900907        restore_current_blog();
     908    }
     909
     910    if ( $return_pages ) {
     911        return $pages;
    901912    }
    902913}
Note: See TracChangeset for help on using the changeset viewer.