Skip to:
Content

BuddyPress.org

Changeset 13686


Ignore:
Timestamp:
01/01/2024 10:56:10 AM (6 months ago)
Author:
imath
Message:

Initialize the support of BP block only Themes

We are now using the locate_block_template() function to get block templates of BuddyPress content when active theme is supporting buddypress and is only using blocks.

For an example of this new kind of BP Themes, you can check the WIP we've started here: https://github.com/buddypress/buddyvibes

Here's a nice way to start 2024! Happy new year to everyone 🥂

Fixes #8900
Closes https://github.com/buddypress/buddypress/pull/104

M src/bp-core/bp-core-actions.php
M src/bp-core/bp-core-catchuri.php
M src/bp-core/bp-core-template-loader.php
M src/bp-core/bp-core-theme-compatibility.php

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

Legend:

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

    r13490 r13686  
    165165 */
    166166add_action( 'bp_after_setup_theme', 'bp_check_theme_template_pack_dependency',   -10 );
     167add_action( 'bp_after_setup_theme', 'bp_set_block_theme_compat',                  0  );
    167168add_action( 'bp_after_setup_theme', 'bp_load_theme_functions',                    1  );
    168169add_action( 'bp_after_setup_theme', 'bp_register_theme_compat_default_features',  10 );
  • trunk/src/bp-core/bp-core-catchuri.php

    r13522 r13686  
    7070 *
    7171 * @since 1.0.0
     72 * @since 14.0.0 Uses `locate_block_template()` to support BuddyPress Block only Themes.
    7273 *
    7374 * @param array $templates Array of templates to attempt to load.
     
    9596    // Only perform template lookup for bp-default themes.
    9697    if ( ! bp_use_theme_compat_with_current_theme() ) {
    97         $template = locate_template( (array) $filtered_templates, false );
     98        if ( bp_theme_compat_is_block_theme() ) {
     99            // Prevent BuddyPress components from using the BP Theme Compat feature.
     100            remove_all_actions( 'bp_setup_theme_compat' );
     101
     102            $block_templates = array();
     103            foreach ( (array) $templates as $template ) {
     104                $block_templates[] = 'buddypress/' . $template;
     105            }
     106
     107            $template_type     = 'buddypress';
     108            $block_templates[] = $template_type;
     109
     110            $template = locate_block_template( '', $template_type, $block_templates );
     111
     112        } else {
     113            $template = locate_template( (array) $filtered_templates, false );
     114        }
    98115
    99116    // Theme compat doesn't require a template lookup.
     
    124141    }
    125142
    126     if ( !empty( $located_template ) ) {
     143    if ( ! empty( $located_template ) ) {
    127144        // Template was located, lets set this as a valid page and not a 404.
    128145        status_header( 200 );
  • trunk/src/bp-core/bp-core-template-loader.php

    r13519 r13686  
    827827    ) );
    828828}
     829
     830/**
     831 * Sets Block Theme compatibility if it supports BuddyPress.
     832 *
     833 * @since 14.0.0
     834 */
     835function bp_set_block_theme_compat() {
     836    if ( bp_is_running_wp( '5.9.0', '>=' ) && wp_is_block_theme() && current_theme_supports( 'buddypress' ) ) {
     837        bp_deregister_template_stack( 'get_stylesheet_directory', 10 );
     838        bp_deregister_template_stack( 'get_template_directory', 12 );
     839
     840        $block_theme     = wp_get_theme();
     841        $theme_compat_id = $block_theme->stylesheet;
     842
     843        bp_register_theme_package(
     844            array(
     845                'id'             => $theme_compat_id,
     846                'name'           => $block_theme->get( 'Name' ),
     847                'version'        => $block_theme->get( 'Version' ),
     848                'dir'            => '',
     849                'url'            => '',
     850                'is_block_theme' => true,
     851            )
     852        );
     853
     854        bp_setup_theme_compat( $theme_compat_id );
     855    }
     856}
  • trunk/src/bp-core/bp-core-theme-compatibility.php

    r13395 r13686  
    10421042    }
    10431043}
     1044
     1045/**
     1046 * Informs about whether current theme compat is about a block theme.
     1047 *
     1048 * @since 14.0.0
     1049 *
     1050 * @return boolean True if current theme compat is about a block theme.
     1051 *                 False otherwise.
     1052 */
     1053function bp_theme_compat_is_block_theme() {
     1054    $theme = buddypress()->theme_compat->theme;
     1055
     1056    return isset( $theme->is_block_theme ) && $theme->is_block_theme;
     1057}
Note: See TracChangeset for help on using the changeset viewer.