PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.7.31.4
Pods – Custom Content Types and Fields v2.7.31.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 / components / Advanced-Relationships.php
pods / components Last commit date
Builder 3 days ago I18n 3 days ago Migrate-CPTUI 3 days ago Migrate-Packages 3 days ago Roles 3 days ago Templates 3 days ago Advanced-Content-Types.php 3 days ago Advanced-Relationships.php 3 days ago Helpers.php 3 days ago Markdown.php 3 days ago Pages.php 3 days ago Table-Storage.php 3 days ago
Advanced-Relationships.php
255 lines
1 <?php
2 /**
3 * Name: Advanced Relationships
4 *
5 * Description: Add advanced relationship objects for relating to including Database Tables, Multisite Networks, Multisite Sites, Themes, Page Templates, Sidebars, Post Type Objects, and Taxonomy Objects
6 *
7 * Version: 2.3
8 *
9 * Category: Advanced
10 *
11 * Tableless Mode: No
12 *
13 * @package Pods\Components
14 * @subpackage Advanced Relationships
15 */
16
17 if ( class_exists( 'Pods_Advanced_Relationships' ) ) {
18 return;
19 }
20
21 /**
22 * Class Pods_Advanced_Relationships
23 */
24 class Pods_Advanced_Relationships extends PodsComponent {
25
26 /**
27 * {@inheritdoc}
28 */
29 public function init() {
30
31 add_action( 'pods_form_ui_field_pick_related_objects_other', array( $this, 'add_related_objects' ) );
32 }
33
34 /**
35 * Add Advanced Related Objects
36 *
37 * @since 2.3.0
38 */
39 public function add_related_objects() {
40
41 PodsField_Pick::$related_objects['table'] = array(
42 'label' => __( 'Database Tables', 'pods' ),
43 'group' => __( 'Advanced Objects', 'pods' ),
44 );
45
46 if ( is_multisite() ) {
47 PodsField_Pick::$related_objects['site'] = array(
48 'label' => __( 'Multisite Sites', 'pods' ),
49 'group' => __( 'Advanced Objects', 'pods' ),
50 );
51
52 PodsField_Pick::$related_objects['network'] = array(
53 'label' => __( 'Multisite Networks', 'pods' ),
54 'group' => __( 'Advanced Objects', 'pods' ),
55 );
56 }
57
58 PodsField_Pick::$related_objects['theme'] = array(
59 'label' => __( 'Themes', 'pods' ),
60 'group' => __( 'Advanced Objects', 'pods' ),
61 'simple' => true,
62 'data_callback' => array( $this, 'data_themes' ),
63 );
64
65 PodsField_Pick::$related_objects['page-template'] = array(
66 'label' => __( 'Page Templates', 'pods' ),
67 'group' => __( 'Advanced Objects', 'pods' ),
68 'simple' => true,
69 'data_callback' => array( $this, 'data_page_templates' ),
70 );
71
72 PodsField_Pick::$related_objects['sidebar'] = array(
73 'label' => __( 'Sidebars', 'pods' ),
74 'group' => __( 'Advanced Objects', 'pods' ),
75 'simple' => true,
76 'data_callback' => array( $this, 'data_sidebars' ),
77 );
78
79 PodsField_Pick::$related_objects['post-types'] = array(
80 'label' => __( 'Post Type Objects', 'pods' ),
81 'group' => __( 'Advanced Objects', 'pods' ),
82 'simple' => true,
83 'data_callback' => array( $this, 'data_post_types' ),
84 );
85
86 PodsField_Pick::$related_objects['taxonomies'] = array(
87 'label' => __( 'Taxonomy Objects', 'pods' ),
88 'group' => __( 'Advanced Objects', 'pods' ),
89 'simple' => true,
90 'data_callback' => array( $this, 'data_taxonomies' ),
91 );
92 }
93
94 /**
95 * Data callback for Themes
96 *
97 * @param string $name The name of the field
98 * @param string|array $value The value of the field
99 * @param array $options Field options
100 * @param array $pod Pod data
101 * @param int $id Item ID
102 *
103 * @return array
104 *
105 * @since 2.3.0
106 */
107 public function data_themes( $name = null, $value = null, $options = null, $pod = null, $id = null ) {
108
109 $data = array();
110
111 $themes = wp_get_themes( array( 'allowed' => true ) );
112
113 foreach ( $themes as $theme ) {
114 $data[ $theme->Template ] = $theme->Name;
115 }
116
117 return apply_filters( 'pods_form_ui_field_pick_data_themes', $data, $name, $value, $options, $pod, $id );
118 }
119
120 /**
121 * Data callback for Page Templates
122 *
123 * @param string $name The name of the field
124 * @param string|array $value The value of the field
125 * @param array $options Field options
126 * @param array $pod Pod data
127 * @param int $id Item ID
128 *
129 * @return array
130 *
131 * @since 2.3.0
132 */
133 public function data_page_templates( $name = null, $value = null, $options = null, $pod = null, $id = null ) {
134
135 $data = array();
136
137 if ( ! function_exists( 'get_page_templates' ) ) {
138 include_once ABSPATH . 'wp-admin/includes/theme.php';
139 }
140
141 $page_templates = apply_filters( 'pods_page_templates', get_page_templates() );
142
143 if ( ! in_array( 'page.php', $page_templates, true ) && locate_template( array( 'page.php', false ) ) ) {
144 $page_templates['Page (WP Default)'] = 'page.php';
145 }
146
147 if ( ! in_array( 'index.php', $page_templates, true ) && locate_template( array( 'index.php', false ) ) ) {
148 $page_templates['Index (WP Fallback)'] = 'index.php';
149 }
150
151 ksort( $page_templates );
152
153 $page_templates = array_flip( $page_templates );
154
155 foreach ( $page_templates as $page_template_file => $page_template ) {
156 $data[ $page_template_file ] = $page_template;
157 }
158
159 return apply_filters( 'pods_form_ui_field_pick_data_page_templates', $data, $name, $value, $options, $pod, $id );
160 }
161
162 /**
163 * Data callback for Sidebars
164 *
165 * @param string $name The name of the field
166 * @param string|array $value The value of the field
167 * @param array $options Field options
168 * @param array $pod Pod data
169 * @param int $id Item ID
170 *
171 * @return array
172 *
173 * @since 2.3.0
174 */
175 public function data_sidebars( $name = null, $value = null, $options = null, $pod = null, $id = null ) {
176
177 $data = array();
178
179 global $wp_registered_sidebars;
180
181 if ( ! empty( $wp_registered_sidebars ) ) {
182 foreach ( $wp_registered_sidebars as $sidebar ) {
183 $data[ $sidebar['id'] ] = $sidebar['name'];
184 }
185 }
186
187 return apply_filters( 'pods_form_ui_field_pick_data_sidebars', $data, $name, $value, $options, $pod, $id );
188 }
189
190 /**
191 * Data callback for Post Types
192 *
193 * @param string $name The name of the field
194 * @param string|array $value The value of the field
195 * @param array $options Field options
196 * @param array $pod Pod data
197 * @param int $id Item ID
198 *
199 * @return array
200 *
201 * @since 2.3.0
202 */
203 public function data_post_types( $name = null, $value = null, $options = null, $pod = null, $id = null ) {
204
205 $data = array();
206
207 $post_types = get_post_types( array(), 'objects' );
208
209 $ignore = array( 'revision', 'nav_menu_item' );
210
211 foreach ( $post_types as $post_type ) {
212 if ( in_array( $post_type->name, $ignore, true ) || 0 === strpos( $post_type->name, '_pods_' ) ) {
213 continue;
214 }
215
216 $data[ $post_type->name ] = $post_type->label;
217 }
218
219 return apply_filters( 'pods_form_ui_field_pick_data_post_types', $data, $name, $value, $options, $pod, $id );
220 }
221
222 /**
223 * Data callback for Taxonomies
224 *
225 * @param string $name The name of the field
226 * @param string|array $value The value of the field
227 * @param array $options Field options
228 * @param array $pod Pod data
229 * @param int $id Item ID
230 *
231 * @return array
232 *
233 * @since 2.3.0
234 */
235 public function data_taxonomies( $name = null, $value = null, $options = null, $pod = null, $id = null ) {
236
237 $data = array();
238
239 $taxonomies = get_taxonomies( array(), 'objects' );
240
241 $ignore = array( 'nav_menu', 'post_format' );
242
243 foreach ( $taxonomies as $taxonomy ) {
244 if ( in_array( $taxonomy->name, $ignore, true ) ) {
245 continue;
246 }
247
248 $data[ $taxonomy->name ] = $taxonomy->label;
249 }
250
251 return apply_filters( 'pods_form_ui_field_pick_data_taxonomies', $data, $name, $value, $options, $pod, $id );
252 }
253
254 }
255