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 filter to disable PostAuthor #12687

Merged
merged 3 commits into from
Jan 8, 2019
Merged

Add filter to disable PostAuthor #12687

merged 3 commits into from
Jan 8, 2019

Conversation

mkaz
Copy link
Member

@mkaz mkaz commented Dec 7, 2018

Description

Adds a filter to the PostAuthor component which allows to override with a custom component.

How has this been tested?

  • Confirm the author field shows fine before/after apply the patch

  • In the plugin or theme that wants to override the component, use the following JavaScript code, remember to include 'wp-hooks', 'wp-element' in your enqueue dependency array.

var MyComponent = wp.element.createElement( 'div', {}, 'My Authors Content' );
wp.hooks.addFilter( 'editor.PostAuthor', 'myplugin', function() { return MyComponent; } );
  • Confirm the Author box no longer displays, instead you should see "My Authors Content"

Types of changes

This extends gutenberg with the editor.PostAuthor filter giving developers a hook to control the component for PostAuthor.

Checklist:

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

@mkaz mkaz requested a review from mtias December 7, 2018 21:01
@mkaz mkaz added the [Feature] Extensibility The ability to extend blocks or the editing experience label Dec 7, 2018
Copy link
Contributor

@georgeh georgeh left a comment

Choose a reason for hiding this comment

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

Tested and confirmed that I was able to remove the see the author dropdown, and that adding the filter in the documentation removed the input.

@chrisvanpatten
Copy link
Member

It'd be nice to get some direction on whether it's worth filtering just the hiding of the box, vs. going a step further and making the component fully filterable so you can replace it entirely. Interesting idea though; definitely can see how it'd be useful to make this more flexible (Co-Authors Plus could benefit, for instance)

@mkaz
Copy link
Member Author

mkaz commented Dec 7, 2018

@chrisvanpatten Co-Authors-Plus is exactly the use case, their quick fix was this PR Automattic/Co-Authors-Plus#630 which is far from ideal.

My thought was that a multiple author plugin stores data in a different way, that it is beyond what the current component does. I suppose a new component provided by the plugin could handle the data the same way it would if it implemented as a sidebar module.

I'm open to the idea of a filter that allows replacing <PostAuthor/> with something like <CoAuthorPlus/> if that could work

@mkaz
Copy link
Member Author

mkaz commented Dec 9, 2018

@chrisvanpatten @mtias - updated with a different approach using a full component passed in to filter to switch it out. I welcome feedback.

For the CoAuthorsPlus use case, it will require them to fully embrace Gutenberg and write a component to integrate. However, this seems like the much better and more flexible path to take.

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.

We should mirror the solution used in other places and wrap PostAuthor component with withFilter HOC as it is always used with PostAuthorCheck anyways. See: https://github.com/WordPress/gutenberg/blob/master/packages/edit-post/src/components/sidebar/post-author/index.js#L9.

See PostFeaturedImage as an example: https://github.com/WordPress/gutenberg/blob/master/packages/editor/src/components/post-featured-image/index.js#L146

@gziolo
Copy link
Member

gziolo commented Dec 12, 2018

See also the first part of README file for PostFeaturedImage in @wordpress/editor to check how it can be used in action: https://github.com/WordPress/gutenberg/blob/master/packages/editor/src/components/post-featured-image/README.md

@gziolo gziolo added this to the 4.8 milestone Dec 12, 2018
Adds the ability for a developer to switch out the PostAuthor component
with their own using the filter `editor.PostAuthor`
@mkaz
Copy link
Member Author

mkaz commented Dec 12, 2018

Thanks @gziolo so much better (and easier).

I was pointed to PostFeatureImage as an example to look at but started off in the wrong direction, I looked at just this piece: https://github.com/WordPress/gutenberg/blob/master/packages/editor/src/components/post-featured-image/index.js#L35

Updated and included a readme for the component documenting how to extend it properly.

@chrisvanpatten
Copy link
Member

The docs look good to me!

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.

It looks good, thanks for updating 👍

@gziolo gziolo added the [Type] Task Issues or PRs that have been broken down into an individual action to take label Dec 13, 2018
@mkaz mkaz removed the request for review from mtias December 13, 2018 17:23
@@ -63,4 +64,5 @@ export default compose( [
},
} ) ),
withInstanceId,
withFilters( 'editor.PostAuthor' ),
Copy link
Contributor

Choose a reason for hiding this comment

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

Like we discussed in previous #core-js chats, we should resist adding new filters/actions.
An alternative here would be to build a custom edit-post module.

Copy link
Member

Choose a reason for hiding this comment

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

It is part of the Post & Status panel, so it had to be re-created from scratch. I think we should introduce all missing filters for the elements we put in the sidebar for backward compatibility and consistency. However, we should stop doing it in other places unless there is a really good reason to do so. I can't think of any at the moment :)

@youknowriad youknowriad modified the milestones: 4.8, 4.9 Dec 19, 2018
@mkaz mkaz merged commit 8cce5f2 into master Jan 8, 2019
@mkaz mkaz deleted the extend/postAuthor branch January 8, 2019 15:41
youknowriad pushed a commit that referenced this pull request Mar 6, 2019
* Add filter to replace PostAuthor component

Adds the ability for a developer to switch out the PostAuthor component
with their own using the filter `editor.PostAuthor`

* Add readme for PostAuthor component, with hook documented

* Remove documentation here, included in component readme
youknowriad pushed a commit that referenced this pull request Mar 6, 2019
* Add filter to replace PostAuthor component

Adds the ability for a developer to switch out the PostAuthor component
with their own using the filter `editor.PostAuthor`

* Add readme for PostAuthor component, with hook documented

* Remove documentation here, included in component readme
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 [Type] Task Issues or PRs that have been broken down into an individual action to take
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants