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

Widget Visibility: add controls to widget block editor #20057

Closed
3 of 4 tasks
jeherve opened this issue Jun 10, 2021 · 34 comments · Fixed by #20255, #20731 or #21222
Closed
3 of 4 tasks

Widget Visibility: add controls to widget block editor #20057

jeherve opened this issue Jun 10, 2021 · 34 comments · Fixed by #20255, #20731 or #21222
Assignees
Labels
Customer Report Issues or PRs that were reported via Happiness. Previously known as "Happiness Request". [Feature] Widget Visibility [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack [Pri] Normal [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Milestone

Comments

@jeherve
Copy link
Member

jeherve commented Jun 10, 2021

Related issue: WordPress/gutenberg#31181

Jetpack's Widget Visibility module adds visibility controls to the widgets available in Appearance > Customize > Widgets and Appearance > Widgets

image

Those controls are added here:

With the upcoming version of WordPress, the widget UI changes to allow you to insert legacy widgets as well as blocks, in two areas:

  • Under Appearance > Customize > Widgets in a refreshed UI.
  • Under a new interface at Appearance > Widgets, now loading themes.php?page=gutenberg-widgets instead of widgets.php.

We'll need to do a few things to ensure that Widget Visibility is compatible with those changes:

  • Revisit the changes that were introduced in Widget Visibility: Disable in Block Editor #17413 to allow the use of Widget Visibility in the block widget editor.
  • Update the Widget Visibility JS so it can hook its buttons into the block widget editor as well as the old interface.
  • Update its CSS to ensure its layout looks good in the old and the new UI.
  • Ensure that widget visibility controls are displayed for blocks.

Primary issue: #19654

Related discussion: pbAok1-2dI-p2

@jeherve jeherve added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Feature] Widget Visibility [Pri] Normal [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack labels Jun 10, 2021
@jeherve
Copy link
Member Author

jeherve commented Jun 10, 2021

Loading the resources in the right screen seems to be possible (I believe something like below should help), but we'll need some extra work to update the JS to target the right elements.

diff --git a/projects/plugins/jetpack/modules/widget-visibility/widget-conditions.php b/projects/plugins/jetpack/modules/widget-visibility/widget-conditions.php
index 2574690f73..6db2e95047 100644
--- a/projects/plugins/jetpack/modules/widget-visibility/widget-conditions.php
+++ b/projects/plugins/jetpack/modules/widget-visibility/widget-conditions.php
@@ -10,11 +10,13 @@ class Jetpack_Widget_Conditions {
 	static $passed_template_redirect = false;
 
 	public static function init() {
-		if ( is_admin() ) {
+		global $pagenow;
+
+		if ( is_customize_preview() || 'widgets.php' === $pagenow || 'themes.php' === $pagenow ) {
 			add_action( 'sidebar_admin_setup', array( __CLASS__, 'widget_admin_setup' ) );
 			add_filter( 'widget_update_callback', array( __CLASS__, 'widget_update' ), 10, 3 );
 			add_action( 'in_widget_form', array( __CLASS__, 'widget_conditions_admin' ), 10, 3 );
-		} elseif ( ! in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ) ) ) {
+		} elseif ( ! in_array( $pagenow, array( 'wp-login.php', 'wp-register.php' ), true ) ) {
 			add_filter( 'widget_display_callback', array( __CLASS__, 'filter_widget' ) );
 			add_filter( 'sidebars_widgets', array( __CLASS__, 'sidebars_widgets' ) );
 			add_action( 'template_redirect', array( __CLASS__, 'template_redirect' ) );
@@ -22,11 +24,6 @@ class Jetpack_Widget_Conditions {
 	}
 
 	public static function widget_admin_setup() {
-		// Return early if we are not in the block editor.
-		if ( wp_should_load_block_editor_scripts_and_styles() ) {
-			return;
-		}
-
 		wp_enqueue_style( 'widget-conditions', plugins_url( 'widget-conditions/widget-conditions.css', __FILE__ ) );
 		wp_style_add_data( 'widget-conditions', 'rtl', 'replace' );
 		wp_enqueue_script(

@cpapazoglou
Copy link
Contributor

Reserved for onboarding.

@cpapazoglou
Copy link
Contributor

I would suggest limiting the scope of this issue to Legacy Widgets so that it's fully ready and tested when WordPress 5.8 is released and opening (?) a new issue regarding support to blocks which will need a more "Gutenberg" oriented approach rather than using jQuery to inject HTML.

@cpapazoglou
Copy link
Contributor

cc: @simison

@jeherve
Copy link
Member Author

jeherve commented Jul 9, 2021

I would suggest limiting the scope of this issue to Legacy Widgets so that it's fully ready and tested when WordPress 5.8 is released and opening (?) a new issue regarding support to blocks which will need a more "Gutenberg" oriented approach rather than using jQuery to inject HTML.

That's fair. We can also keep this issue open and add a new item to the task list here.

@simison
Copy link
Member

simison commented Jul 9, 2021

Fine by me. 👍 We could even roll with that limited scope and sit back and observe feedback and adjust only later, if ever. Important to consider if it's clear why there's such a difference in UI between different blocks. Please also do inform .com happiness + docs people at pbAok1-2cr-p2 — @jeherve can prolly loop in Jetpack HEs/docs?

@jeherve
Copy link
Member Author

jeherve commented Jul 9, 2021

can prolly loop in Jetpack HEs/docs?

@a8ck3n Could you add this to your list for the 9.1.1 release?

In short, Widget Visibility will only work for legacy widgets (i.e. widgets as we know them today) for all folks using the new Widget management screen that will be introduced in WP 5.8. That screen also allows you to add blocks to widget areas, but those will not include any widget visibility controls yet.

Thank you!

@sdixon194
Copy link
Contributor

Re-opened because widget visibility settings still need to be addressed for block widgets themselves, especially as more people convert legacy widgets to block, breaking their visibility settings.

@mzitinfo
Copy link

Another case in 4212591-zen

@fresatomica
Copy link

@jartes
Copy link

jartes commented Aug 12, 2021

Another report here 29532833-hc. User with a Simple Site with no visibility option (even with Legacy Widgets)

@simison
Copy link
Member

simison commented Aug 13, 2021

The fix for legacy widgets in the new interface got deployed for simple sites (D65412-code, D65394-code).

Blocks in the new widgets interface still need a fix.

@MaxPhilip
Copy link

MaxPhilip commented Aug 16, 2021

Another user who needs visibility settings: 4222374-zen

@supernovia
Copy link

@mtias
Copy link
Member

mtias commented Aug 18, 2021

@simison is this assigned anywhere yet? I see it is, scratch that :)

@simison
Copy link
Member

simison commented Aug 18, 2021

@mtias No worries, thanks for caring. :-) Another half of these reports were sorted with the fix, and the rest will be sorted by work from Flow patrol.

Looks like we need design help though, so I've reached out to arrange some eyes for this. (p1629285502046400-slack-dotcom-design)

@dcoleonline
Copy link

4221429-zen asking for visibility for block widgets

@mreishus
Copy link
Contributor

Looking for reviews on #20731

@sajmes
Copy link

sajmes commented Aug 26, 2021

Another request for visibility on block widgets: 4238114-zd-woothemes

@xpurichan
Copy link

31354335-hc

@the-misha
Copy link

Another request: 28417583-hc

@sdixon194 sdixon194 modified the milestones: jetpack/10.1, jetpack/10.2 Sep 3, 2021
@jerrysarcastic
Copy link

Request for followup in https://wordpress.com/forums/topic/changing-widget-visibility-in-sidebar/ when visibility is restored

@simison
Copy link
Member

simison commented Sep 6, 2021

@mreishus hi! What's the status/timeframe on this?

@aisajib
Copy link

aisajib commented Sep 15, 2021

Another forum post regarding this here: https://wordpress.com/forums/topic/visibility-in-blocks-in-the-widget-area/

@fresatomica
Copy link

@edwinho89
Copy link

4313215-zd-woothemes

@sophiegyo
Copy link

Another request came in via 31060326-hc / 4320892-zd

@mreishus
Copy link
Contributor

mreishus commented Sep 23, 2021

This is scheduled for the next Jetpack release (10.2 on 2021-10-05) and is available on certain WordPress.com plans today.

p7DVsv-cIY-p2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Customer Report Issues or PRs that were reported via Happiness. Previously known as "Happiness Request". [Feature] Widget Visibility [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack [Pri] Normal [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet