-
Notifications
You must be signed in to change notification settings - Fork 292
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
Enhanced twg settings validation #5573
Enhanced twg settings validation #5573
Conversation
Size Change: +881 kB (+65%) 🆘 Total Size: 2.25 MB
ℹ️ View Unchanged
|
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.
Looks good, just one question and also a thought on the post types we allow to be saved.
Let me know what you think, after that I think we're good to merge 😄
if ( ! is_array( $button_post_types ) ) { | ||
return array( 'post' ); | ||
} |
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.
Why is this here? I guess it's for the default value/settings? I'd think a safer default is to show this on no post types by default 🤔
if ( ! is_array( $button_post_types ) ) { | |
return array( 'post' ); | |
} | |
if ( ! is_array( $button_post_types ) ) { | |
return array(); | |
} |
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.
SGTM. 👍
if ( ! is_array( $button_post_types ) ) { | ||
return array( 'post' ); | ||
} | ||
return array_intersect( $button_post_types, get_post_types( array( 'public' => true ) ) ); |
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.
Additionally, I wonder if this matches the UI we show… in the UI we only show posts that support viewable
(see: #5456). I wonder if this would allow a user to submit a post type successfully that wouldn't appear in the UI.
Not a big deal as they'd need to intentionally do so, but it would be nice if the only posts we allowed to save would be ones that would appear with the 'viewable'
value in supports
. 🤔
I know this is what was in the ACs/IB, but I think it's maybe a bit inaccurate? Would there be an easy way to get all post types that match what wp.data.select('core').getPostTypes().filter((postType) => postType.viewable)
returns? If so let's do that 😄
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.
Hi, the API for getPostTypes()
uses is_post_type_viewable
for each post to determine the viewable status. For a post to be viewable:
- if it's a builtin post type, the
public
must betrue
. - If it's not a builtin post type, the
publicly_queryable
must betrue
.
Which definitely makes your point valid. I'll see what's the best way to achieve that here.
Off Topic: speaking of getPostTypes
be aware that it only returns 10 post types if the site has more. See here. The workaround is to supply { per_page: -1 }
to the selector which will return 100. If there's 101 post type this workaround will not work 😁
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.
Yeah, sadly I think that's our best option for now until someone runs into an issue 😅
We could add pagination if needed, but for now 101
is probably enough.
@@ -0,0 +1,114 @@ | |||
<?php | |||
/** | |||
* Class Google\Site_Kit\Tests\Modules\Thank_With_Google\Settings |
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.
* Class Google\Site_Kit\Tests\Modules\Thank_With_Google\Settings | |
* Class Google\Site_Kit\Tests\Modules\Thank_With_Google\SettingsTest |
/** | ||
* Gets the setting value. | ||
* | ||
* @since m.e.x.t |
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.
Please be sure to use the correct placeholder as search/replace will miss it otherwise.
* @since m.e.x.t | |
* @since n.e.x.t |
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.
Oh my goodness, they looks same to me on monospaced font. Sorry!
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.
I missed it too, waiting for someone to make a m.e.x.t
release in ZenHub just to really mess with us 😉
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.
Code looks great, thanks! I'm just hunting down the huge filesize increase for Thanks with Google before merging.
Summary
Addresses issue:
Relevant technical choices
PR Author Checklist
Do not alter or remove anything below. The following sections will be managed by moderators only.
Code Reviewer Checklist
Merge Reviewer Checklist