summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2020-12-16 22:07:02 +0100
committerDaniel Weipert <code@drogueronin.de>2020-12-16 22:07:02 +0100
commite3c2639e80665e623e1f1f4ce93fe80babb59f09 (patch)
tree6da034e5841b086083c779153abf65d48a4914a4 /src
parent3195d4785e505f664898b6d5599c844832fa9734 (diff)
Adds Taxonomy Term Meta supportv1.1.0
Diffstat (limited to 'src')
-rw-r--r--src/Metabox.php39
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