PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / trunk
Pods – Custom Content Types and Fields vtrunk
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
I18n 4 months ago Migrate-ACF 4 months ago Migrate-CPTUI 4 months ago Migrate-PHP 3 months ago Migrate-Packages 4 months ago Roles 4 months ago Templates 4 months ago Advanced-Content-Types.php 4 months ago Advanced-Relationships.php 4 months ago Markdown.php 4 months ago Pages.php 4 months ago Table-Storage.php 4 months ago
Advanced-Relationships.php
186 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 // Don't load directly.
18 if ( ! defined( 'ABSPATH' ) ) {
19 die( '-1' );
20 }
21
22 if ( class_exists( 'Pods_Advanced_Relationships' ) ) {
23 return;
24 }
25
26 /**
27 * Class Pods_Advanced_Relationships
28 */
29 class Pods_Advanced_Relationships extends PodsComponent {
30
31 /**
32 * {@inheritdoc}
33 */
34 public function init() {
35 // Bypass if Pods is in types-only mode.
36 if ( pods_is_types_only() ) {
37 return;
38 }
39
40 add_action( 'pods_form_ui_field_pick_related_objects_other', array( $this, 'add_related_objects' ) );
41 }
42
43 /**
44 * Add Advanced Related Objects
45 *
46 * @since 2.3.0
47 */
48 public function add_related_objects() {
49
50 PodsField_Pick::$related_objects['table'] = array(
51 'label' => __( 'Database Tables', 'pods' ),
52 'group' => __( 'Advanced Objects', 'pods' ),
53 );
54
55 if ( is_multisite() ) {
56 PodsField_Pick::$related_objects['site'] = array(
57 'label' => __( 'Multisite Sites', 'pods' ),
58 'group' => __( 'Advanced Objects', 'pods' ),
59 );
60
61 PodsField_Pick::$related_objects['network'] = array(
62 'label' => __( 'Multisite Networks', 'pods' ),
63 'group' => __( 'Advanced Objects', 'pods' ),
64 );
65 }
66
67 PodsField_Pick::$related_objects['theme'] = array(
68 'label' => __( 'Themes', 'pods' ),
69 'group' => __( 'Advanced Objects', 'pods' ),
70 'simple' => true,
71 'data_callback' => array( $this, 'data_themes' ),
72 );
73
74 PodsField_Pick::$related_objects['page-template'] = array(
75 'label' => __( 'Page Templates', 'pods' ),
76 'group' => __( 'Advanced Objects', 'pods' ),
77 'simple' => true,
78 'data_callback' => array( $this, 'data_page_templates' ),
79 );
80
81 PodsField_Pick::$related_objects['sidebar'] = array(
82 'label' => __( 'Sidebars', 'pods' ),
83 'group' => __( 'Advanced Objects', 'pods' ),
84 'simple' => true,
85 'data_callback' => array( $this, 'data_sidebars' ),
86 );
87 }
88
89 /**
90 * Data callback for Themes
91 *
92 * @param string $name The name of the field
93 * @param string|array $value The value of the field
94 * @param array $options Field options
95 * @param array $pod Pod data
96 * @param int $id Item ID
97 *
98 * @return array
99 *
100 * @since 2.3.0
101 */
102 public function data_themes( $name = null, $value = null, $options = null, $pod = null, $id = null ) {
103
104 $data = array();
105
106 $themes = wp_get_themes( array( 'allowed' => true ) );
107
108 foreach ( $themes as $theme ) {
109 $data[ $theme->Template ] = $theme->Name;
110 }
111
112 return apply_filters( 'pods_form_ui_field_pick_data_themes', $data, $name, $value, $options, $pod, $id );
113 }
114
115 /**
116 * Data callback for Page Templates
117 *
118 * @param string $name The name of the field
119 * @param string|array $value The value of the field
120 * @param array $options Field options
121 * @param array $pod Pod data
122 * @param int $id Item ID
123 *
124 * @return array
125 *
126 * @since 2.3.0
127 */
128 public function data_page_templates( $name = null, $value = null, $options = null, $pod = null, $id = null ) {
129
130 $data = array();
131
132 if ( ! function_exists( 'get_page_templates' ) ) {
133 include_once ABSPATH . 'wp-admin/includes/theme.php';
134 }
135
136 $page_templates = apply_filters( 'pods_page_templates', get_page_templates() );
137
138 if ( ! in_array( 'page.php', $page_templates, true ) && locate_template( array( 'page.php', false ) ) ) {
139 $page_templates['Page (WP Default)'] = 'page.php';
140 }
141
142 if ( ! in_array( 'index.php', $page_templates, true ) && locate_template( array( 'index.php', false ) ) ) {
143 $page_templates['Index (WP Fallback)'] = 'index.php';
144 }
145
146 ksort( $page_templates );
147
148 $page_templates = array_flip( $page_templates );
149
150 foreach ( $page_templates as $page_template_file => $page_template ) {
151 $data[ $page_template_file ] = $page_template;
152 }
153
154 return apply_filters( 'pods_form_ui_field_pick_data_page_templates', $data, $name, $value, $options, $pod, $id );
155 }
156
157 /**
158 * Data callback for Sidebars
159 *
160 * @param string $name The name of the field
161 * @param string|array $value The value of the field
162 * @param array $options Field options
163 * @param array $pod Pod data
164 * @param int $id Item ID
165 *
166 * @return array
167 *
168 * @since 2.3.0
169 */
170 public function data_sidebars( $name = null, $value = null, $options = null, $pod = null, $id = null ) {
171
172 $data = array();
173
174 global $wp_registered_sidebars;
175
176 if ( ! empty( $wp_registered_sidebars ) ) {
177 foreach ( $wp_registered_sidebars as $sidebar ) {
178 $data[ $sidebar['id'] ] = $sidebar['name'];
179 }
180 }
181
182 return apply_filters( 'pods_form_ui_field_pick_data_sidebars', $data, $name, $value, $options, $pod, $id );
183 }
184
185 }
186