-
Notifications
You must be signed in to change notification settings - Fork 20
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
Added Settings UI #66
Conversation
d9b532a
to
7f4c3ec
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@akshitsethi thanks so much for the PR! Testing this PR I found some issues:
- Activating the plugin for the first time, the Post and Page are unchecked in the setting page, while they're enabled by default. Pages and posts are still converted to blocks automatically. This can make users confused.
- This doesn't fully resolve Add settings UI to opt CPTs into convert-to-blocks support #54 because the custom post types with
editor
support are still forced to use the classic editor.
add_action( 'admin_init', [ $this, 'register_section' ], 10 ); | ||
add_action( 'admin_init', [ $this, 'register_fields' ], 20 ); | ||
|
||
add_filter( 'post_type_supports_convert_to_blocks', [ $this, 'supported_post_types' ], PHP_INT_MAX, 2 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using PHP_INT_MAX
makes it very hard for plugins and/or themes to use this filter. I think even using the default priority is enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dinhtungdu I totally agree. I was myself having second thoughts about this. I'll correct this.
There are certain scenarios here which I would like a bit more clarity on: Scenario 1Post and pages are enabled by default. What if a user wants to disable the functionality on pages but keep it on for posts? Another point to consider here is that if we do keep the settings enabled by default for the user, then on a blog without CPTs, we won't have any setting to configure. Scenario 2An existing user has configured the plugin using the filter but if we update plugin settings in DB enabling post and pages options by default, it might break the existing filter they have in place. One way to tackle this is to ensure that our filter runs first and then it can be overriden later. Do you think updating DB option on plugin activation should be done? |
What I mean is we should respect the default setting. If users activate the plugin for the first time, Post and Page should be checked on the setting page (there is no data in the database at that point). If user have another CPTs, those post type should be unchecked by default.
The custom filter added by users should have the highest priority and should disable the setting section. We also should display a message let users know that there is an active filter controlling the post type.
Because of the above points, I don't think we need a DB updater here. |
public function field_post_types() { | ||
$post_types = get_option( | ||
sprintf( '%s_post_types', CONVERT_TO_BLOCKS_SLUG ), | ||
apply_filters( 'convert_to_blocks_default_post_types', CONVERT_TO_BLOCKS_DEFAULT_POST_TYPES ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should avoid using the same filter in different places when possible.
For this case, we can define the $cointainer
property for this class, and get the default post types using `$this->container->get_default_post_types(), see this for more details.
By doing so, we don't need the CONVERT_TO_BLOCKS_DEFAULT_POST_TYPES
constant anymore.
<?php | ||
printf( | ||
/* translators: %1$s: link to switch to settings panel, %2$s: closing anchor tag */ | ||
esc_html__( 'A filter hook (post_type_supports_convert_to_blocks) is active which can lead to undesirable outcome. Kindly remove it and configure settings via the %1$sSettings Panel%2$s.', 'convert-to-blocks' ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kindly remove it and configure settings via the %1$sSettings Panel%2$s.
The notice is only displayed on the Convert to Blocks setting page, so we don't need this IMO.
Edit: the notice is displayed for every admin page. I think we should limit it to the post/page list, plugin page, and the Convert to Blocks setting pages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, a filter can be used for advanced conditions like preventing conversion for posts belonging to a category. So IMHO, we just need to notify users that one or more filters to post_type_supports_convert_to_blocks
are being used, without any call to action.
@akshitsethi are you able to work on the feedback items here or would it be best to grab another person to help wrap up this PR? |
@jeffpaul, @akshitsethi said this needs a little more work and he's happy to have someone from the OSP team to takeover. |
@Sidsector9 @jeffpaul will work on this during my OSP week. |
@cadic did you manage to make progress on the updates here locally and can push up to the PR? |
@Sidsector9 @cadic checking to see if either of you are able to help get this updated and off to code review in January perhaps? |
…ure/58-settings-ui
25b8a49
to
83d5399
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
I added few fixes for workflows for them to pass, downgraded some NPM dependencies as npm run build
broke.
@jeffpaul should we bump the minimum PHP version of this plugin from 7.0 to 7.4?
@Sidsector9 yes, fine to bump PHP min to 7.4 |
a7241f2
to
4b94306
Compare
…ure/58-settings-ui
Closes #38, #54
Description of the Change
This PR adds UI for Plugin settings to configure the
post_types
supported by the plugin. Currently, it is being done with the help of a filter hook. With this change, users will be able to visually select thepost_types
they wish to be configured with the plugin.Also, missing yoast/phpunit-polyfills package has been added to enable running of unit tests.
To-do:
post_types
value from DB to configure the pluginPossible Drawbacks
None that I can think of.
Verification Process
To check the working of the Settings panel, follow the steps below:
Checklist:
Changelog Entry