Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theme Previews: Make the back button customizable #54242

Merged
merged 4 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions lib/compat/wordpress-6.4/theme-previews.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* Enable theme previews in the Site Editor for block themes.
*
* @package gutenberg
*/

/**
* Allow developers to customize the back to dashboard link in the Site Editor
*
* @param array $settings The editor settings.
* @return array The editor settings.
*/
function gutenberg_theme_preview_block_editor_settings_all( $settings ) {
$settings['__experimentalDashboardLink'] = 'themes.php';
$settings['__experimentalDashboardLinkText'] = __( 'Go back to the theme showcase' );
return $settings;
}

/**
* Attaches filters to enable theme previews in the Site Editor.
* This would go inside of `initialize_theme_preview_hooks`
* to avoid the global scope when we port this to the core.
*/
if ( ! empty( $_GET['wp_theme_preview'] ) ) {
add_filter( 'block_editor_settings_all', 'gutenberg_theme_preview_block_editor_settings_all' );
}
1 change: 1 addition & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function gutenberg_is_experiment_enabled( $name ) {
// WordPress 6.4 compat.
require_once __DIR__ . '/compat/wordpress-6.4/class-gutenberg-rest-global-styles-revisions-controller-6-4.php';
require_once __DIR__ . '/compat/wordpress-6.4/rest-api.php';
require_once __DIR__ . '/compat/wordpress-6.4/theme-previews.php';

// Plugin specific code.
require_once __DIR__ . '/class-wp-rest-global-styles-controller-gutenberg.php';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ export default function SidebarNavigationScreen( {
description,
backPath: backPathProp,
} ) {
const { dashboardLink } = useSelect( ( select ) => {
const { dashboardLink, dashboardLinkText } = useSelect( ( select ) => {
const { getSettings } = unlock( select( editSiteStore ) );
return {
dashboardLink: getSettings().__experimentalDashboardLink,
dashboardLinkText: getSettings().__experimentalDashboardLinkText,
};
}, [] );
const { getTheme } = useSelect( coreStore );
Expand Down Expand Up @@ -92,15 +93,9 @@ export default function SidebarNavigationScreen( {
<SidebarButton
icon={ icon }
label={
! isPreviewingTheme()
? __( 'Go to the Dashboard' )
: __( 'Go back to the theme showcase' )
}
href={
! isPreviewingTheme()
? dashboardLink || 'index.php'
: 'themes.php'
dashboardLinkText || __( 'Go to the Dashboard' )
}
href={ dashboardLink || 'index.php' }
/>
) }
<Heading
Expand Down
Loading