diff --git a/lib/widgets.php b/lib/widgets.php index 28ebc00367475..7ea5d3a5e770d 100644 --- a/lib/widgets.php +++ b/lib/widgets.php @@ -102,18 +102,17 @@ function gutenberg_get_legacy_widget_settings() { $available_legacy_widgets = array(); global $wp_widget_factory, $wp_registered_widgets; foreach ( $wp_widget_factory->widgets as $class => $widget_obj ) { - if ( ! in_array( $class, $core_widgets ) ) { - $available_legacy_widgets[ $class ] = array( - 'name' => html_entity_decode( $widget_obj->name ), - // wp_widget_description is not being used because its input parameter is a Widget Id. - // Widgets id's reference to a specific widget instance. - // Here we are iterating on all the available widget classes even if no widget instance exists for them. - 'description' => isset( $widget_obj->widget_options['description'] ) ? - html_entity_decode( $widget_obj->widget_options['description'] ) : - null, - 'isCallbackWidget' => false, - ); - } + $available_legacy_widgets[ $class ] = array( + 'name' => html_entity_decode( $widget_obj->name ), + // wp_widget_description is not being used because its input parameter is a Widget Id. + // Widgets id's reference to a specific widget instance. + // Here we are iterating on all the available widget classes even if no widget instance exists for them. + 'description' => isset( $widget_obj->widget_options['description'] ) ? + html_entity_decode( $widget_obj->widget_options['description'] ) : + null, + 'isCallbackWidget' => false, + 'isHidden' => in_array( $class, $core_widgets, true ), + ); } foreach ( $wp_registered_widgets as $widget_id => $widget_obj ) { if ( diff --git a/packages/block-library/src/legacy-widget/edit/index.js b/packages/block-library/src/legacy-widget/edit/index.js index 4b645318eb227..ffe7083d37687 100644 --- a/packages/block-library/src/legacy-widget/edit/index.js +++ b/packages/block-library/src/legacy-widget/edit/index.js @@ -1,7 +1,10 @@ /** * External dependencies */ -import { map } from 'lodash'; +import { + map, + pickBy, +} from 'lodash'; /** * WordPress dependencies @@ -47,6 +50,10 @@ class LegacyWidgetEdit extends Component { hasPermissionsToManageWidgets, setAttributes, } = this.props; + const visibleLegacyWidgets = pickBy( + availableLegacyWidgets, + ( { isHidden } ) => ! isHidden + ); const { isPreview } = this.state; const { identifier, isCallbackWidget } = attributes; const widgetObject = identifier && availableLegacyWidgets[ identifier ]; @@ -55,7 +62,7 @@ class LegacyWidgetEdit extends Component { if ( ! hasPermissionsToManageWidgets ) { placeholderContent = __( 'You don\'t have permissions to use widgets on this site.' ); - } else if ( availableLegacyWidgets.length === 0 ) { + } else if ( visibleLegacyWidgets.length === 0 ) { placeholderContent = __( 'There are no widgets available.' ); } else { placeholderContent = ( @@ -68,7 +75,7 @@ class LegacyWidgetEdit extends Component { isCallbackWidget: availableLegacyWidgets[ value ].isCallbackWidget, } ) } options={ [ { value: 'none', label: 'Select widget' } ].concat( - map( availableLegacyWidgets, ( widget, key ) => { + map( visibleLegacyWidgets, ( widget, key ) => { return { value: key, label: widget.name,