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

Disable customizer and widgets from FSE #26594

Merged
merged 3 commits into from
Nov 2, 2020
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
6 changes: 5 additions & 1 deletion gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ function gutenberg_menu() {
if ( gutenberg_is_fse_theme() ) {
add_menu_page(
__( 'Site Editor (beta)', 'gutenberg' ),
__( 'Site Editor (beta)', 'gutenberg' ),
sprintf(
/* translators: %s: "beta" label. */
__( 'Site Editor %s', 'gutenberg' ),
'<span class="awaiting-mod">' . __( 'beta', 'gutenberg' ) . '</span>'
),
'edit_theme_options',
'gutenberg-edit-site',
'gutenberg_edit_site_page',
Expand Down
61 changes: 61 additions & 0 deletions lib/full-site-editing.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,64 @@ function gutenberg_full_site_editing_notice() {
<?php
}
add_action( 'admin_notices', 'gutenberg_full_site_editing_notice' );

/**
* Removes legacy pages from FSE themes.
*/
function gutenberg_remove_legacy_pages() {
if ( ! gutenberg_is_fse_theme() ) {
return;
}

global $submenu;
if ( isset( $submenu['themes.php'] ) ) {
$indexes_to_remove = array();
foreach ( $submenu['themes.php'] as $index => $menu_item ) {
if (
false !== strpos( $menu_item[2], 'customize.php' ) ||
false !== strpos( $menu_item[2], 'gutenberg-widgets' )
) {
$indexes_to_remove[] = $index;
}
}

foreach ( $indexes_to_remove as $index ) {
unset( $submenu['themes.php'][ $index ] );
}
}
}

add_action( 'admin_menu', 'gutenberg_remove_legacy_pages' );

/**
* Activates the 'menu_order' filter and then hooks into 'menu_order'
*/
add_filter( 'custom_menu_order', '__return_true' );
add_filter( 'menu_order', 'gutenberg_menu_order' );

/**
* Filters WordPress default menu order
*
* @param array $menu_order Menu Order.
*/
function gutenberg_menu_order( $menu_order ) {
if ( ! gutenberg_is_fse_theme() ) {
return;
}

$new_positions = array(
// Position the site editor before the appearnce menu.
'gutenberg-edit-site' => array_search( 'themes.php', $menu_order, true ),
);

// Traverse through the new positions and move
// the items if found in the original menu_positions.
foreach ( $new_positions as $value => $new_index ) {
$current_index = array_search( $value, $menu_order, true );
if ( $current_index ) {
$out = array_splice( $menu_order, $current_index, 1 );
array_splice( $menu_order, $new_index, 0, $out );
}
}
return $menu_order;
}