summaryrefslogtreecommitdiff
path: root/src/Metabox.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Metabox.php')
-rw-r--r--src/Metabox.php53
1 files changed, 24 insertions, 29 deletions
diff --git a/src/Metabox.php b/src/Metabox.php
index b04ef00..4da3c4c 100644
--- a/src/Metabox.php
+++ b/src/Metabox.php
@@ -22,14 +22,9 @@ class Metabox
public string $title;
/**
- * The PostType/s to add the Metabox to
+ * ACF location rule groups
*/
- public array $posttypes = [];
-
- /**
- * The Taxonomies/s to add the Metabox to
- */
- public array $taxonomies = [];
+ public array $locations = [];
/**
* The Box's fields to add
@@ -71,7 +66,7 @@ class Metabox
$posttypes = (array)$posttypes;
foreach ($posttypes as $posttype) {
- $this->posttypes[$posttype] = $posttype;
+ $this->location('post_type', $posttype);
}
return $this;
@@ -89,13 +84,29 @@ class Metabox
$taxonomies = (array)$taxonomies;
foreach ($taxonomies as $taxonomy) {
- $this->taxonomies[$taxonomy] = $taxonomy;
+ $this->location('taxonomy', $taxonomy);
}
return $this;
}
/**
+ * Add a rule group to the acf group location
+ *
+ * @param string $param The type to check against
+ * @param string $value The value to check against
+ * @param string $operator The operator to check with
+ *
+ * @return $this
+ */
+ public function location(string $param, string $value, string $operator = '==')
+ {
+ $this->locations[] = compact('param', 'operator', 'value');
+
+ return $this;
+ }
+
+ /**
* @param MetaboxField|array $fields
*
* @return $this
@@ -133,26 +144,10 @@ class Metabox
*/
public function add()
{
- // build the post type rule groups
- $postTypeRuleGroups = array_map(function ($posttype) {
- return [[
- 'param' => 'post_type',
- 'operator' => '==',
- 'value' => $posttype,
- ]];
- }, $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);
+ // build the location rule groups
+ $ruleGroups = array_map(function ($location) {
+ return [$location];
+ }, $this->locations);
// merge with extra options
$fieldGroup = array_merge_recursive([