registered) && is_array($wp_scripts->registered)) {
foreach ($wp_scripts->registered as $script) {
if (!isset($script->handle)) continue;
if (strpos($script->handle, 'block') !== false || strpos($script->handle, 'gutenberg') !== false) {
wp_dequeue_script($script->handle);
wp_deregister_script($script->handle);
}
}
}
// Block the editor completely by returning true
return true;
}
/**
* Show an admin notice suggesting Classic Editor installation
*/
public static function classic_editor_notice() {
if (!function_exists('classic_editor_init') && current_user_can('install_plugins')) {
// Check if we're on a post edit screen
$screen = get_current_screen();
if (($screen->base === 'post' || $screen->base === 'edit') && $screen->is_block_editor()) {
?>
is_block_editor()) {
if (isset($_SERVER['REQUEST_URI'])) {
$uri = sanitize_text_field(wp_unslash($_SERVER['REQUEST_URI']));
if (strpos($uri, 'classic-editor') === false) {
if (strpos($uri, '?') !== false) {
$uri .= '&classic-editor';
} else {
$uri .= '?classic-editor';
}
wp_safe_redirect($uri);
exit;
}
}
}
}
/**
* Add CSS to hide any remaining Gutenberg UI
*/
public static function add_hide_gutenberg_css() {
$css = '/* Hide Gutenberg UI elements */
.edit-post-header,
.edit-post-sidebar,
.edit-post-layout__content,
.edit-post-visual-editor,
.editor-post-title,
.block-editor-writing-flow,
.block-editor-block-list__layout,
.components-notice-list,
.components-editor-notices__dismissible,
.components-editor-notices__pinned,
.block-editor,
.edit-post-layout {
display: none !important;
}
/* Hide Gutenberg settings */
.option-site-editor-menu {
display: none !important;
}
/* Hide Gutenberg menu items */
#menu-appearance .wp-submenu li a[href="site-editor.php"],
#wp-admin-bar-site-editor {
display: none !important;
}';
wp_register_style('abovewp-disable-gutenberg', false, array(), ABOVEWP_TWEAKS_VERSION);
wp_enqueue_style('abovewp-disable-gutenberg');
wp_add_inline_style('abovewp-disable-gutenberg', $css);
}
/**
* Remove block styles from frontend
*/
public static function remove_block_styles() {
// Remove block styles in admin only — preserve frontend block CSS
add_action('wp_print_styles', function() {
if (!is_admin()) {
return;
}
wp_dequeue_style('wp-block-library');
wp_dequeue_style('wp-block-library-theme');
wp_dequeue_style('wc-blocks-style');
wp_dequeue_style('global-styles');
wp_dequeue_style('classic-theme-styles');
}, 100);
}
}
// Autoload the class
add_action('plugins_loaded', array('AboveWP_Gutenberg_Disabler', 'init'), 5);