PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.8.23.4
Pods – Custom Content Types and Fields v2.8.23.4
2.7.31.4 2.8.23.5 2.9.19.5 3.0.10.5 3.1.4.3 3.2.8.4 3.3.9.2 2.8.23.4 2.9.19.4 3.0.10.4 3.1.4.2 3.2.8.3 3.3.9.1 trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / src / Pods / Whatsit / Group.php
pods / src / Pods / Whatsit Last commit date
Storage 3 weeks ago Block.php 3 weeks ago Block_Collection.php 3 weeks ago Block_Field.php 3 weeks ago Field.php 3 weeks ago Group.php 3 weeks ago Legacy_Object.php 3 weeks ago Object_Field.php 3 weeks ago Page.php 3 weeks ago Pod.php 3 weeks ago Storage.php 3 weeks ago Store.php 3 weeks ago Template.php 3 weeks ago
Group.php
129 lines
1 <?php
2
3 namespace Pods\Whatsit;
4
5 use Pods\Whatsit;
6
7 /**
8 * Group class.
9 *
10 * @since 2.8.0
11 */
12 class Group extends Whatsit {
13
14 /**
15 * {@inheritdoc}
16 */
17 protected static $type = 'group';
18
19 /**
20 * {@inheritdoc}
21 */
22 public function get_args() {
23 $args = parent::get_args();
24
25 // Groups have no group.
26 unset( $args['group'] );
27
28 return $args;
29 }
30
31 /**
32 * {@inheritdoc}
33 */
34 public function get_fields( array $args = [] ) {
35 if ( [] === $this->_fields ) {
36 return [];
37 }
38
39 $object_collection = Store::get_instance();
40
41 $has_custom_args = ! empty( $args );
42
43 if ( null === $this->_fields || $has_custom_args ) {
44 $filtered_args = [
45 'parent' => $this->get_parent_id(),
46 'parent_id' => $this->get_parent_id(),
47 'parent_name' => $this->get_parent_name(),
48 'parent_identifier' => $this->get_parent_identifier(),
49 'group' => $this->get_name(),
50 'group_id' => $this->get_id(),
51 'group_name' => $this->get_name(),
52 'group_identifier' => $this->get_identifier(),
53 ];
54
55 if ( empty( $filtered_args['parent_id'] ) || empty( $filtered_args['group_id'] ) ) {
56 $filtered_args['bypass_post_type_find'] = true;
57 }
58
59 $filtered_args = array_filter( $filtered_args );
60
61 $args = array_merge( [
62 'orderby' => 'menu_order title',
63 'order' => 'ASC',
64 ], $filtered_args, $args );
65
66 try {
67 $api = pods_api();
68
69 if ( ! empty( $args['object_type'] ) ) {
70 $objects = $api->_load_objects( $args );
71 } else {
72 $objects = $api->load_fields( $args );
73 }
74 } catch ( \Exception $exception ) {
75 $objects = [];
76 }
77
78 if ( ! $has_custom_args ) {
79 $this->_fields = wp_list_pluck( $objects, 'identifier' );
80 }
81
82 return $objects;
83 }
84
85 $objects = array_map( [ $object_collection, 'get_object' ], $this->_fields );
86 $objects = array_filter( $objects );
87
88 $names = wp_list_pluck( $objects, 'name' );
89
90 return array_combine( $names, $objects );
91 }
92
93 /**
94 * {@inheritdoc}
95 */
96 public function get_groups( array $args = [] ) {
97 // Groups do not support groups.
98 return [];
99 }
100
101 /**
102 * {@inheritdoc}
103 */
104 public function get_arg( $arg, $default = null, $strict = false ) {
105 $arg = (string) $arg;
106
107 $special_args = [
108 // Pod args.
109 'pod_id' => 'get_parent_id',
110 'pod' => 'get_parent_name',
111 'pod_name' => 'get_parent_name',
112 'pod_identifier' => 'get_parent_identifier',
113 'pod_label' => 'get_parent_label',
114 'pod_description' => 'get_parent_description',
115 'pod_object' => 'get_parent_object',
116 'pod_object_type' => 'get_parent_object_type',
117 'pod_object_storage_type' => 'get_parent_object_storage_type',
118 'pod_type' => 'get_parent_type',
119 ];
120
121 if ( isset( $special_args[ $arg ] ) ) {
122 return $this->{$special_args[ $arg ]}();
123 }
124
125 return parent::get_arg( $arg, $default );
126 }
127
128 }
129