diff --git a/assets/css/admin.css b/assets/css/admin.css
index 0d33a2f..063be71 100644
--- a/assets/css/admin.css
+++ b/assets/css/admin.css
@@ -28,7 +28,9 @@
.context-group-custom_post_types_taxonomies .context-group-wrap { max-height:10em; overflow:auto; padding:0.5em; margin-bottom:0.5em; background:#fff; border:1px solid #ddd; }
.context-group-custom_post_types_taxonomies label { display:block; padding:0.25em 0; }
-.context-group-wrap .wc-field-text-word-count input { width:3em; }
+.widget-context .context-group-word_count .context-group-wrap label { display: inline-block; }
+.widget-context .context-group-word_count .context-group-wrap select,
+.widget-context .context-group-word_count .context-group-wrap input[type="text"] { width:5em; display:inline-block; }
.context-group-admin_notes textarea { height:4em; }
@@ -53,6 +55,13 @@
.widget-content,
#widgets-right .widget { clear:left; }
+.wp-block-legacy-widget__edit-form .widget-context { font-size:13px; line-height: 1.5; color:#000; }
+.wp-block-legacy-widget__edit-form .widget-context .widget-context-header h3 { font-weight:bold; line-height: 2.1; line-height: inherit; font-size:14px; color: #000; }
+.wp-block-legacy-widget__edit-form .context-toggle { font-size:1em; }
+.wp-block-legacy-widget__edit-form .widget-context .context-group { padding-left: 1em; border-left:1px solid #ddd; }
+.wp-block-legacy-widget__edit-form .widget-context .context-group-incexc { padding-left:0; border:none; }
+.wp-block-legacy-widget__edit-form .widget-context-legacy-notice { padding:0.5em 1em; margin:1em 0; font-size:14px; }
+
@media screen and ( max-width: 900px ) {
.widget-context-settings-wrap { padding-right:0; }
.widget-context-form { margin:0; }
diff --git a/assets/js/widget-context.js b/assets/js/widget-context.js
index be4fb99..4617daa 100644
--- a/assets/js/widget-context.js
+++ b/assets/js/widget-context.js
@@ -1,17 +1,19 @@
/* global jQuery */
jQuery( document ).ready( function( $ ) {
- function showHideControls( widgetId ) {
- var condition = $( '#widget-context-' + widgetId + ' .wc-field-select-condition select' ).val();
+ function showHideControls( widgetId, state ) {
+ if ( ! state ) {
+ state = $( '#widget-context-' + widgetId + ' .wc-field-select-condition select' ).val();
+ }
- $( '#widget-context-' + widgetId ).toggleClass( 'context-global', ( condition === 'show' || condition === 'hide' ) );
+ $( '#widget-context-' + widgetId ).toggleClass( 'context-global', ( state === 'show' || state === 'hide' ) );
}
$( '.widget-context-inside' ).each( function() {
showHideControls( $( this ).data( 'widget-id' ) );
} );
- $( '#widgets-right, #widgets-left, #customize-theme-controls' ).on( 'change', '.wc-field-select-condition select', function() {
- showHideControls( $( this ).parent().data( 'widget-id' ) );
+ $( '#widgets-right, #widgets-left, #customize-theme-controls, .edit-widgets-block-editor' ).on( 'change', '.wc-field-select-condition select', function( condition ) {
+ showHideControls( $( this ).parent().data( 'widget-id' ), condition.target.value );
} );
$( document ).on( 'widget-updated widget-added', function( e, widget ) {
diff --git a/composer.json b/composer.json
index 169ed0b..46fbec7 100644
--- a/composer.json
+++ b/composer.json
@@ -46,7 +46,10 @@
"scripts": {
"lint": [
"composer validate --no-check-publish --strict",
- "phpcs ."
+ "phpcs"
+ ],
+ "lint-fix": [
+ "phpcbf"
],
"mess": [
"phpmd ./src text phpmd.xml --suffixes php"
diff --git a/phpcs.xml.dist b/phpcs.xml.dist
index a4e8d68..1165c39 100644
--- a/phpcs.xml.dist
+++ b/phpcs.xml.dist
@@ -7,6 +7,8 @@
%s
', + __( 'No widget controls enabled.', 'widget-context' ) + ), + ); if ( current_user_can( 'edit_theme_options' ) ) { $controls = array( @@ -694,17 +731,10 @@ function display_widget_context( $widget_id = null ) { sprintf( /* translators: %s is a URL to the settings page. */ __( 'No widget controls enabled. You can enable them in Widget Context settings.', 'widget-context' ), - $this->plugin_settings_admin_url() + esc_url( $this->plugin_settings_admin_url() ) ) ), ); - } else { - $controls = array( - sprintf( - '%s
', - __( 'No widget controls enabled.', 'widget-context' ) - ), - ); } } @@ -1064,6 +1094,45 @@ public function customize_widgets_admin_url() { return admin_url( 'customize.php?autofocus[panel]=widgets' ); } + /** + * Disable the widget block editor, if necessary. + * + * @return boolean + */ + public function maybe_disable_block_widget_editor( $enabled ) { + if ( $this->widget_block_editor_disabled() ) { + return false; + } + + return $enabled; + } + + /** + * If the block widget editor is enabled. + * + * @return boolean + */ + public function widget_block_editor_enabled() { + return function_exists( 'wp_use_widgets_block_editor' ) && wp_use_widgets_block_editor(); + } + + /** + * Check if the WP environment supports widget block editor. + * + * @return boolean + */ + public function widget_block_editor_supported() { + return function_exists( 'wp_use_widgets_block_editor' ); + } + + /** + * Check if the widget block editor is enabled in our settings. + * + * @return boolean + */ + public function widget_block_editor_disabled() { + return ! empty( $this->context_settings['widget_block_editor_disable'] ); + } /** * Get the URL to the plugin settings page. @@ -1071,9 +1140,28 @@ public function customize_widgets_admin_url() { * @return string */ public function plugin_settings_admin_url() { - return admin_url( 'themes.php?page=widget_context_settings' ); + return admin_url( sprintf( 'themes.php?page=%s', $this->settings_name ) ); } + /** + * Maybe display a notice about the widget interface. + * + * @return void + */ + public function maybe_notify_of_disabled_block_widget_editor() { + $admin_screen = get_current_screen(); + + if ( ! empty( $admin_screen->base ) && 'widgets' === $admin_screen->base ) { + if ( $this->widget_block_editor_supported() && $this->widget_block_editor_disabled() ) { + printf( + '%s %s
+ +
+