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

Create remaining issues out of this overview #24530

Closed
17 of 20 tasks
noisysocks opened this issue Aug 13, 2020 · 6 comments
Closed
17 of 20 tasks

Create remaining issues out of this overview #24530

noisysocks opened this issue Aug 13, 2020 · 6 comments
Labels
[Package] Edit Widgets /packages/edit-widgets [Type] Task Issues or PRs that have been broken down into an individual action to take

Comments

@noisysocks
Copy link
Member

noisysocks commented Aug 13, 2020

This issue tracks necessary follow-up work from merging #24290.

Has PR:

Lower priority:

Discussion in progress:

Don't do now:

@noisysocks noisysocks added [Type] Task Issues or PRs that have been broken down into an individual action to take [Package] Edit Widgets /packages/edit-widgets labels Aug 13, 2020
@adamziel
Copy link
Contributor

Any thoughts on having a new Gutenberg Block widget vs. using the existing HTML widget?

How would that work @noisysocks? HTML widget is good for storing HTML, but we also want to be able to edit these blocks as, well, blocks. Also I think it would break interoperability with the old widgets screen since the custom HTML widget would only render raw contents only, e.g. <!-- wp:latest-posts /-->, instead of a block. To make it 1:1 replacement of the block, we would need some custom logic to make sure that Custom HTML widget is treated as Custom HTML widgets in certain contexts, and as a block widget in different contexts. It sounds much more complex than just having a separate widget for that.

@noisysocks
Copy link
Member Author

Yep, good points. I think block is the way to go. It matches what I ended up doing for menu items in #24503, too.

@adamziel
Copy link
Contributor

Previewing an old-style widget in the Block Areas screen results in "Block rendered as empty."

I am unable to reproduce that @noisysocks, would you mind providing step-by-step instructions or a gif?

@noisysocks
Copy link
Member Author

Previewing an old-style widget in the Block Areas screen results in "Block rendered as empty."

I am unable to reproduce that @noisysocks, would you mind providing step-by-step instructions or a gif?

  1. Register a widget that doesn't use WP_Widget. Here's some plugin code which will do just that:
function marquee_greeting_init() {
	wp_register_sidebar_widget(
		'marquee_greeting',
		'Marquee Greeting',
		function() {
			$greeting = get_option( 'marquee_greeting', 'Hello!' );
			printf( '<marquee>%s</marquee>', esc_html( $greeting ) );
		}
	);

	wp_register_widget_control(
		'marquee_greeting',
		'Marquee Greeting',
		function() {
			if ( isset( $_POST['marquee-greeting'] ) ) {
				update_option(
					'marquee_greeting',
					sanitize_text_field( $_POST['marquee-greeting'] )
				);
			}

			$greeting = get_option( 'marquee_greeting' );
			?>
			<p>
				<label for="marquee-greeting">Greeting:</label>
				<input
					id="marquee-greeting"
					class="widefat"
					name="marquee-greeting"
					type="text"
					value="<?= esc_attr( $greeting ) ?>"
					placeholder="Hello!"
				/>
			</p>
			<?php
		}
	);
}
add_action( 'init', 'marquee_greeting_init' );
  1. Navigate to the new block-based widgets screen.

  2. Add a Legacy Widget block to one of the block areas.

  3. Select the widget registered in step 1 from the dropdown. (Marquee Greeting, if you used my code sample.)

  4. Click Preview in the block toolbar.

preview-error

@adamziel
Copy link
Contributor

Thank you @noisysocks, I think I got confused with all the wording (beta widgets screen, legacy widgets screen, legacy widgets, legacy not-so-legacy widgets, block widgets), definitely a case something we could solve with a ubiquitous language. Maybe.. function-based legacy widgets, class-based legacy widgets, block-based widgets?

@draganescu
Copy link
Contributor

@adamziel @draganescu maybe create separate issues and let's close this giant one.

@draganescu draganescu changed the title Widgets: Follow-up work from refactoring Widgets screen to use sidebars endpoint Create remaining issues out of this overview Sep 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Edit Widgets /packages/edit-widgets [Type] Task Issues or PRs that have been broken down into an individual action to take
Projects
None yet
Development

No branches or pull requests

3 participants