Skip to content

Allow adding post and term meta by passing all as the object slug #241

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

Merged
merged 3 commits into from
Jul 31, 2023

Conversation

anubisthejackle
Copy link
Contributor

As it says in the title, this allows us to quickly add post meta to all registered post types by passing all to the register_meta_helper function.

As a consequence of this, this also allows us to set our post-meta.json config like so:

{
  "some_meta_key": {
    "default": true,
    "type": "boolean",
    "post_types": "all"
  }
}

Comment on lines +104 to +107
// Fix potential errors since we're allowing `$object_slugs` to be a string or array.
if ( is_string( $object_slugs ) ) {
$object_slugs = [ $object_slugs ];
}
Copy link
Contributor Author

@anubisthejackle anubisthejackle Jul 28, 2023

Choose a reason for hiding this comment

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

This could just as easily be a thrown exception. I opted for fixing the potential type error and trusting the value of the type as if it were a one value array, but I'm not married to this approach.

Copy link
Member

Choose a reason for hiding this comment

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

😄

Copy link
Member

@srtfisher srtfisher left a comment

Choose a reason for hiding this comment

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

one thought to add

src/meta.php Outdated
Comment on lines 91 to 95
(
is_array( $object_slugs ) &&
count( $object_slugs ) === 1 &&
'all' === $object_slugs[0]
) ||
Copy link
Member

@srtfisher srtfisher Jul 31, 2023

Choose a reason for hiding this comment

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

I wonder if it's worth considering ['all'] to be a valid value here. this condition would return true with ['all'] and ['all', 'a-valid-slug'] which is a little confusing but would have the same result either way.

would it be worth making it apply to all object types if $object_slugs is equal to 'all' vs supporting an array with all being the first value? It would make this code a bit cleaner but I see both arguments for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The grouping wouldn't return true here based on your array, due to the count( $object_slugs ) === 1 requirement. If there are multiple slugs, it passes through to the regular handling logic.

This logic is meant to only support all being the only value of the array.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@srtfisher Just to confirm, I made this 3v4l

Comment on lines +104 to +107
// Fix potential errors since we're allowing `$object_slugs` to be a string or array.
if ( is_string( $object_slugs ) ) {
$object_slugs = [ $object_slugs ];
}
Copy link
Member

Choose a reason for hiding this comment

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

😄

@anubisthejackle anubisthejackle disabled auto-merge July 31, 2023 15:26
@anubisthejackle anubisthejackle merged commit 31f3020 into develop Jul 31, 2023
@anubisthejackle anubisthejackle deleted the feature/allow-setting-meta-to-all branch July 31, 2023 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants