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