Skip to:
Content

BuddyPress.org

Changeset 13145


Ignore:
Timestamp:
11/13/2021 02:33:37 PM (3 years ago)
Author:
imath
Message:

WP FSE Compat: make sure BuddyPress templates are loaded on front-end

Adapt the BuddyPress Theme Compat API so that it uses the WordPress block template canvas when the active theme supports block templates. You can now test BuddyPress inside Twenty Twenty-Two: the next WordPress default theme!

Improves the BP Nouveau Template Pack introducing a new function bp_nouveau_get_theme_layout_widths() to get the theme layout available widths and use the wider one by default.

See #8474

Location:
trunk/src
Files:
5 edited

Legend:

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

    r13002 r13145  
    454454    $templates = apply_filters( "bp_get_{$type}_template", $templates );
    455455
    456     // Filter possible templates, try to match one, and set any BuddyPress theme
    457     // compat properties so they can be cross-checked later.
     456    /*
     457     * Filter possible templates, try to match one, and set any BuddyPress theme
     458     * compat properties so they can be cross-checked later.
     459     */
    458460    $templates = bp_set_theme_compat_templates( $templates );
    459461    $template  = bp_locate_template( $templates );
    460     $template  = bp_set_theme_compat_template( $template );
     462
     463    /*
     464     * The current theme is using the WordPress Full Site Editing feature.
     465     * BuddyPress then needs to use the WordPress template canvas to retrieve the community content.
     466     */
     467    if ( current_theme_supports( 'block-templates' ) && $template === get_theme_file_path( 'index.php' ) ) {
     468        $template = ABSPATH . WPINC . '/template-canvas.php';
     469    }
     470
     471    $template = bp_set_theme_compat_template( $template );
    461472
    462473    /**
  • trunk/src/bp-templates/bp-nouveau/buddypress-functions.php

    r13089 r13145  
    177177        add_action( 'bp_actions', array( $this, 'neutralize_core_template_notices' ), 6 );
    178178
    179         // Scripts.
    180         add_action( 'bp_enqueue_scripts', array( $this, 'register_scripts' ), 2 ); // Register theme JS.
     179        // Scripts & Styles.
     180        $registration_params = array(
     181            'hook'     => 'bp_enqueue_scripts',
     182            'priority' => 2,
     183        );
     184
     185        /*
     186         * The WordPress Full Site Editing feature needs Scripts
     187         * and Styles to be registered earlier.
     188         */
     189        if ( current_theme_supports( 'block-templates' ) ) {
     190            $registration_params['hook']     = 'bp_init';
     191            $registration_params['priority'] = 20;
     192        }
     193
     194        // Register theme JS.
     195        add_action( $registration_params['hook'], array( $this, 'register_scripts' ), $registration_params['priority'] );
     196
     197        // Enqueue theme CSS.
     198        add_action( 'bp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
     199
     200        // Enqueue theme JS.
     201        add_action( 'bp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
     202
     203        // Enqueue theme script localization.
     204        add_filter( 'bp_enqueue_scripts', array( $this, 'localize_scripts' ) );
    181205        remove_action( 'bp_enqueue_scripts', 'bp_core_confirmation_js' );
    182         add_action( 'bp_enqueue_scripts', array( $this, 'enqueue_styles' ) ); // Enqueue theme CSS.
    183         add_action( 'bp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); // Enqueue theme JS.
    184         add_filter( 'bp_enqueue_scripts', array( $this, 'localize_scripts' ) ); // Enqueue theme script localization.
    185206
    186207        // Body no-js class.
  • trunk/src/bp-templates/bp-nouveau/includes/customizer.php

    r12537 r13145  
    44 *
    55 * @since 3.0.0
    6  * @version 3.1.0
     6 * @version 10.0.0
    77 */
    88
     
    2222    $wp_customize->register_control_type( 'BP_Nouveau_Nav_Customize_Control' );
    2323    $bp_nouveau_options = bp_nouveau_get_appearance_settings();
     24    $layout_widths      = bp_nouveau_get_theme_layout_widths();
    2425
    2526    $wp_customize->add_panel( 'bp_nouveau_panel', array(
     
    203204    ) );
    204205
    205     if ( current_theme_supports( 'align-wide' ) ) {
     206    if ( $layout_widths ) {
    206207        $settings['bp_nouveau_appearance[global_alignment]'] = array(
    207208            'index'             => 'global_alignment',
     
    307308    $controls = apply_filters( 'bp_nouveau_customizer_controls', $controls );
    308309
    309     if ( current_theme_supports( 'align-wide' ) ) {
     310    if ( $layout_widths ) {
    310311        $controls['global_alignment'] = array(
    311312            'label'      => __( 'Select the BuddyPress container width for your site.', 'buddypress' ),
     
    313314            'settings'   => 'bp_nouveau_appearance[global_alignment]',
    314315            'type'       => 'select',
    315             'choices'    => array(
    316                 'alignnone' => __( 'Default width', 'buddypress' ),
    317                 'alignwide' => __( 'Wide width', 'buddypress' ),
    318                 'alignfull' => __( 'Full width', 'buddypress' ),
    319             ),
     316            'choices'    => $layout_widths,
    320317        );
    321318    }
  • trunk/src/bp-templates/bp-nouveau/includes/functions.php

    r13144 r13145  
    44 *
    55 * @since 3.0.0
    6  * @version 9.0.0
     6 * @version 10.0.0
    77 */
    88
     
    16401640    return $widget_content;
    16411641}
     1642
     1643/**
     1644 * Retuns the theme layout available widths.
     1645 *
     1646 * @since 10.0.0
     1647 *
     1648 * @return array The available theme layout widths.
     1649 */
     1650function bp_nouveau_get_theme_layout_widths() {
     1651    $layout_widths = array();
     1652
     1653    if ( current_theme_supports( 'align-wide' ) ) {
     1654        $layout_widths = array(
     1655            'alignnone' => __( 'Default width', 'buddypress' ),
     1656            'alignwide' => __( 'Wide width', 'buddypress' ),
     1657            'alignfull' => __( 'Full width', 'buddypress' ),
     1658        );
     1659    }
     1660
     1661    // `wp_get_global_settings()` has been introduced in WordPress 5.9
     1662    if ( function_exists( 'wp_get_global_settings' ) ) {
     1663        $theme_layouts = wp_get_global_settings( array( 'layout' ) );
     1664
     1665        if ( isset( $theme_layouts['wideSize'] ) && $theme_layouts['wideSize'] ) {
     1666            $layout_widths = array(
     1667                'alignnone' => __( 'Content width', 'buddypress' ),
     1668                'alignwide' => __( 'Wide width', 'buddypress' ),
     1669            );
     1670        }
     1671    }
     1672
     1673    /**
     1674     * Filter here to edit the available theme layout widths.
     1675     *
     1676     * @since 10.0.0
     1677     *
     1678     * @param array $layout_widths The available theme layout widths.
     1679     */
     1680    return apply_filters( 'bp_nouveau_get_theme_layout_widths', $layout_widths );
     1681}
  • trunk/src/bp-templates/bp-nouveau/includes/template-tags.php

    r13108 r13145  
    44 *
    55 * @since 3.0.0
    6  * @version 8.0.0
     6 * @version 10.0.0
    77 */
    88
     
    15301530        }
    15311531
    1532         $global_alignment = bp_nouveau_get_temporary_setting( 'global_alignment', bp_nouveau_get_appearance_settings( 'global_alignment' ) );
    1533         if ( $global_alignment && 'alignnone' !== $global_alignment && current_theme_supports( 'align-wide' ) ) {
     1532        $global_alignment  = bp_nouveau_get_temporary_setting( 'global_alignment', bp_nouveau_get_appearance_settings( 'global_alignment' ) );
     1533        $layout_widths     = bp_nouveau_get_theme_layout_widths();
     1534
     1535        if ( $global_alignment && 'alignnone' !== $global_alignment && $layout_widths ) {
    15341536            $classes[] = $global_alignment;
    15351537        }
Note: See TracChangeset for help on using the changeset viewer.