-
-
Notifications
You must be signed in to change notification settings - Fork 269
Expand file tree
/
Copy pathclasses.php
More file actions
338 lines (297 loc) · 7.92 KB
/
classes.php
File metadata and controls
338 lines (297 loc) · 7.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
<?php
// Don't load directly.
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* @package Pods
* @category Utilities
*/
use Pods\Whatsit\Pod;
use Pods\Pod_Manager;
/**
* Include and Init the Pods class
*
* @since 2.0.0
*
* @see Pods
*
* @param string $type The pod name, leave null to auto-detect from The Loop.
* @param mixed $id (optional) The ID or slug, to load a single record; Provide array of $params to run 'find';
* Or leave null to auto-detect from The Loop.
* @param bool $strict (optional) If set to true, returns false instead of a Pods object, if the Pod itself doesn't
* exist. Note: If you want to check if the Pods Item itself doesn't exist, use exists().
*
* @return bool|\Pods returns false if $strict, WP_DEBUG, PODS_STRICT or (PODS_DEPRECATED && PODS_STRICT_MODE) are true
*
* @link https://docs.pods.io/code/pods/
*/
function pods( $type = null, $id = null, $strict = null ) {
$pod = new Pods( $type, $id, $strict );
if ( null === $strict ) {
$strict = pods_strict();
}
if ( true === $strict && null !== $type && ! $pod->valid() ) {
return false;
}
return $pod;
}
/**
* Include and Init the Pods class with support for reuse.
*
* @since 2.9.10
*
* @see Pods
*
* @param string $type The pod name, leave null to auto-detect from The Loop.
* @param mixed $id (optional) The ID or slug, to load a single record; Provide array of $params to run 'find';
* Or leave null to auto-detect from The Loop.
* @param bool $strict (optional) If set to true, returns false instead of a Pods object, if the Pod itself doesn't
* exist. Note: If you want to check if the Pods Item itself doesn't exist, use exists().
*
* @return bool|\Pods|WP_Error returns false if $strict, WP_DEBUG, PODS_STRICT or (PODS_DEPRECATED && PODS_STRICT_MODE) are true
*
* @link https://docs.pods.io/code/pods/
*/
function pods_get_instance( $type = null, $id = null, $strict = null ) {
if ( null === $strict ) {
$strict = pods_strict( false );
}
$manager = pods_container( Pod_Manager::class );
$args = [
'name' => $type,
];
if ( $strict ) {
$args['strict'] = $strict;
}
if ( null !== $id ) {
if ( is_array( $id ) ) {
$args['find'] = $id;
} else {
$args['id'] = $id;
}
}
$pod = $manager->get_pod( $args );
if (
true === $strict
&& null !== $type
&& (
! $pod
|| ! $pod->valid()
)
) {
return false;
}
return $pod;
}
/**
* Easily create content admin screens with in-depth customization. This is the primary interface function that Pods
* runs off of. It's also the only function required to be run in order to have a fully functional Manage interface.
*
* @see PodsUI
*
* @param array|string|Pods $obj (optional) Configuration options for the UI
* @param boolean $deprecated (optional) Whether to enable deprecated options (used by pods_ui_manage)
*
* @return PodsUI
*
* @since 2.0.0
* @link https://docs.pods.io/code/pods-ui/
*/
function pods_ui( $obj, $deprecated = false ) {
return new PodsUI( $obj, $deprecated );
}
/**
* Include and get the PodsAPI object, for use with all calls that Pods makes for add, save, delete, and more.
*
* @see PodsAPI
*
* @param string $pod (optional) (deprecated) The Pod name
* @param string $format (optional) (deprecated) Format used in import() and export()
*
* @return PodsAPI
*
* @since 2.0.0
* @link https://docs.pods.io/code/pods-api/
*/
function pods_api( $pod = null, $format = null ) {
return PodsAPI::init( $pod, $format );
}
/**
* Include and Init the PodsData class.
*
* @see PodsData
*
* @param string|Pod $pod The pod object to load.
* @param null|null|string $id (optional) Id of the pod to fetch.
* @param bool $strict (optional) If true throw an error if the pod does not exist.
* @param bool $unique (optional) If true always return a unique class.
*
* @return PodsData
*
* @since 2.0.0
*
* @throws Exception
*/
function pods_data( $pod = null, $id = null, $strict = true, $unique = true ) {
if ( $unique ) {
if ( $pod instanceof Pod || $pod instanceof Pods ) {
return new PodsData( $pod, $id, $strict );
}
if ( ! in_array( $pod, array( null, false ), true ) ) {
return new PodsData( $pod, $id, $strict );
}
return new PodsData;
}
return PodsData::init( $pod, $id, $strict );
}
/**
* Include and Init the PodsFormUI class
*
* @see PodsForm
*
* @return PodsForm
*
* @since 2.0.0
*/
function pods_form() {
return PodsForm::init();
}
/**
* Include and Init the Pods class
*
* @see PodsInit
*
* @return PodsInit
*
* @since 2.0.0
*/
function pods_init() {
return PodsInit::init();
}
/**
* Include and Init the Pods Components class
*
* @see PodsComponents
*
* @return PodsComponents
*
* @since 2.0.0
*/
function pods_components() {
return PodsComponents::init();
}
/**
* Include and Init the PodsAdmin class
*
* @see PodsAdmin
*
* @return PodsAdmin
*
* @since 2.0.0
*/
function pods_admin() {
return PodsAdmin::init();
}
/**
* Include and Init the PodsMeta class
*
* @see PodsMeta
*
* @return PodsMeta
*
* @since 2.0.0
*/
function pods_meta() {
return pods_container( PodsMeta::class );
}
/**
* Include and Init the PodsArray class
*
* @see PodsArray
*
* @param mixed $container Object (or existing Array)
*
* @return PodsArray
*
* @since 2.0.0
*/
function pods_array( $container ) {
return new PodsArray( $container );
}
/**
* @since 2.7.0
*/
function pods_i18n() {
return PodsI18n::get_instance();
}
/**
* Include a file that's child/parent theme-aware, and can be cached into object cache or transients
*
* @see PodsView::view
*
* @param string $view Path of the file to be included, this is relative to the current theme
* @param array|null $data (optional) Data to pass on to the template, using variable => value format
* @param int|bool $expires (optional) Time in seconds for the cache to expire, if false caching is disabled.
* @param string $cache_mode (optional) Specify the caching method to use for the view, available options include
* cache, transient, or site-transient
* @param bool $return (optional) Whether to return the view or not, defaults to false and will echo it
* @param bool $limited (optional) Whether to limit the view to only the theme directory, defaults to false
*
* @return string|bool|null The view output
*
* @since 2.0.0
* @link https://docs.pods.io/code/pods-view/
*/
function pods_view( $view, $data = null, $expires = false, $cache_mode = 'cache', $return = false, $limited = false ) {
$view = PodsView::view( $view, $data, $expires, $cache_mode, $limited );
if ( $return ) {
return $view;
}
echo $view; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
return null;
}
/**
* Include and Init the PodsMigrate class
*
* @see PodsMigrate
*
* @param string $type Export Type (php, json, sv, xml)
* @param string $delimiter Delimiter for export type 'sv'
* @param array $data Array of data
*
* @return PodsMigrate
*
* @since 2.2.0
*/
function pods_migrate( $type = null, $delimiter = null, $data = null ) {
return new PodsMigrate( $type, $delimiter, $data );
}
/**
* Include and Init the PodsUpgrade class
*
* @param string $version Version number of upgrade to get
*
* @see PodsUpgrade
*
* @return PodsUpgrade
*
* @since 2.1.0
*/
function pods_upgrade( $version = '' ) {
include_once PODS_DIR . 'sql/upgrade/PodsUpgrade.php';
$class_name = str_replace( '.', '_', $version );
$class_name = "PodsUpgrade_{$class_name}";
$class_name = trim( $class_name, '_' );
if ( ! class_exists( $class_name ) ) {
$file = PODS_DIR . 'sql/upgrade/' . basename( $class_name ) . '.php';
if ( file_exists( $file ) ) {
include_once $file;
}
}
$class = false;
if ( class_exists( $class_name ) ) {
$class = new $class_name();
}
return $class;
}