diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Metabox.php | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/src/Metabox.php b/src/Metabox.php index b2ae2e4..b04ef00 100644 --- a/src/Metabox.php +++ b/src/Metabox.php @@ -27,6 +27,11 @@ class Metabox public array $posttypes = []; /** + * The Taxonomies/s to add the Metabox to + */ + public array $taxonomies = []; + + /** * The Box's fields to add * * @var MetaboxField[] @@ -73,6 +78,24 @@ class Metabox } /** + * Assign a Taxonomy to add the Metabox to + * + * @param string|array $taxonomies + * + * @return $this + */ + public function taxonomy($taxonomies) + { + $taxonomies = (array)$taxonomies; + + foreach ($taxonomies as $taxonomy) { + $this->taxonomies[$taxonomy] = $taxonomy; + } + + return $this; + } + + /** * @param MetaboxField|array $fields * * @return $this @@ -110,7 +133,7 @@ class Metabox */ public function add() { - // build the rule groups for the location + // build the post type rule groups $postTypeRuleGroups = array_map(function ($posttype) { return [[ 'param' => 'post_type', @@ -119,11 +142,23 @@ class Metabox ]]; }, $this->posttypes); + // build the taxonomy rule groups + $taxonomyRuleGroups = array_map(function ($taxonomy) { + return [[ + 'param' => 'taxonomy', + 'operator' => '==', + 'value' => $taxonomy, + ]]; + }, $this->taxonomies); + + // merge the rules groups for the location + $ruleGroups = array_merge($postTypeRuleGroups, $taxonomyRuleGroups); + // merge with extra options $fieldGroup = array_merge_recursive([ 'key' => $this->key, 'title' => $this->title, - 'location' => $postTypeRuleGroups, + 'location' => $ruleGroups, ], $this->options); // add field group |