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

Add a filter('editor.FeaturedImage') for the FeaturedImage component #6940

Merged
merged 5 commits into from Jul 11, 2018

Conversation

adamsilverstein
Copy link
Member

@adamsilverstein adamsilverstein commented May 24, 2018

Description

Enables developers to change what is displayed for the post's featured image panel, or append to it.

Fixes #6533.

Similar to the current core admin_post_thumbnail_html filter, this enables filtering of the featured image component.

How has this been tested?

Using the console, I tested replacing and appending to the panel.

Replacing the panel

// Replace the panel.
wp.hooks.addFilter( 
	'editor.PostFeaturedImage', 
	'myhook', 
	function() { 
		return function() { 
			return wp.element.createElement( 
				'div', 
				{}, 
				'This is a test' 
			); 
		} 
	} 
);

Appending to the panel

wp.hooks.addFilter( 
	'editor.PostFeaturedImage', 
	'myhook', 
	function( original ) { 
		return function() { 
			return (
				wp.element.createElement( 
					'div', 
					{ key: 'outer' + Math.random() }, 
					[
						_.extend( original( {} ), { key: 'below' + Math.random() } ),
						'Add something below...' 
					]
				)
			);
		} 
	} 
);

Screenshots

replace

append

Types of changes

Filters the FeaturedImage component.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.

@danielbachhuber
Copy link
Member

@adamsilverstein @gziolo Prior to merging, can one of you open a PR against https://github.com/danielbachhuber/gutenberg-migration-guide/blob/master/filter-admin-post-thumbnail-html.md with documentation on how this works?

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you consider adding this filter directly on the editor component instead of on the panel wrapper?

My concern is that you rather don’t want to allow plugin developers to replace this panel with anything else. You rather would expect to replace panel’s content with something else, prepend or append HTML code or disable the panel completely.

I think that we should rather tackle removing individual panels separately and focus here on the Featured Image itself

@adamsilverstein
Copy link
Member Author

Did you consider adding this filter directly on the editor component instead of on the panel wrapper?

Good suggestion, I’ll give that a try.

@adamsilverstein
Copy link
Member Author

Did you consider adding this filter directly on the editor component instead of on the panel wrapper?

@gziolo I did this in 77a4366 and this fixes the issues I noted originally. Let me know what you think and if it looks good I can try to update docs as well.

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good, it’s exactly what I thought about. Let’s add docs and get it in!

@adamsilverstein
Copy link
Member Author

@danielbachhuber opened a PR - danielbachhuber/gutenberg-migration-guide#8

@gziolo took a pass at adding a readme for the component, is this what you had in mind?

return (
wp.element.createElement(
'div',
{ key: 'outer' + Math.random() },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is confusing to use random here. I think you don't need it at all. I also wanted to note that you probably can refactor it as:

const el = wp.element.createElement;

el( 
	'div', 
	{}, 
	'Prepend above',
	el( OriginalComponent, props ),
	'Append below' 
)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, that was bad! thanks for fixing that and cleanup generally.

@gziolo gziolo force-pushed the feature/filter-featured-image branch from c9a48b4 to a7f4269 Compare July 11, 2018 11:52
Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamsilverstein thanks for working on this one, I updated docs to follow other examples. In other files we use ES.Next but I personally prefer to have all the examples using filters to use ES5 so you could paste them in the JS console.

@gziolo gziolo added the [Feature] Extensibility The ability to extend blocks or the editing experience label Jul 11, 2018
@gziolo gziolo added this to In Progress in Extensibility via automation Jul 11, 2018
@gziolo gziolo merged commit 804db6d into master Jul 11, 2018
Extensibility automation moved this from In Progress to Done Jul 11, 2018
@gziolo gziolo deleted the feature/filter-featured-image branch July 11, 2018 12:00
@adamsilverstein
Copy link
Member Author

I personally prefer to have all the examples using filters to use ES5 so you could paste them in the JS console.

For sure that is great, thanks for updating those examples!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Extensibility The ability to extend blocks or the editing experience
Projects
No open projects
Extensibility
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants