diff --git a/class-redux-framework-plugin.php b/class-redux-framework-plugin.php index 6d3761a2..a21a20c5 100644 --- a/class-redux-framework-plugin.php +++ b/class-redux-framework-plugin.php @@ -318,6 +318,7 @@ public static function deactivate( $network_wide ) { } delete_option( 'ReduxFrameworkPlugin' ); + Redux_Enable_Gutenberg::cleanup_options( 'redux-framework' ); // Auto disable Gutenberg and all that. } /** diff --git a/readme.txt b/readme.txt index 0b269b27..ebac477b 100644 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Tags: gutenberg, blocks, gutenberg blocks, editor, block, page builder, block ed Requires at least: 4.0 Requires PHP: 5.3 Tested up to: 5.5 -Stable tag: 4.1.15 +Stable tag: 4.1.16 License: GPL-2.0+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt diff --git a/redux-core/class-redux-core.php b/redux-core/class-redux-core.php index bd4d6d4e..eb2c1331 100644 --- a/redux-core/class-redux-core.php +++ b/redux-core/class-redux-core.php @@ -320,6 +320,7 @@ private function includes() { require_once dirname( __FILE__ ) . '/inc/classes/class-redux-path.php'; require_once dirname( __FILE__ ) . '/inc/classes/class-redux-functions-ex.php'; require_once dirname( __FILE__ ) . '/inc/classes/class-redux-helpers.php'; + require_once dirname( __FILE__ ) . '/inc/classes/class-redux-enable-gutenberg.php'; Redux_Functions_Ex::register_class_path( 'Redux', dirname( __FILE__ ) . '/inc/classes' ); Redux_Functions_Ex::register_class_path( 'Redux', dirname( __FILE__ ) . '/inc/welcome' ); spl_autoload_register( array( $this, 'register_classes' ) ); diff --git a/redux-core/framework.php b/redux-core/framework.php index a49b9ffa..20371848 100644 --- a/redux-core/framework.php +++ b/redux-core/framework.php @@ -23,7 +23,7 @@ require_once dirname( __FILE__ ) . '/class-redux-core.php'; -Redux_Core::$version = '4.1.15'; +Redux_Core::$version = '4.1.16'; Redux_Core::$redux_path = dirname( __FILE__ ); Redux_Core::instance(); diff --git a/redux-core/inc/classes/class-redux-enable-gutenberg.php b/redux-core/inc/classes/class-redux-enable-gutenberg.php new file mode 100644 index 00000000..d1583898 --- /dev/null +++ b/redux-core/inc/classes/class-redux-enable-gutenberg.php @@ -0,0 +1,521 @@ + '', + 'name' => '', + ); + $args = wp_parse_args( $args, $defaults ); + + if ( empty( $args['slug'] ) ) { + echo 'You must pass a slug to the Redux_Enable_Gutenberg() constructor.'; + + return; + } + + if ( strpos( $args['slug'], 'gutenberg' ) === false ) { + $args['slug'] .= '-gutenberg'; + } + $this->slug = $args['slug']; + $this->name = $args['name']; + $this->nobug_option = $this->slug . '-no-bug'; + $this->nonce = $this->slug . '-nonce'; + $this->autoenable_option = $this->slug . '-force-enable'; + $this->decativate_option = $this->slug . '-deactivate-plugins'; + + if ( is_admin() && ! self::$is_disabled && ( 'post-new.php' === $pagenow || 'post.php' === $pagenow ) ) { + // We only want to do this for posts or pages. + if ( ! isset( $_GET['post_type'] ) || ( isset( $_GET['post_type'] ) && 'page' === $_GET['post_type'] ) ) { // phpcs:ignore + add_action( 'init', array( $this, 'check_init' ), 998 ); + add_action( 'init', array( $this, 'run_user_actions' ), 999 ); + if ( ! get_site_option( $this->nobug_option, false ) ) { + add_action( 'plugins_loaded', array( $this, 'check_plugin' ), 999 ); + add_action( 'after_setup_theme', array( $this, 'check_theme' ), 999 ); + add_action( 'admin_notices', array( $this, 'display_admin_notice' ) ); + } + } + } + } + + /** + * Cleanup for plugin deactivation. + * + * @param string $slug Slug for instance. + */ + public static function cleanup_options( $slug = '' ) { + if ( ! empty( $slug ) ) { + $data = array( + 'slug' => $slug, + 'name' => '', + ); + + $obj = new Redux_Enable_Gutenberg( + array( + 'slug' => $slug, + 'name' => '', + ) + ); + delete_site_option( $obj->autoenable_option ); + delete_site_option( $obj->nobug_option ); + } + } + + /** + * Display the admin notice. + */ + public function display_admin_notice() { + if ( ! self::$is_disabled ) { + return; + } + global $pagenow; + + $clean_get = $_GET; // phpcs:ignore WordPress.Security.NonceVerification.Recommended + if ( isset( $clean_get[ $this->nobug_option ] ) ) { + unset( $clean_get[ $this->nobug_option ] ); + } + if ( isset( $clean_get[ $this->autoenable_option ] ) ) { + unset( $clean_get[ $this->autoenable_option ] ); + } + if ( isset( $clean_get[ $this->decativate_option ] ) ) { + unset( $clean_get[ $this->decativate_option ] ); + } + $base_url = admin_url( add_query_arg( $clean_get, $pagenow ) ); + + $no_bug_url = wp_nonce_url( add_query_arg( $this->nobug_option, true, $base_url ), $this->nonce ); + $auto_enable_url = wp_nonce_url( add_query_arg( $this->autoenable_option, true, $base_url ), $this->nonce ); + $deativate_url = wp_nonce_url( add_query_arg( $this->decativate_option, true, $base_url ), $this->nonce ); + + $data = array( + 'url' => '', + 'content' => '', + 'header' => __( 'Gutenberg is currently disabled!', 'redux-framework' ), + 'button' => '', + ); + + if ( isset( $_GET[ $this->decativate_option ] ) || empty( self::$known_plugins ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended + + if ( isset( $_GET[ $this->decativate_option ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended + // That didn't work. + $data['header'] = __( 'Hmm, it seems something else is disabling Gutenberg...', 'redux-framework' ); + $data['content'] = sprintf( '

Well seems like we have more to do. Don\'t worry, we can still fix this! Click the Enable Gutenberg button and Redux will enable Gutenberg for you.

' ); + } elseif ( self::$theme_disabled ) { + $data['header'] = __( 'Your theme author has disabled Gutenberg!', 'redux-framework' ); + $data['content'] .= sprintf( '

It looks like your theme has disabled Gutenberg. Don\'t panic though! Click the Enable Gutenberg button to the right and Redux will enable Gutenberg for you.

' ); + } else { + $data['header'] = __( 'Looks like something has disabled Gutenberg?', 'redux-framework' ); + $data['content'] .= sprintf( '

Did you know that Gutenberg is disabled? If that\'s intended you can dismiss this notice, not what you intended? Click Enable Gutenberg and Redux will automatically fix this for you.

' ); + } + + $data['url'] = $auto_enable_url; + $data['button'] = __( 'Enable Gutenberg', 'redux-framework' ); + + } elseif ( empty( self::$known_plugins ) ) { + // Disabled by the theme or other. + $data['header'] = __( 'Your theme', 'redux-framework' ); + $data['url'] = $auto_enable_url; + $data['button'] = __( 'Enable Gutenberg', 'redux-framework' ); + } else { + // Disable Plugins! + $all_plugins = get_plugins(); + + $plugins = ''; + + foreach ( self::$known_plugins as $slug ) { + if ( isset( $all_plugins[ $slug ] ) ) { + if ( ! empty( $plugins ) ) { + $plugins .= ', '; + } + $plugins .= '' . esc_html( $all_plugins[ $slug ]['Name'] ) . ''; + } + } + + $data['url'] = $deativate_url; + if ( 1 === count( self::$known_plugins ) ) { + $data['button'] = __( 'Disable Plugin', 'redux-framework' ); + $data['content'] = sprintf( '

The following plugin is preventing Gutenberg from working: %s. To automatically fix the issue click the Disable Plugin button on the right.

', $plugins, esc_url( 'https://kinsta.com/blog/gutenberg-wordpress-editor/' ) ); + } else { + $data['button'] = __( 'Disable Plugins', 'redux-framework' ); + $data['content'] = sprintf( '

The following plugin is preventing Gutenberg from working: %s. To automatically fix the issue click the Disable Plugins button on the right.

', $plugins, esc_url( 'https://kinsta.com/blog/gutenberg-wordpress-editor/' ) ); + } + } + + ?> + +
+
+
+ + <?php echo esc_attr__( 'Redux WordPress Plugin', 'redux-framework' ); ?> +
+
+ +

+ +
+
+ %2$s', esc_url( $data['url'] ), esc_html( $data['button'] ) ); ?> + +
+
+
+ nonce ) || ! is_admin() || ! current_user_can( 'manage_options' ) ) ) { + return; + } + + if ( isset( $_GET[ $this->nobug_option ] ) ) { // User doesn't want to see this anymore. + add_site_option( $this->nobug_option, true ); + + return; // No need to redirect. + } elseif ( isset( $_GET[ $this->autoenable_option ] ) ) { // User has opted to just auto-enable Gutenberg. + unset( $_GET[ $this->autoenable_option ] ); + add_site_option( $this->autoenable_option, true ); + } elseif ( isset( $_GET[ $this->decativate_option ] ) && ! empty( self::$known_plugins ) ) { // User has opted to disable known gutenberg plugins. + deactivate_plugins( self::$known_plugins ); + } + global $pagenow; + unset( $_GET['_wpnonce'] ); + $url = admin_url( add_query_arg( $_GET, $pagenow ) ); + wp_safe_redirect( $url ); + + exit(); + + } + + /** + * Set the plugin to no longer bug users if user asks not to be. + */ + public function set_auto_disable() { + + // Bail out if not on correct page. + // phpcs:ignore + if ( ! isset( $_GET['_wpnonce'] ) || ( ! wp_verify_nonce( $_GET['_wpnonce'], $this->nonce ) || ! is_admin() || ! isset( $_GET[ $this->autoenable_option ] ) || ! current_user_can( 'manage_options' ) ) ) { + return; + } + + add_site_option( $this->autoenable_option, true ); + } + + /** + * Check for filter method. + */ + private function check_for_filter() { + if ( version_compare( $GLOBALS['wp_version'], '5.0-beta', '>' ) ) { + if ( has_filter( 'use_block_editor_for_post_type', '__return_false' ) ) { + return true; + } + } else { + if ( has_filter( 'gutenberg_can_edit_post_type', '__return_false' ) ) { + return true; // WP < 5 beta. + } + } + + return false; + } + + /** + * Remove the Gutenberg disable filter for posts and pages only. + */ + private function remove_filter() { + global $pagenow; + + if ( is_admin() && ! self::$is_disabled && ( 'post-new.php' === $pagenow || 'post.php' === $pagenow ) ) { + // We only want to do this for posts or pages. + if ( ! isset( $_GET['post_type'] ) || ( isset( $_GET['post_type'] ) && 'page' === $_GET['post_type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended + if ( version_compare( $GLOBALS['wp_version'], '5.0-beta', '>' ) ) { + // WP > 5 beta. + remove_filter( 'use_block_editor_for_post_type', '__return_false' ); + } else { + // WP < 5 beta. + remove_filter( 'gutenberg_can_edit_post_type', '__return_false' ); + } + } + } + } + + /** + * Quick checks against known plugins for disabling. + */ + public function quick_checks() { + // Testing for known plugins if they're loaded, save on filters and performance. + if ( class_exists( 'Classic_Editor' ) ) { + $a = new \ReflectionClass( 'Classic_Editor' ); + self::$known_plugins[] = plugin_basename( $a->getFileName() ); + } + + if ( defined( 'DISABLE_GUTENBERG_FILE' ) ) { + self::$known_plugins[] = plugin_basename( DISABLE_GUTENBERG_FILE ); + } + + if ( defined( 'ADE_PLUGIN_DIR_PATH' ) ) { + if ( class_exists( 'CodePopular_disable_gutenburg' ) ) { + $a = new \ReflectionClass( 'CodePopular_disable_gutenburg' ); + self::$known_plugins[] = plugin_basename( $a->getFileName() ); + } else { + self::$known_plugins[] = plugin_basename( ADE_PLUGIN_DIR_PATH ) . '/auto-disable-gutenberg.php'; + } + } + self::$known_plugins[] = 'no-gutenberg/no-gutenberg.php'; + self::$known_plugins[] = 'enable-classic-editor/enable-classic-editor.php'; + + $plugins = get_option( 'active_plugins' ); + $results = array_intersect( $plugins, self::$known_plugins ); + self::$known_plugins = $results; + if ( ! empty( self::$known_plugins ) ) { + self::$is_disabled = true; + } + } + + /** + * Check if plugins have the disable filter. + */ + public function check_plugin() { + $this->quick_checks(); + if ( ! self::$is_disabled && $this->check_for_filter() ) { + self::$is_disabled = true; + } + } + + /** + * Check if the theme have the disable filter. + */ + public function check_theme() { + if ( ! self::$is_disabled && $this->check_for_filter() ) { + self::$theme_disabled = true; + self::$is_disabled = true; + } + } + + /** + * Check if init hook still has the disable filter. + */ + public function check_init() { + if ( ! self::$is_disabled ) { + if ( $this->check_for_filter() ) { + self::$is_disabled = true; + } + } + + if ( self::$is_disabled && get_site_option( $this->autoenable_option, false ) ) { + $this->remove_filter(); + } + + } + } + + /* + * Instantiate the Redux_Enable_Gutenberg class. + */ + new Redux_Enable_Gutenberg( + array( + 'slug' => 'redux-framework', + 'name' => __( 'Redux', 'redux-framework' ), + ) + ); + +} diff --git a/redux-framework.php b/redux-framework.php index e16c7ecc..25160621 100644 --- a/redux-framework.php +++ b/redux-framework.php @@ -5,12 +5,12 @@ * standards and PHP best practices in mind. * * Plugin Name: Redux - * Plugin URI: http://wordpress.org/plugins/redux-framework + * Plugin URI: http://wordpress.org/plugins/redux-framework-4 * Github URI: reduxframework/redux-framework * Description: Build better sites in WordPress fast * Author: Redux.io + Dovy Paukstys * Author URI: http://redux.io - * Version: 4.1.15 + * Version: 4.1.16 * Text Domain: redux-framework * License: GPLv3 or later * License URI: http://www.gnu.org/licenses/gpl-3.0.txt