Version Description
- June 4th, 2020 =
- Security: Remove deprecated usage of escapeMarkup in Select2 (@sc0ttkclark, @miha.jirov)
Download this release
Release Info
| Developer | sc0ttkclark |
| Plugin | |
| Version | 2.5.5.1 |
| Comparing to | |
| See all releases | |
Code changes from version 2.7.23 to 2.5.5.1
- classes/Pods.php +1639 -2331
- classes/PodsAPI.php +7521 -8888
- classes/PodsAdmin.php +2257 -3733
- classes/PodsArray.php +110 -247
classes/Pods.php
CHANGED
|
@@ -1,393 +1,285 @@
|
|
| 1 |
<?php
|
| 2 |
-
|
| 3 |
/**
|
| 4 |
-
* Pods class.
|
| 5 |
-
*
|
| 6 |
* @package Pods
|
| 7 |
*/
|
| 8 |
class Pods implements Iterator {
|
| 9 |
|
| 10 |
/**
|
| 11 |
-
* Whether the Pods object is in a PHP Iterator call.
|
| 12 |
-
*
|
| 13 |
* @var bool
|
| 14 |
*/
|
| 15 |
private $iterator = false;
|
| 16 |
|
| 17 |
/**
|
| 18 |
-
* PodsAPI object.
|
| 19 |
-
*
|
| 20 |
* @var PodsAPI
|
| 21 |
*/
|
| 22 |
public $api;
|
| 23 |
|
| 24 |
/**
|
| 25 |
-
* PodsData object.
|
| 26 |
-
*
|
| 27 |
* @var PodsData
|
| 28 |
*/
|
| 29 |
public $data;
|
| 30 |
|
| 31 |
/**
|
| 32 |
-
* PodsData object for additional calls.
|
| 33 |
-
*
|
| 34 |
* @var PodsData
|
| 35 |
*/
|
| 36 |
public $alt_data;
|
| 37 |
|
| 38 |
/**
|
| 39 |
-
* Array of pod item arrays
|
| 40 |
-
*
|
| 41 |
-
* @var array
|
| 42 |
*/
|
| 43 |
-
public $rows;
|
| 44 |
|
| 45 |
/**
|
| 46 |
-
* Current pod item array
|
| 47 |
-
*
|
| 48 |
-
* @var array
|
| 49 |
*/
|
| 50 |
-
public $row;
|
| 51 |
|
| 52 |
/**
|
| 53 |
-
* Row number.
|
| 54 |
-
*
|
| 55 |
* @var int
|
| 56 |
*/
|
| 57 |
-
private $row_number;
|
| 58 |
|
| 59 |
/**
|
| 60 |
-
* Override pod item array
|
| 61 |
-
*
|
| 62 |
-
* @var array
|
| 63 |
*/
|
| 64 |
public $row_override = array();
|
| 65 |
|
| 66 |
/**
|
| 67 |
-
* Whether to display errors on the screen.
|
| 68 |
-
*
|
| 69 |
* @var bool
|
| 70 |
*/
|
| 71 |
public $display_errors = true;
|
| 72 |
|
| 73 |
/**
|
| 74 |
-
* Current pod information.
|
| 75 |
-
*
|
| 76 |
* @var array|bool|mixed|null|void
|
| 77 |
*/
|
| 78 |
public $pod_data;
|
| 79 |
|
| 80 |
/**
|
| 81 |
-
* Last used Pods::find() parameters.
|
| 82 |
-
*
|
| 83 |
* @var array
|
| 84 |
*/
|
| 85 |
public $params = array();
|
| 86 |
|
| 87 |
/**
|
| 88 |
-
* Current Pod name.
|
| 89 |
-
*
|
| 90 |
* @var string
|
| 91 |
*/
|
| 92 |
-
public $pod;
|
| 93 |
|
| 94 |
/**
|
| 95 |
-
* Current Pod ID.
|
| 96 |
-
*
|
| 97 |
* @var int
|
| 98 |
*/
|
| 99 |
-
public $pod_id;
|
| 100 |
|
| 101 |
/**
|
| 102 |
-
* Pod fields information.
|
| 103 |
-
*
|
| 104 |
* @var array
|
| 105 |
*/
|
| 106 |
-
public $fields;
|
| 107 |
|
| 108 |
/**
|
| 109 |
-
* Last used filters() parameters.
|
| 110 |
-
*
|
| 111 |
* @var array
|
| 112 |
*/
|
| 113 |
public $filters = array();
|
| 114 |
|
| 115 |
/**
|
| 116 |
-
* Detail page URL used for Advanced Content Types.
|
| 117 |
-
*
|
| 118 |
* @var string
|
| 119 |
*/
|
| 120 |
public $detail_page;
|
| 121 |
|
| 122 |
/**
|
| 123 |
-
* Current Item ID.
|
| 124 |
-
*
|
| 125 |
* @var int
|
| 126 |
*/
|
| 127 |
-
public $id;
|
| 128 |
|
| 129 |
/**
|
| 130 |
-
* Last used limit from find() lookup.
|
| 131 |
-
*
|
| 132 |
* @var int
|
| 133 |
*/
|
| 134 |
public $limit = 15;
|
| 135 |
|
| 136 |
/**
|
| 137 |
-
* Last used offset from find() lookup.
|
| 138 |
-
*
|
| 139 |
* @var int
|
| 140 |
*/
|
| 141 |
public $offset = 0;
|
| 142 |
|
| 143 |
/**
|
| 144 |
-
* Query variable used for pagination number.
|
| 145 |
-
*
|
| 146 |
* @var string
|
| 147 |
*/
|
| 148 |
public $page_var = 'pg';
|
| 149 |
|
| 150 |
/**
|
| 151 |
-
* Last used page from find() lookup.
|
| 152 |
-
*
|
| 153 |
* @var int|mixed
|
| 154 |
*/
|
| 155 |
public $page = 1;
|
| 156 |
|
| 157 |
/**
|
| 158 |
-
* Last used state of whether pagination was enabled from find() lookup.
|
| 159 |
-
*
|
| 160 |
* @var bool
|
| 161 |
*/
|
| 162 |
public $pagination = true;
|
| 163 |
|
| 164 |
/**
|
| 165 |
-
* Last used state of whether search was enabled from find() lookup.
|
| 166 |
-
*
|
| 167 |
* @var bool
|
| 168 |
*/
|
| 169 |
public $search = true;
|
| 170 |
|
| 171 |
/**
|
| 172 |
-
* Query variable used for search string.
|
| 173 |
-
*
|
| 174 |
* @var string
|
| 175 |
*/
|
| 176 |
public $search_var = 'search';
|
| 177 |
|
| 178 |
/**
|
| 179 |
-
* Search mode (int | text | text_like).
|
| 180 |
-
*
|
| 181 |
* @var string
|
| 182 |
*/
|
| 183 |
-
public $search_mode = 'int';
|
| 184 |
|
| 185 |
/**
|
| 186 |
-
* Total number of records returned from find() lookup.
|
| 187 |
-
*
|
| 188 |
* @var int
|
| 189 |
*/
|
| 190 |
public $total = 0;
|
| 191 |
|
| 192 |
/**
|
| 193 |
-
* Total number of records found from find() lookup.
|
| 194 |
-
*
|
| 195 |
* @var int
|
| 196 |
*/
|
| 197 |
public $total_found = 0;
|
| 198 |
|
| 199 |
/**
|
| 200 |
-
* Last used ui options for ui() call.
|
| 201 |
-
*
|
| 202 |
* @var array
|
| 203 |
*/
|
| 204 |
public $ui = array();
|
| 205 |
|
| 206 |
/**
|
| 207 |
-
*
|
| 208 |
-
*
|
| 209 |
-
* @var string
|
| 210 |
*/
|
| 211 |
public $page_template;
|
| 212 |
-
|
| 213 |
-
/**
|
| 214 |
-
* Body classes to use for SEO feature in Pods Pages.
|
| 215 |
-
*
|
| 216 |
-
* @var array
|
| 217 |
-
*/
|
| 218 |
public $body_classes;
|
| 219 |
-
|
| 220 |
-
/**
|
| 221 |
-
* Meta tags to use for SEO feature in Pods Pages.
|
| 222 |
-
*
|
| 223 |
-
* @var array
|
| 224 |
-
*/
|
| 225 |
public $meta = array();
|
| 226 |
-
|
| 227 |
-
/**
|
| 228 |
-
* Meta properties to use for SEO feature in Pods Pages.
|
| 229 |
-
*
|
| 230 |
-
* @var array
|
| 231 |
-
*/
|
| 232 |
public $meta_properties = array();
|
| 233 |
-
|
| 234 |
-
/**
|
| 235 |
-
* Meta custom HTML to use for SEO feature in Pods Pages.
|
| 236 |
-
*
|
| 237 |
-
* @var string
|
| 238 |
-
*/
|
| 239 |
public $meta_extra = '';
|
| 240 |
|
| 241 |
/**
|
| 242 |
-
* Last SQL query used by a find()
|
| 243 |
-
*
|
| 244 |
-
* @var string
|
| 245 |
*/
|
| 246 |
public $sql;
|
| 247 |
|
| 248 |
/**
|
| 249 |
-
*
|
| 250 |
-
*
|
| 251 |
-
* @var Pods_Deprecated
|
| 252 |
*/
|
| 253 |
public $deprecated;
|
| 254 |
|
| 255 |
-
/**
|
| 256 |
-
* Old Pod name variable.
|
| 257 |
-
*
|
| 258 |
-
* @var string
|
| 259 |
-
*
|
| 260 |
-
* @deprecated 2.0.0
|
| 261 |
-
*/
|
| 262 |
public $datatype;
|
| 263 |
|
| 264 |
-
/**
|
| 265 |
-
* Old Pod ID variable.
|
| 266 |
-
*
|
| 267 |
-
* @var int
|
| 268 |
-
*
|
| 269 |
-
* @deprecated 2.0.0
|
| 270 |
-
*/
|
| 271 |
public $datatype_id;
|
| 272 |
|
| 273 |
/**
|
| 274 |
-
* Constructor - Pods Framework core
|
| 275 |
*
|
| 276 |
-
* @param string $pod The pod name
|
| 277 |
-
* @param mixed
|
|
|
|
|
|
|
| 278 |
*
|
| 279 |
* @license http://www.gnu.org/licenses/gpl-2.0.html
|
| 280 |
-
* @since
|
| 281 |
-
* @link
|
| 282 |
*/
|
| 283 |
-
public function __construct( $pod = null, $id = null ) {
|
| 284 |
-
|
| 285 |
if ( null === $pod ) {
|
| 286 |
-
$
|
| 287 |
-
}
|
| 288 |
|
| 289 |
-
|
| 290 |
-
if ( $pod instanceof WP_Post ) {
|
| 291 |
-
// Post Type Singular.
|
| 292 |
-
$pod = $pod->post_type;
|
| 293 |
-
$id_lookup = true;
|
| 294 |
-
} elseif ( $pod instanceof WP_Term ) {
|
| 295 |
-
// Term Archive.
|
| 296 |
-
$pod = $pod->taxonomy;
|
| 297 |
$id_lookup = true;
|
| 298 |
-
} elseif ( $pod instanceof WP_User ) {
|
| 299 |
-
// Author Archive.
|
| 300 |
-
$pod = 'user';
|
| 301 |
-
$id_lookup = true;
|
| 302 |
-
} elseif ( $pod instanceof WP_Post_Type ) {
|
| 303 |
-
// Post Type Archive.
|
| 304 |
-
$pod = $pod->name;
|
| 305 |
-
$id_lookup = false;
|
| 306 |
-
} else {
|
| 307 |
-
// Unsupported pod object.
|
| 308 |
-
$pod = null;
|
| 309 |
-
$id_lookup = false;
|
| 310 |
-
}
|
| 311 |
|
| 312 |
-
|
| 313 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 314 |
}
|
| 315 |
-
}
|
| 316 |
|
| 317 |
-
$this->api
|
| 318 |
$this->api->display_errors =& $this->display_errors;
|
| 319 |
|
| 320 |
-
$this->data
|
| 321 |
PodsData::$display_errors =& $this->display_errors;
|
| 322 |
|
| 323 |
-
// Set up page variable
|
| 324 |
if ( pods_strict( false ) ) {
|
| 325 |
-
$this->page
|
| 326 |
$this->pagination = false;
|
| 327 |
-
$this->search
|
| 328 |
-
}
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
$this->page = max( 1, pods_absint( $this->page ) );
|
| 334 |
-
}
|
| 335 |
}
|
| 336 |
|
| 337 |
-
// Set default pagination handling to on/off
|
| 338 |
if ( defined( 'PODS_GLOBAL_POD_PAGINATION' ) ) {
|
| 339 |
-
if ( !
|
| 340 |
-
$this->page
|
| 341 |
$this->pagination = false;
|
| 342 |
-
} else {
|
| 343 |
-
$this->pagination = true;
|
| 344 |
}
|
|
|
|
|
|
|
| 345 |
}
|
| 346 |
|
| 347 |
-
// Set default search to on/off
|
| 348 |
if ( defined( 'PODS_GLOBAL_POD_SEARCH' ) ) {
|
| 349 |
-
if ( PODS_GLOBAL_POD_SEARCH )
|
| 350 |
$this->search = true;
|
| 351 |
-
|
| 352 |
$this->search = false;
|
| 353 |
-
}
|
| 354 |
}
|
| 355 |
|
| 356 |
-
// Set default search mode
|
| 357 |
$allowed_search_modes = array( 'int', 'text', 'text_like' );
|
| 358 |
|
| 359 |
-
if ( defined( 'PODS_GLOBAL_POD_SEARCH_MODE' ) && in_array( PODS_GLOBAL_POD_SEARCH_MODE, $allowed_search_modes
|
| 360 |
$this->search_mode = PODS_GLOBAL_POD_SEARCH_MODE;
|
| 361 |
-
}
|
| 362 |
|
| 363 |
-
// Sync Settings
|
| 364 |
-
$this->data->page
|
| 365 |
-
$this->data->limit
|
| 366 |
-
$this->data->pagination
|
| 367 |
-
$this->data->search
|
| 368 |
$this->data->search_mode =& $this->search_mode;
|
| 369 |
|
| 370 |
-
// Sync Pod Data
|
| 371 |
$this->api->pod_data =& $this->data->pod_data;
|
| 372 |
-
$this->pod_data
|
| 373 |
-
$this->api->pod_id
|
| 374 |
-
$this->pod_id
|
| 375 |
-
$this->datatype_id
|
| 376 |
-
$this->api->pod
|
| 377 |
-
$this->pod
|
| 378 |
-
$this->datatype
|
| 379 |
-
$this->api->fields
|
| 380 |
-
$this->fields
|
| 381 |
-
$this->detail_page
|
| 382 |
-
$this->id
|
| 383 |
-
$this->row
|
| 384 |
-
$this->rows
|
| 385 |
-
$this->row_number
|
| 386 |
-
$this->sql
|
| 387 |
-
|
| 388 |
-
if ( is_array( $id ) || is_object( $id ) )
|
| 389 |
$this->find( $id );
|
| 390 |
-
}
|
| 391 |
}
|
| 392 |
|
| 393 |
/**
|
|
@@ -395,17 +287,14 @@ class Pods implements Iterator {
|
|
| 395 |
*
|
| 396 |
* @return bool
|
| 397 |
*
|
| 398 |
-
* @since 2.0
|
| 399 |
*/
|
| 400 |
-
public function valid() {
|
| 401 |
-
|
| 402 |
-
if ( empty( $this->pod_id ) ) {
|
| 403 |
return false;
|
| 404 |
-
}
|
| 405 |
|
| 406 |
-
if ( $this->iterator )
|
| 407 |
return isset( $this->rows[ $this->row_number ] );
|
| 408 |
-
}
|
| 409 |
|
| 410 |
return true;
|
| 411 |
}
|
|
@@ -417,10 +306,9 @@ class Pods implements Iterator {
|
|
| 417 |
*
|
| 418 |
* @since 2.3.4
|
| 419 |
*
|
| 420 |
-
* @link
|
| 421 |
*/
|
| 422 |
-
public function is_iterator() {
|
| 423 |
-
|
| 424 |
return $this->iterator;
|
| 425 |
}
|
| 426 |
|
|
@@ -431,28 +319,31 @@ class Pods implements Iterator {
|
|
| 431 |
*
|
| 432 |
* @since 2.3.4
|
| 433 |
*
|
| 434 |
-
* @link
|
| 435 |
*/
|
| 436 |
-
public function stop_iterator() {
|
| 437 |
-
|
| 438 |
$this->iterator = false;
|
| 439 |
|
|
|
|
| 440 |
}
|
| 441 |
|
| 442 |
/**
|
| 443 |
* Rewind Iterator
|
| 444 |
*
|
|
|
|
|
|
|
| 445 |
* @since 2.3.4
|
| 446 |
*
|
| 447 |
-
* @link
|
| 448 |
*/
|
| 449 |
-
public function rewind() {
|
| 450 |
-
|
| 451 |
-
if ( ! $this->iterator ) {
|
| 452 |
-
$this->iterator = true;
|
| 453 |
-
|
| 454 |
$this->row_number = 0;
|
|
|
|
|
|
|
| 455 |
}
|
|
|
|
|
|
|
| 456 |
}
|
| 457 |
|
| 458 |
/**
|
|
@@ -462,13 +353,11 @@ class Pods implements Iterator {
|
|
| 462 |
*
|
| 463 |
* @since 2.3.4
|
| 464 |
*
|
| 465 |
-
* @link
|
| 466 |
*/
|
| 467 |
-
public function current() {
|
| 468 |
-
|
| 469 |
-
if ( $this->iterator && $this->fetch() ) {
|
| 470 |
return $this;
|
| 471 |
-
}
|
| 472 |
|
| 473 |
return false;
|
| 474 |
}
|
|
@@ -476,29 +365,36 @@ class Pods implements Iterator {
|
|
| 476 |
/**
|
| 477 |
* Get current Iterator key
|
| 478 |
*
|
| 479 |
-
* @return int
|
| 480 |
*
|
| 481 |
* @since 2.3.4
|
| 482 |
*
|
| 483 |
-
* @link
|
| 484 |
*/
|
| 485 |
-
public function key() {
|
|
|
|
|
|
|
| 486 |
|
| 487 |
-
return
|
| 488 |
}
|
| 489 |
|
| 490 |
/**
|
| 491 |
* Move onto the next Iterator row
|
| 492 |
*
|
| 493 |
-
* @return void
|
| 494 |
*
|
| 495 |
* @since 2.3.4
|
| 496 |
*
|
| 497 |
-
* @link
|
| 498 |
*/
|
| 499 |
-
public function next() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 500 |
|
| 501 |
-
|
| 502 |
}
|
| 503 |
|
| 504 |
/**
|
|
@@ -506,13 +402,11 @@ class Pods implements Iterator {
|
|
| 506 |
*
|
| 507 |
* @return bool
|
| 508 |
*
|
| 509 |
-
* @since 2.0
|
| 510 |
*/
|
| 511 |
-
public function exists() {
|
| 512 |
-
|
| 513 |
-
if ( empty( $this->row ) ) {
|
| 514 |
return false;
|
| 515 |
-
}
|
| 516 |
|
| 517 |
return true;
|
| 518 |
}
|
|
@@ -525,16 +419,14 @@ class Pods implements Iterator {
|
|
| 525 |
*
|
| 526 |
* @return array|bool An array of all rows returned from a find() call, or false if no items returned
|
| 527 |
*
|
| 528 |
-
* @since 2.0
|
| 529 |
-
* @link
|
| 530 |
*/
|
| 531 |
-
public function data() {
|
| 532 |
-
|
| 533 |
do_action( 'pods_pods_data', $this );
|
| 534 |
|
| 535 |
-
if ( empty( $this->rows ) )
|
| 536 |
return false;
|
| 537 |
-
}
|
| 538 |
|
| 539 |
return (array) $this->rows;
|
| 540 |
}
|
|
@@ -542,9 +434,9 @@ class Pods implements Iterator {
|
|
| 542 |
/**
|
| 543 |
* Return a field input for a specific field
|
| 544 |
*
|
| 545 |
-
* @param string|array
|
| 546 |
-
* @param string
|
| 547 |
-
* @param mixed
|
| 548 |
*
|
| 549 |
* @return string Field Input HTML
|
| 550 |
*
|
|
@@ -552,28 +444,25 @@ class Pods implements Iterator {
|
|
| 552 |
*/
|
| 553 |
public function input( $field, $input_name = null, $value = '__null' ) {
|
| 554 |
|
|
|
|
| 555 |
if ( is_array( $field ) ) {
|
| 556 |
-
// Field data override.
|
| 557 |
$field_data = $field;
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
$field_data = $this->fields( $field );
|
| 563 |
}
|
| 564 |
|
| 565 |
-
if ( !
|
| 566 |
-
$field_type =
|
| 567 |
|
| 568 |
if ( empty( $input_name ) ) {
|
| 569 |
$input_name = $field;
|
| 570 |
}
|
| 571 |
|
| 572 |
-
if ( '__null'
|
| 573 |
-
$value = $this->field( array(
|
| 574 |
-
'name' => $field,
|
| 575 |
-
'in_form' => true,
|
| 576 |
-
) );
|
| 577 |
}
|
| 578 |
|
| 579 |
return PodsForm::field( $input_name, $value, $field_type, $field_data, $this, $this->id() );
|
|
@@ -586,61 +475,51 @@ class Pods implements Iterator {
|
|
| 586 |
/**
|
| 587 |
* Return field array from a Pod, a field's data, or a field option
|
| 588 |
*
|
| 589 |
-
* @param null $field
|
| 590 |
-
* @param null $option
|
| 591 |
*
|
| 592 |
* @return bool|mixed
|
| 593 |
*
|
| 594 |
-
* @since 2.0
|
| 595 |
*/
|
| 596 |
-
public function fields( $field = null, $option = null ) {
|
| 597 |
-
|
| 598 |
-
$
|
| 599 |
-
|
| 600 |
-
if ( empty( $this->fields ) ) {
|
| 601 |
-
// No fields found.
|
| 602 |
$field_data = array();
|
| 603 |
-
|
| 604 |
-
|
| 605 |
$field_data = (array) $this->fields;
|
| 606 |
-
|
| 607 |
-
|
| 608 |
$field_data = array();
|
| 609 |
-
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
|
| 615 |
-
}
|
| 616 |
-
} else {
|
| 617 |
-
$options = array();
|
| 618 |
|
| 619 |
-
|
| 620 |
-
if ( isset( $this->fields[ $field ] ) ) {
|
| 621 |
-
$options = array_merge( $this->fields[ $field ], $this->fields[ $field ]['options'] );
|
| 622 |
-
} elseif ( isset( $this->pod_data['object_fields'] ) ) {
|
| 623 |
-
$options = array_merge( $this->pod_data['object_fields'][ $field ], $this->pod_data['object_fields'][ $field ]['options'] );
|
| 624 |
-
}
|
| 625 |
|
| 626 |
-
|
| 627 |
-
|
| 628 |
$field_data = PodsForm::field_method( 'pick', 'get_field_data', $options );
|
| 629 |
-
}
|
| 630 |
-
|
|
|
|
| 631 |
$field_data = $options[ $option ];
|
| 632 |
}
|
| 633 |
-
}
|
| 634 |
|
| 635 |
/**
|
| 636 |
* Modify the field data before returning
|
| 637 |
*
|
| 638 |
* @since unknown
|
| 639 |
*
|
| 640 |
-
* @param array
|
| 641 |
-
* @param string|null $field
|
| 642 |
-
* @param string|null $option
|
| 643 |
-
* @param Pods|object $this
|
| 644 |
*/
|
| 645 |
return apply_filters( 'pods_pods_fields', $field_data, $field, $option, $this );
|
| 646 |
|
|
@@ -649,17 +528,15 @@ class Pods implements Iterator {
|
|
| 649 |
/**
|
| 650 |
* Return row array for an item
|
| 651 |
*
|
| 652 |
-
* @return array
|
| 653 |
*
|
| 654 |
-
* @since 2.0
|
| 655 |
*/
|
| 656 |
-
public function row() {
|
| 657 |
-
|
| 658 |
do_action( 'pods_pods_row', $this );
|
| 659 |
|
| 660 |
-
if ( !
|
| 661 |
return false;
|
| 662 |
-
}
|
| 663 |
|
| 664 |
return (array) $this->row;
|
| 665 |
}
|
|
@@ -669,34 +546,31 @@ class Pods implements Iterator {
|
|
| 669 |
* you will want to use field() instead. This function will automatically convert arrays into a
|
| 670 |
* list of text such as "Rick, John, and Gary"
|
| 671 |
*
|
| 672 |
-
* @param string|array
|
| 673 |
-
* @param boolean
|
| 674 |
*
|
| 675 |
-
* @return string|null|false The output from the field, null if the field doesn't exist, false if no value returned
|
| 676 |
-
*
|
| 677 |
-
* @
|
| 678 |
-
* @link https://pods.io/docs/display/
|
| 679 |
*/
|
| 680 |
-
public function display( $name, $single = null ) {
|
| 681 |
-
|
| 682 |
$defaults = array(
|
| 683 |
-
'name'
|
| 684 |
-
'single'
|
| 685 |
-
'display'
|
| 686 |
-
'serial_params' => null
|
| 687 |
);
|
| 688 |
|
| 689 |
if ( is_array( $name ) || is_object( $name ) ) {
|
| 690 |
-
$defaults['name'] = null;
|
| 691 |
-
|
| 692 |
$params = (object) array_merge( $defaults, (array) $name );
|
| 693 |
-
}
|
| 694 |
-
|
| 695 |
-
|
| 696 |
$params = (object) array_merge( $defaults, (array) $single );
|
| 697 |
-
} else {
|
| 698 |
-
$params = $defaults;
|
| 699 |
}
|
|
|
|
|
|
|
| 700 |
|
| 701 |
$params = (object) $params;
|
| 702 |
|
|
@@ -705,18 +579,17 @@ class Pods implements Iterator {
|
|
| 705 |
if ( is_array( $value ) ) {
|
| 706 |
$fields = $this->fields;
|
| 707 |
|
| 708 |
-
|
| 709 |
-
|
| 710 |
-
|
| 711 |
|
| 712 |
$serial_params = array(
|
| 713 |
-
'field'
|
| 714 |
-
'fields' => $fields
|
| 715 |
);
|
| 716 |
|
| 717 |
-
if ( !
|
| 718 |
$serial_params = array_merge( $serial_params, $params->serial_params );
|
| 719 |
-
}
|
| 720 |
|
| 721 |
$value = pods_serial_comma( $value, $serial_params );
|
| 722 |
}
|
|
@@ -729,35 +602,34 @@ class Pods implements Iterator {
|
|
| 729 |
* you will want to use field() instead. This function will automatically convert arrays into a
|
| 730 |
* list of text such as "Rick, John, and Gary"
|
| 731 |
*
|
| 732 |
-
* @param string|array
|
| 733 |
-
* @param boolean
|
| 734 |
*
|
| 735 |
-
* @return string|null|false The output from the field, null if the field doesn't exist, false if no value returned
|
| 736 |
-
*
|
| 737 |
-
* @
|
| 738 |
-
* @link https://pods.io/docs/display/
|
| 739 |
*/
|
| 740 |
-
public function raw( $name, $single = null ) {
|
| 741 |
-
|
| 742 |
$defaults = array(
|
| 743 |
-
'name'
|
| 744 |
'single' => $single,
|
| 745 |
-
'raw'
|
| 746 |
);
|
| 747 |
|
| 748 |
if ( is_array( $name ) || is_object( $name ) ) {
|
| 749 |
-
$defaults['name'] = null;
|
| 750 |
-
|
| 751 |
$params = (object) array_merge( $defaults, (array) $name );
|
| 752 |
-
}
|
| 753 |
-
|
| 754 |
-
|
| 755 |
$params = (object) array_merge( $defaults, (array) $single );
|
| 756 |
-
} else {
|
| 757 |
-
$params = (object) $defaults;
|
| 758 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 759 |
|
| 760 |
-
return $
|
| 761 |
}
|
| 762 |
|
| 763 |
/**
|
|
@@ -767,893 +639,740 @@ class Pods implements Iterator {
|
|
| 767 |
*
|
| 768 |
* This function will return arrays for relationship and file fields.
|
| 769 |
*
|
| 770 |
-
* @param string|array
|
| 771 |
-
* @param boolean
|
| 772 |
-
*
|
| 773 |
-
* @param boolean|array|object $raw Whether to return the raw value, or to run through the field type's display
|
| 774 |
-
* method, or an associative array of parameters.
|
| 775 |
*
|
| 776 |
-
* @return mixed|null Value returned depends on the field type, null if the field doesn't exist, false if no value
|
| 777 |
-
*
|
| 778 |
-
* @
|
| 779 |
-
* @link https://pods.io/docs/field/
|
| 780 |
*/
|
| 781 |
-
public function field( $name, $single = null, $raw = false ) {
|
|
|
|
| 782 |
|
| 783 |
$defaults = array(
|
| 784 |
-
'name'
|
| 785 |
-
'orderby'
|
| 786 |
-
'single'
|
| 787 |
-
'params'
|
| 788 |
-
'in_form'
|
| 789 |
-
'raw'
|
| 790 |
'raw_display' => false,
|
| 791 |
-
'display'
|
| 792 |
-
'get_meta'
|
| 793 |
-
'output'
|
| 794 |
-
'deprecated'
|
| 795 |
-
'
|
| 796 |
-
// extra data to send to field handlers.
|
| 797 |
-
'args' => array(),
|
| 798 |
);
|
| 799 |
|
| 800 |
-
if ( is_object( $name ) ) {
|
| 801 |
-
$name =
|
| 802 |
-
}
|
| 803 |
-
|
| 804 |
-
if ( is_object( $single ) ) {
|
| 805 |
-
$single = get_object_vars( $single );
|
| 806 |
-
}
|
| 807 |
-
|
| 808 |
-
if ( is_object( $raw ) ) {
|
| 809 |
-
$raw = get_object_vars( $raw );
|
| 810 |
-
}
|
| 811 |
-
|
| 812 |
-
if ( is_array( $name ) ) {
|
| 813 |
-
$defaults['name'] = null;
|
| 814 |
-
|
| 815 |
$params = (object) array_merge( $defaults, (array) $name );
|
| 816 |
-
}
|
| 817 |
-
|
| 818 |
-
|
| 819 |
$params = (object) array_merge( $defaults, (array) $single );
|
| 820 |
-
}
|
| 821 |
-
|
| 822 |
-
|
| 823 |
$params = (object) array_merge( $defaults, (array) $raw );
|
| 824 |
-
}
|
|
|
|
| 825 |
$params = (object) $defaults;
|
| 826 |
-
}//end if
|
| 827 |
|
| 828 |
if ( $params->in_form ) {
|
| 829 |
$params->output = 'ids';
|
| 830 |
-
}
|
|
|
|
| 831 |
/**
|
| 832 |
-
* Override the way
|
| 833 |
*
|
| 834 |
-
* @param string
|
| 835 |
-
* @param array|object $row
|
| 836 |
-
* @param array
|
| 837 |
-
* @param Pods
|
| 838 |
*/
|
| 839 |
$params->output = apply_filters( 'pods_pods_field_related_output_type', 'arrays', $this->row, $params, $this );
|
| 840 |
}
|
| 841 |
|
| 842 |
-
if ( in_array( $params->output, array( 'id', 'name', 'object', 'array', 'pod' )
|
| 843 |
$params->output .= 's';
|
| 844 |
-
}
|
| 845 |
|
| 846 |
-
// Support old $orderby variable
|
| 847 |
if ( null !== $params->single && is_string( $params->single ) && empty( $params->orderby ) ) {
|
| 848 |
if ( ! class_exists( 'Pod' ) || Pod::$deprecated_notice ) {
|
| 849 |
pods_deprecated( 'Pods::field', '2.0', 'Use $params[ \'orderby\' ] instead' );
|
| 850 |
}
|
| 851 |
|
| 852 |
$params->orderby = $params->single;
|
| 853 |
-
$params->single
|
| 854 |
}
|
| 855 |
|
| 856 |
-
if ( null !== $params->single )
|
| 857 |
$params->single = (boolean) $params->single;
|
| 858 |
-
}
|
| 859 |
|
| 860 |
$params->name = trim( $params->name );
|
| 861 |
-
if ( is_array( $params->name ) ||
|
| 862 |
return null;
|
| 863 |
-
}
|
| 864 |
|
| 865 |
$params->full_name = $params->name;
|
| 866 |
|
| 867 |
$value = null;
|
| 868 |
|
| 869 |
-
if ( isset( $this->row_override[ $params->name ] ) )
|
| 870 |
$value = $this->row_override[ $params->name ];
|
| 871 |
-
}
|
| 872 |
|
| 873 |
if ( false === $this->row() ) {
|
| 874 |
-
if ( false !== $this->data() )
|
| 875 |
$this->fetch();
|
| 876 |
-
|
| 877 |
return $value;
|
| 878 |
-
}
|
| 879 |
}
|
| 880 |
|
| 881 |
-
if ( $this->data->field_id
|
| 882 |
-
if ( isset( $this->row[ $params->name ] ) )
|
| 883 |
return $this->row[ $params->name ];
|
| 884 |
-
|
| 885 |
-
} elseif ( null !== $value ) {
|
| 886 |
return $value;
|
| 887 |
-
}
|
| 888 |
|
| 889 |
return 0;
|
| 890 |
}
|
| 891 |
|
| 892 |
-
$tableless_field_types
|
| 893 |
$simple_tableless_objects = PodsForm::simple_tableless_objects();
|
| 894 |
|
| 895 |
$params->traverse = array();
|
| 896 |
|
| 897 |
-
$
|
| 898 |
-
|
| 899 |
-
'detail_url',
|
| 900 |
-
'permalink',
|
| 901 |
-
'the_permalink',
|
| 902 |
-
);
|
| 903 |
-
|
| 904 |
-
$wp_object_types = array(
|
| 905 |
-
'post_type',
|
| 906 |
-
'taxonomy',
|
| 907 |
-
'media',
|
| 908 |
-
'user',
|
| 909 |
-
'comment',
|
| 910 |
-
);
|
| 911 |
-
|
| 912 |
-
/** @var string $pod_type The pod object type. */
|
| 913 |
-
$pod_type = pods_v( 'type', $this->pod_data, '' );
|
| 914 |
-
|
| 915 |
-
$is_wp_object = in_array( $pod_type, $wp_object_types, true );
|
| 916 |
-
|
| 917 |
-
if ( in_array( $params->name, $permalink_fields, true ) ) {
|
| 918 |
-
if ( 0 < strlen( $this->detail_page ) && false === strpos( $params->name, 'permalink' ) ) {
|
| 919 |
-
// ACT Pods. Prevent tag loop by not parsing `permalink`.
|
| 920 |
$value = get_home_url() . '/' . $this->do_magic_tags( $this->detail_page );
|
| 921 |
-
|
| 922 |
-
|
| 923 |
-
|
| 924 |
-
|
| 925 |
-
|
| 926 |
-
|
| 927 |
-
|
| 928 |
-
|
| 929 |
-
|
| 930 |
-
|
| 931 |
-
|
| 932 |
-
|
| 933 |
-
|
| 934 |
-
|
| 935 |
-
|
| 936 |
-
|
| 937 |
-
|
| 938 |
-
|
| 939 |
-
|
| 940 |
-
|
| 941 |
-
|
| 942 |
-
|
| 943 |
-
|
| 944 |
-
|
| 945 |
-
|
| 946 |
-
|
| 947 |
-
|
| 948 |
-
|
| 949 |
-
|
| 950 |
-
* @var array $last_field_data The field data used in traversal loop.
|
| 951 |
-
*/
|
| 952 |
-
|
| 953 |
-
$is_field_set = false;
|
| 954 |
-
$is_tableless_field = false;
|
| 955 |
-
$field_source = '';
|
| 956 |
-
$field_data = array();
|
| 957 |
-
$field_type = '';
|
| 958 |
-
$field_options = array();
|
| 959 |
-
$traverse_fields = explode( '.', $params->name );
|
| 960 |
-
$is_traversal = 1 < count( $traverse_fields );
|
| 961 |
-
$first_field = $traverse_fields[0];
|
| 962 |
-
$last_field_data = null;
|
| 963 |
-
|
| 964 |
-
if ( isset( $this->fields[ $params->name ] ) ) {
|
| 965 |
-
// Get the full field name data.
|
| 966 |
-
$field_data = $this->fields[ $params->name ];
|
| 967 |
-
$field_source = 'field';
|
| 968 |
-
$is_field_set = true;
|
| 969 |
-
} elseif ( isset( $this->fields[ $first_field ] ) ) {
|
| 970 |
-
// Get the first field name data.
|
| 971 |
-
$field_data = $this->fields[ $first_field ];
|
| 972 |
-
$field_source = 'field';
|
| 973 |
-
$is_field_set = true;
|
| 974 |
-
} elseif ( ! empty( $this->pod_data['object_fields'] ) ) {
|
| 975 |
-
// Get the object field data.
|
| 976 |
-
if ( isset( $this->pod_data['object_fields'][ $first_field ] ) ) {
|
| 977 |
-
$field_data = $this->pod_data['object_fields'][ $first_field ];
|
| 978 |
-
$field_source = 'object_field';
|
| 979 |
-
$is_field_set = true;
|
| 980 |
-
} else {
|
| 981 |
-
$object_fields = (array) $this->pod_data['object_fields'];
|
| 982 |
-
|
| 983 |
-
// Search through field aliases.
|
| 984 |
-
foreach ( $object_fields as $object_field => $object_field_opt ) {
|
| 985 |
-
if ( in_array( $first_field, $object_field_opt['alias'], true ) ) {
|
| 986 |
-
if ( $first_field === $params->name ) {
|
| 987 |
$params->name = $object_field;
|
| 988 |
-
}
|
| 989 |
|
| 990 |
-
$first_field
|
| 991 |
-
$field_data
|
| 992 |
-
$
|
| 993 |
-
$is_field_set = true;
|
| 994 |
|
| 995 |
break;
|
| 996 |
}
|
| 997 |
}
|
| 998 |
}
|
| 999 |
-
}
|
| 1000 |
-
|
| 1001 |
-
// Store field info.
|
| 1002 |
-
$field_type = pods_v( 'type', $field_data, '' );
|
| 1003 |
-
$field_options = pods_v( 'options', $field_data, array() );
|
| 1004 |
-
$is_tableless_field = in_array( $field_type, $tableless_field_types, true );
|
| 1005 |
|
| 1006 |
-
// Simple fields have no other output options
|
| 1007 |
-
if ( 'pick'
|
| 1008 |
$params->output = 'arrays';
|
| 1009 |
}
|
| 1010 |
|
| 1011 |
-
|
| 1012 |
-
if ( empty( $value ) && $is_tableless_field ) {
|
| 1013 |
$params->raw = true;
|
| 1014 |
|
| 1015 |
$value = false;
|
| 1016 |
|
| 1017 |
-
$
|
| 1018 |
-
|
| 1019 |
-
|
| 1020 |
-
|
| 1021 |
-
} elseif ( 'arrays' === $params->output && isset( $this->row[ $params->name ] ) ) {
|
| 1022 |
$value = $this->row[ $params->name ];
|
| 1023 |
}
|
| 1024 |
|
| 1025 |
-
if (
|
| 1026 |
-
false !== $value &&
|
| 1027 |
-
! is_array( $value ) &&
|
| 1028 |
-
'pick' === $field_type &&
|
| 1029 |
-
in_array( $field_data['pick_object'], $simple_tableless_objects, true )
|
| 1030 |
-
) {
|
| 1031 |
$value = PodsForm::field_method( 'pick', 'simple_value', $params->name, $value, $field_data, $this->pod_data, $this->id(), true );
|
| 1032 |
-
}
|
| 1033 |
}
|
| 1034 |
|
| 1035 |
-
if (
|
| 1036 |
-
empty( $
|
| 1037 |
-
isset( $this->row[ $params->name ] ) &&
|
| 1038 |
-
( ! $is_tableless_field || 'arrays' === $params->output )
|
| 1039 |
-
) {
|
| 1040 |
-
if ( empty( $field_data ) || in_array( $field_type, array( 'boolean', 'number', 'currency' ), true ) ) {
|
| 1041 |
$params->raw = true;
|
| 1042 |
-
}
|
| 1043 |
|
| 1044 |
if ( null === $params->single ) {
|
| 1045 |
-
if ( ! $
|
| 1046 |
$params->single = true;
|
| 1047 |
-
|
| 1048 |
$params->single = false;
|
| 1049 |
-
}
|
| 1050 |
}
|
| 1051 |
|
| 1052 |
$value = $this->row[ $params->name ];
|
| 1053 |
-
}
|
|
|
|
| 1054 |
$object_field_found = false;
|
| 1055 |
|
| 1056 |
-
if ( 'object_field'
|
| 1057 |
$object_field_found = true;
|
| 1058 |
|
| 1059 |
-
if ( isset( $this->row[ $first_field ] ) )
|
| 1060 |
$value = $this->row[ $first_field ];
|
| 1061 |
-
|
| 1062 |
-
// Overwrite existing field data.
|
| 1063 |
$this->fields[ $first_field ] = $field_data;
|
| 1064 |
|
| 1065 |
$object_field_found = false;
|
| 1066 |
-
} else {
|
| 1067 |
-
return null;
|
| 1068 |
}
|
|
|
|
|
|
|
|
|
|
| 1069 |
|
| 1070 |
-
|
| 1071 |
-
|
| 1072 |
-
|
| 1073 |
-
|
| 1074 |
-
|
| 1075 |
-
|
| 1076 |
-
|
| 1077 |
-
|
| 1078 |
-
|
| 1079 |
-
$size = (int) $traverse_fields[1];
|
| 1080 |
-
} else {
|
| 1081 |
-
// Traverse through attachment post.
|
| 1082 |
-
$get_avatar = false;
|
| 1083 |
-
}
|
| 1084 |
-
} else {
|
| 1085 |
-
if ( isset( $traverse_fields[1] ) ) {
|
| 1086 |
-
$size = (int) $traverse_fields[1];
|
| 1087 |
-
}
|
| 1088 |
}
|
| 1089 |
-
}
|
| 1090 |
|
| 1091 |
-
|
|
|
|
|
|
|
| 1092 |
$object_field_found = true;
|
| 1093 |
-
|
| 1094 |
-
|
| 1095 |
-
|
| 1096 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1097 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1098 |
}
|
|
|
|
|
|
|
| 1099 |
|
| 1100 |
-
|
| 1101 |
|
| 1102 |
-
|
| 1103 |
-
|
| 1104 |
-
|
| 1105 |
-
|
|
|
|
|
|
|
|
|
|
| 1106 |
|
| 1107 |
-
|
| 1108 |
-
|
| 1109 |
-
|
|
|
|
|
|
|
|
|
|
| 1110 |
}
|
|
|
|
|
|
|
| 1111 |
|
| 1112 |
-
|
| 1113 |
-
|
| 1114 |
-
|
| 1115 |
-
$object_field_found = true;
|
| 1116 |
|
| 1117 |
-
$
|
| 1118 |
-
|
| 1119 |
-
|
| 1120 |
-
if ( $
|
| 1121 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1122 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1123 |
|
| 1124 |
-
|
| 1125 |
-
|
| 1126 |
-
// Results in an empty array if no traversal params are passed.
|
| 1127 |
-
array_shift( $traverse_params );
|
| 1128 |
|
| 1129 |
-
|
| 1130 |
-
|
| 1131 |
-
case 'post_thumbnail':
|
| 1132 |
-
$attachment_id = get_post_thumbnail_id( $this->id() );
|
| 1133 |
-
break;
|
| 1134 |
-
case 'image_attachment':
|
| 1135 |
-
if ( isset( $traverse_params[0] ) ) {
|
| 1136 |
-
$attachment_id = $traverse_params[0];
|
| 1137 |
-
array_shift( $traverse_params );
|
| 1138 |
-
}
|
| 1139 |
-
break;
|
| 1140 |
}
|
| 1141 |
|
| 1142 |
-
if ( $
|
| 1143 |
-
$
|
|
|
|
|
|
|
| 1144 |
|
| 1145 |
-
|
| 1146 |
-
|
| 1147 |
-
|
|
|
|
|
|
|
| 1148 |
|
| 1149 |
-
|
| 1150 |
-
// Force image request since a valid size parameter is passed.
|
| 1151 |
-
$is_image = true;
|
| 1152 |
-
} else {
|
| 1153 |
-
// No valid image size found.
|
| 1154 |
-
$size = false;
|
| 1155 |
-
}
|
| 1156 |
-
}
|
| 1157 |
|
| 1158 |
-
|
| 1159 |
-
if ( $is_image ) {
|
| 1160 |
-
$value = pods_image_url( $attachment_id, $size, 0, true );
|
| 1161 |
-
} else {
|
| 1162 |
-
$value = wp_get_attachment_url( $attachment_id );
|
| 1163 |
-
}
|
| 1164 |
-
} elseif ( $size ) {
|
| 1165 |
-
// Pods will auto-get the thumbnail ID if this isn't an attachment.
|
| 1166 |
-
$value = pods_image( $attachment_id, $size, 0, null, true );
|
| 1167 |
-
} else {
|
| 1168 |
-
// Fallback to attachment Post object to look for other image properties.
|
| 1169 |
-
$media = pods( 'media', $attachment_id );
|
| 1170 |
-
|
| 1171 |
-
if ( $media && $media->valid() && $media->exists() ) {
|
| 1172 |
-
$value = $media->field( implode( '.', $traverse_params ) );
|
| 1173 |
-
} else {
|
| 1174 |
-
// Fallback to default attachment object.
|
| 1175 |
-
$attachment = get_post( $attachment_id );
|
| 1176 |
-
$value = pods_v( implode( '.', $traverse_params ), $attachment, null );
|
| 1177 |
-
|
| 1178 |
-
if ( null === $value ) {
|
| 1179 |
-
// Start traversal though object property or metadata.
|
| 1180 |
-
$name_key = array_shift( $traverse_params );
|
| 1181 |
-
$value = pods_v( $name_key, $attachment, null );
|
| 1182 |
-
|
| 1183 |
-
if ( null === $value ) {
|
| 1184 |
-
$value = get_post_meta( $attachment_id, $name_key, true );
|
| 1185 |
-
}
|
| 1186 |
|
| 1187 |
-
|
| 1188 |
-
|
| 1189 |
-
|
| 1190 |
-
|
| 1191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1192 |
}
|
| 1193 |
}
|
| 1194 |
|
| 1195 |
-
// Continue regular field parsing.
|
| 1196 |
if ( false === $object_field_found ) {
|
| 1197 |
$params->traverse = array( $params->name );
|
| 1198 |
|
| 1199 |
if ( false !== strpos( $params->name, '.' ) ) {
|
| 1200 |
$params->traverse = explode( '.', $params->name );
|
| 1201 |
|
| 1202 |
-
$params->name = $params->traverse[0];
|
| 1203 |
}
|
| 1204 |
|
| 1205 |
-
if ( $
|
| 1206 |
-
|
| 1207 |
/**
|
| 1208 |
* Modify value returned by field() after its retrieved, but before its validated or formatted
|
| 1209 |
*
|
| 1210 |
-
* Filter name is set dynamically with name of field: "pods_pods_field_{
|
| 1211 |
*
|
| 1212 |
* @since unknown
|
| 1213 |
*
|
| 1214 |
-
* @param array|string|null $value
|
| 1215 |
-
* @param array|object
|
| 1216 |
-
* @param array
|
| 1217 |
-
* @param object|Pods
|
|
|
|
| 1218 |
*/
|
| 1219 |
-
$v = apply_filters(
|
| 1220 |
|
| 1221 |
-
if ( null !== $v )
|
| 1222 |
return $v;
|
| 1223 |
-
}
|
| 1224 |
}
|
| 1225 |
|
| 1226 |
$simple = false;
|
|
|
|
| 1227 |
|
| 1228 |
-
if ( $
|
| 1229 |
-
|
| 1230 |
-
|
| 1231 |
-
|
| 1232 |
}
|
| 1233 |
|
| 1234 |
-
if ( $
|
| 1235 |
$params->raw = true;
|
| 1236 |
|
| 1237 |
-
if ( 'pick'
|
| 1238 |
-
$simple
|
| 1239 |
$params->single = true;
|
| 1240 |
}
|
| 1241 |
-
} elseif ( in_array( $field_type, array( 'boolean', 'number', 'currency' ), true ) ) {
|
| 1242 |
-
$params->raw = true;
|
| 1243 |
}
|
|
|
|
|
|
|
| 1244 |
}
|
| 1245 |
|
| 1246 |
-
if ( ! $
|
| 1247 |
if ( null === $params->single ) {
|
| 1248 |
-
if ( $
|
| 1249 |
$params->single = true;
|
| 1250 |
-
|
| 1251 |
$params->single = false;
|
| 1252 |
-
}
|
| 1253 |
}
|
| 1254 |
|
| 1255 |
-
$no_conflict = pods_no_conflict_check( $
|
| 1256 |
|
| 1257 |
-
if (
|
| 1258 |
-
|
| 1259 |
-
pods_no_conflict_on( $pod_type );
|
| 1260 |
-
}
|
| 1261 |
|
| 1262 |
-
if ( $
|
| 1263 |
$id = $this->id();
|
| 1264 |
|
| 1265 |
-
|
|
|
|
|
|
|
| 1266 |
|
| 1267 |
-
|
| 1268 |
-
|
|
|
|
| 1269 |
|
| 1270 |
-
|
| 1271 |
-
if ( did_action( 'wpml_loaded' ) && apply_filters( 'wpml_is_translated_post_type', false, $this->pod_data['name'] ) ) {
|
| 1272 |
-
$master_post_id = (int) apply_filters( 'wpml_master_post_from_duplicate', $id );
|
| 1273 |
|
| 1274 |
-
|
| 1275 |
-
|
| 1276 |
-
|
| 1277 |
-
|
| 1278 |
-
} elseif ( 'taxonomy' === $metadata_type ) {
|
| 1279 |
-
$metadata_type = 'term';
|
| 1280 |
}
|
| 1281 |
|
| 1282 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1283 |
|
| 1284 |
$single_multi = 'single';
|
| 1285 |
|
| 1286 |
-
if ( $
|
| 1287 |
-
$single_multi = pods_v( $
|
| 1288 |
}
|
| 1289 |
|
| 1290 |
-
if ( $simple && !
|
| 1291 |
-
$value = get_metadata( $
|
| 1292 |
}
|
| 1293 |
-
}
|
| 1294 |
-
|
| 1295 |
-
|
| 1296 |
|
| 1297 |
-
// Handle Simple Relationships
|
| 1298 |
if ( $simple ) {
|
| 1299 |
-
if ( null === $params->single )
|
| 1300 |
$params->single = false;
|
| 1301 |
-
|
| 1302 |
|
| 1303 |
$value = PodsForm::field_method( 'pick', 'simple_value', $params->name, $value, $this->fields[ $params->name ], $this->pod_data, $this->id(), true );
|
| 1304 |
}
|
| 1305 |
|
| 1306 |
-
if (
|
| 1307 |
-
|
| 1308 |
-
|
| 1309 |
-
|
| 1310 |
-
|
| 1311 |
-
|
| 1312 |
-
$
|
| 1313 |
-
$ids = array( $this->id() );
|
| 1314 |
$all_fields = array();
|
| 1315 |
|
| 1316 |
$lookup = $params->traverse;
|
| 1317 |
|
| 1318 |
-
// Get fields matching traversal names
|
| 1319 |
-
if ( !
|
| 1320 |
$fields = $this->api->load_fields( array(
|
| 1321 |
-
'name'
|
| 1322 |
-
'type'
|
| 1323 |
-
'object_fields' => true
|
| 1324 |
-
// @todo support object fields too.
|
| 1325 |
) );
|
| 1326 |
|
| 1327 |
-
if ( !
|
| 1328 |
foreach ( $fields as $field ) {
|
| 1329 |
-
if ( !
|
| 1330 |
-
if ( !
|
| 1331 |
-
$all_fields[ $field['pod'] ] = array();
|
| 1332 |
-
}
|
| 1333 |
|
| 1334 |
-
$all_fields[ $field['pod'] ][ $field['name'] ] = $field;
|
| 1335 |
}
|
| 1336 |
}
|
| 1337 |
}
|
| 1338 |
|
| 1339 |
-
if ( !
|
| 1340 |
-
|
| 1341 |
-
|
| 1342 |
-
foreach ( $object_fields as $object_field => $object_field_opt ) {
|
| 1343 |
-
if ( in_array( $object_field_opt['type'], $tableless_field_types, true ) ) {
|
| 1344 |
$all_fields[ $this->pod ][ $object_field ] = $object_field_opt;
|
| 1345 |
}
|
| 1346 |
}
|
| 1347 |
}
|
| 1348 |
-
}
|
| 1349 |
|
| 1350 |
-
$last_type
|
| 1351 |
-
$
|
| 1352 |
-
$last_pick_val = '';
|
| 1353 |
|
| 1354 |
-
$single_multi = pods_v( $
|
| 1355 |
|
| 1356 |
-
if ( 'multi'
|
| 1357 |
-
$limit = (int) pods_v( $
|
| 1358 |
-
|
| 1359 |
$limit = 1;
|
| 1360 |
-
}
|
| 1361 |
|
| 1362 |
-
|
|
|
|
|
|
|
| 1363 |
foreach ( $params->traverse as $key => $field ) {
|
| 1364 |
$last_loop = false;
|
| 1365 |
|
| 1366 |
-
if ( count( $params->traverse ) <= ( $key + 1 ) )
|
| 1367 |
$last_loop = true;
|
| 1368 |
-
}
|
| 1369 |
|
| 1370 |
$field_exists = isset( $all_fields[ $pod ][ $field ] );
|
| 1371 |
|
| 1372 |
-
$simple
|
| 1373 |
$last_options = array();
|
| 1374 |
|
| 1375 |
-
if (
|
| 1376 |
-
$
|
| 1377 |
-
'pick' === $all_fields[ $pod ][ $field ]['type'] &&
|
| 1378 |
-
in_array( $all_fields[ $pod ][ $field ]['pick_object'], $simple_tableless_objects, true )
|
| 1379 |
-
) {
|
| 1380 |
-
$simple = true;
|
| 1381 |
$last_options = $all_fields[ $pod ][ $field ];
|
| 1382 |
}
|
| 1383 |
|
| 1384 |
-
// Tableless handler
|
| 1385 |
-
if ( $field_exists && ( !
|
| 1386 |
-
'
|
| 1387 |
-
'
|
| 1388 |
-
'
|
| 1389 |
-
|
| 1390 |
-
|
| 1391 |
-
|
| 1392 |
-
|
| 1393 |
-
|
| 1394 |
-
if ( 'table' === $pick_object ) {
|
| 1395 |
-
$pick_val = pods_v( 'pick_table', $all_fields[ $pod ][ $field ]['options'], $pick_val, true );
|
| 1396 |
-
} elseif ( '__current__' === $pick_val ) {
|
| 1397 |
$pick_val = $pod;
|
| 1398 |
}
|
| 1399 |
|
| 1400 |
$last_limit = 0;
|
| 1401 |
|
| 1402 |
-
if ( in_array( $type, $tableless_field_types
|
| 1403 |
-
$single_multi = pods_v( "{$type}_format_type", $all_fields[ $pod ][ $field ]['options'], 'single' );
|
| 1404 |
|
| 1405 |
-
if ( 'multi'
|
| 1406 |
-
$last_limit = (int) pods_v( "{$type}_limit", $all_fields[ $pod ][ $field ]['options'], 0 );
|
| 1407 |
-
}
|
|
|
|
| 1408 |
$last_limit = 1;
|
| 1409 |
}
|
| 1410 |
}
|
| 1411 |
|
| 1412 |
-
$last_type
|
| 1413 |
-
$last_object
|
| 1414 |
$last_pick_val = $pick_val;
|
| 1415 |
-
$last_options
|
| 1416 |
|
| 1417 |
-
// Temporary hack until there's some better handling here
|
| 1418 |
-
$last_limit
|
| 1419 |
|
| 1420 |
-
// Get related IDs
|
| 1421 |
-
if ( !
|
| 1422 |
-
$all_fields[ $pod ][ $field ]['pod_id'] = 0;
|
| 1423 |
}
|
| 1424 |
|
| 1425 |
-
if ( isset( $all_fields[ $pod ][ $field ]['id'] ) ) {
|
| 1426 |
-
$ids = $this->api->lookup_related_items(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1427 |
}
|
| 1428 |
|
| 1429 |
-
// No items found
|
| 1430 |
if ( empty( $ids ) ) {
|
| 1431 |
return false;
|
| 1432 |
-
}
|
| 1433 |
-
|
| 1434 |
$ids = array_slice( $ids, 0, $last_limit );
|
| 1435 |
}
|
| 1436 |
|
| 1437 |
-
// Get $pod if related to a Pod
|
| 1438 |
-
if ( !
|
| 1439 |
-
'
|
| 1440 |
-
'media',
|
| 1441 |
-
'comment',
|
| 1442 |
-
), true ) ) ) {
|
| 1443 |
-
if ( 'pod' === $pick_object ) {
|
| 1444 |
$pod = $pick_val;
|
| 1445 |
-
}
|
|
|
|
| 1446 |
$check = $this->api->get_table_info( $pick_object, $pick_val );
|
| 1447 |
|
| 1448 |
-
if ( !
|
| 1449 |
-
$pod = $check['pod']['name'];
|
| 1450 |
}
|
| 1451 |
}
|
| 1452 |
}
|
| 1453 |
-
}
|
| 1454 |
-
|
| 1455 |
-
|
| 1456 |
-
|
| 1457 |
-
if ( 0
|
| 1458 |
-
|
| 1459 |
-
$last_object = $this->pod_data['object_type'];
|
| 1460 |
-
$last_pick_val = $this->pod_data['name'];
|
| 1461 |
}
|
| 1462 |
-
|
|
|
|
|
|
|
| 1463 |
|
| 1464 |
if ( $last_loop ) {
|
| 1465 |
$object_type = $last_object;
|
| 1466 |
-
$object
|
| 1467 |
|
| 1468 |
-
if ( in_array( $last_type, PodsForm::file_field_types()
|
| 1469 |
$object_type = 'media';
|
| 1470 |
-
$object
|
| 1471 |
}
|
| 1472 |
|
| 1473 |
$data = array();
|
| 1474 |
|
| 1475 |
$table = $this->api->get_table_info( $object_type, $object, null, null, $last_options );
|
| 1476 |
|
| 1477 |
-
$join
|
| 1478 |
-
$where = array();
|
| 1479 |
|
| 1480 |
-
if ( !
|
| 1481 |
-
$join = (array) $table['join'];
|
| 1482 |
-
}
|
| 1483 |
|
| 1484 |
-
if ( !
|
| 1485 |
foreach ( $ids as $id ) {
|
| 1486 |
-
$where[ $id ] = '`t`.`' . $table['field_id'] . '` = ' . (int) $id;
|
| 1487 |
}
|
| 1488 |
|
| 1489 |
-
if ( !
|
| 1490 |
$where = array( implode( ' OR ', $where ) );
|
| 1491 |
}
|
| 1492 |
|
| 1493 |
-
if ( !
|
| 1494 |
-
|
| 1495 |
-
$where = array_merge( $where, array_values( (array) $table['where'] ) );
|
| 1496 |
}
|
| 1497 |
}
|
| 1498 |
|
| 1499 |
/**
|
| 1500 |
-
*
|
| 1501 |
-
*
|
| 1502 |
-
* @var $related_obj Pods|false
|
| 1503 |
*/
|
| 1504 |
$related_obj = false;
|
| 1505 |
|
| 1506 |
-
|
| 1507 |
-
$is_field_output_full = false;
|
| 1508 |
-
|
| 1509 |
-
if ( false !== $field_exists && ( in_array( $last_type, $tableless_field_types, true ) && ! $simple ) ) {
|
| 1510 |
-
$is_field_output_full = true;
|
| 1511 |
-
}
|
| 1512 |
-
|
| 1513 |
-
if ( 'pod' === $object_type ) {
|
| 1514 |
$related_obj = pods( $object, null, false );
|
| 1515 |
-
|
| 1516 |
-
$related_obj = pods( $table['pod']['name'], null, false );
|
| 1517 |
-
}
|
| 1518 |
|
| 1519 |
-
if (
|
| 1520 |
$sql = array(
|
| 1521 |
-
'select'
|
| 1522 |
-
'table'
|
| 1523 |
-
'join'
|
| 1524 |
-
'where'
|
| 1525 |
-
'orderby'
|
| 1526 |
'pagination' => false,
|
| 1527 |
-
'search'
|
| 1528 |
-
'limit'
|
| 1529 |
-
'expires'
|
| 1530 |
-
// @todo This could potentially cause issues if someone changes the data within this time and persistent storage is used.
|
| 1531 |
);
|
| 1532 |
|
| 1533 |
-
|
| 1534 |
-
|
| 1535 |
-
|
| 1536 |
-
|
| 1537 |
-
|
| 1538 |
-
if ( in_array( $params->output, array( 'ids', 'objects', 'pods' ), true ) ) {
|
| 1539 |
-
$sql['select'] = '`t`.`' . $table['field_id'] . '` AS `pod_item_id`';
|
| 1540 |
-
} elseif ( 'names' === $params->output && ! empty( $table['field_index'] ) ) {
|
| 1541 |
-
$sql['select'] = '`t`.`' . $table['field_index'] . '` AS `pod_item_index`, `t`.`' . $table['field_id'] . '` AS `pod_item_id`';
|
| 1542 |
-
}
|
| 1543 |
|
| 1544 |
-
if ( !
|
| 1545 |
-
$where = $sql['where'];
|
| 1546 |
|
| 1547 |
-
// @codingStandardsIgnoreLine.
|
| 1548 |
$sql = array_merge( $sql, $params->params );
|
| 1549 |
|
| 1550 |
-
if ( isset( $params->params['where'] ) )
|
| 1551 |
-
|
| 1552 |
-
$sql['where'] = array_merge( (array) $where, (array) $params->params['where'] );
|
| 1553 |
-
}
|
| 1554 |
}
|
| 1555 |
|
| 1556 |
-
|
| 1557 |
-
|
| 1558 |
-
if ( ! $related_obj || ! $related_obj->valid() ) {
|
| 1559 |
-
if ( ! is_object( $this->alt_data ) ) {
|
| 1560 |
$this->alt_data = pods_data( null, 0, true, true );
|
| 1561 |
-
}
|
| 1562 |
|
| 1563 |
$item_data = $this->alt_data->select( $sql );
|
| 1564 |
-
}
|
| 1565 |
-
|
| 1566 |
-
|
| 1567 |
-
// Handle default orderby for ordering by the IDs.
|
| 1568 |
-
$order_ids = implode( ', ', array_map( 'absint', $ids ) );
|
| 1569 |
-
|
| 1570 |
-
$sql['orderby'] = 'FIELD( `t`.`' . $table['field_id'] . '`, ' . $order_ids . ' )';
|
| 1571 |
-
}
|
| 1572 |
-
|
| 1573 |
-
$related_obj->find( $sql );
|
| 1574 |
-
|
| 1575 |
-
// Support 'find' output.
|
| 1576 |
-
if ( 'find' === $params->output && $is_field_output_full ) {
|
| 1577 |
-
$data = $related_obj;
|
| 1578 |
-
|
| 1579 |
-
$is_field_output_full = true;
|
| 1580 |
-
} else {
|
| 1581 |
-
$item_data = $related_obj->data();
|
| 1582 |
-
}
|
| 1583 |
-
}//end if
|
| 1584 |
|
| 1585 |
$items = array();
|
| 1586 |
|
| 1587 |
-
if ( !
|
| 1588 |
foreach ( $item_data as $item ) {
|
| 1589 |
-
if ( is_array( $item ) )
|
| 1590 |
$item = (object) $item;
|
| 1591 |
-
}
|
| 1592 |
|
| 1593 |
-
if ( empty( $item->pod_item_id ) )
|
| 1594 |
continue;
|
| 1595 |
-
}
|
| 1596 |
|
| 1597 |
-
// Bypass pass field
|
| 1598 |
-
if ( isset( $item->user_pass ) )
|
| 1599 |
unset( $item->user_pass );
|
| 1600 |
-
}
|
| 1601 |
|
| 1602 |
-
// Get Item ID
|
| 1603 |
$item_id = $item->pod_item_id;
|
| 1604 |
|
| 1605 |
-
// Output types
|
| 1606 |
-
if ( 'ids'
|
| 1607 |
$item = (int) $item_id;
|
| 1608 |
-
|
| 1609 |
$item = $item->pod_item_index;
|
| 1610 |
-
|
| 1611 |
-
if ( in_array( $object_type, array( 'post_type', 'media' )
|
| 1612 |
$item = get_post( $item_id );
|
| 1613 |
-
|
| 1614 |
$item = get_term( $item_id, $object );
|
| 1615 |
-
|
| 1616 |
$item = get_userdata( $item_id );
|
| 1617 |
|
| 1618 |
-
if ( !
|
| 1619 |
-
// Get other vars
|
| 1620 |
-
$roles
|
| 1621 |
-
$caps
|
| 1622 |
$allcaps = $item->allcaps;
|
| 1623 |
|
| 1624 |
$item = $item->data;
|
| 1625 |
|
| 1626 |
-
// Set other vars
|
| 1627 |
-
$item->roles
|
| 1628 |
-
$item->caps
|
| 1629 |
$item->allcaps = $allcaps;
|
| 1630 |
|
| 1631 |
unset( $item->user_pass );
|
| 1632 |
}
|
| 1633 |
-
}
|
|
|
|
| 1634 |
$item = get_comment( $item_id );
|
| 1635 |
-
|
| 1636 |
$item = (object) $item;
|
| 1637 |
-
|
| 1638 |
-
|
| 1639 |
-
|
| 1640 |
-
|
| 1641 |
-
|
| 1642 |
-
$item = pods( $object, (int) $item_id );
|
| 1643 |
-
}
|
| 1644 |
-
} else {
|
| 1645 |
-
// arrays.
|
| 1646 |
$item = get_object_vars( (object) $item );
|
| 1647 |
-
}//end if
|
| 1648 |
|
| 1649 |
-
// Pass item data into $data
|
| 1650 |
$items[ $item_id ] = $item;
|
| 1651 |
-
}
|
| 1652 |
|
| 1653 |
-
// Cleanup
|
| 1654 |
unset( $item_data );
|
| 1655 |
|
| 1656 |
-
// Return all of the data in the order expected
|
| 1657 |
if ( empty( $params->orderby ) ) {
|
| 1658 |
foreach ( $ids as $id ) {
|
| 1659 |
if ( isset( $items[ $id ] ) ) {
|
|
@@ -1661,298 +1380,243 @@ class Pods implements Iterator {
|
|
| 1661 |
}
|
| 1662 |
}
|
| 1663 |
} else {
|
| 1664 |
-
// Use order set by orderby
|
| 1665 |
foreach ( $items as $id => $v ) {
|
| 1666 |
-
// @codingStandardsIgnoreLine.
|
| 1667 |
if ( in_array( $id, $ids ) ) {
|
| 1668 |
$data[ $id ] = $v;
|
| 1669 |
}
|
| 1670 |
}
|
| 1671 |
}
|
| 1672 |
-
}
|
| 1673 |
-
}//end if
|
| 1674 |
-
|
| 1675 |
-
if ( in_array( $last_type, $tableless_field_types, true ) || in_array( $last_type, array(
|
| 1676 |
-
'boolean',
|
| 1677 |
-
'number',
|
| 1678 |
-
'currency',
|
| 1679 |
-
), true ) ) {
|
| 1680 |
-
$params->raw = true;
|
| 1681 |
}
|
| 1682 |
|
| 1683 |
-
if (
|
|
|
|
|
|
|
|
|
|
| 1684 |
$value = false;
|
| 1685 |
-
|
| 1686 |
-
$object_type = $table['type'];
|
| 1687 |
|
| 1688 |
-
if ( in_array( $table['type'], array( 'post_type', 'attachment', 'media' )
|
| 1689 |
$object_type = 'post';
|
| 1690 |
-
}
|
| 1691 |
-
|
| 1692 |
|
| 1693 |
-
$
|
| 1694 |
|
| 1695 |
-
|
|
|
|
| 1696 |
|
| 1697 |
-
|
| 1698 |
-
|
| 1699 |
-
pods_no_conflict_on( $object_type );
|
| 1700 |
}
|
| 1701 |
|
| 1702 |
-
|
| 1703 |
-
|
| 1704 |
$value = $data;
|
| 1705 |
-
|
| 1706 |
-
|
| 1707 |
$value = array();
|
| 1708 |
|
| 1709 |
foreach ( $data as $item_id => $item ) {
|
| 1710 |
// $field is 123x123, needs to be _src.123x123
|
| 1711 |
-
$
|
| 1712 |
-
$full_field = implode( '.', $traverse_fields );
|
| 1713 |
-
array_shift( $traverse_fields );
|
| 1714 |
|
| 1715 |
-
if (
|
| 1716 |
-
if ( $table['field_id'] === $field ) {
|
| 1717 |
-
$value[] = (int) $item[ $field ];
|
| 1718 |
-
} else {
|
| 1719 |
-
$value[] = $item[ $field ];
|
| 1720 |
-
}
|
| 1721 |
-
} elseif ( is_object( $item ) && isset( $item->{$field} ) ) {
|
| 1722 |
-
if ( $table['field_id'] === $field ) {
|
| 1723 |
-
$value[] = (int) $item->{$field};
|
| 1724 |
-
} else {
|
| 1725 |
-
$value[] = $item->{$field};
|
| 1726 |
-
}
|
| 1727 |
-
} elseif ( ! empty( $related_obj ) && 0 === strpos( $full_field, 'post_thumbnail' ) ) {
|
| 1728 |
-
// We want to catch post_thumbnail and post_thumbnail_url here
|
| 1729 |
-
$value[] = $related_obj->field( $full_field );
|
| 1730 |
-
} elseif (
|
| 1731 |
-
(
|
| 1732 |
-
( false !== strpos( $full_field, '_src' ) || 'guid' === $field )
|
| 1733 |
-
&& (
|
| 1734 |
-
in_array( $table['type'], array( 'attachment', 'media' ), true )
|
| 1735 |
-
|| in_array( $last_type, PodsForm::file_field_types(), true )
|
| 1736 |
-
)
|
| 1737 |
-
)
|
| 1738 |
-
|| ( in_array( $field, $permalink_fields, true ) && in_array( $last_type, PodsForm::file_field_types(), true ) )
|
| 1739 |
-
) {
|
| 1740 |
-
// @todo Refactor the above condition statement.
|
| 1741 |
$size = 'full';
|
| 1742 |
|
| 1743 |
-
if (
|
| 1744 |
-
// No default sizes for non-images.
|
| 1745 |
-
// When a size is defined this will be overwritten.
|
| 1746 |
-
$size = null;
|
| 1747 |
-
}
|
| 1748 |
-
|
| 1749 |
-
if ( false !== strpos( $full_field, '_src.' ) && 5 < strlen( $full_field ) ) {
|
| 1750 |
$size = substr( $full_field, 5 );
|
| 1751 |
-
|
| 1752 |
$size = substr( $full_field, 14 );
|
| 1753 |
-
|
| 1754 |
$size = substr( $full_field, 16 );
|
| 1755 |
-
}
|
| 1756 |
|
| 1757 |
-
|
| 1758 |
-
$value_url = pods_image_url( $item_id, $size, 0, true );
|
| 1759 |
-
} else {
|
| 1760 |
-
$value_url = wp_get_attachment_url( $item_id );
|
| 1761 |
-
}
|
| 1762 |
|
| 1763 |
-
if ( !
|
| 1764 |
-
|
| 1765 |
-
|
| 1766 |
-
$value_url = $value_url_parsed['path'];
|
| 1767 |
-
} elseif ( false !== strpos( $full_field, '_src_schemeless' ) ) {
|
| 1768 |
-
$value_url = str_replace( array(
|
| 1769 |
-
'http://',
|
| 1770 |
-
'https://',
|
| 1771 |
-
), '//', $value_url );
|
| 1772 |
-
}
|
| 1773 |
}
|
|
|
|
|
|
|
| 1774 |
|
| 1775 |
-
if ( !
|
| 1776 |
$value[] = $value_url;
|
| 1777 |
-
}
|
| 1778 |
|
| 1779 |
$params->raw_display = true;
|
| 1780 |
-
}
|
| 1781 |
-
|
| 1782 |
-
'media',
|
| 1783 |
-
), true ) || in_array( $last_type, PodsForm::file_field_types(), true ) ) ) {
|
| 1784 |
$size = 'full';
|
| 1785 |
|
| 1786 |
-
if ( false !== strpos( $full_field, '_img.' ) && 5 < strlen( $full_field ) )
|
| 1787 |
$size = substr( $full_field, 5 );
|
| 1788 |
-
}
|
| 1789 |
|
| 1790 |
-
$value[] = pods_image( $item_id, $size
|
| 1791 |
|
| 1792 |
$params->raw_display = true;
|
| 1793 |
-
}
|
| 1794 |
-
|
| 1795 |
-
'
|
| 1796 |
-
), true ) || in_array( $field, array( 'permalink', 'the_permalink' ), true ) ) {
|
| 1797 |
-
if ( 'pod' === $object_type ) {
|
| 1798 |
if ( is_object( $related_obj ) ) {
|
| 1799 |
$related_obj->fetch( $item_id );
|
| 1800 |
|
| 1801 |
$value[] = $related_obj->field( 'detail_url' );
|
| 1802 |
-
} else {
|
| 1803 |
-
$value[] = '';
|
| 1804 |
}
|
| 1805 |
-
|
|
|
|
|
|
|
|
|
|
| 1806 |
$value[] = get_permalink( $item_id );
|
| 1807 |
-
|
| 1808 |
$value[] = get_term_link( $item_id, $object );
|
| 1809 |
-
|
| 1810 |
$value[] = get_author_posts_url( $item_id );
|
| 1811 |
-
|
| 1812 |
$value[] = get_comment_link( $item_id );
|
| 1813 |
-
|
| 1814 |
$value[] = '';
|
| 1815 |
-
}
|
| 1816 |
|
| 1817 |
$params->raw_display = true;
|
| 1818 |
-
}
|
| 1819 |
-
|
| 1820 |
-
'
|
| 1821 |
-
|
| 1822 |
-
|
| 1823 |
-
|
| 1824 |
-
|
| 1825 |
-
|
| 1826 |
-
$
|
| 1827 |
-
|
| 1828 |
-
|
| 1829 |
-
|
| 1830 |
-
|
| 1831 |
-
|
| 1832 |
-
|
| 1833 |
-
|
| 1834 |
-
|
| 1835 |
-
|
| 1836 |
-
|
| 1837 |
-
|
| 1838 |
-
$metadata_type = 'term';
|
| 1839 |
}
|
| 1840 |
|
| 1841 |
-
$
|
| 1842 |
-
|
| 1843 |
-
|
| 1844 |
-
$
|
| 1845 |
-
|
| 1846 |
-
|
| 1847 |
-
}
|
| 1848 |
-
}//end if
|
| 1849 |
-
|
| 1850 |
-
if ( $object_no_conflict && ! $no_conflict ) {
|
| 1851 |
-
// Revert temporarily no conflict mode.
|
| 1852 |
-
pods_no_conflict_off( $object_type );
|
| 1853 |
}
|
| 1854 |
|
| 1855 |
-
|
|
|
|
|
|
|
|
|
|
| 1856 |
if ( $simple ) {
|
| 1857 |
-
if ( null === $params->single )
|
| 1858 |
$params->single = false;
|
| 1859 |
-
}
|
| 1860 |
|
| 1861 |
$value = PodsForm::field_method( 'pick', 'simple_value', $field, $value, $last_options, $all_fields[ $pod ], 0, true );
|
| 1862 |
-
} elseif ( false === $params->in_form && ! empty( $value ) && is_array( $value ) && false === $params->keyed ) {
|
| 1863 |
-
$value = array_values( $value );
|
| 1864 |
}
|
|
|
|
|
|
|
| 1865 |
|
| 1866 |
-
// Return a single column value
|
| 1867 |
-
if ( false === $params->in_form && 1
|
| 1868 |
$value = current( $value );
|
| 1869 |
-
|
| 1870 |
-
}//end if
|
| 1871 |
|
| 1872 |
if ( $last_options ) {
|
| 1873 |
$last_field_data = $last_options;
|
| 1874 |
-
} elseif ( isset( $related_obj, $related_obj->fields, $related_obj->fields[ $field ] ) ) {
|
| 1875 |
-
// Save related field data for later to be used for display formatting
|
| 1876 |
-
$last_field_data = $related_obj->fields[ $field ];
|
| 1877 |
}
|
| 1878 |
|
| 1879 |
break;
|
| 1880 |
-
}
|
| 1881 |
-
}
|
| 1882 |
-
}
|
| 1883 |
-
}
|
| 1884 |
-
}
|
| 1885 |
|
| 1886 |
-
if ( !
|
| 1887 |
$field_names = implode( '.', $params->traverse );
|
| 1888 |
|
| 1889 |
$this->row[ $field_names ] = $value;
|
| 1890 |
-
}
|
|
|
|
| 1891 |
$this->row[ '_' . $params->output . '_' . $params->full_name ] = $value;
|
| 1892 |
-
}
|
|
|
|
| 1893 |
$this->row[ $params->full_name ] = $value;
|
| 1894 |
}
|
| 1895 |
|
| 1896 |
-
if (
|
| 1897 |
$value = current( $value );
|
| 1898 |
-
}
|
| 1899 |
|
| 1900 |
if ( ! empty( $last_field_data ) ) {
|
| 1901 |
$field_data = $last_field_data;
|
| 1902 |
}
|
| 1903 |
|
| 1904 |
-
|
| 1905 |
-
|
| 1906 |
-
|
|
|
|
| 1907 |
|
| 1908 |
-
$post_temp
|
| 1909 |
-
$old_post = null;
|
| 1910 |
-
$old_post_id = null;
|
| 1911 |
-
$post_ID = null;
|
| 1912 |
|
| 1913 |
-
if (
|
| 1914 |
global $post_ID, $post;
|
| 1915 |
|
| 1916 |
$post_temp = true;
|
| 1917 |
|
| 1918 |
-
$old_post
|
| 1919 |
-
$
|
| 1920 |
|
| 1921 |
-
|
| 1922 |
-
$post = get_post( $this->id() );
|
| 1923 |
-
// @codingStandardsIgnoreLine.
|
| 1924 |
$post_ID = $this->id();
|
| 1925 |
}
|
| 1926 |
|
| 1927 |
-
$filter =
|
| 1928 |
|
| 1929 |
if ( 0 < strlen( $filter ) ) {
|
| 1930 |
$args = array(
|
| 1931 |
$filter,
|
| 1932 |
-
$value
|
| 1933 |
);
|
| 1934 |
|
| 1935 |
-
$filter_args =
|
| 1936 |
|
| 1937 |
-
if ( !
|
| 1938 |
$args = array_merge( $args, compact( $filter_args ) );
|
| 1939 |
-
}
|
| 1940 |
|
| 1941 |
$value = call_user_func_array( 'apply_filters', $args );
|
| 1942 |
-
}
|
| 1943 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1944 |
}
|
| 1945 |
|
| 1946 |
if ( $post_temp ) {
|
| 1947 |
-
|
| 1948 |
-
$
|
| 1949 |
-
// @codingStandardsIgnoreLine.
|
| 1950 |
-
$post_ID = $old_post_id;
|
| 1951 |
}
|
| 1952 |
-
}
|
| 1953 |
-
|
| 1954 |
-
|
| 1955 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1956 |
|
| 1957 |
/**
|
| 1958 |
* Modify value returned by field() directly before output.
|
|
@@ -1961,10 +1625,11 @@ class Pods implements Iterator {
|
|
| 1961 |
*
|
| 1962 |
* @since unknown
|
| 1963 |
*
|
| 1964 |
-
* @param array|string|null $value
|
| 1965 |
-
* @param array|object
|
| 1966 |
-
* @param array
|
| 1967 |
-
* @param object|Pods
|
|
|
|
| 1968 |
*/
|
| 1969 |
$value = apply_filters( 'pods_pods_field', $value, $this->row, $params, $this );
|
| 1970 |
|
|
@@ -1974,79 +1639,71 @@ class Pods implements Iterator {
|
|
| 1974 |
/**
|
| 1975 |
* Check if an item field has a specific value in it
|
| 1976 |
*
|
| 1977 |
-
* @param string $field Field name
|
| 1978 |
-
* @param mixed
|
| 1979 |
-
* @param int
|
| 1980 |
*
|
| 1981 |
* @return bool Whether the value was found
|
| 1982 |
*
|
| 1983 |
* @since 2.3.3
|
| 1984 |
*/
|
| 1985 |
-
public function has( $field, $value, $id = null ) {
|
| 1986 |
-
|
| 1987 |
$pod =& $this;
|
| 1988 |
|
| 1989 |
-
if ( null === $id )
|
| 1990 |
$id = $this->id();
|
| 1991 |
-
|
| 1992 |
-
} elseif ( $id != $this->id() ) {
|
| 1993 |
$pod = pods( $this->pod, $id );
|
| 1994 |
-
}
|
| 1995 |
|
| 1996 |
$this->do_hook( 'has', $field, $value, $id );
|
| 1997 |
|
| 1998 |
-
if ( !
|
| 1999 |
return false;
|
| 2000 |
-
}
|
| 2001 |
|
| 2002 |
-
// Tableless fields
|
| 2003 |
-
if ( in_array( $this->fields[ $field ]['type'], PodsForm::tableless_field_types()
|
| 2004 |
-
if ( !
|
| 2005 |
$value = explode( ',', $value );
|
| 2006 |
-
}
|
| 2007 |
|
| 2008 |
-
if ( 'pick'
|
| 2009 |
$current_value = $pod->raw( $field );
|
| 2010 |
|
| 2011 |
-
if ( !
|
| 2012 |
$current_value = (array) $current_value;
|
| 2013 |
-
}
|
| 2014 |
|
| 2015 |
foreach ( $current_value as $v ) {
|
| 2016 |
-
|
| 2017 |
-
if ( in_array( $v, $value ) ) {
|
| 2018 |
return true;
|
| 2019 |
-
}
|
| 2020 |
}
|
| 2021 |
-
}
|
| 2022 |
-
|
|
|
|
| 2023 |
|
| 2024 |
foreach ( $value as $k => $v ) {
|
| 2025 |
-
if ( !
|
| 2026 |
$value[ $k ] = (int) $v;
|
| 2027 |
-
|
|
|
|
| 2028 |
|
| 2029 |
-
|
| 2030 |
}
|
| 2031 |
|
| 2032 |
foreach ( $related_ids as $v ) {
|
| 2033 |
-
|
| 2034 |
-
if ( in_array( $v, $value ) ) {
|
| 2035 |
return true;
|
| 2036 |
-
}
|
| 2037 |
}
|
| 2038 |
-
}
|
| 2039 |
-
}
|
| 2040 |
-
|
|
|
|
| 2041 |
$current_value = $pod->raw( $field );
|
| 2042 |
|
| 2043 |
-
if ( 0 < strlen( $current_value ) )
|
| 2044 |
return stripos( $current_value, $value );
|
| 2045 |
-
|
| 2046 |
-
|
| 2047 |
-
|
| 2048 |
return $this->is( $field, $value, $id );
|
| 2049 |
-
}//end if
|
| 2050 |
|
| 2051 |
return false;
|
| 2052 |
}
|
|
@@ -2054,122 +1711,111 @@ class Pods implements Iterator {
|
|
| 2054 |
/**
|
| 2055 |
* Check if an item field is a specific value
|
| 2056 |
*
|
| 2057 |
-
* @param string $field Field name
|
| 2058 |
-
* @param mixed
|
| 2059 |
-
* @param int
|
| 2060 |
*
|
| 2061 |
* @return bool Whether the value was found
|
| 2062 |
*
|
| 2063 |
* @since 2.3.3
|
| 2064 |
*/
|
| 2065 |
-
public function is( $field, $value, $id = null ) {
|
| 2066 |
-
|
| 2067 |
$pod =& $this;
|
| 2068 |
|
| 2069 |
-
if ( null === $id )
|
| 2070 |
$id = $this->id();
|
| 2071 |
-
|
| 2072 |
-
} elseif ( $id != $this->id() ) {
|
| 2073 |
$pod = pods( $this->pod, $id );
|
| 2074 |
-
}
|
| 2075 |
|
| 2076 |
$this->do_hook( 'is', $field, $value, $id );
|
| 2077 |
|
| 2078 |
-
if ( !
|
| 2079 |
return false;
|
| 2080 |
-
}
|
| 2081 |
|
| 2082 |
-
// Tableless fields
|
| 2083 |
-
if ( in_array( $this->fields[ $field ]['type'], PodsForm::tableless_field_types()
|
| 2084 |
-
if ( !
|
| 2085 |
$value = explode( ',', $value );
|
| 2086 |
-
}
|
| 2087 |
|
| 2088 |
$current_value = array();
|
| 2089 |
|
| 2090 |
-
if ( 'pick'
|
| 2091 |
$current_value = $pod->raw( $field );
|
| 2092 |
|
| 2093 |
-
if ( !
|
| 2094 |
$current_value = (array) $current_value;
|
| 2095 |
-
}
|
| 2096 |
|
| 2097 |
foreach ( $current_value as $v ) {
|
| 2098 |
-
|
| 2099 |
-
if ( in_array( $v, $value ) ) {
|
| 2100 |
return true;
|
| 2101 |
-
}
|
| 2102 |
}
|
| 2103 |
-
}
|
| 2104 |
-
|
|
|
|
| 2105 |
|
| 2106 |
foreach ( $value as $k => $v ) {
|
| 2107 |
-
if ( !
|
| 2108 |
$value[ $k ] = (int) $v;
|
| 2109 |
-
|
|
|
|
| 2110 |
|
| 2111 |
-
|
| 2112 |
}
|
| 2113 |
|
| 2114 |
foreach ( $related_ids as $v ) {
|
| 2115 |
-
|
| 2116 |
-
if ( in_array( $v, $value ) ) {
|
| 2117 |
return true;
|
| 2118 |
-
}
|
| 2119 |
}
|
| 2120 |
-
}
|
| 2121 |
|
| 2122 |
-
if ( !
|
| 2123 |
$current_value = array_filter( array_unique( $current_value ) );
|
| 2124 |
-
|
| 2125 |
$current_value = array();
|
| 2126 |
-
}
|
| 2127 |
|
| 2128 |
-
if ( !
|
| 2129 |
$value = array_filter( array_unique( $value ) );
|
| 2130 |
-
|
| 2131 |
$value = array();
|
| 2132 |
-
}
|
| 2133 |
|
| 2134 |
sort( $current_value );
|
| 2135 |
sort( $value );
|
| 2136 |
|
| 2137 |
-
if ( $value === $current_value )
|
| 2138 |
return true;
|
| 2139 |
-
|
| 2140 |
-
|
| 2141 |
-
|
| 2142 |
$current_value = $pod->raw( $field );
|
| 2143 |
|
| 2144 |
-
if ( (float) $current_value === (float) $value )
|
| 2145 |
return true;
|
| 2146 |
-
|
| 2147 |
-
|
| 2148 |
-
|
| 2149 |
$current_value = $pod->raw( $field );
|
| 2150 |
|
| 2151 |
if ( 0 < strlen( $current_value ) ) {
|
| 2152 |
-
if ( strtotime( $current_value )
|
| 2153 |
return true;
|
| 2154 |
-
}
|
| 2155 |
-
} elseif ( empty( $value ) ) {
|
| 2156 |
-
return true;
|
| 2157 |
}
|
| 2158 |
-
|
| 2159 |
-
|
|
|
|
|
|
|
|
|
|
| 2160 |
$current_value = $pod->raw( $field );
|
| 2161 |
|
| 2162 |
-
if ( (string) $current_value === (string) $value )
|
| 2163 |
return true;
|
| 2164 |
-
|
| 2165 |
-
|
| 2166 |
-
|
| 2167 |
$current_value = $pod->raw( $field );
|
| 2168 |
|
| 2169 |
-
if ( $current_value === $value )
|
| 2170 |
return true;
|
| 2171 |
-
|
| 2172 |
-
}//end if
|
| 2173 |
|
| 2174 |
return false;
|
| 2175 |
}
|
|
@@ -2178,101 +1824,98 @@ class Pods implements Iterator {
|
|
| 2178 |
* Return the item ID
|
| 2179 |
*
|
| 2180 |
* @return int
|
| 2181 |
-
* @since 2.0
|
| 2182 |
*/
|
| 2183 |
-
public function id() {
|
| 2184 |
-
|
| 2185 |
-
|
| 2186 |
-
|
| 2187 |
-
return $this->data->row['id'];
|
| 2188 |
}
|
| 2189 |
-
|
| 2190 |
return $this->field( $this->data->field_id );
|
| 2191 |
}
|
| 2192 |
|
| 2193 |
/**
|
| 2194 |
* Return the previous item ID, loops at the last id to return the first
|
| 2195 |
*
|
| 2196 |
-
* @param int
|
| 2197 |
-
* @param array
|
| 2198 |
*
|
| 2199 |
* @return int
|
| 2200 |
-
* @since 2.0
|
| 2201 |
*/
|
| 2202 |
-
public function prev_id( $id = null, $params_override = null ) {
|
| 2203 |
-
|
| 2204 |
-
if ( null === $id ) {
|
| 2205 |
$id = $this->id();
|
| 2206 |
-
}
|
| 2207 |
|
| 2208 |
$id = (int) $id;
|
| 2209 |
|
| 2210 |
$params = array(
|
| 2211 |
-
'select'
|
| 2212 |
-
'where'
|
| 2213 |
'orderby' => "`t`.`{$this->data->field_id}` DESC",
|
| 2214 |
-
'limit'
|
| 2215 |
);
|
| 2216 |
|
| 2217 |
-
if ( !
|
| 2218 |
-
if ( !
|
| 2219 |
$params = $params_override;
|
| 2220 |
-
|
| 2221 |
$params = $this->params;
|
| 2222 |
-
}
|
| 2223 |
|
| 2224 |
if ( is_object( $params ) ) {
|
| 2225 |
$params = get_object_vars( $params );
|
| 2226 |
}
|
| 2227 |
|
| 2228 |
if ( 0 < $id ) {
|
| 2229 |
-
if ( isset( $params['where'] ) && !
|
| 2230 |
-
$params['where']
|
| 2231 |
-
$params['where'][] = "`t`.`{$this->data->field_id}` < {$id}";
|
| 2232 |
-
}
|
| 2233 |
-
|
|
|
|
| 2234 |
}
|
| 2235 |
-
} elseif ( isset( $params['offset'] ) && 0 < $params['offset'] ) {
|
| 2236 |
-
$params['offset'] --;
|
| 2237 |
-
} elseif ( 0 < $this->row_number && ! isset( $params['offset'] ) && ! empty( $this->params ) ) {
|
| 2238 |
-
$params['offset'] = $this->row_number - 1;
|
| 2239 |
-
} else {
|
| 2240 |
-
return 0;
|
| 2241 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2242 |
|
| 2243 |
-
if ( isset( $params['orderby'] ) && !
|
| 2244 |
-
if ( is_array( $params['orderby'] ) ) {
|
| 2245 |
-
foreach ( $params['orderby'] as $orderby => $dir ) {
|
| 2246 |
$dir = strtoupper( $dir );
|
| 2247 |
|
| 2248 |
-
if ( !
|
| 2249 |
continue;
|
| 2250 |
}
|
| 2251 |
|
| 2252 |
-
if ( 'ASC'
|
| 2253 |
-
$params['orderby'][ $orderby ] = 'DESC';
|
| 2254 |
-
}
|
| 2255 |
-
|
|
|
|
| 2256 |
}
|
| 2257 |
}
|
| 2258 |
|
| 2259 |
-
$params['orderby'][ $this->data->field_id ] = 'DESC';
|
| 2260 |
-
} elseif ( "`t`.`{$this->data->field_id}` DESC" !== $params['orderby'] ) {
|
| 2261 |
-
$params['orderby'] .= ", `t`.`{$this->data->field_id}` DESC";
|
| 2262 |
}
|
| 2263 |
-
|
|
|
|
|
|
|
|
|
|
| 2264 |
|
| 2265 |
-
$params['select'] = "`t`.`{$this->data->field_id}`";
|
| 2266 |
-
$params['limit']
|
| 2267 |
-
}
|
| 2268 |
|
| 2269 |
$pod = pods( $this->pod, $params );
|
| 2270 |
|
| 2271 |
$new_id = 0;
|
| 2272 |
|
| 2273 |
-
if ( $pod->fetch() )
|
| 2274 |
$new_id = $pod->id();
|
| 2275 |
-
}
|
| 2276 |
|
| 2277 |
$new_id = $this->do_hook( 'prev_id', $new_id, $id, $pod, $params_override );
|
| 2278 |
|
|
@@ -2282,66 +1925,63 @@ class Pods implements Iterator {
|
|
| 2282 |
/**
|
| 2283 |
* Return the next item ID, loops at the first id to return the last
|
| 2284 |
*
|
| 2285 |
-
* @param int
|
| 2286 |
-
* @param array
|
| 2287 |
*
|
| 2288 |
* @return int
|
| 2289 |
-
* @since 2.0
|
| 2290 |
*/
|
| 2291 |
-
public function next_id( $id = null, $params_override = null ) {
|
| 2292 |
-
|
| 2293 |
-
if ( null === $id ) {
|
| 2294 |
$id = $this->id();
|
| 2295 |
-
}
|
| 2296 |
|
| 2297 |
$id = (int) $id;
|
| 2298 |
|
| 2299 |
$params = array(
|
| 2300 |
-
'select'
|
| 2301 |
-
'where'
|
| 2302 |
'orderby' => "`t`.`{$this->data->field_id}` ASC",
|
| 2303 |
-
'limit'
|
| 2304 |
);
|
| 2305 |
|
| 2306 |
-
if ( !
|
| 2307 |
-
if ( !
|
| 2308 |
$params = $params_override;
|
| 2309 |
-
|
| 2310 |
$params = $this->params;
|
| 2311 |
-
}
|
| 2312 |
|
| 2313 |
if ( is_object( $params ) ) {
|
| 2314 |
$params = get_object_vars( $params );
|
| 2315 |
}
|
| 2316 |
|
| 2317 |
if ( 0 < $id ) {
|
| 2318 |
-
if ( isset( $params['where'] ) && !
|
| 2319 |
-
$params['where']
|
| 2320 |
-
$params['where'][] = "{$id} < `t`.`{$this->data->field_id}`";
|
| 2321 |
-
} else {
|
| 2322 |
-
$params['where'] = "{$id} < `t`.`{$this->data->field_id}`";
|
| 2323 |
}
|
| 2324 |
-
|
| 2325 |
-
|
| 2326 |
-
$params['offset'] = $this->row_number + 1;
|
| 2327 |
-
} else {
|
| 2328 |
-
$params['offset'] = 1;
|
| 2329 |
}
|
| 2330 |
-
} else {
|
| 2331 |
-
$params['offset'] ++;
|
| 2332 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2333 |
|
| 2334 |
-
$params['select'] = "`t`.`{$this->data->field_id}`";
|
| 2335 |
-
$params['limit']
|
| 2336 |
-
}
|
| 2337 |
|
| 2338 |
$pod = pods( $this->pod, $params );
|
| 2339 |
|
| 2340 |
$new_id = 0;
|
| 2341 |
|
| 2342 |
-
if ( $pod->fetch() )
|
| 2343 |
$new_id = $pod->id();
|
| 2344 |
-
}
|
| 2345 |
|
| 2346 |
$new_id = $this->do_hook( 'next_id', $new_id, $id, $pod, $params_override );
|
| 2347 |
|
|
@@ -2351,42 +1991,39 @@ class Pods implements Iterator {
|
|
| 2351 |
/**
|
| 2352 |
* Return the first item ID
|
| 2353 |
*
|
| 2354 |
-
* @param array
|
| 2355 |
*
|
| 2356 |
* @return int
|
| 2357 |
-
* @since 2.3
|
| 2358 |
*/
|
| 2359 |
-
public function first_id( $params_override = null ) {
|
| 2360 |
-
|
| 2361 |
$params = array(
|
| 2362 |
-
'select'
|
| 2363 |
'orderby' => "`t`.`{$this->data->field_id}` ASC",
|
| 2364 |
-
'limit'
|
| 2365 |
);
|
| 2366 |
|
| 2367 |
-
if ( !
|
| 2368 |
-
if ( !
|
| 2369 |
$params = $params_override;
|
| 2370 |
-
|
| 2371 |
$params = $this->params;
|
| 2372 |
-
}
|
| 2373 |
|
| 2374 |
if ( is_object( $params ) ) {
|
| 2375 |
$params = get_object_vars( $params );
|
| 2376 |
}
|
| 2377 |
|
| 2378 |
-
$params['select'] = "`t`.`{$this->data->field_id}`";
|
| 2379 |
-
$params['offset'] = 0;
|
| 2380 |
-
$params['limit']
|
| 2381 |
}
|
| 2382 |
|
| 2383 |
$pod = pods( $this->pod, $params );
|
| 2384 |
|
| 2385 |
$new_id = 0;
|
| 2386 |
|
| 2387 |
-
if ( $pod->fetch() )
|
| 2388 |
$new_id = $pod->id();
|
| 2389 |
-
}
|
| 2390 |
|
| 2391 |
$new_id = $this->do_hook( 'first_id', $new_id, $pod, $params_override );
|
| 2392 |
|
|
@@ -2396,72 +2033,69 @@ class Pods implements Iterator {
|
|
| 2396 |
/**
|
| 2397 |
* Return the last item ID
|
| 2398 |
*
|
| 2399 |
-
* @param array
|
| 2400 |
*
|
| 2401 |
* @return int
|
| 2402 |
-
* @since 2.3
|
| 2403 |
*/
|
| 2404 |
-
public function last_id( $params_override = null ) {
|
| 2405 |
-
|
| 2406 |
$params = array(
|
| 2407 |
-
'select'
|
| 2408 |
'orderby' => "`t`.`{$this->data->field_id}` DESC",
|
| 2409 |
-
'limit'
|
| 2410 |
);
|
| 2411 |
|
| 2412 |
-
if ( !
|
| 2413 |
-
if ( !
|
| 2414 |
$params = $params_override;
|
| 2415 |
-
|
| 2416 |
$params = $this->params;
|
| 2417 |
-
}
|
| 2418 |
|
| 2419 |
if ( is_object( $params ) ) {
|
| 2420 |
$params = get_object_vars( $params );
|
| 2421 |
}
|
| 2422 |
|
| 2423 |
-
if ( isset( $params['total_found'] ) )
|
| 2424 |
-
$params['offset'] = $params['total_found'] - 1;
|
| 2425 |
-
|
| 2426 |
-
$params['offset'] = $this->total_found() - 1;
|
| 2427 |
-
}
|
| 2428 |
|
| 2429 |
-
if ( isset( $params['orderby'] ) && !
|
| 2430 |
-
if ( is_array( $params['orderby'] ) ) {
|
| 2431 |
-
foreach ( $params['orderby'] as $orderby => $dir ) {
|
| 2432 |
$dir = strtoupper( $dir );
|
| 2433 |
|
| 2434 |
-
if ( !
|
| 2435 |
continue;
|
| 2436 |
}
|
| 2437 |
|
| 2438 |
-
if ( 'ASC'
|
| 2439 |
-
$params['orderby'][ $orderby ] = 'DESC';
|
| 2440 |
-
}
|
| 2441 |
-
|
|
|
|
| 2442 |
}
|
| 2443 |
}
|
| 2444 |
|
| 2445 |
-
$params['orderby'][ $this->data->field_id ] = 'DESC';
|
| 2446 |
-
}
|
| 2447 |
-
|
|
|
|
| 2448 |
}
|
| 2449 |
-
}
|
| 2450 |
|
| 2451 |
-
$params['select'] = "`t`.`{$this->data->field_id}`";
|
| 2452 |
-
$params['limit']
|
| 2453 |
-
}
|
| 2454 |
|
| 2455 |
$pod = pods( $this->pod, $params );
|
| 2456 |
|
| 2457 |
$new_id = 0;
|
| 2458 |
|
| 2459 |
-
if ( $pod->fetch() )
|
| 2460 |
$new_id = $pod->id();
|
| 2461 |
-
}
|
| 2462 |
|
| 2463 |
$new_id = $this->do_hook( 'last_id', $new_id, $pod, $params_override );
|
| 2464 |
-
|
| 2465 |
return $new_id;
|
| 2466 |
}
|
| 2467 |
|
|
@@ -2469,248 +2103,219 @@ class Pods implements Iterator {
|
|
| 2469 |
* Return the item name
|
| 2470 |
*
|
| 2471 |
* @return string
|
| 2472 |
-
* @since 2.0
|
| 2473 |
*/
|
| 2474 |
-
public function index() {
|
| 2475 |
-
|
| 2476 |
return $this->field( $this->data->field_index );
|
| 2477 |
}
|
| 2478 |
|
| 2479 |
/**
|
| 2480 |
* Find items of a pod, much like WP_Query, but with advanced table handling.
|
| 2481 |
*
|
| 2482 |
-
* @param array
|
| 2483 |
-
* @param int
|
| 2484 |
-
* @param string
|
| 2485 |
-
* @param string
|
| 2486 |
*
|
| 2487 |
* @return \Pods The pod object
|
| 2488 |
-
* @since 2.0
|
| 2489 |
-
* @link
|
| 2490 |
*/
|
| 2491 |
-
public function find( $params = null, $limit = 15, $where = null, $sql = null ) {
|
| 2492 |
|
| 2493 |
-
$tableless_field_types
|
| 2494 |
$simple_tableless_objects = PodsForm::simple_tableless_objects();
|
| 2495 |
|
|
|
|
| 2496 |
$this->params = $params;
|
| 2497 |
|
| 2498 |
$select = '`t`.*';
|
| 2499 |
|
| 2500 |
-
if (
|
| 2501 |
-
'pod',
|
| 2502 |
-
'table',
|
| 2503 |
-
), true ) ) {
|
| 2504 |
$select .= ', `d`.*';
|
| 2505 |
-
}
|
| 2506 |
|
| 2507 |
-
if ( empty( $this->data->table ) )
|
| 2508 |
return $this;
|
| 2509 |
-
}
|
| 2510 |
|
| 2511 |
$defaults = array(
|
| 2512 |
-
|
| 2513 |
-
'
|
| 2514 |
-
'
|
| 2515 |
-
|
| 2516 |
-
|
| 2517 |
-
'
|
| 2518 |
-
'
|
| 2519 |
-
'
|
| 2520 |
-
|
| 2521 |
-
|
| 2522 |
-
'
|
| 2523 |
-
'
|
| 2524 |
-
'
|
| 2525 |
-
'
|
| 2526 |
-
|
| 2527 |
-
|
| 2528 |
-
'
|
| 2529 |
-
'
|
| 2530 |
-
'
|
| 2531 |
-
'
|
| 2532 |
-
'search_across' => false,
|
| 2533 |
'search_across_picks' => false,
|
| 2534 |
'search_across_files' => false,
|
| 2535 |
-
|
| 2536 |
-
'filters'
|
| 2537 |
-
'sql'
|
| 2538 |
-
|
| 2539 |
-
'expires'
|
| 2540 |
-
'cache_mode'
|
| 2541 |
);
|
| 2542 |
|
| 2543 |
-
if ( is_array( $params ) )
|
| 2544 |
$params = (object) array_merge( $defaults, $params );
|
| 2545 |
-
|
| 2546 |
$params = (object) array_merge( $defaults, get_object_vars( $params ) );
|
| 2547 |
-
|
| 2548 |
-
$defaults['orderby'] = $params;
|
| 2549 |
-
|
| 2550 |
$params = (object) $defaults;
|
| 2551 |
}
|
| 2552 |
|
| 2553 |
-
/**
|
| 2554 |
-
* Filter the Pods::find() parameters.
|
| 2555 |
-
*
|
| 2556 |
-
* @param object $params Parameters to make lookup with.
|
| 2557 |
-
*/
|
| 2558 |
$params = apply_filters( 'pods_pods_find', $params );
|
| 2559 |
|
| 2560 |
$params->limit = (int) $params->limit;
|
| 2561 |
|
| 2562 |
-
if ( 0
|
| 2563 |
-
$params->limit = -
|
| 2564 |
-
}
|
| 2565 |
|
| 2566 |
-
$this->limit
|
| 2567 |
-
$this->offset
|
| 2568 |
-
$this->page
|
| 2569 |
-
$this->page_var
|
| 2570 |
$this->pagination = (boolean) $params->pagination;
|
| 2571 |
-
$this->search
|
| 2572 |
$this->search_var = $params->search_var;
|
| 2573 |
-
$params->join
|
| 2574 |
|
| 2575 |
-
if ( empty( $params->search_query ) )
|
| 2576 |
-
$params->search_query =
|
| 2577 |
-
}
|
| 2578 |
|
| 2579 |
-
// Allow orderby array ( 'field' => 'asc|desc' )
|
| 2580 |
-
if ( !
|
| 2581 |
-
foreach ( $params->orderby as $k =>
|
| 2582 |
-
if ( !
|
| 2583 |
$key = '';
|
| 2584 |
|
| 2585 |
$order = 'ASC';
|
| 2586 |
|
| 2587 |
-
if ( 'DESC'
|
| 2588 |
$order = 'DESC';
|
| 2589 |
-
}
|
| 2590 |
|
| 2591 |
-
if ( isset( $this->fields[ $k ] ) && in_array( $this->fields[ $k ]['type'], $tableless_field_types
|
| 2592 |
-
if ( in_array( $this->fields[ $k ]['pick_object'], $simple_tableless_objects
|
| 2593 |
-
if ( 'table'
|
| 2594 |
-
if ( !
|
| 2595 |
$key = "`d`.`{$k}`";
|
| 2596 |
-
|
| 2597 |
$key = "`t`.`{$k}`";
|
| 2598 |
-
}
|
| 2599 |
-
} else {
|
| 2600 |
-
$key = "`{$k}`.`meta_value`";
|
| 2601 |
}
|
| 2602 |
-
|
| 2603 |
-
|
|
|
|
|
|
|
|
|
|
| 2604 |
|
| 2605 |
-
if ( '__current__'
|
| 2606 |
$pick_val = $this->pod;
|
| 2607 |
-
}
|
| 2608 |
|
| 2609 |
-
$table = $this->api->get_table_info( $this->fields[ $k ]['pick_object'], $pick_val );
|
| 2610 |
|
| 2611 |
-
if ( !
|
| 2612 |
-
$key = "`{$k}`.`" . $table['field_index'] . '`';
|
| 2613 |
-
|
| 2614 |
-
|
| 2615 |
-
}//end if
|
| 2616 |
|
| 2617 |
if ( empty( $key ) ) {
|
| 2618 |
-
if ( !
|
| 2619 |
-
if ( isset( $this->pod_data['object_fields'][ $k ] ) )
|
| 2620 |
$key = "`t`.`{$k}`";
|
| 2621 |
-
|
| 2622 |
-
if ( 'table'
|
| 2623 |
$key = "`d`.`{$k}`";
|
| 2624 |
-
|
| 2625 |
$key = "`{$k}`.`meta_value`";
|
| 2626 |
-
|
| 2627 |
-
|
| 2628 |
-
|
| 2629 |
-
|
| 2630 |
-
foreach ( $object_fields as $object_field => $object_field_opt ) {
|
| 2631 |
-
if ( $object_field === $k || in_array( $k, $object_field_opt['alias'], true ) ) {
|
| 2632 |
$key = "`t`.`{$object_field}`";
|
| 2633 |
-
}
|
| 2634 |
}
|
| 2635 |
}
|
| 2636 |
-
}
|
| 2637 |
-
|
|
|
|
| 2638 |
$key = "`t`.`{$k}`";
|
| 2639 |
-
|
| 2640 |
$key = "`{$k}`.`meta_value`";
|
| 2641 |
-
|
| 2642 |
-
}//end if
|
| 2643 |
|
| 2644 |
if ( empty( $key ) ) {
|
| 2645 |
$key = $k;
|
| 2646 |
|
| 2647 |
-
if ( false === strpos( $key, ' ' ) && false === strpos( $key, '`' ) )
|
| 2648 |
$key = '`' . str_replace( '.', '`.`', $key ) . '`';
|
| 2649 |
-
}
|
| 2650 |
}
|
| 2651 |
-
}
|
| 2652 |
|
| 2653 |
$orderby = $key;
|
| 2654 |
|
| 2655 |
-
if ( false === strpos( $orderby, ' ' ) )
|
| 2656 |
$orderby .= ' ' . $order;
|
| 2657 |
-
|
| 2658 |
-
|
| 2659 |
-
|
| 2660 |
-
}//end if
|
| 2661 |
-
}//end foreach
|
| 2662 |
-
}//end if
|
| 2663 |
|
| 2664 |
-
// Add prefix to $params->orderby if needed
|
| 2665 |
-
if ( !
|
| 2666 |
-
if ( !
|
| 2667 |
$params->orderby = array( $params->orderby );
|
| 2668 |
-
}
|
| 2669 |
|
| 2670 |
-
foreach ( $params->orderby as
|
| 2671 |
if ( false === strpos( $prefix_orderby, ',' ) && false === strpos( $prefix_orderby, '(' ) && false === stripos( $prefix_orderby, ' AS ' ) && false === strpos( $prefix_orderby, '`' ) && false === strpos( $prefix_orderby, '.' ) ) {
|
| 2672 |
if ( false !== stripos( $prefix_orderby, ' DESC' ) ) {
|
| 2673 |
-
$k
|
| 2674 |
$dir = 'DESC';
|
| 2675 |
-
}
|
| 2676 |
-
|
|
|
|
| 2677 |
$dir = 'ASC';
|
| 2678 |
}
|
| 2679 |
|
| 2680 |
$key = $k;
|
| 2681 |
|
| 2682 |
-
if ( !
|
| 2683 |
-
if ( isset( $this->pod_data['object_fields'][ $k ] ) )
|
| 2684 |
$key = "`t`.`{$k}`";
|
| 2685 |
-
|
| 2686 |
-
if ( 'table'
|
| 2687 |
$key = "`d`.`{$k}`";
|
| 2688 |
-
|
| 2689 |
$key = "`{$k}`.`meta_value`";
|
| 2690 |
-
|
| 2691 |
-
|
| 2692 |
-
|
| 2693 |
-
|
| 2694 |
-
foreach ( $object_fields as $object_field => $object_field_opt ) {
|
| 2695 |
-
if ( $object_field === $k || in_array( $k, $object_field_opt['alias'], true ) ) {
|
| 2696 |
$key = "`t`.`{$object_field}`";
|
| 2697 |
-
}
|
| 2698 |
}
|
| 2699 |
}
|
| 2700 |
-
}
|
| 2701 |
-
|
|
|
|
| 2702 |
$key = "`t`.`{$k}`";
|
| 2703 |
-
|
| 2704 |
$key = "`{$k}`.`meta_value`";
|
| 2705 |
-
|
| 2706 |
-
}//end if
|
| 2707 |
|
| 2708 |
$prefix_orderby = "{$key} {$dir}";
|
| 2709 |
-
|
| 2710 |
-
|
| 2711 |
-
|
| 2712 |
-
}//end foreach
|
| 2713 |
-
}//end if
|
| 2714 |
|
| 2715 |
$this->data->select( $params );
|
| 2716 |
|
|
@@ -2721,34 +2326,31 @@ class Pods implements Iterator {
|
|
| 2721 |
* Fetch an item from a Pod. If $id is null, it will return the next item in the list after running find().
|
| 2722 |
* You can rewind the list back to the start by using reset().
|
| 2723 |
*
|
| 2724 |
-
* Providing an $id will fetch a specific item from a Pod, much like a call to pods(), and can handle either an id
|
| 2725 |
-
* or slug.
|
| 2726 |
*
|
| 2727 |
-
* @see
|
| 2728 |
*
|
| 2729 |
-
* @param int
|
| 2730 |
-
* @param bool $explicit_set Whether to set explicitly (use false when in loop)
|
| 2731 |
*
|
| 2732 |
* @return array An array of fields from the row
|
| 2733 |
*
|
| 2734 |
-
* @since 2.0
|
| 2735 |
-
* @link
|
| 2736 |
*/
|
| 2737 |
-
public function fetch( $id = null, $explicit_set = true ) {
|
| 2738 |
-
|
| 2739 |
/**
|
| 2740 |
-
* Runs directly before an item is fetched by fetch()
|
| 2741 |
*
|
| 2742 |
* @since unknown
|
| 2743 |
*
|
| 2744 |
-
* @param int|string|null $id
|
| 2745 |
-
* @param object|Pods
|
| 2746 |
*/
|
| 2747 |
do_action( 'pods_pods_fetch', $id, $this );
|
| 2748 |
|
| 2749 |
-
if ( !
|
| 2750 |
$this->params = array();
|
| 2751 |
-
}
|
| 2752 |
|
| 2753 |
$this->data->fetch( $id, $explicit_set );
|
| 2754 |
|
|
@@ -2758,23 +2360,22 @@ class Pods implements Iterator {
|
|
| 2758 |
/**
|
| 2759 |
* (Re)set the MySQL result pointer
|
| 2760 |
*
|
| 2761 |
-
* @see
|
| 2762 |
*
|
| 2763 |
-
* @param int $row ID of the row to reset to
|
| 2764 |
*
|
| 2765 |
* @return \Pods The pod object
|
| 2766 |
*
|
| 2767 |
-
* @since 2.0
|
| 2768 |
-
* @link
|
| 2769 |
*/
|
| 2770 |
-
public function reset( $row = null ) {
|
| 2771 |
-
|
| 2772 |
/**
|
| 2773 |
* Runs directly before the Pods object is reset by reset()
|
| 2774 |
*
|
| 2775 |
* @since unknown
|
| 2776 |
*
|
| 2777 |
-
* @param int|string|null The ID of the row being reset to or null if being reset to the
|
| 2778 |
* @param object|Pods $this Current Pods object.
|
| 2779 |
*/
|
| 2780 |
do_action( 'pods_pods_reset', $row, $this );
|
|
@@ -2789,14 +2390,13 @@ class Pods implements Iterator {
|
|
| 2789 |
*
|
| 2790 |
* This is different than the total number of rows found in the database, which you can get with total_found().
|
| 2791 |
*
|
| 2792 |
-
* @see
|
| 2793 |
*
|
| 2794 |
* @return int Number of rows returned by find(), based on the 'limit' parameter set
|
| 2795 |
-
* @since 2.0
|
| 2796 |
-
* @link
|
| 2797 |
*/
|
| 2798 |
-
public function total() {
|
| 2799 |
-
|
| 2800 |
do_action( 'pods_pods_total', $this );
|
| 2801 |
|
| 2802 |
$this->data->total();
|
|
@@ -2811,20 +2411,20 @@ class Pods implements Iterator {
|
|
| 2811 |
*
|
| 2812 |
* This is different than the total number of rows limited by the current call, which you can get with total().
|
| 2813 |
*
|
| 2814 |
-
* @see
|
| 2815 |
*
|
| 2816 |
* @return int Number of rows returned by find(), regardless of the 'limit' parameter
|
| 2817 |
-
* @since 2.0
|
| 2818 |
-
* @link
|
| 2819 |
*/
|
| 2820 |
-
public function total_found() {
|
| 2821 |
-
|
| 2822 |
/**
|
| 2823 |
* Runs directly before the value of total_found() is determined and returned.
|
| 2824 |
*
|
| 2825 |
* @since unknown
|
| 2826 |
*
|
| 2827 |
* @param object|Pods $this Current Pods object.
|
|
|
|
| 2828 |
*/
|
| 2829 |
do_action( 'pods_pods_total_found', $this );
|
| 2830 |
|
|
@@ -2838,9 +2438,9 @@ class Pods implements Iterator {
|
|
| 2838 |
/**
|
| 2839 |
* Fetch the total number of pages, based on total rows found and the last find() limit
|
| 2840 |
*
|
| 2841 |
-
* @param null|int $limit
|
| 2842 |
-
* @param null|int $offset Offset of rows
|
| 2843 |
-
* @param null|int $total
|
| 2844 |
*
|
| 2845 |
* @return int Number of pages
|
| 2846 |
* @since 2.3.10
|
|
@@ -2861,20 +2461,21 @@ class Pods implements Iterator {
|
|
| 2861 |
$total = $this->total_found();
|
| 2862 |
}
|
| 2863 |
|
| 2864 |
-
|
|
|
|
|
|
|
| 2865 |
|
| 2866 |
}
|
| 2867 |
|
| 2868 |
/**
|
| 2869 |
* Fetch the zebra switch
|
| 2870 |
*
|
| 2871 |
-
* @see
|
| 2872 |
*
|
| 2873 |
* @return bool Zebra state
|
| 2874 |
* @since 1.12
|
| 2875 |
*/
|
| 2876 |
-
public function zebra() {
|
| 2877 |
-
|
| 2878 |
$this->do_hook( 'zebra' );
|
| 2879 |
|
| 2880 |
return $this->data->zebra();
|
|
@@ -2883,15 +2484,14 @@ class Pods implements Iterator {
|
|
| 2883 |
/**
|
| 2884 |
* Fetch the nth state
|
| 2885 |
*
|
| 2886 |
-
* @see
|
| 2887 |
*
|
| 2888 |
-
* @param int|string $nth The $nth to match on the PodsData::row_number
|
| 2889 |
*
|
| 2890 |
* @return bool Whether $nth matches
|
| 2891 |
-
* @since 2.3
|
| 2892 |
*/
|
| 2893 |
-
public function nth( $nth = null ) {
|
| 2894 |
-
|
| 2895 |
$this->do_hook( 'nth', $nth );
|
| 2896 |
|
| 2897 |
return $this->data->nth( $nth );
|
|
@@ -2900,13 +2500,12 @@ class Pods implements Iterator {
|
|
| 2900 |
/**
|
| 2901 |
* Fetch the current position in the loop (starting at 1)
|
| 2902 |
*
|
| 2903 |
-
* @see
|
| 2904 |
*
|
| 2905 |
* @return int Current row number (+1)
|
| 2906 |
-
* @since 2.3
|
| 2907 |
*/
|
| 2908 |
-
public function position() {
|
| 2909 |
-
|
| 2910 |
$this->do_hook( 'position' );
|
| 2911 |
|
| 2912 |
return $this->data->position();
|
|
@@ -2918,53 +2517,48 @@ class Pods implements Iterator {
|
|
| 2918 |
*
|
| 2919 |
* You may be looking for save() in most cases where you're setting a specific field.
|
| 2920 |
*
|
| 2921 |
-
* @see
|
| 2922 |
*
|
| 2923 |
-
* @param array|string $data
|
| 2924 |
-
* @param mixed
|
| 2925 |
*
|
| 2926 |
* @return int The item ID
|
| 2927 |
*
|
| 2928 |
-
* @since 2.0
|
| 2929 |
-
* @link
|
| 2930 |
*/
|
| 2931 |
-
public function add( $data = null, $value = null ) {
|
| 2932 |
-
|
| 2933 |
-
if ( null !== $value ) {
|
| 2934 |
$data = array( $data => $value );
|
| 2935 |
-
}
|
| 2936 |
|
| 2937 |
$data = (array) $this->do_hook( 'add', $data );
|
| 2938 |
|
| 2939 |
-
if ( empty( $data ) )
|
| 2940 |
return 0;
|
| 2941 |
-
}
|
| 2942 |
|
| 2943 |
$params = array(
|
| 2944 |
-
'pod'
|
| 2945 |
-
'data'
|
| 2946 |
-
'allow_custom_fields' => true
|
| 2947 |
);
|
| 2948 |
|
| 2949 |
return $this->api->save_pod_item( $params );
|
| 2950 |
}
|
| 2951 |
|
| 2952 |
/**
|
| 2953 |
-
* Add an item to the values of a relationship field, add a value to a number field (field+1), add time to a date
|
| 2954 |
-
* field, or add text to a text field
|
| 2955 |
*
|
| 2956 |
-
* @see
|
| 2957 |
*
|
| 2958 |
-
* @param string $field Field name
|
| 2959 |
-
* @param mixed
|
| 2960 |
-
* @param int
|
| 2961 |
*
|
| 2962 |
* @return int The item ID
|
| 2963 |
*
|
| 2964 |
-
* @since 2.3
|
| 2965 |
*/
|
| 2966 |
-
public function add_to( $field, $value, $id = null ) {
|
| 2967 |
-
|
| 2968 |
$pod =& $this;
|
| 2969 |
|
| 2970 |
$fetch = false;
|
|
@@ -2972,108 +2566,99 @@ class Pods implements Iterator {
|
|
| 2972 |
if ( null === $id ) {
|
| 2973 |
$fetch = true;
|
| 2974 |
|
| 2975 |
-
$id = $
|
| 2976 |
-
// @codingStandardsIgnoreLine
|
| 2977 |
-
} elseif ( $id != $this->id() ) {
|
| 2978 |
-
$pod = pods( $this->pod, $id );
|
| 2979 |
}
|
|
|
|
|
|
|
| 2980 |
|
| 2981 |
$this->do_hook( 'add_to', $field, $value, $id );
|
| 2982 |
|
| 2983 |
-
if ( !
|
| 2984 |
return $id;
|
| 2985 |
-
}
|
| 2986 |
|
| 2987 |
-
// Tableless fields
|
| 2988 |
-
if ( in_array( $this->fields[ $field ]['type'], PodsForm::tableless_field_types()
|
| 2989 |
-
if ( !
|
| 2990 |
$value = explode( ',', $value );
|
| 2991 |
-
}
|
| 2992 |
|
| 2993 |
-
if ( 'pick'
|
| 2994 |
$current_value = $pod->raw( $field );
|
| 2995 |
|
| 2996 |
-
if ( !
|
| 2997 |
$current_value = (array) $current_value;
|
| 2998 |
-
|
| 2999 |
$current_value = array();
|
| 3000 |
-
}
|
| 3001 |
|
| 3002 |
$value = array_merge( $current_value, $value );
|
| 3003 |
-
}
|
| 3004 |
-
|
|
|
|
| 3005 |
|
| 3006 |
foreach ( $value as $k => $v ) {
|
| 3007 |
-
if ( !
|
| 3008 |
$value[ $k ] = (int) $v;
|
| 3009 |
-
}
|
| 3010 |
}
|
| 3011 |
|
| 3012 |
$value = array_merge( $related_ids, $value );
|
| 3013 |
-
}
|
| 3014 |
|
| 3015 |
-
if ( !
|
| 3016 |
$value = array_filter( array_unique( $value ) );
|
| 3017 |
-
|
| 3018 |
$value = array();
|
| 3019 |
-
}
|
| 3020 |
|
| 3021 |
-
if ( empty( $value ) )
|
| 3022 |
return $id;
|
| 3023 |
-
|
| 3024 |
-
|
| 3025 |
-
|
| 3026 |
$current_value = (float) $pod->raw( $field );
|
| 3027 |
|
| 3028 |
$value = ( $current_value + (float) $value );
|
| 3029 |
-
}
|
| 3030 |
-
|
|
|
|
| 3031 |
$current_value = $pod->raw( $field );
|
| 3032 |
|
| 3033 |
-
if ( 0 < strlen( $current_value ) )
|
| 3034 |
$value = strtotime( $value, strtotime( $current_value ) );
|
| 3035 |
-
|
| 3036 |
$value = strtotime( $value );
|
| 3037 |
-
|
| 3038 |
-
|
| 3039 |
-
|
| 3040 |
$current_value = $pod->raw( $field );
|
| 3041 |
|
| 3042 |
-
if ( 0 < strlen( $current_value ) )
|
| 3043 |
$value = $current_value . $value;
|
| 3044 |
-
|
| 3045 |
-
|
|
|
|
| 3046 |
|
| 3047 |
-
// @todo handle object fields and taxonomies.
|
| 3048 |
$params = array(
|
| 3049 |
-
'pod'
|
| 3050 |
-
'id'
|
| 3051 |
'data' => array(
|
| 3052 |
-
$field => $value
|
| 3053 |
-
)
|
| 3054 |
);
|
| 3055 |
|
| 3056 |
$id = $this->api->save_pod_item( $params );
|
| 3057 |
|
| 3058 |
-
if ( 0 < $id && $fetch )
|
| 3059 |
-
// Clear local var cache of field values.
|
| 3060 |
-
$pod->data->row = array();
|
| 3061 |
-
|
| 3062 |
$pod->fetch( $id, false );
|
| 3063 |
-
}
|
| 3064 |
|
| 3065 |
return $id;
|
| 3066 |
}
|
| 3067 |
|
| 3068 |
/**
|
| 3069 |
-
* Remove an item from the values of a relationship field, remove a value from a number field (field-1), remove
|
| 3070 |
-
* time to a date field
|
| 3071 |
*
|
| 3072 |
-
* @see
|
| 3073 |
*
|
| 3074 |
-
* @param string $field Field name
|
| 3075 |
-
* @param mixed
|
| 3076 |
-
* @param int
|
| 3077 |
*
|
| 3078 |
* @return int The item ID
|
| 3079 |
*
|
|
@@ -3089,73 +2674,76 @@ class Pods implements Iterator {
|
|
| 3089 |
$fetch = true;
|
| 3090 |
|
| 3091 |
$id = $this->id();
|
| 3092 |
-
|
| 3093 |
-
|
| 3094 |
$pod = pods( $this->pod, $id );
|
| 3095 |
}
|
| 3096 |
|
| 3097 |
$this->do_hook( 'remove_from', $field, $value, $id );
|
| 3098 |
|
| 3099 |
-
if ( !
|
| 3100 |
return $id;
|
| 3101 |
}
|
| 3102 |
|
| 3103 |
-
// Tableless fields
|
| 3104 |
-
if ( in_array( $this->fields[ $field ]['type'], PodsForm::tableless_field_types()
|
| 3105 |
if ( empty( $value ) ) {
|
| 3106 |
$value = array();
|
| 3107 |
}
|
| 3108 |
|
| 3109 |
-
if ( !
|
| 3110 |
-
if ( !
|
| 3111 |
$value = explode( ',', $value );
|
| 3112 |
}
|
| 3113 |
|
| 3114 |
-
if ( 'pick'
|
| 3115 |
$current_value = $pod->raw( $field );
|
| 3116 |
|
| 3117 |
-
if ( !
|
| 3118 |
$current_value = (array) $current_value;
|
| 3119 |
}
|
| 3120 |
|
| 3121 |
foreach ( $current_value as $k => $v ) {
|
| 3122 |
-
// @codingStandardsIgnoreLine.
|
| 3123 |
if ( in_array( $v, $value ) ) {
|
| 3124 |
unset( $current_value[ $k ] );
|
| 3125 |
}
|
| 3126 |
}
|
| 3127 |
|
| 3128 |
$value = $current_value;
|
| 3129 |
-
}
|
| 3130 |
-
|
|
|
|
| 3131 |
|
| 3132 |
foreach ( $value as $k => $v ) {
|
| 3133 |
-
if ( !
|
| 3134 |
$value[ $k ] = (int) $v;
|
| 3135 |
}
|
|
|
|
|
|
|
| 3136 |
|
| 3137 |
-
|
| 3138 |
}
|
| 3139 |
|
| 3140 |
foreach ( $related_ids as $k => $v ) {
|
| 3141 |
-
// @codingStandardsIgnoreLine.
|
| 3142 |
if ( in_array( $v, $value ) ) {
|
| 3143 |
unset( $related_ids[ $k ] );
|
| 3144 |
}
|
| 3145 |
}
|
| 3146 |
|
| 3147 |
$value = $related_ids;
|
| 3148 |
-
}
|
| 3149 |
|
| 3150 |
-
if ( !
|
| 3151 |
$value = array_filter( array_unique( $value ) );
|
| 3152 |
-
}
|
|
|
|
| 3153 |
$value = array();
|
| 3154 |
}
|
| 3155 |
-
}
|
| 3156 |
-
}
|
| 3157 |
-
|
| 3158 |
-
|
|
|
|
| 3159 |
if ( empty( $value ) ) {
|
| 3160 |
return $id;
|
| 3161 |
}
|
|
@@ -3163,9 +2751,10 @@ class Pods implements Iterator {
|
|
| 3163 |
$current_value = (float) $pod->raw( $field );
|
| 3164 |
|
| 3165 |
$value = ( $current_value - (float) $value );
|
| 3166 |
-
}
|
| 3167 |
-
|
| 3168 |
-
|
|
|
|
| 3169 |
if ( empty( $value ) ) {
|
| 3170 |
return $id;
|
| 3171 |
}
|
|
@@ -3174,28 +2763,27 @@ class Pods implements Iterator {
|
|
| 3174 |
|
| 3175 |
if ( 0 < strlen( $current_value ) ) {
|
| 3176 |
$value = strtotime( $value, strtotime( $current_value ) );
|
| 3177 |
-
}
|
|
|
|
| 3178 |
$value = strtotime( $value );
|
| 3179 |
}
|
| 3180 |
|
| 3181 |
$value = date_i18n( 'Y-m-d h:i:s', $value );
|
| 3182 |
-
}
|
|
|
|
|
|
|
| 3183 |
|
| 3184 |
-
// @todo handle object fields and taxonomies.
|
| 3185 |
$params = array(
|
| 3186 |
-
'pod'
|
| 3187 |
-
'id'
|
| 3188 |
'data' => array(
|
| 3189 |
-
$field => $value
|
| 3190 |
-
)
|
| 3191 |
);
|
| 3192 |
|
| 3193 |
$id = $this->api->save_pod_item( $params );
|
| 3194 |
|
| 3195 |
if ( 0 < $id && $fetch ) {
|
| 3196 |
-
// Clear local var cache of field values.
|
| 3197 |
-
$pod->data->row = array();
|
| 3198 |
-
|
| 3199 |
$pod->fetch( $id, false );
|
| 3200 |
}
|
| 3201 |
|
|
@@ -3209,27 +2797,24 @@ class Pods implements Iterator {
|
|
| 3209 |
* Though this function has the capacity to add new items, best practice should direct you
|
| 3210 |
* to use add() for that instead.
|
| 3211 |
*
|
| 3212 |
-
* @see
|
| 3213 |
*
|
| 3214 |
-
* @param array|string $data
|
| 3215 |
-
* @param mixed
|
| 3216 |
-
* @param int
|
| 3217 |
-
* @param array
|
| 3218 |
*
|
| 3219 |
* @return int The item ID
|
| 3220 |
*
|
| 3221 |
-
* @since 2.0
|
| 3222 |
-
* @link
|
| 3223 |
*/
|
| 3224 |
-
public function save( $data = null, $value = null, $id = null, $params = null ) {
|
| 3225 |
-
|
| 3226 |
-
if ( null !== $data && ! is_array( $data ) ) {
|
| 3227 |
$data = array( $data => $value );
|
| 3228 |
-
}
|
| 3229 |
|
| 3230 |
$fetch = false;
|
| 3231 |
|
| 3232 |
-
// @codingStandardsIgnoreLine
|
| 3233 |
if ( null === $id || ( $this->row && $id == $this->id() ) ) {
|
| 3234 |
$fetch = true;
|
| 3235 |
|
|
@@ -3240,42 +2825,36 @@ class Pods implements Iterator {
|
|
| 3240 |
|
| 3241 |
$data = (array) $this->do_hook( 'save', $data, $id );
|
| 3242 |
|
| 3243 |
-
if ( empty( $data )
|
| 3244 |
return $id;
|
| 3245 |
-
}
|
| 3246 |
|
| 3247 |
$default = array();
|
| 3248 |
|
| 3249 |
-
if ( !
|
| 3250 |
$default = $params;
|
| 3251 |
-
}
|
| 3252 |
|
| 3253 |
$params = array(
|
| 3254 |
-
'pod'
|
| 3255 |
-
'id'
|
| 3256 |
-
'data'
|
| 3257 |
'allow_custom_fields' => true,
|
| 3258 |
-
'clear_slug_cache'
|
| 3259 |
);
|
| 3260 |
|
| 3261 |
-
if ( !
|
| 3262 |
$params = array_merge( $params, $default );
|
| 3263 |
-
}
|
| 3264 |
|
| 3265 |
$id = $this->api->save_pod_item( $params );
|
| 3266 |
|
| 3267 |
-
if ( 0 < $id && $fetch )
|
| 3268 |
-
// Clear local var cache of field values.
|
| 3269 |
-
$this->data->row = array();
|
| 3270 |
-
|
| 3271 |
$this->fetch( $id, false );
|
| 3272 |
-
}
|
| 3273 |
|
| 3274 |
-
if ( !
|
| 3275 |
if ( 0 < $id && $fetch ) {
|
| 3276 |
-
$slug = $this->field( $this->pod_data['field_slug'] );
|
| 3277 |
-
}
|
| 3278 |
-
|
|
|
|
| 3279 |
}
|
| 3280 |
|
| 3281 |
if ( 0 < strlen( $slug ) ) {
|
|
@@ -3289,30 +2868,27 @@ class Pods implements Iterator {
|
|
| 3289 |
/**
|
| 3290 |
* Delete an item
|
| 3291 |
*
|
| 3292 |
-
* @see
|
| 3293 |
*
|
| 3294 |
-
* @param int $id ID of the Pod item to delete
|
| 3295 |
*
|
| 3296 |
* @return bool Whether the item was successfully deleted
|
| 3297 |
*
|
| 3298 |
-
* @since 2.0
|
| 3299 |
-
* @link
|
| 3300 |
*/
|
| 3301 |
-
public function delete( $id = null ) {
|
| 3302 |
-
|
| 3303 |
-
if ( null === $id ) {
|
| 3304 |
$id = $this->id();
|
| 3305 |
-
}
|
| 3306 |
|
| 3307 |
$id = (int) $this->do_hook( 'delete', $id );
|
| 3308 |
|
| 3309 |
-
if ( empty( $id ) )
|
| 3310 |
return false;
|
| 3311 |
-
}
|
| 3312 |
|
| 3313 |
$params = array(
|
| 3314 |
'pod' => $this->pod,
|
| 3315 |
-
'id'
|
| 3316 |
);
|
| 3317 |
|
| 3318 |
return $this->api->delete_pod_item( $params );
|
|
@@ -3321,21 +2897,20 @@ class Pods implements Iterator {
|
|
| 3321 |
/**
|
| 3322 |
* Reset Pod
|
| 3323 |
*
|
| 3324 |
-
* @see
|
| 3325 |
*
|
| 3326 |
* @return bool Whether the Pod was successfully reset
|
| 3327 |
*
|
| 3328 |
* @since 2.1.1
|
| 3329 |
*/
|
| 3330 |
-
public function reset_pod() {
|
| 3331 |
-
|
| 3332 |
$params = array( 'id' => $this->pod_id );
|
| 3333 |
|
| 3334 |
-
$this->data->id
|
| 3335 |
-
$this->data->row
|
| 3336 |
$this->data->data = array();
|
| 3337 |
|
| 3338 |
-
$this->data->total
|
| 3339 |
$this->data->total_found = 0;
|
| 3340 |
|
| 3341 |
return $this->api->reset_pod( $params );
|
|
@@ -3344,30 +2919,27 @@ class Pods implements Iterator {
|
|
| 3344 |
/**
|
| 3345 |
* Duplicate an item
|
| 3346 |
*
|
| 3347 |
-
* @see
|
| 3348 |
*
|
| 3349 |
-
* @param int $id ID of the pod item to duplicate
|
| 3350 |
*
|
| 3351 |
* @return int|bool ID of the new pod item
|
| 3352 |
*
|
| 3353 |
-
* @since 2.0
|
| 3354 |
-
* @link
|
| 3355 |
*/
|
| 3356 |
-
public function duplicate( $id = null ) {
|
| 3357 |
-
|
| 3358 |
-
if ( null === $id ) {
|
| 3359 |
$id = $this->id();
|
| 3360 |
-
}
|
| 3361 |
|
| 3362 |
$id = (int) $this->do_hook( 'duplicate', $id );
|
| 3363 |
|
| 3364 |
-
if ( empty( $id ) )
|
| 3365 |
return false;
|
| 3366 |
-
}
|
| 3367 |
|
| 3368 |
$params = array(
|
| 3369 |
'pod' => $this->pod,
|
| 3370 |
-
'id'
|
| 3371 |
);
|
| 3372 |
|
| 3373 |
return $this->api->duplicate_pod_item( $params );
|
|
@@ -3376,71 +2948,64 @@ class Pods implements Iterator {
|
|
| 3376 |
/**
|
| 3377 |
* Import data / Save multiple rows of data at once
|
| 3378 |
*
|
| 3379 |
-
* @see
|
| 3380 |
*
|
| 3381 |
-
* @param mixed
|
| 3382 |
-
* @param bool
|
| 3383 |
-
* @param string $format
|
| 3384 |
*
|
| 3385 |
* @return array IDs of imported items
|
| 3386 |
*
|
| 3387 |
-
* @since 2.3
|
| 3388 |
*/
|
| 3389 |
-
public function import( $import_data, $numeric_mode = false, $format = null ) {
|
| 3390 |
-
|
| 3391 |
return $this->api->import( $import_data, $numeric_mode, $format );
|
| 3392 |
}
|
| 3393 |
|
| 3394 |
/**
|
| 3395 |
* Export an item's data
|
| 3396 |
*
|
| 3397 |
-
* @see
|
| 3398 |
*
|
| 3399 |
-
* @param array
|
| 3400 |
-
* @param int
|
| 3401 |
-
* @param null|string $format (optional) The format of the export (php | json).
|
| 3402 |
*
|
| 3403 |
* @return array|bool Data array of the exported pod item
|
| 3404 |
*
|
| 3405 |
-
* @since 2.0
|
| 3406 |
-
* @link
|
| 3407 |
*/
|
| 3408 |
-
public function export( $fields = null, $id = null, $format = null ) {
|
| 3409 |
-
|
| 3410 |
$params = array(
|
| 3411 |
-
'pod'
|
| 3412 |
-
'id'
|
| 3413 |
-
'fields'
|
| 3414 |
-
'depth'
|
| 3415 |
-
'flatten' => false
|
| 3416 |
-
'context' => null,
|
| 3417 |
-
'format' => $format,
|
| 3418 |
);
|
| 3419 |
|
| 3420 |
-
if ( is_array( $fields ) && ( isset( $fields['fields'] ) || isset( $fields['depth'] ) ) )
|
| 3421 |
$params = array_merge( $params, $fields );
|
| 3422 |
-
|
| 3423 |
-
$params['fields'] = $fields;
|
| 3424 |
-
}
|
| 3425 |
|
| 3426 |
-
if ( isset( $params['fields'] ) && is_array( $params['fields'] ) && !
|
| 3427 |
-
$params['fields'] = array_merge( array( $this->pod_data['field_id'] ), $params['fields'] );
|
| 3428 |
-
}
|
| 3429 |
|
| 3430 |
-
if ( null === $params['id'] )
|
| 3431 |
-
$params['id'] = $this->id();
|
| 3432 |
-
}
|
| 3433 |
|
| 3434 |
$params = (array) $this->do_hook( 'export', $params );
|
| 3435 |
|
| 3436 |
-
if ( empty( $params['id'] ) )
|
| 3437 |
return false;
|
| 3438 |
-
}
|
| 3439 |
|
| 3440 |
$data = $this->api->export_pod_item( $params );
|
| 3441 |
|
| 3442 |
-
if ( !
|
| 3443 |
-
|
|
|
|
|
|
|
| 3444 |
}
|
| 3445 |
|
| 3446 |
return $data;
|
|
@@ -3449,27 +3014,25 @@ class Pods implements Iterator {
|
|
| 3449 |
/**
|
| 3450 |
* Export data from all items
|
| 3451 |
*
|
| 3452 |
-
* @see
|
| 3453 |
*
|
| 3454 |
-
* @param array $params An associative array of parameters
|
| 3455 |
*
|
| 3456 |
* @return array Data arrays of all exported pod items
|
| 3457 |
*
|
| 3458 |
-
* @since 2.3
|
| 3459 |
*/
|
| 3460 |
-
public function export_data( $params = null ) {
|
| 3461 |
-
|
| 3462 |
$defaults = array(
|
| 3463 |
'fields' => null,
|
| 3464 |
-
'depth'
|
| 3465 |
-
'params' => null
|
| 3466 |
);
|
| 3467 |
|
| 3468 |
-
if ( empty( $params ) )
|
| 3469 |
$params = $defaults;
|
| 3470 |
-
|
| 3471 |
$params = array_merge( $defaults, (array) $params );
|
| 3472 |
-
}
|
| 3473 |
|
| 3474 |
return $this->api->export( $this, $params );
|
| 3475 |
}
|
|
@@ -3479,21 +3042,22 @@ class Pods implements Iterator {
|
|
| 3479 |
* are simple, paginate and advanced. The base and format parameters
|
| 3480 |
* are used only for the paginate view.
|
| 3481 |
*
|
| 3482 |
-
* @
|
| 3483 |
*
|
| 3484 |
* @return string Pagination HTML
|
| 3485 |
-
* @since 2.0
|
| 3486 |
-
* @link
|
| 3487 |
*/
|
| 3488 |
public function pagination( $params = null ) {
|
| 3489 |
|
| 3490 |
if ( empty( $params ) ) {
|
| 3491 |
$params = array();
|
| 3492 |
-
}
|
|
|
|
| 3493 |
$params = array( 'label' => $params );
|
| 3494 |
}
|
| 3495 |
|
| 3496 |
-
$this->page_var =
|
| 3497 |
|
| 3498 |
$url = pods_query_arg( null, null, $this->page_var );
|
| 3499 |
|
|
@@ -3504,43 +3068,39 @@ class Pods implements Iterator {
|
|
| 3504 |
}
|
| 3505 |
|
| 3506 |
$defaults = array(
|
| 3507 |
-
'type'
|
| 3508 |
-
'label'
|
| 3509 |
-
'show_label'
|
| 3510 |
-
'first_text'
|
| 3511 |
-
'prev_text'
|
| 3512 |
-
'next_text'
|
| 3513 |
-
'last_text'
|
| 3514 |
-
'prev_next'
|
| 3515 |
-
'first_last'
|
| 3516 |
-
'limit'
|
| 3517 |
-
'offset'
|
| 3518 |
-
'page'
|
| 3519 |
-
'mid_size'
|
| 3520 |
-
'end_size'
|
| 3521 |
'total_found' => $this->total_found(),
|
| 3522 |
-
'page_var'
|
| 3523 |
-
'base'
|
| 3524 |
-
'format'
|
| 3525 |
-
'class'
|
| 3526 |
-
'link_class'
|
| 3527 |
);
|
| 3528 |
|
| 3529 |
-
|
| 3530 |
-
$params = get_object_vars( $params );
|
| 3531 |
-
}
|
| 3532 |
-
|
| 3533 |
-
$params = (object) array_merge( $defaults, (array) $params );
|
| 3534 |
|
| 3535 |
$params->total = $this->total_pages( $params->limit, $params->offset, $params->total_found );
|
| 3536 |
|
| 3537 |
-
if ( $params->limit < 1 || $params->total_found < 1 || 1
|
| 3538 |
return $this->do_hook( 'pagination', $this->do_hook( 'pagination_' . $params->type, '', $params ), $params );
|
| 3539 |
}
|
| 3540 |
|
| 3541 |
$pagination = $params->type;
|
| 3542 |
|
| 3543 |
-
if ( !
|
| 3544 |
$pagination = 'advanced';
|
| 3545 |
}
|
| 3546 |
|
|
@@ -3557,52 +3117,42 @@ class Pods implements Iterator {
|
|
| 3557 |
/**
|
| 3558 |
* Return a filter form for searching a Pod
|
| 3559 |
*
|
| 3560 |
-
* @
|
| 3561 |
*
|
| 3562 |
* @return string Filters HTML
|
| 3563 |
*
|
| 3564 |
-
* @since 2.0
|
| 3565 |
-
* @link
|
| 3566 |
*/
|
| 3567 |
-
public function filters( $params = null ) {
|
| 3568 |
-
|
| 3569 |
$defaults = array(
|
| 3570 |
'fields' => $params,
|
| 3571 |
-
'label'
|
| 3572 |
'action' => '',
|
| 3573 |
-
'search' => ''
|
| 3574 |
);
|
| 3575 |
|
| 3576 |
-
if ( is_array( $params ) )
|
| 3577 |
$params = array_merge( $defaults, $params );
|
| 3578 |
-
|
| 3579 |
$params = $defaults;
|
| 3580 |
-
}
|
| 3581 |
|
| 3582 |
$pod =& $this;
|
| 3583 |
|
| 3584 |
-
/**
|
| 3585 |
-
* Filter the Pods::filters() parameters.
|
| 3586 |
-
*
|
| 3587 |
-
* @param array $params Parameters to filter with.
|
| 3588 |
-
* @param Pods $pod Pods object.
|
| 3589 |
-
*/
|
| 3590 |
$params = apply_filters( 'pods_filters_params', $params, $pod );
|
| 3591 |
|
| 3592 |
-
$fields = $params['fields'];
|
| 3593 |
|
| 3594 |
-
if ( null !== $fields && !
|
| 3595 |
$fields = explode( ',', $fields );
|
| 3596 |
-
}
|
| 3597 |
|
| 3598 |
-
$object_fields = (array)
|
| 3599 |
|
| 3600 |
-
// Force array
|
| 3601 |
-
if ( empty( $fields ) )
|
| 3602 |
$fields = array();
|
| 3603 |
-
|
| 3604 |
-
// Temporary
|
| 3605 |
-
$filter_fields = $fields;
|
| 3606 |
|
| 3607 |
$fields = array();
|
| 3608 |
|
|
@@ -3610,54 +3160,46 @@ class Pods implements Iterator {
|
|
| 3610 |
$name = $k;
|
| 3611 |
|
| 3612 |
$defaults = array(
|
| 3613 |
-
'name' => $name
|
| 3614 |
);
|
| 3615 |
|
| 3616 |
-
if ( !
|
| 3617 |
$name = $field;
|
| 3618 |
|
| 3619 |
$field = array(
|
| 3620 |
-
'name' => $name
|
| 3621 |
);
|
| 3622 |
}
|
| 3623 |
|
| 3624 |
-
// @codingStandardsIgnoreLine.
|
| 3625 |
$field = array_merge( $defaults, $field );
|
| 3626 |
|
| 3627 |
-
$field['name'] = trim( $field['name'] );
|
| 3628 |
|
| 3629 |
-
if (
|
| 3630 |
-
$field['type'] = 'hidden';
|
| 3631 |
-
}
|
| 3632 |
|
| 3633 |
-
if ( isset( $object_fields[ $field['name'] ] ) )
|
| 3634 |
-
|
| 3635 |
-
|
| 3636 |
-
|
| 3637 |
-
|
| 3638 |
-
$fields[ $field['name'] ] = array_merge( $this->fields[ $field['name'] ], $field );
|
| 3639 |
-
}
|
| 3640 |
-
}//end foreach
|
| 3641 |
|
| 3642 |
-
// Cleanup
|
| 3643 |
-
|
| 3644 |
-
}//end if
|
| 3645 |
|
| 3646 |
$this->filters = array_keys( $fields );
|
| 3647 |
|
| 3648 |
-
$label = $params['label'];
|
| 3649 |
|
| 3650 |
-
if (
|
| 3651 |
$label = __( 'Search', 'pods' );
|
| 3652 |
-
}
|
| 3653 |
|
| 3654 |
-
$action = $params['action'];
|
| 3655 |
|
| 3656 |
-
$search = trim( $params['search'] );
|
| 3657 |
|
| 3658 |
-
if (
|
| 3659 |
-
$search =
|
| 3660 |
-
}
|
| 3661 |
|
| 3662 |
ob_start();
|
| 3663 |
|
|
@@ -3670,9 +3212,9 @@ class Pods implements Iterator {
|
|
| 3670 |
*
|
| 3671 |
* @since unknown
|
| 3672 |
*
|
| 3673 |
-
* @param string
|
| 3674 |
-
* @param array
|
| 3675 |
-
* @param object|Pods $this
|
| 3676 |
*/
|
| 3677 |
return apply_filters( 'pods_pods_filters', $output, $params, $this );
|
| 3678 |
}
|
|
@@ -3680,91 +3222,35 @@ class Pods implements Iterator {
|
|
| 3680 |
/**
|
| 3681 |
* Run a helper within a Pod Page or WP Template
|
| 3682 |
*
|
| 3683 |
-
* @see
|
| 3684 |
*
|
| 3685 |
-
* @param string
|
| 3686 |
-
* @param string
|
| 3687 |
-
* @param string
|
| 3688 |
*
|
| 3689 |
* @return mixed Anything returned by the helper
|
| 3690 |
-
* @since 2.0
|
| 3691 |
*/
|
| 3692 |
-
public function helper( $helper, $value = null, $name = null ) {
|
| 3693 |
-
|
| 3694 |
$params = array(
|
| 3695 |
-
'helper'
|
| 3696 |
-
'value'
|
| 3697 |
-
'name'
|
| 3698 |
-
'deprecated' => false
|
| 3699 |
);
|
| 3700 |
|
| 3701 |
-
if ( class_exists( 'Pods_Templates' ) )
|
| 3702 |
-
$params['deprecated'] = Pods_Templates::$deprecated;
|
| 3703 |
-
}
|
| 3704 |
|
| 3705 |
-
if ( is_array( $helper ) )
|
| 3706 |
$params = array_merge( $params, $helper );
|
| 3707 |
-
}
|
| 3708 |
|
| 3709 |
-
if ( class_exists( 'Pods_Helpers' ) )
|
| 3710 |
$value = Pods_Helpers::helper( $params, $this );
|
| 3711 |
-
|
| 3712 |
-
$
|
| 3713 |
-
|
| 3714 |
-
|
| 3715 |
-
'popen',
|
| 3716 |
-
'eval',
|
| 3717 |
-
'preg_replace',
|
| 3718 |
-
'create_function',
|
| 3719 |
-
'include',
|
| 3720 |
-
'include_once',
|
| 3721 |
-
'require',
|
| 3722 |
-
'require_once',
|
| 3723 |
-
);
|
| 3724 |
-
|
| 3725 |
-
$allowed = array();
|
| 3726 |
-
|
| 3727 |
-
/**
|
| 3728 |
-
* Allows adjusting the disallowed callbacks as needed.
|
| 3729 |
-
*
|
| 3730 |
-
* @param array $disallowed List of callbacks not allowed.
|
| 3731 |
-
* @param array $params Parameters used by Pods::helper() method.
|
| 3732 |
-
*
|
| 3733 |
-
* @since 2.7.0
|
| 3734 |
-
*/
|
| 3735 |
-
$disallowed = apply_filters( 'pods_helper_disallowed_callbacks', $disallowed, $params );
|
| 3736 |
-
|
| 3737 |
-
/**
|
| 3738 |
-
* Allows adjusting the allowed allowed callbacks as needed.
|
| 3739 |
-
*
|
| 3740 |
-
* @param array $allowed List of callbacks explicitly allowed.
|
| 3741 |
-
* @param array $params Parameters used by Pods::helper() method.
|
| 3742 |
-
*
|
| 3743 |
-
* @since 2.7.0
|
| 3744 |
-
*/
|
| 3745 |
-
$allowed = apply_filters( 'pods_helper_allowed_callbacks', $allowed, $params );
|
| 3746 |
-
|
| 3747 |
-
// Clean up helper callback (if string).
|
| 3748 |
-
if ( is_string( $params['helper'] ) ) {
|
| 3749 |
-
$params['helper'] = strip_tags( str_replace( array( '`', chr( 96 ) ), "'", $params['helper'] ) );
|
| 3750 |
-
}
|
| 3751 |
-
|
| 3752 |
-
$is_allowed = false;
|
| 3753 |
-
|
| 3754 |
-
if ( ! empty( $allowed ) ) {
|
| 3755 |
-
if ( in_array( $params['helper'], $allowed, true ) ) {
|
| 3756 |
-
$is_allowed = true;
|
| 3757 |
-
}
|
| 3758 |
-
} elseif ( ! in_array( $params['helper'], $disallowed, true ) ) {
|
| 3759 |
-
$is_allowed = true;
|
| 3760 |
-
}
|
| 3761 |
-
|
| 3762 |
-
if ( $is_allowed ) {
|
| 3763 |
-
$value = call_user_func( $params['helper'], $value );
|
| 3764 |
-
}
|
| 3765 |
-
} else {
|
| 3766 |
-
$value = apply_filters( $params['helper'], $value );
|
| 3767 |
-
}//end if
|
| 3768 |
|
| 3769 |
return $value;
|
| 3770 |
}
|
|
@@ -3772,130 +3258,73 @@ class Pods implements Iterator {
|
|
| 3772 |
/**
|
| 3773 |
* Display the page template
|
| 3774 |
*
|
| 3775 |
-
* @see
|
| 3776 |
*
|
| 3777 |
-
* @param string
|
| 3778 |
-
* @param string
|
| 3779 |
-
* @param bool
|
| 3780 |
*
|
| 3781 |
* @return mixed Template output
|
| 3782 |
*
|
| 3783 |
-
* @since 2.0
|
| 3784 |
-
* @link
|
| 3785 |
*/
|
| 3786 |
-
public function template( $template_name, $code = null, $deprecated = false ) {
|
| 3787 |
-
|
| 3788 |
$out = null;
|
| 3789 |
|
| 3790 |
$obj =& $this;
|
| 3791 |
|
| 3792 |
-
if ( !
|
| 3793 |
-
// backwards compatibility
|
| 3794 |
-
$code = str_replace( '$this->', '$obj->', $code );
|
| 3795 |
|
| 3796 |
-
/**
|
| 3797 |
-
* Filter the template code before running it.
|
| 3798 |
-
*
|
| 3799 |
-
* @param string $code Template code.
|
| 3800 |
-
* @param string $template_name Template name.
|
| 3801 |
-
* @param Pods $pod Pods object.
|
| 3802 |
-
*/
|
| 3803 |
$code = apply_filters( 'pods_templates_pre_template', $code, $template_name, $this );
|
| 3804 |
-
|
| 3805 |
-
/**
|
| 3806 |
-
* Filter the template code before running it.
|
| 3807 |
-
*
|
| 3808 |
-
* @param string $code Template code.
|
| 3809 |
-
* @param string $template_name Template name.
|
| 3810 |
-
* @param Pods $pod Pods object.
|
| 3811 |
-
*/
|
| 3812 |
$code = apply_filters( "pods_templates_pre_template_{$template_name}", $code, $template_name, $this );
|
| 3813 |
|
| 3814 |
ob_start();
|
| 3815 |
|
| 3816 |
-
if ( !
|
| 3817 |
-
// Only detail templates need $this->id
|
| 3818 |
if ( empty( $this->id ) ) {
|
| 3819 |
while ( $this->fetch() ) {
|
| 3820 |
-
// @codingStandardsIgnoreLine
|
| 3821 |
echo $this->do_magic_tags( $code );
|
| 3822 |
}
|
| 3823 |
-
} else {
|
| 3824 |
-
// @codingStandardsIgnoreLine
|
| 3825 |
-
echo $this->do_magic_tags( $code );
|
| 3826 |
}
|
|
|
|
|
|
|
| 3827 |
}
|
| 3828 |
|
| 3829 |
$out = ob_get_clean();
|
| 3830 |
|
| 3831 |
-
/**
|
| 3832 |
-
* Filter the template output.
|
| 3833 |
-
*
|
| 3834 |
-
* @param string $out Template output.
|
| 3835 |
-
* @param string $code Template code.
|
| 3836 |
-
* @param string $template_name Template name.
|
| 3837 |
-
* @param Pods $pod Pods object.
|
| 3838 |
-
*/
|
| 3839 |
$out = apply_filters( 'pods_templates_post_template', $out, $code, $template_name, $this );
|
| 3840 |
-
|
| 3841 |
-
/**
|
| 3842 |
-
* Filter the template output.
|
| 3843 |
-
*
|
| 3844 |
-
* @param string $out Template output.
|
| 3845 |
-
* @param string $code Template code.
|
| 3846 |
-
* @param string $template_name Template name.
|
| 3847 |
-
* @param Pods $pod Pods object.
|
| 3848 |
-
*/
|
| 3849 |
$out = apply_filters( "pods_templates_post_template_{$template_name}", $out, $code, $template_name, $this );
|
| 3850 |
-
}
|
|
|
|
| 3851 |
$out = Pods_Templates::template( $template_name, $code, $this, $deprecated );
|
| 3852 |
-
|
| 3853 |
ob_start();
|
| 3854 |
|
| 3855 |
$default_templates = array(
|
| 3856 |
'pods/' . $template_name,
|
| 3857 |
'pods-' . $template_name,
|
| 3858 |
-
$template_name
|
| 3859 |
);
|
| 3860 |
|
| 3861 |
-
/**
|
| 3862 |
-
* Filter the default Pods Template files.
|
| 3863 |
-
*
|
| 3864 |
-
* @param array $default_templates Default Pods Template files.
|
| 3865 |
-
*/
|
| 3866 |
$default_templates = apply_filters( 'pods_template_default_templates', $default_templates );
|
| 3867 |
|
| 3868 |
-
// Only detail templates need $this->id
|
| 3869 |
if ( empty( $this->id ) ) {
|
| 3870 |
while ( $this->fetch() ) {
|
| 3871 |
pods_template_part( $default_templates, compact( array_keys( get_defined_vars() ) ) );
|
| 3872 |
}
|
| 3873 |
-
} else {
|
| 3874 |
-
pods_template_part( $default_templates, compact( array_keys( get_defined_vars() ) ) );
|
| 3875 |
}
|
|
|
|
|
|
|
| 3876 |
|
| 3877 |
$out = ob_get_clean();
|
| 3878 |
|
| 3879 |
-
/**
|
| 3880 |
-
* Filter the template output.
|
| 3881 |
-
*
|
| 3882 |
-
* @param string $out Template output.
|
| 3883 |
-
* @param string $code Template code.
|
| 3884 |
-
* @param string $template_name Template name.
|
| 3885 |
-
* @param Pods $pod Pods object.
|
| 3886 |
-
*/
|
| 3887 |
$out = apply_filters( 'pods_templates_post_template', $out, $code, $template_name, $this );
|
| 3888 |
-
|
| 3889 |
-
/**
|
| 3890 |
-
* Filter the template output.
|
| 3891 |
-
*
|
| 3892 |
-
* @param string $out Template output.
|
| 3893 |
-
* @param string $code Template code.
|
| 3894 |
-
* @param string $template_name Template name.
|
| 3895 |
-
* @param Pods $pod Pods object.
|
| 3896 |
-
*/
|
| 3897 |
$out = apply_filters( "pods_templates_post_template_{$template_name}", $out, $code, $template_name, $this );
|
| 3898 |
-
}
|
| 3899 |
|
| 3900 |
return $out;
|
| 3901 |
}
|
|
@@ -3905,48 +3334,44 @@ class Pods implements Iterator {
|
|
| 3905 |
* and override options where needed. For WP object based Pods, you can pass through the WP object
|
| 3906 |
* field names too, such as "post_title" or "post_content" for example.
|
| 3907 |
*
|
| 3908 |
-
* @param array
|
| 3909 |
-
* @param string $label
|
| 3910 |
-
* @param string $thank_you (optional) Thank you URL to send to upon success
|
| 3911 |
*
|
| 3912 |
* @return bool|mixed
|
| 3913 |
-
* @since 2.0
|
| 3914 |
-
* @link
|
| 3915 |
*/
|
| 3916 |
-
public function form( $params = null, $label = null, $thank_you = null ) {
|
| 3917 |
-
|
| 3918 |
$defaults = array(
|
| 3919 |
-
'fields'
|
| 3920 |
-
'label'
|
| 3921 |
-
'thank_you'
|
| 3922 |
-
'fields_only' => false
|
| 3923 |
);
|
| 3924 |
|
| 3925 |
-
if ( is_array( $params ) )
|
| 3926 |
$params = array_merge( $defaults, $params );
|
| 3927 |
-
|
| 3928 |
$params = $defaults;
|
| 3929 |
-
}
|
| 3930 |
|
| 3931 |
$pod =& $this;
|
| 3932 |
|
| 3933 |
$params = $this->do_hook( 'form_params', $params );
|
| 3934 |
|
| 3935 |
-
$fields = $params['fields'];
|
| 3936 |
|
| 3937 |
-
if ( null !== $fields && !
|
| 3938 |
$fields = explode( ',', $fields );
|
| 3939 |
-
}
|
| 3940 |
|
| 3941 |
-
$object_fields = (array)
|
| 3942 |
|
| 3943 |
if ( empty( $fields ) ) {
|
| 3944 |
-
// Add core object fields if $fields is empty
|
| 3945 |
$fields = array_merge( $object_fields, $this->fields );
|
| 3946 |
}
|
| 3947 |
|
| 3948 |
-
// Temporary
|
| 3949 |
-
$form_fields = $fields;
|
| 3950 |
|
| 3951 |
$fields = array();
|
| 3952 |
|
|
@@ -3954,111 +3379,100 @@ class Pods implements Iterator {
|
|
| 3954 |
$name = $k;
|
| 3955 |
|
| 3956 |
$defaults = array(
|
| 3957 |
-
'name' => $name
|
| 3958 |
);
|
| 3959 |
|
| 3960 |
-
if ( !
|
| 3961 |
$name = $field;
|
| 3962 |
|
| 3963 |
$field = array(
|
| 3964 |
-
'name' => $name
|
| 3965 |
);
|
| 3966 |
}
|
| 3967 |
|
| 3968 |
-
// @codingStandardsIgnoreLine.
|
| 3969 |
$field = array_merge( $defaults, $field );
|
| 3970 |
|
| 3971 |
-
$field['name'] = trim( $field['name'] );
|
| 3972 |
|
| 3973 |
-
$default_value =
|
| 3974 |
-
$value
|
| 3975 |
|
| 3976 |
-
if ( empty( $field['name'] ) )
|
| 3977 |
-
$field['name'] = trim( $name );
|
| 3978 |
-
}
|
| 3979 |
|
| 3980 |
-
if ( isset( $object_fields[ $field['name'] ] ) ) {
|
| 3981 |
-
|
| 3982 |
-
$field = array_merge( $object_fields[ $field['name'] ], $field );
|
| 3983 |
-
} elseif ( isset( $this->fields[ $field['name'] ] ) ) {
|
| 3984 |
-
// @codingStandardsIgnoreLine.
|
| 3985 |
-
$field = array_merge( $this->fields[ $field['name'] ], $field );
|
| 3986 |
}
|
| 3987 |
-
|
| 3988 |
-
|
| 3989 |
-
$field['type'] = 'hidden';
|
| 3990 |
}
|
| 3991 |
|
| 3992 |
-
|
|
|
|
|
|
|
|
|
|
| 3993 |
|
| 3994 |
if ( empty( $this->id ) && null !== $default_value ) {
|
| 3995 |
-
$this->row_override[ $field['name'] ] = $default_value;
|
| 3996 |
-
}
|
| 3997 |
-
|
|
|
|
| 3998 |
}
|
| 3999 |
-
}
|
| 4000 |
|
| 4001 |
-
// Cleanup
|
| 4002 |
-
unset( $form_fields );
|
| 4003 |
|
| 4004 |
$fields = $this->do_hook( 'form_fields', $fields, $params );
|
| 4005 |
|
| 4006 |
-
$label = $params['label'];
|
| 4007 |
|
| 4008 |
-
if ( empty( $label ) )
|
| 4009 |
$label = __( 'Save Changes', 'pods' );
|
| 4010 |
-
}
|
| 4011 |
|
| 4012 |
-
$thank_you
|
| 4013 |
-
$fields_only = $params['fields_only'];
|
| 4014 |
|
| 4015 |
-
PodsForm::$form_counter
|
| 4016 |
|
| 4017 |
ob_start();
|
| 4018 |
|
| 4019 |
if ( empty( $thank_you ) ) {
|
| 4020 |
$success = 'success';
|
| 4021 |
|
| 4022 |
-
if ( 1 < PodsForm::$form_counter )
|
| 4023 |
$success .= PodsForm::$form_counter;
|
| 4024 |
-
}
|
| 4025 |
|
| 4026 |
-
$thank_you = pods_query_arg( array(
|
| 4027 |
-
'success*' => null,
|
| 4028 |
-
$success => 1,
|
| 4029 |
-
) );
|
| 4030 |
|
| 4031 |
-
if ( 1
|
| 4032 |
$message = __( 'Form submitted successfully', 'pods' );
|
| 4033 |
-
|
| 4034 |
/**
|
| 4035 |
-
* Change the text of the message that appears on
|
| 4036 |
*
|
| 4037 |
-
* @param string $message
|
| 4038 |
*
|
| 4039 |
-
* @
|
|
|
|
|
|
|
| 4040 |
*/
|
| 4041 |
$message = apply_filters( 'pods_pod_form_success_message', $message );
|
| 4042 |
|
| 4043 |
-
echo '<div id="message" class="pods-form-front-success">' .
|
| 4044 |
}
|
| 4045 |
-
}
|
| 4046 |
|
| 4047 |
pods_view( PODS_DIR . 'ui/front/form.php', compact( array_keys( get_defined_vars() ) ) );
|
| 4048 |
|
| 4049 |
$output = ob_get_clean();
|
| 4050 |
|
| 4051 |
-
if ( empty( $this->id ) )
|
| 4052 |
$this->row_override = array();
|
| 4053 |
-
}
|
| 4054 |
|
| 4055 |
return $this->do_hook( 'form', $output, $fields, $label, $thank_you, $this, $this->id() );
|
| 4056 |
}
|
| 4057 |
|
| 4058 |
/**
|
| 4059 |
-
*
|
| 4060 |
-
*
|
| 4061 |
-
* @param array|string|null $fields (optional) Fields to show in the view, defaults to all fields.
|
| 4062 |
*
|
| 4063 |
* @return mixed
|
| 4064 |
* @since 2.3.10
|
|
@@ -4067,64 +3481,60 @@ class Pods implements Iterator {
|
|
| 4067 |
|
| 4068 |
$pod =& $this;
|
| 4069 |
|
| 4070 |
-
// Convert comma separated list of fields to an array
|
| 4071 |
-
if ( null !== $fields && !
|
| 4072 |
$fields = explode( ',', $fields );
|
| 4073 |
}
|
| 4074 |
|
| 4075 |
$object_fields = (array) pods_v( 'object_fields', $this->pod_data, array(), true );
|
| 4076 |
|
| 4077 |
if ( empty( $fields ) ) {
|
| 4078 |
-
// Add core object fields if $fields is empty
|
| 4079 |
$fields = array_merge( $object_fields, $this->fields );
|
| 4080 |
}
|
| 4081 |
|
| 4082 |
-
// Temporary
|
| 4083 |
-
$view_fields = $fields;
|
| 4084 |
|
| 4085 |
$fields = array();
|
| 4086 |
|
| 4087 |
foreach ( $view_fields as $name => $field ) {
|
|
|
|
| 4088 |
$defaults = array(
|
| 4089 |
-
'name' => $name
|
| 4090 |
);
|
| 4091 |
|
| 4092 |
-
if ( !
|
| 4093 |
$name = $field;
|
| 4094 |
|
| 4095 |
$field = array(
|
| 4096 |
-
'name' => $name
|
| 4097 |
);
|
| 4098 |
}
|
| 4099 |
|
| 4100 |
-
// @codingStandardsIgnoreLine.
|
| 4101 |
$field = array_merge( $defaults, $field );
|
| 4102 |
|
| 4103 |
-
$field['name'] = trim( $field['name'] );
|
| 4104 |
|
| 4105 |
-
if ( empty( $field['name'] ) ) {
|
| 4106 |
-
$field['name'] = trim( $name );
|
| 4107 |
}
|
| 4108 |
|
| 4109 |
-
if ( isset( $object_fields[ $field['name'] ] ) )
|
| 4110 |
-
|
| 4111 |
-
|
| 4112 |
-
|
| 4113 |
-
// @codingStandardsIgnoreLine.
|
| 4114 |
-
$field = array_merge( $this->fields[ $field['name'] ], $field );
|
| 4115 |
-
}
|
| 4116 |
|
| 4117 |
-
if ( pods_v( 'hidden', $field, false, true ) || 'hidden'
|
| 4118 |
continue;
|
| 4119 |
-
}
|
|
|
|
| 4120 |
continue;
|
| 4121 |
}
|
| 4122 |
|
| 4123 |
-
$fields[ $field['name'] ] = $field;
|
| 4124 |
-
}
|
| 4125 |
|
| 4126 |
-
// Cleanup
|
| 4127 |
-
unset( $view_fields );
|
| 4128 |
|
| 4129 |
$output = pods_view( PODS_DIR . 'ui/front/view.php', compact( array_keys( get_defined_vars() ) ), false, 'cache', true );
|
| 4130 |
|
|
@@ -4135,115 +3545,73 @@ class Pods implements Iterator {
|
|
| 4135 |
/**
|
| 4136 |
* Replace magic tags with their values
|
| 4137 |
*
|
| 4138 |
-
* @param string $code The content to evaluate
|
|
|
|
| 4139 |
*
|
| 4140 |
* @return string Code with Magic Tags evaluated
|
| 4141 |
*
|
| 4142 |
-
* @since 2.0
|
| 4143 |
*/
|
| 4144 |
-
public function do_magic_tags( $code ) {
|
| 4145 |
-
|
| 4146 |
-
/**
|
| 4147 |
-
* Filters the Pods magic tags content before the default function.
|
| 4148 |
-
* Allows complete replacement of the Pods magic tag engine.
|
| 4149 |
-
*
|
| 4150 |
-
* @param null $pre Default is null which processes magic tags normally. Return any other value to override.
|
| 4151 |
-
* @param string $code The content to evaluate.
|
| 4152 |
-
* @param Pods $pods The Pods Object.
|
| 4153 |
-
*
|
| 4154 |
-
* @since 2.7.0
|
| 4155 |
-
*/
|
| 4156 |
-
$pre = apply_filters( 'pods_pre_do_magic_tags', null, $code, $this );
|
| 4157 |
-
if ( null !== $pre ) {
|
| 4158 |
-
return $pre;
|
| 4159 |
-
}
|
| 4160 |
-
|
| 4161 |
return preg_replace_callback( '/({@(.*?)})/m', array( $this, 'process_magic_tags' ), $code );
|
| 4162 |
}
|
| 4163 |
|
| 4164 |
/**
|
| 4165 |
* Replace magic tags with their values
|
| 4166 |
*
|
| 4167 |
-
* @param string
|
|
|
|
| 4168 |
*
|
| 4169 |
* @return string Code with Magic Tags evaluated
|
| 4170 |
*
|
| 4171 |
* @since 2.0.2
|
| 4172 |
*/
|
| 4173 |
-
private function process_magic_tags( $tag ) {
|
| 4174 |
|
| 4175 |
if ( is_array( $tag ) ) {
|
| 4176 |
-
if ( !
|
| 4177 |
return '';
|
| 4178 |
-
}
|
| 4179 |
|
| 4180 |
-
$tag = $tag[2];
|
| 4181 |
}
|
| 4182 |
|
| 4183 |
$tag = trim( $tag, ' {@}' );
|
| 4184 |
$tag = explode( ',', $tag );
|
| 4185 |
|
| 4186 |
-
if ( empty( $tag ) || !
|
| 4187 |
return '';
|
| 4188 |
-
}
|
| 4189 |
|
| 4190 |
-
$tag
|
|
|
|
|
|
|
| 4191 |
|
| 4192 |
-
$field_name = $tag[0];
|
| 4193 |
|
| 4194 |
-
$helper_name = '';
|
| 4195 |
-
$before = '';
|
| 4196 |
-
$after = '';
|
| 4197 |
|
| 4198 |
-
if ( !
|
| 4199 |
$value = $this->field( $field_name );
|
| 4200 |
|
| 4201 |
-
$helper_name = $tag[1];
|
| 4202 |
|
| 4203 |
$value = $this->helper( $helper_name, $value, $field_name );
|
| 4204 |
-
} else {
|
| 4205 |
-
$value = $this->display( $field_name );
|
| 4206 |
-
}
|
| 4207 |
-
|
| 4208 |
-
// Process special magic tags but allow "empty" values for numbers.
|
| 4209 |
-
if (
|
| 4210 |
-
! $value
|
| 4211 |
-
&& ! is_numeric( $value )
|
| 4212 |
-
&& pods_shortcode_allow_evaluate_tags()
|
| 4213 |
-
&& ! $this->fields( $field_name )
|
| 4214 |
-
) {
|
| 4215 |
-
// Do not pass before and after tags (key 2 and 3) or these get processed twice.
|
| 4216 |
-
$value = pods_evaluate_tag( implode( ',', array_slice( $tag, 0, 2 ) ) );
|
| 4217 |
}
|
|
|
|
|
|
|
| 4218 |
|
| 4219 |
-
if ( !
|
| 4220 |
-
$before = $tag[2];
|
| 4221 |
-
}
|
| 4222 |
|
| 4223 |
-
if ( !
|
| 4224 |
-
$after = $tag[3];
|
| 4225 |
-
}
|
| 4226 |
|
| 4227 |
-
/**
|
| 4228 |
-
* Filter the magic tag output for a value.
|
| 4229 |
-
*
|
| 4230 |
-
* @param string $value Magic tag output for value.
|
| 4231 |
-
* @param string $field_name Magic tag field name.
|
| 4232 |
-
* @param string $before Before content.
|
| 4233 |
-
* @param string $after After content.
|
| 4234 |
-
*/
|
| 4235 |
$value = apply_filters( 'pods_do_magic_tags', $value, $field_name, $helper_name, $before, $after );
|
| 4236 |
|
| 4237 |
-
if ( is_array( $value ) )
|
| 4238 |
-
$value = pods_serial_comma( $value, array(
|
| 4239 |
-
'field' => $field_name,
|
| 4240 |
-
'fields' => $this->fields,
|
| 4241 |
-
) );
|
| 4242 |
-
}
|
| 4243 |
|
| 4244 |
-
if ( null !== $value && false !== $value )
|
| 4245 |
return $before . $value . $after;
|
| 4246 |
-
}
|
| 4247 |
|
| 4248 |
return '';
|
| 4249 |
}
|
|
@@ -4252,46 +3620,41 @@ class Pods implements Iterator {
|
|
| 4252 |
*
|
| 4253 |
* Generate UI for Data Management
|
| 4254 |
*
|
| 4255 |
-
* @param mixed $options Array or String containing Pod or Options to be used
|
| 4256 |
-
* @param bool
|
| 4257 |
*
|
| 4258 |
-
* @return PodsUI|
|
| 4259 |
*
|
| 4260 |
* @since 2.3.10
|
| 4261 |
*/
|
| 4262 |
-
public function ui( $options = null, $amend = false ) {
|
| 4263 |
-
|
| 4264 |
$num = '';
|
| 4265 |
|
| 4266 |
-
if ( empty( $options ) )
|
| 4267 |
$options = array();
|
| 4268 |
-
|
| 4269 |
-
$num =
|
| 4270 |
|
| 4271 |
if ( empty( $num ) ) {
|
| 4272 |
$num = '';
|
| 4273 |
}
|
| 4274 |
}
|
| 4275 |
|
| 4276 |
-
$
|
| 4277 |
-
|
| 4278 |
-
// @codingStandardsIgnoreLine
|
| 4279 |
-
if ( $this->id() != $check_id ) {
|
| 4280 |
-
$this->fetch( $check_id );
|
| 4281 |
-
}
|
| 4282 |
|
| 4283 |
-
if ( !
|
| 4284 |
$this->ui = $options;
|
| 4285 |
|
| 4286 |
return pods_ui( $this );
|
| 4287 |
-
}
|
| 4288 |
-
|
|
|
|
| 4289 |
|
| 4290 |
-
if ( !
|
| 4291 |
$actions_enabled = (array) $actions_enabled;
|
| 4292 |
-
|
| 4293 |
$actions_enabled = array();
|
| 4294 |
-
}
|
| 4295 |
|
| 4296 |
$available_actions = array(
|
| 4297 |
'add',
|
|
@@ -4299,197 +3662,176 @@ class Pods implements Iterator {
|
|
| 4299 |
'duplicate',
|
| 4300 |
'delete',
|
| 4301 |
'reorder',
|
| 4302 |
-
'export'
|
| 4303 |
);
|
| 4304 |
|
| 4305 |
-
if ( !
|
| 4306 |
$actions_disabled = array(
|
| 4307 |
-
'view' => 'view'
|
| 4308 |
);
|
| 4309 |
|
| 4310 |
foreach ( $available_actions as $action ) {
|
| 4311 |
-
if ( !
|
| 4312 |
$actions_disabled[ $action ] = $action;
|
| 4313 |
-
}
|
| 4314 |
}
|
| 4315 |
-
}
|
|
|
|
| 4316 |
$actions_disabled = array(
|
| 4317 |
'duplicate' => 'duplicate',
|
| 4318 |
-
'view'
|
| 4319 |
-
'export'
|
| 4320 |
);
|
| 4321 |
|
| 4322 |
-
if ( 1
|
| 4323 |
-
unset( $actions_disabled['export'] );
|
| 4324 |
-
|
| 4325 |
-
}//end if
|
| 4326 |
|
| 4327 |
if ( empty( $options ) ) {
|
| 4328 |
$author_restrict = false;
|
| 4329 |
|
| 4330 |
-
if ( isset( $this->fields['author'] ) && 'pick'
|
| 4331 |
$author_restrict = 'author.ID';
|
| 4332 |
-
}
|
| 4333 |
|
| 4334 |
-
if ( !
|
| 4335 |
-
if ( !
|
| 4336 |
-
$actions_disabled['add'] = 'add';
|
| 4337 |
|
| 4338 |
-
if ( 'add'
|
| 4339 |
$_GET[ 'action' . $num ] = 'manage';
|
| 4340 |
-
}
|
| 4341 |
}
|
| 4342 |
|
| 4343 |
-
if (
|
| 4344 |
-
$actions_disabled['edit'] = 'edit';
|
| 4345 |
-
}
|
| 4346 |
|
| 4347 |
-
if (
|
| 4348 |
-
$actions_disabled['delete'] = 'delete';
|
| 4349 |
-
}
|
| 4350 |
|
| 4351 |
-
if ( !
|
| 4352 |
-
$actions_disabled['reorder'] = 'reorder';
|
| 4353 |
-
}
|
| 4354 |
|
| 4355 |
-
if ( !
|
| 4356 |
-
$actions_disabled['export'] = 'export';
|
| 4357 |
-
|
| 4358 |
-
|
| 4359 |
-
}//end if
|
| 4360 |
|
| 4361 |
-
$_GET[ 'action' . $num ] =
|
| 4362 |
|
| 4363 |
-
$index = $this->pod_data['field_id'];
|
| 4364 |
$label = __( 'ID', 'pods' );
|
| 4365 |
|
| 4366 |
-
if ( isset( $this->pod_data['fields'][ $this->pod_data['field_index'] ] ) ) {
|
| 4367 |
-
$index = $this->pod_data['field_index'];
|
| 4368 |
-
$label = $this->pod_data['fields'][ $this->pod_data['field_index'] ];
|
| 4369 |
}
|
| 4370 |
|
| 4371 |
$manage = array(
|
| 4372 |
-
$index => $label
|
| 4373 |
);
|
| 4374 |
|
| 4375 |
-
if ( isset( $this->pod_data['fields']['modified'] ) )
|
| 4376 |
-
$manage['modified'] = $this->pod_data['fields']['modified']['label'];
|
| 4377 |
-
}
|
| 4378 |
|
| 4379 |
-
$manage_fields = (
|
| 4380 |
|
| 4381 |
-
if ( !
|
| 4382 |
$manage_new = array();
|
| 4383 |
|
| 4384 |
foreach ( $manage_fields as $manage_field ) {
|
| 4385 |
-
if ( isset( $this->pod_data['fields'][ $manage_field ] ) )
|
| 4386 |
-
$manage_new[ $manage_field ] = $this->pod_data['fields'][ $manage_field ];
|
| 4387 |
-
|
| 4388 |
-
$manage_new[ $manage_field ] = $this->pod_data['object_fields'][ $manage_field ];
|
| 4389 |
-
|
| 4390 |
$field = array(
|
| 4391 |
-
'name'
|
| 4392 |
'label' => 'ID',
|
| 4393 |
-
'type'
|
| 4394 |
-
'width' => '8%'
|
| 4395 |
);
|
| 4396 |
|
| 4397 |
-
$manage_new[ $manage_field ] = PodsForm::field_setup( $field, null, $field['type'] );
|
| 4398 |
}
|
| 4399 |
}
|
| 4400 |
|
| 4401 |
-
if ( !
|
| 4402 |
$manage = $manage_new;
|
| 4403 |
-
|
| 4404 |
-
}//end if
|
| 4405 |
|
| 4406 |
-
$
|
| 4407 |
-
$manage = apply_filters( "pods_admin_ui_fields_{$pod_name}", apply_filters( 'pods_admin_ui_fields', $manage, $this->pod, $this ), $this->pod, $this );
|
| 4408 |
|
| 4409 |
-
$icon =
|
| 4410 |
|
| 4411 |
-
if ( !
|
| 4412 |
$icon = pods_image_url( $icon, '32x32' );
|
| 4413 |
-
}
|
| 4414 |
|
| 4415 |
-
$filters =
|
| 4416 |
|
| 4417 |
-
if ( !
|
| 4418 |
$filters_new = array();
|
| 4419 |
|
| 4420 |
-
$filters = (array) $filters;
|
| 4421 |
-
|
| 4422 |
foreach ( $filters as $filter_field ) {
|
| 4423 |
-
if ( isset( $this->pod_data['fields'][ $filter_field ] ) )
|
| 4424 |
-
$filters_new[ $filter_field ] = $this->pod_data['fields'][ $filter_field ];
|
| 4425 |
-
|
| 4426 |
-
$filters_new[ $filter_field ] = $this->pod_data['object_fields'][ $filter_field ];
|
| 4427 |
-
}
|
| 4428 |
}
|
| 4429 |
|
| 4430 |
$filters = $filters_new;
|
| 4431 |
}
|
| 4432 |
|
| 4433 |
$ui = array(
|
| 4434 |
-
'fields'
|
| 4435 |
-
'manage'
|
| 4436 |
-
'add'
|
| 4437 |
-
'edit'
|
| 4438 |
-
'duplicate' => $this->pod_data['fields']
|
| 4439 |
),
|
| 4440 |
-
'icon'
|
| 4441 |
-
'actions_disabled' => $actions_disabled
|
| 4442 |
-
'actions_bulk' => array(),
|
| 4443 |
);
|
| 4444 |
|
| 4445 |
-
if ( !
|
| 4446 |
-
$ui['fields']['search'] = $filters;
|
| 4447 |
-
$ui['filters']
|
| 4448 |
-
$ui['filters_enhanced'] = true;
|
| 4449 |
}
|
| 4450 |
|
| 4451 |
-
$reorder_field =
|
| 4452 |
-
|
| 4453 |
-
if ( ! empty( $reorder_field ) && in_array( 'reorder', $actions_enabled, true ) && ! in_array( 'reorder', $actions_disabled, true ) && ( ( ! empty( $this->pod_data['object_fields'] ) && isset( $this->pod_data['object_fields'][ $reorder_field ] ) ) || isset( $this->pod_data['fields'][ $reorder_field ] ) ) ) {
|
| 4454 |
-
$ui['reorder'] = array( 'on' => $reorder_field );
|
| 4455 |
-
$ui['orderby'] = $reorder_field;
|
| 4456 |
-
$ui['orderby_dir'] = 'ASC';
|
| 4457 |
-
}
|
| 4458 |
|
| 4459 |
-
if ( ! empty( $
|
| 4460 |
-
$ui['
|
|
|
|
|
|
|
| 4461 |
}
|
| 4462 |
|
| 4463 |
-
if ( !
|
| 4464 |
-
$ui['
|
| 4465 |
-
'label' => __( 'Export', 'pods' ),
|
| 4466 |
-
// callback not needed, Pods has this built-in for export.
|
| 4467 |
-
);
|
| 4468 |
-
}
|
| 4469 |
|
| 4470 |
-
if ( !
|
| 4471 |
-
$ui['actions_bulk']
|
| 4472 |
-
'
|
| 4473 |
-
|
|
|
|
|
|
|
| 4474 |
);
|
| 4475 |
}
|
| 4476 |
|
| 4477 |
-
$detail_url =
|
| 4478 |
|
| 4479 |
if ( 0 < strlen( $detail_url ) ) {
|
| 4480 |
-
$ui['actions_custom'] = array(
|
| 4481 |
'view_url' => array(
|
| 4482 |
'label' => 'View',
|
| 4483 |
-
'link'
|
| 4484 |
-
)
|
| 4485 |
);
|
| 4486 |
}
|
| 4487 |
|
| 4488 |
-
// @todo Customize the Add New / Manage links to point to their correct menu items
|
| 4489 |
-
|
| 4490 |
-
$ui
|
| 4491 |
|
| 4492 |
-
// Override UI options
|
| 4493 |
foreach ( $options as $option => $value ) {
|
| 4494 |
$ui[ $option ] = $value;
|
| 4495 |
}
|
|
@@ -4497,36 +3839,28 @@ class Pods implements Iterator {
|
|
| 4497 |
$this->ui = $ui;
|
| 4498 |
|
| 4499 |
return pods_ui( $this );
|
| 4500 |
-
}
|
| 4501 |
|
| 4502 |
-
$pod_name = $this->pod;
|
| 4503 |
do_action( 'pods_admin_ui_custom', $this );
|
| 4504 |
-
do_action(
|
| 4505 |
-
|
| 4506 |
-
return null;
|
| 4507 |
}
|
| 4508 |
|
| 4509 |
/**
|
| 4510 |
* Handle filters / actions for the class
|
| 4511 |
*
|
| 4512 |
-
* @see
|
| 4513 |
-
*
|
| 4514 |
-
* @param string $name Hook name.
|
| 4515 |
*
|
| 4516 |
* @return mixed Value filtered
|
| 4517 |
*
|
| 4518 |
-
* @since 2.0
|
| 4519 |
*/
|
| 4520 |
-
private function do_hook(
|
| 4521 |
-
|
| 4522 |
$args = func_get_args();
|
| 4523 |
|
| 4524 |
-
if ( empty( $args ) )
|
| 4525 |
return false;
|
| 4526 |
-
}
|
| 4527 |
|
| 4528 |
-
|
| 4529 |
-
array_shift( $args );
|
| 4530 |
|
| 4531 |
return pods_do_hook( 'pods', $name, $args, $this );
|
| 4532 |
}
|
|
@@ -4534,38 +3868,35 @@ class Pods implements Iterator {
|
|
| 4534 |
/**
|
| 4535 |
* Handle variables that have been deprecated and PodsData vars
|
| 4536 |
*
|
| 4537 |
-
* @
|
| 4538 |
*
|
| 4539 |
* @return mixed
|
| 4540 |
*
|
| 4541 |
-
* @since 2.0
|
| 4542 |
*/
|
| 4543 |
-
public function __get( $name ) {
|
| 4544 |
-
|
| 4545 |
$name = (string) $name;
|
| 4546 |
|
| 4547 |
-
// PodsData vars
|
| 4548 |
-
if (
|
| 4549 |
return $this->data->{$name};
|
| 4550 |
}
|
| 4551 |
|
| 4552 |
-
if ( ! $this->deprecated ) {
|
| 4553 |
-
require_once PODS_DIR . 'deprecated/classes/Pods.php';
|
| 4554 |
-
|
| 4555 |
$this->deprecated = new Pods_Deprecated( $this );
|
| 4556 |
}
|
| 4557 |
|
| 4558 |
$var = null;
|
| 4559 |
|
| 4560 |
-
$pod_class_exists = class_exists( 'Pod' );
|
| 4561 |
-
|
| 4562 |
if ( isset( $this->deprecated->{$name} ) ) {
|
| 4563 |
-
if ( !
|
| 4564 |
pods_deprecated( "Pods->{$name}", '2.0' );
|
| 4565 |
}
|
| 4566 |
|
| 4567 |
$var = $this->deprecated->{$name};
|
| 4568 |
-
}
|
|
|
|
| 4569 |
pods_deprecated( "Pods->{$name}", '2.0' );
|
| 4570 |
}
|
| 4571 |
|
|
@@ -4573,56 +3904,33 @@ class Pods implements Iterator {
|
|
| 4573 |
}
|
| 4574 |
|
| 4575 |
/**
|
| 4576 |
-
* Handle methods that have been deprecated and any aliasing
|
| 4577 |
*
|
| 4578 |
-
* @
|
| 4579 |
-
* @
|
| 4580 |
*
|
| 4581 |
-
* @return mixed
|
| 4582 |
*
|
| 4583 |
-
* @since 2.0
|
| 4584 |
*/
|
| 4585 |
-
public function __call( $name, $args ) {
|
| 4586 |
-
|
| 4587 |
$name = (string) $name;
|
| 4588 |
|
| 4589 |
-
// select > find alias
|
| 4590 |
-
if ( 'select'
|
| 4591 |
return call_user_func_array( array( $this, 'find' ), $args );
|
| 4592 |
}
|
| 4593 |
|
| 4594 |
-
if ( ! $this->deprecated ) {
|
| 4595 |
-
require_once PODS_DIR . 'deprecated/classes/Pods.php';
|
| 4596 |
-
|
| 4597 |
$this->deprecated = new Pods_Deprecated( $this );
|
| 4598 |
}
|
| 4599 |
|
| 4600 |
-
$pod_class_exists = class_exists( 'Pod' );
|
| 4601 |
-
|
| 4602 |
if ( method_exists( $this->deprecated, $name ) ) {
|
| 4603 |
return call_user_func_array( array( $this->deprecated, $name ), $args );
|
| 4604 |
-
// @codingStandardsIgnoreLine
|
| 4605 |
-
} elseif ( ! $pod_class_exists || Pod::$deprecated_notice ) {
|
| 4606 |
-
pods_deprecated( "Pods::{$name}", '2.0' );
|
| 4607 |
}
|
| 4608 |
-
|
| 4609 |
-
|
| 4610 |
-
}
|
| 4611 |
-
|
| 4612 |
-
/**
|
| 4613 |
-
* Handle casting a Pods() object to string
|
| 4614 |
-
*
|
| 4615 |
-
* @return string Pod type and name in CURIE notation
|
| 4616 |
-
*/
|
| 4617 |
-
public function __toString() {
|
| 4618 |
-
|
| 4619 |
-
$string = '';
|
| 4620 |
-
|
| 4621 |
-
if ( ! empty( $this->pod_data ) ) {
|
| 4622 |
-
$string = sprintf( '%s:%s', $this->pod_data['type'], $this->pod_data['name'] );
|
| 4623 |
}
|
| 4624 |
-
|
| 4625 |
-
return $string;
|
| 4626 |
-
|
| 4627 |
}
|
| 4628 |
}
|
| 1 |
<?php
|
|
|
|
| 2 |
/**
|
|
|
|
|
|
|
| 3 |
* @package Pods
|
| 4 |
*/
|
| 5 |
class Pods implements Iterator {
|
| 6 |
|
| 7 |
/**
|
|
|
|
|
|
|
| 8 |
* @var bool
|
| 9 |
*/
|
| 10 |
private $iterator = false;
|
| 11 |
|
| 12 |
/**
|
|
|
|
|
|
|
| 13 |
* @var PodsAPI
|
| 14 |
*/
|
| 15 |
public $api;
|
| 16 |
|
| 17 |
/**
|
|
|
|
|
|
|
| 18 |
* @var PodsData
|
| 19 |
*/
|
| 20 |
public $data;
|
| 21 |
|
| 22 |
/**
|
|
|
|
|
|
|
| 23 |
* @var PodsData
|
| 24 |
*/
|
| 25 |
public $alt_data;
|
| 26 |
|
| 27 |
/**
|
| 28 |
+
* @var array Array of pod item arrays
|
|
|
|
|
|
|
| 29 |
*/
|
| 30 |
+
public $rows = array();
|
| 31 |
|
| 32 |
/**
|
| 33 |
+
* @var array Current pod item array
|
|
|
|
|
|
|
| 34 |
*/
|
| 35 |
+
public $row = array();
|
| 36 |
|
| 37 |
/**
|
|
|
|
|
|
|
| 38 |
* @var int
|
| 39 |
*/
|
| 40 |
+
private $row_number = -1;
|
| 41 |
|
| 42 |
/**
|
| 43 |
+
* @var array Override pod item array
|
|
|
|
|
|
|
| 44 |
*/
|
| 45 |
public $row_override = array();
|
| 46 |
|
| 47 |
/**
|
|
|
|
|
|
|
| 48 |
* @var bool
|
| 49 |
*/
|
| 50 |
public $display_errors = true;
|
| 51 |
|
| 52 |
/**
|
|
|
|
|
|
|
| 53 |
* @var array|bool|mixed|null|void
|
| 54 |
*/
|
| 55 |
public $pod_data;
|
| 56 |
|
| 57 |
/**
|
|
|
|
|
|
|
| 58 |
* @var array
|
| 59 |
*/
|
| 60 |
public $params = array();
|
| 61 |
|
| 62 |
/**
|
|
|
|
|
|
|
| 63 |
* @var string
|
| 64 |
*/
|
| 65 |
+
public $pod = '';
|
| 66 |
|
| 67 |
/**
|
|
|
|
|
|
|
| 68 |
* @var int
|
| 69 |
*/
|
| 70 |
+
public $pod_id = 0;
|
| 71 |
|
| 72 |
/**
|
|
|
|
|
|
|
| 73 |
* @var array
|
| 74 |
*/
|
| 75 |
+
public $fields = array();
|
| 76 |
|
| 77 |
/**
|
|
|
|
|
|
|
| 78 |
* @var array
|
| 79 |
*/
|
| 80 |
public $filters = array();
|
| 81 |
|
| 82 |
/**
|
|
|
|
|
|
|
| 83 |
* @var string
|
| 84 |
*/
|
| 85 |
public $detail_page;
|
| 86 |
|
| 87 |
/**
|
|
|
|
|
|
|
| 88 |
* @var int
|
| 89 |
*/
|
| 90 |
+
public $id = 0;
|
| 91 |
|
| 92 |
/**
|
|
|
|
|
|
|
| 93 |
* @var int
|
| 94 |
*/
|
| 95 |
public $limit = 15;
|
| 96 |
|
| 97 |
/**
|
|
|
|
|
|
|
| 98 |
* @var int
|
| 99 |
*/
|
| 100 |
public $offset = 0;
|
| 101 |
|
| 102 |
/**
|
|
|
|
|
|
|
| 103 |
* @var string
|
| 104 |
*/
|
| 105 |
public $page_var = 'pg';
|
| 106 |
|
| 107 |
/**
|
|
|
|
|
|
|
| 108 |
* @var int|mixed
|
| 109 |
*/
|
| 110 |
public $page = 1;
|
| 111 |
|
| 112 |
/**
|
|
|
|
|
|
|
| 113 |
* @var bool
|
| 114 |
*/
|
| 115 |
public $pagination = true;
|
| 116 |
|
| 117 |
/**
|
|
|
|
|
|
|
| 118 |
* @var bool
|
| 119 |
*/
|
| 120 |
public $search = true;
|
| 121 |
|
| 122 |
/**
|
|
|
|
|
|
|
| 123 |
* @var string
|
| 124 |
*/
|
| 125 |
public $search_var = 'search';
|
| 126 |
|
| 127 |
/**
|
|
|
|
|
|
|
| 128 |
* @var string
|
| 129 |
*/
|
| 130 |
+
public $search_mode = 'int'; // int | text | text_like
|
| 131 |
|
| 132 |
/**
|
|
|
|
|
|
|
| 133 |
* @var int
|
| 134 |
*/
|
| 135 |
public $total = 0;
|
| 136 |
|
| 137 |
/**
|
|
|
|
|
|
|
| 138 |
* @var int
|
| 139 |
*/
|
| 140 |
public $total_found = 0;
|
| 141 |
|
| 142 |
/**
|
|
|
|
|
|
|
| 143 |
* @var array
|
| 144 |
*/
|
| 145 |
public $ui = array();
|
| 146 |
|
| 147 |
/**
|
| 148 |
+
* @var mixed SEO related vars for Pod Pages
|
|
|
|
|
|
|
| 149 |
*/
|
| 150 |
public $page_template;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
public $body_classes;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
public $meta = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
public $meta_properties = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
public $meta_extra = '';
|
| 155 |
|
| 156 |
/**
|
| 157 |
+
* @var string Last SQL query used by a find()
|
|
|
|
|
|
|
| 158 |
*/
|
| 159 |
public $sql;
|
| 160 |
|
| 161 |
/**
|
| 162 |
+
* @var
|
|
|
|
|
|
|
| 163 |
*/
|
| 164 |
public $deprecated;
|
| 165 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
public $datatype;
|
| 167 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
public $datatype_id;
|
| 169 |
|
| 170 |
/**
|
| 171 |
+
* Constructor - Pods Framework core
|
| 172 |
*
|
| 173 |
+
* @param string $pod The pod name
|
| 174 |
+
* @param mixed $id (optional) The ID or slug, to load a single record; Provide array of $params to run 'find'
|
| 175 |
+
*
|
| 176 |
+
* @return \Pods
|
| 177 |
*
|
| 178 |
* @license http://www.gnu.org/licenses/gpl-2.0.html
|
| 179 |
+
* @since 1.0.0
|
| 180 |
+
* @link http://pods.io/docs/pods/
|
| 181 |
*/
|
| 182 |
+
public function __construct ( $pod = null, $id = null ) {
|
|
|
|
| 183 |
if ( null === $pod ) {
|
| 184 |
+
$queried_object = get_queried_object();
|
|
|
|
| 185 |
|
| 186 |
+
if ( $queried_object ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
$id_lookup = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
|
| 189 |
+
// Post Type Singular
|
| 190 |
+
if ( isset( $queried_object->post_type ) ) {
|
| 191 |
+
$pod = $queried_object->post_type;
|
| 192 |
+
}
|
| 193 |
+
// Term Archive
|
| 194 |
+
elseif ( isset( $queried_object->taxonomy ) ) {
|
| 195 |
+
$pod = $queried_object->taxonomy;
|
| 196 |
+
}
|
| 197 |
+
// Author Archive
|
| 198 |
+
elseif ( isset( $queried_object->user_login ) ) {
|
| 199 |
+
$pod = 'user';
|
| 200 |
+
}
|
| 201 |
+
// Post Type Archive
|
| 202 |
+
elseif ( isset( $queried_object->public ) && isset( $queried_object->name ) ) {
|
| 203 |
+
$pod = $queried_object->name;
|
| 204 |
+
|
| 205 |
+
$id_lookup = false;
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
if ( null === $id && $id_lookup ) {
|
| 209 |
+
$id = get_queried_object_id();
|
| 210 |
+
}
|
| 211 |
}
|
| 212 |
+
}
|
| 213 |
|
| 214 |
+
$this->api = pods_api( $pod );
|
| 215 |
$this->api->display_errors =& $this->display_errors;
|
| 216 |
|
| 217 |
+
$this->data = pods_data( $this->api, $id, false );
|
| 218 |
PodsData::$display_errors =& $this->display_errors;
|
| 219 |
|
| 220 |
+
// Set up page variable
|
| 221 |
if ( pods_strict( false ) ) {
|
| 222 |
+
$this->page = 1;
|
| 223 |
$this->pagination = false;
|
| 224 |
+
$this->search = false;
|
| 225 |
+
}
|
| 226 |
+
else {
|
| 227 |
+
// Get the page variable
|
| 228 |
+
$this->page = pods_var( $this->page_var, 'get' );
|
| 229 |
+
$this->page = ( empty( $this->page ) ? 1 : max( pods_absint( $this->page ), 1 ) );
|
|
|
|
|
|
|
| 230 |
}
|
| 231 |
|
| 232 |
+
// Set default pagination handling to on/off
|
| 233 |
if ( defined( 'PODS_GLOBAL_POD_PAGINATION' ) ) {
|
| 234 |
+
if ( !PODS_GLOBAL_POD_PAGINATION ) {
|
| 235 |
+
$this->page = 1;
|
| 236 |
$this->pagination = false;
|
|
|
|
|
|
|
| 237 |
}
|
| 238 |
+
else
|
| 239 |
+
$this->pagination = true;
|
| 240 |
}
|
| 241 |
|
| 242 |
+
// Set default search to on/off
|
| 243 |
if ( defined( 'PODS_GLOBAL_POD_SEARCH' ) ) {
|
| 244 |
+
if ( PODS_GLOBAL_POD_SEARCH )
|
| 245 |
$this->search = true;
|
| 246 |
+
else
|
| 247 |
$this->search = false;
|
|
|
|
| 248 |
}
|
| 249 |
|
| 250 |
+
// Set default search mode
|
| 251 |
$allowed_search_modes = array( 'int', 'text', 'text_like' );
|
| 252 |
|
| 253 |
+
if ( defined( 'PODS_GLOBAL_POD_SEARCH_MODE' ) && in_array( PODS_GLOBAL_POD_SEARCH_MODE, $allowed_search_modes ) )
|
| 254 |
$this->search_mode = PODS_GLOBAL_POD_SEARCH_MODE;
|
|
|
|
| 255 |
|
| 256 |
+
// Sync Settings
|
| 257 |
+
$this->data->page =& $this->page;
|
| 258 |
+
$this->data->limit =& $this->limit;
|
| 259 |
+
$this->data->pagination =& $this->pagination;
|
| 260 |
+
$this->data->search =& $this->search;
|
| 261 |
$this->data->search_mode =& $this->search_mode;
|
| 262 |
|
| 263 |
+
// Sync Pod Data
|
| 264 |
$this->api->pod_data =& $this->data->pod_data;
|
| 265 |
+
$this->pod_data =& $this->api->pod_data;
|
| 266 |
+
$this->api->pod_id =& $this->data->pod_id;
|
| 267 |
+
$this->pod_id =& $this->api->pod_id;
|
| 268 |
+
$this->datatype_id =& $this->pod_id;
|
| 269 |
+
$this->api->pod =& $this->data->pod;
|
| 270 |
+
$this->pod =& $this->api->pod;
|
| 271 |
+
$this->datatype =& $this->pod;
|
| 272 |
+
$this->api->fields =& $this->data->fields;
|
| 273 |
+
$this->fields =& $this->api->fields;
|
| 274 |
+
$this->detail_page =& $this->data->detail_page;
|
| 275 |
+
$this->id =& $this->data->id;
|
| 276 |
+
$this->row =& $this->data->row;
|
| 277 |
+
$this->rows =& $this->data->data;
|
| 278 |
+
$this->row_number =& $this->data->row_number;
|
| 279 |
+
$this->sql =& $this->data->sql;
|
| 280 |
+
|
| 281 |
+
if ( is_array( $id ) || is_object( $id ) )
|
| 282 |
$this->find( $id );
|
|
|
|
| 283 |
}
|
| 284 |
|
| 285 |
/**
|
| 287 |
*
|
| 288 |
* @return bool
|
| 289 |
*
|
| 290 |
+
* @since 2.0
|
| 291 |
*/
|
| 292 |
+
public function valid () {
|
| 293 |
+
if ( empty( $this->pod_id ) )
|
|
|
|
| 294 |
return false;
|
|
|
|
| 295 |
|
| 296 |
+
if ( $this->iterator )
|
| 297 |
return isset( $this->rows[ $this->row_number ] );
|
|
|
|
| 298 |
|
| 299 |
return true;
|
| 300 |
}
|
| 306 |
*
|
| 307 |
* @since 2.3.4
|
| 308 |
*
|
| 309 |
+
* @link http://www.php.net/manual/en/class.iterator.php
|
| 310 |
*/
|
| 311 |
+
public function is_iterator () {
|
|
|
|
| 312 |
return $this->iterator;
|
| 313 |
}
|
| 314 |
|
| 319 |
*
|
| 320 |
* @since 2.3.4
|
| 321 |
*
|
| 322 |
+
* @link http://www.php.net/manual/en/class.iterator.php
|
| 323 |
*/
|
| 324 |
+
public function stop_iterator () {
|
|
|
|
| 325 |
$this->iterator = false;
|
| 326 |
|
| 327 |
+
return;
|
| 328 |
}
|
| 329 |
|
| 330 |
/**
|
| 331 |
* Rewind Iterator
|
| 332 |
*
|
| 333 |
+
* @return void|boolean
|
| 334 |
+
*
|
| 335 |
* @since 2.3.4
|
| 336 |
*
|
| 337 |
+
* @link http://www.php.net/manual/en/class.iterator.php
|
| 338 |
*/
|
| 339 |
+
public function rewind () {
|
| 340 |
+
if ( $this->iterator ) {
|
|
|
|
|
|
|
|
|
|
| 341 |
$this->row_number = 0;
|
| 342 |
+
|
| 343 |
+
return;
|
| 344 |
}
|
| 345 |
+
|
| 346 |
+
return false;
|
| 347 |
}
|
| 348 |
|
| 349 |
/**
|
| 353 |
*
|
| 354 |
* @since 2.3.4
|
| 355 |
*
|
| 356 |
+
* @link http://www.php.net/manual/en/class.iterator.php
|
| 357 |
*/
|
| 358 |
+
public function current () {
|
| 359 |
+
if ( $this->iterator && $this->fetch() )
|
|
|
|
| 360 |
return $this;
|
|
|
|
| 361 |
|
| 362 |
return false;
|
| 363 |
}
|
| 365 |
/**
|
| 366 |
* Get current Iterator key
|
| 367 |
*
|
| 368 |
+
* @return int|boolean
|
| 369 |
*
|
| 370 |
* @since 2.3.4
|
| 371 |
*
|
| 372 |
+
* @link http://www.php.net/manual/en/class.iterator.php
|
| 373 |
*/
|
| 374 |
+
public function key () {
|
| 375 |
+
if ( $this->iterator )
|
| 376 |
+
return $this->row_number;
|
| 377 |
|
| 378 |
+
return false;
|
| 379 |
}
|
| 380 |
|
| 381 |
/**
|
| 382 |
* Move onto the next Iterator row
|
| 383 |
*
|
| 384 |
+
* @return void|boolean
|
| 385 |
*
|
| 386 |
* @since 2.3.4
|
| 387 |
*
|
| 388 |
+
* @link http://www.php.net/manual/en/class.iterator.php
|
| 389 |
*/
|
| 390 |
+
public function next () {
|
| 391 |
+
if ( $this->iterator ) {
|
| 392 |
+
$this->row_number++;
|
| 393 |
+
|
| 394 |
+
return;
|
| 395 |
+
}
|
| 396 |
|
| 397 |
+
return false;
|
| 398 |
}
|
| 399 |
|
| 400 |
/**
|
| 402 |
*
|
| 403 |
* @return bool
|
| 404 |
*
|
| 405 |
+
* @since 2.0
|
| 406 |
*/
|
| 407 |
+
public function exists () {
|
| 408 |
+
if ( empty( $this->row ) )
|
|
|
|
| 409 |
return false;
|
|
|
|
| 410 |
|
| 411 |
return true;
|
| 412 |
}
|
| 419 |
*
|
| 420 |
* @return array|bool An array of all rows returned from a find() call, or false if no items returned
|
| 421 |
*
|
| 422 |
+
* @since 2.0
|
| 423 |
+
* @link http://pods.io/docs/data/
|
| 424 |
*/
|
| 425 |
+
public function data () {
|
|
|
|
| 426 |
do_action( 'pods_pods_data', $this );
|
| 427 |
|
| 428 |
+
if ( empty( $this->rows ) )
|
| 429 |
return false;
|
|
|
|
| 430 |
|
| 431 |
return (array) $this->rows;
|
| 432 |
}
|
| 434 |
/**
|
| 435 |
* Return a field input for a specific field
|
| 436 |
*
|
| 437 |
+
* @param string|array $field Field name or Field data array
|
| 438 |
+
* @param string $field Input field name to use (overrides default name)
|
| 439 |
+
* @param mixed $value Current value to use
|
| 440 |
*
|
| 441 |
* @return string Field Input HTML
|
| 442 |
*
|
| 444 |
*/
|
| 445 |
public function input( $field, $input_name = null, $value = '__null' ) {
|
| 446 |
|
| 447 |
+
// Field data override
|
| 448 |
if ( is_array( $field ) ) {
|
|
|
|
| 449 |
$field_data = $field;
|
| 450 |
+
$field = pods_var_raw( 'name', $field );
|
| 451 |
+
}
|
| 452 |
+
// Get field data from field name
|
| 453 |
+
else {
|
| 454 |
$field_data = $this->fields( $field );
|
| 455 |
}
|
| 456 |
|
| 457 |
+
if ( !empty( $field_data ) ) {
|
| 458 |
+
$field_type = pods_var_raw( 'type', $field_data );
|
| 459 |
|
| 460 |
if ( empty( $input_name ) ) {
|
| 461 |
$input_name = $field;
|
| 462 |
}
|
| 463 |
|
| 464 |
+
if ( '__null' == $value ) {
|
| 465 |
+
$value = $this->field( array( 'name' => $field, 'in_form' => true ) );
|
|
|
|
|
|
|
|
|
|
| 466 |
}
|
| 467 |
|
| 468 |
return PodsForm::field( $input_name, $value, $field_type, $field_data, $this, $this->id() );
|
| 475 |
/**
|
| 476 |
* Return field array from a Pod, a field's data, or a field option
|
| 477 |
*
|
| 478 |
+
* @param null $field
|
| 479 |
+
* @param null $option
|
| 480 |
*
|
| 481 |
* @return bool|mixed
|
| 482 |
*
|
| 483 |
+
* @since 2.0
|
| 484 |
*/
|
| 485 |
+
public function fields ( $field = null, $option = null ) {
|
| 486 |
+
// No fields found
|
| 487 |
+
if ( empty( $this->fields ) )
|
|
|
|
|
|
|
|
|
|
| 488 |
$field_data = array();
|
| 489 |
+
// Return all fields
|
| 490 |
+
elseif ( empty( $field ) )
|
| 491 |
$field_data = (array) $this->fields;
|
| 492 |
+
// Field not found
|
| 493 |
+
elseif ( !isset( $this->fields[ $field ] ) )
|
| 494 |
$field_data = array();
|
| 495 |
+
// Return all field data
|
| 496 |
+
elseif ( empty( $option ) )
|
| 497 |
+
$field_data = $this->fields[ $field ];
|
| 498 |
+
else {
|
| 499 |
+
// Merge options
|
| 500 |
+
$options = array_merge( $this->fields[ $field ], $this->fields[ $field ][ 'options' ] );
|
|
|
|
|
|
|
|
|
|
| 501 |
|
| 502 |
+
$field_data = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 503 |
|
| 504 |
+
// Get a list of available items from a relationship field
|
| 505 |
+
if ( 'data' == $option && in_array( pods_var_raw( 'type', $options ), PodsForm::tableless_field_types() ) ) {
|
| 506 |
$field_data = PodsForm::field_method( 'pick', 'get_field_data', $options );
|
| 507 |
+
}
|
| 508 |
+
// Return option
|
| 509 |
+
elseif ( isset( $options[ $option ] ) ) {
|
| 510 |
$field_data = $options[ $option ];
|
| 511 |
}
|
| 512 |
+
}
|
| 513 |
|
| 514 |
/**
|
| 515 |
* Modify the field data before returning
|
| 516 |
*
|
| 517 |
* @since unknown
|
| 518 |
*
|
| 519 |
+
* @param array $field_data The data for the field.
|
| 520 |
+
* @param string|null $field The specific field that data is being return for, if set when method is called or null.
|
| 521 |
+
* @param string|null $option Value of option param when method was called. Can be used to get a list of available items from a relationship field.
|
| 522 |
+
* @param Pods|object $this The current Pods class instance.
|
| 523 |
*/
|
| 524 |
return apply_filters( 'pods_pods_fields', $field_data, $field, $option, $this );
|
| 525 |
|
| 528 |
/**
|
| 529 |
* Return row array for an item
|
| 530 |
*
|
| 531 |
+
* @return array
|
| 532 |
*
|
| 533 |
+
* @since 2.0
|
| 534 |
*/
|
| 535 |
+
public function row () {
|
|
|
|
| 536 |
do_action( 'pods_pods_row', $this );
|
| 537 |
|
| 538 |
+
if ( !is_array( $this->row ) )
|
| 539 |
return false;
|
|
|
|
| 540 |
|
| 541 |
return (array) $this->row;
|
| 542 |
}
|
| 546 |
* you will want to use field() instead. This function will automatically convert arrays into a
|
| 547 |
* list of text such as "Rick, John, and Gary"
|
| 548 |
*
|
| 549 |
+
* @param string|array $name The field name, or an associative array of parameters
|
| 550 |
+
* @param boolean $single (optional) For tableless fields, to return an array or the first
|
| 551 |
*
|
| 552 |
+
* @return string|null|false The output from the field, null if the field doesn't exist, false if no value returned for tableless fields
|
| 553 |
+
* @since 2.0
|
| 554 |
+
* @link http://pods.io/docs/display/
|
|
|
|
| 555 |
*/
|
| 556 |
+
public function display ( $name, $single = null ) {
|
|
|
|
| 557 |
$defaults = array(
|
| 558 |
+
'name' => $name,
|
| 559 |
+
'single' => $single,
|
| 560 |
+
'display' => true,
|
| 561 |
+
'serial_params' => null
|
| 562 |
);
|
| 563 |
|
| 564 |
if ( is_array( $name ) || is_object( $name ) ) {
|
| 565 |
+
$defaults[ 'name' ] = null;
|
|
|
|
| 566 |
$params = (object) array_merge( $defaults, (array) $name );
|
| 567 |
+
}
|
| 568 |
+
elseif ( is_array( $single ) || is_object( $single ) ) {
|
| 569 |
+
$defaults[ 'single' ] = null;
|
| 570 |
$params = (object) array_merge( $defaults, (array) $single );
|
|
|
|
|
|
|
| 571 |
}
|
| 572 |
+
else
|
| 573 |
+
$params = $defaults;
|
| 574 |
|
| 575 |
$params = (object) $params;
|
| 576 |
|
| 579 |
if ( is_array( $value ) ) {
|
| 580 |
$fields = $this->fields;
|
| 581 |
|
| 582 |
+
if ( isset( $this->pod_data[ 'object_fields' ] ) ) {
|
| 583 |
+
$fields = array_merge( $fields, $this->pod_data[ 'object_fields' ] );
|
| 584 |
+
}
|
| 585 |
|
| 586 |
$serial_params = array(
|
| 587 |
+
'field' => $params->name,
|
| 588 |
+
'fields' => $fields
|
| 589 |
);
|
| 590 |
|
| 591 |
+
if ( !empty( $params->serial_params ) && is_array( $params->serial_params ) )
|
| 592 |
$serial_params = array_merge( $serial_params, $params->serial_params );
|
|
|
|
| 593 |
|
| 594 |
$value = pods_serial_comma( $value, $serial_params );
|
| 595 |
}
|
| 602 |
* you will want to use field() instead. This function will automatically convert arrays into a
|
| 603 |
* list of text such as "Rick, John, and Gary"
|
| 604 |
*
|
| 605 |
+
* @param string|array $name The field name, or an associative array of parameters
|
| 606 |
+
* @param boolean $single (optional) For tableless fields, to return an array or the first
|
| 607 |
*
|
| 608 |
+
* @return string|null|false The output from the field, null if the field doesn't exist, false if no value returned for tableless fields
|
| 609 |
+
* @since 2.0
|
| 610 |
+
* @link http://pods.io/docs/display/
|
|
|
|
| 611 |
*/
|
| 612 |
+
public function raw ( $name, $single = null ) {
|
|
|
|
| 613 |
$defaults = array(
|
| 614 |
+
'name' => $name,
|
| 615 |
'single' => $single,
|
| 616 |
+
'raw' => true
|
| 617 |
);
|
| 618 |
|
| 619 |
if ( is_array( $name ) || is_object( $name ) ) {
|
| 620 |
+
$defaults[ 'name' ] = null;
|
|
|
|
| 621 |
$params = (object) array_merge( $defaults, (array) $name );
|
| 622 |
+
}
|
| 623 |
+
elseif ( is_array( $single ) || is_object( $single ) ) {
|
| 624 |
+
$defaults[ 'single' ] = null;
|
| 625 |
$params = (object) array_merge( $defaults, (array) $single );
|
|
|
|
|
|
|
| 626 |
}
|
| 627 |
+
else
|
| 628 |
+
$params = (object) $defaults;
|
| 629 |
+
|
| 630 |
+
$value = $this->field( $params );
|
| 631 |
|
| 632 |
+
return $value;
|
| 633 |
}
|
| 634 |
|
| 635 |
/**
|
| 639 |
*
|
| 640 |
* This function will return arrays for relationship and file fields.
|
| 641 |
*
|
| 642 |
+
* @param string|array $name The field name, or an associative array of parameters
|
| 643 |
+
* @param boolean $single (optional) For tableless fields, to return the whole array or the just the first item, or an associative array of parameters
|
| 644 |
+
* @param boolean $raw (optional) Whether to return the raw value, or to run through the field type's display method, or an associative array of parameters
|
|
|
|
|
|
|
| 645 |
*
|
| 646 |
+
* @return mixed|null Value returned depends on the field type, null if the field doesn't exist, false if no value returned for tableless fields
|
| 647 |
+
* @since 2.0
|
| 648 |
+
* @link http://pods.io/docs/field/
|
|
|
|
| 649 |
*/
|
| 650 |
+
public function field ( $name, $single = null, $raw = false ) {
|
| 651 |
+
global $sitepress;
|
| 652 |
|
| 653 |
$defaults = array(
|
| 654 |
+
'name' => $name,
|
| 655 |
+
'orderby' => null,
|
| 656 |
+
'single' => $single,
|
| 657 |
+
'params' => null,
|
| 658 |
+
'in_form' => false,
|
| 659 |
+
'raw' => $raw,
|
| 660 |
'raw_display' => false,
|
| 661 |
+
'display' => false,
|
| 662 |
+
'get_meta' => false,
|
| 663 |
+
'output' => null,
|
| 664 |
+
'deprecated' => false,
|
| 665 |
+
'args' => array() // extra data to send to field handlers
|
|
|
|
|
|
|
| 666 |
);
|
| 667 |
|
| 668 |
+
if ( is_array( $name ) || is_object( $name ) ) {
|
| 669 |
+
$defaults[ 'name' ] = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 670 |
$params = (object) array_merge( $defaults, (array) $name );
|
| 671 |
+
}
|
| 672 |
+
elseif ( is_array( $single ) || is_object( $single ) ) {
|
| 673 |
+
$defaults[ 'single' ] = null;
|
| 674 |
$params = (object) array_merge( $defaults, (array) $single );
|
| 675 |
+
}
|
| 676 |
+
elseif ( is_array( $raw ) || is_object( $raw ) ) {
|
| 677 |
+
$defaults[ 'raw' ] = false;
|
| 678 |
$params = (object) array_merge( $defaults, (array) $raw );
|
| 679 |
+
}
|
| 680 |
+
else
|
| 681 |
$params = (object) $defaults;
|
|
|
|
| 682 |
|
| 683 |
if ( $params->in_form ) {
|
| 684 |
$params->output = 'ids';
|
| 685 |
+
}
|
| 686 |
+
elseif ( null === $params->output ) {
|
| 687 |
/**
|
| 688 |
+
* Override the way realted fields are output
|
| 689 |
*
|
| 690 |
+
* @param string $output How to output related fields. Default is 'arrays'. Options: id|name|object|array|pod
|
| 691 |
+
* @param array|object $row Current row being outputted.
|
| 692 |
+
* @param array $params Params array passed to field().
|
| 693 |
+
* @param object|Pods $this Current Pods object.
|
| 694 |
*/
|
| 695 |
$params->output = apply_filters( 'pods_pods_field_related_output_type', 'arrays', $this->row, $params, $this );
|
| 696 |
}
|
| 697 |
|
| 698 |
+
if ( in_array( $params->output, array( 'id', 'name', 'object', 'array', 'pod' ) ) )
|
| 699 |
$params->output .= 's';
|
|
|
|
| 700 |
|
| 701 |
+
// Support old $orderby variable
|
| 702 |
if ( null !== $params->single && is_string( $params->single ) && empty( $params->orderby ) ) {
|
| 703 |
if ( ! class_exists( 'Pod' ) || Pod::$deprecated_notice ) {
|
| 704 |
pods_deprecated( 'Pods::field', '2.0', 'Use $params[ \'orderby\' ] instead' );
|
| 705 |
}
|
| 706 |
|
| 707 |
$params->orderby = $params->single;
|
| 708 |
+
$params->single = false;
|
| 709 |
}
|
| 710 |
|
| 711 |
+
if ( null !== $params->single )
|
| 712 |
$params->single = (boolean) $params->single;
|
|
|
|
| 713 |
|
| 714 |
$params->name = trim( $params->name );
|
| 715 |
+
if ( is_array( $params->name ) || strlen( $params->name ) < 1 )
|
| 716 |
return null;
|
|
|
|
| 717 |
|
| 718 |
$params->full_name = $params->name;
|
| 719 |
|
| 720 |
$value = null;
|
| 721 |
|
| 722 |
+
if ( isset( $this->row_override[ $params->name ] ) )
|
| 723 |
$value = $this->row_override[ $params->name ];
|
|
|
|
| 724 |
|
| 725 |
if ( false === $this->row() ) {
|
| 726 |
+
if ( false !== $this->data() )
|
| 727 |
$this->fetch();
|
| 728 |
+
else
|
| 729 |
return $value;
|
|
|
|
| 730 |
}
|
| 731 |
|
| 732 |
+
if ( $this->data->field_id == $params->name ) {
|
| 733 |
+
if ( isset( $this->row[ $params->name ] ) )
|
| 734 |
return $this->row[ $params->name ];
|
| 735 |
+
elseif ( null !== $value )
|
|
|
|
| 736 |
return $value;
|
|
|
|
| 737 |
|
| 738 |
return 0;
|
| 739 |
}
|
| 740 |
|
| 741 |
+
$tableless_field_types = PodsForm::tableless_field_types();
|
| 742 |
$simple_tableless_objects = PodsForm::simple_tableless_objects();
|
| 743 |
|
| 744 |
$params->traverse = array();
|
| 745 |
|
| 746 |
+
if ( in_array( $params->name, array( '_link', 'detail_url' ) ) || ( in_array( $params->name, array( 'permalink', 'the_permalink' ) ) && in_array( $this->pod_data[ 'type' ], array( 'post_type', 'media' ) ) ) ) {
|
| 747 |
+
if ( 0 < strlen( $this->detail_page ) )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 748 |
$value = get_home_url() . '/' . $this->do_magic_tags( $this->detail_page );
|
| 749 |
+
elseif ( in_array( $this->pod_data[ 'type' ], array( 'post_type', 'media' ) ) )
|
| 750 |
+
$value = get_permalink( $this->id() );
|
| 751 |
+
elseif ( 'taxonomy' == $this->pod_data[ 'type' ] )
|
| 752 |
+
$value = get_term_link( $this->id(), $this->pod_data[ 'name' ] );
|
| 753 |
+
elseif ( 'user' == $this->pod_data[ 'type' ] )
|
| 754 |
+
$value = get_author_posts_url( $this->id() );
|
| 755 |
+
elseif ( 'comment' == $this->pod_data[ 'type' ] )
|
| 756 |
+
$value = get_comment_link( $this->id() );
|
| 757 |
+
}
|
| 758 |
+
|
| 759 |
+
$field_data = $last_field_data = false;
|
| 760 |
+
$field_type = false;
|
| 761 |
+
|
| 762 |
+
$first_field = explode( '.', $params->name );
|
| 763 |
+
$first_field = $first_field[ 0 ];
|
| 764 |
+
|
| 765 |
+
if ( isset( $this->fields[ $first_field ] ) ) {
|
| 766 |
+
$field_data = $this->fields[ $first_field ];
|
| 767 |
+
$field_type = 'field';
|
| 768 |
+
}
|
| 769 |
+
elseif ( !empty( $this->pod_data[ 'object_fields' ] ) ) {
|
| 770 |
+
if ( isset( $this->pod_data[ 'object_fields' ][ $first_field ] ) ) {
|
| 771 |
+
$field_data = $this->pod_data[ 'object_fields' ][ $first_field ];
|
| 772 |
+
$field_type = 'object_field';
|
| 773 |
+
}
|
| 774 |
+
else {
|
| 775 |
+
foreach ( $this->pod_data[ 'object_fields' ] as $object_field => $object_field_opt ) {
|
| 776 |
+
if ( in_array( $first_field, $object_field_opt[ 'alias' ] ) ) {
|
| 777 |
+
if ( $first_field == $params->name )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 778 |
$params->name = $object_field;
|
|
|
|
| 779 |
|
| 780 |
+
$first_field = $object_field;
|
| 781 |
+
$field_data = $object_field_opt;
|
| 782 |
+
$field_type = 'object_field';
|
|
|
|
| 783 |
|
| 784 |
break;
|
| 785 |
}
|
| 786 |
}
|
| 787 |
}
|
| 788 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 789 |
|
| 790 |
+
// Simple fields have no other output options
|
| 791 |
+
if ( 'pick' == $field_data[ 'type' ] && in_array( $field_data[ 'pick_object' ], $simple_tableless_objects ) ) {
|
| 792 |
$params->output = 'arrays';
|
| 793 |
}
|
| 794 |
|
| 795 |
+
if ( empty( $value ) && in_array( $field_data[ 'type' ], $tableless_field_types ) ) {
|
|
|
|
| 796 |
$params->raw = true;
|
| 797 |
|
| 798 |
$value = false;
|
| 799 |
|
| 800 |
+
if ( 'arrays' != $params->output && isset( $this->row[ '_' . $params->output . '_' . $params->name ] ) ) {
|
| 801 |
+
$value = $this->row[ '_' . $params->output . '_' . $params->name ];
|
| 802 |
+
}
|
| 803 |
+
elseif ( 'arrays' == $params->output && isset( $this->row[ $params->name ] ) ) {
|
|
|
|
| 804 |
$value = $this->row[ $params->name ];
|
| 805 |
}
|
| 806 |
|
| 807 |
+
if ( false !== $value && !is_array( $value ) && 'pick' == $field_data[ 'type' ] && in_array( $field_data[ 'pick_object' ], $simple_tableless_objects ) )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 808 |
$value = PodsForm::field_method( 'pick', 'simple_value', $params->name, $value, $field_data, $this->pod_data, $this->id(), true );
|
|
|
|
| 809 |
}
|
| 810 |
|
| 811 |
+
if ( empty( $value ) && isset( $this->row[ $params->name ] ) && ( !in_array( $field_data[ 'type' ], $tableless_field_types ) || 'arrays' == $params->output ) ) {
|
| 812 |
+
if ( empty( $field_data ) || in_array( $field_data[ 'type' ], array( 'boolean', 'number', 'currency' ) ) )
|
|
|
|
|
|
|
|
|
|
|
|
|
| 813 |
$params->raw = true;
|
|
|
|
| 814 |
|
| 815 |
if ( null === $params->single ) {
|
| 816 |
+
if ( isset( $this->fields[ $params->name ] ) && !in_array( $this->fields[ $params->name ][ 'type' ], $tableless_field_types ) )
|
| 817 |
$params->single = true;
|
| 818 |
+
else
|
| 819 |
$params->single = false;
|
|
|
|
| 820 |
}
|
| 821 |
|
| 822 |
$value = $this->row[ $params->name ];
|
| 823 |
+
}
|
| 824 |
+
elseif ( empty( $value ) ) {
|
| 825 |
$object_field_found = false;
|
| 826 |
|
| 827 |
+
if ( 'object_field' == $field_type ) {
|
| 828 |
$object_field_found = true;
|
| 829 |
|
| 830 |
+
if ( isset( $this->row[ $first_field ] ) )
|
| 831 |
$value = $this->row[ $first_field ];
|
| 832 |
+
elseif ( in_array( $field_data[ 'type' ], $tableless_field_types ) ) {
|
|
|
|
| 833 |
$this->fields[ $first_field ] = $field_data;
|
| 834 |
|
| 835 |
$object_field_found = false;
|
|
|
|
|
|
|
| 836 |
}
|
| 837 |
+
else
|
| 838 |
+
return null;
|
| 839 |
+
}
|
| 840 |
|
| 841 |
+
if ( 'post_type' == $this->pod_data[ 'type' ] && !isset( $this->fields[ $params->name ] ) ) {
|
| 842 |
+
if ( !isset( $this->fields[ 'post_thumbnail' ] ) && ( 'post_thumbnail' == $params->name || 0 === strpos( $params->name, 'post_thumbnail.' ) ) ) {
|
| 843 |
+
$size = 'thumbnail';
|
| 844 |
+
|
| 845 |
+
if ( 0 === strpos( $params->name, 'post_thumbnail.' ) ) {
|
| 846 |
+
$field_names = explode( '.', $params->name );
|
| 847 |
+
|
| 848 |
+
if ( isset( $field_names[ 1 ] ) )
|
| 849 |
+
$size = $field_names[ 1 ];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 850 |
}
|
|
|
|
| 851 |
|
| 852 |
+
// Pods will auto-get the thumbnail ID if this isn't an attachment
|
| 853 |
+
$value = pods_image( $this->id(), $size, 0, null, true );
|
| 854 |
+
|
| 855 |
$object_field_found = true;
|
| 856 |
+
}
|
| 857 |
+
elseif ( !isset( $this->fields[ 'post_thumbnail_url' ] ) && ( 'post_thumbnail_url' == $params->name || 0 === strpos( $params->name, 'post_thumbnail_url.' ) ) ) {
|
| 858 |
+
$size = 'thumbnail';
|
| 859 |
+
|
| 860 |
+
if ( 0 === strpos( $params->name, 'post_thumbnail_url.' ) ) {
|
| 861 |
+
$field_names = explode( '.', $params->name );
|
| 862 |
+
|
| 863 |
+
if ( isset( $field_names[ 1 ] ) )
|
| 864 |
+
$size = $field_names[ 1 ];
|
| 865 |
}
|
| 866 |
+
|
| 867 |
+
// Pods will auto-get the thumbnail ID if this isn't an attachment
|
| 868 |
+
$value = pods_image_url( $this->id(), $size, 0, true );
|
| 869 |
+
|
| 870 |
+
$object_field_found = true;
|
| 871 |
}
|
| 872 |
+
elseif ( 0 === strpos( $params->name, 'image_attachment.' ) ) {
|
| 873 |
+
$size = 'thumbnail';
|
| 874 |
|
| 875 |
+
$image_id = 0;
|
| 876 |
|
| 877 |
+
$field_names = explode( '.', $params->name );
|
| 878 |
+
|
| 879 |
+
if ( isset( $field_names[ 1 ] ) )
|
| 880 |
+
$image_id = $field_names[ 1 ];
|
| 881 |
+
|
| 882 |
+
if ( isset( $field_names[ 2 ] ) )
|
| 883 |
+
$size = $field_names[ 2 ];
|
| 884 |
|
| 885 |
+
if ( !empty( $image_id ) ) {
|
| 886 |
+
$value = pods_image( $image_id, $size, 0, null, true );
|
| 887 |
+
|
| 888 |
+
if ( !empty( $value ) )
|
| 889 |
+
$object_field_found = true;
|
| 890 |
+
}
|
| 891 |
}
|
| 892 |
+
elseif ( 0 === strpos( $params->name, 'image_attachment_url.' ) ) {
|
| 893 |
+
$size = 'thumbnail';
|
| 894 |
|
| 895 |
+
$image_id = 0;
|
| 896 |
+
|
| 897 |
+
$field_names = explode( '.', $params->name );
|
|
|
|
| 898 |
|
| 899 |
+
if ( isset( $field_names[ 1 ] ) )
|
| 900 |
+
$image_id = $field_names[ 1 ];
|
| 901 |
+
|
| 902 |
+
if ( isset( $field_names[ 2 ] ) )
|
| 903 |
+
$size = $field_names[ 2 ];
|
| 904 |
+
|
| 905 |
+
if ( !empty( $image_id ) ) {
|
| 906 |
+
$value = pods_image_url( $image_id, $size, 0, true );
|
| 907 |
+
|
| 908 |
+
if ( !empty( $value ) )
|
| 909 |
+
$object_field_found = true;
|
| 910 |
}
|
| 911 |
+
}
|
| 912 |
+
}
|
| 913 |
+
elseif ( 'user' == $this->pod_data[ 'type' ] && !isset( $this->fields[ $params->name ] ) ) {
|
| 914 |
+
if ( !isset( $this->fields[ 'avatar' ] ) && ( 'avatar' == $params->name || 0 === strpos( $params->name, 'avatar.' ) ) ) {
|
| 915 |
+
$size = null;
|
| 916 |
|
| 917 |
+
if ( 0 === strpos( $params->name, 'avatar.' ) ) {
|
| 918 |
+
$field_names = explode( '.', $params->name );
|
|
|
|
|
|
|
| 919 |
|
| 920 |
+
if ( isset( $field_names[ 1 ] ) )
|
| 921 |
+
$size = (int) $field_names[ 1 ];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 922 |
}
|
| 923 |
|
| 924 |
+
if ( !empty( $size ) )
|
| 925 |
+
$value = get_avatar( $this->id(), $size );
|
| 926 |
+
else
|
| 927 |
+
$value = get_avatar( $this->id() );
|
| 928 |
|
| 929 |
+
$object_field_found = true;
|
| 930 |
+
}
|
| 931 |
+
}
|
| 932 |
+
elseif ( 0 === strpos( $params->name, 'image_attachment.' ) ) {
|
| 933 |
+
$size = 'thumbnail';
|
| 934 |
|
| 935 |
+
$image_id = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 936 |
|
| 937 |
+
$field_names = explode( '.', $params->name );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 938 |
|
| 939 |
+
if ( isset( $field_names[ 1 ] ) )
|
| 940 |
+
$image_id = $field_names[ 1 ];
|
| 941 |
+
|
| 942 |
+
if ( isset( $field_names[ 2 ] ) )
|
| 943 |
+
$size = $field_names[ 2 ];
|
| 944 |
+
|
| 945 |
+
if ( !empty( $image_id ) ) {
|
| 946 |
+
$value = pods_image( $image_id, $size, 0, null, true );
|
| 947 |
+
|
| 948 |
+
if ( !empty( $value ) )
|
| 949 |
+
$object_field_found = true;
|
| 950 |
+
}
|
| 951 |
+
}
|
| 952 |
+
elseif ( 0 === strpos( $params->name, 'image_attachment_url.' ) ) {
|
| 953 |
+
$size = 'thumbnail';
|
| 954 |
+
|
| 955 |
+
$image_id = 0;
|
| 956 |
+
|
| 957 |
+
$field_names = explode( '.', $params->name );
|
| 958 |
+
|
| 959 |
+
if ( isset( $field_names[ 1 ] ) )
|
| 960 |
+
$image_id = $field_names[ 1 ];
|
| 961 |
+
|
| 962 |
+
if ( isset( $field_names[ 2 ] ) )
|
| 963 |
+
$size = $field_names[ 2 ];
|
| 964 |
+
|
| 965 |
+
if ( !empty( $image_id ) ) {
|
| 966 |
+
$value = pods_image_url( $image_id, $size, 0, true );
|
| 967 |
+
|
| 968 |
+
if ( !empty( $value ) )
|
| 969 |
+
$object_field_found = true;
|
| 970 |
}
|
| 971 |
}
|
| 972 |
|
|
|
|
| 973 |
if ( false === $object_field_found ) {
|
| 974 |
$params->traverse = array( $params->name );
|
| 975 |
|
| 976 |
if ( false !== strpos( $params->name, '.' ) ) {
|
| 977 |
$params->traverse = explode( '.', $params->name );
|
| 978 |
|
| 979 |
+
$params->name = $params->traverse[ 0 ];
|
| 980 |
}
|
| 981 |
|
| 982 |
+
if ( isset( $this->fields[ $params->name ] ) && isset( $this->fields[ $params->name ][ 'type' ] ) ) {
|
|
|
|
| 983 |
/**
|
| 984 |
* Modify value returned by field() after its retrieved, but before its validated or formatted
|
| 985 |
*
|
| 986 |
+
* Filter name is set dynamically with name of field: "pods_pods_field_{field_name}"
|
| 987 |
*
|
| 988 |
* @since unknown
|
| 989 |
*
|
| 990 |
+
* @param array|string|null $value Value retrieved.
|
| 991 |
+
* @param array|object $row Current row being outputted.
|
| 992 |
+
* @param array $params Params array passed to field().
|
| 993 |
+
* @param object|Pods $this Current Pods object.
|
| 994 |
+
*
|
| 995 |
*/
|
| 996 |
+
$v = apply_filters( 'pods_pods_field_' . $this->fields[ $params->name ][ 'type' ], null, $this->fields[ $params->name ], $this->row, $params, $this );
|
| 997 |
|
| 998 |
+
if ( null !== $v )
|
| 999 |
return $v;
|
|
|
|
| 1000 |
}
|
| 1001 |
|
| 1002 |
$simple = false;
|
| 1003 |
+
$simple_data = array();
|
| 1004 |
|
| 1005 |
+
if ( isset( $this->fields[ $params->name ] ) ) {
|
| 1006 |
+
if ( 'meta' == $this->pod_data[ 'storage' ] ) {
|
| 1007 |
+
if ( !in_array( $this->fields[ $params->name ][ 'type' ], $tableless_field_types ) )
|
| 1008 |
+
$simple = true;
|
| 1009 |
}
|
| 1010 |
|
| 1011 |
+
if ( in_array( $this->fields[ $params->name ][ 'type' ], $tableless_field_types ) ) {
|
| 1012 |
$params->raw = true;
|
| 1013 |
|
| 1014 |
+
if ( 'pick' == $this->fields[ $params->name ][ 'type' ] && in_array( $this->fields[ $params->name ][ 'pick_object' ], $simple_tableless_objects ) ) {
|
| 1015 |
+
$simple = true;
|
| 1016 |
$params->single = true;
|
| 1017 |
}
|
|
|
|
|
|
|
| 1018 |
}
|
| 1019 |
+
elseif ( in_array( $this->fields[ $params->name ][ 'type' ], array( 'boolean', 'number', 'currency' ) ) )
|
| 1020 |
+
$params->raw = true;
|
| 1021 |
}
|
| 1022 |
|
| 1023 |
+
if ( !isset( $this->fields[ $params->name ] ) || !in_array( $this->fields[ $params->name ][ 'type' ], $tableless_field_types ) || $simple ) {
|
| 1024 |
if ( null === $params->single ) {
|
| 1025 |
+
if ( isset( $this->fields[ $params->name ] ) && !in_array( $this->fields[ $params->name ][ 'type' ], $tableless_field_types ) )
|
| 1026 |
$params->single = true;
|
| 1027 |
+
else
|
| 1028 |
$params->single = false;
|
|
|
|
| 1029 |
}
|
| 1030 |
|
| 1031 |
+
$no_conflict = pods_no_conflict_check( $this->pod_data[ 'type' ] );
|
| 1032 |
|
| 1033 |
+
if ( !$no_conflict )
|
| 1034 |
+
pods_no_conflict_on( $this->pod_data[ 'type' ] );
|
|
|
|
|
|
|
| 1035 |
|
| 1036 |
+
if ( in_array( $this->pod_data[ 'type' ], array( 'post_type', 'media' ) ) ) {
|
| 1037 |
$id = $this->id();
|
| 1038 |
|
| 1039 |
+
// Support for WPML 'duplicated' translation handling
|
| 1040 |
+
if ( is_object( $sitepress ) && $sitepress->is_translated_post_type( $this->pod_data[ 'name' ] ) ) {
|
| 1041 |
+
$master_post_id = (int) get_post_meta( $id, '_icl_lang_duplicate_of', true );
|
| 1042 |
|
| 1043 |
+
if ( 0 < $master_post_id )
|
| 1044 |
+
$id = $master_post_id;
|
| 1045 |
+
}
|
| 1046 |
|
| 1047 |
+
$value = get_post_meta( $id, $params->name, $params->single );
|
|
|
|
|
|
|
| 1048 |
|
| 1049 |
+
$single_multi = 'single';
|
| 1050 |
+
|
| 1051 |
+
if ( isset( $this->fields[ $params->name ] ) ) {
|
| 1052 |
+
$single_multi = pods_v( $this->fields[ $params->name ][ 'type' ] . '_format_type', $this->fields[ $params->name ][ 'options' ], 'single' );
|
|
|
|
|
|
|
| 1053 |
}
|
| 1054 |
|
| 1055 |
+
if ( $simple && !is_array( $value ) && 'single' != $single_multi ) {
|
| 1056 |
+
$value = get_post_meta( $id, $params->name );
|
| 1057 |
+
}
|
| 1058 |
+
}
|
| 1059 |
+
elseif ( in_array( $this->pod_data[ 'type' ], array( 'user', 'comment' ) ) ) {
|
| 1060 |
+
$value = get_metadata( $this->pod_data[ 'type' ], $this->id(), $params->name, $params->single );
|
| 1061 |
|
| 1062 |
$single_multi = 'single';
|
| 1063 |
|
| 1064 |
+
if ( isset( $this->fields[ $params->name ] ) ) {
|
| 1065 |
+
$single_multi = pods_v( $this->fields[ $params->name ][ 'type' ] . '_format_type', $this->fields[ $params->name ][ 'options' ], 'single' );
|
| 1066 |
}
|
| 1067 |
|
| 1068 |
+
if ( $simple && !is_array( $value ) && 'single' != $single_multi ) {
|
| 1069 |
+
$value = get_metadata( $this->pod_data[ 'type' ], $this->id(), $params->name );
|
| 1070 |
}
|
| 1071 |
+
}
|
| 1072 |
+
elseif ( 'settings' == $this->pod_data[ 'type' ] )
|
| 1073 |
+
$value = get_option( $this->pod_data[ 'name' ] . '_' . $params->name, null );
|
| 1074 |
|
| 1075 |
+
// Handle Simple Relationships
|
| 1076 |
if ( $simple ) {
|
| 1077 |
+
if ( null === $params->single )
|
| 1078 |
$params->single = false;
|
| 1079 |
+
|
| 1080 |
|
| 1081 |
$value = PodsForm::field_method( 'pick', 'simple_value', $params->name, $value, $this->fields[ $params->name ], $this->pod_data, $this->id(), true );
|
| 1082 |
}
|
| 1083 |
|
| 1084 |
+
if ( !$no_conflict )
|
| 1085 |
+
pods_no_conflict_off( $this->pod_data[ 'type' ] );
|
| 1086 |
+
}
|
| 1087 |
+
else {
|
| 1088 |
+
// Dot-traversal
|
| 1089 |
+
$pod = $this->pod;
|
| 1090 |
+
$ids = array( $this->id() );
|
|
|
|
| 1091 |
$all_fields = array();
|
| 1092 |
|
| 1093 |
$lookup = $params->traverse;
|
| 1094 |
|
| 1095 |
+
// Get fields matching traversal names
|
| 1096 |
+
if ( !empty( $lookup ) ) {
|
| 1097 |
$fields = $this->api->load_fields( array(
|
| 1098 |
+
'name' => $lookup,
|
| 1099 |
+
'type' => $tableless_field_types,
|
| 1100 |
+
'object_fields' => true // @todo support object fields too
|
|
|
|
| 1101 |
) );
|
| 1102 |
|
| 1103 |
+
if ( !empty( $fields ) ) {
|
| 1104 |
foreach ( $fields as $field ) {
|
| 1105 |
+
if ( !empty( $field ) ) {
|
| 1106 |
+
if ( !isset( $all_fields[ $field[ 'pod' ] ] ) )
|
| 1107 |
+
$all_fields[ $field[ 'pod' ] ] = array();
|
|
|
|
| 1108 |
|
| 1109 |
+
$all_fields[ $field[ 'pod' ] ][ $field[ 'name' ] ] = $field;
|
| 1110 |
}
|
| 1111 |
}
|
| 1112 |
}
|
| 1113 |
|
| 1114 |
+
if ( !empty( $this->pod_data[ 'object_fields' ] ) ) {
|
| 1115 |
+
foreach ( $this->pod_data[ 'object_fields' ] as $object_field => $object_field_opt ) {
|
| 1116 |
+
if ( in_array( $object_field_opt[ 'type' ], $tableless_field_types ) ) {
|
|
|
|
|
|
|
| 1117 |
$all_fields[ $this->pod ][ $object_field ] = $object_field_opt;
|
| 1118 |
}
|
| 1119 |
}
|
| 1120 |
}
|
| 1121 |
+
}
|
| 1122 |
|
| 1123 |
+
$last_type = $last_object = $last_pick_val = '';
|
| 1124 |
+
$last_options = array();
|
|
|
|
| 1125 |
|
| 1126 |
+
$single_multi = pods_v( $this->fields[ $params->name ][ 'type' ] . '_format_type', $this->fields[ $params->name ][ 'options' ], 'single' );
|
| 1127 |
|
| 1128 |
+
if ( 'multi' == $single_multi )
|
| 1129 |
+
$limit = (int) pods_v( $this->fields[ $params->name ][ 'type' ] . '_limit', $this->fields[ $params->name ][ 'options' ], 0 );
|
| 1130 |
+
else
|
| 1131 |
$limit = 1;
|
|
|
|
| 1132 |
|
| 1133 |
+
$last_limit = 0;
|
| 1134 |
+
|
| 1135 |
+
// Loop through each traversal level
|
| 1136 |
foreach ( $params->traverse as $key => $field ) {
|
| 1137 |
$last_loop = false;
|
| 1138 |
|
| 1139 |
+
if ( count( $params->traverse ) <= ( $key + 1 ) )
|
| 1140 |
$last_loop = true;
|
|
|
|
| 1141 |
|
| 1142 |
$field_exists = isset( $all_fields[ $pod ][ $field ] );
|
| 1143 |
|
| 1144 |
+
$simple = false;
|
| 1145 |
$last_options = array();
|
| 1146 |
|
| 1147 |
+
if ( $field_exists && 'pick' == $all_fields[ $pod ][ $field ][ 'type' ] && in_array( $all_fields[ $pod ][ $field ][ 'pick_object' ], $simple_tableless_objects ) ) {
|
| 1148 |
+
$simple = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1149 |
$last_options = $all_fields[ $pod ][ $field ];
|
| 1150 |
}
|
| 1151 |
|
| 1152 |
+
// Tableless handler
|
| 1153 |
+
if ( $field_exists && ( !in_array( $all_fields[ $pod ][ $field ][ 'type' ], array( 'pick', 'taxonomy' ) ) || !$simple ) ) {
|
| 1154 |
+
$type = $all_fields[ $pod ][ $field ][ 'type' ];
|
| 1155 |
+
$pick_object = $all_fields[ $pod ][ $field ][ 'pick_object' ];
|
| 1156 |
+
$pick_val = $all_fields[ $pod ][ $field ][ 'pick_val' ];
|
| 1157 |
+
|
| 1158 |
+
if ( 'table' == $pick_object ) {
|
| 1159 |
+
$pick_val = pods_v( 'pick_table', $all_fields[ $pod ][ $field ][ 'options' ], $pick_val, true );
|
| 1160 |
+
}
|
| 1161 |
+
elseif ( '__current__' == $pick_val ) {
|
|
|
|
|
|
|
|
|
|
| 1162 |
$pick_val = $pod;
|
| 1163 |
}
|
| 1164 |
|
| 1165 |
$last_limit = 0;
|
| 1166 |
|
| 1167 |
+
if ( in_array( $type, $tableless_field_types ) ) {
|
| 1168 |
+
$single_multi = pods_v( "{$type}_format_type", $all_fields[ $pod ][ $field ][ 'options' ], 'single' );
|
| 1169 |
|
| 1170 |
+
if ( 'multi' == $single_multi ) {
|
| 1171 |
+
$last_limit = (int) pods_v( "{$type}_limit", $all_fields[ $pod ][ $field ][ 'options' ], 0 );
|
| 1172 |
+
}
|
| 1173 |
+
else {
|
| 1174 |
$last_limit = 1;
|
| 1175 |
}
|
| 1176 |
}
|
| 1177 |
|
| 1178 |
+
$last_type = $type;
|
| 1179 |
+
$last_object = $pick_object;
|
| 1180 |
$last_pick_val = $pick_val;
|
| 1181 |
+
$last_options = $all_fields[ $pod ][ $field ];
|
| 1182 |
|
| 1183 |
+
// Temporary hack until there's some better handling here
|
| 1184 |
+
$last_limit = $last_limit * count( $ids );
|
| 1185 |
|
| 1186 |
+
// Get related IDs
|
| 1187 |
+
if ( !isset( $all_fields[ $pod ][ $field ][ 'pod_id' ] ) ) {
|
| 1188 |
+
$all_fields[ $pod ][ $field ][ 'pod_id' ] = 0;
|
| 1189 |
}
|
| 1190 |
|
| 1191 |
+
if ( isset( $all_fields[ $pod ][ $field ][ 'id' ] ) ) {
|
| 1192 |
+
$ids = $this->api->lookup_related_items(
|
| 1193 |
+
$all_fields[ $pod ][ $field ][ 'id' ],
|
| 1194 |
+
$all_fields[ $pod ][ $field ][ 'pod_id' ],
|
| 1195 |
+
$ids,
|
| 1196 |
+
$all_fields[ $pod ][ $field ]
|
| 1197 |
+
);
|
| 1198 |
}
|
| 1199 |
|
| 1200 |
+
// No items found
|
| 1201 |
if ( empty( $ids ) ) {
|
| 1202 |
return false;
|
| 1203 |
+
} // @todo This should return array() if not $params->single
|
| 1204 |
+
elseif ( 0 < $last_limit ) {
|
| 1205 |
$ids = array_slice( $ids, 0, $last_limit );
|
| 1206 |
}
|
| 1207 |
|
| 1208 |
+
// Get $pod if related to a Pod
|
| 1209 |
+
if ( !empty( $pick_object ) && ( !empty( $pick_val ) || in_array( $pick_object, array( 'user', 'media', 'comment' ) ) ) ) {
|
| 1210 |
+
if ( 'pod' == $pick_object ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1211 |
$pod = $pick_val;
|
| 1212 |
+
}
|
| 1213 |
+
else {
|
| 1214 |
$check = $this->api->get_table_info( $pick_object, $pick_val );
|
| 1215 |
|
| 1216 |
+
if ( !empty( $check ) && !empty( $check[ 'pod' ] ) ) {
|
| 1217 |
+
$pod = $check[ 'pod' ][ 'name' ];
|
| 1218 |
}
|
| 1219 |
}
|
| 1220 |
}
|
| 1221 |
+
}
|
| 1222 |
+
// Assume last iteration
|
| 1223 |
+
else {
|
| 1224 |
+
// Invalid field
|
| 1225 |
+
if ( 0 == $key ) {
|
| 1226 |
+
return false;
|
|
|
|
|
|
|
| 1227 |
}
|
| 1228 |
+
|
| 1229 |
+
$last_loop = true;
|
| 1230 |
+
}
|
| 1231 |
|
| 1232 |
if ( $last_loop ) {
|
| 1233 |
$object_type = $last_object;
|
| 1234 |
+
$object = $last_pick_val;
|
| 1235 |
|
| 1236 |
+
if ( in_array( $last_type, PodsForm::file_field_types() ) ) {
|
| 1237 |
$object_type = 'media';
|
| 1238 |
+
$object = 'attachment';
|
| 1239 |
}
|
| 1240 |
|
| 1241 |
$data = array();
|
| 1242 |
|
| 1243 |
$table = $this->api->get_table_info( $object_type, $object, null, null, $last_options );
|
| 1244 |
|
| 1245 |
+
$join = $where = array();
|
|
|
|
| 1246 |
|
| 1247 |
+
if ( !empty( $table[ 'join' ] ) )
|
| 1248 |
+
$join = (array) $table[ 'join' ];
|
|
|
|
| 1249 |
|
| 1250 |
+
if ( !empty( $table[ 'where' ] ) || !empty( $ids ) ) {
|
| 1251 |
foreach ( $ids as $id ) {
|
| 1252 |
+
$where[ $id ] = '`t`.`' . $table[ 'field_id' ] . '` = ' . (int) $id;
|
| 1253 |
}
|
| 1254 |
|
| 1255 |
+
if ( !empty( $where ) ) {
|
| 1256 |
$where = array( implode( ' OR ', $where ) );
|
| 1257 |
}
|
| 1258 |
|
| 1259 |
+
if ( !empty( $table[ 'where' ] ) ) {
|
| 1260 |
+
$where = array_merge( $where, array_values( (array) $table[ 'where' ] ) );
|
|
|
|
| 1261 |
}
|
| 1262 |
}
|
| 1263 |
|
| 1264 |
/**
|
| 1265 |
+
* @var $related_obj Pods
|
|
|
|
|
|
|
| 1266 |
*/
|
| 1267 |
$related_obj = false;
|
| 1268 |
|
| 1269 |
+
if ( 'pod' == $object_type )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1270 |
$related_obj = pods( $object, null, false );
|
| 1271 |
+
elseif ( !empty( $table[ 'pod' ] ) )
|
| 1272 |
+
$related_obj = pods( $table[ 'pod' ][ 'name' ], null, false );
|
|
|
|
| 1273 |
|
| 1274 |
+
if ( !empty( $table[ 'table' ] ) || !empty( $related_obj ) ) {
|
| 1275 |
$sql = array(
|
| 1276 |
+
'select' => '*, `t`.`' . $table[ 'field_id' ] . '` AS `pod_item_id`',
|
| 1277 |
+
'table' => $table[ 'table' ],
|
| 1278 |
+
'join' => $join,
|
| 1279 |
+
'where' => $where,
|
| 1280 |
+
'orderby' => $params->orderby,
|
| 1281 |
'pagination' => false,
|
| 1282 |
+
'search' => false,
|
| 1283 |
+
'limit' => -1,
|
| 1284 |
+
'expires' => 180 // @todo This could potentially cause issues if someone changes the data within this time and persistent storage is used
|
|
|
|
| 1285 |
);
|
| 1286 |
|
| 1287 |
+
// Output types
|
| 1288 |
+
if ( in_array( $params->output, array( 'ids', 'objects', 'pods' ) ) )
|
| 1289 |
+
$sql[ 'select' ] = '`t`.`' . $table[ 'field_id' ] . '` AS `pod_item_id`';
|
| 1290 |
+
elseif ( 'names' == $params->output && !empty( $table[ 'field_index' ] ) )
|
| 1291 |
+
$sql[ 'select' ] = '`t`.`' . $table[ 'field_index' ] . '` AS `pod_item_index`, `t`.`' . $table[ 'field_id' ] . '` AS `pod_item_id`';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1292 |
|
| 1293 |
+
if ( !empty( $params->params ) && is_array( $params->params ) ) {
|
| 1294 |
+
$where = $sql[ 'where' ];
|
| 1295 |
|
|
|
|
| 1296 |
$sql = array_merge( $sql, $params->params );
|
| 1297 |
|
| 1298 |
+
if ( isset( $params->params[ 'where' ] ) )
|
| 1299 |
+
$sql[ 'where' ] = array_merge( (array) $where, (array) $params->params['where' ] );
|
|
|
|
|
|
|
| 1300 |
}
|
| 1301 |
|
| 1302 |
+
if ( empty( $related_obj ) ) {
|
| 1303 |
+
if ( !is_object( $this->alt_data ) )
|
|
|
|
|
|
|
| 1304 |
$this->alt_data = pods_data( null, 0, true, true );
|
|
|
|
| 1305 |
|
| 1306 |
$item_data = $this->alt_data->select( $sql );
|
| 1307 |
+
}
|
| 1308 |
+
else
|
| 1309 |
+
$item_data = $related_obj->find( $sql )->data();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1310 |
|
| 1311 |
$items = array();
|
| 1312 |
|
| 1313 |
+
if ( !empty( $item_data ) ) {
|
| 1314 |
foreach ( $item_data as $item ) {
|
| 1315 |
+
if ( is_array( $item ) )
|
| 1316 |
$item = (object) $item;
|
|
|
|
| 1317 |
|
| 1318 |
+
if ( empty( $item->pod_item_id ) )
|
| 1319 |
continue;
|
|
|
|
| 1320 |
|
| 1321 |
+
// Bypass pass field
|
| 1322 |
+
if ( isset( $item->user_pass ) )
|
| 1323 |
unset( $item->user_pass );
|
|
|
|
| 1324 |
|
| 1325 |
+
// Get Item ID
|
| 1326 |
$item_id = $item->pod_item_id;
|
| 1327 |
|
| 1328 |
+
// Output types
|
| 1329 |
+
if ( 'ids' == $params->output )
|
| 1330 |
$item = (int) $item_id;
|
| 1331 |
+
elseif ( 'names' == $params->output && !empty( $table[ 'field_index' ] ) )
|
| 1332 |
$item = $item->pod_item_index;
|
| 1333 |
+
elseif ( 'objects' == $params->output ) {
|
| 1334 |
+
if ( in_array( $object_type, array( 'post_type', 'media' ) ) )
|
| 1335 |
$item = get_post( $item_id );
|
| 1336 |
+
elseif ( 'taxonomy' == $object_type )
|
| 1337 |
$item = get_term( $item_id, $object );
|
| 1338 |
+
elseif ( 'user' == $object_type ) {
|
| 1339 |
$item = get_userdata( $item_id );
|
| 1340 |
|
| 1341 |
+
if ( !empty( $item ) ) {
|
| 1342 |
+
// Get other vars
|
| 1343 |
+
$roles = $item->roles;
|
| 1344 |
+
$caps = $item->caps;
|
| 1345 |
$allcaps = $item->allcaps;
|
| 1346 |
|
| 1347 |
$item = $item->data;
|
| 1348 |
|
| 1349 |
+
// Set other vars
|
| 1350 |
+
$item->roles = $roles;
|
| 1351 |
+
$item->caps = $caps;
|
| 1352 |
$item->allcaps = $allcaps;
|
| 1353 |
|
| 1354 |
unset( $item->user_pass );
|
| 1355 |
}
|
| 1356 |
+
}
|
| 1357 |
+
elseif ( 'comment' == $object_type )
|
| 1358 |
$item = get_comment( $item_id );
|
| 1359 |
+
else
|
| 1360 |
$item = (object) $item;
|
| 1361 |
+
}
|
| 1362 |
+
elseif ( 'pods' == $params->output ) {
|
| 1363 |
+
$item = pods( $object, (int) $item_id );
|
| 1364 |
+
}
|
| 1365 |
+
else // arrays
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1366 |
$item = get_object_vars( (object) $item );
|
|
|
|
| 1367 |
|
| 1368 |
+
// Pass item data into $data
|
| 1369 |
$items[ $item_id ] = $item;
|
| 1370 |
+
}
|
| 1371 |
|
| 1372 |
+
// Cleanup
|
| 1373 |
unset( $item_data );
|
| 1374 |
|
| 1375 |
+
// Return all of the data in the order expected
|
| 1376 |
if ( empty( $params->orderby ) ) {
|
| 1377 |
foreach ( $ids as $id ) {
|
| 1378 |
if ( isset( $items[ $id ] ) ) {
|
| 1380 |
}
|
| 1381 |
}
|
| 1382 |
} else {
|
| 1383 |
+
// Use order set by orderby
|
| 1384 |
foreach ( $items as $id => $v ) {
|
|
|
|
| 1385 |
if ( in_array( $id, $ids ) ) {
|
| 1386 |
$data[ $id ] = $v;
|
| 1387 |
}
|
| 1388 |
}
|
| 1389 |
}
|
| 1390 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1391 |
}
|
| 1392 |
|
| 1393 |
+
if ( in_array( $last_type, $tableless_field_types ) || in_array( $last_type, array( 'boolean', 'number', 'currency' ) ) )
|
| 1394 |
+
$params->raw = true;
|
| 1395 |
+
|
| 1396 |
+
if ( empty( $data ) )
|
| 1397 |
$value = false;
|
| 1398 |
+
else {
|
| 1399 |
+
$object_type = $table[ 'type' ];
|
| 1400 |
|
| 1401 |
+
if ( in_array( $table[ 'type' ], array( 'post_type', 'attachment', 'media' ) ) )
|
| 1402 |
$object_type = 'post';
|
|
|
|
|
|
|
| 1403 |
|
| 1404 |
+
$no_conflict = true;
|
| 1405 |
|
| 1406 |
+
if ( in_array( $object_type, array( 'post', 'user', 'comment', 'settings' ) ) ) {
|
| 1407 |
+
$no_conflict = pods_no_conflict_check( $object_type );
|
| 1408 |
|
| 1409 |
+
if ( !$no_conflict )
|
| 1410 |
+
pods_no_conflict_on( $object_type );
|
|
|
|
| 1411 |
}
|
| 1412 |
|
| 1413 |
+
// Return entire array
|
| 1414 |
+
if ( false !== $field_exists && ( in_array( $last_type, $tableless_field_types ) && !$simple ) )
|
| 1415 |
$value = $data;
|
| 1416 |
+
// Return an array of single column values
|
| 1417 |
+
else {
|
| 1418 |
$value = array();
|
| 1419 |
|
| 1420 |
foreach ( $data as $item_id => $item ) {
|
| 1421 |
// $field is 123x123, needs to be _src.123x123
|
| 1422 |
+
$full_field = implode( '.', array_splice( $params->traverse, $key ) );
|
|
|
|
|
|
|
| 1423 |
|
| 1424 |
+
if ( ( ( false !== strpos( $full_field, '_src' ) || 'guid' == $field ) && ( in_array( $table[ 'type' ], array( 'attachment', 'media' ) ) || in_array( $last_type, PodsForm::file_field_types() ) ) ) || ( in_array( $field, array( '_link', 'detail_url' ) ) || in_array( $field, array( 'permalink', 'the_permalink' ) ) && in_array( $last_type, PodsForm::file_field_types() ) ) ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1425 |
$size = 'full';
|
| 1426 |
|
| 1427 |
+
if ( false !== strpos( $full_field, '_src.' ) && 5 < strlen( $full_field ) )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1428 |
$size = substr( $full_field, 5 );
|
| 1429 |
+
elseif ( false !== strpos( $full_field, '_src_relative.' ) && 14 < strlen( $full_field ) )
|
| 1430 |
$size = substr( $full_field, 14 );
|
| 1431 |
+
elseif ( false !== strpos( $full_field, '_src_schemeless.' ) && 16 < strlen( $full_field ) )
|
| 1432 |
$size = substr( $full_field, 16 );
|
|
|
|
| 1433 |
|
| 1434 |
+
$value_url = pods_image_url( $item_id, $size );
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1435 |
|
| 1436 |
+
if ( false !== strpos( $full_field, '_src_relative' ) && !empty( $value_url ) ) {
|
| 1437 |
+
$value_url_parsed = parse_url( $value_url );
|
| 1438 |
+
$value_url = $value_url_parsed[ 'path' ];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1439 |
}
|
| 1440 |
+
elseif ( false !== strpos( $full_field, '_src_schemeless' ) && !empty( $value_url ) )
|
| 1441 |
+
$value_url = str_replace( array( 'http://', 'https://' ), '//', $value_url );
|
| 1442 |
|
| 1443 |
+
if ( !empty( $value_url ) )
|
| 1444 |
$value[] = $value_url;
|
|
|
|
| 1445 |
|
| 1446 |
$params->raw_display = true;
|
| 1447 |
+
}
|
| 1448 |
+
elseif ( false !== strpos( $full_field, '_img' ) && ( in_array( $table[ 'type' ], array( 'attachment', 'media' ) ) || in_array( $last_type, PodsForm::file_field_types() ) ) ) {
|
|
|
|
|
|
|
| 1449 |
$size = 'full';
|
| 1450 |
|
| 1451 |
+
if ( false !== strpos( $full_field, '_img.' ) && 5 < strlen( $full_field ) )
|
| 1452 |
$size = substr( $full_field, 5 );
|
|
|
|
| 1453 |
|
| 1454 |
+
$value[] = pods_image( $item_id, $size );
|
| 1455 |
|
| 1456 |
$params->raw_display = true;
|
| 1457 |
+
}
|
| 1458 |
+
elseif ( in_array( $field, array( '_link', 'detail_url' ) ) || in_array( $field, array( 'permalink', 'the_permalink' ) ) ) {
|
| 1459 |
+
if ( 'pod' == $object_type ) {
|
|
|
|
|
|
|
| 1460 |
if ( is_object( $related_obj ) ) {
|
| 1461 |
$related_obj->fetch( $item_id );
|
| 1462 |
|
| 1463 |
$value[] = $related_obj->field( 'detail_url' );
|
|
|
|
|
|
|
| 1464 |
}
|
| 1465 |
+
else
|
| 1466 |
+
$value[] = '';
|
| 1467 |
+
}
|
| 1468 |
+
elseif ( 'post' == $object_type )
|
| 1469 |
$value[] = get_permalink( $item_id );
|
| 1470 |
+
elseif ( 'taxonomy' == $object_type )
|
| 1471 |
$value[] = get_term_link( $item_id, $object );
|
| 1472 |
+
elseif ( 'user' == $object_type )
|
| 1473 |
$value[] = get_author_posts_url( $item_id );
|
| 1474 |
+
elseif ( 'comment' == $object_type )
|
| 1475 |
$value[] = get_comment_link( $item_id );
|
| 1476 |
+
else
|
| 1477 |
$value[] = '';
|
|
|
|
| 1478 |
|
| 1479 |
$params->raw_display = true;
|
| 1480 |
+
}
|
| 1481 |
+
elseif ( is_array( $item ) && isset( $item[ $field ] ) ) {
|
| 1482 |
+
if ( $table[ 'field_id' ] == $field )
|
| 1483 |
+
$value[] = (int) $item[ $field ];
|
| 1484 |
+
else
|
| 1485 |
+
$value[] = $item[ $field ];
|
| 1486 |
+
}
|
| 1487 |
+
elseif ( is_object( $item ) && isset( $item->{$field} ) ) {
|
| 1488 |
+
if ( $table[ 'field_id' ] == $field )
|
| 1489 |
+
$value[] = (int) $item->{$field};
|
| 1490 |
+
else
|
| 1491 |
+
$value[] = $item->{$field};
|
| 1492 |
+
}
|
| 1493 |
+
elseif ( 'post' == $object_type ) {
|
| 1494 |
+
// Support for WPML 'duplicated' translation handling
|
| 1495 |
+
if ( is_object( $sitepress ) && $sitepress->is_translated_post_type( $object ) ) {
|
| 1496 |
+
$master_post_id = (int) get_post_meta( $item_id, '_icl_lang_duplicate_of', true );
|
| 1497 |
+
|
| 1498 |
+
if ( 0 < $master_post_id )
|
| 1499 |
+
$item_id = $master_post_id;
|
|
|
|
| 1500 |
}
|
| 1501 |
|
| 1502 |
+
$value[] = get_post_meta( $item_id, $field, true );
|
| 1503 |
+
}
|
| 1504 |
+
elseif ( in_array( $object_type, array( 'post', 'user', 'comment' ) ) )
|
| 1505 |
+
$value[] = get_metadata( $object_type, $item_id, $field, true );
|
| 1506 |
+
elseif ( 'settings' == $object_type )
|
| 1507 |
+
$value[] = get_option( $object . '_' . $field );
|
| 1508 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1509 |
}
|
| 1510 |
|
| 1511 |
+
if ( in_array( $object_type, array( 'post', 'user', 'comment', 'settings' ) ) && !$no_conflict )
|
| 1512 |
+
pods_no_conflict_off( $object_type );
|
| 1513 |
+
|
| 1514 |
+
// Handle Simple Relationships
|
| 1515 |
if ( $simple ) {
|
| 1516 |
+
if ( null === $params->single )
|
| 1517 |
$params->single = false;
|
|
|
|
| 1518 |
|
| 1519 |
$value = PodsForm::field_method( 'pick', 'simple_value', $field, $value, $last_options, $all_fields[ $pod ], 0, true );
|
|
|
|
|
|
|
| 1520 |
}
|
| 1521 |
+
elseif ( false === $params->in_form && !empty( $value ) )
|
| 1522 |
+
$value = array_values( $value );
|
| 1523 |
|
| 1524 |
+
// Return a single column value
|
| 1525 |
+
if ( false === $params->in_form && 1 == $limit && !empty( $value ) && is_array( $value ) && 1 == count( $value ) )
|
| 1526 |
$value = current( $value );
|
| 1527 |
+
}
|
|
|
|
| 1528 |
|
| 1529 |
if ( $last_options ) {
|
| 1530 |
$last_field_data = $last_options;
|
|
|
|
|
|
|
|
|
|
| 1531 |
}
|
| 1532 |
|
| 1533 |
break;
|
| 1534 |
+
}
|
| 1535 |
+
}
|
| 1536 |
+
}
|
| 1537 |
+
}
|
| 1538 |
+
}
|
| 1539 |
|
| 1540 |
+
if ( !empty( $params->traverse ) && 1 < count( $params->traverse ) ) {
|
| 1541 |
$field_names = implode( '.', $params->traverse );
|
| 1542 |
|
| 1543 |
$this->row[ $field_names ] = $value;
|
| 1544 |
+
}
|
| 1545 |
+
elseif ( 'arrays' != $params->output && in_array( $field_data[ 'type' ], $tableless_field_types ) ) {
|
| 1546 |
$this->row[ '_' . $params->output . '_' . $params->full_name ] = $value;
|
| 1547 |
+
}
|
| 1548 |
+
elseif ( 'arrays' == $params->output || !in_array( $field_data[ 'type' ], $tableless_field_types ) ) {
|
| 1549 |
$this->row[ $params->full_name ] = $value;
|
| 1550 |
}
|
| 1551 |
|
| 1552 |
+
if ( $params->single && is_array( $value ) && 1 == count( $value ) )
|
| 1553 |
$value = current( $value );
|
|
|
|
| 1554 |
|
| 1555 |
if ( ! empty( $last_field_data ) ) {
|
| 1556 |
$field_data = $last_field_data;
|
| 1557 |
}
|
| 1558 |
|
| 1559 |
+
// @todo Expand this into traversed fields too
|
| 1560 |
+
if ( !empty( $field_data ) && ( $params->display || !$params->raw ) && !$params->in_form && !$params->raw_display ) {
|
| 1561 |
+
if ( $params->display || ( ( $params->get_meta || $params->deprecated ) && !in_array( $field_data[ 'type' ], $tableless_field_types ) ) ) {
|
| 1562 |
+
$field_data[ 'options' ] = pods_var_raw( 'options', $field_data, array(), null, true );
|
| 1563 |
|
| 1564 |
+
$post_temp = false;
|
|
|
|
|
|
|
|
|
|
| 1565 |
|
| 1566 |
+
if ( 'post_type' == pods_v( 'type', $this->pod_data ) && 0 < $this->id() && ( !isset( $GLOBALS[ 'post' ] ) || empty( $GLOBALS[ 'post' ] ) ) ) {
|
| 1567 |
global $post_ID, $post;
|
| 1568 |
|
| 1569 |
$post_temp = true;
|
| 1570 |
|
| 1571 |
+
$old_post = $GLOBALS[ 'post' ];
|
| 1572 |
+
$old_ID = $GLOBALS[ 'post_ID' ];
|
| 1573 |
|
| 1574 |
+
$post = get_post( $this->id() );
|
|
|
|
|
|
|
| 1575 |
$post_ID = $this->id();
|
| 1576 |
}
|
| 1577 |
|
| 1578 |
+
$filter = pods_var_raw( 'display_filter', $field_data[ 'options' ] );
|
| 1579 |
|
| 1580 |
if ( 0 < strlen( $filter ) ) {
|
| 1581 |
$args = array(
|
| 1582 |
$filter,
|
| 1583 |
+
$value
|
| 1584 |
);
|
| 1585 |
|
| 1586 |
+
$filter_args = pods_var_raw( 'display_filter_args', $field_data[ 'options' ] );
|
| 1587 |
|
| 1588 |
+
if ( !empty( $filter_args ) )
|
| 1589 |
$args = array_merge( $args, compact( $filter_args ) );
|
|
|
|
| 1590 |
|
| 1591 |
$value = call_user_func_array( 'apply_filters', $args );
|
| 1592 |
+
}
|
| 1593 |
+
elseif ( 1 == pods_v( 'display_process', $field_data[ 'options' ], 1 ) ) {
|
| 1594 |
+
$value = PodsForm::display(
|
| 1595 |
+
$field_data[ 'type' ],
|
| 1596 |
+
$value,
|
| 1597 |
+
$params->name,
|
| 1598 |
+
array_merge( $field_data, $field_data[ 'options' ] ),
|
| 1599 |
+
$this->pod_data,
|
| 1600 |
+
$this->id()
|
| 1601 |
+
);
|
| 1602 |
}
|
| 1603 |
|
| 1604 |
if ( $post_temp ) {
|
| 1605 |
+
$post = $old_post;
|
| 1606 |
+
$post_ID = $old_ID;
|
|
|
|
|
|
|
| 1607 |
}
|
| 1608 |
+
}
|
| 1609 |
+
else {
|
| 1610 |
+
$value = PodsForm::value(
|
| 1611 |
+
$field_data[ 'type' ],
|
| 1612 |
+
$value,
|
| 1613 |
+
$params->name,
|
| 1614 |
+
array_merge( $field_data, $field_data[ 'options' ] ),
|
| 1615 |
+
$this->pod_data,
|
| 1616 |
+
$this->id()
|
| 1617 |
+
);
|
| 1618 |
+
}
|
| 1619 |
+
}
|
| 1620 |
|
| 1621 |
/**
|
| 1622 |
* Modify value returned by field() directly before output.
|
| 1625 |
*
|
| 1626 |
* @since unknown
|
| 1627 |
*
|
| 1628 |
+
* @param array|string|null $value Value to be returned.
|
| 1629 |
+
* @param array|object $row Current row being outputted.
|
| 1630 |
+
* @param array $params Params array passed to field().
|
| 1631 |
+
* @param object|Pods $this Current Pods object.
|
| 1632 |
+
*
|
| 1633 |
*/
|
| 1634 |
$value = apply_filters( 'pods_pods_field', $value, $this->row, $params, $this );
|
| 1635 |
|
| 1639 |
/**
|
| 1640 |
* Check if an item field has a specific value in it
|
| 1641 |
*
|
| 1642 |
+
* @param string $field Field name
|
| 1643 |
+
* @param mixed $value Value to check
|
| 1644 |
+
* @param int $id (optional) ID of the pod item to check
|
| 1645 |
*
|
| 1646 |
* @return bool Whether the value was found
|
| 1647 |
*
|
| 1648 |
* @since 2.3.3
|
| 1649 |
*/
|
| 1650 |
+
public function has ( $field, $value, $id = null ) {
|
|
|
|
| 1651 |
$pod =& $this;
|
| 1652 |
|
| 1653 |
+
if ( null === $id )
|
| 1654 |
$id = $this->id();
|
| 1655 |
+
elseif ( $id != $this->id() )
|
|
|
|
| 1656 |
$pod = pods( $this->pod, $id );
|
|
|
|
| 1657 |
|
| 1658 |
$this->do_hook( 'has', $field, $value, $id );
|
| 1659 |
|
| 1660 |
+
if ( !isset( $this->fields[ $field ] ) )
|
| 1661 |
return false;
|
|
|
|
| 1662 |
|
| 1663 |
+
// Tableless fields
|
| 1664 |
+
if ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::tableless_field_types() ) ) {
|
| 1665 |
+
if ( !is_array( $value ) )
|
| 1666 |
$value = explode( ',', $value );
|
|
|
|
| 1667 |
|
| 1668 |
+
if ( 'pick' == $this->fields[ $field ][ 'type' ] && in_array( $this->fields[ $field ][ 'pick_object' ], PodsForm::simple_tableless_objects() ) ) {
|
| 1669 |
$current_value = $pod->raw( $field );
|
| 1670 |
|
| 1671 |
+
if ( !empty( $current_value ) )
|
| 1672 |
$current_value = (array) $current_value;
|
|
|
|
| 1673 |
|
| 1674 |
foreach ( $current_value as $v ) {
|
| 1675 |
+
if ( in_array( $v, $value ) )
|
|
|
|
| 1676 |
return true;
|
|
|
|
| 1677 |
}
|
| 1678 |
+
}
|
| 1679 |
+
else {
|
| 1680 |
+
$related_ids = $this->api->lookup_related_items( $this->fields[ $field ][ 'id' ], $this->pod_data[ 'id' ], $id, $this->fields[ $field ], $this->pod_data );
|
| 1681 |
|
| 1682 |
foreach ( $value as $k => $v ) {
|
| 1683 |
+
if ( !preg_match( '/[^0-9]/', $v ) )
|
| 1684 |
$value[ $k ] = (int) $v;
|
| 1685 |
+
// @todo Convert slugs into IDs
|
| 1686 |
+
else {
|
| 1687 |
|
| 1688 |
+
}
|
| 1689 |
}
|
| 1690 |
|
| 1691 |
foreach ( $related_ids as $v ) {
|
| 1692 |
+
if ( in_array( $v, $value ) )
|
|
|
|
| 1693 |
return true;
|
|
|
|
| 1694 |
}
|
| 1695 |
+
}
|
| 1696 |
+
}
|
| 1697 |
+
// Text fields
|
| 1698 |
+
elseif ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::text_field_types() ) ) {
|
| 1699 |
$current_value = $pod->raw( $field );
|
| 1700 |
|
| 1701 |
+
if ( 0 < strlen( $current_value ) )
|
| 1702 |
return stripos( $current_value, $value );
|
| 1703 |
+
}
|
| 1704 |
+
// All other fields
|
| 1705 |
+
else
|
| 1706 |
return $this->is( $field, $value, $id );
|
|
|
|
| 1707 |
|
| 1708 |
return false;
|
| 1709 |
}
|
| 1711 |
/**
|
| 1712 |
* Check if an item field is a specific value
|
| 1713 |
*
|
| 1714 |
+
* @param string $field Field name
|
| 1715 |
+
* @param mixed $value Value to check
|
| 1716 |
+
* @param int $id (optional) ID of the pod item to check
|
| 1717 |
*
|
| 1718 |
* @return bool Whether the value was found
|
| 1719 |
*
|
| 1720 |
* @since 2.3.3
|
| 1721 |
*/
|
| 1722 |
+
public function is ( $field, $value, $id = null ) {
|
|
|
|
| 1723 |
$pod =& $this;
|
| 1724 |
|
| 1725 |
+
if ( null === $id )
|
| 1726 |
$id = $this->id();
|
| 1727 |
+
elseif ( $id != $this->id() )
|
|
|
|
| 1728 |
$pod = pods( $this->pod, $id );
|
|
|
|
| 1729 |
|
| 1730 |
$this->do_hook( 'is', $field, $value, $id );
|
| 1731 |
|
| 1732 |
+
if ( !isset( $this->fields[ $field ] ) )
|
| 1733 |
return false;
|
|
|
|
| 1734 |
|
| 1735 |
+
// Tableless fields
|
| 1736 |
+
if ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::tableless_field_types() ) ) {
|
| 1737 |
+
if ( !is_array( $value ) )
|
| 1738 |
$value = explode( ',', $value );
|
|
|
|
| 1739 |
|
| 1740 |
$current_value = array();
|
| 1741 |
|
| 1742 |
+
if ( 'pick' == $this->fields[ $field ][ 'type' ] && in_array( $this->fields[ $field ][ 'pick_object' ], PodsForm::simple_tableless_objects() ) ) {
|
| 1743 |
$current_value = $pod->raw( $field );
|
| 1744 |
|
| 1745 |
+
if ( !empty( $current_value ) )
|
| 1746 |
$current_value = (array) $current_value;
|
|
|
|
| 1747 |
|
| 1748 |
foreach ( $current_value as $v ) {
|
| 1749 |
+
if ( in_array( $v, $value ) )
|
|
|
|
| 1750 |
return true;
|
|
|
|
| 1751 |
}
|
| 1752 |
+
}
|
| 1753 |
+
else {
|
| 1754 |
+
$related_ids = $this->api->lookup_related_items( $this->fields[ $field ][ 'id' ], $this->pod_data[ 'id' ], $id, $this->fields[ $field ], $this->pod_data );
|
| 1755 |
|
| 1756 |
foreach ( $value as $k => $v ) {
|
| 1757 |
+
if ( !preg_match( '/[^0-9]/', $v ) )
|
| 1758 |
$value[ $k ] = (int) $v;
|
| 1759 |
+
// @todo Convert slugs into IDs
|
| 1760 |
+
else {
|
| 1761 |
|
| 1762 |
+
}
|
| 1763 |
}
|
| 1764 |
|
| 1765 |
foreach ( $related_ids as $v ) {
|
| 1766 |
+
if ( in_array( $v, $value ) )
|
|
|
|
| 1767 |
return true;
|
|
|
|
| 1768 |
}
|
| 1769 |
+
}
|
| 1770 |
|
| 1771 |
+
if ( !empty( $current_value ) )
|
| 1772 |
$current_value = array_filter( array_unique( $current_value ) );
|
| 1773 |
+
else
|
| 1774 |
$current_value = array();
|
|
|
|
| 1775 |
|
| 1776 |
+
if ( !empty( $value ) )
|
| 1777 |
$value = array_filter( array_unique( $value ) );
|
| 1778 |
+
else
|
| 1779 |
$value = array();
|
|
|
|
| 1780 |
|
| 1781 |
sort( $current_value );
|
| 1782 |
sort( $value );
|
| 1783 |
|
| 1784 |
+
if ( $value === $current_value )
|
| 1785 |
return true;
|
| 1786 |
+
}
|
| 1787 |
+
// Number fields
|
| 1788 |
+
elseif ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::number_field_types() ) ) {
|
| 1789 |
$current_value = $pod->raw( $field );
|
| 1790 |
|
| 1791 |
+
if ( (float) $current_value === (float) $value )
|
| 1792 |
return true;
|
| 1793 |
+
}
|
| 1794 |
+
// Date fields
|
| 1795 |
+
elseif ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::date_field_types() ) ) {
|
| 1796 |
$current_value = $pod->raw( $field );
|
| 1797 |
|
| 1798 |
if ( 0 < strlen( $current_value ) ) {
|
| 1799 |
+
if ( strtotime( $current_value ) == strtotime( $value ) )
|
| 1800 |
return true;
|
|
|
|
|
|
|
|
|
|
| 1801 |
}
|
| 1802 |
+
elseif ( empty( $value ) )
|
| 1803 |
+
return true;
|
| 1804 |
+
}
|
| 1805 |
+
// Text fields
|
| 1806 |
+
elseif ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::text_field_types() ) ) {
|
| 1807 |
$current_value = $pod->raw( $field );
|
| 1808 |
|
| 1809 |
+
if ( (string) $current_value === (string) $value )
|
| 1810 |
return true;
|
| 1811 |
+
}
|
| 1812 |
+
// All other fields
|
| 1813 |
+
else {
|
| 1814 |
$current_value = $pod->raw( $field );
|
| 1815 |
|
| 1816 |
+
if ( $current_value === $value )
|
| 1817 |
return true;
|
| 1818 |
+
}
|
|
|
|
| 1819 |
|
| 1820 |
return false;
|
| 1821 |
}
|
| 1824 |
* Return the item ID
|
| 1825 |
*
|
| 1826 |
* @return int
|
| 1827 |
+
* @since 2.0
|
| 1828 |
*/
|
| 1829 |
+
public function id () {
|
| 1830 |
+
if ( isset( $this->data->row ) && isset( $this->data->row[ 'id' ] ) ) {
|
| 1831 |
+
// If we already have data loaded return that ID
|
| 1832 |
+
return $this->data->row[ 'id' ];
|
|
|
|
| 1833 |
}
|
|
|
|
| 1834 |
return $this->field( $this->data->field_id );
|
| 1835 |
}
|
| 1836 |
|
| 1837 |
/**
|
| 1838 |
* Return the previous item ID, loops at the last id to return the first
|
| 1839 |
*
|
| 1840 |
+
* @param int $id
|
| 1841 |
+
* @param array $params_override
|
| 1842 |
*
|
| 1843 |
* @return int
|
| 1844 |
+
* @since 2.0
|
| 1845 |
*/
|
| 1846 |
+
public function prev_id ( $id = null, $params_override = null ) {
|
| 1847 |
+
if ( null === $id )
|
|
|
|
| 1848 |
$id = $this->id();
|
|
|
|
| 1849 |
|
| 1850 |
$id = (int) $id;
|
| 1851 |
|
| 1852 |
$params = array(
|
| 1853 |
+
'select' => "`t`.`{$this->data->field_id}`",
|
| 1854 |
+
'where' => "`t`.`{$this->data->field_id}` < {$id}",
|
| 1855 |
'orderby' => "`t`.`{$this->data->field_id}` DESC",
|
| 1856 |
+
'limit' => 1
|
| 1857 |
);
|
| 1858 |
|
| 1859 |
+
if ( !empty( $params_override ) || !empty( $this->params ) ) {
|
| 1860 |
+
if ( !empty( $params_override ) )
|
| 1861 |
$params = $params_override;
|
| 1862 |
+
elseif ( !empty( $this->params ) )
|
| 1863 |
$params = $this->params;
|
|
|
|
| 1864 |
|
| 1865 |
if ( is_object( $params ) ) {
|
| 1866 |
$params = get_object_vars( $params );
|
| 1867 |
}
|
| 1868 |
|
| 1869 |
if ( 0 < $id ) {
|
| 1870 |
+
if ( isset( $params[ 'where' ] ) && !empty( $params[ 'where' ] ) ) {
|
| 1871 |
+
$params[ 'where' ] = (array) $params[ 'where' ];
|
| 1872 |
+
$params[ 'where' ][] = "`t`.`{$this->data->field_id}` < {$id}";
|
| 1873 |
+
}
|
| 1874 |
+
else {
|
| 1875 |
+
$params[ 'where' ] = "`t`.`{$this->data->field_id}` < {$id}";
|
| 1876 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1877 |
}
|
| 1878 |
+
elseif ( isset( $params[ 'offset' ] ) && 0 < $params[ 'offset' ] )
|
| 1879 |
+
$params[ 'offset' ] -= 1;
|
| 1880 |
+
elseif ( !isset( $params[ 'offset' ] ) && !empty( $this->params ) && 0 < $this->row_number )
|
| 1881 |
+
$params[ 'offset' ] = $this->row_number - 1;
|
| 1882 |
+
else
|
| 1883 |
+
return 0;
|
| 1884 |
|
| 1885 |
+
if ( isset( $params[ 'orderby' ] ) && !empty( $params[ 'orderby' ] ) ) {
|
| 1886 |
+
if ( is_array( $params[ 'orderby' ] ) ) {
|
| 1887 |
+
foreach ( $params[ 'orderby' ] as $orderby => $dir ) {
|
| 1888 |
$dir = strtoupper( $dir );
|
| 1889 |
|
| 1890 |
+
if ( !in_array( $dir, array( 'ASC', 'DESC' ) ) ) {
|
| 1891 |
continue;
|
| 1892 |
}
|
| 1893 |
|
| 1894 |
+
if ( 'ASC' == $dir ) {
|
| 1895 |
+
$params[ 'orderby' ][ $orderby ] = 'DESC';
|
| 1896 |
+
}
|
| 1897 |
+
else {
|
| 1898 |
+
$params[ 'orderby' ][ $orderby ] = 'ASC';
|
| 1899 |
}
|
| 1900 |
}
|
| 1901 |
|
| 1902 |
+
$params[ 'orderby' ][ $this->data->field_id ] = 'DESC';
|
|
|
|
|
|
|
| 1903 |
}
|
| 1904 |
+
elseif ( "`t`.`{$this->data->field_id}` DESC" != $params[ 'orderby' ] ) {
|
| 1905 |
+
$params[ 'orderby' ] .= ", `t`.`{$this->data->field_id}` DESC";
|
| 1906 |
+
}
|
| 1907 |
+
}
|
| 1908 |
|
| 1909 |
+
$params[ 'select' ] = "`t`.`{$this->data->field_id}`";
|
| 1910 |
+
$params[ 'limit' ] = 1;
|
| 1911 |
+
}
|
| 1912 |
|
| 1913 |
$pod = pods( $this->pod, $params );
|
| 1914 |
|
| 1915 |
$new_id = 0;
|
| 1916 |
|
| 1917 |
+
if ( $pod->fetch() )
|
| 1918 |
$new_id = $pod->id();
|
|
|
|
| 1919 |
|
| 1920 |
$new_id = $this->do_hook( 'prev_id', $new_id, $id, $pod, $params_override );
|
| 1921 |
|
| 1925 |
/**
|
| 1926 |
* Return the next item ID, loops at the first id to return the last
|
| 1927 |
*
|
| 1928 |
+
* @param int $id
|
| 1929 |
+
* @param array $find_params
|
| 1930 |
*
|
| 1931 |
* @return int
|
| 1932 |
+
* @since 2.0
|
| 1933 |
*/
|
| 1934 |
+
public function next_id ( $id = null, $params_override = null ) {
|
| 1935 |
+
if ( null === $id )
|
|
|
|
| 1936 |
$id = $this->id();
|
|
|
|
| 1937 |
|
| 1938 |
$id = (int) $id;
|
| 1939 |
|
| 1940 |
$params = array(
|
| 1941 |
+
'select' => "`t`.`{$this->data->field_id}`",
|
| 1942 |
+
'where' => "{$id} < `t`.`{$this->data->field_id}`",
|
| 1943 |
'orderby' => "`t`.`{$this->data->field_id}` ASC",
|
| 1944 |
+
'limit' => 1
|
| 1945 |
);
|
| 1946 |
|
| 1947 |
+
if ( !empty( $params_override ) || !empty( $this->params ) ) {
|
| 1948 |
+
if ( !empty( $params_override ) )
|
| 1949 |
$params = $params_override;
|
| 1950 |
+
elseif ( !empty( $this->params ) )
|
| 1951 |
$params = $this->params;
|
|
|
|
| 1952 |
|
| 1953 |
if ( is_object( $params ) ) {
|
| 1954 |
$params = get_object_vars( $params );
|
| 1955 |
}
|
| 1956 |
|
| 1957 |
if ( 0 < $id ) {
|
| 1958 |
+
if ( isset( $params[ 'where' ] ) && !empty( $params[ 'where' ] ) ) {
|
| 1959 |
+
$params[ 'where' ] = (array) $params[ 'where' ];
|
| 1960 |
+
$params[ 'where' ][] = "{$id} < `t`.`{$this->data->field_id}`";
|
|
|
|
|
|
|
| 1961 |
}
|
| 1962 |
+
else {
|
| 1963 |
+
$params[ 'where' ] = "{$id} < `t`.`{$this->data->field_id}`";
|
|
|
|
|
|
|
|
|
|
| 1964 |
}
|
|
|
|
|
|
|
| 1965 |
}
|
| 1966 |
+
elseif ( !isset( $params[ 'offset' ] ) ) {
|
| 1967 |
+
if ( !empty( $this->params ) && -1 < $this->row_number )
|
| 1968 |
+
$params[ 'offset' ] = $this->row_number + 1;
|
| 1969 |
+
else
|
| 1970 |
+
$params[ 'offset' ] = 1;
|
| 1971 |
+
}
|
| 1972 |
+
else
|
| 1973 |
+
$params[ 'offset' ] += 1;
|
| 1974 |
|
| 1975 |
+
$params[ 'select' ] = "`t`.`{$this->data->field_id}`";
|
| 1976 |
+
$params[ 'limit' ] = 1;
|
| 1977 |
+
}
|
| 1978 |
|
| 1979 |
$pod = pods( $this->pod, $params );
|
| 1980 |
|
| 1981 |
$new_id = 0;
|
| 1982 |
|
| 1983 |
+
if ( $pod->fetch() )
|
| 1984 |
$new_id = $pod->id();
|
|
|
|
| 1985 |
|
| 1986 |
$new_id = $this->do_hook( 'next_id', $new_id, $id, $pod, $params_override );
|
| 1987 |
|
| 1991 |
/**
|
| 1992 |
* Return the first item ID
|
| 1993 |
*
|
| 1994 |
+
* @param array $params_override
|
| 1995 |
*
|
| 1996 |
* @return int
|
| 1997 |
+
* @since 2.3
|
| 1998 |
*/
|
| 1999 |
+
public function first_id ( $params_override = null ) {
|
|
|
|
| 2000 |
$params = array(
|
| 2001 |
+
'select' => "`t`.`{$this->data->field_id}`",
|
| 2002 |
'orderby' => "`t`.`{$this->data->field_id}` ASC",
|
| 2003 |
+
'limit' => 1
|
| 2004 |
);
|
| 2005 |
|
| 2006 |
+
if ( !empty( $params_override ) || !empty( $this->params ) ) {
|
| 2007 |
+
if ( !empty( $params_override ) )
|
| 2008 |
$params = $params_override;
|
| 2009 |
+
elseif ( !empty( $this->params ) )
|
| 2010 |
$params = $this->params;
|
|
|
|
| 2011 |
|
| 2012 |
if ( is_object( $params ) ) {
|
| 2013 |
$params = get_object_vars( $params );
|
| 2014 |
}
|
| 2015 |
|
| 2016 |
+
$params[ 'select' ] = "`t`.`{$this->data->field_id}`";
|
| 2017 |
+
$params[ 'offset' ] = 0;
|
| 2018 |
+
$params[ 'limit' ] = 1;
|
| 2019 |
}
|
| 2020 |
|
| 2021 |
$pod = pods( $this->pod, $params );
|
| 2022 |
|
| 2023 |
$new_id = 0;
|
| 2024 |
|
| 2025 |
+
if ( $pod->fetch() )
|
| 2026 |
$new_id = $pod->id();
|
|
|
|
| 2027 |
|
| 2028 |
$new_id = $this->do_hook( 'first_id', $new_id, $pod, $params_override );
|
| 2029 |
|
| 2033 |
/**
|
| 2034 |
* Return the last item ID
|
| 2035 |
*
|
| 2036 |
+
* @param array $params_override
|
| 2037 |
*
|
| 2038 |
* @return int
|
| 2039 |
+
* @since 2.3
|
| 2040 |
*/
|
| 2041 |
+
public function last_id ( $params_override = null ) {
|
|
|
|
| 2042 |
$params = array(
|
| 2043 |
+
'select' => "`t`.`{$this->data->field_id}`",
|
| 2044 |
'orderby' => "`t`.`{$this->data->field_id}` DESC",
|
| 2045 |
+
'limit' => 1
|
| 2046 |
);
|
| 2047 |
|
| 2048 |
+
if ( !empty( $params_override ) || !empty( $this->params ) ) {
|
| 2049 |
+
if ( !empty( $params_override ) )
|
| 2050 |
$params = $params_override;
|
| 2051 |
+
elseif ( !empty( $this->params ) )
|
| 2052 |
$params = $this->params;
|
|
|
|
| 2053 |
|
| 2054 |
if ( is_object( $params ) ) {
|
| 2055 |
$params = get_object_vars( $params );
|
| 2056 |
}
|
| 2057 |
|
| 2058 |
+
if ( isset( $params[ 'total_found' ] ) )
|
| 2059 |
+
$params[ 'offset' ] = $params[ 'total_found' ] - 1;
|
| 2060 |
+
else
|
| 2061 |
+
$params[ 'offset' ] = $this->total_found() - 1;
|
|
|
|
| 2062 |
|
| 2063 |
+
if ( isset( $params[ 'orderby' ] ) && !empty( $params[ 'orderby' ] ) ) {
|
| 2064 |
+
if ( is_array( $params[ 'orderby' ] ) ) {
|
| 2065 |
+
foreach ( $params[ 'orderby' ] as $orderby => $dir ) {
|
| 2066 |
$dir = strtoupper( $dir );
|
| 2067 |
|
| 2068 |
+
if ( !in_array( $dir, array( 'ASC', 'DESC' ) ) ) {
|
| 2069 |
continue;
|
| 2070 |
}
|
| 2071 |
|
| 2072 |
+
if ( 'ASC' == $dir ) {
|
| 2073 |
+
$params[ 'orderby' ][ $orderby ] = 'DESC';
|
| 2074 |
+
}
|
| 2075 |
+
else {
|
| 2076 |
+
$params[ 'orderby' ][ $orderby ] = 'ASC';
|
| 2077 |
}
|
| 2078 |
}
|
| 2079 |
|
| 2080 |
+
$params[ 'orderby' ][ $this->data->field_id ] = 'DESC';
|
| 2081 |
+
}
|
| 2082 |
+
elseif ( "`t`.`{$this->data->field_id}` DESC" != $params[ 'orderby' ] ) {
|
| 2083 |
+
$params[ 'orderby' ] .= ", `t`.`{$this->data->field_id}` DESC";
|
| 2084 |
}
|
| 2085 |
+
}
|
| 2086 |
|
| 2087 |
+
$params[ 'select' ] = "`t`.`{$this->data->field_id}`";
|
| 2088 |
+
$params[ 'limit' ] = 1;
|
| 2089 |
+
}
|
| 2090 |
|
| 2091 |
$pod = pods( $this->pod, $params );
|
| 2092 |
|
| 2093 |
$new_id = 0;
|
| 2094 |
|
| 2095 |
+
if ( $pod->fetch() )
|
| 2096 |
$new_id = $pod->id();
|
|
|
|
| 2097 |
|
| 2098 |
$new_id = $this->do_hook( 'last_id', $new_id, $pod, $params_override );
|
|
|
|
| 2099 |
return $new_id;
|
| 2100 |
}
|
| 2101 |
|
| 2103 |
* Return the item name
|
| 2104 |
*
|
| 2105 |
* @return string
|
| 2106 |
+
* @since 2.0
|
| 2107 |
*/
|
| 2108 |
+
public function index () {
|
|
|
|
| 2109 |
return $this->field( $this->data->field_index );
|
| 2110 |
}
|
| 2111 |
|
| 2112 |
/**
|
| 2113 |
* Find items of a pod, much like WP_Query, but with advanced table handling.
|
| 2114 |
*
|
| 2115 |
+
* @param array $params An associative array of parameters
|
| 2116 |
+
* @param int $limit (optional) (deprecated) Limit the number of items to find, use -1 to return all items with no limit
|
| 2117 |
+
* @param string $where (optional) (deprecated) SQL WHERE declaration to use
|
| 2118 |
+
* @param string $sql (optional) (deprecated) For advanced use, a custom SQL query to run
|
| 2119 |
*
|
| 2120 |
* @return \Pods The pod object
|
| 2121 |
+
* @since 2.0
|
| 2122 |
+
* @link http://pods.io/docs/find/
|
| 2123 |
*/
|
| 2124 |
+
public function find ( $params = null, $limit = 15, $where = null, $sql = null ) {
|
| 2125 |
|
| 2126 |
+
$tableless_field_types = PodsForm::tableless_field_types();
|
| 2127 |
$simple_tableless_objects = PodsForm::simple_tableless_objects();
|
| 2128 |
|
| 2129 |
+
|
| 2130 |
$this->params = $params;
|
| 2131 |
|
| 2132 |
$select = '`t`.*';
|
| 2133 |
|
| 2134 |
+
if ( !in_array( $this->pod_data[ 'type' ], array( 'pod', 'table' ) ) && 'table' == $this->pod_data[ 'storage' ] )
|
|
|
|
|
|
|
|
|
|
| 2135 |
$select .= ', `d`.*';
|
|
|
|
| 2136 |
|
| 2137 |
+
if ( empty( $this->data->table ) )
|
| 2138 |
return $this;
|
|
|
|
| 2139 |
|
| 2140 |
$defaults = array(
|
| 2141 |
+
'table' => $this->data->table,
|
| 2142 |
+
'select' => $select,
|
| 2143 |
+
'join' => null,
|
| 2144 |
+
|
| 2145 |
+
'where' => $where,
|
| 2146 |
+
'groupby' => null,
|
| 2147 |
+
'having' => null,
|
| 2148 |
+
'orderby' => null,
|
| 2149 |
+
|
| 2150 |
+
'limit' => (int) $limit,
|
| 2151 |
+
'offset' => null,
|
| 2152 |
+
'page' => (int) $this->page,
|
| 2153 |
+
'page_var' => $this->page_var,
|
| 2154 |
+
'pagination' => (boolean) $this->pagination,
|
| 2155 |
+
|
| 2156 |
+
'search' => (boolean) $this->search,
|
| 2157 |
+
'search_var' => $this->search_var,
|
| 2158 |
+
'search_query' => null,
|
| 2159 |
+
'search_mode' => $this->search_mode,
|
| 2160 |
+
'search_across' => false,
|
|
|
|
| 2161 |
'search_across_picks' => false,
|
| 2162 |
'search_across_files' => false,
|
| 2163 |
+
|
| 2164 |
+
'filters' => $this->filters,
|
| 2165 |
+
'sql' => $sql,
|
| 2166 |
+
|
| 2167 |
+
'expires' => null,
|
| 2168 |
+
'cache_mode' => 'cache'
|
| 2169 |
);
|
| 2170 |
|
| 2171 |
+
if ( is_array( $params ) )
|
| 2172 |
$params = (object) array_merge( $defaults, $params );
|
| 2173 |
+
if ( is_object( $params ) )
|
| 2174 |
$params = (object) array_merge( $defaults, get_object_vars( $params ) );
|
| 2175 |
+
else {
|
| 2176 |
+
$defaults[ 'orderby' ] = $params;
|
|
|
|
| 2177 |
$params = (object) $defaults;
|
| 2178 |
}
|
| 2179 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2180 |
$params = apply_filters( 'pods_pods_find', $params );
|
| 2181 |
|
| 2182 |
$params->limit = (int) $params->limit;
|
| 2183 |
|
| 2184 |
+
if ( 0 == $params->limit )
|
| 2185 |
+
$params->limit = -1;
|
|
|
|
| 2186 |
|
| 2187 |
+
$this->limit = (int) $params->limit;
|
| 2188 |
+
$this->offset = (int) $params->offset;
|
| 2189 |
+
$this->page = (int) $params->page;
|
| 2190 |
+
$this->page_var = $params->page_var;
|
| 2191 |
$this->pagination = (boolean) $params->pagination;
|
| 2192 |
+
$this->search = (boolean) $params->search;
|
| 2193 |
$this->search_var = $params->search_var;
|
| 2194 |
+
$params->join = (array) $params->join;
|
| 2195 |
|
| 2196 |
+
if ( empty( $params->search_query ) )
|
| 2197 |
+
$params->search_query = pods_var( $this->search_var, 'get', '' );
|
|
|
|
| 2198 |
|
| 2199 |
+
// Allow orderby array ( 'field' => 'asc|desc' )
|
| 2200 |
+
if ( !empty( $params->orderby ) && is_array( $params->orderby ) ) {
|
| 2201 |
+
foreach ( $params->orderby as $k => &$orderby ) {
|
| 2202 |
+
if ( !is_numeric( $k ) ) {
|
| 2203 |
$key = '';
|
| 2204 |
|
| 2205 |
$order = 'ASC';
|
| 2206 |
|
| 2207 |
+
if ( 'DESC' == strtoupper( $orderby ) )
|
| 2208 |
$order = 'DESC';
|
|
|
|
| 2209 |
|
| 2210 |
+
if ( isset( $this->fields[ $k ] ) && in_array( $this->fields[ $k ][ 'type' ], $tableless_field_types ) ) {
|
| 2211 |
+
if ( in_array( $this->fields[ $k ][ 'pick_object' ], $simple_tableless_objects ) ) {
|
| 2212 |
+
if ( 'table' == $this->pod_data[ 'storage' ] ) {
|
| 2213 |
+
if ( !in_array( $this->pod_data[ 'type' ], array( 'pod', 'table' ) ) )
|
| 2214 |
$key = "`d`.`{$k}`";
|
| 2215 |
+
else
|
| 2216 |
$key = "`t`.`{$k}`";
|
|
|
|
|
|
|
|
|
|
| 2217 |
}
|
| 2218 |
+
else
|
| 2219 |
+
$key = "`{$k}`.`meta_value`";
|
| 2220 |
+
}
|
| 2221 |
+
else {
|
| 2222 |
+
$pick_val = $this->fields[ $k ][ 'pick_val' ];
|
| 2223 |
|
| 2224 |
+
if ( '__current__' == $pick_val )
|
| 2225 |
$pick_val = $this->pod;
|
|
|
|
| 2226 |
|
| 2227 |
+
$table = $this->api->get_table_info( $this->fields[ $k ][ 'pick_object' ], $pick_val );
|
| 2228 |
|
| 2229 |
+
if ( !empty( $table ) )
|
| 2230 |
+
$key = "`{$k}`.`" . $table[ 'field_index' ] . '`';
|
| 2231 |
+
}
|
| 2232 |
+
}
|
|
|
|
| 2233 |
|
| 2234 |
if ( empty( $key ) ) {
|
| 2235 |
+
if ( !in_array( $this->pod_data[ 'type' ], array( 'pod', 'table' ) ) ) {
|
| 2236 |
+
if ( isset( $this->pod_data[ 'object_fields' ][ $k ] ) )
|
| 2237 |
$key = "`t`.`{$k}`";
|
| 2238 |
+
elseif ( isset( $this->fields[ $k ] ) ) {
|
| 2239 |
+
if ( 'table' == $this->pod_data[ 'storage' ] )
|
| 2240 |
$key = "`d`.`{$k}`";
|
| 2241 |
+
else
|
| 2242 |
$key = "`{$k}`.`meta_value`";
|
| 2243 |
+
}
|
| 2244 |
+
else {
|
| 2245 |
+
foreach ( $this->pod_data[ 'object_fields' ] as $object_field => $object_field_opt ) {
|
| 2246 |
+
if ( $object_field == $k || in_array( $k, $object_field_opt[ 'alias' ] ) )
|
|
|
|
|
|
|
| 2247 |
$key = "`t`.`{$object_field}`";
|
|
|
|
| 2248 |
}
|
| 2249 |
}
|
| 2250 |
+
}
|
| 2251 |
+
elseif ( isset( $this->fields[ $k ] ) ) {
|
| 2252 |
+
if ( 'table' == $this->pod_data[ 'storage' ] )
|
| 2253 |
$key = "`t`.`{$k}`";
|
| 2254 |
+
else
|
| 2255 |
$key = "`{$k}`.`meta_value`";
|
| 2256 |
+
}
|
|
|
|
| 2257 |
|
| 2258 |
if ( empty( $key ) ) {
|
| 2259 |
$key = $k;
|
| 2260 |
|
| 2261 |
+
if ( false === strpos( $key, ' ' ) && false === strpos( $key, '`' ) )
|
| 2262 |
$key = '`' . str_replace( '.', '`.`', $key ) . '`';
|
|
|
|
| 2263 |
}
|
| 2264 |
+
}
|
| 2265 |
|
| 2266 |
$orderby = $key;
|
| 2267 |
|
| 2268 |
+
if ( false === strpos( $orderby, ' ' ) )
|
| 2269 |
$orderby .= ' ' . $order;
|
| 2270 |
+
}
|
| 2271 |
+
}
|
| 2272 |
+
}
|
|
|
|
|
|
|
|
|
|
| 2273 |
|
| 2274 |
+
// Add prefix to $params->orderby if needed
|
| 2275 |
+
if ( !empty( $params->orderby ) ) {
|
| 2276 |
+
if ( !is_array( $params->orderby ) )
|
| 2277 |
$params->orderby = array( $params->orderby );
|
|
|
|
| 2278 |
|
| 2279 |
+
foreach ( $params->orderby as &$prefix_orderby ) {
|
| 2280 |
if ( false === strpos( $prefix_orderby, ',' ) && false === strpos( $prefix_orderby, '(' ) && false === stripos( $prefix_orderby, ' AS ' ) && false === strpos( $prefix_orderby, '`' ) && false === strpos( $prefix_orderby, '.' ) ) {
|
| 2281 |
if ( false !== stripos( $prefix_orderby, ' DESC' ) ) {
|
| 2282 |
+
$k = trim( str_ireplace( array( '`', ' DESC' ), '', $prefix_orderby ) );
|
| 2283 |
$dir = 'DESC';
|
| 2284 |
+
}
|
| 2285 |
+
else {
|
| 2286 |
+
$k = trim( str_ireplace( array( '`', ' ASC' ), '', $prefix_orderby ) );
|
| 2287 |
$dir = 'ASC';
|
| 2288 |
}
|
| 2289 |
|
| 2290 |
$key = $k;
|
| 2291 |
|
| 2292 |
+
if ( !in_array( $this->pod_data[ 'type' ], array( 'pod', 'table' ) ) ) {
|
| 2293 |
+
if ( isset( $this->pod_data[ 'object_fields' ][ $k ] ) )
|
| 2294 |
$key = "`t`.`{$k}`";
|
| 2295 |
+
elseif ( isset( $this->fields[ $k ] ) ) {
|
| 2296 |
+
if ( 'table' == $this->pod_data[ 'storage' ] )
|
| 2297 |
$key = "`d`.`{$k}`";
|
| 2298 |
+
else
|
| 2299 |
$key = "`{$k}`.`meta_value`";
|
| 2300 |
+
}
|
| 2301 |
+
else {
|
| 2302 |
+
foreach ( $this->pod_data[ 'object_fields' ] as $object_field => $object_field_opt ) {
|
| 2303 |
+
if ( $object_field == $k || in_array( $k, $object_field_opt[ 'alias' ] ) )
|
|
|
|
|
|
|
| 2304 |
$key = "`t`.`{$object_field}`";
|
|
|
|
| 2305 |
}
|
| 2306 |
}
|
| 2307 |
+
}
|
| 2308 |
+
elseif ( isset( $this->fields[ $k ] ) ) {
|
| 2309 |
+
if ( 'table' == $this->pod_data[ 'storage' ] )
|
| 2310 |
$key = "`t`.`{$k}`";
|
| 2311 |
+
else
|
| 2312 |
$key = "`{$k}`.`meta_value`";
|
| 2313 |
+
}
|
|
|
|
| 2314 |
|
| 2315 |
$prefix_orderby = "{$key} {$dir}";
|
| 2316 |
+
}
|
| 2317 |
+
}
|
| 2318 |
+
}
|
|
|
|
|
|
|
| 2319 |
|
| 2320 |
$this->data->select( $params );
|
| 2321 |
|
| 2326 |
* Fetch an item from a Pod. If $id is null, it will return the next item in the list after running find().
|
| 2327 |
* You can rewind the list back to the start by using reset().
|
| 2328 |
*
|
| 2329 |
+
* Providing an $id will fetch a specific item from a Pod, much like a call to pods(), and can handle either an id or slug.
|
|
|
|
| 2330 |
*
|
| 2331 |
+
* @see PodsData::fetch
|
| 2332 |
*
|
| 2333 |
+
* @param int $id ID or slug of the item to fetch
|
| 2334 |
+
* @param bool $explicit_set Whether to set explicitly (use false when in loop)
|
| 2335 |
*
|
| 2336 |
* @return array An array of fields from the row
|
| 2337 |
*
|
| 2338 |
+
* @since 2.0
|
| 2339 |
+
* @link http://pods.io/docs/fetch/
|
| 2340 |
*/
|
| 2341 |
+
public function fetch ( $id = null, $explicit_set = true ) {
|
|
|
|
| 2342 |
/**
|
| 2343 |
+
* Runs directly before an item is fetched by fetch()
|
| 2344 |
*
|
| 2345 |
* @since unknown
|
| 2346 |
*
|
| 2347 |
+
* @param int|string|null $id Item ID being fetched or null.
|
| 2348 |
+
* @param object|Pods $this Current Pods object.
|
| 2349 |
*/
|
| 2350 |
do_action( 'pods_pods_fetch', $id, $this );
|
| 2351 |
|
| 2352 |
+
if ( !empty( $id ) )
|
| 2353 |
$this->params = array();
|
|
|
|
| 2354 |
|
| 2355 |
$this->data->fetch( $id, $explicit_set );
|
| 2356 |
|
| 2360 |
/**
|
| 2361 |
* (Re)set the MySQL result pointer
|
| 2362 |
*
|
| 2363 |
+
* @see PodsData::reset
|
| 2364 |
*
|
| 2365 |
+
* @param int $row ID of the row to reset to
|
| 2366 |
*
|
| 2367 |
* @return \Pods The pod object
|
| 2368 |
*
|
| 2369 |
+
* @since 2.0
|
| 2370 |
+
* @link http://pods.io/docs/reset/
|
| 2371 |
*/
|
| 2372 |
+
public function reset ( $row = null ) {
|
|
|
|
| 2373 |
/**
|
| 2374 |
* Runs directly before the Pods object is reset by reset()
|
| 2375 |
*
|
| 2376 |
* @since unknown
|
| 2377 |
*
|
| 2378 |
+
* @param int|string|null The ID of the row being reset to or null if being reset to the beginningg.
|
| 2379 |
* @param object|Pods $this Current Pods object.
|
| 2380 |
*/
|
| 2381 |
do_action( 'pods_pods_reset', $row, $this );
|
| 2390 |
*
|
| 2391 |
* This is different than the total number of rows found in the database, which you can get with total_found().
|
| 2392 |
*
|
| 2393 |
+
* @see PodsData::total
|
| 2394 |
*
|
| 2395 |
* @return int Number of rows returned by find(), based on the 'limit' parameter set
|
| 2396 |
+
* @since 2.0
|
| 2397 |
+
* @link http://pods.io/docs/total/
|
| 2398 |
*/
|
| 2399 |
+
public function total () {
|
|
|
|
| 2400 |
do_action( 'pods_pods_total', $this );
|
| 2401 |
|
| 2402 |
$this->data->total();
|
| 2411 |
*
|
| 2412 |
* This is different than the total number of rows limited by the current call, which you can get with total().
|
| 2413 |
*
|
| 2414 |
+
* @see PodsData::total_found
|
| 2415 |
*
|
| 2416 |
* @return int Number of rows returned by find(), regardless of the 'limit' parameter
|
| 2417 |
+
* @since 2.0
|
| 2418 |
+
* @link http://pods.io/docs/total-found/
|
| 2419 |
*/
|
| 2420 |
+
public function total_found () {
|
|
|
|
| 2421 |
/**
|
| 2422 |
* Runs directly before the value of total_found() is determined and returned.
|
| 2423 |
*
|
| 2424 |
* @since unknown
|
| 2425 |
*
|
| 2426 |
* @param object|Pods $this Current Pods object.
|
| 2427 |
+
*
|
| 2428 |
*/
|
| 2429 |
do_action( 'pods_pods_total_found', $this );
|
| 2430 |
|
| 2438 |
/**
|
| 2439 |
* Fetch the total number of pages, based on total rows found and the last find() limit
|
| 2440 |
*
|
| 2441 |
+
* @param null|int $limit Rows per page
|
| 2442 |
+
* @param null|int $offset Offset of rows
|
| 2443 |
+
* @param null|int $total Total rows
|
| 2444 |
*
|
| 2445 |
* @return int Number of pages
|
| 2446 |
* @since 2.3.10
|
| 2461 |
$total = $this->total_found();
|
| 2462 |
}
|
| 2463 |
|
| 2464 |
+
$total_pages = ceil( ( $total - $offset ) / $limit );
|
| 2465 |
+
|
| 2466 |
+
return $total_pages;
|
| 2467 |
|
| 2468 |
}
|
| 2469 |
|
| 2470 |
/**
|
| 2471 |
* Fetch the zebra switch
|
| 2472 |
*
|
| 2473 |
+
* @see PodsData::zebra
|
| 2474 |
*
|
| 2475 |
* @return bool Zebra state
|
| 2476 |
* @since 1.12
|
| 2477 |
*/
|
| 2478 |
+
public function zebra () {
|
|
|
|
| 2479 |
$this->do_hook( 'zebra' );
|
| 2480 |
|
| 2481 |
return $this->data->zebra();
|
| 2484 |
/**
|
| 2485 |
* Fetch the nth state
|
| 2486 |
*
|
| 2487 |
+
* @see PodsData::nth
|
| 2488 |
*
|
| 2489 |
+
* @param int|string $nth The $nth to match on the PodsData::row_number
|
| 2490 |
*
|
| 2491 |
* @return bool Whether $nth matches
|
| 2492 |
+
* @since 2.3
|
| 2493 |
*/
|
| 2494 |
+
public function nth ( $nth = null ) {
|
|
|
|
| 2495 |
$this->do_hook( 'nth', $nth );
|
| 2496 |
|
| 2497 |
return $this->data->nth( $nth );
|
| 2500 |
/**
|
| 2501 |
* Fetch the current position in the loop (starting at 1)
|
| 2502 |
*
|
| 2503 |
+
* @see PodsData::position
|
| 2504 |
*
|
| 2505 |
* @return int Current row number (+1)
|
| 2506 |
+
* @since 2.3
|
| 2507 |
*/
|
| 2508 |
+
public function position () {
|
|
|
|
| 2509 |
$this->do_hook( 'position' );
|
| 2510 |
|
| 2511 |
return $this->data->position();
|
| 2517 |
*
|
| 2518 |
* You may be looking for save() in most cases where you're setting a specific field.
|
| 2519 |
*
|
| 2520 |
+
* @see PodsAPI::save_pod_item
|
| 2521 |
*
|
| 2522 |
+
* @param array|string $data Either an associative array of field information or a field name
|
| 2523 |
+
* @param mixed $value (optional) Value of the field, if $data is a field name
|
| 2524 |
*
|
| 2525 |
* @return int The item ID
|
| 2526 |
*
|
| 2527 |
+
* @since 2.0
|
| 2528 |
+
* @link http://pods.io/docs/add/
|
| 2529 |
*/
|
| 2530 |
+
public function add ( $data = null, $value = null ) {
|
| 2531 |
+
if ( null !== $value )
|
|
|
|
| 2532 |
$data = array( $data => $value );
|
|
|
|
| 2533 |
|
| 2534 |
$data = (array) $this->do_hook( 'add', $data );
|
| 2535 |
|
| 2536 |
+
if ( empty( $data ) )
|
| 2537 |
return 0;
|
|
|
|
| 2538 |
|
| 2539 |
$params = array(
|
| 2540 |
+
'pod' => $this->pod,
|
| 2541 |
+
'data' => $data,
|
| 2542 |
+
'allow_custom_fields' => true
|
| 2543 |
);
|
| 2544 |
|
| 2545 |
return $this->api->save_pod_item( $params );
|
| 2546 |
}
|
| 2547 |
|
| 2548 |
/**
|
| 2549 |
+
* Add an item to the values of a relationship field, add a value to a number field (field+1), add time to a date field, or add text to a text field
|
|
|
|
| 2550 |
*
|
| 2551 |
+
* @see PodsAPI::save_pod_item
|
| 2552 |
*
|
| 2553 |
+
* @param string $field Field name
|
| 2554 |
+
* @param mixed $value ID(s) to add, int|float to add to number field, string for dates (+1 week), or string for text
|
| 2555 |
+
* @param int $id (optional) ID of the pod item to update
|
| 2556 |
*
|
| 2557 |
* @return int The item ID
|
| 2558 |
*
|
| 2559 |
+
* @since 2.3
|
| 2560 |
*/
|
| 2561 |
+
public function add_to ( $field, $value, $id = null ) {
|
|
|
|
| 2562 |
$pod =& $this;
|
| 2563 |
|
| 2564 |
$fetch = false;
|
| 2566 |
if ( null === $id ) {
|
| 2567 |
$fetch = true;
|
| 2568 |
|
| 2569 |
+
$id = $this->id();
|
|
|
|
|
|
|
|
|
|
| 2570 |
}
|
| 2571 |
+
elseif ( $id != $this->id() )
|
| 2572 |
+
$pod = pods( $this->pod, $id );
|
| 2573 |
|
| 2574 |
$this->do_hook( 'add_to', $field, $value, $id );
|
| 2575 |
|
| 2576 |
+
if ( !isset( $this->fields[ $field ] ) )
|
| 2577 |
return $id;
|
|
|
|
| 2578 |
|
| 2579 |
+
// Tableless fields
|
| 2580 |
+
if ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::tableless_field_types() ) ) {
|
| 2581 |
+
if ( !is_array( $value ) )
|
| 2582 |
$value = explode( ',', $value );
|
|
|
|
| 2583 |
|
| 2584 |
+
if ( 'pick' == $this->fields[ $field ][ 'type' ] && in_array( $this->fields[ $field ][ 'pick_object' ], PodsForm::simple_tableless_objects() ) ) {
|
| 2585 |
$current_value = $pod->raw( $field );
|
| 2586 |
|
| 2587 |
+
if ( !empty( $current_value ) || ( !is_array( $current_value ) && 0 < strlen( $current_value ) ) )
|
| 2588 |
$current_value = (array) $current_value;
|
| 2589 |
+
else
|
| 2590 |
$current_value = array();
|
|
|
|
| 2591 |
|
| 2592 |
$value = array_merge( $current_value, $value );
|
| 2593 |
+
}
|
| 2594 |
+
else {
|
| 2595 |
+
$related_ids = $this->api->lookup_related_items( $this->fields[ $field ][ 'id' ], $this->pod_data[ 'id' ], $id, $this->fields[ $field ], $this->pod_data );
|
| 2596 |
|
| 2597 |
foreach ( $value as $k => $v ) {
|
| 2598 |
+
if ( !preg_match( '/[^0-9]/', $v ) )
|
| 2599 |
$value[ $k ] = (int) $v;
|
|
|
|
| 2600 |
}
|
| 2601 |
|
| 2602 |
$value = array_merge( $related_ids, $value );
|
| 2603 |
+
}
|
| 2604 |
|
| 2605 |
+
if ( !empty( $value ) )
|
| 2606 |
$value = array_filter( array_unique( $value ) );
|
| 2607 |
+
else
|
| 2608 |
$value = array();
|
|
|
|
| 2609 |
|
| 2610 |
+
if ( empty( $value ) )
|
| 2611 |
return $id;
|
| 2612 |
+
}
|
| 2613 |
+
// Number fields
|
| 2614 |
+
elseif ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::number_field_types() ) ) {
|
| 2615 |
$current_value = (float) $pod->raw( $field );
|
| 2616 |
|
| 2617 |
$value = ( $current_value + (float) $value );
|
| 2618 |
+
}
|
| 2619 |
+
// Date fields
|
| 2620 |
+
elseif ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::date_field_types() ) ) {
|
| 2621 |
$current_value = $pod->raw( $field );
|
| 2622 |
|
| 2623 |
+
if ( 0 < strlen( $current_value ) )
|
| 2624 |
$value = strtotime( $value, strtotime( $current_value ) );
|
| 2625 |
+
else
|
| 2626 |
$value = strtotime( $value );
|
| 2627 |
+
}
|
| 2628 |
+
// Text fields
|
| 2629 |
+
elseif ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::text_field_types() ) ) {
|
| 2630 |
$current_value = $pod->raw( $field );
|
| 2631 |
|
| 2632 |
+
if ( 0 < strlen( $current_value ) )
|
| 2633 |
$value = $current_value . $value;
|
| 2634 |
+
}
|
| 2635 |
+
|
| 2636 |
+
// @todo handle object fields and taxonomies
|
| 2637 |
|
|
|
|
| 2638 |
$params = array(
|
| 2639 |
+
'pod' => $this->pod,
|
| 2640 |
+
'id' => $id,
|
| 2641 |
'data' => array(
|
| 2642 |
+
$field => $value
|
| 2643 |
+
)
|
| 2644 |
);
|
| 2645 |
|
| 2646 |
$id = $this->api->save_pod_item( $params );
|
| 2647 |
|
| 2648 |
+
if ( 0 < $id && $fetch )
|
|
|
|
|
|
|
|
|
|
| 2649 |
$pod->fetch( $id, false );
|
|
|
|
| 2650 |
|
| 2651 |
return $id;
|
| 2652 |
}
|
| 2653 |
|
| 2654 |
/**
|
| 2655 |
+
* Remove an item from the values of a relationship field, remove a value from a number field (field-1), remove time to a date field
|
|
|
|
| 2656 |
*
|
| 2657 |
+
* @see PodsAPI::save_pod_item
|
| 2658 |
*
|
| 2659 |
+
* @param string $field Field name
|
| 2660 |
+
* @param mixed $value ID(s) to add, int|float to add to number field, string for dates (-1 week), or string for text
|
| 2661 |
+
* @param int $id (optional) ID of the pod item to update
|
| 2662 |
*
|
| 2663 |
* @return int The item ID
|
| 2664 |
*
|
| 2674 |
$fetch = true;
|
| 2675 |
|
| 2676 |
$id = $this->id();
|
| 2677 |
+
}
|
| 2678 |
+
elseif ( $id != $this->id() ) {
|
| 2679 |
$pod = pods( $this->pod, $id );
|
| 2680 |
}
|
| 2681 |
|
| 2682 |
$this->do_hook( 'remove_from', $field, $value, $id );
|
| 2683 |
|
| 2684 |
+
if ( !isset( $this->fields[ $field ] ) ) {
|
| 2685 |
return $id;
|
| 2686 |
}
|
| 2687 |
|
| 2688 |
+
// Tableless fields
|
| 2689 |
+
if ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::tableless_field_types() ) ) {
|
| 2690 |
if ( empty( $value ) ) {
|
| 2691 |
$value = array();
|
| 2692 |
}
|
| 2693 |
|
| 2694 |
+
if ( !empty( $value ) ) {
|
| 2695 |
+
if ( !is_array( $value ) ) {
|
| 2696 |
$value = explode( ',', $value );
|
| 2697 |
}
|
| 2698 |
|
| 2699 |
+
if ( 'pick' == $this->fields[ $field ][ 'type' ] && in_array( $this->fields[ $field ][ 'pick_object' ], PodsForm::simple_tableless_objects() ) ) {
|
| 2700 |
$current_value = $pod->raw( $field );
|
| 2701 |
|
| 2702 |
+
if ( !empty( $current_value ) ) {
|
| 2703 |
$current_value = (array) $current_value;
|
| 2704 |
}
|
| 2705 |
|
| 2706 |
foreach ( $current_value as $k => $v ) {
|
|
|
|
| 2707 |
if ( in_array( $v, $value ) ) {
|
| 2708 |
unset( $current_value[ $k ] );
|
| 2709 |
}
|
| 2710 |
}
|
| 2711 |
|
| 2712 |
$value = $current_value;
|
| 2713 |
+
}
|
| 2714 |
+
else {
|
| 2715 |
+
$related_ids = $this->api->lookup_related_items( $this->fields[ $field ][ 'id' ], $this->pod_data[ 'id' ], $id, $this->fields[ $field ], $this->pod_data );
|
| 2716 |
|
| 2717 |
foreach ( $value as $k => $v ) {
|
| 2718 |
+
if ( !preg_match( '/[^0-9]/', $v ) ) {
|
| 2719 |
$value[ $k ] = (int) $v;
|
| 2720 |
}
|
| 2721 |
+
// @todo Convert slugs into IDs
|
| 2722 |
+
else {
|
| 2723 |
|
| 2724 |
+
}
|
| 2725 |
}
|
| 2726 |
|
| 2727 |
foreach ( $related_ids as $k => $v ) {
|
|
|
|
| 2728 |
if ( in_array( $v, $value ) ) {
|
| 2729 |
unset( $related_ids[ $k ] );
|
| 2730 |
}
|
| 2731 |
}
|
| 2732 |
|
| 2733 |
$value = $related_ids;
|
| 2734 |
+
}
|
| 2735 |
|
| 2736 |
+
if ( !empty( $value ) ) {
|
| 2737 |
$value = array_filter( array_unique( $value ) );
|
| 2738 |
+
}
|
| 2739 |
+
else {
|
| 2740 |
$value = array();
|
| 2741 |
}
|
| 2742 |
+
}
|
| 2743 |
+
}
|
| 2744 |
+
// Number fields
|
| 2745 |
+
elseif ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::number_field_types() ) ) {
|
| 2746 |
+
// Date fields don't support empty for removing
|
| 2747 |
if ( empty( $value ) ) {
|
| 2748 |
return $id;
|
| 2749 |
}
|
| 2751 |
$current_value = (float) $pod->raw( $field );
|
| 2752 |
|
| 2753 |
$value = ( $current_value - (float) $value );
|
| 2754 |
+
}
|
| 2755 |
+
// Date fields
|
| 2756 |
+
elseif ( in_array( $this->fields[ $field ][ 'type' ], PodsForm::date_field_types() ) ) {
|
| 2757 |
+
// Date fields don't support empty for removing
|
| 2758 |
if ( empty( $value ) ) {
|
| 2759 |
return $id;
|
| 2760 |
}
|
| 2763 |
|
| 2764 |
if ( 0 < strlen( $current_value ) ) {
|
| 2765 |
$value = strtotime( $value, strtotime( $current_value ) );
|
| 2766 |
+
}
|
| 2767 |
+
else {
|
| 2768 |
$value = strtotime( $value );
|
| 2769 |
}
|
| 2770 |
|
| 2771 |
$value = date_i18n( 'Y-m-d h:i:s', $value );
|
| 2772 |
+
}
|
| 2773 |
+
|
| 2774 |
+
// @todo handle object fields and taxonomies
|
| 2775 |
|
|
|
|
| 2776 |
$params = array(
|
| 2777 |
+
'pod' => $this->pod,
|
| 2778 |
+
'id' => $id,
|
| 2779 |
'data' => array(
|
| 2780 |
+
$field => $value
|
| 2781 |
+
)
|
| 2782 |
);
|
| 2783 |
|
| 2784 |
$id = $this->api->save_pod_item( $params );
|
| 2785 |
|
| 2786 |
if ( 0 < $id && $fetch ) {
|
|
|
|
|
|
|
|
|
|
| 2787 |
$pod->fetch( $id, false );
|
| 2788 |
}
|
| 2789 |
|
| 2797 |
* Though this function has the capacity to add new items, best practice should direct you
|
| 2798 |
* to use add() for that instead.
|
| 2799 |
*
|
| 2800 |
+
* @see PodsAPI::save_pod_item
|
| 2801 |
*
|
| 2802 |
+
* @param array|string $data Either an associative array of field information or a field name
|
| 2803 |
+
* @param mixed $value (optional) Value of the field, if $data is a field name
|
| 2804 |
+
* @param int $id (optional) ID of the pod item to update
|
| 2805 |
+
* @param array $params (optional) Additional params to send to save_pod_item
|
| 2806 |
*
|
| 2807 |
* @return int The item ID
|
| 2808 |
*
|
| 2809 |
+
* @since 2.0
|
| 2810 |
+
* @link http://pods.io/docs/save/
|
| 2811 |
*/
|
| 2812 |
+
public function save ( $data = null, $value = null, $id = null, $params = null ) {
|
| 2813 |
+
if ( null !== $value )
|
|
|
|
| 2814 |
$data = array( $data => $value );
|
|
|
|
| 2815 |
|
| 2816 |
$fetch = false;
|
| 2817 |
|
|
|
|
| 2818 |
if ( null === $id || ( $this->row && $id == $this->id() ) ) {
|
| 2819 |
$fetch = true;
|
| 2820 |
|
| 2825 |
|
| 2826 |
$data = (array) $this->do_hook( 'save', $data, $id );
|
| 2827 |
|
| 2828 |
+
if ( empty( $data ) )
|
| 2829 |
return $id;
|
|
|
|
| 2830 |
|
| 2831 |
$default = array();
|
| 2832 |
|
| 2833 |
+
if ( !empty( $params ) && is_array( $params ) )
|
| 2834 |
$default = $params;
|
|
|
|
| 2835 |
|
| 2836 |
$params = array(
|
| 2837 |
+
'pod' => $this->pod,
|
| 2838 |
+
'id' => $id,
|
| 2839 |
+
'data' => $data,
|
| 2840 |
'allow_custom_fields' => true,
|
| 2841 |
+
'clear_slug_cache' => false
|
| 2842 |
);
|
| 2843 |
|
| 2844 |
+
if ( !empty( $default ) )
|
| 2845 |
$params = array_merge( $params, $default );
|
|
|
|
| 2846 |
|
| 2847 |
$id = $this->api->save_pod_item( $params );
|
| 2848 |
|
| 2849 |
+
if ( 0 < $id && $fetch )
|
|
|
|
|
|
|
|
|
|
| 2850 |
$this->fetch( $id, false );
|
|
|
|
| 2851 |
|
| 2852 |
+
if ( !empty( $this->pod_data[ 'field_slug' ] ) ) {
|
| 2853 |
if ( 0 < $id && $fetch ) {
|
| 2854 |
+
$slug = $this->field( $this->pod_data[ 'field_slug' ] );
|
| 2855 |
+
}
|
| 2856 |
+
else {
|
| 2857 |
+
$slug = pods( $this->pod, $id )->field( $this->pod_data[ 'field_slug' ] );
|
| 2858 |
}
|
| 2859 |
|
| 2860 |
if ( 0 < strlen( $slug ) ) {
|
| 2868 |
/**
|
| 2869 |
* Delete an item
|
| 2870 |
*
|
| 2871 |
+
* @see PodsAPI::delete_pod_item
|
| 2872 |
*
|
| 2873 |
+
* @param int $id ID of the Pod item to delete
|
| 2874 |
*
|
| 2875 |
* @return bool Whether the item was successfully deleted
|
| 2876 |
*
|
| 2877 |
+
* @since 2.0
|
| 2878 |
+
* @link http://pods.io/docs/delete/
|
| 2879 |
*/
|
| 2880 |
+
public function delete ( $id = null ) {
|
| 2881 |
+
if ( null === $id )
|
|
|
|
| 2882 |
$id = $this->id();
|
|
|
|
| 2883 |
|
| 2884 |
$id = (int) $this->do_hook( 'delete', $id );
|
| 2885 |
|
| 2886 |
+
if ( empty( $id ) )
|
| 2887 |
return false;
|
|
|
|
| 2888 |
|
| 2889 |
$params = array(
|
| 2890 |
'pod' => $this->pod,
|
| 2891 |
+
'id' => $id
|
| 2892 |
);
|
| 2893 |
|
| 2894 |
return $this->api->delete_pod_item( $params );
|
| 2897 |
/**
|
| 2898 |
* Reset Pod
|
| 2899 |
*
|
| 2900 |
+
* @see PodsAPI::reset_pod
|
| 2901 |
*
|
| 2902 |
* @return bool Whether the Pod was successfully reset
|
| 2903 |
*
|
| 2904 |
* @since 2.1.1
|
| 2905 |
*/
|
| 2906 |
+
public function reset_pod () {
|
|
|
|
| 2907 |
$params = array( 'id' => $this->pod_id );
|
| 2908 |
|
| 2909 |
+
$this->data->id = null;
|
| 2910 |
+
$this->data->row = array();
|
| 2911 |
$this->data->data = array();
|
| 2912 |
|
| 2913 |
+
$this->data->total = 0;
|
| 2914 |
$this->data->total_found = 0;
|
| 2915 |
|
| 2916 |
return $this->api->reset_pod( $params );
|
| 2919 |
/**
|
| 2920 |
* Duplicate an item
|
| 2921 |
*
|
| 2922 |
+
* @see PodsAPI::duplicate_pod_item
|
| 2923 |
*
|
| 2924 |
+
* @param int $id ID of the pod item to duplicate
|
| 2925 |
*
|
| 2926 |
* @return int|bool ID of the new pod item
|
| 2927 |
*
|
| 2928 |
+
* @since 2.0
|
| 2929 |
+
* @link http://pods.io/docs/duplicate/
|
| 2930 |
*/
|
| 2931 |
+
public function duplicate ( $id = null ) {
|
| 2932 |
+
if ( null === $id )
|
|
|
|
| 2933 |
$id = $this->id();
|
|
|
|
| 2934 |
|
| 2935 |
$id = (int) $this->do_hook( 'duplicate', $id );
|
| 2936 |
|
| 2937 |
+
if ( empty( $id ) )
|
| 2938 |
return false;
|
|
|
|
| 2939 |
|
| 2940 |
$params = array(
|
| 2941 |
'pod' => $this->pod,
|
| 2942 |
+
'id' => $id
|
| 2943 |
);
|
| 2944 |
|
| 2945 |
return $this->api->duplicate_pod_item( $params );
|
| 2948 |
/**
|
| 2949 |
* Import data / Save multiple rows of data at once
|
| 2950 |
*
|
| 2951 |
+
* @see PodsAPI::import
|
| 2952 |
*
|
| 2953 |
+
* @param mixed $import_data PHP associative array or CSV input
|
| 2954 |
+
* @param bool $numeric_mode Use IDs instead of the name field when matching
|
| 2955 |
+
* @param string $format Format of import data, options are php or csv
|
| 2956 |
*
|
| 2957 |
* @return array IDs of imported items
|
| 2958 |
*
|
| 2959 |
+
* @since 2.3
|
| 2960 |
*/
|
| 2961 |
+
public function import ( $import_data, $numeric_mode = false, $format = null ) {
|
|
|
|
| 2962 |
return $this->api->import( $import_data, $numeric_mode, $format );
|
| 2963 |
}
|
| 2964 |
|
| 2965 |
/**
|
| 2966 |
* Export an item's data
|
| 2967 |
*
|
| 2968 |
+
* @see PodsAPI::export_pod_item
|
| 2969 |
*
|
| 2970 |
+
* @param array $fields (optional) Fields to export
|
| 2971 |
+
* @param int $id (optional) ID of the pod item to export
|
|
|
|
| 2972 |
*
|
| 2973 |
* @return array|bool Data array of the exported pod item
|
| 2974 |
*
|
| 2975 |
+
* @since 2.0
|
| 2976 |
+
* @link http://pods.io/docs/export/
|
| 2977 |
*/
|
| 2978 |
+
public function export ( $fields = null, $id = null, $format = null ) {
|
|
|
|
| 2979 |
$params = array(
|
| 2980 |
+
'pod' => $this->pod,
|
| 2981 |
+
'id' => $id,
|
| 2982 |
+
'fields' => null,
|
| 2983 |
+
'depth' => 2,
|
| 2984 |
+
'flatten' => false
|
|
|
|
|
|
|
| 2985 |
);
|
| 2986 |
|
| 2987 |
+
if ( is_array( $fields ) && ( isset( $fields[ 'fields' ] ) || isset( $fields[ 'depth' ] ) ) )
|
| 2988 |
$params = array_merge( $params, $fields );
|
| 2989 |
+
else
|
| 2990 |
+
$params[ 'fields' ] = $fields;
|
|
|
|
| 2991 |
|
| 2992 |
+
if ( isset( $params[ 'fields' ] ) && is_array( $params[ 'fields' ] ) && !in_array( $this->pod_data[ 'field_id' ], $params[ 'fields' ] ) )
|
| 2993 |
+
$params[ 'fields' ] = array_merge( array( $this->pod_data[ 'field_id' ] ), $params[ 'fields' ] );
|
|
|
|
| 2994 |
|
| 2995 |
+
if ( null === $params[ 'id' ] )
|
| 2996 |
+
$params[ 'id' ] = $this->id();
|
|
|
|
| 2997 |
|
| 2998 |
$params = (array) $this->do_hook( 'export', $params );
|
| 2999 |
|
| 3000 |
+
if ( empty( $params[ 'id' ] ) )
|
| 3001 |
return false;
|
|
|
|
| 3002 |
|
| 3003 |
$data = $this->api->export_pod_item( $params );
|
| 3004 |
|
| 3005 |
+
if ( !empty( $format ) ) {
|
| 3006 |
+
if ( 'json' == $format )
|
| 3007 |
+
$data = json_encode( (array) $data );
|
| 3008 |
+
// @todo more formats
|
| 3009 |
}
|
| 3010 |
|
| 3011 |
return $data;
|
| 3014 |
/**
|
| 3015 |
* Export data from all items
|
| 3016 |
*
|
| 3017 |
+
* @see PodsAPI::export
|
| 3018 |
*
|
| 3019 |
+
* @param array $params An associative array of parameters
|
| 3020 |
*
|
| 3021 |
* @return array Data arrays of all exported pod items
|
| 3022 |
*
|
| 3023 |
+
* @since 2.3
|
| 3024 |
*/
|
| 3025 |
+
public function export_data ( $params = null ) {
|
|
|
|
| 3026 |
$defaults = array(
|
| 3027 |
'fields' => null,
|
| 3028 |
+
'depth' => 2,
|
| 3029 |
+
'params' => null
|
| 3030 |
);
|
| 3031 |
|
| 3032 |
+
if ( empty( $params ) )
|
| 3033 |
$params = $defaults;
|
| 3034 |
+
else
|
| 3035 |
$params = array_merge( $defaults, (array) $params );
|
|
|
|
| 3036 |
|
| 3037 |
return $this->api->export( $this, $params );
|
| 3038 |
}
|
| 3042 |
* are simple, paginate and advanced. The base and format parameters
|
| 3043 |
* are used only for the paginate view.
|
| 3044 |
*
|
| 3045 |
+
* @var array $params Associative array of parameters
|
| 3046 |
*
|
| 3047 |
* @return string Pagination HTML
|
| 3048 |
+
* @since 2.0
|
| 3049 |
+
* @link http://pods.io/docs/pagination/
|
| 3050 |
*/
|
| 3051 |
public function pagination( $params = null ) {
|
| 3052 |
|
| 3053 |
if ( empty( $params ) ) {
|
| 3054 |
$params = array();
|
| 3055 |
+
}
|
| 3056 |
+
elseif ( !is_array( $params ) ) {
|
| 3057 |
$params = array( 'label' => $params );
|
| 3058 |
}
|
| 3059 |
|
| 3060 |
+
$this->page_var = pods_var_raw( 'page_var', $params, $this->page_var );
|
| 3061 |
|
| 3062 |
$url = pods_query_arg( null, null, $this->page_var );
|
| 3063 |
|
| 3068 |
}
|
| 3069 |
|
| 3070 |
$defaults = array(
|
| 3071 |
+
'type' => 'advanced',
|
| 3072 |
+
'label' => __( 'Go to page:', 'pods' ),
|
| 3073 |
+
'show_label' => true,
|
| 3074 |
+
'first_text' => __( '« First', 'pods' ),
|
| 3075 |
+
'prev_text' => __( '‹ Previous', 'pods' ),
|
| 3076 |
+
'next_text' => __( 'Next ›', 'pods' ),
|
| 3077 |
+
'last_text' => __( 'Last »', 'pods' ),
|
| 3078 |
+
'prev_next' => true,
|
| 3079 |
+
'first_last' => true,
|
| 3080 |
+
'limit' => (int) $this->limit,
|
| 3081 |
+
'offset' => (int) $this->offset,
|
| 3082 |
+
'page' => max( 1, (int) $this->page ),
|
| 3083 |
+
'mid_size' => 2,
|
| 3084 |
+
'end_size' => 1,
|
| 3085 |
'total_found' => $this->total_found(),
|
| 3086 |
+
'page_var' => $this->page_var,
|
| 3087 |
+
'base' => "{$url}{$append}%_%",
|
| 3088 |
+
'format' => "{$this->page_var}=%#%",
|
| 3089 |
+
'class' => '',
|
| 3090 |
+
'link_class' => ''
|
| 3091 |
);
|
| 3092 |
|
| 3093 |
+
$params = (object) array_merge( $defaults, $params );
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3094 |
|
| 3095 |
$params->total = $this->total_pages( $params->limit, $params->offset, $params->total_found );
|
| 3096 |
|
| 3097 |
+
if ( $params->limit < 1 || $params->total_found < 1 || 1 == $params->total || $params->total_found <= $params->offset ) {
|
| 3098 |
return $this->do_hook( 'pagination', $this->do_hook( 'pagination_' . $params->type, '', $params ), $params );
|
| 3099 |
}
|
| 3100 |
|
| 3101 |
$pagination = $params->type;
|
| 3102 |
|
| 3103 |
+
if ( !in_array( $params->type, array( 'simple', 'advanced', 'paginate', 'list' ) ) ) {
|
| 3104 |
$pagination = 'advanced';
|
| 3105 |
}
|
| 3106 |
|
| 3117 |
/**
|
| 3118 |
* Return a filter form for searching a Pod
|
| 3119 |
*
|
| 3120 |
+
* @var array|string $params Comma-separated list of fields or array of parameters
|
| 3121 |
*
|
| 3122 |
* @return string Filters HTML
|
| 3123 |
*
|
| 3124 |
+
* @since 2.0
|
| 3125 |
+
* @link http://pods.io/docs/filters/
|
| 3126 |
*/
|
| 3127 |
+
public function filters ( $params = null ) {
|
|
|
|
| 3128 |
$defaults = array(
|
| 3129 |
'fields' => $params,
|
| 3130 |
+
'label' => '',
|
| 3131 |
'action' => '',
|
| 3132 |
+
'search' => ''
|
| 3133 |
);
|
| 3134 |
|
| 3135 |
+
if ( is_array( $params ) )
|
| 3136 |
$params = array_merge( $defaults, $params );
|
| 3137 |
+
else
|
| 3138 |
$params = $defaults;
|
|
|
|
| 3139 |
|
| 3140 |
$pod =& $this;
|
| 3141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3142 |
$params = apply_filters( 'pods_filters_params', $params, $pod );
|
| 3143 |
|
| 3144 |
+
$fields = $params[ 'fields' ];
|
| 3145 |
|
| 3146 |
+
if ( null !== $fields && !is_array( $fields ) && 0 < strlen( $fields ) )
|
| 3147 |
$fields = explode( ',', $fields );
|
|
|
|
| 3148 |
|
| 3149 |
+
$object_fields = (array) pods_var_raw( 'object_fields', $this->pod_data, array(), null, true );
|
| 3150 |
|
| 3151 |
+
// Force array
|
| 3152 |
+
if ( empty( $fields ) )
|
| 3153 |
$fields = array();
|
| 3154 |
+
else {
|
| 3155 |
+
$filter_fields = $fields; // Temporary
|
|
|
|
| 3156 |
|
| 3157 |
$fields = array();
|
| 3158 |
|
| 3160 |
$name = $k;
|
| 3161 |
|
| 3162 |
$defaults = array(
|
| 3163 |
+
'name' => $name
|
| 3164 |
);
|
| 3165 |
|
| 3166 |
+
if ( !is_array( $field ) ) {
|
| 3167 |
$name = $field;
|
| 3168 |
|
| 3169 |
$field = array(
|
| 3170 |
+
'name' => $name
|
| 3171 |
);
|
| 3172 |
}
|
| 3173 |
|
|
|
|
| 3174 |
$field = array_merge( $defaults, $field );
|
| 3175 |
|
| 3176 |
+
$field[ 'name' ] = trim( $field[ 'name' ] );
|
| 3177 |
|
| 3178 |
+
if ( pods_var_raw( 'hidden', $field, false, null, true ) )
|
| 3179 |
+
$field[ 'type' ] = 'hidden';
|
|
|
|
| 3180 |
|
| 3181 |
+
if ( isset( $object_fields[ $field[ 'name' ] ] ) )
|
| 3182 |
+
$fields[ $field[ 'name' ] ] = array_merge( $object_fields[ $field[ 'name' ] ], $field );
|
| 3183 |
+
elseif ( isset( $this->fields[ $field[ 'name' ] ] ) )
|
| 3184 |
+
$fields[ $field[ 'name' ] ] = array_merge( $this->fields[ $field[ 'name' ] ], $field );
|
| 3185 |
+
}
|
|
|
|
|
|
|
|
|
|
| 3186 |
|
| 3187 |
+
unset( $filter_fields ); // Cleanup
|
| 3188 |
+
}
|
|
|
|
| 3189 |
|
| 3190 |
$this->filters = array_keys( $fields );
|
| 3191 |
|
| 3192 |
+
$label = $params[ 'label' ];
|
| 3193 |
|
| 3194 |
+
if ( strlen( $label ) < 1 )
|
| 3195 |
$label = __( 'Search', 'pods' );
|
|
|
|
| 3196 |
|
| 3197 |
+
$action = $params[ 'action' ];
|
| 3198 |
|
| 3199 |
+
$search = trim( $params[ 'search' ] );
|
| 3200 |
|
| 3201 |
+
if ( strlen( $search ) < 1 )
|
| 3202 |
+
$search = pods_var_raw( $pod->search_var, 'get', '' );
|
|
|
|
| 3203 |
|
| 3204 |
ob_start();
|
| 3205 |
|
| 3212 |
*
|
| 3213 |
* @since unknown
|
| 3214 |
*
|
| 3215 |
+
* @param string $output
|
| 3216 |
+
* @param array $params Params array passed to filters().
|
| 3217 |
+
* @param object|Pods $this Current Pods object.
|
| 3218 |
*/
|
| 3219 |
return apply_filters( 'pods_pods_filters', $output, $params, $this );
|
| 3220 |
}
|
| 3222 |
/**
|
| 3223 |
* Run a helper within a Pod Page or WP Template
|
| 3224 |
*
|
| 3225 |
+
* @see Pods_Helpers::helper
|
| 3226 |
*
|
| 3227 |
+
* @param string $helper Helper name
|
| 3228 |
+
* @param string $value Value to run the helper on
|
| 3229 |
+
* @param string $name Field name
|
| 3230 |
*
|
| 3231 |
* @return mixed Anything returned by the helper
|
| 3232 |
+
* @since 2.0
|
| 3233 |
*/
|
| 3234 |
+
public function helper ( $helper, $value = null, $name = null ) {
|
|
|
|
| 3235 |
$params = array(
|
| 3236 |
+
'helper' => $helper,
|
| 3237 |
+
'value' => $value,
|
| 3238 |
+
'name' => $name,
|
| 3239 |
+
'deprecated' => false
|
| 3240 |
);
|
| 3241 |
|
| 3242 |
+
if ( class_exists( 'Pods_Templates' ) )
|
| 3243 |
+
$params[ 'deprecated' ] = Pods_Templates::$deprecated;
|
|
|
|
| 3244 |
|
| 3245 |
+
if ( is_array( $helper ) )
|
| 3246 |
$params = array_merge( $params, $helper );
|
|
|
|
| 3247 |
|
| 3248 |
+
if ( class_exists( 'Pods_Helpers' ) )
|
| 3249 |
$value = Pods_Helpers::helper( $params, $this );
|
| 3250 |
+
elseif ( function_exists( $params[ 'helper' ] ) )
|
| 3251 |
+
$value = call_user_func( $params[ 'helper' ], $value );
|
| 3252 |
+
else
|
| 3253 |
+
$value = apply_filters( $params[ 'helper' ], $value );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3254 |
|
| 3255 |
return $value;
|
| 3256 |
}
|
| 3258 |
/**
|
| 3259 |
* Display the page template
|
| 3260 |
*
|
| 3261 |
+
* @see Pods_Templates::template
|
| 3262 |
*
|
| 3263 |
+
* @param string $template The template name
|
| 3264 |
+
* @param string $code Custom template code to use instead
|
| 3265 |
+
* @param bool $deprecated Whether to use deprecated functionality based on old function usage
|
| 3266 |
*
|
| 3267 |
* @return mixed Template output
|
| 3268 |
*
|
| 3269 |
+
* @since 2.0
|
| 3270 |
+
* @link http://pods.io/docs/template/
|
| 3271 |
*/
|
| 3272 |
+
public function template ( $template_name, $code = null, $deprecated = false ) {
|
|
|
|
| 3273 |
$out = null;
|
| 3274 |
|
| 3275 |
$obj =& $this;
|
| 3276 |
|
| 3277 |
+
if ( !empty( $code ) ) {
|
| 3278 |
+
$code = str_replace( '$this->', '$obj->', $code ); // backwards compatibility
|
|
|
|
| 3279 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3280 |
$code = apply_filters( 'pods_templates_pre_template', $code, $template_name, $this );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3281 |
$code = apply_filters( "pods_templates_pre_template_{$template_name}", $code, $template_name, $this );
|
| 3282 |
|
| 3283 |
ob_start();
|
| 3284 |
|
| 3285 |
+
if ( !empty( $code ) ) {
|
| 3286 |
+
// Only detail templates need $this->id
|
| 3287 |
if ( empty( $this->id ) ) {
|
| 3288 |
while ( $this->fetch() ) {
|
|
|
|
| 3289 |
echo $this->do_magic_tags( $code );
|
| 3290 |
}
|
|
|
|
|
|
|
|
|
|
| 3291 |
}
|
| 3292 |
+
else
|
| 3293 |
+
echo $this->do_magic_tags( $code );
|
| 3294 |
}
|
| 3295 |
|
| 3296 |
$out = ob_get_clean();
|
| 3297 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3298 |
$out = apply_filters( 'pods_templates_post_template', $out, $code, $template_name, $this );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3299 |
$out = apply_filters( "pods_templates_post_template_{$template_name}", $out, $code, $template_name, $this );
|
| 3300 |
+
}
|
| 3301 |
+
elseif ( class_exists( 'Pods_Templates' ) )
|
| 3302 |
$out = Pods_Templates::template( $template_name, $code, $this, $deprecated );
|
| 3303 |
+
elseif ( $template_name == trim( preg_replace( '/[^a-zA-Z0-9_\-\/]/', '', $template_name ), ' /-' ) ) {
|
| 3304 |
ob_start();
|
| 3305 |
|
| 3306 |
$default_templates = array(
|
| 3307 |
'pods/' . $template_name,
|
| 3308 |
'pods-' . $template_name,
|
| 3309 |
+
$template_name
|
| 3310 |
);
|
| 3311 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3312 |
$default_templates = apply_filters( 'pods_template_default_templates', $default_templates );
|
| 3313 |
|
| 3314 |
+
// Only detail templates need $this->id
|
| 3315 |
if ( empty( $this->id ) ) {
|
| 3316 |
while ( $this->fetch() ) {
|
| 3317 |
pods_template_part( $default_templates, compact( array_keys( get_defined_vars() ) ) );
|
| 3318 |
}
|
|
|
|
|
|
|
| 3319 |
}
|
| 3320 |
+
else
|
| 3321 |
+
pods_template_part( $default_templates, compact( array_keys( get_defined_vars() ) ) );
|
| 3322 |
|
| 3323 |
$out = ob_get_clean();
|
| 3324 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3325 |
$out = apply_filters( 'pods_templates_post_template', $out, $code, $template_name, $this );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3326 |
$out = apply_filters( "pods_templates_post_template_{$template_name}", $out, $code, $template_name, $this );
|
| 3327 |
+
}
|
| 3328 |
|
| 3329 |
return $out;
|
| 3330 |
}
|
| 3334 |
* and override options where needed. For WP object based Pods, you can pass through the WP object
|
| 3335 |
* field names too, such as "post_title" or "post_content" for example.
|
| 3336 |
*
|
| 3337 |
+
* @param array $params (optional) Fields to show on the form, defaults to all fields
|
| 3338 |
+
* @param string $label (optional) Save button label, defaults to "Save Changes"
|
| 3339 |
+
* @param string $thank_you (optional) Thank you URL to send to upon success
|
| 3340 |
*
|
| 3341 |
* @return bool|mixed
|
| 3342 |
+
* @since 2.0
|
| 3343 |
+
* @link http://pods.io/docs/form/
|
| 3344 |
*/
|
| 3345 |
+
public function form ( $params = null, $label = null, $thank_you = null ) {
|
|
|
|
| 3346 |
$defaults = array(
|
| 3347 |
+
'fields' => $params,
|
| 3348 |
+
'label' => $label,
|
| 3349 |
+
'thank_you' => $thank_you,
|
| 3350 |
+
'fields_only' => false
|
| 3351 |
);
|
| 3352 |
|
| 3353 |
+
if ( is_array( $params ) )
|
| 3354 |
$params = array_merge( $defaults, $params );
|
| 3355 |
+
else
|
| 3356 |
$params = $defaults;
|
|
|
|
| 3357 |
|
| 3358 |
$pod =& $this;
|
| 3359 |
|
| 3360 |
$params = $this->do_hook( 'form_params', $params );
|
| 3361 |
|
| 3362 |
+
$fields = $params[ 'fields' ];
|
| 3363 |
|
| 3364 |
+
if ( null !== $fields && !is_array( $fields ) && 0 < strlen( $fields ) )
|
| 3365 |
$fields = explode( ',', $fields );
|
|
|
|
| 3366 |
|
| 3367 |
+
$object_fields = (array) pods_var_raw( 'object_fields', $this->pod_data, array(), null, true );
|
| 3368 |
|
| 3369 |
if ( empty( $fields ) ) {
|
| 3370 |
+
// Add core object fields if $fields is empty
|
| 3371 |
$fields = array_merge( $object_fields, $this->fields );
|
| 3372 |
}
|
| 3373 |
|
| 3374 |
+
$form_fields = $fields; // Temporary
|
|
|
|
| 3375 |
|
| 3376 |
$fields = array();
|
| 3377 |
|
| 3379 |
$name = $k;
|
| 3380 |
|
| 3381 |
$defaults = array(
|
| 3382 |
+
'name' => $name
|
| 3383 |
);
|
| 3384 |
|
| 3385 |
+
if ( !is_array( $field ) ) {
|
| 3386 |
$name = $field;
|
| 3387 |
|
| 3388 |
$field = array(
|
| 3389 |
+
'name' => $name
|
| 3390 |
);
|
| 3391 |
}
|
| 3392 |
|
|
|
|
| 3393 |
$field = array_merge( $defaults, $field );
|
| 3394 |
|
| 3395 |
+
$field[ 'name' ] = trim( $field[ 'name' ] );
|
| 3396 |
|
| 3397 |
+
$default_value = pods_var_raw( 'default', $field );
|
| 3398 |
+
$value = pods_var_raw( 'value', $field );
|
| 3399 |
|
| 3400 |
+
if ( empty( $field[ 'name' ] ) )
|
| 3401 |
+
$field[ 'name' ] = trim( $name );
|
|
|
|
| 3402 |
|
| 3403 |
+
if ( isset( $object_fields[ $field[ 'name' ] ] ) ) {
|
| 3404 |
+
$field = array_merge( $object_fields[ $field[ 'name' ] ], $field );
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3405 |
}
|
| 3406 |
+
elseif ( isset( $this->fields[ $field[ 'name' ] ] ) ) {
|
| 3407 |
+
$field = array_merge( $this->fields[ $field[ 'name' ] ], $field );
|
|
|
|
| 3408 |
}
|
| 3409 |
|
| 3410 |
+
if ( pods_var_raw( 'hidden', $field, false, null, true ) )
|
| 3411 |
+
$field[ 'type' ] = 'hidden';
|
| 3412 |
+
|
| 3413 |
+
$fields[ $field[ 'name' ] ] = $field;
|
| 3414 |
|
| 3415 |
if ( empty( $this->id ) && null !== $default_value ) {
|
| 3416 |
+
$this->row_override[ $field[ 'name' ] ] = $default_value;
|
| 3417 |
+
}
|
| 3418 |
+
elseif ( !empty( $this->id ) && null !== $value ) {
|
| 3419 |
+
$this->row[ $field[ 'name' ] ] = $value;
|
| 3420 |
}
|
| 3421 |
+
}
|
| 3422 |
|
| 3423 |
+
unset( $form_fields ); // Cleanup
|
|
|
|
| 3424 |
|
| 3425 |
$fields = $this->do_hook( 'form_fields', $fields, $params );
|
| 3426 |
|
| 3427 |
+
$label = $params[ 'label' ];
|
| 3428 |
|
| 3429 |
+
if ( empty( $label ) )
|
| 3430 |
$label = __( 'Save Changes', 'pods' );
|
|
|
|
| 3431 |
|
| 3432 |
+
$thank_you = $params[ 'thank_you' ];
|
| 3433 |
+
$fields_only = $params[ 'fields_only' ];
|
| 3434 |
|
| 3435 |
+
PodsForm::$form_counter++;
|
| 3436 |
|
| 3437 |
ob_start();
|
| 3438 |
|
| 3439 |
if ( empty( $thank_you ) ) {
|
| 3440 |
$success = 'success';
|
| 3441 |
|
| 3442 |
+
if ( 1 < PodsForm::$form_counter )
|
| 3443 |
$success .= PodsForm::$form_counter;
|
|
|
|
| 3444 |
|
| 3445 |
+
$thank_you = pods_query_arg( array( 'success*' => null, $success => 1 ) );
|
|
|
|
|
|
|
|
|
|
| 3446 |
|
| 3447 |
+
if ( 1 == pods_v( $success, 'get', 0 ) ) {
|
| 3448 |
$message = __( 'Form submitted successfully', 'pods' );
|
|
|
|
| 3449 |
/**
|
| 3450 |
+
* Change the text of the message that appears on succesful form submission.
|
| 3451 |
*
|
| 3452 |
+
* @param string $message
|
| 3453 |
*
|
| 3454 |
+
* @returns string the message
|
| 3455 |
+
*
|
| 3456 |
+
* @since 3.0.0
|
| 3457 |
*/
|
| 3458 |
$message = apply_filters( 'pods_pod_form_success_message', $message );
|
| 3459 |
|
| 3460 |
+
echo '<div id="message" class="pods-form-front-success">' . $message . '</div>';
|
| 3461 |
}
|
| 3462 |
+
}
|
| 3463 |
|
| 3464 |
pods_view( PODS_DIR . 'ui/front/form.php', compact( array_keys( get_defined_vars() ) ) );
|
| 3465 |
|
| 3466 |
$output = ob_get_clean();
|
| 3467 |
|
| 3468 |
+
if ( empty( $this->id ) )
|
| 3469 |
$this->row_override = array();
|
|
|
|
| 3470 |
|
| 3471 |
return $this->do_hook( 'form', $output, $fields, $label, $thank_you, $this, $this->id() );
|
| 3472 |
}
|
| 3473 |
|
| 3474 |
/**
|
| 3475 |
+
* @param array $fields (optional) Fields to show in the view, defaults to all fields
|
|
|
|
|
|
|
| 3476 |
*
|
| 3477 |
* @return mixed
|
| 3478 |
* @since 2.3.10
|
| 3481 |
|
| 3482 |
$pod =& $this;
|
| 3483 |
|
| 3484 |
+
// Convert comma separated list of fields to an array
|
| 3485 |
+
if ( null !== $fields && !is_array( $fields ) && 0 < strlen( $fields ) ) {
|
| 3486 |
$fields = explode( ',', $fields );
|
| 3487 |
}
|
| 3488 |
|
| 3489 |
$object_fields = (array) pods_v( 'object_fields', $this->pod_data, array(), true );
|
| 3490 |
|
| 3491 |
if ( empty( $fields ) ) {
|
| 3492 |
+
// Add core object fields if $fields is empty
|
| 3493 |
$fields = array_merge( $object_fields, $this->fields );
|
| 3494 |
}
|
| 3495 |
|
| 3496 |
+
$view_fields = $fields; // Temporary
|
|
|
|
| 3497 |
|
| 3498 |
$fields = array();
|
| 3499 |
|
| 3500 |
foreach ( $view_fields as $name => $field ) {
|
| 3501 |
+
|
| 3502 |
$defaults = array(
|
| 3503 |
+
'name' => $name
|
| 3504 |
);
|
| 3505 |
|
| 3506 |
+
if ( !is_array( $field ) ) {
|
| 3507 |
$name = $field;
|
| 3508 |
|
| 3509 |
$field = array(
|
| 3510 |
+
'name' => $name
|
| 3511 |
);
|
| 3512 |
}
|
| 3513 |
|
|
|
|
| 3514 |
$field = array_merge( $defaults, $field );
|
| 3515 |
|
| 3516 |
+
$field[ 'name' ] = trim( $field[ 'name' ] );
|
| 3517 |
|
| 3518 |
+
if ( empty( $field[ 'name' ] ) ) {
|
| 3519 |
+
$field[ 'name' ] = trim( $name );
|
| 3520 |
}
|
| 3521 |
|
| 3522 |
+
if ( isset( $object_fields[ $field[ 'name' ] ] ) )
|
| 3523 |
+
$field = array_merge( $field, $object_fields[ $field[ 'name' ] ] );
|
| 3524 |
+
elseif ( isset( $this->fields[ $field[ 'name' ] ] ) )
|
| 3525 |
+
$field = array_merge( $this->fields[ $field[ 'name' ] ], $field );
|
|
|
|
|
|
|
|
|
|
| 3526 |
|
| 3527 |
+
if ( pods_v( 'hidden', $field, false, null, true ) || 'hidden' == $field[ 'type' ] ) {
|
| 3528 |
continue;
|
| 3529 |
+
}
|
| 3530 |
+
elseif ( !PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field[ 'options' ], $fields, $pod, $pod->id() ) ) {
|
| 3531 |
continue;
|
| 3532 |
}
|
| 3533 |
|
| 3534 |
+
$fields[ $field[ 'name' ] ] = $field;
|
| 3535 |
+
}
|
| 3536 |
|
| 3537 |
+
unset( $view_fields ); // Cleanup
|
|
|
|
| 3538 |
|
| 3539 |
$output = pods_view( PODS_DIR . 'ui/front/view.php', compact( array_keys( get_defined_vars() ) ), false, 'cache', true );
|
| 3540 |
|
| 3545 |
/**
|
| 3546 |
* Replace magic tags with their values
|
| 3547 |
*
|
| 3548 |
+
* @param string $code The content to evaluate
|
| 3549 |
+
* @param object $obj The Pods object
|
| 3550 |
*
|
| 3551 |
* @return string Code with Magic Tags evaluated
|
| 3552 |
*
|
| 3553 |
+
* @since 2.0
|
| 3554 |
*/
|
| 3555 |
+
public function do_magic_tags ( $code ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3556 |
return preg_replace_callback( '/({@(.*?)})/m', array( $this, 'process_magic_tags' ), $code );
|
| 3557 |
}
|
| 3558 |
|
| 3559 |
/**
|
| 3560 |
* Replace magic tags with their values
|
| 3561 |
*
|
| 3562 |
+
* @param string $tag The magic tag to process
|
| 3563 |
+
* @param object $obj The Pods object
|
| 3564 |
*
|
| 3565 |
* @return string Code with Magic Tags evaluated
|
| 3566 |
*
|
| 3567 |
* @since 2.0.2
|
| 3568 |
*/
|
| 3569 |
+
private function process_magic_tags ( $tag ) {
|
| 3570 |
|
| 3571 |
if ( is_array( $tag ) ) {
|
| 3572 |
+
if ( !isset( $tag[ 2 ] ) && strlen( trim( $tag[ 2 ] ) ) < 1 )
|
| 3573 |
return '';
|
|
|
|
| 3574 |
|
| 3575 |
+
$tag = $tag[ 2 ];
|
| 3576 |
}
|
| 3577 |
|
| 3578 |
$tag = trim( $tag, ' {@}' );
|
| 3579 |
$tag = explode( ',', $tag );
|
| 3580 |
|
| 3581 |
+
if ( empty( $tag ) || !isset( $tag[ 0 ] ) || strlen( trim( $tag[ 0 ] ) ) < 1 )
|
| 3582 |
return '';
|
|
|
|
| 3583 |
|
| 3584 |
+
foreach ( $tag as $k => $v ) {
|
| 3585 |
+
$tag[ $k ] = trim( $v );
|
| 3586 |
+
}
|
| 3587 |
|
| 3588 |
+
$field_name = $tag[ 0 ];
|
| 3589 |
|
| 3590 |
+
$helper_name = $before = $after = '';
|
|
|
|
|
|
|
| 3591 |
|
| 3592 |
+
if ( isset( $tag[ 1 ] ) && !empty( $tag[ 1 ] ) ) {
|
| 3593 |
$value = $this->field( $field_name );
|
| 3594 |
|
| 3595 |
+
$helper_name = $tag[ 1 ];
|
| 3596 |
|
| 3597 |
$value = $this->helper( $helper_name, $value, $field_name );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3598 |
}
|
| 3599 |
+
else
|
| 3600 |
+
$value = $this->display( $field_name );
|
| 3601 |
|
| 3602 |
+
if ( isset( $tag[ 2 ] ) && !empty( $tag[ 2 ] ) )
|
| 3603 |
+
$before = $tag[ 2 ];
|
|
|
|
| 3604 |
|
| 3605 |
+
if ( isset( $tag[ 3 ] ) && !empty( $tag[ 3 ] ) )
|
| 3606 |
+
$after = $tag[ 3 ];
|
|
|
|
| 3607 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3608 |
$value = apply_filters( 'pods_do_magic_tags', $value, $field_name, $helper_name, $before, $after );
|
| 3609 |
|
| 3610 |
+
if ( is_array( $value ) )
|
| 3611 |
+
$value = pods_serial_comma( $value, array( 'field' => $field_name, 'fields' => $this->fields ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3612 |
|
| 3613 |
+
if ( null !== $value && false !== $value )
|
| 3614 |
return $before . $value . $after;
|
|
|
|
| 3615 |
|
| 3616 |
return '';
|
| 3617 |
}
|
| 3620 |
*
|
| 3621 |
* Generate UI for Data Management
|
| 3622 |
*
|
| 3623 |
+
* @param mixed $options Array or String containing Pod or Options to be used
|
| 3624 |
+
* @param bool $amend Whether to amend the default UI options or replace entirely
|
| 3625 |
*
|
| 3626 |
+
* @return PodsUI|void UI object or void if custom UI used
|
| 3627 |
*
|
| 3628 |
* @since 2.3.10
|
| 3629 |
*/
|
| 3630 |
+
public function ui ( $options = null, $amend = false ) {
|
|
|
|
| 3631 |
$num = '';
|
| 3632 |
|
| 3633 |
+
if ( empty( $options ) )
|
| 3634 |
$options = array();
|
| 3635 |
+
else {
|
| 3636 |
+
$num = pods_var( 'num', $options, '' );
|
| 3637 |
|
| 3638 |
if ( empty( $num ) ) {
|
| 3639 |
$num = '';
|
| 3640 |
}
|
| 3641 |
}
|
| 3642 |
|
| 3643 |
+
if ( $this->id() != pods_var( 'id' . $num, 'get', null, null, true ) )
|
| 3644 |
+
$this->fetch( pods_var( 'id' . $num, 'get', null, null, true ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3645 |
|
| 3646 |
+
if ( !empty( $options ) && !$amend ) {
|
| 3647 |
$this->ui = $options;
|
| 3648 |
|
| 3649 |
return pods_ui( $this );
|
| 3650 |
+
}
|
| 3651 |
+
elseif ( !empty( $options ) || 'custom' != pods_var( 'ui_style', $this->pod_data[ 'options' ], 'post_type', null, true ) ) {
|
| 3652 |
+
$actions_enabled = pods_var_raw( 'ui_actions_enabled', $this->pod_data[ 'options' ] );
|
| 3653 |
|
| 3654 |
+
if ( !empty( $actions_enabled ) )
|
| 3655 |
$actions_enabled = (array) $actions_enabled;
|
| 3656 |
+
else
|
| 3657 |
$actions_enabled = array();
|
|
|
|
| 3658 |
|
| 3659 |
$available_actions = array(
|
| 3660 |
'add',
|
| 3662 |
'duplicate',
|
| 3663 |
'delete',
|
| 3664 |
'reorder',
|
| 3665 |
+
'export'
|
| 3666 |
);
|
| 3667 |
|
| 3668 |
+
if ( !empty( $actions_enabled ) ) {
|
| 3669 |
$actions_disabled = array(
|
| 3670 |
+
'view' => 'view'
|
| 3671 |
);
|
| 3672 |
|
| 3673 |
foreach ( $available_actions as $action ) {
|
| 3674 |
+
if ( !in_array( $action, $actions_enabled ) )
|
| 3675 |
$actions_disabled[ $action ] = $action;
|
|
|
|
| 3676 |
}
|
| 3677 |
+
}
|
| 3678 |
+
else {
|
| 3679 |
$actions_disabled = array(
|
| 3680 |
'duplicate' => 'duplicate',
|
| 3681 |
+
'view' => 'view',
|
| 3682 |
+
'export' => 'export'
|
| 3683 |
);
|
| 3684 |
|
| 3685 |
+
if ( 1 == pods_var( 'ui_export', $this->pod_data[ 'options' ], 0 ) )
|
| 3686 |
+
unset( $actions_disabled[ 'export' ] );
|
| 3687 |
+
}
|
|
|
|
| 3688 |
|
| 3689 |
if ( empty( $options ) ) {
|
| 3690 |
$author_restrict = false;
|
| 3691 |
|
| 3692 |
+
if ( isset( $this->fields[ 'author' ] ) && 'pick' == $this->fields[ 'author' ][ 'type' ] && 'user' == $this->fields[ 'author' ][ 'pick_object' ] )
|
| 3693 |
$author_restrict = 'author.ID';
|
|
|
|
| 3694 |
|
| 3695 |
+
if ( !pods_is_admin( array( 'pods', 'pods_content' ) ) ) {
|
| 3696 |
+
if ( !current_user_can( 'pods_add_' . $this->pod ) ) {
|
| 3697 |
+
$actions_disabled[ 'add' ] = 'add';
|
| 3698 |
|
| 3699 |
+
if ( 'add' == pods_var( 'action' . $num, 'get' ) )
|
| 3700 |
$_GET[ 'action' . $num ] = 'manage';
|
|
|
|
| 3701 |
}
|
| 3702 |
|
| 3703 |
+
if ( !$author_restrict && !current_user_can( 'pods_edit_' . $this->pod ) && !current_user_can( 'pods_edit_others_' . $this->pod ) )
|
| 3704 |
+
$actions_disabled[ 'edit' ] = 'edit';
|
|
|
|
| 3705 |
|
| 3706 |
+
if ( !$author_restrict && !current_user_can( 'pods_delete_' . $this->pod ) && !current_user_can( 'pods_delete_others_' . $this->pod ) )
|
| 3707 |
+
$actions_disabled[ 'delete' ] = 'delete';
|
|
|
|
| 3708 |
|
| 3709 |
+
if ( !current_user_can( 'pods_reorder_' . $this->pod ) )
|
| 3710 |
+
$actions_disabled[ 'reorder' ] = 'reorder';
|
|
|
|
| 3711 |
|
| 3712 |
+
if ( !current_user_can( 'pods_export_' . $this->pod ) )
|
| 3713 |
+
$actions_disabled[ 'export' ] = 'export';
|
| 3714 |
+
}
|
| 3715 |
+
}
|
|
|
|
| 3716 |
|
| 3717 |
+
$_GET[ 'action' . $num ] = pods_var( 'action' . $num, 'get', pods_var( 'action', $options, 'manage' ) );
|
| 3718 |
|
| 3719 |
+
$index = $this->pod_data[ 'field_id' ];
|
| 3720 |
$label = __( 'ID', 'pods' );
|
| 3721 |
|
| 3722 |
+
if ( isset( $this->pod_data[ 'fields' ][ $this->pod_data[ 'field_index' ] ] ) ) {
|
| 3723 |
+
$index = $this->pod_data[ 'field_index' ];
|
| 3724 |
+
$label = $this->pod_data[ 'fields' ][ $this->pod_data[ 'field_index' ] ];
|
| 3725 |
}
|
| 3726 |
|
| 3727 |
$manage = array(
|
| 3728 |
+
$index => $label
|
| 3729 |
);
|
| 3730 |
|
| 3731 |
+
if ( isset( $this->pod_data[ 'fields' ][ 'modified' ] ) )
|
| 3732 |
+
$manage[ 'modified' ] = $this->pod_data[ 'fields' ][ 'modified' ][ 'label' ];
|
|
|
|
| 3733 |
|
| 3734 |
+
$manage_fields = pods_var_raw( 'ui_fields_manage', $this->pod_data[ 'options' ] );
|
| 3735 |
|
| 3736 |
+
if ( !empty( $manage_fields ) ) {
|
| 3737 |
$manage_new = array();
|
| 3738 |
|
| 3739 |
foreach ( $manage_fields as $manage_field ) {
|
| 3740 |
+
if ( isset( $this->pod_data[ 'fields' ][ $manage_field ] ) )
|
| 3741 |
+
$manage_new[ $manage_field ] = $this->pod_data[ 'fields' ][ $manage_field ];
|
| 3742 |
+
elseif ( isset( $this->pod_data[ 'object_fields' ][ $manage_field ] ) )
|
| 3743 |
+
$manage_new[ $manage_field ] = $this->pod_data[ 'object_fields' ][ $manage_field ];
|
| 3744 |
+
elseif ( $manage_field == $this->pod_data[ 'field_id' ] ) {
|
| 3745 |
$field = array(
|
| 3746 |
+
'name' => $manage_field,
|
| 3747 |
'label' => 'ID',
|
| 3748 |
+
'type' => 'number',
|
| 3749 |
+
'width' => '8%'
|
| 3750 |
);
|
| 3751 |
|
| 3752 |
+
$manage_new[ $manage_field ] = PodsForm::field_setup( $field, null, $field[ 'type' ] );
|
| 3753 |
}
|
| 3754 |
}
|
| 3755 |
|
| 3756 |
+
if ( !empty( $manage_new ) )
|
| 3757 |
$manage = $manage_new;
|
| 3758 |
+
}
|
|
|
|
| 3759 |
|
| 3760 |
+
$manage = apply_filters( 'pods_admin_ui_fields_' . $this->pod, apply_filters( 'pods_admin_ui_fields', $manage, $this->pod, $this ), $this->pod, $this );
|
|
|
|
| 3761 |
|
| 3762 |
+
$icon = pods_var_raw( 'ui_icon', $this->pod_data[ 'options' ] );
|
| 3763 |
|
| 3764 |
+
if ( !empty( $icon ) )
|
| 3765 |
$icon = pods_image_url( $icon, '32x32' );
|
|
|
|
| 3766 |
|
| 3767 |
+
$filters = pods_var_raw( 'ui_filters', $this->pod_data[ 'options' ] );
|
| 3768 |
|
| 3769 |
+
if ( !empty( $filters ) ) {
|
| 3770 |
$filters_new = array();
|
| 3771 |
|
|
|
|
|
|
|
| 3772 |
foreach ( $filters as $filter_field ) {
|
| 3773 |
+
if ( isset( $this->pod_data[ 'fields' ][ $filter_field ] ) )
|
| 3774 |
+
$filters_new[ $filter_field ] = $this->pod_data[ 'fields' ][ $filter_field ];
|
| 3775 |
+
elseif ( isset( $this->pod_data[ 'object_fields' ][ $filter_field ] ) )
|
| 3776 |
+
$filters_new[ $filter_field ] = $this->pod_data[ 'object_fields' ][ $filter_field ];
|
|
|
|
| 3777 |
}
|
| 3778 |
|
| 3779 |
$filters = $filters_new;
|
| 3780 |
}
|
| 3781 |
|
| 3782 |
$ui = array(
|
| 3783 |
+
'fields' => array(
|
| 3784 |
+
'manage' => $manage,
|
| 3785 |
+
'add' => $this->pod_data[ 'fields' ],
|
| 3786 |
+
'edit' => $this->pod_data[ 'fields' ],
|
| 3787 |
+
'duplicate' => $this->pod_data[ 'fields' ]
|
| 3788 |
),
|
| 3789 |
+
'icon' => $icon,
|
| 3790 |
+
'actions_disabled' => $actions_disabled
|
|
|
|
| 3791 |
);
|
| 3792 |
|
| 3793 |
+
if ( !empty( $filters ) ) {
|
| 3794 |
+
$ui[ 'fields' ][ 'search' ] = $filters;
|
| 3795 |
+
$ui[ 'filters' ] = array_keys( $filters );
|
| 3796 |
+
$ui[ 'filters_enhanced' ] = true;
|
| 3797 |
}
|
| 3798 |
|
| 3799 |
+
$reorder_field = pods_var_raw( 'ui_reorder_field', $this->pod_data[ 'options' ] );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3800 |
|
| 3801 |
+
if ( in_array( 'reorder', $actions_enabled ) && !in_array( 'reorder', $actions_disabled ) && !empty( $reorder_field ) && ( ( !empty( $this->pod_data[ 'object_fields' ] ) && isset( $this->pod_data[ 'object_fields' ][ $reorder_field ] ) ) || isset( $this->pod_data[ 'fields' ][ $reorder_field ] ) ) ) {
|
| 3802 |
+
$ui[ 'reorder' ] = array( 'on' => $reorder_field );
|
| 3803 |
+
$ui[ 'orderby' ] = $reorder_field;
|
| 3804 |
+
$ui[ 'orderby_dir' ] = 'ASC';
|
| 3805 |
}
|
| 3806 |
|
| 3807 |
+
if ( !empty( $author_restrict ) )
|
| 3808 |
+
$ui[ 'restrict' ] = array( 'author_restrict' => $author_restrict );
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3809 |
|
| 3810 |
+
if ( !in_array( 'delete', $ui[ 'actions_disabled' ] ) ) {
|
| 3811 |
+
$ui[ 'actions_bulk' ] = array(
|
| 3812 |
+
'delete' => array(
|
| 3813 |
+
'label' => __( 'Delete', 'pods' )
|
| 3814 |
+
// callback not needed, Pods has this built-in for delete
|
| 3815 |
+
)
|
| 3816 |
);
|
| 3817 |
}
|
| 3818 |
|
| 3819 |
+
$detail_url = pods_var( 'detail_url', $this->pod_data[ 'options' ] );
|
| 3820 |
|
| 3821 |
if ( 0 < strlen( $detail_url ) ) {
|
| 3822 |
+
$ui[ 'actions_custom' ] = array(
|
| 3823 |
'view_url' => array(
|
| 3824 |
'label' => 'View',
|
| 3825 |
+
'link' => get_site_url() . '/' . $detail_url
|
| 3826 |
+
)
|
| 3827 |
);
|
| 3828 |
}
|
| 3829 |
|
| 3830 |
+
// @todo Customize the Add New / Manage links to point to their correct menu items
|
| 3831 |
+
|
| 3832 |
+
$ui = apply_filters( 'pods_admin_ui_' . $this->pod, apply_filters( 'pods_admin_ui', $ui, $this->pod, $this ), $this->pod, $this );
|
| 3833 |
|
| 3834 |
+
// Override UI options
|
| 3835 |
foreach ( $options as $option => $value ) {
|
| 3836 |
$ui[ $option ] = $value;
|
| 3837 |
}
|
| 3839 |
$this->ui = $ui;
|
| 3840 |
|
| 3841 |
return pods_ui( $this );
|
| 3842 |
+
}
|
| 3843 |
|
|
|
|
| 3844 |
do_action( 'pods_admin_ui_custom', $this );
|
| 3845 |
+
do_action( 'pods_admin_ui_custom_' . $this->pod, $this );
|
|
|
|
|
|
|
| 3846 |
}
|
| 3847 |
|
| 3848 |
/**
|
| 3849 |
* Handle filters / actions for the class
|
| 3850 |
*
|
| 3851 |
+
* @see pods_do_hook
|
|
|
|
|
|
|
| 3852 |
*
|
| 3853 |
* @return mixed Value filtered
|
| 3854 |
*
|
| 3855 |
+
* @since 2.0
|
| 3856 |
*/
|
| 3857 |
+
private function do_hook () {
|
|
|
|
| 3858 |
$args = func_get_args();
|
| 3859 |
|
| 3860 |
+
if ( empty( $args ) )
|
| 3861 |
return false;
|
|
|
|
| 3862 |
|
| 3863 |
+
$name = array_shift( $args );
|
|
|
|
| 3864 |
|
| 3865 |
return pods_do_hook( 'pods', $name, $args, $this );
|
| 3866 |
}
|
| 3868 |
/**
|
| 3869 |
* Handle variables that have been deprecated and PodsData vars
|
| 3870 |
*
|
| 3871 |
+
* @var $name
|
| 3872 |
*
|
| 3873 |
* @return mixed
|
| 3874 |
*
|
| 3875 |
+
* @since 2.0
|
| 3876 |
*/
|
| 3877 |
+
public function __get ( $name ) {
|
|
|
|
| 3878 |
$name = (string) $name;
|
| 3879 |
|
| 3880 |
+
// PodsData vars
|
| 3881 |
+
if ( 0 === strpos( $name, 'field_' ) && isset( $this->data->{$name} ) ) {
|
| 3882 |
return $this->data->{$name};
|
| 3883 |
}
|
| 3884 |
|
| 3885 |
+
if ( !isset( $this->deprecated ) ) {
|
| 3886 |
+
require_once( PODS_DIR . 'deprecated/classes/Pods.php' );
|
|
|
|
| 3887 |
$this->deprecated = new Pods_Deprecated( $this );
|
| 3888 |
}
|
| 3889 |
|
| 3890 |
$var = null;
|
| 3891 |
|
|
|
|
|
|
|
| 3892 |
if ( isset( $this->deprecated->{$name} ) ) {
|
| 3893 |
+
if ( ! class_exists( 'Pod' ) || Pod::$deprecated_notice ) {
|
| 3894 |
pods_deprecated( "Pods->{$name}", '2.0' );
|
| 3895 |
}
|
| 3896 |
|
| 3897 |
$var = $this->deprecated->{$name};
|
| 3898 |
+
}
|
| 3899 |
+
elseif ( ! class_exists( 'Pod' ) || Pod::$deprecated_notice ) {
|
| 3900 |
pods_deprecated( "Pods->{$name}", '2.0' );
|
| 3901 |
}
|
| 3902 |
|
| 3904 |
}
|
| 3905 |
|
| 3906 |
/**
|
| 3907 |
+
* Handle methods that have been deprecated and any aliasing
|
| 3908 |
*
|
| 3909 |
+
* @var $name
|
| 3910 |
+
* @var $args
|
| 3911 |
*
|
| 3912 |
+
* @return mixed
|
| 3913 |
*
|
| 3914 |
+
* @since 2.0
|
| 3915 |
*/
|
| 3916 |
+
public function __call ( $name, $args ) {
|
|
|
|
| 3917 |
$name = (string) $name;
|
| 3918 |
|
| 3919 |
+
// select > find alias
|
| 3920 |
+
if ( 'select' == $name ) {
|
| 3921 |
return call_user_func_array( array( $this, 'find' ), $args );
|
| 3922 |
}
|
| 3923 |
|
| 3924 |
+
if ( !isset( $this->deprecated ) ) {
|
| 3925 |
+
require_once( PODS_DIR . 'deprecated/classes/Pods.php' );
|
|
|
|
| 3926 |
$this->deprecated = new Pods_Deprecated( $this );
|
| 3927 |
}
|
| 3928 |
|
|
|
|
|
|
|
| 3929 |
if ( method_exists( $this->deprecated, $name ) ) {
|
| 3930 |
return call_user_func_array( array( $this->deprecated, $name ), $args );
|
|
|
|
|
|
|
|
|
|
| 3931 |
}
|
| 3932 |
+
elseif ( ! class_exists( 'Pod' ) || Pod::$deprecated_notice ) {
|
| 3933 |
+
pods_deprecated( "Pods::{$name}", '2.0' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3934 |
}
|
|
|
|
|
|
|
|
|
|
| 3935 |
}
|
| 3936 |
}
|
classes/PodsAPI.php
CHANGED
|
@@ -1,9410 +1,8043 @@
|
|
| 1 |
<?php
|
| 2 |
-
|
| 3 |
/**
|
| 4 |
* @package Pods
|
| 5 |
*/
|
| 6 |
class PodsAPI {
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
|
| 13 |
/**
|
| 14 |
* @var array PodsAPI
|
| 15 |
*/
|
| 16 |
static $instances = array();
|
| 17 |
|
| 18 |
-
/**
|
| 19 |
-
* @var bool
|
| 20 |
-
*/
|
| 21 |
-
public $display_errors = false;
|
| 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 |
-
public $format = null;
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
/**
|
| 55 |
* @var array
|
| 56 |
-
* @since 2.5
|
| 57 |
*/
|
| 58 |
private $fields_cache = array();
|
| 59 |
|
| 60 |
/**
|
| 61 |
* @var array
|
| 62 |
-
* @since 2.5
|
| 63 |
*
|
| 64 |
*/
|
| 65 |
private static $table_info_cache = array();
|
| 66 |
|
| 67 |
/**
|
| 68 |
* @var array
|
| 69 |
-
* @since 2.5
|
| 70 |
*
|
| 71 |
*/
|
| 72 |
private static $related_item_cache = array();
|
| 73 |
|
| 74 |
/**
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
public static function init( $pod = null, $format = null ) {
|
| 85 |
-
|
| 86 |
if ( null !== $pod || null !== $format ) {
|
| 87 |
if ( ! isset( self::$instances[ $pod ] ) ) {
|
| 88 |
// Cache API singleton per Pod
|
| 89 |
self::$instances[ $pod ] = new PodsAPI( $pod, $format );
|
| 90 |
}
|
| 91 |
-
|
| 92 |
return self::$instances[ $pod ];
|
| 93 |
-
}
|
|
|
|
| 94 |
self::$instance = new PodsAPI();
|
| 95 |
}
|
| 96 |
|
| 97 |
return self::$instance;
|
| 98 |
}
|
| 99 |
|
| 100 |
-
/**
|
| 101 |
-
* Store and retrieve data programatically
|
| 102 |
-
*
|
| 103 |
-
* @param string $pod (optional) The pod name
|
| 104 |
-
* @param string $format (deprecated) Format for import/export, "php" or "csv"
|
| 105 |
-
*
|
| 106 |
-
* @return \PodsAPI
|
| 107 |
-
*
|
| 108 |
-
* @license http://www.gnu.org/licenses/gpl-2.0.html
|
| 109 |
-
* @since 1.7.1
|
| 110 |
-
*/
|
| 111 |
-
public function __construct( $pod = null, $format = null ) {
|
| 112 |
-
|
| 113 |
-
if ( null !== $pod && 0 < strlen( (string) $pod ) ) {
|
| 114 |
-
if ( null !== $format ) {
|
| 115 |
-
$this->format = $format;
|
| 116 |
-
|
| 117 |
-
pods_deprecated( 'pods_api( $pod, $format )', '2.0', 'pods_api( $pod )' );
|
| 118 |
-
}
|
| 119 |
-
|
| 120 |
-
$pod = pods_clean_name( $pod );
|
| 121 |
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
$this->pod = $pod['name'];
|
| 127 |
-
$this->pod_id = $pod['id'];
|
| 128 |
-
$this->fields = $pod['fields'];
|
| 129 |
-
}
|
| 130 |
-
}
|
| 131 |
-
}
|
| 132 |
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
*
|
| 136 |
-
* @param string $object_type Object type: post|taxonomy|user|comment|setting
|
| 137 |
-
* @param array $data All post data to be saved
|
| 138 |
-
* @param array $meta (optional) Associative array of meta keys and values
|
| 139 |
-
* @param bool $strict (optional) Decides whether the previous saved meta should be deleted or not
|
| 140 |
-
* @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before
|
| 141 |
-
* sending.
|
| 142 |
-
* @param array $fields (optional) The array of fields and their options, for further processing with
|
| 143 |
-
*
|
| 144 |
-
* @return bool|mixed
|
| 145 |
-
*
|
| 146 |
-
* @since 2.0.0
|
| 147 |
-
*/
|
| 148 |
-
public function save_wp_object( $object_type, $data, $meta = array(), $strict = false, $sanitized = false, $fields = array() ) {
|
| 149 |
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
}
|
| 153 |
|
| 154 |
-
|
| 155 |
-
$object_type = 'term';
|
| 156 |
-
}
|
| 157 |
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
}
|
| 162 |
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
|
|
|
| 169 |
}
|
|
|
|
| 170 |
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
/**
|
| 178 |
-
* Delete a WP object
|
| 179 |
-
*
|
| 180 |
-
* @param string $object_type Object type: post|user|comment
|
| 181 |
-
* @param int $id Object ID
|
| 182 |
-
* @param bool $force_delete (optional) Force deletion instead of trashing (post types only)
|
| 183 |
-
*
|
| 184 |
-
* @return bool|mixed
|
| 185 |
-
*
|
| 186 |
-
* @since 2.0.0
|
| 187 |
-
*/
|
| 188 |
-
public function delete_wp_object( $object_type, $id, $force_delete = true ) {
|
| 189 |
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
}
|
| 193 |
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
}
|
| 197 |
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
|
| 202 |
-
|
| 203 |
-
return wp_delete_post( $id, $force_delete );
|
| 204 |
-
}
|
| 205 |
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
}
|
| 209 |
|
| 210 |
-
|
| 211 |
-
|
| 212 |
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
* @param array $post_meta (optional) All meta to be saved (set value to null to delete)
|
| 218 |
-
* @param bool $strict (optional) Whether to delete previously saved meta not in $post_meta
|
| 219 |
-
* @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before
|
| 220 |
-
* sending.
|
| 221 |
-
* @param array $fields (optional) The array of fields and their options, for further processing with
|
| 222 |
-
*
|
| 223 |
-
* @return mixed|void
|
| 224 |
-
*
|
| 225 |
-
* @since 2.0.0
|
| 226 |
-
*/
|
| 227 |
-
public function save_post( $post_data, $post_meta = null, $strict = false, $sanitized = false, $fields = array() ) {
|
| 228 |
|
| 229 |
-
|
|
|
|
|
|
|
| 230 |
|
| 231 |
-
|
| 232 |
-
pods_no_conflict_on( 'post' );
|
| 233 |
}
|
| 234 |
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
|
|
|
| 238 |
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
} elseif ( 2 < count( $post_data ) || ! isset( $post_data['post_type'] ) ) {
|
| 251 |
-
$post_data['ID'] = wp_update_post( $post_data, true );
|
| 252 |
-
}
|
| 253 |
|
| 254 |
-
|
| 255 |
-
if ( ! $conflicted ) {
|
| 256 |
-
pods_no_conflict_off( 'post' );
|
| 257 |
-
}
|
| 258 |
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
*/
|
| 262 |
-
$post_error = $post_data['ID'];
|
| 263 |
|
| 264 |
-
|
| 265 |
-
|
| 266 |
|
| 267 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
|
| 269 |
-
|
| 270 |
-
pods_no_conflict_off( 'post' );
|
| 271 |
-
}
|
| 272 |
|
| 273 |
-
|
| 274 |
-
|
| 275 |
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
*
|
| 279 |
-
* @param int $id Post ID
|
| 280 |
-
* @param array $post_meta All meta to be saved (set value to null to delete)
|
| 281 |
-
* @param bool $strict Whether to delete previously saved meta not in $post_meta
|
| 282 |
-
* @param array $fields (optional) The array of fields and their options, for further processing with
|
| 283 |
-
*
|
| 284 |
-
* @return int Id of the post with the meta
|
| 285 |
-
*
|
| 286 |
-
* @since 2.0.0
|
| 287 |
-
*/
|
| 288 |
-
public function save_post_meta( $id, $post_meta = null, $strict = false, $fields = array() ) {
|
| 289 |
|
| 290 |
-
|
| 291 |
|
| 292 |
-
|
| 293 |
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
|
| 302 |
-
|
|
|
|
| 303 |
|
| 304 |
-
|
|
|
|
| 305 |
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
$meta[ $k ] = current( $value );
|
| 309 |
-
}
|
| 310 |
-
}
|
| 311 |
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
|
| 316 |
-
|
| 317 |
-
|
|
|
|
| 318 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 319 |
|
| 320 |
-
|
| 321 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 322 |
$simple = false;
|
| 323 |
|
| 324 |
if ( isset( $fields[ $meta_key ] ) ) {
|
| 325 |
$field_data = $fields[ $meta_key ];
|
| 326 |
|
| 327 |
-
$simple = ( 'pick'
|
| 328 |
}
|
| 329 |
|
| 330 |
if ( $simple ) {
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
update_post_meta( $id, '_pods_' . $meta_key, $meta_value );
|
| 334 |
|
| 335 |
if ( ! is_array( $meta_value ) ) {
|
| 336 |
$meta_value = array( $meta_value );
|
| 337 |
}
|
| 338 |
|
| 339 |
foreach ( $meta_value as $value ) {
|
| 340 |
-
|
| 341 |
}
|
| 342 |
-
} else {
|
| 343 |
-
update_post_meta( $id, $meta_key, $meta_value );
|
| 344 |
}
|
| 345 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 362 |
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
* @return int Returns user id on success
|
| 374 |
-
*
|
| 375 |
-
* @since 2.0.0
|
| 376 |
-
*/
|
| 377 |
-
public function save_user( $user_data, $user_meta = null, $strict = false, $sanitized = false, $fields = array() ) {
|
| 378 |
|
| 379 |
-
if (
|
| 380 |
-
|
| 381 |
}
|
| 382 |
|
| 383 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
| 401 |
|
| 402 |
-
|
| 403 |
-
|
| 404 |
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
} elseif ( 1 < count( $user_data ) ) {
|
| 408 |
-
wp_update_user( $user_data );
|
| 409 |
-
}
|
| 410 |
|
| 411 |
-
|
| 412 |
-
if ( ! $conflicted ) {
|
| 413 |
-
pods_no_conflict_off( 'user' );
|
| 414 |
-
}
|
| 415 |
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
*/
|
| 419 |
-
$user_error = $user_data['ID'];
|
| 420 |
|
| 421 |
-
|
| 422 |
-
}
|
| 423 |
|
| 424 |
-
|
| 425 |
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 429 |
|
| 430 |
-
|
| 431 |
-
|
|
|
|
| 432 |
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
*
|
| 436 |
-
* @param int $id User ID
|
| 437 |
-
* @param array $user_meta (optional) All meta to be saved (set value to null to delete)
|
| 438 |
-
* @param bool $strict (optional) Whether to delete previously saved meta not in $user_meta
|
| 439 |
-
* @param array $fields (optional) The array of fields and their options, for further processing with
|
| 440 |
-
*
|
| 441 |
-
* @return int User ID
|
| 442 |
-
*
|
| 443 |
-
* @since 2.0.0
|
| 444 |
-
*
|
| 445 |
-
*/
|
| 446 |
-
public function save_user_meta( $id, $user_meta = null, $strict = false, $fields = array() ) {
|
| 447 |
|
| 448 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 449 |
|
| 450 |
-
|
| 451 |
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
|
|
|
|
|
|
|
|
|
| 459 |
|
| 460 |
-
|
|
|
|
| 461 |
|
| 462 |
-
|
|
|
|
| 463 |
|
| 464 |
-
|
| 465 |
-
if ( null === $meta_value ) {
|
| 466 |
-
$old_meta_value = '';
|
| 467 |
|
| 468 |
-
|
| 469 |
-
$old_meta_value = $meta[ $meta_key ];
|
| 470 |
-
}
|
| 471 |
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
$simple = false;
|
| 475 |
|
| 476 |
-
|
| 477 |
-
|
| 478 |
|
| 479 |
-
|
| 480 |
-
|
| 481 |
|
| 482 |
-
|
| 483 |
-
delete_user_meta( $id, $meta_key );
|
| 484 |
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
}
|
| 495 |
-
}
|
| 496 |
-
}
|
| 497 |
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
delete_user_meta( $id, $meta_key, $user_meta[ $meta_key ] );
|
| 502 |
-
}
|
| 503 |
-
}
|
| 504 |
-
}
|
| 505 |
|
| 506 |
-
|
| 507 |
-
pods_no_conflict_off( 'user' );
|
| 508 |
-
}
|
| 509 |
|
| 510 |
-
|
| 511 |
-
}
|
| 512 |
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
* @param bool $strict (optional) Whether to delete previously saved meta not in $comment_meta
|
| 519 |
-
* @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before
|
| 520 |
-
* sending.
|
| 521 |
-
* @param array $fields (optional) The array of fields and their options, for further processing with
|
| 522 |
-
*
|
| 523 |
-
* @return int Comment ID
|
| 524 |
-
*
|
| 525 |
-
* @since 2.0.0
|
| 526 |
-
*/
|
| 527 |
-
public function save_comment( $comment_data, $comment_meta = null, $strict = false, $sanitized = false, $fields = array() ) {
|
| 528 |
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
}
|
| 532 |
|
| 533 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
| 537 |
-
}
|
| 538 |
|
| 539 |
-
|
| 540 |
-
$comment_meta = array();
|
| 541 |
-
}
|
| 542 |
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
}
|
| 547 |
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
// Expects slashed
|
| 552 |
-
wp_update_comment( $comment_data );
|
| 553 |
-
}
|
| 554 |
|
| 555 |
-
|
| 556 |
-
if ( ! $conflicted ) {
|
| 557 |
-
pods_no_conflict_off( 'comment' );
|
| 558 |
-
}
|
| 559 |
|
| 560 |
-
|
| 561 |
-
* @var $comment_error WP_Error
|
| 562 |
-
*/
|
| 563 |
-
$comment_error = $comment_data['comment_ID'];
|
| 564 |
|
| 565 |
-
|
| 566 |
-
|
| 567 |
|
| 568 |
-
|
| 569 |
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
}
|
| 573 |
|
| 574 |
-
|
| 575 |
-
|
| 576 |
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
*
|
| 580 |
-
* @param int $id Comment ID
|
| 581 |
-
* @param array $comment_meta (optional) All meta to be saved (set value to null to delete)
|
| 582 |
-
* @param bool $strict (optional) Whether to delete previously saved meta not in $comment_meta
|
| 583 |
-
* @param array $fields (optional) The array of fields and their options, for further processing with
|
| 584 |
-
*
|
| 585 |
-
* @return int Comment ID
|
| 586 |
-
*
|
| 587 |
-
* @since 2.0.0
|
| 588 |
-
*/
|
| 589 |
-
public function save_comment_meta( $id, $comment_meta = null, $strict = false, $fields = array() ) {
|
| 590 |
|
| 591 |
-
|
|
|
|
|
|
|
|
|
|
| 592 |
|
| 593 |
-
|
|
|
|
|
|
|
| 594 |
|
| 595 |
-
|
| 596 |
-
pods_no_conflict_on( 'comment' );
|
| 597 |
-
}
|
| 598 |
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
}
|
| 602 |
|
| 603 |
-
|
|
|
|
|
|
|
| 604 |
|
| 605 |
-
|
| 606 |
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
$old_meta_value = '';
|
| 610 |
|
| 611 |
-
|
| 612 |
-
|
| 613 |
-
|
|
|
|
|
|
|
|
|
|
| 614 |
|
| 615 |
-
|
| 616 |
-
|
| 617 |
-
|
|
|
|
| 618 |
|
| 619 |
-
|
| 620 |
-
|
| 621 |
|
| 622 |
-
|
| 623 |
-
|
| 624 |
|
| 625 |
-
|
| 626 |
-
|
| 627 |
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 631 |
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
}
|
| 635 |
-
} else {
|
| 636 |
-
update_comment_meta( $id, $meta_key, $meta_value );
|
| 637 |
-
}
|
| 638 |
-
}
|
| 639 |
}
|
| 640 |
|
| 641 |
-
|
| 642 |
-
|
| 643 |
-
|
| 644 |
-
|
| 645 |
-
}
|
| 646 |
-
}
|
| 647 |
-
}
|
| 648 |
|
| 649 |
-
|
| 650 |
-
|
| 651 |
-
}
|
| 652 |
|
| 653 |
-
|
| 654 |
-
|
| 655 |
|
| 656 |
-
|
| 657 |
-
|
| 658 |
-
*
|
| 659 |
-
* @param array $term_data All term data to be saved (using wp_insert_term / wp_update_term)
|
| 660 |
-
* @param array $term_meta All meta to be saved (set value to null to delete)
|
| 661 |
-
* @param bool $strict (optional) Whether to delete previously saved meta not in $post_meta
|
| 662 |
-
* @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before
|
| 663 |
-
* sending.
|
| 664 |
-
* @param array $fields (optional) The array of fields and their options, for further processing with
|
| 665 |
-
*
|
| 666 |
-
* @return int Term ID
|
| 667 |
-
*
|
| 668 |
-
* @since 2.0.0
|
| 669 |
-
*/
|
| 670 |
-
public function save_term( $term_data, $term_meta, $strict = false, $sanitized = false, $fields = array() ) {
|
| 671 |
|
| 672 |
-
|
| 673 |
-
|
| 674 |
-
}
|
| 675 |
|
| 676 |
-
|
|
|
|
| 677 |
|
| 678 |
-
|
| 679 |
-
|
| 680 |
-
}
|
| 681 |
-
|
| 682 |
-
if ( ! $conflicted ) {
|
| 683 |
-
pods_no_conflict_on( 'taxonomy' );
|
| 684 |
-
}
|
| 685 |
-
|
| 686 |
-
if ( ! is_array( $term_meta ) ) {
|
| 687 |
-
$term_meta = array();
|
| 688 |
-
}
|
| 689 |
-
|
| 690 |
-
if ( $sanitized ) {
|
| 691 |
-
$term_data = pods_unsanitize( $term_data );
|
| 692 |
-
$term_meta = pods_unsanitize( $term_meta );
|
| 693 |
-
}
|
| 694 |
-
|
| 695 |
-
$taxonomy = $term_data['taxonomy'];
|
| 696 |
|
| 697 |
-
|
|
|
|
| 698 |
|
| 699 |
-
|
| 700 |
-
|
| 701 |
|
| 702 |
-
|
|
|
|
| 703 |
|
| 704 |
-
|
| 705 |
-
|
| 706 |
-
$term_data['term_id'] = wp_update_term( $term_data['term_id'], $taxonomy, $term_data );
|
| 707 |
-
}
|
| 708 |
|
| 709 |
-
|
| 710 |
-
|
| 711 |
-
pods_no_conflict_off( 'taxonomy' );
|
| 712 |
-
}
|
| 713 |
|
| 714 |
-
|
| 715 |
-
|
| 716 |
-
*/
|
| 717 |
-
$term_error = $term_data['term_id'];
|
| 718 |
|
| 719 |
-
|
| 720 |
-
|
| 721 |
-
$term_data['term_id'] = $term_data['term_id']['term_id'];
|
| 722 |
-
}
|
| 723 |
|
| 724 |
-
|
|
|
|
| 725 |
|
| 726 |
-
|
| 727 |
-
pods_no_conflict_off( 'taxonomy' );
|
| 728 |
-
}
|
| 729 |
|
| 730 |
-
|
| 731 |
-
}
|
| 732 |
|
| 733 |
-
|
| 734 |
-
|
| 735 |
-
*
|
| 736 |
-
* @param int $id Term ID
|
| 737 |
-
* @param array $term_meta All meta to be saved (set value to null to delete)
|
| 738 |
-
* @param bool $strict Whether to delete previously saved meta not in $term_meta
|
| 739 |
-
* @param array $fields (optional) The array of fields and their options, for further processing with
|
| 740 |
-
*
|
| 741 |
-
* @return int Id of the term with the meta
|
| 742 |
-
*
|
| 743 |
-
* @since 2.0.0
|
| 744 |
-
*/
|
| 745 |
-
public function save_term_meta( $id, $term_meta = null, $strict = false, $fields = array() ) {
|
| 746 |
|
| 747 |
-
|
| 748 |
-
|
| 749 |
-
|
| 750 |
|
| 751 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 752 |
|
| 753 |
-
|
|
|
|
|
|
|
|
|
|
| 754 |
|
| 755 |
-
|
| 756 |
-
pods_no_conflict_on( 'taxonomy' );
|
| 757 |
-
}
|
| 758 |
|
| 759 |
-
|
| 760 |
-
|
| 761 |
-
|
| 762 |
|
| 763 |
-
|
|
|
|
|
|
|
|
|
|
| 764 |
|
| 765 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 766 |
|
| 767 |
-
|
| 768 |
-
|
| 769 |
-
$meta[ $k ] = current( $value );
|
| 770 |
}
|
| 771 |
-
}
|
| 772 |
|
| 773 |
-
|
| 774 |
-
|
| 775 |
-
$old_meta_value = '';
|
| 776 |
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
|
|
|
|
| 780 |
|
| 781 |
-
|
| 782 |
-
|
| 783 |
-
|
|
|
|
| 784 |
|
| 785 |
-
|
| 786 |
-
|
|
|
|
|
|
|
| 787 |
|
| 788 |
-
|
| 789 |
-
|
|
|
|
|
|
|
|
|
|
| 790 |
|
| 791 |
-
|
| 792 |
-
|
| 793 |
|
| 794 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 795 |
|
| 796 |
-
|
| 797 |
-
|
|
|
|
|
|
|
|
|
|
| 798 |
}
|
| 799 |
-
|
| 800 |
-
|
| 801 |
-
add_term_meta( $id, $meta_key, $value );
|
| 802 |
}
|
| 803 |
-
} else {
|
| 804 |
-
update_term_meta( $id, $meta_key, $meta_value );
|
| 805 |
-
}
|
| 806 |
-
}
|
| 807 |
-
}
|
| 808 |
|
| 809 |
-
|
| 810 |
-
|
| 811 |
-
|
| 812 |
-
|
|
|
|
|
|
|
| 813 |
}
|
| 814 |
}
|
| 815 |
-
}
|
| 816 |
-
|
| 817 |
-
if ( ! $conflicted ) {
|
| 818 |
-
pods_no_conflict_off( 'taxonomy' );
|
| 819 |
-
}
|
| 820 |
-
|
| 821 |
-
return $id;
|
| 822 |
-
}
|
| 823 |
|
| 824 |
-
|
| 825 |
-
|
| 826 |
-
|
| 827 |
-
|
| 828 |
-
|
| 829 |
-
|
| 830 |
-
|
| 831 |
-
|
| 832 |
-
* @return bool
|
| 833 |
-
*
|
| 834 |
-
* @since 2.3.0
|
| 835 |
-
*/
|
| 836 |
-
public function save_setting( $setting, $option_data, $sanitized = false ) {
|
| 837 |
-
|
| 838 |
-
if ( ! is_array( $option_data ) || empty( $option_data ) ) {
|
| 839 |
-
return pods_error( __( 'Setting data is required but is either invalid or empty', 'pods' ), $this );
|
| 840 |
-
}
|
| 841 |
-
|
| 842 |
-
$conflicted = pods_no_conflict_check( 'settings' );
|
| 843 |
-
|
| 844 |
-
if ( ! $conflicted ) {
|
| 845 |
-
pods_no_conflict_on( 'settings' );
|
| 846 |
-
}
|
| 847 |
|
| 848 |
-
|
| 849 |
-
$option_data = pods_unsanitize( $option_data );
|
| 850 |
-
}
|
| 851 |
|
| 852 |
-
|
| 853 |
-
|
| 854 |
-
|
|
|
|
| 855 |
}
|
|
|
|
| 856 |
|
| 857 |
-
|
| 858 |
-
|
| 859 |
-
|
| 860 |
-
if ( ! $conflicted ) {
|
| 861 |
-
pods_no_conflict_off( 'settings' );
|
| 862 |
-
}
|
| 863 |
-
|
| 864 |
-
return true;
|
| 865 |
-
}
|
| 866 |
-
|
| 867 |
-
/**
|
| 868 |
-
* Rename a WP object's type
|
| 869 |
-
*
|
| 870 |
-
* @param string $object_type Object type: post|taxonomy|comment|setting
|
| 871 |
-
* @param string $old_name The old name
|
| 872 |
-
* @param string $new_name The new name
|
| 873 |
-
*
|
| 874 |
-
* @return bool
|
| 875 |
-
*
|
| 876 |
-
* @since 2.0.0
|
| 877 |
-
*/
|
| 878 |
-
public function rename_wp_object_type( $object_type, $old_name, $new_name ) {
|
| 879 |
|
| 880 |
-
|
| 881 |
-
* @var $wpdb wpdb
|
| 882 |
-
*/
|
| 883 |
-
global $wpdb;
|
| 884 |
|
| 885 |
-
|
| 886 |
-
|
| 887 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 888 |
|
| 889 |
-
|
| 890 |
-
|
| 891 |
-
|
| 892 |
-
$old_name
|
| 893 |
-
) );
|
| 894 |
-
} elseif ( 'taxonomy' === $object_type ) {
|
| 895 |
-
pods_query( "UPDATE `{$wpdb->term_taxonomy}` SET `taxonomy` = %s WHERE `taxonomy` = %s", array(
|
| 896 |
-
$new_name,
|
| 897 |
-
$old_name
|
| 898 |
-
) );
|
| 899 |
-
} elseif ( 'comment' === $object_type ) {
|
| 900 |
-
pods_query( "UPDATE `{$wpdb->comments}` SET `comment_type` = %s WHERE `comment_type` = %s", array(
|
| 901 |
-
$new_name,
|
| 902 |
-
$old_name
|
| 903 |
-
) );
|
| 904 |
-
} elseif ( 'settings' === $object_type ) {
|
| 905 |
-
pods_query( "UPDATE `{$wpdb->options}` SET `option_name` = REPLACE( `option_name`, %s, %s ) WHERE `option_name` LIKE '" . pods_sanitize_like( $old_name ) . "_%'", array(
|
| 906 |
-
$new_name . '_',
|
| 907 |
-
$old_name . '_'
|
| 908 |
-
) );
|
| 909 |
-
}
|
| 910 |
|
| 911 |
-
|
| 912 |
-
|
| 913 |
|
| 914 |
-
|
| 915 |
-
* Get a list of core WP object fields for a specific object
|
| 916 |
-
*
|
| 917 |
-
* @param string $object The pod type to look for, possible values: post_type, user, comment, taxonomy
|
| 918 |
-
* @param array $pod Array of Pod data
|
| 919 |
-
* @param boolean $refresh Whether to force refresh the information
|
| 920 |
-
*
|
| 921 |
-
* @return array Array of fields
|
| 922 |
-
*
|
| 923 |
-
* @since 2.0.0
|
| 924 |
-
*/
|
| 925 |
-
public function get_wp_object_fields( $object = 'post_type', $pod = null, $refresh = false ) {
|
| 926 |
|
| 927 |
-
|
|
|
|
| 928 |
|
| 929 |
-
|
| 930 |
-
|
| 931 |
-
$pod_name = 'attachment';
|
| 932 |
-
}
|
| 933 |
|
| 934 |
-
|
|
|
|
| 935 |
|
| 936 |
-
|
| 937 |
-
$fields = pods_transient_get( trim( 'pods_api_object_fields_' . $object . $pod_name . '_', '_' ) );
|
| 938 |
-
}
|
| 939 |
|
| 940 |
-
|
| 941 |
-
|
| 942 |
-
|
|
|
|
|
|
|
| 943 |
|
| 944 |
-
|
| 945 |
-
|
| 946 |
-
if ( 'post_type' === $object ) {
|
| 947 |
-
$fields = array(
|
| 948 |
-
'ID' => array(
|
| 949 |
-
'name' => 'ID',
|
| 950 |
-
'label' => 'ID',
|
| 951 |
-
'type' => 'number',
|
| 952 |
-
'alias' => array( 'id' ),
|
| 953 |
-
'options' => array(
|
| 954 |
-
'number_format' => '9999.99'
|
| 955 |
-
)
|
| 956 |
-
),
|
| 957 |
-
'post_title' => array(
|
| 958 |
-
'name' => 'post_title',
|
| 959 |
-
'label' => 'Title',
|
| 960 |
-
'type' => 'text',
|
| 961 |
-
'alias' => array( 'title', 'name' ),
|
| 962 |
-
'options' => array(
|
| 963 |
-
'display_filter' => 'the_title',
|
| 964 |
-
'display_filter_args' => array( 'post_ID' )
|
| 965 |
-
)
|
| 966 |
-
),
|
| 967 |
-
'post_content' => array(
|
| 968 |
-
'name' => 'post_content',
|
| 969 |
-
'label' => 'Content',
|
| 970 |
-
'type' => 'wysiwyg',
|
| 971 |
-
'alias' => array( 'content' ),
|
| 972 |
-
'options' => array(
|
| 973 |
-
'wysiwyg_allowed_html_tags' => '',
|
| 974 |
-
'display_filter' => 'the_content',
|
| 975 |
-
'pre_save' => 0
|
| 976 |
-
)
|
| 977 |
-
),
|
| 978 |
-
'post_excerpt' => array(
|
| 979 |
-
'name' => 'post_excerpt',
|
| 980 |
-
'label' => 'Excerpt',
|
| 981 |
-
'type' => 'paragraph',
|
| 982 |
-
'alias' => array( 'excerpt' ),
|
| 983 |
-
'options' => array(
|
| 984 |
-
'paragraph_allow_html' => 1,
|
| 985 |
-
'paragraph_allowed_html_tags' => '',
|
| 986 |
-
'display_filter' => 'the_excerpt',
|
| 987 |
-
'pre_save' => 0
|
| 988 |
-
)
|
| 989 |
-
),
|
| 990 |
-
'post_author' => array(
|
| 991 |
-
'name' => 'post_author',
|
| 992 |
-
'label' => 'Author',
|
| 993 |
-
'type' => 'pick',
|
| 994 |
-
'alias' => array( 'author' ),
|
| 995 |
-
'pick_object' => 'user',
|
| 996 |
-
'options' => array(
|
| 997 |
-
'pick_format_type' => 'single',
|
| 998 |
-
'pick_format_single' => 'autocomplete',
|
| 999 |
-
'default_value' => '{@user.ID}'
|
| 1000 |
-
)
|
| 1001 |
-
),
|
| 1002 |
-
'post_date' => array(
|
| 1003 |
-
'name' => 'post_date',
|
| 1004 |
-
'label' => 'Publish Date',
|
| 1005 |
-
'type' => 'datetime',
|
| 1006 |
-
'alias' => array( 'created', 'date' )
|
| 1007 |
-
),
|
| 1008 |
-
'post_date_gmt' => array(
|
| 1009 |
-
'name' => 'post_date_gmt',
|
| 1010 |
-
'label' => 'Publish Date (GMT)',
|
| 1011 |
-
'type' => 'datetime',
|
| 1012 |
-
'alias' => array(),
|
| 1013 |
-
'hidden' => true
|
| 1014 |
-
),
|
| 1015 |
-
'post_status' => array(
|
| 1016 |
-
'name' => 'post_status',
|
| 1017 |
-
'label' => 'Status',
|
| 1018 |
-
'type' => 'pick',
|
| 1019 |
-
'pick_object' => 'post-status',
|
| 1020 |
-
'default' => $this->do_hook( 'default_status_' . $pod_name, pods_var( 'default_status', pods_var_raw( 'options', $pod ), 'draft', null, true ), $pod ),
|
| 1021 |
-
'alias' => array( 'status' )
|
| 1022 |
-
),
|
| 1023 |
-
'comment_status' => array(
|
| 1024 |
-
'name' => 'comment_status',
|
| 1025 |
-
'label' => 'Comment Status',
|
| 1026 |
-
'type' => 'text',
|
| 1027 |
-
'default' => get_option( 'default_comment_status', 'open' ),
|
| 1028 |
-
'alias' => array(),
|
| 1029 |
-
'data' => array(
|
| 1030 |
-
'open' => __( 'Open', 'pods' ),
|
| 1031 |
-
'closed' => __( 'Closed', 'pods' )
|
| 1032 |
-
)
|
| 1033 |
-
),
|
| 1034 |
-
'ping_status' => array(
|
| 1035 |
-
'name' => 'ping_status',
|
| 1036 |
-
'label' => 'Ping Status',
|
| 1037 |
-
'default' => get_option( 'default_ping_status', 'open' ),
|
| 1038 |
-
'type' => 'text',
|
| 1039 |
-
'alias' => array(),
|
| 1040 |
-
'data' => array(
|
| 1041 |
-
'open' => __( 'Open', 'pods' ),
|
| 1042 |
-
'closed' => __( 'Closed', 'pods' )
|
| 1043 |
-
)
|
| 1044 |
-
),
|
| 1045 |
-
'post_password' => array(
|
| 1046 |
-
'name' => 'post_password',
|
| 1047 |
-
'label' => 'Password',
|
| 1048 |
-
'type' => 'text',
|
| 1049 |
-
'alias' => array()
|
| 1050 |
-
),
|
| 1051 |
-
'post_name' => array(
|
| 1052 |
-
'name' => 'post_name',
|
| 1053 |
-
'label' => 'Permalink',
|
| 1054 |
-
'type' => 'slug',
|
| 1055 |
-
'alias' => array( 'slug', 'permalink' )
|
| 1056 |
-
),
|
| 1057 |
-
'to_ping' => array(
|
| 1058 |
-
'name' => 'to_ping',
|
| 1059 |
-
'label' => 'To Ping',
|
| 1060 |
-
'type' => 'text',
|
| 1061 |
-
'alias' => array(),
|
| 1062 |
-
'hidden' => true
|
| 1063 |
-
),
|
| 1064 |
-
'pinged' => array(
|
| 1065 |
-
'name' => 'pinged',
|
| 1066 |
-
'label' => 'Pinged',
|
| 1067 |
-
'type' => 'text',
|
| 1068 |
-
'alias' => array(),
|
| 1069 |
-
'hidden' => true
|
| 1070 |
-
),
|
| 1071 |
-
'post_modified' => array(
|
| 1072 |
-
'name' => 'post_modified',
|
| 1073 |
-
'label' => 'Last Modified Date',
|
| 1074 |
-
'type' => 'datetime',
|
| 1075 |
-
'alias' => array( 'modified' ),
|
| 1076 |
-
'hidden' => true
|
| 1077 |
-
),
|
| 1078 |
-
'post_modified_gmt' => array(
|
| 1079 |
-
'name' => 'post_modified_gmt',
|
| 1080 |
-
'label' => 'Last Modified Date (GMT)',
|
| 1081 |
-
'type' => 'datetime',
|
| 1082 |
-
'alias' => array(),
|
| 1083 |
-
'hidden' => true
|
| 1084 |
-
),
|
| 1085 |
-
'post_content_filtered' => array(
|
| 1086 |
-
'name' => 'post_content_filtered',
|
| 1087 |
-
'label' => 'Content (filtered)',
|
| 1088 |
-
'type' => 'paragraph',
|
| 1089 |
-
'alias' => array(),
|
| 1090 |
-
'hidden' => true,
|
| 1091 |
-
'options' => array(
|
| 1092 |
-
'paragraph_allow_html' => 1,
|
| 1093 |
-
'paragraph_oembed' => 1,
|
| 1094 |
-
'paragraph_wptexturize' => 1,
|
| 1095 |
-
'paragraph_convert_chars' => 1,
|
| 1096 |
-
'paragraph_wpautop' => 1,
|
| 1097 |
-
'paragraph_allow_shortcode' => 1,
|
| 1098 |
-
'paragraph_allowed_html_tags' => ''
|
| 1099 |
-
)
|
| 1100 |
-
),
|
| 1101 |
-
'post_parent' => array(
|
| 1102 |
-
'name' => 'post_parent',
|
| 1103 |
-
'label' => 'Parent',
|
| 1104 |
-
'type' => 'pick',
|
| 1105 |
-
'pick_object' => 'post_type',
|
| 1106 |
-
'pick_val' => '__current__',
|
| 1107 |
-
'alias' => array( 'parent' ),
|
| 1108 |
-
'data' => array(),
|
| 1109 |
-
'hidden' => true
|
| 1110 |
-
),
|
| 1111 |
-
'guid' => array(
|
| 1112 |
-
'name' => 'guid',
|
| 1113 |
-
'label' => 'GUID',
|
| 1114 |
-
'type' => 'text',
|
| 1115 |
-
'alias' => array(),
|
| 1116 |
-
'hidden' => true
|
| 1117 |
-
),
|
| 1118 |
-
'menu_order' => array(
|
| 1119 |
-
'name' => 'menu_order',
|
| 1120 |
-
'label' => 'Menu Order',
|
| 1121 |
-
'type' => 'number',
|
| 1122 |
-
'alias' => array(),
|
| 1123 |
-
'options' => array(
|
| 1124 |
-
'number_format' => '9999.99'
|
| 1125 |
-
)
|
| 1126 |
-
),
|
| 1127 |
-
'post_type' => array(
|
| 1128 |
-
'name' => 'post_type',
|
| 1129 |
-
'label' => 'Type',
|
| 1130 |
-
'type' => 'text',
|
| 1131 |
-
'alias' => array( 'type' ),
|
| 1132 |
-
'hidden' => true
|
| 1133 |
-
),
|
| 1134 |
-
'post_mime_type' => array(
|
| 1135 |
-
'name' => 'post_mime_type',
|
| 1136 |
-
'label' => 'Mime Type',
|
| 1137 |
-
'type' => 'text',
|
| 1138 |
-
'alias' => array(),
|
| 1139 |
-
'hidden' => true
|
| 1140 |
-
),
|
| 1141 |
-
'comment_count' => array(
|
| 1142 |
-
'name' => 'comment_count',
|
| 1143 |
-
'label' => 'Comment Count',
|
| 1144 |
-
'type' => 'number',
|
| 1145 |
-
'alias' => array(),
|
| 1146 |
-
'hidden' => true
|
| 1147 |
-
),
|
| 1148 |
-
'comments' => array(
|
| 1149 |
-
'name' => 'comments',
|
| 1150 |
-
'label' => 'Comments',
|
| 1151 |
-
'type' => 'comment',
|
| 1152 |
-
'pick_object' => 'comment',
|
| 1153 |
-
'pick_val' => 'comment',
|
| 1154 |
-
'alias' => array(),
|
| 1155 |
-
'hidden' => true,
|
| 1156 |
-
'options' => array(
|
| 1157 |
-
'comment_format_type' => 'multi'
|
| 1158 |
-
)
|
| 1159 |
-
)
|
| 1160 |
-
);
|
| 1161 |
|
| 1162 |
-
|
| 1163 |
-
$taxonomies = get_object_taxonomies( $pod_name, 'objects' );
|
| 1164 |
|
| 1165 |
-
|
| 1166 |
-
|
| 1167 |
-
|
| 1168 |
-
'label' => $taxonomy->labels->name,
|
| 1169 |
-
'type' => 'taxonomy',
|
| 1170 |
-
'pick_object' => 'taxonomy',
|
| 1171 |
-
'pick_val' => $taxonomy->name,
|
| 1172 |
-
'alias' => array(),
|
| 1173 |
-
'hidden' => true,
|
| 1174 |
-
'options' => array(
|
| 1175 |
-
'taxonomy_format_type' => 'multi'
|
| 1176 |
-
)
|
| 1177 |
-
);
|
| 1178 |
-
}
|
| 1179 |
-
}
|
| 1180 |
-
} elseif ( 'user' === $object ) {
|
| 1181 |
-
$fields = array(
|
| 1182 |
-
'ID' => array(
|
| 1183 |
-
'name' => 'ID',
|
| 1184 |
-
'label' => 'ID',
|
| 1185 |
-
'type' => 'number',
|
| 1186 |
-
'alias' => array( 'id' ),
|
| 1187 |
-
'options' => array(
|
| 1188 |
-
'number_format' => '9999.99'
|
| 1189 |
-
)
|
| 1190 |
-
),
|
| 1191 |
-
'user_login' => array(
|
| 1192 |
-
'name' => 'user_login',
|
| 1193 |
-
'label' => 'Title',
|
| 1194 |
-
'type' => 'text',
|
| 1195 |
-
'alias' => array( 'login' ),
|
| 1196 |
-
'options' => array(
|
| 1197 |
-
'required' => 1
|
| 1198 |
-
)
|
| 1199 |
-
),
|
| 1200 |
-
'user_nicename' => array(
|
| 1201 |
-
'name' => 'user_nicename',
|
| 1202 |
-
'label' => 'Permalink',
|
| 1203 |
-
'type' => 'slug',
|
| 1204 |
-
'alias' => array( 'nicename', 'slug', 'permalink' )
|
| 1205 |
-
),
|
| 1206 |
-
'display_name' => array(
|
| 1207 |
-
'name' => 'display_name',
|
| 1208 |
-
'label' => 'Display Name',
|
| 1209 |
-
'type' => 'text',
|
| 1210 |
-
'alias' => array( 'title', 'name' )
|
| 1211 |
-
),
|
| 1212 |
-
'user_pass' => array(
|
| 1213 |
-
'name' => 'user_pass',
|
| 1214 |
-
'label' => 'Password',
|
| 1215 |
-
'type' => 'text',
|
| 1216 |
-
'alias' => array( 'password', 'pass' ),
|
| 1217 |
-
'options' => array(
|
| 1218 |
-
'required' => 1,
|
| 1219 |
-
'text_format_type' => 'password'
|
| 1220 |
-
)
|
| 1221 |
-
),
|
| 1222 |
-
'user_email' => array(
|
| 1223 |
-
'name' => 'user_email',
|
| 1224 |
-
'label' => 'E-mail',
|
| 1225 |
-
'type' => 'text',
|
| 1226 |
-
'alias' => array( 'email' ),
|
| 1227 |
-
'options' => array(
|
| 1228 |
-
'required' => 1,
|
| 1229 |
-
'text_format_type' => 'email'
|
| 1230 |
-
)
|
| 1231 |
-
),
|
| 1232 |
-
'user_url' => array(
|
| 1233 |
-
'name' => 'user_url',
|
| 1234 |
-
'label' => 'URL',
|
| 1235 |
-
'type' => 'text',
|
| 1236 |
-
'alias' => array( 'url', 'website' ),
|
| 1237 |
-
'options' => array(
|
| 1238 |
-
'required' => 0,
|
| 1239 |
-
'text_format_type' => 'website',
|
| 1240 |
-
'text_format_website' => 'normal'
|
| 1241 |
-
)
|
| 1242 |
-
),
|
| 1243 |
-
'user_registered' => array(
|
| 1244 |
-
'name' => 'user_registered',
|
| 1245 |
-
'label' => 'Registration Date',
|
| 1246 |
-
'type' => 'date',
|
| 1247 |
-
'alias' => array( 'created', 'date', 'registered' ),
|
| 1248 |
-
'options' => array(
|
| 1249 |
-
'date_format_type' => 'datetime'
|
| 1250 |
-
)
|
| 1251 |
-
)
|
| 1252 |
-
);
|
| 1253 |
-
} elseif ( 'comment' === $object ) {
|
| 1254 |
-
$fields = array(
|
| 1255 |
-
'comment_ID' => array(
|
| 1256 |
-
'name' => 'comment_ID',
|
| 1257 |
-
'label' => 'ID',
|
| 1258 |
-
'type' => 'number',
|
| 1259 |
-
'alias' => array( 'id', 'ID', 'comment_id' ),
|
| 1260 |
-
'options' => array(
|
| 1261 |
-
'number_format' => '9999.99'
|
| 1262 |
-
)
|
| 1263 |
-
),
|
| 1264 |
-
'comment_content' => array(
|
| 1265 |
-
'name' => 'comment_content',
|
| 1266 |
-
'label' => 'Content',
|
| 1267 |
-
'type' => 'wysiwyg',
|
| 1268 |
-
'alias' => array( 'content' )
|
| 1269 |
-
),
|
| 1270 |
-
'comment_approved' => array(
|
| 1271 |
-
'name' => 'comment_approved',
|
| 1272 |
-
'label' => 'Approved',
|
| 1273 |
-
'type' => 'number',
|
| 1274 |
-
'alias' => array( 'approved' ),
|
| 1275 |
-
'options' => array(
|
| 1276 |
-
'number_format' => '9999.99'
|
| 1277 |
-
)
|
| 1278 |
-
),
|
| 1279 |
-
'comment_post_ID' => array(
|
| 1280 |
-
'name' => 'comment_post_ID',
|
| 1281 |
-
'label' => 'Post',
|
| 1282 |
-
'type' => 'pick',
|
| 1283 |
-
'alias' => array( 'post', 'post_id' ),
|
| 1284 |
-
'data' => array()
|
| 1285 |
-
),
|
| 1286 |
-
'user_id' => array(
|
| 1287 |
-
'name' => 'user_id',
|
| 1288 |
-
'label' => 'Author',
|
| 1289 |
-
'type' => 'pick',
|
| 1290 |
-
'alias' => array( 'author' ),
|
| 1291 |
-
'pick_object' => 'user',
|
| 1292 |
-
'data' => array()
|
| 1293 |
-
),
|
| 1294 |
-
'comment_date' => array(
|
| 1295 |
-
'name' => 'comment_date',
|
| 1296 |
-
'label' => 'Date',
|
| 1297 |
-
'type' => 'date',
|
| 1298 |
-
'alias' => array( 'created', 'date' ),
|
| 1299 |
-
'options' => array(
|
| 1300 |
-
'date_format_type' => 'datetime'
|
| 1301 |
-
)
|
| 1302 |
-
),
|
| 1303 |
-
'comment_author' => array(
|
| 1304 |
-
'name' => 'comment_author',
|
| 1305 |
-
'label' => 'Author',
|
| 1306 |
-
'type' => 'text',
|
| 1307 |
-
'alias' => array( 'author' )
|
| 1308 |
-
),
|
| 1309 |
-
'comment_author_email' => array(
|
| 1310 |
-
'name' => 'comment_author_email',
|
| 1311 |
-
'label' => 'Author E-mail',
|
| 1312 |
-
'type' => 'email',
|
| 1313 |
-
'alias' => array( 'author_email' )
|
| 1314 |
-
),
|
| 1315 |
-
'comment_author_url' => array(
|
| 1316 |
-
'name' => 'comment_author_url',
|
| 1317 |
-
'label' => 'Author URL',
|
| 1318 |
-
'type' => 'text',
|
| 1319 |
-
'alias' => array( 'author_url' )
|
| 1320 |
-
),
|
| 1321 |
-
'comment_author_IP' => array(
|
| 1322 |
-
'name' => 'comment_author_IP',
|
| 1323 |
-
'label' => 'Author IP',
|
| 1324 |
-
'type' => 'text',
|
| 1325 |
-
'alias' => array( 'author_IP' )
|
| 1326 |
-
),
|
| 1327 |
-
'comment_type' => array(
|
| 1328 |
-
'name' => 'comment_type',
|
| 1329 |
-
'label' => 'Type',
|
| 1330 |
-
'type' => 'text',
|
| 1331 |
-
'alias' => array( 'type' ),
|
| 1332 |
-
'hidden' => true
|
| 1333 |
-
),
|
| 1334 |
-
'comment_parent' => array(
|
| 1335 |
-
'name' => 'comment_parent',
|
| 1336 |
-
'label' => 'Parent',
|
| 1337 |
-
'type' => 'pick',
|
| 1338 |
-
'pick_object' => 'comment',
|
| 1339 |
-
'pick_val' => '__current__',
|
| 1340 |
-
'alias' => array( 'parent' ),
|
| 1341 |
-
'data' => array(),
|
| 1342 |
-
'hidden' => true
|
| 1343 |
-
)
|
| 1344 |
-
);
|
| 1345 |
-
} elseif ( 'taxonomy' === $object ) {
|
| 1346 |
-
$fields = array(
|
| 1347 |
-
'term_id' => array(
|
| 1348 |
-
'name' => 'term_id',
|
| 1349 |
-
'label' => 'ID',
|
| 1350 |
-
'type' => 'number',
|
| 1351 |
-
'alias' => array( 'id', 'ID' ),
|
| 1352 |
-
'options' => array(
|
| 1353 |
-
'number_format' => '9999.99'
|
| 1354 |
-
)
|
| 1355 |
-
),
|
| 1356 |
-
'name' => array(
|
| 1357 |
-
'name' => 'name',
|
| 1358 |
-
'label' => 'Title',
|
| 1359 |
-
'type' => 'text',
|
| 1360 |
-
'alias' => array( 'title' )
|
| 1361 |
-
),
|
| 1362 |
-
'slug' => array(
|
| 1363 |
-
'name' => 'slug',
|
| 1364 |
-
'label' => 'Permalink',
|
| 1365 |
-
'type' => 'slug',
|
| 1366 |
-
'alias' => array( 'permalink' )
|
| 1367 |
-
),
|
| 1368 |
-
'description' => array(
|
| 1369 |
-
'name' => 'description',
|
| 1370 |
-
'label' => 'Description',
|
| 1371 |
-
'type' => 'wysiwyg',
|
| 1372 |
-
'alias' => array( 'content' )
|
| 1373 |
-
),
|
| 1374 |
-
'taxonomy' => array(
|
| 1375 |
-
'name' => 'taxonomy',
|
| 1376 |
-
'label' => 'Taxonomy',
|
| 1377 |
-
'type' => 'text',
|
| 1378 |
-
'alias' => array()
|
| 1379 |
-
),
|
| 1380 |
-
'parent' => array(
|
| 1381 |
-
'name' => 'parent',
|
| 1382 |
-
'label' => 'Parent',
|
| 1383 |
-
'type' => 'pick',
|
| 1384 |
-
'pick_object' => 'taxonomy',
|
| 1385 |
-
'pick_val' => '__current__',
|
| 1386 |
-
'alias' => array( 'parent' ),
|
| 1387 |
-
'data' => array(),
|
| 1388 |
-
'hidden' => true
|
| 1389 |
-
),
|
| 1390 |
-
'term_taxonomy_id' => array(
|
| 1391 |
-
'name' => 'term_taxonomy_id',
|
| 1392 |
-
'label' => 'Term Taxonomy ID',
|
| 1393 |
-
'type' => 'number',
|
| 1394 |
-
'alias' => array(),
|
| 1395 |
-
'hidden' => true,
|
| 1396 |
-
'options' => array(
|
| 1397 |
-
'number_format' => '9999.99'
|
| 1398 |
-
)
|
| 1399 |
-
),
|
| 1400 |
-
'term_group' => array(
|
| 1401 |
-
'name' => 'term_group',
|
| 1402 |
-
'label' => 'Term Group',
|
| 1403 |
-
'type' => 'number',
|
| 1404 |
-
'alias' => array( 'group' ),
|
| 1405 |
-
'hidden' => true,
|
| 1406 |
-
'options' => array(
|
| 1407 |
-
'number_format' => '9999.99'
|
| 1408 |
-
)
|
| 1409 |
-
),
|
| 1410 |
-
'count' => array(
|
| 1411 |
-
'name' => 'count',
|
| 1412 |
-
'label' => 'Count',
|
| 1413 |
-
'type' => 'number',
|
| 1414 |
-
'alias' => array(),
|
| 1415 |
-
'hidden' => true,
|
| 1416 |
-
'options' => array(
|
| 1417 |
-
'number_format' => '9999.99'
|
| 1418 |
-
)
|
| 1419 |
-
)
|
| 1420 |
-
);
|
| 1421 |
-
}
|
| 1422 |
|
| 1423 |
-
|
|
|
|
|
|
|
|
|
|
| 1424 |
|
| 1425 |
-
|
| 1426 |
-
|
| 1427 |
-
|
| 1428 |
-
|
| 1429 |
-
|
| 1430 |
-
}
|
| 1431 |
|
| 1432 |
-
|
| 1433 |
-
|
| 1434 |
-
}
|
| 1435 |
|
| 1436 |
-
|
| 1437 |
-
|
| 1438 |
|
| 1439 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1440 |
|
| 1441 |
-
if (
|
| 1442 |
-
|
| 1443 |
}
|
| 1444 |
|
| 1445 |
-
|
| 1446 |
-
}
|
| 1447 |
-
|
| 1448 |
-
/**
|
| 1449 |
-
*
|
| 1450 |
-
* @see PodsAPI::save_pod
|
| 1451 |
-
*
|
| 1452 |
-
* Add a Pod via the Wizard
|
| 1453 |
-
*
|
| 1454 |
-
* $params['create_extend'] string Create or Extend a Content Type
|
| 1455 |
-
* $params['create_pod_type'] string Pod Type (for Creating)
|
| 1456 |
-
* $params['create_name'] string Pod Name (for Creating)
|
| 1457 |
-
* $params['create_label_plural'] string Plural Label (for Creating)
|
| 1458 |
-
* $params['create_label_singular'] string Singular Label (for Creating)
|
| 1459 |
-
* $params['create_storage'] string Storage Type (for Creating Post Types)
|
| 1460 |
-
* $params['create_storage_taxonomy'] string Storage Type (for Creating Taxonomies)
|
| 1461 |
-
* $params['extend_pod_type'] string Pod Type (for Extending)
|
| 1462 |
-
* $params['extend_post_type'] string Post Type (for Extending Post Types)
|
| 1463 |
-
* $params['extend_taxonomy'] string Taxonomy (for Extending Taxonomies)
|
| 1464 |
-
* $params['extend_storage'] string Storage Type (for Extending Post Types / Users / Comments)
|
| 1465 |
-
*
|
| 1466 |
-
* @param array $params An associative array of parameters
|
| 1467 |
-
*
|
| 1468 |
-
* @return bool|int Pod ID
|
| 1469 |
-
* @since 2.0.0
|
| 1470 |
-
*/
|
| 1471 |
-
public function add_pod( $params ) {
|
| 1472 |
-
|
| 1473 |
-
$defaults = array(
|
| 1474 |
-
'create_extend' => 'create',
|
| 1475 |
-
'create_pod_type' => 'post_type',
|
| 1476 |
-
|
| 1477 |
-
'create_name' => '',
|
| 1478 |
-
'create_label_singular' => '',
|
| 1479 |
-
'create_label_plural' => '',
|
| 1480 |
-
'create_storage' => 'meta',
|
| 1481 |
-
'create_storage_taxonomy' => '',
|
| 1482 |
-
|
| 1483 |
-
'create_setting_name' => '',
|
| 1484 |
-
'create_label_title' => '',
|
| 1485 |
-
'create_label_menu' => '',
|
| 1486 |
-
'create_menu_location' => 'settings',
|
| 1487 |
-
|
| 1488 |
-
'extend_pod_type' => 'post_type',
|
| 1489 |
-
'extend_post_type' => 'post',
|
| 1490 |
-
'extend_taxonomy' => 'category',
|
| 1491 |
-
'extend_table' => '',
|
| 1492 |
-
'extend_storage' => 'meta',
|
| 1493 |
-
'extend_storage_taxonomy' => '',
|
| 1494 |
-
);
|
| 1495 |
|
| 1496 |
-
|
| 1497 |
-
$defaults['create_storage_taxonomy'] = 'none';
|
| 1498 |
-
$defaults['extend_storage_taxonomy' ] = 'table' ;
|
| 1499 |
-
}
|
| 1500 |
|
| 1501 |
-
|
| 1502 |
|
| 1503 |
-
|
| 1504 |
-
|
| 1505 |
-
}
|
| 1506 |
|
| 1507 |
-
|
| 1508 |
-
'name' => '',
|
| 1509 |
-
'label' => '',
|
| 1510 |
-
'type' => '',
|
| 1511 |
-
'storage' => 'table',
|
| 1512 |
-
'object' => '',
|
| 1513 |
-
'options' => array(),
|
| 1514 |
-
'create_extend' => $params->create_extend,
|
| 1515 |
-
);
|
| 1516 |
|
| 1517 |
-
|
| 1518 |
-
|
|
|
|
|
|
|
| 1519 |
|
| 1520 |
-
|
| 1521 |
-
$label = $params->create_label_singular;
|
| 1522 |
-
}
|
| 1523 |
|
| 1524 |
-
|
| 1525 |
-
|
| 1526 |
-
|
| 1527 |
-
|
| 1528 |
-
|
| 1529 |
-
|
| 1530 |
-
|
| 1531 |
-
|
| 1532 |
|
| 1533 |
-
|
| 1534 |
-
|
| 1535 |
-
|
| 1536 |
-
}
|
| 1537 |
|
| 1538 |
-
|
| 1539 |
-
|
| 1540 |
-
|
| 1541 |
-
|
|
|
|
|
|
|
| 1542 |
|
| 1543 |
-
|
|
|
|
|
|
|
|
|
|
| 1544 |
|
| 1545 |
-
|
| 1546 |
-
|
| 1547 |
-
|
| 1548 |
-
} elseif ( 'taxonomy' === $pod_params['type'] ) {
|
| 1549 |
-
if ( empty( $pod_params['name'] ) ) {
|
| 1550 |
-
return pods_error( __( 'Please enter a Name for this Pod', 'pods' ), $this );
|
| 1551 |
-
}
|
| 1552 |
|
| 1553 |
-
|
| 1554 |
|
| 1555 |
-
|
| 1556 |
-
$pod_params['storage'] = $params->create_storage_taxonomy;
|
| 1557 |
-
}
|
| 1558 |
|
| 1559 |
-
|
| 1560 |
-
|
|
|
|
| 1561 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1562 |
|
| 1563 |
-
|
| 1564 |
-
|
| 1565 |
-
|
| 1566 |
-
return pods_error( __( 'Please enter a Name for this Pod', 'pod' ), $this );
|
| 1567 |
}
|
| 1568 |
-
|
| 1569 |
-
|
| 1570 |
-
$pod_params['type'] = 'post_type';
|
| 1571 |
-
$pod_params['storage'] = 'meta';
|
| 1572 |
}
|
| 1573 |
-
|
| 1574 |
-
|
| 1575 |
-
$pod_params['label'] = ( ! empty( $params->create_label_title ) ? $params->create_label_title : ucwords( str_replace( '_', ' ', $params->create_setting_name ) ) );
|
| 1576 |
-
$pod_params['options'] = array(
|
| 1577 |
-
'menu_name' => ( ! empty( $params->create_label_menu ) ? $params->create_label_menu : $pod_params['label'] ),
|
| 1578 |
-
'menu_location' => $params->create_menu_location
|
| 1579 |
-
);
|
| 1580 |
-
$pod_params['storage'] = 'none';
|
| 1581 |
-
|
| 1582 |
-
// Auto-generate name if not provided
|
| 1583 |
-
if ( empty( $pod_params['name'] ) && ! empty( $pod_params['label'] ) ) {
|
| 1584 |
-
$pod_params['name'] = pods_clean_name( $pod_params['label'] );
|
| 1585 |
}
|
| 1586 |
|
| 1587 |
-
|
| 1588 |
-
return pods_error( __( 'Please enter a Name for this Pod', 'pods' ), $this );
|
| 1589 |
-
}
|
| 1590 |
}
|
| 1591 |
-
} elseif ( 'extend' === $params->create_extend ) {
|
| 1592 |
-
$pod_params['type'] = $params->extend_pod_type;
|
| 1593 |
|
| 1594 |
-
|
| 1595 |
-
$pod_params['storage'] = $params->extend_storage;
|
| 1596 |
|
| 1597 |
-
|
| 1598 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1599 |
}
|
| 1600 |
|
| 1601 |
-
|
| 1602 |
-
|
| 1603 |
-
$pod_params['storage'] = $params->extend_storage;
|
| 1604 |
|
| 1605 |
-
|
| 1606 |
-
|
| 1607 |
-
}
|
| 1608 |
|
| 1609 |
-
|
| 1610 |
-
|
| 1611 |
-
|
| 1612 |
|
| 1613 |
-
|
| 1614 |
-
|
| 1615 |
-
|
| 1616 |
-
|
| 1617 |
-
|
| 1618 |
-
$pod_params['storage'] = $params->extend_storage;
|
| 1619 |
|
| 1620 |
-
|
| 1621 |
-
|
| 1622 |
-
}
|
| 1623 |
|
| 1624 |
-
|
| 1625 |
-
|
| 1626 |
|
| 1627 |
-
|
| 1628 |
-
$pod_params['object'] = $pod_params['name'];
|
| 1629 |
-
}
|
| 1630 |
|
| 1631 |
-
|
| 1632 |
-
|
| 1633 |
-
|
|
|
|
|
|
|
| 1634 |
|
| 1635 |
-
|
| 1636 |
-
return pods_error( sprintf( __( 'Post Type %s already exists, try extending it instead', 'pods' ), $pod_params['name'] ), $this );
|
| 1637 |
-
}
|
| 1638 |
|
| 1639 |
-
|
| 1640 |
-
|
| 1641 |
-
|
| 1642 |
-
|
| 1643 |
|
| 1644 |
-
|
| 1645 |
-
|
| 1646 |
-
|
| 1647 |
-
|
| 1648 |
-
}
|
| 1649 |
|
| 1650 |
-
|
| 1651 |
-
|
|
|
|
|
|
|
|
|
|
| 1652 |
}
|
| 1653 |
|
| 1654 |
-
|
| 1655 |
-
}
|
| 1656 |
|
| 1657 |
-
|
| 1658 |
-
|
| 1659 |
-
*
|
| 1660 |
-
* $params['id'] int The Pod ID
|
| 1661 |
-
* $params['name'] string The Pod name
|
| 1662 |
-
* $params['label'] string The Pod label
|
| 1663 |
-
* $params['type'] string The Pod type
|
| 1664 |
-
* $params['object'] string The object being extended (if any)
|
| 1665 |
-
* $params['storage'] string The Pod storage
|
| 1666 |
-
* $params['options'] array Options
|
| 1667 |
-
* $params['create_extend'] string Create or Extend a Content Type
|
| 1668 |
-
*
|
| 1669 |
-
* @param array $params An associative array of parameters
|
| 1670 |
-
* @param bool $sanitized (optional) Decides whether the params have been sanitized before being passed, will
|
| 1671 |
-
* sanitize them if false.
|
| 1672 |
-
* @param bool|int $db (optional) Whether to save into the DB or just return Pod array.
|
| 1673 |
-
*
|
| 1674 |
-
* @return int Pod ID
|
| 1675 |
-
* @since 1.7.9
|
| 1676 |
-
*/
|
| 1677 |
-
public function save_pod( $params, $sanitized = false, $db = true ) {
|
| 1678 |
|
| 1679 |
-
|
| 1680 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1681 |
|
| 1682 |
-
|
| 1683 |
-
|
| 1684 |
|
| 1685 |
-
|
|
|
|
|
|
|
| 1686 |
|
| 1687 |
-
|
| 1688 |
-
|
| 1689 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1690 |
|
| 1691 |
-
|
| 1692 |
-
$load_params->name = $load_params->old_name;
|
| 1693 |
-
}
|
| 1694 |
|
| 1695 |
-
|
|
|
|
| 1696 |
|
| 1697 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1698 |
|
| 1699 |
-
|
|
|
|
| 1700 |
|
| 1701 |
-
|
| 1702 |
-
|
| 1703 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1704 |
|
| 1705 |
-
|
| 1706 |
-
|
| 1707 |
-
|
|
|
|
|
|
|
|
|
|
| 1708 |
|
| 1709 |
-
|
| 1710 |
-
$old_options = array();
|
| 1711 |
|
| 1712 |
-
|
| 1713 |
-
|
| 1714 |
-
|
| 1715 |
|
| 1716 |
-
|
| 1717 |
-
|
| 1718 |
|
| 1719 |
-
|
| 1720 |
-
|
| 1721 |
-
}
|
| 1722 |
|
| 1723 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1724 |
|
| 1725 |
-
|
| 1726 |
-
|
| 1727 |
-
|
| 1728 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1729 |
|
| 1730 |
-
|
| 1731 |
-
|
| 1732 |
-
|
| 1733 |
-
}
|
| 1734 |
|
| 1735 |
-
|
| 1736 |
-
if ( false !== $this->pod_exists( array( 'name' => $params->name ) ) ) {
|
| 1737 |
-
return pods_error( sprintf( __( 'Pod %1$s already exists, you cannot rename %2$s to that', 'pods' ), $params->name, $old_name ), $this );
|
| 1738 |
-
}
|
| 1739 |
|
| 1740 |
-
|
| 1741 |
-
|
| 1742 |
-
&& in_array( $pod['object'], array( 'user', 'comment', 'media' ), true )
|
| 1743 |
-
) {
|
| 1744 |
-
return pods_error( sprintf( __( 'Pod %s cannot be renamed, it extends an existing WP Object', 'pods' ), $old_name ), $this );
|
| 1745 |
-
}
|
| 1746 |
|
| 1747 |
-
|
| 1748 |
-
|
| 1749 |
-
|
| 1750 |
-
|
| 1751 |
-
|
| 1752 |
-
|
| 1753 |
-
|
| 1754 |
-
|
| 1755 |
|
| 1756 |
-
|
| 1757 |
-
|
| 1758 |
-
|
| 1759 |
-
} else {
|
| 1760 |
-
return pods_error( sprintf( __( 'Pod %s already exists', 'pods' ), $params->name ), $this );
|
| 1761 |
-
}
|
| 1762 |
-
}
|
| 1763 |
-
} else {
|
| 1764 |
-
// New pod (create).
|
| 1765 |
-
|
| 1766 |
-
if (
|
| 1767 |
-
in_array( $params->name, pods_reserved_keywords(), true )
|
| 1768 |
-
&& in_array( pods_v( 'type', $params ), array( 'post_type', 'taxonomy' ), true )
|
| 1769 |
-
) {
|
| 1770 |
-
$valid_name = false;
|
| 1771 |
-
|
| 1772 |
-
// Only if it's extending an existing content type then these
|
| 1773 |
-
// names are still allowed, even if they are reserved.
|
| 1774 |
-
if ( $extend ) {
|
| 1775 |
-
if ( 'post_type' === pods_v( 'type', $params ) ) {
|
| 1776 |
-
$valid_name = in_array( $params->name, get_post_types(), true );
|
| 1777 |
-
} elseif ( 'taxonomy' === pods_v( 'type', $params ) ) {
|
| 1778 |
-
$valid_name = in_array( $params->name, get_taxonomies(), true );
|
| 1779 |
-
}
|
| 1780 |
-
}
|
| 1781 |
|
| 1782 |
-
|
| 1783 |
-
|
| 1784 |
-
|
| 1785 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1786 |
|
| 1787 |
-
|
| 1788 |
-
|
| 1789 |
-
'name' => $params->name,
|
| 1790 |
-
'label' => $params->name,
|
| 1791 |
-
'description' => '',
|
| 1792 |
-
'type' => 'pod',
|
| 1793 |
-
'storage' => 'table',
|
| 1794 |
-
'object' => '',
|
| 1795 |
-
'alias' => '',
|
| 1796 |
-
'options' => array(),
|
| 1797 |
-
'fields' => array(),
|
| 1798 |
-
);
|
| 1799 |
-
}
|
| 1800 |
-
|
| 1801 |
-
// Blank out fields and options for AJAX calls (everything should be sent to it for a full overwrite)
|
| 1802 |
-
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
|
| 1803 |
-
$pod['fields'] = array();
|
| 1804 |
-
$pod['options'] = array();
|
| 1805 |
-
}
|
| 1806 |
-
|
| 1807 |
-
// Setup options
|
| 1808 |
-
$options = get_object_vars( $params );
|
| 1809 |
-
|
| 1810 |
-
if ( isset( $options['method'] ) ) {
|
| 1811 |
-
unset( $options['method'] );
|
| 1812 |
-
}
|
| 1813 |
-
|
| 1814 |
-
$options_ignore = array(
|
| 1815 |
-
'object_type',
|
| 1816 |
-
'object_name',
|
| 1817 |
-
'table',
|
| 1818 |
-
'meta_table',
|
| 1819 |
-
'pod_table',
|
| 1820 |
-
'field_id',
|
| 1821 |
-
'field_index',
|
| 1822 |
-
'field_slug',
|
| 1823 |
-
'field_type',
|
| 1824 |
-
'field_parent',
|
| 1825 |
-
'field_parent_select',
|
| 1826 |
-
'meta_field_id',
|
| 1827 |
-
'meta_field_index',
|
| 1828 |
-
'meta_field_value',
|
| 1829 |
-
'pod_field_id',
|
| 1830 |
-
'pod_field_index',
|
| 1831 |
-
'object_fields',
|
| 1832 |
-
'join',
|
| 1833 |
-
'where',
|
| 1834 |
-
'where_default',
|
| 1835 |
-
'orderby',
|
| 1836 |
-
'pod',
|
| 1837 |
-
'recurse',
|
| 1838 |
-
'table_info',
|
| 1839 |
-
'attributes',
|
| 1840 |
-
'group',
|
| 1841 |
-
'grouped',
|
| 1842 |
-
'developer_mode',
|
| 1843 |
-
'dependency',
|
| 1844 |
-
'depends-on',
|
| 1845 |
-
'excludes-on'
|
| 1846 |
-
);
|
| 1847 |
-
|
| 1848 |
-
foreach ( $options_ignore as $ignore ) {
|
| 1849 |
-
if ( isset( $options[ $ignore ] ) ) {
|
| 1850 |
-
unset( $options[ $ignore ] );
|
| 1851 |
-
}
|
| 1852 |
-
}
|
| 1853 |
-
|
| 1854 |
-
$exclude = array(
|
| 1855 |
-
'id',
|
| 1856 |
-
'name',
|
| 1857 |
-
'label',
|
| 1858 |
-
'description',
|
| 1859 |
-
'type',
|
| 1860 |
-
'storage',
|
| 1861 |
-
'object',
|
| 1862 |
-
'alias',
|
| 1863 |
-
'options',
|
| 1864 |
-
'fields'
|
| 1865 |
-
);
|
| 1866 |
-
|
| 1867 |
-
foreach ( $exclude as $k => $exclude_field ) {
|
| 1868 |
-
$aliases = array( $exclude_field );
|
| 1869 |
-
|
| 1870 |
-
if ( is_array( $exclude_field ) ) {
|
| 1871 |
-
$aliases = array_merge( array( $k ), $exclude_field );
|
| 1872 |
-
$exclude_field = $k;
|
| 1873 |
-
}
|
| 1874 |
-
|
| 1875 |
-
foreach ( $aliases as $alias ) {
|
| 1876 |
-
if ( isset( $options[ $alias ] ) ) {
|
| 1877 |
-
$pod[ $exclude_field ] = pods_trim( $options[ $alias ] );
|
| 1878 |
-
|
| 1879 |
-
unset( $options[ $alias ] );
|
| 1880 |
-
}
|
| 1881 |
-
}
|
| 1882 |
-
}
|
| 1883 |
-
|
| 1884 |
-
if ( pods_tableless() && ! in_array( $pod['type'], array( 'settings', 'table' ) ) ) {
|
| 1885 |
-
if ( 'pod' === $pod['type'] ) {
|
| 1886 |
-
$pod['type'] = 'post_type';
|
| 1887 |
-
}
|
| 1888 |
-
|
| 1889 |
-
if ( 'table' === $pod['storage'] ) {
|
| 1890 |
-
if ( 'taxonomy' === $pod['type'] && ! function_exists( 'get_term_meta' ) ) {
|
| 1891 |
-
$pod['storage'] = 'none';
|
| 1892 |
-
} else {
|
| 1893 |
-
$pod['storage'] = 'meta';
|
| 1894 |
-
}
|
| 1895 |
-
}
|
| 1896 |
-
}
|
| 1897 |
-
|
| 1898 |
-
$pod['options']['type'] = $pod['type'];
|
| 1899 |
-
$pod['options']['storage'] = $pod['storage'];
|
| 1900 |
-
$pod['options']['object'] = $pod['object'];
|
| 1901 |
-
$pod['options']['alias'] = $pod['alias'];
|
| 1902 |
-
|
| 1903 |
-
$pod['options'] = array_merge( $pod['options'], $options );
|
| 1904 |
-
|
| 1905 |
-
/**
|
| 1906 |
-
* @var WP_Query
|
| 1907 |
-
*/
|
| 1908 |
-
global $wp_query;
|
| 1909 |
-
|
| 1910 |
-
$reserved_query_vars = array(
|
| 1911 |
-
'post_type',
|
| 1912 |
-
'taxonomy',
|
| 1913 |
-
'output'
|
| 1914 |
-
);
|
| 1915 |
-
|
| 1916 |
-
if ( is_object( $wp_query ) ) {
|
| 1917 |
-
$reserved_query_vars = array_merge( $reserved_query_vars, array_keys( $wp_query->fill_query_vars( array() ) ) );
|
| 1918 |
-
}
|
| 1919 |
-
|
| 1920 |
-
if ( isset( $pod['options']['query_var_string'] ) ) {
|
| 1921 |
-
if ( in_array( $pod['options']['query_var_string'], $reserved_query_vars ) ) {
|
| 1922 |
-
$pod['options']['query_var_string'] = $pod['options']['type'] . '_' . $pod['options']['query_var_string'];
|
| 1923 |
-
}
|
| 1924 |
-
}
|
| 1925 |
-
|
| 1926 |
-
if ( isset( $pod['options']['query_var'] ) ) {
|
| 1927 |
-
if ( in_array( $pod['options']['query_var'], $reserved_query_vars ) ) {
|
| 1928 |
-
$pod['options']['query_var'] = $pod['options']['type'] . '_' . $pod['options']['query_var'];
|
| 1929 |
-
}
|
| 1930 |
-
}
|
| 1931 |
-
|
| 1932 |
-
if ( strlen( $pod['label'] ) < 1 ) {
|
| 1933 |
-
$pod['label'] = $pod['name'];
|
| 1934 |
-
}
|
| 1935 |
-
|
| 1936 |
-
if ( 'post_type' === $pod['type'] ) {
|
| 1937 |
-
// Max length for post types are 20 characters
|
| 1938 |
-
$pod['name'] = substr( $pod['name'], 0, 20 );
|
| 1939 |
-
} elseif ( 'taxonomy' === $pod['type'] ) {
|
| 1940 |
-
// Max length for taxonomies are 32 characters
|
| 1941 |
-
$pod['name'] = substr( $pod['name'], 0, 32 );
|
| 1942 |
-
}
|
| 1943 |
-
|
| 1944 |
-
$params->id = $pod['id'];
|
| 1945 |
-
$params->name = $pod['name'];
|
| 1946 |
-
|
| 1947 |
-
if ( null !== $old_name && $old_name !== $params->name && empty( $pod['object'] ) ) {
|
| 1948 |
-
if ( 'post_type' === $pod['type'] ) {
|
| 1949 |
-
$check = get_post_type_object( $params->name );
|
| 1950 |
-
|
| 1951 |
-
if ( ! empty( $check ) ) {
|
| 1952 |
-
return pods_error( sprintf( __( 'Post Type %1$s already exists, you cannot rename %2$s to that', 'pods' ), $params->name, $old_name ), $this );
|
| 1953 |
-
}
|
| 1954 |
-
} elseif ( 'taxonomy' === $pod['type'] ) {
|
| 1955 |
-
$check = get_taxonomy( $params->name );
|
| 1956 |
-
|
| 1957 |
-
if ( ! empty( $check ) ) {
|
| 1958 |
-
return pods_error( sprintf( __( 'Taxonomy %1$s already exists, you cannot rename %2$s to that', 'pods' ), $params->name, $old_name ), $this );
|
| 1959 |
-
}
|
| 1960 |
-
}
|
| 1961 |
-
}
|
| 1962 |
-
|
| 1963 |
-
$field_table_operation = true;
|
| 1964 |
-
|
| 1965 |
-
// Add new pod
|
| 1966 |
-
if ( empty( $params->id ) ) {
|
| 1967 |
-
if ( strlen( $params->name ) < 1 ) {
|
| 1968 |
-
return pods_error( __( 'Pod name cannot be empty', 'pods' ), $this );
|
| 1969 |
-
}
|
| 1970 |
-
|
| 1971 |
-
$post_data = array(
|
| 1972 |
-
'post_name' => $pod['name'],
|
| 1973 |
-
'post_title' => $pod['label'],
|
| 1974 |
-
'post_content' => $pod['description'],
|
| 1975 |
-
'post_type' => '_pods_pod',
|
| 1976 |
-
'post_status' => 'publish'
|
| 1977 |
-
);
|
| 1978 |
-
|
| 1979 |
-
if ( 'pod' === $pod['type'] && ( ! is_array( $pod['fields'] ) || empty( $pod['fields'] ) ) ) {
|
| 1980 |
-
$pod['fields'] = array();
|
| 1981 |
-
|
| 1982 |
-
$pod['fields']['name'] = array(
|
| 1983 |
-
'name' => 'name',
|
| 1984 |
-
'label' => 'Name',
|
| 1985 |
-
'type' => 'text',
|
| 1986 |
-
'options' => array(
|
| 1987 |
-
'required' => '1'
|
| 1988 |
-
)
|
| 1989 |
-
);
|
| 1990 |
-
|
| 1991 |
-
$pod['fields']['created'] = array(
|
| 1992 |
-
'name' => 'created',
|
| 1993 |
-
'label' => 'Date Created',
|
| 1994 |
-
'type' => 'datetime',
|
| 1995 |
-
'options' => array(
|
| 1996 |
-
'datetime_format' => 'ymd_slash',
|
| 1997 |
-
'datetime_time_type' => '12',
|
| 1998 |
-
'datetime_time_format' => 'h_mm_ss_A'
|
| 1999 |
-
)
|
| 2000 |
-
);
|
| 2001 |
-
|
| 2002 |
-
$pod['fields']['modified'] = array(
|
| 2003 |
-
'name' => 'modified',
|
| 2004 |
-
'label' => 'Date Modified',
|
| 2005 |
-
'type' => 'datetime',
|
| 2006 |
-
'options' => array(
|
| 2007 |
-
'datetime_format' => 'ymd_slash',
|
| 2008 |
-
'datetime_time_type' => '12',
|
| 2009 |
-
'datetime_time_format' => 'h_mm_ss_A'
|
| 2010 |
-
)
|
| 2011 |
-
);
|
| 2012 |
-
|
| 2013 |
-
$pod['fields']['author'] = array(
|
| 2014 |
-
'name' => 'author',
|
| 2015 |
-
'label' => 'Author',
|
| 2016 |
-
'type' => 'pick',
|
| 2017 |
-
'pick_object' => 'user',
|
| 2018 |
-
'options' => array(
|
| 2019 |
-
'pick_format_type' => 'single',
|
| 2020 |
-
'pick_format_single' => 'autocomplete',
|
| 2021 |
-
'default_value' => '{@user.ID}'
|
| 2022 |
-
)
|
| 2023 |
-
);
|
| 2024 |
-
|
| 2025 |
-
$pod['fields']['permalink'] = array(
|
| 2026 |
-
'name' => 'permalink',
|
| 2027 |
-
'label' => 'Permalink',
|
| 2028 |
-
'type' => 'slug',
|
| 2029 |
-
'description' => 'Leave blank to auto-generate from Name'
|
| 2030 |
-
);
|
| 2031 |
-
|
| 2032 |
-
if ( ! isset( $pod['options']['pod_index'] ) ) {
|
| 2033 |
-
$pod['options']['pod_index'] = 'name';
|
| 2034 |
-
}
|
| 2035 |
-
}
|
| 2036 |
-
|
| 2037 |
-
$pod = $this->do_hook( 'save_pod_default_pod', $pod, $params, $sanitized, $db );
|
| 2038 |
-
|
| 2039 |
-
$field_table_operation = false;
|
| 2040 |
-
} else {
|
| 2041 |
-
$post_data = array(
|
| 2042 |
-
'ID' => $pod['id'],
|
| 2043 |
-
'post_name' => $pod['name'],
|
| 2044 |
-
'post_title' => $pod['label'],
|
| 2045 |
-
'post_content' => $pod['description'],
|
| 2046 |
-
'post_status' => 'publish'
|
| 2047 |
-
);
|
| 2048 |
-
}
|
| 2049 |
-
|
| 2050 |
-
if ( true === $db ) {
|
| 2051 |
-
if ( ! has_filter( 'wp_unique_post_slug', array( $this, 'save_slug_fix' ) ) ) {
|
| 2052 |
-
add_filter( 'wp_unique_post_slug', array( $this, 'save_slug_fix' ), 100, 6 );
|
| 2053 |
-
}
|
| 2054 |
-
|
| 2055 |
-
$conflicted = false;
|
| 2056 |
-
|
| 2057 |
-
// Headway compatibility fix
|
| 2058 |
-
if ( has_filter( 'wp_insert_post_data', 'headway_clean_slug', 0 ) ) {
|
| 2059 |
-
remove_filter( 'wp_insert_post_data', 'headway_clean_slug', 0 );
|
| 2060 |
-
|
| 2061 |
-
$conflicted = true;
|
| 2062 |
-
}
|
| 2063 |
-
|
| 2064 |
-
$params->id = $this->save_wp_object( 'post', $post_data, $pod['options'], true, true );
|
| 2065 |
-
|
| 2066 |
-
if ( $conflicted ) {
|
| 2067 |
-
add_filter( 'wp_insert_post_data', 'headway_clean_slug', 0 );
|
| 2068 |
-
}
|
| 2069 |
-
|
| 2070 |
-
if ( false === $params->id ) {
|
| 2071 |
-
return pods_error( __( 'Cannot save Pod', 'pods' ), $this );
|
| 2072 |
-
}
|
| 2073 |
-
} elseif ( empty( $params->id ) ) {
|
| 2074 |
-
$params->id = (int) $db;
|
| 2075 |
-
}
|
| 2076 |
-
|
| 2077 |
-
$pod['id'] = $params->id;
|
| 2078 |
-
|
| 2079 |
-
// Setup / update tables
|
| 2080 |
-
if ( 'table' !== $pod['type'] && 'table' === $pod['storage'] && $old_storage !== $pod['storage'] && $db ) {
|
| 2081 |
-
$definitions = array( "`id` BIGINT(20) UNSIGNED AUTO_INCREMENT PRIMARY KEY" );
|
| 2082 |
-
|
| 2083 |
-
$defined_fields = array();
|
| 2084 |
-
|
| 2085 |
-
foreach ( $pod['fields'] as $field ) {
|
| 2086 |
-
if ( ! is_array( $field ) || ! isset( $field['name'] ) || in_array( $field['name'], $defined_fields ) ) {
|
| 2087 |
-
continue;
|
| 2088 |
-
}
|
| 2089 |
-
|
| 2090 |
-
$defined_fields[] = $field['name'];
|
| 2091 |
-
|
| 2092 |
-
if ( ! in_array( $field['type'], $tableless_field_types ) || ( 'pick' === $field['type'] && in_array( pods_var( 'pick_object', $field ), $simple_tableless_objects ) ) ) {
|
| 2093 |
-
$definition = $this->get_field_definition( $field['type'], array_merge( $field, pods_var_raw( 'options', $field, array() ) ) );
|
| 2094 |
-
|
| 2095 |
-
if ( 0 < strlen( $definition ) ) {
|
| 2096 |
-
$definitions[] = "`{$field['name']}` " . $definition;
|
| 2097 |
-
}
|
| 2098 |
-
}
|
| 2099 |
-
}
|
| 2100 |
-
|
| 2101 |
-
pods_query( "DROP TABLE IF EXISTS `@wp_pods_{$params->name}`" );
|
| 2102 |
-
|
| 2103 |
-
/**
|
| 2104 |
-
* @todo Central function to fetch charset.
|
| 2105 |
-
* @see PodsUpgrade::install() L64-L76
|
| 2106 |
-
*/
|
| 2107 |
-
$charset_collate = 'DEFAULT CHARSET utf8';
|
| 2108 |
-
|
| 2109 |
-
global $wpdb;
|
| 2110 |
-
if ( ! empty( $wpdb->charset ) ) {
|
| 2111 |
-
$charset_collate = "DEFAULT CHARSET {$wpdb->charset}";
|
| 2112 |
-
}
|
| 2113 |
-
|
| 2114 |
-
if ( ! empty( $wpdb->collate ) ) {
|
| 2115 |
-
$charset_collate .= " COLLATE {$wpdb->collate}";
|
| 2116 |
-
}
|
| 2117 |
-
|
| 2118 |
-
$result = pods_query( "CREATE TABLE `@wp_pods_{$params->name}` (" . implode( ', ', $definitions ) . ") {$charset_collate}", $this );
|
| 2119 |
-
|
| 2120 |
-
if ( empty( $result ) ) {
|
| 2121 |
-
return pods_error( __( 'Cannot add Database Table for Pod', 'pods' ), $this );
|
| 2122 |
-
}
|
| 2123 |
-
|
| 2124 |
-
} elseif ( 'table' !== $pod['type'] && 'table' === $pod['storage'] && $pod['storage'] == $old_storage && null !== $old_name && $old_name !== $params->name && $db ) {
|
| 2125 |
-
$result = pods_query( "ALTER TABLE `@wp_pods_{$old_name}` RENAME `@wp_pods_{$params->name}`", $this );
|
| 2126 |
-
|
| 2127 |
-
if ( empty( $result ) ) {
|
| 2128 |
-
return pods_error( __( 'Cannot update Database Table for Pod', 'pods' ), $this );
|
| 2129 |
-
}
|
| 2130 |
-
}
|
| 2131 |
-
|
| 2132 |
-
/**
|
| 2133 |
-
* @var $wpdb wpdb
|
| 2134 |
-
*/
|
| 2135 |
-
global $wpdb;
|
| 2136 |
-
|
| 2137 |
-
if ( null !== $old_name && $old_name !== $params->name && $db ) {
|
| 2138 |
-
// Rename items in the DB pointed at the old WP Object names
|
| 2139 |
-
if ( 'post_type' === $pod['type'] && empty( $pod['object'] ) ) {
|
| 2140 |
-
$this->rename_wp_object_type( 'post', $old_name, $params->name );
|
| 2141 |
-
} elseif ( 'taxonomy' === $pod['type'] && empty( $pod['object'] ) ) {
|
| 2142 |
-
$this->rename_wp_object_type( 'taxonomy', $old_name, $params->name );
|
| 2143 |
-
} elseif ( 'comment' === $pod['type'] && empty( $pod['object'] ) ) {
|
| 2144 |
-
$this->rename_wp_object_type( 'comment', $old_name, $params->name );
|
| 2145 |
-
} elseif ( 'settings' === $pod['type'] ) {
|
| 2146 |
-
$this->rename_wp_object_type( 'settings', $old_name, $params->name );
|
| 2147 |
-
}
|
| 2148 |
-
|
| 2149 |
-
// Sync any related fields if the name has changed
|
| 2150 |
-
$fields = pods_query( "
|
| 2151 |
-
SELECT `p`.`ID`
|
| 2152 |
-
FROM `{$wpdb->posts}` AS `p`
|
| 2153 |
-
LEFT JOIN `{$wpdb->postmeta}` AS `pm` ON `pm`.`post_id` = `p`.`ID`
|
| 2154 |
-
LEFT JOIN `{$wpdb->postmeta}` AS `pm2` ON `pm2`.`post_id` = `p`.`ID`
|
| 2155 |
-
WHERE
|
| 2156 |
-
`p`.`post_type` = '_pods_field'
|
| 2157 |
-
AND `pm`.`meta_key` = 'pick_object'
|
| 2158 |
-
AND (
|
| 2159 |
-
`pm`.`meta_value` = 'pod'
|
| 2160 |
-
OR `pm`.`meta_value` = '" . $pod['type'] . "'
|
| 2161 |
-
)
|
| 2162 |
-
AND `pm2`.`meta_key` = 'pick_val'
|
| 2163 |
-
AND `pm2`.`meta_value` = '{$old_name}'
|
| 2164 |
-
" );
|
| 2165 |
-
|
| 2166 |
-
if ( ! empty( $fields ) ) {
|
| 2167 |
-
foreach ( $fields as $field ) {
|
| 2168 |
-
update_post_meta( $field->ID, 'pick_object', $pod['type'] );
|
| 2169 |
-
update_post_meta( $field->ID, 'pick_val', $params->name );
|
| 2170 |
-
}
|
| 2171 |
-
}
|
| 2172 |
-
|
| 2173 |
-
$fields = pods_query( "
|
| 2174 |
-
SELECT `p`.`ID`
|
| 2175 |
-
FROM `{$wpdb->posts}` AS `p`
|
| 2176 |
-
LEFT JOIN `{$wpdb->postmeta}` AS `pm` ON `pm`.`post_id` = `p`.`ID`
|
| 2177 |
-
WHERE
|
| 2178 |
-
`p`.`post_type` = '_pods_field'
|
| 2179 |
-
AND `pm`.`meta_key` = 'pick_object'
|
| 2180 |
-
AND (
|
| 2181 |
-
`pm`.`meta_value` = 'pod-{$old_name}'
|
| 2182 |
-
OR `pm`.`meta_value` = '" . $pod['type'] . "-{$old_name}'
|
| 2183 |
-
)
|
| 2184 |
-
" );
|
| 2185 |
-
|
| 2186 |
-
if ( ! empty( $fields ) ) {
|
| 2187 |
-
foreach ( $fields as $field ) {
|
| 2188 |
-
update_post_meta( $field->ID, 'pick_object', $pod['type'] );
|
| 2189 |
-
update_post_meta( $field->ID, 'pick_val', $params->name );
|
| 2190 |
-
}
|
| 2191 |
-
}
|
| 2192 |
-
}
|
| 2193 |
-
|
| 2194 |
-
// Sync built-in options for post types and taxonomies
|
| 2195 |
-
if ( in_array( $pod['type'], array( 'post_type', 'taxonomy' ) ) && empty( $pod['object'] ) && $db ) {
|
| 2196 |
-
// Build list of 'built_in' for later
|
| 2197 |
-
$built_in = array();
|
| 2198 |
-
|
| 2199 |
-
foreach ( $pod['options'] as $key => $val ) {
|
| 2200 |
-
if ( false === strpos( $key, 'built_in_' ) ) {
|
| 2201 |
-
continue;
|
| 2202 |
-
} elseif ( false !== strpos( $key, 'built_in_post_types_' ) ) {
|
| 2203 |
-
$built_in_type = 'post_type';
|
| 2204 |
-
} elseif ( false !== strpos( $key, 'built_in_taxonomies_' ) ) {
|
| 2205 |
-
$built_in_type = 'taxonomy';
|
| 2206 |
-
} else {
|
| 2207 |
-
continue;
|
| 2208 |
-
}
|
| 2209 |
-
|
| 2210 |
-
if ( $built_in_type == $pod['type'] ) {
|
| 2211 |
-
continue;
|
| 2212 |
-
}
|
| 2213 |
-
|
| 2214 |
-
if ( ! isset( $built_in[ $built_in_type ] ) ) {
|
| 2215 |
-
$built_in[ $built_in_type ] = array();
|
| 2216 |
-
}
|
| 2217 |
-
|
| 2218 |
-
$built_in_object = str_replace( array( 'built_in_post_types_', 'built_in_taxonomies_' ), '', $key );
|
| 2219 |
-
|
| 2220 |
-
$built_in[ $built_in_type ][ $built_in_object ] = (int) $val;
|
| 2221 |
-
}
|
| 2222 |
-
|
| 2223 |
-
$lookup_option = false;
|
| 2224 |
-
$lookup_built_in = false;
|
| 2225 |
-
|
| 2226 |
-
$lookup_name = $pod['name'];
|
| 2227 |
-
|
| 2228 |
-
if ( 'post_type' === $pod['type'] ) {
|
| 2229 |
-
$lookup_option = 'built_in_post_types_' . $lookup_name;
|
| 2230 |
-
$lookup_built_in = 'taxonomy';
|
| 2231 |
-
} elseif ( 'taxonomy' === $pod['type'] ) {
|
| 2232 |
-
$lookup_option = 'built_in_taxonomies_' . $lookup_name;
|
| 2233 |
-
$lookup_built_in = 'post_type';
|
| 2234 |
-
}
|
| 2235 |
-
|
| 2236 |
-
if ( ! empty( $lookup_option ) && ! empty( $lookup_built_in ) && isset( $built_in[ $lookup_built_in ] ) ) {
|
| 2237 |
-
foreach ( $built_in[ $lookup_built_in ] as $built_in_object => $val ) {
|
| 2238 |
-
$search_val = 1;
|
| 2239 |
-
|
| 2240 |
-
if ( 1 == $val ) {
|
| 2241 |
-
$search_val = 0;
|
| 2242 |
-
}
|
| 2243 |
-
|
| 2244 |
-
$query = "SELECT p.ID FROM {$wpdb->posts} AS p
|
| 2245 |
-
LEFT JOIN {$wpdb->postmeta} AS pm ON pm.post_id = p.ID AND pm.meta_key = '{$lookup_option}'
|
| 2246 |
-
LEFT JOIN {$wpdb->postmeta} AS pm2 ON pm2.post_id = p.ID AND pm2.meta_key = 'type' AND pm2.meta_value = '{$lookup_built_in}'
|
| 2247 |
-
LEFT JOIN {$wpdb->postmeta} AS pm3 ON pm3.post_id = p.ID AND pm3.meta_key = 'object' AND pm3.meta_value = ''
|
| 2248 |
-
WHERE p.post_type = '_pods_pod' AND p.post_name = '{$built_in_object}'
|
| 2249 |
-
AND pm2.meta_id IS NOT NULL
|
| 2250 |
-
AND ( pm.meta_id IS NULL OR pm.meta_value = {$search_val} )";
|
| 2251 |
-
|
| 2252 |
-
$results = pods_query( $query );
|
| 2253 |
-
|
| 2254 |
-
if ( ! empty( $results ) ) {
|
| 2255 |
-
foreach ( $results as $the_pod ) {
|
| 2256 |
-
delete_post_meta( $the_pod->ID, $lookup_option );
|
| 2257 |
-
|
| 2258 |
-
add_post_meta( $the_pod->ID, $lookup_option, $val );
|
| 2259 |
-
}
|
| 2260 |
-
}
|
| 2261 |
-
}
|
| 2262 |
-
}
|
| 2263 |
-
}
|
| 2264 |
-
|
| 2265 |
-
$saved = array();
|
| 2266 |
-
$errors = array();
|
| 2267 |
-
|
| 2268 |
-
$field_index_change = false;
|
| 2269 |
-
$field_index_id = 0;
|
| 2270 |
-
|
| 2271 |
-
$id_required = false;
|
| 2272 |
-
|
| 2273 |
-
$field_index = pods_var( 'pod_index', $pod['options'], 'id', null, true );
|
| 2274 |
-
|
| 2275 |
-
if ( 'pod' === $pod['type'] && ! empty( $pod['fields'] ) && isset( $pod['fields'][ $field_index ] ) ) {
|
| 2276 |
-
$field_index_id = $pod['fields'][ $field_index ];
|
| 2277 |
-
}
|
| 2278 |
-
|
| 2279 |
-
if ( isset( $params->fields ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
|
| 2280 |
-
$fields = array();
|
| 2281 |
-
|
| 2282 |
-
if ( isset( $params->fields ) ) {
|
| 2283 |
-
$params->fields = (array) $params->fields;
|
| 2284 |
-
|
| 2285 |
-
$weight = 0;
|
| 2286 |
-
|
| 2287 |
-
foreach ( $params->fields as $field ) {
|
| 2288 |
-
if ( ! is_array( $field ) || ! isset( $field['name'] ) ) {
|
| 2289 |
-
continue;
|
| 2290 |
-
}
|
| 2291 |
-
|
| 2292 |
-
if ( ! isset( $field['weight'] ) ) {
|
| 2293 |
-
$field['weight'] = $weight;
|
| 2294 |
-
|
| 2295 |
-
$weight ++;
|
| 2296 |
-
}
|
| 2297 |
-
|
| 2298 |
-
$fields[ $field['name'] ] = $field;
|
| 2299 |
-
}
|
| 2300 |
-
}
|
| 2301 |
-
|
| 2302 |
-
$weight = 0;
|
| 2303 |
-
|
| 2304 |
-
$saved_field_ids = array();
|
| 2305 |
-
|
| 2306 |
-
foreach ( $pod['fields'] as $k => $field ) {
|
| 2307 |
-
if ( ! empty( $old_id ) && ( ! is_array( $field ) || ! isset( $field['name'] ) || ! isset( $fields[ $field['name'] ] ) ) ) {
|
| 2308 |
-
// Iterative change handling for setup-edit.php
|
| 2309 |
-
if ( ! is_array( $field ) && isset( $old_fields[ $k ] ) ) {
|
| 2310 |
-
$saved[ $old_fields[ $k ]['name'] ] = true;
|
| 2311 |
-
}
|
| 2312 |
-
|
| 2313 |
-
continue;
|
| 2314 |
-
}
|
| 2315 |
-
|
| 2316 |
-
if ( ! empty( $old_id ) ) {
|
| 2317 |
-
$field = array_merge( $field, $fields[ $field['name'] ] );
|
| 2318 |
-
}
|
| 2319 |
-
|
| 2320 |
-
$field['pod'] = $pod;
|
| 2321 |
-
|
| 2322 |
-
if ( ! isset( $field['weight'] ) ) {
|
| 2323 |
-
$field['weight'] = $weight;
|
| 2324 |
-
|
| 2325 |
-
$weight ++;
|
| 2326 |
-
}
|
| 2327 |
-
|
| 2328 |
-
if ( 0 < $field_index_id && pods_var( 'id', $field ) == $field_index_id ) {
|
| 2329 |
-
$field_index_change = $field['name'];
|
| 2330 |
-
}
|
| 2331 |
-
|
| 2332 |
-
if ( 0 < pods_var( 'id', $field ) ) {
|
| 2333 |
-
$id_required = true;
|
| 2334 |
-
}
|
| 2335 |
-
|
| 2336 |
-
if ( $id_required ) {
|
| 2337 |
-
$field['id_required'] = true;
|
| 2338 |
-
}
|
| 2339 |
-
|
| 2340 |
-
$field_data = $field;
|
| 2341 |
-
|
| 2342 |
-
$field = $this->save_field( $field_data, $field_table_operation, true, $db );
|
| 2343 |
-
|
| 2344 |
-
if ( true !== $db ) {
|
| 2345 |
-
$pod['fields'][ $k ] = $field;
|
| 2346 |
-
$saved_field_ids[] = $field['id'];
|
| 2347 |
-
} else {
|
| 2348 |
-
if ( ! empty( $field ) && 0 < $field ) {
|
| 2349 |
-
$saved[ $field_data['name'] ] = true;
|
| 2350 |
-
$saved_field_ids[] = $field;
|
| 2351 |
-
} else {
|
| 2352 |
-
$errors[] = sprintf( __( 'Cannot save the %s field', 'pods' ), $field_data['name'] );
|
| 2353 |
-
}
|
| 2354 |
-
}
|
| 2355 |
-
}
|
| 2356 |
-
|
| 2357 |
-
if ( true === $db ) {
|
| 2358 |
-
foreach ( $old_fields as $field ) {
|
| 2359 |
-
if ( isset( $pod['fields'][ $field['name'] ] ) || isset( $saved[ $field['name'] ] ) || in_array( $field['id'], $saved_field_ids ) ) {
|
| 2360 |
-
continue;
|
| 2361 |
-
}
|
| 2362 |
-
|
| 2363 |
-
if ( $field['id'] == $field_index_id ) {
|
| 2364 |
-
$field_index_change = 'id';
|
| 2365 |
-
} elseif ( $field['name'] == $field_index ) {
|
| 2366 |
-
$field_index_change = 'id';
|
| 2367 |
-
}
|
| 2368 |
-
|
| 2369 |
-
$this->delete_field( array(
|
| 2370 |
-
'id' => (int) $field['id'],
|
| 2371 |
-
'name' => $field['name'],
|
| 2372 |
-
'pod' => $pod
|
| 2373 |
-
), $field_table_operation );
|
| 2374 |
-
}
|
| 2375 |
-
}
|
| 2376 |
-
|
| 2377 |
-
// Update field index if the name has changed or the field has been removed
|
| 2378 |
-
if ( false !== $field_index_change && true === $db ) {
|
| 2379 |
-
update_post_meta( $pod['id'], 'pod_index', $field_index_change );
|
| 2380 |
-
}
|
| 2381 |
-
}
|
| 2382 |
-
|
| 2383 |
-
$this->cache_flush_pods( $pod );
|
| 2384 |
-
|
| 2385 |
-
if ( ! empty( $errors ) ) {
|
| 2386 |
-
return pods_error( $errors, $this );
|
| 2387 |
-
}
|
| 2388 |
-
|
| 2389 |
-
$refresh_pod = $this->load_pod( array( 'name' => $pod['name'] ), false );
|
| 2390 |
-
|
| 2391 |
-
if ( $refresh_pod ) {
|
| 2392 |
-
$pod = $refresh_pod;
|
| 2393 |
-
}
|
| 2394 |
-
|
| 2395 |
-
if ( 'post_type' === $pod['type'] ) {
|
| 2396 |
-
PodsMeta::$post_types[ $pod['id'] ] = $pod;
|
| 2397 |
-
} elseif ( 'taxonomy' === $pod['type'] ) {
|
| 2398 |
-
PodsMeta::$taxonomies[ $pod['id'] ] = $pod;
|
| 2399 |
-
} elseif ( 'media' === $pod['type'] ) {
|
| 2400 |
-
PodsMeta::$media[ $pod['id'] ] = $pod;
|
| 2401 |
-
} elseif ( 'user' === $pod['type'] ) {
|
| 2402 |
-
PodsMeta::$user[ $pod['id'] ] = $pod;
|
| 2403 |
-
} elseif ( 'comment' === $pod['type'] ) {
|
| 2404 |
-
PodsMeta::$comment[ $pod['id'] ] = $pod;
|
| 2405 |
-
}
|
| 2406 |
-
|
| 2407 |
-
if ( ! class_exists( 'PodsInit' ) ) {
|
| 2408 |
-
pods_init();
|
| 2409 |
-
}
|
| 2410 |
-
|
| 2411 |
-
// Register Post Types / Taxonomies post-registration from PodsInit
|
| 2412 |
-
if (
|
| 2413 |
-
! empty( PodsInit::$content_types_registered )
|
| 2414 |
-
&& in_array( $pod['type'], array(
|
| 2415 |
-
'post_type',
|
| 2416 |
-
'taxonomy'
|
| 2417 |
-
) )
|
| 2418 |
-
&& empty( $pod['object'] )
|
| 2419 |
-
) {
|
| 2420 |
-
pods_init()->setup_content_types( true );
|
| 2421 |
-
}
|
| 2422 |
-
|
| 2423 |
-
if ( true === $db ) {
|
| 2424 |
-
return $pod['id'];
|
| 2425 |
-
} else {
|
| 2426 |
-
return $pod;
|
| 2427 |
-
}
|
| 2428 |
-
}
|
| 2429 |
-
|
| 2430 |
-
/**
|
| 2431 |
-
* Add or edit a field within a Pod
|
| 2432 |
-
*
|
| 2433 |
-
* $params['id'] int Field ID (id OR pod_id+pod+name required)
|
| 2434 |
-
* $params['pod_id'] int Pod ID (id OR pod_id+pod+name required)
|
| 2435 |
-
* $params['pod'] string Pod name (id OR pod_id+pod+name required)
|
| 2436 |
-
* $params['name'] string Field name (id OR pod_id+pod+name required)
|
| 2437 |
-
* $params['label'] string (optional) Field label
|
| 2438 |
-
* $params['type'] string (optional) Field type (avatar, boolean, code, color, currency, date, datetime, email,
|
| 2439 |
-
* file, number, paragraph, password, phone, pick, slug, text, time, website, wysiwyg)
|
| 2440 |
-
* $params['pick_object'] string (optional) Related Object (for relationships)
|
| 2441 |
-
* $params['pick_val'] string (optional) Related Object name (for relationships)
|
| 2442 |
-
* $params['sister_id'] int (optional) Related Field ID (for bidirectional relationships)
|
| 2443 |
-
* $params['weight'] int (optional) Order in which the field appears
|
| 2444 |
-
* $params['options'] array (optional) Options
|
| 2445 |
-
*
|
| 2446 |
-
* @param array $params An associative array of parameters
|
| 2447 |
-
* @param bool $table_operation (optional) Whether or not to handle table operations
|
| 2448 |
-
* @param bool $sanitized (optional) Decides wether the params have been sanitized before being passed,
|
| 2449 |
-
* will sanitize them if false.
|
| 2450 |
-
* @param bool|int $db (optional) Whether to save into the DB or just return field array.
|
| 2451 |
-
*
|
| 2452 |
-
* @return int|array The field ID or field array (if !$db)
|
| 2453 |
-
* @since 1.7.9
|
| 2454 |
-
*/
|
| 2455 |
-
public function save_field( $params, $table_operation = true, $sanitized = false, $db = true ) {
|
| 2456 |
-
|
| 2457 |
-
/**
|
| 2458 |
-
* @var $wpdb wpdb
|
| 2459 |
-
*/
|
| 2460 |
-
global $wpdb;
|
| 2461 |
-
|
| 2462 |
-
if ( true !== $db ) {
|
| 2463 |
-
$table_operation = false;
|
| 2464 |
-
}
|
| 2465 |
-
|
| 2466 |
-
$tableless_field_types = PodsForm::tableless_field_types();
|
| 2467 |
-
$simple_tableless_objects = PodsForm::simple_tableless_objects();
|
| 2468 |
-
|
| 2469 |
-
$params = (object) $params;
|
| 2470 |
-
|
| 2471 |
-
if ( false === $sanitized ) {
|
| 2472 |
-
$params = pods_sanitize( $params );
|
| 2473 |
-
}
|
| 2474 |
-
|
| 2475 |
-
if ( isset( $params->pod_id ) ) {
|
| 2476 |
-
$params->pod_id = pods_absint( $params->pod_id );
|
| 2477 |
-
}
|
| 2478 |
-
|
| 2479 |
-
if ( true !== $db ) {
|
| 2480 |
-
$params->pod_id = (int) $db;
|
| 2481 |
-
}
|
| 2482 |
-
|
| 2483 |
-
$pod = null;
|
| 2484 |
-
$save_pod = false;
|
| 2485 |
-
$id_required = false;
|
| 2486 |
-
|
| 2487 |
-
if ( isset( $params->id_required ) ) {
|
| 2488 |
-
unset( $params->id_required );
|
| 2489 |
-
|
| 2490 |
-
$id_required = true;
|
| 2491 |
-
}
|
| 2492 |
-
|
| 2493 |
-
if ( ( ! isset( $params->pod ) || empty( $params->pod ) ) && ( ! isset( $params->pod_id ) || empty( $params->pod_id ) ) ) {
|
| 2494 |
-
return pods_error( __( 'Pod ID or name is required', 'pods' ), $this );
|
| 2495 |
-
}
|
| 2496 |
-
|
| 2497 |
-
if ( isset( $params->pod ) && is_array( $params->pod ) ) {
|
| 2498 |
-
$pod = $params->pod;
|
| 2499 |
-
|
| 2500 |
-
$save_pod = true;
|
| 2501 |
-
} elseif ( ( ! isset( $params->pod_id ) || empty( $params->pod_id ) ) && ( true === $db || 0 < $db ) ) {
|
| 2502 |
-
$pod = $this->load_pod( array( 'name' => $params->pod, 'table_info' => true ) );
|
| 2503 |
-
} elseif ( ! isset( $params->pod ) && ( true === $db || 0 < $db ) ) {
|
| 2504 |
-
$pod = $this->load_pod( array( 'id' => $params->pod_id, 'table_info' => true ) );
|
| 2505 |
-
} elseif ( true === $db || 0 < $db ) {
|
| 2506 |
-
$pod = $this->load_pod( array( 'id' => $params->pod_id, 'name' => $params->pod, 'table_info' => true ) );
|
| 2507 |
-
}
|
| 2508 |
-
|
| 2509 |
-
if ( empty( $pod ) && true === $db ) {
|
| 2510 |
-
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
| 2511 |
-
}
|
| 2512 |
-
|
| 2513 |
-
$params->pod_id = $pod['id'];
|
| 2514 |
-
$params->pod = $pod['name'];
|
| 2515 |
-
$params->pod_data = $pod;
|
| 2516 |
-
|
| 2517 |
-
$params->name = pods_clean_name( $params->name, true, ( 'meta' === $pod['storage'] ? false : true ) );
|
| 2518 |
-
|
| 2519 |
-
if ( ! isset( $params->id ) ) {
|
| 2520 |
-
$params->id = 0;
|
| 2521 |
-
}
|
| 2522 |
-
|
| 2523 |
-
if ( empty( $params->name ) ) {
|
| 2524 |
-
return pods_error( __( 'Pod field name is required', 'pods' ), $this );
|
| 2525 |
-
}
|
| 2526 |
-
|
| 2527 |
-
$field = $this->load_field( $params );
|
| 2528 |
-
|
| 2529 |
-
unset( $params->pod_data );
|
| 2530 |
-
|
| 2531 |
-
$old_id = null;
|
| 2532 |
-
$old_name = null;
|
| 2533 |
-
$old_type = null;
|
| 2534 |
-
$old_definition = null;
|
| 2535 |
-
$old_simple = null;
|
| 2536 |
-
$old_options = null;
|
| 2537 |
-
$old_sister_id = null;
|
| 2538 |
-
|
| 2539 |
-
// @todo pods_reserved_keywords();
|
| 2540 |
-
$reserved_keywords = array( 'id', 'ID' );
|
| 2541 |
-
|
| 2542 |
-
if ( ! empty( $field ) ) {
|
| 2543 |
-
$old_id = pods_var( 'id', $field );
|
| 2544 |
-
$old_name = pods_clean_name( $field['name'], true, ( 'meta' === $pod['storage'] ? false : true ) );
|
| 2545 |
-
$old_type = $field['type'];
|
| 2546 |
-
$old_options = $field['options'];
|
| 2547 |
-
$old_sister_id = (int) pods_var( 'sister_id', $old_options, 0 );
|
| 2548 |
-
|
| 2549 |
-
$old_simple = ( 'pick' === $old_type && in_array( pods_var( 'pick_object', $field ), $simple_tableless_objects ) );
|
| 2550 |
-
|
| 2551 |
-
if ( isset( $params->name ) && ! empty( $params->name ) ) {
|
| 2552 |
-
$field['name'] = $params->name;
|
| 2553 |
-
}
|
| 2554 |
-
|
| 2555 |
-
if ( $old_name !== $field['name'] ) {
|
| 2556 |
-
if ( in_array( $field['name'], $reserved_keywords, true ) ) {
|
| 2557 |
-
return pods_error( sprintf( __( '%s is reserved for internal WordPress or Pods usage, please try a different name', 'pods' ), $field['name'] ), $this );
|
| 2558 |
-
}
|
| 2559 |
-
|
| 2560 |
-
if ( false !== $this->field_exists( $params ) ) {
|
| 2561 |
-
return pods_error( sprintf( __( 'Field %1$s already exists, you cannot rename %2$s to that', 'pods' ), $field['name'], $old_name ), $this );
|
| 2562 |
-
}
|
| 2563 |
-
}
|
| 2564 |
-
|
| 2565 |
-
if ( ( $id_required || ! empty( $params->id ) ) && ( empty( $old_id ) || $old_id != $params->id ) ) {
|
| 2566 |
-
return pods_error( sprintf( __( 'Field %s already exists', 'pods' ), $field['name'] ), $this );
|
| 2567 |
-
}
|
| 2568 |
-
|
| 2569 |
-
if ( empty( $params->id ) ) {
|
| 2570 |
-
$params->id = $old_id;
|
| 2571 |
-
}
|
| 2572 |
-
|
| 2573 |
-
if ( ! in_array( $old_type, $tableless_field_types ) || $old_simple ) {
|
| 2574 |
-
$definition = $this->get_field_definition( $old_type, array_merge( $field, $old_options ) );
|
| 2575 |
-
|
| 2576 |
-
if ( 0 < strlen( $definition ) ) {
|
| 2577 |
-
$old_definition = "`{$old_name}` " . $definition;
|
| 2578 |
-
}
|
| 2579 |
-
}
|
| 2580 |
-
} else {
|
| 2581 |
-
$field = array(
|
| 2582 |
-
'id' => 0,
|
| 2583 |
-
'pod_id' => $params->pod_id,
|
| 2584 |
-
'name' => $params->name,
|
| 2585 |
-
'label' => $params->name,
|
| 2586 |
-
'description' => '',
|
| 2587 |
-
'type' => 'text',
|
| 2588 |
-
'pick_object' => '',
|
| 2589 |
-
'pick_val' => '',
|
| 2590 |
-
'sister_id' => '',
|
| 2591 |
-
'weight' => null,
|
| 2592 |
-
'options' => array()
|
| 2593 |
-
);
|
| 2594 |
-
}
|
| 2595 |
-
|
| 2596 |
-
// Setup options
|
| 2597 |
-
$options = get_object_vars( $params );
|
| 2598 |
-
|
| 2599 |
-
$options_ignore = array(
|
| 2600 |
-
'method',
|
| 2601 |
-
'table_info',
|
| 2602 |
-
'attributes',
|
| 2603 |
-
'group',
|
| 2604 |
-
'grouped',
|
| 2605 |
-
'developer_mode',
|
| 2606 |
-
'dependency',
|
| 2607 |
-
'depends-on',
|
| 2608 |
-
'excludes-on'
|
| 2609 |
-
);
|
| 2610 |
-
|
| 2611 |
-
foreach ( $options_ignore as $ignore ) {
|
| 2612 |
-
if ( isset( $options[ $ignore ] ) ) {
|
| 2613 |
-
unset( $options[ $ignore ] );
|
| 2614 |
-
}
|
| 2615 |
-
}
|
| 2616 |
-
|
| 2617 |
-
if ( isset( $options['method'] ) ) {
|
| 2618 |
-
unset( $options['method'] );
|
| 2619 |
-
} elseif ( isset( $options['table_info'] ) ) {
|
| 2620 |
-
unset( $options['table_info'] );
|
| 2621 |
-
}
|
| 2622 |
-
|
| 2623 |
-
$exclude = array(
|
| 2624 |
-
'id',
|
| 2625 |
-
'pod_id',
|
| 2626 |
-
'pod',
|
| 2627 |
-
'name',
|
| 2628 |
-
'label',
|
| 2629 |
-
'description',
|
| 2630 |
-
'type',
|
| 2631 |
-
'pick_object',
|
| 2632 |
-
'pick_val',
|
| 2633 |
-
'sister_id',
|
| 2634 |
-
'weight',
|
| 2635 |
-
'options'
|
| 2636 |
-
);
|
| 2637 |
-
|
| 2638 |
-
foreach ( $exclude as $k => $exclude_field ) {
|
| 2639 |
-
$aliases = array( $exclude_field );
|
| 2640 |
-
|
| 2641 |
-
if ( is_array( $exclude_field ) ) {
|
| 2642 |
-
$aliases = array_merge( array( $k ), $exclude_field );
|
| 2643 |
-
$exclude_field = $k;
|
| 2644 |
-
}
|
| 2645 |
-
|
| 2646 |
-
foreach ( $aliases as $alias ) {
|
| 2647 |
-
if ( isset( $options[ $alias ] ) ) {
|
| 2648 |
-
$field[ $exclude_field ] = pods_trim( $options[ $alias ] );
|
| 2649 |
-
|
| 2650 |
-
unset( $options[ $alias ] );
|
| 2651 |
-
}
|
| 2652 |
-
}
|
| 2653 |
-
}
|
| 2654 |
-
|
| 2655 |
-
if ( strlen( $field['label'] ) < 1 ) {
|
| 2656 |
-
$field['label'] = $field['name'];
|
| 2657 |
-
}
|
| 2658 |
-
|
| 2659 |
-
$field['options']['type'] = $field['type'];
|
| 2660 |
-
|
| 2661 |
-
if ( in_array( $field['options']['type'], $tableless_field_types ) ) {
|
| 2662 |
-
// Clean up special drop-down in field editor and save out pick_val
|
| 2663 |
-
$field['pick_object'] = pods_var( 'pick_object', $field, '', null, true );
|
| 2664 |
-
|
| 2665 |
-
if ( 0 === strpos( $field['pick_object'], 'pod-' ) ) {
|
| 2666 |
-
$field['pick_val'] = pods_str_replace( 'pod-', '', $field['pick_object'], 1 );
|
| 2667 |
-
$field['pick_object'] = 'pod';
|
| 2668 |
-
} elseif ( 0 === strpos( $field['pick_object'], 'post_type-' ) ) {
|
| 2669 |
-
$field['pick_val'] = pods_str_replace( 'post_type-', '', $field['pick_object'], 1 );
|
| 2670 |
-
$field['pick_object'] = 'post_type';
|
| 2671 |
-
} elseif ( 0 === strpos( $field['pick_object'], 'taxonomy-' ) ) {
|
| 2672 |
-
$field['pick_val'] = pods_str_replace( 'taxonomy-', '', $field['pick_object'], 1 );
|
| 2673 |
-
$field['pick_object'] = 'taxonomy';
|
| 2674 |
-
} elseif ( 'table' === $field['pick_object'] && 0 < strlen( pods_var_raw( 'pick_table', $field['options'] ) ) ) {
|
| 2675 |
-
$field['pick_val'] = $field['options']['pick_table'];
|
| 2676 |
-
$field['pick_object'] = 'table';
|
| 2677 |
-
} elseif ( false === strpos( $field['pick_object'], '-' ) && ! in_array( $field['pick_object'], array(
|
| 2678 |
-
'pod',
|
| 2679 |
-
'post_type',
|
| 2680 |
-
'taxonomy'
|
| 2681 |
-
) ) ) {
|
| 2682 |
-
$field['pick_val'] = '';
|
| 2683 |
-
} elseif ( 'custom-simple' === $field['pick_object'] ) {
|
| 2684 |
-
$field['pick_val'] = '';
|
| 2685 |
-
}
|
| 2686 |
-
|
| 2687 |
-
$field['options']['pick_object'] = $field['pick_object'];
|
| 2688 |
-
$field['options']['pick_val'] = $field['pick_val'];
|
| 2689 |
-
$field['options']['sister_id'] = pods_var( 'sister_id', $field );
|
| 2690 |
-
|
| 2691 |
-
unset( $field['pick_object'] );
|
| 2692 |
-
unset( $field['pick_val'] );
|
| 2693 |
-
|
| 2694 |
-
if ( isset( $field['sister_id'] ) ) {
|
| 2695 |
-
unset( $field['sister_id'] );
|
| 2696 |
-
}
|
| 2697 |
-
}
|
| 2698 |
-
|
| 2699 |
-
$field['options'] = array_merge( $field['options'], $options );
|
| 2700 |
-
|
| 2701 |
-
$object_fields = (array) pods_var_raw( 'object_fields', $pod, array(), null, true );
|
| 2702 |
-
|
| 2703 |
-
if ( 0 < $old_id && defined( 'PODS_FIELD_STRICT' ) && ! PODS_FIELD_STRICT ) {
|
| 2704 |
-
$params->id = $old_id;
|
| 2705 |
-
$field['id'] = $old_id;
|
| 2706 |
-
}
|
| 2707 |
-
|
| 2708 |
-
// Add new field
|
| 2709 |
-
if ( ! isset( $params->id ) || empty( $params->id ) || empty( $field ) ) {
|
| 2710 |
-
if ( $table_operation && in_array( $field['name'], array(
|
| 2711 |
-
'created',
|
| 2712 |
-
'modified'
|
| 2713 |
-
) ) && ! in_array( $field['type'], array(
|
| 2714 |
-
'date',
|
| 2715 |
-
'datetime'
|
| 2716 |
-
) ) && ( ! defined( 'PODS_FIELD_STRICT' ) || PODS_FIELD_STRICT ) ) {
|
| 2717 |
-
return pods_error( sprintf( __( '%s is reserved for internal Pods usage, please try a different name', 'pods' ), $field['name'] ), $this );
|
| 2718 |
-
}
|
| 2719 |
-
|
| 2720 |
-
if ( $table_operation && 'author' === $field['name'] && 'pick' !== $field['type'] && ( ! defined( 'PODS_FIELD_STRICT' ) || PODS_FIELD_STRICT ) ) {
|
| 2721 |
-
return pods_error( sprintf( __( '%s is reserved for internal Pods usage, please try a different name', 'pods' ), $field['name'] ), $this );
|
| 2722 |
-
}
|
| 2723 |
-
|
| 2724 |
-
if ( in_array( $field['name'], $reserved_keywords, true ) ) {
|
| 2725 |
-
return pods_error( sprintf( __( '%s is reserved for internal WordPress or Pods usage, please try a different name', 'pods' ), $field['name'] ), $this );
|
| 2726 |
-
}
|
| 2727 |
-
|
| 2728 |
-
foreach ( $object_fields as $object_field => $object_field_opt ) {
|
| 2729 |
-
if ( $object_field == $field['name'] || in_array( $field['name'], $object_field_opt['alias'] ) ) {
|
| 2730 |
-
return pods_error( sprintf( __( '%s is reserved for internal WordPress or Pods usage, please try a different name. Also consider what WordPress and Pods provide you built-in.', 'pods' ), $field['name'] ), $this );
|
| 2731 |
-
}
|
| 2732 |
-
}
|
| 2733 |
-
|
| 2734 |
-
if ( in_array( $field['name'], array( 'rss' ) ) ) // Reserved post_name values that can't be used as field names
|
| 2735 |
-
{
|
| 2736 |
-
$field['name'] .= '2';
|
| 2737 |
-
}
|
| 2738 |
-
|
| 2739 |
-
if ( 'slug' === $field['type'] && true === $db ) {
|
| 2740 |
-
if ( in_array( $pod['type'], array( 'post_type', 'taxonomy', 'user' ) ) ) {
|
| 2741 |
-
return pods_error( __( 'This pod already has an internal WordPress permalink field', 'pods' ), $this );
|
| 2742 |
-
}
|
| 2743 |
-
|
| 2744 |
-
$slug_field = get_posts( array(
|
| 2745 |
-
'post_type' => '_pods_field',
|
| 2746 |
-
'orderby' => 'menu_order',
|
| 2747 |
-
'order' => 'ASC',
|
| 2748 |
-
'posts_per_page' => 1,
|
| 2749 |
-
'post_parent' => $field['pod_id'],
|
| 2750 |
-
'meta_query' => array(
|
| 2751 |
-
array(
|
| 2752 |
-
'key' => 'type',
|
| 2753 |
-
'value' => 'slug'
|
| 2754 |
-
)
|
| 2755 |
-
)
|
| 2756 |
-
) );
|
| 2757 |
-
|
| 2758 |
-
if ( ! empty( $slug_field ) ) {
|
| 2759 |
-
return pods_error( __( 'This pod already has a permalink field', 'pods' ), $this );
|
| 2760 |
-
}
|
| 2761 |
-
}
|
| 2762 |
-
|
| 2763 |
-
// Sink the new field to the bottom of the list
|
| 2764 |
-
if ( null === $field['weight'] ) {
|
| 2765 |
-
$field['weight'] = 0;
|
| 2766 |
-
|
| 2767 |
-
$bottom_most_field = get_posts( array(
|
| 2768 |
-
'post_type' => '_pods_field',
|
| 2769 |
-
'orderby' => 'menu_order',
|
| 2770 |
-
'order' => 'DESC',
|
| 2771 |
-
'posts_per_page' => 1,
|
| 2772 |
-
'post_parent' => $field['pod_id']
|
| 2773 |
-
) );
|
| 2774 |
-
|
| 2775 |
-
if ( ! empty( $bottom_most_field ) ) {
|
| 2776 |
-
$field['weight'] = pods_absint( $bottom_most_field[0]->menu_order ) + 1;
|
| 2777 |
-
}
|
| 2778 |
-
}
|
| 2779 |
-
|
| 2780 |
-
$field['weight'] = pods_absint( $field['weight'] );
|
| 2781 |
-
|
| 2782 |
-
$post_data = array(
|
| 2783 |
-
'post_name' => $field['name'],
|
| 2784 |
-
'post_title' => $field['label'],
|
| 2785 |
-
'post_content' => $field['description'],
|
| 2786 |
-
'post_type' => '_pods_field',
|
| 2787 |
-
'post_parent' => $field['pod_id'],
|
| 2788 |
-
'post_status' => 'publish',
|
| 2789 |
-
'menu_order' => $field['weight']
|
| 2790 |
-
);
|
| 2791 |
-
} else {
|
| 2792 |
-
if ( in_array( $field['name'], array( 'id', 'ID' ) ) ) {
|
| 2793 |
-
if ( null !== $old_name ) {
|
| 2794 |
-
return pods_error( sprintf( __( '%s is reserved for internal Pods usage, please try a different name', 'pods' ), $field['name'] ), $this );
|
| 2795 |
-
} else {
|
| 2796 |
-
return pods_error( sprintf( __( '%s is not editable', 'pods' ), $field['name'] ), $this );
|
| 2797 |
-
}
|
| 2798 |
-
}
|
| 2799 |
-
|
| 2800 |
-
if ( null !== $old_name && $field['name'] !== $old_name && in_array( $field['name'], array(
|
| 2801 |
-
'created',
|
| 2802 |
-
'modified'
|
| 2803 |
-
) ) && ! in_array( $field['type'], array(
|
| 2804 |
-
'date',
|
| 2805 |
-
'datetime'
|
| 2806 |
-
) ) && ( ! defined( 'PODS_FIELD_STRICT' ) || PODS_FIELD_STRICT ) ) {
|
| 2807 |
-
return pods_error( sprintf( __( '%s is reserved for internal Pods usage, please try a different name', 'pods' ), $field['name'] ), $this );
|
| 2808 |
-
}
|
| 2809 |
-
|
| 2810 |
-
if ( null !== $old_name && $field['name'] !== $old_name && 'author' === $field['name'] && 'pick' !== $field['type'] && ( ! defined( 'PODS_FIELD_STRICT' ) || PODS_FIELD_STRICT ) ) {
|
| 2811 |
-
return pods_error( sprintf( __( '%s is reserved for internal Pods usage, please try a different name', 'pods' ), $field['name'] ), $this );
|
| 2812 |
-
}
|
| 2813 |
-
|
| 2814 |
-
foreach ( $object_fields as $object_field => $object_field_opt ) {
|
| 2815 |
-
if ( $object_field !== $field['name'] && ! in_array( $field['name'], $object_field_opt['alias'] ) ) {
|
| 2816 |
-
continue;
|
| 2817 |
-
}
|
| 2818 |
-
|
| 2819 |
-
if ( null !== $old_name ) {
|
| 2820 |
-
return pods_error( sprintf( __( '%s is reserved for internal WordPress or Pods usage, please try a different name', 'pods' ), $field['name'] ), $this );
|
| 2821 |
-
} else {
|
| 2822 |
-
return pods_error( sprintf( __( '%s is not editable', 'pods' ), $field['name'] ), $this );
|
| 2823 |
-
}
|
| 2824 |
-
}
|
| 2825 |
-
|
| 2826 |
-
$post_data = array(
|
| 2827 |
-
'ID' => $field['id'],
|
| 2828 |
-
'post_name' => $field['name'],
|
| 2829 |
-
'post_title' => $field['label'],
|
| 2830 |
-
'post_content' => $field['description']
|
| 2831 |
-
);
|
| 2832 |
-
|
| 2833 |
-
if ( null !== $field['weight'] ) {
|
| 2834 |
-
$field['weight'] = pods_absint( $field['weight'] );
|
| 2835 |
-
|
| 2836 |
-
$post_data['menu_order'] = $field['weight'];
|
| 2837 |
-
}
|
| 2838 |
-
}
|
| 2839 |
-
|
| 2840 |
-
if ( true === $db ) {
|
| 2841 |
-
if ( ! has_filter( 'wp_unique_post_slug', array( $this, 'save_slug_fix' ) ) ) {
|
| 2842 |
-
add_filter( 'wp_unique_post_slug', array( $this, 'save_slug_fix' ), 100, 6 );
|
| 2843 |
-
}
|
| 2844 |
-
|
| 2845 |
-
$conflicted = false;
|
| 2846 |
-
|
| 2847 |
-
// Headway compatibility fix
|
| 2848 |
-
if ( has_filter( 'wp_insert_post_data', 'headway_clean_slug', 0 ) ) {
|
| 2849 |
-
remove_filter( 'wp_insert_post_data', 'headway_clean_slug', 0 );
|
| 2850 |
-
|
| 2851 |
-
$conflicted = true;
|
| 2852 |
-
}
|
| 2853 |
-
|
| 2854 |
-
// Store the old field name
|
| 2855 |
-
if ( $old_name && $old_name !== $post_data['post_name'] ) {
|
| 2856 |
-
$field['options']['old_name'] = $old_name;
|
| 2857 |
-
}
|
| 2858 |
-
|
| 2859 |
-
$params->id = $this->save_wp_object( 'post', $post_data, $field['options'], true, true );
|
| 2860 |
-
|
| 2861 |
-
if ( $conflicted ) {
|
| 2862 |
-
add_filter( 'wp_insert_post_data', 'headway_clean_slug', 0 );
|
| 2863 |
-
}
|
| 2864 |
-
|
| 2865 |
-
if ( false === $params->id ) {
|
| 2866 |
-
return pods_error( __( 'Cannot save Field', 'pods' ), $this );
|
| 2867 |
-
}
|
| 2868 |
-
} else {
|
| 2869 |
-
$params->id = $field['name'];
|
| 2870 |
-
}
|
| 2871 |
-
|
| 2872 |
-
$field['id'] = $params->id;
|
| 2873 |
-
|
| 2874 |
-
$simple = ( 'pick' === $field['type'] && in_array( pods_v( 'pick_object', $field['options'] ), $simple_tableless_objects, true ) );
|
| 2875 |
-
|
| 2876 |
-
$definition = false;
|
| 2877 |
-
|
| 2878 |
-
if ( ! in_array( $field['type'], $tableless_field_types ) || $simple ) {
|
| 2879 |
-
$field_definition = $this->get_field_definition( $field['type'], array_merge( $field, $field['options'] ) );
|
| 2880 |
-
|
| 2881 |
-
if ( 0 < strlen( $field_definition ) ) {
|
| 2882 |
-
$definition = '`' . $field['name'] . '` ' . $field_definition;
|
| 2883 |
-
}
|
| 2884 |
-
}
|
| 2885 |
-
|
| 2886 |
-
$sister_id = (int) pods_var( 'sister_id', $field['options'], 0 );
|
| 2887 |
-
|
| 2888 |
-
$definition_mode = 'bypass';
|
| 2889 |
-
|
| 2890 |
-
if ( $table_operation && 'table' === $pod['storage'] && ! pods_tableless() ) {
|
| 2891 |
-
if ( ! empty( $old_id ) ) {
|
| 2892 |
-
if ( ( $field['type'] !== $old_type || $old_simple !== $simple ) && empty( $definition ) ) {
|
| 2893 |
-
$definition_mode = 'drop';
|
| 2894 |
-
} elseif ( 0 < strlen( $definition ) ) {
|
| 2895 |
-
if ( $old_name !== $field['name'] || $old_simple !== $simple || $old_definition !== $definition ) {
|
| 2896 |
-
$definition_mode = 'add';
|
| 2897 |
-
|
| 2898 |
-
if ( 0 < strlen( $old_definition ) ) {
|
| 2899 |
-
$definition_mode = 'change';
|
| 2900 |
-
}
|
| 2901 |
-
} elseif ( null !== $old_definition && $definition !== $old_definition ) {
|
| 2902 |
-
$definition_mode = 'change';
|
| 2903 |
-
}
|
| 2904 |
-
}
|
| 2905 |
-
} elseif ( 0 < strlen( $definition ) ) {
|
| 2906 |
-
$definition_mode = 'add';
|
| 2907 |
-
|
| 2908 |
-
if ( 0 < strlen( $old_definition ) ) {
|
| 2909 |
-
$definition_mode = 'change';
|
| 2910 |
-
}
|
| 2911 |
-
}
|
| 2912 |
-
|
| 2913 |
-
if ( 'bypass' !== $definition_mode ) {
|
| 2914 |
-
/**
|
| 2915 |
-
* Allow hooking into before the table has been altered for any custom functionality needed.
|
| 2916 |
-
*
|
| 2917 |
-
* @since 2.7.17
|
| 2918 |
-
*
|
| 2919 |
-
* @param string $definition_mode The definition mode used for the table field.
|
| 2920 |
-
* @param array $pod The pod object.
|
| 2921 |
-
* @param string $type The field type.
|
| 2922 |
-
* @param array $field The field object.
|
| 2923 |
-
* @param array $extra_info {
|
| 2924 |
-
* Extra information about the field.
|
| 2925 |
-
*
|
| 2926 |
-
* @type bool $simple Whether the field is a simple tableless field.
|
| 2927 |
-
* @type string $definition The field definition.
|
| 2928 |
-
* @type null|string $old_name The old field name (if preexisting).
|
| 2929 |
-
* @type null|string $old_definition The old field definition (if preexisting).
|
| 2930 |
-
* @type null|array $old_options The old field options (if preexisting).
|
| 2931 |
-
* }
|
| 2932 |
-
*/
|
| 2933 |
-
do_action( 'pods_api_save_field_table_pre_alter', $definition_mode, $pod, $field['type'], $field, array(
|
| 2934 |
-
'simple' => $simple,
|
| 2935 |
-
'definition' => $definition,
|
| 2936 |
-
'old_name' => $old_name,
|
| 2937 |
-
'old_definition' => $old_definition,
|
| 2938 |
-
'old_options' => $old_options,
|
| 2939 |
-
) );
|
| 2940 |
-
|
| 2941 |
-
if ( 'drop' === $definition_mode ) {
|
| 2942 |
-
// Drop field column.
|
| 2943 |
-
pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` DROP COLUMN `{$old_name}`", false );
|
| 2944 |
-
} elseif ( 'change' === $definition_mode ) {
|
| 2945 |
-
// Change field column definition.
|
| 2946 |
-
if ( $old_name && $old_name !== $field['name'] ) {
|
| 2947 |
-
$test = pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` CHANGE `{$old_name}` {$definition}", false );
|
| 2948 |
-
} else {
|
| 2949 |
-
$test = pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` MODIFY {$definition}", false );
|
| 2950 |
-
}
|
| 2951 |
-
|
| 2952 |
-
if ( false === $test ) {
|
| 2953 |
-
$definition_mode = 'add';
|
| 2954 |
-
}
|
| 2955 |
-
}
|
| 2956 |
-
|
| 2957 |
-
// If the old field doesn't exist, continue to add a new field
|
| 2958 |
-
if ( 'add' === $definition_mode ) {
|
| 2959 |
-
pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` ADD COLUMN {$definition}", __( 'Cannot create new field', 'pods' ) );
|
| 2960 |
-
}
|
| 2961 |
-
|
| 2962 |
-
/**
|
| 2963 |
-
* Allow hooking into after the table has been altered for any custom functionality needed.
|
| 2964 |
-
*
|
| 2965 |
-
* @since 2.7.17
|
| 2966 |
-
*
|
| 2967 |
-
* @param string $definition_mode The definition mode used for the table field.
|
| 2968 |
-
* @param array $pod The pod object.
|
| 2969 |
-
* @param string $type The field type.
|
| 2970 |
-
* @param array $field The field object.
|
| 2971 |
-
* @param array $extra_info {
|
| 2972 |
-
* Extra information about the field.
|
| 2973 |
-
*
|
| 2974 |
-
* @type bool $simple Whether the field is a simple tableless field.
|
| 2975 |
-
* @type string $definition The field definition.
|
| 2976 |
-
* @type null|string $old_name The old field name (if preexisting).
|
| 2977 |
-
* @type null|string $old_definition The old field definition (if preexisting).
|
| 2978 |
-
* @type null|array $old_options The old field options (if preexisting).
|
| 2979 |
-
* }
|
| 2980 |
-
*/
|
| 2981 |
-
do_action( 'pods_api_save_field_table_altered', $definition_mode, $pod, $field['type'], $field, array(
|
| 2982 |
-
'simple' => $simple,
|
| 2983 |
-
'definition' => $definition,
|
| 2984 |
-
'old_name' => $old_name,
|
| 2985 |
-
'old_definition' => $old_definition,
|
| 2986 |
-
'old_options' => $old_options,
|
| 2987 |
-
) );
|
| 2988 |
-
}
|
| 2989 |
-
}
|
| 2990 |
-
|
| 2991 |
-
if ( ! empty( $old_id ) && 'meta' === $pod['storage'] && $old_name !== $field['name'] && $pod['meta_table'] !== $pod['table'] ) {
|
| 2992 |
-
$prepare = array(
|
| 2993 |
-
$field['name'],
|
| 2994 |
-
$old_name
|
| 2995 |
-
);
|
| 2996 |
-
|
| 2997 |
-
// Users don't have a type
|
| 2998 |
-
if ( ! empty( $pod['field_type'] ) ) {
|
| 2999 |
-
$prepare[] = $pod['name'];
|
| 3000 |
-
}
|
| 3001 |
-
|
| 3002 |
-
$join_table = $pod['table'];
|
| 3003 |
-
|
| 3004 |
-
// Taxonomies are the odd type out, terrible I know
|
| 3005 |
-
if ( 'taxonomy' === $pod['type'] ) {
|
| 3006 |
-
// wp_term_taxonomy has the 'taxonomy' field we need to limit by
|
| 3007 |
-
$join_table = $wpdb->term_taxonomy;
|
| 3008 |
-
}
|
| 3009 |
-
|
| 3010 |
-
pods_query( "
|
| 3011 |
-
UPDATE `{$pod[ 'meta_table' ]}` AS `m`
|
| 3012 |
-
LEFT JOIN `{$join_table}` AS `t`
|
| 3013 |
-
ON `t`.`{$pod[ 'field_id' ]}` = `m`.`{$pod[ 'meta_field_id' ]}`
|
| 3014 |
-
SET
|
| 3015 |
-
`m`.`{$pod[ 'meta_field_index' ]}` = %s
|
| 3016 |
-
WHERE
|
| 3017 |
-
`m`.`{$pod[ 'meta_field_index' ]}` = %s
|
| 3018 |
-
" . ( ! empty( $pod['field_type'] ) ? " AND `t`.`{$pod[ 'field_type' ]}` = %s" : "" ), $prepare );
|
| 3019 |
-
}
|
| 3020 |
-
|
| 3021 |
-
if ( $field['type'] !== $old_type && in_array( $old_type, $tableless_field_types ) ) {
|
| 3022 |
-
delete_post_meta( $old_sister_id, 'sister_id' );
|
| 3023 |
-
|
| 3024 |
-
if ( true === $db ) {
|
| 3025 |
-
pods_query( "
|
| 3026 |
-
DELETE pm
|
| 3027 |
-
FROM {$wpdb->postmeta} AS pm
|
| 3028 |
-
LEFT JOIN {$wpdb->posts} AS p
|
| 3029 |
-
ON p.post_type = '_pods_field'
|
| 3030 |
-
AND p.ID = pm.post_id
|
| 3031 |
-
WHERE
|
| 3032 |
-
p.ID IS NOT NULL
|
| 3033 |
-
AND pm.meta_key = 'sister_id'
|
| 3034 |
-
AND pm.meta_value = %d
|
| 3035 |
-
", array(
|
| 3036 |
-
$params->id
|
| 3037 |
-
) );
|
| 3038 |
-
|
| 3039 |
-
if ( ! pods_tableless() ) {
|
| 3040 |
-
pods_query( "DELETE FROM @wp_podsrel WHERE `field_id` = {$params->id}", false );
|
| 3041 |
-
|
| 3042 |
-
pods_query( "
|
| 3043 |
-
UPDATE `@wp_podsrel`
|
| 3044 |
-
SET `related_field_id` = 0
|
| 3045 |
-
WHERE `field_id` = %d
|
| 3046 |
-
", array(
|
| 3047 |
-
$old_sister_id
|
| 3048 |
-
) );
|
| 3049 |
-
}
|
| 3050 |
-
}
|
| 3051 |
-
} elseif ( 0 < $sister_id ) {
|
| 3052 |
-
update_post_meta( $sister_id, 'sister_id', $params->id );
|
| 3053 |
-
|
| 3054 |
-
if ( true === $db && ( ! pods_tableless() ) ) {
|
| 3055 |
-
pods_query( "
|
| 3056 |
-
UPDATE `@wp_podsrel`
|
| 3057 |
-
SET `related_field_id` = %d
|
| 3058 |
-
WHERE `field_id` = %d
|
| 3059 |
-
", array(
|
| 3060 |
-
$params->id,
|
| 3061 |
-
$sister_id
|
| 3062 |
-
) );
|
| 3063 |
-
}
|
| 3064 |
-
} elseif ( 0 < $old_sister_id ) {
|
| 3065 |
-
delete_post_meta( $old_sister_id, 'sister_id' );
|
| 3066 |
-
|
| 3067 |
-
if ( true === $db && ( ! pods_tableless() ) ) {
|
| 3068 |
-
pods_query( "
|
| 3069 |
-
UPDATE `@wp_podsrel`
|
| 3070 |
-
SET `related_field_id` = 0
|
| 3071 |
-
WHERE `field_id` = %d
|
| 3072 |
-
", array(
|
| 3073 |
-
$old_sister_id
|
| 3074 |
-
) );
|
| 3075 |
-
}
|
| 3076 |
-
}
|
| 3077 |
-
|
| 3078 |
-
if ( ! empty( $old_id ) && $old_name !== $field['name'] && true === $db ) {
|
| 3079 |
-
pods_query( "
|
| 3080 |
-
UPDATE `@wp_postmeta`
|
| 3081 |
-
SET `meta_value` = %s
|
| 3082 |
-
WHERE
|
| 3083 |
-
`post_id` = %d
|
| 3084 |
-
AND `meta_key` = 'pod_index'
|
| 3085 |
-
AND `meta_value` = %s
|
| 3086 |
-
", array(
|
| 3087 |
-
$field['name'],
|
| 3088 |
-
$pod['id'],
|
| 3089 |
-
$old_name
|
| 3090 |
-
) );
|
| 3091 |
-
}
|
| 3092 |
-
|
| 3093 |
-
if ( ! $save_pod ) {
|
| 3094 |
-
$this->cache_flush_pods( $pod );
|
| 3095 |
-
} else {
|
| 3096 |
-
pods_transient_clear( 'pods_field_' . $pod['name'] . '_' . $field['name'] );
|
| 3097 |
-
|
| 3098 |
-
if ( ! empty( $old_id ) && $old_name !== $field['name'] ) {
|
| 3099 |
-
pods_transient_clear( 'pods_field_' . $pod['name'] . '_' . $old_name );
|
| 3100 |
-
}
|
| 3101 |
-
}
|
| 3102 |
-
|
| 3103 |
-
if ( true === $db ) {
|
| 3104 |
-
return $params->id;
|
| 3105 |
-
} else {
|
| 3106 |
-
return $field;
|
| 3107 |
-
}
|
| 3108 |
-
}
|
| 3109 |
-
|
| 3110 |
-
/**
|
| 3111 |
-
* Fix Pod / Field post_name to ensure they are exactly as saved (allow multiple posts w/ same post_name)
|
| 3112 |
-
*
|
| 3113 |
-
* @param string $slug Unique slug value
|
| 3114 |
-
* @param int $post_ID Post ID
|
| 3115 |
-
* @param string $post_status Post Status
|
| 3116 |
-
* @param string $post_type Post Type
|
| 3117 |
-
* @param int $post_parent Post Parent ID
|
| 3118 |
-
* @param string $original_slug Original slug value
|
| 3119 |
-
*
|
| 3120 |
-
* @return string Final slug value
|
| 3121 |
-
*
|
| 3122 |
-
* @since 2.3.3
|
| 3123 |
-
*/
|
| 3124 |
-
public function save_slug_fix( $slug, $post_ID, $post_status, $post_type, $post_parent = 0, $original_slug = null ) {
|
| 3125 |
-
|
| 3126 |
-
if ( in_array( $post_type, array( '_pods_field', '_pods_pod' ) ) && false !== strpos( $slug, '-' ) ) {
|
| 3127 |
-
$slug = $original_slug;
|
| 3128 |
-
}
|
| 3129 |
-
|
| 3130 |
-
return $slug;
|
| 3131 |
-
}
|
| 3132 |
-
|
| 3133 |
-
/**
|
| 3134 |
-
* Add or Edit a Pods Object
|
| 3135 |
-
*
|
| 3136 |
-
* $params['id'] int The Object ID
|
| 3137 |
-
* $params['name'] string The Object name
|
| 3138 |
-
* $params['type'] string The Object type
|
| 3139 |
-
* $params['options'] Associative array of Object options
|
| 3140 |
-
*
|
| 3141 |
-
* @param array|object $params An associative array of parameters
|
| 3142 |
-
* @param bool $sanitized (optional) Decides whether the params have been sanitized before being passed,
|
| 3143 |
-
* will sanitize them if false.
|
| 3144 |
-
*
|
| 3145 |
-
* @return int The Object ID
|
| 3146 |
-
* @since 2.0.0
|
| 3147 |
-
*/
|
| 3148 |
-
public function save_object( $params, $sanitized = false ) {
|
| 3149 |
-
|
| 3150 |
-
$params = (object) $params;
|
| 3151 |
-
|
| 3152 |
-
if ( false === $sanitized ) {
|
| 3153 |
-
$params = pods_sanitize( $params );
|
| 3154 |
-
}
|
| 3155 |
-
|
| 3156 |
-
if ( ! isset( $params->name ) || empty( $params->name ) ) {
|
| 3157 |
-
return pods_error( __( 'Name must be given to save an Object', 'pods' ), $this );
|
| 3158 |
-
}
|
| 3159 |
-
|
| 3160 |
-
if ( ! isset( $params->type ) || empty( $params->type ) ) {
|
| 3161 |
-
return pods_error( __( 'Type must be given to save an Object', 'pods' ), $this );
|
| 3162 |
-
}
|
| 3163 |
-
|
| 3164 |
-
$object = array(
|
| 3165 |
-
'id' => 0,
|
| 3166 |
-
'name' => $params->name,
|
| 3167 |
-
'type' => $params->type,
|
| 3168 |
-
'code' => '',
|
| 3169 |
-
'options' => array()
|
| 3170 |
-
);
|
| 3171 |
-
|
| 3172 |
-
// Setup options
|
| 3173 |
-
$options = get_object_vars( $params );
|
| 3174 |
-
|
| 3175 |
-
if ( isset( $options['method'] ) ) {
|
| 3176 |
-
unset( $options['method'] );
|
| 3177 |
-
}
|
| 3178 |
-
|
| 3179 |
-
$exclude = array(
|
| 3180 |
-
'id',
|
| 3181 |
-
'name',
|
| 3182 |
-
'helper_type',
|
| 3183 |
-
'code',
|
| 3184 |
-
'options',
|
| 3185 |
-
'status'
|
| 3186 |
-
);
|
| 3187 |
-
|
| 3188 |
-
foreach ( $exclude as $k => $exclude_field ) {
|
| 3189 |
-
$aliases = array( $exclude_field );
|
| 3190 |
-
|
| 3191 |
-
if ( is_array( $exclude_field ) ) {
|
| 3192 |
-
$aliases = array_merge( array( $k ), $exclude_field );
|
| 3193 |
-
$exclude_field = $k;
|
| 3194 |
-
}
|
| 3195 |
-
|
| 3196 |
-
foreach ( $aliases as $alias ) {
|
| 3197 |
-
if ( isset( $options[ $alias ] ) ) {
|
| 3198 |
-
$object[ $exclude_field ] = pods_trim( $options[ $alias ] );
|
| 3199 |
-
|
| 3200 |
-
unset( $options[ $alias ] );
|
| 3201 |
-
}
|
| 3202 |
-
}
|
| 3203 |
-
}
|
| 3204 |
-
|
| 3205 |
-
if ( 'helper' === $object['type'] ) {
|
| 3206 |
-
$object['options']['helper_type'] = $object['helper_type'];
|
| 3207 |
-
}
|
| 3208 |
-
|
| 3209 |
-
if ( isset( $object['options']['code'] ) ) {
|
| 3210 |
-
unset( $object['options']['code'] );
|
| 3211 |
-
}
|
| 3212 |
-
|
| 3213 |
-
$object['options'] = array_merge( $object['options'], $options );
|
| 3214 |
-
|
| 3215 |
-
$post_data = array(
|
| 3216 |
-
'post_name' => pods_clean_name( $object['name'], true ),
|
| 3217 |
-
'post_title' => $object['name'],
|
| 3218 |
-
'post_content' => $object['code'],
|
| 3219 |
-
'post_type' => '_pods_' . $object['type'],
|
| 3220 |
-
'post_status' => 'publish'
|
| 3221 |
-
);
|
| 3222 |
-
|
| 3223 |
-
if ( ! empty( $object['id'] ) ) {
|
| 3224 |
-
$post_data['ID'] = $object['id'];
|
| 3225 |
-
}
|
| 3226 |
-
|
| 3227 |
-
if ( null !== pods_var( 'status', $object, null, null, true ) ) {
|
| 3228 |
-
$post_data['post_status'] = pods_var( 'status', $object, null, null, true );
|
| 3229 |
-
}
|
| 3230 |
-
|
| 3231 |
-
remove_filter( 'content_save_pre', 'balanceTags', 50 );
|
| 3232 |
-
|
| 3233 |
-
$post_data = pods_sanitize( $post_data );
|
| 3234 |
-
|
| 3235 |
-
$params->id = $this->save_post( $post_data, $object['options'], true, true );
|
| 3236 |
-
|
| 3237 |
-
pods_transient_clear( 'pods_objects_' . $params->type );
|
| 3238 |
-
pods_transient_clear( 'pods_objects_' . $params->type . '_get' );
|
| 3239 |
-
|
| 3240 |
-
return $params->id;
|
| 3241 |
-
}
|
| 3242 |
-
|
| 3243 |
-
/**
|
| 3244 |
-
* @see PodsAPI::save_object
|
| 3245 |
-
*
|
| 3246 |
-
* Add or edit a Pod Template
|
| 3247 |
-
*
|
| 3248 |
-
* $params['id'] int The template ID
|
| 3249 |
-
* $params['name'] string The template name
|
| 3250 |
-
* $params['code'] string The template code
|
| 3251 |
-
*
|
| 3252 |
-
* @param array|object $params An associative array of parameters
|
| 3253 |
-
* @param bool $sanitized (optional) Decides wether the params have been sanitized before being passed,
|
| 3254 |
-
* will sanitize them if false.
|
| 3255 |
-
*
|
| 3256 |
-
* @return int The Template ID
|
| 3257 |
-
*
|
| 3258 |
-
* @since 1.7.9
|
| 3259 |
-
*/
|
| 3260 |
-
public function save_template( $params, $sanitized = false ) {
|
| 3261 |
-
|
| 3262 |
-
$params = (object) $params;
|
| 3263 |
-
|
| 3264 |
-
$params->type = 'template';
|
| 3265 |
-
|
| 3266 |
-
return $this->save_object( $params, $sanitized );
|
| 3267 |
-
}
|
| 3268 |
-
|
| 3269 |
-
/**
|
| 3270 |
-
* @see PodsAPI::save_object
|
| 3271 |
-
*
|
| 3272 |
-
* Add or edit a Pod Page
|
| 3273 |
-
*
|
| 3274 |
-
* $params['id'] int The page ID
|
| 3275 |
-
* $params['name'] string The page URI
|
| 3276 |
-
* $params['code'] string The page code
|
| 3277 |
-
*
|
| 3278 |
-
* @param array|object $params An associative array of parameters
|
| 3279 |
-
* @param bool $sanitized (optional) Decides wether the params have been sanitized before being passed,
|
| 3280 |
-
* will sanitize them if false.
|
| 3281 |
-
*
|
| 3282 |
-
* @return int The page ID
|
| 3283 |
-
* @since 1.7.9
|
| 3284 |
-
*/
|
| 3285 |
-
public function save_page( $params, $sanitized = false ) {
|
| 3286 |
-
|
| 3287 |
-
$params = (object) $params;
|
| 3288 |
-
|
| 3289 |
-
if ( ! isset( $params->name ) ) {
|
| 3290 |
-
$params->name = $params->uri;
|
| 3291 |
-
unset( $params->uri );
|
| 3292 |
-
}
|
| 3293 |
-
|
| 3294 |
-
if ( isset( $params->phpcode ) ) {
|
| 3295 |
-
$params->code = $params->phpcode;
|
| 3296 |
-
unset( $params->phpcode );
|
| 3297 |
-
}
|
| 3298 |
-
|
| 3299 |
-
$params->name = trim( $params->name, '/' );
|
| 3300 |
-
$params->type = 'page';
|
| 3301 |
-
|
| 3302 |
-
return $this->save_object( $params, $sanitized );
|
| 3303 |
-
}
|
| 3304 |
-
|
| 3305 |
-
/**
|
| 3306 |
-
* @see PodsAPI::save_object
|
| 3307 |
-
*
|
| 3308 |
-
* Add or edit a Pod Helper
|
| 3309 |
-
*
|
| 3310 |
-
* $params['id'] int The helper ID
|
| 3311 |
-
* $params['name'] string The helper name
|
| 3312 |
-
* $params['helper_type'] string The helper type ("pre_save", "display", etc)
|
| 3313 |
-
* $params['code'] string The helper code
|
| 3314 |
-
*
|
| 3315 |
-
* @param array $params An associative array of parameters
|
| 3316 |
-
* @param bool $sanitized (optional) Decides wether the params have been sanitized before being passed, will
|
| 3317 |
-
* sanitize them if false.
|
| 3318 |
-
*
|
| 3319 |
-
* @return int The helper ID
|
| 3320 |
-
* @since 1.7.9
|
| 3321 |
-
*/
|
| 3322 |
-
public function save_helper( $params, $sanitized = false ) {
|
| 3323 |
-
|
| 3324 |
-
$params = (object) $params;
|
| 3325 |
-
|
| 3326 |
-
if ( isset( $params->phpcode ) ) {
|
| 3327 |
-
$params->code = $params->phpcode;
|
| 3328 |
-
unset( $params->phpcode );
|
| 3329 |
-
}
|
| 3330 |
-
|
| 3331 |
-
if ( isset( $params->type ) ) {
|
| 3332 |
-
$params->helper_type = $params->type;
|
| 3333 |
-
unset( $params->type );
|
| 3334 |
-
}
|
| 3335 |
-
|
| 3336 |
-
$params->type = 'helper';
|
| 3337 |
-
|
| 3338 |
-
return $this->save_object( $params, $sanitized );
|
| 3339 |
-
}
|
| 3340 |
-
|
| 3341 |
-
/**
|
| 3342 |
-
* Add or edit a single pod item
|
| 3343 |
-
*
|
| 3344 |
-
* $params['pod'] string The Pod name (pod or pod_id is required)
|
| 3345 |
-
* $params['pod_id'] string The Pod ID (pod or pod_id is required)
|
| 3346 |
-
* $params['id'] int|array The item ID, or an array of item IDs to save data for
|
| 3347 |
-
* $params['data'] array (optional) Associative array of field names + values
|
| 3348 |
-
* $params['bypass_helpers'] bool Set to true to bypass running pre-save and post-save helpers
|
| 3349 |
-
* $params['track_changed_fields'] bool Set to true to enable tracking of saved fields via
|
| 3350 |
-
* PodsAPI::get_changed_fields()
|
| 3351 |
-
* $params['error_mode'] string Throw an 'exception', 'exit' with the message, return 'false', or return 'wp_error'
|
| 3352 |
-
*
|
| 3353 |
-
* @param array|object $params An associative array of parameters
|
| 3354 |
-
*
|
| 3355 |
-
* @return int|array The item ID, or an array of item IDs (if `id` is an array if IDs)
|
| 3356 |
-
*
|
| 3357 |
-
* @since 1.7.9
|
| 3358 |
-
*/
|
| 3359 |
-
public function save_pod_item( $params ) {
|
| 3360 |
-
|
| 3361 |
-
global $wpdb;
|
| 3362 |
-
|
| 3363 |
-
$params = (object) pods_str_replace( '@wp_', '{prefix}', $params );
|
| 3364 |
-
|
| 3365 |
-
$tableless_field_types = PodsForm::tableless_field_types();
|
| 3366 |
-
$repeatable_field_types = PodsForm::repeatable_field_types();
|
| 3367 |
-
$simple_tableless_objects = PodsForm::simple_tableless_objects();
|
| 3368 |
-
|
| 3369 |
-
$error_mode = $this->display_errors;
|
| 3370 |
-
|
| 3371 |
-
if ( ! empty( $params->error_mode ) ) {
|
| 3372 |
-
$error_mode = $params->error_mode;
|
| 3373 |
-
}
|
| 3374 |
-
|
| 3375 |
-
// @deprecated 2.0.0
|
| 3376 |
-
if ( isset( $params->datatype ) ) {
|
| 3377 |
-
pods_deprecated( '$params->pod instead of $params->datatype', '2.0' );
|
| 3378 |
-
|
| 3379 |
-
$params->pod = $params->datatype;
|
| 3380 |
-
|
| 3381 |
-
unset( $params->datatype );
|
| 3382 |
-
|
| 3383 |
-
if ( isset( $params->pod_id ) ) {
|
| 3384 |
-
pods_deprecated( '$params->id instead of $params->pod_id', '2.0' );
|
| 3385 |
-
|
| 3386 |
-
$params->id = $params->pod_id;
|
| 3387 |
-
|
| 3388 |
-
unset( $params->pod_id );
|
| 3389 |
-
}
|
| 3390 |
-
|
| 3391 |
-
if ( isset( $params->data ) && ! empty( $params->data ) && is_array( $params->data ) ) {
|
| 3392 |
-
$check = current( $params->data );
|
| 3393 |
-
|
| 3394 |
-
if ( is_array( $check ) ) {
|
| 3395 |
-
pods_deprecated( 'PodsAPI::save_pod_items', '2.0' );
|
| 3396 |
-
|
| 3397 |
-
return $this->save_pod_items( $params, $params->data );
|
| 3398 |
-
}
|
| 3399 |
-
}
|
| 3400 |
-
}
|
| 3401 |
-
|
| 3402 |
-
// @deprecated 2.0.0
|
| 3403 |
-
if ( isset( $params->tbl_row_id ) ) {
|
| 3404 |
-
pods_deprecated( '$params->id instead of $params->tbl_row_id', '2.0' );
|
| 3405 |
-
|
| 3406 |
-
$params->id = $params->tbl_row_id;
|
| 3407 |
-
|
| 3408 |
-
unset( $params->tbl_row_id );
|
| 3409 |
-
}
|
| 3410 |
-
|
| 3411 |
-
// @deprecated 2.0.0
|
| 3412 |
-
if ( isset( $params->columns ) ) {
|
| 3413 |
-
pods_deprecated( '$params->data instead of $params->columns', '2.0' );
|
| 3414 |
-
|
| 3415 |
-
$params->data = $params->columns;
|
| 3416 |
-
|
| 3417 |
-
unset( $params->columns );
|
| 3418 |
-
}
|
| 3419 |
-
|
| 3420 |
-
if ( ! isset( $params->pod ) ) {
|
| 3421 |
-
$params->pod = false;
|
| 3422 |
-
}
|
| 3423 |
-
if ( isset( $params->pod_id ) ) {
|
| 3424 |
-
$params->pod_id = pods_absint( $params->pod_id );
|
| 3425 |
-
} else {
|
| 3426 |
-
$params->pod_id = 0;
|
| 3427 |
-
}
|
| 3428 |
-
|
| 3429 |
-
if ( isset( $params->id ) ) {
|
| 3430 |
-
$params->id = pods_absint( $params->id );
|
| 3431 |
-
} else {
|
| 3432 |
-
$params->id = 0;
|
| 3433 |
-
}
|
| 3434 |
-
|
| 3435 |
-
if ( ! isset( $params->from ) ) {
|
| 3436 |
-
$params->from = 'save';
|
| 3437 |
-
}
|
| 3438 |
-
|
| 3439 |
-
if ( ! isset( $params->location ) ) {
|
| 3440 |
-
$params->location = null;
|
| 3441 |
-
}
|
| 3442 |
-
|
| 3443 |
-
if ( ! isset( $params->track_changed_fields ) ) {
|
| 3444 |
-
$params->track_changed_fields = false;
|
| 3445 |
-
}
|
| 3446 |
-
|
| 3447 |
-
$pod_name = $params->pod;
|
| 3448 |
-
/**
|
| 3449 |
-
* Override $params['track_changed_fields']
|
| 3450 |
-
*
|
| 3451 |
-
* Use for globally setting field change tracking.
|
| 3452 |
-
*
|
| 3453 |
-
* @param bool
|
| 3454 |
-
*
|
| 3455 |
-
* @since 2.3.19
|
| 3456 |
-
*/
|
| 3457 |
-
$track_changed_fields = apply_filters( "pods_api_save_pod_item_track_changed_fields_{$pod_name}", (boolean) $params->track_changed_fields, $params );
|
| 3458 |
-
|
| 3459 |
-
$changed_fields = array();
|
| 3460 |
-
|
| 3461 |
-
if ( ! isset( $params->clear_slug_cache ) ) {
|
| 3462 |
-
$params->clear_slug_cache = true;
|
| 3463 |
-
}
|
| 3464 |
-
|
| 3465 |
-
// Support for bulk edit
|
| 3466 |
-
if ( isset( $params->id ) && ! empty( $params->id ) && is_array( $params->id ) ) {
|
| 3467 |
-
$ids = array();
|
| 3468 |
-
$new_params = $params;
|
| 3469 |
-
|
| 3470 |
-
foreach ( $params->id as $id ) {
|
| 3471 |
-
$new_params->id = $id;
|
| 3472 |
-
|
| 3473 |
-
$ids[] = $this->save_pod_item( $new_params );
|
| 3474 |
-
}
|
| 3475 |
-
|
| 3476 |
-
return $ids;
|
| 3477 |
-
}
|
| 3478 |
-
|
| 3479 |
-
// Allow Helpers to know what's going on, are we adding or saving?
|
| 3480 |
-
$is_new_item = false;
|
| 3481 |
-
|
| 3482 |
-
if ( empty( $params->id ) ) {
|
| 3483 |
-
$is_new_item = true;
|
| 3484 |
-
}
|
| 3485 |
-
|
| 3486 |
-
if ( isset( $params->is_new_item ) ) {
|
| 3487 |
-
$is_new_item = (boolean) $params->is_new_item;
|
| 3488 |
-
}
|
| 3489 |
-
|
| 3490 |
-
// Allow Helpers to bypass subsequent helpers in recursive save_pod_item calls
|
| 3491 |
-
$bypass_helpers = false;
|
| 3492 |
-
|
| 3493 |
-
if ( isset( $params->bypass_helpers ) && false !== $params->bypass_helpers ) {
|
| 3494 |
-
$bypass_helpers = true;
|
| 3495 |
-
}
|
| 3496 |
-
|
| 3497 |
-
// Allow Custom Fields not defined by Pods to be saved
|
| 3498 |
-
$allow_custom_fields = false;
|
| 3499 |
-
|
| 3500 |
-
if ( isset( $params->allow_custom_fields ) && false !== $params->allow_custom_fields ) {
|
| 3501 |
-
$allow_custom_fields = true;
|
| 3502 |
-
}
|
| 3503 |
-
|
| 3504 |
-
// Get array of Pods
|
| 3505 |
-
$pod = $this->load_pod( array( 'id' => $params->pod_id, 'name' => $params->pod, 'table_info' => true ) );
|
| 3506 |
-
|
| 3507 |
-
if ( false === $pod ) {
|
| 3508 |
-
return pods_error( __( 'Pod not found', 'pods' ), $error_mode );
|
| 3509 |
-
}
|
| 3510 |
-
|
| 3511 |
-
$params->pod = $pod['name'];
|
| 3512 |
-
$params->pod_id = $pod['id'];
|
| 3513 |
-
|
| 3514 |
-
if ( 'settings' === $pod['type'] ) {
|
| 3515 |
-
$params->id = $pod['id'];
|
| 3516 |
-
}
|
| 3517 |
-
|
| 3518 |
-
$fields = $pod['fields'];
|
| 3519 |
-
|
| 3520 |
-
$object_fields = (array) pods_var_raw( 'object_fields', $pod, array(), null, true );
|
| 3521 |
-
|
| 3522 |
-
$fields_active = array();
|
| 3523 |
-
$custom_data = array();
|
| 3524 |
-
$custom_fields = array();
|
| 3525 |
-
|
| 3526 |
-
// Find the active fields (loop through $params->data to retain order)
|
| 3527 |
-
if ( ! empty( $params->data ) && is_array( $params->data ) ) {
|
| 3528 |
-
foreach ( $params->data as $field => $value ) {
|
| 3529 |
-
if ( isset( $object_fields[ $field ] ) ) {
|
| 3530 |
-
$object_fields[ $field ]['value'] = $value;
|
| 3531 |
-
$fields_active[] = $field;
|
| 3532 |
-
} elseif ( isset( $fields[ $field ] ) ) {
|
| 3533 |
-
if ( 'save' === $params->from || true === PodsForm::permission( $fields[ $field ]['type'], $field, $fields[ $field ], $fields, $pod, $params->id, $params ) ) {
|
| 3534 |
-
$fields[ $field ]['value'] = $value;
|
| 3535 |
-
$fields_active[] = $field;
|
| 3536 |
-
} elseif ( ! pods_has_permissions( $fields[ $field ]['options'] ) && pods_var( 'hidden', $fields[ $field ]['options'], false ) ) {
|
| 3537 |
-
$fields[ $field ]['value'] = $value;
|
| 3538 |
-
$fields_active[] = $field;
|
| 3539 |
-
}
|
| 3540 |
-
} else {
|
| 3541 |
-
$found = false;
|
| 3542 |
-
|
| 3543 |
-
foreach ( $object_fields as $object_field => $object_field_opt ) {
|
| 3544 |
-
if ( in_array( $field, $object_field_opt['alias'] ) ) {
|
| 3545 |
-
$object_fields[ $object_field ]['value'] = $value;
|
| 3546 |
-
$fields_active[] = $object_field;
|
| 3547 |
-
|
| 3548 |
-
$found = true;
|
| 3549 |
-
|
| 3550 |
-
break;
|
| 3551 |
-
}
|
| 3552 |
-
}
|
| 3553 |
-
|
| 3554 |
-
if ( $allow_custom_fields && ! $found ) {
|
| 3555 |
-
$custom_fields[] = $field;
|
| 3556 |
-
}
|
| 3557 |
-
}
|
| 3558 |
-
}
|
| 3559 |
-
|
| 3560 |
-
if ( $allow_custom_fields && ! empty( $custom_fields ) ) {
|
| 3561 |
-
foreach ( $custom_fields as $field ) {
|
| 3562 |
-
$custom_data[ $field ] = $params->data[ $field ];
|
| 3563 |
-
}
|
| 3564 |
-
}
|
| 3565 |
-
|
| 3566 |
-
unset( $params->data );
|
| 3567 |
-
}
|
| 3568 |
-
|
| 3569 |
-
if ( empty( $params->id ) && ! in_array( 'created', $fields_active ) && isset( $fields['created'] ) && in_array( $fields['created']['type'], array(
|
| 3570 |
-
'date',
|
| 3571 |
-
'datetime'
|
| 3572 |
-
) ) ) {
|
| 3573 |
-
$fields['created']['value'] = current_time( 'mysql' );
|
| 3574 |
-
$fields_active[] = 'created';
|
| 3575 |
-
}
|
| 3576 |
-
|
| 3577 |
-
if ( ! in_array( 'modified', $fields_active ) && isset( $fields['modified'] ) && in_array( $fields['modified']['type'], array(
|
| 3578 |
-
'date',
|
| 3579 |
-
'datetime'
|
| 3580 |
-
) ) ) {
|
| 3581 |
-
$fields['modified']['value'] = current_time( 'mysql' );
|
| 3582 |
-
$fields_active[] = 'modified';
|
| 3583 |
-
}
|
| 3584 |
-
|
| 3585 |
-
if ( in_array( $pod['type'], array(
|
| 3586 |
-
'pod',
|
| 3587 |
-
'table'
|
| 3588 |
-
) ) && empty( $params->id ) && ! empty( $pod['pod_field_index'] ) && in_array( $pod['pod_field_index'], $fields_active ) && ! in_array( $pod['pod_field_slug'], $fields_active ) && isset( $fields[ $pod['pod_field_slug'] ] ) ) {
|
| 3589 |
-
$fields[ $pod['pod_field_slug'] ]['value'] = ''; // this will get picked up by slug pre_save method
|
| 3590 |
-
$fields_active[] = $pod['pod_field_slug'];
|
| 3591 |
-
}
|
| 3592 |
-
|
| 3593 |
-
// Handle hidden fields
|
| 3594 |
-
if ( empty( $params->id ) ) {
|
| 3595 |
-
foreach ( $fields as $field => $field_data ) {
|
| 3596 |
-
if ( in_array( $field, $fields_active ) ) {
|
| 3597 |
-
continue;
|
| 3598 |
-
}
|
| 3599 |
-
|
| 3600 |
-
if ( in_array( $params->from, array(
|
| 3601 |
-
'save',
|
| 3602 |
-
'process_form'
|
| 3603 |
-
) ) || true === PodsForm::permission( $fields[ $field ]['type'], $field, $fields[ $field ], $fields, $pod, $params->id, $params ) ) {
|
| 3604 |
-
$value = PodsForm::default_value( pods_var_raw( $field, 'post' ), $field_data['type'], $field, pods_var_raw( 'options', $field_data, $field_data, null, true ), $pod, $params->id );
|
| 3605 |
-
|
| 3606 |
-
if ( null !== $value && '' !== $value && false !== $value ) {
|
| 3607 |
-
$fields[ $field ]['value'] = $value;
|
| 3608 |
-
$fields_active[] = $field;
|
| 3609 |
-
}
|
| 3610 |
-
}
|
| 3611 |
-
}
|
| 3612 |
-
|
| 3613 |
-
// Set default field values for object fields
|
| 3614 |
-
if ( ! empty( $object_fields ) ) {
|
| 3615 |
-
foreach ( $object_fields as $field => $field_data ) {
|
| 3616 |
-
if ( in_array( $field, $fields_active ) ) {
|
| 3617 |
-
continue;
|
| 3618 |
-
} elseif ( ! isset( $field_data['default'] ) || strlen( $field_data['default'] ) < 1 ) {
|
| 3619 |
-
continue;
|
| 3620 |
-
}
|
| 3621 |
-
|
| 3622 |
-
$value = PodsForm::default_value( pods_var_raw( $field, 'post' ), $field_data['type'], $field, pods_var_raw( 'options', $field_data, $field_data, null, true ), $pod, $params->id );
|
| 3623 |
-
|
| 3624 |
-
if ( null !== $value && '' !== $value && false !== $value ) {
|
| 3625 |
-
$object_fields[ $field ]['value'] = $value;
|
| 3626 |
-
$fields_active[] = $field;
|
| 3627 |
-
}
|
| 3628 |
-
}
|
| 3629 |
-
}
|
| 3630 |
-
|
| 3631 |
-
// Set default field values for Pod fields
|
| 3632 |
-
foreach ( $fields as $field => $field_data ) {
|
| 3633 |
-
if ( in_array( $field, $fields_active ) ) {
|
| 3634 |
-
continue;
|
| 3635 |
-
} elseif ( ! isset( $field_data['default'] ) || strlen( $field_data['default'] ) < 1 ) {
|
| 3636 |
-
continue;
|
| 3637 |
-
}
|
| 3638 |
-
|
| 3639 |
-
$value = PodsForm::default_value( pods_var_raw( $field, 'post' ), $field_data['type'], $field, pods_var_raw( 'options', $field_data, $field_data, null, true ), $pod, $params->id );
|
| 3640 |
-
|
| 3641 |
-
if ( null !== $value && '' !== $value && false !== $value ) {
|
| 3642 |
-
$fields[ $field ]['value'] = $value;
|
| 3643 |
-
$fields_active[] = $field;
|
| 3644 |
-
}
|
| 3645 |
-
}
|
| 3646 |
-
}
|
| 3647 |
-
|
| 3648 |
-
$columns =& $fields; // @deprecated 2.0.0
|
| 3649 |
-
$active_columns =& $fields_active; // @deprecated 2.0.0
|
| 3650 |
-
$params->tbl_row_id =& $params->id; // @deprecated 2.0.0
|
| 3651 |
-
|
| 3652 |
-
$pre_save_helpers = array();
|
| 3653 |
-
$post_save_helpers = array();
|
| 3654 |
-
|
| 3655 |
-
$pieces = array(
|
| 3656 |
-
'fields',
|
| 3657 |
-
'params',
|
| 3658 |
-
'pod',
|
| 3659 |
-
'fields_active',
|
| 3660 |
-
'object_fields',
|
| 3661 |
-
'custom_fields',
|
| 3662 |
-
'custom_data',
|
| 3663 |
-
'track_changed_fields',
|
| 3664 |
-
'changed_fields'
|
| 3665 |
-
);
|
| 3666 |
-
|
| 3667 |
-
if ( $track_changed_fields ) {
|
| 3668 |
-
self::handle_changed_fields( $params->pod, $params->id, 'set' );
|
| 3669 |
-
}
|
| 3670 |
-
|
| 3671 |
-
if ( false === $bypass_helpers ) {
|
| 3672 |
-
// Plugin hooks
|
| 3673 |
-
$hooked = $this->do_hook( 'pre_save_pod_item', compact( $pieces ), $is_new_item, $params->id );
|
| 3674 |
-
|
| 3675 |
-
if ( is_array( $hooked ) && ! empty( $hooked ) ) {
|
| 3676 |
-
extract( $hooked );
|
| 3677 |
-
}
|
| 3678 |
-
|
| 3679 |
-
$hooked = $this->do_hook( "pre_save_pod_item_{$params->pod}", compact( $pieces ), $is_new_item, $params->id );
|
| 3680 |
-
|
| 3681 |
-
if ( is_array( $hooked ) && ! empty( $hooked ) ) {
|
| 3682 |
-
extract( $hooked );
|
| 3683 |
-
}
|
| 3684 |
-
|
| 3685 |
-
if ( $is_new_item ) {
|
| 3686 |
-
$hooked = $this->do_hook( 'pre_create_pod_item', compact( $pieces ) );
|
| 3687 |
-
|
| 3688 |
-
if ( is_array( $hooked ) && ! empty( $hooked ) ) {
|
| 3689 |
-
extract( $hooked );
|
| 3690 |
-
}
|
| 3691 |
-
|
| 3692 |
-
$hooked = $this->do_hook( "pre_create_pod_item_{$params->pod}", compact( $pieces ) );
|
| 3693 |
-
|
| 3694 |
-
if ( is_array( $hooked ) && ! empty( $hooked ) ) {
|
| 3695 |
-
extract( $hooked );
|
| 3696 |
-
}
|
| 3697 |
-
} else {
|
| 3698 |
-
$hooked = $this->do_hook( 'pre_edit_pod_item', compact( $pieces ), $params->id );
|
| 3699 |
-
|
| 3700 |
-
if ( is_array( $hooked ) && ! empty( $hooked ) ) {
|
| 3701 |
-
extract( $hooked );
|
| 3702 |
-
}
|
| 3703 |
-
|
| 3704 |
-
$hooked = $this->do_hook( "pre_edit_pod_item_{$params->pod}", compact( $pieces ), $params->id );
|
| 3705 |
-
|
| 3706 |
-
if ( is_array( $hooked ) && ! empty( $hooked ) ) {
|
| 3707 |
-
extract( $hooked );
|
| 3708 |
-
}
|
| 3709 |
-
}
|
| 3710 |
-
|
| 3711 |
-
// Call any pre-save helpers (if not bypassed)
|
| 3712 |
-
if ( ! defined( 'PODS_DISABLE_EVAL' ) || ! PODS_DISABLE_EVAL ) {
|
| 3713 |
-
if ( ! empty( $pod['options'] ) && is_array( $pod['options'] ) ) {
|
| 3714 |
-
$helpers = array( 'pre_save_helpers', 'post_save_helpers' );
|
| 3715 |
-
|
| 3716 |
-
foreach ( $helpers as $helper ) {
|
| 3717 |
-
if ( isset( $pod['options'][ $helper ] ) && ! empty( $pod['options'][ $helper ] ) ) {
|
| 3718 |
-
${$helper} = explode( ',', $pod['options'][ $helper ] );
|
| 3719 |
-
}
|
| 3720 |
-
}
|
| 3721 |
-
}
|
| 3722 |
-
|
| 3723 |
-
if ( ! empty( $pre_save_helpers ) ) {
|
| 3724 |
-
pods_deprecated( sprintf( __( 'Pre-save helpers are deprecated, use the action pods_pre_save_pod_item_%s instead', 'pods' ), $params->pod ), '2.0' );
|
| 3725 |
-
|
| 3726 |
-
foreach ( $pre_save_helpers as $helper ) {
|
| 3727 |
-
$helper = $this->load_helper( array( 'name' => $helper ) );
|
| 3728 |
-
|
| 3729 |
-
if ( false !== $helper ) {
|
| 3730 |
-
eval( '?>' . $helper['code'] );
|
| 3731 |
-
}
|
| 3732 |
-
}
|
| 3733 |
-
}
|
| 3734 |
-
}
|
| 3735 |
-
}
|
| 3736 |
-
|
| 3737 |
-
$table_data = array();
|
| 3738 |
-
$table_formats = array();
|
| 3739 |
-
$update_values = array();
|
| 3740 |
-
$rel_fields = array();
|
| 3741 |
-
$rel_field_ids = array();
|
| 3742 |
-
|
| 3743 |
-
$object_type = $pod['type'];
|
| 3744 |
-
|
| 3745 |
-
$object_ID = 'ID';
|
| 3746 |
-
|
| 3747 |
-
if ( 'comment' === $object_type ) {
|
| 3748 |
-
$object_ID = 'comment_ID';
|
| 3749 |
-
} elseif ( 'taxonomy' === $object_type ) {
|
| 3750 |
-
$object_ID = 'term_id';
|
| 3751 |
-
}
|
| 3752 |
-
|
| 3753 |
-
$object_data = array();
|
| 3754 |
-
$object_meta = array();
|
| 3755 |
-
$post_term_data = array();
|
| 3756 |
-
|
| 3757 |
-
if ( 'settings' === $object_type ) {
|
| 3758 |
-
$object_data['option_id'] = $pod['name'];
|
| 3759 |
-
} elseif ( ! empty( $params->id ) ) {
|
| 3760 |
-
$object_data[ $object_ID ] = $params->id;
|
| 3761 |
-
}
|
| 3762 |
-
|
| 3763 |
-
$fields_active = array_unique( $fields_active );
|
| 3764 |
-
|
| 3765 |
-
// Loop through each active field, validating and preparing the table data
|
| 3766 |
-
foreach ( $fields_active as $field ) {
|
| 3767 |
-
if ( isset( $object_fields[ $field ] ) ) {
|
| 3768 |
-
$field_data = $object_fields[ $field ];
|
| 3769 |
-
} elseif ( isset( $fields[ $field ] ) ) {
|
| 3770 |
-
$field_data = $fields[ $field ];
|
| 3771 |
-
} else {
|
| 3772 |
-
continue;
|
| 3773 |
-
}
|
| 3774 |
-
|
| 3775 |
-
$value = $field_data['value'];
|
| 3776 |
-
$type = $field_data['type'];
|
| 3777 |
-
$options = pods_var( 'options', $field_data, array() );
|
| 3778 |
-
|
| 3779 |
-
// WPML AJAX compatibility
|
| 3780 |
-
if ( is_admin()
|
| 3781 |
-
&& ( isset( $_POST['action'] ) && 'wpml_save_job_ajax' === $_POST['action'] )
|
| 3782 |
-
|| ( isset( $_GET['page'] ) && false !== strpos( $_GET['page'], '/menu/languages.php' )
|
| 3783 |
-
&& isset( $_POST['icl_ajx_action'] ) && isset( $_POST['_icl_nonce'] )
|
| 3784 |
-
&& wp_verify_nonce( $_POST['_icl_nonce'], $_POST['icl_ajx_action'] . '_nonce' ) )
|
| 3785 |
-
) {
|
| 3786 |
-
$options['unique'] = 0;
|
| 3787 |
-
$fields[ $field ]['options']['unique'] = 0;
|
| 3788 |
-
$options['required'] = 0;
|
| 3789 |
-
$fields[ $field ]['options']['required'] = 0;
|
| 3790 |
-
} else {
|
| 3791 |
-
// Validate value
|
| 3792 |
-
$validate = $this->handle_field_validation( $value, $field, $object_fields, $fields, $pod, $params );
|
| 3793 |
-
|
| 3794 |
-
if ( false === $validate ) {
|
| 3795 |
-
$validate = sprintf( __( 'There was an issue validating the field %s', 'pods' ), $field_data['label'] );
|
| 3796 |
-
} elseif ( true !== $validate ) {
|
| 3797 |
-
$validate = (array) $validate;
|
| 3798 |
-
}
|
| 3799 |
-
|
| 3800 |
-
if ( ! is_bool( $validate ) && ! empty( $validate ) ) {
|
| 3801 |
-
return pods_error( $validate, $error_mode );
|
| 3802 |
-
}
|
| 3803 |
-
}
|
| 3804 |
-
|
| 3805 |
-
$value = PodsForm::pre_save( $field_data['type'], $value, $params->id, $field, array_merge( $field_data, $options ), array_merge( $fields, $object_fields ), $pod, $params );
|
| 3806 |
-
|
| 3807 |
-
$field_data['value'] = $value;
|
| 3808 |
-
|
| 3809 |
-
if ( isset( $object_fields[ $field ] ) ) {
|
| 3810 |
-
// @todo Eventually support 'comment' field type saving here too
|
| 3811 |
-
if ( 'taxonomy' === $object_fields[ $field ]['type'] ) {
|
| 3812 |
-
$post_term_data[ $field ] = $value;
|
| 3813 |
-
} else {
|
| 3814 |
-
$object_data[ $field ] = $value;
|
| 3815 |
-
}
|
| 3816 |
-
} else {
|
| 3817 |
-
$simple = ( 'pick' === $type && in_array( pods_var( 'pick_object', $field_data ), $simple_tableless_objects ) );
|
| 3818 |
-
$simple = (boolean) $this->do_hook( 'tableless_custom', $simple, $field_data, $field, $fields, $pod, $params );
|
| 3819 |
-
|
| 3820 |
-
// Handle Simple Relationships
|
| 3821 |
-
if ( $simple ) {
|
| 3822 |
-
if ( ! is_array( $value ) ) {
|
| 3823 |
-
if ( 0 < strlen( $value ) ) {
|
| 3824 |
-
$value = array( $value );
|
| 3825 |
-
} else {
|
| 3826 |
-
$value = array();
|
| 3827 |
-
}
|
| 3828 |
-
}
|
| 3829 |
-
|
| 3830 |
-
$pick_limit = (int) pods_var_raw( 'pick_limit', $options, 0 );
|
| 3831 |
-
|
| 3832 |
-
if ( 'single' === pods_var_raw( 'pick_format_type', $options ) ) {
|
| 3833 |
-
$pick_limit = 1;
|
| 3834 |
-
}
|
| 3835 |
-
|
| 3836 |
-
if ( 'custom-simple' === pods_var( 'pick_object', $field_data ) ) {
|
| 3837 |
-
$custom = pods_var_raw( 'pick_custom', $options, '' );
|
| 3838 |
-
|
| 3839 |
-
$custom = apply_filters( 'pods_form_ui_field_pick_custom_values', $custom, $field_data['name'], $value, array_merge( $field_data, $options ), $pod, $params->id );
|
| 3840 |
-
|
| 3841 |
-
// Input values are unslashed. Unslash database values as well to ensure correct comparison.
|
| 3842 |
-
$custom = pods_unslash( $custom );
|
| 3843 |
-
|
| 3844 |
-
if ( empty( $value ) || empty( $custom ) ) {
|
| 3845 |
-
$value = '';
|
| 3846 |
-
} elseif ( ! empty( $custom ) ) {
|
| 3847 |
-
if ( ! is_array( $custom ) ) {
|
| 3848 |
-
$custom = explode( "\n", $custom );
|
| 3849 |
-
|
| 3850 |
-
$custom_values = array();
|
| 3851 |
-
|
| 3852 |
-
foreach ( $custom as $c => $cv ) {
|
| 3853 |
-
if ( 0 < strlen( $cv ) ) {
|
| 3854 |
-
$custom_label = explode( '|', $cv );
|
| 3855 |
-
|
| 3856 |
-
if ( ! isset( $custom_label[1] ) ) {
|
| 3857 |
-
$custom_label[1] = $custom_label[0];
|
| 3858 |
-
}
|
| 3859 |
-
|
| 3860 |
-
$custom_label[0] = trim( (string) $custom_label[0] );
|
| 3861 |
-
$custom_label[1] = trim( (string) $custom_label[1] );
|
| 3862 |
-
$custom_values[ $custom_label[0] ] = $custom_label[1];
|
| 3863 |
-
}
|
| 3864 |
-
}
|
| 3865 |
-
} else {
|
| 3866 |
-
$custom_values = $custom;
|
| 3867 |
-
}
|
| 3868 |
-
|
| 3869 |
-
$values = array();
|
| 3870 |
-
|
| 3871 |
-
foreach ( $value as $k => $v ) {
|
| 3872 |
-
$v = pods_unsanitize( $v );
|
| 3873 |
-
|
| 3874 |
-
if ( isset( $custom_values[ $v ] ) ) {
|
| 3875 |
-
$values[ $k ] = $v;
|
| 3876 |
-
}
|
| 3877 |
-
}
|
| 3878 |
-
|
| 3879 |
-
$value = $values;
|
| 3880 |
-
}
|
| 3881 |
-
}
|
| 3882 |
-
|
| 3883 |
-
if ( 0 < $pick_limit && ! empty( $value ) ) {
|
| 3884 |
-
$value = array_slice( $value, 0, $pick_limit );
|
| 3885 |
-
}
|
| 3886 |
-
|
| 3887 |
-
// Don't save an empty array, just make it an empty string
|
| 3888 |
-
if ( empty( $value ) ) {
|
| 3889 |
-
$value = '';
|
| 3890 |
-
} elseif ( is_array( $value ) ) {
|
| 3891 |
-
if ( 1 == $pick_limit || 1 == count( $value ) ) {
|
| 3892 |
-
// If there's just one item, don't save as an array, save the string
|
| 3893 |
-
$value = implode( '', $value );
|
| 3894 |
-
} elseif ( 'table' === pods_var( 'storage', $pod ) ) {
|
| 3895 |
-
// If storage is set to table, json encode, otherwise WP will serialize automatically
|
| 3896 |
-
$value = version_compare( PHP_VERSION, '5.4.0', '>=' ) ? json_encode( $value, JSON_UNESCAPED_UNICODE ) : json_encode( $value );
|
| 3897 |
-
}
|
| 3898 |
-
}
|
| 3899 |
-
}
|
| 3900 |
-
|
| 3901 |
-
// Prepare all table / meta data
|
| 3902 |
-
if ( ! in_array( $type, $tableless_field_types ) || $simple ) {
|
| 3903 |
-
if ( in_array( $type, $repeatable_field_types ) && 1 == pods_var( $type . '_repeatable', $field_data, 0 ) ) {
|
| 3904 |
-
// Don't save an empty array, just make it an empty string
|
| 3905 |
-
if ( empty( $value ) ) {
|
| 3906 |
-
$value = '';
|
| 3907 |
-
} elseif ( is_array( $value ) ) {
|
| 3908 |
-
if ( 1 == count( $value ) ) {
|
| 3909 |
-
// If there's just one item, don't save as an array, save the string
|
| 3910 |
-
$value = implode( '', $value );
|
| 3911 |
-
} elseif ( 'table' === pods_var( 'storage', $pod ) ) {
|
| 3912 |
-
// If storage is set to table, json encode, otherwise WP will serialize automatically
|
| 3913 |
-
$value = version_compare( PHP_VERSION, '5.4.0', '>=' ) ? json_encode( $value, JSON_UNESCAPED_UNICODE ) : json_encode( $value );
|
| 3914 |
-
}
|
| 3915 |
-
}
|
| 3916 |
-
}
|
| 3917 |
-
|
| 3918 |
-
$table_data[ $field ] = str_replace( array( '{prefix}', '@wp_' ), array(
|
| 3919 |
-
'{/prefix/}',
|
| 3920 |
-
'{prefix}'
|
| 3921 |
-
), $value ); // Fix for pods_query
|
| 3922 |
-
$table_formats[] = PodsForm::prepare( $type, $options );
|
| 3923 |
-
|
| 3924 |
-
$object_meta[ $field ] = $value;
|
| 3925 |
-
} else {
|
| 3926 |
-
// Store relational field data to be looped through later
|
| 3927 |
-
// Convert values from a comma-separated string into an array
|
| 3928 |
-
if ( ! is_array( $value ) ) {
|
| 3929 |
-
$value = explode( ',', $value );
|
| 3930 |
-
}
|
| 3931 |
-
|
| 3932 |
-
$rel_fields[ $type ][ $field ] = $value;
|
| 3933 |
-
$rel_field_ids[] = $field_data['id'];
|
| 3934 |
-
}
|
| 3935 |
-
}
|
| 3936 |
-
}
|
| 3937 |
-
|
| 3938 |
-
if ( in_array( $pod['type'], array( 'post_type', 'taxonomy' ) ) ) {
|
| 3939 |
-
$object_name = $pod['name'];
|
| 3940 |
-
|
| 3941 |
-
if ( ! empty( $pod['object'] ) ) {
|
| 3942 |
-
$object_name = $pod['object'];
|
| 3943 |
-
}
|
| 3944 |
-
|
| 3945 |
-
$object_name_field = 'post_type';
|
| 3946 |
-
|
| 3947 |
-
if ( 'taxonomy' === $pod['type'] ) {
|
| 3948 |
-
$object_name_field = 'taxonomy';
|
| 3949 |
-
}
|
| 3950 |
-
|
| 3951 |
-
$object_data[ $object_name_field ] = $object_name;
|
| 3952 |
-
}
|
| 3953 |
-
|
| 3954 |
-
if ( ! in_array( $pod['type'], array( 'pod', 'table', '' ) ) ) {
|
| 3955 |
-
$meta_fields = array();
|
| 3956 |
-
|
| 3957 |
-
if ( 'meta' === $pod['storage'] || 'settings' === $pod['type'] || ( 'taxonomy' === $pod['type'] && 'none' === $pod['storage'] ) ) {
|
| 3958 |
-
$meta_fields = $object_meta;
|
| 3959 |
-
}
|
| 3960 |
-
|
| 3961 |
-
if ( $allow_custom_fields && ! empty( $custom_data ) ) {
|
| 3962 |
-
$meta_fields = array_merge( $custom_data, $meta_fields );
|
| 3963 |
-
}
|
| 3964 |
-
|
| 3965 |
-
$fields_to_send = array_flip( array_keys( $meta_fields ) );
|
| 3966 |
-
|
| 3967 |
-
foreach ( $fields_to_send as $field => $field_data ) {
|
| 3968 |
-
if ( isset( $object_fields[ $field ] ) ) {
|
| 3969 |
-
$field_data = $object_fields[ $field ];
|
| 3970 |
-
} elseif ( isset( $fields[ $field ] ) ) {
|
| 3971 |
-
$field_data = $fields[ $field ];
|
| 3972 |
-
} else {
|
| 3973 |
-
unset( $fields_to_send[ $field ] );
|
| 3974 |
-
}
|
| 3975 |
-
|
| 3976 |
-
$fields_to_send[ $field ] = $field_data;
|
| 3977 |
-
}
|
| 3978 |
-
|
| 3979 |
-
$params->id = $this->save_wp_object( $object_type, $object_data, $meta_fields, false, true, $fields_to_send );
|
| 3980 |
-
|
| 3981 |
-
if ( ! empty( $params->id ) && 'settings' === $pod['type'] ) {
|
| 3982 |
-
$params->id = $pod['id'];
|
| 3983 |
-
}
|
| 3984 |
-
}
|
| 3985 |
-
|
| 3986 |
-
if ( 'table' === $pod['storage'] ) {
|
| 3987 |
-
// Every row should have an id set here, otherwise Pods with nothing
|
| 3988 |
-
// but relationship fields won't get properly ID'd
|
| 3989 |
-
if ( empty( $params->id ) ) {
|
| 3990 |
-
$params->id = 0;
|
| 3991 |
-
}
|
| 3992 |
-
|
| 3993 |
-
$table_data = array( 'id' => $params->id ) + $table_data;
|
| 3994 |
-
array_unshift( $table_formats, '%d' );
|
| 3995 |
-
|
| 3996 |
-
if ( ! empty( $table_data ) ) {
|
| 3997 |
-
$sql = pods_data()->insert_on_duplicate( "@wp_pods_{$params->pod}", $table_data, $table_formats );
|
| 3998 |
-
|
| 3999 |
-
$id = pods_query( $sql, 'Cannot add/save table row' );
|
| 4000 |
-
|
| 4001 |
-
if ( empty( $params->id ) ) {
|
| 4002 |
-
$params->id = $id;
|
| 4003 |
-
}
|
| 4004 |
-
}
|
| 4005 |
-
}
|
| 4006 |
-
|
| 4007 |
-
$params->id = (int) $params->id;
|
| 4008 |
-
|
| 4009 |
-
// Save terms for taxonomies associated to a post type
|
| 4010 |
-
if ( 0 < $params->id && 'post_type' === $pod['type'] && ! empty( $post_term_data ) ) {
|
| 4011 |
-
foreach ( $post_term_data as $post_taxonomy => $post_terms ) {
|
| 4012 |
-
$post_terms = (array) $post_terms;
|
| 4013 |
-
|
| 4014 |
-
foreach ( $post_terms as $k => $v ) {
|
| 4015 |
-
if ( ! preg_match( '/[^0-9]/', $v ) ) {
|
| 4016 |
-
$v = (int) $v;
|
| 4017 |
-
}
|
| 4018 |
-
|
| 4019 |
-
$post_terms[ $k ] = $v;
|
| 4020 |
-
}
|
| 4021 |
-
|
| 4022 |
-
wp_set_object_terms( $params->id, $post_terms, $post_taxonomy );
|
| 4023 |
-
}
|
| 4024 |
-
}
|
| 4025 |
-
|
| 4026 |
-
$no_conflict = pods_no_conflict_check( $pod['type'] );
|
| 4027 |
-
|
| 4028 |
-
if ( ! $no_conflict ) {
|
| 4029 |
-
pods_no_conflict_on( $pod['type'] );
|
| 4030 |
-
}
|
| 4031 |
-
|
| 4032 |
-
// Save relationship / file data
|
| 4033 |
-
if ( ! empty( $rel_fields ) ) {
|
| 4034 |
-
foreach ( $rel_fields as $type => $data ) {
|
| 4035 |
-
// Only handle tableless fields
|
| 4036 |
-
if ( ! in_array( $type, $tableless_field_types ) ) {
|
| 4037 |
-
continue;
|
| 4038 |
-
}
|
| 4039 |
-
|
| 4040 |
-
foreach ( $data as $field => $values ) {
|
| 4041 |
-
$pick_val = pods_var( 'pick_val', $fields[ $field ] );
|
| 4042 |
-
|
| 4043 |
-
if ( 'table' === pods_var( 'pick_object', $fields[ $field ] ) ) {
|
| 4044 |
-
$pick_val = pods_var( 'pick_table', $fields[ $field ]['options'], $pick_val, null, true );
|
| 4045 |
-
}
|
| 4046 |
-
|
| 4047 |
-
if ( '__current__' === $pick_val ) {
|
| 4048 |
-
if ( is_object( $pod ) ) {
|
| 4049 |
-
$pick_val = $pod->pod;
|
| 4050 |
-
} elseif ( is_array( $pod ) ) {
|
| 4051 |
-
$pick_val = $pod['name'];
|
| 4052 |
-
} elseif ( 0 < strlen( $pod ) ) {
|
| 4053 |
-
$pick_val = $pod;
|
| 4054 |
-
}
|
| 4055 |
-
}
|
| 4056 |
-
|
| 4057 |
-
$fields[ $field ]['options']['table_info'] = pods_api()->get_table_info( pods_var( 'pick_object', $fields[ $field ] ), $pick_val, null, null, $fields[ $field ]['options'] );
|
| 4058 |
-
|
| 4059 |
-
if ( isset( $fields[ $field ]['options']['table_info']['pod'] ) && ! empty( $fields[ $field ]['options']['table_info']['pod'] ) && isset( $fields[ $field ]['options']['table_info']['pod']['name'] ) ) {
|
| 4060 |
-
$search_data = pods( $fields[ $field ]['options']['table_info']['pod']['name'] );
|
| 4061 |
-
|
| 4062 |
-
$data_mode = 'pods';
|
| 4063 |
-
} else {
|
| 4064 |
-
$search_data = pods_data();
|
| 4065 |
-
$search_data->table( $fields[ $field ]['options']['table_info'] );
|
| 4066 |
-
|
| 4067 |
-
$data_mode = 'data';
|
| 4068 |
-
}
|
| 4069 |
-
|
| 4070 |
-
$find_rel_params = array(
|
| 4071 |
-
'select' => "`t`.`{$search_data->field_id}`",
|
| 4072 |
-
'where' => "`t`.`{$search_data->field_slug}` = %s OR `t`.`{$search_data->field_index}` = %s",
|
| 4073 |
-
'limit' => 1,
|
| 4074 |
-
'pagination' => false,
|
| 4075 |
-
'search' => false
|
| 4076 |
-
);
|
| 4077 |
-
|
| 4078 |
-
if ( empty( $search_data->field_slug ) && ! empty( $search_data->field_index ) ) {
|
| 4079 |
-
$find_rel_params['where'] = "`t`.`{$search_data->field_index}` = %s";
|
| 4080 |
-
} elseif ( empty( $search_data->field_slug ) && empty( $search_data->field_index ) ) {
|
| 4081 |
-
$find_rel_params = false;
|
| 4082 |
-
}
|
| 4083 |
-
|
| 4084 |
-
$related_limit = (int) pods_var_raw( $type . '_limit', $fields[ $field ]['options'], 0 );
|
| 4085 |
-
|
| 4086 |
-
if ( 'single' === pods_var_raw( $type . '_format_type', $fields[ $field ]['options'] ) ) {
|
| 4087 |
-
$related_limit = 1;
|
| 4088 |
-
}
|
| 4089 |
-
|
| 4090 |
-
// Enforce integers / unique values for IDs
|
| 4091 |
-
$value_ids = array();
|
| 4092 |
-
|
| 4093 |
-
$is_file_field = in_array( $type, PodsForm::file_field_types() );
|
| 4094 |
-
$is_taggable = ( in_array( $type, PodsForm::tableless_field_types() ) && 1 == pods_v( $type . '_taggable', $fields[ $field ]['options'] ) );
|
| 4095 |
-
|
| 4096 |
-
// @todo Handle simple relationships eventually
|
| 4097 |
-
foreach ( $values as $v ) {
|
| 4098 |
-
if ( ! empty( $v ) ) {
|
| 4099 |
-
if ( ! is_array( $v ) ) {
|
| 4100 |
-
if ( ! preg_match( '/[^0-9]/', $v ) ) {
|
| 4101 |
-
$v = (int) $v;
|
| 4102 |
-
} elseif ( $is_file_field ) {
|
| 4103 |
-
// File handling
|
| 4104 |
-
// Get ID from GUID
|
| 4105 |
-
$v = pods_image_id_from_field( $v );
|
| 4106 |
-
|
| 4107 |
-
// If file not found, add it
|
| 4108 |
-
if ( empty( $v ) ) {
|
| 4109 |
-
$v = pods_attachment_import( $v );
|
| 4110 |
-
}
|
| 4111 |
-
} else {
|
| 4112 |
-
// Reference by slug
|
| 4113 |
-
$v_data = false;
|
| 4114 |
-
|
| 4115 |
-
if ( false !== $find_rel_params ) {
|
| 4116 |
-
$rel_params = $find_rel_params;
|
| 4117 |
-
$rel_params['where'] = $wpdb->prepare( $rel_params['where'], array( $v, $v ) );
|
| 4118 |
-
|
| 4119 |
-
$search_data->select( $rel_params );
|
| 4120 |
-
|
| 4121 |
-
$v_data = $search_data->fetch( $v );
|
| 4122 |
-
}
|
| 4123 |
-
|
| 4124 |
-
if ( ! empty( $v_data ) && isset( $v_data[ $search_data->field_id ] ) ) {
|
| 4125 |
-
$v = (int) $v_data[ $search_data->field_id ];
|
| 4126 |
-
} elseif ( $is_taggable && 'pods' === $data_mode ) {
|
| 4127 |
-
// Allow tagging for Pods objects
|
| 4128 |
-
$tag_data = array(
|
| 4129 |
-
$search_data->field_index => $v
|
| 4130 |
-
);
|
| 4131 |
-
|
| 4132 |
-
if ( 'post_type' === $search_data->pod_data['type'] ) {
|
| 4133 |
-
$tag_data['post_status'] = 'publish';
|
| 4134 |
-
}
|
| 4135 |
-
|
| 4136 |
-
/**
|
| 4137 |
-
* Filter for changing tag before adding new item.
|
| 4138 |
-
*
|
| 4139 |
-
* @param array $tag_data Fields for creating new item.
|
| 4140 |
-
* @param int $v Field ID of tag.
|
| 4141 |
-
* @param Pods $search_data Search object for tag.
|
| 4142 |
-
* @param string $field Table info for field.
|
| 4143 |
-
* @param array $pieces Field array.
|
| 4144 |
-
*
|
| 4145 |
-
* @since 2.3.19
|
| 4146 |
-
*/
|
| 4147 |
-
$tag_data = apply_filters( 'pods_api_save_pod_item_taggable_data', $tag_data, $v, $search_data, $field, compact( $pieces ) );
|
| 4148 |
-
|
| 4149 |
-
// Save $v to a new item on related object
|
| 4150 |
-
$v = $search_data->add( $tag_data );
|
| 4151 |
-
|
| 4152 |
-
// @todo Support non-Pods for tagging
|
| 4153 |
-
}
|
| 4154 |
-
}
|
| 4155 |
-
} elseif ( $is_file_field && isset( $v['id'] ) ) {
|
| 4156 |
-
$v = (int) $v['id'];
|
| 4157 |
-
} else {
|
| 4158 |
-
continue;
|
| 4159 |
-
}
|
| 4160 |
-
|
| 4161 |
-
if ( ! empty( $v ) && ! in_array( $v, $value_ids ) ) {
|
| 4162 |
-
$value_ids[] = $v;
|
| 4163 |
-
}
|
| 4164 |
-
}
|
| 4165 |
-
}
|
| 4166 |
-
|
| 4167 |
-
$value_ids = array_unique( array_filter( $value_ids ) );
|
| 4168 |
-
|
| 4169 |
-
// Filter unique values not equal to false in case of a multidimensional array
|
| 4170 |
-
$filtered_values = $this->array_filter_walker( $values );
|
| 4171 |
-
$serialized_values = array_map( 'serialize', $filtered_values );
|
| 4172 |
-
$unique_serialized_values = array_unique( $serialized_values );
|
| 4173 |
-
|
| 4174 |
-
$values = array_map( 'unserialize', $unique_serialized_values );
|
| 4175 |
-
|
| 4176 |
-
// Limit values
|
| 4177 |
-
if ( 0 < $related_limit && ! empty( $value_ids ) ) {
|
| 4178 |
-
$value_ids = array_slice( $value_ids, 0, $related_limit );
|
| 4179 |
-
$values = array_slice( $values, 0, $related_limit );
|
| 4180 |
-
}
|
| 4181 |
-
|
| 4182 |
-
// Get current values
|
| 4183 |
-
if ( 'pick' === $type && isset( PodsField_Pick::$related_data[ $fields[ $field ]['id'] ] ) && isset( PodsField_Pick::$related_data[ $fields[ $field ]['id'] ]['current_ids'] ) ) {
|
| 4184 |
-
$related_ids = PodsField_Pick::$related_data[ $fields[ $field ]['id'] ]['current_ids'];
|
| 4185 |
-
} else {
|
| 4186 |
-
$related_ids = $this->lookup_related_items( $fields[ $field ]['id'], $pod['id'], $params->id, $fields[ $field ], $pod );
|
| 4187 |
-
}
|
| 4188 |
-
|
| 4189 |
-
// Get ids to remove
|
| 4190 |
-
$remove_ids = array_diff( $related_ids, $value_ids );
|
| 4191 |
-
|
| 4192 |
-
// Delete relationships
|
| 4193 |
-
if ( ! empty( $remove_ids ) ) {
|
| 4194 |
-
$this->delete_relationships( $params->id, $remove_ids, $pod, $fields[ $field ] );
|
| 4195 |
-
}
|
| 4196 |
-
|
| 4197 |
-
// Save relationships
|
| 4198 |
-
if ( ! empty( $value_ids ) ) {
|
| 4199 |
-
$this->save_relationships( $params->id, $value_ids, $pod, $fields[ $field ] );
|
| 4200 |
-
}
|
| 4201 |
-
|
| 4202 |
-
$field_save_values = $value_ids;
|
| 4203 |
-
|
| 4204 |
-
if ( 'file' === $type ) {
|
| 4205 |
-
$field_save_values = $values;
|
| 4206 |
-
}
|
| 4207 |
-
|
| 4208 |
-
// Run save function for field type (where needed)
|
| 4209 |
-
PodsForm::save( $type, $field_save_values, $params->id, $field, array_merge( $fields[ $field ], $fields[ $field ]['options'] ), array_merge( $fields, $object_fields ), $pod, $params );
|
| 4210 |
-
}
|
| 4211 |
-
|
| 4212 |
-
// Unset data no longer needed
|
| 4213 |
-
if ( 'pick' === $type ) {
|
| 4214 |
-
foreach ( $data as $field => $values ) {
|
| 4215 |
-
if ( isset( PodsField_Pick::$related_data[ $fields[ $field ]['id'] ] ) ) {
|
| 4216 |
-
unset( PodsField_Pick::$related_data[ PodsField_Pick::$related_data[ $fields[ $field ]['id'] ]['related_field']['id'] ] );
|
| 4217 |
-
unset( PodsField_Pick::$related_data[ $fields[ $field ]['id'] ] );
|
| 4218 |
-
}
|
| 4219 |
-
}
|
| 4220 |
-
}
|
| 4221 |
-
}
|
| 4222 |
-
}
|
| 4223 |
-
|
| 4224 |
-
if ( ! $no_conflict ) {
|
| 4225 |
-
pods_no_conflict_off( $pod['type'] );
|
| 4226 |
-
}
|
| 4227 |
-
|
| 4228 |
-
// Clear cache
|
| 4229 |
-
pods_cache_clear( $params->id, 'pods_items_' . $pod['name'] );
|
| 4230 |
-
|
| 4231 |
-
if ( $params->clear_slug_cache && ! empty( $pod['field_slug'] ) ) {
|
| 4232 |
-
$slug = pods( $pod['name'], $params->id )->field( $pod['field_slug'] );
|
| 4233 |
-
|
| 4234 |
-
if ( 0 < strlen( $slug ) ) {
|
| 4235 |
-
pods_cache_clear( $slug, 'pods_items_' . $pod['name'] );
|
| 4236 |
-
}
|
| 4237 |
-
}
|
| 4238 |
-
|
| 4239 |
-
// Clear WP meta cache
|
| 4240 |
-
if ( in_array( $pod['type'], array( 'post_type', 'media', 'taxonomy', 'user', 'comment' ) ) ) {
|
| 4241 |
-
$meta_type = $pod['type'];
|
| 4242 |
-
|
| 4243 |
-
if ( 'post_type' === $meta_type ) {
|
| 4244 |
-
$meta_type = 'post';
|
| 4245 |
-
}
|
| 4246 |
-
|
| 4247 |
-
wp_cache_delete( $params->id, $meta_type . '_meta' );
|
| 4248 |
-
wp_cache_delete( $params->id, 'pods_' . $meta_type . '_meta' );
|
| 4249 |
-
}
|
| 4250 |
-
|
| 4251 |
-
if ( false === $bypass_helpers ) {
|
| 4252 |
-
if ( $track_changed_fields ) {
|
| 4253 |
-
$changed_fields = self::handle_changed_fields( $params->pod, $params->id, 'get' );
|
| 4254 |
-
}
|
| 4255 |
-
|
| 4256 |
-
$compact_pieces = compact( $pieces );
|
| 4257 |
-
|
| 4258 |
-
// Plugin hooks
|
| 4259 |
-
$this->do_hook( 'post_save_pod_item', $compact_pieces, $is_new_item, $params->id );
|
| 4260 |
-
$this->do_hook( "post_save_pod_item_{$params->pod}", $compact_pieces, $is_new_item, $params->id );
|
| 4261 |
-
|
| 4262 |
-
if ( $is_new_item ) {
|
| 4263 |
-
$this->do_hook( 'post_create_pod_item', $compact_pieces, $params->id );
|
| 4264 |
-
$this->do_hook( "post_create_pod_item_{$params->pod}", $compact_pieces, $params->id );
|
| 4265 |
-
} else {
|
| 4266 |
-
$this->do_hook( 'post_edit_pod_item', $compact_pieces, $params->id );
|
| 4267 |
-
$this->do_hook( "post_edit_pod_item_{$params->pod}", $compact_pieces, $params->id );
|
| 4268 |
-
}
|
| 4269 |
-
|
| 4270 |
-
// Call any post-save helpers (if not bypassed)
|
| 4271 |
-
if ( ! defined( 'PODS_DISABLE_EVAL' ) || ! PODS_DISABLE_EVAL ) {
|
| 4272 |
-
if ( ! empty( $post_save_helpers ) ) {
|
| 4273 |
-
pods_deprecated( sprintf( __( 'Post-save helpers are deprecated, use the action pods_post_save_pod_item_%s instead', 'pods' ), $params->pod ), '2.0' );
|
| 4274 |
-
|
| 4275 |
-
foreach ( $post_save_helpers as $helper ) {
|
| 4276 |
-
$helper = $this->load_helper( array( 'name' => $helper ) );
|
| 4277 |
-
|
| 4278 |
-
if ( false !== $helper && ( ! defined( 'PODS_DISABLE_EVAL' ) || ! PODS_DISABLE_EVAL ) ) {
|
| 4279 |
-
eval( '?>' . $helper['code'] );
|
| 4280 |
-
}
|
| 4281 |
-
}
|
| 4282 |
-
}
|
| 4283 |
-
}
|
| 4284 |
-
}
|
| 4285 |
-
|
| 4286 |
-
// Success! Return the id
|
| 4287 |
-
return $params->id;
|
| 4288 |
-
|
| 4289 |
-
}
|
| 4290 |
-
|
| 4291 |
-
/**
|
| 4292 |
-
* @see PodsAPI::save_pod_item
|
| 4293 |
-
* Add multiple pod items
|
| 4294 |
-
*
|
| 4295 |
-
* $params['pod'] string The Pod name (pod or pod_id is required)
|
| 4296 |
-
* $params['pod_id'] string The Pod ID (pod or pod_id is required)
|
| 4297 |
-
* $params['bypass_helpers'] bool Set to true to bypass running pre-save and post-save helpers
|
| 4298 |
-
*
|
| 4299 |
-
* $data['id'] int The item ID (optional)
|
| 4300 |
-
* $data['data'] array An associative array of field names + values
|
| 4301 |
-
*
|
| 4302 |
-
* @param array|object $params An associative array of parameters, data excluded
|
| 4303 |
-
* @param array $data An associative array of pod ids and field names + values (arrays of field data)
|
| 4304 |
-
*
|
| 4305 |
-
* @return int The item ID
|
| 4306 |
-
* @since 2.0.0
|
| 4307 |
-
*/
|
| 4308 |
-
public function save_pod_items( $params, $data ) {
|
| 4309 |
-
|
| 4310 |
-
$params = (object) $params;
|
| 4311 |
-
|
| 4312 |
-
$ids = array();
|
| 4313 |
-
|
| 4314 |
-
foreach ( $data as $fields ) {
|
| 4315 |
-
$params->data = $fields;
|
| 4316 |
-
|
| 4317 |
-
if ( isset( $fields['id'] ) && isset( $fields['data'] ) ) {
|
| 4318 |
-
$params->id = $fields['id'];
|
| 4319 |
-
$params->data = $fields['data'];
|
| 4320 |
-
}
|
| 4321 |
-
|
| 4322 |
-
$ids[] = $this->save_pod_item( $params );
|
| 4323 |
-
}
|
| 4324 |
-
|
| 4325 |
-
return $ids;
|
| 4326 |
-
}
|
| 4327 |
-
|
| 4328 |
-
/**
|
| 4329 |
-
* Handle tracking changed fields or get them.
|
| 4330 |
-
*
|
| 4331 |
-
* @since 2.7.0
|
| 4332 |
-
*
|
| 4333 |
-
* @param string $pod
|
| 4334 |
-
* @param int $id
|
| 4335 |
-
* @param string $mode
|
| 4336 |
-
*
|
| 4337 |
-
* @return array List of changed fields (if $mode = 'get')
|
| 4338 |
-
*/
|
| 4339 |
-
public static function handle_changed_fields( $pod, $id, $mode = 'set' ) {
|
| 4340 |
-
|
| 4341 |
-
static $changed_pods_cache = array();
|
| 4342 |
-
static $old_fields_cache = array();
|
| 4343 |
-
static $changed_fields_cache = array();
|
| 4344 |
-
|
| 4345 |
-
$cache_key = $pod . '|' . $id;
|
| 4346 |
-
|
| 4347 |
-
$export_params = array(
|
| 4348 |
-
'depth' => 1,
|
| 4349 |
-
);
|
| 4350 |
-
|
| 4351 |
-
if ( in_array( $mode, array( 'set', 'reset' ), true ) ) {
|
| 4352 |
-
if ( isset( $changed_fields_cache[ $cache_key ] ) ) {
|
| 4353 |
-
unset( $changed_fields_cache[ $cache_key ] );
|
| 4354 |
-
}
|
| 4355 |
-
|
| 4356 |
-
if ( empty( $old_fields_cache[ $cache_key ] ) || 'reset' === $mode ) {
|
| 4357 |
-
$old_fields_cache[ $cache_key ] = array();
|
| 4358 |
-
|
| 4359 |
-
if ( ! empty( $id ) ) {
|
| 4360 |
-
if ( ! isset( $changed_pods_cache[ $pod ] ) ) {
|
| 4361 |
-
$changed_pods_cache[ $pod ] = pods( $pod );
|
| 4362 |
-
}
|
| 4363 |
-
|
| 4364 |
-
if ( $changed_pods_cache[ $pod ] && $changed_pods_cache[ $pod ]->valid() ) {
|
| 4365 |
-
$changed_pods_cache[ $pod ]->fetch( $id );
|
| 4366 |
-
|
| 4367 |
-
$old_fields_cache[ $cache_key ] = $changed_pods_cache[ $pod ]->export( $export_params );
|
| 4368 |
-
}
|
| 4369 |
-
}
|
| 4370 |
-
}
|
| 4371 |
-
}
|
| 4372 |
-
|
| 4373 |
-
$changed_fields = array();
|
| 4374 |
-
|
| 4375 |
-
if ( isset( $changed_fields_cache[ $cache_key ] ) ) {
|
| 4376 |
-
$changed_fields = $changed_fields_cache[ $cache_key ];
|
| 4377 |
-
} elseif ( isset( $old_fields_cache[ $cache_key ] ) ) {
|
| 4378 |
-
$old_fields = $old_fields_cache[ $cache_key ];
|
| 4379 |
-
|
| 4380 |
-
if ( 'get' === $mode ) {
|
| 4381 |
-
$changed_fields_cache[ $cache_key ] = array();
|
| 4382 |
-
|
| 4383 |
-
if ( ! empty( $changed_pods_cache[ $pod ] ) ) {
|
| 4384 |
-
if ( $id != $changed_pods_cache[ $pod ]->id() ) {
|
| 4385 |
-
$changed_pods_cache[ $pod ]->fetch( $id );
|
| 4386 |
-
}
|
| 4387 |
-
|
| 4388 |
-
$new_fields = $changed_pods_cache[ $pod ]->export( $export_params );
|
| 4389 |
-
|
| 4390 |
-
foreach ( $new_fields as $field => $value ) {
|
| 4391 |
-
if ( ! isset( $old_fields[ $field ] ) || $value != $old_fields[ $field ] ) {
|
| 4392 |
-
$changed_fields[ $field ] = $value;
|
| 4393 |
-
}
|
| 4394 |
-
}
|
| 4395 |
-
|
| 4396 |
-
$changed_fields_cache[ $cache_key ] = $changed_fields;
|
| 4397 |
-
}
|
| 4398 |
-
}
|
| 4399 |
-
}
|
| 4400 |
-
|
| 4401 |
-
return $changed_fields;
|
| 4402 |
-
|
| 4403 |
-
}
|
| 4404 |
-
|
| 4405 |
-
/**
|
| 4406 |
-
* Get the fields that have changed during a save
|
| 4407 |
-
*
|
| 4408 |
-
* @param array $pieces Pieces array from save_pod_item
|
| 4409 |
-
*
|
| 4410 |
-
* @return array Array of fields and values that have changed
|
| 4411 |
-
*
|
| 4412 |
-
* @deprecated 2.7.0 Use PodsAPI::handle_changed_fields
|
| 4413 |
-
*/
|
| 4414 |
-
public function get_changed_fields( $pieces ) {
|
| 4415 |
-
|
| 4416 |
-
return self::handle_changed_fields( $pieces['params']->pod, $pieces['params']->id, 'get' );
|
| 4417 |
-
|
| 4418 |
-
}
|
| 4419 |
-
|
| 4420 |
-
/**
|
| 4421 |
-
* Save relationships
|
| 4422 |
-
*
|
| 4423 |
-
* @param int $id ID of item
|
| 4424 |
-
* @param int|array $related_id ID or IDs to save
|
| 4425 |
-
* @param array $pod Pod data
|
| 4426 |
-
* @param array $field Field data
|
| 4427 |
-
*/
|
| 4428 |
-
public function save_relationships( $id, $related_ids, $pod, $field ) {
|
| 4429 |
-
|
| 4430 |
-
// Get current values
|
| 4431 |
-
if ( 'pick' === $field['type'] && isset( PodsField_Pick::$related_data[ $field['id'] ] ) && isset( PodsField_Pick::$related_data[ $field['id'] ]['current_ids'] ) ) {
|
| 4432 |
-
$current_ids = PodsField_Pick::$related_data[ $field['id'] ]['current_ids'];
|
| 4433 |
-
} else {
|
| 4434 |
-
$current_ids = $this->lookup_related_items( $field['id'], $pod['id'], $id, $field, $pod );
|
| 4435 |
-
}
|
| 4436 |
-
|
| 4437 |
-
if ( isset( self::$related_item_cache[ $pod['id'] ][ $field['id'] ] ) ) {
|
| 4438 |
-
// Delete relationship from cache
|
| 4439 |
-
unset( self::$related_item_cache[ $pod['id'] ][ $field['id'] ] );
|
| 4440 |
-
}
|
| 4441 |
-
|
| 4442 |
-
if ( ! is_array( $related_ids ) ) {
|
| 4443 |
-
$related_ids = implode( ',', $related_ids );
|
| 4444 |
-
}
|
| 4445 |
-
|
| 4446 |
-
foreach ( $related_ids as $k => $related_id ) {
|
| 4447 |
-
$related_ids[ $k ] = (int) $related_id;
|
| 4448 |
-
}
|
| 4449 |
-
|
| 4450 |
-
$related_ids = array_unique( array_filter( $related_ids ) );
|
| 4451 |
-
|
| 4452 |
-
$related_limit = (int) pods_var_raw( $field['type'] . '_limit', $field['options'], 0 );
|
| 4453 |
-
|
| 4454 |
-
if ( 'single' === pods_var_raw( $field['type'] . '_format_type', $field['options'] ) ) {
|
| 4455 |
-
$related_limit = 1;
|
| 4456 |
-
}
|
| 4457 |
-
|
| 4458 |
-
// Limit values
|
| 4459 |
-
if ( 0 < $related_limit && ! empty( $related_ids ) ) {
|
| 4460 |
-
$related_ids = array_slice( $related_ids, 0, $related_limit );
|
| 4461 |
-
}
|
| 4462 |
-
|
| 4463 |
-
// Post Types, Media, Users, and Comments (meta-based)
|
| 4464 |
-
if ( in_array( $pod['type'], array( 'post_type', 'media', 'taxonomy', 'user', 'comment' ) ) ) {
|
| 4465 |
-
$object_type = $pod['type'];
|
| 4466 |
-
|
| 4467 |
-
if ( in_array( $object_type, array( 'post_type', 'media' ) ) ) {
|
| 4468 |
-
$object_type = 'post';
|
| 4469 |
-
} elseif ( 'taxonomy' === $object_type ) {
|
| 4470 |
-
$object_type = 'term';
|
| 4471 |
-
}
|
| 4472 |
-
|
| 4473 |
-
delete_metadata( $object_type, $id, $field['name'] );
|
| 4474 |
-
|
| 4475 |
-
if ( ! empty( $related_ids ) ) {
|
| 4476 |
-
update_metadata( $object_type, $id, '_pods_' . $field['name'], $related_ids );
|
| 4477 |
-
|
| 4478 |
-
foreach ( $related_ids as $related_id ) {
|
| 4479 |
-
add_metadata( $object_type, $id, $field['name'], $related_id );
|
| 4480 |
-
}
|
| 4481 |
-
} else {
|
| 4482 |
-
delete_metadata( $object_type, $id, '_pods_' . $field['name'] );
|
| 4483 |
-
}
|
| 4484 |
-
} elseif ( 'settings' === $pod['type'] ) {
|
| 4485 |
-
// Custom Settings Pages (options-based)
|
| 4486 |
-
if ( ! empty( $related_ids ) ) {
|
| 4487 |
-
update_option( $pod['name'] . '_' . $field['name'], $related_ids );
|
| 4488 |
-
} else {
|
| 4489 |
-
delete_option( $pod['name'] . '_' . $field['name'] );
|
| 4490 |
-
}
|
| 4491 |
-
}
|
| 4492 |
-
|
| 4493 |
-
$related_pod_id = 0;
|
| 4494 |
-
$related_field_id = 0;
|
| 4495 |
-
|
| 4496 |
-
if ( 'pick' === $field['type'] && isset( PodsField_Pick::$related_data[ $field['id'] ] ) && ! empty( PodsField_Pick::$related_data[ $field['id'] ]['related_field'] ) ) {
|
| 4497 |
-
$related_pod_id = PodsField_Pick::$related_data[ $field['id'] ]['related_pod']['id'];
|
| 4498 |
-
$related_field_id = PodsField_Pick::$related_data[ $field['id'] ]['related_field']['id'];
|
| 4499 |
-
}
|
| 4500 |
-
|
| 4501 |
-
// Relationships table
|
| 4502 |
-
if ( ! pods_tableless() ) {
|
| 4503 |
-
$related_weight = 0;
|
| 4504 |
-
|
| 4505 |
-
foreach ( $related_ids as $related_id ) {
|
| 4506 |
-
if ( in_array( $related_id, $current_ids ) ) {
|
| 4507 |
-
pods_query( "
|
| 4508 |
-
UPDATE `@wp_podsrel`
|
| 4509 |
-
SET
|
| 4510 |
-
`pod_id` = %d,
|
| 4511 |
-
`field_id` = %d,
|
| 4512 |
-
`item_id` = %d,
|
| 4513 |
-
`related_pod_id` = %d,
|
| 4514 |
-
`related_field_id` = %d,
|
| 4515 |
-
`related_item_id` = %d,
|
| 4516 |
-
`weight` = %d
|
| 4517 |
-
WHERE
|
| 4518 |
-
`pod_id` = %d
|
| 4519 |
-
AND `field_id` = %d
|
| 4520 |
-
AND `item_id` = %d
|
| 4521 |
-
AND `related_item_id` = %d
|
| 4522 |
-
", array(
|
| 4523 |
-
$pod['id'],
|
| 4524 |
-
$field['id'],
|
| 4525 |
-
$id,
|
| 4526 |
-
$related_pod_id,
|
| 4527 |
-
$related_field_id,
|
| 4528 |
-
$related_id,
|
| 4529 |
-
$related_weight,
|
| 4530 |
-
|
| 4531 |
-
$pod['id'],
|
| 4532 |
-
$field['id'],
|
| 4533 |
-
$id,
|
| 4534 |
-
$related_id,
|
| 4535 |
-
) );
|
| 4536 |
-
} else {
|
| 4537 |
-
pods_query( "
|
| 4538 |
-
INSERT INTO `@wp_podsrel`
|
| 4539 |
-
(
|
| 4540 |
-
`pod_id`,
|
| 4541 |
-
`field_id`,
|
| 4542 |
-
`item_id`,
|
| 4543 |
-
`related_pod_id`,
|
| 4544 |
-
`related_field_id`,
|
| 4545 |
-
`related_item_id`,
|
| 4546 |
-
`weight`
|
| 4547 |
-
)
|
| 4548 |
-
VALUES ( %d, %d, %d, %d, %d, %d, %d )
|
| 4549 |
-
", array(
|
| 4550 |
-
$pod['id'],
|
| 4551 |
-
$field['id'],
|
| 4552 |
-
$id,
|
| 4553 |
-
$related_pod_id,
|
| 4554 |
-
$related_field_id,
|
| 4555 |
-
$related_id,
|
| 4556 |
-
$related_weight
|
| 4557 |
-
) );
|
| 4558 |
-
}
|
| 4559 |
-
|
| 4560 |
-
$related_weight ++;
|
| 4561 |
-
}
|
| 4562 |
-
}
|
| 4563 |
-
}
|
| 4564 |
-
|
| 4565 |
-
/**
|
| 4566 |
-
* Duplicate a Pod
|
| 4567 |
-
*
|
| 4568 |
-
* $params['id'] int The Pod ID
|
| 4569 |
-
* $params['name'] string The Pod name
|
| 4570 |
-
* $params['new_name'] string The new Pod name
|
| 4571 |
-
*
|
| 4572 |
-
* @param array $params An associative array of parameters
|
| 4573 |
-
* @param bool $strict (optional) Makes sure a pod exists, if it doesn't throws an error
|
| 4574 |
-
*
|
| 4575 |
-
* @return int New Pod ID
|
| 4576 |
-
* @since 2.3.0
|
| 4577 |
-
*/
|
| 4578 |
-
public function duplicate_pod( $params, $strict = false ) {
|
| 4579 |
-
|
| 4580 |
-
if ( ! is_object( $params ) && ! is_array( $params ) ) {
|
| 4581 |
-
if ( is_numeric( $params ) ) {
|
| 4582 |
-
$params = array( 'id' => $params );
|
| 4583 |
-
} else {
|
| 4584 |
-
$params = array( 'name' => $params );
|
| 4585 |
-
}
|
| 4586 |
-
|
| 4587 |
-
$params = (object) pods_sanitize( $params );
|
| 4588 |
-
} else {
|
| 4589 |
-
$params = (object) pods_sanitize( $params );
|
| 4590 |
-
}
|
| 4591 |
-
|
| 4592 |
-
$params->table_info = false;
|
| 4593 |
-
|
| 4594 |
-
$pod = $this->load_pod( $params, $strict );
|
| 4595 |
-
|
| 4596 |
-
if ( empty( $pod ) ) {
|
| 4597 |
-
if ( false !== $strict ) {
|
| 4598 |
-
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
| 4599 |
-
}
|
| 4600 |
-
|
| 4601 |
-
return false;
|
| 4602 |
-
} elseif ( in_array( $pod['type'], array( 'media', 'user', 'comment' ) ) ) {
|
| 4603 |
-
if ( false !== $strict ) {
|
| 4604 |
-
return pods_error( __( 'Pod not allowed to be duplicated', 'pods' ), $this );
|
| 4605 |
-
}
|
| 4606 |
-
|
| 4607 |
-
return false;
|
| 4608 |
-
} elseif ( in_array( $pod['type'], array( 'post_type', 'taxonomy' ) ) && 0 < strlen( $pod['object'] ) ) {
|
| 4609 |
-
$pod['object'] = '';
|
| 4610 |
-
}
|
| 4611 |
-
|
| 4612 |
-
unset( $pod['id'] );
|
| 4613 |
-
|
| 4614 |
-
if ( isset( $params->new_name ) ) {
|
| 4615 |
-
$pod['name'] = $params->new_name;
|
| 4616 |
-
}
|
| 4617 |
-
|
| 4618 |
-
$try = 1;
|
| 4619 |
-
|
| 4620 |
-
$check_name = $pod['name'];
|
| 4621 |
-
$new_label = $pod['label'];
|
| 4622 |
-
|
| 4623 |
-
while ( $this->load_pod( array( 'name' => $check_name, 'table_info' => false ), false ) ) {
|
| 4624 |
-
$try ++;
|
| 4625 |
-
|
| 4626 |
-
$check_name = $pod['name'] . $try;
|
| 4627 |
-
$new_label = $pod['label'] . $try;
|
| 4628 |
-
}
|
| 4629 |
-
|
| 4630 |
-
$pod['name'] = $check_name;
|
| 4631 |
-
$pod['label'] = $new_label;
|
| 4632 |
-
|
| 4633 |
-
foreach ( $pod['fields'] as $field => $field_data ) {
|
| 4634 |
-
unset( $pod['fields'][ $field ]['id'] );
|
| 4635 |
-
}
|
| 4636 |
-
|
| 4637 |
-
return $this->save_pod( $pod );
|
| 4638 |
-
}
|
| 4639 |
-
|
| 4640 |
-
/**
|
| 4641 |
-
* Duplicate a Field
|
| 4642 |
-
*
|
| 4643 |
-
* $params['pod_id'] int The Pod ID
|
| 4644 |
-
* $params['pod'] string The Pod name
|
| 4645 |
-
* $params['id'] int The Field ID
|
| 4646 |
-
* $params['name'] string The Field name
|
| 4647 |
-
* $params['new_name'] string The new Field name
|
| 4648 |
-
*
|
| 4649 |
-
* @param array $params An associative array of parameters
|
| 4650 |
-
* @param bool $strict (optional) Makes sure a field exists, if it doesn't throws an error
|
| 4651 |
-
*
|
| 4652 |
-
* @return int New Field ID
|
| 4653 |
-
* @since 2.3.10
|
| 4654 |
-
*/
|
| 4655 |
-
public function duplicate_field( $params, $strict = false ) {
|
| 4656 |
-
|
| 4657 |
-
if ( ! is_object( $params ) && ! is_array( $params ) ) {
|
| 4658 |
-
if ( is_numeric( $params ) ) {
|
| 4659 |
-
$params = array( 'id' => $params );
|
| 4660 |
-
} else {
|
| 4661 |
-
$params = array( 'name' => $params );
|
| 4662 |
-
}
|
| 4663 |
-
}
|
| 4664 |
-
|
| 4665 |
-
$params = (object) pods_sanitize( $params );
|
| 4666 |
-
|
| 4667 |
-
$params->table_info = false;
|
| 4668 |
-
|
| 4669 |
-
$field = $this->load_field( $params, $strict );
|
| 4670 |
-
|
| 4671 |
-
if ( empty( $field ) ) {
|
| 4672 |
-
if ( false !== $strict ) {
|
| 4673 |
-
return pods_error( __( 'Field not found', 'pods' ), $this );
|
| 4674 |
-
}
|
| 4675 |
-
|
| 4676 |
-
return false;
|
| 4677 |
-
}
|
| 4678 |
-
|
| 4679 |
-
unset( $field['id'] );
|
| 4680 |
-
|
| 4681 |
-
if ( isset( $params->new_name ) ) {
|
| 4682 |
-
$field['name'] = $params->new_name;
|
| 4683 |
-
}
|
| 4684 |
-
|
| 4685 |
-
$try = 1;
|
| 4686 |
-
|
| 4687 |
-
$check_name = $field['name'];
|
| 4688 |
-
$new_label = $field['label'];
|
| 4689 |
-
|
| 4690 |
-
while ( $this->load_field( array(
|
| 4691 |
-
'pod_id' => $field['pod_id'],
|
| 4692 |
-
'name' => $check_name,
|
| 4693 |
-
'table_info' => false
|
| 4694 |
-
), false ) ) {
|
| 4695 |
-
$try ++;
|
| 4696 |
-
|
| 4697 |
-
$check_name = $field['name'] . $try;
|
| 4698 |
-
$new_label = $field['label'] . $try;
|
| 4699 |
-
}
|
| 4700 |
-
|
| 4701 |
-
$field['name'] = $check_name;
|
| 4702 |
-
$field['label'] = $new_label;
|
| 4703 |
-
|
| 4704 |
-
return $this->save_field( $field );
|
| 4705 |
-
|
| 4706 |
-
}
|
| 4707 |
-
|
| 4708 |
-
/**
|
| 4709 |
-
* @see PodsAPI::save_pod_item
|
| 4710 |
-
*
|
| 4711 |
-
* Duplicate a pod item
|
| 4712 |
-
*
|
| 4713 |
-
* $params['pod'] string The Pod name
|
| 4714 |
-
* $params['id'] int The item's ID from the wp_pods_* table
|
| 4715 |
-
*
|
| 4716 |
-
* @param array $params An associative array of parameters
|
| 4717 |
-
*
|
| 4718 |
-
* @return int The table row ID
|
| 4719 |
-
*
|
| 4720 |
-
* @since 1.12
|
| 4721 |
-
*/
|
| 4722 |
-
public function duplicate_pod_item( $params ) {
|
| 4723 |
-
|
| 4724 |
-
$params = (object) pods_sanitize( $params );
|
| 4725 |
-
|
| 4726 |
-
$load_pod_params = array(
|
| 4727 |
-
'name' => $params->pod,
|
| 4728 |
-
'table_info' => false,
|
| 4729 |
-
);
|
| 4730 |
-
|
| 4731 |
-
$pod = $this->load_pod( $load_pod_params );
|
| 4732 |
-
|
| 4733 |
-
if ( false === $pod ) {
|
| 4734 |
-
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
| 4735 |
-
}
|
| 4736 |
-
|
| 4737 |
-
$pod = pods( $params->pod, $params->id );
|
| 4738 |
-
|
| 4739 |
-
$params->pod = $pod->pod;
|
| 4740 |
-
$params->pod_id = $pod->pod_id;
|
| 4741 |
-
|
| 4742 |
-
$fields = (array) pods_var_raw( 'fields', $pod->pod_data, array(), null, true );
|
| 4743 |
-
$object_fields = (array) pods_var_raw( 'object_fields', $pod->pod_data, array(), null, true );
|
| 4744 |
-
|
| 4745 |
-
if ( ! empty( $object_fields ) ) {
|
| 4746 |
-
$fields = array_merge( $object_fields, $fields );
|
| 4747 |
-
}
|
| 4748 |
-
|
| 4749 |
-
$save_params = array(
|
| 4750 |
-
'pod' => $params->pod,
|
| 4751 |
-
'data' => array(),
|
| 4752 |
-
'is_new_item' => true,
|
| 4753 |
-
);
|
| 4754 |
-
|
| 4755 |
-
$ignore_fields = array(
|
| 4756 |
-
$pod->pod_data['field_id'],
|
| 4757 |
-
$pod->pod_data['field_slug'],
|
| 4758 |
-
);
|
| 4759 |
-
|
| 4760 |
-
if ( in_array( $pod->pod_data['type'], array( 'post_type', 'media' ) ) ) {
|
| 4761 |
-
$ignore_fields = array(
|
| 4762 |
-
'ID',
|
| 4763 |
-
'post_name',
|
| 4764 |
-
'post_date',
|
| 4765 |
-
'post_date_gmt',
|
| 4766 |
-
'post_modified',
|
| 4767 |
-
'post_modified_gmt',
|
| 4768 |
-
'guid',
|
| 4769 |
-
);
|
| 4770 |
-
} elseif ( 'term' === $pod->pod_data['type'] ) {
|
| 4771 |
-
$ignore_fields = array(
|
| 4772 |
-
'term_id',
|
| 4773 |
-
'term_taxonomy_id',
|
| 4774 |
-
'slug',
|
| 4775 |
-
);
|
| 4776 |
-
} elseif ( 'user' === $pod->pod_data['type'] ) {
|
| 4777 |
-
$ignore_fields = array(
|
| 4778 |
-
'ID',
|
| 4779 |
-
'user_nicename',
|
| 4780 |
-
);
|
| 4781 |
-
} elseif ( 'comment' === $pod->pod_data['type'] ) {
|
| 4782 |
-
$ignore_fields = array(
|
| 4783 |
-
'comment_ID',
|
| 4784 |
-
);
|
| 4785 |
-
} elseif ( 'settings' === $pod->pod_data['type'] ) {
|
| 4786 |
-
return pods_error( __( 'Settings do not support duplication.', 'pods' ), $this );
|
| 4787 |
-
}
|
| 4788 |
-
|
| 4789 |
-
/**
|
| 4790 |
-
* Filter the fields to ignore during duplication
|
| 4791 |
-
*
|
| 4792 |
-
* @since 2.6.6
|
| 4793 |
-
*
|
| 4794 |
-
* @param array $ignore_fields Fields to ignore and not save during duplication
|
| 4795 |
-
* @param Pods $pod Pod object
|
| 4796 |
-
* @param array $fields Fields on the pod to duplicate
|
| 4797 |
-
* @param object $params Params passed into duplicate_pod_item()
|
| 4798 |
-
*/
|
| 4799 |
-
$ignore_fields = apply_filters( 'pods_api_duplicate_pod_item_ignore_fields', $ignore_fields, $pod, $fields, $params );
|
| 4800 |
-
|
| 4801 |
-
foreach ( $fields as $field ) {
|
| 4802 |
-
if ( in_array( $field['name'], $ignore_fields ) ) {
|
| 4803 |
-
continue;
|
| 4804 |
-
}
|
| 4805 |
-
|
| 4806 |
-
$field = array(
|
| 4807 |
-
'name' => $field['name'],
|
| 4808 |
-
'output' => 'ids'
|
| 4809 |
-
);
|
| 4810 |
-
|
| 4811 |
-
$value = $pod->field( $field );
|
| 4812 |
-
|
| 4813 |
-
// @todo Add post type compatibility to set unique post_title
|
| 4814 |
-
// @todo Add term compatibility to set unique name
|
| 4815 |
-
// @todo Add user compatibility to set unique user_login/user_email
|
| 4816 |
-
|
| 4817 |
-
if ( ! empty( $value ) || ( ! is_array( $value ) && 0 < strlen( $value ) ) ) {
|
| 4818 |
-
$save_params['data'][ $field['name'] ] = $value;
|
| 4819 |
-
}
|
| 4820 |
-
}
|
| 4821 |
-
|
| 4822 |
-
$save_params = $this->do_hook( 'duplicate_pod_item', $save_params, $pod->pod, $pod->id(), $params );
|
| 4823 |
-
|
| 4824 |
-
$id = $this->save_pod_item( $save_params );
|
| 4825 |
-
|
| 4826 |
-
return $id;
|
| 4827 |
-
|
| 4828 |
-
}
|
| 4829 |
-
|
| 4830 |
-
/**
|
| 4831 |
-
* @see pods()
|
| 4832 |
-
*
|
| 4833 |
-
* Export a pod item
|
| 4834 |
-
*
|
| 4835 |
-
* $params['pod'] string The Pod name
|
| 4836 |
-
* $params['id'] int The item's ID from the wp_pods_* table
|
| 4837 |
-
* $params['fields'] array The fields to export
|
| 4838 |
-
* $params['depth'] int How many levels deep to export data
|
| 4839 |
-
*
|
| 4840 |
-
* @param array $params An associative array of parameters
|
| 4841 |
-
* @param object $pod (optional) Pods object
|
| 4842 |
-
*
|
| 4843 |
-
* @return int The table row ID
|
| 4844 |
-
* @since 1.12
|
| 4845 |
-
*/
|
| 4846 |
-
public function export_pod_item( $params, $pod = null ) {
|
| 4847 |
-
|
| 4848 |
-
if ( ! is_object( $pod ) || 'Pods' !== get_class( $pod ) ) {
|
| 4849 |
-
if ( empty( $params ) ) {
|
| 4850 |
-
return false;
|
| 4851 |
-
}
|
| 4852 |
-
|
| 4853 |
-
if ( is_object( $params ) ) {
|
| 4854 |
-
$params = get_object_vars( (object) $params );
|
| 4855 |
-
}
|
| 4856 |
-
|
| 4857 |
-
$params = pods_sanitize( $params );
|
| 4858 |
-
|
| 4859 |
-
$pod = pods( $params['pod'], $params['id'], false );
|
| 4860 |
-
|
| 4861 |
-
if ( empty( $pod ) ) {
|
| 4862 |
-
return false;
|
| 4863 |
-
}
|
| 4864 |
-
}
|
| 4865 |
-
|
| 4866 |
-
$params['fields'] = (array) pods_v( 'fields', $params, array(), true );
|
| 4867 |
-
$params['depth'] = (int) pods_v( 'depth', $params, 2, true );
|
| 4868 |
-
$params['object_fields'] = (array) pods_v( 'object_fields', $pod->pod_data, array(), true );
|
| 4869 |
-
$params['flatten'] = (boolean) pods_v( 'flatten', $params, false, true );
|
| 4870 |
-
$params['context'] = pods_v( 'context', $params, null, true );
|
| 4871 |
-
|
| 4872 |
-
if ( empty( $params['fields'] ) ) {
|
| 4873 |
-
$params['fields'] = array_merge( $pod->fields, $params['object_fields'] );
|
| 4874 |
-
}
|
| 4875 |
-
|
| 4876 |
-
$data = $this->export_pod_item_level( $pod, $params );
|
| 4877 |
-
|
| 4878 |
-
$data = $this->do_hook( 'export_pod_item', $data, $pod->pod, $pod->id(), $pod, $params['fields'], $params['depth'], $params['flatten'], $params );
|
| 4879 |
-
|
| 4880 |
-
return $data;
|
| 4881 |
-
}
|
| 4882 |
-
|
| 4883 |
-
/**
|
| 4884 |
-
* Export a pod item by depth level
|
| 4885 |
-
*
|
| 4886 |
-
* @param Pods $pod Pods object
|
| 4887 |
-
* @param array $params Export params
|
| 4888 |
-
*
|
| 4889 |
-
* @return array Data array
|
| 4890 |
-
*
|
| 4891 |
-
* @since 2.3.0
|
| 4892 |
-
*/
|
| 4893 |
-
private function export_pod_item_level( $pod, $params ) {
|
| 4894 |
-
|
| 4895 |
-
$fields = $params['fields'];
|
| 4896 |
-
$depth = $params['depth'];
|
| 4897 |
-
$flatten = $params['flatten'];
|
| 4898 |
-
$current_depth = pods_v( 'current_depth', $params, 1, true );
|
| 4899 |
-
$context = $params['context'];
|
| 4900 |
-
|
| 4901 |
-
$tableless_field_types = PodsForm::tableless_field_types();
|
| 4902 |
-
$simple_tableless_objects = PodsForm::simple_tableless_objects();
|
| 4903 |
-
|
| 4904 |
-
$object_fields = (array) pods_v( 'object_fields', $pod->pod_data, array(), true );
|
| 4905 |
-
|
| 4906 |
-
$export_fields = array();
|
| 4907 |
-
|
| 4908 |
-
$pod_type = $pod->pod_data['type'];
|
| 4909 |
-
|
| 4910 |
-
if ( 'post_type' === $pod_type ) {
|
| 4911 |
-
$pod_type = 'post';
|
| 4912 |
-
} elseif ( 'taxonomy' === $pod_type ) {
|
| 4913 |
-
$pod_type = 'term';
|
| 4914 |
-
}
|
| 4915 |
-
|
| 4916 |
-
$registered_meta_keys = false;
|
| 4917 |
-
|
| 4918 |
-
if ( function_exists( 'get_registered_meta_keys' ) ) {
|
| 4919 |
-
$registered_meta_keys = get_registered_meta_keys( $pod_type );
|
| 4920 |
-
}
|
| 4921 |
-
|
| 4922 |
-
$show_in_rest = false;
|
| 4923 |
-
|
| 4924 |
-
// If in rest, check if this pod can be exposed
|
| 4925 |
-
if ( 'rest' === $context ) {
|
| 4926 |
-
$read_all = (int) pods_v( 'read_all', $pod->pod_data['options'], 0 );
|
| 4927 |
-
|
| 4928 |
-
if ( 1 === $read_all ) {
|
| 4929 |
-
$show_in_rest = true;
|
| 4930 |
-
}
|
| 4931 |
-
}
|
| 4932 |
-
|
| 4933 |
-
foreach ( $fields as $k => $field ) {
|
| 4934 |
-
if ( ! is_array( $field ) ) {
|
| 4935 |
-
$field = array(
|
| 4936 |
-
'id' => 0,
|
| 4937 |
-
'name' => $field
|
| 4938 |
-
);
|
| 4939 |
-
}
|
| 4940 |
-
|
| 4941 |
-
if ( isset( $pod->fields[ $field['name'] ] ) ) {
|
| 4942 |
-
// If in rest, check if this field can be exposed
|
| 4943 |
-
if ( 'rest' === $context && false === $show_in_rest ) {
|
| 4944 |
-
$show_in_rest = PodsRESTFields::field_allowed_to_extend( $field['name'], $pod, 'read' );
|
| 4945 |
-
|
| 4946 |
-
if ( false === $show_in_rest ) {
|
| 4947 |
-
// Fallback to checking $registered_meta_keys
|
| 4948 |
-
if ( false !== $registered_meta_keys ) {
|
| 4949 |
-
if ( ! isset( $registered_meta_keys[ $field['name'] ] ) ) {
|
| 4950 |
-
continue;
|
| 4951 |
-
} elseif ( empty( $registered_meta_keys[ $field['name'] ]['show_in_rest'] ) ) {
|
| 4952 |
-
continue;
|
| 4953 |
-
}
|
| 4954 |
-
}
|
| 4955 |
-
}
|
| 4956 |
-
}
|
| 4957 |
-
|
| 4958 |
-
$field = $pod->fields[ $field['name'] ];
|
| 4959 |
-
$field['lookup_name'] = $field['name'];
|
| 4960 |
-
|
| 4961 |
-
if ( in_array( $field['type'], $tableless_field_types, true ) && ! in_array( pods_v( 'pick_object', $field ), $simple_tableless_objects, true ) ) {
|
| 4962 |
-
if ( 'pick' === $field['type'] ) {
|
| 4963 |
-
if ( empty( $field['table_info'] ) ) {
|
| 4964 |
-
$field['table_info'] = $this->get_table_info( pods_v( 'pick_object', $field ), pods_v( 'pick_val', $field ), null, null, $field );
|
| 4965 |
-
}
|
| 4966 |
-
|
| 4967 |
-
if ( ! empty( $field['table_info'] ) && 'table' !== $field['table_info']['object_type'] ) {
|
| 4968 |
-
$field['lookup_name'] .= '.' . $field['table_info']['field_id'];
|
| 4969 |
-
}
|
| 4970 |
-
} elseif ( in_array( $field['type'], PodsForm::file_field_types() ) ) {
|
| 4971 |
-
$field['lookup_name'] .= '.guid';
|
| 4972 |
-
}
|
| 4973 |
-
}
|
| 4974 |
-
|
| 4975 |
-
$export_fields[ $field['name'] ] = $field;
|
| 4976 |
-
} elseif ( isset( $object_fields[ $field['name'] ] ) ) {
|
| 4977 |
-
$field = $object_fields[ $field['name'] ];
|
| 4978 |
-
$field['lookup_name'] = $field['name'];
|
| 4979 |
-
|
| 4980 |
-
$export_fields[ $field['name'] ] = $field;
|
| 4981 |
-
} elseif ( $field['name'] == $pod->pod_data['field_id'] ) {
|
| 4982 |
-
$field['type'] = 'number';
|
| 4983 |
-
$field['lookup_name'] = $field['name'];
|
| 4984 |
-
|
| 4985 |
-
$export_fields[ $field['name'] ] = $field;
|
| 4986 |
-
}
|
| 4987 |
-
}
|
| 4988 |
-
|
| 4989 |
-
$data = array();
|
| 4990 |
-
|
| 4991 |
-
foreach ( $export_fields as $field ) {
|
| 4992 |
-
// Return IDs (or guid for files) if only one level deep
|
| 4993 |
-
if ( 1 == $depth ) {
|
| 4994 |
-
$data[ $field['name'] ] = $pod->field( array( 'name' => $field['lookup_name'], 'output' => 'arrays' ) );
|
| 4995 |
-
} elseif ( ( - 1 == $depth || $current_depth < $depth ) && 'pick' === $field['type'] && ! in_array( pods_var( 'pick_object', $field ), $simple_tableless_objects ) ) {
|
| 4996 |
-
// Recurse depth levels for pick fields if $depth allows
|
| 4997 |
-
$related_data = array();
|
| 4998 |
-
|
| 4999 |
-
$related_ids = $pod->field( array( 'name' => $field['name'], 'output' => 'ids' ) );
|
| 5000 |
-
|
| 5001 |
-
if ( ! empty( $related_ids ) ) {
|
| 5002 |
-
$related_ids = (array) $related_ids;
|
| 5003 |
-
|
| 5004 |
-
$pick_object = pods_var_raw( 'pick_object', $field );
|
| 5005 |
-
|
| 5006 |
-
$related_pod = pods( pods_var_raw( 'pick_val', $field ), null, false );
|
| 5007 |
-
|
| 5008 |
-
// If this isn't a Pod, return data exactly as Pods does normally
|
| 5009 |
-
if ( empty( $related_pod ) || ( 'pod' !== $pick_object && $pick_object !== $related_pod->pod_data['type'] ) || $related_pod->pod == $pod->pod ) {
|
| 5010 |
-
$related_data = $pod->field( array( 'name' => $field['name'], 'output' => 'arrays' ) );
|
| 5011 |
-
} else {
|
| 5012 |
-
$related_object_fields = (array) pods_var_raw( 'object_fields', $related_pod->pod_data, array(), null, true );
|
| 5013 |
-
|
| 5014 |
-
$related_fields = array_merge( $related_pod->fields, $related_object_fields );
|
| 5015 |
-
|
| 5016 |
-
foreach ( $related_ids as $related_id ) {
|
| 5017 |
-
if ( $related_pod->fetch( $related_id ) ) {
|
| 5018 |
-
$related_params = array(
|
| 5019 |
-
'fields' => $related_fields,
|
| 5020 |
-
'depth' => $depth,
|
| 5021 |
-
'flatten' => $flatten,
|
| 5022 |
-
'current_depth' => $current_depth + 1,
|
| 5023 |
-
'context' => $context,
|
| 5024 |
-
);
|
| 5025 |
-
|
| 5026 |
-
$related_item = $this->export_pod_item_level( $related_pod, $related_params );
|
| 5027 |
-
|
| 5028 |
-
$related_item_data = $this->do_hook( 'export_pod_item_level', $related_item, $related_pod->pod, $related_pod->id(), $related_pod, $related_fields, $depth, $flatten, ( $current_depth + 1 ), $params );
|
| 5029 |
-
|
| 5030 |
-
if ( function_exists( 'wp_is_json_request' ) && wp_is_json_request() ) {
|
| 5031 |
-
// Don't pass IDs as keys for REST API context to ensure arrays of data are returned.
|
| 5032 |
-
$related_data[] = $related_item_data;
|
| 5033 |
-
} else {
|
| 5034 |
-
$related_data[ $related_id ] = $related_item_data;
|
| 5035 |
-
}
|
| 5036 |
-
}
|
| 5037 |
-
}
|
| 5038 |
-
|
| 5039 |
-
if ( $flatten && ! empty( $related_data ) ) {
|
| 5040 |
-
$related_data = pods_serial_comma( array_values( $related_data ), array(
|
| 5041 |
-
'and' => '',
|
| 5042 |
-
'field_index' => $related_pod->pod_data['field_index']
|
| 5043 |
-
) );
|
| 5044 |
-
}
|
| 5045 |
-
}
|
| 5046 |
-
}
|
| 5047 |
-
|
| 5048 |
-
$data[ $field['name'] ] = $related_data;
|
| 5049 |
-
} else {
|
| 5050 |
-
// Return data exactly as Pods does normally
|
| 5051 |
-
$data[ $field['name'] ] = $pod->field( array( 'name' => $field['name'], 'output' => 'arrays' ) );
|
| 5052 |
-
}
|
| 5053 |
-
|
| 5054 |
-
if ( $flatten && is_array( $data[ $field['name'] ] ) ) {
|
| 5055 |
-
$data[ $field['name'] ] = pods_serial_comma( $data[ $field['name'] ], array(
|
| 5056 |
-
'field' => $field['name'],
|
| 5057 |
-
'fields' => $export_fields,
|
| 5058 |
-
'and' => ''
|
| 5059 |
-
) );
|
| 5060 |
-
}
|
| 5061 |
-
}
|
| 5062 |
-
|
| 5063 |
-
$data['id'] = (int) $pod->id();
|
| 5064 |
-
|
| 5065 |
-
return $data;
|
| 5066 |
-
}
|
| 5067 |
-
|
| 5068 |
-
/**
|
| 5069 |
-
* Reorder a Pod
|
| 5070 |
-
*
|
| 5071 |
-
* $params['pod'] string The Pod name
|
| 5072 |
-
* $params['field'] string The field name of the field to reorder
|
| 5073 |
-
* $params['order'] array The key => value array of items to reorder (key should be an integer)
|
| 5074 |
-
*
|
| 5075 |
-
* @param array $params An associative array of parameters
|
| 5076 |
-
*
|
| 5077 |
-
* @return bool
|
| 5078 |
-
*
|
| 5079 |
-
* @since 1.9.0
|
| 5080 |
-
*/
|
| 5081 |
-
public function reorder_pod_item( $params ) {
|
| 5082 |
-
|
| 5083 |
-
$params = (object) pods_sanitize( $params );
|
| 5084 |
-
|
| 5085 |
-
// @deprecated 2.0.0
|
| 5086 |
-
if ( isset( $params->datatype ) ) {
|
| 5087 |
-
pods_deprecated( __( '$params->pod instead of $params->datatype', 'pods' ), '2.0' );
|
| 5088 |
-
|
| 5089 |
-
$params->pod = $params->datatype;
|
| 5090 |
-
|
| 5091 |
-
unset( $params->datatype );
|
| 5092 |
-
}
|
| 5093 |
-
|
| 5094 |
-
if ( null === pods_var_raw( 'pod', $params, null, null, true ) ) {
|
| 5095 |
-
return pods_error( __( '$params->pod is required', 'pods' ), $this );
|
| 5096 |
-
}
|
| 5097 |
-
|
| 5098 |
-
if ( ! is_array( $params->order ) ) {
|
| 5099 |
-
$params->order = explode( ',', $params->order );
|
| 5100 |
-
}
|
| 5101 |
-
|
| 5102 |
-
$pod = $this->load_pod( array( 'name' => $params->pod, 'table_info' => true ) );
|
| 5103 |
-
|
| 5104 |
-
$params->name = $pod['name'];
|
| 5105 |
-
|
| 5106 |
-
if ( false === $pod ) {
|
| 5107 |
-
return pods_error( __( 'Pod is required', 'pods' ), $this );
|
| 5108 |
-
}
|
| 5109 |
-
|
| 5110 |
-
foreach ( $params->order as $order => $id ) {
|
| 5111 |
-
if ( isset( $pod['fields'][ $params->field ] ) || isset( $pod['object_fields'][ $params->field ] ) ) {
|
| 5112 |
-
if ( 'table' === $pod['storage'] && ( ! pods_tableless() ) ) {
|
| 5113 |
-
if ( isset( $pod['fields'][ $params->field ] ) ) {
|
| 5114 |
-
pods_query( "UPDATE `@wp_pods_{$params->name}` SET `{$params->field}` = " . pods_absint( $order ) . " WHERE `id` = " . pods_absint( $id ) . " LIMIT 1" );
|
| 5115 |
-
} else {
|
| 5116 |
-
pods_query( "UPDATE `{$pod['table']}` SET `{$params->field}` = " . pods_absint( $order ) . " WHERE `{$pod['field_id']}` = " . pods_absint( $id ) . " LIMIT 1" );
|
| 5117 |
-
}
|
| 5118 |
-
} else {
|
| 5119 |
-
$this->save_pod_item( array(
|
| 5120 |
-
'pod' => $params->pod,
|
| 5121 |
-
'pod_id' => $params->pod_id,
|
| 5122 |
-
'id' => $id,
|
| 5123 |
-
'data' => array( $params->field => pods_absint( $order ) )
|
| 5124 |
-
) );
|
| 5125 |
-
}
|
| 5126 |
-
}
|
| 5127 |
-
}
|
| 5128 |
-
|
| 5129 |
-
return true;
|
| 5130 |
-
}
|
| 5131 |
-
|
| 5132 |
-
/**
|
| 5133 |
-
*
|
| 5134 |
-
* Delete all content for a Pod
|
| 5135 |
-
*
|
| 5136 |
-
* $params['id'] int The Pod ID
|
| 5137 |
-
* $params['name'] string The Pod name
|
| 5138 |
-
*
|
| 5139 |
-
* @param array $params An associative array of parameters
|
| 5140 |
-
* @param array $pod Pod data
|
| 5141 |
-
*
|
| 5142 |
-
* @return bool
|
| 5143 |
-
*
|
| 5144 |
-
* @uses pods_query
|
| 5145 |
-
* @uses pods_cache_clear
|
| 5146 |
-
*
|
| 5147 |
-
* @since 1.9.0
|
| 5148 |
-
*/
|
| 5149 |
-
public function reset_pod( $params, $pod = false ) {
|
| 5150 |
-
|
| 5151 |
-
$params = (object) pods_sanitize( $params );
|
| 5152 |
-
|
| 5153 |
-
$params->table_info = true;
|
| 5154 |
-
|
| 5155 |
-
if ( empty( $pod ) ) {
|
| 5156 |
-
$pod = $this->load_pod( $params );
|
| 5157 |
-
}
|
| 5158 |
-
|
| 5159 |
-
if ( false === $pod ) {
|
| 5160 |
-
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
| 5161 |
-
}
|
| 5162 |
-
|
| 5163 |
-
$params->id = $pod['id'];
|
| 5164 |
-
$params->name = $pod['name'];
|
| 5165 |
-
|
| 5166 |
-
if ( ! pods_tableless() ) {
|
| 5167 |
-
if ( 'table' === $pod['storage'] ) {
|
| 5168 |
-
try {
|
| 5169 |
-
pods_query( "TRUNCATE `@wp_pods_{$params->name}`", false );
|
| 5170 |
-
} catch ( Exception $e ) {
|
| 5171 |
-
// Allow pod to be reset if the table doesn't exist
|
| 5172 |
-
if ( false === strpos( $e->getMessage(), 'Unknown table' ) ) {
|
| 5173 |
-
return pods_error( $e->getMessage(), $this );
|
| 5174 |
-
}
|
| 5175 |
-
}
|
| 5176 |
-
}
|
| 5177 |
-
|
| 5178 |
-
pods_query( "DELETE FROM `@wp_podsrel` WHERE `pod_id` = {$params->id} OR `related_pod_id` = {$params->id}", false );
|
| 5179 |
-
}
|
| 5180 |
-
|
| 5181 |
-
// @todo Delete relationships from tableless relationships
|
| 5182 |
-
|
| 5183 |
-
// Delete all posts/revisions from this post type
|
| 5184 |
-
if ( in_array( $pod['type'], array( 'post_type', 'media' ) ) ) {
|
| 5185 |
-
$type = pods_var( 'object', $pod, $pod['name'], null, true );
|
| 5186 |
-
|
| 5187 |
-
$sql = "
|
| 5188 |
-
DELETE `t`, `r`, `m`
|
| 5189 |
-
FROM `{$pod['table']}` AS `t`
|
| 5190 |
-
LEFT JOIN `{$pod['meta_table']}` AS `m`
|
| 5191 |
-
ON `m`.`{$pod['meta_field_id']}` = `t`.`{$pod['field_id']}`
|
| 5192 |
-
LEFT JOIN `{$pod['table']}` AS `r`
|
| 5193 |
-
ON `r`.`post_parent` = `t`.`{$pod['field_id']}` AND `r`.`post_status` = 'inherit'
|
| 5194 |
-
WHERE `t`.`{$pod['field_type']}` = '{$type}'
|
| 5195 |
-
";
|
| 5196 |
-
|
| 5197 |
-
pods_query( $sql, false );
|
| 5198 |
-
} elseif ( 'taxonomy' === $pod['type'] ) {
|
| 5199 |
-
// Delete all terms from this taxonomy
|
| 5200 |
-
if ( function_exists( 'get_term_meta' ) ) {
|
| 5201 |
-
$sql = "
|
| 5202 |
-
DELETE `t`, `m`, `tt`, `tr`
|
| 5203 |
-
FROM `{$pod['table']}` AS `t`
|
| 5204 |
-
LEFT JOIN `{$pod['meta_table']}` AS `m`
|
| 5205 |
-
ON `m`.`{$pod['meta_field_id']}` = `t`.`{$pod['field_id']}`
|
| 5206 |
-
" . $pod['join']['tt'] . "
|
| 5207 |
-
" . $pod['join']['tr'] . "
|
| 5208 |
-
WHERE " . implode( ' AND ', $pod['where'] ) . "
|
| 5209 |
-
";
|
| 5210 |
-
} else {
|
| 5211 |
-
$sql = "
|
| 5212 |
-
DELETE `t`, `tt`, `tr`
|
| 5213 |
-
FROM `{$pod['table']}` AS `t`
|
| 5214 |
-
" . $pod['join']['tt'] . "
|
| 5215 |
-
" . $pod['join']['tr'] . "
|
| 5216 |
-
WHERE " . implode( ' AND ', $pod['where'] ) . "
|
| 5217 |
-
";
|
| 5218 |
-
}
|
| 5219 |
-
|
| 5220 |
-
pods_query( $sql, false );
|
| 5221 |
-
} elseif ( 'user' === $pod['type'] ) {
|
| 5222 |
-
// Delete all users except the current one
|
| 5223 |
-
$sql = "
|
| 5224 |
-
DELETE `t`, `m`
|
| 5225 |
-
FROM `{$pod['table']}` AS `t`
|
| 5226 |
-
LEFT JOIN `{$pod['meta_table']}` AS `m`
|
| 5227 |
-
ON `m`.`{$pod['meta_field_id']}` = `t`.`{$pod['field_id']}`
|
| 5228 |
-
WHERE `t`.`{$pod['field_id']}` != " . (int) get_current_user_id() . "
|
| 5229 |
-
";
|
| 5230 |
-
|
| 5231 |
-
pods_query( $sql, false );
|
| 5232 |
-
} elseif ( 'comment' === $pod['type'] ) {
|
| 5233 |
-
// Delete all comments
|
| 5234 |
-
$type = pods_var( 'object', $pod, $pod['name'], null, true );
|
| 5235 |
-
|
| 5236 |
-
$sql = "
|
| 5237 |
-
DELETE `t`, `m`
|
| 5238 |
-
FROM `{$pod['table']}` AS `t`
|
| 5239 |
-
LEFT JOIN `{$pod['meta_table']}` AS `m`
|
| 5240 |
-
ON `m`.`{$pod['meta_field_id']}` = `t`.`{$pod['field_id']}`
|
| 5241 |
-
WHERE `t`.`{$pod['field_type']}` = '{$type}'
|
| 5242 |
-
";
|
| 5243 |
-
|
| 5244 |
-
pods_query( $sql, false );
|
| 5245 |
-
}
|
| 5246 |
-
|
| 5247 |
-
pods_cache_clear( true ); // only way to reliably clear out cached data across an entire group
|
| 5248 |
-
|
| 5249 |
-
return true;
|
| 5250 |
-
}
|
| 5251 |
-
|
| 5252 |
-
/**
|
| 5253 |
-
* Delete a Pod and all its content
|
| 5254 |
-
*
|
| 5255 |
-
* $params['id'] int The Pod ID
|
| 5256 |
-
* $params['name'] string The Pod name
|
| 5257 |
-
*
|
| 5258 |
-
* @param array $params An associative array of parameters
|
| 5259 |
-
* @param bool $strict (optional) Makes sure a pod exists, if it doesn't throws an error
|
| 5260 |
-
* @param bool $delete_all (optional) Whether to delete all content from a WP object
|
| 5261 |
-
*
|
| 5262 |
-
* @uses PodsAPI::load_pod
|
| 5263 |
-
* @uses wp_delete_post
|
| 5264 |
-
* @uses pods_query
|
| 5265 |
-
*
|
| 5266 |
-
* @return bool
|
| 5267 |
-
* @since 1.7.9
|
| 5268 |
-
*/
|
| 5269 |
-
public function delete_pod( $params, $strict = false, $delete_all = false ) {
|
| 5270 |
-
|
| 5271 |
-
/**
|
| 5272 |
-
* @var $wpdb wpdb
|
| 5273 |
-
*/
|
| 5274 |
-
global $wpdb;
|
| 5275 |
-
|
| 5276 |
-
if ( ! is_object( $params ) && ! is_array( $params ) ) {
|
| 5277 |
-
if ( is_numeric( $params ) ) {
|
| 5278 |
-
$params = array( 'id' => $params );
|
| 5279 |
-
} else {
|
| 5280 |
-
$params = array( 'name' => $params );
|
| 5281 |
-
}
|
| 5282 |
-
|
| 5283 |
-
$params = (object) pods_sanitize( $params );
|
| 5284 |
-
} else {
|
| 5285 |
-
$params = (object) pods_sanitize( $params );
|
| 5286 |
-
}
|
| 5287 |
-
|
| 5288 |
-
if ( ! isset( $params->delete_all ) ) {
|
| 5289 |
-
$params->delete_all = $delete_all;
|
| 5290 |
-
}
|
| 5291 |
-
|
| 5292 |
-
$params->table_info = false;
|
| 5293 |
-
|
| 5294 |
-
$pod = $this->load_pod( $params, $strict );
|
| 5295 |
-
|
| 5296 |
-
if ( empty( $pod ) ) {
|
| 5297 |
-
if ( false !== $strict ) {
|
| 5298 |
-
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
| 5299 |
-
}
|
| 5300 |
-
|
| 5301 |
-
return false;
|
| 5302 |
-
}
|
| 5303 |
-
|
| 5304 |
-
$params->id = (int) $pod['id'];
|
| 5305 |
-
$params->name = $pod['name'];
|
| 5306 |
-
|
| 5307 |
-
// Reset content
|
| 5308 |
-
if ( true === $params->delete_all ) {
|
| 5309 |
-
$this->reset_pod( $params, $pod );
|
| 5310 |
-
}
|
| 5311 |
-
|
| 5312 |
-
foreach ( $pod['fields'] as $field ) {
|
| 5313 |
-
$field['pod'] = $pod;
|
| 5314 |
-
|
| 5315 |
-
$this->delete_field( $field, false );
|
| 5316 |
-
}
|
| 5317 |
-
|
| 5318 |
-
// Only delete the post once the fields are taken care of, it's not required anymore
|
| 5319 |
-
$success = wp_delete_post( $params->id );
|
| 5320 |
-
|
| 5321 |
-
if ( ! $success ) {
|
| 5322 |
-
return pods_error( __( 'Pod unable to be deleted', 'pods' ), $this );
|
| 5323 |
-
}
|
| 5324 |
-
|
| 5325 |
-
if ( ! pods_tableless() ) {
|
| 5326 |
-
if ( 'table' === $pod['storage'] ) {
|
| 5327 |
-
try {
|
| 5328 |
-
pods_query( "DROP TABLE IF EXISTS `@wp_pods_{$params->name}`", false );
|
| 5329 |
-
} catch ( Exception $e ) {
|
| 5330 |
-
// Allow pod to be deleted if the table doesn't exist
|
| 5331 |
-
if ( false === strpos( $e->getMessage(), 'Unknown table' ) ) {
|
| 5332 |
-
return pods_error( $e->getMessage(), $this );
|
| 5333 |
-
}
|
| 5334 |
-
}
|
| 5335 |
-
}
|
| 5336 |
-
|
| 5337 |
-
pods_query( "DELETE FROM `@wp_podsrel` WHERE `pod_id` = {$params->id} OR `related_pod_id` = {$params->id}", false );
|
| 5338 |
-
}
|
| 5339 |
-
|
| 5340 |
-
// @todo Delete relationships from tableless relationships
|
| 5341 |
-
|
| 5342 |
-
// Delete any relationship references
|
| 5343 |
-
$sql = "
|
| 5344 |
-
DELETE `pm`
|
| 5345 |
-
FROM `{$wpdb->postmeta}` AS `pm`
|
| 5346 |
-
LEFT JOIN `{$wpdb->posts}` AS `p`
|
| 5347 |
-
ON `p`.`post_type` = '_pods_field'
|
| 5348 |
-
AND `p`.`ID` = `pm`.`post_id`
|
| 5349 |
-
LEFT JOIN `{$wpdb->postmeta}` AS `pm2`
|
| 5350 |
-
ON `pm2`.`meta_key` = 'pick_object'
|
| 5351 |
-
AND `pm2`.`meta_value` = 'pod'
|
| 5352 |
-
AND `pm2`.`post_id` = `pm`.`post_id`
|
| 5353 |
-
WHERE
|
| 5354 |
-
`p`.`ID` IS NOT NULL
|
| 5355 |
-
AND `pm2`.`meta_id` IS NOT NULL
|
| 5356 |
-
AND `pm`.`meta_key` = 'pick_val'
|
| 5357 |
-
AND `pm`.`meta_value` = '{$params->name}'
|
| 5358 |
-
";
|
| 5359 |
-
|
| 5360 |
-
pods_query( $sql );
|
| 5361 |
-
|
| 5362 |
-
$this->cache_flush_pods( $pod );
|
| 5363 |
-
|
| 5364 |
-
return true;
|
| 5365 |
-
}
|
| 5366 |
-
|
| 5367 |
-
/**
|
| 5368 |
-
* Drop a field within a Pod
|
| 5369 |
-
*
|
| 5370 |
-
* $params['id'] int The field ID
|
| 5371 |
-
* $params['name'] int The field name
|
| 5372 |
-
* $params['pod'] string The Pod name
|
| 5373 |
-
* $params['pod_id'] string The Pod name
|
| 5374 |
-
*
|
| 5375 |
-
* @param array $params An associative array of parameters
|
| 5376 |
-
* @param bool $table_operation Whether or not to handle table operations
|
| 5377 |
-
*
|
| 5378 |
-
* @uses PodsAPI::load_field
|
| 5379 |
-
* @uses wp_delete_post
|
| 5380 |
-
* @uses pods_query
|
| 5381 |
-
*
|
| 5382 |
-
* @return bool
|
| 5383 |
-
* @since 1.7.9
|
| 5384 |
-
*/
|
| 5385 |
-
public function delete_field( $params, $table_operation = true ) {
|
| 5386 |
-
|
| 5387 |
-
/**
|
| 5388 |
-
* @var $wpdb wpdb
|
| 5389 |
-
*/
|
| 5390 |
-
global $wpdb;
|
| 5391 |
-
|
| 5392 |
-
$tableless_field_types = PodsForm::tableless_field_types();
|
| 5393 |
-
$simple_tableless_objects = PodsForm::simple_tableless_objects();
|
| 5394 |
-
|
| 5395 |
-
$params = (object) pods_sanitize( $params );
|
| 5396 |
-
|
| 5397 |
-
if ( ! isset( $params->pod ) ) {
|
| 5398 |
-
$params->pod = '';
|
| 5399 |
-
}
|
| 5400 |
-
|
| 5401 |
-
if ( ! isset( $params->pod_id ) ) {
|
| 5402 |
-
$params->pod_id = 0;
|
| 5403 |
-
}
|
| 5404 |
-
|
| 5405 |
-
$pod = $params->pod;
|
| 5406 |
-
|
| 5407 |
-
$save_pod = false;
|
| 5408 |
-
|
| 5409 |
-
if ( ! is_array( $pod ) ) {
|
| 5410 |
-
$pod = $this->load_pod( array( 'name' => $pod, 'id' => $params->pod_id, 'table_info' => false ) );
|
| 5411 |
-
} else {
|
| 5412 |
-
$save_pod = true;
|
| 5413 |
-
}
|
| 5414 |
-
|
| 5415 |
-
if ( empty( $pod ) ) {
|
| 5416 |
-
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
| 5417 |
-
}
|
| 5418 |
-
|
| 5419 |
-
$params->pod_id = $pod['id'];
|
| 5420 |
-
$params->pod = $pod['name'];
|
| 5421 |
-
|
| 5422 |
-
if ( ! isset( $params->name ) ) {
|
| 5423 |
-
$params->name = '';
|
| 5424 |
-
}
|
| 5425 |
-
|
| 5426 |
-
if ( ! isset( $params->id ) ) {
|
| 5427 |
-
$params->id = 0;
|
| 5428 |
-
}
|
| 5429 |
-
|
| 5430 |
-
$field = $this->load_field( array(
|
| 5431 |
-
'name' => $params->name,
|
| 5432 |
-
'id' => $params->id,
|
| 5433 |
-
'pod' => $params->pod,
|
| 5434 |
-
'pod_id' => $params->pod_id
|
| 5435 |
-
) );
|
| 5436 |
-
|
| 5437 |
-
if ( false === $field ) {
|
| 5438 |
-
return pods_error( __( 'Field not found', 'pods' ), $this );
|
| 5439 |
-
}
|
| 5440 |
-
|
| 5441 |
-
$params->id = $field['id'];
|
| 5442 |
-
$params->name = $field['name'];
|
| 5443 |
-
|
| 5444 |
-
$simple = ( 'pick' === $field['type'] && in_array( pods_var( 'pick_object', $field ), $simple_tableless_objects ) );
|
| 5445 |
-
$simple = (boolean) $this->do_hook( 'tableless_custom', $simple, $field, $pod, $params );
|
| 5446 |
-
|
| 5447 |
-
if ( $table_operation && 'table' === $pod['storage'] && ( ! in_array( $field['type'], $tableless_field_types ) || $simple ) ) {
|
| 5448 |
-
pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` DROP COLUMN `{$params->name}`", false );
|
| 5449 |
-
}
|
| 5450 |
-
|
| 5451 |
-
$success = wp_delete_post( $params->id );
|
| 5452 |
-
|
| 5453 |
-
if ( ! $success ) {
|
| 5454 |
-
return pods_error( __( 'Field unable to be deleted', 'pods' ), $this );
|
| 5455 |
-
}
|
| 5456 |
-
|
| 5457 |
-
$wpdb->query( $wpdb->prepare( "DELETE pm FROM {$wpdb->postmeta} AS pm
|
| 5458 |
-
LEFT JOIN {$wpdb->posts} AS p
|
| 5459 |
-
ON p.post_type = '_pods_field' AND p.ID = pm.post_id
|
| 5460 |
-
WHERE p.ID IS NOT NULL AND pm.meta_key = 'sister_id' AND pm.meta_value = %d", $params->id ) );
|
| 5461 |
-
|
| 5462 |
-
if ( ( ! pods_tableless() ) && $table_operation ) {
|
| 5463 |
-
pods_query( "DELETE FROM `@wp_podsrel` WHERE (`pod_id` = {$params->pod_id} AND `field_id` = {$params->id}) OR (`related_pod_id` = {$params->pod_id} AND `related_field_id` = {$params->id})", false );
|
| 5464 |
-
}
|
| 5465 |
-
|
| 5466 |
-
// @todo Delete tableless relationship meta
|
| 5467 |
-
|
| 5468 |
-
if ( true === $save_pod ) {
|
| 5469 |
-
$this->cache_flush_pods( $pod );
|
| 5470 |
-
}
|
| 5471 |
-
|
| 5472 |
-
return true;
|
| 5473 |
-
}
|
| 5474 |
-
|
| 5475 |
-
/**
|
| 5476 |
-
* Drop a Pod Object
|
| 5477 |
-
*
|
| 5478 |
-
* $params['id'] int The object ID
|
| 5479 |
-
* $params['name'] string The object name
|
| 5480 |
-
* $params['type'] string The object type
|
| 5481 |
-
*
|
| 5482 |
-
* @param array|object $params An associative array of parameters
|
| 5483 |
-
*
|
| 5484 |
-
* @uses wp_delete_post
|
| 5485 |
-
*
|
| 5486 |
-
* @return bool
|
| 5487 |
-
* @since 2.0.0
|
| 5488 |
-
*/
|
| 5489 |
-
public function delete_object( $params ) {
|
| 5490 |
-
|
| 5491 |
-
$params = (object) $params;
|
| 5492 |
-
$object = $this->load_object( $params );
|
| 5493 |
-
|
| 5494 |
-
if ( empty( $object ) ) {
|
| 5495 |
-
return pods_error( sprintf( __( "%s Object not found", 'pods' ), ucwords( $params->type ) ), $this );
|
| 5496 |
-
}
|
| 5497 |
-
|
| 5498 |
-
$success = wp_delete_post( $params->id );
|
| 5499 |
-
|
| 5500 |
-
if ( ! $success ) {
|
| 5501 |
-
return pods_error( sprintf( __( "%s Object not deleted", 'pods' ), ucwords( $params->type ) ), $this );
|
| 5502 |
-
}
|
| 5503 |
-
|
| 5504 |
-
pods_transient_clear( 'pods_objects_' . $params->type );
|
| 5505 |
-
|
| 5506 |
-
return true;
|
| 5507 |
-
}
|
| 5508 |
-
|
| 5509 |
-
/**
|
| 5510 |
-
* @see PodsAPI::delete_object
|
| 5511 |
-
*
|
| 5512 |
-
* Drop a Pod Template
|
| 5513 |
-
*
|
| 5514 |
-
* $params['id'] int The template ID
|
| 5515 |
-
* $params['name'] string The template name
|
| 5516 |
-
*
|
| 5517 |
-
* @param array $params An associative array of parameters
|
| 5518 |
-
*
|
| 5519 |
-
* @return bool
|
| 5520 |
-
* @since 1.7.9
|
| 5521 |
-
*/
|
| 5522 |
-
public function delete_template( $params ) {
|
| 5523 |
-
|
| 5524 |
-
$params = (object) $params;
|
| 5525 |
-
$params->type = 'template';
|
| 5526 |
-
|
| 5527 |
-
return $this->delete_object( $params );
|
| 5528 |
-
}
|
| 5529 |
-
|
| 5530 |
-
/**
|
| 5531 |
-
* @see PodsAPI::delete_object
|
| 5532 |
-
*
|
| 5533 |
-
* Drop a Pod Page
|
| 5534 |
-
*
|
| 5535 |
-
* $params['id'] int The page ID
|
| 5536 |
-
* $params['uri'] string The page URI
|
| 5537 |
-
*
|
| 5538 |
-
* @param array $params An associative array of parameters
|
| 5539 |
-
*
|
| 5540 |
-
* @return bool
|
| 5541 |
-
* @since 1.7.9
|
| 5542 |
-
*/
|
| 5543 |
-
public function delete_page( $params ) {
|
| 5544 |
-
|
| 5545 |
-
$params = (object) $params;
|
| 5546 |
-
if ( isset( $params->uri ) ) {
|
| 5547 |
-
$params->name = $params->uri;
|
| 5548 |
-
unset( $params->uri );
|
| 5549 |
-
}
|
| 5550 |
-
if ( isset( $params->name ) ) {
|
| 5551 |
-
$params->name = trim( $params->name, '/' );
|
| 5552 |
-
}
|
| 5553 |
-
$params->type = 'page';
|
| 5554 |
-
|
| 5555 |
-
return $this->delete_object( $params );
|
| 5556 |
-
}
|
| 5557 |
-
|
| 5558 |
-
/**
|
| 5559 |
-
* @see PodsAPI::delete_object
|
| 5560 |
-
*
|
| 5561 |
-
* Drop a Pod Helper
|
| 5562 |
-
*
|
| 5563 |
-
* $params['id'] int The helper ID
|
| 5564 |
-
* $params['name'] string The helper name
|
| 5565 |
-
*
|
| 5566 |
-
* @param array $params An associative array of parameters
|
| 5567 |
-
*
|
| 5568 |
-
* @return bool
|
| 5569 |
-
* @since 1.7.9
|
| 5570 |
-
*/
|
| 5571 |
-
public function delete_helper( $params ) {
|
| 5572 |
-
|
| 5573 |
-
$params = (object) $params;
|
| 5574 |
-
$params->type = 'helper';
|
| 5575 |
-
|
| 5576 |
-
return $this->delete_object( $params );
|
| 5577 |
-
}
|
| 5578 |
-
|
| 5579 |
-
/**
|
| 5580 |
-
* Drop a single pod item
|
| 5581 |
-
*
|
| 5582 |
-
* $params['id'] int (optional) The item's ID from the wp_pod_* table (used with datatype parameter)
|
| 5583 |
-
* $params['pod'] string (optional) The Pod name (used with id parameter)
|
| 5584 |
-
* $params['pod_id'] int (optional) The Pod ID (used with id parameter)
|
| 5585 |
-
* $params['bypass_helpers'] bool Set to true to bypass running pre-save and post-save helpers
|
| 5586 |
-
*
|
| 5587 |
-
* @param array $params An associative array of parameters
|
| 5588 |
-
* @param bool $wp Whether to run WP object delete action
|
| 5589 |
-
*
|
| 5590 |
-
* @return bool
|
| 5591 |
-
* @since 1.7.9
|
| 5592 |
-
*/
|
| 5593 |
-
public function delete_pod_item( $params, $wp = true ) {
|
| 5594 |
-
|
| 5595 |
-
$params = (object) pods_sanitize( $params );
|
| 5596 |
-
|
| 5597 |
-
// @deprecated 2.0.0
|
| 5598 |
-
if ( isset( $params->datatype_id ) || isset( $params->datatype ) || isset( $params->tbl_row_id ) ) {
|
| 5599 |
-
if ( isset( $params->tbl_row_id ) ) {
|
| 5600 |
-
pods_deprecated( __( '$params->id instead of $params->tbl_row_id', 'pods' ), '2.0' );
|
| 5601 |
-
$params->id = $params->tbl_row_id;
|
| 5602 |
-
unset( $params->tbl_row_id );
|
| 5603 |
-
}
|
| 5604 |
-
|
| 5605 |
-
if ( isset( $params->pod_id ) ) {
|
| 5606 |
-
pods_deprecated( __( '$params->id instead of $params->pod_id', 'pods' ), '2.0' );
|
| 5607 |
-
$params->id = $params->pod_id;
|
| 5608 |
-
unset( $params->pod_id );
|
| 5609 |
-
}
|
| 5610 |
-
|
| 5611 |
-
if ( isset( $params->dataype_id ) ) {
|
| 5612 |
-
pods_deprecated( __( '$params->pod_id instead of $params->datatype_id', 'pods' ), '2.0' );
|
| 5613 |
-
$params->pod_id = $params->dataype_id;
|
| 5614 |
-
unset( $params->dataype_id );
|
| 5615 |
-
}
|
| 5616 |
-
|
| 5617 |
-
if ( isset( $params->datatype ) ) {
|
| 5618 |
-
pods_deprecated( __( '$params->pod instead of $params->datatype', 'pods' ), '2.0' );
|
| 5619 |
-
$params->pod = $params->datatype;
|
| 5620 |
-
unset( $params->datatype );
|
| 5621 |
-
}
|
| 5622 |
-
}
|
| 5623 |
-
|
| 5624 |
-
if ( ! isset( $params->id ) ) {
|
| 5625 |
-
return pods_error( __( 'Pod Item not found', 'pods' ), $this );
|
| 5626 |
-
}
|
| 5627 |
-
|
| 5628 |
-
$params->id = pods_absint( $params->id );
|
| 5629 |
-
|
| 5630 |
-
if ( ! isset( $params->pod ) ) {
|
| 5631 |
-
$params->pod = '';
|
| 5632 |
-
}
|
| 5633 |
-
|
| 5634 |
-
if ( ! isset( $params->pod_id ) ) {
|
| 5635 |
-
$params->pod_id = 0;
|
| 5636 |
-
}
|
| 5637 |
-
|
| 5638 |
-
$pod = $this->load_pod( array( 'name' => $params->pod, 'id' => $params->pod_id, 'table_info' => false ) );
|
| 5639 |
-
|
| 5640 |
-
if ( false === $pod ) {
|
| 5641 |
-
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
| 5642 |
-
}
|
| 5643 |
-
|
| 5644 |
-
$params->pod_id = $pod['id'];
|
| 5645 |
-
$params->pod = $pod['name'];
|
| 5646 |
-
|
| 5647 |
-
// Allow Helpers to bypass subsequent helpers in recursive delete_pod_item calls
|
| 5648 |
-
$bypass_helpers = false;
|
| 5649 |
-
|
| 5650 |
-
if ( isset( $params->bypass_helpers ) && false !== $params->bypass_helpers ) {
|
| 5651 |
-
$bypass_helpers = true;
|
| 5652 |
-
}
|
| 5653 |
-
|
| 5654 |
-
$pre_delete_helpers = array();
|
| 5655 |
-
$post_delete_helpers = array();
|
| 5656 |
-
|
| 5657 |
-
if ( false === $bypass_helpers ) {
|
| 5658 |
-
// Plugin hook
|
| 5659 |
-
$this->do_hook( 'pre_delete_pod_item', $params, $pod );
|
| 5660 |
-
$this->do_hook( "pre_delete_pod_item_{$params->pod}", $params, $pod );
|
| 5661 |
-
|
| 5662 |
-
// Call any pre-save helpers (if not bypassed)
|
| 5663 |
-
if ( ! defined( 'PODS_DISABLE_EVAL' ) || ! PODS_DISABLE_EVAL ) {
|
| 5664 |
-
if ( ! empty( $pod['options'] ) && is_array( $pod['options'] ) ) {
|
| 5665 |
-
$helpers = array( 'pre_delete_helpers', 'post_delete_helpers' );
|
| 5666 |
-
|
| 5667 |
-
foreach ( $helpers as $helper ) {
|
| 5668 |
-
if ( isset( $pod['options'][ $helper ] ) && ! empty( $pod['options'][ $helper ] ) ) {
|
| 5669 |
-
${$helper} = explode( ',', $pod['options'][ $helper ] );
|
| 5670 |
-
}
|
| 5671 |
-
}
|
| 5672 |
-
}
|
| 5673 |
-
|
| 5674 |
-
if ( ! empty( $pre_delete_helpers ) ) {
|
| 5675 |
-
pods_deprecated( sprintf( __( 'Pre-delete helpers are deprecated, use the action pods_pre_delete_pod_item_%s instead', 'pods' ), $params->pod ), '2.0' );
|
| 5676 |
-
|
| 5677 |
-
foreach ( $pre_delete_helpers as $helper ) {
|
| 5678 |
-
$helper = $this->load_helper( array( 'name' => $helper ) );
|
| 5679 |
-
|
| 5680 |
-
if ( false !== $helper ) {
|
| 5681 |
-
eval( '?>' . $helper['code'] );
|
| 5682 |
-
}
|
| 5683 |
-
}
|
| 5684 |
-
}
|
| 5685 |
-
}
|
| 5686 |
-
}
|
| 5687 |
-
|
| 5688 |
-
// Delete object from relationship fields
|
| 5689 |
-
$this->delete_object_from_relationships( $params->id, $pod );
|
| 5690 |
-
|
| 5691 |
-
if ( 'table' === $pod['storage'] ) {
|
| 5692 |
-
pods_query( "DELETE FROM `@wp_pods_{$params->pod}` WHERE `id` = {$params->id} LIMIT 1" );
|
| 5693 |
-
}
|
| 5694 |
-
|
| 5695 |
-
if ( $wp ) {
|
| 5696 |
-
if ( 'taxonomy' === $pod['type'] ) {
|
| 5697 |
-
$taxonomy = $pod['name'];
|
| 5698 |
-
|
| 5699 |
-
if ( ! empty( $pod['object'] ) ) {
|
| 5700 |
-
$taxonomy = $pod['object'];
|
| 5701 |
-
}
|
| 5702 |
-
|
| 5703 |
-
wp_delete_term( $params->id, $taxonomy );
|
| 5704 |
-
} elseif ( ! in_array( $pod['type'], array( 'pod', 'table', '', 'taxonomy' ) ) ) {
|
| 5705 |
-
$this->delete_wp_object( $pod['type'], $params->id );
|
| 5706 |
-
}
|
| 5707 |
-
}
|
| 5708 |
-
|
| 5709 |
-
if ( false === $bypass_helpers ) {
|
| 5710 |
-
// Plugin hook
|
| 5711 |
-
$this->do_hook( 'post_delete_pod_item', $params, $pod );
|
| 5712 |
-
$this->do_hook( "post_delete_pod_item_{$params->pod}", $params, $pod );
|
| 5713 |
-
|
| 5714 |
-
// Call any post-save helpers (if not bypassed)
|
| 5715 |
-
if ( ! defined( 'PODS_DISABLE_EVAL' ) || ! PODS_DISABLE_EVAL ) {
|
| 5716 |
-
if ( ! empty( $post_delete_helpers ) ) {
|
| 5717 |
-
pods_deprecated( sprintf( __( 'Post-delete helpers are deprecated, use the action pods_post_delete_pod_item_%s instead', 'pods' ), $params->pod ), '2.0' );
|
| 5718 |
-
|
| 5719 |
-
foreach ( $post_delete_helpers as $helper ) {
|
| 5720 |
-
$helper = $this->load_helper( array( 'name' => $helper ) );
|
| 5721 |
-
|
| 5722 |
-
if ( false !== $helper ) {
|
| 5723 |
-
eval( '?>' . $helper['code'] );
|
| 5724 |
-
}
|
| 5725 |
-
}
|
| 5726 |
-
}
|
| 5727 |
-
}
|
| 5728 |
-
}
|
| 5729 |
-
|
| 5730 |
-
pods_cache_clear( $params->id, 'pods_items_' . $params->pod );
|
| 5731 |
-
|
| 5732 |
-
return true;
|
| 5733 |
-
}
|
| 5734 |
-
|
| 5735 |
-
/**
|
| 5736 |
-
* Delete an object from tableless fields
|
| 5737 |
-
*
|
| 5738 |
-
* @param int $id
|
| 5739 |
-
* @param string $type
|
| 5740 |
-
* @param string $name
|
| 5741 |
-
*
|
| 5742 |
-
* @return bool
|
| 5743 |
-
*
|
| 5744 |
-
* @since 2.3.0
|
| 5745 |
-
*/
|
| 5746 |
-
public function delete_object_from_relationships( $id, $object, $name = null ) {
|
| 5747 |
-
|
| 5748 |
-
/**
|
| 5749 |
-
* @var $pods_init \PodsInit
|
| 5750 |
-
* @todo Use pods_init() function?
|
| 5751 |
-
*/
|
| 5752 |
-
global $pods_init;
|
| 5753 |
-
|
| 5754 |
-
$pod = false;
|
| 5755 |
-
|
| 5756 |
-
// Run any bidirectional delete operations
|
| 5757 |
-
if ( is_array( $object ) ) {
|
| 5758 |
-
$pod = $object;
|
| 5759 |
-
} elseif ( is_object( $pods_init ) ) {
|
| 5760 |
-
$pod = PodsInit::$meta->get_object( $object, $name );
|
| 5761 |
-
}
|
| 5762 |
-
|
| 5763 |
-
if ( ! empty( $pod ) ) {
|
| 5764 |
-
$object = $pod['type'];
|
| 5765 |
-
$name = $pod['name'];
|
| 5766 |
-
|
| 5767 |
-
foreach ( $pod['fields'] as $field ) {
|
| 5768 |
-
PodsForm::delete( $field['type'], $id, $field['name'], array_merge( $field, $field['options'] ), $pod );
|
| 5769 |
-
}
|
| 5770 |
-
}
|
| 5771 |
-
|
| 5772 |
-
// Lookup related fields (non-bidirectional)
|
| 5773 |
-
$params = array(
|
| 5774 |
-
'where' => array(
|
| 5775 |
-
array(
|
| 5776 |
-
'key' => 'type',
|
| 5777 |
-
'value' => 'pick'
|
| 5778 |
-
),
|
| 5779 |
-
array(
|
| 5780 |
-
'key' => 'pick_object',
|
| 5781 |
-
'value' => $object
|
| 5782 |
-
)
|
| 5783 |
-
)
|
| 5784 |
-
);
|
| 5785 |
-
|
| 5786 |
-
if ( ! empty( $name ) && $name !== $object ) {
|
| 5787 |
-
$params['where'][] = array(
|
| 5788 |
-
'key' => 'pick_val',
|
| 5789 |
-
'value' => $name
|
| 5790 |
-
);
|
| 5791 |
-
}
|
| 5792 |
-
|
| 5793 |
-
$fields = $this->load_fields( $params, false );
|
| 5794 |
-
|
| 5795 |
-
if ( ! empty( $pod ) && 'media' === $pod['type'] ) {
|
| 5796 |
-
$params['where'] = array(
|
| 5797 |
-
array(
|
| 5798 |
-
'key' => 'type',
|
| 5799 |
-
'value' => 'file'
|
| 5800 |
-
)
|
| 5801 |
-
);
|
| 5802 |
-
|
| 5803 |
-
$fields = array_merge( $fields, $this->load_fields( $params, false ) );
|
| 5804 |
-
}
|
| 5805 |
-
|
| 5806 |
-
if ( is_array( $fields ) && ! empty( $fields ) ) {
|
| 5807 |
-
foreach ( $fields as $related_field ) {
|
| 5808 |
-
$related_pod = $this->load_pod( array( 'id' => $related_field['pod_id'], 'fields' => false ), false );
|
| 5809 |
-
|
| 5810 |
-
if ( empty( $related_pod ) ) {
|
| 5811 |
-
continue;
|
| 5812 |
-
}
|
| 5813 |
-
|
| 5814 |
-
$related_from = $this->lookup_related_items_from( $related_field['id'], $related_pod['id'], $id, $related_field, $related_pod );
|
| 5815 |
-
|
| 5816 |
-
$this->delete_relationships( $related_from, $id, $related_pod, $related_field );
|
| 5817 |
-
}
|
| 5818 |
-
}
|
| 5819 |
-
|
| 5820 |
-
if ( ! empty( $pod ) && ! pods_tableless() ) {
|
| 5821 |
-
pods_query( "
|
| 5822 |
-
DELETE FROM `@wp_podsrel`
|
| 5823 |
-
WHERE
|
| 5824 |
-
(
|
| 5825 |
-
`pod_id` = %d
|
| 5826 |
-
AND `item_id` = %d
|
| 5827 |
-
)
|
| 5828 |
-
OR (
|
| 5829 |
-
`related_pod_id` = %d
|
| 5830 |
-
AND `related_item_id` = %d
|
| 5831 |
-
)
|
| 5832 |
-
", array(
|
| 5833 |
-
$pod['id'],
|
| 5834 |
-
$id,
|
| 5835 |
-
|
| 5836 |
-
$pod['id'],
|
| 5837 |
-
$id
|
| 5838 |
-
) );
|
| 5839 |
-
}
|
| 5840 |
-
|
| 5841 |
-
return true;
|
| 5842 |
-
}
|
| 5843 |
-
|
| 5844 |
-
/**
|
| 5845 |
-
* Delete relationships
|
| 5846 |
-
*
|
| 5847 |
-
* @param int|array $related_id IDs for items to save
|
| 5848 |
-
* @param int|array $id ID or IDs to remove
|
| 5849 |
-
* @param array $related_pod Pod data
|
| 5850 |
-
* @param array $related_field Field data
|
| 5851 |
-
*
|
| 5852 |
-
* @return void
|
| 5853 |
-
*
|
| 5854 |
-
* @since 2.3.0
|
| 5855 |
-
*/
|
| 5856 |
-
public function delete_relationships( $related_id, $id, $related_pod, $related_field ) {
|
| 5857 |
-
|
| 5858 |
-
if ( is_array( $related_id ) ) {
|
| 5859 |
-
foreach ( $related_id as $rid ) {
|
| 5860 |
-
$this->delete_relationships( $rid, $id, $related_pod, $related_field );
|
| 5861 |
-
}
|
| 5862 |
-
|
| 5863 |
-
return;
|
| 5864 |
-
}
|
| 5865 |
-
|
| 5866 |
-
if ( is_array( $id ) ) {
|
| 5867 |
-
foreach ( $id as $rid ) {
|
| 5868 |
-
$this->delete_relationships( $related_id, $rid, $related_pod, $related_field );
|
| 5869 |
-
}
|
| 5870 |
-
|
| 5871 |
-
return;
|
| 5872 |
-
}
|
| 5873 |
-
|
| 5874 |
-
$id = (int) $id;
|
| 5875 |
-
|
| 5876 |
-
if ( empty( $id ) ) {
|
| 5877 |
-
return;
|
| 5878 |
-
}
|
| 5879 |
-
|
| 5880 |
-
$related_ids = $this->lookup_related_items( $related_field['id'], $related_pod['id'], $related_id, $related_field, $related_pod );
|
| 5881 |
-
|
| 5882 |
-
if ( empty( $related_ids ) ) {
|
| 5883 |
-
return;
|
| 5884 |
-
} elseif ( ! in_array( $id, $related_ids ) ) {
|
| 5885 |
-
return;
|
| 5886 |
-
}
|
| 5887 |
-
|
| 5888 |
-
if ( isset( self::$related_item_cache[ $related_pod['id'] ][ $related_field['id'] ] ) ) {
|
| 5889 |
-
// Delete relationship from cache
|
| 5890 |
-
unset( self::$related_item_cache[ $related_pod['id'] ][ $related_field['id'] ] );
|
| 5891 |
-
}
|
| 5892 |
-
|
| 5893 |
-
// @codingStandardsIgnoreLine
|
| 5894 |
-
unset( $related_ids[ array_search( $id, $related_ids ) ] );
|
| 5895 |
-
|
| 5896 |
-
$no_conflict = pods_no_conflict_check( $related_pod['type'] );
|
| 5897 |
-
|
| 5898 |
-
if ( ! $no_conflict ) {
|
| 5899 |
-
pods_no_conflict_on( $related_pod['type'] );
|
| 5900 |
-
}
|
| 5901 |
-
|
| 5902 |
-
// Post Types, Media, Users, and Comments (meta-based)
|
| 5903 |
-
if ( in_array( $related_pod['type'], array( 'post_type', 'media', 'taxonomy', 'user', 'comment' ) ) ) {
|
| 5904 |
-
$object_type = $related_pod['type'];
|
| 5905 |
-
|
| 5906 |
-
if ( in_array( $object_type, array( 'post_type', 'media' ) ) ) {
|
| 5907 |
-
$object_type = 'post';
|
| 5908 |
-
} elseif ( 'taxonomy' === $object_type ) {
|
| 5909 |
-
$object_type = 'term';
|
| 5910 |
-
}
|
| 5911 |
-
|
| 5912 |
-
delete_metadata( $object_type, $related_id, $related_field['name'] );
|
| 5913 |
-
|
| 5914 |
-
if ( ! empty( $related_ids ) ) {
|
| 5915 |
-
update_metadata( $object_type, $related_id, '_pods_' . $related_field['name'], $related_ids );
|
| 5916 |
-
|
| 5917 |
-
foreach ( $related_ids as $rel_id ) {
|
| 5918 |
-
add_metadata( $object_type, $related_id, $related_field['name'], $rel_id );
|
| 5919 |
-
}
|
| 5920 |
-
} else {
|
| 5921 |
-
delete_metadata( $object_type, $related_id, '_pods_' . $related_field['name'] );
|
| 5922 |
-
}
|
| 5923 |
-
} elseif ( 'settings' === $related_pod['type'] ) {
|
| 5924 |
-
// Custom Settings Pages (options-based)
|
| 5925 |
-
if ( ! empty( $related_ids ) ) {
|
| 5926 |
-
update_option( $related_pod['name'] . '_' . $related_field['name'], $related_ids );
|
| 5927 |
-
} else {
|
| 5928 |
-
delete_option( $related_pod['name'] . '_' . $related_field['name'] );
|
| 5929 |
-
}
|
| 5930 |
-
}
|
| 5931 |
-
|
| 5932 |
-
// Relationships table
|
| 5933 |
-
if ( ! pods_tableless() ) {
|
| 5934 |
-
pods_query( "
|
| 5935 |
-
DELETE FROM `@wp_podsrel`
|
| 5936 |
-
WHERE
|
| 5937 |
-
(
|
| 5938 |
-
`pod_id` = %d
|
| 5939 |
-
AND `field_id` = %d
|
| 5940 |
-
AND `item_id` = %d
|
| 5941 |
-
AND `related_item_id` = %d
|
| 5942 |
-
)
|
| 5943 |
-
OR (
|
| 5944 |
-
`related_pod_id` = %d
|
| 5945 |
-
AND `related_field_id` = %d
|
| 5946 |
-
AND `related_item_id` = %d
|
| 5947 |
-
AND `item_id` = %d
|
| 5948 |
-
)
|
| 5949 |
-
", array(
|
| 5950 |
-
$related_pod['id'],
|
| 5951 |
-
$related_field['id'],
|
| 5952 |
-
$related_id,
|
| 5953 |
-
$id,
|
| 5954 |
-
|
| 5955 |
-
$related_pod['id'],
|
| 5956 |
-
$related_field['id'],
|
| 5957 |
-
$related_id,
|
| 5958 |
-
$id
|
| 5959 |
-
) );
|
| 5960 |
-
}
|
| 5961 |
-
|
| 5962 |
-
if ( ! $no_conflict ) {
|
| 5963 |
-
pods_no_conflict_off( $related_pod['type'] );
|
| 5964 |
-
}
|
| 5965 |
-
}
|
| 5966 |
-
|
| 5967 |
-
/**
|
| 5968 |
-
* Check if a Pod exists
|
| 5969 |
-
*
|
| 5970 |
-
* $params['id'] int Pod ID
|
| 5971 |
-
* $params['name'] string Pod name
|
| 5972 |
-
*
|
| 5973 |
-
* @param array $params An associative array of parameters
|
| 5974 |
-
*
|
| 5975 |
-
* @return bool True if exists
|
| 5976 |
-
*
|
| 5977 |
-
* @since 1.12
|
| 5978 |
-
*/
|
| 5979 |
-
public function pod_exists( $params, $type = null ) {
|
| 5980 |
-
|
| 5981 |
-
if ( is_string( $params ) ) {
|
| 5982 |
-
$params = array( 'name' => $params );
|
| 5983 |
-
}
|
| 5984 |
-
|
| 5985 |
-
$params = (object) pods_sanitize( $params );
|
| 5986 |
-
|
| 5987 |
-
if ( ! empty( $params->id ) || ! empty( $params->name ) ) {
|
| 5988 |
-
if ( ! isset( $params->name ) ) {
|
| 5989 |
-
$dummy = (int) $params->id;
|
| 5990 |
-
$pod = get_post( $dummy );
|
| 5991 |
-
} else {
|
| 5992 |
-
$pod = get_posts( array(
|
| 5993 |
-
'name' => $params->name,
|
| 5994 |
-
'post_type' => '_pods_pod',
|
| 5995 |
-
'posts_per_page' => 1
|
| 5996 |
-
) );
|
| 5997 |
-
|
| 5998 |
-
if ( is_array( $pod ) && ! empty( $pod[0] ) ) {
|
| 5999 |
-
$pod = $pod[0];
|
| 6000 |
-
}
|
| 6001 |
-
}
|
| 6002 |
-
|
| 6003 |
-
if ( ! empty( $pod ) && ( empty( $type ) || $type == get_post_meta( $pod->ID, 'type', true ) ) ) {
|
| 6004 |
-
return true;
|
| 6005 |
-
}
|
| 6006 |
-
}
|
| 6007 |
-
|
| 6008 |
-
return false;
|
| 6009 |
-
}
|
| 6010 |
-
|
| 6011 |
-
/**
|
| 6012 |
-
* Get number of pods for a specific pod type
|
| 6013 |
-
*
|
| 6014 |
-
* @param string $type Type to get count
|
| 6015 |
-
*
|
| 6016 |
-
* @return int Total number of pods for a type
|
| 6017 |
-
*
|
| 6018 |
-
* @since 2.6.6
|
| 6019 |
-
*/
|
| 6020 |
-
public function get_pod_type_count( $type ) {
|
| 6021 |
-
|
| 6022 |
-
$args = array(
|
| 6023 |
-
'post_type' => '_pods_pod',
|
| 6024 |
-
'posts_per_page' => - 1,
|
| 6025 |
-
'nopaging' => true,
|
| 6026 |
-
'fields' => 'ids',
|
| 6027 |
-
'meta_query' => array(
|
| 6028 |
-
array(
|
| 6029 |
-
'key' => 'type',
|
| 6030 |
-
'value' => $type,
|
| 6031 |
-
),
|
| 6032 |
-
),
|
| 6033 |
-
);
|
| 6034 |
-
|
| 6035 |
-
$posts = get_posts( $args );
|
| 6036 |
-
|
| 6037 |
-
$total = count( $posts );
|
| 6038 |
-
|
| 6039 |
-
return $total;
|
| 6040 |
-
|
| 6041 |
-
}
|
| 6042 |
-
|
| 6043 |
-
/**
|
| 6044 |
-
* Load a Pod and all of its fields
|
| 6045 |
-
*
|
| 6046 |
-
* $params['id'] int The Pod ID
|
| 6047 |
-
* $params['name'] string The Pod name
|
| 6048 |
-
* $params['fields'] bool Whether to load fields (default is true)
|
| 6049 |
-
* $params['bypass_cache'] boolean Bypass the cache when getting data
|
| 6050 |
-
*
|
| 6051 |
-
* @param array|object $params An associative array of parameters or pod name as a string
|
| 6052 |
-
* @param bool $strict Makes sure the pod exists, throws an error if it doesn't work
|
| 6053 |
-
*
|
| 6054 |
-
* @return array|bool|mixed|void
|
| 6055 |
-
* @since 1.7.9
|
| 6056 |
-
*/
|
| 6057 |
-
public function load_pod( $params, $strict = true ) {
|
| 6058 |
-
|
| 6059 |
-
/**
|
| 6060 |
-
* @var $sitepress SitePress
|
| 6061 |
-
* @var $wpdb wpdb
|
| 6062 |
-
*/
|
| 6063 |
-
global $wpdb;
|
| 6064 |
-
|
| 6065 |
-
$current_language = false;
|
| 6066 |
-
$load_fields = true;
|
| 6067 |
-
$bypass_cache = false;
|
| 6068 |
-
|
| 6069 |
-
// Get current language data
|
| 6070 |
-
$lang_data = pods_i18n()->get_current_language_data();
|
| 6071 |
-
|
| 6072 |
-
if ( $lang_data ) {
|
| 6073 |
-
if ( ! empty( $lang_data['language'] ) ) {
|
| 6074 |
-
$current_language = $lang_data['language'];
|
| 6075 |
-
}
|
| 6076 |
-
}
|
| 6077 |
-
|
| 6078 |
-
if ( ! is_array( $params ) && ! is_object( $params ) ) {
|
| 6079 |
-
$params = array( 'name' => $params, 'table_info' => false, 'fields' => true );
|
| 6080 |
-
}
|
| 6081 |
-
|
| 6082 |
-
if ( is_object( $params ) && ! is_a( $params, 'WP_Post' ) && isset( $params->fields ) && ! $params->fields ) {
|
| 6083 |
-
$load_fields = false;
|
| 6084 |
-
} elseif ( is_array( $params ) && isset( $params['fields'] ) && ! $params['fields'] ) {
|
| 6085 |
-
$load_fields = false;
|
| 6086 |
-
}
|
| 6087 |
-
|
| 6088 |
-
$table_info = false;
|
| 6089 |
-
|
| 6090 |
-
if ( is_object( $params ) && ! is_a( $params, 'WP_Post' ) && ! empty( $params->table_info ) ) {
|
| 6091 |
-
$table_info = true;
|
| 6092 |
-
} elseif ( is_array( $params ) && ! empty( $params['table_info'] ) ) {
|
| 6093 |
-
$table_info = true;
|
| 6094 |
-
}
|
| 6095 |
-
|
| 6096 |
-
$transient = 'pods_' . $wpdb->prefix . '_pod';
|
| 6097 |
-
|
| 6098 |
-
if ( ! empty( $current_language ) ) {
|
| 6099 |
-
$transient .= '_' . $current_language;
|
| 6100 |
-
}
|
| 6101 |
-
|
| 6102 |
-
if ( ! $load_fields ) {
|
| 6103 |
-
$transient .= '_nofields';
|
| 6104 |
-
}
|
| 6105 |
-
|
| 6106 |
-
if ( $table_info ) {
|
| 6107 |
-
$transient .= '_tableinfo';
|
| 6108 |
-
}
|
| 6109 |
-
|
| 6110 |
-
$check_pod = $params;
|
| 6111 |
-
|
| 6112 |
-
if ( is_object( $params ) && ! is_a( $params, 'WP_Post' ) && ! empty( $params->pod ) ) {
|
| 6113 |
-
$check_pod = $params->pod;
|
| 6114 |
-
} elseif ( is_array( $params ) && ! empty( $params['pod'] ) ) {
|
| 6115 |
-
$check_pod = $params['pod'];
|
| 6116 |
-
}
|
| 6117 |
-
|
| 6118 |
-
if ( is_object( $check_pod ) && ( is_a( $check_pod, 'WP_Post' ) || isset( $check_pod->post_name ) ) ) {
|
| 6119 |
-
$pod = false;
|
| 6120 |
-
|
| 6121 |
-
if ( pods_api_cache() ) {
|
| 6122 |
-
$pod = pods_transient_get( $transient . '_' . $check_pod->post_name );
|
| 6123 |
-
}
|
| 6124 |
-
|
| 6125 |
-
if ( false !== $pod && ( ! $table_info || isset( $pod['table'] ) ) ) {
|
| 6126 |
-
// @todo Is this needed anymore for WPML?
|
| 6127 |
-
if ( in_array( $pod['type'], array(
|
| 6128 |
-
'post_type',
|
| 6129 |
-
'taxonomy'
|
| 6130 |
-
) ) && did_action( 'wpml_loaded' ) && apply_filters( 'wpml_setting', true, 'auto_adjust_ids' ) ) {
|
| 6131 |
-
$pod = array_merge( $pod, $this->get_table_info( $pod['type'], $pod['object'], $pod['name'], $pod ) );
|
| 6132 |
-
}
|
| 6133 |
-
|
| 6134 |
-
return $pod;
|
| 6135 |
-
}
|
| 6136 |
-
|
| 6137 |
-
$_pod = get_object_vars( $check_pod );
|
| 6138 |
-
} else {
|
| 6139 |
-
$params = (object) pods_sanitize( $params );
|
| 6140 |
-
|
| 6141 |
-
if ( ( ! isset( $params->id ) || empty( $params->id ) ) && ( ! isset( $params->name ) || empty( $params->name ) ) ) {
|
| 6142 |
-
if ( $strict ) {
|
| 6143 |
-
return pods_error( __( 'Either Pod ID or Name are required', 'pods' ), $this );
|
| 6144 |
-
}
|
| 6145 |
-
|
| 6146 |
-
return false;
|
| 6147 |
-
}
|
| 6148 |
-
|
| 6149 |
-
if ( ! empty( $params->bypass_cache ) ) {
|
| 6150 |
-
$bypass_cache = true;
|
| 6151 |
-
}
|
| 6152 |
-
|
| 6153 |
-
if ( isset( $params->name ) ) {
|
| 6154 |
-
$pod = false;
|
| 6155 |
-
|
| 6156 |
-
if ( '_pods_pod' === $params->name ) {
|
| 6157 |
-
$pod = array(
|
| 6158 |
-
'id' => 0,
|
| 6159 |
-
'name' => $params->name,
|
| 6160 |
-
'object' => $params->name,
|
| 6161 |
-
'label' => __( 'Pods', 'pods' ),
|
| 6162 |
-
'type' => 'post_type',
|
| 6163 |
-
'storage' => 'meta',
|
| 6164 |
-
'options' => array(
|
| 6165 |
-
'label_singular' => __( 'Pod', 'pods' )
|
| 6166 |
-
),
|
| 6167 |
-
'fields' => array()
|
| 6168 |
-
);
|
| 6169 |
-
} elseif ( '_pods_field' === $params->name ) {
|
| 6170 |
-
$pod = array(
|
| 6171 |
-
'id' => 0,
|
| 6172 |
-
'name' => $params->name,
|
| 6173 |
-
'object' => $params->name,
|
| 6174 |
-
'label' => __( 'Pod Fields', 'pods' ),
|
| 6175 |
-
'type' => 'post_type',
|
| 6176 |
-
'storage' => 'meta',
|
| 6177 |
-
'options' => array(
|
| 6178 |
-
'label_singular' => __( 'Pod Field', 'pods' )
|
| 6179 |
-
),
|
| 6180 |
-
'fields' => array()
|
| 6181 |
-
);
|
| 6182 |
-
} elseif ( ! $bypass_cache & pods_api_cache() ) {
|
| 6183 |
-
$pod = pods_transient_get( $transient . '_' . $params->name );
|
| 6184 |
-
}
|
| 6185 |
-
|
| 6186 |
-
if ( false !== $pod && ( ! $table_info || isset( $pod['table'] ) ) ) {
|
| 6187 |
-
if ( in_array( $pod['type'], array(
|
| 6188 |
-
'post_type',
|
| 6189 |
-
'taxonomy'
|
| 6190 |
-
) ) && did_action( 'wpml_loaded' ) && apply_filters( 'wpml_setting', true, 'auto_adjust_ids' ) ) {
|
| 6191 |
-
$pod = array_merge( $pod, $this->get_table_info( $pod['type'], $pod['object'], $pod['name'], $pod ) );
|
| 6192 |
-
}
|
| 6193 |
-
|
| 6194 |
-
return $pod;
|
| 6195 |
-
}
|
| 6196 |
-
}
|
| 6197 |
-
|
| 6198 |
-
if ( ! isset( $params->name ) ) {
|
| 6199 |
-
$dummy = (int) $params->id;
|
| 6200 |
-
$pod = get_post( $dummy );
|
| 6201 |
-
} else {
|
| 6202 |
-
$pod = get_posts( array(
|
| 6203 |
-
'name' => $params->name,
|
| 6204 |
-
'post_type' => '_pods_pod',
|
| 6205 |
-
'posts_per_page' => 1
|
| 6206 |
-
) );
|
| 6207 |
-
}
|
| 6208 |
-
|
| 6209 |
-
if ( empty( $pod ) ) {
|
| 6210 |
-
if ( $strict ) {
|
| 6211 |
-
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
| 6212 |
-
}
|
| 6213 |
-
|
| 6214 |
-
return false;
|
| 6215 |
-
}
|
| 6216 |
-
|
| 6217 |
-
if ( is_array( $pod ) && ! empty( $pod[0] ) ) {
|
| 6218 |
-
$pod = $pod[0];
|
| 6219 |
-
}
|
| 6220 |
-
|
| 6221 |
-
$_pod = get_object_vars( $pod );
|
| 6222 |
-
}
|
| 6223 |
-
|
| 6224 |
-
$pod = false;
|
| 6225 |
-
|
| 6226 |
-
if ( ! $bypass_cache || pods_api_cache() ) {
|
| 6227 |
-
$pod = pods_transient_get( $transient . '_' . $_pod['post_name'] );
|
| 6228 |
-
}
|
| 6229 |
-
|
| 6230 |
-
if ( false !== $pod && ( ! $table_info || isset( $pod['table'] ) ) ) {
|
| 6231 |
-
if ( in_array( $pod['type'], array(
|
| 6232 |
-
'post_type',
|
| 6233 |
-
'taxonomy'
|
| 6234 |
-
) ) && did_action( 'wpml_loaded' ) && apply_filters( 'wpml_setting', true, 'auto_adjust_ids' ) ) {
|
| 6235 |
-
$pod = array_merge( $pod, $this->get_table_info( $pod['type'], $pod['object'], $pod['name'], $pod ) );
|
| 6236 |
-
}
|
| 6237 |
-
|
| 6238 |
-
return $pod;
|
| 6239 |
-
}
|
| 6240 |
-
|
| 6241 |
-
$pod = array(
|
| 6242 |
-
'id' => $_pod['ID'],
|
| 6243 |
-
'name' => $_pod['post_name'],
|
| 6244 |
-
'label' => $_pod['post_title'],
|
| 6245 |
-
'description' => $_pod['post_content']
|
| 6246 |
-
);
|
| 6247 |
-
|
| 6248 |
-
if ( strlen( $pod['label'] ) < 1 ) {
|
| 6249 |
-
$pod['label'] = $pod['name'];
|
| 6250 |
-
}
|
| 6251 |
-
|
| 6252 |
-
// @todo update with a method to put all options in
|
| 6253 |
-
$defaults = array(
|
| 6254 |
-
'show_in_menu' => 1,
|
| 6255 |
-
'type' => 'post_type',
|
| 6256 |
-
'storage' => 'meta',
|
| 6257 |
-
'object' => '',
|
| 6258 |
-
'alias' => ''
|
| 6259 |
-
);
|
| 6260 |
-
|
| 6261 |
-
if ( $bypass_cache ) {
|
| 6262 |
-
wp_cache_delete( $pod['id'], 'post_meta' );
|
| 6263 |
-
|
| 6264 |
-
update_postmeta_cache( array( $pod['id'] ) );
|
| 6265 |
-
}
|
| 6266 |
-
|
| 6267 |
-
$pod['options'] = get_post_meta( $pod['id'] );
|
| 6268 |
-
|
| 6269 |
-
foreach ( $pod['options'] as $option => $value ) {
|
| 6270 |
-
if ( is_array( $value ) ) {
|
| 6271 |
-
foreach ( $value as $k => $v ) {
|
| 6272 |
-
if ( ! is_array( $v ) ) {
|
| 6273 |
-
$value[ $k ] = maybe_unserialize( $v );
|
| 6274 |
-
}
|
| 6275 |
-
}
|
| 6276 |
-
|
| 6277 |
-
if ( 1 == count( $value ) ) {
|
| 6278 |
-
$value = current( $value );
|
| 6279 |
-
}
|
| 6280 |
-
} else {
|
| 6281 |
-
$value = maybe_unserialize( $value );
|
| 6282 |
-
}
|
| 6283 |
-
|
| 6284 |
-
$pod['options'][ $option ] = $value;
|
| 6285 |
-
}
|
| 6286 |
-
|
| 6287 |
-
$pod['options'] = array_merge( $defaults, $pod['options'] );
|
| 6288 |
-
|
| 6289 |
-
$pod['type'] = $pod['options']['type'];
|
| 6290 |
-
$pod['storage'] = $pod['options']['storage'];
|
| 6291 |
-
$pod['object'] = $pod['options']['object'];
|
| 6292 |
-
$pod['alias'] = $pod['options']['alias'];
|
| 6293 |
-
|
| 6294 |
-
unset( $pod['options']['type'] );
|
| 6295 |
-
unset( $pod['options']['storage'] );
|
| 6296 |
-
unset( $pod['options']['object'] );
|
| 6297 |
-
unset( $pod['options']['alias'] );
|
| 6298 |
-
|
| 6299 |
-
if ( $table_info ) {
|
| 6300 |
-
$pod = array_merge( $this->get_table_info( $pod['type'], $pod['object'], $pod['name'], $pod ), $pod );
|
| 6301 |
-
}
|
| 6302 |
-
|
| 6303 |
-
// Override old 'none' storage type
|
| 6304 |
-
if ( 'taxonomy' === $pod['type'] && 'none' === $pod['storage'] && function_exists( 'get_term_meta' ) ) {
|
| 6305 |
-
$pod['storage'] = 'meta';
|
| 6306 |
-
}
|
| 6307 |
-
|
| 6308 |
-
if ( isset( $pod['pod'] ) ) {
|
| 6309 |
-
unset( $pod['pod'] );
|
| 6310 |
-
}
|
| 6311 |
-
|
| 6312 |
-
$pod['fields'] = array();
|
| 6313 |
-
|
| 6314 |
-
$pod['object_fields'] = array();
|
| 6315 |
-
|
| 6316 |
-
if ( 'pod' !== $pod['type'] ) {
|
| 6317 |
-
$pod['object_fields'] = $this->get_wp_object_fields( $pod['type'], $pod );
|
| 6318 |
-
}
|
| 6319 |
-
|
| 6320 |
-
$fields = get_posts( array(
|
| 6321 |
-
'post_type' => '_pods_field',
|
| 6322 |
-
'posts_per_page' => - 1,
|
| 6323 |
-
'nopaging' => true,
|
| 6324 |
-
'post_parent' => $pod['id'],
|
| 6325 |
-
'orderby' => 'menu_order',
|
| 6326 |
-
'order' => 'ASC'
|
| 6327 |
-
) );
|
| 6328 |
-
|
| 6329 |
-
if ( ! empty( $fields ) ) {
|
| 6330 |
-
foreach ( $fields as $field ) {
|
| 6331 |
-
$field->pod = $pod['name'];
|
| 6332 |
-
$field->table_info = $table_info;
|
| 6333 |
-
$field->bypass_cache = $bypass_cache;
|
| 6334 |
-
|
| 6335 |
-
if ( $load_fields ) {
|
| 6336 |
-
$field = $this->load_field( $field );
|
| 6337 |
-
|
| 6338 |
-
$field = PodsForm::field_setup( $field, null, $field['type'] );
|
| 6339 |
-
} else {
|
| 6340 |
-
if ( $bypass_cache ) {
|
| 6341 |
-
wp_cache_delete( $field->ID, 'post_meta' );
|
| 6342 |
-
|
| 6343 |
-
update_postmeta_cache( array( $field->ID ) );
|
| 6344 |
-
}
|
| 6345 |
-
|
| 6346 |
-
$field = array(
|
| 6347 |
-
'id' => $field->ID,
|
| 6348 |
-
'name' => $field->post_name,
|
| 6349 |
-
'label' => $field->post_title,
|
| 6350 |
-
'type' => get_post_meta( $field->ID, 'type', true )
|
| 6351 |
-
);
|
| 6352 |
-
}
|
| 6353 |
-
|
| 6354 |
-
$pod['fields'][ $field['name'] ] = $field;
|
| 6355 |
-
}
|
| 6356 |
-
}
|
| 6357 |
-
|
| 6358 |
-
if ( did_action( 'init' ) && pods_api_cache() ) {
|
| 6359 |
-
pods_transient_set( $transient . '_' . $pod['name'], $pod );
|
| 6360 |
-
}
|
| 6361 |
-
|
| 6362 |
-
return $pod;
|
| 6363 |
-
}
|
| 6364 |
-
|
| 6365 |
-
/**
|
| 6366 |
-
* Load a list of Pods based on filters specified.
|
| 6367 |
-
*
|
| 6368 |
-
* $params['type'] string/array Pod Type(s) to filter by
|
| 6369 |
-
* $params['object'] string/array Pod Object(s) to filter by
|
| 6370 |
-
* $params['options'] array Pod Option(s) key=>value array to filter by
|
| 6371 |
-
* $params['orderby'] string ORDER BY clause of query
|
| 6372 |
-
* $params['limit'] string Number of Pods to return
|
| 6373 |
-
* $params['where'] string WHERE clause of query
|
| 6374 |
-
* $params['ids'] string|array IDs of Objects
|
| 6375 |
-
* $params['count'] boolean Return only a count of Pods
|
| 6376 |
-
* $params['names'] boolean Return only an array of name => label
|
| 6377 |
-
* $params['ids'] boolean Return only an array of ID => label
|
| 6378 |
-
* $params['fields'] boolean Return pod fields with Pods (default is true)
|
| 6379 |
-
* $params['key_names'] boolean Return pods keyed by name
|
| 6380 |
-
* $params['bypass_cache'] boolean Bypass the cache when getting data
|
| 6381 |
-
*
|
| 6382 |
-
* @param array $params An associative array of parameters
|
| 6383 |
-
*
|
| 6384 |
-
* @return array|mixed
|
| 6385 |
-
*
|
| 6386 |
-
* @uses PodsAPI::load_pod
|
| 6387 |
-
*
|
| 6388 |
-
* @since 2.0.0
|
| 6389 |
-
*/
|
| 6390 |
-
public function load_pods( $params = null ) {
|
| 6391 |
-
|
| 6392 |
-
$current_language = false;
|
| 6393 |
-
|
| 6394 |
-
// Get current language data
|
| 6395 |
-
$lang_data = pods_i18n()->get_current_language_data();
|
| 6396 |
-
|
| 6397 |
-
if ( $lang_data ) {
|
| 6398 |
-
if ( ! empty( $lang_data['language'] ) ) {
|
| 6399 |
-
$current_language = $lang_data['language'];
|
| 6400 |
-
}
|
| 6401 |
-
}
|
| 6402 |
-
|
| 6403 |
-
$params = (object) pods_sanitize( $params );
|
| 6404 |
-
|
| 6405 |
-
$order = 'ASC';
|
| 6406 |
-
$orderby = 'menu_order title';
|
| 6407 |
-
$limit = - 1;
|
| 6408 |
-
$ids = false;
|
| 6409 |
-
|
| 6410 |
-
$meta_query = array();
|
| 6411 |
-
$cache_key = '';
|
| 6412 |
-
|
| 6413 |
-
$bypass_cache = false;
|
| 6414 |
-
|
| 6415 |
-
if ( ! empty( $params->bypass_cache ) ) {
|
| 6416 |
-
$bypass_cache = true;
|
| 6417 |
-
}
|
| 6418 |
-
|
| 6419 |
-
if ( isset( $params->type ) && ! empty( $params->type ) ) {
|
| 6420 |
-
if ( ! is_array( $params->type ) ) {
|
| 6421 |
-
$params->type = array( trim( $params->type ) );
|
| 6422 |
-
}
|
| 6423 |
-
|
| 6424 |
-
sort( $params->type );
|
| 6425 |
-
|
| 6426 |
-
$meta_query[] = array(
|
| 6427 |
-
'key' => 'type',
|
| 6428 |
-
'value' => $params->type,
|
| 6429 |
-
'compare' => 'IN'
|
| 6430 |
-
);
|
| 6431 |
-
|
| 6432 |
-
if ( 0 < count( $params->type ) ) {
|
| 6433 |
-
$cache_key .= '_type_' . trim( implode( '_', $params->type ) );
|
| 6434 |
-
}
|
| 6435 |
-
}
|
| 6436 |
-
|
| 6437 |
-
if ( isset( $params->object ) && ! empty( $params->object ) ) {
|
| 6438 |
-
if ( ! is_array( $params->object ) ) {
|
| 6439 |
-
$params->object = array( $params->object );
|
| 6440 |
-
}
|
| 6441 |
-
|
| 6442 |
-
$params->object = pods_trim( $params->object );
|
| 6443 |
-
|
| 6444 |
-
sort( $params->object );
|
| 6445 |
-
|
| 6446 |
-
$meta_query[] = array(
|
| 6447 |
-
'key' => 'object',
|
| 6448 |
-
'value' => $params->object,
|
| 6449 |
-
'compare' => 'IN'
|
| 6450 |
-
);
|
| 6451 |
-
|
| 6452 |
-
if ( 1 == count( $params->object ) ) {
|
| 6453 |
-
$cache_key .= '_object_' . trim( implode( '', $params->object ) );
|
| 6454 |
-
}
|
| 6455 |
-
}
|
| 6456 |
-
|
| 6457 |
-
if ( isset( $params->options ) && ! empty( $params->options ) && is_array( $params->options ) ) {
|
| 6458 |
-
foreach ( $params->options as $option => $value ) {
|
| 6459 |
-
if ( ! is_array( $value ) ) {
|
| 6460 |
-
$value = array( $value );
|
| 6461 |
-
}
|
| 6462 |
-
|
| 6463 |
-
$value = pods_trim( $value );
|
| 6464 |
-
|
| 6465 |
-
sort( $value );
|
| 6466 |
-
|
| 6467 |
-
$meta_query[] = array(
|
| 6468 |
-
'key' => $option,
|
| 6469 |
-
'value' => pods_sanitize( $value ),
|
| 6470 |
-
'compare' => 'IN'
|
| 6471 |
-
);
|
| 6472 |
-
}
|
| 6473 |
-
|
| 6474 |
-
$cache_key = '';
|
| 6475 |
-
}
|
| 6476 |
-
|
| 6477 |
-
if ( isset( $params->where ) && is_array( $params->where ) ) {
|
| 6478 |
-
$meta_query = array_merge( $meta_query, (array) $params->where );
|
| 6479 |
-
}
|
| 6480 |
-
|
| 6481 |
-
if ( isset( $params->order ) && ! empty( $params->order ) && in_array( strtoupper( $params->order ), array(
|
| 6482 |
-
'ASC',
|
| 6483 |
-
'DESC'
|
| 6484 |
-
) ) ) {
|
| 6485 |
-
$order = strtoupper( $params->order );
|
| 6486 |
-
}
|
| 6487 |
-
|
| 6488 |
-
if ( isset( $params->orderby ) && ! empty( $params->orderby ) ) {
|
| 6489 |
-
$orderby = strtoupper( $params->orderby );
|
| 6490 |
-
}
|
| 6491 |
-
|
| 6492 |
-
if ( isset( $params->limit ) && ! empty( $params->limit ) ) {
|
| 6493 |
-
$limit = pods_absint( $params->limit );
|
| 6494 |
-
}
|
| 6495 |
-
|
| 6496 |
-
if ( isset( $params->ids ) && ! empty( $params->ids ) ) {
|
| 6497 |
-
$ids = $params->ids;
|
| 6498 |
-
|
| 6499 |
-
if ( ! is_array( $ids ) ) {
|
| 6500 |
-
$ids = explode( ',', $ids );
|
| 6501 |
-
}
|
| 6502 |
-
}
|
| 6503 |
-
|
| 6504 |
-
if ( empty( $ids ) ) {
|
| 6505 |
-
$ids = false;
|
| 6506 |
-
}
|
| 6507 |
-
|
| 6508 |
-
$pre_key = '';
|
| 6509 |
-
|
| 6510 |
-
if ( ! empty( $current_language ) ) {
|
| 6511 |
-
$pre_key .= '_' . $current_language;
|
| 6512 |
-
}
|
| 6513 |
-
|
| 6514 |
-
if ( isset( $params->count ) && $params->count ) {
|
| 6515 |
-
$pre_key .= '_count';
|
| 6516 |
-
}
|
| 6517 |
-
|
| 6518 |
-
if ( isset( $params->ids ) && $params->ids && ! empty( $ids ) ) {
|
| 6519 |
-
$pre_key .= '_ids_' . implode( '_', $ids );
|
| 6520 |
-
}
|
| 6521 |
-
|
| 6522 |
-
if ( isset( $params->names ) && $params->names ) {
|
| 6523 |
-
$pre_key .= '_names';
|
| 6524 |
-
} elseif ( isset( $params->names_ids ) && $params->names_ids ) {
|
| 6525 |
-
$pre_key .= '_names_ids';
|
| 6526 |
-
}
|
| 6527 |
-
|
| 6528 |
-
if ( isset( $params->key_names ) && $params->key_names ) {
|
| 6529 |
-
$pre_key .= '_namekeys';
|
| 6530 |
-
}
|
| 6531 |
-
|
| 6532 |
-
if ( isset( $params->fields ) && ! $params->fields ) {
|
| 6533 |
-
$pre_key .= '_nofields';
|
| 6534 |
-
}
|
| 6535 |
-
|
| 6536 |
-
if ( isset( $params->table_info ) && $params->table_info ) {
|
| 6537 |
-
$pre_key .= '_tableinfo';
|
| 6538 |
-
}
|
| 6539 |
-
|
| 6540 |
-
$pre_key .= '_get';
|
| 6541 |
-
|
| 6542 |
-
if ( empty( $cache_key ) ) {
|
| 6543 |
-
$cache_key = 'pods' . $pre_key . '_all';
|
| 6544 |
-
} else {
|
| 6545 |
-
$cache_key = 'pods' . $pre_key . $cache_key;
|
| 6546 |
-
}
|
| 6547 |
-
|
| 6548 |
-
if ( ! $bypass_cache && pods_api_cache() && ! empty( $cache_key ) && ( 'pods' . ( ! empty( $current_language ) ? '_' . $current_language : '' ) . '_get_all' !== $cache_key || empty( $meta_query ) ) && $limit < 1 && ( empty( $orderby ) || 'menu_order title' === $orderby ) && empty( $ids ) ) {
|
| 6549 |
-
$the_pods = pods_transient_get( $cache_key );
|
| 6550 |
-
|
| 6551 |
-
if ( false === $the_pods ) {
|
| 6552 |
-
$the_pods = pods_cache_get( $cache_key, 'pods' );
|
| 6553 |
-
}
|
| 6554 |
-
|
| 6555 |
-
if ( ! is_array( $the_pods ) && 'none' === $the_pods ) {
|
| 6556 |
-
return array();
|
| 6557 |
-
} elseif ( false !== $the_pods ) {
|
| 6558 |
-
return $the_pods;
|
| 6559 |
-
}
|
| 6560 |
-
}
|
| 6561 |
-
|
| 6562 |
-
$the_pods = array();
|
| 6563 |
-
|
| 6564 |
-
$args = array(
|
| 6565 |
-
'post_type' => '_pods_pod',
|
| 6566 |
-
'nopaging' => true,
|
| 6567 |
-
'posts_per_page' => $limit,
|
| 6568 |
-
'order' => $order,
|
| 6569 |
-
'orderby' => $orderby,
|
| 6570 |
-
'meta_query' => $meta_query,
|
| 6571 |
-
);
|
| 6572 |
-
|
| 6573 |
-
// Only set post__in if there are ids to filter (see https://core.trac.wordpress.org/ticket/28099)
|
| 6574 |
-
if ( false !== $ids ) {
|
| 6575 |
-
$args['post__in'] = $ids;
|
| 6576 |
-
}
|
| 6577 |
-
|
| 6578 |
-
$_pods = get_posts( $args );
|
| 6579 |
-
|
| 6580 |
-
$export_ignore = array(
|
| 6581 |
-
'object_type',
|
| 6582 |
-
'object_name',
|
| 6583 |
-
'table',
|
| 6584 |
-
'meta_table',
|
| 6585 |
-
'pod_table',
|
| 6586 |
-
'field_id',
|
| 6587 |
-
'field_index',
|
| 6588 |
-
'field_slug',
|
| 6589 |
-
'field_type',
|
| 6590 |
-
'field_parent',
|
| 6591 |
-
'field_parent_select',
|
| 6592 |
-
'meta_field_id',
|
| 6593 |
-
'meta_field_index',
|
| 6594 |
-
'meta_field_value',
|
| 6595 |
-
'pod_field_id',
|
| 6596 |
-
'pod_field_index',
|
| 6597 |
-
'object_fields',
|
| 6598 |
-
'join',
|
| 6599 |
-
'where',
|
| 6600 |
-
'where_default',
|
| 6601 |
-
'orderby',
|
| 6602 |
-
'pod',
|
| 6603 |
-
'recurse',
|
| 6604 |
-
'table_info',
|
| 6605 |
-
'attributes',
|
| 6606 |
-
'group',
|
| 6607 |
-
'grouped',
|
| 6608 |
-
'developer_mode',
|
| 6609 |
-
'dependency',
|
| 6610 |
-
'depends-on',
|
| 6611 |
-
'excludes-on'
|
| 6612 |
-
);
|
| 6613 |
-
|
| 6614 |
-
$total_fields = 0;
|
| 6615 |
-
|
| 6616 |
-
if ( isset( $params->count ) && $params->count ) {
|
| 6617 |
-
$the_pods = count( $_pods );
|
| 6618 |
-
} else {
|
| 6619 |
-
foreach ( $_pods as $pod ) {
|
| 6620 |
-
if ( isset( $params->names ) && $params->names ) {
|
| 6621 |
-
$the_pods[ $pod->post_name ] = $pod->post_title;
|
| 6622 |
-
} elseif ( isset( $params->names_ids ) && $params->names_ids ) {
|
| 6623 |
-
$the_pods[ $pod->ID ] = $pod->post_name;
|
| 6624 |
-
} else {
|
| 6625 |
-
if ( isset( $params->fields ) && ! $params->fields ) {
|
| 6626 |
-
$pod->fields = false;
|
| 6627 |
-
}
|
| 6628 |
-
|
| 6629 |
-
$pod = $this->load_pod( array(
|
| 6630 |
-
'pod' => $pod,
|
| 6631 |
-
'table_info' => ! empty( $params->table_info ),
|
| 6632 |
-
'bypass_cache' => $bypass_cache
|
| 6633 |
-
) );
|
| 6634 |
-
|
| 6635 |
-
// Remove extra data not needed
|
| 6636 |
-
if ( pods_var( 'export', $params, false ) && ( ! isset( $params->fields ) || $params->fields ) ) {
|
| 6637 |
-
foreach ( $export_ignore as $ignore ) {
|
| 6638 |
-
if ( isset( $pod[ $ignore ] ) ) {
|
| 6639 |
-
unset( $pod[ $ignore ] );
|
| 6640 |
-
}
|
| 6641 |
-
}
|
| 6642 |
-
|
| 6643 |
-
foreach ( $pod['fields'] as $field => $field_data ) {
|
| 6644 |
-
if ( isset( $pod['fields'][ $field ]['table_info'] ) ) {
|
| 6645 |
-
unset( $pod['fields'][ $field ]['table_info'] );
|
| 6646 |
-
}
|
| 6647 |
-
}
|
| 6648 |
-
}
|
| 6649 |
-
|
| 6650 |
-
$total_fields += count( $pod['fields'] );
|
| 6651 |
-
|
| 6652 |
-
if ( isset( $params->key_names ) && $params->key_names ) {
|
| 6653 |
-
$the_pods[ $pod['name'] ] = $pod;
|
| 6654 |
-
} else {
|
| 6655 |
-
$the_pods[ $pod['id'] ] = $pod;
|
| 6656 |
-
}
|
| 6657 |
-
}
|
| 6658 |
-
}
|
| 6659 |
-
}
|
| 6660 |
-
|
| 6661 |
-
if ( ( ! function_exists( 'pll_current_language' ) || ! empty( $params->refresh ) ) && ! empty( $cache_key ) && ( 'pods' !== $cache_key || empty( $meta_query ) ) && $limit < 1 && ( empty( $orderby ) || 'menu_order title' === $orderby ) && empty( $ids ) ) {
|
| 6662 |
-
$total_pods = (int) ( is_array( $the_pods ) ) ? count( $the_pods ) : $the_pods;
|
| 6663 |
-
// Too many Pods can cause issues with the DB when caching is not enabled
|
| 6664 |
-
if ( 15 < $total_pods || 75 < (int) $total_fields ) {
|
| 6665 |
-
pods_transient_clear( $cache_key );
|
| 6666 |
-
|
| 6667 |
-
if ( pods_api_cache() ) {
|
| 6668 |
-
if ( empty( $the_pods ) && ( ! isset( $params->count ) || ! $params->count ) ) {
|
| 6669 |
-
pods_cache_set( $cache_key, 'none', 'pods' );
|
| 6670 |
-
} else {
|
| 6671 |
-
pods_cache_set( $cache_key, $the_pods, 'pods' );
|
| 6672 |
-
}
|
| 6673 |
-
}
|
| 6674 |
-
} else {
|
| 6675 |
-
pods_cache_clear( $cache_key, 'pods' );
|
| 6676 |
-
|
| 6677 |
-
if ( pods_api_cache() ) {
|
| 6678 |
-
if ( empty( $the_pods ) && ( ! isset( $params->count ) || ! $params->count ) ) {
|
| 6679 |
-
pods_transient_set( $cache_key, 'none' );
|
| 6680 |
-
} else {
|
| 6681 |
-
pods_transient_set( $cache_key, $the_pods );
|
| 6682 |
-
}
|
| 6683 |
-
}
|
| 6684 |
-
}
|
| 6685 |
-
}
|
| 6686 |
-
|
| 6687 |
-
return $the_pods;
|
| 6688 |
-
}
|
| 6689 |
-
|
| 6690 |
-
/**
|
| 6691 |
-
* Check if a Pod's field exists
|
| 6692 |
-
*
|
| 6693 |
-
* $params['pod_id'] int The Pod ID
|
| 6694 |
-
* $params['id'] int The field ID
|
| 6695 |
-
* $params['name'] string The field name
|
| 6696 |
-
*
|
| 6697 |
-
* @param array $params An associative array of parameters
|
| 6698 |
-
*
|
| 6699 |
-
* @return bool
|
| 6700 |
-
*
|
| 6701 |
-
* @since 1.12
|
| 6702 |
-
*/
|
| 6703 |
-
public function field_exists( $params ) {
|
| 6704 |
-
|
| 6705 |
-
$params = (object) pods_sanitize( $params );
|
| 6706 |
-
|
| 6707 |
-
if ( ( ! empty( $params->id ) || ! empty( $params->name ) ) && isset( $params->pod_id ) && ! empty( $params->pod_id ) ) {
|
| 6708 |
-
if ( ! isset( $params->name ) ) {
|
| 6709 |
-
$dummy = (int) $params->id;
|
| 6710 |
-
$field = get_post( $dummy );
|
| 6711 |
-
} else {
|
| 6712 |
-
$field = get_posts( array(
|
| 6713 |
-
'name' => $params->name,
|
| 6714 |
-
'post_type' => '_pods_field',
|
| 6715 |
-
'posts_per_page' => 1,
|
| 6716 |
-
'post_parent' => $params->pod_id
|
| 6717 |
-
) );
|
| 6718 |
-
}
|
| 6719 |
-
|
| 6720 |
-
if ( ! empty( $field ) ) {
|
| 6721 |
-
return true;
|
| 6722 |
-
}
|
| 6723 |
-
}
|
| 6724 |
-
|
| 6725 |
-
return false;
|
| 6726 |
-
}
|
| 6727 |
-
|
| 6728 |
-
/**
|
| 6729 |
-
* Load a field
|
| 6730 |
-
*
|
| 6731 |
-
* $params['pod_id'] int The Pod ID
|
| 6732 |
-
* $params['pod'] string The Pod name
|
| 6733 |
-
* $params['id'] int The field ID
|
| 6734 |
-
* $params['name'] string The field name
|
| 6735 |
-
* $params['table_info'] boolean Whether to lookup a pick field's table info
|
| 6736 |
-
* $params['bypass_cache'] boolean Bypass the cache when getting data
|
| 6737 |
-
*
|
| 6738 |
-
* @param array $params An associative array of parameters
|
| 6739 |
-
* @param boolean $strict Whether to require a field exist or not when loading the info
|
| 6740 |
-
*
|
| 6741 |
-
* @return array|bool Array with field data, false if field not found
|
| 6742 |
-
* @since 1.7.9
|
| 6743 |
-
*/
|
| 6744 |
-
public function load_field( $params, $strict = false ) {
|
| 6745 |
-
|
| 6746 |
-
$params = (object) $params;
|
| 6747 |
-
|
| 6748 |
-
if ( ! isset( $params->table_info ) ) {
|
| 6749 |
-
$params->table_info = false;
|
| 6750 |
-
}
|
| 6751 |
-
|
| 6752 |
-
$bypass_cache = false;
|
| 6753 |
-
|
| 6754 |
-
if ( ! empty( $params->bypass_cache ) ) {
|
| 6755 |
-
$bypass_cache = true;
|
| 6756 |
-
}
|
| 6757 |
-
|
| 6758 |
-
$pod = array();
|
| 6759 |
-
$field = array();
|
| 6760 |
-
|
| 6761 |
-
if ( isset( $params->post_title ) ) {
|
| 6762 |
-
$_field = $params;
|
| 6763 |
-
} elseif ( isset( $params->id ) && ! empty( $params->id ) ) {
|
| 6764 |
-
$dummy = (int) $params->id;
|
| 6765 |
-
$_field = get_post( $dummy );
|
| 6766 |
-
} else {
|
| 6767 |
-
if ( ! isset( $params->pod ) ) {
|
| 6768 |
-
$params->pod = '';
|
| 6769 |
-
}
|
| 6770 |
-
|
| 6771 |
-
if ( ! isset( $params->pod_id ) ) {
|
| 6772 |
-
$params->pod_id = 0;
|
| 6773 |
-
}
|
| 6774 |
-
|
| 6775 |
-
if ( isset( $params->pod_data ) ) {
|
| 6776 |
-
$pod = $params->pod_data;
|
| 6777 |
-
} else {
|
| 6778 |
-
$pod = $this->load_pod( array(
|
| 6779 |
-
'name' => $params->pod,
|
| 6780 |
-
'id' => $params->pod_id,
|
| 6781 |
-
'table_info' => false,
|
| 6782 |
-
'bypass_cache' => $bypass_cache
|
| 6783 |
-
), false );
|
| 6784 |
-
|
| 6785 |
-
if ( false === $pod ) {
|
| 6786 |
-
if ( $strict ) {
|
| 6787 |
-
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
| 6788 |
-
}
|
| 6789 |
-
|
| 6790 |
-
return false;
|
| 6791 |
-
}
|
| 6792 |
-
}
|
| 6793 |
-
|
| 6794 |
-
$params->pod_id = $pod['id'];
|
| 6795 |
-
$params->pod = $pod['name'];
|
| 6796 |
-
|
| 6797 |
-
if ( empty( $params->name ) && empty( $params->pod ) && empty( $params->pod_id ) ) {
|
| 6798 |
-
return pods_error( __( 'Either Field Name or Field ID / Pod ID are required', 'pods' ), $this );
|
| 6799 |
-
}
|
| 6800 |
-
|
| 6801 |
-
$params->name = pods_clean_name( $params->name, true, ( 'meta' === $pod['storage'] ? false : true ) );
|
| 6802 |
-
|
| 6803 |
-
if ( isset( $pod['fields'][ $params->name ] ) && isset( $pod['fields'][ $params->name ]['id'] ) ) {
|
| 6804 |
-
return $pod['fields'][ $params->name ];
|
| 6805 |
-
}
|
| 6806 |
-
|
| 6807 |
-
$field = false;
|
| 6808 |
-
|
| 6809 |
-
if ( ! $bypass_cache && pods_api_cache() ) {
|
| 6810 |
-
$field = pods_transient_get( 'pods_field_' . $params->pod . '_' . $params->name );
|
| 6811 |
-
}
|
| 6812 |
-
|
| 6813 |
-
if ( empty( $field ) ) {
|
| 6814 |
-
$field = get_posts( array(
|
| 6815 |
-
'name' => $params->name,
|
| 6816 |
-
'post_type' => '_pods_field',
|
| 6817 |
-
'posts_per_page' => 1,
|
| 6818 |
-
'post_parent' => $params->pod_id
|
| 6819 |
-
) );
|
| 6820 |
-
|
| 6821 |
-
if ( empty( $field ) || empty( $field[0] ) ) {
|
| 6822 |
-
if ( $strict ) {
|
| 6823 |
-
return pods_error( __( 'Field not found', 'pods' ), $this );
|
| 6824 |
-
}
|
| 6825 |
-
|
| 6826 |
-
return false;
|
| 6827 |
-
}
|
| 6828 |
-
|
| 6829 |
-
$_field = $field[0];
|
| 6830 |
-
|
| 6831 |
-
$field = array();
|
| 6832 |
-
}
|
| 6833 |
-
}
|
| 6834 |
-
|
| 6835 |
-
if ( empty( $_field ) ) {
|
| 6836 |
-
if ( $strict ) {
|
| 6837 |
-
return pods_error( __( 'Field not found', 'pods' ), $this );
|
| 6838 |
-
}
|
| 6839 |
-
|
| 6840 |
-
return false;
|
| 6841 |
-
}
|
| 6842 |
-
|
| 6843 |
-
$_field = get_object_vars( $_field );
|
| 6844 |
-
|
| 6845 |
-
if ( ! isset( $pod['name'] ) && ! isset( $_field['pod'] ) ) {
|
| 6846 |
-
if ( 0 < $_field['post_parent'] ) {
|
| 6847 |
-
$pod = $this->load_pod( array( 'id' => $_field['post_parent'], 'table_info' => false ), false );
|
| 6848 |
-
}
|
| 6849 |
-
|
| 6850 |
-
if ( empty( $pod ) ) {
|
| 6851 |
-
if ( $strict ) {
|
| 6852 |
-
return pods_error( __( 'Pod for field not found', 'pods' ), $this );
|
| 6853 |
-
}
|
| 6854 |
-
|
| 6855 |
-
return false;
|
| 6856 |
-
}
|
| 6857 |
-
}
|
| 6858 |
-
|
| 6859 |
-
if ( empty( $field ) ) {
|
| 6860 |
-
if ( ! $bypass_cache && pods_api_cache() && ( isset( $pod['name'] ) || isset( $_field['pod'] ) ) ) {
|
| 6861 |
-
$field = pods_transient_get( 'pods_field_' . pods_var( 'name', $pod, pods_var( 'pod', $_field ), null, true ) . '_' . $_field['post_name'] );
|
| 6862 |
-
}
|
| 6863 |
-
|
| 6864 |
-
if ( empty( $field ) ) {
|
| 6865 |
-
$defaults = array(
|
| 6866 |
-
'type' => 'text'
|
| 6867 |
-
);
|
| 6868 |
-
|
| 6869 |
-
$field = array(
|
| 6870 |
-
'id' => $_field['ID'],
|
| 6871 |
-
'name' => $_field['post_name'],
|
| 6872 |
-
'label' => $_field['post_title'],
|
| 6873 |
-
'description' => $_field['post_content'],
|
| 6874 |
-
'weight' => $_field['menu_order'],
|
| 6875 |
-
'pod_id' => $_field['post_parent'],
|
| 6876 |
-
'pick_object' => '',
|
| 6877 |
-
'pick_val' => '',
|
| 6878 |
-
'sister_id' => '',
|
| 6879 |
-
'table_info' => array()
|
| 6880 |
-
);
|
| 6881 |
-
|
| 6882 |
-
if ( isset( $pod['name'] ) ) {
|
| 6883 |
-
$field['pod'] = $pod['name'];
|
| 6884 |
-
} elseif ( isset( $_field['pod'] ) ) {
|
| 6885 |
-
$field['pod'] = $_field['pod'];
|
| 6886 |
-
}
|
| 6887 |
-
|
| 6888 |
-
if ( $bypass_cache ) {
|
| 6889 |
-
wp_cache_delete( $field['id'], 'post_meta' );
|
| 6890 |
-
|
| 6891 |
-
update_postmeta_cache( array( $field['id'] ) );
|
| 6892 |
-
}
|
| 6893 |
-
|
| 6894 |
-
$field['options'] = get_post_meta( $field['id'] );
|
| 6895 |
-
|
| 6896 |
-
$options_ignore = array(
|
| 6897 |
-
'method',
|
| 6898 |
-
'table_info',
|
| 6899 |
-
'attributes',
|
| 6900 |
-
'group',
|
| 6901 |
-
'grouped',
|
| 6902 |
-
'developer_mode',
|
| 6903 |
-
'dependency',
|
| 6904 |
-
'depends-on',
|
| 6905 |
-
'excludes-on'
|
| 6906 |
-
);
|
| 6907 |
-
|
| 6908 |
-
foreach ( $options_ignore as $ignore ) {
|
| 6909 |
-
if ( isset( $field['options'][ $ignore ] ) ) {
|
| 6910 |
-
unset( $field['options'][ $ignore ] );
|
| 6911 |
-
}
|
| 6912 |
-
}
|
| 6913 |
-
|
| 6914 |
-
foreach ( $field['options'] as $option => $value ) {
|
| 6915 |
-
if ( is_array( $value ) ) {
|
| 6916 |
-
foreach ( $value as $k => $v ) {
|
| 6917 |
-
if ( ! is_array( $v ) ) {
|
| 6918 |
-
$value[ $k ] = maybe_unserialize( $v );
|
| 6919 |
-
}
|
| 6920 |
-
}
|
| 6921 |
-
|
| 6922 |
-
if ( 1 == count( $value ) ) {
|
| 6923 |
-
$value = current( $value );
|
| 6924 |
-
}
|
| 6925 |
-
} else {
|
| 6926 |
-
$value = maybe_unserialize( $value );
|
| 6927 |
-
}
|
| 6928 |
-
|
| 6929 |
-
$field['options'][ $option ] = $value;
|
| 6930 |
-
}
|
| 6931 |
-
|
| 6932 |
-
$field['options'] = array_merge( $defaults, $field['options'] );
|
| 6933 |
-
|
| 6934 |
-
$field['type'] = $field['options']['type'];
|
| 6935 |
-
|
| 6936 |
-
unset( $field['options']['type'] );
|
| 6937 |
-
|
| 6938 |
-
if ( isset( $field['options']['pick_object'] ) ) {
|
| 6939 |
-
$field['pick_object'] = $field['options']['pick_object'];
|
| 6940 |
-
|
| 6941 |
-
unset( $field['options']['pick_object'] );
|
| 6942 |
-
}
|
| 6943 |
-
|
| 6944 |
-
if ( isset( $field['options']['pick_val'] ) ) {
|
| 6945 |
-
$field['pick_val'] = $field['options']['pick_val'];
|
| 6946 |
-
|
| 6947 |
-
unset( $field['options']['pick_val'] );
|
| 6948 |
-
}
|
| 6949 |
-
|
| 6950 |
-
if ( isset( $field['options']['sister_id'] ) ) {
|
| 6951 |
-
$field['sister_id'] = $field['options']['sister_id'];
|
| 6952 |
-
|
| 6953 |
-
unset( $field['options']['sister_id'] );
|
| 6954 |
-
}
|
| 6955 |
-
|
| 6956 |
-
if ( isset( $field['options']['sister_field_id'] ) ) {
|
| 6957 |
-
unset( $field['options']['sister_field_id'] );
|
| 6958 |
-
}
|
| 6959 |
-
|
| 6960 |
-
if ( pods_api_cache() && ( isset( $pod['name'] ) || isset( $_field['pod'] ) ) ) {
|
| 6961 |
-
pods_transient_set( 'pods_field_' . pods_var( 'name', $pod, pods_var( 'pod', $_field ), null, true ) . '_' . $field['name'], $field );
|
| 6962 |
-
}
|
| 6963 |
-
}
|
| 6964 |
-
}
|
| 6965 |
-
|
| 6966 |
-
$field['table_info'] = array();
|
| 6967 |
-
|
| 6968 |
-
if ( 'pick' === $field['type'] && $params->table_info ) {
|
| 6969 |
-
$field['table_info'] = $this->get_table_info( $field['pick_object'], $field['pick_val'], null, null, $field );
|
| 6970 |
-
}
|
| 6971 |
-
|
| 6972 |
-
return $field;
|
| 6973 |
-
}
|
| 6974 |
-
|
| 6975 |
-
/**
|
| 6976 |
-
* Load fields by Pod, ID, Name, and/or Type
|
| 6977 |
-
*
|
| 6978 |
-
* $params['pod_id'] int The Pod ID
|
| 6979 |
-
* $params['pod'] string The Pod name
|
| 6980 |
-
* $params['id'] array The field IDs
|
| 6981 |
-
* $params['name'] array The field names
|
| 6982 |
-
* $params['type'] array The field types
|
| 6983 |
-
* $params['options'] array Field Option(s) key=>value array to filter by
|
| 6984 |
-
* $params['where'] string WHERE clause of query
|
| 6985 |
-
* $params['object_fields'] bool Whether to include the object fields for WP objects, default true
|
| 6986 |
-
*
|
| 6987 |
-
* @param array $params An associative array of parameters
|
| 6988 |
-
* @param bool $strict Whether to require a field exist or not when loading the info
|
| 6989 |
-
*
|
| 6990 |
-
* @return array Array of field data.
|
| 6991 |
-
*
|
| 6992 |
-
* @since 1.7.9
|
| 6993 |
-
*/
|
| 6994 |
-
public function load_fields( $params, $strict = false ) {
|
| 6995 |
-
|
| 6996 |
-
// @todo Get away from using md5/serialize, I'm sure we can cache specific parts
|
| 6997 |
-
$cache_key = md5( serialize( $params ) );
|
| 6998 |
-
if ( isset( $this->fields_cache[ $cache_key ] ) ) {
|
| 6999 |
-
return $this->fields_cache[ $cache_key ];
|
| 7000 |
-
}
|
| 7001 |
-
|
| 7002 |
-
$params = (object) pods_sanitize( $params );
|
| 7003 |
-
|
| 7004 |
-
if ( ! isset( $params->pod ) || empty( $params->pod ) ) {
|
| 7005 |
-
$params->pod = '';
|
| 7006 |
-
}
|
| 7007 |
-
|
| 7008 |
-
if ( ! isset( $params->pod_id ) || empty( $params->pod_id ) ) {
|
| 7009 |
-
$params->pod_id = 0;
|
| 7010 |
-
}
|
| 7011 |
-
|
| 7012 |
-
if ( ! isset( $params->name ) || empty( $params->name ) ) {
|
| 7013 |
-
$params->name = array();
|
| 7014 |
-
} else {
|
| 7015 |
-
$params->name = (array) $params->name;
|
| 7016 |
-
}
|
| 7017 |
-
|
| 7018 |
-
if ( ! isset( $params->id ) || empty( $params->id ) ) {
|
| 7019 |
-
$params->id = array();
|
| 7020 |
-
} else {
|
| 7021 |
-
$params->id = (array) $params->id;
|
| 7022 |
-
|
| 7023 |
-
foreach ( $params->id as &$id ) {
|
| 7024 |
-
$id = pods_absint( $id );
|
| 7025 |
-
}
|
| 7026 |
-
}
|
| 7027 |
-
|
| 7028 |
-
if ( ! isset( $params->type ) || empty( $params->type ) ) {
|
| 7029 |
-
$params->type = array();
|
| 7030 |
-
} else {
|
| 7031 |
-
$params->type = (array) $params->type;
|
| 7032 |
-
}
|
| 7033 |
-
|
| 7034 |
-
if ( ! isset( $params->object_fields ) ) {
|
| 7035 |
-
$params->object_fields = true;
|
| 7036 |
-
} else {
|
| 7037 |
-
$params->object_fields = (boolean) $params->object_fields;
|
| 7038 |
-
}
|
| 7039 |
-
|
| 7040 |
-
$fields = array();
|
| 7041 |
-
|
| 7042 |
-
if ( ! empty( $params->pod ) || ! empty( $params->pod_id ) ) {
|
| 7043 |
-
$pod = $this->load_pod( array(
|
| 7044 |
-
'name' => $params->pod,
|
| 7045 |
-
'id' => $params->pod_id,
|
| 7046 |
-
'table_info' => true
|
| 7047 |
-
), false );
|
| 7048 |
-
|
| 7049 |
-
if ( false === $pod ) {
|
| 7050 |
-
if ( $strict ) {
|
| 7051 |
-
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
| 7052 |
-
}
|
| 7053 |
-
|
| 7054 |
-
return $fields;
|
| 7055 |
-
}
|
| 7056 |
-
|
| 7057 |
-
if ( $params->object_fields && ! empty( $pod['object_fields'] ) ) {
|
| 7058 |
-
$pod['fields'] = array_merge( $pod['object_fields'], $pod['fields'] );
|
| 7059 |
-
}
|
| 7060 |
-
|
| 7061 |
-
foreach ( $pod['fields'] as $field ) {
|
| 7062 |
-
if ( empty( $params->name ) && empty( $params->id ) && empty( $params->type ) ) {
|
| 7063 |
-
$fields[ $field['name'] ] = $field;
|
| 7064 |
-
} elseif ( in_array( $fields['name'], $params->name ) || in_array( $fields['id'], $params->id ) || in_array( $fields['type'], $params->type ) ) {
|
| 7065 |
-
$fields[ $field['name'] ] = $field;
|
| 7066 |
-
}
|
| 7067 |
-
}
|
| 7068 |
-
} elseif ( ( isset( $params->options ) && ! empty( $params->options ) && is_array( $params->options ) ) || ( isset( $params->where ) && ! empty( $params->where ) && is_array( $params->where ) ) ) {
|
| 7069 |
-
$order = 'ASC';
|
| 7070 |
-
$orderby = 'menu_order title';
|
| 7071 |
-
$limit = - 1;
|
| 7072 |
-
$ids = false;
|
| 7073 |
-
|
| 7074 |
-
$meta_query = array();
|
| 7075 |
-
|
| 7076 |
-
if ( isset( $params->options ) && ! empty( $params->options ) && is_array( $params->options ) ) {
|
| 7077 |
-
foreach ( $params->options as $option => $value ) {
|
| 7078 |
-
if ( ! is_array( $value ) ) {
|
| 7079 |
-
$value = array( $value );
|
| 7080 |
-
}
|
| 7081 |
-
|
| 7082 |
-
$value = pods_trim( $value );
|
| 7083 |
-
|
| 7084 |
-
sort( $value );
|
| 7085 |
-
|
| 7086 |
-
$meta_query[] = array(
|
| 7087 |
-
'key' => $option,
|
| 7088 |
-
'value' => pods_sanitize( $value ),
|
| 7089 |
-
'compare' => 'IN'
|
| 7090 |
-
);
|
| 7091 |
-
}
|
| 7092 |
-
}
|
| 7093 |
-
|
| 7094 |
-
if ( isset( $params->where ) && ! empty( $params->where ) && is_array( $params->where ) ) {
|
| 7095 |
-
$meta_query = array_merge( $meta_query, (array) $params->where );
|
| 7096 |
-
}
|
| 7097 |
-
|
| 7098 |
-
$args = array(
|
| 7099 |
-
'post_type' => '_pods_field',
|
| 7100 |
-
'nopaging' => true,
|
| 7101 |
-
'posts_per_page' => $limit,
|
| 7102 |
-
'order' => $order,
|
| 7103 |
-
'orderby' => $orderby,
|
| 7104 |
-
'meta_query' => $meta_query,
|
| 7105 |
-
);
|
| 7106 |
-
|
| 7107 |
-
// Only set post__in if there are ids to filter (see https://core.trac.wordpress.org/ticket/28099)
|
| 7108 |
-
if ( false !== $ids ) {
|
| 7109 |
-
$args['post__in'] = $ids;
|
| 7110 |
-
}
|
| 7111 |
-
|
| 7112 |
-
$fields = array();
|
| 7113 |
-
|
| 7114 |
-
$_fields = get_posts( $args );
|
| 7115 |
-
|
| 7116 |
-
foreach ( $_fields as $field ) {
|
| 7117 |
-
$field = $this->load_field( $field, false );
|
| 7118 |
-
|
| 7119 |
-
if ( ! empty( $field ) ) {
|
| 7120 |
-
$fields[ $field['id'] ] = $field;
|
| 7121 |
-
}
|
| 7122 |
-
}
|
| 7123 |
-
} else {
|
| 7124 |
-
if ( empty( $params->name ) && empty( $params->id ) && empty( $params->type ) ) {
|
| 7125 |
-
return pods_error( __( 'Either Field Name / Field ID / Field Type, or Pod Name / Pod ID are required', 'pods' ), $this );
|
| 7126 |
-
}
|
| 7127 |
-
|
| 7128 |
-
$lookup = array();
|
| 7129 |
-
|
| 7130 |
-
if ( ! empty( $params->name ) ) {
|
| 7131 |
-
$fields = implode( "', '", $params->name );
|
| 7132 |
-
|
| 7133 |
-
$lookup[] = "`post_name` IN ( '{$fields}' )";
|
| 7134 |
-
}
|
| 7135 |
-
|
| 7136 |
-
if ( ! empty( $params->id ) ) {
|
| 7137 |
-
$fields = implode( ", ", $params->id );
|
| 7138 |
-
|
| 7139 |
-
$lookup[] = "`ID` IN ( {$fields} )";
|
| 7140 |
-
}
|
| 7141 |
-
|
| 7142 |
-
$lookup = implode( ' AND ', $lookup );
|
| 7143 |
-
|
| 7144 |
-
$result = pods_query( "SELECT `ID`, `post_name`, `post_parent` FROM `@wp_posts` WHERE `post_type` = '_pods_field' AND ( {$lookup} )" );
|
| 7145 |
-
|
| 7146 |
-
$fields = array();
|
| 7147 |
-
|
| 7148 |
-
if ( ! empty( $result ) ) {
|
| 7149 |
-
foreach ( $result as $field ) {
|
| 7150 |
-
$field = $this->load_field( array(
|
| 7151 |
-
'id' => $field->ID,
|
| 7152 |
-
'name' => $field->post_name,
|
| 7153 |
-
'pod_id' => $field->post_parent
|
| 7154 |
-
), false );
|
| 7155 |
-
|
| 7156 |
-
if ( ! empty( $field ) && ( empty( $params->type ) || in_array( $field['type'], $params->type ) ) ) {
|
| 7157 |
-
$fields[ $field['id'] ] = $field;
|
| 7158 |
-
}
|
| 7159 |
-
}
|
| 7160 |
-
}
|
| 7161 |
-
}
|
| 7162 |
-
if ( isset( $cache_key ) ) {
|
| 7163 |
-
$this->fields_cache[ $cache_key ] = $fields;
|
| 7164 |
-
}
|
| 7165 |
-
|
| 7166 |
-
return $fields;
|
| 7167 |
-
}
|
| 7168 |
-
|
| 7169 |
-
/**
|
| 7170 |
-
* Load a Pods Object
|
| 7171 |
-
*
|
| 7172 |
-
* $params['id'] int The Object ID
|
| 7173 |
-
* $params['name'] string The Object name
|
| 7174 |
-
* $params['type'] string The Object type
|
| 7175 |
-
*
|
| 7176 |
-
* @param array|object $params An associative array of parameters
|
| 7177 |
-
* @param bool $strict
|
| 7178 |
-
*
|
| 7179 |
-
* @return array|bool
|
| 7180 |
-
* @since 2.0.0
|
| 7181 |
-
*/
|
| 7182 |
-
public function load_object( $params, $strict = false ) {
|
| 7183 |
-
|
| 7184 |
-
if ( is_object( $params ) && isset( $params->post_title ) ) {
|
| 7185 |
-
$_object = get_object_vars( $params );
|
| 7186 |
-
} else {
|
| 7187 |
-
$params = (object) pods_sanitize( $params );
|
| 7188 |
-
|
| 7189 |
-
if ( ! isset( $params->type ) || empty( $params->type ) ) {
|
| 7190 |
-
return pods_error( __( 'Object type is required', 'pods' ), $this );
|
| 7191 |
-
}
|
| 7192 |
-
|
| 7193 |
-
if ( ( ! isset( $params->id ) || empty( $params->id ) ) && ( ! isset( $params->name ) || empty( $params->name ) ) ) {
|
| 7194 |
-
return pods_error( __( 'Either Object ID or Name are required', 'pods' ), $this );
|
| 7195 |
-
}
|
| 7196 |
-
|
| 7197 |
-
/**
|
| 7198 |
-
* @var $wpdb wpdb
|
| 7199 |
-
*/
|
| 7200 |
-
global $wpdb;
|
| 7201 |
-
|
| 7202 |
-
if ( isset( $params->name ) ) {
|
| 7203 |
-
$_object = pods_by_title( $params->name, ARRAY_A, '_pods_' . $params->type, 'publish' );
|
| 7204 |
-
} else {
|
| 7205 |
-
$object = $params->id;
|
| 7206 |
-
|
| 7207 |
-
$_object = get_post( $object, ARRAY_A );
|
| 7208 |
-
}
|
| 7209 |
-
|
| 7210 |
-
if ( empty( $_object ) ) {
|
| 7211 |
-
if ( $strict ) {
|
| 7212 |
-
return pods_error( __( 'Object not found', 'pods' ), $this );
|
| 7213 |
-
}
|
| 7214 |
-
|
| 7215 |
-
return false;
|
| 7216 |
-
}
|
| 7217 |
-
}
|
| 7218 |
-
|
| 7219 |
-
$object = array(
|
| 7220 |
-
'id' => $_object['ID'],
|
| 7221 |
-
'name' => $_object['post_title'],
|
| 7222 |
-
'code' => $_object['post_content'],
|
| 7223 |
-
'type' => str_replace( '_pods_', '', $_object['post_type'] ),
|
| 7224 |
-
'slug' => $_object['post_name']
|
| 7225 |
-
);
|
| 7226 |
-
|
| 7227 |
-
$object['options'] = get_post_meta( $object['id'] );
|
| 7228 |
-
|
| 7229 |
-
foreach ( $object['options'] as $option => &$value ) {
|
| 7230 |
-
if ( is_array( $value ) && 1 == count( $value ) ) {
|
| 7231 |
-
$value = current( $value );
|
| 7232 |
-
}
|
| 7233 |
-
}
|
| 7234 |
-
|
| 7235 |
-
return $object;
|
| 7236 |
-
}
|
| 7237 |
-
|
| 7238 |
-
/**
|
| 7239 |
-
* Load Multiple Pods Objects
|
| 7240 |
-
*
|
| 7241 |
-
* $params['type'] string The Object type
|
| 7242 |
-
* $params['options'] array Pod Option(s) key=>value array to filter by
|
| 7243 |
-
* $params['orderby'] string ORDER BY clause of query
|
| 7244 |
-
* $params['limit'] string Number of objects to return
|
| 7245 |
-
* $params['where'] string WHERE clause of query
|
| 7246 |
-
* $params['ids'] string|array IDs of Objects
|
| 7247 |
-
*
|
| 7248 |
-
* @param array|object $params An associative array of parameters
|
| 7249 |
-
*
|
| 7250 |
-
* @return array
|
| 7251 |
-
* @since 2.0.0
|
| 7252 |
-
*/
|
| 7253 |
-
public function load_objects( $params ) {
|
| 7254 |
-
|
| 7255 |
-
$params = (object) pods_sanitize( $params );
|
| 7256 |
-
|
| 7257 |
-
if ( ! isset( $params->type ) || empty( $params->type ) ) {
|
| 7258 |
-
return pods_error( __( 'Pods Object type is required', 'pods' ), $this );
|
| 7259 |
-
}
|
| 7260 |
-
|
| 7261 |
-
$order = 'ASC';
|
| 7262 |
-
$orderby = 'menu_order';
|
| 7263 |
-
$limit = - 1;
|
| 7264 |
-
$ids = false;
|
| 7265 |
-
|
| 7266 |
-
$meta_query = array();
|
| 7267 |
-
$cache_key = '';
|
| 7268 |
-
|
| 7269 |
-
if ( isset( $params->options ) && ! empty( $params->options ) && is_array( $params->options ) ) {
|
| 7270 |
-
foreach ( $params->options as $option => $value ) {
|
| 7271 |
-
if ( ! is_array( $value ) ) {
|
| 7272 |
-
$value = array( $value );
|
| 7273 |
-
}
|
| 7274 |
-
|
| 7275 |
-
$value = pods_trim( $value );
|
| 7276 |
-
|
| 7277 |
-
sort( $value );
|
| 7278 |
-
|
| 7279 |
-
$meta_query[] = array(
|
| 7280 |
-
'key' => $option,
|
| 7281 |
-
'value' => pods_sanitize( $value ),
|
| 7282 |
-
'compare' => 'IN'
|
| 7283 |
-
);
|
| 7284 |
-
}
|
| 7285 |
-
}
|
| 7286 |
-
|
| 7287 |
-
if ( isset( $params->where ) && is_array( $params->where ) ) {
|
| 7288 |
-
$meta_query = array_merge( $meta_query, (array) $params->where );
|
| 7289 |
-
}
|
| 7290 |
-
|
| 7291 |
-
if ( isset( $params->order ) && ! empty( $params->order ) && in_array( strtoupper( $params->order ), array(
|
| 7292 |
-
'ASC',
|
| 7293 |
-
'DESC'
|
| 7294 |
-
) ) ) {
|
| 7295 |
-
$order = strtoupper( $params->order );
|
| 7296 |
-
}
|
| 7297 |
-
|
| 7298 |
-
if ( isset( $params->orderby ) && ! empty( $params->orderby ) ) {
|
| 7299 |
-
$orderby = strtoupper( $params->orderby );
|
| 7300 |
-
}
|
| 7301 |
-
|
| 7302 |
-
if ( isset( $params->limit ) && ! empty( $params->limit ) ) {
|
| 7303 |
-
$limit = pods_absint( $params->limit );
|
| 7304 |
-
}
|
| 7305 |
-
|
| 7306 |
-
if ( isset( $params->ids ) && ! empty( $params->ids ) ) {
|
| 7307 |
-
$ids = $params->ids;
|
| 7308 |
-
|
| 7309 |
-
if ( ! is_array( $ids ) ) {
|
| 7310 |
-
$ids = explode( ',', $ids );
|
| 7311 |
-
}
|
| 7312 |
-
}
|
| 7313 |
-
|
| 7314 |
-
if ( empty( $ids ) ) {
|
| 7315 |
-
$ids = false;
|
| 7316 |
-
}
|
| 7317 |
-
|
| 7318 |
-
if ( pods_api_cache() && empty( $meta_query ) && empty( $limit ) && ( empty( $orderby ) || 'menu_order' === $orderby ) && empty( $ids ) ) {
|
| 7319 |
-
$cache_key = 'pods_objects_' . $params->type;
|
| 7320 |
-
|
| 7321 |
-
$the_objects = pods_transient_get( $cache_key );
|
| 7322 |
-
|
| 7323 |
-
if ( false !== $the_objects ) {
|
| 7324 |
-
return $the_objects;
|
| 7325 |
-
}
|
| 7326 |
-
}
|
| 7327 |
-
|
| 7328 |
-
$the_objects = array();
|
| 7329 |
-
|
| 7330 |
-
$args = array(
|
| 7331 |
-
'post_type' => '_pods_' . $params->type,
|
| 7332 |
-
'nopaging' => true,
|
| 7333 |
-
'posts_per_page' => $limit,
|
| 7334 |
-
'order' => $order,
|
| 7335 |
-
'orderby' => $orderby,
|
| 7336 |
-
'meta_query' => $meta_query,
|
| 7337 |
-
);
|
| 7338 |
-
|
| 7339 |
-
// Only set post__in if there are ids to filter (see https://core.trac.wordpress.org/ticket/28099)
|
| 7340 |
-
if ( false !== $ids ) {
|
| 7341 |
-
$args['post__in'] = $ids;
|
| 7342 |
-
}
|
| 7343 |
-
|
| 7344 |
-
$objects = get_posts( $args );
|
| 7345 |
-
|
| 7346 |
-
foreach ( $objects as $object ) {
|
| 7347 |
-
$object = $this->load_object( $object );
|
| 7348 |
-
|
| 7349 |
-
$the_objects[ $object['name'] ] = $object;
|
| 7350 |
-
}
|
| 7351 |
-
|
| 7352 |
-
if ( pods_api_cache() && ! empty( $cache_key ) ) {
|
| 7353 |
-
pods_transient_set( $cache_key, $the_objects );
|
| 7354 |
-
}
|
| 7355 |
-
|
| 7356 |
-
return $the_objects;
|
| 7357 |
-
}
|
| 7358 |
-
|
| 7359 |
-
/**
|
| 7360 |
-
* @see PodsAPI::load_object
|
| 7361 |
-
*
|
| 7362 |
-
* Load a Pod Template
|
| 7363 |
-
*
|
| 7364 |
-
* $params['id'] int The template ID
|
| 7365 |
-
* $params['name'] string The template name
|
| 7366 |
-
*
|
| 7367 |
-
* @param array $params An associative array of parameters
|
| 7368 |
-
*
|
| 7369 |
-
* @return array|bool
|
| 7370 |
-
* @since 1.7.9
|
| 7371 |
-
*/
|
| 7372 |
-
public function load_template( $params ) {
|
| 7373 |
-
|
| 7374 |
-
if ( ! class_exists( 'Pods_Templates' ) ) {
|
| 7375 |
-
return false;
|
| 7376 |
-
}
|
| 7377 |
-
|
| 7378 |
-
$params = (object) $params;
|
| 7379 |
-
$params->type = 'template';
|
| 7380 |
-
|
| 7381 |
-
return $this->load_object( $params );
|
| 7382 |
-
}
|
| 7383 |
-
|
| 7384 |
-
/**
|
| 7385 |
-
* @see PodsAPI::load_objects
|
| 7386 |
-
*
|
| 7387 |
-
* Load Multiple Pod Templates
|
| 7388 |
-
*
|
| 7389 |
-
* $params['where'] string The WHERE clause of query
|
| 7390 |
-
* $params['options'] array Pod Option(s) key=>value array to filter by
|
| 7391 |
-
* $params['orderby'] string ORDER BY clause of query
|
| 7392 |
-
* $params['limit'] string Number of templates to return
|
| 7393 |
-
*
|
| 7394 |
-
* @param array $params (optional) An associative array of parameters
|
| 7395 |
-
*
|
| 7396 |
-
* @return array
|
| 7397 |
-
*
|
| 7398 |
-
* @since 2.0.0
|
| 7399 |
-
*/
|
| 7400 |
-
public function load_templates( $params = null ) {
|
| 7401 |
-
|
| 7402 |
-
if ( ! class_exists( 'Pods_Templates' ) ) {
|
| 7403 |
-
return array();
|
| 7404 |
-
}
|
| 7405 |
-
|
| 7406 |
-
$params = (object) $params;
|
| 7407 |
-
$params->type = 'template';
|
| 7408 |
-
|
| 7409 |
-
return $this->load_objects( $params );
|
| 7410 |
-
}
|
| 7411 |
-
|
| 7412 |
-
/**
|
| 7413 |
-
* @see PodsAPI::load_object
|
| 7414 |
-
*
|
| 7415 |
-
* Load a Pod Page
|
| 7416 |
-
*
|
| 7417 |
-
* $params['id'] int The page ID
|
| 7418 |
-
* $params['name'] string The page URI
|
| 7419 |
-
*
|
| 7420 |
-
* @param array $params An associative array of parameters
|
| 7421 |
-
*
|
| 7422 |
-
* @return array|bool
|
| 7423 |
-
*
|
| 7424 |
-
* @since 1.7.9
|
| 7425 |
-
*/
|
| 7426 |
-
public function load_page( $params ) {
|
| 7427 |
-
|
| 7428 |
-
if ( ! class_exists( 'Pods_Pages' ) ) {
|
| 7429 |
-
return false;
|
| 7430 |
-
}
|
| 7431 |
-
|
| 7432 |
-
$params = (object) $params;
|
| 7433 |
-
if ( ! isset( $params->name ) && isset( $params->uri ) ) {
|
| 7434 |
-
$params->name = $params->uri;
|
| 7435 |
-
unset( $params->uri );
|
| 7436 |
-
}
|
| 7437 |
-
$params->type = 'page';
|
| 7438 |
-
|
| 7439 |
-
return $this->load_object( $params );
|
| 7440 |
-
}
|
| 7441 |
-
|
| 7442 |
-
/**
|
| 7443 |
-
* @see PodsAPI::load_objects
|
| 7444 |
-
*
|
| 7445 |
-
* Load Multiple Pod Pages
|
| 7446 |
-
*
|
| 7447 |
-
* $params['where'] string The WHERE clause of query
|
| 7448 |
-
* $params['options'] array Pod Option(s) key=>value array to filter by
|
| 7449 |
-
* $params['orderby'] string ORDER BY clause of query
|
| 7450 |
-
* $params['limit'] string Number of pages to return
|
| 7451 |
-
*
|
| 7452 |
-
* @param array $params (optional) An associative array of parameters
|
| 7453 |
-
*
|
| 7454 |
-
* @return array
|
| 7455 |
-
*
|
| 7456 |
-
* @since 2.0.0
|
| 7457 |
-
*/
|
| 7458 |
-
public function load_pages( $params = null ) {
|
| 7459 |
-
|
| 7460 |
-
if ( ! class_exists( 'Pods_Pages' ) ) {
|
| 7461 |
-
return array();
|
| 7462 |
-
}
|
| 7463 |
-
|
| 7464 |
-
$params = (object) $params;
|
| 7465 |
-
$params->type = 'page';
|
| 7466 |
-
|
| 7467 |
-
return $this->load_objects( $params );
|
| 7468 |
-
}
|
| 7469 |
-
|
| 7470 |
-
/**
|
| 7471 |
-
* @see PodsAPI::load_object
|
| 7472 |
-
*
|
| 7473 |
-
* Load a Pod Helper
|
| 7474 |
-
*
|
| 7475 |
-
* $params['id'] int The helper ID
|
| 7476 |
-
* $params['name'] string The helper name
|
| 7477 |
-
*
|
| 7478 |
-
* @param array $params An associative array of parameters
|
| 7479 |
-
*
|
| 7480 |
-
* @return array|bool
|
| 7481 |
-
*
|
| 7482 |
-
* @since 1.7.9
|
| 7483 |
-
*/
|
| 7484 |
-
public function load_helper( $params ) {
|
| 7485 |
-
|
| 7486 |
-
if ( ! class_exists( 'Pods_Helpers' ) ) {
|
| 7487 |
-
return false;
|
| 7488 |
-
}
|
| 7489 |
-
|
| 7490 |
-
$params = (object) $params;
|
| 7491 |
-
$params->type = 'helper';
|
| 7492 |
-
|
| 7493 |
-
return $this->load_object( $params );
|
| 7494 |
-
}
|
| 7495 |
-
|
| 7496 |
-
/**
|
| 7497 |
-
* @see PodsAPI::load_objects
|
| 7498 |
-
*
|
| 7499 |
-
* Load Multiple Pod Helpers
|
| 7500 |
-
*
|
| 7501 |
-
* $params['where'] string The WHERE clause of query
|
| 7502 |
-
* $params['options'] array Pod Option(s) key=>value array to filter by
|
| 7503 |
-
* $params['orderby'] string ORDER BY clause of query
|
| 7504 |
-
* $params['limit'] string Number of pages to return
|
| 7505 |
-
*
|
| 7506 |
-
* @param array $params (optional) An associative array of parameters
|
| 7507 |
-
*
|
| 7508 |
-
* @return array
|
| 7509 |
-
*
|
| 7510 |
-
* @since 2.0.0
|
| 7511 |
-
*/
|
| 7512 |
-
public function load_helpers( $params = null ) {
|
| 7513 |
-
|
| 7514 |
-
if ( ! class_exists( 'Pods_Helpers' ) ) {
|
| 7515 |
-
return array();
|
| 7516 |
-
}
|
| 7517 |
-
|
| 7518 |
-
$params = (object) $params;
|
| 7519 |
-
$params->type = 'helper';
|
| 7520 |
-
|
| 7521 |
-
return $this->load_objects( $params );
|
| 7522 |
-
}
|
| 7523 |
-
|
| 7524 |
-
/**
|
| 7525 |
-
* Load the pod item object
|
| 7526 |
-
*
|
| 7527 |
-
* $params['pod'] string The datatype name
|
| 7528 |
-
* $params['id'] int (optional) The item's ID
|
| 7529 |
-
*
|
| 7530 |
-
* @param array $params An associative array of parameters
|
| 7531 |
-
*
|
| 7532 |
-
* @return bool|\Pods
|
| 7533 |
-
*
|
| 7534 |
-
* @uses pods()
|
| 7535 |
-
*
|
| 7536 |
-
* @since 2.0.0
|
| 7537 |
-
*/
|
| 7538 |
-
public function load_pod_item( $params ) {
|
| 7539 |
-
|
| 7540 |
-
$params = (object) pods_sanitize( $params );
|
| 7541 |
-
|
| 7542 |
-
if ( ! isset( $params->pod ) || empty( $params->pod ) ) {
|
| 7543 |
-
return pods_error( __( 'Pod name required', 'pods' ), $this );
|
| 7544 |
-
}
|
| 7545 |
-
if ( ! isset( $params->id ) || empty( $params->id ) ) {
|
| 7546 |
-
return pods_error( __( 'Item ID required', 'pods' ), $this );
|
| 7547 |
-
}
|
| 7548 |
-
|
| 7549 |
-
$pod = false;
|
| 7550 |
-
|
| 7551 |
-
if ( pods_api_cache() ) {
|
| 7552 |
-
$pod = pods_cache_get( $params->id, 'pods_item_object_' . $params->pod );
|
| 7553 |
-
}
|
| 7554 |
-
|
| 7555 |
-
if ( false !== $pod ) {
|
| 7556 |
-
return $pod;
|
| 7557 |
-
}
|
| 7558 |
-
|
| 7559 |
-
$pod = pods( $params->pod, $params->id );
|
| 7560 |
-
|
| 7561 |
-
if ( pods_api_cache() ) {
|
| 7562 |
-
pods_cache_set( $params->id, $pod, 'pods_item_object_' . $params->pod );
|
| 7563 |
-
}
|
| 7564 |
-
|
| 7565 |
-
return $pod;
|
| 7566 |
-
}
|
| 7567 |
-
|
| 7568 |
-
/**
|
| 7569 |
-
* Load potential sister fields for a specific field
|
| 7570 |
-
*
|
| 7571 |
-
* $params['pod'] int The Pod name
|
| 7572 |
-
* $params['related_pod'] string The related Pod name
|
| 7573 |
-
*
|
| 7574 |
-
* @param array $params An associative array of parameters
|
| 7575 |
-
* @param array $pod (optional) Array of Pod data to use (to avoid lookup)
|
| 7576 |
-
*
|
| 7577 |
-
* @return array|bool
|
| 7578 |
-
*
|
| 7579 |
-
* @since 1.7.9
|
| 7580 |
-
*
|
| 7581 |
-
* @uses PodsAPI::load_pod
|
| 7582 |
-
*/
|
| 7583 |
-
public function load_sister_fields( $params, $pod = null ) {
|
| 7584 |
-
|
| 7585 |
-
$params = (object) pods_sanitize( $params );
|
| 7586 |
-
|
| 7587 |
-
if ( empty( $pod ) ) {
|
| 7588 |
-
$pod = $this->load_pod( array( 'name' => $params->pod, 'table_info' => false ), false );
|
| 7589 |
-
|
| 7590 |
-
if ( false === $pod ) {
|
| 7591 |
-
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
| 7592 |
-
}
|
| 7593 |
-
}
|
| 7594 |
-
|
| 7595 |
-
$params->pod_id = $pod['id'];
|
| 7596 |
-
$params->pod = $pod['name'];
|
| 7597 |
-
|
| 7598 |
-
$type = false;
|
| 7599 |
-
|
| 7600 |
-
if ( 0 === strpos( $params->related_pod, 'pod-' ) ) {
|
| 7601 |
-
$params->related_pod = pods_str_replace( 'pod-', '', $params->related_pod, 1 );
|
| 7602 |
-
$type = 'pod';
|
| 7603 |
-
} elseif ( 0 === strpos( $params->related_pod, 'post_type-' ) ) {
|
| 7604 |
-
$params->related_pod = pods_str_replace( 'post_type-', '', $params->related_pod, 1 );
|
| 7605 |
-
$type = 'post_type';
|
| 7606 |
-
} elseif ( 0 === strpos( $params->related_pod, 'taxonomy-' ) ) {
|
| 7607 |
-
$params->related_pod = pods_str_replace( 'taxonomy-', '', $params->related_pod, 1 );
|
| 7608 |
-
$type = 'taxonomy';
|
| 7609 |
-
} elseif ( 'comment' === $params->related_pod ) {
|
| 7610 |
-
$type = $params->related_pod;
|
| 7611 |
-
}
|
| 7612 |
-
|
| 7613 |
-
$related_pod = $this->load_pod( array( 'name' => $params->related_pod, 'table_info' => false ), false );
|
| 7614 |
-
|
| 7615 |
-
if ( false === $related_pod || ( false !== $type && 'pod' !== $type && $type !== $related_pod['type'] ) ) {
|
| 7616 |
-
return pods_error( __( 'Related Pod not found', 'pods' ), $this );
|
| 7617 |
-
}
|
| 7618 |
-
|
| 7619 |
-
$params->related_pod_id = $related_pod['id'];
|
| 7620 |
-
$params->related_pod = $related_pod['name'];
|
| 7621 |
-
|
| 7622 |
-
$sister_fields = array();
|
| 7623 |
-
|
| 7624 |
-
foreach ( $related_pod['fields'] as $field ) {
|
| 7625 |
-
if ( 'pick' === $field['type'] && in_array( $field['pick_object'], array(
|
| 7626 |
-
$pod['type'],
|
| 7627 |
-
'pod'
|
| 7628 |
-
) ) && ( $params->pod == $field['pick_object'] || $params->pod == $field['pick_val'] ) ) {
|
| 7629 |
-
$sister_fields[ $field['id'] ] = esc_html( $field['label'] . ' (' . $field['name'] . ')' );
|
| 7630 |
-
}
|
| 7631 |
-
}
|
| 7632 |
-
|
| 7633 |
-
return $sister_fields;
|
| 7634 |
-
}
|
| 7635 |
-
|
| 7636 |
-
/**
|
| 7637 |
-
* Takes a sql field such as tinyint and returns the pods field type, such as num.
|
| 7638 |
-
*
|
| 7639 |
-
* @param string $sql_field The SQL field to look for
|
| 7640 |
-
*
|
| 7641 |
-
* @return string The field type
|
| 7642 |
-
*
|
| 7643 |
-
* @since 2.0.0
|
| 7644 |
-
*/
|
| 7645 |
-
public static function detect_pod_field_from_sql_data_type( $sql_field ) {
|
| 7646 |
-
|
| 7647 |
-
$sql_field = strtolower( $sql_field );
|
| 7648 |
-
|
| 7649 |
-
$field_to_field_map = array(
|
| 7650 |
-
'tinyint' => 'number',
|
| 7651 |
-
'smallint' => 'number',
|
| 7652 |
-
'mediumint' => 'number',
|
| 7653 |
-
'int' => 'number',
|
| 7654 |
-
'bigint' => 'number',
|
| 7655 |
-
'float' => 'number',
|
| 7656 |
-
'double' => 'number',
|
| 7657 |
-
'decimal' => 'number',
|
| 7658 |
-
'date' => 'date',
|
| 7659 |
-
'datetime' => 'datetime',
|
| 7660 |
-
'timestamp' => 'datetime',
|
| 7661 |
-
'time' => 'time',
|
| 7662 |
-
'year' => 'date',
|
| 7663 |
-
'varchar' => 'text',
|
| 7664 |
-
'text' => 'paragraph',
|
| 7665 |
-
'mediumtext' => 'paragraph',
|
| 7666 |
-
'longtext' => 'paragraph'
|
| 7667 |
-
);
|
| 7668 |
-
|
| 7669 |
-
return ( array_key_exists( $sql_field, $field_to_field_map ) ) ? $field_to_field_map[ $sql_field ] : 'paragraph';
|
| 7670 |
-
}
|
| 7671 |
-
|
| 7672 |
-
/**
|
| 7673 |
-
* Gets all field types
|
| 7674 |
-
*
|
| 7675 |
-
* @return array Array of field types
|
| 7676 |
-
*
|
| 7677 |
-
* @uses PodsForm::field_loader
|
| 7678 |
-
*
|
| 7679 |
-
* @since 2.0.0
|
| 7680 |
-
* @deprecated 2.3.0
|
| 7681 |
-
*/
|
| 7682 |
-
public function get_field_types() {
|
| 7683 |
-
|
| 7684 |
-
return PodsForm::field_types();
|
| 7685 |
-
}
|
| 7686 |
-
|
| 7687 |
-
/**
|
| 7688 |
-
* Gets the schema definition of a field.
|
| 7689 |
-
*
|
| 7690 |
-
* @param string $type Field type to look for
|
| 7691 |
-
* @param array $options (optional) Options of the field to pass to the schema function.
|
| 7692 |
-
*
|
| 7693 |
-
* @return array|bool|mixed|null
|
| 7694 |
-
*
|
| 7695 |
-
* @since 2.0.0
|
| 7696 |
-
*/
|
| 7697 |
-
private function get_field_definition( $type, $options = null ) {
|
| 7698 |
-
|
| 7699 |
-
$definition = PodsForm::field_method( $type, 'schema', $options );
|
| 7700 |
-
|
| 7701 |
-
return $this->do_hook( 'field_definition', $definition, $type, $options );
|
| 7702 |
-
}
|
| 7703 |
-
|
| 7704 |
-
/**
|
| 7705 |
-
* @see PodsForm:validate
|
| 7706 |
-
*
|
| 7707 |
-
* Validates the value of a field.
|
| 7708 |
-
*
|
| 7709 |
-
* @param mixed $value The value to validate
|
| 7710 |
-
* @param string $field Field to use for validation
|
| 7711 |
-
* @param array $object_fields Fields of the object we're validating
|
| 7712 |
-
* @param array $fields Array of all fields data
|
| 7713 |
-
* @param array|Pods $pod Array of pod data (or Pods object)
|
| 7714 |
-
* @param array|object $params Extra parameters to pass to the validation function of the field.
|
| 7715 |
-
*
|
| 7716 |
-
* @return array|bool
|
| 7717 |
-
*
|
| 7718 |
-
* @uses PodsForm::validate
|
| 7719 |
-
*
|
| 7720 |
-
* @since 2.0.0
|
| 7721 |
-
*/
|
| 7722 |
-
public function handle_field_validation( &$value, $field, $object_fields, $fields, $pod, $params ) {
|
| 7723 |
-
|
| 7724 |
-
$tableless_field_types = PodsForm::tableless_field_types();
|
| 7725 |
-
|
| 7726 |
-
$fields = array_merge( $fields, $object_fields );
|
| 7727 |
-
|
| 7728 |
-
$options = $fields[ $field ];
|
| 7729 |
-
|
| 7730 |
-
$id = ( is_object( $params ) ? $params->id : ( is_object( $pod ) ? $pod->id() : 0 ) );
|
| 7731 |
-
|
| 7732 |
-
if ( is_object( $pod ) ) {
|
| 7733 |
-
$pod = $pod->pod_data;
|
| 7734 |
-
}
|
| 7735 |
-
|
| 7736 |
-
$type = $options['type'];
|
| 7737 |
-
$label = $options['label'];
|
| 7738 |
-
$label = empty( $label ) ? $field : $label;
|
| 7739 |
-
|
| 7740 |
-
// Verify required fields
|
| 7741 |
-
if ( 1 == pods_var( 'required', $options['options'], 0 ) && 'slug' !== $type ) {
|
| 7742 |
-
if ( '' === $value || null === $value || array() === $value ) {
|
| 7743 |
-
return pods_error( sprintf( __( '%s is empty', 'pods' ), $label ), $this );
|
| 7744 |
-
}
|
| 7745 |
-
|
| 7746 |
-
if ( 'multi' === pods_var( 'pick_format_type', $options['options'] ) && 'autocomplete' !== pods_var( 'pick_format_multi', $options['options'] ) ) {
|
| 7747 |
-
$has_value = false;
|
| 7748 |
-
|
| 7749 |
-
$check_value = (array) $value;
|
| 7750 |
-
|
| 7751 |
-
foreach ( $check_value as $val ) {
|
| 7752 |
-
if ( '' !== $val && null !== $val && 0 !== $val && '0' !== $val ) {
|
| 7753 |
-
$has_value = true;
|
| 7754 |
-
|
| 7755 |
-
continue;
|
| 7756 |
-
}
|
| 7757 |
-
}
|
| 7758 |
-
|
| 7759 |
-
if ( ! $has_value ) {
|
| 7760 |
-
return pods_error( sprintf( __( '%s is required', 'pods' ), $label ), $this );
|
| 7761 |
-
}
|
| 7762 |
-
}
|
| 7763 |
-
|
| 7764 |
-
}
|
| 7765 |
-
|
| 7766 |
-
// @todo move this to after pre-save preparations
|
| 7767 |
-
// Verify unique fields
|
| 7768 |
-
if ( 1 == pods_var( 'unique', $options['options'], 0 ) && '' !== $value && null !== $value && array() !== $value ) {
|
| 7769 |
-
if ( empty( $pod ) ) {
|
| 7770 |
-
return false;
|
| 7771 |
-
}
|
| 7772 |
-
|
| 7773 |
-
if ( ! in_array( $type, $tableless_field_types ) ) {
|
| 7774 |
-
$exclude = '';
|
| 7775 |
-
|
| 7776 |
-
if ( ! empty( $id ) ) {
|
| 7777 |
-
$exclude = "AND `id` != {$id}";
|
| 7778 |
-
}
|
| 7779 |
-
|
| 7780 |
-
$check = false;
|
| 7781 |
-
|
| 7782 |
-
$check_value = pods_sanitize( $value );
|
| 7783 |
-
|
| 7784 |
-
// @todo handle meta-based fields
|
| 7785 |
-
// Trigger an error if not unique
|
| 7786 |
-
if ( 'table' === $pod['storage'] ) {
|
| 7787 |
-
$check = pods_query( "SELECT `id` FROM `@wp_pods_" . $pod['name'] . "` WHERE `{$field}` = '{$check_value}' {$exclude} LIMIT 1", $this );
|
| 7788 |
-
}
|
| 7789 |
-
|
| 7790 |
-
if ( ! empty( $check ) ) {
|
| 7791 |
-
return pods_error( sprintf( __( '%s needs to be unique', 'pods' ), $label ), $this );
|
| 7792 |
-
}
|
| 7793 |
-
} else {
|
| 7794 |
-
// @todo handle tableless check
|
| 7795 |
-
}
|
| 7796 |
-
}
|
| 7797 |
-
|
| 7798 |
-
$validate = PodsForm::validate( $options['type'], $value, $field, array_merge( $options, pods_var( 'options', $options, array() ) ), $fields, $pod, $id, $params );
|
| 7799 |
-
|
| 7800 |
-
$validate = $this->do_hook( 'field_validation', $validate, $value, $field, $object_fields, $fields, $pod, $params );
|
| 7801 |
-
|
| 7802 |
-
return $validate;
|
| 7803 |
-
}
|
| 7804 |
-
|
| 7805 |
-
/**
|
| 7806 |
-
* Find items related to a parent field
|
| 7807 |
-
*
|
| 7808 |
-
* @param int $field_id The Field ID
|
| 7809 |
-
* @param int $pod_id The Pod ID
|
| 7810 |
-
* @param mixed $ids A comma-separated string (or array) of item IDs
|
| 7811 |
-
* @param array $field Field data array
|
| 7812 |
-
* @param array $pod Pod data array
|
| 7813 |
-
*
|
| 7814 |
-
* @return int[]
|
| 7815 |
-
*
|
| 7816 |
-
* @since 2.0.0
|
| 7817 |
-
*
|
| 7818 |
-
* @uses pods_query()
|
| 7819 |
-
*/
|
| 7820 |
-
public function lookup_related_items( $field_id, $pod_id, $ids, $field = null, $pod = null ) {
|
| 7821 |
-
|
| 7822 |
-
$related_ids = array();
|
| 7823 |
-
|
| 7824 |
-
if ( ! is_array( $ids ) ) {
|
| 7825 |
-
$ids = explode( ',', $ids );
|
| 7826 |
-
}
|
| 7827 |
-
|
| 7828 |
-
$ids = array_map( 'absint', $ids );
|
| 7829 |
-
|
| 7830 |
-
$ids = array_unique( array_filter( $ids ) );
|
| 7831 |
-
|
| 7832 |
-
$idstring = implode( ',', $ids );
|
| 7833 |
-
|
| 7834 |
-
if ( 0 != $pod_id && 0 != $field_id && isset( self::$related_item_cache[ $pod_id ][ $field_id ][ $idstring ] ) ) {
|
| 7835 |
-
// Check cache first, no point in running the same query multiple times
|
| 7836 |
-
return self::$related_item_cache[ $pod_id ][ $field_id ][ $idstring ];
|
| 7837 |
-
}
|
| 7838 |
-
|
| 7839 |
-
$tableless_field_types = PodsForm::tableless_field_types();
|
| 7840 |
-
|
| 7841 |
-
$field_type = pods_v( 'type', $field );
|
| 7842 |
-
|
| 7843 |
-
if ( empty( $ids ) || ! in_array( $field_type, $tableless_field_types ) ) {
|
| 7844 |
-
return array();
|
| 7845 |
-
}
|
| 7846 |
-
|
| 7847 |
-
$related_pick_limit = 0;
|
| 7848 |
-
|
| 7849 |
-
if ( empty( $field ) ) {
|
| 7850 |
-
$field = $this->load_field( array( 'id' => $field_id ) );
|
| 7851 |
-
}
|
| 7852 |
-
|
| 7853 |
-
if ( ! empty( $field ) ) {
|
| 7854 |
-
$options = (array) pods_var_raw( 'options', $field, $field, null, true );
|
| 7855 |
-
|
| 7856 |
-
$related_pick_limit = (int) pods_v( $field_type . '_limit', $options, 0 );
|
| 7857 |
-
|
| 7858 |
-
if ( 'single' === pods_var_raw( $field_type . '_format_type', $options ) ) {
|
| 7859 |
-
$related_pick_limit = 1;
|
| 7860 |
-
}
|
| 7861 |
-
|
| 7862 |
-
// Temporary hack until there's some better handling here
|
| 7863 |
-
$related_pick_limit = $related_pick_limit * count( $ids );
|
| 7864 |
-
}
|
| 7865 |
-
|
| 7866 |
-
if ( 'taxonomy' === $field_type ) {
|
| 7867 |
-
$related = wp_get_object_terms( $ids, pods_v( 'name', $field ), array( 'fields' => 'ids' ) );
|
| 7868 |
-
|
| 7869 |
-
if ( ! is_wp_error( $related ) ) {
|
| 7870 |
-
$related_ids = $related;
|
| 7871 |
-
}
|
| 7872 |
-
} elseif ( 'comment' === $field_type ) {
|
| 7873 |
-
$comment_args = array(
|
| 7874 |
-
'post__in' => $ids,
|
| 7875 |
-
'fields' => 'ids',
|
| 7876 |
-
);
|
| 7877 |
-
|
| 7878 |
-
$related = get_comments( $comment_args );
|
| 7879 |
-
|
| 7880 |
-
if ( ! is_wp_error( $related ) ) {
|
| 7881 |
-
$related_ids = $related;
|
| 7882 |
-
}
|
| 7883 |
-
} elseif ( ! pods_tableless() ) {
|
| 7884 |
-
$ids = implode( ', ', $ids );
|
| 7885 |
-
|
| 7886 |
-
$field_id = (int) $field_id;
|
| 7887 |
-
$sister_id = (int) pods_var_raw( 'sister_id', $field, 0 );
|
| 7888 |
-
|
| 7889 |
-
$related_where = "
|
| 7890 |
-
`field_id` = {$field_id}
|
| 7891 |
-
AND `item_id` IN ( {$ids} )
|
| 7892 |
-
";
|
| 7893 |
-
|
| 7894 |
-
$sql = "
|
| 7895 |
-
SELECT item_id, related_item_id, related_field_id
|
| 7896 |
-
FROM `@wp_podsrel`
|
| 7897 |
-
WHERE
|
| 7898 |
-
{$related_where}
|
| 7899 |
-
ORDER BY `weight`
|
| 7900 |
-
";
|
| 7901 |
-
|
| 7902 |
-
$relationships = pods_query( $sql );
|
| 7903 |
-
|
| 7904 |
-
if ( ! empty( $relationships ) ) {
|
| 7905 |
-
foreach ( $relationships as $relation ) {
|
| 7906 |
-
if ( ! in_array( $relation->related_item_id, $related_ids ) ) {
|
| 7907 |
-
$related_ids[] = (int) $relation->related_item_id;
|
| 7908 |
-
} elseif ( 0 < $sister_id && $field_id == $relation->related_field_id && ! in_array( $relation->item_id, $related_ids ) ) {
|
| 7909 |
-
$related_ids[] = (int) $relation->item_id;
|
| 7910 |
-
}
|
| 7911 |
-
}
|
| 7912 |
-
}
|
| 7913 |
-
} else {
|
| 7914 |
-
if ( ! is_array( $pod ) ) {
|
| 7915 |
-
$pod = $this->load_pod( array( 'id' => $pod_id, 'table_info' => false ), false );
|
| 7916 |
-
}
|
| 7917 |
-
|
| 7918 |
-
if ( ! empty( $pod ) && in_array( $pod['type'], array(
|
| 7919 |
-
'post_type',
|
| 7920 |
-
'media',
|
| 7921 |
-
'taxonomy',
|
| 7922 |
-
'user',
|
| 7923 |
-
'comment',
|
| 7924 |
-
'settings'
|
| 7925 |
-
) ) ) {
|
| 7926 |
-
$meta_type = $pod['type'];
|
| 7927 |
-
|
| 7928 |
-
if ( in_array( $meta_type, array( 'post_type', 'media' ) ) ) {
|
| 7929 |
-
$meta_type = 'post';
|
| 7930 |
-
} elseif ( 'taxonomy' === $meta_type ) {
|
| 7931 |
-
$meta_type = 'term';
|
| 7932 |
-
}
|
| 7933 |
-
|
| 7934 |
-
$no_conflict = pods_no_conflict_check( ( 'term' === $meta_type ? 'taxonomy' : $meta_type ) );
|
| 7935 |
-
|
| 7936 |
-
if ( ! $no_conflict ) {
|
| 7937 |
-
pods_no_conflict_on( ( 'term' === $meta_type ? 'taxonomy' : $meta_type ) );
|
| 7938 |
-
}
|
| 7939 |
-
|
| 7940 |
-
foreach ( $ids as $id ) {
|
| 7941 |
-
if ( 'settings' === $meta_type ) {
|
| 7942 |
-
$related_id = get_option( '_pods_' . $pod['name'] . '_' . $field['name'] );
|
| 7943 |
-
|
| 7944 |
-
if ( empty( $related_id ) ) {
|
| 7945 |
-
$related_id = get_option( $pod['name'] . '_' . $field['name'] );
|
| 7946 |
-
}
|
| 7947 |
|
| 7948 |
-
|
| 7949 |
-
foreach ( $related_id as $related ) {
|
| 7950 |
-
if ( is_array( $related ) && ! empty( $related ) ) {
|
| 7951 |
-
if ( isset( $related['id'] ) ) {
|
| 7952 |
-
$related_ids[] = (int) $related['id'];
|
| 7953 |
-
} else {
|
| 7954 |
-
foreach ( $related as $r ) {
|
| 7955 |
-
$related_ids[] = (int) $r;
|
| 7956 |
-
}
|
| 7957 |
}
|
| 7958 |
-
} else {
|
| 7959 |
-
$related_ids[] = (int) $related;
|
| 7960 |
}
|
| 7961 |
}
|
| 7962 |
-
|
| 7963 |
-
|
| 7964 |
-
|
| 7965 |
-
|
| 7966 |
-
|
| 7967 |
-
$related_id = get_metadata( $meta_type, $id, $field['name'] );
|
| 7968 |
-
}
|
| 7969 |
-
|
| 7970 |
-
if ( is_array( $related_id ) && ! empty( $related_id ) ) {
|
| 7971 |
-
foreach ( $related_id as $related ) {
|
| 7972 |
-
if ( is_array( $related ) && ! empty( $related ) ) {
|
| 7973 |
-
if ( isset( $related['id'] ) ) {
|
| 7974 |
-
$related_ids[] = (int) $related['id'];
|
| 7975 |
-
} else {
|
| 7976 |
-
foreach ( $related as $r ) {
|
| 7977 |
-
if ( isset( $related['id'] ) ) {
|
| 7978 |
-
$related_ids[] = (int) $r['id'];
|
| 7979 |
-
} else {
|
| 7980 |
-
$related_ids[] = (int) $r;
|
| 7981 |
-
}
|
| 7982 |
-
}
|
| 7983 |
-
}
|
| 7984 |
-
} else {
|
| 7985 |
-
$related_ids[] = (int) $related;
|
| 7986 |
-
}
|
| 7987 |
}
|
| 7988 |
-
}
|
| 7989 |
-
}
|
| 7990 |
-
}
|
| 7991 |
-
|
| 7992 |
-
if ( ! $no_conflict ) {
|
| 7993 |
-
pods_no_conflict_off( ( 'term' === $meta_type ? 'taxonomy' : $meta_type ) );
|
| 7994 |
-
}
|
| 7995 |
-
}
|
| 7996 |
-
}
|
| 7997 |
-
|
| 7998 |
-
if ( is_array( $related_ids ) ) {
|
| 7999 |
-
$related_ids = array_unique( array_filter( $related_ids ) );
|
| 8000 |
-
|
| 8001 |
-
if ( 0 < $related_pick_limit && ! empty( $related_ids ) ) {
|
| 8002 |
-
$related_ids = array_slice( $related_ids, 0, $related_pick_limit );
|
| 8003 |
-
}
|
| 8004 |
-
}
|
| 8005 |
-
if ( 0 != $pod_id && 0 != $field_id && ! empty( $related_ids ) ) {
|
| 8006 |
-
// Only cache if $pod_id and $field_id were passed
|
| 8007 |
-
self::$related_item_cache[ $pod_id ][ $field_id ][ $idstring ] = $related_ids;
|
| 8008 |
-
}
|
| 8009 |
-
|
| 8010 |
-
return $related_ids;
|
| 8011 |
-
}
|
| 8012 |
-
|
| 8013 |
-
/**
|
| 8014 |
-
* Find related items related to an item
|
| 8015 |
-
*
|
| 8016 |
-
* @param int $field_id The Field ID
|
| 8017 |
-
* @param int $pod_id The Pod ID
|
| 8018 |
-
* @param int $id Item ID to get related IDs from
|
| 8019 |
-
* @param array $field Field data array
|
| 8020 |
-
* @param array $pod Pod data array
|
| 8021 |
-
*
|
| 8022 |
-
* @return array|bool
|
| 8023 |
-
*
|
| 8024 |
-
* @since 2.3.0
|
| 8025 |
-
*
|
| 8026 |
-
* @uses pods_query()
|
| 8027 |
-
*/
|
| 8028 |
-
public function lookup_related_items_from( $field_id, $pod_id, $id, $field = null, $pod = null ) {
|
| 8029 |
-
|
| 8030 |
-
$related_ids = false;
|
| 8031 |
-
|
| 8032 |
-
$id = (int) $id;
|
| 8033 |
-
|
| 8034 |
-
$tableless_field_types = PodsForm::tableless_field_types();
|
| 8035 |
-
|
| 8036 |
-
if ( empty( $id ) || ! in_array( pods_v( 'type', $field ), $tableless_field_types ) ) {
|
| 8037 |
-
return false;
|
| 8038 |
-
}
|
| 8039 |
-
|
| 8040 |
-
$related_pick_limit = 0;
|
| 8041 |
-
|
| 8042 |
-
if ( ! empty( $field ) ) {
|
| 8043 |
-
$options = (array) pods_var_raw( 'options', $field, $field, null, true );
|
| 8044 |
|
| 8045 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8046 |
|
| 8047 |
-
if (
|
| 8048 |
-
|
| 8049 |
}
|
| 8050 |
}
|
| 8051 |
|
| 8052 |
-
|
| 8053 |
-
|
| 8054 |
-
|
| 8055 |
-
|
| 8056 |
-
$related_where = "
|
| 8057 |
-
`field_id` = {$field_id}
|
| 8058 |
-
AND `related_item_id` = {$id}
|
| 8059 |
-
";
|
| 8060 |
-
|
| 8061 |
-
$sql = "
|
| 8062 |
-
SELECT *
|
| 8063 |
-
FROM `@wp_podsrel`
|
| 8064 |
-
WHERE
|
| 8065 |
-
{$related_where}
|
| 8066 |
-
ORDER BY `weight`
|
| 8067 |
-
";
|
| 8068 |
-
|
| 8069 |
-
$relationships = pods_query( $sql );
|
| 8070 |
-
|
| 8071 |
-
if ( ! empty( $relationships ) ) {
|
| 8072 |
-
$related_ids = array();
|
| 8073 |
-
|
| 8074 |
-
foreach ( $relationships as $relation ) {
|
| 8075 |
-
if ( $field_id == $relation->field_id && ! in_array( $relation->item_id, $related_ids ) ) {
|
| 8076 |
-
$related_ids[] = (int) $relation->item_id;
|
| 8077 |
-
} elseif ( 0 < $sister_id && $field_id == $relation->related_field_id && ! in_array( $relation->related_item_id, $related_ids ) ) {
|
| 8078 |
-
$related_ids[] = (int) $relation->related_item_id;
|
| 8079 |
-
}
|
| 8080 |
-
}
|
| 8081 |
-
}
|
| 8082 |
-
} else {
|
| 8083 |
-
// @todo handle meta-based lookups
|
| 8084 |
-
return false;
|
| 8085 |
-
|
| 8086 |
-
if ( ! is_array( $pod ) ) {
|
| 8087 |
-
$pod = $this->load_pod( array( 'id' => $pod_id, 'table_info' => false ), false );
|
| 8088 |
-
}
|
| 8089 |
-
|
| 8090 |
-
if ( ! empty( $pod ) && in_array( $pod['type'], array(
|
| 8091 |
-
'post_type',
|
| 8092 |
-
'media',
|
| 8093 |
-
'taxonomy',
|
| 8094 |
-
'user',
|
| 8095 |
-
'comment',
|
| 8096 |
-
'settings'
|
| 8097 |
-
) ) ) {
|
| 8098 |
-
$related_ids = array();
|
| 8099 |
-
|
| 8100 |
-
$meta_type = $pod['type'];
|
| 8101 |
-
|
| 8102 |
-
if ( in_array( $meta_type, array( 'post_type', 'media' ) ) ) {
|
| 8103 |
-
$meta_type = 'post';
|
| 8104 |
-
} elseif ( 'taxonomy' === $meta_type ) {
|
| 8105 |
-
$meta_type = 'term';
|
| 8106 |
-
}
|
| 8107 |
|
| 8108 |
-
|
|
|
|
| 8109 |
|
| 8110 |
-
|
| 8111 |
-
|
| 8112 |
-
|
| 8113 |
|
| 8114 |
-
|
| 8115 |
-
|
| 8116 |
|
| 8117 |
-
|
| 8118 |
-
$related_id = get_option( $pod['name'] . '_' . $field['name'] );
|
| 8119 |
-
}
|
| 8120 |
|
| 8121 |
-
|
| 8122 |
-
|
| 8123 |
-
|
| 8124 |
-
|
| 8125 |
-
|
| 8126 |
-
|
| 8127 |
-
|
| 8128 |
-
|
| 8129 |
-
|
| 8130 |
-
|
| 8131 |
-
|
| 8132 |
-
|
| 8133 |
-
|
| 8134 |
-
|
| 8135 |
-
|
| 8136 |
-
|
| 8137 |
-
|
|
|
|
|
|
|
| 8138 |
|
| 8139 |
-
|
| 8140 |
-
$related_id = get_metadata( $meta_type, $id, $field['name'] );
|
| 8141 |
-
}
|
| 8142 |
|
| 8143 |
-
|
| 8144 |
-
|
| 8145 |
-
if ( is_array( $related ) && ! empty( $related ) ) {
|
| 8146 |
-
if ( isset( $related['id'] ) ) {
|
| 8147 |
-
$related_ids[] = (int) $related['id'];
|
| 8148 |
-
} else {
|
| 8149 |
-
foreach ( $related as $r ) {
|
| 8150 |
-
if ( isset( $related['id'] ) ) {
|
| 8151 |
-
$related_ids[] = (int) $r['id'];
|
| 8152 |
-
} else {
|
| 8153 |
-
$related_ids[] = (int) $r;
|
| 8154 |
-
}
|
| 8155 |
-
}
|
| 8156 |
-
}
|
| 8157 |
-
} else {
|
| 8158 |
-
$related_ids[] = (int) $related;
|
| 8159 |
-
}
|
| 8160 |
-
}
|
| 8161 |
-
}
|
| 8162 |
-
}
|
| 8163 |
|
| 8164 |
-
|
| 8165 |
-
|
| 8166 |
-
|
| 8167 |
-
|
| 8168 |
-
}
|
| 8169 |
|
| 8170 |
-
|
| 8171 |
-
|
| 8172 |
-
}
|
| 8173 |
|
| 8174 |
-
|
| 8175 |
-
|
| 8176 |
|
| 8177 |
/**
|
|
|
|
| 8178 |
*
|
| 8179 |
-
*
|
| 8180 |
-
*
|
| 8181 |
-
* @param $object_type
|
| 8182 |
-
* @param string $object The object to look for
|
| 8183 |
-
* @param null $name (optional) Name of the pod to load
|
| 8184 |
-
* @param array $pod (optional) Array with pod information
|
| 8185 |
-
*
|
| 8186 |
-
* @return array
|
| 8187 |
*
|
| 8188 |
-
* @
|
| 8189 |
*/
|
| 8190 |
-
public function
|
| 8191 |
-
|
| 8192 |
-
$info = array();
|
| 8193 |
-
|
| 8194 |
-
if ( 'pod' === $object_type && null === $pod ) {
|
| 8195 |
-
if ( empty( $name ) ) {
|
| 8196 |
-
$prefix = 'pod-';
|
| 8197 |
-
|
| 8198 |
-
// Make sure we actually have the prefix before trying anything with the name
|
| 8199 |
-
if ( 0 === strpos( $object_type, $prefix ) ) {
|
| 8200 |
-
$name = substr( $object_type, strlen( $prefix ), strlen( $object_type ) );
|
| 8201 |
-
}
|
| 8202 |
-
}
|
| 8203 |
-
|
| 8204 |
-
if ( empty( $name ) && ! empty( $object ) ) {
|
| 8205 |
-
$name = $object;
|
| 8206 |
-
}
|
| 8207 |
-
|
| 8208 |
-
$pod = $this->load_pod( array( 'name' => $name, 'table_info' => false ), false );
|
| 8209 |
-
|
| 8210 |
-
if ( ! empty( $pod ) ) {
|
| 8211 |
-
$object_type = $pod['type'];
|
| 8212 |
-
$name = $pod['name'];
|
| 8213 |
-
$object = $pod['object'];
|
| 8214 |
-
|
| 8215 |
-
$info['pod'] = $pod;
|
| 8216 |
-
}
|
| 8217 |
-
} elseif ( null === $pod ) {
|
| 8218 |
-
if ( empty( $name ) ) {
|
| 8219 |
-
$prefix = $object_type . '-';
|
| 8220 |
-
|
| 8221 |
-
// Make sure we actually have the prefix before trying anything with the name
|
| 8222 |
-
if ( 0 === strpos( $object_type, $prefix ) ) {
|
| 8223 |
-
$name = substr( $object_type, strlen( $prefix ), strlen( $object_type ) );
|
| 8224 |
-
}
|
| 8225 |
-
}
|
| 8226 |
|
| 8227 |
-
|
| 8228 |
-
|
| 8229 |
-
}
|
| 8230 |
|
| 8231 |
-
|
| 8232 |
-
$pod = $this->load_pod( array( 'name' => $name, 'table_info' => false ), false );
|
| 8233 |
|
| 8234 |
-
|
| 8235 |
-
|
| 8236 |
-
$name = $pod['name'];
|
| 8237 |
-
$object = $pod['object'];
|
| 8238 |
|
| 8239 |
-
|
|
|
|
|
|
|
| 8240 |
}
|
| 8241 |
}
|
| 8242 |
-
} elseif ( ! empty( $pod ) ) {
|
| 8243 |
-
$info['pod'] = $pod;
|
| 8244 |
}
|
| 8245 |
|
| 8246 |
-
|
| 8247 |
-
if ( empty( $name ) ) {
|
| 8248 |
-
$prefix = 'pod-';
|
| 8249 |
-
|
| 8250 |
-
// Make sure we actually have the prefix before trying anything with the name
|
| 8251 |
-
if ( 0 === strpos( $object_type, $prefix ) ) {
|
| 8252 |
-
$name = substr( $object_type, strlen( $prefix ), strlen( $object_type ) );
|
| 8253 |
-
}
|
| 8254 |
-
}
|
| 8255 |
-
|
| 8256 |
-
$info['type'] = 'pod';
|
| 8257 |
-
global $wpdb;
|
| 8258 |
-
|
| 8259 |
-
$info['meta_table'] = $wpdb->prefix . 'pods_' . ( empty( $object ) ? $name : $object );
|
| 8260 |
-
$info['table'] = $info['meta_table'];
|
| 8261 |
-
|
| 8262 |
-
if ( is_array( $info['pod'] ) && 'pod' === pods_v( 'type', $info['pod'] ) ) {
|
| 8263 |
-
$info['meta_field_value'] = pods_v( 'pod_index', $info['pod']['options'], 'id', true );
|
| 8264 |
-
$info['pod_field_index'] = $info['meta_field_value'];
|
| 8265 |
-
$info['field_index'] = $info['meta_field_value'];
|
| 8266 |
-
$info['meta_field_index'] = $info['meta_field_value'];
|
| 8267 |
-
|
| 8268 |
-
$slug_field = get_posts( array(
|
| 8269 |
-
'post_type' => '_pods_field',
|
| 8270 |
-
'posts_per_page' => 1,
|
| 8271 |
-
'nopaging' => true,
|
| 8272 |
-
'post_parent' => $info['pod']['id'],
|
| 8273 |
-
'orderby' => 'menu_order',
|
| 8274 |
-
'order' => 'ASC',
|
| 8275 |
-
'meta_query' => array(
|
| 8276 |
-
array(
|
| 8277 |
-
'key' => 'type',
|
| 8278 |
-
'value' => 'slug',
|
| 8279 |
-
)
|
| 8280 |
-
)
|
| 8281 |
-
) );
|
| 8282 |
-
|
| 8283 |
-
if ( ! empty( $slug_field[0] ) ) {
|
| 8284 |
-
$slug_field = $slug_field[0];
|
| 8285 |
|
| 8286 |
-
$info['pod_field_slug'] = $slug_field->post_name;
|
| 8287 |
-
$info['field_slug'] = $slug_field->post_name;
|
| 8288 |
-
}
|
| 8289 |
-
|
| 8290 |
-
if ( 1 == pods_v( 'hierarchical', $info['pod']['options'], 0 ) ) {
|
| 8291 |
-
$parent_field = pods_v( 'pod_parent', $info['pod']['options'], 'id', true );
|
| 8292 |
-
|
| 8293 |
-
if ( ! empty( $parent_field ) && isset( $info['pod']['fields'][ $parent_field ] ) ) {
|
| 8294 |
-
$info['object_hierarchical'] = true;
|
| 8295 |
-
|
| 8296 |
-
$info['field_parent'] = $parent_field . '_select';
|
| 8297 |
-
$info['pod_field_parent'] = $info['field_parent'];
|
| 8298 |
-
$info['field_parent_select'] = '`' . $parent_field . '`.`id` AS `' . $info['field_parent'] . '`';
|
| 8299 |
-
}
|
| 8300 |
-
}
|
| 8301 |
-
}
|
| 8302 |
-
}
|
| 8303 |
-
|
| 8304 |
-
return $info;
|
| 8305 |
}
|
| 8306 |
|
| 8307 |
-
|
| 8308 |
-
|
| 8309 |
-
|
| 8310 |
-
|
| 8311 |
-
|
| 8312 |
-
|
| 8313 |
-
|
| 8314 |
-
|
| 8315 |
-
|
| 8316 |
-
|
| 8317 |
-
|
| 8318 |
-
|
| 8319 |
-
|
| 8320 |
-
|
| 8321 |
-
|
| 8322 |
-
|
| 8323 |
-
|
| 8324 |
-
|
| 8325 |
-
|
| 8326 |
-
|
| 8327 |
-
|
| 8328 |
-
|
| 8329 |
-
|
| 8330 |
-
|
| 8331 |
-
|
| 8332 |
-
|
| 8333 |
-
|
| 8334 |
-
|
| 8335 |
-
|
| 8336 |
-
|
| 8337 |
-
|
| 8338 |
-
|
| 8339 |
-
|
| 8340 |
-
|
| 8341 |
-
|
| 8342 |
-
|
| 8343 |
-
|
| 8344 |
-
|
| 8345 |
-
|
| 8346 |
-
|
| 8347 |
-
|
| 8348 |
-
|
| 8349 |
-
|
| 8350 |
-
|
| 8351 |
-
|
| 8352 |
-
|
| 8353 |
-
|
| 8354 |
-
|
| 8355 |
-
|
| 8356 |
-
|
| 8357 |
-
|
| 8358 |
-
|
| 8359 |
-
|
| 8360 |
-
|
| 8361 |
-
|
| 8362 |
-
|
| 8363 |
-
|
| 8364 |
-
|
| 8365 |
-
|
| 8366 |
-
|
| 8367 |
-
|
| 8368 |
-
|
| 8369 |
-
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8418 |
|
| 8419 |
-
|
| 8420 |
-
|
|
|
|
| 8421 |
}
|
| 8422 |
-
|
| 8423 |
-
|
| 8424 |
-
if ( ! empty( $current_language ) ) {
|
| 8425 |
-
$transient = 'pods_' . $wpdb->prefix . '_get_table_info_' . $current_language . '_' . md5( $object_type . '_object_' . $object . '_name_' . $name . '_pod_' . $pod_name . '_field_' . $field_name );
|
| 8426 |
-
}
|
| 8427 |
-
|
| 8428 |
-
$_info = false;
|
| 8429 |
-
$transient_cached = false;
|
| 8430 |
-
|
| 8431 |
-
if ( isset( self::$table_info_cache[ $transient ] ) ) {
|
| 8432 |
-
// Prefer info from the object internal cache
|
| 8433 |
-
$_info = self::$table_info_cache[ $transient ];
|
| 8434 |
-
} elseif ( pods_api_cache() ) {
|
| 8435 |
-
$_info = pods_transient_get( $transient );
|
| 8436 |
-
if ( false === $_info && ! did_action( 'init' ) ) {
|
| 8437 |
-
$_info = pods_transient_get( $transient . '_pre_init' );
|
| 8438 |
}
|
| 8439 |
-
$transient_cached = true;
|
| 8440 |
}
|
| 8441 |
|
| 8442 |
-
|
| 8443 |
-
// Data was cached, use that
|
| 8444 |
-
$info = $_info;
|
| 8445 |
-
} else {
|
| 8446 |
-
// Data not cached, load it up
|
| 8447 |
-
$_info = $this->get_table_info_load( $object_type, $object, $name, $pod );
|
| 8448 |
-
if ( isset( $_info['type'] ) ) {
|
| 8449 |
-
// Allow function to override $object_type
|
| 8450 |
-
$object_type = $_info['type'];
|
| 8451 |
-
}
|
| 8452 |
-
$info = array_merge( $info, $_info );
|
| 8453 |
-
}
|
| 8454 |
|
| 8455 |
-
|
| 8456 |
-
'post_type',
|
| 8457 |
-
'media'
|
| 8458 |
-
) ) ) {
|
| 8459 |
-
$info['table'] = $wpdb->posts;
|
| 8460 |
-
$info['meta_table'] = $wpdb->postmeta;
|
| 8461 |
-
|
| 8462 |
-
$info['field_id'] = 'ID';
|
| 8463 |
-
$info['field_index'] = 'post_title';
|
| 8464 |
-
$info['field_slug'] = 'post_name';
|
| 8465 |
-
$info['field_type'] = 'post_type';
|
| 8466 |
-
$info['field_parent'] = 'post_parent';
|
| 8467 |
-
$info['field_parent_select'] = '`t`.`' . $info['field_parent'] . '`';
|
| 8468 |
-
|
| 8469 |
-
$info['meta_field_id'] = 'post_id';
|
| 8470 |
-
$info['meta_field_index'] = 'meta_key';
|
| 8471 |
-
$info['meta_field_value'] = 'meta_value';
|
| 8472 |
-
|
| 8473 |
-
if ( 'media' === $object_type ) {
|
| 8474 |
-
$object = 'attachment';
|
| 8475 |
-
}
|
| 8476 |
|
| 8477 |
-
|
| 8478 |
-
$prefix = 'post_type-';
|
| 8479 |
|
| 8480 |
-
|
| 8481 |
-
|
| 8482 |
-
|
| 8483 |
-
}
|
| 8484 |
}
|
| 8485 |
|
| 8486 |
-
|
| 8487 |
-
|
| 8488 |
-
}
|
| 8489 |
|
| 8490 |
-
|
| 8491 |
|
| 8492 |
-
|
| 8493 |
-
|
| 8494 |
-
|
| 8495 |
-
$info['pod_table'] = $wpdb->prefix . 'pods_' . pods_clean_name( $post_type, true, false );
|
| 8496 |
-
}
|
| 8497 |
|
| 8498 |
-
|
| 8499 |
|
| 8500 |
-
|
| 8501 |
-
|
| 8502 |
-
}
|
| 8503 |
|
| 8504 |
-
|
| 8505 |
-
$
|
| 8506 |
|
| 8507 |
-
|
| 8508 |
-
|
| 8509 |
-
|
| 8510 |
-
} elseif ( ! empty( $field['pick_post_status'] ) ) {
|
| 8511 |
-
$post_status = (array) $field['pick_post_status'];
|
| 8512 |
-
}
|
| 8513 |
|
| 8514 |
-
|
| 8515 |
-
|
| 8516 |
-
*
|
| 8517 |
-
* Use to change "default" post status from publish to any other status or statuses.
|
| 8518 |
-
*
|
| 8519 |
-
* @param array $post_status List of post statuses. Default is 'publish' or field setting (if available).
|
| 8520 |
-
* @param string $post_type Post type of current object.
|
| 8521 |
-
* @param array $info Array of information about the object.
|
| 8522 |
-
* @param string $object Type of object.
|
| 8523 |
-
* @param string $name Name of pod to load.
|
| 8524 |
-
* @param array $pod Array with Pod information. Result of PodsAPI::load_pod().
|
| 8525 |
-
* @param array $field Array with field information.
|
| 8526 |
-
*
|
| 8527 |
-
* @since unknown
|
| 8528 |
-
*/
|
| 8529 |
-
$post_status = apply_filters( 'pods_api_get_table_info_default_post_status', $post_status, $post_type, $info, $object_type, $object, $name, $pod, $field );
|
| 8530 |
-
|
| 8531 |
-
$info['where'] = array(
|
| 8532 |
-
//'post_status' => '`t`.`post_status` IN ( "inherit", "publish" )', // @todo Figure out what statuses Attachments can be
|
| 8533 |
-
'post_type' => '`t`.`' . $info['field_type'] . '` = "' . $post_type . '"'
|
| 8534 |
-
);
|
| 8535 |
|
| 8536 |
-
|
| 8537 |
-
$info['where_default'] = '`t`.`post_status` IN ( "' . implode( '", "', $post_status ) . '" )';
|
| 8538 |
-
}
|
| 8539 |
|
| 8540 |
-
|
| 8541 |
-
|
| 8542 |
-
/*
|
| 8543 |
-
* @todo wpml-comp Check if WPML filters can be applied afterwards
|
| 8544 |
-
*/
|
| 8545 |
-
// WPML support
|
| 8546 |
-
if ( did_action( 'wpml_loaded' ) && ! empty( $current_language ) && apply_filters( 'wpml_is_translated_post_type', false, $post_type ) && apply_filters( 'wpml_setting', true, 'auto_adjust_ids' ) ) {
|
| 8547 |
-
$info['join']['wpml_translations'] = "
|
| 8548 |
-
LEFT JOIN `{$wpdb->prefix}icl_translations` AS `wpml_translations`
|
| 8549 |
-
ON `wpml_translations`.`element_id` = `t`.`ID`
|
| 8550 |
-
AND `wpml_translations`.`element_type` = 'post_{$post_type}'
|
| 8551 |
-
AND `wpml_translations`.`language_code` = '{$current_language}'
|
| 8552 |
-
";
|
| 8553 |
-
|
| 8554 |
-
$info['join']['wpml_languages'] = "
|
| 8555 |
-
LEFT JOIN `{$wpdb->prefix}icl_languages` AS `wpml_languages`
|
| 8556 |
-
ON `wpml_languages`.`code` = `wpml_translations`.`language_code` AND `wpml_languages`.`active` = 1
|
| 8557 |
-
";
|
| 8558 |
-
|
| 8559 |
-
$info['where']['wpml_languages'] = "`wpml_languages`.`code` IS NOT NULL";
|
| 8560 |
-
} elseif ( ( function_exists( 'PLL' ) || is_object( $polylang ) ) && ! empty( $current_language ) && function_exists( 'pll_is_translated_post_type' ) && pll_is_translated_post_type( $post_type ) ) {
|
| 8561 |
-
// Polylang support
|
| 8562 |
-
$info['join']['polylang_languages'] = "
|
| 8563 |
-
LEFT JOIN `{$wpdb->term_relationships}` AS `polylang_languages`
|
| 8564 |
-
ON `polylang_languages`.`object_id` = `t`.`ID`
|
| 8565 |
-
AND `polylang_languages`.`term_taxonomy_id` = {$current_language_tt_id}
|
| 8566 |
-
";
|
| 8567 |
-
|
| 8568 |
-
$info['where']['polylang_languages'] = "`polylang_languages`.`object_id` IS NOT NULL";
|
| 8569 |
-
}
|
| 8570 |
|
| 8571 |
-
|
| 8572 |
-
|
| 8573 |
-
|
| 8574 |
-
|
| 8575 |
-
|
| 8576 |
-
|
| 8577 |
-
|
| 8578 |
-
|
| 8579 |
-
|
| 8580 |
-
|
| 8581 |
-
|
| 8582 |
-
|
| 8583 |
-
|
| 8584 |
-
|
| 8585 |
-
|
| 8586 |
-
|
| 8587 |
-
|
| 8588 |
-
|
| 8589 |
-
|
| 8590 |
-
|
| 8591 |
-
|
| 8592 |
-
|
| 8593 |
-
|
| 8594 |
-
|
| 8595 |
-
|
| 8596 |
-
|
| 8597 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8598 |
|
| 8599 |
-
|
| 8600 |
-
|
| 8601 |
-
} elseif ( 'post_format' === $object_type ) {
|
| 8602 |
-
$object = 'post_format';
|
| 8603 |
-
}
|
| 8604 |
|
| 8605 |
-
|
| 8606 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8607 |
|
| 8608 |
-
|
| 8609 |
-
|
| 8610 |
-
$name = substr( $object_type, strlen( $prefix ), strlen( $object_type ) );
|
| 8611 |
-
}
|
| 8612 |
-
}
|
| 8613 |
|
| 8614 |
-
|
| 8615 |
-
|
| 8616 |
-
|
|
|
|
| 8617 |
|
| 8618 |
-
|
| 8619 |
|
| 8620 |
-
|
|
|
|
|
|
|
|
|
|
| 8621 |
|
| 8622 |
-
|
| 8623 |
|
| 8624 |
-
|
| 8625 |
-
|
| 8626 |
-
}
|
| 8627 |
|
| 8628 |
-
|
| 8629 |
-
|
| 8630 |
-
);
|
| 8631 |
|
| 8632 |
-
|
| 8633 |
-
|
| 8634 |
-
* @todo wpml-comp Check if WPML filters can be applied afterwards
|
| 8635 |
-
*/
|
| 8636 |
-
// WPML Support
|
| 8637 |
-
if ( is_object( $sitepress ) && ! empty( $current_language ) && $sitepress->is_translated_taxonomy( $taxonomy ) && apply_filters( 'wpml_setting', true, 'auto_adjust_ids' ) ) {
|
| 8638 |
-
$info['join']['wpml_translations'] = "
|
| 8639 |
-
LEFT JOIN `{$wpdb->prefix}icl_translations` AS `wpml_translations`
|
| 8640 |
-
ON `wpml_translations`.`element_id` = `tt`.`term_taxonomy_id`
|
| 8641 |
-
AND `wpml_translations`.`element_type` = 'tax_{$taxonomy}'
|
| 8642 |
-
AND `wpml_translations`.`language_code` = '{$current_language}'
|
| 8643 |
-
";
|
| 8644 |
-
|
| 8645 |
-
$info['join']['wpml_languages'] = "
|
| 8646 |
-
LEFT JOIN `{$wpdb->prefix}icl_languages` AS `wpml_languages`
|
| 8647 |
-
ON `wpml_languages`.`code` = `wpml_translations`.`language_code` AND `wpml_languages`.`active` = 1
|
| 8648 |
-
";
|
| 8649 |
-
|
| 8650 |
-
$info['where']['wpml_languages'] = "`wpml_languages`.`code` IS NOT NULL";
|
| 8651 |
-
} elseif ( ( function_exists( 'PLL' ) || is_object( $polylang ) ) && ! empty( $current_language ) && ! empty( $current_language_tl_tt_id ) && function_exists( 'pll_is_translated_taxonomy' ) && pll_is_translated_taxonomy( $taxonomy ) ) {
|
| 8652 |
-
// Polylang support
|
| 8653 |
-
$info['join']['polylang_languages'] = "
|
| 8654 |
-
LEFT JOIN `{$wpdb->term_relationships}` AS `polylang_languages`
|
| 8655 |
-
ON `polylang_languages`.`object_id` = `t`.`term_id`
|
| 8656 |
-
AND `polylang_languages`.`term_taxonomy_id` = {$current_language_tl_tt_id}
|
| 8657 |
-
";
|
| 8658 |
-
|
| 8659 |
-
$info['where']['polylang_languages'] = "`polylang_languages`.`object_id` IS NOT NULL";
|
| 8660 |
-
}
|
| 8661 |
|
| 8662 |
-
|
| 8663 |
-
|
| 8664 |
-
$info['table'] = $wpdb->users;
|
| 8665 |
-
$info['meta_table'] = $wpdb->usermeta;
|
| 8666 |
-
$info['pod_table'] = $wpdb->prefix . 'pods_user';
|
| 8667 |
|
| 8668 |
-
|
| 8669 |
-
|
| 8670 |
-
$info['field_slug'] = 'user_nicename';
|
| 8671 |
|
| 8672 |
-
|
| 8673 |
-
|
| 8674 |
-
|
| 8675 |
|
| 8676 |
-
|
| 8677 |
-
|
| 8678 |
-
);
|
| 8679 |
|
| 8680 |
-
|
| 8681 |
-
|
| 8682 |
-
|
|
|
|
| 8683 |
|
| 8684 |
-
|
| 8685 |
-
|
| 8686 |
-
|
| 8687 |
|
| 8688 |
-
|
| 8689 |
-
|
| 8690 |
-
$info['field_type'] = 'comment_type';
|
| 8691 |
-
$info['field_parent'] = 'comment_parent';
|
| 8692 |
-
$info['field_parent_select'] = '`t`.`' . $info['field_parent'] . '`';
|
| 8693 |
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8712 |
|
| 8713 |
-
|
| 8714 |
-
|
| 8715 |
-
|
| 8716 |
-
|
| 8717 |
-
|
| 8718 |
-
|
| 8719 |
-
|
| 8720 |
-
|
| 8721 |
-
|
| 8722 |
-
$info['field_index'] = 'option_name';
|
| 8723 |
-
|
| 8724 |
-
$info['meta_field_id'] = 'option_id';
|
| 8725 |
-
$info['meta_field_index'] = 'option_name';
|
| 8726 |
-
$info['meta_field_value'] = 'option_value';
|
| 8727 |
-
|
| 8728 |
-
$info['orderby'] = '`t`.`' . $info['field_index'] . '` ASC';
|
| 8729 |
-
} elseif ( is_multisite() && ( in_array( $object_type, array(
|
| 8730 |
-
'site_option',
|
| 8731 |
-
'site_settings'
|
| 8732 |
-
) ) || 'site_settings' === pods_var_raw( 'type', $info['pod'] ) ) ) {
|
| 8733 |
-
$info['table'] = $wpdb->sitemeta;
|
| 8734 |
-
$info['meta_table'] = $wpdb->sitemeta;
|
| 8735 |
-
|
| 8736 |
-
$info['field_id'] = 'site_id';
|
| 8737 |
-
$info['field_index'] = 'meta_key';
|
| 8738 |
-
|
| 8739 |
-
$info['meta_field_id'] = 'site_id';
|
| 8740 |
-
$info['meta_field_index'] = 'meta_key';
|
| 8741 |
-
$info['meta_field_value'] = 'meta_value';
|
| 8742 |
-
|
| 8743 |
-
$info['orderby'] = '`t`.`' . $info['field_index'] . '` ASC';
|
| 8744 |
-
} elseif ( is_multisite() && 'network' === $object_type ) { // Network = Site
|
| 8745 |
-
$info['table'] = $wpdb->site;
|
| 8746 |
-
$info['meta_table'] = $wpdb->sitemeta;
|
| 8747 |
-
|
| 8748 |
-
$info['field_id'] = 'id';
|
| 8749 |
-
$info['field_index'] = 'domain';
|
| 8750 |
-
|
| 8751 |
-
$info['meta_field_id'] = 'site_id';
|
| 8752 |
-
$info['meta_field_index'] = 'meta_key';
|
| 8753 |
-
$info['meta_field_value'] = 'meta_value';
|
| 8754 |
-
|
| 8755 |
-
$info['orderby'] = '`t`.`' . $info['field_index'] . '` ASC, `t`.`path` ASC, `t`.`' . $info['field_id'] . '`';
|
| 8756 |
-
} elseif ( is_multisite() && 'site' === $object_type ) { // Site = Blog
|
| 8757 |
-
$info['table'] = $wpdb->blogs;
|
| 8758 |
-
|
| 8759 |
-
$info['field_id'] = 'blog_id';
|
| 8760 |
-
$info['field_index'] = 'domain';
|
| 8761 |
-
$info['field_type'] = 'site_id';
|
| 8762 |
-
|
| 8763 |
-
$info['where'] = array(
|
| 8764 |
-
'archived' => '`t`.`archived` = 0',
|
| 8765 |
-
'spam' => '`t`.`spam` = 0',
|
| 8766 |
-
'deleted' => '`t`.`deleted` = 0',
|
| 8767 |
-
'site_id' => '`t`.`' . $info['field_type'] . '` = ' . (int) get_current_site()->id
|
| 8768 |
-
);
|
| 8769 |
|
| 8770 |
-
|
| 8771 |
-
|
| 8772 |
-
|
| 8773 |
-
|
| 8774 |
|
|
|
|
| 8775 |
|
| 8776 |
-
|
| 8777 |
-
if ( ! is_array( $field ) ) {
|
| 8778 |
-
if ( is_string( $pod ) ) {
|
| 8779 |
-
$pod = pods( $pod );
|
| 8780 |
-
}
|
| 8781 |
-
if ( $pod && ! empty( $pod->fields[ $field ] ) ) {
|
| 8782 |
-
$field = $pod->fields[ $field ];
|
| 8783 |
-
}
|
| 8784 |
-
}
|
| 8785 |
-
if ( is_array( $field ) ) {
|
| 8786 |
-
$info['table'] = pods_var_raw( 'pick_table', pods_var_raw( 'options', $field, $field ) );
|
| 8787 |
-
$info['field_id'] = pods_var_raw( 'pick_table_id', pods_var_raw( 'options', $field, $field ) );
|
| 8788 |
-
$info['meta_field_value'] = pods_var_raw( 'pick_table_index', pods_var_raw( 'options', $field, $field ) );
|
| 8789 |
-
$info['field_index'] = $info['meta_field_value'];
|
| 8790 |
-
$info['meta_field_index'] = $info['meta_field_value'];
|
| 8791 |
-
}
|
| 8792 |
-
}
|
| 8793 |
-
}
|
| 8794 |
|
| 8795 |
-
|
| 8796 |
-
|
| 8797 |
-
|
|
|
|
|
|
|
|
|
|
| 8798 |
|
| 8799 |
-
|
| 8800 |
-
|
| 8801 |
-
$info['field_slug'] = pods_clean_name( $info['field_slug'], false, false );
|
| 8802 |
|
| 8803 |
-
|
| 8804 |
-
|
| 8805 |
-
$info['meta_field_value'] = pods_clean_name( $info['meta_field_value'], false, false );
|
| 8806 |
|
| 8807 |
-
|
| 8808 |
-
|
| 8809 |
-
}
|
| 8810 |
|
| 8811 |
-
|
| 8812 |
-
|
| 8813 |
-
'table'
|
| 8814 |
-
) ) ) {
|
| 8815 |
-
$info['join']['d'] = 'LEFT JOIN `' . $info['pod_table'] . '` AS `d` ON `d`.`id` = `t`.`' . $info['field_id'] . '`';
|
| 8816 |
-
//$info[ 'select' ] .= ', `d`.*';
|
| 8817 |
-
}
|
| 8818 |
|
| 8819 |
-
|
| 8820 |
-
|
| 8821 |
-
}
|
| 8822 |
|
| 8823 |
-
|
| 8824 |
-
|
| 8825 |
|
| 8826 |
-
|
| 8827 |
-
|
| 8828 |
-
|
| 8829 |
-
}
|
| 8830 |
|
| 8831 |
-
|
| 8832 |
-
|
| 8833 |
-
}
|
| 8834 |
-
}
|
| 8835 |
|
| 8836 |
-
|
| 8837 |
|
| 8838 |
-
|
| 8839 |
-
|
| 8840 |
|
| 8841 |
-
|
| 8842 |
-
|
| 8843 |
-
*
|
| 8844 |
-
* $params['pods'] array Pod Type IDs to export
|
| 8845 |
-
* $params['templates'] array Template IDs to export
|
| 8846 |
-
* $params['pages'] array Pod Page IDs to export
|
| 8847 |
-
* $params['helpers'] array Helper IDs to export
|
| 8848 |
-
*
|
| 8849 |
-
* @param array $params An associative array of parameters
|
| 8850 |
-
*
|
| 8851 |
-
* @return array|bool
|
| 8852 |
-
*
|
| 8853 |
-
* @since 1.9.0
|
| 8854 |
-
* @deprecated 2.0.0
|
| 8855 |
-
*/
|
| 8856 |
-
public function export_package( $params ) {
|
| 8857 |
|
| 8858 |
-
|
| 8859 |
-
|
| 8860 |
-
}
|
| 8861 |
|
| 8862 |
-
|
| 8863 |
-
|
|
|
|
|
|
|
| 8864 |
|
| 8865 |
-
|
| 8866 |
-
|
| 8867 |
-
*
|
| 8868 |
-
* @param mixed $data (optional) An associative array containing a package, or the json encoded package
|
| 8869 |
-
*
|
| 8870 |
-
* @return bool
|
| 8871 |
-
*
|
| 8872 |
-
* @since 1.9.8
|
| 8873 |
-
* @deprecated 2.0.0
|
| 8874 |
-
*/
|
| 8875 |
-
public function replace_package( $data = false ) {
|
| 8876 |
|
| 8877 |
-
|
| 8878 |
-
|
| 8879 |
|
| 8880 |
-
|
| 8881 |
-
|
| 8882 |
-
*
|
| 8883 |
-
* @param mixed $data (optional) An associative array containing a package, or the json encoded package
|
| 8884 |
-
* @param bool $replace (optional) Replace existing items when found
|
| 8885 |
-
*
|
| 8886 |
-
* @return bool
|
| 8887 |
-
*
|
| 8888 |
-
* @since 1.9.0
|
| 8889 |
-
* @deprecated 2.0.0
|
| 8890 |
-
*/
|
| 8891 |
-
public function import_package( $data = false, $replace = false ) {
|
| 8892 |
|
| 8893 |
-
if ( class_exists( 'Pods_Migrate_Packages' ) ) {
|
| 8894 |
-
return Pods_Migrate_Packages::import( $data, $replace );
|
| 8895 |
-
}
|
| 8896 |
|
| 8897 |
-
|
| 8898 |
-
}
|
| 8899 |
|
| 8900 |
-
|
| 8901 |
-
|
| 8902 |
-
|
| 8903 |
-
|
| 8904 |
-
* @param bool $output (optional)
|
| 8905 |
-
*
|
| 8906 |
-
* @return array|bool
|
| 8907 |
-
*
|
| 8908 |
-
* @since 1.9.0
|
| 8909 |
-
* @deprecated 2.0.0
|
| 8910 |
-
*/
|
| 8911 |
-
public function validate_package( $data = false, $output = false ) {
|
| 8912 |
|
| 8913 |
-
|
| 8914 |
-
|
| 8915 |
|
| 8916 |
-
|
| 8917 |
-
|
| 8918 |
-
*
|
| 8919 |
-
* @param mixed $import_data PHP associative array or CSV input
|
| 8920 |
-
* @param bool $numeric_mode Use IDs instead of the name field when matching
|
| 8921 |
-
* @param string $format Format of import data, options are php or csv
|
| 8922 |
-
*
|
| 8923 |
-
* @return array IDs of imported items
|
| 8924 |
-
*
|
| 8925 |
-
* @since 1.7.1
|
| 8926 |
-
* @todo This needs some love and use of table_info etc for relationships
|
| 8927 |
-
*/
|
| 8928 |
-
public function import( $import_data, $numeric_mode = false, $format = null ) {
|
| 8929 |
|
| 8930 |
-
|
| 8931 |
-
|
| 8932 |
-
|
| 8933 |
-
|
|
|
|
| 8934 |
|
| 8935 |
-
|
| 8936 |
-
$format = $this->format;
|
| 8937 |
-
}
|
| 8938 |
|
| 8939 |
-
|
| 8940 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8941 |
|
| 8942 |
-
|
|
|
|
|
|
|
| 8943 |
}
|
| 8944 |
|
| 8945 |
-
|
| 8946 |
-
pods_query( "SET CHARACTER SET utf8" );
|
| 8947 |
|
| 8948 |
-
|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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8950 |
|
| 8951 |
-
|
| 8952 |
-
if ( ! is_array( @current( $import_data ) ) ) {
|
| 8953 |
-
$import_data = array( $import_data );
|
| 8954 |
-
}
|
| 8955 |
|
| 8956 |
-
|
|
|
|
| 8957 |
|
| 8958 |
-
|
| 8959 |
-
|
| 8960 |
-
}
|
| 8961 |
|
| 8962 |
-
|
|
|
|
|
|
|
|
|
|
| 8963 |
|
| 8964 |
-
|
|
|
|
|
|
|
|
|
|
| 8965 |
|
| 8966 |
-
|
| 8967 |
-
|
|
|
|
|
|
|
| 8968 |
|
| 8969 |
-
|
| 8970 |
-
|
| 8971 |
-
|
| 8972 |
-
|
| 8973 |
-
}
|
| 8974 |
|
| 8975 |
-
|
| 8976 |
-
$type = $field_data['type'];
|
| 8977 |
-
$pick_object = isset( $field_data['pick_object'] ) ? $field_data['pick_object'] : '';
|
| 8978 |
-
$pick_val = isset( $field_data['pick_val'] ) ? $field_data['pick_val'] : '';
|
| 8979 |
|
| 8980 |
-
|
| 8981 |
-
|
| 8982 |
-
} else {
|
| 8983 |
-
$field_value = $data_row[ $field_data['label'] ];
|
| 8984 |
-
}
|
| 8985 |
|
| 8986 |
-
|
| 8987 |
-
|
| 8988 |
-
|
| 8989 |
-
$pick_values = array();
|
| 8990 |
|
| 8991 |
-
|
| 8992 |
-
|
| 8993 |
-
$where = "`guid` = '" . pods_sanitize( $pick_value ) . "'";
|
| 8994 |
|
| 8995 |
-
|
| 8996 |
-
$where = "`ID` = " . pods_absint( $pick_value );
|
| 8997 |
-
}
|
| 8998 |
|
| 8999 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9000 |
|
| 9001 |
-
|
| 9002 |
-
$pick_values[] = $result[0]->id;
|
| 9003 |
-
}
|
| 9004 |
-
} elseif ( 'pick' === $type ) {
|
| 9005 |
-
// @todo This could and should be abstracted better and simplified
|
| 9006 |
-
$related_pod = false;
|
| 9007 |
-
|
| 9008 |
-
if ( 'pod' === $pick_object ) {
|
| 9009 |
-
$related_pod = $this->load_pod( array(
|
| 9010 |
-
'name' => $pick_val,
|
| 9011 |
-
'table_info' => true
|
| 9012 |
-
), false );
|
| 9013 |
-
}
|
| 9014 |
|
| 9015 |
-
|
| 9016 |
-
|
| 9017 |
-
|
| 9018 |
-
|
| 9019 |
-
);
|
| 9020 |
-
}
|
| 9021 |
|
| 9022 |
-
|
| 9023 |
-
$where = "`t`.`name` = '" . pods_sanitize( $pick_value ) . "'";
|
| 9024 |
|
| 9025 |
-
|
| 9026 |
-
$where = "`tt`.`term_id` = " . pods_absint( $pick_value );
|
| 9027 |
-
}
|
| 9028 |
|
| 9029 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9030 |
|
| 9031 |
-
|
| 9032 |
-
|
| 9033 |
-
}
|
| 9034 |
-
} elseif ( in_array( 'post_type', array(
|
| 9035 |
-
$pick_object,
|
| 9036 |
-
$related_pod['type']
|
| 9037 |
-
) ) || in_array( 'media', array( $pick_object, $related_pod['type'] ) ) ) {
|
| 9038 |
-
$where = "`post_title` = '" . pods_sanitize( $pick_value ) . "'";
|
| 9039 |
-
|
| 9040 |
-
if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode ) {
|
| 9041 |
-
$where = "`ID` = " . pods_absint( $pick_value );
|
| 9042 |
-
}
|
| 9043 |
|
| 9044 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9045 |
|
| 9046 |
-
|
| 9047 |
-
|
| 9048 |
-
|
| 9049 |
-
|
| 9050 |
-
$where = "`user_login` = '" . pods_sanitize( $pick_value ) . "'";
|
| 9051 |
|
| 9052 |
-
|
| 9053 |
-
$where = "`ID` = " . pods_absint( $pick_value );
|
| 9054 |
-
}
|
| 9055 |
|
| 9056 |
-
|
| 9057 |
|
| 9058 |
-
|
| 9059 |
-
|
| 9060 |
-
}
|
| 9061 |
-
} elseif ( in_array( 'comment', array( $pick_object, $related_pod['type'] ) ) ) {
|
| 9062 |
-
$where = "`comment_ID` = " . pods_absint( $pick_value );
|
| 9063 |
|
| 9064 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9065 |
|
| 9066 |
-
|
| 9067 |
-
$pick_values[] = $result[0]->id;
|
| 9068 |
-
}
|
| 9069 |
-
} elseif ( in_array( $pick_object, $simple_tableless_objects ) ) {
|
| 9070 |
-
$pick_values[] = $pick_value;
|
| 9071 |
-
} elseif ( ! empty( $related_pod['id'] ) ) {
|
| 9072 |
-
$where = "`" . $related_pod['field_index'] . "` = '" . pods_sanitize( $pick_value ) . "'";
|
| 9073 |
|
| 9074 |
-
|
| 9075 |
-
|
| 9076 |
-
}
|
| 9077 |
|
| 9078 |
-
|
|
|
|
| 9079 |
|
| 9080 |
-
|
| 9081 |
-
|
| 9082 |
-
}
|
| 9083 |
-
}
|
| 9084 |
-
}
|
| 9085 |
-
}
|
| 9086 |
|
| 9087 |
-
|
| 9088 |
-
|
| 9089 |
|
| 9090 |
-
|
| 9091 |
-
}
|
| 9092 |
-
}
|
| 9093 |
|
| 9094 |
-
|
| 9095 |
-
$params = array(
|
| 9096 |
-
'pod' => $this->pod,
|
| 9097 |
-
'data' => $data
|
| 9098 |
-
);
|
| 9099 |
|
| 9100 |
-
|
| 9101 |
-
}
|
| 9102 |
-
}
|
| 9103 |
|
| 9104 |
-
|
| 9105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9106 |
|
| 9107 |
-
|
| 9108 |
-
|
| 9109 |
-
*
|
| 9110 |
-
* @param string|object $pod The pod name or Pods object
|
| 9111 |
-
* @param array $params An associative array of parameters
|
| 9112 |
-
*
|
| 9113 |
-
* @return array Data arrays of all exported pod items
|
| 9114 |
-
* @since 1.7.1
|
| 9115 |
-
*/
|
| 9116 |
-
public function export( $pod = null, $params = null ) {
|
| 9117 |
|
| 9118 |
-
|
| 9119 |
-
|
| 9120 |
-
}
|
| 9121 |
|
| 9122 |
-
|
| 9123 |
-
|
| 9124 |
-
|
| 9125 |
-
'pagination' => false
|
| 9126 |
-
);
|
| 9127 |
|
| 9128 |
-
|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171 |
-
|
| 9172 |
-
|
| 9173 |
-
* @return void
|
| 9174 |
-
*
|
| 9175 |
-
* @since 2.0.0
|
| 9176 |
-
*/
|
| 9177 |
-
public function cache_flush_pods( $pod = null ) {
|
| 9178 |
|
| 9179 |
-
|
| 9180 |
-
* @var $wpdb wpdb
|
| 9181 |
-
*/
|
| 9182 |
-
global $wpdb;
|
| 9183 |
|
| 9184 |
-
|
| 9185 |
-
pods_transient_clear( 'pods_components' );
|
| 9186 |
|
| 9187 |
-
|
| 9188 |
-
|
| 9189 |
-
pods_cache_clear( $pod['name'], 'pods-class' );
|
| 9190 |
|
| 9191 |
-
|
| 9192 |
-
pods_transient_clear( 'pods_field_' . $pod['name'] . '_' . $field['name'] );
|
| 9193 |
-
}
|
| 9194 |
|
| 9195 |
-
|
| 9196 |
-
|
| 9197 |
-
}
|
| 9198 |
-
} else {
|
| 9199 |
-
pods_transient_clear( 'pods_wp_cpt_ct' );
|
| 9200 |
}
|
| 9201 |
|
| 9202 |
-
|
| 9203 |
-
|
| 9204 |
-
$wpdb->query( "DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE '_transient_timeout_pods%'" );
|
| 9205 |
|
| 9206 |
-
|
| 9207 |
-
$wpdb->query( "DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE '_pods_option_%'" );
|
| 9208 |
|
| 9209 |
-
|
|
|
|
| 9210 |
|
| 9211 |
-
|
|
|
|
|
|
|
| 9212 |
|
| 9213 |
-
|
| 9214 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9215 |
|
| 9216 |
/**
|
| 9217 |
-
* Process a Pod-based form
|
| 9218 |
*
|
| 9219 |
-
*
|
| 9220 |
-
*
|
| 9221 |
-
* @param
|
| 9222 |
-
* @param string $
|
|
|
|
|
|
|
| 9223 |
*
|
| 9224 |
-
* @return
|
| 9225 |
*
|
| 9226 |
-
* @since 2.
|
| 9227 |
*/
|
| 9228 |
-
public function
|
|
|
|
|
|
|
| 9229 |
|
| 9230 |
-
$
|
|
|
|
|
|
|
| 9231 |
|
| 9232 |
-
|
|
|
|
|
|
|
|
|
|
| 9233 |
|
| 9234 |
-
|
| 9235 |
-
|
| 9236 |
-
$id = pods_var( '_pods_id', $params );
|
| 9237 |
-
$uri = pods_var( '_pods_uri', $params );
|
| 9238 |
-
$form = pods_var( '_pods_form', $params );
|
| 9239 |
-
$location = pods_var( '_pods_location', $params );
|
| 9240 |
|
| 9241 |
-
|
| 9242 |
-
$pod = $obj->pod;
|
| 9243 |
-
$id = $obj->id();
|
| 9244 |
-
}
|
| 9245 |
|
| 9246 |
-
|
| 9247 |
-
|
| 9248 |
-
|
| 9249 |
-
|
| 9250 |
-
$fields = explode( ',', $form );
|
| 9251 |
-
}
|
| 9252 |
|
| 9253 |
-
|
| 9254 |
-
|
| 9255 |
}
|
|
|
|
|
|
|
|
|
|
| 9256 |
|
| 9257 |
-
|
|
|
|
|
|
|
|
|
|
| 9258 |
|
| 9259 |
-
|
| 9260 |
-
|
| 9261 |
-
}
|
| 9262 |
|
| 9263 |
-
|
|
|
|
| 9264 |
|
| 9265 |
-
|
|
|
|
|
|
|
|
|
|
| 9266 |
|
| 9267 |
-
|
| 9268 |
-
|
|
|
|
| 9269 |
}
|
|
|
|
|
|
|
| 9270 |
|
| 9271 |
-
if (
|
| 9272 |
-
|
| 9273 |
-
|
| 9274 |
|
| 9275 |
-
|
|
|
|
|
|
|
|
|
|
| 9276 |
|
| 9277 |
-
|
| 9278 |
-
|
| 9279 |
-
}
|
| 9280 |
|
| 9281 |
-
|
| 9282 |
-
'pod' => $pod,
|
| 9283 |
-
'id' => $id,
|
| 9284 |
-
'data' => $data,
|
| 9285 |
-
'from' => 'process_form',
|
| 9286 |
-
'location' => $location
|
| 9287 |
-
);
|
| 9288 |
|
| 9289 |
-
|
|
|
|
| 9290 |
|
| 9291 |
-
|
| 9292 |
-
|
| 9293 |
-
|
| 9294 |
-
|
| 9295 |
-
|
| 9296 |
-
|
| 9297 |
-
|
| 9298 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9299 |
|
| 9300 |
-
|
| 9301 |
-
|
| 9302 |
-
if ( 0 < $id && ! empty( $thank_you ) ) {
|
| 9303 |
-
$thank_you = str_replace( 'X_ID_X', $id, $thank_you );
|
| 9304 |
|
| 9305 |
-
|
| 9306 |
-
|
| 9307 |
-
}
|
| 9308 |
|
| 9309 |
-
|
| 9310 |
-
|
| 9311 |
|
| 9312 |
-
|
| 9313 |
-
|
| 9314 |
-
*
|
| 9315 |
-
* @since 2.0.0
|
| 9316 |
-
*/
|
| 9317 |
-
private function do_hook() {
|
| 9318 |
|
| 9319 |
-
|
| 9320 |
-
|
| 9321 |
-
|
|
|
|
|
|
|
| 9322 |
}
|
| 9323 |
-
|
| 9324 |
-
|
| 9325 |
-
return pods_do_hook( "api", $name, $args, $this );
|
| 9326 |
}
|
| 9327 |
|
| 9328 |
-
|
| 9329 |
-
|
| 9330 |
-
|
| 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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9361 |
|
| 9362 |
-
$
|
| 9363 |
|
| 9364 |
-
|
| 9365 |
-
require_once( PODS_DIR . 'deprecated/classes/PodsAPI.php' );
|
| 9366 |
-
$this->deprecated = new PodsAPI_Deprecated( $this );
|
| 9367 |
-
}
|
| 9368 |
|
| 9369 |
-
|
| 9370 |
-
|
| 9371 |
-
} else {
|
| 9372 |
-
pods_deprecated( "PodsAPI::{$name}", '2.0' );
|
| 9373 |
-
}
|
| 9374 |
-
}
|
| 9375 |
|
| 9376 |
-
|
| 9377 |
-
|
| 9378 |
-
*
|
| 9379 |
-
* @param array $values
|
| 9380 |
-
*
|
| 9381 |
-
* @return array
|
| 9382 |
-
*
|
| 9383 |
-
* @since 2.6.10
|
| 9384 |
-
*/
|
| 9385 |
-
private function array_filter_walker( $values = array() ) {
|
| 9386 |
-
|
| 9387 |
-
$values = (array) $values;
|
| 9388 |
-
|
| 9389 |
-
foreach ( $values as $k => $v ) {
|
| 9390 |
-
if ( is_object( $v ) ) {
|
| 9391 |
-
// Skip objects
|
| 9392 |
-
continue;
|
| 9393 |
-
} elseif ( is_array( $v ) ) {
|
| 9394 |
-
if ( empty( $v ) ) {
|
| 9395 |
-
// Filter values with empty arrays
|
| 9396 |
-
unset( $values[ $k ] );
|
| 9397 |
-
}
|
| 9398 |
-
} else {
|
| 9399 |
-
if ( ! $v ) {
|
| 9400 |
-
// Filter empty values
|
| 9401 |
-
unset( $values[ $k ] );
|
| 9402 |
-
}
|
| 9403 |
-
}
|
| 9404 |
-
}
|
| 9405 |
|
| 9406 |
-
|
| 9407 |
|
| 9408 |
-
|
|
|
|
|
|
|
| 9409 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9410 |
}
|
| 1 |
<?php
|
|
|
|
| 2 |
/**
|
| 3 |
* @package Pods
|
| 4 |
*/
|
| 5 |
class PodsAPI {
|
| 6 |
|
| 7 |
+
/**
|
| 8 |
+
* @var PodsAPI
|
| 9 |
+
*/
|
| 10 |
+
static $instance = null;
|
| 11 |
|
| 12 |
/**
|
| 13 |
* @var array PodsAPI
|
| 14 |
*/
|
| 15 |
static $instances = array();
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
/**
|
| 19 |
+
* @var bool
|
| 20 |
+
*/
|
| 21 |
+
public $display_errors = false;
|
| 22 |
|
| 23 |
+
/**
|
| 24 |
+
* @var array|bool|mixed|null|void
|
| 25 |
+
*/
|
| 26 |
+
public $pod_data;
|
| 27 |
|
| 28 |
+
/**
|
| 29 |
+
* @var
|
| 30 |
+
*/
|
| 31 |
+
public $pod;
|
| 32 |
|
| 33 |
+
/**
|
| 34 |
+
* @var
|
| 35 |
+
*/
|
| 36 |
+
public $pod_id;
|
| 37 |
|
| 38 |
+
/**
|
| 39 |
+
* @var
|
| 40 |
+
*/
|
| 41 |
+
public $fields;
|
|
|
|
| 42 |
|
| 43 |
+
/**
|
| 44 |
+
* @var
|
| 45 |
+
* @deprecated 2.0
|
| 46 |
+
*/
|
| 47 |
+
public $format = null;
|
| 48 |
+
|
| 49 |
+
/**
|
| 50 |
+
* @var
|
| 51 |
+
*/
|
| 52 |
+
private $deprecated;
|
| 53 |
|
| 54 |
/**
|
| 55 |
* @var array
|
| 56 |
+
* @since 2.5
|
| 57 |
*/
|
| 58 |
private $fields_cache = array();
|
| 59 |
|
| 60 |
/**
|
| 61 |
* @var array
|
| 62 |
+
* @since 2.5
|
| 63 |
*
|
| 64 |
*/
|
| 65 |
private static $table_info_cache = array();
|
| 66 |
|
| 67 |
/**
|
| 68 |
* @var array
|
| 69 |
+
* @since 2.5
|
| 70 |
*
|
| 71 |
*/
|
| 72 |
private static $related_item_cache = array();
|
| 73 |
|
| 74 |
/**
|
| 75 |
+
* Singleton-ish handling for a basic pods_api() request
|
| 76 |
+
*
|
| 77 |
+
* @param string $pod (optional) The pod name
|
| 78 |
+
* @param string $format (deprecated) Format for import/export, "php" or "csv"
|
| 79 |
+
*
|
| 80 |
+
* @return \PodsAPI
|
| 81 |
+
*
|
| 82 |
+
* @since 2.3.5
|
| 83 |
+
*/
|
| 84 |
+
public static function init ( $pod = null, $format = null ) {
|
|
|
|
| 85 |
if ( null !== $pod || null !== $format ) {
|
| 86 |
if ( ! isset( self::$instances[ $pod ] ) ) {
|
| 87 |
// Cache API singleton per Pod
|
| 88 |
self::$instances[ $pod ] = new PodsAPI( $pod, $format );
|
| 89 |
}
|
|
|
|
| 90 |
return self::$instances[ $pod ];
|
| 91 |
+
}
|
| 92 |
+
elseif ( !is_object( self::$instance ) ) {
|
| 93 |
self::$instance = new PodsAPI();
|
| 94 |
}
|
| 95 |
|
| 96 |
return self::$instance;
|
| 97 |
}
|
| 98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
+
/**
|
| 101 |
+
* Store and retrieve data programatically
|
| 102 |
+
*
|
| 103 |
+
* @param string $pod (optional) The pod name
|
| 104 |
+
* @param string $format (deprecated) Format for import/export, "php" or "csv"
|
| 105 |
+
*
|
| 106 |
+
* @return \PodsAPI
|
| 107 |
+
*
|
| 108 |
+
* @license http://www.gnu.org/licenses/gpl-2.0.html
|
| 109 |
+
* @since 1.7.1
|
| 110 |
+
*/
|
| 111 |
+
public function __construct ( $pod = null, $format = null ) {
|
| 112 |
+
if ( null !== $pod && 0 < strlen( (string) $pod ) ) {
|
| 113 |
+
if ( null !== $format ) {
|
| 114 |
+
$this->format = $format;
|
| 115 |
+
|
| 116 |
+
pods_deprecated( 'pods_api( $pod, $format )', '2.0', 'pods_api( $pod )' );
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
$pod = pods_clean_name( $pod );
|
| 120 |
+
|
| 121 |
+
$pod = $this->load_pod( array( 'name' => $pod, 'table_info' => true ), false );
|
| 122 |
+
|
| 123 |
+
if ( !empty( $pod ) ) {
|
| 124 |
+
$this->pod_data = $pod;
|
| 125 |
+
$this->pod = $pod[ 'name' ];
|
| 126 |
+
$this->pod_id = $pod[ 'id' ];
|
| 127 |
+
$this->fields = $pod[ 'fields' ];
|
| 128 |
+
}
|
| 129 |
+
}
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
/**
|
| 133 |
+
* Save a WP object and its meta
|
| 134 |
+
*
|
| 135 |
+
* @param string $object_type Object type: post|user|comment|setting
|
| 136 |
+
* @param array $data All post data to be saved
|
| 137 |
+
* @param array $meta (optional) Associative array of meta keys and values
|
| 138 |
+
* @param bool $strict (optional) Decides whether the previous saved meta should be deleted or not
|
| 139 |
+
* @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before sending.
|
| 140 |
+
* @param array $fields (optional) The array of fields and their options, for further processing with
|
| 141 |
+
*
|
| 142 |
+
* @return bool|mixed
|
| 143 |
+
*
|
| 144 |
+
* @since 2.0
|
| 145 |
+
*/
|
| 146 |
+
public function save_wp_object ( $object_type, $data, $meta = array(), $strict = false, $sanitized = false, $fields = array() ) {
|
| 147 |
+
if ( in_array( $object_type, array( 'post_type', 'media' ) ) )
|
| 148 |
+
$object_type = 'post';
|
| 149 |
+
|
| 150 |
+
if ( $sanitized ) {
|
| 151 |
+
$data = pods_unsanitize( $data );
|
| 152 |
+
$meta = pods_unsanitize( $meta );
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
if ( in_array( $object_type, array( 'post', 'user', 'comment' ) ) )
|
| 156 |
+
return call_user_func( array( $this, 'save_' . $object_type ), $data, $meta, $strict, false, $fields );
|
| 157 |
+
elseif ( 'settings' == $object_type ) {
|
| 158 |
+
// Nothing to save
|
| 159 |
+
if ( empty( $meta ) )
|
| 160 |
+
return true;
|
| 161 |
+
|
| 162 |
+
return $this->save_setting( pods_var( 'option_id', $data ), $meta, false );
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
return false;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
/**
|
| 169 |
+
* Delete a WP object
|
| 170 |
+
*
|
| 171 |
+
* @param string $object_type Object type: post|user|comment
|
| 172 |
+
* @param int $id Object ID
|
| 173 |
+
* @param bool $force_delete (optional) Force deletion instead of trashing (post types only)
|
| 174 |
+
*
|
| 175 |
+
* @return bool|mixed
|
| 176 |
+
*
|
| 177 |
+
* @since 2.0
|
| 178 |
+
*/
|
| 179 |
+
public function delete_wp_object ( $object_type, $id, $force_delete = true ) {
|
| 180 |
+
if ( in_array( $object_type, array( 'post_type', 'media' ) ) )
|
| 181 |
+
$object_type = 'post';
|
| 182 |
+
|
| 183 |
+
if ( empty( $id ) )
|
| 184 |
+
return false;
|
| 185 |
+
|
| 186 |
+
if ( in_array( $object_type, array( 'post' ) ) )
|
| 187 |
+
return wp_delete_post( $id, $force_delete );
|
| 188 |
+
|
| 189 |
+
if ( function_exists( 'wp_delete_' . $object_type ) )
|
| 190 |
+
return call_user_func( 'wp_delete_' . $object_type, $id );
|
| 191 |
+
|
| 192 |
+
return false;
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
/**
|
| 196 |
+
* Save a post and it's meta
|
| 197 |
+
*
|
| 198 |
+
* @param array $post_data All post data to be saved (using wp_insert_post / wp_update_post)
|
| 199 |
+
* @param array $post_meta (optional) All meta to be saved (set value to null to delete)
|
| 200 |
+
* @param bool $strict (optional) Whether to delete previously saved meta not in $post_meta
|
| 201 |
+
* @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before sending.
|
| 202 |
+
* @param array $fields (optional) The array of fields and their options, for further processing with
|
| 203 |
+
*
|
| 204 |
+
* @return mixed|void
|
| 205 |
+
*
|
| 206 |
+
* @since 2.0
|
| 207 |
+
*/
|
| 208 |
+
public function save_post ( $post_data, $post_meta = null, $strict = false, $sanitized = false, $fields = array() ) {
|
| 209 |
+
$conflicted = pods_no_conflict_check( 'post' );
|
| 210 |
+
|
| 211 |
+
if ( !$conflicted )
|
| 212 |
+
pods_no_conflict_on( 'post' );
|
| 213 |
+
|
| 214 |
+
if ( !is_array( $post_data ) || empty( $post_data ) )
|
| 215 |
+
$post_data = array( 'post_title' => '' );
|
| 216 |
+
|
| 217 |
+
if ( !is_array( $post_meta ) )
|
| 218 |
+
$post_meta = array();
|
| 219 |
+
|
| 220 |
+
if ( $sanitized ) {
|
| 221 |
+
$post_data = pods_unsanitize( $post_data );
|
| 222 |
+
$post_meta = pods_unsanitize( $post_meta );
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
if ( !isset( $post_data[ 'ID' ] ) || empty( $post_data[ 'ID' ] ) )
|
| 226 |
+
$post_data[ 'ID' ] = wp_insert_post( $post_data, true );
|
| 227 |
+
elseif ( 2 < count( $post_data ) || !isset( $post_data[ 'post_type' ] ) )
|
| 228 |
+
wp_update_post( $post_data );
|
| 229 |
+
|
| 230 |
+
if ( is_wp_error( $post_data[ 'ID' ] ) ) {
|
| 231 |
+
if ( !$conflicted )
|
| 232 |
+
pods_no_conflict_off( 'post' );
|
| 233 |
+
|
| 234 |
+
/**
|
| 235 |
+
* @var $post_error WP_Error
|
| 236 |
+
*/
|
| 237 |
+
$post_error = $post_data[ 'ID' ];
|
| 238 |
+
|
| 239 |
+
return pods_error( $post_error->get_error_message(), $this );
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
$this->save_post_meta( $post_data[ 'ID' ], $post_meta, $strict, $fields );
|
| 243 |
+
|
| 244 |
+
if ( !$conflicted )
|
| 245 |
+
pods_no_conflict_off( 'post' );
|
| 246 |
+
|
| 247 |
+
return $post_data[ 'ID' ];
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
/**
|
| 251 |
+
* Save a post's meta
|
| 252 |
+
*
|
| 253 |
+
* @param int $id Post ID
|
| 254 |
+
* @param array $post_meta All meta to be saved (set value to null to delete)
|
| 255 |
+
* @param bool $strict Whether to delete previously saved meta not in $post_meta
|
| 256 |
+
* @param array $fields (optional) The array of fields and their options, for further processing with
|
| 257 |
+
*
|
| 258 |
+
* @return int Id of the post with the meta
|
| 259 |
+
*
|
| 260 |
+
* @since 2.0
|
| 261 |
+
*/
|
| 262 |
+
public function save_post_meta ( $id, $post_meta = null, $strict = false, $fields = array() ) {
|
| 263 |
+
$simple_tableless_objects = PodsForm::simple_tableless_objects();
|
| 264 |
+
|
| 265 |
+
$conflicted = pods_no_conflict_check( 'post' );
|
| 266 |
+
|
| 267 |
+
if ( !$conflicted )
|
| 268 |
+
pods_no_conflict_on( 'post' );
|
| 269 |
+
|
| 270 |
+
if ( !is_array( $post_meta ) )
|
| 271 |
+
$post_meta = array();
|
| 272 |
+
|
| 273 |
+
$id = (int) $id;
|
| 274 |
+
|
| 275 |
+
$meta = get_post_meta( $id );
|
| 276 |
+
|
| 277 |
+
foreach ( $meta as $k => $value ) {
|
| 278 |
+
if ( is_array( $value ) && 1 == count( $value ) )
|
| 279 |
+
$meta[ $k ] = current( $value );
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
foreach ( $post_meta as $meta_key => $meta_value ) {
|
| 283 |
+
if ( null === $meta_value || ( $strict && '' === $post_meta[ $meta_key ] ) ) {
|
| 284 |
+
$old_meta_value = '';
|
| 285 |
+
|
| 286 |
+
if ( isset( $meta[ $meta_key ] ) )
|
| 287 |
+
$old_meta_value = $meta[ $meta_key ];
|
| 288 |
+
|
| 289 |
+
delete_post_meta( $id, $meta_key, $old_meta_value );
|
| 290 |
+
}
|
| 291 |
+
else {
|
| 292 |
+
$simple = false;
|
| 293 |
|
| 294 |
+
if ( isset( $fields[ $meta_key ] ) ) {
|
| 295 |
+
$field_data = $fields[ $meta_key ];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 296 |
|
| 297 |
+
$simple = ( 'pick' == $field_data[ 'type' ] && in_array( pods_var( 'pick_object', $field_data ), $simple_tableless_objects ) );
|
| 298 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
|
| 300 |
+
if ( $simple ) {
|
| 301 |
+
delete_post_meta( $id, $meta_key );
|
|
|
|
| 302 |
|
| 303 |
+
update_post_meta( $id, '_pods_' . $meta_key, $meta_value );
|
|
|
|
|
|
|
| 304 |
|
| 305 |
+
if ( ! is_array( $meta_value ) ) {
|
| 306 |
+
$meta_value = array( $meta_value );
|
| 307 |
+
}
|
|
|
|
| 308 |
|
| 309 |
+
foreach ( $meta_value as $value ) {
|
| 310 |
+
add_post_meta( $id, $meta_key, $value );
|
| 311 |
+
}
|
| 312 |
+
}
|
| 313 |
+
else {
|
| 314 |
+
update_post_meta( $id, $meta_key, $meta_value );
|
| 315 |
+
}
|
| 316 |
}
|
| 317 |
+
}
|
| 318 |
|
| 319 |
+
if ( $strict ) {
|
| 320 |
+
foreach ( $meta as $meta_key => $meta_value ) {
|
| 321 |
+
if ( !isset( $post_meta[ $meta_key ] ) )
|
| 322 |
+
delete_post_meta( $id, $meta_key, $meta_value );
|
| 323 |
+
}
|
| 324 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 325 |
|
| 326 |
+
if ( !$conflicted )
|
| 327 |
+
pods_no_conflict_off( 'post' );
|
|
|
|
| 328 |
|
| 329 |
+
return $id;
|
| 330 |
+
}
|
|
|
|
| 331 |
|
| 332 |
+
/**
|
| 333 |
+
* Save a user and it's meta
|
| 334 |
+
*
|
| 335 |
+
* @param array $user_data All user data to be saved (using wp_insert_user / wp_update_user)
|
| 336 |
+
* @param array $user_meta (optional) All meta to be saved (set value to null to delete)
|
| 337 |
+
* @param bool $strict (optional) Whether to delete previously saved meta not in $user_meta
|
| 338 |
+
* @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before sending.
|
| 339 |
+
* @param array $fields (optional) The array of fields and their options, for further processing with
|
| 340 |
+
*
|
| 341 |
+
* @return int Returns user id on success
|
| 342 |
+
*
|
| 343 |
+
* @since 2.0
|
| 344 |
+
*/
|
| 345 |
+
public function save_user ( $user_data, $user_meta = null, $strict = false, $sanitized = false, $fields = array() ) {
|
| 346 |
+
if ( !is_array( $user_data ) || empty( $user_data ) )
|
| 347 |
+
return pods_error( __( 'User data is required but is either invalid or empty', 'pods' ), $this );
|
| 348 |
|
| 349 |
+
$conflicted = pods_no_conflict_check( 'user' );
|
|
|
|
|
|
|
| 350 |
|
| 351 |
+
if ( !$conflicted )
|
| 352 |
+
pods_no_conflict_on( 'user' );
|
|
|
|
| 353 |
|
| 354 |
+
if ( !is_array( $user_meta ) )
|
| 355 |
+
$user_meta = array();
|
| 356 |
|
| 357 |
+
if ( $sanitized ) {
|
| 358 |
+
$user_data = pods_unsanitize( $user_data );
|
| 359 |
+
$user_meta = pods_unsanitize( $user_meta );
|
| 360 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 361 |
|
| 362 |
+
// Set role
|
| 363 |
+
if ( isset( $user_meta[ 'role' ] ) ) {
|
| 364 |
+
$user_data[ 'role' ] = $user_meta[ 'role' ];
|
| 365 |
|
| 366 |
+
unset( $user_meta[ 'role' ] );
|
|
|
|
| 367 |
}
|
| 368 |
|
| 369 |
+
if ( !isset( $user_data[ 'ID' ] ) || empty( $user_data[ 'ID' ] ) )
|
| 370 |
+
$user_data[ 'ID' ] = wp_insert_user( $user_data );
|
| 371 |
+
elseif ( 1 < count( $user_data ) )
|
| 372 |
+
wp_update_user( $user_data );
|
| 373 |
|
| 374 |
+
if ( is_wp_error( $user_data[ 'ID' ] ) ) {
|
| 375 |
+
if ( !$conflicted )
|
| 376 |
+
pods_no_conflict_off( 'user' );
|
| 377 |
|
| 378 |
+
/**
|
| 379 |
+
* @var $user_error WP_Error
|
| 380 |
+
*/
|
| 381 |
+
$user_error = $user_data[ 'ID' ];
|
| 382 |
|
| 383 |
+
return pods_error( $user_error->get_error_message(), $this );
|
| 384 |
+
}
|
|
|
|
|
|
|
|
|
|
| 385 |
|
| 386 |
+
$this->save_user_meta( $user_data[ 'ID' ], $user_meta, $strict, $fields );
|
|
|
|
|
|
|
|
|
|
| 387 |
|
| 388 |
+
if ( !$conflicted )
|
| 389 |
+
pods_no_conflict_off( 'user' );
|
|
|
|
|
|
|
| 390 |
|
| 391 |
+
return $user_data[ 'ID' ];
|
| 392 |
+
}
|
| 393 |
|
| 394 |
+
/**
|
| 395 |
+
* Save a user meta
|
| 396 |
+
*
|
| 397 |
+
* @param int $id User ID
|
| 398 |
+
* @param array $user_meta (optional) All meta to be saved (set value to null to delete)
|
| 399 |
+
* @param bool $strict (optional) Whether to delete previously saved meta not in $user_meta
|
| 400 |
+
* @param array $fields (optional) The array of fields and their options, for further processing with
|
| 401 |
+
*
|
| 402 |
+
* @return int User ID
|
| 403 |
+
*
|
| 404 |
+
* @since 2.0
|
| 405 |
+
*
|
| 406 |
+
*/
|
| 407 |
+
public function save_user_meta ( $id, $user_meta = null, $strict = false, $fields = array() ) {
|
| 408 |
+
$simple_tableless_objects = PodsForm::simple_tableless_objects();
|
| 409 |
|
| 410 |
+
$conflicted = pods_no_conflict_check( 'user' );
|
|
|
|
|
|
|
| 411 |
|
| 412 |
+
if ( !$conflicted )
|
| 413 |
+
pods_no_conflict_on( 'user' );
|
| 414 |
|
| 415 |
+
if ( !is_array( $user_meta ) )
|
| 416 |
+
$user_meta = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 417 |
|
| 418 |
+
$id = (int) $id;
|
| 419 |
|
| 420 |
+
$meta = get_user_meta( $id );
|
| 421 |
|
| 422 |
+
foreach ( $user_meta as $meta_key => $meta_value ) {
|
| 423 |
+
if ( null === $meta_value ) {
|
| 424 |
+
$old_meta_value = '';
|
| 425 |
|
| 426 |
+
if ( isset( $meta[ $meta_key ] ) )
|
| 427 |
+
$old_meta_value = $meta[ $meta_key ];
|
| 428 |
+
|
| 429 |
+
delete_user_meta( $id, $meta_key, $old_meta_value );
|
| 430 |
+
}
|
| 431 |
+
else {
|
| 432 |
+
$simple = false;
|
| 433 |
|
| 434 |
+
if ( isset( $fields[ $meta_key ] ) ) {
|
| 435 |
+
$field_data = $fields[ $meta_key ];
|
| 436 |
|
| 437 |
+
$simple = ( 'pick' == $field_data[ 'type' ] && in_array( pods_var( 'pick_object', $field_data ), $simple_tableless_objects ) );
|
| 438 |
+
}
|
| 439 |
|
| 440 |
+
if ( $simple ) {
|
| 441 |
+
delete_user_meta( $id, $meta_key );
|
|
|
|
|
|
|
|
|
|
| 442 |
|
| 443 |
+
if ( ! is_array( $meta_value ) ) {
|
| 444 |
+
$meta_value = array( $meta_value );
|
| 445 |
+
}
|
| 446 |
|
| 447 |
+
foreach ( $meta_value as $value ) {
|
| 448 |
+
add_user_meta( $id, $meta_key, $value );
|
| 449 |
+
}
|
| 450 |
}
|
| 451 |
+
else {
|
| 452 |
+
update_user_meta( $id, $meta_key, $meta_value );
|
| 453 |
+
}
|
| 454 |
+
}
|
| 455 |
+
}
|
| 456 |
|
| 457 |
+
if ( $strict ) {
|
| 458 |
+
foreach ( $meta as $meta_key => $meta_value ) {
|
| 459 |
+
if ( !isset( $user_meta[ $meta_key ] ) )
|
| 460 |
+
delete_user_meta( $id, $meta_key, $user_meta[ $meta_key ] );
|
| 461 |
+
}
|
| 462 |
+
}
|
| 463 |
+
|
| 464 |
+
if ( !$conflicted )
|
| 465 |
+
pods_no_conflict_off( 'user' );
|
| 466 |
+
|
| 467 |
+
return $id;
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
/**
|
| 471 |
+
* Save a comment and it's meta
|
| 472 |
+
*
|
| 473 |
+
* @param array $comment_data All comment data to be saved (using wp_insert_comment / wp_update_comment)
|
| 474 |
+
* @param array $comment_meta (optional) All meta to be saved (set value to null to delete)
|
| 475 |
+
* @param bool $strict (optional) Whether to delete previously saved meta not in $comment_meta
|
| 476 |
+
* @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before sending.
|
| 477 |
+
* @param array $fields (optional) The array of fields and their options, for further processing with
|
| 478 |
+
*
|
| 479 |
+
* @return int Comment ID
|
| 480 |
+
*
|
| 481 |
+
* @since 2.0
|
| 482 |
+
*/
|
| 483 |
+
public function save_comment ( $comment_data, $comment_meta = null, $strict = false, $sanitized = false, $fields = array() ) {
|
| 484 |
+
if ( !is_array( $comment_data ) || empty( $comment_data ) )
|
| 485 |
+
return pods_error( __( 'Comment data is required but is either invalid or empty', 'pods' ), $this );
|
| 486 |
+
|
| 487 |
+
$conflicted = pods_no_conflict_check( 'comment' );
|
| 488 |
+
|
| 489 |
+
if ( !$conflicted )
|
| 490 |
+
pods_no_conflict_on( 'comment' );
|
| 491 |
+
|
| 492 |
+
if ( !is_array( $comment_meta ) )
|
| 493 |
+
$comment_meta = array();
|
| 494 |
+
|
| 495 |
+
if ( $sanitized ) {
|
| 496 |
+
$comment_data = pods_unsanitize( $comment_data );
|
| 497 |
+
$comment_meta = pods_unsanitize( $comment_meta );
|
| 498 |
+
}
|
| 499 |
+
|
| 500 |
+
if ( !isset( $comment_data[ 'comment_ID' ] ) || empty( $comment_data[ 'comment_ID' ] ) )
|
| 501 |
+
$comment_data[ 'comment_ID' ] = wp_insert_comment( pods_slash( $comment_data ) ); // Expects slashed
|
| 502 |
+
elseif ( 1 < count( $comment_data ) )
|
| 503 |
+
wp_update_comment( $comment_data );
|
| 504 |
+
|
| 505 |
+
if ( is_wp_error( $comment_data[ 'comment_ID' ] ) ) {
|
| 506 |
+
if ( !$conflicted )
|
| 507 |
+
pods_no_conflict_off( 'comment' );
|
| 508 |
+
|
| 509 |
+
/**
|
| 510 |
+
* @var $comment_error WP_Error
|
| 511 |
+
*/
|
| 512 |
+
$comment_error = $comment_data[ 'comment_ID' ];
|
| 513 |
+
|
| 514 |
+
return pods_error( $comment_error->get_error_message(), $this );
|
| 515 |
+
}
|
| 516 |
+
|
| 517 |
+
$this->save_comment_meta( $comment_data[ 'comment_ID' ], $comment_meta, $strict, $fields );
|
| 518 |
+
|
| 519 |
+
if ( !$conflicted )
|
| 520 |
+
pods_no_conflict_off( 'comment' );
|
| 521 |
+
|
| 522 |
+
return $comment_data[ 'comment_ID' ];
|
| 523 |
+
}
|
| 524 |
+
|
| 525 |
+
/**
|
| 526 |
+
* Save a comment meta
|
| 527 |
+
*
|
| 528 |
+
* @param int $id Comment ID
|
| 529 |
+
* @param array $comment_meta (optional) All meta to be saved (set value to null to delete)
|
| 530 |
+
* @param bool $strict (optional) Whether to delete previously saved meta not in $comment_meta
|
| 531 |
+
* @param array $fields (optional) The array of fields and their options, for further processing with
|
| 532 |
+
*
|
| 533 |
+
* @return int Comment ID
|
| 534 |
+
*
|
| 535 |
+
* @since 2.0
|
| 536 |
+
*/
|
| 537 |
+
public function save_comment_meta ( $id, $comment_meta = null, $strict = false, $fields = array() ) {
|
| 538 |
+
$simple_tableless_objects = PodsForm::simple_tableless_objects();
|
| 539 |
+
|
| 540 |
+
$conflicted = pods_no_conflict_check( 'comment' );
|
| 541 |
+
|
| 542 |
+
if ( !$conflicted )
|
| 543 |
+
pods_no_conflict_on( 'comment' );
|
| 544 |
+
|
| 545 |
+
if ( !is_array( $comment_meta ) )
|
| 546 |
+
$comment_meta = array();
|
| 547 |
+
|
| 548 |
+
$id = (int) $id;
|
| 549 |
+
|
| 550 |
+
$meta = get_comment_meta( $id );
|
| 551 |
+
|
| 552 |
+
foreach ( $comment_meta as $meta_key => $meta_value ) {
|
| 553 |
+
if ( null === $meta_value ) {
|
| 554 |
+
$old_meta_value = '';
|
| 555 |
+
|
| 556 |
+
if ( isset( $meta[ $meta_key ] ) )
|
| 557 |
+
$old_meta_value = $meta[ $meta_key ];
|
| 558 |
+
|
| 559 |
+
delete_comment_meta( $id, $meta_key, $old_meta_value );
|
| 560 |
+
}
|
| 561 |
+
else {
|
| 562 |
$simple = false;
|
| 563 |
|
| 564 |
if ( isset( $fields[ $meta_key ] ) ) {
|
| 565 |
$field_data = $fields[ $meta_key ];
|
| 566 |
|
| 567 |
+
$simple = ( 'pick' == $field_data[ 'type' ] && in_array( pods_var( 'pick_object', $field_data ), $simple_tableless_objects ) );
|
| 568 |
}
|
| 569 |
|
| 570 |
if ( $simple ) {
|
| 571 |
+
delete_comment_meta( $id, $meta_key );
|
|
|
|
|
|
|
| 572 |
|
| 573 |
if ( ! is_array( $meta_value ) ) {
|
| 574 |
$meta_value = array( $meta_value );
|
| 575 |
}
|
| 576 |
|
| 577 |
foreach ( $meta_value as $value ) {
|
| 578 |
+
add_comment_meta( $id, $meta_key, $value );
|
| 579 |
}
|
|
|
|
|
|
|
| 580 |
}
|
| 581 |
+
else {
|
| 582 |
+
update_comment_meta( $id, $meta_key, $meta_value );
|
| 583 |
+
}
|
| 584 |
+
}
|
| 585 |
+
}
|
| 586 |
+
|
| 587 |
+
if ( $strict ) {
|
| 588 |
+
foreach ( $meta as $meta_key => $meta_value ) {
|
| 589 |
+
if ( !isset( $comment_meta[ $meta_key ] ) )
|
| 590 |
+
delete_comment_meta( (int) $id, $meta_key, $comment_meta[ $meta_key ] );
|
| 591 |
+
}
|
| 592 |
+
}
|
| 593 |
+
|
| 594 |
+
if ( !$conflicted )
|
| 595 |
+
pods_no_conflict_off( 'comment' );
|
| 596 |
+
|
| 597 |
+
return $id;
|
| 598 |
+
}
|
| 599 |
+
|
| 600 |
+
/**
|
| 601 |
+
* Save a taxonomy's term
|
| 602 |
+
*
|
| 603 |
+
* @param int $term_ID Term ID, leave empty to add
|
| 604 |
+
* @param string $term Term name
|
| 605 |
+
* @param string $taxonomy Taxonomy name
|
| 606 |
+
* @param array $term_data All term data to be saved (using wp_insert_term / wp_update_term)
|
| 607 |
+
* @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before sending.
|
| 608 |
+
* @param array $fields (optional) The array of fields and their options, for further processing with
|
| 609 |
+
*
|
| 610 |
+
* @return int Term ID
|
| 611 |
+
*
|
| 612 |
+
* @since 2.0
|
| 613 |
+
*/
|
| 614 |
+
public function save_term ( $term_ID, $term, $taxonomy, $term_data, $sanitized = false, $fields = array() ) {
|
| 615 |
+
$conflicted = pods_no_conflict_check( 'taxonomy' );
|
| 616 |
+
|
| 617 |
+
if ( !$conflicted )
|
| 618 |
+
pods_no_conflict_on( 'taxonomy' );
|
| 619 |
+
|
| 620 |
+
if ( !is_array( $term_data ) )
|
| 621 |
+
$term_data = array();
|
| 622 |
+
|
| 623 |
+
$term_ID = (int) $term_ID;
|
| 624 |
+
|
| 625 |
+
if ( $sanitized ) {
|
| 626 |
+
$term = pods_unsanitize( $term );
|
| 627 |
+
$taxonomy = pods_unsanitize( $taxonomy );
|
| 628 |
+
$term_data = pods_unsanitize( $term_data );
|
| 629 |
+
}
|
| 630 |
+
|
| 631 |
+
if ( empty( $term_ID ) )
|
| 632 |
+
$term_ID = wp_insert_term( $term, $taxonomy, $term_data );
|
| 633 |
+
else {
|
| 634 |
+
if ( 0 < strlen( $term ) )
|
| 635 |
+
$term_data[ 'term' ] = $term;
|
| 636 |
+
|
| 637 |
+
if ( empty( $term_data ) ) {
|
| 638 |
+
if ( !$conflicted )
|
| 639 |
+
pods_no_conflict_off( 'taxonomy' );
|
| 640 |
+
|
| 641 |
+
return pods_error( __( 'Taxonomy term data is required but is either invalid or empty', 'pods' ), $this );
|
| 642 |
+
}
|
| 643 |
+
|
| 644 |
+
wp_update_term( $term_ID, $taxonomy, $term_data );
|
| 645 |
+
}
|
| 646 |
+
|
| 647 |
+
if ( is_wp_error( $term_ID ) ) {
|
| 648 |
+
if ( !$conflicted )
|
| 649 |
+
pods_no_conflict_off( 'taxonomy' );
|
| 650 |
+
|
| 651 |
+
return pods_error( $term_ID->get_error_message(), $this );
|
| 652 |
+
}
|
| 653 |
+
elseif ( is_array( $term_ID ) )
|
| 654 |
+
$term_ID = $term_ID[ 'term_id' ];
|
| 655 |
+
|
| 656 |
+
if ( !$conflicted )
|
| 657 |
+
pods_no_conflict_off( 'taxonomy' );
|
| 658 |
+
|
| 659 |
+
return $term_ID;
|
| 660 |
+
}
|
| 661 |
+
|
| 662 |
+
/**
|
| 663 |
+
* Save a set of options
|
| 664 |
+
*
|
| 665 |
+
* @param string $setting Setting group name
|
| 666 |
+
* @param array $option_data All option data to be saved
|
| 667 |
+
* @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before sending.
|
| 668 |
+
*
|
| 669 |
+
* @return bool
|
| 670 |
+
*
|
| 671 |
+
* @since 2.3
|
| 672 |
+
*/
|
| 673 |
+
public function save_setting ( $setting, $option_data, $sanitized = false ) {
|
| 674 |
+
if ( !is_array( $option_data ) || empty( $option_data ) )
|
| 675 |
+
return pods_error( __( 'Setting data is required but is either invalid or empty', 'pods' ), $this );
|
| 676 |
+
|
| 677 |
+
$conflicted = pods_no_conflict_check( 'settings' );
|
| 678 |
+
|
| 679 |
+
if ( !$conflicted )
|
| 680 |
+
pods_no_conflict_on( 'settings' );
|
| 681 |
+
|
| 682 |
+
if ( $sanitized )
|
| 683 |
+
$option_data = pods_unsanitize( $option_data );
|
| 684 |
+
|
| 685 |
+
foreach ( $option_data as $option => $value ) {
|
| 686 |
+
if ( !empty( $setting ) )
|
| 687 |
+
$option = $setting . '_' . $option;
|
| 688 |
+
|
| 689 |
+
update_option( $option, $value );
|
| 690 |
+
}
|
| 691 |
+
|
| 692 |
+
if ( !$conflicted )
|
| 693 |
+
pods_no_conflict_off( 'settings' );
|
| 694 |
+
|
| 695 |
+
return true;
|
| 696 |
+
}
|
| 697 |
+
|
| 698 |
+
/**
|
| 699 |
+
* Rename a WP object's type
|
| 700 |
+
*
|
| 701 |
+
* @param string $object_type Object type: post|taxonomy|comment|setting
|
| 702 |
+
* @param string $old_name The old name
|
| 703 |
+
* @param string $new_name The new name
|
| 704 |
+
*
|
| 705 |
+
* @return bool
|
| 706 |
+
*
|
| 707 |
+
* @since 2.0
|
| 708 |
+
*/
|
| 709 |
+
public function rename_wp_object_type ( $object_type, $old_name, $new_name ) {
|
| 710 |
+
/**
|
| 711 |
+
* @var $wpdb wpdb
|
| 712 |
+
*/
|
| 713 |
+
global $wpdb;
|
| 714 |
+
|
| 715 |
+
if ( 'post_type' == $object_type )
|
| 716 |
+
$object_type = 'post';
|
| 717 |
+
|
| 718 |
+
if ( 'post' == $object_type ) {
|
| 719 |
+
pods_query( "UPDATE `{$wpdb->posts}` SET `post_type` = %s WHERE `post_type` = %s", array(
|
| 720 |
+
$new_name,
|
| 721 |
+
$old_name
|
| 722 |
+
) );
|
| 723 |
+
}
|
| 724 |
+
elseif ( 'taxonomy' == $object_type ) {
|
| 725 |
+
pods_query( "UPDATE `{$wpdb->term_taxonomy}` SET `taxonomy` = %s WHERE `taxonomy` = %s", array(
|
| 726 |
+
$new_name,
|
| 727 |
+
$old_name
|
| 728 |
+
) );
|
| 729 |
+
}
|
| 730 |
+
elseif ( 'comment' == $object_type ) {
|
| 731 |
+
pods_query( "UPDATE `{$wpdb->comments}` SET `comment_type` = %s WHERE `comment_type` = %s", array(
|
| 732 |
+
$new_name,
|
| 733 |
+
$old_name
|
| 734 |
+
) );
|
| 735 |
+
}
|
| 736 |
+
elseif ( 'settings' == $object_type ) {
|
| 737 |
+
pods_query( "UPDATE `{$wpdb->options}` SET `option_name` = REPLACE( `option_name`, %s, %s ) WHERE `option_name` LIKE '" . pods_sanitize_like( $old_name ) . "_%'", array(
|
| 738 |
+
$new_name . '_',
|
| 739 |
+
$old_name . '_'
|
| 740 |
+
) );
|
| 741 |
+
}
|
| 742 |
+
|
| 743 |
+
return true;
|
| 744 |
+
}
|
| 745 |
+
|
| 746 |
+
/**
|
| 747 |
+
* Get a list of core WP object fields for a specific object
|
| 748 |
+
*
|
| 749 |
+
* @param string $object The pod type to look for, possible values: post_type, user, comment, taxonomy
|
| 750 |
+
* @param array $pod Array of Pod data
|
| 751 |
+
* @param boolean $refresh Whether to force refresh the information
|
| 752 |
+
*
|
| 753 |
+
* @return array Array of fields
|
| 754 |
+
*
|
| 755 |
+
* @since 2.0
|
| 756 |
+
*/
|
| 757 |
+
public function get_wp_object_fields ( $object = 'post_type', $pod = null, $refresh = false ) {
|
| 758 |
+
$pod_name = pods_var_raw( 'name', $pod, $object, null, true );
|
| 759 |
+
|
| 760 |
+
if ( 'media' == $pod_name ) {
|
| 761 |
+
$object = 'post_type';
|
| 762 |
+
$pod_name = 'attachment';
|
| 763 |
}
|
| 764 |
|
| 765 |
+
$fields = false;
|
| 766 |
+
|
| 767 |
+
if ( pods_api_cache() )
|
| 768 |
+
$fields = pods_transient_get( trim( 'pods_api_object_fields_' . $object . $pod_name . '_', '_' ) );
|
| 769 |
+
|
| 770 |
+
if ( false !== $fields && !$refresh )
|
| 771 |
+
return $this->do_hook( 'get_wp_object_fields', $fields, $object, $pod );
|
| 772 |
+
|
| 773 |
+
$fields = array();
|
| 774 |
+
|
| 775 |
+
if ( 'post_type' == $object ) {
|
| 776 |
+
$fields = array(
|
| 777 |
+
'ID' => array(
|
| 778 |
+
'name' => 'ID',
|
| 779 |
+
'label' => 'ID',
|
| 780 |
+
'type' => 'number',
|
| 781 |
+
'alias' => array( 'id' ),
|
| 782 |
+
'options' => array(
|
| 783 |
+
'number_format' => '9999.99'
|
| 784 |
+
)
|
| 785 |
+
),
|
| 786 |
+
'post_title' => array(
|
| 787 |
+
'name' => 'post_title',
|
| 788 |
+
'label' => 'Title',
|
| 789 |
+
'type' => 'text',
|
| 790 |
+
'alias' => array( 'title', 'name' ),
|
| 791 |
+
'options' => array(
|
| 792 |
+
'display_filter' => 'the_title',
|
| 793 |
+
'display_filter_args' => array( 'post_ID' )
|
| 794 |
+
)
|
| 795 |
+
),
|
| 796 |
+
'post_content' => array(
|
| 797 |
+
'name' => 'post_content',
|
| 798 |
+
'label' => 'Content',
|
| 799 |
+
'type' => 'wysiwyg',
|
| 800 |
+
'alias' => array( 'content' ),
|
| 801 |
+
'options' => array(
|
| 802 |
+
'wysiwyg_allowed_html_tags' => '',
|
| 803 |
+
'display_filter' => 'the_content',
|
| 804 |
+
'pre_save' => 0
|
| 805 |
+
)
|
| 806 |
+
),
|
| 807 |
+
'post_excerpt' => array(
|
| 808 |
+
'name' => 'post_excerpt',
|
| 809 |
+
'label' => 'Excerpt',
|
| 810 |
+
'type' => 'paragraph',
|
| 811 |
+
'alias' => array( 'excerpt' ),
|
| 812 |
+
'options' => array(
|
| 813 |
+
'paragraph_allow_html' => 1,
|
| 814 |
+
'paragraph_allowed_html_tags' => '',
|
| 815 |
+
'display_filter' => 'the_excerpt',
|
| 816 |
+
'pre_save' => 0
|
| 817 |
+
)
|
| 818 |
+
),
|
| 819 |
+
'post_author' => array(
|
| 820 |
+
'name' => 'post_author',
|
| 821 |
+
'label' => 'Author',
|
| 822 |
+
'type' => 'pick',
|
| 823 |
+
'alias' => array( 'author' ),
|
| 824 |
+
'pick_object' => 'user',
|
| 825 |
+
'options' => array(
|
| 826 |
+
'pick_format_type' => 'single',
|
| 827 |
+
'pick_format_single' => 'autocomplete',
|
| 828 |
+
'default_value' => '{@user.ID}'
|
| 829 |
+
)
|
| 830 |
+
),
|
| 831 |
+
'post_date' => array(
|
| 832 |
+
'name' => 'post_date',
|
| 833 |
+
'label' => 'Publish Date',
|
| 834 |
+
'type' => 'datetime',
|
| 835 |
+
'alias' => array( 'created', 'date' )
|
| 836 |
+
),
|
| 837 |
+
'post_date_gmt' => array(
|
| 838 |
+
'name' => 'post_date_gmt',
|
| 839 |
+
'label' => 'Publish Date (GMT)',
|
| 840 |
+
'type' => 'datetime',
|
| 841 |
+
'alias' => array(),
|
| 842 |
+
'hidden' => true
|
| 843 |
+
),
|
| 844 |
+
'post_status' => array(
|
| 845 |
+
'name' => 'post_status',
|
| 846 |
+
'label' => 'Status',
|
| 847 |
+
'type' => 'pick',
|
| 848 |
+
'pick_object' => 'post-status',
|
| 849 |
+
'default' => $this->do_hook( 'default_status_' . $pod_name, pods_var( 'default_status', pods_var_raw( 'options', $pod ), 'draft', null, true ), $pod ),
|
| 850 |
+
'alias' => array( 'status' )
|
| 851 |
+
),
|
| 852 |
+
'comment_status' => array(
|
| 853 |
+
'name' => 'comment_status',
|
| 854 |
+
'label' => 'Comment Status',
|
| 855 |
+
'type' => 'text',
|
| 856 |
+
'default' => get_option( 'default_comment_status', 'open' ),
|
| 857 |
+
'alias' => array(),
|
| 858 |
+
'data' => array(
|
| 859 |
+
'open' => __( 'Open', 'pods' ),
|
| 860 |
+
'closed' => __( 'Closed', 'pods' )
|
| 861 |
+
)
|
| 862 |
+
),
|
| 863 |
+
'ping_status' => array(
|
| 864 |
+
'name' => 'ping_status',
|
| 865 |
+
'label' => 'Ping Status',
|
| 866 |
+
'default' => get_option( 'default_ping_status', 'open' ),
|
| 867 |
+
'type' => 'text',
|
| 868 |
+
'alias' => array(),
|
| 869 |
+
'data' => array(
|
| 870 |
+
'open' => __( 'Open', 'pods' ),
|
| 871 |
+
'closed' => __( 'Closed', 'pods' )
|
| 872 |
+
)
|
| 873 |
+
),
|
| 874 |
+
'post_password' => array(
|
| 875 |
+
'name' => 'post_password',
|
| 876 |
+
'label' => 'Password',
|
| 877 |
+
'type' => 'text',
|
| 878 |
+
'alias' => array()
|
| 879 |
+
),
|
| 880 |
+
'post_name' => array(
|
| 881 |
+
'name' => 'post_name',
|
| 882 |
+
'label' => 'Permalink',
|
| 883 |
+
'type' => 'slug',
|
| 884 |
+
'alias' => array( 'slug', 'permalink' )
|
| 885 |
+
),
|
| 886 |
+
'to_ping' => array(
|
| 887 |
+
'name' => 'to_ping',
|
| 888 |
+
'label' => 'To Ping',
|
| 889 |
+
'type' => 'text',
|
| 890 |
+
'alias' => array(),
|
| 891 |
+
'hidden' => true
|
| 892 |
+
),
|
| 893 |
+
'pinged' => array(
|
| 894 |
+
'name' => 'pinged',
|
| 895 |
+
'label' => 'Pinged',
|
| 896 |
+
'type' => 'text',
|
| 897 |
+
'alias' => array(),
|
| 898 |
+
'hidden' => true
|
| 899 |
+
),
|
| 900 |
+
'post_modified' => array(
|
| 901 |
+
'name' => 'post_modified',
|
| 902 |
+
'label' => 'Last Modified Date',
|
| 903 |
+
'type' => 'datetime',
|
| 904 |
+
'alias' => array( 'modified' ),
|
| 905 |
+
'hidden' => true
|
| 906 |
+
),
|
| 907 |
+
'post_modified_gmt' => array(
|
| 908 |
+
'name' => 'post_modified_gmt',
|
| 909 |
+
'label' => 'Last Modified Date (GMT)',
|
| 910 |
+
'type' => 'datetime',
|
| 911 |
+
'alias' => array(),
|
| 912 |
+
'hidden' => true
|
| 913 |
+
),
|
| 914 |
+
'post_content_filtered' => array(
|
| 915 |
+
'name' => 'post_content_filtered',
|
| 916 |
+
'label' => 'Content (filtered)',
|
| 917 |
+
'type' => 'paragraph',
|
| 918 |
+
'alias' => array(),
|
| 919 |
+
'hidden' => true,
|
| 920 |
+
'options' => array(
|
| 921 |
+
'paragraph_allow_html' => 1,
|
| 922 |
+
'paragraph_oembed' => 1,
|
| 923 |
+
'paragraph_wptexturize' => 1,
|
| 924 |
+
'paragraph_convert_chars' => 1,
|
| 925 |
+
'paragraph_wpautop' => 1,
|
| 926 |
+
'paragraph_allow_shortcode' => 1,
|
| 927 |
+
'paragraph_allowed_html_tags' => ''
|
| 928 |
+
)
|
| 929 |
+
),
|
| 930 |
+
'post_parent' => array(
|
| 931 |
+
'name' => 'post_parent',
|
| 932 |
+
'label' => 'Parent',
|
| 933 |
+
'type' => 'pick',
|
| 934 |
+
'pick_object' => 'post_type',
|
| 935 |
+
'pick_val' => '__current__',
|
| 936 |
+
'alias' => array( 'parent' ),
|
| 937 |
+
'data' => array(),
|
| 938 |
+
'hidden' => true
|
| 939 |
+
),
|
| 940 |
+
'guid' => array(
|
| 941 |
+
'name' => 'guid',
|
| 942 |
+
'label' => 'GUID',
|
| 943 |
+
'type' => 'text',
|
| 944 |
+
'alias' => array(),
|
| 945 |
+
'hidden' => true
|
| 946 |
+
),
|
| 947 |
+
'menu_order' => array(
|
| 948 |
+
'name' => 'menu_order',
|
| 949 |
+
'label' => 'Menu Order',
|
| 950 |
+
'type' => 'number',
|
| 951 |
+
'alias' => array(),
|
| 952 |
+
'options' => array(
|
| 953 |
+
'number_format' => '9999.99'
|
| 954 |
+
)
|
| 955 |
+
),
|
| 956 |
+
'post_type' => array(
|
| 957 |
+
'name' => 'post_type',
|
| 958 |
+
'label' => 'Type',
|
| 959 |
+
'type' => 'text',
|
| 960 |
+
'alias' => array( 'type' ),
|
| 961 |
+
'hidden' => true
|
| 962 |
+
),
|
| 963 |
+
'post_mime_type' => array(
|
| 964 |
+
'name' => 'post_mime_type',
|
| 965 |
+
'label' => 'Mime Type',
|
| 966 |
+
'type' => 'text',
|
| 967 |
+
'alias' => array(),
|
| 968 |
+
'hidden' => true
|
| 969 |
+
),
|
| 970 |
+
'comment_count' => array(
|
| 971 |
+
'name' => 'comment_count',
|
| 972 |
+
'label' => 'Comment Count',
|
| 973 |
+
'type' => 'number',
|
| 974 |
+
'alias' => array(),
|
| 975 |
+
'hidden' => true
|
| 976 |
+
)
|
| 977 |
+
);
|
| 978 |
+
|
| 979 |
+
if ( !empty( $pod ) ) {
|
| 980 |
+
$taxonomies = get_object_taxonomies( $pod_name, 'objects' );
|
| 981 |
+
|
| 982 |
+
foreach ( $taxonomies as $taxonomy ) {
|
| 983 |
+
$fields[ $taxonomy->name ] = array(
|
| 984 |
+
'name' => $taxonomy->name,
|
| 985 |
+
'label' => $taxonomy->labels->name,
|
| 986 |
+
'type' => 'taxonomy',
|
| 987 |
+
'pick_object' => 'taxonomy',
|
| 988 |
+
'pick_val' => $taxonomy->name,
|
| 989 |
+
'alias' => array(),
|
| 990 |
+
'hidden' => true,
|
| 991 |
+
'options' => array(
|
| 992 |
+
'taxonomy_format_type' => 'multi'
|
| 993 |
+
)
|
| 994 |
+
);
|
| 995 |
+
}
|
| 996 |
+
}
|
| 997 |
+
}
|
| 998 |
+
elseif ( 'user' == $object ) {
|
| 999 |
+
$fields = array(
|
| 1000 |
+
'ID' => array(
|
| 1001 |
+
'name' => 'ID',
|
| 1002 |
+
'label' => 'ID',
|
| 1003 |
+
'type' => 'number',
|
| 1004 |
+
'alias' => array( 'id' ),
|
| 1005 |
+
'options' => array(
|
| 1006 |
+
'number_format' => '9999.99'
|
| 1007 |
+
)
|
| 1008 |
+
),
|
| 1009 |
+
'user_login' => array(
|
| 1010 |
+
'name' => 'user_login',
|
| 1011 |
+
'label' => 'Title',
|
| 1012 |
+
'type' => 'text',
|
| 1013 |
+
'alias' => array( 'login' ),
|
| 1014 |
+
'options' => array(
|
| 1015 |
+
'required' => 1
|
| 1016 |
+
)
|
| 1017 |
+
),
|
| 1018 |
+
'user_nicename' => array(
|
| 1019 |
+
'name' => 'user_nicename',
|
| 1020 |
+
'label' => 'Permalink',
|
| 1021 |
+
'type' => 'slug',
|
| 1022 |
+
'alias' => array( 'nicename', 'slug', 'permalink' )
|
| 1023 |
+
),
|
| 1024 |
+
'display_name' => array(
|
| 1025 |
+
'name' => 'display_name',
|
| 1026 |
+
'label' => 'Display Name',
|
| 1027 |
+
'type' => 'text',
|
| 1028 |
+
'alias' => array( 'title', 'name' )
|
| 1029 |
+
),
|
| 1030 |
+
'user_pass' => array(
|
| 1031 |
+
'name' => 'user_pass',
|
| 1032 |
+
'label' => 'Password',
|
| 1033 |
+
'type' => 'text',
|
| 1034 |
+
'alias' => array( 'password', 'pass' ),
|
| 1035 |
+
'options' => array(
|
| 1036 |
+
'required' => 1,
|
| 1037 |
+
'text_format_type' => 'password'
|
| 1038 |
+
)
|
| 1039 |
+
),
|
| 1040 |
+
'user_email' => array(
|
| 1041 |
+
'name' => 'user_email',
|
| 1042 |
+
'label' => 'E-mail',
|
| 1043 |
+
'type' => 'text',
|
| 1044 |
+
'alias' => array( 'email' ),
|
| 1045 |
+
'options' => array(
|
| 1046 |
+
'required' => 1,
|
| 1047 |
+
'text_format_type' => 'email'
|
| 1048 |
+
)
|
| 1049 |
+
),
|
| 1050 |
+
'user_url' => array(
|
| 1051 |
+
'name' => 'user_url',
|
| 1052 |
+
'label' => 'URL',
|
| 1053 |
+
'type' => 'text',
|
| 1054 |
+
'alias' => array( 'url', 'website' ),
|
| 1055 |
+
'options' => array(
|
| 1056 |
+
'required' => 0,
|
| 1057 |
+
'text_format_type' => 'website',
|
| 1058 |
+
'text_format_website' => 'normal'
|
| 1059 |
+
)
|
| 1060 |
+
),
|
| 1061 |
+
'user_registered' => array(
|
| 1062 |
+
'name' => 'user_registered',
|
| 1063 |
+
'label' => 'Registration Date',
|
| 1064 |
+
'type' => 'date',
|
| 1065 |
+
'alias' => array( 'created', 'date', 'registered' ),
|
| 1066 |
+
'options' => array(
|
| 1067 |
+
'date_format_type' => 'datetime'
|
| 1068 |
+
)
|
| 1069 |
+
)
|
| 1070 |
+
);
|
| 1071 |
+
}
|
| 1072 |
+
elseif ( 'comment' == $object ) {
|
| 1073 |
+
$fields = array(
|
| 1074 |
+
'comment_ID' => array(
|
| 1075 |
+
'name' => 'comment_ID',
|
| 1076 |
+
'label' => 'ID',
|
| 1077 |
+
'type' => 'number',
|
| 1078 |
+
'alias' => array( 'id', 'ID', 'comment_id' ),
|
| 1079 |
+
'options' => array(
|
| 1080 |
+
'number_format' => '9999.99'
|
| 1081 |
+
)
|
| 1082 |
+
),
|
| 1083 |
+
'comment_content' => array(
|
| 1084 |
+
'name' => 'comment_content',
|
| 1085 |
+
'label' => 'Content',
|
| 1086 |
+
'type' => 'wysiwyg',
|
| 1087 |
+
'alias' => array( 'content' )
|
| 1088 |
+
),
|
| 1089 |
+
'comment_approved' => array(
|
| 1090 |
+
'name' => 'comment_approved',
|
| 1091 |
+
'label' => 'Approved',
|
| 1092 |
+
'type' => 'number',
|
| 1093 |
+
'alias' => array( 'approved' ),
|
| 1094 |
+
'options' => array(
|
| 1095 |
+
'number_format' => '9999.99'
|
| 1096 |
+
)
|
| 1097 |
+
),
|
| 1098 |
+
'comment_post_ID' => array(
|
| 1099 |
+
'name' => 'comment_post_ID',
|
| 1100 |
+
'label' => 'Post',
|
| 1101 |
+
'type' => 'pick',
|
| 1102 |
+
'alias' => array( 'post', 'post_id' ),
|
| 1103 |
+
'data' => array()
|
| 1104 |
+
),
|
| 1105 |
+
'user_id' => array(
|
| 1106 |
+
'name' => 'user_id',
|
| 1107 |
+
'label' => 'Author',
|
| 1108 |
+
'type' => 'pick',
|
| 1109 |
+
'alias' => array( 'author' ),
|
| 1110 |
+
'pick_object' => 'user',
|
| 1111 |
+
'data' => array()
|
| 1112 |
+
),
|
| 1113 |
+
'comment_date' => array(
|
| 1114 |
+
'name' => 'comment_date',
|
| 1115 |
+
'label' => 'Date',
|
| 1116 |
+
'type' => 'date',
|
| 1117 |
+
'alias' => array( 'created', 'date' ),
|
| 1118 |
+
'options' => array(
|
| 1119 |
+
'date_format_type' => 'datetime'
|
| 1120 |
+
)
|
| 1121 |
+
),
|
| 1122 |
+
'comment_author' => array(
|
| 1123 |
+
'name' => 'comment_author',
|
| 1124 |
+
'label' => 'Author',
|
| 1125 |
+
'type' => 'text',
|
| 1126 |
+
'alias' => array( 'author' )
|
| 1127 |
+
),
|
| 1128 |
+
'comment_author_email' => array(
|
| 1129 |
+
'name' => 'comment_author_email',
|
| 1130 |
+
'label' => 'Author E-mail',
|
| 1131 |
+
'type' => 'email',
|
| 1132 |
+
'alias' => array( 'author_email' )
|
| 1133 |
+
),
|
| 1134 |
+
'comment_author_url' => array(
|
| 1135 |
+
'name' => 'comment_author_url',
|
| 1136 |
+
'label' => 'Author URL',
|
| 1137 |
+
'type' => 'text',
|
| 1138 |
+
'alias' => array( 'author_url' )
|
| 1139 |
+
),
|
| 1140 |
+
'comment_author_IP' => array(
|
| 1141 |
+
'name' => 'comment_author_IP',
|
| 1142 |
+
'label' => 'Author IP',
|
| 1143 |
+
'type' => 'text',
|
| 1144 |
+
'alias' => array( 'author_IP' )
|
| 1145 |
+
),
|
| 1146 |
+
'comment_type' => array(
|
| 1147 |
+
'name' => 'comment_type',
|
| 1148 |
+
'label' => 'Type',
|
| 1149 |
+
'type' => 'text',
|
| 1150 |
+
'alias' => array( 'type' ),
|
| 1151 |
+
'hidden' => true
|
| 1152 |
+
),
|
| 1153 |
+
'comment_parent' => array(
|
| 1154 |
+
'name' => 'comment_parent',
|
| 1155 |
+
'label' => 'Parent',
|
| 1156 |
+
'type' => 'pick',
|
| 1157 |
+
'pick_object' => 'comment',
|
| 1158 |
+
'pick_val' => '__current__',
|
| 1159 |
+
'alias' => array( 'parent' ),
|
| 1160 |
+
'data' => array(),
|
| 1161 |
+
'hidden' => true
|
| 1162 |
+
)
|
| 1163 |
+
);
|
| 1164 |
+
}
|
| 1165 |
+
elseif ( 'taxonomy' == $object ) {
|
| 1166 |
+
$fields = array(
|
| 1167 |
+
'term_id' => array(
|
| 1168 |
+
'name' => 'term_id',
|
| 1169 |
+
'label' => 'ID',
|
| 1170 |
+
'type' => 'number',
|
| 1171 |
+
'alias' => array( 'id', 'ID' ),
|
| 1172 |
+
'options' => array(
|
| 1173 |
+
'number_format' => '9999.99'
|
| 1174 |
+
)
|
| 1175 |
+
),
|
| 1176 |
+
'name' => array(
|
| 1177 |
+
'name' => 'name',
|
| 1178 |
+
'label' => 'Title',
|
| 1179 |
+
'type' => 'text',
|
| 1180 |
+
'alias' => array( 'title' )
|
| 1181 |
+
),
|
| 1182 |
+
'slug' => array(
|
| 1183 |
+
'name' => 'slug',
|
| 1184 |
+
'label' => 'Permalink',
|
| 1185 |
+
'type' => 'slug',
|
| 1186 |
+
'alias' => array( 'permalink' )
|
| 1187 |
+
),
|
| 1188 |
+
'description' => array(
|
| 1189 |
+
'name' => 'description',
|
| 1190 |
+
'label' => 'Description',
|
| 1191 |
+
'type' => 'wysiwyg',
|
| 1192 |
+
'alias' => array( 'content' )
|
| 1193 |
+
),
|
| 1194 |
+
'taxonomy' => array(
|
| 1195 |
+
'name' => 'taxonomy',
|
| 1196 |
+
'label' => 'Taxonomy',
|
| 1197 |
+
'type' => 'pick',
|
| 1198 |
+
'alias' => array()
|
| 1199 |
+
),
|
| 1200 |
+
'parent' => array(
|
| 1201 |
+
'name' => 'parent',
|
| 1202 |
+
'label' => 'Parent',
|
| 1203 |
+
'type' => 'pick',
|
| 1204 |
+
'pick_object' => 'taxonomy',
|
| 1205 |
+
'pick_val' => '__current__',
|
| 1206 |
+
'alias' => array( 'parent' ),
|
| 1207 |
+
'data' => array(),
|
| 1208 |
+
'hidden' => true
|
| 1209 |
+
),
|
| 1210 |
+
'term_taxonomy_id' => array(
|
| 1211 |
+
'name' => 'term_taxonomy_id',
|
| 1212 |
+
'label' => 'Term Taxonomy ID',
|
| 1213 |
+
'type' => 'number',
|
| 1214 |
+
'alias' => array(),
|
| 1215 |
+
'hidden' => true,
|
| 1216 |
+
'options' => array(
|
| 1217 |
+
'number_format' => '9999.99'
|
| 1218 |
+
)
|
| 1219 |
+
),
|
| 1220 |
+
'term_group' => array(
|
| 1221 |
+
'name' => 'term_group',
|
| 1222 |
+
'label' => 'Term Group',
|
| 1223 |
+
'type' => 'number',
|
| 1224 |
+
'alias' => array( 'group' ),
|
| 1225 |
+
'hidden' => true,
|
| 1226 |
+
'options' => array(
|
| 1227 |
+
'number_format' => '9999.99'
|
| 1228 |
+
)
|
| 1229 |
+
),
|
| 1230 |
+
'count' => array(
|
| 1231 |
+
'name' => 'count',
|
| 1232 |
+
'label' => 'Count',
|
| 1233 |
+
'type' => 'number',
|
| 1234 |
+
'alias' => array(),
|
| 1235 |
+
'hidden' => true,
|
| 1236 |
+
'options' => array(
|
| 1237 |
+
'number_format' => '9999.99'
|
| 1238 |
+
)
|
| 1239 |
+
)
|
| 1240 |
+
);
|
| 1241 |
+
}
|
| 1242 |
+
|
| 1243 |
+
$fields = $this->do_hook( 'get_wp_object_fields', $fields, $object, $pod );
|
| 1244 |
+
|
| 1245 |
+
foreach ( $fields as $field => $options ) {
|
| 1246 |
+
if ( !isset( $options[ 'alias' ] ) )
|
| 1247 |
+
$options[ 'alias' ] = array();
|
| 1248 |
+
else
|
| 1249 |
+
$options[ 'alias' ] = (array) $options[ 'alias' ];
|
| 1250 |
+
|
| 1251 |
+
if ( !isset( $options[ 'name' ] ) )
|
| 1252 |
+
$options[ 'name' ] = $field;
|
| 1253 |
+
|
| 1254 |
+
$fields[ $field ] = $options;
|
| 1255 |
+
}
|
| 1256 |
+
|
| 1257 |
+
$fields = PodsForm::fields_setup( $fields );
|
| 1258 |
+
|
| 1259 |
+
if ( did_action( 'init' ) && pods_api_cache() )
|
| 1260 |
+
pods_transient_set( trim( 'pods_api_object_fields_' . $object . $pod_name . '_', '_' ), $fields );
|
| 1261 |
+
|
| 1262 |
+
return $fields;
|
| 1263 |
+
}
|
| 1264 |
+
|
| 1265 |
+
/**
|
| 1266 |
+
*
|
| 1267 |
+
* @see PodsAPI::save_pod
|
| 1268 |
+
*
|
| 1269 |
+
* Add a Pod via the Wizard
|
| 1270 |
+
*
|
| 1271 |
+
* $params['create_extend'] string Create or Extend a Content Type
|
| 1272 |
+
* $params['create_pod_type'] string Pod Type (for Creating)
|
| 1273 |
+
* $params['create_name'] string Pod Name (for Creating)
|
| 1274 |
+
* $params['create_label_plural'] string Plural Label (for Creating)
|
| 1275 |
+
* $params['create_label_singular'] string Singular Label (for Creating)
|
| 1276 |
+
* $params['create_storage'] string Storage Type (for Creating Post Types)
|
| 1277 |
+
* $params['create_storage_taxonomy'] string Storage Type (for Creating Taxonomies)
|
| 1278 |
+
* $params['extend_pod_type'] string Pod Type (for Extending)
|
| 1279 |
+
* $params['extend_post_type'] string Post Type (for Extending Post Types)
|
| 1280 |
+
* $params['extend_taxonomy'] string Taxonomy (for Extending Taxonomies)
|
| 1281 |
+
* $params['extend_storage'] string Storage Type (for Extending Post Types / Users / Comments)
|
| 1282 |
+
*
|
| 1283 |
+
* @param array $params An associative array of parameters
|
| 1284 |
+
*
|
| 1285 |
+
* @return bool|int Pod ID
|
| 1286 |
+
* @since 2.0
|
| 1287 |
+
*/
|
| 1288 |
+
public function add_pod ( $params ) {
|
| 1289 |
+
$defaults = array(
|
| 1290 |
+
'create_extend' => 'create',
|
| 1291 |
+
'create_pod_type' => 'post_type',
|
| 1292 |
+
|
| 1293 |
+
'create_name' => '',
|
| 1294 |
+
'create_label_singular' => '',
|
| 1295 |
+
'create_label_plural' => '',
|
| 1296 |
+
'create_storage' => 'meta',
|
| 1297 |
+
'create_storage_taxonomy' => 'none',
|
| 1298 |
+
|
| 1299 |
+
'create_setting_name' => '',
|
| 1300 |
+
'create_label_title' => '',
|
| 1301 |
+
'create_label_menu' => '',
|
| 1302 |
+
'create_menu_location' => 'settings',
|
| 1303 |
+
|
| 1304 |
+
'extend_pod_type' => 'post_type',
|
| 1305 |
+
'extend_post_type' => 'post',
|
| 1306 |
+
'extend_taxonomy' => 'category',
|
| 1307 |
+
'extend_table' => '',
|
| 1308 |
+
'extend_storage_taxonomy' => 'table',
|
| 1309 |
+
'extend_storage' => 'meta'
|
| 1310 |
+
);
|
| 1311 |
+
|
| 1312 |
+
$params = (object) array_merge( $defaults, (array) $params );
|
| 1313 |
+
|
| 1314 |
+
if ( empty( $params->create_extend ) || !in_array( $params->create_extend, array( 'create', 'extend' ) ) )
|
| 1315 |
+
return pods_error( __( 'Please choose whether to Create or Extend a Content Type', 'pods' ), $this );
|
| 1316 |
+
|
| 1317 |
+
$pod_params = array(
|
| 1318 |
+
'name' => '',
|
| 1319 |
+
'label' => '',
|
| 1320 |
+
'type' => '',
|
| 1321 |
+
'storage' => 'table',
|
| 1322 |
+
'object' => '',
|
| 1323 |
+
'options' => array()
|
| 1324 |
+
);
|
| 1325 |
+
|
| 1326 |
+
if ( 'create' == $params->create_extend ) {
|
| 1327 |
+
$label = ucwords( str_replace( '_', ' ', $params->create_name ) );
|
| 1328 |
+
|
| 1329 |
+
if ( !empty( $params->create_label_singular ) )
|
| 1330 |
+
$label = $params->create_label_singular;
|
| 1331 |
+
|
| 1332 |
+
$pod_params[ 'name' ] = $params->create_name;
|
| 1333 |
+
$pod_params[ 'label' ] = ( !empty( $params->create_label_plural ) ? $params->create_label_plural : $label );
|
| 1334 |
+
$pod_params[ 'type' ] = $params->create_pod_type;
|
| 1335 |
+
$pod_params[ 'options' ] = array(
|
| 1336 |
+
'label_singular' => ( !empty( $params->create_label_singular ) ? $params->create_label_singular : $pod_params[ 'label' ] ),
|
| 1337 |
+
'public' => 1,
|
| 1338 |
+
'show_ui' => 1
|
| 1339 |
+
);
|
| 1340 |
+
|
| 1341 |
+
// Auto-generate name if not provided
|
| 1342 |
+
if ( empty( $pod_params[ 'name' ] ) && !empty( $pod_params[ 'options' ][ 'label_singular' ] ) )
|
| 1343 |
+
$pod_params[ 'name' ] = pods_clean_name( $pod_params[ 'options' ][ 'label_singular' ] );
|
| 1344 |
+
|
| 1345 |
+
if ( 'post_type' == $pod_params[ 'type' ] ) {
|
| 1346 |
+
if ( empty( $pod_params[ 'name' ] ) )
|
| 1347 |
+
return pods_error( 'Please enter a Name for this Pod', $this );
|
| 1348 |
+
|
| 1349 |
+
$pod_params[ 'storage' ] = $params->create_storage;
|
| 1350 |
+
|
| 1351 |
+
if ( pods_tableless() )
|
| 1352 |
+
$pod_params[ 'storage' ] = 'meta';
|
| 1353 |
+
}
|
| 1354 |
+
elseif ( 'taxonomy' == $pod_params[ 'type' ] ) {
|
| 1355 |
+
if ( empty( $pod_params[ 'name' ] ) )
|
| 1356 |
+
return pods_error( 'Please enter a Name for this Pod', $this );
|
| 1357 |
+
|
| 1358 |
+
$pod_params[ 'storage' ] = $params->create_storage_taxonomy;
|
| 1359 |
+
|
| 1360 |
+
if ( pods_tableless() )
|
| 1361 |
+
$pod_params[ 'storage' ] = 'none';
|
| 1362 |
+
}
|
| 1363 |
+
elseif ( 'pod' == $pod_params[ 'type' ] ) {
|
| 1364 |
+
if ( empty( $pod_params[ 'name' ] ) )
|
| 1365 |
+
return pods_error( 'Please enter a Name for this Pod', $this );
|
| 1366 |
+
|
| 1367 |
+
if ( pods_tableless() ) {
|
| 1368 |
+
$pod_params[ 'type' ] = 'post_type';
|
| 1369 |
+
$pod_params[ 'storage' ] = 'meta';
|
| 1370 |
+
}
|
| 1371 |
+
}
|
| 1372 |
+
elseif ( 'settings' == $pod_params[ 'type' ] ) {
|
| 1373 |
+
$pod_params[ 'name' ] = $params->create_setting_name;
|
| 1374 |
+
$pod_params[ 'label' ] = ( !empty( $params->create_label_title ) ? $params->create_label_title : ucwords( str_replace( '_', ' ', $params->create_setting_name ) ) );
|
| 1375 |
+
$pod_params[ 'options' ] = array(
|
| 1376 |
+
'menu_name' => ( !empty( $params->create_label_menu ) ? $params->create_label_menu : $pod_params[ 'label' ] ),
|
| 1377 |
+
'menu_location' => $params->create_menu_location
|
| 1378 |
+
);
|
| 1379 |
+
$pod_params[ 'storage' ] = 'none';
|
| 1380 |
+
|
| 1381 |
+
// Auto-generate name if not provided
|
| 1382 |
+
if ( empty( $pod_params[ 'name' ] ) && !empty( $pod_params[ 'label' ] ) )
|
| 1383 |
+
$pod_params[ 'name' ] = pods_clean_name( $pod_params[ 'label' ] );
|
| 1384 |
+
|
| 1385 |
+
if ( empty( $pod_params[ 'name' ] ) )
|
| 1386 |
+
return pods_error( 'Please enter a Name for this Pod', $this );
|
| 1387 |
+
}
|
| 1388 |
+
}
|
| 1389 |
+
elseif ( 'extend' == $params->create_extend ) {
|
| 1390 |
+
$pod_params[ 'type' ] = $params->extend_pod_type;
|
| 1391 |
+
|
| 1392 |
+
if ( 'post_type' == $pod_params[ 'type' ] ) {
|
| 1393 |
+
$pod_params[ 'storage' ] = $params->extend_storage;
|
| 1394 |
+
|
| 1395 |
+
if ( pods_tableless() )
|
| 1396 |
+
$pod_params[ 'storage' ] = 'meta';
|
| 1397 |
+
|
| 1398 |
+
$pod_params[ 'name' ] = $params->extend_post_type;
|
| 1399 |
+
}
|
| 1400 |
+
elseif ( 'taxonomy' == $pod_params[ 'type' ] ) {
|
| 1401 |
+
$pod_params[ 'storage' ] = $params->extend_storage_taxonomy;
|
| 1402 |
+
|
| 1403 |
+
if ( pods_tableless() )
|
| 1404 |
+
$pod_params[ 'storage' ] = 'none';
|
| 1405 |
+
|
| 1406 |
+
$pod_params[ 'name' ] = $params->extend_taxonomy;
|
| 1407 |
+
}
|
| 1408 |
+
elseif ( 'table' == $pod_params[ 'type' ] ) {
|
| 1409 |
+
$pod_params[ 'storage' ] = 'table';
|
| 1410 |
+
$pod_params[ 'name' ] = $params->extend_table;
|
| 1411 |
+
}
|
| 1412 |
+
else {
|
| 1413 |
+
$pod_params[ 'storage' ] = $params->extend_storage;
|
| 1414 |
+
|
| 1415 |
+
if ( pods_tableless() )
|
| 1416 |
+
$pod_params[ 'storage' ] = 'meta';
|
| 1417 |
+
|
| 1418 |
+
$pod_params[ 'name' ] = $params->extend_pod_type;
|
| 1419 |
+
}
|
| 1420 |
+
|
| 1421 |
+
$pod_params[ 'label' ] = ucwords( str_replace( '_', ' ', $pod_params[ 'name' ] ) );
|
| 1422 |
+
$pod_params[ 'object' ] = $pod_params[ 'name' ];
|
| 1423 |
+
}
|
| 1424 |
+
|
| 1425 |
+
if ( empty( $pod_params[ 'object' ] ) ) {
|
| 1426 |
+
if ( 'post_type' == $pod_params[ 'type' ] ) {
|
| 1427 |
+
$check = get_post_type_object( $pod_params[ 'name' ] );
|
| 1428 |
+
|
| 1429 |
+
if ( !empty( $check ) )
|
| 1430 |
+
return pods_error( sprintf( __( 'Post Type %s already exists, try extending it instead', 'pods' ), $pod_params[ 'name' ] ), $this );
|
| 1431 |
+
|
| 1432 |
+
$pod_params[ 'options' ][ 'supports_title' ] = 1;
|
| 1433 |
+
$pod_params[ 'options' ][ 'supports_editor' ] = 1;
|
| 1434 |
+
}
|
| 1435 |
+
elseif ( 'taxonomy' == $pod_params[ 'type' ] ) {
|
| 1436 |
+
$check = get_taxonomy( $pod_params[ 'name' ] );
|
| 1437 |
+
|
| 1438 |
+
if ( !empty( $check ) )
|
| 1439 |
+
return pods_error( sprintf( __( 'Taxonomy %s already exists, try extending it instead', 'pods' ), $pod_params[ 'name' ] ), $this );
|
| 1440 |
+
}
|
| 1441 |
+
}
|
| 1442 |
+
|
| 1443 |
+
if ( !empty( $pod_params ) )
|
| 1444 |
+
return $this->save_pod( $pod_params );
|
| 1445 |
+
|
| 1446 |
+
return false;
|
| 1447 |
+
}
|
| 1448 |
+
|
| 1449 |
+
/**
|
| 1450 |
+
* Add or edit a Pod
|
| 1451 |
+
*
|
| 1452 |
+
* $params['id'] int The Pod ID
|
| 1453 |
+
* $params['name'] string The Pod name
|
| 1454 |
+
* $params['label'] string The Pod label
|
| 1455 |
+
* $params['type'] string The Pod type
|
| 1456 |
+
* $params['object'] string The object being extended (if any)
|
| 1457 |
+
* $params['storage'] string The Pod storage
|
| 1458 |
+
* $params['options'] array Options
|
| 1459 |
+
*
|
| 1460 |
+
* @param array $params An associative array of parameters
|
| 1461 |
+
* @param bool $sanitized (optional) Decides whether the params have been sanitized before being passed, will sanitize them if false.
|
| 1462 |
+
* @param bool|int $db (optional) Whether to save into the DB or just return Pod array.
|
| 1463 |
+
*
|
| 1464 |
+
* @return int Pod ID
|
| 1465 |
+
* @since 1.7.9
|
| 1466 |
+
*/
|
| 1467 |
+
public function save_pod ( $params, $sanitized = false, $db = true ) {
|
| 1468 |
+
$tableless_field_types = PodsForm::tableless_field_types();
|
| 1469 |
+
$simple_tableless_objects = PodsForm::simple_tableless_objects();
|
| 1470 |
+
|
| 1471 |
+
$load_params = (object) $params;
|
| 1472 |
+
|
| 1473 |
+
if ( isset( $load_params->id ) && isset( $load_params->name ) )
|
| 1474 |
+
unset( $load_params->name );
|
| 1475 |
+
|
| 1476 |
+
if ( isset( $load_params->old_name ) )
|
| 1477 |
+
$load_params->name = $load_params->old_name;
|
| 1478 |
+
|
| 1479 |
+
$load_params->table_info = true;
|
| 1480 |
+
|
| 1481 |
+
$pod = $this->load_pod( $load_params, false );
|
| 1482 |
+
|
| 1483 |
+
$params = (object) $params;
|
| 1484 |
+
|
| 1485 |
+
if ( false === $sanitized )
|
| 1486 |
+
$params = pods_sanitize( $params );
|
| 1487 |
+
|
| 1488 |
+
$old_id = $old_name = $old_storage = null;
|
| 1489 |
+
|
| 1490 |
+
$old_fields = $old_options = array();
|
| 1491 |
|
| 1492 |
+
if ( isset( $params->name ) && ! isset( $params->object ) ) {
|
| 1493 |
+
$params->name = pods_clean_name( $params->name );
|
| 1494 |
}
|
| 1495 |
|
| 1496 |
+
if ( !empty( $pod ) ) {
|
| 1497 |
+
if ( isset( $params->id ) && 0 < $params->id )
|
| 1498 |
+
$old_id = $params->id;
|
| 1499 |
+
|
| 1500 |
+
$params->id = $pod[ 'id' ];
|
| 1501 |
+
|
| 1502 |
+
$old_name = $pod[ 'name' ];
|
| 1503 |
+
$old_storage = $pod[ 'storage' ];
|
| 1504 |
+
$old_fields = $pod[ 'fields' ];
|
| 1505 |
+
$old_options = $pod[ 'options' ];
|
| 1506 |
+
|
| 1507 |
+
if ( !isset( $params->name ) && empty( $params->name ) )
|
| 1508 |
+
$params->name = $pod[ 'name' ];
|
| 1509 |
+
|
| 1510 |
+
if ( $old_name != $params->name && false !== $this->pod_exists( array( 'name' => $params->name ) ) )
|
| 1511 |
+
return pods_error( sprintf( __( 'Pod %s already exists, you cannot rename %s to that', 'pods' ), $params->name, $old_name ), $this );
|
| 1512 |
+
|
| 1513 |
+
if ( $old_name != $params->name && in_array( $pod[ 'type' ], array( 'user', 'comment', 'media' ) ) && in_array( $pod[ 'object' ], array( 'user', 'comment', 'media' ) ) )
|
| 1514 |
+
return pods_error( sprintf( __( 'Pod %s cannot be renamed, it extends an existing WP Object', 'pods' ), $old_name ), $this );
|
| 1515 |
+
|
| 1516 |
+
if ( $old_name != $params->name && in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) && !empty( $pod[ 'object' ] ) && $pod[ 'object' ] == $old_name )
|
| 1517 |
+
return pods_error( sprintf( __( 'Pod %s cannot be renamed, it extends an existing WP Object', 'pods' ), $old_name ), $this );
|
| 1518 |
+
|
| 1519 |
+
if ( $old_id != $params->id ) {
|
| 1520 |
+
if ( $params->type == $pod[ 'type' ] && isset( $params->object ) && $params->object == $pod[ 'object' ] )
|
| 1521 |
+
return pods_error( sprintf( __( 'Pod using %s already exists, you can not reuse an object across multiple pods', 'pods' ), $params->object ), $this );
|
| 1522 |
+
else
|
| 1523 |
+
return pods_error( sprintf( __( 'Pod %s already exists', 'pods' ), $params->name ), $this );
|
| 1524 |
+
}
|
| 1525 |
+
}
|
| 1526 |
+
elseif ( in_array( $params->name, array( 'order','orderby','post_type' ) ) && 'post_type' == pods_var( 'type', $params ) ) {
|
| 1527 |
+
return pods_error( sprintf( 'There are certain names that a Custom Post Types cannot be named and unfortunately, %s is one of them.', $params->name ), $this );
|
| 1528 |
+
}
|
| 1529 |
+
else {
|
| 1530 |
+
$pod = array(
|
| 1531 |
+
'id' => 0,
|
| 1532 |
+
'name' => $params->name,
|
| 1533 |
+
'label' => $params->name,
|
| 1534 |
+
'description' => '',
|
| 1535 |
+
'type' => 'pod',
|
| 1536 |
+
'storage' => 'table',
|
| 1537 |
+
'object' => '',
|
| 1538 |
+
'alias' => '',
|
| 1539 |
+
'options' => array(),
|
| 1540 |
+
'fields' => array()
|
| 1541 |
+
);
|
| 1542 |
+
}
|
| 1543 |
+
|
| 1544 |
+
// Blank out fields and options for AJAX calls (everything should be sent to it for a full overwrite)
|
| 1545 |
+
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
|
| 1546 |
+
$pod[ 'fields' ] = array();
|
| 1547 |
+
$pod[ 'options' ] = array();
|
| 1548 |
+
}
|
| 1549 |
+
|
| 1550 |
+
// Setup options
|
| 1551 |
+
$options = get_object_vars( $params );
|
| 1552 |
+
|
| 1553 |
+
if ( isset( $options[ 'method' ] ) )
|
| 1554 |
+
unset( $options[ 'method' ] );
|
| 1555 |
+
|
| 1556 |
+
$options_ignore = array(
|
| 1557 |
+
'object_type',
|
| 1558 |
+
'object_name',
|
| 1559 |
+
'table',
|
| 1560 |
+
'meta_table',
|
| 1561 |
+
'pod_table',
|
| 1562 |
+
'field_id',
|
| 1563 |
+
'field_index',
|
| 1564 |
+
'field_slug',
|
| 1565 |
+
'field_type',
|
| 1566 |
+
'field_parent',
|
| 1567 |
+
'field_parent_select',
|
| 1568 |
+
'meta_field_id',
|
| 1569 |
+
'meta_field_index',
|
| 1570 |
+
'meta_field_value',
|
| 1571 |
+
'pod_field_id',
|
| 1572 |
+
'pod_field_index',
|
| 1573 |
+
'object_fields',
|
| 1574 |
+
'join',
|
| 1575 |
+
'where',
|
| 1576 |
+
'where_default',
|
| 1577 |
+
'orderby',
|
| 1578 |
+
'pod',
|
| 1579 |
+
'recurse',
|
| 1580 |
+
'table_info',
|
| 1581 |
+
'attributes',
|
| 1582 |
+
'group',
|
| 1583 |
+
'grouped',
|
| 1584 |
+
'developer_mode',
|
| 1585 |
+
'dependency',
|
| 1586 |
+
'depends-on',
|
| 1587 |
+
'excludes-on'
|
| 1588 |
+
);
|
| 1589 |
+
|
| 1590 |
+
foreach ( $options_ignore as $ignore ) {
|
| 1591 |
+
if ( isset( $options[ $ignore ] ) )
|
| 1592 |
+
unset( $options[ $ignore ] );
|
| 1593 |
+
}
|
| 1594 |
+
|
| 1595 |
+
$exclude = array(
|
| 1596 |
+
'id',
|
| 1597 |
+
'name',
|
| 1598 |
+
'label',
|
| 1599 |
+
'description',
|
| 1600 |
+
'type',
|
| 1601 |
+
'storage',
|
| 1602 |
+
'object',
|
| 1603 |
+
'alias',
|
| 1604 |
+
'options',
|
| 1605 |
+
'fields'
|
| 1606 |
+
);
|
| 1607 |
+
|
| 1608 |
+
foreach ( $exclude as $k => $exclude_field ) {
|
| 1609 |
+
$aliases = array( $exclude_field );
|
| 1610 |
+
|
| 1611 |
+
if ( is_array( $exclude_field ) ) {
|
| 1612 |
+
$aliases = array_merge( array( $k ), $exclude_field );
|
| 1613 |
+
$exclude_field = $k;
|
| 1614 |
+
}
|
| 1615 |
+
|
| 1616 |
+
foreach ( $aliases as $alias ) {
|
| 1617 |
+
if ( isset( $options[ $alias ] ) ) {
|
| 1618 |
+
$pod[ $exclude_field ] = pods_trim( $options[ $alias ] );
|
| 1619 |
+
|
| 1620 |
+
unset( $options[ $alias ] );
|
| 1621 |
+
}
|
| 1622 |
+
}
|
| 1623 |
+
}
|
| 1624 |
+
|
| 1625 |
+
if ( pods_tableless() && !in_array( $pod[ 'type' ], array( 'settings', 'table' ) ) ) {
|
| 1626 |
+
if ( 'pod' == $pod[ 'type' ] )
|
| 1627 |
+
$pod[ 'type' ] = 'post_type';
|
| 1628 |
+
|
| 1629 |
+
if ( 'table' == $pod[ 'storage' ] ) {
|
| 1630 |
+
if ( 'taxonomy' == $pod[ 'type' ] )
|
| 1631 |
+
$pod[ 'storage' ] = 'none';
|
| 1632 |
+
else
|
| 1633 |
+
$pod[ 'storage' ] = 'meta';
|
| 1634 |
+
}
|
| 1635 |
+
}
|
| 1636 |
+
|
| 1637 |
+
$pod[ 'options' ][ 'type' ] = $pod[ 'type' ];
|
| 1638 |
+
$pod[ 'options' ][ 'storage' ] = $pod[ 'storage' ];
|
| 1639 |
+
$pod[ 'options' ][ 'object' ] = $pod[ 'object' ];
|
| 1640 |
+
$pod[ 'options' ][ 'alias' ] = $pod[ 'alias' ];
|
| 1641 |
+
|
| 1642 |
+
$pod[ 'options' ] = array_merge( $pod[ 'options' ], $options );
|
| 1643 |
|
| 1644 |
+
/**
|
| 1645 |
+
* @var WP_Query
|
| 1646 |
+
*/
|
| 1647 |
+
global $wp_query;
|
| 1648 |
+
|
| 1649 |
+
$reserved_query_vars = array(
|
| 1650 |
+
'post_type',
|
| 1651 |
+
'taxonomy',
|
| 1652 |
+
'output'
|
| 1653 |
+
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1654 |
|
| 1655 |
+
if ( is_object( $wp_query ) ) {
|
| 1656 |
+
$reserved_query_vars = array_merge( $reserved_query_vars, array_keys( $wp_query->fill_query_vars( array() ) ) );
|
| 1657 |
}
|
| 1658 |
|
| 1659 |
+
if ( isset( $pod[ 'options' ][ 'query_var_string' ] ) ) {
|
| 1660 |
+
if ( in_array( $pod[ 'options' ][ 'query_var_string' ], $reserved_query_vars ) ) {
|
| 1661 |
+
$pod[ 'options' ][ 'query_var_string' ] = $pod[ 'options' ][ 'type' ] . '_' . $pod[ 'options' ][ 'query_var_string' ];
|
| 1662 |
+
}
|
| 1663 |
+
}
|
| 1664 |
+
|
| 1665 |
+
if ( isset( $pod[ 'options' ][ 'query_var' ] ) ) {
|
| 1666 |
+
if ( in_array( $pod[ 'options' ][ 'query_var' ], $reserved_query_vars ) ) {
|
| 1667 |
+
$pod[ 'options' ][ 'query_var' ] = $pod[ 'options' ][ 'type' ] . '_' . $pod[ 'options' ][ 'query_var' ];
|
| 1668 |
+
}
|
| 1669 |
+
}
|
| 1670 |
+
|
| 1671 |
+
if ( strlen( $pod[ 'label' ] ) < 1 )
|
| 1672 |
+
$pod[ 'label' ] = $pod[ 'name' ];
|
| 1673 |
+
|
| 1674 |
+
if ( 'post_type' == $pod[ 'type' ] ) {
|
| 1675 |
+
// Max length for post types are 20 characters
|
| 1676 |
+
$pod[ 'name' ] = substr( $pod[ 'name' ], 0, 20 );
|
| 1677 |
+
}
|
| 1678 |
+
elseif ( 'taxonomy' == $pod[ 'type' ] ) {
|
| 1679 |
+
// Max length for taxonomies are 32 characters
|
| 1680 |
+
$pod[ 'name' ] = substr( $pod[ 'name' ], 0, 32 );
|
| 1681 |
+
}
|
| 1682 |
+
|
| 1683 |
+
$params->id = $pod[ 'id' ];
|
| 1684 |
+
$params->name = $pod[ 'name' ];
|
| 1685 |
+
|
| 1686 |
+
if ( null !== $old_name && $old_name != $params->name && empty( $pod[ 'object' ] ) ) {
|
| 1687 |
+
if ( 'post_type' == $pod[ 'type' ] ) {
|
| 1688 |
+
$check = get_post_type_object( $params->name );
|
| 1689 |
+
|
| 1690 |
+
if ( !empty( $check ) )
|
| 1691 |
+
return pods_error( sprintf( __( 'Post Type %s already exists, you cannot rename %s to that', 'pods' ), $params->name, $old_name ), $this );
|
| 1692 |
+
}
|
| 1693 |
+
elseif ( 'taxonomy' == $pod[ 'type' ] ) {
|
| 1694 |
+
$check = get_taxonomy( $params->name );
|
| 1695 |
+
|
| 1696 |
+
if ( !empty( $check ) )
|
| 1697 |
+
return pods_error( sprintf( __( 'Taxonomy %s already exists, you cannot rename %s to that', 'pods' ), $params->name, $old_name ), $this );
|
| 1698 |
+
}
|
| 1699 |
+
}
|
| 1700 |
+
|
| 1701 |
+
$field_table_operation = true;
|
| 1702 |
+
|
| 1703 |
+
// Add new pod
|
| 1704 |
+
if ( empty( $params->id ) ) {
|
| 1705 |
+
if ( strlen( $params->name ) < 1 )
|
| 1706 |
+
return pods_error( __( 'Pod name cannot be empty', 'pods' ), $this );
|
| 1707 |
+
|
| 1708 |
+
$post_data = array(
|
| 1709 |
+
'post_name' => $pod[ 'name' ],
|
| 1710 |
+
'post_title' => $pod[ 'label' ],
|
| 1711 |
+
'post_content' => $pod[ 'description' ],
|
| 1712 |
+
'post_type' => '_pods_pod',
|
| 1713 |
+
'post_status' => 'publish'
|
| 1714 |
+
);
|
| 1715 |
+
|
| 1716 |
+
if ( 'pod' == $pod[ 'type' ] && ( !is_array( $pod[ 'fields' ] ) || empty( $pod[ 'fields' ] ) ) ) {
|
| 1717 |
+
$pod[ 'fields' ] = array();
|
| 1718 |
+
|
| 1719 |
+
$pod[ 'fields' ][ 'name' ] = array(
|
| 1720 |
+
'name' => 'name',
|
| 1721 |
+
'label' => 'Name',
|
| 1722 |
+
'type' => 'text',
|
| 1723 |
+
'options' => array(
|
| 1724 |
+
'required' => '1'
|
| 1725 |
+
)
|
| 1726 |
+
);
|
| 1727 |
+
|
| 1728 |
+
$pod[ 'fields' ][ 'created' ] = array(
|
| 1729 |
+
'name' => 'created',
|
| 1730 |
+
'label' => 'Date Created',
|
| 1731 |
+
'type' => 'datetime',
|
| 1732 |
+
'options' => array(
|
| 1733 |
+
'datetime_format' => 'ymd_slash',
|
| 1734 |
+
'datetime_time_type' => '12',
|
| 1735 |
+
'datetime_time_format' => 'h_mm_ss_A'
|
| 1736 |
+
)
|
| 1737 |
+
);
|
| 1738 |
+
|
| 1739 |
+
$pod[ 'fields' ][ 'modified' ] = array(
|
| 1740 |
+
'name' => 'modified',
|
| 1741 |
+
'label' => 'Date Modified',
|
| 1742 |
+
'type' => 'datetime',
|
| 1743 |
+
'options' => array(
|
| 1744 |
+
'datetime_format' => 'ymd_slash',
|
| 1745 |
+
'datetime_time_type' => '12',
|
| 1746 |
+
'datetime_time_format' => 'h_mm_ss_A'
|
| 1747 |
+
)
|
| 1748 |
+
);
|
| 1749 |
+
|
| 1750 |
+
$pod[ 'fields' ][ 'author' ] = array(
|
| 1751 |
+
'name' => 'author',
|
| 1752 |
+
'label' => 'Author',
|
| 1753 |
+
'type' => 'pick',
|
| 1754 |
+
'pick_object' => 'user',
|
| 1755 |
+
'options' => array(
|
| 1756 |
+
'pick_format_type' => 'single',
|
| 1757 |
+
'pick_format_single' => 'autocomplete',
|
| 1758 |
+
'default_value' => '{@user.ID}'
|
| 1759 |
+
)
|
| 1760 |
+
);
|
| 1761 |
+
|
| 1762 |
+
$pod[ 'fields' ][ 'permalink' ] = array(
|
| 1763 |
+
'name' => 'permalink',
|
| 1764 |
+
'label' => 'Permalink',
|
| 1765 |
+
'type' => 'slug',
|
| 1766 |
+
'description' => 'Leave blank to auto-generate from Name'
|
| 1767 |
+
);
|
| 1768 |
+
|
| 1769 |
+
if ( !isset( $pod[ 'options' ][ 'pod_index' ] ) )
|
| 1770 |
+
$pod[ 'options' ][ 'pod_index' ] = 'name';
|
| 1771 |
+
}
|
| 1772 |
+
|
| 1773 |
+
$pod = $this->do_hook( 'save_pod_default_pod', $pod, $params, $sanitized, $db );
|
| 1774 |
+
|
| 1775 |
+
$field_table_operation = false;
|
| 1776 |
+
}
|
| 1777 |
+
else {
|
| 1778 |
+
$post_data = array(
|
| 1779 |
+
'ID' => $pod[ 'id' ],
|
| 1780 |
+
'post_name' => $pod[ 'name' ],
|
| 1781 |
+
'post_title' => $pod[ 'label' ],
|
| 1782 |
+
'post_content' => $pod[ 'description' ],
|
| 1783 |
+
'post_status' => 'publish'
|
| 1784 |
+
);
|
| 1785 |
+
}
|
| 1786 |
+
|
| 1787 |
+
if ( true === $db ) {
|
| 1788 |
+
if ( !has_filter( 'wp_unique_post_slug', array( $this, 'save_slug_fix' ) ) )
|
| 1789 |
+
add_filter( 'wp_unique_post_slug', array( $this, 'save_slug_fix' ), 100, 6 );
|
| 1790 |
+
|
| 1791 |
+
$conflicted = false;
|
| 1792 |
+
|
| 1793 |
+
// Headway compatibility fix
|
| 1794 |
+
if ( has_filter( 'wp_insert_post_data', 'headway_clean_slug', 0 ) ) {
|
| 1795 |
+
remove_filter( 'wp_insert_post_data', 'headway_clean_slug', 0 );
|
| 1796 |
+
|
| 1797 |
+
$conflicted = true;
|
| 1798 |
+
}
|
| 1799 |
+
|
| 1800 |
+
$params->id = $this->save_wp_object( 'post', $post_data, $pod[ 'options' ], true, true );
|
| 1801 |
+
|
| 1802 |
+
if ( $conflicted )
|
| 1803 |
+
add_filter( 'wp_insert_post_data', 'headway_clean_slug', 0 );
|
| 1804 |
+
|
| 1805 |
+
if ( false === $params->id )
|
| 1806 |
+
return pods_error( __( 'Cannot save Pod', 'pods' ), $this );
|
| 1807 |
+
}
|
| 1808 |
+
elseif ( empty( $params->id ) )
|
| 1809 |
+
$params->id = (int) $db;
|
| 1810 |
+
|
| 1811 |
+
$pod[ 'id' ] = $params->id;
|
| 1812 |
+
|
| 1813 |
+
// Setup / update tables
|
| 1814 |
+
if ( 'table' != $pod[ 'type' ] && 'table' == $pod[ 'storage' ] && $old_storage != $pod[ 'storage' ] && $db ) {
|
| 1815 |
+
$definitions = array( "`id` BIGINT(20) UNSIGNED AUTO_INCREMENT PRIMARY KEY" );
|
| 1816 |
+
|
| 1817 |
+
$defined_fields = array();
|
| 1818 |
+
|
| 1819 |
+
foreach ( $pod[ 'fields' ] as $field ) {
|
| 1820 |
+
if ( !is_array( $field ) || !isset( $field[ 'name' ] ) || in_array( $field[ 'name' ], $defined_fields ) )
|
| 1821 |
+
continue;
|
| 1822 |
+
|
| 1823 |
+
$defined_fields[] = $field[ 'name' ];
|
| 1824 |
+
|
| 1825 |
+
if ( !in_array( $field[ 'type' ], $tableless_field_types ) || ( 'pick' == $field[ 'type' ] && in_array( pods_var( 'pick_object', $field ), $simple_tableless_objects ) ) ) {
|
| 1826 |
+
$definition = $this->get_field_definition( $field[ 'type' ], array_merge( $field, pods_var_raw( 'options', $field, array() ) ) );
|
| 1827 |
+
|
| 1828 |
+
if ( 0 < strlen( $definition ) )
|
| 1829 |
+
$definitions[] = "`{$field['name']}` " . $definition;
|
| 1830 |
+
}
|
| 1831 |
+
}
|
| 1832 |
+
|
| 1833 |
+
pods_query( "DROP TABLE IF EXISTS `@wp_pods_{$params->name}`" );
|
| 1834 |
+
|
| 1835 |
+
$result = pods_query( "CREATE TABLE `@wp_pods_{$params->name}` (" . implode( ', ', $definitions ) . ") DEFAULT CHARSET utf8", $this );
|
| 1836 |
+
|
| 1837 |
+
if ( empty( $result ) )
|
| 1838 |
+
return pods_error( __( 'Cannot add Database Table for Pod', 'pods' ), $this );
|
| 1839 |
+
|
| 1840 |
+
}
|
| 1841 |
+
elseif ( 'table' != $pod[ 'type' ] && 'table' == $pod[ 'storage' ] && $pod[ 'storage' ] == $old_storage && null !== $old_name && $old_name != $params->name && $db ) {
|
| 1842 |
+
$result = pods_query( "ALTER TABLE `@wp_pods_{$old_name}` RENAME `@wp_pods_{$params->name}`", $this );
|
| 1843 |
+
|
| 1844 |
+
if ( empty( $result ) )
|
| 1845 |
+
return pods_error( __( 'Cannot update Database Table for Pod', 'pods' ), $this );
|
| 1846 |
+
}
|
| 1847 |
+
|
| 1848 |
+
/**
|
| 1849 |
+
* @var $wpdb wpdb
|
| 1850 |
+
*/
|
| 1851 |
+
global $wpdb;
|
| 1852 |
+
|
| 1853 |
+
if ( null !== $old_name && $old_name != $params->name && $db ) {
|
| 1854 |
+
// Rename items in the DB pointed at the old WP Object names
|
| 1855 |
+
if ( 'post_type' == $pod[ 'type' ] && empty( $pod[ 'object' ] ) ) {
|
| 1856 |
+
$this->rename_wp_object_type( 'post', $old_name, $params->name );
|
| 1857 |
+
}
|
| 1858 |
+
elseif ( 'taxonomy' == $pod[ 'type' ] && empty( $pod[ 'object' ] ) ) {
|
| 1859 |
+
$this->rename_wp_object_type( 'taxonomy', $old_name, $params->name );
|
| 1860 |
+
}
|
| 1861 |
+
elseif ( 'comment' == $pod[ 'type' ] && empty( $pod[ 'object' ] ) ) {
|
| 1862 |
+
$this->rename_wp_object_type( 'comment', $old_name, $params->name );
|
| 1863 |
+
}
|
| 1864 |
+
elseif ( 'settings' == $pod[ 'type' ] ) {
|
| 1865 |
+
$this->rename_wp_object_type( 'settings', $old_name, $params->name );
|
| 1866 |
+
}
|
| 1867 |
|
| 1868 |
+
// Sync any related fields if the name has changed
|
| 1869 |
+
$fields = pods_query( "
|
| 1870 |
+
SELECT `p`.`ID`
|
| 1871 |
+
FROM `{$wpdb->posts}` AS `p`
|
| 1872 |
+
LEFT JOIN `{$wpdb->postmeta}` AS `pm` ON `pm`.`post_id` = `p`.`ID`
|
| 1873 |
+
LEFT JOIN `{$wpdb->postmeta}` AS `pm2` ON `pm2`.`post_id` = `p`.`ID`
|
| 1874 |
+
WHERE
|
| 1875 |
+
`p`.`post_type` = '_pods_field'
|
| 1876 |
+
AND `pm`.`meta_key` = 'pick_object'
|
| 1877 |
+
AND (
|
| 1878 |
+
`pm`.`meta_value` = 'pod'
|
| 1879 |
+
OR `pm`.`meta_value` = '" . $pod[ 'type' ] . "'
|
| 1880 |
+
)
|
| 1881 |
+
AND `pm2`.`meta_key` = 'pick_val'
|
| 1882 |
+
AND `pm2`.`meta_value` = '{$old_name}'
|
| 1883 |
+
" );
|
| 1884 |
+
|
| 1885 |
+
if ( !empty( $fields ) ) {
|
| 1886 |
+
foreach ( $fields as $field ) {
|
| 1887 |
+
update_post_meta( $field->ID, 'pick_object', $pod[ 'type' ] );
|
| 1888 |
+
update_post_meta( $field->ID, 'pick_val', $params->name );
|
| 1889 |
+
}
|
| 1890 |
+
}
|
| 1891 |
+
|
| 1892 |
+
$fields = pods_query( "
|
| 1893 |
+
SELECT `p`.`ID`
|
| 1894 |
+
FROM `{$wpdb->posts}` AS `p`
|
| 1895 |
+
LEFT JOIN `{$wpdb->postmeta}` AS `pm` ON `pm`.`post_id` = `p`.`ID`
|
| 1896 |
+
WHERE
|
| 1897 |
+
`p`.`post_type` = '_pods_field'
|
| 1898 |
+
AND `pm`.`meta_key` = 'pick_object'
|
| 1899 |
+
AND (
|
| 1900 |
+
`pm`.`meta_value` = 'pod-{$old_name}'
|
| 1901 |
+
OR `pm`.`meta_value` = '" . $pod[ 'type' ] . "-{$old_name}'
|
| 1902 |
+
)
|
| 1903 |
+
" );
|
| 1904 |
|
| 1905 |
+
if ( !empty( $fields ) ) {
|
| 1906 |
+
foreach ( $fields as $field ) {
|
| 1907 |
+
update_post_meta( $field->ID, 'pick_object', $pod[ 'type' ] );
|
| 1908 |
+
update_post_meta( $field->ID, 'pick_val', $params->name );
|
| 1909 |
+
}
|
| 1910 |
+
}
|
| 1911 |
+
}
|
| 1912 |
|
| 1913 |
+
// Sync built-in options for post types and taxonomies
|
| 1914 |
+
if ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) && empty( $pod[ 'object' ] ) && $db ) {
|
| 1915 |
+
// Build list of 'built_in' for later
|
| 1916 |
+
$built_in = array();
|
| 1917 |
|
| 1918 |
+
foreach ( $pod[ 'options' ] as $key => $val ) {
|
| 1919 |
+
if ( false === strpos( $key, 'built_in_' ) )
|
| 1920 |
+
continue;
|
| 1921 |
+
elseif ( false !== strpos( $key, 'built_in_post_types_' ) )
|
| 1922 |
+
$built_in_type = 'post_type';
|
| 1923 |
+
elseif ( false !== strpos( $key, 'built_in_taxonomies_' ) )
|
| 1924 |
+
$built_in_type = 'taxonomy';
|
| 1925 |
+
else
|
| 1926 |
+
continue;
|
| 1927 |
|
| 1928 |
+
if ( $built_in_type == $pod[ 'type' ] )
|
| 1929 |
+
continue;
|
| 1930 |
|
| 1931 |
+
if ( !isset( $built_in[ $built_in_type ] ) )
|
| 1932 |
+
$built_in[ $built_in_type ] = array();
|
|
|
|
|
|
|
|
|
|
| 1933 |
|
| 1934 |
+
$built_in_object = str_replace( array( 'built_in_post_types_', 'built_in_taxonomies_' ), '', $key );
|
|
|
|
|
|
|
|
|
|
| 1935 |
|
| 1936 |
+
$built_in[ $built_in_type ][ $built_in_object ] = (int) $val;
|
| 1937 |
+
}
|
|
|
|
|
|
|
| 1938 |
|
| 1939 |
+
$lookup_option = $lookup_built_in = false;
|
|
|
|
| 1940 |
|
| 1941 |
+
$lookup_name = $pod[ 'name' ];
|
| 1942 |
|
| 1943 |
+
if ( 'post_type' == $pod[ 'type' ] ) {
|
| 1944 |
+
$lookup_option = 'built_in_post_types_' . $lookup_name;
|
| 1945 |
+
$lookup_built_in = 'taxonomy';
|
| 1946 |
+
}
|
| 1947 |
+
elseif ( 'taxonomy' == $pod[ 'type' ] ) {
|
| 1948 |
+
$lookup_option = 'built_in_taxonomies_' . $lookup_name;
|
| 1949 |
+
$lookup_built_in = 'post_type';
|
| 1950 |
+
}
|
| 1951 |
|
| 1952 |
+
if ( !empty( $lookup_option ) && !empty( $lookup_built_in ) && isset( $built_in[ $lookup_built_in ] ) ) {
|
| 1953 |
+
foreach ( $built_in[ $lookup_built_in ] as $built_in_object => $val ) {
|
| 1954 |
+
$search_val = 1;
|
| 1955 |
|
| 1956 |
+
if ( 1 == $val )
|
| 1957 |
+
$search_val = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1958 |
|
| 1959 |
+
$query = "SELECT p.ID FROM {$wpdb->posts} AS p
|
| 1960 |
+
LEFT JOIN {$wpdb->postmeta} AS pm ON pm.post_id = p.ID AND pm.meta_key = '{$lookup_option}'
|
| 1961 |
+
LEFT JOIN {$wpdb->postmeta} AS pm2 ON pm2.post_id = p.ID AND pm2.meta_key = 'type' AND pm2.meta_value = '{$lookup_built_in}'
|
| 1962 |
+
LEFT JOIN {$wpdb->postmeta} AS pm3 ON pm3.post_id = p.ID AND pm3.meta_key = 'object' AND pm3.meta_value = ''
|
| 1963 |
+
WHERE p.post_type = '_pods_pod' AND p.post_name = '{$built_in_object}'
|
| 1964 |
+
AND pm2.meta_id IS NOT NULL
|
| 1965 |
+
AND ( pm.meta_id IS NULL OR pm.meta_value = {$search_val} )";
|
| 1966 |
|
| 1967 |
+
$results = pods_query( $query );
|
| 1968 |
|
| 1969 |
+
if ( !empty( $results ) ) {
|
| 1970 |
+
foreach ( $results as $the_pod ) {
|
| 1971 |
+
delete_post_meta( $the_pod->ID, $lookup_option );
|
| 1972 |
|
| 1973 |
+
add_post_meta( $the_pod->ID, $lookup_option, $val );
|
| 1974 |
+
}
|
| 1975 |
+
}
|
| 1976 |
+
}
|
| 1977 |
+
}
|
| 1978 |
+
}
|
| 1979 |
|
| 1980 |
+
$saved = array();
|
| 1981 |
+
$errors = array();
|
| 1982 |
|
| 1983 |
+
$field_index_change = false;
|
| 1984 |
+
$field_index_id = 0;
|
| 1985 |
|
| 1986 |
+
$id_required = false;
|
|
|
|
|
|
|
| 1987 |
|
| 1988 |
+
$field_index = pods_var( 'pod_index', $pod[ 'options' ], 'id', null, true );
|
|
|
|
|
|
|
| 1989 |
|
| 1990 |
+
if ( 'pod' == $pod[ 'type' ] && !empty( $pod[ 'fields' ] ) && isset( $pod[ 'fields' ][ $field_index ] ) )
|
| 1991 |
+
$field_index_id = $pod[ 'fields' ][ $field_index ];
|
|
|
|
| 1992 |
|
| 1993 |
+
if ( isset( $params->fields ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
|
| 1994 |
+
$fields = array();
|
| 1995 |
|
| 1996 |
+
if ( isset( $params->fields ) ) {
|
| 1997 |
+
$params->fields = (array) $params->fields;
|
| 1998 |
|
| 1999 |
+
$weight = 0;
|
|
|
|
| 2000 |
|
| 2001 |
+
foreach ( $params->fields as $field ) {
|
| 2002 |
+
if ( !is_array( $field ) || !isset( $field[ 'name' ] ) )
|
| 2003 |
+
continue;
|
| 2004 |
|
| 2005 |
+
if ( !isset( $field[ 'weight' ] ) ) {
|
| 2006 |
+
$field[ 'weight' ] = $weight;
|
| 2007 |
+
|
| 2008 |
+
$weight++;
|
| 2009 |
+
}
|
|
|
|
|
|
|
|
|
|
| 2010 |
|
| 2011 |
+
$fields[ $field[ 'name' ] ] = $field;
|
| 2012 |
+
}
|
| 2013 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2014 |
|
| 2015 |
+
$weight = 0;
|
|
|
|
|
|
|
| 2016 |
|
| 2017 |
+
$saved_field_ids = array();
|
|
|
|
| 2018 |
|
| 2019 |
+
foreach ( $pod[ 'fields' ] as $k => $field ) {
|
| 2020 |
+
if ( !empty( $old_id ) && ( !is_array( $field ) || !isset( $field[ 'name' ] ) || !isset( $fields[ $field[ 'name' ] ] ) ) ) {
|
| 2021 |
+
// Iterative change handling for setup-edit.php
|
| 2022 |
+
if ( !is_array( $field ) && isset( $old_fields[ $k ] ) )
|
| 2023 |
+
$saved[ $old_fields[ $k ][ 'name' ] ] = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2024 |
|
| 2025 |
+
continue;
|
| 2026 |
+
}
|
|
|
|
| 2027 |
|
| 2028 |
+
if ( !empty( $old_id ) )
|
| 2029 |
+
$field = array_merge( $field, $fields[ $field[ 'name' ] ] );
|
| 2030 |
+
|
| 2031 |
+
$field[ 'pod' ] = $pod;
|
| 2032 |
+
|
| 2033 |
+
if ( !isset( $field[ 'weight' ] ) ) {
|
| 2034 |
+
$field[ 'weight' ] = $weight;
|
| 2035 |
+
|
| 2036 |
+
$weight++;
|
| 2037 |
+
}
|
| 2038 |
+
|
| 2039 |
+
if ( 0 < $field_index_id && pods_var( 'id', $field ) == $field_index_id )
|
| 2040 |
+
$field_index_change = $field[ 'name' ];
|
| 2041 |
+
|
| 2042 |
+
if ( 0 < pods_var( 'id', $field ) )
|
| 2043 |
+
$id_required = true;
|
| 2044 |
+
|
| 2045 |
+
if ( $id_required )
|
| 2046 |
+
$field[ 'id_required' ] = true;
|
| 2047 |
+
|
| 2048 |
+
$field_data = $field;
|
| 2049 |
+
|
| 2050 |
+
$field = $this->save_field( $field_data, $field_table_operation, true, $db );
|
| 2051 |
+
|
| 2052 |
+
if ( true !== $db ) {
|
| 2053 |
+
$pod[ 'fields' ][ $k ] = $field;
|
| 2054 |
+
$saved_field_ids[] = $field[ 'id' ];
|
| 2055 |
+
}
|
| 2056 |
+
else {
|
| 2057 |
+
if ( !empty( $field ) && 0 < $field ) {
|
| 2058 |
+
$saved[ $field_data[ 'name' ] ] = true;
|
| 2059 |
+
$saved_field_ids[] = $field;
|
| 2060 |
+
}
|
| 2061 |
+
else
|
| 2062 |
+
$errors[] = sprintf( __( 'Cannot save the %s field', 'pods' ), $field_data[ 'name' ] );
|
| 2063 |
+
}
|
| 2064 |
+
}
|
| 2065 |
+
|
| 2066 |
+
if ( true === $db ) {
|
| 2067 |
+
foreach ( $old_fields as $field ) {
|
| 2068 |
+
if ( isset( $pod[ 'fields' ][ $field[ 'name' ] ] ) || isset( $saved[ $field[ 'name' ] ] ) || in_array( $field[ 'id' ], $saved_field_ids ) )
|
| 2069 |
+
continue;
|
| 2070 |
+
|
| 2071 |
+
if ( $field[ 'id' ] == $field_index_id )
|
| 2072 |
+
$field_index_change = 'id';
|
| 2073 |
+
elseif ( $field[ 'name' ] == $field_index )
|
| 2074 |
+
$field_index_change = 'id';
|
| 2075 |
+
|
| 2076 |
+
$this->delete_field( array(
|
| 2077 |
+
'id' => (int) $field[ 'id' ],
|
| 2078 |
+
'name' => $field[ 'name' ],
|
| 2079 |
+
'pod' => $pod
|
| 2080 |
+
), $field_table_operation );
|
| 2081 |
+
}
|
| 2082 |
+
}
|
| 2083 |
+
|
| 2084 |
+
// Update field index if the name has changed or the field has been removed
|
| 2085 |
+
if ( false !== $field_index_change && true === $db )
|
| 2086 |
+
update_post_meta( $pod[ 'id' ], 'pod_index', $field_index_change );
|
| 2087 |
+
}
|
| 2088 |
+
|
| 2089 |
+
if ( !empty( $errors ) )
|
| 2090 |
+
return pods_error( $errors, $this );
|
| 2091 |
+
|
| 2092 |
+
$this->cache_flush_pods( $pod );
|
| 2093 |
+
|
| 2094 |
+
if ( 'post_type' == $pod[ 'type' ] )
|
| 2095 |
+
PodsMeta::$post_types[ $pod[ 'id' ] ] = $this->load_pod( array( 'name' => $pod[ 'name' ] ) );
|
| 2096 |
+
elseif ( 'taxonomy' == $pod[ 'type' ] )
|
| 2097 |
+
PodsMeta::$taxonomies[ $pod[ 'id' ] ] = $this->load_pod( array( 'name' => $pod[ 'name' ] ) );
|
| 2098 |
+
elseif ( 'media' == $pod[ 'type' ] )
|
| 2099 |
+
PodsMeta::$media[ $pod[ 'id' ] ] = $this->load_pod( array( 'name' => $pod[ 'name' ] ) );
|
| 2100 |
+
elseif ( 'user' == $pod[ 'type' ] )
|
| 2101 |
+
PodsMeta::$user[ $pod[ 'id' ] ] = $this->load_pod( array( 'name' => $pod[ 'name' ] ) );
|
| 2102 |
+
elseif ( 'comment' == $pod[ 'type' ] )
|
| 2103 |
+
PodsMeta::$comment[ $pod[ 'id' ] ] = $this->load_pod( array( 'name' => $pod[ 'name' ] ) );
|
| 2104 |
+
|
| 2105 |
+
// Register Post Types / Taxonomies post-registration from PodsInit
|
| 2106 |
+
if ( !empty( PodsInit::$content_types_registered ) && in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) && empty( $pod[ 'object' ] ) ) {
|
| 2107 |
+
global $pods_init;
|
| 2108 |
+
|
| 2109 |
+
$pods_init->setup_content_types( true );
|
| 2110 |
+
}
|
| 2111 |
+
|
| 2112 |
+
if ( true === $db )
|
| 2113 |
+
return $pod[ 'id' ];
|
| 2114 |
+
else
|
| 2115 |
+
return $pod;
|
| 2116 |
+
}
|
| 2117 |
+
|
| 2118 |
+
/**
|
| 2119 |
+
* Add or edit a field within a Pod
|
| 2120 |
+
*
|
| 2121 |
+
* $params['id'] int Field ID (id OR pod_id+pod+name required)
|
| 2122 |
+
* $params['pod_id'] int Pod ID (id OR pod_id+pod+name required)
|
| 2123 |
+
* $params['pod'] string Pod name (id OR pod_id+pod+name required)
|
| 2124 |
+
* $params['name'] string Field name (id OR pod_id+pod+name required)
|
| 2125 |
+
* $params['label'] string (optional) Field label
|
| 2126 |
+
* $params['type'] string (optional) Field type (avatar, boolean, code, color, currency, date, datetime, email, file, number, paragraph, password, phone, pick, slug, text, time, website, wysiwyg)
|
| 2127 |
+
* $params['pick_object'] string (optional) Related Object (for relationships)
|
| 2128 |
+
* $params['pick_val'] string (optional) Related Object name (for relationships)
|
| 2129 |
+
* $params['sister_id'] int (optional) Related Field ID (for bidirectional relationships)
|
| 2130 |
+
* $params['weight'] int (optional) Order in which the field appears
|
| 2131 |
+
* $params['options'] array (optional) Options
|
| 2132 |
+
*
|
| 2133 |
+
* @param array $params An associative array of parameters
|
| 2134 |
+
* @param bool $table_operation (optional) Whether or not to handle table operations
|
| 2135 |
+
* @param bool $sanitized (optional) Decides wether the params have been sanitized before being passed, will sanitize them if false.
|
| 2136 |
+
* @param bool|int $db (optional) Whether to save into the DB or just return field array.
|
| 2137 |
+
*
|
| 2138 |
+
* @return int|array The field ID or field array (if !$db)
|
| 2139 |
+
* @since 1.7.9
|
| 2140 |
+
*/
|
| 2141 |
+
public function save_field ( $params, $table_operation = true, $sanitized = false, $db = true ) {
|
| 2142 |
+
/**
|
| 2143 |
+
* @var $wpdb wpdb
|
| 2144 |
+
*/
|
| 2145 |
+
global $wpdb;
|
| 2146 |
+
|
| 2147 |
+
if ( true !== $db )
|
| 2148 |
+
$table_operation = false;
|
| 2149 |
+
|
| 2150 |
+
$tableless_field_types = PodsForm::tableless_field_types();
|
| 2151 |
+
$simple_tableless_objects = PodsForm::simple_tableless_objects();
|
| 2152 |
+
|
| 2153 |
+
$params = (object) $params;
|
| 2154 |
+
|
| 2155 |
+
if ( false === $sanitized )
|
| 2156 |
+
$params = pods_sanitize( $params );
|
| 2157 |
+
|
| 2158 |
+
if ( isset( $params->pod_id ) )
|
| 2159 |
+
$params->pod_id = pods_absint( $params->pod_id );
|
| 2160 |
+
|
| 2161 |
+
if ( true !== $db )
|
| 2162 |
+
$params->pod_id = (int) $db;
|
| 2163 |
+
|
| 2164 |
+
$pod = null;
|
| 2165 |
+
$save_pod = false;
|
| 2166 |
+
$id_required = false;
|
| 2167 |
+
|
| 2168 |
+
if ( isset( $params->id_required ) ) {
|
| 2169 |
+
unset( $params->id_required );
|
| 2170 |
+
|
| 2171 |
+
$id_required = true;
|
| 2172 |
+
}
|
| 2173 |
+
|
| 2174 |
+
if ( ( !isset( $params->pod ) || empty( $params->pod ) ) && ( !isset( $params->pod_id ) || empty( $params->pod_id ) ) )
|
| 2175 |
+
return pods_error( __( 'Pod ID or name is required', 'pods' ), $this );
|
| 2176 |
+
|
| 2177 |
+
if ( isset( $params->pod ) && is_array( $params->pod ) ) {
|
| 2178 |
+
$pod = $params->pod;
|
| 2179 |
+
|
| 2180 |
+
$save_pod = true;
|
| 2181 |
+
}
|
| 2182 |
+
elseif ( ( !isset( $params->pod_id ) || empty( $params->pod_id ) ) && ( true === $db || 0 < $db ) )
|
| 2183 |
+
$pod = $this->load_pod( array( 'name' => $params->pod, 'table_info' => true ) );
|
| 2184 |
+
elseif ( !isset( $params->pod ) && ( true === $db || 0 < $db ) )
|
| 2185 |
+
$pod = $this->load_pod( array( 'id' => $params->pod_id, 'table_info' => true ) );
|
| 2186 |
+
elseif ( true === $db || 0 < $db )
|
| 2187 |
+
$pod = $this->load_pod( array( 'id' => $params->pod_id, 'name' => $params->pod, 'table_info' => true ) );
|
| 2188 |
+
|
| 2189 |
+
if ( empty( $pod ) && true === $db )
|
| 2190 |
+
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
| 2191 |
+
|
| 2192 |
+
$params->pod_id = $pod[ 'id' ];
|
| 2193 |
+
$params->pod = $pod[ 'name' ];
|
| 2194 |
+
$params->pod_data = $pod;
|
| 2195 |
+
|
| 2196 |
+
$params->name = pods_clean_name( $params->name, true, ( 'meta' == $pod[ 'storage' ] ? false : true ) );
|
| 2197 |
+
|
| 2198 |
+
if ( !isset( $params->id ) )
|
| 2199 |
+
$params->id = 0;
|
| 2200 |
+
|
| 2201 |
+
if ( empty( $params->name ) )
|
| 2202 |
+
return pods_error( 'Pod field name is required', $this );
|
| 2203 |
+
|
| 2204 |
+
$field = $this->load_field( $params );
|
| 2205 |
+
|
| 2206 |
+
unset( $params->pod_data );
|
| 2207 |
+
|
| 2208 |
+
$old_id = $old_name = $old_type = $old_definition = $old_simple = $old_options = $old_sister_id = null;
|
| 2209 |
+
|
| 2210 |
+
if ( !empty( $field ) ) {
|
| 2211 |
+
$old_id = pods_var( 'id', $field );
|
| 2212 |
+
$old_name = pods_clean_name( $field[ 'name' ], true, ( 'meta' == $pod[ 'storage' ] ? false : true ) );
|
| 2213 |
+
$old_type = $field[ 'type' ];
|
| 2214 |
+
$old_options = $field[ 'options' ];
|
| 2215 |
+
$old_sister_id = (int) pods_var( 'sister_id', $old_options, 0 );
|
| 2216 |
+
|
| 2217 |
+
$old_simple = ( 'pick' == $old_type && in_array( pods_var( 'pick_object', $field ), $simple_tableless_objects ) );
|
| 2218 |
+
|
| 2219 |
+
if ( isset( $params->name ) && !empty( $params->name ) )
|
| 2220 |
+
$field[ 'name' ] = $params->name;
|
| 2221 |
+
|
| 2222 |
+
if ( $old_name != $field[ 'name' ] && false !== $this->field_exists( $params ) )
|
| 2223 |
+
return pods_error( sprintf( __( 'Field %s already exists, you cannot rename %s to that', 'pods' ), $field[ 'name' ], $old_name ), $this );
|
| 2224 |
+
|
| 2225 |
+
if ( ( $id_required || !empty( $params->id ) ) && ( empty( $old_id ) || $old_id != $params->id ) )
|
| 2226 |
+
return pods_error( sprintf( __( 'Field %s already exists', 'pods' ), $field[ 'name' ] ), $this );
|
| 2227 |
+
|
| 2228 |
+
if ( empty( $params->id ) )
|
| 2229 |
+
$params->id = $old_id;
|
| 2230 |
+
|
| 2231 |
+
if ( !in_array( $old_type, $tableless_field_types ) || $old_simple ) {
|
| 2232 |
+
$definition = $this->get_field_definition( $old_type, array_merge( $field, $old_options ) );
|
| 2233 |
+
|
| 2234 |
+
if ( 0 < strlen( $definition ) )
|
| 2235 |
+
$old_definition = "`{$old_name}` " . $definition;
|
| 2236 |
+
}
|
| 2237 |
+
}
|
| 2238 |
+
else {
|
| 2239 |
+
$field = array(
|
| 2240 |
+
'id' => 0,
|
| 2241 |
+
'pod_id' => $params->pod_id,
|
| 2242 |
+
'name' => $params->name,
|
| 2243 |
+
'label' => $params->name,
|
| 2244 |
+
'description' => '',
|
| 2245 |
+
'type' => 'text',
|
| 2246 |
+
'pick_object' => '',
|
| 2247 |
+
'pick_val' => '',
|
| 2248 |
+
'sister_id' => '',
|
| 2249 |
+
'weight' => null,
|
| 2250 |
+
'options' => array()
|
| 2251 |
+
);
|
| 2252 |
+
}
|
| 2253 |
+
|
| 2254 |
+
// Setup options
|
| 2255 |
+
$options = get_object_vars( $params );
|
| 2256 |
+
|
| 2257 |
+
$options_ignore = array(
|
| 2258 |
+
'method',
|
| 2259 |
+
'table_info',
|
| 2260 |
+
'attributes',
|
| 2261 |
+
'group',
|
| 2262 |
+
'grouped',
|
| 2263 |
+
'developer_mode',
|
| 2264 |
+
'dependency',
|
| 2265 |
+
'depends-on',
|
| 2266 |
+
'excludes-on'
|
| 2267 |
+
);
|
| 2268 |
+
|
| 2269 |
+
foreach ( $options_ignore as $ignore ) {
|
| 2270 |
+
if ( isset( $options[ $ignore ] ) )
|
| 2271 |
+
unset( $options[ $ignore ] );
|
| 2272 |
+
}
|
| 2273 |
+
|
| 2274 |
+
if ( isset( $options[ 'method' ] ) )
|
| 2275 |
+
unset( $options[ 'method' ] );
|
| 2276 |
+
elseif ( isset( $options[ 'table_info' ] ) )
|
| 2277 |
+
unset( $options[ 'table_info' ] );
|
| 2278 |
+
|
| 2279 |
+
$exclude = array(
|
| 2280 |
+
'id',
|
| 2281 |
+
'pod_id',
|
| 2282 |
+
'pod',
|
| 2283 |
+
'name',
|
| 2284 |
+
'label',
|
| 2285 |
+
'description',
|
| 2286 |
+
'type',
|
| 2287 |
+
'pick_object',
|
| 2288 |
+
'pick_val',
|
| 2289 |
+
'sister_id',
|
| 2290 |
+
'weight',
|
| 2291 |
+
'options'
|
| 2292 |
+
);
|
| 2293 |
+
|
| 2294 |
+
foreach ( $exclude as $k => $exclude_field ) {
|
| 2295 |
+
$aliases = array( $exclude_field );
|
| 2296 |
+
|
| 2297 |
+
if ( is_array( $exclude_field ) ) {
|
| 2298 |
+
$aliases = array_merge( array( $k ), $exclude_field );
|
| 2299 |
+
$exclude_field = $k;
|
| 2300 |
+
}
|
| 2301 |
+
|
| 2302 |
+
foreach ( $aliases as $alias ) {
|
| 2303 |
+
if ( isset( $options[ $alias ] ) ) {
|
| 2304 |
+
$field[ $exclude_field ] = pods_trim( $options[ $alias ] );
|
| 2305 |
+
|
| 2306 |
+
unset( $options[ $alias ] );
|
| 2307 |
+
}
|
| 2308 |
+
}
|
| 2309 |
+
}
|
| 2310 |
+
|
| 2311 |
+
if ( strlen( $field[ 'label' ] ) < 1 )
|
| 2312 |
+
$field[ 'label' ] = $field[ 'name' ];
|
| 2313 |
+
|
| 2314 |
+
$field[ 'options' ][ 'type' ] = $field[ 'type' ];
|
| 2315 |
+
|
| 2316 |
+
if ( in_array( $field[ 'options' ][ 'type' ], $tableless_field_types ) ) {
|
| 2317 |
+
// Clean up special drop-down in field editor and save out pick_val
|
| 2318 |
+
$field[ 'pick_object' ] = pods_var( 'pick_object', $field, '', null, true );
|
| 2319 |
+
|
| 2320 |
+
if ( 0 === strpos( $field[ 'pick_object' ], 'pod-' ) ) {
|
| 2321 |
+
$field[ 'pick_val' ] = pods_str_replace( 'pod-', '', $field[ 'pick_object' ], 1 );
|
| 2322 |
+
$field[ 'pick_object' ] = 'pod';
|
| 2323 |
+
}
|
| 2324 |
+
elseif ( 0 === strpos( $field[ 'pick_object' ], 'post_type-' ) ) {
|
| 2325 |
+
$field[ 'pick_val' ] = pods_str_replace( 'post_type-', '', $field[ 'pick_object' ], 1 );
|
| 2326 |
+
$field[ 'pick_object' ] = 'post_type';
|
| 2327 |
+
}
|
| 2328 |
+
elseif ( 0 === strpos( $field[ 'pick_object' ], 'taxonomy-' ) ) {
|
| 2329 |
+
$field[ 'pick_val' ] = pods_str_replace( 'taxonomy-', '', $field[ 'pick_object' ], 1 );
|
| 2330 |
+
$field[ 'pick_object' ] = 'taxonomy';
|
| 2331 |
+
}
|
| 2332 |
+
elseif ( 'table' == $field[ 'pick_object' ] && 0 < strlen( pods_var_raw( 'pick_table', $field[ 'options' ] ) ) ) {
|
| 2333 |
+
$field[ 'pick_val' ] = $field[ 'options' ][ 'pick_table' ];
|
| 2334 |
+
$field[ 'pick_object' ] = 'table';
|
| 2335 |
+
}
|
| 2336 |
+
elseif ( false === strpos( $field[ 'pick_object' ], '-' ) && !in_array( $field[ 'pick_object' ], array( 'pod', 'post_type', 'taxonomy' ) ) ) {
|
| 2337 |
+
$field[ 'pick_val' ] = '';
|
| 2338 |
+
}
|
| 2339 |
+
elseif ( 'custom-simple' == $field[ 'pick_object' ] ) {
|
| 2340 |
+
$field[ 'pick_val' ] = '';
|
| 2341 |
+
}
|
| 2342 |
+
|
| 2343 |
+
$field[ 'options' ][ 'pick_object' ] = $field[ 'pick_object' ];
|
| 2344 |
+
$field[ 'options' ][ 'pick_val' ] = $field[ 'pick_val' ];
|
| 2345 |
+
$field[ 'options' ][ 'sister_id' ] = pods_var( 'sister_id', $field );
|
| 2346 |
+
|
| 2347 |
+
unset( $field[ 'pick_object' ] );
|
| 2348 |
+
unset( $field[ 'pick_val' ] );
|
| 2349 |
+
|
| 2350 |
+
if ( isset( $field[ 'sister_id' ] ) )
|
| 2351 |
+
unset( $field[ 'sister_id' ] );
|
| 2352 |
+
}
|
| 2353 |
+
|
| 2354 |
+
$field[ 'options' ] = array_merge( $field[ 'options' ], $options );
|
| 2355 |
+
|
| 2356 |
+
$object_fields = (array) pods_var_raw( 'object_fields', $pod, array(), null, true );
|
| 2357 |
+
|
| 2358 |
+
if ( 0 < $old_id && defined( 'PODS_FIELD_STRICT' ) && !PODS_FIELD_STRICT )
|
| 2359 |
+
$params->id = $field[ 'id' ] = $old_id;
|
| 2360 |
+
|
| 2361 |
+
// Add new field
|
| 2362 |
+
if ( !isset( $params->id ) || empty( $params->id ) || empty( $field ) ) {
|
| 2363 |
+
if ( $table_operation && in_array( $field[ 'name' ], array( 'created', 'modified' ) ) && !in_array( $field[ 'type' ], array( 'date', 'datetime' ) ) && ( !defined( 'PODS_FIELD_STRICT' ) || PODS_FIELD_STRICT ) )
|
| 2364 |
+
return pods_error( sprintf( __( '%s is reserved for internal Pods usage, please try a different name', 'pods' ), $field[ 'name' ] ), $this );
|
| 2365 |
+
|
| 2366 |
+
if ( $table_operation && 'author' == $field[ 'name' ] && 'pick' != $field[ 'type' ] && ( !defined( 'PODS_FIELD_STRICT' ) || PODS_FIELD_STRICT ) )
|
| 2367 |
+
return pods_error( sprintf( __( '%s is reserved for internal Pods usage, please try a different name', 'pods' ), $field[ 'name' ] ), $this );
|
| 2368 |
+
|
| 2369 |
+
if ( in_array( $field[ 'name' ], array( 'id', 'ID' ) ) )
|
| 2370 |
+
return pods_error( sprintf( __( '%s is reserved for internal Pods usage, please try a different name', 'pods' ), $field[ 'name' ] ), $this );
|
| 2371 |
+
|
| 2372 |
+
foreach ( $object_fields as $object_field => $object_field_opt ) {
|
| 2373 |
+
if ( $object_field == $field[ 'name' ] || in_array( $field[ 'name' ], $object_field_opt[ 'alias' ] ) )
|
| 2374 |
+
return pods_error( sprintf( __( '%s is reserved for internal WordPress or Pods usage, please try a different name. Also consider what WordPress and Pods provide you built-in.', 'pods' ), $field[ 'name' ] ), $this );
|
| 2375 |
+
}
|
| 2376 |
+
|
| 2377 |
+
if ( in_array( $field[ 'name' ], array( 'rss' ) ) ) // Reserved post_name values that can't be used as field names
|
| 2378 |
+
$field[ 'name' ] .= '2';
|
| 2379 |
+
|
| 2380 |
+
if ( 'slug' == $field[ 'type' ] && true === $db ) {
|
| 2381 |
+
if ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy', 'user' ) ) )
|
| 2382 |
+
return pods_error( __( 'This pod already has an internal WordPress permalink field', 'pods' ), $this );
|
| 2383 |
+
|
| 2384 |
+
$slug_field = get_posts( array(
|
| 2385 |
+
'post_type' => '_pods_field',
|
| 2386 |
+
'orderby' => 'menu_order',
|
| 2387 |
+
'order' => 'ASC',
|
| 2388 |
+
'posts_per_page' => 1,
|
| 2389 |
+
'post_parent' => $field[ 'pod_id' ],
|
| 2390 |
+
'meta_query' => array(
|
| 2391 |
+
array(
|
| 2392 |
+
'key' => 'type',
|
| 2393 |
+
'value' => 'slug'
|
| 2394 |
+
)
|
| 2395 |
+
)
|
| 2396 |
+
) );
|
| 2397 |
+
|
| 2398 |
+
if ( !empty( $slug_field ) )
|
| 2399 |
+
return pods_error( __( 'This pod already has a permalink field', 'pods' ), $this );
|
| 2400 |
+
}
|
| 2401 |
+
|
| 2402 |
+
// Sink the new field to the bottom of the list
|
| 2403 |
+
if ( null === $field[ 'weight' ] ) {
|
| 2404 |
+
$field[ 'weight' ] = 0;
|
| 2405 |
+
|
| 2406 |
+
$bottom_most_field = get_posts( array(
|
| 2407 |
+
'post_type' => '_pods_field',
|
| 2408 |
+
'orderby' => 'menu_order',
|
| 2409 |
+
'order' => 'DESC',
|
| 2410 |
+
'posts_per_page' => 1,
|
| 2411 |
+
'post_parent' => $field[ 'pod_id' ]
|
| 2412 |
+
) );
|
| 2413 |
+
|
| 2414 |
+
if ( !empty( $bottom_most_field ) )
|
| 2415 |
+
$field[ 'weight' ] = pods_absint( $bottom_most_field[ 0 ]->menu_order ) + 1;
|
| 2416 |
+
}
|
| 2417 |
+
|
| 2418 |
+
$field[ 'weight' ] = pods_absint( $field[ 'weight' ] );
|
| 2419 |
+
|
| 2420 |
+
$post_data = array(
|
| 2421 |
+
'post_name' => $field[ 'name' ],
|
| 2422 |
+
'post_title' => $field[ 'label' ],
|
| 2423 |
+
'post_content' => $field[ 'description' ],
|
| 2424 |
+
'post_type' => '_pods_field',
|
| 2425 |
+
'post_parent' => $field[ 'pod_id' ],
|
| 2426 |
+
'post_status' => 'publish',
|
| 2427 |
+
'menu_order' => $field[ 'weight' ]
|
| 2428 |
+
);
|
| 2429 |
+
}
|
| 2430 |
+
else {
|
| 2431 |
+
if ( in_array( $field[ 'name' ], array( 'id', 'ID' ) ) ) {
|
| 2432 |
+
if ( null !== $old_name )
|
| 2433 |
+
return pods_error( sprintf( __( '%s is reserved for internal Pods usage, please try a different name', 'pods' ), $field[ 'name' ] ), $this );
|
| 2434 |
+
else
|
| 2435 |
+
return pods_error( sprintf( __( '%s is not editable', 'pods' ), $field[ 'name' ] ), $this );
|
| 2436 |
+
}
|
| 2437 |
+
|
| 2438 |
+
if ( null !== $old_name && $field[ 'name' ] != $old_name && in_array( $field[ 'name' ], array( 'created', 'modified' ) ) && !in_array( $field[ 'type' ], array( 'date', 'datetime' ) ) && ( !defined( 'PODS_FIELD_STRICT' ) || PODS_FIELD_STRICT ) )
|
| 2439 |
+
return pods_error( sprintf( __( '%s is reserved for internal Pods usage, please try a different name', 'pods' ), $field[ 'name' ] ), $this );
|
| 2440 |
+
|
| 2441 |
+
if ( null !== $old_name && $field[ 'name' ] != $old_name && 'author' == $field[ 'name' ] && 'pick' != $field[ 'type' ] && ( !defined( 'PODS_FIELD_STRICT' ) || PODS_FIELD_STRICT ) )
|
| 2442 |
+
return pods_error( sprintf( __( '%s is reserved for internal Pods usage, please try a different name', 'pods' ), $field[ 'name' ] ), $this );
|
| 2443 |
+
|
| 2444 |
+
foreach ( $object_fields as $object_field => $object_field_opt ) {
|
| 2445 |
+
if ( $object_field != $field[ 'name' ] && !in_array( $field[ 'name' ], $object_field_opt[ 'alias' ] ) )
|
| 2446 |
+
continue;
|
| 2447 |
+
|
| 2448 |
+
if ( null !== $old_name )
|
| 2449 |
+
return pods_error( sprintf( __( '%s is reserved for internal WordPress or Pods usage, please try a different name', 'pods' ), $field[ 'name' ] ), $this );
|
| 2450 |
+
else
|
| 2451 |
+
return pods_error( sprintf( __( '%s is not editable', 'pods' ), $field[ 'name' ] ), $this );
|
| 2452 |
+
}
|
| 2453 |
+
|
| 2454 |
+
$post_data = array(
|
| 2455 |
+
'ID' => $field[ 'id' ],
|
| 2456 |
+
'post_name' => $field[ 'name' ],
|
| 2457 |
+
'post_title' => $field[ 'label' ],
|
| 2458 |
+
'post_content' => $field[ 'description' ]
|
| 2459 |
+
);
|
| 2460 |
+
|
| 2461 |
+
if ( null !== $field[ 'weight' ] ) {
|
| 2462 |
+
$field[ 'weight' ] = pods_absint( $field[ 'weight' ] );
|
| 2463 |
+
|
| 2464 |
+
$post_data[ 'menu_order' ] = $field[ 'weight' ];
|
| 2465 |
+
}
|
| 2466 |
+
}
|
| 2467 |
+
|
| 2468 |
+
if ( true === $db ) {
|
| 2469 |
+
if ( !has_filter( 'wp_unique_post_slug', array( $this, 'save_slug_fix' ) ) )
|
| 2470 |
+
add_filter( 'wp_unique_post_slug', array( $this, 'save_slug_fix' ), 100, 6 );
|
| 2471 |
+
|
| 2472 |
+
$conflicted = false;
|
| 2473 |
+
|
| 2474 |
+
// Headway compatibility fix
|
| 2475 |
+
if ( has_filter( 'wp_insert_post_data', 'headway_clean_slug', 0 ) ) {
|
| 2476 |
+
remove_filter( 'wp_insert_post_data', 'headway_clean_slug', 0 );
|
| 2477 |
+
|
| 2478 |
+
$conflicted = true;
|
| 2479 |
+
}
|
| 2480 |
+
|
| 2481 |
+
$params->id = $this->save_wp_object( 'post', $post_data, $field[ 'options' ], true, true );
|
| 2482 |
+
|
| 2483 |
+
if ( $conflicted )
|
| 2484 |
+
add_filter( 'wp_insert_post_data', 'headway_clean_slug', 0 );
|
| 2485 |
+
|
| 2486 |
+
if ( false === $params->id )
|
| 2487 |
+
return pods_error( __( 'Cannot save Field', 'pods' ), $this );
|
| 2488 |
+
}
|
| 2489 |
+
else
|
| 2490 |
+
$params->id = $field[ 'name' ];
|
| 2491 |
+
|
| 2492 |
+
$field[ 'id' ] = $params->id;
|
| 2493 |
+
|
| 2494 |
+
$simple = ( 'pick' == $field[ 'type' ] && in_array( pods_var( 'pick_object', $field[ 'options' ] ), $simple_tableless_objects ) );
|
| 2495 |
+
|
| 2496 |
+
$definition = false;
|
| 2497 |
+
|
| 2498 |
+
if ( !in_array( $field[ 'type' ], $tableless_field_types ) || $simple ) {
|
| 2499 |
+
$field_definition = $this->get_field_definition( $field[ 'type' ], array_merge( $field, $field[ 'options' ] ) );
|
| 2500 |
+
|
| 2501 |
+
if ( 0 < strlen( $field_definition ) )
|
| 2502 |
+
$definition = '`' . $field[ 'name' ] . '` ' . $field_definition;
|
| 2503 |
+
}
|
| 2504 |
+
|
| 2505 |
+
$sister_id = (int) pods_var( 'sister_id', $field[ 'options' ], 0 );
|
| 2506 |
+
|
| 2507 |
+
if ( $table_operation && 'table' == $pod[ 'storage' ] && !pods_tableless() ) {
|
| 2508 |
+
if ( !empty( $old_id ) ) {
|
| 2509 |
+
if ( ( $field[ 'type' ] != $old_type || $old_simple != $simple ) && empty( $definition ) )
|
| 2510 |
+
pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` DROP COLUMN `{$old_name}`", false );
|
| 2511 |
+
elseif ( 0 < strlen( $definition ) ) {
|
| 2512 |
+
if ( $old_name != $field[ 'name' ] || $old_simple != $simple ) {
|
| 2513 |
+
$test = false;
|
| 2514 |
+
|
| 2515 |
+
if ( 0 < strlen( $old_definition ) )
|
| 2516 |
+
$test = pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` CHANGE `{$old_name}` {$definition}", false );
|
| 2517 |
+
|
| 2518 |
+
// If the old field doesn't exist, continue to add a new field
|
| 2519 |
+
if ( false === $test )
|
| 2520 |
+
pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` ADD COLUMN {$definition}", __( 'Cannot create new field', 'pods' ) );
|
| 2521 |
+
}
|
| 2522 |
+
elseif ( null !== $old_definition && $definition != $old_definition ) {
|
| 2523 |
+
$test = pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` CHANGE `{$old_name}` {$definition}", false );
|
| 2524 |
+
|
| 2525 |
+
// If the old field doesn't exist, continue to add a new field
|
| 2526 |
+
if ( false === $test )
|
| 2527 |
+
pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` ADD COLUMN {$definition}", __( 'Cannot create new field', 'pods' ) );
|
| 2528 |
+
}
|
| 2529 |
+
}
|
| 2530 |
+
}
|
| 2531 |
+
elseif ( 0 < strlen( $definition ) ) {
|
| 2532 |
+
$test = false;
|
| 2533 |
+
|
| 2534 |
+
if ( 0 < strlen( $old_definition ) )
|
| 2535 |
+
$test = pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` CHANGE `" . $field[ 'name' ] . "` {$definition}", false );
|
| 2536 |
+
|
| 2537 |
+
// If the old field doesn't exist, continue to add a new field
|
| 2538 |
+
if ( false === $test )
|
| 2539 |
+
pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` ADD COLUMN {$definition}", __( 'Cannot create new field', 'pods' ) );
|
| 2540 |
+
}
|
| 2541 |
+
}
|
| 2542 |
+
|
| 2543 |
+
if ( !empty( $old_id ) && 'meta' == $pod[ 'storage' ] && $old_name != $field[ 'name' ] && $pod[ 'meta_table' ] != $pod[ 'table' ] ) {
|
| 2544 |
+
$prepare = array(
|
| 2545 |
+
$field[ 'name' ],
|
| 2546 |
+
$old_name
|
| 2547 |
+
);
|
| 2548 |
+
|
| 2549 |
+
// Users don't have a type
|
| 2550 |
+
if ( !empty( $pod[ 'field_type' ] ) )
|
| 2551 |
+
$prepare[] = $pod[ 'name' ];
|
| 2552 |
+
|
| 2553 |
+
pods_query( "
|
| 2554 |
+
UPDATE `{$pod[ 'meta_table' ]}` AS `m`
|
| 2555 |
+
LEFT JOIN `{$pod[ 'table' ]}` AS `t`
|
| 2556 |
+
ON `t`.`{$pod[ 'field_id' ]}` = `m`.`{$pod[ 'meta_field_id' ]}`
|
| 2557 |
+
SET
|
| 2558 |
+
`m`.`{$pod[ 'meta_field_index' ]}` = %s
|
| 2559 |
+
WHERE
|
| 2560 |
+
`m`.`{$pod[ 'meta_field_index' ]}` = %s
|
| 2561 |
+
" . ( !empty( $pod[ 'field_type' ] ) ? " AND `t`.`{$pod[ 'field_type' ]}` = %s" : "" ),
|
| 2562 |
+
$prepare
|
| 2563 |
+
);
|
| 2564 |
+
}
|
| 2565 |
+
|
| 2566 |
+
if ( $field[ 'type' ] != $old_type && in_array( $old_type, $tableless_field_types ) ) {
|
| 2567 |
+
delete_post_meta( $old_sister_id, 'sister_id' );
|
| 2568 |
+
|
| 2569 |
+
if ( true === $db ) {
|
| 2570 |
+
pods_query( "
|
| 2571 |
+
DELETE pm
|
| 2572 |
+
FROM {$wpdb->postmeta} AS pm
|
| 2573 |
+
LEFT JOIN {$wpdb->posts} AS p
|
| 2574 |
+
ON p.post_type = '_pods_field'
|
| 2575 |
+
AND p.ID = pm.post_id
|
| 2576 |
+
WHERE
|
| 2577 |
+
p.ID IS NOT NULL
|
| 2578 |
+
AND pm.meta_key = 'sister_id'
|
| 2579 |
+
AND pm.meta_value = %d
|
| 2580 |
+
", array(
|
| 2581 |
+
$params->id
|
| 2582 |
+
)
|
| 2583 |
+
);
|
| 2584 |
+
|
| 2585 |
+
if ( !pods_tableless() ) {
|
| 2586 |
+
pods_query( "DELETE FROM @wp_podsrel WHERE `field_id` = {$params->id}", false );
|
| 2587 |
+
|
| 2588 |
+
pods_query( "
|
| 2589 |
+
UPDATE `@wp_podsrel`
|
| 2590 |
+
SET `related_field_id` = 0
|
| 2591 |
+
WHERE `field_id` = %d
|
| 2592 |
+
", array(
|
| 2593 |
+
$old_sister_id
|
| 2594 |
+
)
|
| 2595 |
+
);
|
| 2596 |
+
}
|
| 2597 |
+
}
|
| 2598 |
+
}
|
| 2599 |
+
elseif ( 0 < $sister_id ) {
|
| 2600 |
+
update_post_meta( $sister_id, 'sister_id', $params->id );
|
| 2601 |
+
|
| 2602 |
+
if ( true === $db && ( !pods_tableless() ) ) {
|
| 2603 |
+
pods_query( "
|
| 2604 |
+
UPDATE `@wp_podsrel`
|
| 2605 |
+
SET `related_field_id` = %d
|
| 2606 |
+
WHERE `field_id` = %d
|
| 2607 |
+
",
|
| 2608 |
+
array(
|
| 2609 |
+
$params->id,
|
| 2610 |
+
$sister_id
|
| 2611 |
+
)
|
| 2612 |
+
);
|
| 2613 |
+
}
|
| 2614 |
+
}
|
| 2615 |
+
elseif ( 0 < $old_sister_id ) {
|
| 2616 |
+
delete_post_meta( $old_sister_id, 'sister_id' );
|
| 2617 |
+
|
| 2618 |
+
if ( true === $db && ( !pods_tableless() ) ) {
|
| 2619 |
+
pods_query( "
|
| 2620 |
+
UPDATE `@wp_podsrel`
|
| 2621 |
+
SET `related_field_id` = 0
|
| 2622 |
+
WHERE `field_id` = %d
|
| 2623 |
+
", array(
|
| 2624 |
+
$old_sister_id
|
| 2625 |
+
)
|
| 2626 |
+
);
|
| 2627 |
+
}
|
| 2628 |
+
}
|
| 2629 |
+
|
| 2630 |
+
if ( !empty( $old_id ) && $old_name != $field[ 'name' ] && true === $db ) {
|
| 2631 |
+
pods_query( "
|
| 2632 |
+
UPDATE `@wp_postmeta`
|
| 2633 |
+
SET `meta_value` = %s
|
| 2634 |
+
WHERE
|
| 2635 |
+
`post_id` = %d
|
| 2636 |
+
AND `meta_key` = 'pod_index'
|
| 2637 |
+
AND `meta_value` = %s
|
| 2638 |
+
", array(
|
| 2639 |
+
$field[ 'name' ],
|
| 2640 |
+
$pod[ 'id' ],
|
| 2641 |
+
$old_name
|
| 2642 |
+
)
|
| 2643 |
+
);
|
| 2644 |
+
}
|
| 2645 |
+
|
| 2646 |
+
if ( !$save_pod )
|
| 2647 |
+
$this->cache_flush_pods( $pod );
|
| 2648 |
+
else {
|
| 2649 |
+
pods_transient_clear( 'pods_field_' . $pod[ 'name' ] . '_' . $field[ 'name' ] );
|
| 2650 |
+
|
| 2651 |
+
if ( !empty( $old_id ) && $old_name != $field[ 'name' ] )
|
| 2652 |
+
pods_transient_clear( 'pods_field_' . $pod[ 'name' ] . '_' . $old_name );
|
| 2653 |
+
}
|
| 2654 |
+
|
| 2655 |
+
if ( true === $db )
|
| 2656 |
+
return $params->id;
|
| 2657 |
+
else
|
| 2658 |
+
return $field;
|
| 2659 |
+
}
|
| 2660 |
+
|
| 2661 |
+
/**
|
| 2662 |
+
* Fix Pod / Field post_name to ensure they are exactly as saved (allow multiple posts w/ same post_name)
|
| 2663 |
+
*
|
| 2664 |
+
* @param string $slug Unique slug value
|
| 2665 |
+
* @param int $post_ID Post ID
|
| 2666 |
+
* @param string $post_status Post Status
|
| 2667 |
+
* @param string $post_type Post Type
|
| 2668 |
+
* @param int $post_parent Post Parent ID
|
| 2669 |
+
* @param string $original_slug Original slug value
|
| 2670 |
+
*
|
| 2671 |
+
* @return string Final slug value
|
| 2672 |
+
*
|
| 2673 |
+
* @since 2.3.3
|
| 2674 |
+
*/
|
| 2675 |
+
public function save_slug_fix ( $slug, $post_ID, $post_status, $post_type, $post_parent = 0, $original_slug = null ) {
|
| 2676 |
+
if ( in_array( $post_type, array( '_pods_field', '_pods_pod' ) ) && false !== strpos( $slug, '-' ) )
|
| 2677 |
+
$slug = $original_slug;
|
| 2678 |
+
|
| 2679 |
+
return $slug;
|
| 2680 |
+
}
|
| 2681 |
+
|
| 2682 |
+
/**
|
| 2683 |
+
* Add or Edit a Pods Object
|
| 2684 |
+
*
|
| 2685 |
+
* $params['id'] int The Object ID
|
| 2686 |
+
* $params['name'] string The Object name
|
| 2687 |
+
* $params['type'] string The Object type
|
| 2688 |
+
* $params['options'] Associative array of Object options
|
| 2689 |
+
*
|
| 2690 |
+
* @param array|object $params An associative array of parameters
|
| 2691 |
+
* @param bool $sanitized (optional) Decides whether the params have been sanitized before being passed, will sanitize them if false.
|
| 2692 |
+
*
|
| 2693 |
+
* @return int The Object ID
|
| 2694 |
+
* @since 2.0
|
| 2695 |
+
*/
|
| 2696 |
+
public function save_object ( $params, $sanitized = false ) {
|
| 2697 |
+
$params = (object) $params;
|
| 2698 |
+
|
| 2699 |
+
if ( false === $sanitized )
|
| 2700 |
+
$params = pods_sanitize( $params );
|
| 2701 |
+
|
| 2702 |
+
if ( !isset( $params->name ) || empty( $params->name ) )
|
| 2703 |
+
return pods_error( __( 'Name must be given to save an Object', 'pods' ), $this );
|
| 2704 |
+
|
| 2705 |
+
if ( !isset( $params->type ) || empty( $params->type ) )
|
| 2706 |
+
return pods_error( __( 'Type must be given to save an Object', 'pods' ), $this );
|
| 2707 |
+
|
| 2708 |
+
$object = array(
|
| 2709 |
+
'id' => 0,
|
| 2710 |
+
'name' => $params->name,
|
| 2711 |
+
'type' => $params->type,
|
| 2712 |
+
'code' => '',
|
| 2713 |
+
'options' => array()
|
| 2714 |
+
);
|
| 2715 |
+
|
| 2716 |
+
// Setup options
|
| 2717 |
+
$options = get_object_vars( $params );
|
| 2718 |
+
|
| 2719 |
+
if ( isset( $options[ 'method' ] ) )
|
| 2720 |
+
unset( $options[ 'method' ] );
|
| 2721 |
+
|
| 2722 |
+
$exclude = array(
|
| 2723 |
+
'id',
|
| 2724 |
+
'name',
|
| 2725 |
+
'helper_type',
|
| 2726 |
+
'code',
|
| 2727 |
+
'options',
|
| 2728 |
+
'status'
|
| 2729 |
+
);
|
| 2730 |
+
|
| 2731 |
+
foreach ( $exclude as $k => $exclude_field ) {
|
| 2732 |
+
$aliases = array( $exclude_field );
|
| 2733 |
+
|
| 2734 |
+
if ( is_array( $exclude_field ) ) {
|
| 2735 |
+
$aliases = array_merge( array( $k ), $exclude_field );
|
| 2736 |
+
$exclude_field = $k;
|
| 2737 |
+
}
|
| 2738 |
+
|
| 2739 |
+
foreach ( $aliases as $alias ) {
|
| 2740 |
+
if ( isset( $options[ $alias ] ) ) {
|
| 2741 |
+
$object[ $exclude_field ] = pods_trim( $options[ $alias ] );
|
| 2742 |
+
|
| 2743 |
+
unset( $options[ $alias ] );
|
| 2744 |
+
}
|
| 2745 |
+
}
|
| 2746 |
+
}
|
| 2747 |
+
|
| 2748 |
+
if ( 'helper' == $object[ 'type' ] )
|
| 2749 |
+
$object[ 'options' ][ 'helper_type' ] = $object[ 'helper_type' ];
|
| 2750 |
+
|
| 2751 |
+
if ( isset( $object[ 'options' ][ 'code' ] ) )
|
| 2752 |
+
unset( $object[ 'options' ][ 'code' ] );
|
| 2753 |
+
|
| 2754 |
+
$object[ 'options' ] = array_merge( $object[ 'options' ], $options );
|
| 2755 |
+
|
| 2756 |
+
$post_data = array(
|
| 2757 |
+
'post_name' => pods_clean_name( $object[ 'name' ], true),
|
| 2758 |
+
'post_title' => $object[ 'name' ],
|
| 2759 |
+
'post_content' => $object[ 'code' ],
|
| 2760 |
+
'post_type' => '_pods_' . $object[ 'type' ],
|
| 2761 |
+
'post_status' => 'publish'
|
| 2762 |
+
);
|
| 2763 |
+
|
| 2764 |
+
if ( !empty( $object[ 'id' ] ) )
|
| 2765 |
+
$post_data[ 'ID' ] = $object[ 'id' ];
|
| 2766 |
+
|
| 2767 |
+
if ( null !== pods_var( 'status', $object, null, null, true ) )
|
| 2768 |
+
$post_data[ 'post_status' ] = pods_var( 'status', $object, null, null, true );
|
| 2769 |
+
|
| 2770 |
+
remove_filter( 'content_save_pre', 'balanceTags', 50 );
|
| 2771 |
+
|
| 2772 |
+
$post_data = pods_sanitize( $post_data );
|
| 2773 |
+
|
| 2774 |
+
$params->id = $this->save_post( $post_data, $object[ 'options' ], true, true );
|
| 2775 |
+
|
| 2776 |
+
pods_transient_clear( 'pods_objects_' . $params->type );
|
| 2777 |
+
pods_transient_clear( 'pods_objects_' . $params->type . '_get' );
|
| 2778 |
+
|
| 2779 |
+
return $params->id;
|
| 2780 |
+
}
|
| 2781 |
+
|
| 2782 |
+
/**
|
| 2783 |
+
* @see PodsAPI::save_object
|
| 2784 |
+
*
|
| 2785 |
+
* Add or edit a Pod Template
|
| 2786 |
+
*
|
| 2787 |
+
* $params['id'] int The template ID
|
| 2788 |
+
* $params['name'] string The template name
|
| 2789 |
+
* $params['code'] string The template code
|
| 2790 |
+
*
|
| 2791 |
+
* @param array|object $params An associative array of parameters
|
| 2792 |
+
* @param bool $sanitized (optional) Decides wether the params have been sanitized before being passed, will sanitize them if false.
|
| 2793 |
+
*
|
| 2794 |
+
* @return int The Template ID
|
| 2795 |
+
*
|
| 2796 |
+
* @since 1.7.9
|
| 2797 |
+
*/
|
| 2798 |
+
public function save_template ( $params, $sanitized = false ) {
|
| 2799 |
+
$params = (object) $params;
|
| 2800 |
+
|
| 2801 |
+
$params->type = 'template';
|
| 2802 |
+
|
| 2803 |
+
return $this->save_object( $params, $sanitized );
|
| 2804 |
+
}
|
| 2805 |
+
|
| 2806 |
+
/**
|
| 2807 |
+
* @see PodsAPI::save_object
|
| 2808 |
+
*
|
| 2809 |
+
* Add or edit a Pod Page
|
| 2810 |
+
*
|
| 2811 |
+
* $params['id'] int The page ID
|
| 2812 |
+
* $params['name'] string The page URI
|
| 2813 |
+
* $params['code'] string The page code
|
| 2814 |
+
*
|
| 2815 |
+
* @param array|object $params An associative array of parameters
|
| 2816 |
+
* @param bool $sanitized (optional) Decides wether the params have been sanitized before being passed, will sanitize them if false.
|
| 2817 |
+
*
|
| 2818 |
+
* @return int The page ID
|
| 2819 |
+
* @since 1.7.9
|
| 2820 |
+
*/
|
| 2821 |
+
public function save_page ( $params, $sanitized = false ) {
|
| 2822 |
+
$params = (object) $params;
|
| 2823 |
+
|
| 2824 |
+
if ( !isset( $params->name ) ) {
|
| 2825 |
+
$params->name = $params->uri;
|
| 2826 |
+
unset( $params->uri );
|
| 2827 |
+
}
|
| 2828 |
+
|
| 2829 |
+
if ( isset( $params->phpcode ) ) {
|
| 2830 |
+
$params->code = $params->phpcode;
|
| 2831 |
+
unset( $params->phpcode );
|
| 2832 |
+
}
|
| 2833 |
+
|
| 2834 |
+
$params->name = trim( $params->name, '/' );
|
| 2835 |
+
$params->type = 'page';
|
| 2836 |
+
|
| 2837 |
+
return $this->save_object( $params, $sanitized );
|
| 2838 |
+
}
|
| 2839 |
+
|
| 2840 |
+
/**
|
| 2841 |
+
* @see PodsAPI::save_object
|
| 2842 |
+
*
|
| 2843 |
+
* Add or edit a Pod Helper
|
| 2844 |
+
*
|
| 2845 |
+
* $params['id'] int The helper ID
|
| 2846 |
+
* $params['name'] string The helper name
|
| 2847 |
+
* $params['helper_type'] string The helper type ("pre_save", "display", etc)
|
| 2848 |
+
* $params['code'] string The helper code
|
| 2849 |
+
*
|
| 2850 |
+
* @param array $params An associative array of parameters
|
| 2851 |
+
* @param bool $sanitized (optional) Decides wether the params have been sanitized before being passed, will sanitize them if false.
|
| 2852 |
+
*
|
| 2853 |
+
* @return int The helper ID
|
| 2854 |
+
* @since 1.7.9
|
| 2855 |
+
*/
|
| 2856 |
+
public function save_helper ( $params, $sanitized = false ) {
|
| 2857 |
+
$params = (object) $params;
|
| 2858 |
+
|
| 2859 |
+
if ( isset( $params->phpcode ) ) {
|
| 2860 |
+
$params->code = $params->phpcode;
|
| 2861 |
+
unset( $params->phpcode );
|
| 2862 |
+
}
|
| 2863 |
+
|
| 2864 |
+
if ( isset( $params->type ) ) {
|
| 2865 |
+
$params->helper_type = $params->type;
|
| 2866 |
+
unset( $params->type );
|
| 2867 |
+
}
|
| 2868 |
+
|
| 2869 |
+
$params->type = 'helper';
|
| 2870 |
+
|
| 2871 |
+
return $this->save_object( $params, $sanitized );
|
| 2872 |
+
}
|
| 2873 |
+
|
| 2874 |
+
/**
|
| 2875 |
+
* Add or edit a single pod item
|
| 2876 |
+
*
|
| 2877 |
+
* $params['pod'] string The Pod name (pod or pod_id is required)
|
| 2878 |
+
* $params['pod_id'] string The Pod ID (pod or pod_id is required)
|
| 2879 |
+
* $params['id'] int The item ID
|
| 2880 |
+
* $params['data'] array (optional) Associative array of field names + values
|
| 2881 |
+
* $params['bypass_helpers'] bool Set to true to bypass running pre-save and post-save helpers
|
| 2882 |
+
* $params['track_changed_fields'] bool Set to true to enable tracking of saved fields via PodsAPI::get_changed_fields()
|
| 2883 |
+
*
|
| 2884 |
+
* @param array|object $params An associative array of parameters
|
| 2885 |
+
*
|
| 2886 |
+
* @return int The item ID
|
| 2887 |
+
*
|
| 2888 |
+
* @since 1.7.9
|
| 2889 |
+
*/
|
| 2890 |
+
public function save_pod_item ( $params ) {
|
| 2891 |
|
| 2892 |
+
global $wpdb;
|
|
|
|
|
|
|
| 2893 |
|
| 2894 |
+
$params = (object) pods_str_replace( '@wp_', '{prefix}', $params );
|
|
|
|
|
|
|
| 2895 |
|
| 2896 |
+
$tableless_field_types = PodsForm::tableless_field_types();
|
| 2897 |
+
$repeatable_field_types = PodsForm::repeatable_field_types();
|
| 2898 |
+
$simple_tableless_objects = PodsForm::simple_tableless_objects();
|
|
|
|
| 2899 |
|
| 2900 |
+
// @deprecated 2.0
|
| 2901 |
+
if ( isset( $params->datatype ) ) {
|
| 2902 |
+
pods_deprecated( '$params->pod instead of $params->datatype', '2.0' );
|
|
|
|
|
|
|
|
|
|
| 2903 |
|
| 2904 |
+
$params->pod = $params->datatype;
|
|
|
|
|
|
|
|
|
|
| 2905 |
|
| 2906 |
+
unset( $params->datatype );
|
|
|
|
|
|
|
|
|
|
| 2907 |
|
| 2908 |
+
if ( isset( $params->pod_id ) ) {
|
| 2909 |
+
pods_deprecated( '$params->id instead of $params->pod_id', '2.0' );
|
| 2910 |
|
| 2911 |
+
$params->id = $params->pod_id;
|
| 2912 |
|
| 2913 |
+
unset( $params->pod_id );
|
| 2914 |
+
}
|
|
|
|
| 2915 |
|
| 2916 |
+
if ( isset( $params->data ) && !empty( $params->data ) && is_array( $params->data ) ) {
|
| 2917 |
+
$check = current( $params->data );
|
| 2918 |
|
| 2919 |
+
if ( is_array( $check ) ) {
|
| 2920 |
+
pods_deprecated( 'PodsAPI::save_pod_items', '2.0' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2921 |
|
| 2922 |
+
return $this->save_pod_items( $params, $params->data );
|
| 2923 |
+
}
|
| 2924 |
+
}
|
| 2925 |
+
}
|
| 2926 |
|
| 2927 |
+
// @deprecated 2.0
|
| 2928 |
+
if ( isset( $params->tbl_row_id ) ) {
|
| 2929 |
+
pods_deprecated( '$params->id instead of $params->tbl_row_id', '2.0' );
|
| 2930 |
|
| 2931 |
+
$params->id = $params->tbl_row_id;
|
|
|
|
|
|
|
| 2932 |
|
| 2933 |
+
unset( $params->tbl_row_id );
|
| 2934 |
+
}
|
|
|
|
| 2935 |
|
| 2936 |
+
// @deprecated 2.0
|
| 2937 |
+
if ( isset( $params->columns ) ) {
|
| 2938 |
+
pods_deprecated( '$params->data instead of $params->columns', '2.0' );
|
| 2939 |
|
| 2940 |
+
$params->data = $params->columns;
|
| 2941 |
|
| 2942 |
+
unset( $params->columns );
|
| 2943 |
+
}
|
|
|
|
| 2944 |
|
| 2945 |
+
if ( !isset( $params->pod ) )
|
| 2946 |
+
$params->pod = false;
|
| 2947 |
+
if ( isset( $params->pod_id ) )
|
| 2948 |
+
$params->pod_id = pods_absint( $params->pod_id );
|
| 2949 |
+
else
|
| 2950 |
+
$params->pod_id = 0;
|
| 2951 |
|
| 2952 |
+
if ( isset( $params->id ) )
|
| 2953 |
+
$params->id = pods_absint( $params->id );
|
| 2954 |
+
else
|
| 2955 |
+
$params->id = 0;
|
| 2956 |
|
| 2957 |
+
if ( !isset( $params->from ) )
|
| 2958 |
+
$params->from = 'save';
|
| 2959 |
|
| 2960 |
+
if ( !isset( $params->location ) )
|
| 2961 |
+
$params->location = null;
|
| 2962 |
|
| 2963 |
+
if ( !isset( $params->track_changed_fields ) )
|
| 2964 |
+
$params->track_changed_fields = false;
|
| 2965 |
|
| 2966 |
+
/**
|
| 2967 |
+
* Override $params['track_changed_fields']
|
| 2968 |
+
*
|
| 2969 |
+
* Use for globally setting field change tracking.
|
| 2970 |
+
*
|
| 2971 |
+
* @param bool
|
| 2972 |
+
*
|
| 2973 |
+
* @since 2.3.19
|
| 2974 |
+
*/
|
| 2975 |
+
$track_changed_fields = apply_filters( 'pods_api_save_pod_item_track_changed_fields_' . $params->pod, (boolean) $params->track_changed_fields, $params );
|
| 2976 |
+
$changed_fields = array();
|
| 2977 |
|
| 2978 |
+
if ( !isset( $params->clear_slug_cache ) ) {
|
| 2979 |
+
$params->clear_slug_cache = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2980 |
}
|
| 2981 |
|
| 2982 |
+
// Support for bulk edit
|
| 2983 |
+
if ( isset( $params->id ) && !empty( $params->id ) && is_array( $params->id ) ) {
|
| 2984 |
+
$ids = array();
|
| 2985 |
+
$new_params = $params;
|
|
|
|
|
|
|
|
|
|
| 2986 |
|
| 2987 |
+
foreach ( $params->id as $id ) {
|
| 2988 |
+
$new_params->id = $id;
|
|
|
|
| 2989 |
|
| 2990 |
+
$ids[] = $this->save_pod_item( $new_params );
|
| 2991 |
+
}
|
| 2992 |
|
| 2993 |
+
return $ids;
|
| 2994 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2995 |
|
| 2996 |
+
// Allow Helpers to know what's going on, are we adding or saving?
|
| 2997 |
+
$is_new_item = false;
|
|
|
|
| 2998 |
|
| 2999 |
+
if ( empty( $params->id ) )
|
| 3000 |
+
$is_new_item = true;
|
| 3001 |
|
| 3002 |
+
if ( isset( $params->is_new_item ) )
|
| 3003 |
+
$is_new_item = (boolean) $params->is_new_item;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3004 |
|
| 3005 |
+
// Allow Helpers to bypass subsequent helpers in recursive save_pod_item calls
|
| 3006 |
+
$bypass_helpers = false;
|
| 3007 |
|
| 3008 |
+
if ( isset( $params->bypass_helpers ) && false !== $params->bypass_helpers )
|
| 3009 |
+
$bypass_helpers = true;
|
| 3010 |
|
| 3011 |
+
// Allow Custom Fields not defined by Pods to be saved
|
| 3012 |
+
$allow_custom_fields = false;
|
| 3013 |
|
| 3014 |
+
if ( isset( $params->allow_custom_fields ) && false !== $params->allow_custom_fields )
|
| 3015 |
+
$allow_custom_fields = true;
|
|
|
|
|
|
|
| 3016 |
|
| 3017 |
+
// Get array of Pods
|
| 3018 |
+
$pod = $this->load_pod( array( 'id' => $params->pod_id, 'name' => $params->pod, 'table_info' => true ) );
|
|
|
|
|
|
|
| 3019 |
|
| 3020 |
+
if ( false === $pod )
|
| 3021 |
+
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
|
|
|
|
|
|
| 3022 |
|
| 3023 |
+
$params->pod = $pod[ 'name' ];
|
| 3024 |
+
$params->pod_id = $pod[ 'id' ];
|
|
|
|
|
|
|
| 3025 |
|
| 3026 |
+
if ( 'settings' == $pod[ 'type' ] )
|
| 3027 |
+
$params->id = $pod[ 'id' ];
|
| 3028 |
|
| 3029 |
+
$fields = $pod[ 'fields' ];
|
|
|
|
|
|
|
| 3030 |
|
| 3031 |
+
$object_fields = (array) pods_var_raw( 'object_fields', $pod, array(), null, true );
|
|
|
|
| 3032 |
|
| 3033 |
+
$fields_active = array();
|
| 3034 |
+
$custom_data = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3035 |
|
| 3036 |
+
// Find the active fields (loop through $params->data to retain order)
|
| 3037 |
+
if ( !empty( $params->data ) && is_array( $params->data ) ) {
|
| 3038 |
+
$custom_fields = array();
|
| 3039 |
|
| 3040 |
+
foreach ( $params->data as $field => $value ) {
|
| 3041 |
+
if ( isset( $object_fields[ $field ] ) ) {
|
| 3042 |
+
$object_fields[ $field ][ 'value' ] = $value;
|
| 3043 |
+
$fields_active[] = $field;
|
| 3044 |
+
}
|
| 3045 |
+
elseif ( isset( $fields[ $field ] ) ) {
|
| 3046 |
+
if ( 'save' == $params->from || true === PodsForm::permission( $fields[ $field ][ 'type' ], $field, $fields[ $field ], $fields, $pod, $params->id, $params ) ) {
|
| 3047 |
+
$fields[ $field ][ 'value' ] = $value;
|
| 3048 |
+
$fields_active[] = $field;
|
| 3049 |
+
}
|
| 3050 |
+
elseif ( !pods_has_permissions( $fields[ $field ][ 'options' ] ) && pods_var( 'hidden', $fields[ $field ][ 'options' ], false ) ) {
|
| 3051 |
+
$fields[ $field ][ 'value' ] = $value;
|
| 3052 |
+
$fields_active[] = $field;
|
| 3053 |
+
}
|
| 3054 |
+
}
|
| 3055 |
+
else {
|
| 3056 |
+
$found = false;
|
| 3057 |
|
| 3058 |
+
foreach ( $object_fields as $object_field => $object_field_opt ) {
|
| 3059 |
+
if ( in_array( $field, $object_field_opt[ 'alias' ] ) ) {
|
| 3060 |
+
$object_fields[ $object_field ][ 'value' ] = $value;
|
| 3061 |
+
$fields_active[] = $object_field;
|
| 3062 |
|
| 3063 |
+
$found = true;
|
|
|
|
|
|
|
| 3064 |
|
| 3065 |
+
break;
|
| 3066 |
+
}
|
| 3067 |
+
}
|
| 3068 |
|
| 3069 |
+
if ( $allow_custom_fields && !$found )
|
| 3070 |
+
$custom_fields[] = $field;
|
| 3071 |
+
}
|
| 3072 |
+
}
|
| 3073 |
|
| 3074 |
+
if ( $allow_custom_fields && !empty( $custom_fields ) ) {
|
| 3075 |
+
foreach ( $custom_fields as $field ) {
|
| 3076 |
+
$custom_data[ $field ] = $params->data[ $field ];
|
| 3077 |
+
}
|
| 3078 |
+
}
|
| 3079 |
|
| 3080 |
+
if ( $pod[ 'type' ] === 'taxonomy' && isset( $params->data ) && !empty( $params->data ) ) {
|
| 3081 |
+
$term_data = $params->data;
|
|
|
|
| 3082 |
}
|
|
|
|
| 3083 |
|
| 3084 |
+
unset( $params->data );
|
| 3085 |
+
}
|
|
|
|
| 3086 |
|
| 3087 |
+
if ( empty( $params->id ) && !in_array( 'created', $fields_active ) && isset( $fields[ 'created' ] ) && in_array( $fields[ 'created' ][ 'type' ], array( 'date', 'datetime' ) ) ) {
|
| 3088 |
+
$fields[ 'created' ][ 'value' ] = current_time( 'mysql' );
|
| 3089 |
+
$fields_active[] = 'created';
|
| 3090 |
+
}
|
| 3091 |
|
| 3092 |
+
if ( !in_array( 'modified', $fields_active ) && isset( $fields[ 'modified' ] ) && in_array( $fields[ 'modified' ][ 'type' ], array( 'date', 'datetime' ) ) ) {
|
| 3093 |
+
$fields[ 'modified' ][ 'value' ] = current_time( 'mysql' );
|
| 3094 |
+
$fields_active[] = 'modified';
|
| 3095 |
+
}
|
| 3096 |
|
| 3097 |
+
if ( in_array( $pod[ 'type' ], array( 'pod', 'table' ) ) && empty( $params->id ) && !empty( $pod[ 'pod_field_index' ] ) && in_array( $pod[ 'pod_field_index' ], $fields_active ) && !in_array( $pod[ 'pod_field_slug' ], $fields_active ) && isset( $fields[ $pod[ 'pod_field_slug' ] ] ) ) {
|
| 3098 |
+
$fields[ $pod[ 'pod_field_slug' ] ][ 'value' ] = ''; // this will get picked up by slug pre_save method
|
| 3099 |
+
$fields_active[] = $pod[ 'pod_field_slug' ];
|
| 3100 |
+
}
|
| 3101 |
|
| 3102 |
+
// Handle hidden fields
|
| 3103 |
+
if ( empty( $params->id ) ) {
|
| 3104 |
+
foreach ( $fields as $field => $field_data ) {
|
| 3105 |
+
if ( in_array( $field, $fields_active ) )
|
| 3106 |
+
continue;
|
| 3107 |
|
| 3108 |
+
if ( in_array( $params->from, array( 'save', 'process_form' ) ) || true === PodsForm::permission( $fields[ $field ][ 'type' ], $field, $fields[ $field ], $fields, $pod, $params->id, $params ) ) {
|
| 3109 |
+
$value = PodsForm::default_value( pods_var_raw( $field, 'post' ), $field_data[ 'type' ], $field, pods_var_raw( 'options', $field_data, $field_data, null, true ), $pod, $params->id );
|
| 3110 |
|
| 3111 |
+
if ( null !== $value && '' !== $value && false !== $value ) {
|
| 3112 |
+
$fields[ $field ][ 'value' ] = $value;
|
| 3113 |
+
$fields_active[] = $field;
|
| 3114 |
+
}
|
| 3115 |
+
}
|
| 3116 |
+
}
|
| 3117 |
|
| 3118 |
+
// Set default field values for object fields
|
| 3119 |
+
if ( !empty( $object_fields ) ) {
|
| 3120 |
+
foreach ( $object_fields as $field => $field_data ) {
|
| 3121 |
+
if ( in_array( $field, $fields_active ) ) {
|
| 3122 |
+
continue;
|
| 3123 |
}
|
| 3124 |
+
elseif ( !isset( $field_data[ 'default' ] ) || strlen( $field_data[ 'default' ] ) < 1 ) {
|
| 3125 |
+
continue;
|
|
|
|
| 3126 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3127 |
|
| 3128 |
+
$value = PodsForm::default_value( pods_var_raw( $field, 'post' ), $field_data[ 'type' ], $field, pods_var_raw( 'options', $field_data, $field_data, null, true ), $pod, $params->id );
|
| 3129 |
+
|
| 3130 |
+
if ( null !== $value && '' !== $value && false !== $value ) {
|
| 3131 |
+
$object_fields[ $field ][ 'value' ] = $value;
|
| 3132 |
+
$fields_active[] = $field;
|
| 3133 |
+
}
|
| 3134 |
}
|
| 3135 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3136 |
|
| 3137 |
+
// Set default field values for Pod fields
|
| 3138 |
+
foreach ( $fields as $field => $field_data ) {
|
| 3139 |
+
if ( in_array( $field, $fields_active ) ) {
|
| 3140 |
+
continue;
|
| 3141 |
+
}
|
| 3142 |
+
elseif ( !isset( $field_data[ 'default' ] ) || strlen( $field_data[ 'default' ] ) < 1 ) {
|
| 3143 |
+
continue;
|
| 3144 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3145 |
|
| 3146 |
+
$value = PodsForm::default_value( pods_var_raw( $field, 'post' ), $field_data[ 'type' ], $field, pods_var_raw( 'options', $field_data, $field_data, null, true ), $pod, $params->id );
|
|
|
|
|
|
|
| 3147 |
|
| 3148 |
+
if ( null !== $value && '' !== $value && false !== $value ) {
|
| 3149 |
+
$fields[ $field ][ 'value' ] = $value;
|
| 3150 |
+
$fields_active[] = $field;
|
| 3151 |
+
}
|
| 3152 |
}
|
| 3153 |
+
}
|
| 3154 |
|
| 3155 |
+
$columns =& $fields; // @deprecated 2.0
|
| 3156 |
+
$active_columns =& $fields_active; // @deprecated 2.0
|
| 3157 |
+
$params->tbl_row_id =& $params->id; // @deprecated 2.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3158 |
|
| 3159 |
+
$pre_save_helpers = $post_save_helpers = array();
|
|
|
|
|
|
|
|
|
|
| 3160 |
|
| 3161 |
+
$pieces = array(
|
| 3162 |
+
'fields',
|
| 3163 |
+
'params',
|
| 3164 |
+
'pod',
|
| 3165 |
+
'fields_active',
|
| 3166 |
+
'object_fields',
|
| 3167 |
+
'custom_fields',
|
| 3168 |
+
'custom_data',
|
| 3169 |
+
'track_changed_fields',
|
| 3170 |
+
'changed_fields'
|
| 3171 |
+
);
|
| 3172 |
|
| 3173 |
+
if ( false === $bypass_helpers ) {
|
| 3174 |
+
// Plugin hooks
|
| 3175 |
+
$hooked = $this->do_hook( 'pre_save_pod_item', compact( $pieces ), $is_new_item, $params->id );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3176 |
|
| 3177 |
+
if ( is_array( $hooked ) && !empty( $hooked ) )
|
| 3178 |
+
extract( $hooked );
|
| 3179 |
|
| 3180 |
+
$hooked = $this->do_hook( "pre_save_pod_item_{$params->pod}", compact( $pieces ), $is_new_item, $params->id );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3181 |
|
| 3182 |
+
if ( is_array( $hooked ) && !empty( $hooked ) )
|
| 3183 |
+
extract( $hooked );
|
| 3184 |
|
| 3185 |
+
if ( $is_new_item ) {
|
| 3186 |
+
$hooked = $this->do_hook( 'pre_create_pod_item', compact( $pieces ) );
|
|
|
|
|
|
|
| 3187 |
|
| 3188 |
+
if ( is_array( $hooked ) && !empty( $hooked ) )
|
| 3189 |
+
extract( $hooked );
|
| 3190 |
|
| 3191 |
+
$hooked = $this->do_hook( "pre_create_pod_item_{$params->pod}", compact( $pieces ) );
|
|
|
|
|
|
|
| 3192 |
|
| 3193 |
+
if ( is_array( $hooked ) && !empty( $hooked ) )
|
| 3194 |
+
extract( $hooked );
|
| 3195 |
+
}
|
| 3196 |
+
else {
|
| 3197 |
+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
|
|
| 3207 |
|
| 3208 |
+
// Call any pre-save helpers (if not bypassed)
|
| 3209 |
+
if ( !defined( 'PODS_DISABLE_EVAL' ) || !PODS_DISABLE_EVAL ) {
|
| 3210 |
+
if ( !empty( $pod[ 'options' ] ) && is_array( $pod[ 'options' ] ) ) {
|
| 3211 |
+
$helpers = array( 'pre_save_helpers', 'post_save_helpers' );
|
| 3212 |
|
| 3213 |
+
foreach ( $helpers as $helper ) {
|
| 3214 |
+
if ( isset( $pod[ 'options' ][ $helper ] ) && !empty( $pod[ 'options' ][ $helper ] ) )
|
| 3215 |
+
${$helper} = explode( ',', $pod[ 'options' ][ $helper ] );
|
| 3216 |
+
}
|
| 3217 |
+
}
|
|
|
|
| 3218 |
|
| 3219 |
+
if ( !empty( $pre_save_helpers ) ) {
|
| 3220 |
+
pods_deprecated( sprintf( __( 'Pre-save helpers are deprecated, use the action pods_pre_save_pod_item_%s instead', 'pods' ), $params->pod ), '2.0' );
|
|
|
|
| 3221 |
|
| 3222 |
+
foreach ( $pre_save_helpers as $helper ) {
|
| 3223 |
+
$helper = $this->load_helper( array( 'name' => $helper ) );
|
| 3224 |
|
| 3225 |
+
if ( false !== $helper )
|
| 3226 |
+
eval( '?>' . $helper[ 'code' ] );
|
| 3227 |
+
}
|
| 3228 |
+
}
|
| 3229 |
+
}
|
| 3230 |
+
}
|
| 3231 |
|
| 3232 |
+
if ( $track_changed_fields ) {
|
| 3233 |
+
$changed_fields = $this->get_changed_fields( compact( $pieces ) );
|
| 3234 |
}
|
| 3235 |
|
| 3236 |
+
$table_data = $table_formats = $update_values = $rel_fields = $rel_field_ids = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3237 |
|
| 3238 |
+
$object_type = $pod[ 'type' ];
|
|
|
|
|
|
|
|
|
|
| 3239 |
|
| 3240 |
+
$object_ID = 'ID';
|
| 3241 |
|
| 3242 |
+
if ( 'comment' == $object_type )
|
| 3243 |
+
$object_ID = 'comment_ID';
|
|
|
|
| 3244 |
|
| 3245 |
+
$object_data = $object_meta = $post_term_data = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3246 |
|
| 3247 |
+
if ( 'settings' == $object_type )
|
| 3248 |
+
$object_data[ 'option_id' ] = $pod[ 'name' ];
|
| 3249 |
+
elseif ( !empty( $params->id ) )
|
| 3250 |
+
$object_data[ $object_ID ] = $params->id;
|
| 3251 |
|
| 3252 |
+
$fields_active = array_unique( $fields_active );
|
|
|
|
|
|
|
| 3253 |
|
| 3254 |
+
// Loop through each active field, validating and preparing the table data
|
| 3255 |
+
foreach ( $fields_active as $field ) {
|
| 3256 |
+
if ( isset( $object_fields[ $field ] ) )
|
| 3257 |
+
$field_data = $object_fields[ $field ];
|
| 3258 |
+
elseif ( isset( $fields[ $field ] ) )
|
| 3259 |
+
$field_data = $fields[ $field ];
|
| 3260 |
+
else
|
| 3261 |
+
continue;
|
| 3262 |
|
| 3263 |
+
$value = $field_data[ 'value' ];
|
| 3264 |
+
$type = $field_data[ 'type' ];
|
| 3265 |
+
$options = pods_var( 'options', $field_data, array() );
|
|
|
|
| 3266 |
|
| 3267 |
+
// WPML AJAX compatibility
|
| 3268 |
+
if ( is_admin() && isset( $_GET[ 'page' ] ) && false !== strpos( $_GET[ 'page' ], '/menu/languages.php' ) && isset( $_POST[ 'icl_ajx_action' ] ) && isset( $_POST[ '_icl_nonce' ] ) && wp_verify_nonce( $_POST[ '_icl_nonce' ], $_POST[ 'icl_ajx_action' ] . '_nonce' ) )
|
| 3269 |
+
$options[ 'unique' ] = $fields[ $field ][ 'options' ][ 'unique' ] = $options[ 'required' ] = $fields[ $field ][ 'options' ][ 'required' ] = 0;
|
| 3270 |
+
else {
|
| 3271 |
+
// Validate value
|
| 3272 |
+
$validate = $this->handle_field_validation( $value, $field, $object_fields, $fields, $pod, $params );
|
| 3273 |
|
| 3274 |
+
if ( false === $validate )
|
| 3275 |
+
$validate = sprintf( __( 'There was an issue validating the field %s', 'pods' ), $field_data[ 'label' ] );
|
| 3276 |
+
elseif ( true !== $validate )
|
| 3277 |
+
$validate = (array) $validate;
|
| 3278 |
|
| 3279 |
+
if ( !is_bool( $validate ) && !empty( $validate ) )
|
| 3280 |
+
return pods_error( $validate, $this );
|
| 3281 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3282 |
|
| 3283 |
+
$value = PodsForm::pre_save( $field_data[ 'type' ], $value, $params->id, $field, array_merge( $field_data, $options ), array_merge( $fields, $object_fields ), $pod, $params );
|
| 3284 |
|
| 3285 |
+
$field_data[ 'value' ] = $value;
|
|
|
|
|
|
|
| 3286 |
|
| 3287 |
+
if ( isset( $object_fields[ $field ] ) ) {
|
| 3288 |
+
if ( 'taxonomy' == $object_fields[ $field ][ 'type' ] ) {
|
| 3289 |
+
$post_term_data[ $field ] = $value;
|
| 3290 |
}
|
| 3291 |
+
else {
|
| 3292 |
+
$object_data[ $field ] = $value;
|
| 3293 |
+
}
|
| 3294 |
+
}
|
| 3295 |
+
else {
|
| 3296 |
+
$simple = ( 'pick' == $type && in_array( pods_var( 'pick_object', $field_data ), $simple_tableless_objects ) );
|
| 3297 |
+
$simple = (boolean) $this->do_hook( 'tableless_custom', $simple, $field_data, $field, $fields, $pod, $params );
|
| 3298 |
+
|
| 3299 |
+
// Handle Simple Relationships
|
| 3300 |
+
if ( $simple ) {
|
| 3301 |
+
if ( !is_array( $value ) )
|
| 3302 |
+
$value = explode( ',', $value );
|
| 3303 |
+
|
| 3304 |
+
$pick_limit = (int) pods_var_raw( 'pick_limit', $options, 0 );
|
| 3305 |
+
|
| 3306 |
+
if ( 'single' == pods_var_raw( 'pick_format_type', $options ) )
|
| 3307 |
+
$pick_limit = 1;
|
| 3308 |
+
|
| 3309 |
+
if ( 'custom-simple' == pods_var( 'pick_object', $field_data ) ) {
|
| 3310 |
+
$custom = pods_var_raw( 'pick_custom', $options, '' );
|
| 3311 |
+
|
| 3312 |
+
$custom = apply_filters( 'pods_form_ui_field_pick_custom_values', $custom, $field_data[ 'name' ], $value, array_merge( $field_data, $options ), $pod, $params->id );
|
| 3313 |
+
|
| 3314 |
+
if ( empty( $value ) || empty( $custom ) )
|
| 3315 |
+
$value = '';
|
| 3316 |
+
elseif ( !empty( $custom ) ) {
|
| 3317 |
+
if ( !is_array( $custom ) ) {
|
| 3318 |
+
$custom = explode( "\n", $custom );
|
| 3319 |
+
|
| 3320 |
+
$custom_values = array();
|
| 3321 |
+
|
| 3322 |
+
foreach ( $custom as $c => $cv ) {
|
| 3323 |
+
if ( 0 < strlen( $cv ) ) {
|
| 3324 |
+
$custom_label = explode( '|', $cv );
|
| 3325 |
+
|
| 3326 |
+
if ( !isset( $custom_label[ 1 ] ) )
|
| 3327 |
+
$custom_label[ 1 ] = $custom_label[ 0 ];
|
| 3328 |
+
|
| 3329 |
+
$custom_label[ 0 ] = trim( (string) $custom_label[ 0 ] );
|
| 3330 |
+
$custom_label[ 1 ] = trim( (string) $custom_label[ 1 ] );
|
| 3331 |
+
$custom_values[ $custom_label[ 0 ] ] = $custom_label[ 1 ];
|
| 3332 |
+
}
|
| 3333 |
+
}
|
| 3334 |
+
}
|
| 3335 |
+
else
|
| 3336 |
+
$custom_values = $custom;
|
| 3337 |
+
|
| 3338 |
+
$values = array();
|
| 3339 |
+
|
| 3340 |
+
foreach ( $value as $k => $v ) {
|
| 3341 |
+
$v = pods_unsanitize( $v );
|
| 3342 |
+
|
| 3343 |
+
if ( isset( $custom_values[ $v ] ) )
|
| 3344 |
+
$values[ $k ] = $v;
|
| 3345 |
+
}
|
| 3346 |
+
|
| 3347 |
+
$value = $values;
|
| 3348 |
+
}
|
| 3349 |
+
}
|
| 3350 |
+
|
| 3351 |
+
if ( 0 < $pick_limit && !empty( $value ) )
|
| 3352 |
+
$value = array_slice( $value, 0, $pick_limit );
|
| 3353 |
+
|
| 3354 |
+
// Don't save an empty array, just make it an empty string
|
| 3355 |
+
if ( empty( $value ) )
|
| 3356 |
+
$value = '';
|
| 3357 |
+
elseif ( is_array( $value ) ) {
|
| 3358 |
+
// If there's just one item, don't save as an array, save the string
|
| 3359 |
+
if ( 1 == $pick_limit || 1 == count( $value ) )
|
| 3360 |
+
$value = implode( '', $value );
|
| 3361 |
+
// If storage is set to table, json encode, otherwise WP will serialize automatically
|
| 3362 |
+
elseif ( 'table' == pods_var( 'storage', $pod ) )
|
| 3363 |
+
$value = version_compare( PHP_VERSION, '5.4.0', '>=' ) ? json_encode( $value, JSON_UNESCAPED_UNICODE ) : json_encode( $value );
|
| 3364 |
+
}
|
| 3365 |
+
}
|
| 3366 |
+
|
| 3367 |
+
// Prepare all table / meta data
|
| 3368 |
+
if ( !in_array( $type, $tableless_field_types ) || $simple ) {
|
| 3369 |
+
if ( in_array( $type, $repeatable_field_types ) && 1 == pods_var( $type . '_repeatable', $field_data, 0 ) ) {
|
| 3370 |
+
// Don't save an empty array, just make it an empty string
|
| 3371 |
+
if ( empty( $value ) )
|
| 3372 |
+
$value = '';
|
| 3373 |
+
elseif ( is_array( $value ) ) {
|
| 3374 |
+
// If there's just one item, don't save as an array, save the string
|
| 3375 |
+
if ( 1 == count( $value ) )
|
| 3376 |
+
$value = implode( '', $value );
|
| 3377 |
+
// If storage is set to table, json encode, otherwise WP will serialize automatically
|
| 3378 |
+
elseif ( 'table' == pods_var( 'storage', $pod ) )
|
| 3379 |
+
$value = version_compare( PHP_VERSION, '5.4.0', '>=' ) ? json_encode( $value, JSON_UNESCAPED_UNICODE ) : json_encode( $value );
|
| 3380 |
+
}
|
| 3381 |
+
}
|
| 3382 |
+
|
| 3383 |
+
$table_data[ $field ] = str_replace( array( '{prefix}', '@wp_' ), array( '{/prefix/}', '{prefix}' ), $value ); // Fix for pods_query
|
| 3384 |
+
$table_formats[] = PodsForm::prepare( $type, $options );
|
| 3385 |
+
|
| 3386 |
+
$object_meta[ $field ] = $value;
|
| 3387 |
+
}
|
| 3388 |
+
// Store relational field data to be looped through later
|
| 3389 |
+
else {
|
| 3390 |
+
// Convert values from a comma-separated string into an array
|
| 3391 |
+
if ( !is_array( $value ) )
|
| 3392 |
+
$value = explode( ',', $value );
|
| 3393 |
+
|
| 3394 |
+
$rel_fields[ $type ][ $field ] = $value;
|
| 3395 |
+
$rel_field_ids[] = $field_data[ 'id' ];
|
| 3396 |
+
}
|
| 3397 |
+
}
|
| 3398 |
+
}
|
| 3399 |
+
|
| 3400 |
+
if ( 'post_type' == $pod[ 'type' ] ) {
|
| 3401 |
+
$post_type = $pod[ 'name' ];
|
| 3402 |
+
|
| 3403 |
+
if ( !empty( $pod[ 'object' ] ) )
|
| 3404 |
+
$post_type = $pod[ 'object' ];
|
| 3405 |
+
|
| 3406 |
+
$object_data[ 'post_type' ] = $post_type;
|
| 3407 |
+
}
|
| 3408 |
+
|
| 3409 |
+
if ( ( 'meta' == $pod[ 'storage' ] || 'settings' == $pod[ 'type' ] ) && !in_array( $pod[ 'type' ], array( 'taxonomy', 'pod', 'table', '' ) ) ) {
|
| 3410 |
+
if ( $allow_custom_fields && !empty( $custom_data ) )
|
| 3411 |
+
$object_meta = array_merge( $custom_data, $object_meta );
|
| 3412 |
+
|
| 3413 |
+
$fields_to_send = array_flip( array_keys( $object_meta ) );
|
| 3414 |
|
| 3415 |
+
foreach ( $fields_to_send as $field => $field_data ) {
|
| 3416 |
+
if ( isset( $object_fields[ $field ] ) ) {
|
| 3417 |
+
$field_data = $object_fields[ $field ];
|
|
|
|
| 3418 |
}
|
| 3419 |
+
elseif ( isset( $fields[ $field ] ) ) {
|
| 3420 |
+
$field_data = $fields[ $field ];
|
|
|
|
|
|
|
| 3421 |
}
|
| 3422 |
+
else {
|
| 3423 |
+
unset( $fields_to_send[ $field ] );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3424 |
}
|
| 3425 |
|
| 3426 |
+
$fields_to_send[ $field ] = $field_data;
|
|
|
|
|
|
|
| 3427 |
}
|
|
|
|
|
|
|
| 3428 |
|
| 3429 |
+
$params->id = $this->save_wp_object( $object_type, $object_data, $object_meta, false, true, $fields_to_send );
|
|
|
|
| 3430 |
|
| 3431 |
+
if ( !empty( $params->id ) && 'settings' == $object_type )
|
| 3432 |
+
$params->id = $pod[ 'id' ];
|
| 3433 |
+
}
|
| 3434 |
+
else {
|
| 3435 |
+
if ( !in_array( $pod[ 'type' ], array( 'taxonomy', 'pod', 'table', '' ) ) )
|
| 3436 |
+
$params->id = $this->save_wp_object( $object_type, $object_data, array(), false, true );
|
| 3437 |
+
elseif ( 'taxonomy' == $pod[ 'type' ] ) {
|
| 3438 |
+
$term = pods_v( $object_fields[ 'name' ][ 'name' ], $object_data, '', null, true );
|
| 3439 |
+
if ( !isset( $term_data ) ) {
|
| 3440 |
+
$term_data = array ();
|
| 3441 |
}
|
| 3442 |
|
| 3443 |
+
if ( empty( $params->id ) || !empty( $term_data ) ) {
|
| 3444 |
+
$taxonomy = $pod[ 'name' ];
|
|
|
|
| 3445 |
|
| 3446 |
+
if ( !empty( $pod[ 'object' ] ) )
|
| 3447 |
+
$taxonomy = $pod[ 'object' ];
|
|
|
|
| 3448 |
|
| 3449 |
+
$params->id = $this->save_term( $params->id, $term, $taxonomy, $term_data, true );
|
| 3450 |
+
}
|
| 3451 |
+
}
|
| 3452 |
|
| 3453 |
+
if ( 'table' == $pod[ 'storage' ] ) {
|
| 3454 |
+
// Every row should have an id set here, otherwise Pods with nothing
|
| 3455 |
+
// but relationship fields won't get properly ID'd
|
| 3456 |
+
if ( empty( $params->id ) )
|
| 3457 |
+
$params->id = 0;
|
|
|
|
| 3458 |
|
| 3459 |
+
$table_data = array( 'id' => $params->id ) + $table_data;
|
| 3460 |
+
array_unshift( $table_formats, '%d' );
|
|
|
|
| 3461 |
|
| 3462 |
+
if ( !empty( $table_data ) ) {
|
| 3463 |
+
$sql = pods_data()->insert_on_duplicate( "@wp_pods_{$params->pod}", $table_data, $table_formats );
|
| 3464 |
|
| 3465 |
+
$id = pods_query( $sql, 'Cannot add/save table row' );
|
|
|
|
|
|
|
| 3466 |
|
| 3467 |
+
if ( empty( $params->id ) )
|
| 3468 |
+
$params->id = $id;
|
| 3469 |
+
}
|
| 3470 |
+
}
|
| 3471 |
+
}
|
| 3472 |
|
| 3473 |
+
$params->id = (int) $params->id;
|
|
|
|
|
|
|
| 3474 |
|
| 3475 |
+
// Save terms for taxonomies associated to a post type
|
| 3476 |
+
if ( 0 < $params->id && 'post_type' == $pod[ 'type' ] && !empty( $post_term_data ) ) {
|
| 3477 |
+
foreach ( $post_term_data as $post_taxonomy => $post_terms ) {
|
| 3478 |
+
$post_terms = (array) $post_terms;
|
| 3479 |
|
| 3480 |
+
foreach ( $post_terms as $k => $v ) {
|
| 3481 |
+
if ( ! preg_match( '/[^0-9]/', $v ) ) {
|
| 3482 |
+
$v = (int) $v;
|
| 3483 |
+
}
|
|
|
|
| 3484 |
|
| 3485 |
+
$post_terms[ $k ] = $v;
|
| 3486 |
+
}
|
| 3487 |
+
|
| 3488 |
+
wp_set_object_terms( $params->id, $post_terms, $post_taxonomy );
|
| 3489 |
+
}
|
| 3490 |
}
|
| 3491 |
|
| 3492 |
+
$no_conflict = pods_no_conflict_check( $pod[ 'type' ] );
|
|
|
|
| 3493 |
|
| 3494 |
+
if ( !$no_conflict )
|
| 3495 |
+
pods_no_conflict_on( $pod[ 'type' ] );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3496 |
|
| 3497 |
+
// Save relationship / file data
|
| 3498 |
+
if ( !empty( $rel_fields ) ) {
|
| 3499 |
+
foreach ( $rel_fields as $type => $data ) {
|
| 3500 |
+
// Only handle tableless fields
|
| 3501 |
+
if ( !in_array( $type, $tableless_field_types ) ) {
|
| 3502 |
+
continue;
|
| 3503 |
+
}
|
| 3504 |
|
| 3505 |
+
foreach ( $data as $field => $values ) {
|
| 3506 |
+
$pick_val = pods_var( 'pick_val', $fields[ $field ] );
|
| 3507 |
|
| 3508 |
+
if ( 'table' == pods_var( 'pick_object', $fields[ $field ] ) ) {
|
| 3509 |
+
$pick_val = pods_var( 'pick_table', $fields[ $field ][ 'options' ], $pick_val, null, true );
|
| 3510 |
+
}
|
| 3511 |
|
| 3512 |
+
if ( '__current__' == $pick_val ) {
|
| 3513 |
+
if ( is_object( $pod ) ) {
|
| 3514 |
+
$pick_val = $pod->pod;
|
| 3515 |
+
}
|
| 3516 |
+
elseif ( is_array( $pod ) ) {
|
| 3517 |
+
$pick_val = $pod[ 'name' ];
|
| 3518 |
+
}
|
| 3519 |
+
elseif ( 0 < strlen( $pod ) ) {
|
| 3520 |
+
$pick_val = $pod;
|
| 3521 |
+
}
|
| 3522 |
+
}
|
| 3523 |
|
| 3524 |
+
$fields[ $field ][ 'options' ][ 'table_info' ] = pods_api()->get_table_info( pods_var( 'pick_object', $fields[ $field ] ), $pick_val, null, null, $fields[ $field ][ 'options' ] );
|
|
|
|
|
|
|
| 3525 |
|
| 3526 |
+
if ( isset( $fields[ $field ][ 'options' ][ 'table_info' ][ 'pod' ] ) && !empty( $fields[ $field ][ 'options' ][ 'table_info' ][ 'pod' ] ) && isset( $fields[ $field ][ 'options' ][ 'table_info' ][ 'pod' ][ 'name' ] ) ) {
|
| 3527 |
+
$search_data = pods( $fields[ $field ][ 'options' ][ 'table_info' ][ 'pod' ][ 'name' ] );
|
| 3528 |
|
| 3529 |
+
$data_mode = 'pods';
|
| 3530 |
+
}
|
| 3531 |
+
else {
|
| 3532 |
+
$search_data = pods_data();
|
| 3533 |
+
$search_data->table( $fields[ $field ][ 'options' ][ 'table_info' ] );
|
| 3534 |
|
| 3535 |
+
$data_mode = 'data';
|
| 3536 |
+
}
|
| 3537 |
|
| 3538 |
+
$find_rel_params = array(
|
| 3539 |
+
'select' => "`t`.`{$search_data->field_id}`",
|
| 3540 |
+
'where' => "`t`.`{$search_data->field_slug}` = %s OR `t`.`{$search_data->field_index}` = %s",
|
| 3541 |
+
'limit' => 1,
|
| 3542 |
+
'pagination' => false,
|
| 3543 |
+
'search' => false
|
| 3544 |
+
);
|
| 3545 |
|
| 3546 |
+
if ( empty( $search_data->field_slug ) && !empty( $search_data->field_index ) ) {
|
| 3547 |
+
$find_rel_params[ 'where' ] = "`t`.`{$search_data->field_index}` = %s";
|
| 3548 |
+
}
|
| 3549 |
+
elseif ( empty( $search_data->field_slug ) && empty( $search_data->field_index ) ) {
|
| 3550 |
+
$find_rel_params = false;
|
| 3551 |
+
}
|
| 3552 |
|
| 3553 |
+
$related_limit = (int) pods_var_raw( $type . '_limit', $fields[ $field ][ 'options' ], 0 );
|
|
|
|
| 3554 |
|
| 3555 |
+
if ( 'single' == pods_var_raw( $type . '_format_type', $fields[ $field ][ 'options' ] ) ) {
|
| 3556 |
+
$related_limit = 1;
|
| 3557 |
+
}
|
| 3558 |
|
| 3559 |
+
// Enforce integers / unique values for IDs
|
| 3560 |
+
$value_ids = array();
|
| 3561 |
|
| 3562 |
+
$is_file_field = in_array( $type, PodsForm::file_field_types() );
|
| 3563 |
+
$is_taggable = ( in_array( $type, PodsForm::tableless_field_types() ) && 1 == pods_v( $type . '_taggable', $fields[ $field ][ 'options' ] ) );
|
|
|
|
| 3564 |
|
| 3565 |
+
// @todo Handle simple relationships eventually
|
| 3566 |
+
foreach ( $values as $v ) {
|
| 3567 |
+
if ( !empty( $v ) ) {
|
| 3568 |
+
if ( !is_array( $v ) ) {
|
| 3569 |
+
if ( !preg_match( '/[^0-9]/', $v ) ) {
|
| 3570 |
+
$v = (int) $v;
|
| 3571 |
+
}
|
| 3572 |
+
// File handling
|
| 3573 |
+
elseif ( $is_file_field ) {
|
| 3574 |
+
// Get ID from GUID
|
| 3575 |
+
$v = pods_image_id_from_field( $v );
|
| 3576 |
|
| 3577 |
+
// If file not found, add it
|
| 3578 |
+
if ( empty( $v ) ) {
|
| 3579 |
+
$v = pods_attachment_import( $v );
|
| 3580 |
+
}
|
| 3581 |
+
}
|
| 3582 |
+
// Reference by slug
|
| 3583 |
+
else {
|
| 3584 |
+
$v_data = false;
|
| 3585 |
|
| 3586 |
+
if ( false !== $find_rel_params ) {
|
| 3587 |
+
$rel_params = $find_rel_params;
|
| 3588 |
+
$rel_params[ 'where' ] = $wpdb->prepare( $rel_params[ 'where' ], array( $v, $v ) );
|
|
|
|
| 3589 |
|
| 3590 |
+
$search_data->select( $rel_params );
|
|
|
|
|
|
|
|
|
|
| 3591 |
|
| 3592 |
+
$v_data = $search_data->fetch( $v );
|
| 3593 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3594 |
|
| 3595 |
+
if ( !empty( $v_data ) && isset( $v_data[ $search_data->field_id ] ) ) {
|
| 3596 |
+
$v = (int) $v_data[ $search_data->field_id ];
|
| 3597 |
+
}
|
| 3598 |
+
// Allow tagging for Pods objects
|
| 3599 |
+
elseif ( $is_taggable && 'pods' == $data_mode ) {
|
| 3600 |
+
$tag_data = array(
|
| 3601 |
+
$search_data->field_index => $v
|
| 3602 |
+
);
|
| 3603 |
|
| 3604 |
+
if ( 'post_type' == $search_data->pod_data[ 'type' ] ) {
|
| 3605 |
+
$tag_data[ 'post_status' ] = 'publish';
|
| 3606 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3607 |
|
| 3608 |
+
/**
|
| 3609 |
+
* Filter for changing tag before adding new item.
|
| 3610 |
+
*
|
| 3611 |
+
* @param array $tag_data Fields for creating new item.
|
| 3612 |
+
* @param int $v Field ID of tag.
|
| 3613 |
+
* @param obj $search_data Search object for tag.
|
| 3614 |
+
* @param string $field Table info for field.
|
| 3615 |
+
* @param array $pieces Field array.
|
| 3616 |
+
*
|
| 3617 |
+
* @since 2.3.19
|
| 3618 |
+
*/
|
| 3619 |
+
$tag_data = apply_filters( 'pods_api_save_pod_item_taggable_data', $tag_data, $v, $search_data, $field, compact( $pieces ) );
|
| 3620 |
|
| 3621 |
+
// Save $v to a new item on related object
|
| 3622 |
+
$v = $search_data->add( $tag_data );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3634 |
|
| 3635 |
+
if ( !empty( $v ) && !in_array( $v, $value_ids ) ) {
|
| 3636 |
+
$value_ids[] = $v;
|
| 3637 |
+
}
|
| 3638 |
+
}
|
| 3639 |
+
}
|
| 3640 |
+
|
| 3641 |
+
$value_ids = array_unique( array_filter( $value_ids ) );
|
| 3642 |
+
|
| 3643 |
+
// Limit values
|
| 3644 |
+
if ( 0 < $related_limit && !empty( $value_ids ) )
|
| 3645 |
+
$value_ids = array_slice( $value_ids, 0, $related_limit );
|
| 3646 |
+
|
| 3647 |
+
// Get current values
|
| 3648 |
+
if ( 'pick' == $type && isset( PodsField_Pick::$related_data[ $fields[ $field ][ 'id' ] ] ) && isset( PodsField_Pick::$related_data[ $fields[ $field ][ 'id' ] ][ 'current_ids' ] ) )
|
| 3649 |
+
$related_ids = PodsField_Pick::$related_data[ $fields[ $field ][ 'id' ] ][ 'current_ids' ];
|
| 3650 |
+
else
|
| 3651 |
+
$related_ids = $this->lookup_related_items( $fields[ $field ][ 'id' ], $pod[ 'id' ], $params->id, $fields[ $field ], $pod );
|
| 3652 |
+
|
| 3653 |
+
// Get ids to remove
|
| 3654 |
+
$remove_ids = array_diff( $related_ids, $value_ids );
|
| 3655 |
+
|
| 3656 |
+
// Delete relationships
|
| 3657 |
+
if ( !empty( $remove_ids ) )
|
| 3658 |
+
$this->delete_relationships( $params->id, $remove_ids, $pod, $fields[ $field ] );
|
| 3659 |
+
|
| 3660 |
+
// Save relationships
|
| 3661 |
+
if ( !empty( $value_ids ) )
|
| 3662 |
+
$this->save_relationships( $params->id, $value_ids, $pod, $fields[ $field ] );
|
| 3663 |
+
|
| 3664 |
+
// Run save function for field type (where needed)
|
| 3665 |
+
PodsForm::save( $type, $values, $params->id, $field, array_merge( $fields[ $field ], $fields[ $field ][ 'options' ] ), array_merge( $fields, $object_fields ), $pod, $params );
|
| 3666 |
+
}
|
| 3667 |
+
|
| 3668 |
+
// Unset data no longer needed
|
| 3669 |
+
if ( 'pick' == $type ) {
|
| 3670 |
+
foreach ( $data as $field => $values ) {
|
| 3671 |
+
if ( isset( PodsField_Pick::$related_data[ $fields[ $field ][ 'id' ] ] ) ) {
|
| 3672 |
+
unset( PodsField_Pick::$related_data[ PodsField_Pick::$related_data[ $fields[ $field ][ 'id' ] ][ 'related_field' ][ 'id' ] ] );
|
| 3673 |
+
unset( PodsField_Pick::$related_data[ $fields[ $field ][ 'id' ] ] );
|
| 3674 |
+
}
|
| 3675 |
+
}
|
| 3676 |
+
}
|
| 3677 |
+
}
|
| 3678 |
+
}
|
| 3679 |
+
|
| 3680 |
+
if ( !$no_conflict )
|
| 3681 |
+
pods_no_conflict_off( $pod[ 'type' ] );
|
| 3682 |
+
|
| 3683 |
+
if ( false === $bypass_helpers ) {
|
| 3684 |
+
$pieces = compact( $pieces );
|
| 3685 |
+
|
| 3686 |
+
// Plugin hooks
|
| 3687 |
+
$this->do_hook( 'post_save_pod_item', $pieces, $is_new_item, $params->id );
|
| 3688 |
+
$this->do_hook( "post_save_pod_item_{$params->pod}", $pieces, $is_new_item, $params->id );
|
| 3689 |
+
|
| 3690 |
+
if ( $is_new_item ) {
|
| 3691 |
+
$this->do_hook( 'post_create_pod_item', $pieces, $params->id );
|
| 3692 |
+
$this->do_hook( "post_create_pod_item_{$params->pod}", $pieces, $params->id );
|
| 3693 |
+
}
|
| 3694 |
+
else {
|
| 3695 |
+
$this->do_hook( 'post_edit_pod_item', $pieces, $params->id );
|
| 3696 |
+
$this->do_hook( "post_edit_pod_item_{$params->pod}", $pieces, $params->id );
|
| 3697 |
+
}
|
| 3698 |
+
|
| 3699 |
+
// Call any post-save helpers (if not bypassed)
|
| 3700 |
+
if ( !defined( 'PODS_DISABLE_EVAL' ) || !PODS_DISABLE_EVAL ) {
|
| 3701 |
+
if ( !empty( $post_save_helpers ) ) {
|
| 3702 |
+
pods_deprecated( sprintf( __( 'Post-save helpers are deprecated, use the action pods_post_save_pod_item_%s instead', 'pods' ), $params->pod ), '2.0' );
|
| 3703 |
+
|
| 3704 |
+
foreach ( $post_save_helpers as $helper ) {
|
| 3705 |
+
$helper = $this->load_helper( array( 'name' => $helper ) );
|
| 3706 |
+
|
| 3707 |
+
if ( false !== $helper && ( !defined( 'PODS_DISABLE_EVAL' ) || !PODS_DISABLE_EVAL ) )
|
| 3708 |
+
eval( '?>' . $helper[ 'code' ] );
|
| 3709 |
+
}
|
| 3710 |
+
}
|
| 3711 |
+
}
|
| 3712 |
+
}
|
| 3713 |
+
|
| 3714 |
+
// Clear cache
|
| 3715 |
+
pods_cache_clear( $params->id, 'pods_items_' . $pod[ 'name' ] );
|
| 3716 |
+
|
| 3717 |
+
if ( $params->clear_slug_cache && !empty( $pod[ 'field_slug' ] ) ) {
|
| 3718 |
+
$slug = pods( $pod[ 'name' ], $params->id )->field( $pod[ 'field_slug' ] );
|
| 3719 |
|
| 3720 |
+
if ( 0 < strlen( $slug ) ) {
|
| 3721 |
+
pods_cache_clear( $slug, 'pods_items_' . $pod[ 'name' ] );
|
| 3722 |
}
|
| 3723 |
}
|
| 3724 |
|
| 3725 |
+
// Clear WP meta cache
|
| 3726 |
+
if ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy', 'user', 'comment' ) ) ) {
|
| 3727 |
+
$meta_type = $pod[ 'type' ];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3728 |
|
| 3729 |
+
if ( 'post_type' == $meta_type )
|
| 3730 |
+
$meta_type = 'post';
|
| 3731 |
|
| 3732 |
+
wp_cache_delete( $params->id, $meta_type . '_meta' );
|
| 3733 |
+
wp_cache_delete( $params->id, 'pods_' . $meta_type . '_meta' );
|
| 3734 |
+
}
|
| 3735 |
|
| 3736 |
+
// Success! Return the id
|
| 3737 |
+
return $params->id;
|
| 3738 |
|
| 3739 |
+
}
|
|
|
|
|
|
|
| 3740 |
|
| 3741 |
+
/**
|
| 3742 |
+
* @see PodsAPI::save_pod_item
|
| 3743 |
+
* Add multiple pod items
|
| 3744 |
+
*
|
| 3745 |
+
* $params['pod'] string The Pod name (pod or pod_id is required)
|
| 3746 |
+
* $params['pod_id'] string The Pod ID (pod or pod_id is required)
|
| 3747 |
+
* $params['bypass_helpers'] bool Set to true to bypass running pre-save and post-save helpers
|
| 3748 |
+
*
|
| 3749 |
+
* $data['id'] int The item ID (optional)
|
| 3750 |
+
* $data['data'] array An associative array of field names + values
|
| 3751 |
+
*
|
| 3752 |
+
* @param array|object $params An associative array of parameters, data excluded
|
| 3753 |
+
* @param array $data An associative array of pod ids and field names + values (arrays of field data)
|
| 3754 |
+
*
|
| 3755 |
+
* @return int The item ID
|
| 3756 |
+
* @since 2.0
|
| 3757 |
+
*/
|
| 3758 |
+
public function save_pod_items ( $params, $data ) {
|
| 3759 |
+
$params = (object) $params;
|
| 3760 |
|
| 3761 |
+
$ids = array();
|
|
|
|
|
|
|
| 3762 |
|
| 3763 |
+
foreach ( $data as $fields ) {
|
| 3764 |
+
$params->data = $fields;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3765 |
|
| 3766 |
+
if ( isset( $fields[ 'id' ] ) && isset( $fields[ 'data' ] ) ) {
|
| 3767 |
+
$params->id = $fields[ 'id' ];
|
| 3768 |
+
$params->data = $fields[ 'data' ];
|
| 3769 |
+
}
|
|
|
|
| 3770 |
|
| 3771 |
+
$ids[] = $this->save_pod_item( $params );
|
| 3772 |
+
}
|
|
|
|
| 3773 |
|
| 3774 |
+
return $ids;
|
| 3775 |
+
}
|
| 3776 |
|
| 3777 |
/**
|
| 3778 |
+
* Get the fields that have changed during a save
|
| 3779 |
*
|
| 3780 |
+
* @param array $pieces Pieces array from save_pod_item
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3781 |
*
|
| 3782 |
+
* @return array Array of fields and values that have changed
|
| 3783 |
*/
|
| 3784 |
+
public function get_changed_fields( $pieces ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3785 |
|
| 3786 |
+
$fields = $pieces[ 'fields' ];
|
| 3787 |
+
$fields_active = $pieces[ 'fields_active' ];
|
|
|
|
| 3788 |
|
| 3789 |
+
$fields_changed = array();
|
|
|
|
| 3790 |
|
| 3791 |
+
if ( 0 < $pieces[ 'params' ]->id ) {
|
| 3792 |
+
$pod = pods( $pieces[ 'params' ]->pod, $pieces[ 'params' ]->id );
|
|
|
|
|
|
|
| 3793 |
|
| 3794 |
+
foreach ( $fields_active as $field ) {
|
| 3795 |
+
if ( isset( $fields[ $field ] ) && $pod->raw( $field ) != $fields[ $field ][ 'value' ] ) {
|
| 3796 |
+
$fields_changed[ $field ] = $fields[ $field ][ 'value' ];
|
| 3797 |
}
|
| 3798 |
}
|
|
|
|
|
|
|
| 3799 |
}
|
| 3800 |
|
| 3801 |
+
return $fields_changed;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3802 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3803 |
}
|
| 3804 |
|
| 3805 |
+
/**
|
| 3806 |
+
* Save relationships
|
| 3807 |
+
*
|
| 3808 |
+
* @param int $id ID of item
|
| 3809 |
+
* @param int|array $related_id ID or IDs to save
|
| 3810 |
+
* @param array $pod Pod data
|
| 3811 |
+
* @param array $field Field data
|
| 3812 |
+
*/
|
| 3813 |
+
public function save_relationships ( $id, $related_ids, $pod, $field ) {
|
| 3814 |
+
// Get current values
|
| 3815 |
+
if ( 'pick' == $field[ 'type' ] && isset( PodsField_Pick::$related_data[ $field[ 'id' ] ] ) && isset( PodsField_Pick::$related_data[ $field[ 'id' ] ][ 'current_ids' ] ) )
|
| 3816 |
+
$current_ids = PodsField_Pick::$related_data[ $field[ 'id' ] ][ 'current_ids' ];
|
| 3817 |
+
else
|
| 3818 |
+
$current_ids = $this->lookup_related_items( $field[ 'id' ], $pod[ 'id' ], $id, $field, $pod );
|
| 3819 |
+
|
| 3820 |
+
if ( !is_array( $related_ids ) )
|
| 3821 |
+
$related_ids = implode( ',', $related_ids );
|
| 3822 |
+
|
| 3823 |
+
foreach ( $related_ids as $k => $related_id ) {
|
| 3824 |
+
$related_ids[ $k ] = (int) $related_id;
|
| 3825 |
+
}
|
| 3826 |
+
|
| 3827 |
+
$related_ids = array_unique( array_filter( $related_ids ) );
|
| 3828 |
+
|
| 3829 |
+
$related_limit = (int) pods_var_raw( $field[ 'type' ] . '_limit', $field[ 'options' ], 0 );
|
| 3830 |
+
|
| 3831 |
+
if ( 'single' == pods_var_raw( $field[ 'type' ] . '_format_type', $field[ 'options' ] ) )
|
| 3832 |
+
$related_limit = 1;
|
| 3833 |
+
|
| 3834 |
+
// Limit values
|
| 3835 |
+
if ( 0 < $related_limit && !empty( $related_ids ) )
|
| 3836 |
+
$related_ids = array_slice( $related_ids, 0, $related_limit );
|
| 3837 |
+
|
| 3838 |
+
// Post Types, Media, Users, and Comments (meta-based)
|
| 3839 |
+
if ( in_array( $pod[ 'type' ], array( 'post_type', 'media', 'user', 'comment' ) ) ) {
|
| 3840 |
+
$object_type = $pod[ 'type' ];
|
| 3841 |
+
|
| 3842 |
+
if ( 'post_type' == $object_type || 'media' == $object_type )
|
| 3843 |
+
$object_type = 'post';
|
| 3844 |
+
|
| 3845 |
+
delete_metadata( $object_type, $id, $field[ 'name' ] );
|
| 3846 |
+
|
| 3847 |
+
if ( !empty( $related_ids ) ) {
|
| 3848 |
+
update_metadata( $object_type, $id, '_pods_' . $field[ 'name' ], $related_ids );
|
| 3849 |
+
|
| 3850 |
+
foreach ( $related_ids as $related_id ) {
|
| 3851 |
+
add_metadata( $object_type, $id, $field[ 'name' ], $related_id );
|
| 3852 |
+
}
|
| 3853 |
+
}
|
| 3854 |
+
else
|
| 3855 |
+
delete_metadata( $object_type, $id, '_pods_' . $field[ 'name' ] );
|
| 3856 |
+
}
|
| 3857 |
+
// Custom Settings Pages (options-based)
|
| 3858 |
+
elseif ( 'settings' == $pod[ 'type' ] ) {
|
| 3859 |
+
if ( !empty( $related_ids ) )
|
| 3860 |
+
update_option( $pod[ 'name' ] . '_' . $field[ 'name' ], $related_ids );
|
| 3861 |
+
else
|
| 3862 |
+
delete_option( $pod[ 'name' ] . '_' . $field[ 'name' ] );
|
| 3863 |
+
}
|
| 3864 |
+
|
| 3865 |
+
$related_pod_id = $related_field_id = 0;
|
| 3866 |
+
|
| 3867 |
+
if ( 'pick' == $field[ 'type' ] && isset( PodsField_Pick::$related_data[ $field[ 'id' ] ] ) && !empty( PodsField_Pick::$related_data[ $field[ 'id' ] ][ 'related_field' ] ) ) {
|
| 3868 |
+
$related_pod_id = PodsField_Pick::$related_data[ $field[ 'id' ] ][ 'related_pod' ][ 'id' ];
|
| 3869 |
+
$related_field_id = PodsField_Pick::$related_data[ $field[ 'id' ] ][ 'related_field' ][ 'id' ];
|
| 3870 |
+
}
|
| 3871 |
+
|
| 3872 |
+
// Relationships table
|
| 3873 |
+
if ( !pods_tableless() ) {
|
| 3874 |
+
$related_weight = 0;
|
| 3875 |
+
|
| 3876 |
+
foreach ( $related_ids as $related_id ) {
|
| 3877 |
+
if ( in_array( $related_id, $current_ids ) ) {
|
| 3878 |
+
pods_query( "
|
| 3879 |
+
UPDATE `@wp_podsrel`
|
| 3880 |
+
SET
|
| 3881 |
+
`pod_id` = %d,
|
| 3882 |
+
`field_id` = %d,
|
| 3883 |
+
`item_id` = %d,
|
| 3884 |
+
`related_pod_id` = %d,
|
| 3885 |
+
`related_field_id` = %d,
|
| 3886 |
+
`related_item_id` = %d,
|
| 3887 |
+
`weight` = %d
|
| 3888 |
+
WHERE
|
| 3889 |
+
`pod_id` = %d
|
| 3890 |
+
AND `field_id` = %d
|
| 3891 |
+
AND `item_id` = %d
|
| 3892 |
+
AND `related_item_id` = %d
|
| 3893 |
+
", array(
|
| 3894 |
+
$pod[ 'id' ],
|
| 3895 |
+
$field[ 'id' ],
|
| 3896 |
+
$id,
|
| 3897 |
+
$related_pod_id,
|
| 3898 |
+
$related_field_id,
|
| 3899 |
+
$related_id,
|
| 3900 |
+
$related_weight,
|
| 3901 |
+
|
| 3902 |
+
$pod[ 'id' ],
|
| 3903 |
+
$field[ 'id' ],
|
| 3904 |
+
$id,
|
| 3905 |
+
$related_id,
|
| 3906 |
+
) );
|
| 3907 |
+
}
|
| 3908 |
+
else {
|
| 3909 |
+
pods_query( "
|
| 3910 |
+
INSERT INTO `@wp_podsrel`
|
| 3911 |
+
(
|
| 3912 |
+
`pod_id`,
|
| 3913 |
+
`field_id`,
|
| 3914 |
+
`item_id`,
|
| 3915 |
+
`related_pod_id`,
|
| 3916 |
+
`related_field_id`,
|
| 3917 |
+
`related_item_id`,
|
| 3918 |
+
`weight`
|
| 3919 |
+
)
|
| 3920 |
+
VALUES ( %d, %d, %d, %d, %d, %d, %d )
|
| 3921 |
+
", array(
|
| 3922 |
+
$pod[ 'id' ],
|
| 3923 |
+
$field[ 'id' ],
|
| 3924 |
+
$id,
|
| 3925 |
+
$related_pod_id,
|
| 3926 |
+
$related_field_id,
|
| 3927 |
+
$related_id,
|
| 3928 |
+
$related_weight
|
| 3929 |
+
) );
|
| 3930 |
+
}
|
| 3931 |
+
|
| 3932 |
+
$related_weight++;
|
| 3933 |
+
}
|
| 3934 |
+
}
|
| 3935 |
+
}
|
| 3936 |
+
|
| 3937 |
+
/**
|
| 3938 |
+
* Duplicate a Pod
|
| 3939 |
+
*
|
| 3940 |
+
* $params['id'] int The Pod ID
|
| 3941 |
+
* $params['name'] string The Pod name
|
| 3942 |
+
* $params['new_name'] string The new Pod name
|
| 3943 |
+
*
|
| 3944 |
+
* @param array $params An associative array of parameters
|
| 3945 |
+
* @param bool $strict (optional) Makes sure a pod exists, if it doesn't throws an error
|
| 3946 |
+
*
|
| 3947 |
+
* @return int New Pod ID
|
| 3948 |
+
* @since 2.3
|
| 3949 |
+
*/
|
| 3950 |
+
public function duplicate_pod ( $params, $strict = false ) {
|
| 3951 |
+
if ( !is_object( $params ) && !is_array( $params ) ) {
|
| 3952 |
+
if ( is_numeric( $params ) )
|
| 3953 |
+
$params = array( 'id' => $params );
|
| 3954 |
+
else
|
| 3955 |
+
$params = array( 'name' => $params );
|
| 3956 |
+
|
| 3957 |
+
$params = (object) pods_sanitize( $params );
|
| 3958 |
+
}
|
| 3959 |
+
else
|
| 3960 |
+
$params = (object) pods_sanitize( $params );
|
| 3961 |
+
|
| 3962 |
+
$params->table_info = false;
|
| 3963 |
+
|
| 3964 |
+
$pod = $this->load_pod( $params, $strict );
|
| 3965 |
+
|
| 3966 |
+
if ( empty( $pod ) ) {
|
| 3967 |
+
if ( false !== $strict )
|
| 3968 |
+
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
| 3969 |
+
|
| 3970 |
+
return false;
|
| 3971 |
+
}
|
| 3972 |
+
elseif ( in_array( $pod[ 'type' ], array( 'media', 'user', 'comment' ) ) ) {
|
| 3973 |
+
if ( false !== $strict )
|
| 3974 |
+
return pods_error( __( 'Pod not allowed to be duplicated', 'pods' ), $this );
|
| 3975 |
+
|
| 3976 |
+
return false;
|
| 3977 |
+
}
|
| 3978 |
+
elseif ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) && 0 < strlen( $pod[ 'object' ] ) ) {
|
| 3979 |
+
$pod[ 'object' ] = '';
|
| 3980 |
+
}
|
| 3981 |
+
|
| 3982 |
+
unset( $pod[ 'id' ] );
|
| 3983 |
+
|
| 3984 |
+
if ( isset( $params->new_name ) )
|
| 3985 |
+
$pod[ 'name' ] = $params->new_name;
|
| 3986 |
+
|
| 3987 |
+
$try = 1;
|
| 3988 |
+
|
| 3989 |
+
$check_name = $pod[ 'name' ];
|
| 3990 |
+
$new_label = $pod[ 'label' ];
|
| 3991 |
+
|
| 3992 |
+
while ( $this->load_pod( array( 'name' => $check_name, 'table_info' => false ), false ) ) {
|
| 3993 |
+
$try++;
|
| 3994 |
+
|
| 3995 |
+
$check_name = $pod[ 'name' ] . $try;
|
| 3996 |
+
$new_label = $pod[ 'label' ] . $try;
|
| 3997 |
+
}
|
| 3998 |
+
|
| 3999 |
+
$pod[ 'name' ] = $check_name;
|
| 4000 |
+
$pod[ 'label' ] = $new_label;
|
| 4001 |
+
|
| 4002 |
+
foreach ( $pod[ 'fields' ] as $field => $field_data ) {
|
| 4003 |
+
unset( $pod[ 'fields' ][ $field ][ 'id' ] );
|
| 4004 |
+
}
|
| 4005 |
+
|
| 4006 |
+
return $this->save_pod( $pod );
|
| 4007 |
+
}
|
| 4008 |
+
|
| 4009 |
+
/**
|
| 4010 |
+
* Duplicate a Field
|
| 4011 |
+
*
|
| 4012 |
+
* $params['pod_id'] int The Pod ID
|
| 4013 |
+
* $params['pod'] string The Pod name
|
| 4014 |
+
* $params['id'] int The Field ID
|
| 4015 |
+
* $params['name'] string The Field name
|
| 4016 |
+
* $params['new_name'] string The new Field name
|
| 4017 |
+
*
|
| 4018 |
+
* @param array $params An associative array of parameters
|
| 4019 |
+
* @param bool $strict (optional) Makes sure a field exists, if it doesn't throws an error
|
| 4020 |
+
*
|
| 4021 |
+
* @return int New Field ID
|
| 4022 |
+
* @since 2.3.10
|
| 4023 |
+
*/
|
| 4024 |
+
public function duplicate_field( $params, $strict = false ) {
|
| 4025 |
|
| 4026 |
+
if ( !is_object( $params ) && !is_array( $params ) ) {
|
| 4027 |
+
if ( is_numeric( $params ) ) {
|
| 4028 |
+
$params = array( 'id' => $params );
|
| 4029 |
}
|
| 4030 |
+
else {
|
| 4031 |
+
$params = array( 'name' => $params );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4032 |
}
|
|
|
|
| 4033 |
}
|
| 4034 |
|
| 4035 |
+
$params = (object) pods_sanitize( $params );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4036 |
|
| 4037 |
+
$params->table_info = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4038 |
|
| 4039 |
+
$field = $this->load_field( $params, $strict );
|
|
|
|
| 4040 |
|
| 4041 |
+
if ( empty( $field ) ) {
|
| 4042 |
+
if ( false !== $strict ) {
|
| 4043 |
+
return pods_error( __( 'Field not found', 'pods' ), $this );
|
|
|
|
| 4044 |
}
|
| 4045 |
|
| 4046 |
+
return false;
|
| 4047 |
+
}
|
|
|
|
| 4048 |
|
| 4049 |
+
unset( $field[ 'id' ] );
|
| 4050 |
|
| 4051 |
+
if ( isset( $params->new_name ) ) {
|
| 4052 |
+
$field[ 'name' ] = $params->new_name;
|
| 4053 |
+
}
|
|
|
|
|
|
|
| 4054 |
|
| 4055 |
+
$try = 1;
|
| 4056 |
|
| 4057 |
+
$check_name = $field[ 'name' ];
|
| 4058 |
+
$new_label = $field[ 'label' ];
|
|
|
|
| 4059 |
|
| 4060 |
+
while ( $this->load_field( array( 'pod_id' => $field[ 'pod_id' ], 'name' => $check_name, 'table_info' => false ), false ) ) {
|
| 4061 |
+
$try++;
|
| 4062 |
|
| 4063 |
+
$check_name = $field[ 'name' ] . $try;
|
| 4064 |
+
$new_label = $field[ 'label' ] . $try;
|
| 4065 |
+
}
|
|
|
|
|
|
|
|
|
|
| 4066 |
|
| 4067 |
+
$field[ 'name' ] = $check_name;
|
| 4068 |
+
$field[ 'label' ] = $new_label;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4069 |
|
| 4070 |
+
return $this->save_field( $field );
|
|
|
|
|
|
|
| 4071 |
|
| 4072 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4073 |
|
| 4074 |
+
/**
|
| 4075 |
+
* @see PodsAPI::save_pod_item
|
| 4076 |
+
*
|
| 4077 |
+
* Duplicate a pod item
|
| 4078 |
+
*
|
| 4079 |
+
* $params['pod'] string The Pod name
|
| 4080 |
+
* $params['id'] int The item's ID from the wp_pods_* table
|
| 4081 |
+
*
|
| 4082 |
+
* @param array $params An associative array of parameters
|
| 4083 |
+
*
|
| 4084 |
+
* @return int The table row ID
|
| 4085 |
+
* @since 1.12
|
| 4086 |
+
*/
|
| 4087 |
+
public function duplicate_pod_item ( $params ) {
|
| 4088 |
+
$params = (object) pods_sanitize( $params );
|
| 4089 |
+
|
| 4090 |
+
$pod = $this->load_pod( array( 'name' => $params->pod, 'table_info' => false ) );
|
| 4091 |
+
|
| 4092 |
+
if ( false === $pod )
|
| 4093 |
+
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
| 4094 |
+
|
| 4095 |
+
$pod = pods( $params->pod, $params->id );
|
| 4096 |
+
|
| 4097 |
+
$params->pod = $pod->pod;
|
| 4098 |
+
$params->pod_id = $pod->pod_id;
|
| 4099 |
+
|
| 4100 |
+
$fields = (array) pods_var_raw( 'fields', $pod->pod_data, array(), null, true );
|
| 4101 |
+
$object_fields = (array) pods_var_raw( 'object_fields', $pod->pod_data, array(), null, true );
|
| 4102 |
+
|
| 4103 |
+
if ( !empty( $object_fields ) )
|
| 4104 |
+
$fields = array_merge( $object_fields, $fields );
|
| 4105 |
+
|
| 4106 |
+
$save_params = array(
|
| 4107 |
+
'pod' => $params->pod,
|
| 4108 |
+
'data' => array()
|
| 4109 |
+
);
|
| 4110 |
+
|
| 4111 |
+
foreach ( $fields as $field ) {
|
| 4112 |
+
$value = $pod->field( array( 'name' => $field[ 'name' ], 'output' => 'ids' ) );
|
| 4113 |
+
|
| 4114 |
+
if ( !empty( $value ) || ( !is_array( $value ) && 0 < strlen( $value ) ) )
|
| 4115 |
+
$save_params[ 'data' ][ $field[ 'name' ] ] = $value;
|
| 4116 |
+
}
|
| 4117 |
+
|
| 4118 |
+
$save_params = $this->do_hook( 'duplicate_pod_item', $save_params, $pod->pod, $pod->id(), $params );
|
| 4119 |
+
|
| 4120 |
+
$id = $this->save_pod_item( $save_params );
|
| 4121 |
+
|
| 4122 |
+
return $id;
|
| 4123 |
+
}
|
| 4124 |
+
|
| 4125 |
+
/**
|
| 4126 |
+
* @see pods()
|
| 4127 |
+
*
|
| 4128 |
+
* Export a pod item
|
| 4129 |
+
*
|
| 4130 |
+
* $params['pod'] string The Pod name
|
| 4131 |
+
* $params['id'] int The item's ID from the wp_pods_* table
|
| 4132 |
+
* $params['fields'] array The fields to export
|
| 4133 |
+
* $params['depth'] int How many levels deep to export data
|
| 4134 |
+
*
|
| 4135 |
+
* @param array $params An associative array of parameters
|
| 4136 |
+
* @param object $pod (optional) Pods object
|
| 4137 |
+
*
|
| 4138 |
+
* @return int The table row ID
|
| 4139 |
+
* @since 1.12
|
| 4140 |
+
*/
|
| 4141 |
+
public function export_pod_item ( $params, $pod = null ) {
|
| 4142 |
+
if ( !is_object( $pod ) || 'Pods' != get_class( $pod ) ) {
|
| 4143 |
+
if ( empty( $params ) )
|
| 4144 |
+
return false;
|
| 4145 |
+
|
| 4146 |
+
$params = (object) pods_sanitize( $params );
|
| 4147 |
+
|
| 4148 |
+
$pod = pods( $params->pod, $params->id, false );
|
| 4149 |
+
|
| 4150 |
+
if ( empty( $pod ) )
|
| 4151 |
+
return false;
|
| 4152 |
+
}
|
| 4153 |
+
|
| 4154 |
+
$fields = (array) pods_var_raw( 'fields', $params, array(), null, true );
|
| 4155 |
+
$depth = (int) pods_var_raw( 'depth', $params, 2, null, true );
|
| 4156 |
+
$object_fields = (array) pods_var_raw( 'object_fields', $pod->pod_data, array(), null, true );
|
| 4157 |
+
$flatten = (boolean) pods_var( 'flatten', $params, false, null, true );
|
| 4158 |
+
|
| 4159 |
+
if ( empty( $fields ) ) {
|
| 4160 |
+
$fields = $pod->fields;
|
| 4161 |
+
$fields = array_merge( $fields, $object_fields );
|
| 4162 |
+
}
|
| 4163 |
+
|
| 4164 |
+
$data = $this->export_pod_item_level( $pod, $fields, $depth, $flatten );
|
| 4165 |
+
|
| 4166 |
+
$data = $this->do_hook( 'export_pod_item', $data, $pod->pod, $pod->id(), $pod, $fields, $depth, $flatten );
|
| 4167 |
+
|
| 4168 |
+
return $data;
|
| 4169 |
+
}
|
| 4170 |
+
|
| 4171 |
+
/**
|
| 4172 |
+
* Export a pod item by depth level
|
| 4173 |
+
*
|
| 4174 |
+
* @param Pods $pod Pods object
|
| 4175 |
+
* @param array $fields Fields to export
|
| 4176 |
+
* @param int $depth Depth limit
|
| 4177 |
+
* @param boolean $flatten Whether to flatten arrays for display
|
| 4178 |
+
* @param int $current_depth Current depth level
|
| 4179 |
+
*
|
| 4180 |
+
* @return array Data array
|
| 4181 |
+
*
|
| 4182 |
+
* @since 2.3
|
| 4183 |
+
*/
|
| 4184 |
+
private function export_pod_item_level ( $pod, $fields, $depth, $flatten = false, $current_depth = 1 ) {
|
| 4185 |
+
$tableless_field_types = PodsForm::tableless_field_types();
|
| 4186 |
+
$simple_tableless_objects = PodsForm::simple_tableless_objects();
|
| 4187 |
+
|
| 4188 |
+
$object_fields = (array) pods_var_raw( 'object_fields', $pod->pod_data, array(), null, true );
|
| 4189 |
+
|
| 4190 |
+
$export_fields = array();
|
| 4191 |
+
|
| 4192 |
+
foreach ( $fields as $k => $field ) {
|
| 4193 |
+
if ( !is_array( $field ) ) {
|
| 4194 |
+
$field = array(
|
| 4195 |
+
'id' => 0,
|
| 4196 |
+
'name' => $field
|
| 4197 |
+
);
|
| 4198 |
+
}
|
| 4199 |
+
|
| 4200 |
+
if ( isset( $pod->fields[ $field[ 'name' ] ] ) ) {
|
| 4201 |
+
$field = $pod->fields[ $field[ 'name' ] ];
|
| 4202 |
+
$field[ 'lookup_name' ] = $field[ 'name' ];
|
| 4203 |
+
|
| 4204 |
+
if ( in_array( $field[ 'type' ], $tableless_field_types ) && !in_array( pods_var( 'pick_object', $field ), $simple_tableless_objects ) ) {
|
| 4205 |
+
if ( 'pick' == $field[ 'type' ] ) {
|
| 4206 |
+
if ( empty( $field[ 'table_info' ] ) )
|
| 4207 |
+
$field[ 'table_info' ] = $this->get_table_info( pods_var_raw( 'pick_object', $field ), pods_var_raw( 'pick_val', $field ), null, null, $field );
|
| 4208 |
+
|
| 4209 |
+
if ( !empty( $field[ 'table_info' ] ) )
|
| 4210 |
+
$field[ 'lookup_name' ] .= '.' . $field[ 'table_info' ][ 'field_id' ];
|
| 4211 |
+
}
|
| 4212 |
+
elseif ( in_array( $field[ 'type' ], PodsForm::file_field_types() ) )
|
| 4213 |
+
$field[ 'lookup_name' ] .= '.guid';
|
| 4214 |
+
}
|
| 4215 |
+
|
| 4216 |
+
$export_fields[ $field[ 'name' ] ] = $field;
|
| 4217 |
+
}
|
| 4218 |
+
elseif ( isset( $object_fields[ $field[ 'name' ] ] ) ) {
|
| 4219 |
+
$field = $object_fields[ $field[ 'name' ] ];
|
| 4220 |
+
$field[ 'lookup_name' ] = $field[ 'name' ];
|
| 4221 |
+
|
| 4222 |
+
$export_fields[ $field[ 'name' ] ] = $field;
|
| 4223 |
+
}
|
| 4224 |
+
elseif ( $field[ 'name' ] == $pod->pod_data[ 'field_id' ] ) {
|
| 4225 |
+
$field[ 'type' ] = 'number';
|
| 4226 |
+
$field[ 'lookup_name' ] = $field[ 'name' ];
|
| 4227 |
+
|
| 4228 |
+
$export_fields[ $field[ 'name' ] ] = $field;
|
| 4229 |
+
}
|
| 4230 |
+
}
|
| 4231 |
+
|
| 4232 |
+
$data = array();
|
| 4233 |
+
|
| 4234 |
+
foreach ( $export_fields as $field ) {
|
| 4235 |
+
// Return IDs (or guid for files) if only one level deep
|
| 4236 |
+
if ( 1 == $depth )
|
| 4237 |
+
$data[ $field[ 'name' ] ] = $pod->field( array( 'name' => $field[ 'lookup_name' ], 'output' => 'arrays' ) );
|
| 4238 |
+
// Recurse depth levels for pick fields if $depth allows
|
| 4239 |
+
elseif ( ( -1 == $depth || $current_depth < $depth ) && 'pick' == $field[ 'type' ] && !in_array( pods_var( 'pick_object', $field ), $simple_tableless_objects ) ) {
|
| 4240 |
+
$related_data = array();
|
| 4241 |
+
|
| 4242 |
+
$related_ids = $pod->field( array( 'name' => $field[ 'name' ], 'output' => 'ids' ) );
|
| 4243 |
+
|
| 4244 |
+
if ( !empty( $related_ids ) ) {
|
| 4245 |
+
$related_ids = (array) $related_ids;
|
| 4246 |
+
|
| 4247 |
+
$pick_object = pods_var_raw( 'pick_object', $field );
|
| 4248 |
+
|
| 4249 |
+
$related_pod = pods( pods_var_raw( 'pick_val', $field ), null, false );
|
| 4250 |
+
|
| 4251 |
+
// If this isn't a Pod, return data exactly as Pods does normally
|
| 4252 |
+
if ( empty( $related_pod ) || ( 'pod' != $pick_object && $pick_object != $related_pod->pod_data[ 'type' ] ) || $related_pod->pod == $pod->pod )
|
| 4253 |
+
$related_data = $pod->field( array( 'name' => $field[ 'name' ], 'output' => 'arrays' ) );
|
| 4254 |
+
else {
|
| 4255 |
+
$related_object_fields = (array) pods_var_raw( 'object_fields', $related_pod->pod_data, array(), null, true );
|
| 4256 |
+
|
| 4257 |
+
$related_fields = array_merge( $related_pod->fields, $related_object_fields );
|
| 4258 |
+
|
| 4259 |
+
foreach ( $related_ids as $related_id ) {
|
| 4260 |
+
if ( $related_pod->fetch( $related_id ) ) {
|
| 4261 |
+
$related_item = $this->export_pod_item_level( $related_pod, $related_fields, $depth, $flatten, ( $current_depth + 1 ) );
|
| 4262 |
+
|
| 4263 |
+
$related_data[ $related_id ] = $this->do_hook( 'export_pod_item_level', $related_item, $related_pod->pod, $related_pod->id(), $related_pod, $related_fields, $depth, $flatten, ( $current_depth + 1 ) );
|
| 4264 |
+
}
|
| 4265 |
+
}
|
| 4266 |
+
|
| 4267 |
+
if ( $flatten && !empty( $related_data ) )
|
| 4268 |
+
$related_data = pods_serial_comma( array_values( $related_data ), array( 'and' => '', 'field_index' => $related_pod->pod_data[ 'field_index' ] ) );
|
| 4269 |
+
}
|
| 4270 |
+
}
|
| 4271 |
+
|
| 4272 |
+
$data[ $field[ 'name' ] ] = $related_data;
|
| 4273 |
+
}
|
| 4274 |
+
// Return data exactly as Pods does normally
|
| 4275 |
+
else
|
| 4276 |
+
$data[ $field[ 'name' ] ] = $pod->field( array( 'name' => $field[ 'name' ], 'output' => 'arrays' ) );
|
| 4277 |
+
|
| 4278 |
+
if ( $flatten && is_array( $data[ $field[ 'name' ] ] ) )
|
| 4279 |
+
$data[ $field[ 'name' ] ] = pods_serial_comma( $data[ $field[ 'name' ] ], array( 'field' => $field[ 'name' ], 'fields' => $export_fields, 'and' => '' ) );
|
| 4280 |
+
}
|
| 4281 |
+
|
| 4282 |
+
$data[ 'id' ] = (int) $pod->id();
|
| 4283 |
+
return $data;
|
| 4284 |
+
}
|
| 4285 |
+
|
| 4286 |
+
/**
|
| 4287 |
+
* Reorder a Pod
|
| 4288 |
+
*
|
| 4289 |
+
* $params['pod'] string The Pod name
|
| 4290 |
+
* $params['field'] string The field name of the field to reorder
|
| 4291 |
+
* $params['order'] array The key => value array of items to reorder (key should be an integer)
|
| 4292 |
+
*
|
| 4293 |
+
* @param array $params An associative array of parameters
|
| 4294 |
+
*
|
| 4295 |
+
* @return bool
|
| 4296 |
+
*
|
| 4297 |
+
* @since 1.9.0
|
| 4298 |
+
*/
|
| 4299 |
+
public function reorder_pod_item ( $params ) {
|
| 4300 |
+
$params = (object) pods_sanitize( $params );
|
| 4301 |
+
|
| 4302 |
+
// @deprecated 2.0
|
| 4303 |
+
if ( isset( $params->datatype ) ) {
|
| 4304 |
+
pods_deprecated( __( '$params->pod instead of $params->datatype', 'pods' ), '2.0' );
|
| 4305 |
+
|
| 4306 |
+
$params->pod = $params->datatype;
|
| 4307 |
+
|
| 4308 |
+
unset( $params->datatype );
|
| 4309 |
+
}
|
| 4310 |
+
|
| 4311 |
+
if ( null === pods_var_raw( 'pod', $params, null, null, true ) )
|
| 4312 |
+
return pods_error( __( '$params->pod is required', 'pods' ), $this );
|
| 4313 |
+
|
| 4314 |
+
if ( !is_array( $params->order ) )
|
| 4315 |
+
$params->order = explode( ',', $params->order );
|
| 4316 |
+
|
| 4317 |
+
$pod = $this->load_pod( array( 'name' => $params->pod, 'table_info' => true ) );
|
| 4318 |
+
|
| 4319 |
+
$params->name = $pod[ 'name' ];
|
| 4320 |
+
|
| 4321 |
+
if ( false === $pod )
|
| 4322 |
+
return pods_error( __( 'Pod is required', 'pods' ), $this );
|
| 4323 |
+
|
| 4324 |
+
foreach ( $params->order as $order => $id ) {
|
| 4325 |
+
if ( isset( $pod[ 'fields' ][ $params->field ] ) || isset( $pod[ 'object_fields' ][ $params->field ] ) ) {
|
| 4326 |
+
if ( 'table' == $pod[ 'storage' ] && ( !pods_tableless() ) ) {
|
| 4327 |
+
if ( isset( $pod[ 'fields' ][ $params->field ] ) )
|
| 4328 |
+
pods_query( "UPDATE `@wp_pods_{$params->name}` SET `{$params->field}` = " . pods_absint( $order ) . " WHERE `id` = " . pods_absint( $id ) . " LIMIT 1" );
|
| 4329 |
+
else
|
| 4330 |
+
pods_query( "UPDATE `{$pod['table']}` SET `{$params->field}` = " . pods_absint( $order ) . " WHERE `{$pod['field_id']}` = " . pods_absint( $id ) . " LIMIT 1" );
|
| 4331 |
+
}
|
| 4332 |
+
else
|
| 4333 |
+
$this->save_pod_item( array( 'pod' => $params->pod, 'pod_id' => $params->pod_id, 'id' => $id, 'data' => array( $params->field => pods_absint( $order ) ) ) );
|
| 4334 |
+
}
|
| 4335 |
+
}
|
| 4336 |
+
|
| 4337 |
+
return true;
|
| 4338 |
+
}
|
| 4339 |
+
|
| 4340 |
+
/**
|
| 4341 |
+
*
|
| 4342 |
+
* Delete all content for a Pod
|
| 4343 |
+
*
|
| 4344 |
+
* $params['id'] int The Pod ID
|
| 4345 |
+
* $params['name'] string The Pod name
|
| 4346 |
+
*
|
| 4347 |
+
* @param array $params An associative array of parameters
|
| 4348 |
+
* @param array $pod Pod data
|
| 4349 |
+
*
|
| 4350 |
+
* @return bool
|
| 4351 |
+
*
|
| 4352 |
+
* @uses pods_query
|
| 4353 |
+
* @uses pods_cache_clear
|
| 4354 |
+
*
|
| 4355 |
+
* @since 1.9.0
|
| 4356 |
+
*/
|
| 4357 |
+
public function reset_pod ( $params, $pod = false ) {
|
| 4358 |
+
$params = (object) pods_sanitize( $params );
|
| 4359 |
+
|
| 4360 |
+
$params->table_info = true;
|
| 4361 |
+
|
| 4362 |
+
if ( empty( $pod ) )
|
| 4363 |
+
$pod = $this->load_pod( $params );
|
| 4364 |
+
|
| 4365 |
+
if ( false === $pod )
|
| 4366 |
+
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
| 4367 |
+
|
| 4368 |
+
$params->id = $pod[ 'id' ];
|
| 4369 |
+
$params->name = $pod[ 'name' ];
|
| 4370 |
+
|
| 4371 |
+
if ( !pods_tableless() ) {
|
| 4372 |
+
if ( 'table' == $pod[ 'storage' ] ) {
|
| 4373 |
+
try {
|
| 4374 |
+
pods_query( "TRUNCATE `@wp_pods_{$params->name}`", false );
|
| 4375 |
+
}
|
| 4376 |
+
catch ( Exception $e ) {
|
| 4377 |
+
// Allow pod to be reset if the table doesn't exist
|
| 4378 |
+
if ( false === strpos( $e->getMessage(), 'Unknown table' ) )
|
| 4379 |
+
return pods_error( $e->getMessage(), $this );
|
| 4380 |
+
}
|
| 4381 |
+
}
|
| 4382 |
+
|
| 4383 |
+
pods_query( "DELETE FROM `@wp_podsrel` WHERE `pod_id` = {$params->id} OR `related_pod_id` = {$params->id}", false );
|
| 4384 |
+
}
|
| 4385 |
+
|
| 4386 |
+
// @todo Delete relationships from tableless relationships
|
| 4387 |
+
|
| 4388 |
+
// Delete all posts/revisions from this post type
|
| 4389 |
+
if ( in_array( $pod[ 'type' ], array( 'post_type', 'media' ) ) ) {
|
| 4390 |
+
$type = pods_var( 'object', $pod, $pod[ 'name' ], null, true );
|
| 4391 |
+
|
| 4392 |
+
$sql = "
|
| 4393 |
+
DELETE `t`, `r`, `m`
|
| 4394 |
+
FROM `{$pod['table']}` AS `t`
|
| 4395 |
+
LEFT JOIN `{$pod['meta_table']}` AS `m`
|
| 4396 |
+
ON `m`.`{$pod['meta_field_id']}` = `t`.`{$pod['field_id']}`
|
| 4397 |
+
LEFT JOIN `{$pod['table']}` AS `r`
|
| 4398 |
+
ON `r`.`post_parent` = `t`.`{$pod['field_id']}` AND `r`.`post_status` = 'inherit'
|
| 4399 |
+
WHERE `t`.`{$pod['field_type']}` = '{$type}'
|
| 4400 |
+
";
|
| 4401 |
+
|
| 4402 |
+
pods_query( $sql, false );
|
| 4403 |
+
}
|
| 4404 |
+
// Delete all terms from this taxonomy
|
| 4405 |
+
elseif ( 'taxonomy' == $pod[ 'type' ] ) {
|
| 4406 |
+
$type = pods_var( 'object', $pod, $pod[ 'name' ], null, true );
|
| 4407 |
+
|
| 4408 |
+
$sql = "
|
| 4409 |
+
DELETE FROM `{$pod['table']}` AS `t`
|
| 4410 |
+
" . $pod['join']['tt'] . "
|
| 4411 |
+
WHERE " . implode( ' AND ', $pod['where'] ) . "
|
| 4412 |
+
";
|
| 4413 |
+
|
| 4414 |
+
pods_query( $sql, false );
|
| 4415 |
+
}
|
| 4416 |
+
// Delete all users except the current one
|
| 4417 |
+
elseif ( 'user' == $pod[ 'type' ] ) {
|
| 4418 |
+
$sql = "
|
| 4419 |
+
DELETE `t`, `m`
|
| 4420 |
+
FROM `{$pod['table']}` AS `t`
|
| 4421 |
+
LEFT JOIN `{$pod['meta_table']}` AS `m`
|
| 4422 |
+
ON `m`.`{$pod['meta_field_id']}` = `t`.`{$pod['field_id']}`
|
| 4423 |
+
WHERE `t`.`{$pod['field_id']}` != " . (int) get_current_user_id() . "
|
| 4424 |
+
";
|
| 4425 |
+
|
| 4426 |
+
pods_query( $sql, false );
|
| 4427 |
+
}
|
| 4428 |
+
// Delete all comments
|
| 4429 |
+
elseif ( 'comment' == $pod[ 'type' ] ) {
|
| 4430 |
+
$type = pods_var( 'object', $pod, $pod[ 'name' ], null, true );
|
| 4431 |
+
|
| 4432 |
+
$sql = "
|
| 4433 |
+
DELETE `t`, `m`
|
| 4434 |
+
FROM `{$pod['table']}` AS `t`
|
| 4435 |
+
LEFT JOIN `{$pod['meta_table']}` AS `m`
|
| 4436 |
+
ON `m`.`{$pod['meta_field_id']}` = `t`.`{$pod['field_id']}`
|
| 4437 |
+
WHERE `t`.`{$pod['field_type']}` = '{$type}'
|
| 4438 |
+
";
|
| 4439 |
+
|
| 4440 |
+
pods_query( $sql, false );
|
| 4441 |
+
}
|
| 4442 |
+
|
| 4443 |
+
pods_cache_clear( true ); // only way to reliably clear out cached data across an entire group
|
| 4444 |
+
|
| 4445 |
+
return true;
|
| 4446 |
+
}
|
| 4447 |
+
|
| 4448 |
+
/**
|
| 4449 |
+
* Delete a Pod and all its content
|
| 4450 |
+
*
|
| 4451 |
+
* $params['id'] int The Pod ID
|
| 4452 |
+
* $params['name'] string The Pod name
|
| 4453 |
+
*
|
| 4454 |
+
* @param array $params An associative array of parameters
|
| 4455 |
+
* @param bool $strict (optional) Makes sure a pod exists, if it doesn't throws an error
|
| 4456 |
+
* @param bool $delete_all (optional) Whether to delete all content from a WP object
|
| 4457 |
+
*
|
| 4458 |
+
* @uses PodsAPI::load_pod
|
| 4459 |
+
* @uses wp_delete_post
|
| 4460 |
+
* @uses pods_query
|
| 4461 |
+
*
|
| 4462 |
+
* @return bool
|
| 4463 |
+
* @since 1.7.9
|
| 4464 |
+
*/
|
| 4465 |
+
public function delete_pod ( $params, $strict = false, $delete_all = false ) {
|
| 4466 |
+
/**
|
| 4467 |
+
* @var $wpdb wpdb
|
| 4468 |
+
*/
|
| 4469 |
+
global $wpdb;
|
| 4470 |
+
|
| 4471 |
+
if ( !is_object( $params ) && !is_array( $params ) ) {
|
| 4472 |
+
if ( is_numeric( $params ) )
|
| 4473 |
+
$params = array( 'id' => $params );
|
| 4474 |
+
else
|
| 4475 |
+
$params = array( 'name' => $params );
|
| 4476 |
+
|
| 4477 |
+
$params = (object) pods_sanitize( $params );
|
| 4478 |
+
}
|
| 4479 |
+
else
|
| 4480 |
+
$params = (object) pods_sanitize( $params );
|
| 4481 |
+
|
| 4482 |
+
$params->table_info = false;
|
| 4483 |
+
|
| 4484 |
+
$pod = $this->load_pod( $params, $strict );
|
| 4485 |
+
|
| 4486 |
+
if ( empty( $pod ) ) {
|
| 4487 |
+
if ( false !== $strict )
|
| 4488 |
+
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
| 4489 |
+
|
| 4490 |
+
return false;
|
| 4491 |
+
}
|
| 4492 |
+
|
| 4493 |
+
$params->id = (int) $pod[ 'id' ];
|
| 4494 |
+
$params->name = $pod[ 'name' ];
|
| 4495 |
+
|
| 4496 |
+
foreach ( $pod[ 'fields' ] as $field ) {
|
| 4497 |
+
$field[ 'pod' ] = $pod;
|
| 4498 |
+
|
| 4499 |
+
$this->delete_field( $field, false );
|
| 4500 |
+
}
|
| 4501 |
+
|
| 4502 |
+
// Only delete the post once the fields are taken care of, it's not required anymore
|
| 4503 |
+
$success = wp_delete_post( $params->id );
|
| 4504 |
+
|
| 4505 |
+
if ( !$success )
|
| 4506 |
+
return pods_error( __( 'Pod unable to be deleted', 'pods' ), $this );
|
| 4507 |
+
|
| 4508 |
+
// Reset content
|
| 4509 |
+
if ( $delete_all )
|
| 4510 |
+
$this->reset_pod( $params, $pod );
|
| 4511 |
+
|
| 4512 |
+
if ( !pods_tableless() ) {
|
| 4513 |
+
if ( 'table' == $pod[ 'storage' ] ) {
|
| 4514 |
+
try {
|
| 4515 |
+
pods_query( "DROP TABLE IF EXISTS `@wp_pods_{$params->name}`", false );
|
| 4516 |
+
}
|
| 4517 |
+
catch ( Exception $e ) {
|
| 4518 |
+
// Allow pod to be deleted if the table doesn't exist
|
| 4519 |
+
if ( false === strpos( $e->getMessage(), 'Unknown table' ) )
|
| 4520 |
+
return pods_error( $e->getMessage(), $this );
|
| 4521 |
+
}
|
| 4522 |
+
}
|
| 4523 |
+
|
| 4524 |
+
pods_query( "DELETE FROM `@wp_podsrel` WHERE `pod_id` = {$params->id} OR `related_pod_id` = {$params->id}", false );
|
| 4525 |
+
}
|
| 4526 |
+
|
| 4527 |
+
// @todo Delete relationships from tableless relationships
|
| 4528 |
+
|
| 4529 |
+
// Delete any relationship references
|
| 4530 |
+
$sql = "
|
| 4531 |
+
DELETE `pm`
|
| 4532 |
+
FROM `{$wpdb->postmeta}` AS `pm`
|
| 4533 |
+
LEFT JOIN `{$wpdb->posts}` AS `p`
|
| 4534 |
+
ON `p`.`post_type` = '_pods_field'
|
| 4535 |
+
AND `p`.`ID` = `pm`.`post_id`
|
| 4536 |
+
LEFT JOIN `{$wpdb->postmeta}` AS `pm2`
|
| 4537 |
+
ON `pm2`.`meta_key` = 'pick_object'
|
| 4538 |
+
AND `pm2`.`meta_value` = 'pod'
|
| 4539 |
+
AND `pm2`.`post_id` = `pm`.`post_id`
|
| 4540 |
+
WHERE
|
| 4541 |
+
`p`.`ID` IS NOT NULL
|
| 4542 |
+
AND `pm2`.`meta_id` IS NOT NULL
|
| 4543 |
+
AND `pm`.`meta_key` = 'pick_val'
|
| 4544 |
+
AND `pm`.`meta_value` = '{$params->name}'
|
| 4545 |
+
";
|
| 4546 |
+
|
| 4547 |
+
pods_query( $sql );
|
| 4548 |
+
|
| 4549 |
+
$this->cache_flush_pods( $pod );
|
| 4550 |
+
|
| 4551 |
+
return true;
|
| 4552 |
+
}
|
| 4553 |
+
|
| 4554 |
+
/**
|
| 4555 |
+
* Drop a field within a Pod
|
| 4556 |
+
*
|
| 4557 |
+
* $params['id'] int The field ID
|
| 4558 |
+
* $params['name'] int The field name
|
| 4559 |
+
* $params['pod'] string The Pod name
|
| 4560 |
+
* $params['pod_id'] string The Pod name
|
| 4561 |
+
*
|
| 4562 |
+
* @param array $params An associative array of parameters
|
| 4563 |
+
* @param bool $table_operation Whether or not to handle table operations
|
| 4564 |
+
*
|
| 4565 |
+
* @uses PodsAPI::load_field
|
| 4566 |
+
* @uses wp_delete_post
|
| 4567 |
+
* @uses pods_query
|
| 4568 |
+
*
|
| 4569 |
+
* @return bool
|
| 4570 |
+
* @since 1.7.9
|
| 4571 |
+
*/
|
| 4572 |
+
public function delete_field ( $params, $table_operation = true ) {
|
| 4573 |
+
/**
|
| 4574 |
+
* @var $wpdb wpdb
|
| 4575 |
+
*/
|
| 4576 |
+
global $wpdb;
|
| 4577 |
+
|
| 4578 |
+
$tableless_field_types = PodsForm::tableless_field_types();
|
| 4579 |
+
$simple_tableless_objects = PodsForm::simple_tableless_objects();
|
| 4580 |
+
|
| 4581 |
+
$params = (object) pods_sanitize( $params );
|
| 4582 |
+
|
| 4583 |
+
if ( !isset( $params->pod ) )
|
| 4584 |
+
$params->pod = '';
|
| 4585 |
+
|
| 4586 |
+
if ( !isset( $params->pod_id ) )
|
| 4587 |
+
$params->pod_id = 0;
|
| 4588 |
+
|
| 4589 |
+
$pod = $params->pod;
|
| 4590 |
+
|
| 4591 |
+
$save_pod = false;
|
| 4592 |
+
|
| 4593 |
+
if ( !is_array( $pod ) )
|
| 4594 |
+
$pod = $this->load_pod( array( 'name' => $pod, 'id' => $params->pod_id, 'table_info' => false ) );
|
| 4595 |
+
else
|
| 4596 |
+
$save_pod = true;
|
| 4597 |
+
|
| 4598 |
+
if ( empty( $pod ) )
|
| 4599 |
+
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
| 4600 |
+
|
| 4601 |
+
$params->pod_id = $pod[ 'id' ];
|
| 4602 |
+
$params->pod = $pod[ 'name' ];
|
| 4603 |
+
|
| 4604 |
+
if ( !isset( $params->name ) )
|
| 4605 |
+
$params->name = '';
|
| 4606 |
+
|
| 4607 |
+
if ( !isset( $params->id ) )
|
| 4608 |
+
$params->id = 0;
|
| 4609 |
+
|
| 4610 |
+
$field = $this->load_field( array( 'name' => $params->name, 'id' => $params->id, 'pod' => $params->pod, 'pod_id' => $params->pod_id ) );
|
| 4611 |
+
|
| 4612 |
+
if ( false === $field )
|
| 4613 |
+
return pods_error( __( 'Field not found', 'pods' ), $this );
|
| 4614 |
+
|
| 4615 |
+
$params->id = $field[ 'id' ];
|
| 4616 |
+
$params->name = $field[ 'name' ];
|
| 4617 |
+
|
| 4618 |
+
$simple = ( 'pick' == $field[ 'type' ] && in_array( pods_var( 'pick_object', $field ), $simple_tableless_objects ) );
|
| 4619 |
+
$simple = (boolean) $this->do_hook( 'tableless_custom', $simple, $field, $pod, $params );
|
| 4620 |
+
|
| 4621 |
+
if ( $table_operation && 'table' == $pod[ 'storage' ] && ( !in_array( $field[ 'type' ], $tableless_field_types ) || $simple ) )
|
| 4622 |
+
pods_query( "ALTER TABLE `@wp_pods_{$params->pod}` DROP COLUMN `{$params->name}`", false );
|
| 4623 |
+
|
| 4624 |
+
$success = wp_delete_post( $params->id );
|
| 4625 |
+
|
| 4626 |
+
if ( !$success )
|
| 4627 |
+
return pods_error( __( 'Field unable to be deleted', 'pods' ), $this );
|
| 4628 |
+
|
| 4629 |
+
$wpdb->query( $wpdb->prepare( "DELETE pm FROM {$wpdb->postmeta} AS pm
|
| 4630 |
+
LEFT JOIN {$wpdb->posts} AS p
|
| 4631 |
+
ON p.post_type = '_pods_field' AND p.ID = pm.post_id
|
| 4632 |
+
WHERE p.ID IS NOT NULL AND pm.meta_key = 'sister_id' AND pm.meta_value = %d", $params->id ) );
|
| 4633 |
+
|
| 4634 |
+
if ( ( !pods_tableless() ) && $table_operation ) {
|
| 4635 |
+
pods_query( "DELETE FROM `@wp_podsrel` WHERE (`pod_id` = {$params->pod_id} AND `field_id` = {$params->id}) OR (`related_pod_id` = {$params->pod_id} AND `related_field_id` = {$params->id})", false );
|
| 4636 |
+
}
|
| 4637 |
+
|
| 4638 |
+
// @todo Delete tableless relationship meta
|
| 4639 |
+
|
| 4640 |
+
if ( true === $save_pod )
|
| 4641 |
+
$this->cache_flush_pods( $pod );
|
| 4642 |
+
|
| 4643 |
+
return true;
|
| 4644 |
+
}
|
| 4645 |
+
|
| 4646 |
+
/**
|
| 4647 |
+
* Drop a Pod Object
|
| 4648 |
+
*
|
| 4649 |
+
* $params['id'] int The object ID
|
| 4650 |
+
* $params['name'] string The object name
|
| 4651 |
+
* $params['type'] string The object type
|
| 4652 |
+
*
|
| 4653 |
+
* @param array|object $params An associative array of parameters
|
| 4654 |
+
*
|
| 4655 |
+
* @uses wp_delete_post
|
| 4656 |
+
*
|
| 4657 |
+
* @return bool
|
| 4658 |
+
* @since 2.0
|
| 4659 |
+
*/
|
| 4660 |
+
public function delete_object ( $params ) {
|
| 4661 |
+
$params = (object) $params;
|
| 4662 |
+
$object = $this->load_object( $params );
|
| 4663 |
+
|
| 4664 |
+
if ( empty( $object ) )
|
| 4665 |
+
return pods_error( sprintf( __( "%s Object not found", 'pods' ), ucwords( $params->type ) ), $this );
|
| 4666 |
+
|
| 4667 |
+
$success = wp_delete_post( $params->id );
|
| 4668 |
+
|
| 4669 |
+
if ( !$success )
|
| 4670 |
+
return pods_error( sprintf( __( "%s Object not deleted", 'pods' ), ucwords( $params->type ) ), $this );
|
| 4671 |
+
|
| 4672 |
+
pods_transient_clear( 'pods_objects_' . $params->type );
|
| 4673 |
+
|
| 4674 |
+
return true;
|
| 4675 |
+
}
|
| 4676 |
+
|
| 4677 |
+
/**
|
| 4678 |
+
* @see PodsAPI::delete_object
|
| 4679 |
+
*
|
| 4680 |
+
* Drop a Pod Template
|
| 4681 |
+
*
|
| 4682 |
+
* $params['id'] int The template ID
|
| 4683 |
+
* $params['name'] string The template name
|
| 4684 |
+
*
|
| 4685 |
+
* @param array $params An associative array of parameters
|
| 4686 |
+
*
|
| 4687 |
+
* @return bool
|
| 4688 |
+
* @since 1.7.9
|
| 4689 |
+
*/
|
| 4690 |
+
public function delete_template ( $params ) {
|
| 4691 |
+
$params = (object) $params;
|
| 4692 |
+
$params->type = 'template';
|
| 4693 |
+
return $this->delete_object( $params );
|
| 4694 |
+
}
|
| 4695 |
+
|
| 4696 |
+
/**
|
| 4697 |
+
* @see PodsAPI::delete_object
|
| 4698 |
+
*
|
| 4699 |
+
* Drop a Pod Page
|
| 4700 |
+
*
|
| 4701 |
+
* $params['id'] int The page ID
|
| 4702 |
+
* $params['uri'] string The page URI
|
| 4703 |
+
*
|
| 4704 |
+
* @param array $params An associative array of parameters
|
| 4705 |
+
*
|
| 4706 |
+
* @return bool
|
| 4707 |
+
* @since 1.7.9
|
| 4708 |
+
*/
|
| 4709 |
+
public function delete_page ( $params ) {
|
| 4710 |
+
$params = (object) $params;
|
| 4711 |
+
if ( isset( $params->uri ) ) {
|
| 4712 |
+
$params->name = $params->uri;
|
| 4713 |
+
unset( $params->uri );
|
| 4714 |
+
}
|
| 4715 |
+
if ( isset( $params->name ) )
|
| 4716 |
+
$params->name = trim( $params->name, '/' );
|
| 4717 |
+
$params->type = 'page';
|
| 4718 |
+
return $this->delete_object( $params );
|
| 4719 |
+
}
|
| 4720 |
+
|
| 4721 |
+
/**
|
| 4722 |
+
* @see PodsAPI::delete_object
|
| 4723 |
+
*
|
| 4724 |
+
* Drop a Pod Helper
|
| 4725 |
+
*
|
| 4726 |
+
* $params['id'] int The helper ID
|
| 4727 |
+
* $params['name'] string The helper name
|
| 4728 |
+
*
|
| 4729 |
+
* @param array $params An associative array of parameters
|
| 4730 |
+
*
|
| 4731 |
+
* @return bool
|
| 4732 |
+
* @since 1.7.9
|
| 4733 |
+
*/
|
| 4734 |
+
public function delete_helper ( $params ) {
|
| 4735 |
+
$params = (object) $params;
|
| 4736 |
+
$params->type = 'helper';
|
| 4737 |
+
return $this->delete_object( $params );
|
| 4738 |
+
}
|
| 4739 |
+
|
| 4740 |
+
/**
|
| 4741 |
+
* Drop a single pod item
|
| 4742 |
+
*
|
| 4743 |
+
* $params['id'] int (optional) The item's ID from the wp_pod_* table (used with datatype parameter)
|
| 4744 |
+
* $params['pod'] string (optional) The Pod name (used with id parameter)
|
| 4745 |
+
* $params['pod_id'] int (optional) The Pod ID (used with id parameter)
|
| 4746 |
+
* $params['bypass_helpers'] bool Set to true to bypass running pre-save and post-save helpers
|
| 4747 |
+
*
|
| 4748 |
+
* @param array $params An associative array of parameters
|
| 4749 |
+
* @param bool $wp Whether to run WP object delete action
|
| 4750 |
+
*
|
| 4751 |
+
* @return bool
|
| 4752 |
+
* @since 1.7.9
|
| 4753 |
+
*/
|
| 4754 |
+
public function delete_pod_item ( $params, $wp = true ) {
|
| 4755 |
+
$params = (object) pods_sanitize( $params );
|
| 4756 |
+
|
| 4757 |
+
// @deprecated 2.0
|
| 4758 |
+
if ( isset( $params->datatype_id ) || isset( $params->datatype ) || isset( $params->tbl_row_id ) ) {
|
| 4759 |
+
if ( isset( $params->tbl_row_id ) ) {
|
| 4760 |
+
pods_deprecated( __( '$params->id instead of $params->tbl_row_id', 'pods' ), '2.0' );
|
| 4761 |
+
$params->id = $params->tbl_row_id;
|
| 4762 |
+
unset( $params->tbl_row_id );
|
| 4763 |
+
}
|
| 4764 |
+
|
| 4765 |
+
if ( isset( $params->pod_id ) ) {
|
| 4766 |
+
pods_deprecated( __( '$params->id instead of $params->pod_id', 'pods' ), '2.0' );
|
| 4767 |
+
$params->id = $params->pod_id;
|
| 4768 |
+
unset( $params->pod_id );
|
| 4769 |
+
}
|
| 4770 |
+
|
| 4771 |
+
if ( isset( $params->dataype_id ) ) {
|
| 4772 |
+
pods_deprecated( __( '$params->pod_id instead of $params->datatype_id', 'pods' ), '2.0' );
|
| 4773 |
+
$params->pod_id = $params->dataype_id;
|
| 4774 |
+
unset( $params->dataype_id );
|
| 4775 |
+
}
|
| 4776 |
+
|
| 4777 |
+
if ( isset( $params->datatype ) ) {
|
| 4778 |
+
pods_deprecated( __( '$params->pod instead of $params->datatype', 'pods' ), '2.0' );
|
| 4779 |
+
$params->pod = $params->datatype;
|
| 4780 |
+
unset( $params->datatype );
|
| 4781 |
+
}
|
| 4782 |
+
}
|
| 4783 |
+
|
| 4784 |
+
if ( !isset( $params->id ) )
|
| 4785 |
+
return pods_error( __( 'Pod Item not found', 'pods' ), $this );
|
| 4786 |
+
|
| 4787 |
+
$params->id = pods_absint( $params->id );
|
| 4788 |
+
|
| 4789 |
+
if ( !isset( $params->pod ) )
|
| 4790 |
+
$params->pod = '';
|
| 4791 |
+
|
| 4792 |
+
if ( !isset( $params->pod_id ) )
|
| 4793 |
+
$params->pod_id = 0;
|
| 4794 |
+
|
| 4795 |
+
$pod = $this->load_pod( array( 'name' => $params->pod, 'id' => $params->pod_id, 'table_info' => false ) );
|
| 4796 |
+
|
| 4797 |
+
if ( false === $pod )
|
| 4798 |
+
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
| 4799 |
+
|
| 4800 |
+
$params->pod_id = $pod[ 'id' ];
|
| 4801 |
+
$params->pod = $pod[ 'name' ];
|
| 4802 |
+
|
| 4803 |
+
// Allow Helpers to bypass subsequent helpers in recursive delete_pod_item calls
|
| 4804 |
+
$bypass_helpers = false;
|
| 4805 |
+
|
| 4806 |
+
if ( isset( $params->bypass_helpers ) && false !== $params->bypass_helpers )
|
| 4807 |
+
$bypass_helpers = true;
|
| 4808 |
+
|
| 4809 |
+
$pre_delete_helpers = $post_delete_helpers = array();
|
| 4810 |
+
|
| 4811 |
+
if ( false === $bypass_helpers ) {
|
| 4812 |
+
// Plugin hook
|
| 4813 |
+
$this->do_hook( 'pre_delete_pod_item', $params, $pod );
|
| 4814 |
+
$this->do_hook( "pre_delete_pod_item_{$params->pod}", $params, $pod );
|
| 4815 |
+
|
| 4816 |
+
// Call any pre-save helpers (if not bypassed)
|
| 4817 |
+
if ( !defined( 'PODS_DISABLE_EVAL' ) || !PODS_DISABLE_EVAL ) {
|
| 4818 |
+
if ( !empty( $pod[ 'options' ] ) && is_array( $pod[ 'options' ] ) ) {
|
| 4819 |
+
$helpers = array( 'pre_delete_helpers', 'post_delete_helpers' );
|
| 4820 |
+
|
| 4821 |
+
foreach ( $helpers as $helper ) {
|
| 4822 |
+
if ( isset( $pod[ 'options' ][ $helper ] ) && !empty( $pod[ 'options' ][ $helper ] ) )
|
| 4823 |
+
${$helper} = explode( ',', $pod[ 'options' ][ $helper ] );
|
| 4824 |
+
}
|
| 4825 |
+
}
|
| 4826 |
+
|
| 4827 |
+
if ( !empty( $pre_delete_helpers ) ) {
|
| 4828 |
+
pods_deprecated( sprintf( __( 'Pre-delete helpers are deprecated, use the action pods_pre_delete_pod_item_%s instead', 'pods' ), $params->pod ), '2.0' );
|
| 4829 |
+
|
| 4830 |
+
foreach ( $pre_delete_helpers as $helper ) {
|
| 4831 |
+
$helper = $this->load_helper( array( 'name' => $helper ) );
|
| 4832 |
+
|
| 4833 |
+
if ( false !== $helper )
|
| 4834 |
+
eval( '?>' . $helper[ 'code' ] );
|
| 4835 |
+
}
|
| 4836 |
+
}
|
| 4837 |
+
}
|
| 4838 |
+
}
|
| 4839 |
+
|
| 4840 |
+
// Delete object from relationship fields
|
| 4841 |
+
$this->delete_object_from_relationships( $params->id, $pod );
|
| 4842 |
+
|
| 4843 |
+
if ( 'table' == $pod[ 'storage' ] )
|
| 4844 |
+
pods_query( "DELETE FROM `@wp_pods_{$params->pod}` WHERE `id` = {$params->id} LIMIT 1" );
|
| 4845 |
+
|
| 4846 |
+
if ( $wp && 'taxonomy' == $pod[ 'type' ] ) {
|
| 4847 |
+
$taxonomy = $pod[ 'name' ];
|
| 4848 |
+
|
| 4849 |
+
if ( !empty( $pod[ 'object' ] ) )
|
| 4850 |
+
$taxonomy = $pod[ 'object' ];
|
| 4851 |
+
|
| 4852 |
+
wp_delete_term( $params->id, $taxonomy );
|
| 4853 |
+
}
|
| 4854 |
+
elseif ( $wp && !in_array( $pod[ 'type' ], array( 'pod', 'table', '', 'taxonomy' ) ) )
|
| 4855 |
+
$this->delete_wp_object( $pod[ 'type' ], $params->id );
|
| 4856 |
+
|
| 4857 |
+
if ( false === $bypass_helpers ) {
|
| 4858 |
+
// Plugin hook
|
| 4859 |
+
$this->do_hook( 'post_delete_pod_item', $params, $pod );
|
| 4860 |
+
$this->do_hook( "post_delete_pod_item_{$params->pod}", $params, $pod );
|
| 4861 |
+
|
| 4862 |
+
// Call any post-save helpers (if not bypassed)
|
| 4863 |
+
if ( !defined( 'PODS_DISABLE_EVAL' ) || !PODS_DISABLE_EVAL ) {
|
| 4864 |
+
if ( !empty( $post_delete_helpers ) ) {
|
| 4865 |
+
pods_deprecated( sprintf( __( 'Post-delete helpers are deprecated, use the action pods_post_delete_pod_item_%s instead', 'pods' ), $params->pod ), '2.0' );
|
| 4866 |
+
|
| 4867 |
+
foreach ( $post_delete_helpers as $helper ) {
|
| 4868 |
+
$helper = $this->load_helper( array( 'name' => $helper ) );
|
| 4869 |
+
|
| 4870 |
+
if ( false !== $helper )
|
| 4871 |
+
eval( '?>' . $helper[ 'code' ] );
|
| 4872 |
+
}
|
| 4873 |
+
}
|
| 4874 |
+
}
|
| 4875 |
+
}
|
| 4876 |
+
|
| 4877 |
+
pods_cache_clear( $params->id, 'pods_items_' . $params->pod );
|
| 4878 |
+
|
| 4879 |
+
return true;
|
| 4880 |
+
}
|
| 4881 |
+
|
| 4882 |
+
/**
|
| 4883 |
+
* Delete an object from tableless fields
|
| 4884 |
+
*
|
| 4885 |
+
* @param int $id
|
| 4886 |
+
* @param string $type
|
| 4887 |
+
* @param string $name
|
| 4888 |
+
*
|
| 4889 |
+
* @return bool
|
| 4890 |
+
*
|
| 4891 |
+
* @since 2.3
|
| 4892 |
+
*/
|
| 4893 |
+
public function delete_object_from_relationships ( $id, $object, $name = null ) {
|
| 4894 |
+
/**
|
| 4895 |
+
* @var $pods_init \PodsInit
|
| 4896 |
+
*/
|
| 4897 |
+
global $pods_init;
|
| 4898 |
+
|
| 4899 |
+
$pod = false;
|
| 4900 |
+
|
| 4901 |
+
// Run any bidirectional delete operations
|
| 4902 |
+
if ( is_array( $object ) )
|
| 4903 |
+
$pod = $object;
|
| 4904 |
+
elseif ( is_object( $pods_init ) )
|
| 4905 |
+
$pod = PodsInit::$meta->get_object( $object, $name );
|
| 4906 |
+
|
| 4907 |
+
if ( !empty( $pod ) ) {
|
| 4908 |
+
$object = $pod[ 'type' ];
|
| 4909 |
+
$name = $pod[ 'name' ];
|
| 4910 |
+
|
| 4911 |
+
foreach ( $pod[ 'fields' ] as $field ) {
|
| 4912 |
+
PodsForm::delete( $field[ 'type' ], $id, $field[ 'name' ], array_merge( $field, $field[ 'options' ] ), $pod );
|
| 4913 |
+
}
|
| 4914 |
+
}
|
| 4915 |
+
|
| 4916 |
+
// Lookup related fields (non-bidirectional)
|
| 4917 |
+
$params = array(
|
| 4918 |
+
'where' => array(
|
| 4919 |
+
array(
|
| 4920 |
+
'key' => 'type',
|
| 4921 |
+
'value' => 'pick'
|
| 4922 |
+
),
|
| 4923 |
+
array(
|
| 4924 |
+
'key' => 'pick_object',
|
| 4925 |
+
'value' => $object
|
| 4926 |
+
)
|
| 4927 |
+
)
|
| 4928 |
+
);
|
| 4929 |
+
|
| 4930 |
+
if ( !empty( $name ) && $name != $object ) {
|
| 4931 |
+
$params[ 'where' ][] = array(
|
| 4932 |
+
'key' => 'pick_val',
|
| 4933 |
+
'value' => $name
|
| 4934 |
+
);
|
| 4935 |
+
}
|
| 4936 |
+
|
| 4937 |
+
$fields = $this->load_fields( $params, false );
|
| 4938 |
+
|
| 4939 |
+
if ( !empty( $pod ) && 'media' == $pod[ 'type' ] ) {
|
| 4940 |
+
$params[ 'where' ] = array(
|
| 4941 |
+
array(
|
| 4942 |
+
'key' => 'type',
|
| 4943 |
+
'value' => 'file'
|
| 4944 |
+
)
|
| 4945 |
+
);
|
| 4946 |
+
|
| 4947 |
+
$fields = array_merge( $fields, $this->load_fields( $params, false ) );
|
| 4948 |
+
}
|
| 4949 |
+
|
| 4950 |
+
if ( is_array( $fields ) && !empty( $fields ) ) {
|
| 4951 |
+
foreach ( $fields as $related_field ) {
|
| 4952 |
+
$related_pod = $this->load_pod( array( 'id' => $related_field[ 'pod_id' ], 'fields' => false ), false );
|
| 4953 |
+
|
| 4954 |
+
if ( empty( $related_pod ) )
|
| 4955 |
+
continue;
|
| 4956 |
+
|
| 4957 |
+
$related_from = $this->lookup_related_items_from( $related_field[ 'id' ], $related_pod[ 'id' ], $id, $related_field, $related_pod );
|
| 4958 |
+
|
| 4959 |
+
$this->delete_relationships( $related_from, $id, $related_pod, $related_field );
|
| 4960 |
+
}
|
| 4961 |
+
}
|
| 4962 |
+
|
| 4963 |
+
if ( !empty( $pod ) && !pods_tableless() ) {
|
| 4964 |
+
pods_query( "
|
| 4965 |
+
DELETE FROM `@wp_podsrel`
|
| 4966 |
+
WHERE
|
| 4967 |
+
(
|
| 4968 |
+
`pod_id` = %d
|
| 4969 |
+
AND `item_id` = %d
|
| 4970 |
+
)
|
| 4971 |
+
OR (
|
| 4972 |
+
`related_pod_id` = %d
|
| 4973 |
+
AND `related_item_id` = %d
|
| 4974 |
+
)
|
| 4975 |
+
", array(
|
| 4976 |
+
$pod[ 'id' ],
|
| 4977 |
+
$id,
|
| 4978 |
+
|
| 4979 |
+
$pod[ 'id' ],
|
| 4980 |
+
$id
|
| 4981 |
+
) );
|
| 4982 |
+
}
|
| 4983 |
+
|
| 4984 |
+
return true;
|
| 4985 |
+
}
|
| 4986 |
+
|
| 4987 |
+
/**
|
| 4988 |
+
* Delete relationships
|
| 4989 |
+
*
|
| 4990 |
+
* @param int|array $related_id IDs for items to save
|
| 4991 |
+
* @param int|array $id ID or IDs to remove
|
| 4992 |
+
* @param array $related_pod Pod data
|
| 4993 |
+
* @param array $related_field Field data
|
| 4994 |
+
*
|
| 4995 |
+
* @return void
|
| 4996 |
+
*
|
| 4997 |
+
* @since 2.3
|
| 4998 |
+
*/
|
| 4999 |
+
public function delete_relationships ( $related_id, $id, $related_pod, $related_field ) {
|
| 5000 |
+
if ( is_array( $related_id ) ) {
|
| 5001 |
+
foreach ( $related_id as $rid ) {
|
| 5002 |
+
$this->delete_relationships( $rid, $id, $related_pod, $related_field );
|
| 5003 |
+
}
|
| 5004 |
+
|
| 5005 |
+
return;
|
| 5006 |
+
}
|
| 5007 |
+
|
| 5008 |
+
if ( is_array( $id ) ) {
|
| 5009 |
+
foreach ( $id as $rid ) {
|
| 5010 |
+
$this->delete_relationships( $related_id, $rid, $related_pod, $related_field );
|
| 5011 |
+
}
|
| 5012 |
+
|
| 5013 |
+
return;
|
| 5014 |
+
}
|
| 5015 |
+
|
| 5016 |
+
$id = (int) $id;
|
| 5017 |
+
|
| 5018 |
+
if ( empty( $id ) )
|
| 5019 |
+
return;
|
| 5020 |
+
|
| 5021 |
+
$related_ids = $this->lookup_related_items( $related_field[ 'id' ], $related_pod[ 'id' ], $related_id, $related_field, $related_pod );
|
| 5022 |
+
|
| 5023 |
+
if ( empty( $related_ids ) )
|
| 5024 |
+
return;
|
| 5025 |
+
elseif ( !in_array( $id, $related_ids ) )
|
| 5026 |
+
return;
|
| 5027 |
+
|
| 5028 |
+
if ( isset( self::$related_item_cache[ $related_pod[ 'id' ] ][ $related_field[ 'id' ] ] ) ) {
|
| 5029 |
+
// Delete relationship from cache
|
| 5030 |
+
unset( self::$related_item_cache[ $related_pod[ 'id' ] ][ $related_field[ 'id' ] ] );
|
| 5031 |
+
}
|
| 5032 |
+
unset( $related_ids[ array_search( $id, $related_ids ) ] );
|
| 5033 |
+
|
| 5034 |
+
$no_conflict = pods_no_conflict_check( $related_pod[ 'type' ] );
|
| 5035 |
+
|
| 5036 |
+
if ( !$no_conflict )
|
| 5037 |
+
pods_no_conflict_on( $related_pod[ 'type' ] );
|
| 5038 |
+
|
| 5039 |
+
// Post Types, Media, Users, and Comments (meta-based)
|
| 5040 |
+
if ( in_array( $related_pod[ 'type' ], array( 'post_type', 'media', 'user', 'comment' ) ) ) {
|
| 5041 |
+
$object_type = $related_pod[ 'type' ];
|
| 5042 |
+
|
| 5043 |
+
if ( 'post_type' == $object_type || 'media' == $object_type )
|
| 5044 |
+
$object_type = 'post';
|
| 5045 |
+
|
| 5046 |
+
delete_metadata( $object_type, $related_id, $related_field[ 'name' ] );
|
| 5047 |
+
|
| 5048 |
+
if ( !empty( $related_ids ) ) {
|
| 5049 |
+
update_metadata( $object_type, $related_id, '_pods_' . $related_field[ 'name' ], $related_ids );
|
| 5050 |
+
|
| 5051 |
+
foreach ( $related_ids as $rel_id ) {
|
| 5052 |
+
add_metadata( $object_type, $related_id, $related_field[ 'name' ], $rel_id );
|
| 5053 |
+
}
|
| 5054 |
+
}
|
| 5055 |
+
else
|
| 5056 |
+
delete_metadata( $object_type, $related_id, '_pods_' . $related_field[ 'name' ] );
|
| 5057 |
+
}
|
| 5058 |
+
// Custom Settings Pages (options-based)
|
| 5059 |
+
elseif ( 'settings' == $related_pod[ 'type' ] ) {
|
| 5060 |
+
if ( !empty( $related_ids ) )
|
| 5061 |
+
update_option( $related_pod[ 'name' ] . '_' . $related_field[ 'name' ], $related_ids );
|
| 5062 |
+
else
|
| 5063 |
+
delete_option( $related_pod[ 'name' ] . '_' . $related_field[ 'name' ] );
|
| 5064 |
+
}
|
| 5065 |
+
|
| 5066 |
+
// Relationships table
|
| 5067 |
+
if ( !pods_tableless() ) {
|
| 5068 |
+
pods_query( "
|
| 5069 |
+
DELETE FROM `@wp_podsrel`
|
| 5070 |
+
WHERE
|
| 5071 |
+
(
|
| 5072 |
+
`pod_id` = %d
|
| 5073 |
+
AND `field_id` = %d
|
| 5074 |
+
AND `item_id` = %d
|
| 5075 |
+
AND `related_item_id` = %d
|
| 5076 |
+
)
|
| 5077 |
+
OR (
|
| 5078 |
+
`related_pod_id` = %d
|
| 5079 |
+
AND `related_field_id` = %d
|
| 5080 |
+
AND `related_item_id` = %d
|
| 5081 |
+
AND `item_id` = %d
|
| 5082 |
+
)
|
| 5083 |
+
", array(
|
| 5084 |
+
$related_pod[ 'id' ],
|
| 5085 |
+
$related_field[ 'id' ],
|
| 5086 |
+
$related_id,
|
| 5087 |
+
$id,
|
| 5088 |
+
|
| 5089 |
+
$related_pod[ 'id' ],
|
| 5090 |
+
$related_field[ 'id' ],
|
| 5091 |
+
$related_id,
|
| 5092 |
+
$id
|
| 5093 |
+
) );
|
| 5094 |
+
}
|
| 5095 |
+
|
| 5096 |
+
if ( !$no_conflict )
|
| 5097 |
+
pods_no_conflict_off( $related_pod[ 'type' ] );
|
| 5098 |
+
}
|
| 5099 |
+
|
| 5100 |
+
/**
|
| 5101 |
+
* Check if a Pod exists
|
| 5102 |
+
*
|
| 5103 |
+
* $params['id'] int Pod ID
|
| 5104 |
+
* $params['name'] string Pod name
|
| 5105 |
+
*
|
| 5106 |
+
* @param array $params An associative array of parameters
|
| 5107 |
+
*
|
| 5108 |
+
* @return bool True if exists
|
| 5109 |
+
*
|
| 5110 |
+
* @since 1.12
|
| 5111 |
+
*/
|
| 5112 |
+
public function pod_exists ( $params, $type = null ) {
|
| 5113 |
+
if ( is_string( $params ) )
|
| 5114 |
+
$params = array( 'name' => $params );
|
| 5115 |
+
|
| 5116 |
+
$params = (object) pods_sanitize( $params );
|
| 5117 |
+
|
| 5118 |
+
if ( !empty( $params->id ) || !empty( $params->name ) ) {
|
| 5119 |
+
if ( !isset( $params->name ) )
|
| 5120 |
+
$pod = get_post( $dummy = (int) $params->id );
|
| 5121 |
+
else {
|
| 5122 |
+
$pod = get_posts( array(
|
| 5123 |
+
'name' => $params->name,
|
| 5124 |
+
'post_type' => '_pods_pod',
|
| 5125 |
+
'posts_per_page' => 1
|
| 5126 |
+
) );
|
| 5127 |
+
}
|
| 5128 |
+
|
| 5129 |
+
if ( !empty( $pod ) && ( empty( $type ) || $type == get_post_meta( $pod->ID, 'type', true ) ) )
|
| 5130 |
+
return true;
|
| 5131 |
+
}
|
| 5132 |
+
|
| 5133 |
+
return false;
|
| 5134 |
+
}
|
| 5135 |
+
|
| 5136 |
+
/**
|
| 5137 |
+
* Load a Pod and all of its fields
|
| 5138 |
+
*
|
| 5139 |
+
* $params['id'] int The Pod ID
|
| 5140 |
+
* $params['name'] string The Pod name
|
| 5141 |
+
* $params['fields'] bool Whether to load fields (default is true)
|
| 5142 |
+
*
|
| 5143 |
+
* @param array|object $params An associative array of parameters or pod name as a string
|
| 5144 |
+
* @param bool $strict Makes sure the pod exists, throws an error if it doesn't work
|
| 5145 |
+
*
|
| 5146 |
+
* @return array|bool|mixed|void
|
| 5147 |
+
* @since 1.7.9
|
| 5148 |
+
*/
|
| 5149 |
+
public function load_pod ( $params, $strict = true ) {
|
| 5150 |
+
|
| 5151 |
+
/**
|
| 5152 |
+
* @var $sitepress SitePress
|
| 5153 |
+
* @var $wpdb wpdb
|
| 5154 |
+
*/
|
| 5155 |
+
global $sitepress, $icl_adjust_id_url_filter_off, $wpdb;
|
| 5156 |
|
| 5157 |
+
$current_language = false;
|
| 5158 |
+
$load_fields = true;
|
|
|
|
|
|
|
|
|
|
| 5159 |
|
| 5160 |
+
// WPML support
|
| 5161 |
+
if ( is_object( $sitepress ) && !$icl_adjust_id_url_filter_off )
|
| 5162 |
+
$current_language = pods_sanitize( ICL_LANGUAGE_CODE );
|
| 5163 |
+
// Polylang support
|
| 5164 |
+
elseif ( function_exists( 'pll_current_language' ) )
|
| 5165 |
+
$current_language = pll_current_language( 'slug' );
|
| 5166 |
|
| 5167 |
+
if ( !is_array( $params ) && !is_object( $params ) )
|
| 5168 |
+
$params = array( 'name' => $params, 'table_info' => false, 'fields' => true );
|
|
|
|
|
|
|
|
|
|
| 5169 |
|
| 5170 |
+
if ( is_object( $params ) && isset( $params->fields ) && !$params->fields )
|
| 5171 |
+
$load_fields = false;
|
| 5172 |
+
elseif ( is_array( $params ) && isset( $params[ 'fields' ] ) && !$params[ 'fields' ] )
|
| 5173 |
+
$load_fields = false;
|
| 5174 |
|
| 5175 |
+
$table_info = false;
|
| 5176 |
|
| 5177 |
+
if ( is_object( $params ) && ! empty( $params->table_info ) )
|
| 5178 |
+
$table_info = true;
|
| 5179 |
+
elseif ( is_array( $params ) && ! empty( $params[ 'table_info' ] ) )
|
| 5180 |
+
$table_info = true;
|
| 5181 |
|
| 5182 |
+
$transient = 'pods_' . $wpdb->prefix . '_pod';
|
| 5183 |
|
| 5184 |
+
if ( !empty( $current_language ) )
|
| 5185 |
+
$transient .= '_' . $current_language;
|
|
|
|
| 5186 |
|
| 5187 |
+
if ( !$load_fields )
|
| 5188 |
+
$transient .= '_nofields';
|
|
|
|
| 5189 |
|
| 5190 |
+
if ( $table_info )
|
| 5191 |
+
$transient .= '_tableinfo';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5192 |
|
| 5193 |
+
if ( is_object( $params ) && isset( $params->post_name ) ) {
|
| 5194 |
+
$pod = false;
|
|
|
|
|
|
|
|
|
|
| 5195 |
|
| 5196 |
+
if ( pods_api_cache() )
|
| 5197 |
+
$pod = pods_transient_get( $transient . '_' . $params->post_name );
|
|
|
|
| 5198 |
|
| 5199 |
+
if ( false !== $pod && ( ! $table_info || isset( $pod[ 'table' ] ) ) ) {
|
| 5200 |
+
if ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) && is_object( $sitepress ) && !$icl_adjust_id_url_filter_off )
|
| 5201 |
+
$pod = array_merge( $pod, $this->get_table_info( $pod[ 'type' ], $pod[ 'object' ], $pod[ 'name' ], $pod ) );
|
| 5202 |
|
| 5203 |
+
return $pod;
|
| 5204 |
+
}
|
|
|
|
| 5205 |
|
| 5206 |
+
$_pod = get_object_vars( $params );
|
| 5207 |
+
}
|
| 5208 |
+
else {
|
| 5209 |
+
$params = (object) pods_sanitize( $params );
|
| 5210 |
|
| 5211 |
+
if ( ( !isset( $params->id ) || empty( $params->id ) ) && ( !isset( $params->name ) || empty( $params->name ) ) ) {
|
| 5212 |
+
if ( $strict )
|
| 5213 |
+
return pods_error( 'Either Pod ID or Name are required', $this );
|
| 5214 |
|
| 5215 |
+
return false;
|
| 5216 |
+
}
|
|
|
|
|
|
|
|
|
|
| 5217 |
|
| 5218 |
+
if ( isset( $params->name ) ) {
|
| 5219 |
+
$pod = false;
|
|
|
|
| 5220 |
|
| 5221 |
+
if ( '_pods_pod' == $params->name ) {
|
| 5222 |
+
$pod = array(
|
| 5223 |
+
'id' => 0,
|
| 5224 |
+
'name' => $params->name,
|
| 5225 |
+
'label' => __( 'Pods', 'pods' ),
|
| 5226 |
+
'type' => 'post_type',
|
| 5227 |
+
'storage' => 'meta',
|
| 5228 |
+
'options' => array(
|
| 5229 |
+
'label_singular' => __( 'Pod', 'pods' )
|
| 5230 |
+
),
|
| 5231 |
+
'fields' => array()
|
| 5232 |
+
);
|
| 5233 |
+
}
|
| 5234 |
+
elseif ( '_pods_field' == $params->name ) {
|
| 5235 |
+
$pod = array(
|
| 5236 |
+
'id' => 0,
|
| 5237 |
+
'name' => $params->name,
|
| 5238 |
+
'label' => __( 'Pod Fields', 'pods' ),
|
| 5239 |
+
'type' => 'post_type',
|
| 5240 |
+
'storage' => 'meta',
|
| 5241 |
+
'options' => array(
|
| 5242 |
+
'label_singular' => __( 'Pod Field', 'pods' )
|
| 5243 |
+
),
|
| 5244 |
+
'fields' => array()
|
| 5245 |
+
);
|
| 5246 |
+
}
|
| 5247 |
+
elseif ( pods_api_cache() )
|
| 5248 |
+
$pod = pods_transient_get( $transient . '_' . $params->name );
|
| 5249 |
|
| 5250 |
+
if ( false !== $pod && ( ! $table_info || isset( $pod[ 'table' ] ) ) ) {
|
| 5251 |
+
if ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) && is_object( $sitepress ) && !$icl_adjust_id_url_filter_off )
|
| 5252 |
+
$pod = array_merge( $pod, $this->get_table_info( $pod[ 'type' ], $pod[ 'object' ], $pod[ 'name' ], $pod ) );
|
| 5253 |
|
| 5254 |
+
return $pod;
|
| 5255 |
+
}
|
| 5256 |
+
}
|
| 5257 |
|
| 5258 |
+
if ( !isset( $params->name ) )
|
| 5259 |
+
$pod = get_post( $dummy = (int) $params->id );
|
| 5260 |
+
else {
|
| 5261 |
+
$pod = get_posts( array(
|
| 5262 |
+
'name' => $params->name,
|
| 5263 |
+
'post_type' => '_pods_pod',
|
| 5264 |
+
'posts_per_page' => 1
|
| 5265 |
+
) );
|
| 5266 |
+
}
|
| 5267 |
+
|
| 5268 |
+
if ( empty( $pod ) ) {
|
| 5269 |
+
if ( $strict )
|
| 5270 |
+
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
| 5271 |
|
| 5272 |
+
return false;
|
| 5273 |
+
}
|
| 5274 |
+
|
| 5275 |
+
if ( is_array( $pod ) )
|
| 5276 |
+
$pod = $pod[ 0 ];
|
| 5277 |
+
|
| 5278 |
+
$_pod = get_object_vars( $pod );
|
| 5279 |
+
}
|
| 5280 |
+
|
| 5281 |
+
$pod = false;
|
| 5282 |
+
|
| 5283 |
+
if ( pods_api_cache() )
|
| 5284 |
+
$pod = pods_transient_get( $transient . '_' . $_pod[ 'post_name' ] );
|
| 5285 |
+
|
| 5286 |
+
if ( false !== $pod && ( ! $table_info || isset( $pod[ 'table' ] ) ) ) {
|
| 5287 |
+
if ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) && is_object( $sitepress ) && !$icl_adjust_id_url_filter_off )
|
| 5288 |
+
$pod = array_merge( $pod, $this->get_table_info( $pod[ 'type' ], $pod[ 'object' ], $pod[ 'name' ], $pod ) );
|
| 5289 |
+
|
| 5290 |
+
return $pod;
|
| 5291 |
+
}
|
| 5292 |
+
|
| 5293 |
+
$pod = array(
|
| 5294 |
+
'id' => $_pod[ 'ID' ],
|
| 5295 |
+
'name' => $_pod[ 'post_name' ],
|
| 5296 |
+
'label' => $_pod[ 'post_title' ],
|
| 5297 |
+
'description' => $_pod[ 'post_content' ]
|
| 5298 |
+
);
|
| 5299 |
+
|
| 5300 |
+
if ( strlen( $pod[ 'label' ] ) < 1 )
|
| 5301 |
+
$pod[ 'label' ] = $pod[ 'name' ];
|
| 5302 |
+
|
| 5303 |
+
// @todo update with a method to put all options in
|
| 5304 |
+
$defaults = array(
|
| 5305 |
+
'show_in_menu' => 1,
|
| 5306 |
+
'type' => 'post_type',
|
| 5307 |
+
'storage' => 'meta',
|
| 5308 |
+
'object' => '',
|
| 5309 |
+
'alias' => ''
|
| 5310 |
+
);
|
| 5311 |
+
|
| 5312 |
+
$pod[ 'options' ] = get_post_meta( $pod[ 'id' ] );
|
| 5313 |
+
|
| 5314 |
+
foreach ( $pod[ 'options' ] as $option => $value ) {
|
| 5315 |
+
if ( is_array( $value ) ) {
|
| 5316 |
+
foreach ( $value as $k => $v ) {
|
| 5317 |
+
if ( !is_array( $v ) )
|
| 5318 |
+
$value[ $k ] = maybe_unserialize( $v );
|
| 5319 |
+
}
|
| 5320 |
+
|
| 5321 |
+
if ( 1 == count( $value ) )
|
| 5322 |
+
$value = current( $value );
|
| 5323 |
+
}
|
| 5324 |
+
else
|
| 5325 |
+
$value = maybe_unserialize( $value );
|
| 5326 |
+
|
| 5327 |
+
$pod[ 'options' ][ $option ] = $value;
|
| 5328 |
+
}
|
| 5329 |
+
|
| 5330 |
+
$pod[ 'options' ] = array_merge( $defaults, $pod[ 'options' ] );
|
| 5331 |
+
|
| 5332 |
+
$pod[ 'type' ] = $pod[ 'options' ][ 'type' ];
|
| 5333 |
+
$pod[ 'storage' ] = $pod[ 'options' ][ 'storage' ];
|
| 5334 |
+
$pod[ 'object' ] = $pod[ 'options' ][ 'object' ];
|
| 5335 |
+
$pod[ 'alias' ] = $pod[ 'options' ][ 'alias' ];
|
| 5336 |
+
|
| 5337 |
+
unset( $pod[ 'options' ][ 'type' ] );
|
| 5338 |
+
unset( $pod[ 'options' ][ 'storage' ] );
|
| 5339 |
+
unset( $pod[ 'options' ][ 'object' ] );
|
| 5340 |
+
unset( $pod[ 'options' ][ 'alias' ] );
|
| 5341 |
+
|
| 5342 |
+
if ( $table_info )
|
| 5343 |
+
$pod = array_merge( $this->get_table_info( $pod[ 'type' ], $pod[ 'object' ], $pod[ 'name' ], $pod ), $pod );
|
| 5344 |
+
|
| 5345 |
+
if ( isset( $pod[ 'pod' ] ) )
|
| 5346 |
+
unset( $pod[ 'pod' ] );
|
| 5347 |
+
|
| 5348 |
+
$pod[ 'fields' ] = array();
|
| 5349 |
+
|
| 5350 |
+
$pod[ 'object_fields' ] = array();
|
| 5351 |
+
|
| 5352 |
+
if ( 'pod' != $pod[ 'type' ] )
|
| 5353 |
+
$pod[ 'object_fields' ] = $this->get_wp_object_fields( $pod[ 'type' ], $pod );
|
| 5354 |
+
|
| 5355 |
+
$fields = get_posts( array(
|
| 5356 |
+
'post_type' => '_pods_field',
|
| 5357 |
+
'posts_per_page' => -1,
|
| 5358 |
+
'nopaging' => true,
|
| 5359 |
+
'post_parent' => $pod[ 'id' ],
|
| 5360 |
+
'orderby' => 'menu_order',
|
| 5361 |
+
'order' => 'ASC'
|
| 5362 |
+
) );
|
| 5363 |
+
|
| 5364 |
+
if ( !empty( $fields ) ) {
|
| 5365 |
+
foreach ( $fields as $field ) {
|
| 5366 |
+
$field->pod = $pod[ 'name' ];
|
| 5367 |
+
$field->table_info = $table_info;
|
| 5368 |
+
|
| 5369 |
+
if ( $load_fields ) {
|
| 5370 |
+
$field = $this->load_field( $field );
|
| 5371 |
+
|
| 5372 |
+
$field = PodsForm::field_setup( $field, null, $field[ 'type' ] );
|
| 5373 |
+
}
|
| 5374 |
+
else {
|
| 5375 |
+
$field = array(
|
| 5376 |
+
'id' => $field->ID,
|
| 5377 |
+
'name' => $field->post_name,
|
| 5378 |
+
'label' => $field->post_title,
|
| 5379 |
+
'type' => get_post_meta( $field->ID, 'type', true )
|
| 5380 |
+
);
|
| 5381 |
+
}
|
| 5382 |
+
|
| 5383 |
+
$pod[ 'fields' ][ $field[ 'name' ] ] = $field;
|
| 5384 |
+
}
|
| 5385 |
+
}
|
| 5386 |
+
|
| 5387 |
+
if ( did_action( 'init' ) && pods_api_cache() )
|
| 5388 |
+
pods_transient_set( $transient . '_' . $pod[ 'name' ], $pod );
|
| 5389 |
+
|
| 5390 |
+
return $pod;
|
| 5391 |
+
}
|
| 5392 |
+
|
| 5393 |
+
/**
|
| 5394 |
+
* Load a list of Pods based on filters specified.
|
| 5395 |
+
*
|
| 5396 |
+
* $params['type'] string/array Pod Type(s) to filter by
|
| 5397 |
+
* $params['object'] string/array Pod Object(s) to filter by
|
| 5398 |
+
* $params['options'] array Pod Option(s) key=>value array to filter by
|
| 5399 |
+
* $params['orderby'] string ORDER BY clause of query
|
| 5400 |
+
* $params['limit'] string Number of Pods to return
|
| 5401 |
+
* $params['where'] string WHERE clause of query
|
| 5402 |
+
* $params['ids'] string|array IDs of Objects
|
| 5403 |
+
* $params['count'] boolean Return only a count of Pods
|
| 5404 |
+
* $params['names'] boolean Return only an array of name => label
|
| 5405 |
+
* $params['ids'] boolean Return only an array of ID => label
|
| 5406 |
+
* $params['fields'] boolean Return pod fields with Pods (default is true)
|
| 5407 |
+
* $params['key_names'] boolean Return pods keyed by name
|
| 5408 |
+
*
|
| 5409 |
+
* @param array $params An associative array of parameters
|
| 5410 |
+
*
|
| 5411 |
+
* @return array|mixed
|
| 5412 |
+
*
|
| 5413 |
+
* @uses PodsAPI::load_pod
|
| 5414 |
+
*
|
| 5415 |
+
* @since 2.0
|
| 5416 |
+
*/
|
| 5417 |
+
public function load_pods ( $params = null ) {
|
| 5418 |
+
|
| 5419 |
+
/**
|
| 5420 |
+
* @var $sitepress SitePress
|
| 5421 |
+
*/
|
| 5422 |
+
global $sitepress, $icl_adjust_id_url_filter_off;
|
| 5423 |
+
|
| 5424 |
+
$current_language = false;
|
| 5425 |
+
|
| 5426 |
+
// WPML support
|
| 5427 |
+
if ( is_object( $sitepress ) && !$icl_adjust_id_url_filter_off )
|
| 5428 |
+
$current_language = pods_sanitize( ICL_LANGUAGE_CODE );
|
| 5429 |
+
// Polylang support
|
| 5430 |
+
elseif ( function_exists( 'pll_current_language' ) )
|
| 5431 |
+
$current_language = pll_current_language( 'slug' );
|
| 5432 |
+
|
| 5433 |
+
$params = (object) pods_sanitize( $params );
|
| 5434 |
+
|
| 5435 |
+
$order = 'ASC';
|
| 5436 |
+
$orderby = 'menu_order title';
|
| 5437 |
+
$limit = -1;
|
| 5438 |
+
$ids = false;
|
| 5439 |
+
|
| 5440 |
+
$meta_query = array();
|
| 5441 |
+
$cache_key = '';
|
| 5442 |
+
|
| 5443 |
+
if ( isset( $params->type ) && !empty( $params->type ) ) {
|
| 5444 |
+
if ( !is_array( $params->type ) )
|
| 5445 |
+
$params->type = array( trim( $params->type ) );
|
| 5446 |
+
|
| 5447 |
+
sort( $params->type );
|
| 5448 |
+
|
| 5449 |
+
$meta_query[] = array(
|
| 5450 |
+
'key' => 'type',
|
| 5451 |
+
'value' => $params->type,
|
| 5452 |
+
'compare' => 'IN'
|
| 5453 |
+
);
|
| 5454 |
+
|
| 5455 |
+
if ( 0 < count( $params->type ) )
|
| 5456 |
+
$cache_key .= '_type_' . trim( implode( '_', $params->type ) );
|
| 5457 |
+
}
|
| 5458 |
+
|
| 5459 |
+
if ( isset( $params->object ) && !empty( $params->object ) ) {
|
| 5460 |
+
if ( !is_array( $params->object ) )
|
| 5461 |
+
$params->object = array( $params->object );
|
| 5462 |
+
|
| 5463 |
+
$params->object = pods_trim( $params->object );
|
| 5464 |
+
|
| 5465 |
+
sort( $params->object );
|
| 5466 |
|
| 5467 |
+
$meta_query[] = array(
|
| 5468 |
+
'key' => 'object',
|
| 5469 |
+
'value' => $params->object,
|
| 5470 |
+
'compare' => 'IN'
|
| 5471 |
+
);
|
| 5472 |
+
|
| 5473 |
+
if ( 1 == count( $params->object ) )
|
| 5474 |
+
$cache_key .= '_object_' . trim( implode( '', $params->object ) );
|
| 5475 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5476 |
|
| 5477 |
+
if ( isset( $params->options ) && !empty( $params->options ) && is_array( $params->options ) ) {
|
| 5478 |
+
foreach ( $params->options as $option => $value ) {
|
| 5479 |
+
if ( !is_array( $value ) )
|
| 5480 |
+
$value = array( $value );
|
| 5481 |
|
| 5482 |
+
$value = pods_trim( $value );
|
| 5483 |
|
| 5484 |
+
sort( $value );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5485 |
|
| 5486 |
+
$meta_query[] = array(
|
| 5487 |
+
'key' => $option,
|
| 5488 |
+
'value' => pods_sanitize( $value ),
|
| 5489 |
+
'compare' => 'IN'
|
| 5490 |
+
);
|
| 5491 |
+
}
|
| 5492 |
|
| 5493 |
+
$cache_key = '';
|
| 5494 |
+
}
|
|
|
|
| 5495 |
|
| 5496 |
+
if ( isset( $params->where ) && is_array( $params->where ) )
|
| 5497 |
+
$meta_query = array_merge( $meta_query, (array) $params->where );
|
|
|
|
| 5498 |
|
| 5499 |
+
if ( isset( $params->order ) && !empty( $params->order ) && in_array( strtoupper( $params->order ), array( 'ASC', 'DESC' ) ) )
|
| 5500 |
+
$order = strtoupper( $params->order );
|
|
|
|
| 5501 |
|
| 5502 |
+
if ( isset( $params->orderby ) && !empty( $params->orderby ) )
|
| 5503 |
+
$orderby = strtoupper( $params->orderby );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5504 |
|
| 5505 |
+
if ( isset( $params->limit ) && !empty( $params->limit ) )
|
| 5506 |
+
$limit = pods_absint( $params->limit );
|
|
|
|
| 5507 |
|
| 5508 |
+
if ( isset( $params->ids ) && !empty( $params->ids ) ) {
|
| 5509 |
+
$ids = $params->ids;
|
| 5510 |
|
| 5511 |
+
if ( !is_array( $ids ) )
|
| 5512 |
+
$ids = explode( ',', $ids );
|
| 5513 |
+
}
|
|
|
|
| 5514 |
|
| 5515 |
+
if ( empty( $ids ) )
|
| 5516 |
+
$ids = false;
|
|
|
|
|
|
|
| 5517 |
|
| 5518 |
+
$pre_key = '';
|
| 5519 |
|
| 5520 |
+
if ( !empty( $current_language ) )
|
| 5521 |
+
$pre_key .= '_' . $current_language;
|
| 5522 |
|
| 5523 |
+
if ( isset( $params->count ) && $params->count )
|
| 5524 |
+
$pre_key .= '_count';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5525 |
|
| 5526 |
+
if ( isset( $params->ids ) && $params->ids && !empty( $ids ) )
|
| 5527 |
+
$pre_key .= '_ids_' . implode( '_', $ids );
|
|
|
|
| 5528 |
|
| 5529 |
+
if ( isset( $params->names ) && $params->names )
|
| 5530 |
+
$pre_key .= '_names';
|
| 5531 |
+
elseif ( isset( $params->names_ids ) && $params->names_ids )
|
| 5532 |
+
$pre_key .= '_names_ids';
|
| 5533 |
|
| 5534 |
+
if ( isset( $params->key_names ) && $params->key_names )
|
| 5535 |
+
$pre_key .= '_namekeys';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5536 |
|
| 5537 |
+
if ( isset( $params->fields ) && !$params->fields )
|
| 5538 |
+
$pre_key .= '_nofields';
|
| 5539 |
|
| 5540 |
+
if ( isset( $params->table_info ) && $params->table_info )
|
| 5541 |
+
$pre_key .= '_tableinfo';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5542 |
|
|
|
|
|
|
|
|
|
|
| 5543 |
|
| 5544 |
+
$pre_key .= '_get';
|
|
|
|
| 5545 |
|
| 5546 |
+
if ( empty( $cache_key ) )
|
| 5547 |
+
$cache_key = 'pods' . $pre_key . '_all';
|
| 5548 |
+
else
|
| 5549 |
+
$cache_key = 'pods' . $pre_key . $cache_key;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5550 |
|
| 5551 |
+
if ( pods_api_cache() && !empty( $cache_key ) && ( 'pods' . ( !empty( $current_language ) ? '_' . $current_language : '' ) . '_get_all' != $cache_key || empty( $meta_query ) ) && $limit < 1 && ( empty( $orderby ) || 'menu_order title' == $orderby ) && empty( $ids ) ) {
|
| 5552 |
+
$the_pods = pods_transient_get( $cache_key );
|
| 5553 |
|
| 5554 |
+
if ( false === $the_pods )
|
| 5555 |
+
$the_pods = pods_cache_get( $cache_key, 'pods' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5556 |
|
| 5557 |
+
if ( !is_array( $the_pods ) && 'none' == $the_pods )
|
| 5558 |
+
return array();
|
| 5559 |
+
elseif ( false !== $the_pods )
|
| 5560 |
+
return $the_pods;
|
| 5561 |
+
}
|
| 5562 |
|
| 5563 |
+
$the_pods = array();
|
|
|
|
|
|
|
| 5564 |
|
| 5565 |
+
$args = array(
|
| 5566 |
+
'post_type' => '_pods_pod',
|
| 5567 |
+
'nopaging' => true,
|
| 5568 |
+
'posts_per_page' => $limit,
|
| 5569 |
+
'order' => $order,
|
| 5570 |
+
'orderby' => $orderby,
|
| 5571 |
+
'meta_query' => $meta_query,
|
| 5572 |
+
);
|
| 5573 |
|
| 5574 |
+
// Only set post__in if there are ids to filter (see https://core.trac.wordpress.org/ticket/28099)
|
| 5575 |
+
if ( false != $ids ) {
|
| 5576 |
+
$args[ 'post__in' ] = $ids;
|
| 5577 |
}
|
| 5578 |
|
| 5579 |
+
$_pods = get_posts( $args );
|
|
|
|
| 5580 |
|
| 5581 |
+
$export_ignore = array(
|
| 5582 |
+
'object_type',
|
| 5583 |
+
'object_name',
|
| 5584 |
+
'table',
|
| 5585 |
+
'meta_table',
|
| 5586 |
+
'pod_table',
|
| 5587 |
+
'field_id',
|
| 5588 |
+
'field_index',
|
| 5589 |
+
'field_slug',
|
| 5590 |
+
'field_type',
|
| 5591 |
+
'field_parent',
|
| 5592 |
+
'field_parent_select',
|
| 5593 |
+
'meta_field_id',
|
| 5594 |
+
'meta_field_index',
|
| 5595 |
+
'meta_field_value',
|
| 5596 |
+
'pod_field_id',
|
| 5597 |
+
'pod_field_index',
|
| 5598 |
+
'object_fields',
|
| 5599 |
+
'join',
|
| 5600 |
+
'where',
|
| 5601 |
+
'where_default',
|
| 5602 |
+
'orderby',
|
| 5603 |
+
'pod',
|
| 5604 |
+
'recurse',
|
| 5605 |
+
'table_info',
|
| 5606 |
+
'attributes',
|
| 5607 |
+
'group',
|
| 5608 |
+
'grouped',
|
| 5609 |
+
'developer_mode',
|
| 5610 |
+
'dependency',
|
| 5611 |
+
'depends-on',
|
| 5612 |
+
'excludes-on'
|
| 5613 |
+
);
|
| 5614 |
+
|
| 5615 |
+
$total_fields = 0;
|
| 5616 |
+
|
| 5617 |
+
if ( isset( $params->count ) && $params->count )
|
| 5618 |
+
$the_pods = count( $_pods );
|
| 5619 |
+
else {
|
| 5620 |
+
foreach ( $_pods as $pod ) {
|
| 5621 |
+
if ( isset( $params->names ) && $params->names )
|
| 5622 |
+
$the_pods[ $pod->post_name ] = $pod->post_title;
|
| 5623 |
+
elseif ( isset( $params->names_ids ) && $params->names_ids )
|
| 5624 |
+
$the_pods[ $pod->ID ] = $pod->post_name;
|
| 5625 |
+
else {
|
| 5626 |
+
if ( isset( $params->fields ) && !$params->fields )
|
| 5627 |
+
$pod->fields = false;
|
| 5628 |
+
|
| 5629 |
+
$pod = $this->load_pod( $pod );
|
| 5630 |
+
|
| 5631 |
+
// Remove extra data not needed
|
| 5632 |
+
if ( pods_var( 'export', $params, false ) && ( !isset( $params->fields ) || $params->fields ) ) {
|
| 5633 |
+
foreach ( $export_ignore as $ignore ) {
|
| 5634 |
+
if ( isset( $pod[ $ignore ] ) )
|
| 5635 |
+
unset( $pod[ $ignore ] );
|
| 5636 |
+
}
|
| 5637 |
+
|
| 5638 |
+
foreach ( $pod[ 'fields' ] as $field => $field_data ) {
|
| 5639 |
+
if ( isset( $pod[ 'fields' ][ $field ][ 'table_info' ] ) )
|
| 5640 |
+
unset( $pod[ 'fields' ][ $field ][ 'table_info' ] );
|
| 5641 |
+
}
|
| 5642 |
+
}
|
| 5643 |
+
|
| 5644 |
+
$total_fields += count( $pod[ 'fields' ] );
|
| 5645 |
+
|
| 5646 |
+
if ( isset( $params->key_names ) && $params->key_names )
|
| 5647 |
+
$the_pods[ $pod[ 'name' ] ] = $pod;
|
| 5648 |
+
else
|
| 5649 |
+
$the_pods[ $pod[ 'id' ] ] = $pod;
|
| 5650 |
+
}
|
| 5651 |
+
}
|
| 5652 |
+
}
|
| 5653 |
+
|
| 5654 |
+
if ( ( !function_exists( 'pll_current_language' ) || ( isset( $params->refresh ) && $params->refresh ) ) && !empty( $cache_key ) && ( 'pods' != $cache_key || empty( $meta_query ) ) && $limit < 1 && ( empty( $orderby ) || 'menu_order title' == $orderby ) && empty( $ids ) ) {
|
| 5655 |
+
// Too many Pods can cause issues with the DB when caching is not enabled
|
| 5656 |
+
if ( 15 < count( $the_pods ) || 75 < count( $total_fields ) ) {
|
| 5657 |
+
pods_transient_clear( $cache_key );
|
| 5658 |
+
|
| 5659 |
+
if ( pods_api_cache() ) {
|
| 5660 |
+
if ( empty( $the_pods ) && ( !isset( $params->count ) || !$params->count ) )
|
| 5661 |
+
pods_cache_set( $cache_key, 'none', 'pods' );
|
| 5662 |
+
else
|
| 5663 |
+
pods_cache_set( $cache_key, $the_pods, 'pods' );
|
| 5664 |
+
}
|
| 5665 |
+
}
|
| 5666 |
+
else {
|
| 5667 |
+
pods_cache_clear( $cache_key, 'pods' );
|
| 5668 |
+
|
| 5669 |
+
if ( pods_api_cache() ) {
|
| 5670 |
+
if ( empty( $the_pods ) && ( !isset( $params->count ) || !$params->count ) )
|
| 5671 |
+
pods_transient_set( $cache_key, 'none' );
|
| 5672 |
+
else
|
| 5673 |
+
pods_transient_set( $cache_key, $the_pods );
|
| 5674 |
+
}
|
| 5675 |
+
}
|
| 5676 |
+
}
|
| 5677 |
+
|
| 5678 |
+
return $the_pods;
|
| 5679 |
+
}
|
| 5680 |
+
|
| 5681 |
+
/**
|
| 5682 |
+
* Check if a Pod's field exists
|
| 5683 |
+
*
|
| 5684 |
+
* $params['pod_id'] int The Pod ID
|
| 5685 |
+
* $params['id'] int The field ID
|
| 5686 |
+
* $params['name'] string The field name
|
| 5687 |
+
*
|
| 5688 |
+
* @param array $params An associative array of parameters
|
| 5689 |
+
*
|
| 5690 |
+
* @return bool
|
| 5691 |
+
*
|
| 5692 |
+
* @since 1.12
|
| 5693 |
+
*/
|
| 5694 |
+
public function field_exists ( $params ) {
|
| 5695 |
+
$params = (object) pods_sanitize( $params );
|
| 5696 |
+
|
| 5697 |
+
if ( ( !empty( $params->id ) || !empty( $params->name ) ) && isset( $params->pod_id ) && !empty( $params->pod_id ) ) {
|
| 5698 |
+
if ( !isset( $params->name ) )
|
| 5699 |
+
$field = get_post( $dummy = (int) $params->id );
|
| 5700 |
+
else {
|
| 5701 |
+
$field = get_posts( array(
|
| 5702 |
+
'name' => $params->name,
|
| 5703 |
+
'post_type' => '_pods_field',
|
| 5704 |
+
'posts_per_page' => 1,
|
| 5705 |
+
'post_parent' => $params->pod_id
|
| 5706 |
+
) );
|
| 5707 |
+
}
|
| 5708 |
+
|
| 5709 |
+
if ( !empty( $field ) )
|
| 5710 |
+
return true;
|
| 5711 |
+
}
|
| 5712 |
+
|
| 5713 |
+
return false;
|
| 5714 |
+
}
|
| 5715 |
+
|
| 5716 |
+
/**
|
| 5717 |
+
* Load a field
|
| 5718 |
+
*
|
| 5719 |
+
* $params['pod_id'] int The Pod ID
|
| 5720 |
+
* $params['pod'] string The Pod name
|
| 5721 |
+
* $params['id'] int The field ID
|
| 5722 |
+
* $params['name'] string The field name
|
| 5723 |
+
* $params['table_info'] boolean Whether to lookup a pick field's table info
|
| 5724 |
+
*
|
| 5725 |
+
* @param array $params An associative array of parameters
|
| 5726 |
+
* @param boolean $strict Whether to require a field exist or not when loading the info
|
| 5727 |
+
*
|
| 5728 |
+
* @return array|bool Array with field data, false if field not found
|
| 5729 |
+
* @since 1.7.9
|
| 5730 |
+
*/
|
| 5731 |
+
public function load_field ( $params, $strict = false ) {
|
| 5732 |
+
$params = (object) $params;
|
| 5733 |
+
|
| 5734 |
+
if ( !isset( $params->table_info ) )
|
| 5735 |
+
$params->table_info = false;
|
| 5736 |
+
|
| 5737 |
+
$pod = array();
|
| 5738 |
+
$field = array();
|
| 5739 |
+
|
| 5740 |
+
if ( isset( $params->post_title ) )
|
| 5741 |
+
$_field = $params;
|
| 5742 |
+
elseif ( isset( $params->id ) && !empty( $params->id ) )
|
| 5743 |
+
$_field = get_post( $dumb = (int) $params->id );
|
| 5744 |
+
else {
|
| 5745 |
+
if ( !isset( $params->pod ) )
|
| 5746 |
+
$params->pod = '';
|
| 5747 |
+
|
| 5748 |
+
if ( !isset( $params->pod_id ) )
|
| 5749 |
+
$params->pod_id = 0;
|
| 5750 |
+
|
| 5751 |
+
if ( isset( $params->pod_data ) )
|
| 5752 |
+
$pod = $params->pod_data;
|
| 5753 |
+
else {
|
| 5754 |
+
$pod = $this->load_pod( array( 'name' => $params->pod, 'id' => $params->pod_id, 'table_info' => false ), false );
|
| 5755 |
+
|
| 5756 |
+
if ( false === $pod ) {
|
| 5757 |
+
if ( $strict )
|
| 5758 |
+
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
| 5759 |
+
|
| 5760 |
+
return false;
|
| 5761 |
+
}
|
| 5762 |
+
}
|
| 5763 |
+
|
| 5764 |
+
$params->pod_id = $pod[ 'id' ];
|
| 5765 |
+
$params->pod = $pod[ 'name' ];
|
| 5766 |
+
|
| 5767 |
+
if ( empty( $params->name ) && empty( $params->pod ) && empty( $params->pod_id ) )
|
| 5768 |
+
return pods_error( __( 'Either Field Name or Field ID / Pod ID are required', 'pods' ), $this );
|
| 5769 |
+
|
| 5770 |
+
$params->name = pods_clean_name( $params->name, true, ( 'meta' == $pod[ 'storage' ] ? false : true ) );
|
| 5771 |
+
|
| 5772 |
+
if ( isset( $pod[ 'fields' ][ $params->name ] ) && isset( $pod[ 'fields' ][ $params->name ][ 'id' ] ) )
|
| 5773 |
+
return $pod[ 'fields' ][ $params->name ];
|
| 5774 |
+
|
| 5775 |
+
$field = false;
|
| 5776 |
+
|
| 5777 |
+
if ( pods_api_cache() )
|
| 5778 |
+
$field = pods_transient_get( 'pods_field_' . $params->pod . '_' . $params->name );
|
| 5779 |
+
|
| 5780 |
+
if ( empty( $field ) ) {
|
| 5781 |
+
$field = get_posts( array(
|
| 5782 |
+
'name' => $params->name,
|
| 5783 |
+
'post_type' => '_pods_field',
|
| 5784 |
+
'posts_per_page' => 1,
|
| 5785 |
+
'post_parent' => $params->pod_id
|
| 5786 |
+
) );
|
| 5787 |
+
|
| 5788 |
+
if ( empty( $field ) ) {
|
| 5789 |
+
if ( $strict )
|
| 5790 |
+
return pods_error( __( 'Field not found', 'pods' ), $this );
|
| 5791 |
+
|
| 5792 |
+
return false;
|
| 5793 |
+
}
|
| 5794 |
+
|
| 5795 |
+
$_field = $field[ 0 ];
|
| 5796 |
+
|
| 5797 |
+
$field = array();
|
| 5798 |
+
}
|
| 5799 |
+
}
|
| 5800 |
+
|
| 5801 |
+
if ( empty( $_field ) ) {
|
| 5802 |
+
if ( $strict )
|
| 5803 |
+
return pods_error( __( 'Field not found', 'pods' ), $this );
|
| 5804 |
+
|
| 5805 |
+
return false;
|
| 5806 |
+
}
|
| 5807 |
+
|
| 5808 |
+
$_field = get_object_vars( $_field );
|
| 5809 |
+
|
| 5810 |
+
if ( !isset( $pod[ 'name' ] ) && !isset( $_field[ 'pod' ] ) ) {
|
| 5811 |
+
if ( 0 < $_field[ 'post_parent' ] )
|
| 5812 |
+
$pod = $this->load_pod( array( 'id' => $_field[ 'post_parent' ], 'table_info' => false ), false );
|
| 5813 |
+
|
| 5814 |
+
if ( empty( $pod ) ) {
|
| 5815 |
+
if ( $strict )
|
| 5816 |
+
return pods_error( __( 'Pod for field not found', 'pods' ), $this );
|
| 5817 |
+
|
| 5818 |
+
return false;
|
| 5819 |
+
}
|
| 5820 |
+
}
|
| 5821 |
+
|
| 5822 |
+
if ( empty( $field ) ) {
|
| 5823 |
+
if ( pods_api_cache() && ( isset( $pod[ 'name' ] ) || isset( $_field[ 'pod' ] ) ) )
|
| 5824 |
+
$field = pods_transient_get( 'pods_field_' . pods_var( 'name', $pod, pods_var( 'pod', $_field ), null, true ) . '_' . $_field[ 'post_name' ] );
|
| 5825 |
+
|
| 5826 |
+
if ( empty( $field ) ) {
|
| 5827 |
+
$defaults = array(
|
| 5828 |
+
'type' => 'text'
|
| 5829 |
+
);
|
| 5830 |
+
|
| 5831 |
+
$field = array(
|
| 5832 |
+
'id' => $_field[ 'ID' ],
|
| 5833 |
+
'name' => $_field[ 'post_name' ],
|
| 5834 |
+
'label' => $_field[ 'post_title' ],
|
| 5835 |
+
'description' => $_field[ 'post_content' ],
|
| 5836 |
+
'weight' => $_field[ 'menu_order' ],
|
| 5837 |
+
'pod_id' => $_field[ 'post_parent' ],
|
| 5838 |
+
'pick_object' => '',
|
| 5839 |
+
'pick_val' => '',
|
| 5840 |
+
'sister_id' => '',
|
| 5841 |
+
'table_info' => array()
|
| 5842 |
+
);
|
| 5843 |
+
|
| 5844 |
+
if ( isset( $pod[ 'name' ] ) )
|
| 5845 |
+
$field[ 'pod' ] = $pod[ 'name' ];
|
| 5846 |
+
elseif ( isset( $_field[ 'pod' ] ) )
|
| 5847 |
+
$field[ 'pod' ] = $_field[ 'pod' ];
|
| 5848 |
+
|
| 5849 |
+
$field[ 'options' ] = get_post_meta( $field[ 'id' ] );
|
| 5850 |
+
|
| 5851 |
+
$options_ignore = array(
|
| 5852 |
+
'method',
|
| 5853 |
+
'table_info',
|
| 5854 |
+
'attributes',
|
| 5855 |
+
'group',
|
| 5856 |
+
'grouped',
|
| 5857 |
+
'developer_mode',
|
| 5858 |
+
'dependency',
|
| 5859 |
+
'depends-on',
|
| 5860 |
+
'excludes-on'
|
| 5861 |
+
);
|
| 5862 |
+
|
| 5863 |
+
foreach ( $options_ignore as $ignore ) {
|
| 5864 |
+
if ( isset( $field[ 'options' ][ $ignore ] ) )
|
| 5865 |
+
unset( $field[ 'options' ][ $ignore ] );
|
| 5866 |
+
}
|
| 5867 |
+
|
| 5868 |
+
foreach ( $field[ 'options' ] as $option => $value ) {
|
| 5869 |
+
if ( is_array( $value ) ) {
|
| 5870 |
+
foreach ( $value as $k => $v ) {
|
| 5871 |
+
if ( !is_array( $v ) )
|
| 5872 |
+
$value[ $k ] = maybe_unserialize( $v );
|
| 5873 |
+
}
|
| 5874 |
+
|
| 5875 |
+
if ( 1 == count( $value ) )
|
| 5876 |
+
$value = current( $value );
|
| 5877 |
+
}
|
| 5878 |
+
else
|
| 5879 |
+
$value = maybe_unserialize( $value );
|
| 5880 |
+
|
| 5881 |
+
$field[ 'options' ][ $option ] = $value;
|
| 5882 |
+
}
|
| 5883 |
+
|
| 5884 |
+
$field[ 'options' ] = array_merge( $defaults, $field[ 'options' ] );
|
| 5885 |
+
|
| 5886 |
+
$field[ 'type' ] = $field[ 'options' ][ 'type' ];
|
| 5887 |
+
|
| 5888 |
+
unset( $field[ 'options' ][ 'type' ] );
|
| 5889 |
+
|
| 5890 |
+
if ( isset( $field[ 'options' ][ 'pick_object' ] ) ) {
|
| 5891 |
+
$field[ 'pick_object' ] = $field[ 'options' ][ 'pick_object' ];
|
| 5892 |
+
|
| 5893 |
+
unset( $field[ 'options' ][ 'pick_object' ] );
|
| 5894 |
+
}
|
| 5895 |
+
|
| 5896 |
+
if ( isset( $field[ 'options' ][ 'pick_val' ] ) ) {
|
| 5897 |
+
$field[ 'pick_val' ] = $field[ 'options' ][ 'pick_val' ];
|
| 5898 |
+
|
| 5899 |
+
unset( $field[ 'options' ][ 'pick_val' ] );
|
| 5900 |
+
}
|
| 5901 |
+
|
| 5902 |
+
if ( isset( $field[ 'options' ][ 'sister_id' ] ) ) {
|
| 5903 |
+
$field[ 'sister_id' ] = $field[ 'options' ][ 'sister_id' ];
|
| 5904 |
+
|
| 5905 |
+
unset( $field[ 'options' ][ 'sister_id' ] );
|
| 5906 |
+
}
|
| 5907 |
+
|
| 5908 |
+
if ( isset( $field[ 'options' ][ 'sister_field_id' ] ) )
|
| 5909 |
+
unset( $field[ 'options' ][ 'sister_field_id' ] );
|
| 5910 |
+
|
| 5911 |
+
if ( pods_api_cache() && ( isset( $pod[ 'name' ] ) || isset( $_field[ 'pod' ] ) ) )
|
| 5912 |
+
pods_transient_set( 'pods_field_' . pods_var( 'name', $pod, pods_var( 'pod', $_field ), null, true ) . '_' . $field[ 'name' ], $field );
|
| 5913 |
+
}
|
| 5914 |
+
}
|
| 5915 |
+
|
| 5916 |
+
$field[ 'table_info' ] = array();
|
| 5917 |
+
|
| 5918 |
+
if ( 'pick' == $field[ 'type' ] && $params->table_info )
|
| 5919 |
+
$field[ 'table_info' ] = $this->get_table_info( $field[ 'pick_object' ], $field[ 'pick_val' ], null, null, $field );
|
| 5920 |
+
|
| 5921 |
+
return $field;
|
| 5922 |
+
}
|
| 5923 |
+
|
| 5924 |
+
/**
|
| 5925 |
+
* Load fields by Pod, ID, Name, and/or Type
|
| 5926 |
+
*
|
| 5927 |
+
* $params['pod_id'] int The Pod ID
|
| 5928 |
+
* $params['pod'] string The Pod name
|
| 5929 |
+
* $params['id'] array The field IDs
|
| 5930 |
+
* $params['name'] array The field names
|
| 5931 |
+
* $params['type'] array The field types
|
| 5932 |
+
* $params['options'] array Field Option(s) key=>value array to filter by
|
| 5933 |
+
* $params['where'] string WHERE clause of query
|
| 5934 |
+
*
|
| 5935 |
+
* @param array $params An associative array of parameters
|
| 5936 |
+
* @param bool $strict Whether to require a field exist or not when loading the info
|
| 5937 |
+
*
|
| 5938 |
+
* @return array Array of field data.
|
| 5939 |
+
*
|
| 5940 |
+
* @since 1.7.9
|
| 5941 |
+
*/
|
| 5942 |
+
public function load_fields ( $params, $strict = false ) {
|
| 5943 |
+
// @todo Get away from using md5/serialize, I'm sure we can cache specific parts
|
| 5944 |
+
$cache_key = md5( serialize( $params ) );
|
| 5945 |
+
if ( isset( $this->fields_cache[ $cache_key ] ) ) {
|
| 5946 |
+
return $this->fields_cache[ $cache_key ];
|
| 5947 |
+
}
|
| 5948 |
|
| 5949 |
+
$params = (object) pods_sanitize( $params );
|
|
|
|
|
|
|
|
|
|
| 5950 |
|
| 5951 |
+
if ( !isset( $params->pod ) || empty( $params->pod ) )
|
| 5952 |
+
$params->pod = '';
|
| 5953 |
|
| 5954 |
+
if ( !isset( $params->pod_id ) || empty( $params->pod_id ) )
|
| 5955 |
+
$params->pod_id = 0;
|
|
|
|
| 5956 |
|
| 5957 |
+
if ( !isset( $params->name ) || empty( $params->name ) )
|
| 5958 |
+
$params->name = array();
|
| 5959 |
+
else
|
| 5960 |
+
$params->name = (array) $params->name;
|
| 5961 |
|
| 5962 |
+
if ( !isset( $params->id ) || empty( $params->id ) )
|
| 5963 |
+
$params->id = array();
|
| 5964 |
+
else {
|
| 5965 |
+
$params->id = (array) $params->id;
|
| 5966 |
|
| 5967 |
+
foreach ( $params->id as &$id ) {
|
| 5968 |
+
$id = pods_absint( $id );
|
| 5969 |
+
}
|
| 5970 |
+
}
|
| 5971 |
|
| 5972 |
+
if ( !isset( $params->type ) || empty( $params->type ) )
|
| 5973 |
+
$params->type = array();
|
| 5974 |
+
else
|
| 5975 |
+
$params->type = (array) $params->type;
|
|
|
|
| 5976 |
|
| 5977 |
+
$fields = array();
|
|
|
|
|
|
|
|
|
|
| 5978 |
|
| 5979 |
+
if ( !empty( $params->pod ) || !empty( $params->pod_id ) ) {
|
| 5980 |
+
$pod = $this->load_pod( array( 'name' => $params->pod, 'id' => $params->pod_id, 'table_info' => true ), false );
|
|
|
|
|
|
|
|
|
|
| 5981 |
|
| 5982 |
+
if ( false === $pod ) {
|
| 5983 |
+
if ( $strict )
|
| 5984 |
+
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
|
|
|
| 5985 |
|
| 5986 |
+
return $fields;
|
| 5987 |
+
}
|
|
|
|
| 5988 |
|
| 5989 |
+
$pod[ 'fields' ] = array_merge( pods_var_raw( 'object_fields', $pod, array() ), $pod[ 'fields' ] );
|
|
|
|
|
|
|
| 5990 |
|
| 5991 |
+
foreach ( $pod[ 'fields' ] as $field ) {
|
| 5992 |
+
if ( empty( $params->name ) && empty( $params->id ) && empty( $params->type ) )
|
| 5993 |
+
$fields[ $field[ 'name' ] ] = $field;
|
| 5994 |
+
elseif ( in_array( $fields[ 'name' ], $params->name ) || in_array( $fields[ 'id' ], $params->id ) || in_array( $fields[ 'type' ], $params->type ) )
|
| 5995 |
+
$fields[ $field[ 'name' ] ] = $field;
|
| 5996 |
+
}
|
| 5997 |
+
}
|
| 5998 |
+
elseif ( ( isset( $params->options ) && !empty( $params->options ) && is_array( $params->options ) ) || ( isset( $params->where ) && !empty( $params->where ) && is_array( $params->where ) ) ) {
|
| 5999 |
+
$order = 'ASC';
|
| 6000 |
+
$orderby = 'menu_order title';
|
| 6001 |
+
$limit = -1;
|
| 6002 |
+
$ids = false;
|
| 6003 |
|
| 6004 |
+
$meta_query = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6005 |
|
| 6006 |
+
if ( isset( $params->options ) && !empty( $params->options ) && is_array( $params->options ) ) {
|
| 6007 |
+
foreach ( $params->options as $option => $value ) {
|
| 6008 |
+
if ( !is_array( $value ) )
|
| 6009 |
+
$value = array( $value );
|
|
|
|
|
|
|
| 6010 |
|
| 6011 |
+
$value = pods_trim( $value );
|
|
|
|
| 6012 |
|
| 6013 |
+
sort( $value );
|
|
|
|
|
|
|
| 6014 |
|
| 6015 |
+
$meta_query[] = array(
|
| 6016 |
+
'key' => $option,
|
| 6017 |
+
'value' => pods_sanitize( $value ),
|
| 6018 |
+
'compare' => 'IN'
|
| 6019 |
+
);
|
| 6020 |
+
}
|
| 6021 |
+
}
|
| 6022 |
|
| 6023 |
+
if ( isset( $params->where ) && !empty( $params->where ) && is_array( $params->where ) )
|
| 6024 |
+
$meta_query = array_merge( $meta_query, (array) $params->where );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6025 |
|
| 6026 |
+
$args = array(
|
| 6027 |
+
'post_type' => '_pods_field',
|
| 6028 |
+
'nopaging' => true,
|
| 6029 |
+
'posts_per_page' => $limit,
|
| 6030 |
+
'order' => $order,
|
| 6031 |
+
'orderby' => $orderby,
|
| 6032 |
+
'meta_query' => $meta_query,
|
| 6033 |
+
);
|
| 6034 |
|
| 6035 |
+
// Only set post__in if there are ids to filter (see https://core.trac.wordpress.org/ticket/28099)
|
| 6036 |
+
if ( false != $ids ) {
|
| 6037 |
+
$args[ 'post__in' ] = $ids;
|
| 6038 |
+
}
|
|
|
|
| 6039 |
|
| 6040 |
+
$fields = array();
|
|
|
|
|
|
|
| 6041 |
|
| 6042 |
+
$_fields = get_posts( $args );
|
| 6043 |
|
| 6044 |
+
foreach ( $_fields as $field ) {
|
| 6045 |
+
$field = $this->load_field( $field, false );
|
|
|
|
|
|
|
|
|
|
| 6046 |
|
| 6047 |
+
if ( !empty( $field ) )
|
| 6048 |
+
$fields[ $field[ 'id' ] ] = $field;
|
| 6049 |
+
}
|
| 6050 |
+
}
|
| 6051 |
+
else {
|
| 6052 |
+
if ( empty( $params->name ) && empty( $params->id ) && empty( $params->type ) )
|
| 6053 |
+
return pods_error( __( 'Either Field Name / Field ID / Field Type, or Pod Name / Pod ID are required', 'pods' ), $this );
|
| 6054 |
|
| 6055 |
+
$lookup = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6056 |
|
| 6057 |
+
if ( !empty( $params->name ) ) {
|
| 6058 |
+
$fields = implode( "', '", $params->name );
|
|
|
|
| 6059 |
|
| 6060 |
+
$lookup[] = "`post_name` IN ( '{$fields}' )";
|
| 6061 |
+
}
|
| 6062 |
|
| 6063 |
+
if ( !empty( $params->id ) ) {
|
| 6064 |
+
$fields = implode( ", ", $params->id );
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6065 |
|
| 6066 |
+
$lookup[] = "`ID` IN ( {$fields} )";
|
| 6067 |
+
}
|
| 6068 |
|
| 6069 |
+
$lookup = implode( ' AND ', $lookup );
|
|
|
|
|
|
|
| 6070 |
|
| 6071 |
+
$result = pods_query( "SELECT `ID`, `post_name`, `post_parent` FROM `@wp_posts` WHERE `post_type` = '_pods_field' AND ( {$lookup} )" );
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6072 |
|
| 6073 |
+
$fields = array();
|
|
|
|
|
|
|
| 6074 |
|
| 6075 |
+
if ( !empty( $result ) ) {
|
| 6076 |
+
foreach ( $result as $field ) {
|
| 6077 |
+
$field = $this->load_field( array(
|
| 6078 |
+
'id' => $field->ID,
|
| 6079 |
+
'name' => $field->post_name,
|
| 6080 |
+
'pod_id' => $field->post_parent
|
| 6081 |
+
), false );
|
| 6082 |
+
|
| 6083 |
+
if ( !empty( $field ) && ( empty( $params->type ) || in_array( $field[ 'type' ], $params->type ) ) )
|
| 6084 |
+
$fields[ $field[ 'id' ] ] = $field;
|
| 6085 |
+
}
|
| 6086 |
+
}
|
| 6087 |
+
}
|
| 6088 |
+
if ( isset( $cache_key ) ) {
|
| 6089 |
+
$this->fields_cache[ $cache_key ] = $fields;
|
| 6090 |
+
}
|
| 6091 |
+
return $fields;
|
| 6092 |
+
}
|
| 6093 |
+
|
| 6094 |
+
/**
|
| 6095 |
+
* Load a Pods Object
|
| 6096 |
+
*
|
| 6097 |
+
* $params['id'] int The Object ID
|
| 6098 |
+
* $params['name'] string The Object name
|
| 6099 |
+
* $params['type'] string The Object type
|
| 6100 |
+
*
|
| 6101 |
+
* @param array|object $params An associative array of parameters
|
| 6102 |
+
* @param bool $strict
|
| 6103 |
+
*
|
| 6104 |
+
* @return array|bool
|
| 6105 |
+
* @since 2.0
|
| 6106 |
+
*/
|
| 6107 |
+
public function load_object ( $params, $strict = false ) {
|
| 6108 |
+
if ( is_object( $params ) && isset( $params->post_title ) )
|
| 6109 |
+
$_object = get_object_vars( $params );
|
| 6110 |
+
else {
|
| 6111 |
+
$params = (object) pods_sanitize( $params );
|
| 6112 |
+
|
| 6113 |
+
if ( !isset( $params->type ) || empty( $params->type ) )
|
| 6114 |
+
return pods_error( __( 'Object type is required', 'pods' ), $this );
|
| 6115 |
+
|
| 6116 |
+
if ( ( !isset( $params->id ) || empty( $params->id ) ) && ( !isset( $params->name ) || empty( $params->name ) ) )
|
| 6117 |
+
return pods_error( __( 'Either Object ID or Name are required', 'pods' ), $this );
|
| 6118 |
+
|
| 6119 |
+
/**
|
| 6120 |
+
* @var $wpdb wpdb
|
| 6121 |
+
*/
|
| 6122 |
+
global $wpdb;
|
| 6123 |
+
|
| 6124 |
+
if ( isset( $params->name ) )
|
| 6125 |
+
$_object = pods_by_title( $params->name, ARRAY_A, '_pods_' . $params->type, 'publish' );
|
| 6126 |
+
else {
|
| 6127 |
+
$object = $params->id;
|
| 6128 |
+
|
| 6129 |
+
$_object = get_post( $object, ARRAY_A );
|
| 6130 |
+
}
|
| 6131 |
+
|
| 6132 |
+
if ( empty( $_object ) ) {
|
| 6133 |
+
if ( $strict )
|
| 6134 |
+
return pods_error( __( 'Object not found', 'pods' ), $this );
|
| 6135 |
+
|
| 6136 |
+
return false;
|
| 6137 |
+
}
|
| 6138 |
+
}
|
| 6139 |
+
|
| 6140 |
+
$object = array(
|
| 6141 |
+
'id' => $_object[ 'ID' ],
|
| 6142 |
+
'name' => $_object[ 'post_title' ],
|
| 6143 |
+
'code' => $_object[ 'post_content' ],
|
| 6144 |
+
'type' => str_replace( '_pods_', '', $_object[ 'post_type' ] ),
|
| 6145 |
+
'slug' => $_object[ 'post_name' ]
|
| 6146 |
+
);
|
| 6147 |
+
|
| 6148 |
+
$object[ 'options' ] = get_post_meta( $object[ 'id' ] );
|
| 6149 |
+
|
| 6150 |
+
foreach ( $object[ 'options' ] as $option => &$value ) {
|
| 6151 |
+
if ( is_array( $value ) && 1 == count( $value ) )
|
| 6152 |
+
$value = current( $value );
|
| 6153 |
+
}
|
| 6154 |
+
|
| 6155 |
+
return $object;
|
| 6156 |
+
}
|
| 6157 |
+
|
| 6158 |
+
/**
|
| 6159 |
+
* Load Multiple Pods Objects
|
| 6160 |
+
*
|
| 6161 |
+
* $params['type'] string The Object type
|
| 6162 |
+
* $params['options'] array Pod Option(s) key=>value array to filter by
|
| 6163 |
+
* $params['orderby'] string ORDER BY clause of query
|
| 6164 |
+
* $params['limit'] string Number of objects to return
|
| 6165 |
+
* $params['where'] string WHERE clause of query
|
| 6166 |
+
* $params['ids'] string|array IDs of Objects
|
| 6167 |
+
*
|
| 6168 |
+
* @param array|object $params An associative array of parameters
|
| 6169 |
+
*
|
| 6170 |
+
* @return array
|
| 6171 |
+
* @since 2.0
|
| 6172 |
+
*/
|
| 6173 |
+
public function load_objects ( $params ) {
|
| 6174 |
+
$params = (object) pods_sanitize( $params );
|
| 6175 |
+
|
| 6176 |
+
if ( !isset( $params->type ) || empty( $params->type ) )
|
| 6177 |
+
return pods_error( __( 'Pods Object type is required', 'pods' ), $this );
|
| 6178 |
+
|
| 6179 |
+
$order = 'ASC';
|
| 6180 |
+
$orderby = 'menu_order';
|
| 6181 |
+
$limit = -1;
|
| 6182 |
+
$ids = false;
|
| 6183 |
+
|
| 6184 |
+
$meta_query = array();
|
| 6185 |
+
$cache_key = '';
|
| 6186 |
+
|
| 6187 |
+
if ( isset( $params->options ) && !empty( $params->options ) && is_array( $params->options ) ) {
|
| 6188 |
+
foreach ( $params->options as $option => $value ) {
|
| 6189 |
+
if ( !is_array( $value ) )
|
| 6190 |
+
$value = array( $value );
|
| 6191 |
+
|
| 6192 |
+
$value = pods_trim( $value );
|
| 6193 |
+
|
| 6194 |
+
sort( $value );
|
| 6195 |
+
|
| 6196 |
+
$meta_query[] = array(
|
| 6197 |
+
'key' => $option,
|
| 6198 |
+
'value' => pods_sanitize( $value ),
|
| 6199 |
+
'compare' => 'IN'
|
| 6200 |
+
);
|
| 6201 |
+
}
|
| 6202 |
+
}
|
| 6203 |
+
|
| 6204 |
+
if ( isset( $params->where ) && is_array( $params->where ) )
|
| 6205 |
+
$meta_query = array_merge( $meta_query, (array) $params->where );
|
| 6206 |
+
|
| 6207 |
+
if ( isset( $params->order ) && !empty( $params->order ) && in_array( strtoupper( $params->order ), array( 'ASC', 'DESC' ) ) )
|
| 6208 |
+
$order = strtoupper( $params->order );
|
| 6209 |
+
|
| 6210 |
+
if ( isset( $params->orderby ) && !empty( $params->orderby ) )
|
| 6211 |
+
$orderby = strtoupper( $params->orderby );
|
| 6212 |
|
| 6213 |
+
if ( isset( $params->limit ) && !empty( $params->limit ) )
|
| 6214 |
+
$limit = pods_absint( $params->limit );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6215 |
|
| 6216 |
+
if ( isset( $params->ids ) && !empty( $params->ids ) ) {
|
| 6217 |
+
$ids = $params->ids;
|
|
|
|
| 6218 |
|
| 6219 |
+
if ( !is_array( $ids ) )
|
| 6220 |
+
$ids = explode( ',', $ids );
|
| 6221 |
+
}
|
|
|
|
|
|
|
| 6222 |
|
| 6223 |
+
if ( empty( $ids ) )
|
| 6224 |
+
$ids = false;
|
| 6225 |
+
|
| 6226 |
+
if ( pods_api_cache() && empty( $meta_query ) && empty( $limit ) && ( empty( $orderby ) || 'menu_order' == $orderby ) && empty( $ids ) ) {
|
| 6227 |
+
$cache_key = 'pods_objects_' . $params->type;
|
| 6228 |
|
| 6229 |
+
$the_objects = pods_transient_get( $cache_key );
|
| 6230 |
|
| 6231 |
+
if ( false !== $the_objects )
|
| 6232 |
+
return $the_objects;
|
| 6233 |
+
}
|
|
|
|
| 6234 |
|
| 6235 |
+
$the_objects = array();
|
| 6236 |
|
| 6237 |
+
$args = array(
|
| 6238 |
+
'post_type' => '_pods_' . $params->type,
|
| 6239 |
+
'nopaging' => true,
|
| 6240 |
+
'posts_per_page' => $limit,
|
| 6241 |
+
'order' => $order,
|
| 6242 |
+
'orderby' => $orderby,
|
| 6243 |
+
'meta_query' => $meta_query,
|
| 6244 |
+
);
|
| 6245 |
|
| 6246 |
+
// Only set post__in if there are ids to filter (see https://core.trac.wordpress.org/ticket/28099)
|
| 6247 |
+
if ( false != $ids ) {
|
| 6248 |
+
$args[ 'post__in' ] = $ids;
|
| 6249 |
+
}
|
| 6250 |
|
| 6251 |
+
$objects = get_posts( $args );
|
|
|
|
| 6252 |
|
| 6253 |
+
foreach ( $objects as $object ) {
|
| 6254 |
+
$object = $this->load_object( $object );
|
| 6255 |
+
|
| 6256 |
+
$the_objects[ $object[ 'name' ] ] = $object;
|
| 6257 |
+
}
|
| 6258 |
+
|
| 6259 |
+
if ( pods_api_cache() && !empty( $cache_key ) )
|
| 6260 |
+
pods_transient_set( $cache_key, $the_objects );
|
| 6261 |
+
|
| 6262 |
+
return $the_objects;
|
| 6263 |
+
}
|
| 6264 |
+
|
| 6265 |
+
/**
|
| 6266 |
+
* @see PodsAPI::load_object
|
| 6267 |
+
*
|
| 6268 |
+
* Load a Pod Template
|
| 6269 |
+
*
|
| 6270 |
+
* $params['id'] int The template ID
|
| 6271 |
+
* $params['name'] string The template name
|
| 6272 |
+
*
|
| 6273 |
+
* @param array $params An associative array of parameters
|
| 6274 |
+
*
|
| 6275 |
+
* @return array|bool
|
| 6276 |
+
* @since 1.7.9
|
| 6277 |
+
*/
|
| 6278 |
+
public function load_template ( $params ) {
|
| 6279 |
+
if ( !class_exists( 'Pods_Templates' ) )
|
| 6280 |
+
return false;
|
| 6281 |
+
|
| 6282 |
+
$params = (object) $params;
|
| 6283 |
+
$params->type = 'template';
|
| 6284 |
+
return $this->load_object( $params );
|
| 6285 |
+
}
|
| 6286 |
+
|
| 6287 |
+
/**
|
| 6288 |
+
* @see PodsAPI::load_objects
|
| 6289 |
+
*
|
| 6290 |
+
* Load Multiple Pod Templates
|
| 6291 |
+
*
|
| 6292 |
+
* $params['where'] string The WHERE clause of query
|
| 6293 |
+
* $params['options'] array Pod Option(s) key=>value array to filter by
|
| 6294 |
+
* $params['orderby'] string ORDER BY clause of query
|
| 6295 |
+
* $params['limit'] string Number of templates to return
|
| 6296 |
+
*
|
| 6297 |
+
* @param array $params (optional) An associative array of parameters
|
| 6298 |
+
*
|
| 6299 |
+
* @return array
|
| 6300 |
+
*
|
| 6301 |
+
* @since 2.0
|
| 6302 |
+
*/
|
| 6303 |
+
public function load_templates ( $params = null ) {
|
| 6304 |
+
if ( !class_exists( 'Pods_Templates' ) )
|
| 6305 |
+
return array();
|
| 6306 |
+
|
| 6307 |
+
$params = (object) $params;
|
| 6308 |
+
$params->type = 'template';
|
| 6309 |
+
return $this->load_objects( $params );
|
| 6310 |
+
}
|
| 6311 |
+
|
| 6312 |
+
/**
|
| 6313 |
+
* @see PodsAPI::load_object
|
| 6314 |
+
*
|
| 6315 |
+
* Load a Pod Page
|
| 6316 |
+
*
|
| 6317 |
+
* $params['id'] int The page ID
|
| 6318 |
+
* $params['name'] string The page URI
|
| 6319 |
+
*
|
| 6320 |
+
* @param array $params An associative array of parameters
|
| 6321 |
+
*
|
| 6322 |
+
* @return array|bool
|
| 6323 |
+
*
|
| 6324 |
+
* @since 1.7.9
|
| 6325 |
+
*/
|
| 6326 |
+
public function load_page ( $params ) {
|
| 6327 |
+
if ( !class_exists( 'Pods_Pages' ) )
|
| 6328 |
+
return false;
|
| 6329 |
+
|
| 6330 |
+
$params = (object) $params;
|
| 6331 |
+
if ( !isset( $params->name ) && isset( $params->uri ) ) {
|
| 6332 |
+
$params->name = $params->uri;
|
| 6333 |
+
unset( $params->uri );
|
| 6334 |
+
}
|
| 6335 |
+
$params->type = 'page';
|
| 6336 |
+
return $this->load_object( $params );
|
| 6337 |
+
}
|
| 6338 |
+
|
| 6339 |
+
/**
|
| 6340 |
+
* @see PodsAPI::load_objects
|
| 6341 |
+
*
|
| 6342 |
+
* Load Multiple Pod Pages
|
| 6343 |
+
*
|
| 6344 |
+
* $params['where'] string The WHERE clause of query
|
| 6345 |
+
* $params['options'] array Pod Option(s) key=>value array to filter by
|
| 6346 |
+
* $params['orderby'] string ORDER BY clause of query
|
| 6347 |
+
* $params['limit'] string Number of pages to return
|
| 6348 |
+
*
|
| 6349 |
+
* @param array $params (optional) An associative array of parameters
|
| 6350 |
+
*
|
| 6351 |
+
* @return array
|
| 6352 |
+
*
|
| 6353 |
+
* @since 2.0
|
| 6354 |
+
*/
|
| 6355 |
+
public function load_pages ( $params = null ) {
|
| 6356 |
+
if ( !class_exists( 'Pods_Pages' ) )
|
| 6357 |
+
return array();
|
| 6358 |
+
|
| 6359 |
+
$params = (object) $params;
|
| 6360 |
+
$params->type = 'page';
|
| 6361 |
+
return $this->load_objects( $params );
|
| 6362 |
+
}
|
| 6363 |
+
|
| 6364 |
+
/**
|
| 6365 |
+
* @see PodsAPI::load_object
|
| 6366 |
+
*
|
| 6367 |
+
* Load a Pod Helper
|
| 6368 |
+
*
|
| 6369 |
+
* $params['id'] int The helper ID
|
| 6370 |
+
* $params['name'] string The helper name
|
| 6371 |
+
*
|
| 6372 |
+
* @param array $params An associative array of parameters
|
| 6373 |
+
*
|
| 6374 |
+
* @return array|bool
|
| 6375 |
+
*
|
| 6376 |
+
* @since 1.7.9
|
| 6377 |
+
*/
|
| 6378 |
+
public function load_helper ( $params ) {
|
| 6379 |
+
if ( !class_exists( 'Pods_Helpers' ) )
|
| 6380 |
+
return false;
|
| 6381 |
+
|
| 6382 |
+
$params = (object) $params;
|
| 6383 |
+
$params->type = 'helper';
|
| 6384 |
+
return $this->load_object( $params );
|
| 6385 |
+
}
|
| 6386 |
+
|
| 6387 |
+
/**
|
| 6388 |
+
* @see PodsAPI::load_objects
|
| 6389 |
+
*
|
| 6390 |
+
* Load Multiple Pod Helpers
|
| 6391 |
+
*
|
| 6392 |
+
* $params['where'] string The WHERE clause of query
|
| 6393 |
+
* $params['options'] array Pod Option(s) key=>value array to filter by
|
| 6394 |
+
* $params['orderby'] string ORDER BY clause of query
|
| 6395 |
+
* $params['limit'] string Number of pages to return
|
| 6396 |
+
*
|
| 6397 |
+
* @param array $params (optional) An associative array of parameters
|
| 6398 |
+
*
|
| 6399 |
+
* @return array
|
| 6400 |
+
*
|
| 6401 |
+
* @since 2.0
|
| 6402 |
+
*/
|
| 6403 |
+
public function load_helpers ( $params = null ) {
|
| 6404 |
+
if ( !class_exists( 'Pods_Helpers' ) )
|
| 6405 |
+
return array();
|
| 6406 |
+
|
| 6407 |
+
$params = (object) $params;
|
| 6408 |
+
$params->type = 'helper';
|
| 6409 |
+
return $this->load_objects( $params );
|
| 6410 |
+
}
|
| 6411 |
+
|
| 6412 |
+
/**
|
| 6413 |
+
* Load the pod item object
|
| 6414 |
+
*
|
| 6415 |
+
* $params['pod'] string The datatype name
|
| 6416 |
+
* $params['id'] int (optional) The item's ID
|
| 6417 |
+
*
|
| 6418 |
+
* @param array $params An associative array of parameters
|
| 6419 |
+
*
|
| 6420 |
+
* @return bool|\Pods
|
| 6421 |
+
*
|
| 6422 |
+
* @uses pods()
|
| 6423 |
+
*
|
| 6424 |
+
* @since 2.0
|
| 6425 |
+
*/
|
| 6426 |
+
public function load_pod_item ( $params ) {
|
| 6427 |
+
$params = (object) pods_sanitize( $params );
|
| 6428 |
+
|
| 6429 |
+
if ( !isset( $params->pod ) || empty( $params->pod ) )
|
| 6430 |
+
return pods_error( __( 'Pod name required', 'pods' ), $this );
|
| 6431 |
+
if ( !isset( $params->id ) || empty( $params->id ) )
|
| 6432 |
+
return pods_error( __( 'Item ID required', 'pods' ), $this );
|
| 6433 |
+
|
| 6434 |
+
$pod = false;
|
| 6435 |
+
|
| 6436 |
+
if ( pods_api_cache() )
|
| 6437 |
+
$pod = pods_cache_get( $params->id, 'pods_item_object_' . $params->pod );
|
| 6438 |
+
|
| 6439 |
+
if ( false !== $pod )
|
| 6440 |
+
return $pod;
|
| 6441 |
+
|
| 6442 |
+
$pod = pods( $params->pod, $params->id );
|
| 6443 |
+
|
| 6444 |
+
if ( pods_api_cache() )
|
| 6445 |
+
pods_cache_set( $params->id, $pod, 'pods_item_object_' . $params->pod );
|
| 6446 |
+
|
| 6447 |
+
return $pod;
|
| 6448 |
+
}
|
| 6449 |
+
|
| 6450 |
+
/**
|
| 6451 |
+
* Load potential sister fields for a specific field
|
| 6452 |
+
*
|
| 6453 |
+
* $params['pod'] int The Pod name
|
| 6454 |
+
* $params['related_pod'] string The related Pod name
|
| 6455 |
+
*
|
| 6456 |
+
* @param array $params An associative array of parameters
|
| 6457 |
+
* @param array $pod (optional) Array of Pod data to use (to avoid lookup)
|
| 6458 |
+
*
|
| 6459 |
+
* @return array|bool
|
| 6460 |
+
*
|
| 6461 |
+
* @since 1.7.9
|
| 6462 |
+
*
|
| 6463 |
+
* @uses PodsAPI::load_pod
|
| 6464 |
+
*/
|
| 6465 |
+
public function load_sister_fields ( $params, $pod = null ) {
|
| 6466 |
+
$params = (object) pods_sanitize( $params );
|
| 6467 |
+
|
| 6468 |
+
if ( empty( $pod ) ) {
|
| 6469 |
+
$pod = $this->load_pod( array( 'name' => $params->pod, 'table_info' => false ), false );
|
| 6470 |
+
|
| 6471 |
+
if ( false === $pod )
|
| 6472 |
+
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
| 6473 |
+
}
|
| 6474 |
+
|
| 6475 |
+
$params->pod_id = $pod[ 'id' ];
|
| 6476 |
+
$params->pod = $pod[ 'name' ];
|
| 6477 |
+
|
| 6478 |
+
$type = false;
|
| 6479 |
+
|
| 6480 |
+
if ( 0 === strpos( $params->related_pod, 'pod-' ) ) {
|
| 6481 |
+
$params->related_pod = pods_str_replace( 'pod-', '', $params->related_pod, 1 );
|
| 6482 |
+
$type = 'pod';
|
| 6483 |
+
}
|
| 6484 |
+
elseif ( 0 === strpos( $params->related_pod, 'post_type-' ) ) {
|
| 6485 |
+
$params->related_pod = pods_str_replace( 'post_type-', '', $params->related_pod, 1 );
|
| 6486 |
+
$type = 'post_type';
|
| 6487 |
+
}
|
| 6488 |
+
elseif ( 0 === strpos( $params->related_pod, 'taxonomy-' ) ) {
|
| 6489 |
+
$params->related_pod = pods_str_replace( 'taxonomy-', '', $params->related_pod, 1 );
|
| 6490 |
+
$type = 'taxonomy';
|
| 6491 |
+
}
|
| 6492 |
+
|
| 6493 |
+
$related_pod = $this->load_pod( array( 'name' => $params->related_pod, 'table_info' => false ), false );
|
| 6494 |
+
|
| 6495 |
+
if ( false === $related_pod || ( false !== $type && 'pod' != $type && $type != $related_pod[ 'type' ] ) )
|
| 6496 |
+
return pods_error( __( 'Related Pod not found', 'pods' ), $this );
|
| 6497 |
+
|
| 6498 |
+
$params->related_pod_id = $related_pod[ 'id' ];
|
| 6499 |
+
$params->related_pod = $related_pod[ 'name' ];
|
| 6500 |
+
|
| 6501 |
+
$sister_fields = array();
|
| 6502 |
+
|
| 6503 |
+
foreach ( $related_pod[ 'fields' ] as $field ) {
|
| 6504 |
+
if ( 'pick' == $field[ 'type' ] && in_array( $field[ 'pick_object' ], array( $pod[ 'type' ], 'pod' ) ) && ( $params->pod == $field[ 'pick_object' ] || $params->pod == $field[ 'pick_val' ] ) )
|
| 6505 |
+
$sister_fields[ $field[ 'id' ] ] = esc_html( $field[ 'label' ] . ' (' . $field[ 'name' ] . ')' );
|
| 6506 |
+
}
|
| 6507 |
+
|
| 6508 |
+
return $sister_fields;
|
| 6509 |
+
}
|
| 6510 |
+
|
| 6511 |
+
/**
|
| 6512 |
+
* Takes a sql field such as tinyint and returns the pods field type, such as num.
|
| 6513 |
+
*
|
| 6514 |
+
* @param string $sql_field The SQL field to look for
|
| 6515 |
+
*
|
| 6516 |
+
* @return string The field type
|
| 6517 |
+
*
|
| 6518 |
+
* @since 2.0
|
| 6519 |
+
*/
|
| 6520 |
+
public static function detect_pod_field_from_sql_data_type ( $sql_field ) {
|
| 6521 |
+
$sql_field = strtolower( $sql_field );
|
| 6522 |
+
|
| 6523 |
+
$field_to_field_map = array(
|
| 6524 |
+
'tinyint' => 'number',
|
| 6525 |
+
'smallint' => 'number',
|
| 6526 |
+
'mediumint' => 'number',
|
| 6527 |
+
'int' => 'number',
|
| 6528 |
+
'bigint' => 'number',
|
| 6529 |
+
'float' => 'number',
|
| 6530 |
+
'double' => 'number',
|
| 6531 |
+
'decimal' => 'number',
|
| 6532 |
+
'date' => 'date',
|
| 6533 |
+
'datetime' => 'datetime',
|
| 6534 |
+
'timestamp' => 'datetime',
|
| 6535 |
+
'time' => 'time',
|
| 6536 |
+
'year' => 'date',
|
| 6537 |
+
'varchar' => 'text',
|
| 6538 |
+
'text' => 'paragraph',
|
| 6539 |
+
'mediumtext' => 'paragraph',
|
| 6540 |
+
'longtext' => 'paragraph'
|
| 6541 |
+
);
|
| 6542 |
+
|
| 6543 |
+
return ( array_key_exists( $sql_field, $field_to_field_map ) ) ? $field_to_field_map[ $sql_field ] : 'paragraph';
|
| 6544 |
+
}
|
| 6545 |
+
|
| 6546 |
+
/**
|
| 6547 |
+
* Gets all field types
|
| 6548 |
+
*
|
| 6549 |
+
* @return array Array of field types
|
| 6550 |
+
*
|
| 6551 |
+
* @uses PodsForm::field_loader
|
| 6552 |
+
*
|
| 6553 |
+
* @since 2.0
|
| 6554 |
+
* @deprecated
|
| 6555 |
+
*/
|
| 6556 |
+
public function get_field_types () {
|
| 6557 |
+
return PodsForm::field_types();
|
| 6558 |
+
}
|
| 6559 |
+
|
| 6560 |
+
/**
|
| 6561 |
+
* Gets the schema definition of a field.
|
| 6562 |
+
*
|
| 6563 |
+
* @param string $type Field type to look for
|
| 6564 |
+
* @param array $options (optional) Options of the field to pass to the schema function.
|
| 6565 |
+
*
|
| 6566 |
+
* @return array|bool|mixed|null
|
| 6567 |
+
*
|
| 6568 |
+
* @since 2.0
|
| 6569 |
+
*/
|
| 6570 |
+
private function get_field_definition ( $type, $options = null ) {
|
| 6571 |
+
$definition = PodsForm::field_method( $type, 'schema', $options );
|
| 6572 |
+
|
| 6573 |
+
return $this->do_hook( 'field_definition', $definition, $type, $options );
|
| 6574 |
+
}
|
| 6575 |
+
|
| 6576 |
+
/**
|
| 6577 |
+
* @see PodsForm:validate
|
| 6578 |
+
*
|
| 6579 |
+
* Validates the value of a field.
|
| 6580 |
+
*
|
| 6581 |
+
* @param mixed $value The value to validate
|
| 6582 |
+
* @param string $field Field to use for validation
|
| 6583 |
+
* @param array $object_fields Fields of the object we're validating
|
| 6584 |
+
* @param array $fields Array of all fields data
|
| 6585 |
+
* @param array|Pods $pod Array of pod data (or Pods object)
|
| 6586 |
+
* @param array|object $params Extra parameters to pass to the validation function of the field.
|
| 6587 |
+
*
|
| 6588 |
+
* @return array|bool
|
| 6589 |
+
*
|
| 6590 |
+
* @uses PodsForm::validate
|
| 6591 |
+
*
|
| 6592 |
+
* @since 2.0
|
| 6593 |
+
*/
|
| 6594 |
+
public function handle_field_validation ( &$value, $field, $object_fields, $fields, $pod, $params ) {
|
| 6595 |
+
$tableless_field_types = PodsForm::tableless_field_types();
|
| 6596 |
+
|
| 6597 |
+
$fields = array_merge( $fields, $object_fields );
|
| 6598 |
+
|
| 6599 |
+
$options = $fields[ $field ];
|
| 6600 |
+
|
| 6601 |
+
$id = ( is_object( $params ) ? $params->id : ( is_object( $pod ) ? $pod->id() : 0 ) );
|
| 6602 |
+
|
| 6603 |
+
if ( is_object( $pod ) )
|
| 6604 |
+
$pod = $pod->pod_data;
|
| 6605 |
+
|
| 6606 |
+
$type = $options[ 'type' ];
|
| 6607 |
+
$label = $options[ 'label' ];
|
| 6608 |
+
$label = empty( $label ) ? $field : $label;
|
| 6609 |
+
|
| 6610 |
+
// Verify required fields
|
| 6611 |
+
if ( 1 == pods_var( 'required', $options[ 'options' ], 0 ) && 'slug' != $type ) {
|
| 6612 |
+
if ( '' == $value || null === $value || array() === $value )
|
| 6613 |
+
return pods_error( sprintf( __( '%s is empty', 'pods' ), $label ), $this );
|
| 6614 |
+
|
| 6615 |
+
if ( 'multi' == pods_var( 'pick_format_type', $options[ 'options' ] ) && 'autocomplete' != pods_var( 'pick_format_multi', $options[ 'options' ] ) ) {
|
| 6616 |
+
$has_value = false;
|
| 6617 |
+
|
| 6618 |
+
$check_value = (array) $value;
|
| 6619 |
+
|
| 6620 |
+
foreach ( $check_value as $val ) {
|
| 6621 |
+
if ( '' != $val && null !== $val && 0 !== $val && '0' !== $val ) {
|
| 6622 |
+
$has_value = true;
|
| 6623 |
+
|
| 6624 |
+
continue;
|
| 6625 |
+
}
|
| 6626 |
+
}
|
| 6627 |
+
|
| 6628 |
+
if ( !$has_value )
|
| 6629 |
+
return pods_error( sprintf( __( '%s is required', 'pods' ), $label ), $this );
|
| 6630 |
+
}
|
| 6631 |
+
|
| 6632 |
+
}
|
| 6633 |
+
|
| 6634 |
+
// @todo move this to after pre-save preparations
|
| 6635 |
+
// Verify unique fields
|
| 6636 |
+
if ( 1 == pods_var( 'unique', $options[ 'options' ], 0 ) && '' !== $value && null !== $value && array() !== $value ) {
|
| 6637 |
+
if ( empty( $pod ) )
|
| 6638 |
+
return false;
|
| 6639 |
+
|
| 6640 |
+
if ( !in_array( $type, $tableless_field_types ) ) {
|
| 6641 |
+
$exclude = '';
|
| 6642 |
+
|
| 6643 |
+
if ( !empty( $id ) )
|
| 6644 |
+
$exclude = "AND `id` != {$id}";
|
| 6645 |
+
|
| 6646 |
+
$check = false;
|
| 6647 |
+
|
| 6648 |
+
$check_value = pods_sanitize( $value );
|
| 6649 |
+
|
| 6650 |
+
// @todo handle meta-based fields
|
| 6651 |
+
// Trigger an error if not unique
|
| 6652 |
+
if ( 'table' == $pod[ 'storage' ] )
|
| 6653 |
+
$check = pods_query( "SELECT `id` FROM `@wp_pods_" . $pod[ 'name' ] . "` WHERE `{$field}` = '{$check_value}' {$exclude} LIMIT 1", $this );
|
| 6654 |
+
|
| 6655 |
+
if ( !empty( $check ) )
|
| 6656 |
+
return pods_error( sprintf( __( '%s needs to be unique', 'pods' ), $label ), $this );
|
| 6657 |
+
}
|
| 6658 |
+
else {
|
| 6659 |
+
// @todo handle tableless check
|
| 6660 |
+
}
|
| 6661 |
+
}
|
| 6662 |
+
|
| 6663 |
+
$validate = PodsForm::validate( $options[ 'type' ], $value, $field, array_merge( $options, pods_var( 'options', $options, array() ) ), $fields, $pod, $id, $params );
|
| 6664 |
+
|
| 6665 |
+
$validate = $this->do_hook( 'field_validation', $validate, $value, $field, $object_fields, $fields, $pod, $params );
|
| 6666 |
+
|
| 6667 |
+
return $validate;
|
| 6668 |
+
}
|
| 6669 |
+
|
| 6670 |
+
/**
|
| 6671 |
+
* Find items related to a parent field
|
| 6672 |
+
*
|
| 6673 |
+
* @param int $field_id The Field ID
|
| 6674 |
+
* @param int $pod_id The Pod ID
|
| 6675 |
+
* @param mixed $ids A comma-separated string (or array) of item IDs
|
| 6676 |
+
* @param array $field Field data array
|
| 6677 |
+
* @param array $pod Pod data array
|
| 6678 |
+
*
|
| 6679 |
+
* @return array
|
| 6680 |
+
*
|
| 6681 |
+
* @since 2.0
|
| 6682 |
+
*
|
| 6683 |
+
* @uses pods_query()
|
| 6684 |
+
*/
|
| 6685 |
+
public function lookup_related_items ( $field_id, $pod_id, $ids, $field = null, $pod = null ) {
|
| 6686 |
+
$related_ids = array();
|
| 6687 |
|
| 6688 |
+
if ( !is_array( $ids ) )
|
| 6689 |
+
$ids = explode( ',', $ids );
|
| 6690 |
|
| 6691 |
+
foreach ( $ids as $k => $id ) {
|
| 6692 |
+
$ids[ $k ] = (int) $id;
|
| 6693 |
+
}
|
| 6694 |
|
| 6695 |
+
$ids = array_unique( array_filter( $ids ) );
|
|
|
|
| 6696 |
|
| 6697 |
+
$idstring = implode( ',', $ids );
|
| 6698 |
+
if ( 0 != $pod_id && 0 != $field_id && isset( self::$related_item_cache[ $pod_id ][ $field_id ][ $idstring ] ) ) {
|
| 6699 |
+
// Check cache first, no point in running the same query multiple times
|
| 6700 |
+
return self::$related_item_cache[ $pod_id ][ $field_id ][ $idstring ];
|
| 6701 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6702 |
|
| 6703 |
+
$tableless_field_types = PodsForm::tableless_field_types();
|
|
|
|
|
|
|
|
|
|
| 6704 |
|
| 6705 |
+
$field_type = pods_v( 'type', $field );
|
|
|
|
| 6706 |
|
| 6707 |
+
if ( empty( $ids ) || !in_array( $field_type, $tableless_field_types ) )
|
| 6708 |
+
return array();
|
|
|
|
| 6709 |
|
| 6710 |
+
$related_pick_limit = 0;
|
|
|
|
|
|
|
| 6711 |
|
| 6712 |
+
if ( empty( $field ) ) {
|
| 6713 |
+
$field = $this->load_field( array( 'id' => $field_id ) );
|
|
|
|
|
|
|
|
|
|
| 6714 |
}
|
| 6715 |
|
| 6716 |
+
if ( !empty( $field ) ) {
|
| 6717 |
+
$options = (array) pods_var_raw( 'options', $field, $field, null, true );
|
|
|
|
| 6718 |
|
| 6719 |
+
$related_pick_limit = (int) pods_v( $field_type . '_limit', $options, 0 );
|
|
|
|
| 6720 |
|
| 6721 |
+
if ( 'single' == pods_var_raw( $field_type . '_format_type', $options ) )
|
| 6722 |
+
$related_pick_limit = 1;
|
| 6723 |
|
| 6724 |
+
// Temporary hack until there's some better handling here
|
| 6725 |
+
$related_pick_limit = $related_pick_limit * count( $ids );
|
| 6726 |
+
}
|
| 6727 |
|
| 6728 |
+
if ( 'taxonomy' == $field_type ) {
|
| 6729 |
+
$related = wp_get_object_terms( $ids, pods_v( 'name', $field ), array( 'fields' => 'ids' ) );
|
| 6730 |
+
|
| 6731 |
+
if ( !is_wp_error( $related ) ) {
|
| 6732 |
+
$related_ids = $related;
|
| 6733 |
+
}
|
| 6734 |
+
}
|
| 6735 |
+
elseif ( !pods_tableless() ) {
|
| 6736 |
+
$ids = implode( ', ', $ids );
|
| 6737 |
+
|
| 6738 |
+
$field_id = (int) $field_id;
|
| 6739 |
+
$sister_id = (int) pods_var_raw( 'sister_id', $field, 0 );
|
| 6740 |
+
|
| 6741 |
+
$related_where = "
|
| 6742 |
+
`field_id` = {$field_id}
|
| 6743 |
+
AND `item_id` IN ( {$ids} )
|
| 6744 |
+
";
|
| 6745 |
+
|
| 6746 |
+
$sql = "
|
| 6747 |
+
SELECT item_id, related_item_id, related_field_id
|
| 6748 |
+
FROM `@wp_podsrel`
|
| 6749 |
+
WHERE
|
| 6750 |
+
{$related_where}
|
| 6751 |
+
ORDER BY `weight`
|
| 6752 |
+
";
|
| 6753 |
+
|
| 6754 |
+
$relationships = pods_query( $sql );
|
| 6755 |
+
|
| 6756 |
+
if ( !empty( $relationships ) ) {
|
| 6757 |
+
foreach ( $relationships as $relation ) {
|
| 6758 |
+
if ( !in_array( $relation->related_item_id, $related_ids ) )
|
| 6759 |
+
$related_ids[] = (int) $relation->related_item_id;
|
| 6760 |
+
elseif ( 0 < $sister_id && $field_id == $relation->related_field_id && !in_array( $relation->item_id, $related_ids ) )
|
| 6761 |
+
$related_ids[] = (int) $relation->item_id;
|
| 6762 |
+
}
|
| 6763 |
+
}
|
| 6764 |
+
}
|
| 6765 |
+
else {
|
| 6766 |
+
if ( !is_array( $pod ) )
|
| 6767 |
+
$pod = $this->load_pod( array( 'id' => $pod_id, 'table_info' => false ), false );
|
| 6768 |
+
|
| 6769 |
+
if ( !empty( $pod ) && in_array( $pod[ 'type' ], array( 'post_type', 'media', 'user', 'comment', 'settings' ) ) ) {
|
| 6770 |
+
$meta_type = $pod[ 'type' ];
|
| 6771 |
+
|
| 6772 |
+
if ( in_array( $pod[ 'type' ], array( 'post_type', 'media' ) ) )
|
| 6773 |
+
$meta_type = 'post';
|
| 6774 |
+
|
| 6775 |
+
$no_conflict = pods_no_conflict_check( $meta_type );
|
| 6776 |
+
|
| 6777 |
+
if ( !$no_conflict )
|
| 6778 |
+
pods_no_conflict_on( $meta_type );
|
| 6779 |
+
|
| 6780 |
+
foreach ( $ids as $id ) {
|
| 6781 |
+
if ( 'settings' == $meta_type ) {
|
| 6782 |
+
$related_id = get_option( '_pods_' . $pod[ 'name' ] . '_' . $field[ 'name' ] );
|
| 6783 |
+
|
| 6784 |
+
if ( empty( $related_id ) )
|
| 6785 |
+
$related_id = get_option( $pod[ 'name' ] . '_' . $field[ 'name' ] );
|
| 6786 |
+
|
| 6787 |
+
if ( is_array( $related_id ) && !empty( $related_id ) ) {
|
| 6788 |
+
foreach ( $related_id as $related ) {
|
| 6789 |
+
if ( is_array( $related ) && !empty( $related ) ) {
|
| 6790 |
+
if ( isset( $related[ 'id' ] ) )
|
| 6791 |
+
$related_ids[] = (int) $related[ 'id' ];
|
| 6792 |
+
else {
|
| 6793 |
+
foreach ( $related as $r ) {
|
| 6794 |
+
$related_ids[] = (int) $r;
|
| 6795 |
+
}
|
| 6796 |
+
}
|
| 6797 |
+
}
|
| 6798 |
+
else
|
| 6799 |
+
$related_ids[] = (int) $related;
|
| 6800 |
+
}
|
| 6801 |
+
}
|
| 6802 |
+
}
|
| 6803 |
+
else {
|
| 6804 |
+
$related_id = get_metadata( $meta_type, $id, '_pods_' . $field[ 'name' ], true );
|
| 6805 |
+
|
| 6806 |
+
if ( empty( $related_id ) )
|
| 6807 |
+
$related_id = get_metadata( $meta_type, $id, $field[ 'name' ] );
|
| 6808 |
+
|
| 6809 |
+
if ( is_array( $related_id ) && !empty( $related_id ) ) {
|
| 6810 |
+
foreach ( $related_id as $related ) {
|
| 6811 |
+
if ( is_array( $related ) && !empty( $related ) ) {
|
| 6812 |
+
if ( isset( $related[ 'id' ] ) )
|
| 6813 |
+
$related_ids[] = (int) $related[ 'id' ];
|
| 6814 |
+
else {
|
| 6815 |
+
foreach ( $related as $r ) {
|
| 6816 |
+
if ( isset( $related[ 'id' ] ) )
|
| 6817 |
+
$related_ids[] = (int) $r[ 'id' ];
|
| 6818 |
+
else
|
| 6819 |
+
$related_ids[] = (int) $r;
|
| 6820 |
+
}
|
| 6821 |
+
}
|
| 6822 |
+
}
|
| 6823 |
+
else
|
| 6824 |
+
$related_ids[] = (int) $related;
|
| 6825 |
+
}
|
| 6826 |
+
}
|
| 6827 |
+
}
|
| 6828 |
+
}
|
| 6829 |
+
|
| 6830 |
+
if ( !$no_conflict )
|
| 6831 |
+
pods_no_conflict_off( $meta_type );
|
| 6832 |
+
}
|
| 6833 |
+
}
|
| 6834 |
+
|
| 6835 |
+
if ( is_array( $related_ids ) ) {
|
| 6836 |
+
$related_ids = array_unique( array_filter( $related_ids ) );
|
| 6837 |
+
|
| 6838 |
+
if ( 0 < $related_pick_limit && !empty( $related_ids ) )
|
| 6839 |
+
$related_ids = array_slice( $related_ids, 0, $related_pick_limit );
|
| 6840 |
+
}
|
| 6841 |
+
if ( 0 != $pod_id && 0 != $field_id && ! empty( $related_ids ) ) {
|
| 6842 |
+
// Only cache if $pod_id and $field_id were passed
|
| 6843 |
+
self::$related_item_cache[ $pod_id ][ $field_id ][ $idstring ] = $related_ids;
|
| 6844 |
+
}
|
| 6845 |
+
|
| 6846 |
+
return $related_ids;
|
| 6847 |
+
}
|
| 6848 |
+
|
| 6849 |
+
/**
|
| 6850 |
+
* Find related items related to an item
|
| 6851 |
+
*
|
| 6852 |
+
* @param int $field_id The Field ID
|
| 6853 |
+
* @param int $pod_id The Pod ID
|
| 6854 |
+
* @param int $id Item ID to get related IDs from
|
| 6855 |
+
* @param array $field Field data array
|
| 6856 |
+
* @param array $pod Pod data array
|
| 6857 |
+
*
|
| 6858 |
+
* @return array|bool
|
| 6859 |
+
*
|
| 6860 |
+
* @since 2.3
|
| 6861 |
+
*
|
| 6862 |
+
* @uses pods_query()
|
| 6863 |
+
*/
|
| 6864 |
+
public function lookup_related_items_from ( $field_id, $pod_id, $id, $field = null, $pod = null ) {
|
| 6865 |
+
$related_ids = false;
|
| 6866 |
+
|
| 6867 |
+
$id = (int) $id;
|
| 6868 |
+
|
| 6869 |
+
$tableless_field_types = PodsForm::tableless_field_types();
|
| 6870 |
+
|
| 6871 |
+
if ( empty( $id ) || !in_array( pods_v( 'type', $field ), $tableless_field_types ) )
|
| 6872 |
+
return false;
|
| 6873 |
+
|
| 6874 |
+
$related_pick_limit = 0;
|
| 6875 |
+
|
| 6876 |
+
if ( !empty( $field ) ) {
|
| 6877 |
+
$options = (array) pods_var_raw( 'options', $field, $field, null, true );
|
| 6878 |
+
|
| 6879 |
+
$related_pick_limit = (int) pods_v( 'pick_limit', $options, 0 );
|
| 6880 |
+
|
| 6881 |
+
if ( 'single' == pods_var_raw( 'pick_format_type', $options ) )
|
| 6882 |
+
$related_pick_limit = 1;
|
| 6883 |
+
}
|
| 6884 |
+
|
| 6885 |
+
if ( !pods_tableless() ) {
|
| 6886 |
+
$field_id = (int) $field_id;
|
| 6887 |
+
$sister_id = (int) pods_var_raw( 'sister_id', $field, 0 );
|
| 6888 |
+
|
| 6889 |
+
$related_where = "
|
| 6890 |
+
`field_id` = {$field_id}
|
| 6891 |
+
AND `related_item_id` = {$id}
|
| 6892 |
+
";
|
| 6893 |
+
|
| 6894 |
+
$sql = "
|
| 6895 |
+
SELECT *
|
| 6896 |
+
FROM `@wp_podsrel`
|
| 6897 |
+
WHERE
|
| 6898 |
+
{$related_where}
|
| 6899 |
+
ORDER BY `weight`
|
| 6900 |
+
";
|
| 6901 |
+
|
| 6902 |
+
$relationships = pods_query( $sql );
|
| 6903 |
+
|
| 6904 |
+
if ( !empty( $relationships ) ) {
|
| 6905 |
+
$related_ids = array();
|
| 6906 |
+
|
| 6907 |
+
foreach ( $relationships as $relation ) {
|
| 6908 |
+
if ( $field_id == $relation->field_id && !in_array( $relation->item_id, $related_ids ) )
|
| 6909 |
+
$related_ids[] = (int) $relation->item_id;
|
| 6910 |
+
elseif ( 0 < $sister_id && $field_id == $relation->related_field_id && !in_array( $relation->related_item_id, $related_ids ) )
|
| 6911 |
+
$related_ids[] = (int) $relation->related_item_id;
|
| 6912 |
+
}
|
| 6913 |
+
}
|
| 6914 |
+
}
|
| 6915 |
+
else {
|
| 6916 |
+
// @todo handle meta-based lookups
|
| 6917 |
+
return false;
|
| 6918 |
+
|
| 6919 |
+
if ( !is_array( $pod ) )
|
| 6920 |
+
$pod = $this->load_pod( array( 'id' => $pod_id, 'table_info' => false ), false );
|
| 6921 |
+
|
| 6922 |
+
if ( !empty( $pod ) && in_array( $pod[ 'type' ], array( 'post_type', 'media', 'user', 'comment', 'settings' ) ) ) {
|
| 6923 |
+
$related_ids = array();
|
| 6924 |
+
|
| 6925 |
+
$meta_type = $pod[ 'type' ];
|
| 6926 |
+
|
| 6927 |
+
if ( in_array( $pod[ 'type' ], array( 'post_type', 'media' ) ) )
|
| 6928 |
+
$meta_type = 'post';
|
| 6929 |
+
|
| 6930 |
+
$no_conflict = pods_no_conflict_check( $meta_type );
|
| 6931 |
+
|
| 6932 |
+
if ( !$no_conflict )
|
| 6933 |
+
pods_no_conflict_on( $meta_type );
|
| 6934 |
+
|
| 6935 |
+
if ( 'settings' == $meta_type ) {
|
| 6936 |
+
$related_id = get_option( '_pods_' . $pod[ 'name' ] . '_' . $field[ 'name' ] );
|
| 6937 |
+
|
| 6938 |
+
if ( empty( $related_id ) )
|
| 6939 |
+
$related_id = get_option( $pod[ 'name' ] . '_' . $field[ 'name' ] );
|
| 6940 |
+
|
| 6941 |
+
if ( is_array( $related_id ) && !empty( $related_id ) ) {
|
| 6942 |
+
foreach ( $related_id as $related ) {
|
| 6943 |
+
if ( is_array( $related ) && !empty( $related ) ) {
|
| 6944 |
+
if ( isset( $related[ 'id' ] ) )
|
| 6945 |
+
$related_ids[] = (int) $related[ 'id' ];
|
| 6946 |
+
else {
|
| 6947 |
+
foreach ( $related as $r ) {
|
| 6948 |
+
$related_ids[] = (int) $r;
|
| 6949 |
+
}
|
| 6950 |
+
}
|
| 6951 |
+
}
|
| 6952 |
+
else
|
| 6953 |
+
$related_ids[] = (int) $related;
|
| 6954 |
+
}
|
| 6955 |
+
}
|
| 6956 |
+
}
|
| 6957 |
+
else {
|
| 6958 |
+
$related_id = get_metadata( $meta_type, $id, '_pods_' . $field[ 'name' ], true );
|
| 6959 |
+
|
| 6960 |
+
if ( empty( $related_id ) )
|
| 6961 |
+
$related_id = get_metadata( $meta_type, $id, $field[ 'name' ] );
|
| 6962 |
+
|
| 6963 |
+
if ( is_array( $related_id ) && !empty( $related_id ) ) {
|
| 6964 |
+
foreach ( $related_id as $related ) {
|
| 6965 |
+
if ( is_array( $related ) && !empty( $related ) ) {
|
| 6966 |
+
if ( isset( $related[ 'id' ] ) )
|
| 6967 |
+
$related_ids[] = (int) $related[ 'id' ];
|
| 6968 |
+
else {
|
| 6969 |
+
foreach ( $related as $r ) {
|
| 6970 |
+
if ( isset( $related[ 'id' ] ) )
|
| 6971 |
+
$related_ids[] = (int) $r[ 'id' ];
|
| 6972 |
+
else
|
| 6973 |
+
$related_ids[] = (int) $r;
|
| 6974 |
+
}
|
| 6975 |
+
}
|
| 6976 |
+
}
|
| 6977 |
+
else
|
| 6978 |
+
$related_ids[] = (int) $related;
|
| 6979 |
+
}
|
| 6980 |
+
}
|
| 6981 |
+
}
|
| 6982 |
+
|
| 6983 |
+
if ( !$no_conflict )
|
| 6984 |
+
pods_no_conflict_off( $meta_type );
|
| 6985 |
+
}
|
| 6986 |
+
}
|
| 6987 |
+
|
| 6988 |
+
if ( is_array( $related_ids ) )
|
| 6989 |
+
$related_ids = array_unique( array_filter( $related_ids ) );
|
| 6990 |
+
|
| 6991 |
+
return $related_ids;
|
| 6992 |
+
}
|
| 6993 |
|
| 6994 |
/**
|
|
|
|
| 6995 |
*
|
| 6996 |
+
* Load the information about an objects MySQL table
|
| 6997 |
+
*
|
| 6998 |
+
* @param $object_type
|
| 6999 |
+
* @param string $object The object to look for
|
| 7000 |
+
* @param null $name (optional) Name of the pod to load
|
| 7001 |
+
* @param array $pod (optional) Array with pod information
|
| 7002 |
*
|
| 7003 |
+
* @return array
|
| 7004 |
*
|
| 7005 |
+
* @since 2.5
|
| 7006 |
*/
|
| 7007 |
+
public function get_table_info_load ( $object_type, $object, $name = null, $pod = null ) {
|
| 7008 |
+
|
| 7009 |
+
$info = array();
|
| 7010 |
|
| 7011 |
+
if ( 'pod' == $object_type && null === $pod ) {
|
| 7012 |
+
if ( empty( $name ) ) {
|
| 7013 |
+
$prefix = 'pod-';
|
| 7014 |
|
| 7015 |
+
// Make sure we actually have the prefix before trying anything with the name
|
| 7016 |
+
if ( 0 === strpos( $object_type, $prefix ) )
|
| 7017 |
+
$name = substr( $object_type, strlen( $prefix ), strlen( $object_type ) );
|
| 7018 |
+
}
|
| 7019 |
|
| 7020 |
+
if ( empty( $name ) && !empty( $object ) )
|
| 7021 |
+
$name = $object;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7022 |
|
| 7023 |
+
$pod = $this->load_pod( array( 'name' => $name, 'table_info' => false ), false );
|
|
|
|
|
|
|
|
|
|
| 7024 |
|
| 7025 |
+
if ( !empty( $pod ) ) {
|
| 7026 |
+
$object_type = $pod[ 'type' ];
|
| 7027 |
+
$name = $pod[ 'name' ];
|
| 7028 |
+
$object = $pod[ 'object' ];
|
|
|
|
|
|
|
| 7029 |
|
| 7030 |
+
$info[ 'pod' ] = $pod;
|
| 7031 |
+
}
|
| 7032 |
}
|
| 7033 |
+
elseif ( null === $pod ) {
|
| 7034 |
+
if ( empty( $name ) ) {
|
| 7035 |
+
$prefix = $object_type . '-';
|
| 7036 |
|
| 7037 |
+
// Make sure we actually have the prefix before trying anything with the name
|
| 7038 |
+
if ( 0 === strpos( $object_type, $prefix ) )
|
| 7039 |
+
$name = substr( $object_type, strlen( $prefix ), strlen( $object_type ) );
|
| 7040 |
+
}
|
| 7041 |
|
| 7042 |
+
if ( empty( $name ) && !empty( $object ) )
|
| 7043 |
+
$name = $object;
|
|
|
|
| 7044 |
|
| 7045 |
+
if ( !empty( $name ) ) {
|
| 7046 |
+
$pod = $this->load_pod( array( 'name' => $name, 'table_info' => false ), false );
|
| 7047 |
|
| 7048 |
+
if ( !empty( $pod ) && ( null === $object_type || $object_type == $pod[ 'type' ] ) ) {
|
| 7049 |
+
$object_type = $pod[ 'type' ];
|
| 7050 |
+
$name = $pod[ 'name' ];
|
| 7051 |
+
$object = $pod[ 'object' ];
|
| 7052 |
|
| 7053 |
+
$info[ 'pod' ] = $pod;
|
| 7054 |
+
}
|
| 7055 |
+
}
|
| 7056 |
}
|
| 7057 |
+
elseif ( !empty( $pod ) )
|
| 7058 |
+
$info[ 'pod' ] = $pod;
|
| 7059 |
|
| 7060 |
+
if ( 0 === strpos( $object_type, 'pod' ) ) {
|
| 7061 |
+
if ( empty( $name ) ) {
|
| 7062 |
+
$prefix = 'pod-';
|
| 7063 |
|
| 7064 |
+
// Make sure we actually have the prefix before trying anything with the name
|
| 7065 |
+
if ( 0 === strpos( $object_type, $prefix ) )
|
| 7066 |
+
$name = substr( $object_type, strlen( $prefix ), strlen( $object_type ) );
|
| 7067 |
+
}
|
| 7068 |
|
| 7069 |
+
$info[ 'type' ] = 'pod';
|
| 7070 |
+
global $wpdb;
|
|
|
|
| 7071 |
|
| 7072 |
+
$info[ 'table' ] = $info[ 'meta_table' ] = $wpdb->prefix . 'pods_' . ( empty( $object ) ? $name : $object );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7073 |
|
| 7074 |
+
if ( is_array( $info[ 'pod' ] ) && 'pod' == pods_v( 'type', $info[ 'pod' ] ) ) {
|
| 7075 |
+
$info[ 'pod_field_index' ] = $info[ 'field_index' ] = $info[ 'meta_field_index' ] = $info[ 'meta_field_value' ] = pods_v( 'pod_index', $info[ 'pod' ][ 'options' ], 'id', true );
|
| 7076 |
|
| 7077 |
+
$slug_field = get_posts( array(
|
| 7078 |
+
'post_type' => '_pods_field',
|
| 7079 |
+
'posts_per_page' => 1,
|
| 7080 |
+
'nopaging' => true,
|
| 7081 |
+
'post_parent' => $info[ 'pod' ][ 'id' ],
|
| 7082 |
+
'orderby' => 'menu_order',
|
| 7083 |
+
'order' => 'ASC',
|
| 7084 |
+
'meta_query' => array(
|
| 7085 |
+
array(
|
| 7086 |
+
'key' => 'type',
|
| 7087 |
+
'value' => 'slug',
|
| 7088 |
+
)
|
| 7089 |
+
)
|
| 7090 |
+
) );
|
| 7091 |
|
| 7092 |
+
if ( !empty( $slug_field ) ) {
|
| 7093 |
+
$slug_field = $slug_field[ 0 ];
|
|
|
|
|
|
|
| 7094 |
|
| 7095 |
+
$info[ 'field_slug' ] = $info[ 'pod_field_slug' ] = $slug_field->post_name;
|
| 7096 |
+
}
|
|
|
|
| 7097 |
|
| 7098 |
+
if ( 1 == pods_v( 'hierarchical', $info[ 'pod' ][ 'options' ], 0 ) ) {
|
| 7099 |
+
$parent_field = pods_v( 'pod_parent', $info[ 'pod' ][ 'options' ], 'id', true );
|
| 7100 |
|
| 7101 |
+
if ( !empty( $parent_field ) && isset( $info[ 'pod' ][ 'fields' ][ $parent_field ] ) ) {
|
| 7102 |
+
$info[ 'object_hierarchical' ] = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7103 |
|
| 7104 |
+
$info[ 'pod_field_parent' ] = $info[ 'field_parent' ] = $parent_field . '_select';
|
| 7105 |
+
$info[ 'field_parent_select' ] = '`' . $parent_field . '`.`id` AS `' . $info[ 'field_parent' ] . '`';
|
| 7106 |
+
}
|
| 7107 |
+
}
|
| 7108 |
+
}
|
| 7109 |
}
|
| 7110 |
+
return $info;
|
|
|
|
|
|
|
| 7111 |
}
|
| 7112 |
|
| 7113 |
+
/**
|
| 7114 |
+
* Get information about an objects MySQL table
|
| 7115 |
+
*
|
| 7116 |
+
* @param string $object_type
|
| 7117 |
+
* @param string $object The object to look for
|
| 7118 |
+
* @param null $name (optional) Name of the pod to load
|
| 7119 |
+
* @param array $pod (optional) Array with pod information
|
| 7120 |
+
* @param array $field (optional) Array with field information
|
| 7121 |
+
*
|
| 7122 |
+
* @return array|bool
|
| 7123 |
+
*
|
| 7124 |
+
* @since 2.0
|
| 7125 |
+
*/
|
| 7126 |
+
public function get_table_info ( $object_type, $object, $name = null, $pod = null, $field = null ) {
|
| 7127 |
+
/**
|
| 7128 |
+
* @var $wpdb wpdb
|
| 7129 |
+
* @var $sitepress SitePress
|
| 7130 |
+
* @var $icl_adjust_id_url_filter_off boolean
|
| 7131 |
+
*/
|
| 7132 |
+
global $wpdb, $sitepress, $icl_adjust_id_url_filter_off, $polylang;
|
| 7133 |
|
| 7134 |
+
// @todo Handle $object arrays for Post Types, Taxonomies, Comments (table pulled from first object in array)
|
| 7135 |
|
| 7136 |
+
$info = array(
|
| 7137 |
+
//'select' => '`t`.*',
|
| 7138 |
+
'object_type' => $object_type,
|
| 7139 |
+
'type' => null,
|
| 7140 |
+
'object_name' => $object,
|
| 7141 |
+
'object_hierarchical' => false,
|
| 7142 |
+
|
| 7143 |
+
'table' => $object,
|
| 7144 |
+
'meta_table' => $object,
|
| 7145 |
+
'pod_table' => $wpdb->prefix . 'pods_' . ( empty( $object ) ? $name : $object ),
|
| 7146 |
+
|
| 7147 |
+
'field_id' => 'id',
|
| 7148 |
+
'field_index' => 'name',
|
| 7149 |
+
'field_slug' => null,
|
| 7150 |
+
'field_type' => null,
|
| 7151 |
+
'field_parent' => null,
|
| 7152 |
+
'field_parent_select' => null,
|
| 7153 |
+
|
| 7154 |
+
'meta_field_id' => 'id',
|
| 7155 |
+
'meta_field_index' => 'name',
|
| 7156 |
+
'meta_field_value' => 'name',
|
| 7157 |
+
|
| 7158 |
+
'pod_field_id' => 'id',
|
| 7159 |
+
'pod_field_index' => 'name',
|
| 7160 |
+
'pod_field_slug' => null,
|
| 7161 |
+
'pod_field_parent' => null,
|
| 7162 |
+
|
| 7163 |
+
'join' => array(),
|
| 7164 |
+
|
| 7165 |
+
'where' => null,
|
| 7166 |
+
'where_default' => null,
|
| 7167 |
+
|
| 7168 |
+
'orderby' => null,
|
| 7169 |
+
|
| 7170 |
+
'pod' => null,
|
| 7171 |
+
'recurse' => false
|
| 7172 |
+
);
|
| 7173 |
+
|
| 7174 |
+
if ( empty( $object_type ) ) {
|
| 7175 |
+
$object_type = 'post_type';
|
| 7176 |
+
$object = 'post';
|
| 7177 |
+
}
|
| 7178 |
+
elseif ( empty( $object ) && in_array( $object_type, array( 'user', 'media', 'comment' ) ) ) {
|
| 7179 |
+
$object = $object_type;
|
| 7180 |
+
}
|
| 7181 |
+
|
| 7182 |
+
$pod_name = $pod;
|
| 7183 |
+
|
| 7184 |
+
if ( is_array( $pod_name ) )
|
| 7185 |
+
$pod_name = pods_var_raw( 'name', $pod_name, ( version_compare( PHP_VERSION, '5.4.0', '>=' ) ? json_encode( $pod_name, JSON_UNESCAPED_UNICODE ) : json_encode( $pod_name ) ), null, true );
|
| 7186 |
+
else {
|
| 7187 |
+
$pod_name = $object;
|
| 7188 |
+
}
|
| 7189 |
+
|
| 7190 |
+
$field_name = $field;
|
| 7191 |
+
|
| 7192 |
+
if ( is_array( $field_name ) )
|
| 7193 |
+
$field_name = pods_var_raw( 'name', $field_name, ( version_compare( PHP_VERSION, '5.4.0', '>=' ) ? json_encode( $pod_name, JSON_UNESCAPED_UNICODE ) : json_encode( $field_name ) ), null, true );
|
| 7194 |
+
|
| 7195 |
+
$transient = 'pods_' . $wpdb->prefix . '_get_table_info_' . md5( $object_type . '_object_' . $object . '_name_' . $name . '_pod_' . $pod_name . '_field_' . $field_name );
|
| 7196 |
+
|
| 7197 |
+
$current_language = false;
|
| 7198 |
+
$current_language_t_id = $current_language_tt_id = 0;
|
| 7199 |
+
|
| 7200 |
+
// WPML support
|
| 7201 |
+
if ( is_object( $sitepress ) && !$icl_adjust_id_url_filter_off )
|
| 7202 |
+
$current_language = pods_sanitize( ICL_LANGUAGE_CODE );
|
| 7203 |
+
// Polylang support
|
| 7204 |
+
elseif ( is_object( $polylang ) && function_exists( 'pll_current_language' ) ) {
|
| 7205 |
+
$current_language = pods_sanitize( pll_current_language( 'slug' ) );
|
| 7206 |
+
|
| 7207 |
+
if ( !empty( $current_language ) ) {
|
| 7208 |
+
$current_language_t_id = (int) $polylang->get_language( $current_language )->term_id;
|
| 7209 |
+
$current_language_tt_id = (int) $polylang->get_language( $current_language )->term_taxonomy_id;
|
| 7210 |
+
}
|
| 7211 |
+
}
|
| 7212 |
+
|
| 7213 |
+
if ( !empty( $current_language ) )
|
| 7214 |
+
$transient = 'pods_' . $wpdb->prefix . '_get_table_info_' . $current_language . '_' . md5( $object_type . '_object_' . $object . '_name_' . $name . '_pod_' . $pod_name . '_field_' . $field_name );
|
| 7215 |
+
|
| 7216 |
+
$_info = false;
|
| 7217 |
+
|
| 7218 |
+
if ( isset( self::$table_info_cache[ $transient ] ) ) {
|
| 7219 |
+
// Prefer info from the object internal cache
|
| 7220 |
+
$_info = self::$table_info_cache[ $transient ];
|
| 7221 |
+
} elseif ( pods_api_cache() ) {
|
| 7222 |
+
$_info = pods_transient_get( $transient );
|
| 7223 |
+
if ( false === $_info && ! did_action( 'init' ) ) {
|
| 7224 |
+
$_info = pods_transient_get( $transient . '_pre_init' );
|
| 7225 |
+
}
|
| 7226 |
+
}
|
| 7227 |
+
|
| 7228 |
+
if ( false !== $_info ) {
|
| 7229 |
+
// Data was cached, use that
|
| 7230 |
+
$info = $_info;
|
| 7231 |
+
} else {
|
| 7232 |
+
// Data not cached, load it up
|
| 7233 |
+
$_info = $this->get_table_info_load( $object_type, $object, $name, $pod );
|
| 7234 |
+
if ( isset( $_info[ 'type' ] ) ) {
|
| 7235 |
+
// Allow function to override $object_type
|
| 7236 |
+
$object_type = $_info[ 'type' ];
|
| 7237 |
+
}
|
| 7238 |
+
$info = array_merge( $info, $_info );
|
| 7239 |
+
}
|
| 7240 |
+
|
| 7241 |
+
if ( 0 === strpos( $object_type, 'post_type' ) || 'media' == $object_type || in_array( pods_var_raw( 'type', $info[ 'pod' ] ), array( 'post_type', 'media' ) ) ) {
|
| 7242 |
+
$info[ 'table' ] = $wpdb->posts;
|
| 7243 |
+
$info[ 'meta_table' ] = $wpdb->postmeta;
|
| 7244 |
+
|
| 7245 |
+
$info[ 'field_id' ] = 'ID';
|
| 7246 |
+
$info[ 'field_index' ] = 'post_title';
|
| 7247 |
+
$info[ 'field_slug' ] = 'post_name';
|
| 7248 |
+
$info[ 'field_type' ] = 'post_type';
|
| 7249 |
+
$info[ 'field_parent' ] = 'post_parent';
|
| 7250 |
+
$info[ 'field_parent_select' ] = '`t`.`' . $info[ 'field_parent' ] . '`';
|
| 7251 |
+
|
| 7252 |
+
$info[ 'meta_field_id' ] = 'post_id';
|
| 7253 |
+
$info[ 'meta_field_index' ] = 'meta_key';
|
| 7254 |
+
$info[ 'meta_field_value' ] = 'meta_value';
|
| 7255 |
+
|
| 7256 |
+
if ( 'media' == $object_type )
|
| 7257 |
+
$object = 'attachment';
|
| 7258 |
+
|
| 7259 |
+
if ( empty( $name ) ) {
|
| 7260 |
+
$prefix = 'post_type-';
|
| 7261 |
+
|
| 7262 |
+
// Make sure we actually have the prefix before trying anything with the name
|
| 7263 |
+
if ( 0 === strpos( $object_type, $prefix ) )
|
| 7264 |
+
$name = substr( $object_type, strlen( $prefix ), strlen( $object_type ) );
|
| 7265 |
+
}
|
| 7266 |
+
|
| 7267 |
+
if ( 'media' != $object_type )
|
| 7268 |
+
$object_type = 'post_type';
|
| 7269 |
+
|
| 7270 |
+
$post_type = pods_sanitize( ( empty( $object ) ? $name : $object ) );
|
| 7271 |
+
|
| 7272 |
+
if ( 'attachment' == $post_type || 'media' == $object_type )
|
| 7273 |
+
$info[ 'pod_table' ] = $wpdb->prefix . 'pods_media';
|
| 7274 |
+
else
|
| 7275 |
+
$info[ 'pod_table' ] = $wpdb->prefix . 'pods_' . pods_clean_name( $post_type, true, false );
|
| 7276 |
+
|
| 7277 |
+
$post_type_object = get_post_type_object( $post_type );
|
| 7278 |
+
|
| 7279 |
+
if ( is_object( $post_type_object ) && $post_type_object->hierarchical )
|
| 7280 |
+
$info[ 'object_hierarchical' ] = true;
|
| 7281 |
+
|
| 7282 |
+
/**
|
| 7283 |
+
* Default Post Status to query for.
|
| 7284 |
+
*
|
| 7285 |
+
* Use to change "default" post status from publish to any other status or statuses.
|
| 7286 |
+
*
|
| 7287 |
+
* @param array $post_status List of post statuses. Default is 'publish'
|
| 7288 |
+
* @param string $post_type Post type of current object
|
| 7289 |
+
* @param array $info Array of information about the object.
|
| 7290 |
+
* @param string $object Type of object
|
| 7291 |
+
* @param string $name Name of pod to load
|
| 7292 |
+
* @param array $pod Array with Pod information. Result of PodsAPI::load_pod()
|
| 7293 |
+
* @param array $field Array with field information
|
| 7294 |
+
*
|
| 7295 |
+
* @since unknown
|
| 7296 |
+
*/
|
| 7297 |
+
$post_status = apply_filters( 'pods_api_get_table_info_default_post_status', array( 'publish' ), $post_type, $info, $object_type, $object, $name, $pod, $field );
|
| 7298 |
+
|
| 7299 |
+
$info[ 'where' ] = array(
|
| 7300 |
+
//'post_status' => '`t`.`post_status` IN ( "inherit", "publish" )', // @todo Figure out what statuses Attachments can be
|
| 7301 |
+
'post_type' => '`t`.`' . $info[ 'field_type' ] . '` = "' . $post_type . '"'
|
| 7302 |
+
);
|
| 7303 |
+
|
| 7304 |
+
if ( 'post_type' == $object_type )
|
| 7305 |
+
$info[ 'where_default' ] = '`t`.`post_status` IN ( "' . implode( '", "', $post_status ) . '" )';
|
| 7306 |
+
|
| 7307 |
+
$info[ 'orderby' ] = '`t`.`menu_order`, `t`.`' . $info[ 'field_index' ] . '`, `t`.`post_date`';
|
| 7308 |
+
|
| 7309 |
+
// WPML support
|
| 7310 |
+
if ( is_object( $sitepress ) && $sitepress->is_translated_post_type( $post_type ) && !$icl_adjust_id_url_filter_off ) {
|
| 7311 |
+
$info[ 'join' ][ 'wpml_translations' ] = "
|
| 7312 |
+
LEFT JOIN `{$wpdb->prefix}icl_translations` AS `wpml_translations`
|
| 7313 |
+
ON `wpml_translations`.`element_id` = `t`.`ID`
|
| 7314 |
+
AND `wpml_translations`.`element_type` = 'post_{$post_type}'
|
| 7315 |
+
AND `wpml_translations`.`language_code` = '{$current_language}'
|
| 7316 |
+
";
|
| 7317 |
+
|
| 7318 |
+
$info[ 'join' ][ 'wpml_languages' ] = "
|
| 7319 |
+
LEFT JOIN `{$wpdb->prefix}icl_languages` AS `wpml_languages`
|
| 7320 |
+
ON `wpml_languages`.`code` = `wpml_translations`.`language_code` AND `wpml_languages`.`active` = 1
|
| 7321 |
+
";
|
| 7322 |
+
|
| 7323 |
+
$info[ 'where' ][ 'wpml_languages' ] = "`wpml_languages`.`code` IS NOT NULL";
|
| 7324 |
+
}
|
| 7325 |
+
// Polylang support
|
| 7326 |
+
elseif( is_object( $polylang ) && !empty( $current_language ) && function_exists( 'pll_is_translated_post_type' ) && pll_is_translated_post_type( $post_type ) ) {
|
| 7327 |
+
$info[ 'join' ][ 'polylang_languages' ] = "
|
| 7328 |
+
LEFT JOIN `{$wpdb->term_relationships}` AS `polylang_languages`
|
| 7329 |
+
ON `polylang_languages`.`object_id` = `t`.`ID`
|
| 7330 |
+
AND `polylang_languages`.`term_taxonomy_id` = {$current_language_tt_id}
|
| 7331 |
+
";
|
| 7332 |
+
|
| 7333 |
+
$info[ 'where' ][ 'polylang_languages' ] = "`polylang_languages`.`object_id` IS NOT NULL";
|
| 7334 |
+
}
|
| 7335 |
+
|
| 7336 |
+
$info[ 'object_fields' ] = $this->get_wp_object_fields( $object_type, $info[ 'pod' ] );
|
| 7337 |
+
}
|
| 7338 |
+
elseif ( 0 === strpos( $object_type, 'taxonomy' ) || in_array( $object_type, array( 'nav_menu', 'post_format' ) ) || 'taxonomy' == pods_var_raw( 'type', $info[ 'pod' ] ) ) {
|
| 7339 |
+
$info[ 'table' ] = $info[ 'meta_table' ] = $wpdb->terms;
|
| 7340 |
+
|
| 7341 |
+
$info[ 'join' ][ 'tt' ] = "LEFT JOIN `{$wpdb->term_taxonomy}` AS `tt` ON `tt`.`term_id` = `t`.`term_id`";
|
| 7342 |
+
$info[ 'field_id' ] = $info[ 'meta_field_id' ] = 'term_id';
|
| 7343 |
+
$info[ 'field_index' ] = $info[ 'meta_field_index' ] = $info[ 'meta_field_value' ] = 'name';
|
| 7344 |
+
$info[ 'field_slug' ] = 'slug';
|
| 7345 |
+
$info[ 'field_type' ] = 'taxonomy';
|
| 7346 |
+
$info[ 'field_parent' ] = 'parent';
|
| 7347 |
+
$info[ 'field_parent_select' ] = '`tt`.`' . $info[ 'field_parent' ] . '`';
|
| 7348 |
+
|
| 7349 |
+
if ( 'nav_menu' == $object_type )
|
| 7350 |
+
$object = 'nav_menu';
|
| 7351 |
+
elseif ( 'post_format' == $object_type )
|
| 7352 |
+
$object = 'post_format';
|
| 7353 |
+
|
| 7354 |
+
if ( empty( $name ) ) {
|
| 7355 |
+
$prefix = 'taxonomy-';
|
| 7356 |
+
|
| 7357 |
+
// Make sure we actually have the prefix before trying anything with the name
|
| 7358 |
+
if ( 0 === strpos( $object_type, $prefix ) )
|
| 7359 |
+
$name = substr( $object_type, strlen( $prefix ), strlen( $object_type ) );
|
| 7360 |
+
}
|
| 7361 |
+
|
| 7362 |
+
if ( !in_array( $object_type, array( 'nav_menu', 'post_format' ) ) )
|
| 7363 |
+
$object_type = 'taxonomy';
|
| 7364 |
+
|
| 7365 |
+
$taxonomy = pods_sanitize( ( empty( $object ) ? $name : $object ) );
|
| 7366 |
+
|
| 7367 |
+
$info[ 'pod_table' ] = $wpdb->prefix . 'pods_' . pods_clean_name( $taxonomy, true, false );
|
| 7368 |
+
|
| 7369 |
+
$taxonomy_object = get_taxonomy( $taxonomy );
|
| 7370 |
+
|
| 7371 |
+
if ( is_object( $taxonomy_object ) && $taxonomy_object->hierarchical )
|
| 7372 |
+
$info[ 'object_hierarchical' ] = true;
|
| 7373 |
+
|
| 7374 |
+
$info[ 'where' ] = array(
|
| 7375 |
+
'tt.taxonomy' => '`tt`.`' . $info[ 'field_type' ] . '` = "' . $taxonomy . '"'
|
| 7376 |
+
);
|
| 7377 |
+
|
| 7378 |
+
// WPML Support
|
| 7379 |
+
if ( is_object( $sitepress ) && $sitepress->is_translated_taxonomy( $taxonomy ) && !$icl_adjust_id_url_filter_off ) {
|
| 7380 |
+
$info[ 'join' ][ 'wpml_translations' ] = "
|
| 7381 |
+
LEFT JOIN `{$wpdb->prefix}icl_translations` AS `wpml_translations`
|
| 7382 |
+
ON `wpml_translations`.`element_id` = `tt`.`term_taxonomy_id`
|
| 7383 |
+
AND `wpml_translations`.`element_type` = 'tax_{$taxonomy}'
|
| 7384 |
+
AND `wpml_translations`.`language_code` = '{$current_language}'
|
| 7385 |
+
";
|
| 7386 |
+
|
| 7387 |
+
$info[ 'join' ][ 'wpml_languages' ] = "
|
| 7388 |
+
LEFT JOIN `{$wpdb->prefix}icl_languages` AS `wpml_languages`
|
| 7389 |
+
ON `wpml_languages`.`code` = `wpml_translations`.`language_code` AND `wpml_languages`.`active` = 1
|
| 7390 |
+
";
|
| 7391 |
+
|
| 7392 |
+
$info[ 'where' ][ 'wpml_languages' ] = "`wpml_languages`.`code` IS NOT NULL";
|
| 7393 |
+
}
|
| 7394 |
+
// Polylang support
|
| 7395 |
+
elseif ( is_object( $polylang ) && !empty( $current_language ) && function_exists( 'pll_is_translated_taxonomy' ) && pll_is_translated_taxonomy( $taxonomy ) ) {
|
| 7396 |
+
$info[ 'join' ][ 'polylang_languages' ] = "
|
| 7397 |
+
LEFT JOIN `{$wpdb->termmeta}` AS `polylang_languages`
|
| 7398 |
+
ON `polylang_languages`.`term_id` = `t`.`term_id`
|
| 7399 |
+
AND `polylang_languages`.`meta_value` = {$current_language_t_id}
|
| 7400 |
+
";
|
| 7401 |
+
|
| 7402 |
+
$info[ 'where' ][ 'polylang_languages' ] = "`polylang_languages`.`term_id` IS NOT NULL";
|
| 7403 |
+
}
|
| 7404 |
+
|
| 7405 |
+
$info[ 'object_fields' ] = $this->get_wp_object_fields( $object_type, $info[ 'pod' ] );
|
| 7406 |
+
}
|
| 7407 |
+
elseif ( 'user' == $object_type || 'user' == pods_var_raw( 'type', $info[ 'pod' ] ) ) {
|
| 7408 |
+
$info[ 'table' ] = $wpdb->users;
|
| 7409 |
+
$info[ 'meta_table' ] = $wpdb->usermeta;
|
| 7410 |
+
$info[ 'pod_table' ] = $wpdb->prefix . 'pods_user';
|
| 7411 |
+
|
| 7412 |
+
$info[ 'field_id' ] = 'ID';
|
| 7413 |
+
$info[ 'field_index' ] = 'display_name';
|
| 7414 |
+
$info[ 'field_slug' ] = 'user_nicename';
|
| 7415 |
+
|
| 7416 |
+
$info[ 'meta_field_id' ] = 'user_id';
|
| 7417 |
+
$info[ 'meta_field_index' ] = 'meta_key';
|
| 7418 |
+
$info[ 'meta_field_value' ] = 'meta_value';
|
| 7419 |
+
|
| 7420 |
+
$info[ 'where' ] = array(
|
| 7421 |
+
'user_status' => '`t`.`user_status` = 0'
|
| 7422 |
+
);
|
| 7423 |
+
|
| 7424 |
+
$info[ 'object_fields' ] = $this->get_wp_object_fields( $object_type, $info[ 'pod' ] );
|
| 7425 |
+
}
|
| 7426 |
+
elseif ( 'comment' == $object_type || 'comment' == pods_var_raw( 'type', $info[ 'pod' ] ) ) {
|
| 7427 |
+
//$info[ 'object_hierarchical' ] = true;
|
| 7428 |
+
|
| 7429 |
+
$info[ 'table' ] = $wpdb->comments;
|
| 7430 |
+
$info[ 'meta_table' ] = $wpdb->commentmeta;
|
| 7431 |
+
$info[ 'pod_table' ] = $wpdb->prefix . 'pods_comment';
|
| 7432 |
+
|
| 7433 |
+
$info[ 'field_id' ] = 'comment_ID';
|
| 7434 |
+
$info[ 'field_index' ] = 'comment_date';
|
| 7435 |
+
$info[ 'field_type' ] = 'comment_type';
|
| 7436 |
+
$info[ 'field_parent' ] = 'comment_parent';
|
| 7437 |
+
$info[ 'field_parent_select' ] = '`t`.`' . $info[ 'field_parent' ] . '`';
|
| 7438 |
+
|
| 7439 |
+
$info[ 'meta_field_id' ] = 'comment_id';
|
| 7440 |
+
$info[ 'meta_field_index' ] = 'meta_key';
|
| 7441 |
+
$info[ 'meta_field_value' ] = 'meta_value';
|
| 7442 |
+
|
| 7443 |
+
$object = 'comment';
|
| 7444 |
+
|
| 7445 |
+
$comment_type = ( empty( $object ) ? $name : $object );
|
| 7446 |
+
|
| 7447 |
+
$comment_type_clause = '`t`.`' . $info[ 'field_type' ] . '` = "' . $comment_type . '"';
|
| 7448 |
+
|
| 7449 |
+
if ( 'comment' == $comment_type ) {
|
| 7450 |
+
$comment_type_clause = '( ' . $comment_type_clause . ' OR `t`.`' . $info[ 'field_type' ] . '` = "" )';
|
| 7451 |
+
}
|
| 7452 |
+
|
| 7453 |
+
$info[ 'where' ] = array(
|
| 7454 |
+
'comment_approved' => '`t`.`comment_approved` = 1',
|
| 7455 |
+
'comment_type' => $comment_type_clause
|
| 7456 |
+
);
|
| 7457 |
+
|
| 7458 |
+
$info[ 'orderby' ] = '`t`.`' . $info[ 'field_index' ] . '` DESC, `t`.`' . $info[ 'field_id' ] . '`';
|
| 7459 |
+
}
|
| 7460 |
+
elseif ( in_array( $object_type, array( 'option', 'settings' ) ) || 'settings' == pods_var_raw( 'type', $info[ 'pod' ] ) ) {
|
| 7461 |
+
$info[ 'table' ] = $wpdb->options;
|
| 7462 |
+
$info[ 'meta_table' ] = $wpdb->options;
|
| 7463 |
+
|
| 7464 |
+
$info[ 'field_id' ] = 'option_id';
|
| 7465 |
+
$info[ 'field_index' ] = 'option_name';
|
| 7466 |
+
|
| 7467 |
+
$info[ 'meta_field_id' ] = 'option_id';
|
| 7468 |
+
$info[ 'meta_field_index' ] = 'option_name';
|
| 7469 |
+
$info[ 'meta_field_value' ] = 'option_value';
|
| 7470 |
+
|
| 7471 |
+
$info[ 'orderby' ] = '`t`.`' . $info[ 'field_index' ] . '` ASC';
|
| 7472 |
+
}
|
| 7473 |
+
elseif ( is_multisite() && ( in_array( $object_type, array( 'site_option', 'site_settings' ) ) || 'site_settings' == pods_var_raw( 'type', $info[ 'pod' ] ) ) ) {
|
| 7474 |
+
$info[ 'table' ] = $wpdb->sitemeta;
|
| 7475 |
+
$info[ 'meta_table' ] = $wpdb->sitemeta;
|
| 7476 |
+
|
| 7477 |
+
$info[ 'field_id' ] = 'site_id';
|
| 7478 |
+
$info[ 'field_index' ] = 'meta_key';
|
| 7479 |
+
|
| 7480 |
+
$info[ 'meta_field_id' ] = 'site_id';
|
| 7481 |
+
$info[ 'meta_field_index' ] = 'meta_key';
|
| 7482 |
+
$info[ 'meta_field_value' ] = 'meta_value';
|
| 7483 |
+
|
| 7484 |
+
$info[ 'orderby' ] = '`t`.`' . $info[ 'field_index' ] . '` ASC';
|
| 7485 |
+
}
|
| 7486 |
+
elseif ( is_multisite() && 'network' == $object_type ) { // Network = Site
|
| 7487 |
+
$info[ 'table' ] = $wpdb->site;
|
| 7488 |
+
$info[ 'meta_table' ] = $wpdb->sitemeta;
|
| 7489 |
+
|
| 7490 |
+
$info[ 'field_id' ] = 'id';
|
| 7491 |
+
$info[ 'field_index' ] = 'domain';
|
| 7492 |
+
|
| 7493 |
+
$info[ 'meta_field_id' ] = 'site_id';
|
| 7494 |
+
$info[ 'meta_field_index' ] = 'meta_key';
|
| 7495 |
+
$info[ 'meta_field_value' ] = 'meta_value';
|
| 7496 |
+
|
| 7497 |
+
$info[ 'orderby' ] = '`t`.`' . $info[ 'field_index' ] . '` ASC, `t`.`path` ASC, `t`.`' . $info[ 'field_id' ] . '`';
|
| 7498 |
+
}
|
| 7499 |
+
elseif ( is_multisite() && 'site' == $object_type ) { // Site = Blog
|
| 7500 |
+
$info[ 'table' ] = $wpdb->blogs;
|
| 7501 |
+
|
| 7502 |
+
$info[ 'field_id' ] = 'blog_id';
|
| 7503 |
+
$info[ 'field_index' ] = 'domain';
|
| 7504 |
+
$info[ 'field_type' ] = 'site_id';
|
| 7505 |
+
|
| 7506 |
+
$info[ 'where' ] = array(
|
| 7507 |
+
'archived' => '`t`.`archived` = 0',
|
| 7508 |
+
'spam' => '`t`.`spam` = 0',
|
| 7509 |
+
'deleted' => '`t`.`deleted` = 0',
|
| 7510 |
+
'site_id' => '`t`.`' . $info[ 'field_type' ] . '` = ' . (int) get_current_site()->id
|
| 7511 |
+
);
|
| 7512 |
+
|
| 7513 |
+
$info[ 'orderby' ] = '`t`.`' . $info[ 'field_index' ] . '` ASC, `t`.`path` ASC, `t`.`' . $info[ 'field_id' ] . '`';
|
| 7514 |
+
}
|
| 7515 |
+
elseif ( 'table' == $object_type || 'table' == pods_var_raw( 'type', $info[ 'pod' ] ) ) {
|
| 7516 |
+
$info[ 'table' ] = ( empty( $object ) ? $name : $object );
|
| 7517 |
+
$info[ 'pod_table' ] = $wpdb->prefix . 'pods_' . $info[ 'table' ];
|
| 7518 |
+
|
| 7519 |
+
if ( !empty( $field ) && is_array( $field ) ) {
|
| 7520 |
+
$info[ 'table' ] = pods_var_raw( 'pick_table', pods_var_raw( 'options', $field, $field ) );
|
| 7521 |
+
$info[ 'field_id' ] = pods_var_raw( 'pick_table_id', pods_var_raw( 'options', $field, $field ) );
|
| 7522 |
+
$info[ 'field_index' ] = $info[ 'meta_field_index' ] = $info[ 'meta_field_value' ] = pods_var_raw( 'pick_table_index', pods_var_raw( 'options', $field, $field ) );
|
| 7523 |
+
}
|
| 7524 |
+
}
|
| 7525 |
+
|
| 7526 |
+
$info[ 'table' ] = pods_clean_name( $info[ 'table' ], false, false );
|
| 7527 |
+
$info[ 'meta_table' ] = pods_clean_name( $info[ 'meta_table' ], false, false );
|
| 7528 |
+
$info[ 'pod_table' ] = pods_clean_name( $info[ 'pod_table' ], false, false );
|
| 7529 |
+
|
| 7530 |
+
$info[ 'field_id' ] = pods_clean_name( $info[ 'field_id' ], false, false );
|
| 7531 |
+
$info[ 'field_index' ] = pods_clean_name( $info[ 'field_index' ], false, false );
|
| 7532 |
+
$info[ 'field_slug' ] = pods_clean_name( $info[ 'field_slug' ], false, false );
|
| 7533 |
+
|
| 7534 |
+
$info[ 'meta_field_id' ] = pods_clean_name( $info[ 'meta_field_id' ], false, false );
|
| 7535 |
+
$info[ 'meta_field_index' ] = pods_clean_name( $info[ 'meta_field_index' ], false, false );
|
| 7536 |
+
$info[ 'meta_field_value' ] = pods_clean_name( $info[ 'meta_field_value' ], false, false );
|
| 7537 |
+
|
| 7538 |
+
if ( empty( $info[ 'orderby' ] ) )
|
| 7539 |
+
$info[ 'orderby' ] = '`t`.`' . $info[ 'field_index' ] . '`, `t`.`' . $info[ 'field_id' ] . '`';
|
| 7540 |
+
|
| 7541 |
+
if ( 'table' == pods_var_raw( 'storage', $info[ 'pod' ] ) && !in_array( $object_type, array( 'pod', 'table' ) ) ) {
|
| 7542 |
+
$info[ 'join' ][ 'd' ] = 'LEFT JOIN `' . $info[ 'pod_table' ] . '` AS `d` ON `d`.`id` = `t`.`' . $info[ 'field_id' ] . '`';
|
| 7543 |
+
//$info[ 'select' ] .= ', `d`.*';
|
| 7544 |
+
}
|
| 7545 |
+
|
| 7546 |
+
if ( !empty( $info[ 'pod' ] ) && is_array( $info[ 'pod' ] ) )
|
| 7547 |
+
$info[ 'recurse' ] = true;
|
| 7548 |
+
|
| 7549 |
+
$info[ 'type' ] = $object_type;
|
| 7550 |
+
$info[ 'object_name' ] = $object;
|
| 7551 |
+
|
| 7552 |
+
if ( pods_api_cache() ) {
|
| 7553 |
+
if ( ! did_action( 'init' ) ) {
|
| 7554 |
+
$transient .= '_pre_init';
|
| 7555 |
+
}
|
| 7556 |
+
pods_transient_set( $transient, $info );
|
| 7557 |
+
}
|
| 7558 |
+
|
| 7559 |
+
|
| 7560 |
+
self::$table_info_cache[ $transient ] = apply_filters( 'pods_api_get_table_info', $info, $object_type, $object, $name, $pod, $field, $this );
|
| 7561 |
+
|
| 7562 |
+
return self::$table_info_cache[ $transient ];
|
| 7563 |
+
}
|
| 7564 |
+
|
| 7565 |
+
/**
|
| 7566 |
+
* Export a package
|
| 7567 |
+
*
|
| 7568 |
+
* $params['pod'] string Pod Type IDs to export
|
| 7569 |
+
* $params['template'] string Template IDs to export
|
| 7570 |
+
* $params['podpage'] string Pod Page IDs to export
|
| 7571 |
+
* $params['helper'] string Helper IDs to export
|
| 7572 |
+
*
|
| 7573 |
+
* @param array $params An associative array of parameters
|
| 7574 |
+
*
|
| 7575 |
+
* @return array|bool
|
| 7576 |
+
*
|
| 7577 |
+
* @since 1.9.0
|
| 7578 |
+
* @deprecated 2.0
|
| 7579 |
+
*/
|
| 7580 |
+
public function export_package ( $params ) {
|
| 7581 |
+
if ( class_exists( 'Pods_Migrate_Packages' ) )
|
| 7582 |
+
return Pods_Migrate_Packages::export( $params );
|
| 7583 |
+
|
| 7584 |
+
return false;
|
| 7585 |
+
}
|
| 7586 |
+
|
| 7587 |
+
/**
|
| 7588 |
+
* Replace an existing package
|
| 7589 |
+
*
|
| 7590 |
+
* @param mixed $data (optional) An associative array containing a package, or the json encoded package
|
| 7591 |
+
*
|
| 7592 |
+
* @return bool
|
| 7593 |
+
*
|
| 7594 |
+
* @since 1.9.8
|
| 7595 |
+
* @deprecated 2.0
|
| 7596 |
+
*/
|
| 7597 |
+
public function replace_package ( $data = false ) {
|
| 7598 |
+
return $this->import_package( $data, true );
|
| 7599 |
+
}
|
| 7600 |
+
|
| 7601 |
+
/**
|
| 7602 |
+
* Import a package
|
| 7603 |
+
*
|
| 7604 |
+
* @param mixed $data (optional) An associative array containing a package, or the json encoded package
|
| 7605 |
+
* @param bool $replace (optional) Replace existing items when found
|
| 7606 |
+
*
|
| 7607 |
+
* @return bool
|
| 7608 |
+
*
|
| 7609 |
+
* @since 1.9.0
|
| 7610 |
+
* @deprecated 2.0
|
| 7611 |
+
*/
|
| 7612 |
+
public function import_package ( $data = false, $replace = false ) {
|
| 7613 |
+
if ( class_exists( 'Pods_Migrate_Packages' ) )
|
| 7614 |
+
return Pods_Migrate_Packages::import( $data, $replace );
|
| 7615 |
+
|
| 7616 |
+
return false;
|
| 7617 |
+
}
|
| 7618 |
+
|
| 7619 |
+
/**
|
| 7620 |
+
* Validate a package
|
| 7621 |
+
*
|
| 7622 |
+
* @param array|string $data (optional) An associative array containing a package, or the json encoded package
|
| 7623 |
+
* @param bool $output (optional)
|
| 7624 |
+
*
|
| 7625 |
+
* @return array|bool
|
| 7626 |
+
*
|
| 7627 |
+
* @since 1.9.0
|
| 7628 |
+
* @deprecated 2.0
|
| 7629 |
+
*/
|
| 7630 |
+
public function validate_package ( $data = false, $output = false ) {
|
| 7631 |
+
return true;
|
| 7632 |
+
}
|
| 7633 |
+
|
| 7634 |
+
/**
|
| 7635 |
+
* Import data from an array or a CSV file.
|
| 7636 |
+
*
|
| 7637 |
+
* @param mixed $import_data PHP associative array or CSV input
|
| 7638 |
+
* @param bool $numeric_mode Use IDs instead of the name field when matching
|
| 7639 |
+
* @param string $format Format of import data, options are php or csv
|
| 7640 |
+
*
|
| 7641 |
+
* @return array IDs of imported items
|
| 7642 |
+
*
|
| 7643 |
+
* @since 1.7.1
|
| 7644 |
+
* @todo This needs some love and use of table_info etc for relationships
|
| 7645 |
+
*/
|
| 7646 |
+
public function import ( $import_data, $numeric_mode = false, $format = null ) {
|
| 7647 |
+
/**
|
| 7648 |
+
* @var $wpdb wpdb
|
| 7649 |
+
*/
|
| 7650 |
+
global $wpdb;
|
| 7651 |
+
|
| 7652 |
+
if ( null === $format && null !== $this->format )
|
| 7653 |
+
$format = $this->format;
|
| 7654 |
+
|
| 7655 |
+
if ( 'csv' == $format && !is_array( $import_data ) ) {
|
| 7656 |
+
$data = pods_migrate( 'sv', ',' )->parse( $import_data );
|
| 7657 |
+
|
| 7658 |
+
$import_data = $data[ 'items' ];
|
| 7659 |
+
}
|
| 7660 |
+
|
| 7661 |
+
pods_query( "SET NAMES utf8" );
|
| 7662 |
+
pods_query( "SET CHARACTER SET utf8" );
|
| 7663 |
+
|
| 7664 |
+
// Loop through the array of items
|
| 7665 |
+
$ids = array();
|
| 7666 |
+
|
| 7667 |
+
// Test to see if it's an array of arrays
|
| 7668 |
+
if ( !is_array( @current( $import_data ) ) )
|
| 7669 |
+
$import_data = array( $import_data );
|
| 7670 |
+
|
| 7671 |
+
$pod = $this->load_pod( array( 'name' => $this->pod ) );
|
| 7672 |
+
|
| 7673 |
+
if ( false === $pod )
|
| 7674 |
+
return pods_error( __( 'Pod not found', 'pods' ), $this );
|
| 7675 |
+
|
| 7676 |
+
$fields = array_merge( $pod[ 'fields' ], $pod[ 'object_fields' ] );
|
| 7677 |
+
|
| 7678 |
+
$simple_tableless_objects = PodsForm::simple_tableless_objects();
|
| 7679 |
+
|
| 7680 |
+
foreach ( $import_data as $key => $data_row ) {
|
| 7681 |
+
$data = array();
|
| 7682 |
+
|
| 7683 |
+
// Loop through each field (use $fields so only valid fields get parsed)
|
| 7684 |
+
foreach ( $fields as $field_name => $field_data ) {
|
| 7685 |
+
if ( !isset( $data_row[ $field_name ] ) && !isset( $data_row[ $field_data[ 'label' ] ] ) )
|
| 7686 |
+
continue;
|
| 7687 |
+
|
| 7688 |
+
$field_id = $field_data[ 'id' ];
|
| 7689 |
+
$type = $field_data[ 'type' ];
|
| 7690 |
+
$pick_object = isset( $field_data[ 'pick_object' ] ) ? $field_data[ 'pick_object' ] : '';
|
| 7691 |
+
$pick_val = isset( $field_data[ 'pick_val' ] ) ? $field_data[ 'pick_val' ] : '';
|
| 7692 |
+
|
| 7693 |
+
if ( isset( $data_row[ $field_name] ) )
|
| 7694 |
+
$field_value = $data_row[ $field_name ];
|
| 7695 |
+
else
|
| 7696 |
+
$field_value = $data_row[ $field_data[ 'label' ] ];
|
| 7697 |
+
|
| 7698 |
+
if ( null !== $field_value && false !== $field_value && '' !== $field_value ) {
|
| 7699 |
+
if ( 'pick' == $type || in_array( $type, PodsForm::file_field_types() ) ) {
|
| 7700 |
+
$field_values = is_array( $field_value ) ? $field_value : array( $field_value );
|
| 7701 |
+
$pick_values = array();
|
| 7702 |
+
|
| 7703 |
+
foreach ( $field_values as $pick_value ) {
|
| 7704 |
+
if ( in_array( $type, PodsForm::file_field_types() ) || 'media' == $pick_object ) {
|
| 7705 |
+
$where = "`guid` = '" . pods_sanitize( $pick_value ) . "'";
|
| 7706 |
+
|
| 7707 |
+
if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode )
|
| 7708 |
+
$where = "`ID` = " . pods_absint( $pick_value );
|
| 7709 |
+
|
| 7710 |
+
$result = pods_query( "SELECT `ID` AS `id` FROM `{$wpdb->posts}` WHERE `post_type` = 'attachment' AND {$where} ORDER BY `ID`", $this );
|
| 7711 |
+
|
| 7712 |
+
if ( !empty( $result ) )
|
| 7713 |
+
$pick_values[] = $result[ 0 ]->id;
|
| 7714 |
+
}
|
| 7715 |
+
// @todo This could and should be abstracted better and simplified
|
| 7716 |
+
elseif ( 'pick' == $type ) {
|
| 7717 |
+
$related_pod = false;
|
| 7718 |
+
|
| 7719 |
+
if ( 'pod' == $pick_object )
|
| 7720 |
+
$related_pod = $this->load_pod( array( 'name' => $pick_val, 'table_info' => true ), false );
|
| 7721 |
+
|
| 7722 |
+
if ( empty( $related_pod ) ) {
|
| 7723 |
+
$related_pod = array(
|
| 7724 |
+
'id' => 0,
|
| 7725 |
+
'type' => $pick_object
|
| 7726 |
+
);
|
| 7727 |
+
}
|
| 7728 |
+
|
| 7729 |
+
if ( in_array( 'taxonomy', array( $pick_object, $related_pod[ 'type' ] ) ) ) {
|
| 7730 |
+
$where = "`t`.`name` = '" . pods_sanitize( $pick_value ) . "'";
|
| 7731 |
+
|
| 7732 |
+
if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode )
|
| 7733 |
+
$where = "`tt`.`term_id` = " . pods_absint( $pick_value );
|
| 7734 |
+
|
| 7735 |
+
$result = pods_query( "SELECT `t`.`term_id` AS `id` FROM `{$wpdb->term_taxonomy}` AS `tt` LEFT JOIN `{$wpdb->terms}` AS `t` ON `t`.`term_id` = `tt`.`term_id` WHERE `taxonomy` = '{$pick_val}' AND {$where} ORDER BY `t`.`term_id`", $this );
|
| 7736 |
+
|
| 7737 |
+
if ( !empty( $result ) )
|
| 7738 |
+
$pick_values[] = $result[ 0 ]->id;
|
| 7739 |
+
}
|
| 7740 |
+
elseif ( in_array( 'post_type', array( $pick_object, $related_pod[ 'type' ] ) ) || in_array( 'media', array( $pick_object, $related_pod[ 'type' ] ) ) ) {
|
| 7741 |
+
$where = "`post_title` = '" . pods_sanitize( $pick_value ) . "'";
|
| 7742 |
+
|
| 7743 |
+
if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode )
|
| 7744 |
+
$where = "`ID` = " . pods_absint( $pick_value );
|
| 7745 |
|
| 7746 |
+
$result = pods_query( "SELECT `ID` AS `id` FROM `{$wpdb->posts}` WHERE `post_type` = '{$pick_val}' AND {$where} ORDER BY `ID`", $this );
|
| 7747 |
|
| 7748 |
+
if ( !empty( $result ) )
|
| 7749 |
+
$pick_values[] = $result[ 0 ]->id;
|
| 7750 |
+
}
|
| 7751 |
+
elseif ( in_array( 'user', array( $pick_object, $related_pod[ 'type' ] ) ) ) {
|
| 7752 |
+
$where = "`user_login` = '" . pods_sanitize( $pick_value ) . "'";
|
| 7753 |
|
| 7754 |
+
if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode )
|
| 7755 |
+
$where = "`ID` = " . pods_absint( $pick_value );
|
|
|
|
|
|
|
| 7756 |
|
| 7757 |
+
$result = pods_query( "SELECT `ID` AS `id` FROM `{$wpdb->users}` WHERE {$where} ORDER BY `ID`", $this );
|
| 7758 |
+
|
| 7759 |
+
if ( !empty( $result ) )
|
| 7760 |
+
$pick_values[] = $result[ 0 ]->id;
|
| 7761 |
+
}
|
| 7762 |
+
elseif ( in_array( 'comment', array( $pick_object, $related_pod[ 'type' ] ) ) ) {
|
| 7763 |
+
$where = "`comment_ID` = " . pods_absint( $pick_value );
|
| 7764 |
+
|
| 7765 |
+
$result = pods_query( "SELECT `comment_ID` AS `id` FROM `{$wpdb->comments}` WHERE {$where} ORDER BY `ID`", $this );
|
| 7766 |
|
| 7767 |
+
if ( !empty( $result ) )
|
| 7768 |
+
$pick_values[] = $result[ 0 ]->id;
|
| 7769 |
+
}
|
| 7770 |
+
elseif ( in_array( $pick_object, $simple_tableless_objects ) )
|
| 7771 |
+
$pick_values[] = $pick_value;
|
| 7772 |
+
elseif ( !empty( $related_pod[ 'id' ] ) ) {
|
| 7773 |
+
$where = "`" . $related_pod[ 'field_index' ] . "` = '" . pods_sanitize( $pick_value ) . "'";
|
| 7774 |
+
|
| 7775 |
+
if ( 0 < pods_absint( $pick_value ) && false !== $numeric_mode )
|
| 7776 |
+
$where = "`" . $related_pod[ 'field_id' ] . "` = " . pods_absint( $pick_value );
|
| 7777 |
+
|
| 7778 |
+
$result = pods_query( "SELECT `" . $related_pod[ 'field_id' ] . "` AS `id` FROM `" . $related_pod[ 'table' ] . "` WHERE {$where} ORDER BY `" . $related_pod[ 'field_id' ] . "`", $this );
|
| 7779 |
+
|
| 7780 |
+
if ( !empty( $result ) )
|
| 7781 |
+
$pick_values[] = $result[ 0 ]->id;
|
| 7782 |
+
}
|
| 7783 |
+
}
|
| 7784 |
+
}
|
| 7785 |
+
|
| 7786 |
+
$field_value = implode( ',', $pick_values );
|
| 7787 |
+
}
|
| 7788 |
+
|
| 7789 |
+
$data[ $field_name ] = $field_value;
|
| 7790 |
+
}
|
| 7791 |
+
}
|
| 7792 |
+
|
| 7793 |
+
if ( !empty( $data ) ) {
|
| 7794 |
+
$params = array(
|
| 7795 |
+
'pod' => $this->pod,
|
| 7796 |
+
'data' => $data
|
| 7797 |
+
);
|
| 7798 |
+
|
| 7799 |
+
$ids[] = $this->save_pod_item( $params );
|
| 7800 |
+
}
|
| 7801 |
+
}
|
| 7802 |
+
|
| 7803 |
+
return $ids;
|
| 7804 |
+
}
|
| 7805 |
+
|
| 7806 |
+
/**
|
| 7807 |
+
* Export data from a Pod
|
| 7808 |
+
*
|
| 7809 |
+
* @param string|object $pod The pod name or Pods object
|
| 7810 |
+
* @param array $params An associative array of parameters
|
| 7811 |
+
*
|
| 7812 |
+
* @return array Data arrays of all exported pod items
|
| 7813 |
+
* @since 1.7.1
|
| 7814 |
+
*/
|
| 7815 |
+
public function export ( $pod = null, $params = null ) {
|
| 7816 |
+
|
| 7817 |
+
if ( empty( $pod ) ) {
|
| 7818 |
+
$pod = $this->pod;
|
| 7819 |
+
}
|
| 7820 |
+
|
| 7821 |
+
$find = array(
|
| 7822 |
+
'limit' => -1,
|
| 7823 |
+
'search' => false,
|
| 7824 |
+
'pagination' => false
|
| 7825 |
+
);
|
| 7826 |
+
|
| 7827 |
+
if ( !empty( $params ) && isset( $params[ 'params' ] ) ) {
|
| 7828 |
+
$find = array_merge( $find, (array) $params[ 'params' ] );
|
| 7829 |
+
|
| 7830 |
+
unset( $params[ 'params' ] );
|
| 7831 |
+
|
| 7832 |
+
$pod = pods( $pod, $find );
|
| 7833 |
+
}
|
| 7834 |
+
elseif ( !is_object( $pod ) ) {
|
| 7835 |
+
$pod = pods( $pod, $find );
|
| 7836 |
+
}
|
| 7837 |
+
|
| 7838 |
+
$data = array();
|
| 7839 |
+
|
| 7840 |
+
while ( $pod->fetch() ) {
|
| 7841 |
+
$data[ $pod->id() ] = $this->export_pod_item( $params, $pod );
|
| 7842 |
+
}
|
| 7843 |
+
|
| 7844 |
+
$data = $this->do_hook( 'export', $data, $pod->pod, $pod );
|
| 7845 |
+
|
| 7846 |
+
return $data;
|
| 7847 |
+
}
|
| 7848 |
+
|
| 7849 |
+
/**
|
| 7850 |
+
* Convert CSV to a PHP array
|
| 7851 |
+
*
|
| 7852 |
+
* @param string $data The CSV input
|
| 7853 |
+
*
|
| 7854 |
+
* @return array
|
| 7855 |
+
* @since 1.7.1
|
| 7856 |
+
*
|
| 7857 |
+
* @deprecated 2.3.5
|
| 7858 |
+
*/
|
| 7859 |
+
public function csv_to_php ( $data, $delimiter = ',' ) {
|
| 7860 |
+
pods_deprecated( "PodsAPI->csv_to_php", '2.3.5' );
|
| 7861 |
+
|
| 7862 |
+
$data = pods_migrate( 'sv', $delimiter, $data )->parse();
|
| 7863 |
+
|
| 7864 |
+
return $data[ 'items' ];
|
| 7865 |
+
}
|
| 7866 |
+
|
| 7867 |
+
/**
|
| 7868 |
+
* Clear Pod-related cache
|
| 7869 |
+
*
|
| 7870 |
+
* @param array $pod
|
| 7871 |
+
*
|
| 7872 |
+
* @return void
|
| 7873 |
+
*
|
| 7874 |
+
* @since 2.0
|
| 7875 |
+
*/
|
| 7876 |
+
public function cache_flush_pods ( $pod = null ) {
|
| 7877 |
+
/**
|
| 7878 |
+
* @var $wpdb wpdb
|
| 7879 |
+
*/
|
| 7880 |
+
global $wpdb;
|
| 7881 |
+
|
| 7882 |
+
pods_transient_clear( 'pods' );
|
| 7883 |
+
pods_transient_clear( 'pods_components' );
|
| 7884 |
+
|
| 7885 |
+
if ( null !== $pod && is_array( $pod ) ) {
|
| 7886 |
+
pods_transient_clear( 'pods_pod_' . $pod[ 'name' ] );
|
| 7887 |
+
pods_cache_clear( $pod[ 'name' ], 'pods-class' );
|
| 7888 |
+
|
| 7889 |
+
foreach ( $pod[ 'fields' ] as $field ) {
|
| 7890 |
+
pods_transient_clear( 'pods_field_' . $pod[ 'name' ] . '_' . $field[ 'name' ] );
|
| 7891 |
+
}
|
| 7892 |
+
|
| 7893 |
+
if ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) )
|
| 7894 |
+
pods_transient_clear( 'pods_wp_cpt_ct' );
|
| 7895 |
+
}
|
| 7896 |
+
else
|
| 7897 |
+
pods_transient_clear( 'pods_wp_cpt_ct' );
|
| 7898 |
+
|
| 7899 |
+
$wpdb->query( "DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE '_transient_pods%'" );
|
| 7900 |
+
$wpdb->query( "DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE '_transient_timeout_pods%'" );
|
| 7901 |
+
|
| 7902 |
+
pods_cache_clear( true );
|
| 7903 |
+
|
| 7904 |
+
pods_transient_set( 'pods_flush_rewrites', 1 );
|
| 7905 |
+
}
|
| 7906 |
+
|
| 7907 |
+
/**
|
| 7908 |
+
* Process a Pod-based form
|
| 7909 |
+
*
|
| 7910 |
+
* @param mixed $params
|
| 7911 |
+
* @param object $obj Pod object
|
| 7912 |
+
* @param array $fields Fields being submitted in form ( key => settings )
|
| 7913 |
+
* @param string $thank_you URL to send to upon success
|
| 7914 |
+
*
|
| 7915 |
+
* @return mixed
|
| 7916 |
+
*
|
| 7917 |
+
* @since 2.0
|
| 7918 |
+
*/
|
| 7919 |
+
public function process_form ( $params, $obj = null, $fields = null, $thank_you = null ) {
|
| 7920 |
+
$this->display_errors = false;
|
| 7921 |
+
|
| 7922 |
+
$form = null;
|
| 7923 |
+
|
| 7924 |
+
$nonce = pods_var( '_pods_nonce', $params );
|
| 7925 |
+
$pod = pods_var( '_pods_pod', $params );
|
| 7926 |
+
$id = pods_var( '_pods_id', $params );
|
| 7927 |
+
$uri = pods_var( '_pods_uri', $params );
|
| 7928 |
+
$form = pods_var( '_pods_form', $params );
|
| 7929 |
+
$location = pods_var( '_pods_location', $params );
|
| 7930 |
+
|
| 7931 |
+
if ( is_object( $obj ) ) {
|
| 7932 |
+
$pod = $obj->pod;
|
| 7933 |
+
$id = $obj->id();
|
| 7934 |
+
}
|
| 7935 |
+
|
| 7936 |
+
if ( !empty( $fields ) ) {
|
| 7937 |
+
$fields = array_keys( $fields );
|
| 7938 |
+
$form = implode( ',', $fields );
|
| 7939 |
+
}
|
| 7940 |
+
else
|
| 7941 |
+
$fields = explode( ',', $form );
|
| 7942 |
+
|
| 7943 |
+
if ( empty( $nonce ) || empty( $pod ) || empty( $uri ) || empty( $fields ) )
|
| 7944 |
+
return pods_error( __( 'Invalid submission', 'pods' ), $this );
|
| 7945 |
+
|
| 7946 |
+
$uid = @session_id();
|
| 7947 |
+
|
| 7948 |
+
if ( is_user_logged_in() )
|
| 7949 |
+
$uid = 'user_' . get_current_user_id();
|
| 7950 |
|
| 7951 |
+
$field_hash = wp_create_nonce( 'pods_fields_' . $form );
|
| 7952 |
|
| 7953 |
+
$action = 'pods_form_' . $pod . '_' . $uid . '_' . $id . '_' . $uri . '_' . $field_hash;
|
|
|
|
|
|
|
|
|
|
| 7954 |
|
| 7955 |
+
if ( empty( $uid ) )
|
| 7956 |
+
return pods_error( __( 'Access denied for your session, please refresh and try again.', 'pods' ), $this );
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7957 |
|
| 7958 |
+
if ( false === wp_verify_nonce( $nonce, $action ) )
|
| 7959 |
+
return pods_error( __( 'Access denied, please refresh and try again.', 'pods' ), $this );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7960 |
|
| 7961 |
+
$data = array();
|
| 7962 |
|
| 7963 |
+
foreach ( $fields as $field ) {
|
| 7964 |
+
$data[ $field ] = pods_var_raw( 'pods_field_' . $field, $params, '' );
|
| 7965 |
+
}
|
| 7966 |
|
| 7967 |
+
$params = array(
|
| 7968 |
+
'pod' => $pod,
|
| 7969 |
+
'id' => $id,
|
| 7970 |
+
'data' => $data,
|
| 7971 |
+
'from' => 'process_form',
|
| 7972 |
+
'location' => $location
|
| 7973 |
+
);
|
| 7974 |
+
|
| 7975 |
+
$id = $this->save_pod_item( $params );
|
| 7976 |
+
|
| 7977 |
+
if ( 0 < $id && !empty( $thank_you ) ) {
|
| 7978 |
+
$thank_you = str_replace( 'X_ID_X', $id, $thank_you );
|
| 7979 |
+
|
| 7980 |
+
pods_redirect( $thank_you );
|
| 7981 |
+
}
|
| 7982 |
+
|
| 7983 |
+
return $id;
|
| 7984 |
+
}
|
| 7985 |
+
|
| 7986 |
+
/**
|
| 7987 |
+
* Handle filters / actions for the class
|
| 7988 |
+
*
|
| 7989 |
+
* @since 2.0
|
| 7990 |
+
*/
|
| 7991 |
+
private function do_hook () {
|
| 7992 |
+
$args = func_get_args();
|
| 7993 |
+
if ( empty( $args ) )
|
| 7994 |
+
return false;
|
| 7995 |
+
$name = array_shift( $args );
|
| 7996 |
+
return pods_do_hook( "api", $name, $args, $this );
|
| 7997 |
+
}
|
| 7998 |
+
|
| 7999 |
+
/**
|
| 8000 |
+
* Handle variables that have been deprecated
|
| 8001 |
+
*
|
| 8002 |
+
* @since 2.0
|
| 8003 |
+
*/
|
| 8004 |
+
public function __get ( $name ) {
|
| 8005 |
+
$name = (string) $name;
|
| 8006 |
+
|
| 8007 |
+
if ( !isset( $this->deprecated ) ) {
|
| 8008 |
+
require_once( PODS_DIR . 'deprecated/classes/PodsAPI.php' );
|
| 8009 |
+
$this->deprecated = new PodsAPI_Deprecated( $this );
|
| 8010 |
+
}
|
| 8011 |
+
|
| 8012 |
+
$var = null;
|
| 8013 |
+
|
| 8014 |
+
if ( isset( $this->deprecated->{$name} ) ) {
|
| 8015 |
+
pods_deprecated( "PodsAPI->{$name}", '2.0' );
|
| 8016 |
+
|
| 8017 |
+
$var = $this->deprecated->{$name};
|
| 8018 |
+
}
|
| 8019 |
+
else
|
| 8020 |
+
pods_deprecated( "PodsAPI->{$name}", '2.0' );
|
| 8021 |
+
|
| 8022 |
+
return $var;
|
| 8023 |
+
}
|
| 8024 |
+
|
| 8025 |
+
/**
|
| 8026 |
+
* Handle methods that have been deprecated
|
| 8027 |
+
*
|
| 8028 |
+
* @since 2.0
|
| 8029 |
+
*/
|
| 8030 |
+
public function __call ( $name, $args ) {
|
| 8031 |
+
$name = (string) $name;
|
| 8032 |
+
|
| 8033 |
+
if ( !isset( $this->deprecated ) ) {
|
| 8034 |
+
require_once( PODS_DIR . 'deprecated/classes/PodsAPI.php' );
|
| 8035 |
+
$this->deprecated = new PodsAPI_Deprecated( $this );
|
| 8036 |
+
}
|
| 8037 |
+
|
| 8038 |
+
if ( method_exists( $this->deprecated, $name ) )
|
| 8039 |
+
return call_user_func_array( array( $this->deprecated, $name ), $args );
|
| 8040 |
+
else
|
| 8041 |
+
pods_deprecated( "PodsAPI::{$name}", '2.0' );
|
| 8042 |
+
}
|
| 8043 |
}
|
classes/PodsAdmin.php
CHANGED
|
@@ -1,3352 +1,2245 @@
|
|
| 1 |
<?php
|
| 2 |
-
|
| 3 |
/**
|
| 4 |
* @package Pods
|
| 5 |
*/
|
| 6 |
class PodsAdmin {
|
| 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 |
-
wp_enqueue_script( 'jquery-qtip2' );
|
| 142 |
-
wp_enqueue_script( 'pods-qtip-init' );
|
| 143 |
-
|
| 144 |
-
wp_enqueue_script( 'pods' );
|
| 145 |
-
|
| 146 |
-
if ( 0 === strpos( $page, 'pods-manage-' ) || 0 === strpos( $page, 'pods-add-new-' ) ) {
|
| 147 |
-
wp_enqueue_script( 'post' );
|
| 148 |
-
} elseif ( 0 === strpos( $page, 'pods-settings-' ) ) {
|
| 149 |
-
wp_enqueue_script( 'post' );
|
| 150 |
-
}
|
| 151 |
-
|
| 152 |
-
if ( 'pods-advanced' === $page ) {
|
| 153 |
-
wp_register_script( 'pods-advanced', PODS_URL . 'ui/js/advanced.js', array(), PODS_VERSION );
|
| 154 |
-
wp_enqueue_script( 'jquery-ui-effects-core', PODS_URL . 'ui/js/jquery-ui/jquery.effects.core.js', array( 'jquery' ), '1.8.8' );
|
| 155 |
-
wp_enqueue_script( 'jquery-ui-effects-fade', PODS_URL . 'ui/js/jquery-ui/jquery.effects.fade.js', array( 'jquery' ), '1.8.8' );
|
| 156 |
-
wp_enqueue_script( 'jquery-ui-dialog' );
|
| 157 |
-
wp_enqueue_script( 'pods-advanced' );
|
| 158 |
-
} elseif ( 'pods-packages' === $page ) {
|
| 159 |
-
wp_enqueue_style( 'pods-wizard' );
|
| 160 |
-
} elseif ( 'pods-wizard' === $page || 'pods-upgrade' === $page || ( in_array(
|
| 161 |
-
$page, array(
|
| 162 |
-
'pods',
|
| 163 |
-
'pods-add-new',
|
| 164 |
-
), true
|
| 165 |
-
) && in_array(
|
| 166 |
-
pods_v( 'action', 'get', 'manage' ), array(
|
| 167 |
-
'add',
|
| 168 |
-
'manage',
|
| 169 |
-
), true
|
| 170 |
-
) ) ) {
|
| 171 |
-
wp_enqueue_style( 'pods-wizard' );
|
| 172 |
-
|
| 173 |
-
if ( 'pods-upgrade' === $page ) {
|
| 174 |
-
wp_enqueue_script( 'pods-upgrade' );
|
| 175 |
-
}
|
| 176 |
-
}//end if
|
| 177 |
-
}//end if
|
| 178 |
-
}//end if
|
| 179 |
-
|
| 180 |
-
/**
|
| 181 |
-
* Filter to disable default loading of the DFV script. By default, Pods
|
| 182 |
-
* will always enqueue the DFV script if is_admin()
|
| 183 |
-
*
|
| 184 |
-
* Example: add_filter( 'pods_default_enqueue_dfv', '__return_false');
|
| 185 |
-
*
|
| 186 |
-
* @param bool Whether or not to enqueue by default
|
| 187 |
-
*
|
| 188 |
-
* @since 2.7.10
|
| 189 |
-
*/
|
| 190 |
-
if ( apply_filters( 'pods_default_enqueue_dfv', true ) ) {
|
| 191 |
-
wp_enqueue_script( 'pods-dfv' );
|
| 192 |
-
}
|
| 193 |
-
|
| 194 |
-
// New Styles Enqueue
|
| 195 |
-
wp_enqueue_style( 'pods-styles' );
|
| 196 |
-
}
|
| 197 |
-
|
| 198 |
-
/**
|
| 199 |
-
* Build the admin menus
|
| 200 |
-
*
|
| 201 |
-
* @since 2.0.0
|
| 202 |
-
*/
|
| 203 |
-
public function admin_menu() {
|
| 204 |
-
|
| 205 |
-
$advanced_content_types = PodsMeta::$advanced_content_types;
|
| 206 |
-
$taxonomies = PodsMeta::$taxonomies;
|
| 207 |
-
$settings = PodsMeta::$settings;
|
| 208 |
-
|
| 209 |
-
$all_pods = pods_api()->load_pods( array( 'count' => true ) );
|
| 210 |
-
|
| 211 |
-
if ( ! PodsInit::$upgrade_needed || ( pods_is_admin() && 1 === (int) pods_v( 'pods_upgrade_bypass' ) ) ) {
|
| 212 |
-
$submenu_items = array();
|
| 213 |
-
|
| 214 |
-
if ( ! empty( $advanced_content_types ) ) {
|
| 215 |
-
$submenu = array();
|
| 216 |
-
|
| 217 |
-
$pods_pages = 0;
|
| 218 |
-
|
| 219 |
-
foreach ( (array) $advanced_content_types as $pod ) {
|
| 220 |
-
if ( ! isset( $pod['name'] ) || ! isset( $pod['options'] ) || empty( $pod['fields'] ) ) {
|
| 221 |
-
continue;
|
| 222 |
-
} elseif ( ! pods_is_admin(
|
| 223 |
-
array(
|
| 224 |
-
'pods',
|
| 225 |
-
'pods_content',
|
| 226 |
-
'pods_add_' . $pod['name'],
|
| 227 |
-
'pods_edit_' . $pod['name'],
|
| 228 |
-
'pods_delete_' . $pod['name'],
|
| 229 |
-
)
|
| 230 |
-
) ) {
|
| 231 |
-
continue;
|
| 232 |
-
}
|
| 233 |
-
|
| 234 |
-
$pod_name = $pod['name'];
|
| 235 |
-
|
| 236 |
-
$pod = apply_filters( "pods_advanced_content_type_pod_data_{$pod_name}", $pod, $pod['name'] );
|
| 237 |
-
$pod = apply_filters( 'pods_advanced_content_type_pod_data', $pod, $pod['name'] );
|
| 238 |
-
|
| 239 |
-
if ( 1 === (int) pods_v( 'show_in_menu', $pod['options'], 0 ) ) {
|
| 240 |
-
$page_title = pods_v( 'label', $pod, ucwords( str_replace( '_', ' ', $pod['name'] ) ), true );
|
| 241 |
-
$page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod );
|
| 242 |
-
|
| 243 |
-
$menu_label = pods_v( 'menu_name', $pod['options'], $page_title, true );
|
| 244 |
-
$menu_label = apply_filters( 'pods_admin_menu_label', $menu_label, $pod );
|
| 245 |
-
|
| 246 |
-
$singular_label = pods_v( 'label_singular', $pod['options'], pods_v( 'label', $pod, ucwords( str_replace( '_', ' ', $pod['name'] ) ), true ), true );
|
| 247 |
-
$plural_label = pods_v( 'label', $pod, ucwords( str_replace( '_', ' ', $pod['name'] ) ), true );
|
| 248 |
-
|
| 249 |
-
$menu_location = pods_v( 'menu_location', $pod['options'], 'objects' );
|
| 250 |
-
$menu_location_custom = pods_v( 'menu_location_custom', $pod['options'], '' );
|
| 251 |
-
|
| 252 |
-
$menu_position = pods_v( 'menu_position', $pod['options'], '', true );
|
| 253 |
-
$menu_icon = pods_evaluate_tags( pods_v( 'menu_icon', $pod['options'], '', true ), true );
|
| 254 |
-
|
| 255 |
-
if ( empty( $menu_position ) ) {
|
| 256 |
-
$menu_position = null;
|
| 257 |
-
}
|
| 258 |
-
|
| 259 |
-
$parent_page = null;
|
| 260 |
-
|
| 261 |
-
if ( pods_is_admin(
|
| 262 |
-
array(
|
| 263 |
-
'pods',
|
| 264 |
-
'pods_content',
|
| 265 |
-
'pods_edit_' . $pod['name'],
|
| 266 |
-
'pods_delete_' . $pod['name'],
|
| 267 |
-
)
|
| 268 |
-
) ) {
|
| 269 |
-
if ( ! empty( $menu_location_custom ) ) {
|
| 270 |
-
if ( ! isset( $submenu_items[ $menu_location_custom ] ) ) {
|
| 271 |
-
$submenu_items[ $menu_location_custom ] = array();
|
| 272 |
-
}
|
| 273 |
-
|
| 274 |
-
$submenu_items[ $menu_location_custom ][] = array(
|
| 275 |
-
$menu_location_custom,
|
| 276 |
-
$page_title,
|
| 277 |
-
$menu_label,
|
| 278 |
-
'read',
|
| 279 |
-
'pods-manage-' . $pod['name'],
|
| 280 |
-
array( $this, 'admin_content' ),
|
| 281 |
-
);
|
| 282 |
-
|
| 283 |
-
continue;
|
| 284 |
-
} else {
|
| 285 |
-
$pods_pages ++;
|
| 286 |
-
|
| 287 |
-
$page = 'pods-manage-' . $pod['name'];
|
| 288 |
-
$parent_page = $page;
|
| 289 |
-
|
| 290 |
-
if ( empty( $menu_position ) ) {
|
| 291 |
-
$menu_position = null;
|
| 292 |
-
}
|
| 293 |
-
add_menu_page( $page_title, $menu_label, 'read', $parent_page, '', $menu_icon, $menu_position );
|
| 294 |
-
|
| 295 |
-
$all_title = $plural_label;
|
| 296 |
-
$all_label = pods_v( 'label_all_items', $pod['options'], __( 'All', 'pods' ) . ' ' . $plural_label );
|
| 297 |
-
|
| 298 |
-
if ( pods_v( 'page' ) === $page ) {
|
| 299 |
-
if ( 'edit' === pods_v( 'action', 'get', 'manage' ) ) {
|
| 300 |
-
$all_title = pods_v( 'label_edit_item', $pod['options'], __( 'Edit', 'pods' ) . ' ' . $singular_label );
|
| 301 |
-
} elseif ( 'add' === pods_v( 'action', 'get', 'manage' ) ) {
|
| 302 |
-
$all_title = pods_v( 'label_add_new_item', $pod['options'], __( 'Add New', 'pods' ) . ' ' . $singular_label );
|
| 303 |
-
}
|
| 304 |
-
}
|
| 305 |
-
|
| 306 |
-
add_submenu_page(
|
| 307 |
-
$parent_page, $all_title, $all_label, 'read', $page, array(
|
| 308 |
-
$this,
|
| 309 |
-
'admin_content',
|
| 310 |
-
)
|
| 311 |
-
);
|
| 312 |
-
}//end if
|
| 313 |
-
}//end if
|
| 314 |
-
|
| 315 |
-
if ( pods_is_admin( array( 'pods', 'pods_content', 'pods_add_' . $pod['name'] ) ) ) {
|
| 316 |
-
$page = 'pods-add-new-' . $pod['name'];
|
| 317 |
-
|
| 318 |
-
if ( null === $parent_page ) {
|
| 319 |
-
$pods_pages ++;
|
| 320 |
-
|
| 321 |
-
$parent_page = $page;
|
| 322 |
-
|
| 323 |
-
if ( empty( $menu_position ) ) {
|
| 324 |
-
$menu_position = null;
|
| 325 |
-
}
|
| 326 |
-
add_menu_page( $page_title, $menu_label, 'read', $parent_page, '', $menu_icon, $menu_position );
|
| 327 |
-
}
|
| 328 |
-
|
| 329 |
-
$add_title = pods_v( 'label_add_new_item', $pod['options'], __( 'Add New', 'pods' ) . ' ' . $singular_label );
|
| 330 |
-
$add_label = pods_v( 'label_add_new', $pod['options'], __( 'Add New', 'pods' ) );
|
| 331 |
-
|
| 332 |
-
add_submenu_page(
|
| 333 |
-
$parent_page, $add_title, $add_label, 'read', $page, array(
|
| 334 |
-
$this,
|
| 335 |
-
'admin_content',
|
| 336 |
-
)
|
| 337 |
-
);
|
| 338 |
-
}//end if
|
| 339 |
-
} else {
|
| 340 |
-
$submenu[] = $pod;
|
| 341 |
-
}//end if
|
| 342 |
-
}//end foreach
|
| 343 |
-
|
| 344 |
-
$submenu = apply_filters( 'pods_admin_menu_secondary_content', $submenu );
|
| 345 |
-
|
| 346 |
-
if ( ! empty( $submenu ) && ( ! defined( 'PODS_DISABLE_CONTENT_MENU' ) || ! PODS_DISABLE_CONTENT_MENU ) ) {
|
| 347 |
-
$parent_page = null;
|
| 348 |
-
|
| 349 |
-
foreach ( $submenu as $item ) {
|
| 350 |
-
$singular_label = pods_v( 'label_singular', $item['options'], pods_v( 'label', $item, ucwords( str_replace( '_', ' ', $item['name'] ) ), true ), true );
|
| 351 |
-
$plural_label = pods_v( 'label', $item, ucwords( str_replace( '_', ' ', $item['name'] ) ), true );
|
| 352 |
-
|
| 353 |
-
if ( pods_is_admin(
|
| 354 |
-
array(
|
| 355 |
-
'pods',
|
| 356 |
-
'pods_content',
|
| 357 |
-
'pods_edit_' . $item['name'],
|
| 358 |
-
'pods_delete_' . $item['name'],
|
| 359 |
-
)
|
| 360 |
-
) ) {
|
| 361 |
-
$page = 'pods-manage-' . $item['name'];
|
| 362 |
-
|
| 363 |
-
if ( null === $parent_page ) {
|
| 364 |
-
$parent_page = $page;
|
| 365 |
-
|
| 366 |
-
add_menu_page( 'Pods', 'Pods', 'read', $parent_page, null, 'dashicons-pods', '58.5' );
|
| 367 |
-
}
|
| 368 |
-
|
| 369 |
-
$all_title = $plural_label;
|
| 370 |
-
$all_label = __( 'Manage', 'pods' ) . ' ' . $plural_label;
|
| 371 |
-
|
| 372 |
-
if ( pods_v( 'page' ) === $page ) {
|
| 373 |
-
if ( 'edit' === pods_v( 'action', 'get', 'manage' ) ) {
|
| 374 |
-
$all_title = __( 'Edit', 'pods' ) . ' ' . $singular_label;
|
| 375 |
-
} elseif ( 'add' === pods_v( 'action', 'get', 'manage' ) ) {
|
| 376 |
-
$all_title = __( 'Add New', 'pods' ) . ' ' . $singular_label;
|
| 377 |
-
}
|
| 378 |
-
}
|
| 379 |
-
|
| 380 |
-
add_submenu_page(
|
| 381 |
-
$parent_page, $all_title, $all_label, 'read', $page, array(
|
| 382 |
-
$this,
|
| 383 |
-
'admin_content',
|
| 384 |
-
)
|
| 385 |
-
);
|
| 386 |
-
} elseif ( current_user_can( 'pods_add_' . $item['name'] ) ) {
|
| 387 |
-
$page = 'pods-add-new-' . $item['name'];
|
| 388 |
-
|
| 389 |
-
if ( null === $parent_page ) {
|
| 390 |
-
$parent_page = $page;
|
| 391 |
-
|
| 392 |
-
add_menu_page( 'Pods', 'Pods', 'read', $parent_page, null, 'dashicons-pods', '58.5' );
|
| 393 |
-
}
|
| 394 |
-
|
| 395 |
-
$add_title = __( 'Add New', 'pods' ) . ' ' . $singular_label;
|
| 396 |
-
$add_label = __( 'Manage', 'pods' ) . ' ' . $plural_label;
|
| 397 |
-
|
| 398 |
-
add_submenu_page(
|
| 399 |
-
$parent_page, $add_title, $add_label, 'read', $page, array(
|
| 400 |
-
$this,
|
| 401 |
-
'admin_content',
|
| 402 |
-
)
|
| 403 |
-
);
|
| 404 |
-
}//end if
|
| 405 |
-
}//end foreach
|
| 406 |
-
}//end if
|
| 407 |
-
}//end if
|
| 408 |
-
|
| 409 |
-
if ( ! empty( $taxonomies ) ) {
|
| 410 |
-
foreach ( (array) $taxonomies as $pod ) {
|
| 411 |
-
// Default taxonomy capability
|
| 412 |
-
$capability = 'manage_categories';
|
| 413 |
-
|
| 414 |
-
if ( ! empty( $pod['options']['capability_type'] ) ) {
|
| 415 |
-
if ( 'custom' === $pod['options']['capability_type'] && ! empty( $pod['options']['capability_type_custom'] ) ) {
|
| 416 |
-
$capability = 'manage_' . (string) $pod['options']['capability_type_custom'] . '_terms';
|
| 417 |
-
}
|
| 418 |
-
}
|
| 419 |
-
|
| 420 |
-
// Check capabilities.
|
| 421 |
-
if ( ! pods_is_admin(
|
| 422 |
-
array(
|
| 423 |
-
'pods',
|
| 424 |
-
'pods_content',
|
| 425 |
-
'pods_edit_' . $pod['name'],
|
| 426 |
-
$capability,
|
| 427 |
-
)
|
| 428 |
-
) ) {
|
| 429 |
-
continue;
|
| 430 |
-
}
|
| 431 |
-
|
| 432 |
-
// Check UI settings
|
| 433 |
-
if ( 1 !== (int) pods_v( 'show_ui', $pod['options'], 0 ) || 1 !== (int) pods_v( 'show_in_menu', $pod['options'], 0 ) ) {
|
| 434 |
-
continue;
|
| 435 |
-
}
|
| 436 |
-
|
| 437 |
-
$menu_location = pods_v( 'menu_location', $pod['options'], 'default' );
|
| 438 |
-
|
| 439 |
-
if ( 'default' === $menu_location ) {
|
| 440 |
-
continue;
|
| 441 |
-
}
|
| 442 |
-
|
| 443 |
-
$page_title = pods_v( 'label', $pod, ucwords( str_replace( '_', ' ', $pod['name'] ) ), true );
|
| 444 |
-
$page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod );
|
| 445 |
-
|
| 446 |
-
$menu_label = pods_v( 'menu_name', $pod['options'], $page_title, true );
|
| 447 |
-
$menu_label = apply_filters( 'pods_admin_menu_label', $menu_label, $pod );
|
| 448 |
-
|
| 449 |
-
$menu_icon = pods_evaluate_tags( pods_v( 'menu_icon', $pod['options'], '', true ), true );
|
| 450 |
-
$menu_slug = 'edit-tags.php?taxonomy=' . $pod['name'];
|
| 451 |
-
$menu_location_custom = pods_v( 'menu_location_custom', $pod['options'], '' );
|
| 452 |
-
|
| 453 |
-
$menu_position = pods_v( 'menu_position', $pod['options'], '', true );
|
| 454 |
-
if ( empty( $menu_position ) ) {
|
| 455 |
-
$menu_position = null;
|
| 456 |
-
}
|
| 457 |
-
|
| 458 |
-
$taxonomy_data = get_taxonomy( $pod['name'] );
|
| 459 |
-
|
| 460 |
-
foreach ( (array) $taxonomy_data->object_type as $post_type ) {
|
| 461 |
-
if ( 'post' === $post_type ) {
|
| 462 |
-
remove_submenu_page( 'edit.php', $menu_slug );
|
| 463 |
-
} elseif ( 'attachment' === $post_type ) {
|
| 464 |
-
remove_submenu_page( 'upload.php', $menu_slug . '&post_type=' . $post_type );
|
| 465 |
-
} else {
|
| 466 |
-
remove_submenu_page( 'edit.php?post_type=' . $post_type, $menu_slug . '&post_type=' . $post_type );
|
| 467 |
-
}
|
| 468 |
-
}
|
| 469 |
-
|
| 470 |
-
if ( 'settings' === $menu_location ) {
|
| 471 |
-
add_options_page( $page_title, $menu_label, 'read', $menu_slug );
|
| 472 |
-
} elseif ( 'appearances' === $menu_location ) {
|
| 473 |
-
add_theme_page( $page_title, $menu_label, 'read', $menu_slug );
|
| 474 |
-
} elseif ( 'objects' === $menu_location || 'top' === $menu_location ) {
|
| 475 |
-
add_menu_page( $page_title, $menu_label, 'read', $menu_slug, '', $menu_icon, $menu_position );
|
| 476 |
-
} elseif ( 'submenu' === $menu_location && ! empty( $menu_location_custom ) ) {
|
| 477 |
-
if ( ! isset( $submenu_items[ $menu_location_custom ] ) ) {
|
| 478 |
-
$submenu_items[ $menu_location_custom ] = array();
|
| 479 |
-
}
|
| 480 |
-
|
| 481 |
-
$submenu_items[ $menu_location_custom ][] = array(
|
| 482 |
-
$menu_location_custom,
|
| 483 |
-
$page_title,
|
| 484 |
-
$menu_label,
|
| 485 |
-
'read',
|
| 486 |
-
$menu_slug,
|
| 487 |
-
'',
|
| 488 |
-
);
|
| 489 |
-
}//end if
|
| 490 |
-
}//end foreach
|
| 491 |
-
}//end if
|
| 492 |
-
|
| 493 |
-
if ( ! empty( $settings ) ) {
|
| 494 |
-
foreach ( (array) $settings as $pod ) {
|
| 495 |
-
if ( ! pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $pod['name'] ) ) ) {
|
| 496 |
-
continue;
|
| 497 |
-
}
|
| 498 |
-
|
| 499 |
-
$page_title = pods_v( 'label', $pod, ucwords( str_replace( '_', ' ', $pod['name'] ) ), true );
|
| 500 |
-
$page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod );
|
| 501 |
-
|
| 502 |
-
$menu_label = pods_v( 'menu_name', $pod['options'], $page_title, true );
|
| 503 |
-
$menu_label = apply_filters( 'pods_admin_menu_label', $menu_label, $pod );
|
| 504 |
-
|
| 505 |
-
$menu_icon = pods_evaluate_tags( pods_v( 'menu_icon', $pod['options'], '', true ), true );
|
| 506 |
-
|
| 507 |
-
$menu_position = pods_v( 'menu_position', $pod['options'], '', true );
|
| 508 |
-
if ( empty( $menu_position ) ) {
|
| 509 |
-
$menu_position = null;
|
| 510 |
-
}
|
| 511 |
-
|
| 512 |
-
$menu_slug = 'pods-settings-' . $pod['name'];
|
| 513 |
-
$menu_location = pods_v( 'menu_location', $pod['options'], 'settings' );
|
| 514 |
-
$menu_location_custom = pods_v( 'menu_location_custom', $pod['options'], '' );
|
| 515 |
-
$menu_callback = array( $this, 'admin_content_settings' );
|
| 516 |
-
|
| 517 |
-
if ( 'settings' === $menu_location ) {
|
| 518 |
-
add_options_page( $page_title, $menu_label, 'read', $menu_slug, $menu_callback, $menu_position );
|
| 519 |
-
} elseif ( 'appearances' === $menu_location ) {
|
| 520 |
-
add_theme_page( $page_title, $menu_label, 'read', $menu_slug, $menu_callback, $menu_position );
|
| 521 |
-
} elseif ( 'objects' === $menu_location || 'top' === $menu_location ) {
|
| 522 |
-
add_menu_page( $page_title, $menu_label, 'read', $menu_slug, $menu_callback, $menu_icon, $menu_position );
|
| 523 |
-
} elseif ( 'submenu' === $menu_location && ! empty( $menu_location_custom ) ) {
|
| 524 |
-
if ( ! isset( $submenu_items[ $menu_location_custom ] ) ) {
|
| 525 |
-
$submenu_items[ $menu_location_custom ] = array();
|
| 526 |
-
}
|
| 527 |
-
|
| 528 |
-
$submenu_items[ $menu_location_custom ][] = array(
|
| 529 |
-
$menu_location_custom,
|
| 530 |
-
$page_title,
|
| 531 |
-
$menu_label,
|
| 532 |
-
'read',
|
| 533 |
-
$menu_slug,
|
| 534 |
-
$menu_callback,
|
| 535 |
-
$menu_position,
|
| 536 |
-
);
|
| 537 |
-
}//end if
|
| 538 |
-
}//end foreach
|
| 539 |
-
}//end if
|
| 540 |
-
|
| 541 |
-
foreach ( $submenu_items as $items ) {
|
| 542 |
-
foreach ( $items as $item ) {
|
| 543 |
-
call_user_func_array( 'add_submenu_page', $item );
|
| 544 |
-
}
|
| 545 |
-
}
|
| 546 |
-
|
| 547 |
-
$admin_menus = array(
|
| 548 |
-
'pods' => array(
|
| 549 |
-
'label' => __( 'Edit Pods', 'pods' ),
|
| 550 |
-
'function' => array( $this, 'admin_setup' ),
|
| 551 |
-
'access' => 'pods',
|
| 552 |
-
),
|
| 553 |
-
'pods-add-new' => array(
|
| 554 |
-
'label' => __( 'Add New', 'pods' ),
|
| 555 |
-
'function' => array( $this, 'admin_setup' ),
|
| 556 |
-
'access' => 'pods',
|
| 557 |
-
),
|
| 558 |
-
'pods-components' => array(
|
| 559 |
-
'label' => __( 'Components', 'pods' ),
|
| 560 |
-
'function' => array( $this, 'admin_components' ),
|
| 561 |
-
'access' => 'pods_components',
|
| 562 |
-
),
|
| 563 |
-
'pods-settings' => array(
|
| 564 |
-
'label' => __( 'Settings', 'pods' ),
|
| 565 |
-
'function' => array( $this, 'admin_settings' ),
|
| 566 |
-
'access' => 'pods_settings',
|
| 567 |
-
),
|
| 568 |
-
'pods-help' => array(
|
| 569 |
-
'label' => __( 'Help', 'pods' ),
|
| 570 |
-
'function' => array( $this, 'admin_help' ),
|
| 571 |
-
),
|
| 572 |
-
);
|
| 573 |
-
|
| 574 |
-
if ( empty( $all_pods ) ) {
|
| 575 |
-
unset( $admin_menus['pods'] );
|
| 576 |
-
|
| 577 |
-
if ( 'pods' === pods_v( 'page', 'get' ) ) {
|
| 578 |
-
// Replace `pods` page param with first existing pod page and redirect.
|
| 579 |
-
$url = add_query_arg( 'page', key( $admin_menus ) );
|
| 580 |
-
$url = get_site_url( null, $url );
|
| 581 |
-
|
| 582 |
-
wp_safe_redirect( $url );
|
| 583 |
-
die();
|
| 584 |
-
}
|
| 585 |
-
}
|
| 586 |
-
|
| 587 |
-
add_filter( 'parent_file', array( $this, 'parent_file' ) );
|
| 588 |
-
} else {
|
| 589 |
-
$admin_menus = array(
|
| 590 |
-
'pods-upgrade' => array(
|
| 591 |
-
'label' => __( 'Upgrade', 'pods' ),
|
| 592 |
-
'function' => array( $this, 'admin_upgrade' ),
|
| 593 |
-
'access' => 'manage_options',
|
| 594 |
-
),
|
| 595 |
-
'pods-settings' => array(
|
| 596 |
-
'label' => __( 'Settings', 'pods' ),
|
| 597 |
-
'function' => array( $this, 'admin_settings' ),
|
| 598 |
-
'access' => 'pods_settings',
|
| 599 |
-
),
|
| 600 |
-
'pods-help' => array(
|
| 601 |
-
'label' => __( 'Help', 'pods' ),
|
| 602 |
-
'function' => array( $this, 'admin_help' ),
|
| 603 |
-
),
|
| 604 |
-
);
|
| 605 |
-
|
| 606 |
-
add_action( 'admin_notices', array( $this, 'upgrade_notice' ) );
|
| 607 |
-
}//end if
|
| 608 |
-
|
| 609 |
-
/**
|
| 610 |
-
* Add or change Pods Admin menu items
|
| 611 |
-
*
|
| 612 |
-
* @param array $admin_menus The submenu items in Pods Admin menu.
|
| 613 |
-
*
|
| 614 |
-
* @since unknown
|
| 615 |
-
*/
|
| 616 |
-
$admin_menus = apply_filters( 'pods_admin_menu', $admin_menus );
|
| 617 |
-
|
| 618 |
-
$parent = false;
|
| 619 |
-
|
| 620 |
-
// PODS_LIGHT disables all Pods components so remove the components menu
|
| 621 |
-
if ( pods_light() ) {
|
| 622 |
-
unset( $admin_menus['pods-components'] );
|
| 623 |
-
}
|
| 624 |
-
|
| 625 |
-
if ( ! empty( $admin_menus ) && ( ! defined( 'PODS_DISABLE_ADMIN_MENU' ) || ! PODS_DISABLE_ADMIN_MENU ) ) {
|
| 626 |
-
foreach ( $admin_menus as $page => $menu_item ) {
|
| 627 |
-
if ( ! pods_is_admin( pods_v( 'access', $menu_item ) ) ) {
|
| 628 |
-
continue;
|
| 629 |
-
}
|
| 630 |
-
|
| 631 |
-
// Don't just show the help page
|
| 632 |
-
if ( false === $parent && 'pods-help' === $page ) {
|
| 633 |
-
continue;
|
| 634 |
-
}
|
| 635 |
-
|
| 636 |
-
if ( ! isset( $menu_item['label'] ) ) {
|
| 637 |
-
$menu_item['label'] = $page;
|
| 638 |
-
}
|
| 639 |
-
|
| 640 |
-
if ( false === $parent ) {
|
| 641 |
-
$parent = $page;
|
| 642 |
-
|
| 643 |
-
$menu = __( 'Pods Admin', 'pods' );
|
| 644 |
-
|
| 645 |
-
if ( 'pods-upgrade' === $parent ) {
|
| 646 |
-
$menu = __( 'Pods Upgrade', 'pods' );
|
| 647 |
-
}
|
| 648 |
-
|
| 649 |
-
add_menu_page( $menu, $menu, 'read', $parent, null, 'dashicons-pods' );
|
| 650 |
-
}
|
| 651 |
-
|
| 652 |
-
add_submenu_page( $parent, $menu_item['label'], $menu_item['label'], 'read', $page, $menu_item['function'] );
|
| 653 |
-
|
| 654 |
-
if ( 'pods-components' === $page && is_object( PodsInit::$components ) ) {
|
| 655 |
-
PodsInit::$components->menu( $parent );
|
| 656 |
-
}
|
| 657 |
-
}//end foreach
|
| 658 |
-
}//end if
|
| 659 |
-
}
|
| 660 |
-
|
| 661 |
-
/**
|
| 662 |
-
* Set the correct parent_file to highlight the correct top level menu
|
| 663 |
-
*
|
| 664 |
-
* @param string $parent_file The parent file.
|
| 665 |
-
*
|
| 666 |
-
* @return mixed|string
|
| 667 |
-
*
|
| 668 |
-
* @since unknown
|
| 669 |
-
*/
|
| 670 |
-
public function parent_file( $parent_file ) {
|
| 671 |
-
|
| 672 |
-
global $current_screen;
|
| 673 |
-
|
| 674 |
-
if ( isset( $current_screen ) && ! empty( $current_screen->taxonomy ) ) {
|
| 675 |
-
$taxonomies = PodsMeta::$taxonomies;
|
| 676 |
-
if ( ! empty( $taxonomies ) ) {
|
| 677 |
-
foreach ( (array) $taxonomies as $pod ) {
|
| 678 |
-
if ( $current_screen->taxonomy !== $pod['name'] ) {
|
| 679 |
-
continue;
|
| 680 |
-
}
|
| 681 |
-
|
| 682 |
-
$menu_slug = 'edit-tags.php?taxonomy=' . $pod['name'];
|
| 683 |
-
$menu_location = pods_v( 'menu_location', $pod['options'], 'default' );
|
| 684 |
-
$menu_location_custom = pods_v( 'menu_location_custom', $pod['options'], '' );
|
| 685 |
-
|
| 686 |
-
if ( 'settings' === $menu_location ) {
|
| 687 |
-
$parent_file = 'options-general.php';
|
| 688 |
-
} elseif ( 'appearances' === $menu_location ) {
|
| 689 |
-
$parent_file = 'themes.php';
|
| 690 |
-
} elseif ( 'objects' === $menu_location ) {
|
| 691 |
-
$parent_file = $menu_slug;
|
| 692 |
-
} elseif ( 'top' === $menu_location ) {
|
| 693 |
-
$parent_file = $menu_slug;
|
| 694 |
-
} elseif ( 'submenu' === $menu_location && ! empty( $menu_location_custom ) ) {
|
| 695 |
-
$parent_file = $menu_location_custom;
|
| 696 |
-
}
|
| 697 |
-
|
| 698 |
-
break;
|
| 699 |
-
}//end foreach
|
| 700 |
-
}//end if
|
| 701 |
-
}//end if
|
| 702 |
-
|
| 703 |
-
if ( isset( $current_screen ) && ! empty( $current_screen->post_type ) && is_object( PodsInit::$components ) ) {
|
| 704 |
-
global $submenu_file;
|
| 705 |
-
|
| 706 |
-
$components = PodsInit::$components->components;
|
| 707 |
-
|
| 708 |
-
foreach ( $components as $component => $component_data ) {
|
| 709 |
-
if ( ! empty( $component_data['MenuPage'] ) && $parent_file === $component_data['MenuPage'] ) {
|
| 710 |
-
$parent_file = 'pods';
|
| 711 |
-
|
| 712 |
-
// @codingStandardsIgnoreLine
|
| 713 |
-
$submenu_file = $component_data['MenuPage'];
|
| 714 |
-
}
|
| 715 |
-
}
|
| 716 |
-
}
|
| 717 |
-
|
| 718 |
-
return $parent_file;
|
| 719 |
-
}
|
| 720 |
-
|
| 721 |
-
/**
|
| 722 |
-
* Show upgrade notice.
|
| 723 |
-
*/
|
| 724 |
-
public function upgrade_notice() {
|
| 725 |
-
|
| 726 |
-
echo '<div class="error fade"><p>';
|
| 727 |
-
// @codingStandardsIgnoreLine
|
| 728 |
-
echo sprintf( __( '<strong>NOTICE:</strong> Pods %1$s requires your action to complete the upgrade. Please run the <a href="%2$s">Upgrade Wizard</a>.', 'pods' ), esc_html( PODS_VERSION ), esc_url( admin_url( 'admin.php?page=pods-upgrade' ) ) );
|
| 729 |
-
echo '</p></div>';
|
| 730 |
-
}
|
| 731 |
-
|
| 732 |
-
/**
|
| 733 |
-
* Create PodsUI content for the administration pages
|
| 734 |
-
*/
|
| 735 |
-
public function admin_content() {
|
| 736 |
-
|
| 737 |
-
// @codingStandardsIgnoreLine
|
| 738 |
-
$pod_name = str_replace( array( 'pods-manage-', 'pods-add-new-' ), '', $_GET['page'] );
|
| 739 |
-
|
| 740 |
-
$pod = pods( $pod_name, pods_v( 'id', 'get', null, true ) );
|
| 741 |
-
|
| 742 |
-
// @codingStandardsIgnoreLine
|
| 743 |
-
if ( false !== strpos( $_GET['page'], 'pods-add-new-' ) ) {
|
| 744 |
-
// @codingStandardsIgnoreLine
|
| 745 |
-
$_GET['action'] = pods_v( 'action', 'get', 'add' );
|
| 746 |
-
}
|
| 747 |
-
|
| 748 |
-
$pod->ui();
|
| 749 |
-
}
|
| 750 |
-
|
| 751 |
-
/**
|
| 752 |
-
* Create PodsUI content for the settings administration pages
|
| 753 |
-
*/
|
| 754 |
-
public function admin_content_settings() {
|
| 755 |
-
|
| 756 |
-
// @codingStandardsIgnoreLine
|
| 757 |
-
$pod_name = str_replace( 'pods-settings-', '', $_GET['page'] );
|
| 758 |
-
|
| 759 |
-
$pod = pods( $pod_name );
|
| 760 |
-
|
| 761 |
-
if ( 'custom' !== pods_v( 'ui_style', $pod->pod_data['options'], 'settings', true ) ) {
|
| 762 |
-
$actions_disabled = array(
|
| 763 |
-
'manage' => 'manage',
|
| 764 |
-
'add' => 'add',
|
| 765 |
-
'delete' => 'delete',
|
| 766 |
-
'duplicate' => 'duplicate',
|
| 767 |
-
'view' => 'view',
|
| 768 |
-
'export' => 'export',
|
| 769 |
-
);
|
| 770 |
-
|
| 771 |
-
// @codingStandardsIgnoreLine
|
| 772 |
-
$_GET['action'] = 'edit';
|
| 773 |
-
|
| 774 |
-
$page_title = pods_v( 'label', $pod->pod_data, ucwords( str_replace( '_', ' ', $pod->pod_data['name'] ) ), true );
|
| 775 |
-
$page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod->pod_data );
|
| 776 |
-
|
| 777 |
-
$ui = array(
|
| 778 |
-
'pod' => $pod,
|
| 779 |
-
'fields' => array(
|
| 780 |
-
'edit' => $pod->pod_data['fields'],
|
| 781 |
-
),
|
| 782 |
-
'header' => array(
|
| 783 |
-
'edit' => $page_title,
|
| 784 |
-
),
|
| 785 |
-
'label' => array(
|
| 786 |
-
'edit' => __( 'Save Changes', 'pods' ),
|
| 787 |
-
),
|
| 788 |
-
'style' => pods_v( 'ui_style', $pod->pod_data['options'], 'settings', true ),
|
| 789 |
-
'icon' => pods_evaluate_tags( pods_v( 'menu_icon', $pod->pod_data['options'] ), true ),
|
| 790 |
-
'actions_disabled' => $actions_disabled,
|
| 791 |
-
);
|
| 792 |
-
|
| 793 |
-
$pod_pod_name = $pod->pod;
|
| 794 |
-
|
| 795 |
-
$ui = apply_filters( "pods_admin_ui_{$pod_pod_name}", apply_filters( 'pods_admin_ui', $ui, $pod->pod, $pod ), $pod->pod, $pod );
|
| 796 |
-
|
| 797 |
-
// Force disabled actions, do not pass go, do not collect $two_hundred
|
| 798 |
-
$ui['actions_disabled'] = $actions_disabled;
|
| 799 |
-
|
| 800 |
-
pods_ui( $ui );
|
| 801 |
-
} else {
|
| 802 |
-
$pod_pod_name = $pod->pod;
|
| 803 |
-
do_action( 'pods_admin_ui_custom', $pod );
|
| 804 |
-
do_action( "pods_admin_ui_custom_{$pod_pod_name}", $pod );
|
| 805 |
-
}//end if
|
| 806 |
-
}
|
| 807 |
-
|
| 808 |
-
/**
|
| 809 |
-
* Add media button for Pods shortcode
|
| 810 |
-
*
|
| 811 |
-
* @param string $context Media button context.
|
| 812 |
-
*
|
| 813 |
-
* @return string
|
| 814 |
-
*/
|
| 815 |
-
public function media_button( $context = null ) {
|
| 816 |
-
|
| 817 |
-
// If shortcodes are disabled don't show the button
|
| 818 |
-
if ( defined( 'PODS_DISABLE_SHORTCODE' ) && PODS_DISABLE_SHORTCODE ) {
|
| 819 |
-
return '';
|
| 820 |
-
}
|
| 821 |
-
|
| 822 |
-
/**
|
| 823 |
-
* Filter to remove Pods shortcode button from the post editor.
|
| 824 |
-
*
|
| 825 |
-
* @param bool $show_button Set to false to block the shortcode button from appearing.
|
| 826 |
-
* @param string $context Media button context.
|
| 827 |
-
*
|
| 828 |
-
* @since 2.3.19
|
| 829 |
-
*/
|
| 830 |
-
if ( ! apply_filters( 'pods_admin_media_button', true, $context ) ) {
|
| 831 |
-
return '';
|
| 832 |
-
}
|
| 833 |
-
|
| 834 |
-
$current_page = basename( $_SERVER['PHP_SELF'] );
|
| 835 |
-
$current_page = explode( '?', $current_page );
|
| 836 |
-
$current_page = explode( '#', $current_page[0] );
|
| 837 |
-
$current_page = $current_page[0];
|
| 838 |
-
|
| 839 |
-
// Only show the button on post type pages
|
| 840 |
-
if ( ! in_array(
|
| 841 |
-
$current_page, array(
|
| 842 |
-
'post-new.php',
|
| 843 |
-
'post.php',
|
| 844 |
-
), true
|
| 845 |
-
) ) {
|
| 846 |
-
return '';
|
| 847 |
-
}
|
| 848 |
-
|
| 849 |
-
add_action( 'admin_footer', array( $this, 'mce_popup' ) );
|
| 850 |
-
|
| 851 |
-
echo '<a href="#TB_inline?width=640&inlineId=pods_shortcode_form" class="thickbox button" id="add_pod_button" title="Pods Shortcode"><img style="padding: 0px 6px 0px 0px; margin: -3px 0px 0px;" src="' . esc_url( PODS_URL . 'ui/images/icon16.png' ) . '" alt="' . esc_attr__( 'Pods Shortcode', 'pods' ) . '" />' . esc_html__( 'Pods Shortcode', 'pods' ) . '</a>';
|
| 852 |
-
}
|
| 853 |
-
|
| 854 |
-
/**
|
| 855 |
-
* Enqueue assets for Media Library Popup
|
| 856 |
-
*/
|
| 857 |
-
public function register_media_assets() {
|
| 858 |
-
|
| 859 |
-
if ( 'pods_media_attachment' === pods_v( 'inlineId' ) ) {
|
| 860 |
-
wp_enqueue_style( 'pods-styles' );
|
| 861 |
-
}
|
| 862 |
-
}
|
| 863 |
-
|
| 864 |
-
/**
|
| 865 |
-
* Output Pods shortcode popup window
|
| 866 |
-
*/
|
| 867 |
-
public function mce_popup() {
|
| 868 |
-
|
| 869 |
-
pods_view( PODS_DIR . 'ui/admin/shortcode.php', compact( array_keys( get_defined_vars() ) ) );
|
| 870 |
-
}
|
| 871 |
|
| 872 |
-
|
| 873 |
-
|
| 874 |
-
|
| 875 |
-
public function admin_setup() {
|
| 876 |
|
| 877 |
-
|
|
|
|
|
|
|
| 878 |
|
| 879 |
-
|
| 880 |
-
|
| 881 |
-
|
| 882 |
-
|
| 883 |
-
|
| 884 |
-
|
| 885 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 886 |
|
| 887 |
-
|
| 888 |
-
|
| 889 |
-
// @codingStandardsIgnoreLine
|
| 890 |
-
if ( isset( $_GET['action'] ) && 'add' !== $_GET['action'] ) {
|
| 891 |
-
pods_redirect(
|
| 892 |
-
pods_query_arg(
|
| 893 |
-
array(
|
| 894 |
-
'page' => 'pods',
|
| 895 |
-
// @codingStandardsIgnoreLine
|
| 896 |
-
'action' => $_GET['action'],
|
| 897 |
-
)
|
| 898 |
-
)
|
| 899 |
-
);
|
| 900 |
-
} else {
|
| 901 |
-
// @codingStandardsIgnoreLine
|
| 902 |
-
$_GET['action'] = 'add';
|
| 903 |
-
}
|
| 904 |
-
// @codingStandardsIgnoreLine
|
| 905 |
-
} elseif ( isset( $_GET['action'] ) && 'add' === $_GET['action'] ) {
|
| 906 |
-
pods_redirect(
|
| 907 |
-
pods_query_arg(
|
| 908 |
-
array(
|
| 909 |
-
'page' => 'pods-add-new',
|
| 910 |
-
'action' => '',
|
| 911 |
-
)
|
| 912 |
-
)
|
| 913 |
-
);
|
| 914 |
-
}//end if
|
| 915 |
-
|
| 916 |
-
$types = array(
|
| 917 |
-
'post_type' => __( 'Post Type (extended)', 'pods' ),
|
| 918 |
-
'taxonomy' => __( 'Taxonomy (extended)', 'pods' ),
|
| 919 |
-
'cpt' => __( 'Custom Post Type', 'pods' ),
|
| 920 |
-
'ct' => __( 'Custom Taxonomy', 'pods' ),
|
| 921 |
-
'user' => __( 'User (extended)', 'pods' ),
|
| 922 |
-
'media' => __( 'Media (extended)', 'pods' ),
|
| 923 |
-
'comment' => __( 'Comments (extended)', 'pods' ),
|
| 924 |
-
'pod' => __( 'Advanced Content Type', 'pods' ),
|
| 925 |
-
'settings' => __( 'Custom Settings Page', 'pods' ),
|
| 926 |
-
);
|
| 927 |
-
|
| 928 |
-
$row = false;
|
| 929 |
-
|
| 930 |
-
$pod_types_found = array();
|
| 931 |
-
|
| 932 |
-
$fields = array(
|
| 933 |
-
'label' => array( 'label' => __( 'Label', 'pods' ) ),
|
| 934 |
-
'name' => array( 'label' => __( 'Name', 'pods' ) ),
|
| 935 |
-
'type' => array( 'label' => __( 'Type', 'pods' ) ),
|
| 936 |
-
'storage' => array(
|
| 937 |
-
'label' => __( 'Storage Type', 'pods' ),
|
| 938 |
-
'width' => '10%',
|
| 939 |
-
),
|
| 940 |
-
'field_count' => array(
|
| 941 |
-
'label' => __( 'Number of Fields', 'pods' ),
|
| 942 |
-
'width' => '8%',
|
| 943 |
-
),
|
| 944 |
-
);
|
| 945 |
-
|
| 946 |
-
$total_fields = 0;
|
| 947 |
-
|
| 948 |
-
foreach ( $pods as $k => $pod ) {
|
| 949 |
-
if ( isset( $types[ $pod['type'] ] ) ) {
|
| 950 |
-
if ( in_array(
|
| 951 |
-
$pod['type'], array(
|
| 952 |
-
'post_type',
|
| 953 |
-
'taxonomy',
|
| 954 |
-
), true
|
| 955 |
-
) ) {
|
| 956 |
-
if ( empty( $pod['object'] ) ) {
|
| 957 |
-
if ( 'post_type' === $pod['type'] ) {
|
| 958 |
-
$pod['type'] = 'cpt';
|
| 959 |
-
} else {
|
| 960 |
-
$pod['type'] = 'ct';
|
| 961 |
-
}
|
| 962 |
-
}
|
| 963 |
-
}
|
| 964 |
|
| 965 |
-
|
| 966 |
-
|
| 967 |
-
|
| 968 |
-
|
| 969 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 970 |
|
| 971 |
-
|
| 972 |
-
unset( $pods[ $k ] );
|
| 973 |
|
| 974 |
-
|
| 975 |
-
|
| 976 |
|
| 977 |
-
|
| 978 |
-
|
| 979 |
-
} elseif ( 'all' !== $view ) {
|
| 980 |
-
continue;
|
| 981 |
-
}//end if
|
| 982 |
|
| 983 |
-
|
| 984 |
-
|
| 985 |
-
// @codingStandardsIgnoreLine
|
| 986 |
-
if ( $pod['id'] == pods_v( 'id' ) && 'delete' !== pods_v( 'action' ) ) {
|
| 987 |
-
$row = $pod;
|
| 988 |
-
}
|
| 989 |
-
|
| 990 |
-
$pod = array(
|
| 991 |
-
'id' => $pod['id'],
|
| 992 |
-
'label' => pods_v( 'label', $pod ),
|
| 993 |
-
'name' => pods_v( 'name', $pod ),
|
| 994 |
-
'object' => pods_v( 'object', $pod ),
|
| 995 |
-
'type' => pods_v( 'type', $pod ),
|
| 996 |
-
'real_type' => pods_v( 'real_type', $pod ),
|
| 997 |
-
'storage' => pods_v( 'storage', $pod ),
|
| 998 |
-
'field_count' => count( $pod['fields'] ),
|
| 999 |
-
);
|
| 1000 |
-
|
| 1001 |
-
$total_fields += $pod['field_count'];
|
| 1002 |
-
|
| 1003 |
-
$pods[ $k ] = $pod;
|
| 1004 |
-
}//end foreach
|
| 1005 |
-
|
| 1006 |
-
if ( false === $row && 0 < pods_v( 'id' ) && 'delete' !== pods_v( 'action' ) ) {
|
| 1007 |
-
pods_message( 'Pod not found', 'error' );
|
| 1008 |
-
|
| 1009 |
-
// @codingStandardsIgnoreLine
|
| 1010 |
-
unset( $_GET['id'], $_GET['action'] );
|
| 1011 |
-
}
|
| 1012 |
-
|
| 1013 |
-
$ui = array(
|
| 1014 |
-
'data' => $pods,
|
| 1015 |
-
'row' => $row,
|
| 1016 |
-
'total' => count( $pods ),
|
| 1017 |
-
'total_found' => count( $pods ),
|
| 1018 |
-
'items' => 'Pods',
|
| 1019 |
-
'item' => 'Pod',
|
| 1020 |
-
'fields' => array(
|
| 1021 |
-
'manage' => $fields,
|
| 1022 |
-
),
|
| 1023 |
-
'actions_disabled' => array( 'view', 'export' ),
|
| 1024 |
-
'actions_custom' => array(
|
| 1025 |
-
'add' => array( $this, 'admin_setup_add' ),
|
| 1026 |
-
'edit' => array( $this, 'admin_setup_edit' ),
|
| 1027 |
-
'duplicate' => array(
|
| 1028 |
-
'callback' => array( $this, 'admin_setup_duplicate' ),
|
| 1029 |
-
'restrict_callback' => array( $this, 'admin_setup_duplicate_restrict' ),
|
| 1030 |
-
),
|
| 1031 |
-
'reset' => array(
|
| 1032 |
-
'label' => __( 'Delete All Items', 'pods' ),
|
| 1033 |
-
'confirm' => __( 'Are you sure you want to delete all items from this Pod? If this is an extended Pod, it will remove the original items extended too.', 'pods' ),
|
| 1034 |
-
'callback' => array( $this, 'admin_setup_reset' ),
|
| 1035 |
-
'restrict_callback' => array( $this, 'admin_setup_reset_restrict' ),
|
| 1036 |
-
'nonce' => true,
|
| 1037 |
-
),
|
| 1038 |
-
'delete' => array( $this, 'admin_setup_delete' ),
|
| 1039 |
-
),
|
| 1040 |
-
'action_links' => array(
|
| 1041 |
-
'add' => pods_query_arg(
|
| 1042 |
-
array(
|
| 1043 |
-
'page' => 'pods-add-new',
|
| 1044 |
-
'action' => '',
|
| 1045 |
-
'id' => '',
|
| 1046 |
-
'do' => '',
|
| 1047 |
-
)
|
| 1048 |
-
),
|
| 1049 |
-
),
|
| 1050 |
-
'search' => false,
|
| 1051 |
-
'searchable' => false,
|
| 1052 |
-
'sortable' => true,
|
| 1053 |
-
'pagination' => false,
|
| 1054 |
-
'extra' => array(
|
| 1055 |
-
'total' => ', ' . number_format_i18n( $total_fields ) . ' ' . _n( 'field', 'fields', $total_fields, 'pods' ),
|
| 1056 |
-
),
|
| 1057 |
-
);
|
| 1058 |
-
|
| 1059 |
-
if ( 1 < count( $pod_types_found ) ) {
|
| 1060 |
-
$ui['views'] = array( 'all' => __( 'All', 'pods' ) );
|
| 1061 |
-
$ui['view'] = $view;
|
| 1062 |
-
$ui['heading'] = array( 'views' => __( 'Type', 'pods' ) );
|
| 1063 |
-
$ui['filters_enhanced'] = true;
|
| 1064 |
-
|
| 1065 |
-
foreach ( $pod_types_found as $pod_type => $number_found ) {
|
| 1066 |
-
$ui['views'][ $pod_type ] = $types[ $pod_type ];
|
| 1067 |
-
}
|
| 1068 |
-
}
|
| 1069 |
-
|
| 1070 |
-
// Add our custom callouts.
|
| 1071 |
-
$this->handle_callouts_updates();
|
| 1072 |
-
|
| 1073 |
-
add_filter( 'pods_ui_manage_custom_container_classes', array( $this, 'admin_manage_container_class' ) );
|
| 1074 |
-
add_action( 'pods_ui_manage_after_container', array( $this, 'admin_manage_callouts' ) );
|
| 1075 |
-
|
| 1076 |
-
pods_ui( $ui );
|
| 1077 |
-
}
|
| 1078 |
-
|
| 1079 |
-
/**
|
| 1080 |
-
* Get list of callouts to show.
|
| 1081 |
-
*
|
| 1082 |
-
* @since 2.7.17
|
| 1083 |
-
*
|
| 1084 |
-
* @return array List of callouts.
|
| 1085 |
-
*/
|
| 1086 |
-
public function get_callouts() {
|
| 1087 |
-
$force_callouts = false;
|
| 1088 |
-
|
| 1089 |
-
$page = pods_v( 'page' );
|
| 1090 |
-
|
| 1091 |
-
if ( in_array( $page, array( 'pods-settings', 'pods-help' ), true ) ) {
|
| 1092 |
-
$force_callouts = true;
|
| 1093 |
-
}
|
| 1094 |
-
|
| 1095 |
-
$callouts = get_option( 'pods_callouts' );
|
| 1096 |
-
|
| 1097 |
-
if ( ! $callouts ) {
|
| 1098 |
-
$callouts = array(
|
| 1099 |
-
'friends_2020' => 1,
|
| 1100 |
-
);
|
| 1101 |
-
}
|
| 1102 |
-
|
| 1103 |
-
// Handle Friends of Pods 2020 callout logic.
|
| 1104 |
-
$callouts['friends_2020'] = ! isset( $callouts['friends_2020'] ) || $callouts['friends_2020'] || $force_callouts ? 1 : 0;
|
| 1105 |
-
|
| 1106 |
-
/**
|
| 1107 |
-
* Allow hooking into whether or not the specific callouts should show.
|
| 1108 |
-
*
|
| 1109 |
-
* @since 2.7.17
|
| 1110 |
-
*
|
| 1111 |
-
* @param array List of callouts to enable.
|
| 1112 |
-
*/
|
| 1113 |
-
$callouts = apply_filters( 'pods_admin_callouts', $callouts );
|
| 1114 |
-
|
| 1115 |
-
return $callouts;
|
| 1116 |
-
}
|
| 1117 |
-
|
| 1118 |
-
/**
|
| 1119 |
-
* Handle callouts update logic.
|
| 1120 |
-
*
|
| 1121 |
-
* @since 2.7.17
|
| 1122 |
-
*/
|
| 1123 |
-
public function handle_callouts_updates() {
|
| 1124 |
-
$callouts = get_option( 'pods_callouts' );
|
| 1125 |
-
|
| 1126 |
-
if ( ! $callouts ) {
|
| 1127 |
-
$callouts = array();
|
| 1128 |
-
}
|
| 1129 |
-
|
| 1130 |
-
$disable_pods = pods_v( 'pods_callout_dismiss' );
|
| 1131 |
-
|
| 1132 |
-
// Disable Friends of Pods 2020 callout.
|
| 1133 |
-
if ( 'friends_2020' === $disable_pods ) {
|
| 1134 |
-
$callouts['friends_2020'] = 0;
|
| 1135 |
-
|
| 1136 |
-
update_option( 'pods_callouts', $callouts );
|
| 1137 |
-
} elseif ( 'reset' === $disable_pods ) {
|
| 1138 |
-
$callouts = array();
|
| 1139 |
-
|
| 1140 |
-
update_option( 'pods_callouts', $callouts );
|
| 1141 |
-
}
|
| 1142 |
-
}
|
| 1143 |
-
|
| 1144 |
-
/**
|
| 1145 |
-
* Add class to container if we have callouts to show.
|
| 1146 |
-
*
|
| 1147 |
-
* @since 2.7.17
|
| 1148 |
-
*
|
| 1149 |
-
* @param array $classes List of classes to use.
|
| 1150 |
-
*
|
| 1151 |
-
* @return array List of classes to use.
|
| 1152 |
-
*/
|
| 1153 |
-
public function admin_manage_container_class( $classes ) {
|
| 1154 |
-
$callouts = $this->get_callouts();
|
| 1155 |
-
|
| 1156 |
-
// Only get enabled callouts.
|
| 1157 |
-
$callouts = array_filter( $callouts );
|
| 1158 |
-
|
| 1159 |
-
if ( ! empty( $callouts ) ) {
|
| 1160 |
-
$classes[] = 'pods-admin--flex';
|
| 1161 |
-
}
|
| 1162 |
-
|
| 1163 |
-
return $classes;
|
| 1164 |
-
}
|
| 1165 |
-
|
| 1166 |
-
/**
|
| 1167 |
-
* Add callouts to let admins know about certain things.
|
| 1168 |
-
*
|
| 1169 |
-
* @since 2.7.17
|
| 1170 |
-
*/
|
| 1171 |
-
public function admin_manage_callouts() {
|
| 1172 |
-
$force_callouts = false;
|
| 1173 |
-
|
| 1174 |
-
$page = pods_v( 'page' );
|
| 1175 |
-
|
| 1176 |
-
if ( in_array( $page, array( 'pods-settings', 'pods-help' ), true ) ) {
|
| 1177 |
-
$force_callouts = true;
|
| 1178 |
-
}
|
| 1179 |
-
|
| 1180 |
-
$callouts = $this->get_callouts();
|
| 1181 |
-
|
| 1182 |
-
if ( ! empty( $callouts['friends_2020'] ) ) {
|
| 1183 |
-
?>
|
| 1184 |
-
<div class="pods-admin_friends-callout_container">
|
| 1185 |
-
<?php if ( ! $force_callouts ) : ?>
|
| 1186 |
-
<a href="<?php echo esc_url( add_query_arg( 'pods_callout_dismiss', 'friends_2020' ) ); ?>" class="pods-admin_friends-callout_close">
|
| 1187 |
-
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" x="0px" y="0px" viewBox="0 0 100 125" enable-background="new 0 0 100 100" xml:space="preserve"><polygon points="95,17 83,5 50,38 17,5 5,17 38,50 5,83 17,95 50,62 83,95 95,83 62,50 "/></svg>
|
| 1188 |
-
</a>
|
| 1189 |
-
<?php endif; ?>
|
| 1190 |
-
<div class="pods-admin_friends-callout_logo-container">
|
| 1191 |
-
<svg version="1.1" viewBox="0 0 305 111" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><title>Friends of Pods Logo</title> <defs> <path id="a" d="m0.14762 49.116c0 27.103 21.919 49.075 48.956 49.075 19.888 0 37.007-11.888 44.669-28.962-2.1342-6.538-3.9812-18.041 3.3854-29.538-0.3152-1.624-0.71019-3.219-1.1807-4.781-22.589 22.49-40.827 24.596-54.558 24.229-0.12701-4e-3 -0.58883-0.079-0.71152-0.35667 0 0-0.20016-0.89933 0.38502-0.89933 26.307 0 41.29-15.518 53.531-26.865-0.66763-1.687-1.4264-3.3273-2.2695-4.9167-13.196-3.6393-18.267-14.475-20.067-20.221-6.9007-3.7267-14.796-5.8413-23.184-5.8413-27.037 0-48.956 21.972-48.956 49.076zm62.283-34.287s18.69-2.039 24.194 21.114c-20.424-1.412-24.194-21.114-24.194-21.114zm-7.4779 9.7423s16.57-0.55467 20.342 20.219c-17.938-2.602-20.342-20.219-20.342-20.219zm-9.1018 8.256s14.912-0.97567 18.728 17.626c-16.209-1.8273-18.728-17.626-18.728-17.626zm40.774 3.116c0.021279 0.0013333 0.040563 0.0026667 0.061842 0.0043333l-0.044886 0.067667c-0.0056523-0.024-0.011304-0.048-0.016957-0.072zm-48.709 3.445s13.103-0.859 16.456 15.486c-14.243-1.6047-16.456-15.486-16.456-15.486zm-10.498 1.6027s12.587-0.82333 15.808 14.877c-13.68-1.5417-15.808-14.877-15.808-14.877zm-10.391 0.72233s11.423-0.74667 14.347 13.502c-12.417-1.3997-14.347-13.502-14.347-13.502zm-11.298 2.0857s9.5832-2.526 13.712 9.0523c-0.44919 0.036667-0.88474 0.054333-1.3073 0.054333-9.6148-3.333e-4 -12.405-9.1067-12.405-9.1067zm81.565 0.964c-0.0073147-0.021333-0.014962-0.043667-0.021612-0.064667l0.066497 0.018333c-0.014962 0.015333-0.029924 0.030667-0.044886 0.046333 7.1338 21.557-5.5721 33.29-5.5721 33.29s-8.9279-18.395 5.5721-33.29zm-11.999 0.027333c0.017622 0.0023333 0.035576 5e-3 0.053198 0.0076667l-0.041561 0.056c-0.0036573-0.021667-0.0073147-0.042-0.011637-0.063667zm-10.716 5.6627c0.015959 2e-3 0.032916 0.0036666 0.048543 0.0056666l-0.036573 0.051c-0.0039899-0.019667-0.0076472-0.037333-0.01197-0.056667zm12.212 1.8693c-0.0023274-0.021-0.0046548-0.043333-0.0066497-0.064667l0.056523 0.035667c-0.016624 0.01-0.032916 0.019333-0.049873 0.029 2.2323 21.678-11.682 28.793-11.682 28.793s-4.4962-19.303 11.682-28.793zm-57.318 0.52633-0.018619 0.037333c-0.0039899-0.011667-0.0086447-0.023667-0.012302-0.034667 0.010307-1e-3 0.020614-0.0016667 0.030921-0.0026667zm34.9 2.0257c0.013964 0.0013333 0.027264 3e-3 0.041561 0.0043333l-0.031254 0.046333c-0.0036573-0.017-0.0069822-0.034-0.010307-0.050667zm-22.998 0.34067c0.012302 0.0016666 0.025269 3e-3 0.037571 0.0043333l-0.028594 0.039c-0.0029924-0.014667-0.0056523-0.028667-0.0089771-0.043333zm-16.9 3.542s8.0594-7.693 18.254 0.88467c-3.1137 2.6673-6.0605 3.5853-8.642 3.5853-5.6965 0-9.6125-4.47-9.6125-4.47zm28.752-2.8893c0.013632 0.0013334 0.027264 3e-3 0.040896 0.0043334l-0.030589 0.045c-0.0033249-0.016-0.0069822-0.033333-0.010307-0.049333zm21.183 2.4917c3.325e-4 -0.019 3.325e-4 -0.039333 6.65e-4 -0.058333l0.046548 0.039667c-0.015959 0.0063334-0.031254 0.012333-0.047213 0.018667-0.19118 19.436-13.172 23.733-13.172 23.733s-2.0415-17.662 13.172-23.733zm-31.651 1.257v0.05c-0.0099746-0.0083333-0.019617-0.016333-0.029259-0.024667 0.0093096-0.0086666 0.019284-0.017 0.029259-0.025333zm-6.6234 10.543s4.296-11.202 16.634-9.0197c-3.5273 8.062-9.0759 9.5947-12.782 9.5947-2.2719 0-3.8515-0.575-3.8515-0.575zm16.651-9.0593 0.018287 0.046c-0.01197-2e-3 -0.023606-0.0043334-0.035576-0.0063334 0.0059848-0.013333 0.011637-0.026333 0.017289-0.039667zm10.12 0.685c0.0029923-0.016333 0.0059847-0.033333 0.0089771-0.049667l0.034911 0.043c-0.014629 0.0023333-0.029259 0.0046667-0.043888 0.0066667-2.9518 16.71-14.755 17.762-14.755 17.762s0.77369-15.639 14.755-17.762z"/> </defs> <g fill="none" fill-rule="evenodd"> <g transform="translate(6.3172 6.3333)"> <mask id="b" fill="white"> <use xlink:href="#a"/> </mask> <polygon points="-3.1772 -3.2937 100.48 -3.2937 100.48 101.52 -3.1772 101.52" fill="#fff" mask="url(#b)"/> </g> <path d="m55.303 3.569c-28.538 0-51.754 23.273-51.754 51.88 0 28.607 23.216 51.88 51.754 51.88 28.538 0 51.754-23.273 51.754-51.88 0-28.607-23.217-51.88-51.754-51.88m0 107.18c-30.417 0-55.163-24.807-55.163-55.298 0-30.492 24.746-55.298 55.163-55.298 30.417 0 55.164 24.807 55.164 55.298 0 30.491-24.747 55.298-55.164 55.298" fill="#fff"/> <path d="m137.42 77.263-2.7699 22.725h-14.958l8.2174-67.434h22.252c4.001 0 7.4249 0.48597 10.272 1.4579 2.8469 0.97195 5.1859 2.3141 7.0171 4.0266 1.8312 1.7125 3.1777 3.7335 4.0395 6.0631 0.86176 2.3296 1.2926 4.8366 1.2926 7.521 0 3.6718-0.56167 7.0736-1.685 10.205-1.1234 3.1318-2.8392 5.8394-5.1474 8.1227s-5.232 4.0729-8.7714 5.3688-7.725 1.9439-12.557 1.9439h-7.2018zm4.1549-33.463-2.7238 22.123h7.248c2.1544 0 3.9625-0.31626 5.4244-0.9488 1.4619-0.63254 2.6468-1.5273 3.5547-2.6844 0.90792-1.1571 1.5619-2.5378 1.962-4.1423 0.4001-1.6045 0.60015-3.3632 0.60015-5.2763 0-1.3268-0.17696-2.5456-0.5309-3.6564-0.35394-1.1108-0.90022-2.0673-1.6389-2.8695-0.73865-0.80224-1.6696-1.4271-2.793-1.8745-1.1234-0.4474-2.4544-0.6711-3.9933-0.6711h-7.1095zm48.956 46.283c1.6004 0 3.0315-0.48597 4.2934-1.4579 1.2619-0.97195 2.3313-2.2987 3.2085-3.9803 0.87714-1.6816 1.5542-3.6409 2.0313-5.8779 0.47704-2.237 0.71556-4.6206 0.71556-7.1507 0-3.4867-0.46934-5.9782-1.408-7.4747-0.9387-1.4965-2.4698-2.2447-4.5934-2.2447-1.6004 0-3.0315 0.48597-4.2934 1.4579-1.2619 0.97195-2.3313 2.291-3.2085 3.9572s-1.5542 3.6255-2.0313 5.8779c-0.47704 2.2525-0.71556 4.6437-0.71556 7.1739 0 3.425 0.46934 5.9011 1.408 7.4284 0.9387 1.5273 2.4698 2.291 4.5934 2.291zm-1.2926 10.645c-2.6776 0-5.1782-0.4474-7.5019-1.3422-2.3237-0.89481-4.3395-2.1984-6.0477-3.9109-1.7081-1.7125-3.0469-3.8261-4.0164-6.3408-0.96948-2.5147-1.4542-5.4074-1.4542-8.6781 0-4.2581 0.70017-8.1689 2.1005-11.733 1.4004-3.5638 3.2854-6.6416 5.6552-9.2335s5.1166-4.6129 8.2405-6.0631 6.4093-2.1753 9.8563-2.1753c2.6776 0 5.1705 0.4474 7.4788 1.3422 2.3083 0.89481 4.3164 2.1984 6.0246 3.9109 1.7081 1.7125 3.0546 3.8261 4.0395 6.3408 0.98486 2.5147 1.4773 5.4074 1.4773 8.6781 0 4.1963-0.70017 8.0764-2.1005 11.64-1.4004 3.5638-3.2854 6.6493-5.6552 9.2566-2.3698 2.6073-5.1166 4.6437-8.2405 6.1094-3.1239 1.4656-6.4093 2.1984-9.8563 2.1984zm62.6-0.74053c-0.89253 0-1.6389-0.11571-2.239-0.34712-0.60015-0.23142-1.0772-0.54768-1.4311-0.9488s-0.60015-0.87937-0.73864-1.4348c-0.1385-0.5554-0.20774-1.1571-0.20774-1.805v-4.0266c-2.1852 2.9004-4.6011 5.176-7.248 6.8267-2.6468 1.6508-5.4629 2.4761-8.4482 2.4761-1.9697 0-3.7702-0.34712-5.4013-1.0414-1.6312-0.69425-3.0392-1.7819-4.2241-3.263s-2.1082-3.3709-2.7699-5.6697c-0.66171-2.2987-0.99255-5.0525-0.99255-8.2615 0-2.777 0.29238-5.4845 0.87714-8.1227 0.58476-2.6381 1.4003-5.1143 2.4468-7.4284s2.2929-4.4354 3.7394-6.3639c1.4465-1.9285 3.0392-3.5792 4.7781-4.9523 1.7389-1.3731 3.5778-2.4453 5.5168-3.2167s3.9394-1.1571 6.0015-1.1571c1.9697 0 3.7471 0.33169 5.3321 0.99508 1.585 0.66339 2.9777 1.535 4.178 2.615l3.0469-24.16h14.034l-8.5867 69.286h-7.6634zm-14.588-10.182c0.98486 0 2.0082-0.37026 3.07-1.1108s2.0928-1.7587 3.0931-3.0547 1.9312-2.8155 2.793-4.5589c0.86176-1.7433 1.6004-3.6178 2.2159-5.6234l1.4773-11.663c-0.89253-0.70968-1.8851-1.2188-2.9777-1.5273s-2.1313-0.46283-3.1162-0.46283c-1.662 0-3.1931 0.55539-4.5934 1.6662s-2.6083 2.5687-3.624 4.3737c-1.0156 1.805-1.8081 3.8646-2.3775 6.1788s-0.85406 4.6746-0.85406 7.0813c0 3.0547 0.44626 5.2685 1.3388 6.6416 0.89253 1.3731 2.0774 2.0596 3.5547 2.0596zm63.465-27.724c-0.43088 0.5554-0.83097 0.95651-1.2003 1.2034s-0.86175 0.37026-1.4773 0.37026-1.2234-0.13885-1.8235-0.41655-1.2465-0.59396-1.9389-0.9488c-0.69248-0.35484-1.4773-0.6711-2.3544-0.9488-0.87714-0.2777-1.8851-0.41655-3.0238-0.41655-2.1236 0-3.6394 0.40883-4.5473 1.2265-0.90792 0.81767-1.3619 1.8745-1.3619 3.1704 0 0.8331 0.25391 1.5428 0.76173 2.129 0.50782 0.58625 1.1772 1.1108 2.0082 1.5736 0.83098 0.46283 1.7774 0.88709 2.8392 1.2728 1.0618 0.38569 2.1467 0.81766 3.2547 1.2959 1.108 0.47826 2.1928 1.0259 3.2547 1.643s2.0082 1.3731 2.8392 2.2679c0.83098 0.89481 1.5004 1.9593 2.0082 3.1935 0.50782 1.2342 0.76173 2.6998 0.76173 4.3969 0 2.4067-0.47704 4.6823-1.4311 6.8267-0.95409 2.1445-2.3236 4.0112-4.1087 5.6002-1.7851 1.5891-3.9471 2.8541-6.4862 3.7952-2.5391 0.94109-5.3936 1.4116-8.5637 1.4116-1.5081 0-3.0007-0.15428-4.478-0.46283-1.4773-0.30856-2.8699-0.7251-4.178-1.2496s-2.5006-1.1494-3.5778-1.8745c-1.0772-0.7251-1.9543-1.5042-2.6314-2.3373l3.5086-5.2763c0.43088-0.61711 0.931-1.1031 1.5004-1.4579 0.56938-0.35484 1.2695-0.53225 2.1005-0.53225 0.76942 0 1.4311 0.18513 1.9851 0.5554 0.55399 0.37027 1.1541 0.77138 1.8004 1.2034s1.4157 0.83309 2.3083 1.2034c0.89253 0.37027 2.062 0.5554 3.5086 0.5554 2.0313 0 3.5393-0.45511 4.5242-1.3653 0.98486-0.91024 1.4773-1.9824 1.4773-3.2167 0-0.95652-0.25391-1.7433-0.76173-2.3604-0.50782-0.61711-1.1772-1.1494-2.0082-1.5968-0.83098-0.4474-1.7697-0.84852-2.8161-1.2034-1.0464-0.35484-2.1236-0.74824-3.2316-1.1802s-2.1852-0.93337-3.2316-1.5042c-1.0464-0.57083-1.9851-1.2882-2.8161-2.1522-0.83098-0.86395-1.5004-1.9285-2.0082-3.1935-0.50782-1.2651-0.76173-2.7924-0.76173-4.582 0-2.2216 0.40779-4.3814 1.2234-6.4796s2.0313-3.9572 3.6471-5.5771c1.6158-1.6199 3.624-2.9235 6.0246-3.9109s5.2013-1.4811 8.4021-1.4811c3.2008 0 6.0553 0.55539 8.5637 1.6662 2.5083 1.1108 4.578 2.4684 6.2092 4.0729l-3.6932 5.0911z" fill="#fff"/> <g transform="translate(128.86 3.5426)" fill="#fff"> <path d="m14.411 3.7958h-8.3873l-0.77821 6.399h7.0759l-0.3891 3.0104h-7.0471l-1.052 8.6095h-3.7613l2.5652-21.029h12.149l-0.37469 3.0104zm-0.59086 18.019 1.8014-14.936h1.8014c0.34587 0 0.62929 0.077562 0.85026 0.23269 0.22097 0.15513 0.33146 0.40236 0.33146 0.7417v0.050901c0 0.033934-0.0048037 0.13331-0.014411 0.29813s-0.019215 0.42417-0.028822 0.77806c-0.0096075 0.35388-0.028822 0.85077-0.057645 1.4907 0.60527-1.1732 1.2682-2.0797 1.9887-2.7196 0.72056-0.6399 1.4699-0.95985 2.2482-0.95985 0.39391 0 0.79262 0.087258 1.1961 0.26178l-0.6485 3.4322c-0.48038-0.2036-0.93673-0.30541-1.3691-0.30541-0.85507 0-1.6044 0.41205-2.2482 1.2362-0.6437 0.82411-1.1721 2.1136-1.5852 3.8685l-0.77821 6.5299h-3.4875zm16.083-14.921-1.7726 14.921h-3.5163l1.7726-14.921h3.5163zm0.8935-4.3484c0 0.31025-0.06485 0.60111-0.19455 0.87259-0.1297 0.27147-0.29783 0.50901-0.50439 0.71261-0.20656 0.2036-0.44434 0.366-0.71336 0.48719-0.26901 0.12119-0.54762 0.18179-0.83585 0.18179-0.27862 0-0.55003-0.060596-0.81423-0.18179-0.26421-0.12119-0.49719-0.28359-0.69894-0.48719s-0.36268-0.44114-0.48278-0.71261c-0.12009-0.27147-0.18014-0.56233-0.18014-0.87259s0.062448-0.60596 0.18735-0.88713 0.28822-0.52597 0.48998-0.73443c0.20176-0.20845 0.43474-0.37327 0.69894-0.49447 0.26421-0.12119 0.53562-0.18179 0.81423-0.18179 0.28823 0 0.56684 0.060596 0.83585 0.18179 0.26901 0.12119 0.50679 0.28359 0.71336 0.48719 0.20656 0.2036 0.37229 0.44599 0.49719 0.72716s0.18735 0.58172 0.18735 0.90167zm13.402 7.8097c0 0.66899-0.1321 1.2798-0.39631 1.8324-0.26421 0.55264-0.73737 1.0471-1.4195 1.4834-0.68213 0.4363-1.6068 0.81199-2.7742 1.1271-1.1673 0.3151-2.6541 0.56476-4.4603 0.74897v0.18906c0 2.3463 0.98476 3.5194 2.9543 3.5194 0.42273 0 0.79742-0.041205 1.1241-0.12362s0.61248-0.18179 0.85747-0.29813 0.46596-0.24723 0.66292-0.39266c0.19695-0.14543 0.37949-0.27632 0.54763-0.39266 0.16813-0.11635 0.33386-0.21572 0.49719-0.29813 0.16333-0.082411 0.34106-0.12362 0.53322-0.12362 0.11529 0 0.23058 0.026662 0.34587 0.079987 0.11529 0.053325 0.21136 0.13331 0.28822 0.23996l0.90791 1.1053c-0.5092 0.51386-1.0088 0.95984-1.4988 1.338-0.48998 0.37812-0.98957 0.68837-1.4988 0.93076-0.5092 0.24239-1.0472 0.42175-1.6141 0.5381-0.56684 0.11635-1.1865 0.17452-1.859 0.17452-0.86468 0-1.6477-0.14785-2.349-0.44356-0.70135-0.29571-1.3018-0.71261-1.8014-1.2507-0.49959-0.5381-0.88629-1.1877-1.1601-1.9488-0.27381-0.76109-0.41072-1.6119-0.41072-2.5523 0-0.78533 0.084065-1.5561 0.2522-2.3124 0.16813-0.75625 0.41072-1.4737 0.72777-2.1524 0.31705-0.67868 0.70615-1.304 1.1673-1.8761 0.46116-0.57203 0.98236-1.0665 1.5636-1.4834 0.58126-0.4169 1.2201-0.7417 1.9167-0.97439 0.69655-0.23269 1.4435-0.34903 2.2409-0.34903 0.77821 0 1.4579 0.1115 2.0392 0.33449 0.58126 0.223 1.0664 0.51143 1.4555 0.86532 0.3891 0.35388 0.67973 0.74897 0.87188 1.1853 0.19215 0.4363 0.28822 0.86289 0.28822 1.2798zm-4.8566-1.1634c-0.48038 0-0.92712 0.099377-1.3402 0.29813-0.41312 0.19876-0.78541 0.4775-1.1169 0.83623-0.33146 0.35873-0.61968 0.78775-0.86467 1.2871-0.24499 0.49932-0.43954 1.0447-0.58365 1.6361 1.1913-0.16482 2.1497-0.34419 2.875-0.5381 0.72537-0.19391 1.2874-0.40721 1.6861-0.6399 0.39871-0.23269 0.66292-0.47992 0.79262-0.7417 0.1297-0.26178 0.19455-0.54294 0.19455-0.8435 0-0.14543-0.031224-0.29571-0.093673-0.45084-0.062449-0.15513-0.15852-0.29329-0.28822-0.41448-0.1297-0.12119-0.29783-0.22299-0.50439-0.30541-0.20656-0.082411-0.45876-0.12362-0.75659-0.12362zm6.0095 12.623 1.7726-14.936h1.8158c0.37469 0 0.66532 0.092105 0.87188 0.27632 0.20656 0.18421 0.30984 0.47992 0.30984 0.88713l-0.10088 1.9342c0.74939-1.115 1.5804-1.9464 2.4931-2.4941 0.91272-0.54779 1.8542-0.82169 2.8246-0.82169 0.54763 0 1.0448 0.099377 1.4916 0.29813s0.82864 0.48962 1.1457 0.87259 0.56204 0.85319 0.73497 1.4107c0.17294 0.55749 0.2594 1.1998 0.2594 1.927 0 0.18421-0.0072055 0.37085-0.021617 0.55991s-0.031224 0.38539-0.050439 0.589l-1.1097 9.4967h-3.5596c0.19215-1.6385 0.35548-3.0274 0.48998-4.1666 0.13451-1.1392 0.24499-2.0869 0.33146-2.8432 0.086468-0.75625 0.15372-1.3501 0.20176-1.7815 0.048038-0.43145 0.084065-0.75866 0.10808-0.98166 0.024019-0.223 0.03843-0.37085 0.043234-0.44356s0.0072056-0.13331 0.0072056-0.18179c0-0.6399-0.11529-1.1029-0.34587-1.3889s-0.59086-0.42902-1.0808-0.42902c-0.39391 0-0.80222 0.11634-1.225 0.34903-0.42273 0.23269-0.82624 0.56233-1.2105 0.98893-0.3843 0.4266-0.73497 0.94045-1.052 1.5416-0.31705 0.60112-0.57645 1.2701-0.77821 2.0069l-0.80703 7.3297h-3.5596zm25.738 0c-0.43234 0-0.73497-0.1018-0.90791-0.30541-0.17294-0.2036-0.2594-0.46053-0.2594-0.77078l0.11529-2.1815c-0.71096 1.0665-1.5084 1.9124-2.3923 2.5378-0.88389 0.62536-1.8254 0.93803-2.8246 0.93803-0.61488 0-1.1745-0.11392-1.6789-0.34176-0.5044-0.22784-0.93433-0.5696-1.2898-1.0253s-0.62929-1.0326-0.82144-1.7306c-0.19215-0.69807-0.28822-1.5222-0.28822-2.4723 0-0.8435 0.086466-1.67 0.2594-2.4796 0.17294-0.80957 0.41792-1.5779 0.73497-2.3051 0.31705-0.72716 0.69414-1.3961 1.1313-2.0069 0.43714-0.61081 0.92472-1.1392 1.4627-1.5852 0.53802-0.44599 1.1121-0.79502 1.7221-1.0471s1.2418-0.37812 1.8951-0.37812c0.66292 0 1.2634 0.12119 1.8014 0.36358 0.53802 0.24239 1.0088 0.57203 1.4123 0.98893l0.96555-7.8097h3.4875l-2.6373 21.611h-1.8879zm-4.8854-2.6032c-0.60527 0-1.076-0.2545-1.4123-0.76351-0.33626-0.50901-0.50439-1.2871-0.50439-2.3342 0-0.80472 0.10088-1.607 0.30264-2.4069 0.20176-0.79988 0.48758-1.5198 0.85747-2.1597 0.36989-0.6399 0.81423-1.1586 1.333-1.5561 0.51881-0.39751 1.0952-0.59627 1.7293-0.59627 0.40352 0 0.81663 0.072715 1.2394 0.21815s0.79742 0.39751 1.1241 0.75624l-0.44675 3.6212c-0.23058 0.73685-0.50679 1.4228-0.82865 2.0579-0.32185 0.63505-0.67012 1.1877-1.0448 1.6579-0.37469 0.47023-0.76379 0.83865-1.1673 1.1053s-0.79742 0.39994-1.1817 0.39994zm19.549-9.5612c-0.10501 0.15274-0.20525 0.26014-0.30071 0.32219-0.095464 0.062051-0.21956 0.093077-0.37231 0.093077-0.16229 0-0.32935-0.047731-0.50118-0.14319-0.17183-0.095464-0.36992-0.20286-0.59426-0.32219-0.22434-0.11933-0.48209-0.22672-0.77325-0.32219s-0.64199-0.14319-1.0525-0.14319c-0.75416 0-1.3317 0.16945-1.7327 0.50834-0.40095 0.3389-0.60142 0.76132-0.60142 1.2673 0 0.29594 0.083529 0.54653 0.25059 0.75177s0.38424 0.38424 0.65154 0.53698c0.2673 0.15274 0.57278 0.29355 0.91645 0.42242s0.69688 0.2673 1.0596 0.41526 0.71597 0.31503 1.0596 0.50118c0.34367 0.18615 0.64915 0.41288 0.91645 0.68017 0.2673 0.2673 0.48447 0.58948 0.65154 0.96656s0.25059 0.82814 0.25059 1.3532c0 0.70643-0.14081 1.3794-0.42242 2.019-0.28162 0.63961-0.68495 1.2004-1.21 1.6825-0.52505 0.48209-1.1599 0.86394-1.9045 1.1456-0.74462 0.28162-1.5751 0.42242-2.4916 0.42242-0.46777 0-0.91883-0.045344-1.3532-0.13603-0.43436-0.09069-0.84246-0.21718-1.2243-0.37947-0.38185-0.16229-0.7279-0.35321-1.0382-0.57278-0.31026-0.21957-0.57516-0.45822-0.79473-0.71597l0.85917-1.346c0.10501-0.16229 0.2315-0.28639 0.37947-0.37231 0.14797-0.085917 0.32219-0.12888 0.52266-0.12888s0.38185 0.06205 0.54414 0.18615c0.16229 0.1241 0.35321 0.26014 0.57278 0.4081s0.48447 0.284 0.79473 0.4081 0.70881 0.18615 1.1957 0.18615c0.3914 0 0.73745-0.052504 1.0382-0.15751 0.30071-0.10501 0.55369-0.2482 0.75893-0.42958 0.20525-0.18138 0.36037-0.3914 0.46538-0.63006 0.10501-0.23866 0.15751-0.49163 0.15751-0.75893 0-0.32458-0.081143-0.59426-0.24343-0.80905-0.16229-0.21479-0.37946-0.40094-0.65154-0.55846-0.27207-0.15751-0.57994-0.29594-0.92361-0.41526s-0.69449-0.24582-1.0525-0.37947c-0.35799-0.13365-0.70643-0.28639-1.0453-0.45822s-0.64437-0.38901-0.91645-0.65154c-0.27207-0.26252-0.48925-0.58232-0.65154-0.9594-0.16229-0.37708-0.24343-0.83769-0.24343-1.3818 0-0.64915 0.1241-1.2816 0.37231-1.8973 0.24821-0.61574 0.61335-1.1599 1.0954-1.6324 0.48209-0.47254 1.074-0.85201 1.7756-1.1384 0.70166-0.28639 1.5059-0.42958 2.4128-0.42958 0.93554 0 1.7637 0.1599 2.4844 0.4797 0.72075 0.3198 1.3293 0.7279 1.8257 1.2243l-0.91645 1.2888z"/> <path d="m57.693 40.297c0.49639 0 0.94473-0.14341 1.345-0.43023 0.40031-0.28682 0.74258-0.6706 1.0268-1.1513 0.28422-0.48073 0.50239-1.0402 0.65451-1.6785 0.15212-0.63828 0.22818-1.3089 0.22818-2.0118 0-1.0099-0.17013-1.7533-0.5104-2.2299-0.34027-0.47669-0.85466-0.71504-1.5432-0.71504-0.49639 0-0.94473 0.14139-1.345 0.42417s-0.74058 0.66656-1.0208 1.1513c-0.28022 0.48477-0.49639 1.0463-0.6485 1.6846-0.15212 0.63828-0.22818 1.3129-0.22818 2.0239 0 1.0099 0.16813 1.7512 0.50439 2.2239s0.84866 0.70898 1.5372 0.70898zm-0.26421 2.3027c-0.68053 0-1.311-0.11513-1.8915-0.3454s-1.0808-0.56758-1.5012-1.012-0.75058-0.98974-0.99077-1.6361c-0.24019-0.64636-0.36028-1.3856-0.36028-2.2178 0-1.0746 0.17013-2.0764 0.5104-3.0056 0.34027-0.92915 0.80462-1.7331 1.3931-2.4117 0.58846-0.67868 1.275-1.2119 2.0596-1.5997 0.78461-0.38782 1.6213-0.58172 2.51-0.58172 0.68053 0 1.311 0.11513 1.8915 0.3454s1.0828 0.56758 1.5072 1.012c0.42433 0.44438 0.75659 0.98974 0.99678 1.6361 0.24019 0.64636 0.36028 1.3856 0.36028 2.2178 0 1.0665-0.17213 2.0623-0.5164 2.9874-0.34427 0.92511-0.81063 1.729-1.3991 2.4117-0.58846 0.68272-1.275 1.22-2.0596 1.6119-0.78461 0.39186-1.6213 0.58778-2.51 0.58778zm12.177-10.374-1.1649 9.6833-0.61248 2.2784c-0.11209 0.3959-0.28622 0.69888-0.52241 0.90894-0.23619 0.21007-0.57044 0.3151-1.0028 0.3151h-1.1889l1.5732-13.186-0.94874-0.16967c-0.17614-0.032318-0.32025-0.098973-0.43234-0.19997-0.11209-0.10099-0.16813-0.2444-0.16813-0.43023 0-0.0080796 0.0020015-0.024238 0.0060047-0.048477 0.0040031-0.024239 0.010008-0.078775 0.018014-0.16361 0.0080063-0.084835 0.022017-0.21411 0.042033-0.38782 0.020016-0.17371 0.050039-0.41811 0.09007-0.73322h1.6573l0.10808-0.92106c0.088069-0.711 0.27421-1.3493 0.55843-1.9148 0.28422-0.56557 0.6445-1.0463 1.0808-1.4422 0.43634-0.3959 0.93873-0.69888 1.5072-0.90894 0.56845-0.21007 1.1809-0.3151 1.8374-0.3151 0.5124 0 0.98476 0.076755 1.4171 0.23027l-0.26421 1.5513c-0.016013 0.088875-0.054042 0.15957-0.11409 0.21209-0.060047 0.052517-0.1341 0.090894-0.22217 0.11513s-0.18614 0.040398-0.29423 0.048477c-0.10808 0.0080796-0.21817 0.012119-0.33026 0.012119-0.32025 0-0.61448 0.044437-0.88269 0.13331s-0.50439 0.23228-0.70855 0.43023c-0.20416 0.19795-0.37229 0.45649-0.50439 0.77563-0.1321 0.31914-0.22618 0.70897-0.28222 1.1695l-0.096075 0.82411h2.7622l-0.27622 2.133h-2.6421z"/> </g> </g> </svg>
|
| 1192 |
-
</div>
|
| 1193 |
-
<div class="pods-admin_friends-callout_content-container">
|
| 1194 |
-
<h2 class="pods-admin_friends-callout_headline"><?php printf( esc_html__( 'We need %1$sYOU%2$s in 2020 and beyond', 'pods' ), '<span class="pods-admin_friends-you">', '</span>' ); ?></h2>
|
| 1195 |
-
<p class="pods-admin_friends-callout_text"><?php esc_html_e( 'Things are changing for Pods and we want you to be a part of it! Our goal is to be fully funded by users like you. Help us reach our goal of 200 recurring donors in 2020.', 'pods' ); ?></p>
|
| 1196 |
-
<div class="pods-admin_friends-callout_button-group">
|
| 1197 |
-
<a href="https://friends.pods.io/?utm_source=pods_plugin_callout&utm_medium=link&utm_campaign=friends_of_pods_2020" class="pods-admin_friends-callout_button"><?php esc_html_e( 'Learn More', 'pods' ); ?></a>
|
| 1198 |
-
<a href="https://friends.pods.io/membership-levels/?utm_source=pods_plugin_callout&utm_medium=link&utm_campaign=friends_of_pods_2020" class="pods-admin_friends-callout_button--join"><?php esc_html_e( 'Join Now', 'pods' ); ?></a>
|
| 1199 |
-
</div>
|
| 1200 |
-
</div>
|
| 1201 |
-
</div>
|
| 1202 |
-
<?php
|
| 1203 |
-
}
|
| 1204 |
-
}
|
| 1205 |
-
|
| 1206 |
-
/**
|
| 1207 |
-
* Get the add page of an object
|
| 1208 |
-
*
|
| 1209 |
-
* @param PodsUI $obj PodsUI object.
|
| 1210 |
-
*/
|
| 1211 |
-
public function admin_setup_add( $obj ) {
|
| 1212 |
-
|
| 1213 |
-
pods_view( PODS_DIR . 'ui/admin/setup-add.php', compact( array_keys( get_defined_vars() ) ) );
|
| 1214 |
-
}
|
| 1215 |
-
|
| 1216 |
-
/**
|
| 1217 |
-
* Get the edit page of an object
|
| 1218 |
-
*
|
| 1219 |
-
* @param boolean $duplicate Whether the screen is for duplicating.
|
| 1220 |
-
* @param PodsUI $obj PodsUI object.
|
| 1221 |
-
*/
|
| 1222 |
-
public function admin_setup_edit( $duplicate, $obj ) {
|
| 1223 |
-
|
| 1224 |
-
pods_view( PODS_DIR . 'ui/admin/setup-edit.php', compact( array_keys( get_defined_vars() ) ) );
|
| 1225 |
-
}
|
| 1226 |
-
|
| 1227 |
-
/**
|
| 1228 |
-
* Get list of Pod option tabs
|
| 1229 |
-
*
|
| 1230 |
-
* @param array $pod Pod options.
|
| 1231 |
-
*
|
| 1232 |
-
* @return array
|
| 1233 |
-
*/
|
| 1234 |
-
public function admin_setup_edit_tabs( $pod ) {
|
| 1235 |
-
|
| 1236 |
-
$fields = true;
|
| 1237 |
-
$labels = false;
|
| 1238 |
-
$admin_ui = false;
|
| 1239 |
-
$advanced = false;
|
| 1240 |
-
|
| 1241 |
-
if ( 'post_type' === pods_v( 'type', $pod ) && '' === pods_v( 'object', $pod ) ) {
|
| 1242 |
-
$labels = true;
|
| 1243 |
-
$admin_ui = true;
|
| 1244 |
-
$advanced = true;
|
| 1245 |
-
} elseif ( 'taxonomy' === pods_v( 'type', $pod ) && '' === pods_v( 'object', $pod ) ) {
|
| 1246 |
-
$labels = true;
|
| 1247 |
-
$admin_ui = true;
|
| 1248 |
-
$advanced = true;
|
| 1249 |
-
} elseif ( 'pod' === pods_v( 'type', $pod ) ) {
|
| 1250 |
-
$labels = true;
|
| 1251 |
-
$admin_ui = true;
|
| 1252 |
-
$advanced = true;
|
| 1253 |
-
} elseif ( 'settings' === pods_v( 'type', $pod ) ) {
|
| 1254 |
-
$labels = true;
|
| 1255 |
-
$admin_ui = true;
|
| 1256 |
-
}
|
| 1257 |
-
|
| 1258 |
-
if ( ! function_exists( 'get_term_meta' ) && 'none' === pods_v( 'storage', $pod, 'none', true ) && 'taxonomy' === pods_v( 'type', $pod ) ) {
|
| 1259 |
-
$fields = false;
|
| 1260 |
-
}
|
| 1261 |
-
|
| 1262 |
-
$tabs = array();
|
| 1263 |
-
|
| 1264 |
-
if ( $fields ) {
|
| 1265 |
-
$tabs['manage-fields'] = __( 'Manage Fields', 'pods' );
|
| 1266 |
-
}
|
| 1267 |
-
|
| 1268 |
-
if ( $labels ) {
|
| 1269 |
-
$tabs['labels'] = __( 'Labels', 'pods' );
|
| 1270 |
-
}
|
| 1271 |
-
|
| 1272 |
-
if ( $admin_ui ) {
|
| 1273 |
-
$tabs['admin-ui'] = __( 'Admin UI', 'pods' );
|
| 1274 |
-
}
|
| 1275 |
-
|
| 1276 |
-
if ( $advanced ) {
|
| 1277 |
-
$tabs['advanced'] = __( 'Advanced Options', 'pods' );
|
| 1278 |
-
}
|
| 1279 |
-
|
| 1280 |
-
if ( 'taxonomy' === pods_v( 'type', $pod ) && ! $fields ) {
|
| 1281 |
-
$tabs['extra-fields'] = __( 'Extra Fields', 'pods' );
|
| 1282 |
-
}
|
| 1283 |
-
|
| 1284 |
-
$addtl_args = compact( array( 'fields', 'labels', 'admin_ui', 'advanced' ) );
|
| 1285 |
-
|
| 1286 |
-
$pod_type = $pod['type'];
|
| 1287 |
-
$pod_name = $pod['name'];
|
| 1288 |
-
|
| 1289 |
-
/**
|
| 1290 |
-
* Add or modify tabs in Pods editor for a specific Pod
|
| 1291 |
-
*
|
| 1292 |
-
* @param array $tabs Tabs to set.
|
| 1293 |
-
* @param object $pod Current Pods object.
|
| 1294 |
-
* @param array $addtl_args Additional args.
|
| 1295 |
-
*
|
| 1296 |
-
* @since unknown
|
| 1297 |
-
*/
|
| 1298 |
-
$tabs = apply_filters( "pods_admin_setup_edit_tabs_{$pod_type}_{$pod_name}", $tabs, $pod, $addtl_args );
|
| 1299 |
-
|
| 1300 |
-
/**
|
| 1301 |
-
* Add or modify tabs for any Pod in Pods editor of a specific post type.
|
| 1302 |
-
*/
|
| 1303 |
-
$tabs = apply_filters( "pods_admin_setup_edit_tabs_{$pod_type}", $tabs, $pod, $addtl_args );
|
| 1304 |
-
|
| 1305 |
-
/**
|
| 1306 |
-
* Add or modify tabs in Pods editor for all pods.
|
| 1307 |
-
*/
|
| 1308 |
-
$tabs = apply_filters( 'pods_admin_setup_edit_tabs', $tabs, $pod, $addtl_args );
|
| 1309 |
-
|
| 1310 |
-
return $tabs;
|
| 1311 |
-
}
|
| 1312 |
-
|
| 1313 |
-
/**
|
| 1314 |
-
* Get list of Pod options
|
| 1315 |
-
*
|
| 1316 |
-
* @param array $pod Pod options.
|
| 1317 |
-
*
|
| 1318 |
-
* @return array
|
| 1319 |
-
*/
|
| 1320 |
-
public function admin_setup_edit_options( $pod ) {
|
| 1321 |
-
|
| 1322 |
-
$options = array();
|
| 1323 |
-
|
| 1324 |
-
if ( '' === pods_v( 'object', $pod ) && 'settings' !== pods_v( 'type', $pod ) ) {
|
| 1325 |
-
$labels = array(
|
| 1326 |
-
'label' => array(
|
| 1327 |
-
'label' => __( 'Label', 'pods' ),
|
| 1328 |
-
'help' => __( 'help', 'pods' ),
|
| 1329 |
-
'type' => 'text',
|
| 1330 |
-
'default' => str_replace( '_', ' ', pods_v( 'name', $pod ) ),
|
| 1331 |
-
'text_max_length' => 30,
|
| 1332 |
-
),
|
| 1333 |
-
'label_singular' => array(
|
| 1334 |
-
'label' => __( 'Singular Label', 'pods' ),
|
| 1335 |
-
'help' => __( 'help', 'pods' ),
|
| 1336 |
-
'type' => 'text',
|
| 1337 |
-
'default' => pods_v( 'label', $pod, ucwords( str_replace( '_', ' ', pods_v( 'name', $pod ) ) ) ),
|
| 1338 |
-
'text_max_length' => 30,
|
| 1339 |
-
),
|
| 1340 |
-
'label_add_new' => array(
|
| 1341 |
-
'label' => __( 'Add New', 'pods' ),
|
| 1342 |
-
'help' => __( 'help', 'pods' ),
|
| 1343 |
-
'type' => 'text',
|
| 1344 |
-
'default' => '',
|
| 1345 |
-
'object_type' => array( 'post_type', 'pod' ),
|
| 1346 |
-
),
|
| 1347 |
-
'label_add_new_item' => array(
|
| 1348 |
-
'label' => __( 'Add new <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
|
| 1349 |
-
'help' => __( 'help', 'pods' ),
|
| 1350 |
-
'type' => 'text',
|
| 1351 |
-
'default' => '',
|
| 1352 |
-
),
|
| 1353 |
-
'label_new_item' => array(
|
| 1354 |
-
'label' => __( 'New <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
|
| 1355 |
-
'help' => __( 'help', 'pods' ),
|
| 1356 |
-
'type' => 'text',
|
| 1357 |
-
'default' => '',
|
| 1358 |
-
'object_type' => array( 'post_type', 'pod' ),
|
| 1359 |
-
),
|
| 1360 |
-
'label_new_item_name' => array(
|
| 1361 |
-
'label' => __( 'New <span class="pods-slugged" data-sluggable="label_singular">Item</span> Name', 'pods' ),
|
| 1362 |
-
'help' => __( 'help', 'pods' ),
|
| 1363 |
-
'type' => 'text',
|
| 1364 |
-
'default' => '',
|
| 1365 |
-
'object_type' => array( 'taxonomy' ),
|
| 1366 |
-
),
|
| 1367 |
-
'label_edit' => array(
|
| 1368 |
-
'label' => __( 'Edit', 'pods' ),
|
| 1369 |
-
'help' => __( 'help', 'pods' ),
|
| 1370 |
-
'type' => 'text',
|
| 1371 |
-
'default' => '',
|
| 1372 |
-
'object_type' => array( 'pod' ),
|
| 1373 |
-
),
|
| 1374 |
-
'label_edit_item' => array(
|
| 1375 |
-
'label' => __( 'Edit <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
|
| 1376 |
-
'help' => __( 'help', 'pods' ),
|
| 1377 |
-
'type' => 'text',
|
| 1378 |
-
'default' => '',
|
| 1379 |
-
),
|
| 1380 |
-
'label_update_item' => array(
|
| 1381 |
-
'label' => __( 'Update <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
|
| 1382 |
-
'help' => __( 'help', 'pods' ),
|
| 1383 |
-
'type' => 'text',
|
| 1384 |
-
'default' => '',
|
| 1385 |
-
'object_type' => array( 'taxonomy', 'pod' ),
|
| 1386 |
-
),
|
| 1387 |
-
'label_duplicate' => array(
|
| 1388 |
-
'label' => __( 'Duplicate', 'pods' ),
|
| 1389 |
-
'help' => __( 'help', 'pods' ),
|
| 1390 |
-
'type' => 'text',
|
| 1391 |
-
'default' => '',
|
| 1392 |
-
'object_type' => array( 'pod' ),
|
| 1393 |
-
),
|
| 1394 |
-
'label_duplicate_item' => array(
|
| 1395 |
-
'label' => __( 'Duplicate <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
|
| 1396 |
-
'help' => __( 'help', 'pods' ),
|
| 1397 |
-
'type' => 'text',
|
| 1398 |
-
'default' => '',
|
| 1399 |
-
'object_type' => array( 'pod' ),
|
| 1400 |
-
),
|
| 1401 |
-
'label_delete_item' => array(
|
| 1402 |
-
'label' => __( 'Delete <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
|
| 1403 |
-
'help' => __( 'help', 'pods' ),
|
| 1404 |
-
'type' => 'text',
|
| 1405 |
-
'default' => '',
|
| 1406 |
-
'object_type' => array( 'pod' ),
|
| 1407 |
-
),
|
| 1408 |
-
'label_view' => array(
|
| 1409 |
-
'label' => __( 'View', 'pods' ),
|
| 1410 |
-
'help' => __( 'help', 'pods' ),
|
| 1411 |
-
'type' => 'text',
|
| 1412 |
-
'default' => '',
|
| 1413 |
-
'object_type' => array( 'pod' ),
|
| 1414 |
-
),
|
| 1415 |
-
'label_view_item' => array(
|
| 1416 |
-
'label' => __( 'View <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
|
| 1417 |
-
'help' => __( 'help', 'pods' ),
|
| 1418 |
-
'type' => 'text',
|
| 1419 |
-
'default' => '',
|
| 1420 |
-
),
|
| 1421 |
-
'label_view_items' => array(
|
| 1422 |
-
'label' => __( 'View <span class="pods-slugged" data-sluggable="label">Items</span>', 'pods' ),
|
| 1423 |
-
'help' => __( 'help', 'pods' ),
|
| 1424 |
-
'type' => 'text',
|
| 1425 |
-
'default' => '',
|
| 1426 |
-
'object_type' => array( 'post_type' ),
|
| 1427 |
-
),
|
| 1428 |
-
'label_back_to_manage' => array(
|
| 1429 |
-
'label' => __( 'Back to Manage', 'pods' ),
|
| 1430 |
-
'help' => __( 'help', 'pods' ),
|
| 1431 |
-
'type' => 'text',
|
| 1432 |
-
'default' => '',
|
| 1433 |
-
'object_type' => array( 'pod' ),
|
| 1434 |
-
),
|
| 1435 |
-
'label_manage' => array(
|
| 1436 |
-
'label' => __( 'Manage', 'pods' ),
|
| 1437 |
-
'help' => __( 'help', 'pods' ),
|
| 1438 |
-
'type' => 'text',
|
| 1439 |
-
'default' => '',
|
| 1440 |
-
'object_type' => array( 'pod' ),
|
| 1441 |
-
),
|
| 1442 |
-
'label_manage_items' => array(
|
| 1443 |
-
'label' => __( 'Manage <span class="pods-slugged" data-sluggable="label">Items</span>', 'pods' ),
|
| 1444 |
-
'help' => __( 'help', 'pods' ),
|
| 1445 |
-
'type' => 'text',
|
| 1446 |
-
'default' => '',
|
| 1447 |
-
'object_type' => array( 'pod' ),
|
| 1448 |
-
),
|
| 1449 |
-
'label_reorder' => array(
|
| 1450 |
-
'label' => __( 'Reorder', 'pods' ),
|
| 1451 |
-
'help' => __( 'help', 'pods' ),
|
| 1452 |
-
'type' => 'text',
|
| 1453 |
-
'default' => '',
|
| 1454 |
-
'object_type' => array( 'pod' ),
|
| 1455 |
-
),
|
| 1456 |
-
'label_reorder_items' => array(
|
| 1457 |
-
'label' => __( 'Reorder <span class="pods-slugged" data-sluggable="label">Items</span>', 'pods' ),
|
| 1458 |
-
'help' => __( 'help', 'pods' ),
|
| 1459 |
-
'type' => 'text',
|
| 1460 |
-
'default' => '',
|
| 1461 |
-
'object_type' => array( 'pod' ),
|
| 1462 |
-
),
|
| 1463 |
-
'label_all_items' => array(
|
| 1464 |
-
'label' => __( 'All <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
|
| 1465 |
-
'help' => __( 'help', 'pods' ),
|
| 1466 |
-
'type' => 'text',
|
| 1467 |
-
'default' => '',
|
| 1468 |
-
),
|
| 1469 |
-
'label_search' => array(
|
| 1470 |
-
'label' => __( 'Search', 'pods' ),
|
| 1471 |
-
'help' => __( 'help', 'pods' ),
|
| 1472 |
-
'type' => 'text',
|
| 1473 |
-
'default' => '',
|
| 1474 |
-
'object_type' => array( 'pod' ),
|
| 1475 |
-
),
|
| 1476 |
-
'label_search_items' => array(
|
| 1477 |
-
'label' => __( 'Search <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
|
| 1478 |
-
'help' => __( 'help', 'pods' ),
|
| 1479 |
-
'type' => 'text',
|
| 1480 |
-
'default' => '',
|
| 1481 |
-
),
|
| 1482 |
-
'label_popular_items' => array(
|
| 1483 |
-
'label' => __( 'Popular <span class="pods-slugged" data-sluggable="label">Items</span>', 'pods' ),
|
| 1484 |
-
'help' => __( 'help', 'pods' ),
|
| 1485 |
-
'type' => 'text',
|
| 1486 |
-
'default' => '',
|
| 1487 |
-
'object_type' => array( 'taxonomy' ),
|
| 1488 |
-
),
|
| 1489 |
-
// @todo Why was label_parent added previously? Can't find it in WP
|
| 1490 |
-
'label_parent' => array(
|
| 1491 |
-
'label' => __( 'Parent <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
|
| 1492 |
-
'help' => __( 'help', 'pods' ),
|
| 1493 |
-
'type' => 'text',
|
| 1494 |
-
'default' => '',
|
| 1495 |
-
'object_type' => array( 'post_type', 'pod' ),
|
| 1496 |
-
),
|
| 1497 |
-
'label_parent_item' => array(
|
| 1498 |
-
'label' => __( 'Parent <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
|
| 1499 |
-
'help' => __( 'help', 'pods' ),
|
| 1500 |
-
'type' => 'text',
|
| 1501 |
-
'default' => '',
|
| 1502 |
-
'object_type' => array( 'taxonomy' ),
|
| 1503 |
-
),
|
| 1504 |
-
'label_parent_item_colon' => array(
|
| 1505 |
-
'label' => __( 'Parent <span class="pods-slugged" data-sluggable="label_singular">Item</span>:', 'pods' ),
|
| 1506 |
-
'help' => __( 'help', 'pods' ),
|
| 1507 |
-
'type' => 'text',
|
| 1508 |
-
'default' => '',
|
| 1509 |
-
),
|
| 1510 |
-
'label_not_found' => array(
|
| 1511 |
-
'label' => __( 'Not Found', 'pods' ),
|
| 1512 |
-
'help' => __( 'help', 'pods' ),
|
| 1513 |
-
'type' => 'text',
|
| 1514 |
-
'default' => '',
|
| 1515 |
-
),
|
| 1516 |
-
'label_no_items_found' => array(
|
| 1517 |
-
'label' => __( 'No <span class="pods-slugged" data-sluggable="label_singular">Item</span> Found', 'pods' ),
|
| 1518 |
-
'help' => __( 'help', 'pods' ),
|
| 1519 |
-
'type' => 'text',
|
| 1520 |
-
'default' => '',
|
| 1521 |
-
'object_type' => array( 'pod' ),
|
| 1522 |
-
),
|
| 1523 |
-
'label_not_found_in_trash' => array(
|
| 1524 |
-
'label' => __( 'Not Found in Trash', 'pods' ),
|
| 1525 |
-
'help' => __( 'help', 'pods' ),
|
| 1526 |
-
'type' => 'text',
|
| 1527 |
-
'default' => '',
|
| 1528 |
-
'object_type' => array( 'post_type', 'pod' ),
|
| 1529 |
-
),
|
| 1530 |
-
'label_archives' => array(
|
| 1531 |
-
'label' => __( '<span class="pods-slugged" data-sluggable="label_singular">Item</span> Archives', 'pods' ),
|
| 1532 |
-
'help' => __( 'help', 'pods' ),
|
| 1533 |
-
'type' => 'text',
|
| 1534 |
-
'default' => '',
|
| 1535 |
-
'object_type' => array( 'post_type' ),
|
| 1536 |
-
),
|
| 1537 |
-
'label_attributes' => array(
|
| 1538 |
-
'label' => __( '<span class="pods-slugged" data-sluggable="label_singular">Item</span> Attributes', 'pods' ),
|
| 1539 |
-
'help' => __( 'help', 'pods' ),
|
| 1540 |
-
'type' => 'text',
|
| 1541 |
-
'default' => '',
|
| 1542 |
-
'object_type' => array( 'post_type' ),
|
| 1543 |
-
),
|
| 1544 |
-
'label_insert_into_item' => array(
|
| 1545 |
-
'label' => __( 'Insert into <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
|
| 1546 |
-
'help' => __( 'help', 'pods' ),
|
| 1547 |
-
'type' => 'text',
|
| 1548 |
-
'default' => '',
|
| 1549 |
-
'object_type' => array( 'post_type' ),
|
| 1550 |
-
),
|
| 1551 |
-
'label_uploaded_to_this_item' => array(
|
| 1552 |
-
'label' => __( 'Uploaded to this <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
|
| 1553 |
-
'help' => __( 'help', 'pods' ),
|
| 1554 |
-
'type' => 'text',
|
| 1555 |
-
'default' => '',
|
| 1556 |
-
'object_type' => array( 'post_type' ),
|
| 1557 |
-
),
|
| 1558 |
-
'label_featured_image' => array(
|
| 1559 |
-
'label' => __( 'Featured Image', 'pods' ),
|
| 1560 |
-
'help' => __( 'help', 'pods' ),
|
| 1561 |
-
'type' => 'text',
|
| 1562 |
-
'default' => '',
|
| 1563 |
-
// 'depends-on' => array( 'supports_thumbnail' => true ), // @todo Dependency from other tabs not working
|
| 1564 |
-
'object_type' => array( 'post_type' ),
|
| 1565 |
-
),
|
| 1566 |
-
'label_set_featured_image' => array(
|
| 1567 |
-
'label' => __( 'Set featured Image', 'pods' ),
|
| 1568 |
-
'help' => __( 'help', 'pods' ),
|
| 1569 |
-
'type' => 'text',
|
| 1570 |
-
'default' => '',
|
| 1571 |
-
// 'depends-on' => array( 'supports_thumbnail' => true ), // @todo Dependency from other tabs not working
|
| 1572 |
-
'object_type' => array( 'post_type' ),
|
| 1573 |
-
),
|
| 1574 |
-
'label_remove_featured_image' => array(
|
| 1575 |
-
'label' => __( 'Remove featured Image', 'pods' ),
|
| 1576 |
-
'help' => __( 'help', 'pods' ),
|
| 1577 |
-
'type' => 'text',
|
| 1578 |
-
'default' => '',
|
| 1579 |
-
// 'depends-on' => array( 'supports_thumbnail' => true ), // @todo Dependency from other tabs not working
|
| 1580 |
-
'object_type' => array( 'post_type' ),
|
| 1581 |
-
),
|
| 1582 |
-
'label_use_featured_image' => array(
|
| 1583 |
-
'label' => __( 'Use as featured Image', 'pods' ),
|
| 1584 |
-
'help' => __( 'help', 'pods' ),
|
| 1585 |
-
'type' => 'text',
|
| 1586 |
-
'default' => '',
|
| 1587 |
-
// 'depends-on' => array( 'supports_thumbnail' => true ), // @todo Dependency from other tabs not working
|
| 1588 |
-
'object_type' => array( 'post_type' ),
|
| 1589 |
-
),
|
| 1590 |
-
'label_filter_items_list' => array(
|
| 1591 |
-
'label' => __( 'Filter <span class="pods-slugged" data-sluggable="label">Items</span> lists', 'pods' ),
|
| 1592 |
-
'help' => __( 'help', 'pods' ),
|
| 1593 |
-
'type' => 'text',
|
| 1594 |
-
'default' => '',
|
| 1595 |
-
'object_type' => array( 'post_type' ),
|
| 1596 |
-
),
|
| 1597 |
-
'label_items_list_navigation' => array(
|
| 1598 |
-
'label' => __( '<span class="pods-slugged" data-sluggable="label">Items</span> list navigation', 'pods' ),
|
| 1599 |
-
'help' => __( 'help', 'pods' ),
|
| 1600 |
-
'type' => 'text',
|
| 1601 |
-
'default' => '',
|
| 1602 |
-
'object_type' => array( 'post_type', 'taxonomy' ),
|
| 1603 |
-
),
|
| 1604 |
-
'label_items_list' => array(
|
| 1605 |
-
'label' => __( '<span class="pods-slugged" data-sluggable="label">Items</span> list', 'pods' ),
|
| 1606 |
-
'help' => __( 'help', 'pods' ),
|
| 1607 |
-
'type' => 'text',
|
| 1608 |
-
'default' => '',
|
| 1609 |
-
'object_type' => array( 'post_type', 'taxonomy' ),
|
| 1610 |
-
),
|
| 1611 |
-
'label_separate_items_with_commas' => array(
|
| 1612 |
-
'label' => __( 'Separate <span class="pods-slugged-lower" data-sluggable="label">items</span> with commas', 'pods' ),
|
| 1613 |
-
'help' => __( 'help', 'pods' ),
|
| 1614 |
-
'type' => 'text',
|
| 1615 |
-
'default' => '',
|
| 1616 |
-
'object_type' => array( 'taxonomy' ),
|
| 1617 |
-
),
|
| 1618 |
-
'label_add_or_remove_items' => array(
|
| 1619 |
-
'label' => __( 'Add or remove <span class="pods-slugged-lower" data-sluggable="label">items</span>', 'pods' ),
|
| 1620 |
-
'help' => __( 'help', 'pods' ),
|
| 1621 |
-
'type' => 'text',
|
| 1622 |
-
'default' => '',
|
| 1623 |
-
'object_type' => array( 'taxonomy' ),
|
| 1624 |
-
),
|
| 1625 |
-
'label_choose_from_the_most_used' => array(
|
| 1626 |
-
'label' => __( 'Choose from the most used <span class="pods-slugged-lower" data-sluggable="label">items</span>', 'pods' ),
|
| 1627 |
-
'help' => __( 'help', 'pods' ),
|
| 1628 |
-
'type' => 'text',
|
| 1629 |
-
'default' => '',
|
| 1630 |
-
'object_type' => array( 'taxonomy' ),
|
| 1631 |
-
),
|
| 1632 |
-
'label_no_terms' => array(
|
| 1633 |
-
'label' => __( 'No <span class="pods-slugged-lower" data-sluggable="label">items</span>', 'pods' ),
|
| 1634 |
-
'help' => __( 'help', 'pods' ),
|
| 1635 |
-
'type' => 'text',
|
| 1636 |
-
'default' => '',
|
| 1637 |
-
'object_type' => array( 'taxonomy' ),
|
| 1638 |
-
),
|
| 1639 |
-
'label_item_published' => array(
|
| 1640 |
-
'label' => __( '<span class="pods-slugged" data-sluggable="label_singular">Item</span> Published.', 'pods' ),
|
| 1641 |
-
'help' => __( 'help', 'pods' ),
|
| 1642 |
-
'type' => 'text',
|
| 1643 |
-
'default' => '',
|
| 1644 |
-
'object_type' => array( 'post_type' ),
|
| 1645 |
-
),
|
| 1646 |
-
'label_item_published_privately' => array(
|
| 1647 |
-
'label' => __( '<span class="pods-slugged" data-sluggable="label_singular">Item</span> published privately.', 'pods' ),
|
| 1648 |
-
'help' => __( 'help', 'pods' ),
|
| 1649 |
-
'type' => 'text',
|
| 1650 |
-
'default' => '',
|
| 1651 |
-
'object_type' => array( 'post_type' ),
|
| 1652 |
-
),
|
| 1653 |
-
'label_item_reverted_to_draft' => array(
|
| 1654 |
-
'label' => __( '<span class="pods-slugged" data-sluggable="label_singular">Item</span> reverted to draft.', 'pods' ),
|
| 1655 |
-
'help' => __( 'help', 'pods' ),
|
| 1656 |
-
'type' => 'text',
|
| 1657 |
-
'default' => '',
|
| 1658 |
-
'object_type' => array( 'post_type' ),
|
| 1659 |
-
),
|
| 1660 |
-
'label_item_scheduled' => array(
|
| 1661 |
-
'label' => __( '<span class="pods-slugged" data-sluggable="label_singular">Item</span> scheduled.', 'pods' ),
|
| 1662 |
-
'help' => __( 'help', 'pods' ),
|
| 1663 |
-
'type' => 'text',
|
| 1664 |
-
'default' => '',
|
| 1665 |
-
'object_type' => array( 'post_type' ),
|
| 1666 |
-
),
|
| 1667 |
-
'label_item_updated' => array(
|
| 1668 |
-
'label' => __( '<span class="pods-slugged" data-sluggable="label_singular">Item</span> updated.', 'pods' ),
|
| 1669 |
-
'help' => __( 'help', 'pods' ),
|
| 1670 |
-
'type' => 'text',
|
| 1671 |
-
'default' => '',
|
| 1672 |
-
'object_type' => array( 'post_type' ),
|
| 1673 |
-
),
|
| 1674 |
-
);
|
| 1675 |
-
|
| 1676 |
-
$options['labels'] = array();
|
| 1677 |
-
|
| 1678 |
-
/**
|
| 1679 |
-
* Filter through all labels if they have an object_type set and match it against the current object type
|
| 1680 |
-
*/
|
| 1681 |
-
foreach ( $labels as $label => $labeldata ) {
|
| 1682 |
-
if ( array_key_exists( 'object_type', $labeldata ) ) {
|
| 1683 |
-
if ( in_array( pods_v( 'type', $pod ), $labeldata['object_type'], true ) ) {
|
| 1684 |
-
// Do not add the object_type to the actual label data
|
| 1685 |
-
unset( $labeldata['object_type'] );
|
| 1686 |
-
$options['labels'][ $label ] = $labeldata;
|
| 1687 |
-
}
|
| 1688 |
-
} else {
|
| 1689 |
-
$options['labels'][ $label ] = $labeldata;
|
| 1690 |
-
}
|
| 1691 |
-
}
|
| 1692 |
-
} elseif ( 'settings' === pods_v( 'type', $pod ) ) {
|
| 1693 |
-
|
| 1694 |
-
$options['labels'] = array(
|
| 1695 |
-
'label' => array(
|
| 1696 |
-
'label' => __( 'Page Title', 'pods' ),
|
| 1697 |
-
'help' => __( 'help', 'pods' ),
|
| 1698 |
-
'type' => 'text',
|
| 1699 |
-
'default' => str_replace( '_', ' ', pods_v( 'name', $pod ) ),
|
| 1700 |
-
'text_max_length' => 30,
|
| 1701 |
-
),
|
| 1702 |
-
'menu_name' => array(
|
| 1703 |
-
'label' => __( 'Menu Name', 'pods' ),
|
| 1704 |
-
'help' => __( 'help', 'pods' ),
|
| 1705 |
-
'type' => 'text',
|
| 1706 |
-
'default' => pods_v( 'label', $pod, ucwords( str_replace( '_', ' ', pods_v( 'name', $pod ) ) ) ),
|
| 1707 |
-
'text_max_length' => 30,
|
| 1708 |
-
),
|
| 1709 |
-
);
|
| 1710 |
-
}//end if
|
| 1711 |
-
|
| 1712 |
-
if ( 'post_type' === $pod['type'] ) {
|
| 1713 |
-
$options['admin-ui'] = array(
|
| 1714 |
-
'description' => array(
|
| 1715 |
-
'label' => __( 'Post Type Description', 'pods' ),
|
| 1716 |
-
'help' => __( 'A short descriptive summary of what the post type is.', 'pods' ),
|
| 1717 |
-
'type' => 'text',
|
| 1718 |
-
'default' => '',
|
| 1719 |
-
),
|
| 1720 |
-
'show_ui' => array(
|
| 1721 |
-
'label' => __( 'Show Admin UI', 'pods' ),
|
| 1722 |
-
'help' => __( 'Whether to generate a default UI for managing this post type in the admin.', 'pods' ),
|
| 1723 |
-
'type' => 'boolean',
|
| 1724 |
-
'default' => pods_v( 'public', $pod, true ),
|
| 1725 |
-
'boolean_yes_label' => '',
|
| 1726 |
-
),
|
| 1727 |
-
'show_in_menu' => array(
|
| 1728 |
-
'label' => __( 'Show Admin Menu in Dashboard', 'pods' ),
|
| 1729 |
-
'help' => __( 'Whether to show the post type in the admin menu.', 'pods' ),
|
| 1730 |
-
'type' => 'boolean',
|
| 1731 |
-
'default' => pods_v( 'public', $pod, true ),
|
| 1732 |
-
'dependency' => true,
|
| 1733 |
-
'boolean_yes_label' => '',
|
| 1734 |
-
),
|
| 1735 |
-
'menu_location_custom' => array(
|
| 1736 |
-
'label' => __( 'Parent Menu ID (optional)', 'pods' ),
|
| 1737 |
-
'help' => __( 'help', 'pods' ),
|
| 1738 |
-
'type' => 'text',
|
| 1739 |
-
'depends-on' => array( 'show_in_menu' => true ),
|
| 1740 |
-
),
|
| 1741 |
-
'menu_name' => array(
|
| 1742 |
-
'label' => __( 'Menu Name', 'pods' ),
|
| 1743 |
-
'help' => __( 'help', 'pods' ),
|
| 1744 |
-
'type' => 'text',
|
| 1745 |
-
'default' => '',
|
| 1746 |
-
'depends-on' => array( 'show_in_menu' => true ),
|
| 1747 |
-
),
|
| 1748 |
-
'menu_position' => array(
|
| 1749 |
-
'label' => __( 'Menu Position', 'pods' ),
|
| 1750 |
-
'help' => __( 'help', 'pods' ),
|
| 1751 |
-
'type' => 'number',
|
| 1752 |
-
'number_decimals' => 2,
|
| 1753 |
-
'number_format' => '9999.99',
|
| 1754 |
-
'number_format_soft' => 1,
|
| 1755 |
-
'default' => 0,
|
| 1756 |
-
'depends-on' => array( 'show_in_menu' => true ),
|
| 1757 |
-
),
|
| 1758 |
-
'menu_icon' => array(
|
| 1759 |
-
'label' => __( 'Menu Icon', 'pods' ),
|
| 1760 |
-
'help' => __( 'URL or Dashicon name for the menu icon. You may specify the path to the icon using one of the <a href="https://pods.io/docs/build/special-magic-tags/#site-tags" target="_blank" rel="noopener noreferrer">site tag</a> type <a href="https://pods.io/docs/build/special-magic-tags/" target="_blank" rel="noopener noreferrer">special magic tags</a>. For example, for a file in your theme directory, use "{@template-url}/path/to/image.png". You may also use the name of a <a href="https://developer.wordpress.org/resource/dashicons/" target="_blank" rel="noopener noreferrer">Dashicon</a>. For example, to use the empty star icon, use "dashicons-star-empty".', 'pods' ),
|
| 1761 |
-
'type' => 'text',
|
| 1762 |
-
'default' => '',
|
| 1763 |
-
'depends-on' => array( 'show_in_menu' => true ),
|
| 1764 |
-
),
|
| 1765 |
-
'show_in_nav_menus' => array(
|
| 1766 |
-
'label' => __( 'Show in Navigation Menus', 'pods' ),
|
| 1767 |
-
'help' => __( 'help', 'pods' ),
|
| 1768 |
-
'type' => 'boolean',
|
| 1769 |
-
'default' => true,
|
| 1770 |
-
'boolean_yes_label' => '',
|
| 1771 |
-
),
|
| 1772 |
-
'show_in_admin_bar' => array(
|
| 1773 |
-
'label' => __( 'Show in Admin Bar "New" Menu', 'pods' ),
|
| 1774 |
-
'help' => __( 'help', 'pods' ),
|
| 1775 |
-
'type' => 'boolean',
|
| 1776 |
-
'default' => true,
|
| 1777 |
-
'dependency' => true,
|
| 1778 |
-
'boolean_yes_label' => '',
|
| 1779 |
-
),
|
| 1780 |
-
'name_admin_bar' => array(
|
| 1781 |
-
'label' => __( 'Admin bar name', 'pods' ),
|
| 1782 |
-
'help' => __( 'Defaults to singular name', 'pods' ),
|
| 1783 |
-
'type' => 'text',
|
| 1784 |
-
'default' => '',
|
| 1785 |
-
'depends-on' => array( 'show_in_admin_bar' => true ),
|
| 1786 |
-
),
|
| 1787 |
-
);
|
| 1788 |
-
|
| 1789 |
-
$post_type_name = pods_v( 'name', $pod, 'post_type', true );
|
| 1790 |
-
|
| 1791 |
-
$options['advanced'] = array(
|
| 1792 |
-
'public' => array(
|
| 1793 |
-
'label' => __( 'Public', 'pods' ),
|
| 1794 |
-
'help' => __( 'help', 'pods' ),
|
| 1795 |
-
'type' => 'boolean',
|
| 1796 |
-
'default' => true,
|
| 1797 |
-
'boolean_yes_label' => '',
|
| 1798 |
-
),
|
| 1799 |
-
'publicly_queryable' => array(
|
| 1800 |
-
'label' => __( 'Publicly Queryable', 'pods' ),
|
| 1801 |
-
'help' => __( 'help', 'pods' ),
|
| 1802 |
-
'type' => 'boolean',
|
| 1803 |
-
'default' => pods_v( 'public', $pod, true ),
|
| 1804 |
-
'boolean_yes_label' => '',
|
| 1805 |
-
),
|
| 1806 |
-
'exclude_from_search' => array(
|
| 1807 |
-
'label' => __( 'Exclude from Search', 'pods' ),
|
| 1808 |
-
'help' => __( 'help', 'pods' ),
|
| 1809 |
-
'type' => 'boolean',
|
| 1810 |
-
'default' => ! pods_v( 'public', $pod, true ),
|
| 1811 |
-
'boolean_yes_label' => '',
|
| 1812 |
-
),
|
| 1813 |
-
'capability_type' => array(
|
| 1814 |
-
'label' => __( 'User Capability', 'pods' ),
|
| 1815 |
-
'help' => __( 'Uses these capabilties for access to this post type: edit_{capability}, read_{capability}, and delete_{capability}', 'pods' ),
|
| 1816 |
-
'type' => 'pick',
|
| 1817 |
-
'default' => 'post',
|
| 1818 |
-
'data' => array(
|
| 1819 |
-
'post' => 'post',
|
| 1820 |
-
'page' => 'page',
|
| 1821 |
-
'custom' => __( 'Custom Capability', 'pods' ),
|
| 1822 |
-
),
|
| 1823 |
-
'dependency' => true,
|
| 1824 |
-
),
|
| 1825 |
-
'capability_type_custom' => array(
|
| 1826 |
-
'label' => __( 'Custom User Capability', 'pods' ),
|
| 1827 |
-
'help' => __( 'help', 'pods' ),
|
| 1828 |
-
'type' => 'text',
|
| 1829 |
-
'default' => pods_v( 'name', $pod ),
|
| 1830 |
-
'depends-on' => array( 'capability_type' => 'custom' ),
|
| 1831 |
-
),
|
| 1832 |
-
'capability_type_extra' => array(
|
| 1833 |
-
'label' => __( 'Additional User Capabilities', 'pods' ),
|
| 1834 |
-
'help' => __( 'Enables additional capabilities for this Post Type including: delete_{capability}s, delete_private_{capability}s, delete_published_{capability}s, delete_others_{capability}s, edit_private_{capability}s, and edit_published_{capability}s', 'pods' ),
|
| 1835 |
-
'type' => 'boolean',
|
| 1836 |
-
'default' => true,
|
| 1837 |
-
'boolean_yes_label' => '',
|
| 1838 |
-
),
|
| 1839 |
-
'has_archive' => array(
|
| 1840 |
-
'label' => __( 'Enable Archive Page', 'pods' ),
|
| 1841 |
-
'help' => __( 'If enabled, creates an archive page with list of of items in this custom post type. Functions like a category page for posts. Can be controlled with a template in your theme called "archive-{$post-type}.php".', 'pods' ),
|
| 1842 |
-
'type' => 'boolean',
|
| 1843 |
-
'default' => false,
|
| 1844 |
-
'dependency' => true,
|
| 1845 |
-
'boolean_yes_label' => '',
|
| 1846 |
-
),
|
| 1847 |
-
'has_archive_slug' => array(
|
| 1848 |
-
'label' => __( 'Archive Page Slug Override', 'pods' ),
|
| 1849 |
-
'help' => __( 'If archive page is enabled, you can override the slug used by WordPress, which defaults to the name of the post type.', 'pods' ),
|
| 1850 |
-
'type' => 'text',
|
| 1851 |
-
'default' => '',
|
| 1852 |
-
'depends-on' => array( 'has_archive' => true ),
|
| 1853 |
-
),
|
| 1854 |
-
'hierarchical' => array(
|
| 1855 |
-
'label' => __( 'Hierarchical', 'pods' ),
|
| 1856 |
-
'help' => __( 'Allows for parent/ child relationships between items, just like with Pages. Note: To edit relationships in the post editor, you must enable "Page Attributes" in the "Supports" section below.', 'pods' ),
|
| 1857 |
-
'type' => 'boolean',
|
| 1858 |
-
'default' => false,
|
| 1859 |
-
'dependency' => true,
|
| 1860 |
-
'boolean_yes_label' => '',
|
| 1861 |
-
),
|
| 1862 |
-
'label_parent_item_colon' => array(
|
| 1863 |
-
'label' => __( '<strong>Label: </strong> Parent <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
|
| 1864 |
-
'help' => __( 'help', 'pods' ),
|
| 1865 |
-
'type' => 'text',
|
| 1866 |
-
'default' => '',
|
| 1867 |
-
'depends-on' => array( 'hierarchical' => true ),
|
| 1868 |
-
),
|
| 1869 |
-
'label_parent' => array(
|
| 1870 |
-
'label' => __( '<strong>Label: </strong> Parent', 'pods' ),
|
| 1871 |
-
'help' => __( 'help', 'pods' ),
|
| 1872 |
-
'type' => 'text',
|
| 1873 |
-
'default' => '',
|
| 1874 |
-
'depends-on' => array( 'hierarchical' => true ),
|
| 1875 |
-
),
|
| 1876 |
-
'rewrite' => array(
|
| 1877 |
-
'label' => __( 'Rewrite', 'pods' ),
|
| 1878 |
-
'help' => __( 'Allows you to use pretty permalinks, if set in WordPress Settings->Permalinks. If not enabled, your links will be in the form of "example.com/?pod_name=post_slug" regardless of your permalink settings.', 'pods' ),
|
| 1879 |
-
'type' => 'boolean',
|
| 1880 |
-
'default' => true,
|
| 1881 |
-
'dependency' => true,
|
| 1882 |
-
'boolean_yes_label' => '',
|
| 1883 |
-
),
|
| 1884 |
-
'rewrite_custom_slug' => array(
|
| 1885 |
-
'label' => __( 'Custom Rewrite Slug', 'pods' ),
|
| 1886 |
-
'help' => __( 'Changes the first segment of the URL, which by default is the name of the Pod. For example, if your Pod is called "foo", if this field is left blank, your link will be "example.com/foo/post_slug", but if you were to enter "bar" your link will be "example.com/bar/post_slug".', 'pods' ),
|
| 1887 |
-
'type' => 'text',
|
| 1888 |
-
'default' => '',
|
| 1889 |
-
'depends-on' => array( 'rewrite' => true ),
|
| 1890 |
-
),
|
| 1891 |
-
'rewrite_with_front' => array(
|
| 1892 |
-
'label' => __( 'Rewrite with Front', 'pods' ),
|
| 1893 |
-
'help' => __( 'Allows permalinks to be prepended with your front base (example: if your permalink structure is /blog/, then your links will be: Unchecked->/news/, Checked->/blog/news/)', 'pods' ),
|
| 1894 |
-
'type' => 'boolean',
|
| 1895 |
-
'default' => true,
|
| 1896 |
-
'depends-on' => array( 'rewrite' => true ),
|
| 1897 |
-
'boolean_yes_label' => '',
|
| 1898 |
-
),
|
| 1899 |
-
'rewrite_feeds' => array(
|
| 1900 |
-
'label' => __( 'Rewrite Feeds', 'pods' ),
|
| 1901 |
-
'help' => __( 'help', 'pods' ),
|
| 1902 |
-
'type' => 'boolean',
|
| 1903 |
-
'default' => false,
|
| 1904 |
-
'depends-on' => array( 'rewrite' => true ),
|
| 1905 |
-
'boolean_yes_label' => '',
|
| 1906 |
-
),
|
| 1907 |
-
'rewrite_pages' => array(
|
| 1908 |
-
'label' => __( 'Rewrite Pages', 'pods' ),
|
| 1909 |
-
'help' => __( 'help', 'pods' ),
|
| 1910 |
-
'type' => 'boolean',
|
| 1911 |
-
'default' => true,
|
| 1912 |
-
'depends-on' => array( 'rewrite' => true ),
|
| 1913 |
-
'boolean_yes_label' => '',
|
| 1914 |
-
),
|
| 1915 |
-
'query_var' => array(
|
| 1916 |
-
'label' => __( 'Query Var', 'pods' ),
|
| 1917 |
-
'help' => __( 'The Query Var is used in the URL and underneath the WordPress Rewrite API to tell WordPress what page or post type you are on. For a list of reserved Query Vars, read <a href="http://codex.wordpress.org/WordPress_Query_Vars">WordPress Query Vars</a> from the WordPress Codex.', 'pods' ),
|
| 1918 |
-
'type' => 'boolean',
|
| 1919 |
-
'default' => true,
|
| 1920 |
-
'boolean_yes_label' => '',
|
| 1921 |
-
),
|
| 1922 |
-
'can_export' => array(
|
| 1923 |
-
'label' => __( 'Exportable', 'pods' ),
|
| 1924 |
-
'help' => __( 'help', 'pods' ),
|
| 1925 |
-
'type' => 'boolean',
|
| 1926 |
-
'default' => true,
|
| 1927 |
-
'boolean_yes_label' => '',
|
| 1928 |
-
),
|
| 1929 |
-
'default_status' => array(
|
| 1930 |
-
'label' => __( 'Default Status', 'pods' ),
|
| 1931 |
-
'help' => __( 'help', 'pods' ),
|
| 1932 |
-
'type' => 'pick',
|
| 1933 |
-
'pick_object' => 'post-status',
|
| 1934 |
-
'default' => apply_filters( "pods_api_default_status_{$post_type_name}", 'draft', $pod ),
|
| 1935 |
-
),
|
| 1936 |
-
);
|
| 1937 |
-
} elseif ( 'taxonomy' === $pod['type'] ) {
|
| 1938 |
-
$options['admin-ui'] = array(
|
| 1939 |
-
'description' => array(
|
| 1940 |
-
'label' => __( 'Taxonomy Description', 'pods' ),
|
| 1941 |
-
'help' => __( 'A short descriptive summary of what the taxonomy is.', 'pods' ),
|
| 1942 |
-
'type' => 'text',
|
| 1943 |
-
'default' => '',
|
| 1944 |
-
),
|
| 1945 |
-
'show_ui' => array(
|
| 1946 |
-
'label' => __( 'Show Admin UI', 'pods' ),
|
| 1947 |
-
'help' => __( 'Whether to generate a default UI for managing this taxonomy.', 'pods' ),
|
| 1948 |
-
'type' => 'boolean',
|
| 1949 |
-
'default' => pods_v( 'public', $pod, true ),
|
| 1950 |
-
'dependency' => true,
|
| 1951 |
-
'boolean_yes_label' => '',
|
| 1952 |
-
),
|
| 1953 |
-
'show_in_menu' => array(
|
| 1954 |
-
'label' => __( 'Show Admin Menu in Dashboard', 'pods' ),
|
| 1955 |
-
'help' => __( 'Whether to show the taxonomy in the admin menu.', 'pods' ),
|
| 1956 |
-
'type' => 'boolean',
|
| 1957 |
-
'default' => pods_v( 'public', $pod, true ),
|
| 1958 |
-
'dependency' => true,
|
| 1959 |
-
'depends-on' => array( 'show_ui' => true ),
|
| 1960 |
-
'boolean_yes_label' => '',
|
| 1961 |
-
),
|
| 1962 |
-
'menu_name' => array(
|
| 1963 |
-
'label' => __( 'Menu Name', 'pods' ),
|
| 1964 |
-
'help' => __( 'help', 'pods' ),
|
| 1965 |
-
'type' => 'text',
|
| 1966 |
-
'default' => '',
|
| 1967 |
-
'depends-on' => array( 'show_ui' => true ),
|
| 1968 |
-
),
|
| 1969 |
-
'menu_location' => array(
|
| 1970 |
-
'label' => __( 'Menu Location', 'pods' ),
|
| 1971 |
-
'help' => __( 'help', 'pods' ),
|
| 1972 |
-
'type' => 'pick',
|
| 1973 |
-
'default' => 'default',
|
| 1974 |
-
'depends-on' => array( 'show_ui' => true ),
|
| 1975 |
-
'data' => array(
|
| 1976 |
-
'default' => __( 'Default - Add to associated Post Type(s) menus', 'pods' ),
|
| 1977 |
-
'settings' => __( 'Add a submenu item to Settings menu', 'pods' ),
|
| 1978 |
-
'appearances' => __( 'Add a submenu item to Appearances menu', 'pods' ),
|
| 1979 |
-
'submenu' => __( 'Add a submenu item to another menu', 'pods' ),
|
| 1980 |
-
'objects' => __( 'Make a new menu item', 'pods' ),
|
| 1981 |
-
'top' => __( 'Make a new menu item below Settings', 'pods' ),
|
| 1982 |
-
),
|
| 1983 |
-
'dependency' => true,
|
| 1984 |
-
),
|
| 1985 |
-
'menu_location_custom' => array(
|
| 1986 |
-
'label' => __( 'Custom Menu Location', 'pods' ),
|
| 1987 |
-
'help' => __( 'help', 'pods' ),
|
| 1988 |
-
'type' => 'text',
|
| 1989 |
-
'depends-on' => array( 'menu_location' => 'submenu' ),
|
| 1990 |
-
),
|
| 1991 |
-
'menu_position' => array(
|
| 1992 |
-
'label' => __( 'Menu Position', 'pods' ),
|
| 1993 |
-
'help' => __( 'help', 'pods' ),
|
| 1994 |
-
'type' => 'number',
|
| 1995 |
-
'number_decimals' => 2,
|
| 1996 |
-
'number_format' => '9999.99',
|
| 1997 |
-
'number_format_soft' => 1,
|
| 1998 |
-
'default' => 0,
|
| 1999 |
-
'depends-on' => array( 'menu_location' => array( 'objects', 'top' ) ),
|
| 2000 |
-
),
|
| 2001 |
-
'menu_icon' => array(
|
| 2002 |
-
'label' => __( 'Menu Icon URL', 'pods' ),
|
| 2003 |
-
'help' => __( 'help', 'pods' ),
|
| 2004 |
-
'type' => 'text',
|
| 2005 |
-
'default' => '',
|
| 2006 |
-
'depends-on' => array( 'menu_location' => array( 'objects', 'top' ) ),
|
| 2007 |
-
),
|
| 2008 |
-
'show_in_nav_menus' => array(
|
| 2009 |
-
'label' => __( 'Show in Navigation Menus', 'pods' ),
|
| 2010 |
-
'help' => __( 'help', 'pods' ),
|
| 2011 |
-
'type' => 'boolean',
|
| 2012 |
-
'default' => pods_v( 'public', $pod, true ),
|
| 2013 |
-
'boolean_yes_label' => '',
|
| 2014 |
-
),
|
| 2015 |
-
'show_tagcloud' => array(
|
| 2016 |
-
'label' => __( 'Allow in Tagcloud Widget', 'pods' ),
|
| 2017 |
-
'help' => __( 'help', 'pods' ),
|
| 2018 |
-
'type' => 'boolean',
|
| 2019 |
-
'default' => pods_v( 'show_ui', $pod, pods_v( 'public', $pod, true ) ),
|
| 2020 |
-
'boolean_yes_label' => '',
|
| 2021 |
-
),
|
| 2022 |
-
// @todo check https://core.trac.wordpress.org/ticket/36964
|
| 2023 |
-
'show_tagcloud_in_edit' => array(
|
| 2024 |
-
'label' => __( 'Allow Tagcloud on term edit pages', 'pods' ),
|
| 2025 |
-
'help' => __( 'help', 'pods' ),
|
| 2026 |
-
'type' => 'boolean',
|
| 2027 |
-
'default' => pods_v( 'show_ui', $pod, pods_v( 'show_tagcloud', $pod, true ) ),
|
| 2028 |
-
'boolean_yes_label' => '',
|
| 2029 |
-
),
|
| 2030 |
-
'show_in_quick_edit' => array(
|
| 2031 |
-
'label' => __( 'Allow in quick/bulk edit panel', 'pods' ),
|
| 2032 |
-
'help' => __( 'help', 'pods' ),
|
| 2033 |
-
'type' => 'boolean',
|
| 2034 |
-
'default' => pods_v( 'show_ui', $pod, pods_v( 'public', $pod, true ) ),
|
| 2035 |
-
'boolean_yes_label' => '',
|
| 2036 |
-
),
|
| 2037 |
-
);
|
| 2038 |
-
|
| 2039 |
-
$options['admin-ui']['show_admin_column'] = array(
|
| 2040 |
-
'label' => __( 'Show Taxonomy column on Post Types', 'pods' ),
|
| 2041 |
-
'help' => __( 'Whether to add a column for this taxonomy on the associated post types manage screens', 'pods' ),
|
| 2042 |
-
'type' => 'boolean',
|
| 2043 |
-
'default' => false,
|
| 2044 |
-
'boolean_yes_label' => '',
|
| 2045 |
-
);
|
| 2046 |
-
|
| 2047 |
-
// Integration for Single Value Taxonomy UI
|
| 2048 |
-
if ( function_exists( 'tax_single_value_meta_box' ) ) {
|
| 2049 |
-
$options['admin-ui']['single_value'] = array(
|
| 2050 |
-
'label' => __( 'Single Value Taxonomy', 'pods' ),
|
| 2051 |
-
'help' => __( 'Use a drop-down for the input instead of the WordPress default', 'pods' ),
|
| 2052 |
-
'type' => 'boolean',
|
| 2053 |
-
'default' => false,
|
| 2054 |
-
'boolean_yes_label' => '',
|
| 2055 |
-
);
|
| 2056 |
-
|
| 2057 |
-
$options['admin-ui']['single_value_required'] = array(
|
| 2058 |
-
'label' => __( 'Single Value Taxonomy - Required', 'pods' ),
|
| 2059 |
-
'help' => __( 'A term will be selected by default in the Post Editor, not optional', 'pods' ),
|
| 2060 |
-
'type' => 'boolean',
|
| 2061 |
-
'default' => false,
|
| 2062 |
-
'boolean_yes_label' => '',
|
| 2063 |
-
);
|
| 2064 |
-
}
|
| 2065 |
-
|
| 2066 |
-
$options['advanced'] = array(
|
| 2067 |
-
'public' => array(
|
| 2068 |
-
'label' => __( 'Public', 'pods' ),
|
| 2069 |
-
'help' => __( 'help', 'pods' ),
|
| 2070 |
-
'type' => 'boolean',
|
| 2071 |
-
'default' => true,
|
| 2072 |
-
'boolean_yes_label' => '',
|
| 2073 |
-
),
|
| 2074 |
-
'hierarchical' => array(
|
| 2075 |
-
'label' => __( 'Hierarchical', 'pods' ),
|
| 2076 |
-
'help' => __( 'Hierarchical taxonomies will have a list with checkboxes to select an existing category in the taxonomy admin box on the post edit page (like default post categories). Non-hierarchical taxonomies will just have an empty text field to type-in taxonomy terms to associate with the post (like default post tags).', 'pods' ),
|
| 2077 |
-
'type' => 'boolean',
|
| 2078 |
-
'default' => true,
|
| 2079 |
-
'dependency' => true,
|
| 2080 |
-
'boolean_yes_label' => '',
|
| 2081 |
-
),
|
| 2082 |
-
'label_parent_item_colon' => array(
|
| 2083 |
-
'label' => __( '<strong>Label: </strong> Parent <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
|
| 2084 |
-
'help' => __( 'help', 'pods' ),
|
| 2085 |
-
'type' => 'text',
|
| 2086 |
-
'default' => '',
|
| 2087 |
-
'depends-on' => array( 'hierarchical' => true ),
|
| 2088 |
-
),
|
| 2089 |
-
'label_parent' => array(
|
| 2090 |
-
'label' => __( '<strong>Label: </strong> Parent', 'pods' ),
|
| 2091 |
-
'help' => __( 'help', 'pods' ),
|
| 2092 |
-
'type' => 'text',
|
| 2093 |
-
'default' => '',
|
| 2094 |
-
'depends-on' => array( 'hierarchical' => true ),
|
| 2095 |
-
),
|
| 2096 |
-
'label_no_terms' => array(
|
| 2097 |
-
'label' => __( '<strong>Label: </strong> No <span class="pods-slugged" data-sluggable="label">Items</span>', 'pods' ),
|
| 2098 |
-
'help' => __( 'help', 'pods' ),
|
| 2099 |
-
'type' => 'text',
|
| 2100 |
-
'default' => '',
|
| 2101 |
-
'depends-on' => array( 'hierarchical' => true ),
|
| 2102 |
-
),
|
| 2103 |
-
'rewrite' => array(
|
| 2104 |
-
'label' => __( 'Rewrite', 'pods' ),
|
| 2105 |
-
'help' => __( 'help', 'pods' ),
|
| 2106 |
-
'type' => 'boolean',
|
| 2107 |
-
'default' => true,
|
| 2108 |
-
'dependency' => true,
|
| 2109 |
-
'boolean_yes_label' => '',
|
| 2110 |
-
),
|
| 2111 |
-
'rewrite_custom_slug' => array(
|
| 2112 |
-
'label' => __( 'Custom Rewrite Slug', 'pods' ),
|
| 2113 |
-
'help' => __( 'help', 'pods' ),
|
| 2114 |
-
'type' => 'text',
|
| 2115 |
-
'default' => '',
|
| 2116 |
-
'depends-on' => array( 'rewrite' => true ),
|
| 2117 |
-
),
|
| 2118 |
-
'rewrite_with_front' => array(
|
| 2119 |
-
'label' => __( 'Rewrite with Front', 'pods' ),
|
| 2120 |
-
'help' => __( 'Allows permalinks to be prepended with your front base (example: if your permalink structure is /blog/, then your links will be: Unchecked->/news/, Checked->/blog/news/)', 'pods' ),
|
| 2121 |
-
'type' => 'boolean',
|
| 2122 |
-
'default' => true,
|
| 2123 |
-
'boolean_yes_label' => '',
|
| 2124 |
-
'depends-on' => array( 'rewrite' => true ),
|
| 2125 |
-
),
|
| 2126 |
-
'rewrite_hierarchical' => array(
|
| 2127 |
-
'label' => __( 'Hierarchical Permalinks', 'pods' ),
|
| 2128 |
-
'help' => __( 'help', 'pods' ),
|
| 2129 |
-
'type' => 'boolean',
|
| 2130 |
-
'default' => true,
|
| 2131 |
-
'boolean_yes_label' => '',
|
| 2132 |
-
'depends-on' => array( 'rewrite' => true ),
|
| 2133 |
-
),
|
| 2134 |
-
'capability_type' => array(
|
| 2135 |
-
'label' => __( 'User Capability', 'pods' ),
|
| 2136 |
-
'help' => __( 'Uses WordPress term capabilities by default', 'pods' ),
|
| 2137 |
-
'type' => 'pick',
|
| 2138 |
-
'default' => 'default',
|
| 2139 |
-
'data' => array(
|
| 2140 |
-
'default' => 'Default',
|
| 2141 |
-
'custom' => __( 'Custom Capability', 'pods' ),
|
| 2142 |
-
),
|
| 2143 |
-
'dependency' => true,
|
| 2144 |
-
),
|
| 2145 |
-
'capability_type_custom' => array(
|
| 2146 |
-
'label' => __( 'Custom User Capability', 'pods' ),
|
| 2147 |
-
'help' => __( 'Enables additional capabilities for this Taxonomy including: manage_{capability}_terms, edit_{capability}_terms, assign_{capability}_terms, and delete_{capability}_terms', 'pods' ),
|
| 2148 |
-
'type' => 'text',
|
| 2149 |
-
'default' => pods_v( 'name', $pod ),
|
| 2150 |
-
'depends-on' => array( 'capability_type' => 'custom' ),
|
| 2151 |
-
),
|
| 2152 |
-
'query_var' => array(
|
| 2153 |
-
'label' => __( 'Query Var', 'pods' ),
|
| 2154 |
-
'help' => __( 'help', 'pods' ),
|
| 2155 |
-
'type' => 'boolean',
|
| 2156 |
-
'default' => false,
|
| 2157 |
-
'boolean_yes_label' => '',
|
| 2158 |
-
),
|
| 2159 |
-
'query_var' => array(
|
| 2160 |
-
'label' => __( 'Query Var', 'pods' ),
|
| 2161 |
-
'help' => __( 'help', 'pods' ),
|
| 2162 |
-
'type' => 'boolean',
|
| 2163 |
-
'default' => false,
|
| 2164 |
-
'dependency' => true,
|
| 2165 |
-
'boolean_yes_label' => '',
|
| 2166 |
-
),
|
| 2167 |
-
'query_var_string' => array(
|
| 2168 |
-
'label' => __( 'Custom Query Var Name', 'pods' ),
|
| 2169 |
-
'help' => __( 'help', 'pods' ),
|
| 2170 |
-
'type' => 'text',
|
| 2171 |
-
'default' => '',
|
| 2172 |
-
'depends-on' => array( 'query_var' => true ),
|
| 2173 |
-
),
|
| 2174 |
-
'sort' => array(
|
| 2175 |
-
'label' => __( 'Remember order saved on Post Types', 'pods' ),
|
| 2176 |
-
'help' => __( 'help', 'pods' ),
|
| 2177 |
-
'type' => 'boolean',
|
| 2178 |
-
'default' => false,
|
| 2179 |
-
'boolean_yes_label' => '',
|
| 2180 |
-
),
|
| 2181 |
-
'update_count_callback' => array(
|
| 2182 |
-
'label' => __( 'Function to call when updating counts', 'pods' ),
|
| 2183 |
-
'help' => __( 'help', 'pods' ),
|
| 2184 |
-
'type' => 'text',
|
| 2185 |
-
'default' => '',
|
| 2186 |
-
),
|
| 2187 |
-
);
|
| 2188 |
-
} elseif ( 'settings' === $pod['type'] ) {
|
| 2189 |
-
$options['admin-ui'] = array(
|
| 2190 |
-
'ui_style' => array(
|
| 2191 |
-
'label' => __( 'Admin UI Style', 'pods' ),
|
| 2192 |
-
'help' => __( 'help', 'pods' ),
|
| 2193 |
-
'type' => 'pick',
|
| 2194 |
-
'default' => 'settings',
|
| 2195 |
-
'data' => array(
|
| 2196 |
-
'settings' => __( 'Normal Settings Form', 'pods' ),
|
| 2197 |
-
'post_type' => __( 'Post Type UI', 'pods' ),
|
| 2198 |
-
'custom' => __( 'Custom (hook into pods_admin_ui_custom or pods_admin_ui_custom_{podname} action)', 'pods' ),
|
| 2199 |
-
),
|
| 2200 |
-
'dependency' => true,
|
| 2201 |
-
),
|
| 2202 |
-
'menu_location' => array(
|
| 2203 |
-
'label' => __( 'Menu Location', 'pods' ),
|
| 2204 |
-
'help' => __( 'help', 'pods' ),
|
| 2205 |
-
'type' => 'pick',
|
| 2206 |
-
'default' => 'settings',
|
| 2207 |
-
'data' => array(
|
| 2208 |
-
'settings' => __( 'Add a submenu item to Settings menu', 'pods' ),
|
| 2209 |
-
'appearances' => __( 'Add a submenu item to Appearances menu', 'pods' ),
|
| 2210 |
-
'submenu' => __( 'Add a submenu item to another menu', 'pods' ),
|
| 2211 |
-
'top' => __( 'Make a new menu item below Settings', 'pods' ),
|
| 2212 |
-
),
|
| 2213 |
-
'dependency' => true,
|
| 2214 |
-
),
|
| 2215 |
-
'menu_location_custom' => array(
|
| 2216 |
-
'label' => __( 'Custom Menu Location', 'pods' ),
|
| 2217 |
-
'help' => __( 'help', 'pods' ),
|
| 2218 |
-
'type' => 'text',
|
| 2219 |
-
'depends-on' => array( 'menu_location' => 'submenu' ),
|
| 2220 |
-
),
|
| 2221 |
-
'menu_position' => array(
|
| 2222 |
-
'label' => __( 'Menu Position', 'pods' ),
|
| 2223 |
-
'help' => __( 'help', 'pods' ),
|
| 2224 |
-
'type' => 'number',
|
| 2225 |
-
'number_decimals' => 2,
|
| 2226 |
-
'number_format' => '9999.99',
|
| 2227 |
-
'number_format_soft' => 1,
|
| 2228 |
-
'default' => 0,
|
| 2229 |
-
'depends-on' => array( 'menu_location' => 'top' ),
|
| 2230 |
-
),
|
| 2231 |
-
'menu_icon' => array(
|
| 2232 |
-
'label' => __( 'Menu Icon URL', 'pods' ),
|
| 2233 |
-
'help' => __( 'help', 'pods' ),
|
| 2234 |
-
'type' => 'text',
|
| 2235 |
-
'default' => '',
|
| 2236 |
-
'depends-on' => array( 'menu_location' => 'top' ),
|
| 2237 |
-
),
|
| 2238 |
-
);
|
| 2239 |
-
|
| 2240 |
-
// @todo fill this in
|
| 2241 |
-
$options['advanced'] = array(
|
| 2242 |
-
'temporary' => 'This type has the fields hardcoded',
|
| 2243 |
-
// :(
|
| 2244 |
-
);
|
| 2245 |
-
} elseif ( 'pod' === $pod['type'] ) {
|
| 2246 |
-
$actions_enabled = array(
|
| 2247 |
-
'add',
|
| 2248 |
-
'edit',
|
| 2249 |
-
'duplicate',
|
| 2250 |
-
'delete',
|
| 2251 |
-
);
|
| 2252 |
-
|
| 2253 |
-
if ( 1 === (int) pods_v( 'ui_export', $pod ) ) {
|
| 2254 |
-
$actions_enabled = array(
|
| 2255 |
-
'add',
|
| 2256 |
-
'edit',
|
| 2257 |
-
'duplicate',
|
| 2258 |
-
'delete',
|
| 2259 |
-
'export',
|
| 2260 |
-
);
|
| 2261 |
-
}
|
| 2262 |
-
|
| 2263 |
-
$options['admin-ui'] = array(
|
| 2264 |
-
'ui_style' => array(
|
| 2265 |
-
'label' => __( 'Admin UI Style', 'pods' ),
|
| 2266 |
-
'help' => __( 'help', 'pods' ),
|
| 2267 |
-
'type' => 'pick',
|
| 2268 |
-
'default' => 'settings',
|
| 2269 |
-
'data' => array(
|
| 2270 |
-
'post_type' => __( 'Normal (Looks like the Post Type UI)', 'pods' ),
|
| 2271 |
-
'custom' => __( 'Custom (hook into pods_admin_ui_custom or pods_admin_ui_custom_{podname} action)', 'pods' ),
|
| 2272 |
-
),
|
| 2273 |
-
'dependency' => true,
|
| 2274 |
-
),
|
| 2275 |
-
'show_in_menu' => array(
|
| 2276 |
-
'label' => __( 'Show Admin Menu in Dashboard', 'pods' ),
|
| 2277 |
-
'help' => __( 'help', 'pods' ),
|
| 2278 |
-
'type' => 'boolean',
|
| 2279 |
-
'default' => false,
|
| 2280 |
-
'boolean_yes_label' => '',
|
| 2281 |
-
'dependency' => true,
|
| 2282 |
-
),
|
| 2283 |
-
'menu_location_custom' => array(
|
| 2284 |
-
'label' => __( 'Parent Menu ID (optional)', 'pods' ),
|
| 2285 |
-
'help' => __( 'help', 'pods' ),
|
| 2286 |
-
'type' => 'text',
|
| 2287 |
-
'depends-on' => array( 'show_in_menu' => true ),
|
| 2288 |
-
),
|
| 2289 |
-
'menu_position' => array(
|
| 2290 |
-
'label' => __( 'Menu Position', 'pods' ),
|
| 2291 |
-
'help' => __( 'help', 'pods' ),
|
| 2292 |
-
'type' => 'number',
|
| 2293 |
-
'number_decimals' => 2,
|
| 2294 |
-
'number_format' => '9999.99',
|
| 2295 |
-
'number_format_soft' => 1,
|
| 2296 |
-
'default' => 0,
|
| 2297 |
-
'depends-on' => array( 'show_in_menu' => true ),
|
| 2298 |
-
),
|
| 2299 |
-
'menu_icon' => array(
|
| 2300 |
-
'label' => __( 'Menu Icon URL', 'pods' ),
|
| 2301 |
-
'help' => __( 'This is the icon shown to the left of the menu text for this content type.', 'pods' ),
|
| 2302 |
-
'type' => 'text',
|
| 2303 |
-
'default' => '',
|
| 2304 |
-
'depends-on' => array( 'show_in_menu' => true ),
|
| 2305 |
-
),
|
| 2306 |
-
'ui_icon' => array(
|
| 2307 |
-
'label' => __( 'Header Icon', 'pods' ),
|
| 2308 |
-
'help' => __( 'This is the icon shown to the left of the heading text at the top of the manage pages for this content type.', 'pods' ),
|
| 2309 |
-
'type' => 'file',
|
| 2310 |
-
'default' => '',
|
| 2311 |
-
'file_edit_title' => 0,
|
| 2312 |
-
'depends-on' => array( 'show_in_menu' => true ),
|
| 2313 |
-
),
|
| 2314 |
-
'ui_actions_enabled' => array(
|
| 2315 |
-
'label' => __( 'Actions Available', 'pods' ),
|
| 2316 |
-
'help' => __( 'help', 'pods' ),
|
| 2317 |
-
'type' => 'pick',
|
| 2318 |
-
'default' => $actions_enabled,
|
| 2319 |
-
'data' => array(
|
| 2320 |
-
'add' => __( 'Add New', 'pods' ),
|
| 2321 |
-
'edit' => __( 'Edit', 'pods' ),
|
| 2322 |
-
'duplicate' => __( 'Duplicate', 'pods' ),
|
| 2323 |
-
'delete' => __( 'Delete', 'pods' ),
|
| 2324 |
-
'reorder' => __( 'Reorder', 'pods' ),
|
| 2325 |
-
'export' => __( 'Export', 'pods' ),
|
| 2326 |
-
),
|
| 2327 |
-
'pick_format_type' => 'multi',
|
| 2328 |
-
'dependency' => true,
|
| 2329 |
-
),
|
| 2330 |
-
'ui_reorder_field' => array(
|
| 2331 |
-
'label' => __( 'Reorder Field', 'pods' ),
|
| 2332 |
-
'help' => __( 'This is the field that will be reordered on, it should be numeric.', 'pods' ),
|
| 2333 |
-
'type' => 'text',
|
| 2334 |
-
'default' => 'menu_order',
|
| 2335 |
-
'depends-on' => array( 'ui_actions_enabled' => 'reorder' ),
|
| 2336 |
-
),
|
| 2337 |
-
'ui_fields_manage' => array(
|
| 2338 |
-
'label' => __( 'Admin Table Columns', 'pods' ),
|
| 2339 |
-
'help' => __( 'help', 'pods' ),
|
| 2340 |
-
'type' => 'pick',
|
| 2341 |
-
'default' => array(),
|
| 2342 |
-
'data' => array(),
|
| 2343 |
-
'pick_format_type' => 'multi',
|
| 2344 |
-
),
|
| 2345 |
-
'ui_filters' => array(
|
| 2346 |
-
'label' => __( 'Search Filters', 'pods' ),
|
| 2347 |
-
'help' => __( 'help', 'pods' ),
|
| 2348 |
-
'type' => 'pick',
|
| 2349 |
-
'default' => array(),
|
| 2350 |
-
'data' => array(),
|
| 2351 |
-
'pick_format_type' => 'multi',
|
| 2352 |
-
),
|
| 2353 |
-
);
|
| 2354 |
-
|
| 2355 |
-
if ( ! empty( $pod['fields'] ) ) {
|
| 2356 |
-
if ( isset( $pod['fields'][ pods_v( 'pod_index', $pod, 'name' ) ] ) ) {
|
| 2357 |
-
$options['admin-ui']['ui_fields_manage']['default'][] = pods_v( 'pod_index', $pod, 'name' );
|
| 2358 |
-
}
|
| 2359 |
-
|
| 2360 |
-
if ( isset( $pod['fields']['modified'] ) ) {
|
| 2361 |
-
$options['admin-ui']['ui_fields_manage']['default'][] = 'modified';
|
| 2362 |
-
}
|
| 2363 |
-
|
| 2364 |
-
foreach ( $pod['fields'] as $field ) {
|
| 2365 |
-
$type = '';
|
| 2366 |
-
|
| 2367 |
-
if ( isset( $field_types[ $field['type'] ] ) ) {
|
| 2368 |
-
$type = ' <small>(' . $field_types[ $field['type'] ]['label'] . ')</small>';
|
| 2369 |
-
}
|
| 2370 |
-
|
| 2371 |
-
$options['admin-ui']['ui_fields_manage']['data'][ $field['name'] ] = $field['label'] . $type;
|
| 2372 |
-
$options['admin-ui']['ui_filters']['data'][ $field['name'] ] = $field['label'] . $type;
|
| 2373 |
-
}
|
| 2374 |
-
|
| 2375 |
-
$options['admin-ui']['ui_fields_manage']['data']['id'] = 'ID';
|
| 2376 |
-
} else {
|
| 2377 |
-
unset( $options['admin-ui']['ui_fields_manage'] );
|
| 2378 |
-
unset( $options['admin-ui']['ui_filters'] );
|
| 2379 |
-
}//end if
|
| 2380 |
-
|
| 2381 |
-
// @todo fill this in
|
| 2382 |
-
$options['advanced'] = array(
|
| 2383 |
-
'temporary' => 'This type has the fields hardcoded',
|
| 2384 |
-
// :(
|
| 2385 |
-
);
|
| 2386 |
-
}//end if
|
| 2387 |
-
|
| 2388 |
-
$pod_type = $pod['type'];
|
| 2389 |
-
$pod_name = $pod['name'];
|
| 2390 |
-
|
| 2391 |
-
/**
|
| 2392 |
-
* Add admin fields to the Pods editor for a specific Pod
|
| 2393 |
-
*
|
| 2394 |
-
* @param array $options The Options fields.
|
| 2395 |
-
* @param object $pod Current Pods object.
|
| 2396 |
-
*
|
| 2397 |
-
* @since unkown
|
| 2398 |
-
*/
|
| 2399 |
-
$options = apply_filters( "pods_admin_setup_edit_options_{$pod_type}_{$pod_name}", $options, $pod );
|
| 2400 |
-
|
| 2401 |
-
/**
|
| 2402 |
-
* Add admin fields to the Pods editor for any Pod of a specific content type.
|
| 2403 |
-
*
|
| 2404 |
-
* @param array $options The Options fields.
|
| 2405 |
-
* @param object $pod Current Pods object.
|
| 2406 |
-
*/
|
| 2407 |
-
$options = apply_filters( "pods_admin_setup_edit_options_{$pod_type}", $options, $pod );
|
| 2408 |
-
|
| 2409 |
-
/**
|
| 2410 |
-
* Add admin fields to the Pods editor for all Pods
|
| 2411 |
-
*
|
| 2412 |
-
* @param array $options The Options fields.
|
| 2413 |
-
* @param object $pod Current Pods object.
|
| 2414 |
-
*/
|
| 2415 |
-
$options = apply_filters( 'pods_admin_setup_edit_options', $options, $pod );
|
| 2416 |
-
|
| 2417 |
-
return $options;
|
| 2418 |
-
}
|
| 2419 |
-
|
| 2420 |
-
/**
|
| 2421 |
-
* Get list of Pod field option tabs
|
| 2422 |
-
*
|
| 2423 |
-
* @param array $pod Pod options.
|
| 2424 |
-
*
|
| 2425 |
-
* @return array
|
| 2426 |
-
*/
|
| 2427 |
-
public function admin_setup_edit_field_tabs( $pod ) {
|
| 2428 |
-
|
| 2429 |
-
$core_tabs = array(
|
| 2430 |
-
'basic' => __( 'Basic', 'pods' ),
|
| 2431 |
-
'additional-field' => __( 'Additional Field Options', 'pods' ),
|
| 2432 |
-
'advanced' => __( 'Advanced', 'pods' ),
|
| 2433 |
-
);
|
| 2434 |
-
|
| 2435 |
-
/**
|
| 2436 |
-
* Field option tabs
|
| 2437 |
-
*
|
| 2438 |
-
* Use to add new tabs, default tabs are added after this filter (IE you can't remove/modify them with this, kthanksbye).
|
| 2439 |
-
*
|
| 2440 |
-
* @since unknown
|
| 2441 |
-
*
|
| 2442 |
-
* @param array $tabs Tabs to add, starts empty.
|
| 2443 |
-
* @param object|Pod $pod Current Pods object.
|
| 2444 |
-
*/
|
| 2445 |
-
$tabs = apply_filters( 'pods_admin_setup_edit_field_tabs', array(), $pod );
|
| 2446 |
-
|
| 2447 |
-
$tabs = array_merge( $core_tabs, $tabs );
|
| 2448 |
-
|
| 2449 |
-
return $tabs;
|
| 2450 |
-
}
|
| 2451 |
-
|
| 2452 |
-
/**
|
| 2453 |
-
* Get list of Pod field options
|
| 2454 |
-
*
|
| 2455 |
-
* @param array $pod Pod options.
|
| 2456 |
-
*
|
| 2457 |
-
* @return array
|
| 2458 |
-
*/
|
| 2459 |
-
public function admin_setup_edit_field_options( $pod ) {
|
| 2460 |
-
|
| 2461 |
-
$options = array();
|
| 2462 |
-
|
| 2463 |
-
$options['additional-field'] = array();
|
| 2464 |
-
|
| 2465 |
-
$field_types = PodsForm::field_types();
|
| 2466 |
-
|
| 2467 |
-
foreach ( $field_types as $type => $field_type_data ) {
|
| 2468 |
-
/**
|
| 2469 |
-
* @var $field_type PodsField
|
| 2470 |
-
*/
|
| 2471 |
-
$field_type = PodsForm::field_loader( $type, $field_type_data['file'] );
|
| 2472 |
-
|
| 2473 |
-
$field_type_vars = get_class_vars( get_class( $field_type ) );
|
| 2474 |
-
|
| 2475 |
-
if ( ! isset( $field_type_vars['pod_types'] ) ) {
|
| 2476 |
-
$field_type_vars['pod_types'] = true;
|
| 2477 |
-
}
|
| 2478 |
-
|
| 2479 |
-
$options['additional-field'][ $type ] = array();
|
| 2480 |
-
|
| 2481 |
-
// Only show supported field types
|
| 2482 |
-
if ( true !== $field_type_vars['pod_types'] ) {
|
| 2483 |
-
if ( empty( $field_type_vars['pod_types'] ) ) {
|
| 2484 |
-
continue;
|
| 2485 |
-
} elseif ( is_array( $field_type_vars['pod_types'] ) && ! in_array( pods_v( 'type', $pod ), $field_type_vars['pod_types'], true ) ) {
|
| 2486 |
-
continue;
|
| 2487 |
-
} elseif ( ! is_array( $field_type_vars['pod_types'] ) && pods_v( 'type', $pod ) !== $field_type_vars['pod_types'] ) {
|
| 2488 |
-
continue;
|
| 2489 |
-
}
|
| 2490 |
-
}
|
| 2491 |
-
|
| 2492 |
-
$options['additional-field'][ $type ] = PodsForm::ui_options( $type );
|
| 2493 |
-
|
| 2494 |
-
/**
|
| 2495 |
-
* Modify Additional Field Options tab
|
| 2496 |
-
*
|
| 2497 |
-
* @since 2.7.0
|
| 2498 |
-
*
|
| 2499 |
-
* @param array $options Additional field type options,
|
| 2500 |
-
* @param string $type Field type,
|
| 2501 |
-
* @param array $options Tabs, indexed by label,
|
| 2502 |
-
* @param object|Pods $pod Pods object for the Pod this UI is for.
|
| 2503 |
-
*/
|
| 2504 |
-
$options['additional-field'][ $type ] = apply_filters( "pods_admin_setup_edit_{$type}_additional_field_options", $options['additional-field'][ $type ], $type, $options, $pod );
|
| 2505 |
-
$options['additional-field'][ $type ] = apply_filters( 'pods_admin_setup_edit_additional_field_options', $options['additional-field'][ $type ], $type, $options, $pod );
|
| 2506 |
-
}//end foreach
|
| 2507 |
-
|
| 2508 |
-
$input_helpers = array(
|
| 2509 |
-
'' => '-- Select --',
|
| 2510 |
-
);
|
| 2511 |
-
|
| 2512 |
-
if ( class_exists( 'Pods_Helpers' ) ) {
|
| 2513 |
-
$helpers = pods_api()->load_helpers( array( 'options' => array( 'helper_type' => 'input' ) ) );
|
| 2514 |
-
|
| 2515 |
-
foreach ( $helpers as $helper ) {
|
| 2516 |
-
$input_helpers[ $helper['name'] ] = $helper['name'];
|
| 2517 |
-
}
|
| 2518 |
-
}
|
| 2519 |
-
|
| 2520 |
-
$options['advanced'] = array(
|
| 2521 |
-
__( 'Visual', 'pods' ) => array(
|
| 2522 |
-
'class' => array(
|
| 2523 |
-
'name' => 'class',
|
| 2524 |
-
'label' => __( 'Additional CSS Classes', 'pods' ),
|
| 2525 |
-
'help' => __( 'help', 'pods' ),
|
| 2526 |
-
'type' => 'text',
|
| 2527 |
-
'default' => '',
|
| 2528 |
-
),
|
| 2529 |
-
'input_helper' => array(
|
| 2530 |
-
'name' => 'input_helper',
|
| 2531 |
-
'label' => __( 'Input Helper', 'pods' ),
|
| 2532 |
-
'help' => __( 'help', 'pods' ),
|
| 2533 |
-
'type' => 'pick',
|
| 2534 |
-
'default' => '',
|
| 2535 |
-
'data' => $input_helpers,
|
| 2536 |
-
),
|
| 2537 |
-
),
|
| 2538 |
-
__( 'Values', 'pods' ) => array(
|
| 2539 |
-
'default_value' => array(
|
| 2540 |
-
'name' => 'default_value',
|
| 2541 |
-
'label' => __( 'Default Value', 'pods' ),
|
| 2542 |
-
'help' => __( 'help', 'pods' ),
|
| 2543 |
-
'type' => 'text',
|
| 2544 |
-
'default' => '',
|
| 2545 |
-
'options' => array(
|
| 2546 |
-
'text_max_length' => - 1,
|
| 2547 |
-
),
|
| 2548 |
-
),
|
| 2549 |
-
'default_value_parameter' => array(
|
| 2550 |
-
'name' => 'default_value_parameter',
|
| 2551 |
-
'label' => __( 'Set Default Value via Parameter', 'pods' ),
|
| 2552 |
-
'help' => __( 'help', 'pods' ),
|
| 2553 |
-
'type' => 'text',
|
| 2554 |
-
'default' => '',
|
| 2555 |
-
),
|
| 2556 |
-
),
|
| 2557 |
-
__( 'Visibility', 'pods' ) => array(
|
| 2558 |
-
'restrict_access' => array(
|
| 2559 |
-
'name' => 'restrict_access',
|
| 2560 |
-
'label' => __( 'Restrict Access', 'pods' ),
|
| 2561 |
-
'group' => array(
|
| 2562 |
-
'admin_only' => array(
|
| 2563 |
-
'name' => 'admin_only',
|
| 2564 |
-
'label' => __( 'Restrict access to Admins?', 'pods' ),
|
| 2565 |
-
'default' => 0,
|
| 2566 |
-
'type' => 'boolean',
|
| 2567 |
-
'dependency' => true,
|
| 2568 |
-
'help' => __( 'This field will only be able to be edited by users with the ability to manage_options or delete_users, or super admins of a WordPress Multisite network', 'pods' ),
|
| 2569 |
-
),
|
| 2570 |
-
'restrict_role' => array(
|
| 2571 |
-
'name' => 'restrict_role',
|
| 2572 |
-
'label' => __( 'Restrict access by Role?', 'pods' ),
|
| 2573 |
-
'default' => 0,
|
| 2574 |
-
'type' => 'boolean',
|
| 2575 |
-
'dependency' => true,
|
| 2576 |
-
),
|
| 2577 |
-
'restrict_capability' => array(
|
| 2578 |
-
'name' => 'restrict_capability',
|
| 2579 |
-
'label' => __( 'Restrict access by Capability?', 'pods' ),
|
| 2580 |
-
'default' => 0,
|
| 2581 |
-
'type' => 'boolean',
|
| 2582 |
-
'dependency' => true,
|
| 2583 |
-
),
|
| 2584 |
-
'hidden' => array(
|
| 2585 |
-
'name' => 'hidden',
|
| 2586 |
-
'label' => __( 'Hide field from UI', 'pods' ),
|
| 2587 |
-
'default' => 0,
|
| 2588 |
-
'type' => 'boolean',
|
| 2589 |
-
'help' => __( 'This option is overriden by access restrictions. If the user does not have access to edit this field, it will be hidden. If no access restrictions are set, this field will always be hidden.', 'pods' ),
|
| 2590 |
-
),
|
| 2591 |
-
'read_only' => array(
|
| 2592 |
-
'name' => 'read_only',
|
| 2593 |
-
'label' => __( 'Make field "Read Only" in UI', 'pods' ),
|
| 2594 |
-
'default' => 0,
|
| 2595 |
-
'type' => 'boolean',
|
| 2596 |
-
'help' => __( 'This option is overriden by access restrictions. If the user does not have access to edit this field, it will be read only. If no access restrictions are set, this field will always be read only.', 'pods' ),
|
| 2597 |
-
'depends-on' => array(
|
| 2598 |
-
'type' => array(
|
| 2599 |
-
'boolean',
|
| 2600 |
-
'color',
|
| 2601 |
-
'currency',
|
| 2602 |
-
'date',
|
| 2603 |
-
'datetime',
|
| 2604 |
-
'email',
|
| 2605 |
-
'number',
|
| 2606 |
-
'paragraph',
|
| 2607 |
-
'password',
|
| 2608 |
-
'phone',
|
| 2609 |
-
'slug',
|
| 2610 |
-
'text',
|
| 2611 |
-
'time',
|
| 2612 |
-
'website',
|
| 2613 |
-
),
|
| 2614 |
-
),
|
| 2615 |
-
),
|
| 2616 |
-
),
|
| 2617 |
-
),
|
| 2618 |
-
'roles_allowed' => array(
|
| 2619 |
-
'name' => 'roles_allowed',
|
| 2620 |
-
'label' => __( 'Role(s) Allowed', 'pods' ),
|
| 2621 |
-
'help' => __( 'help', 'pods' ),
|
| 2622 |
-
'type' => 'pick',
|
| 2623 |
-
'pick_object' => 'role',
|
| 2624 |
-
'pick_format_type' => 'multi',
|
| 2625 |
-
'default' => 'administrator',
|
| 2626 |
-
'depends-on' => array(
|
| 2627 |
-
'restrict_role' => true,
|
| 2628 |
-
),
|
| 2629 |
-
),
|
| 2630 |
-
'capability_allowed' => array(
|
| 2631 |
-
'name' => 'capability_allowed',
|
| 2632 |
-
'label' => __( 'Capability Allowed', 'pods' ),
|
| 2633 |
-
'help' => __( 'Comma-separated list of cababilities, for example add_podname_item, please see the Roles and Capabilities component for the complete list and a way to add your own.', 'pods' ),
|
| 2634 |
-
'type' => 'text',
|
| 2635 |
-
'default' => '',
|
| 2636 |
-
'depends-on' => array(
|
| 2637 |
-
'restrict_capability' => true,
|
| 2638 |
-
),
|
| 2639 |
-
),
|
| 2640 |
-
),
|
| 2641 |
-
);
|
| 2642 |
-
|
| 2643 |
-
/*
|
| 2644 |
-
$options['advanced'][ __( 'Visibility', 'pods' ) ]['search'] = array(
|
| 2645 |
-
'label' => __( 'Include in searches', 'pods' ),
|
| 2646 |
-
'help' => __( 'help', 'pods' ),
|
| 2647 |
-
'default' => 1,
|
| 2648 |
-
'type' => 'boolean',
|
| 2649 |
-
);
|
| 2650 |
-
*/
|
| 2651 |
-
|
| 2652 |
-
/*
|
| 2653 |
-
$options['advanced'][ __( 'Validation', 'pods' ) ] = array(
|
| 2654 |
-
'regex_validation' => array(
|
| 2655 |
-
'label' => __( 'RegEx Validation', 'pods' ),
|
| 2656 |
-
'help' => __( 'help', 'pods' ),
|
| 2657 |
-
'type' => 'text',
|
| 2658 |
-
'default' => '',
|
| 2659 |
-
),
|
| 2660 |
-
'message_regex' => array(
|
| 2661 |
-
'label' => __( 'Message if field does not pass RegEx', 'pods' ),
|
| 2662 |
-
'help' => __( 'help', 'pods' ),
|
| 2663 |
-
'type' => 'text',
|
| 2664 |
-
'default' => '',
|
| 2665 |
-
),
|
| 2666 |
-
'message_required' => array(
|
| 2667 |
-
'label' => __( 'Message if field is blank', 'pods' ),
|
| 2668 |
-
'help' => __( 'help', 'pods' ),
|
| 2669 |
-
'type' => 'text',
|
| 2670 |
-
'default' => '',
|
| 2671 |
-
'depends-on' => array( 'required' => true ),
|
| 2672 |
-
),
|
| 2673 |
-
'message_unique' => array(
|
| 2674 |
-
'label' => __( 'Message if field is not unique', 'pods' ),
|
| 2675 |
-
'help' => __( 'help', 'pods' ),
|
| 2676 |
-
'type' => 'text',
|
| 2677 |
-
'default' => '',
|
| 2678 |
-
'depends-on' => array( 'unique' => true ),
|
| 2679 |
-
),
|
| 2680 |
-
);
|
| 2681 |
-
*/
|
| 2682 |
-
|
| 2683 |
-
if ( ! class_exists( 'Pods_Helpers' ) ) {
|
| 2684 |
-
unset( $options['advanced']['input_helper'] );
|
| 2685 |
-
}
|
| 2686 |
-
|
| 2687 |
-
/**
|
| 2688 |
-
* Modify tabs and their contents for field options
|
| 2689 |
-
*
|
| 2690 |
-
* @since unknown
|
| 2691 |
-
*
|
| 2692 |
-
* @param array $options Tabs, indexed by label.
|
| 2693 |
-
* @param object|Pods $pod Pods object for the Pod this UI is for.
|
| 2694 |
-
*/
|
| 2695 |
-
$options = apply_filters( 'pods_admin_setup_edit_field_options', $options, $pod );
|
| 2696 |
-
|
| 2697 |
-
return $options;
|
| 2698 |
-
}
|
| 2699 |
-
|
| 2700 |
-
/**
|
| 2701 |
-
* Duplicate a pod
|
| 2702 |
-
*
|
| 2703 |
-
* @param PodsUI $obj PodsUI object.
|
| 2704 |
-
*/
|
| 2705 |
-
public function admin_setup_duplicate( $obj ) {
|
| 2706 |
-
|
| 2707 |
-
$new_id = pods_api()->duplicate_pod( array( 'id' => $obj->id ) );
|
| 2708 |
-
|
| 2709 |
-
if ( 0 < $new_id ) {
|
| 2710 |
-
pods_redirect(
|
| 2711 |
-
pods_query_arg(
|
| 2712 |
-
array(
|
| 2713 |
-
'action' => 'edit',
|
| 2714 |
-
'id' => $new_id,
|
| 2715 |
-
'do' => 'duplicate',
|
| 2716 |
-
)
|
| 2717 |
-
)
|
| 2718 |
-
);
|
| 2719 |
-
}
|
| 2720 |
-
}
|
| 2721 |
-
|
| 2722 |
-
/**
|
| 2723 |
-
* Restrict Duplicate action to custom types, not extended
|
| 2724 |
-
*
|
| 2725 |
-
* @param bool $restricted Whether action is restricted.
|
| 2726 |
-
* @param array $restrict Restriction array.
|
| 2727 |
-
* @param string $action Current action.
|
| 2728 |
-
* @param array $row Item data row.
|
| 2729 |
-
* @param PodsUI $obj PodsUI object.
|
| 2730 |
-
*
|
| 2731 |
-
* @since 2.3.10
|
| 2732 |
-
*
|
| 2733 |
-
* @return bool
|
| 2734 |
-
*/
|
| 2735 |
-
public function admin_setup_duplicate_restrict( $restricted, $restrict, $action, $row, $obj ) {
|
| 2736 |
-
|
| 2737 |
-
if ( in_array(
|
| 2738 |
-
$row['real_type'], array(
|
| 2739 |
-
'user',
|
| 2740 |
-
'media',
|
| 2741 |
-
'comment',
|
| 2742 |
-
), true
|
| 2743 |
-
) ) {
|
| 2744 |
-
$restricted = true;
|
| 2745 |
-
}
|
| 2746 |
-
|
| 2747 |
-
return $restricted;
|
| 2748 |
-
|
| 2749 |
-
}
|
| 2750 |
-
|
| 2751 |
-
/**
|
| 2752 |
-
* Reset a pod
|
| 2753 |
-
*
|
| 2754 |
-
* @param PodsUI $obj PodsUI object.
|
| 2755 |
-
* @param int|string $id Item ID.
|
| 2756 |
-
*
|
| 2757 |
-
* @return mixed
|
| 2758 |
-
*/
|
| 2759 |
-
public function admin_setup_reset( $obj, $id ) {
|
| 2760 |
-
|
| 2761 |
-
$pod = pods_api()->load_pod( array( 'id' => $id ), false );
|
| 2762 |
-
|
| 2763 |
-
if ( empty( $pod ) ) {
|
| 2764 |
-
return $obj->error( __( 'Pod not found.', 'pods' ) );
|
| 2765 |
-
}
|
| 2766 |
-
|
| 2767 |
-
pods_api()->reset_pod( array( 'id' => $id ) );
|
| 2768 |
-
|
| 2769 |
-
$obj->message( __( 'Pod reset successfully.', 'pods' ) );
|
| 2770 |
-
|
| 2771 |
-
$obj->manage();
|
| 2772 |
-
}
|
| 2773 |
-
|
| 2774 |
-
/**
|
| 2775 |
-
* Restrict Reset action from users and media
|
| 2776 |
-
*
|
| 2777 |
-
* @param bool $restricted Whether action is restricted.
|
| 2778 |
-
* @param array $restrict Restriction array.
|
| 2779 |
-
* @param string $action Current action.
|
| 2780 |
-
* @param array $row Item data row.
|
| 2781 |
-
* @param PodsUI $obj PodsUI object.
|
| 2782 |
-
*
|
| 2783 |
-
* @since 2.3.10
|
| 2784 |
-
*/
|
| 2785 |
-
public function admin_setup_reset_restrict( $restricted, $restrict, $action, $row, $obj ) {
|
| 2786 |
-
|
| 2787 |
-
if ( in_array(
|
| 2788 |
-
$row['real_type'], array(
|
| 2789 |
-
'user',
|
| 2790 |
-
'media',
|
| 2791 |
-
), true
|
| 2792 |
-
) ) {
|
| 2793 |
-
$restricted = true;
|
| 2794 |
-
}
|
| 2795 |
-
|
| 2796 |
-
return $restricted;
|
| 2797 |
-
|
| 2798 |
-
}
|
| 2799 |
-
|
| 2800 |
-
/**
|
| 2801 |
-
* Delete a pod
|
| 2802 |
-
*
|
| 2803 |
-
* @param int|string $id Item ID.
|
| 2804 |
-
* @param PodsUI $obj PodsUI object.
|
| 2805 |
-
*
|
| 2806 |
-
* @return mixed
|
| 2807 |
-
*/
|
| 2808 |
-
public function admin_setup_delete( $id, $obj ) {
|
| 2809 |
-
|
| 2810 |
-
$pod = pods_api()->load_pod( array( 'id' => $id ), false );
|
| 2811 |
-
|
| 2812 |
-
if ( empty( $pod ) ) {
|
| 2813 |
-
return $obj->error( __( 'Pod not found.', 'pods' ) );
|
| 2814 |
-
}
|
| 2815 |
-
|
| 2816 |
-
pods_api()->delete_pod( array( 'id' => $id ) );
|
| 2817 |
-
|
| 2818 |
-
unset( $obj->data[ $pod['id'] ] );
|
| 2819 |
-
|
| 2820 |
-
$obj->total = count( $obj->data );
|
| 2821 |
-
$obj->total_found = count( $obj->data );
|
| 2822 |
-
|
| 2823 |
-
$obj->message( __( 'Pod deleted successfully.', 'pods' ) );
|
| 2824 |
-
}
|
| 2825 |
-
|
| 2826 |
-
/**
|
| 2827 |
-
* Get advanced administration view.
|
| 2828 |
-
*/
|
| 2829 |
-
public function admin_advanced() {
|
| 2830 |
-
|
| 2831 |
-
pods_view( PODS_DIR . 'ui/admin/advanced.php', compact( array_keys( get_defined_vars() ) ) );
|
| 2832 |
-
}
|
| 2833 |
-
|
| 2834 |
-
/**
|
| 2835 |
-
* Get settings administration view
|
| 2836 |
-
*/
|
| 2837 |
-
public function admin_settings() {
|
| 2838 |
-
|
| 2839 |
-
// Add our custom callouts.
|
| 2840 |
-
add_action( 'pods_admin_after_settings', array( $this, 'admin_manage_callouts' ) );
|
| 2841 |
-
|
| 2842 |
-
pods_view( PODS_DIR . 'ui/admin/settings.php', compact( array_keys( get_defined_vars() ) ) );
|
| 2843 |
-
}
|
| 2844 |
-
|
| 2845 |
-
/**
|
| 2846 |
-
* Get components administration UI
|
| 2847 |
-
*/
|
| 2848 |
-
public function admin_components() {
|
| 2849 |
-
|
| 2850 |
-
if ( ! is_object( PodsInit::$components ) ) {
|
| 2851 |
-
return;
|
| 2852 |
-
}
|
| 2853 |
-
|
| 2854 |
-
$components = PodsInit::$components->components;
|
| 2855 |
-
|
| 2856 |
-
$view = pods_v( 'view', 'get', 'all', true );
|
| 2857 |
-
|
| 2858 |
-
$recommended = array(
|
| 2859 |
-
'advanced-relationships',
|
| 2860 |
-
'advanced-content-types',
|
| 2861 |
-
'migrate-packages',
|
| 2862 |
-
'roles-and-capabilities',
|
| 2863 |
-
'pages',
|
| 2864 |
-
'table-storage',
|
| 2865 |
-
'templates',
|
| 2866 |
-
);
|
| 2867 |
-
|
| 2868 |
-
foreach ( $components as $component => &$component_data ) {
|
| 2869 |
-
if ( ! in_array(
|
| 2870 |
-
$view, array(
|
| 2871 |
-
'all',
|
| 2872 |
-
'recommended',
|
| 2873 |
-
'dev',
|
| 2874 |
-
), true
|
| 2875 |
-
) && ( ! isset( $component_data['Category'] ) || sanitize_title( $component_data['Category'] ) !== $view ) ) {
|
| 2876 |
-
unset( $components[ $component ] );
|
| 2877 |
-
|
| 2878 |
-
continue;
|
| 2879 |
-
} elseif ( 'recommended' === $view && ! in_array( $component_data['ID'], $recommended, true ) ) {
|
| 2880 |
-
unset( $components[ $component ] );
|
| 2881 |
-
|
| 2882 |
-
continue;
|
| 2883 |
-
} elseif ( 'dev' === $view && pods_developer() && ! pods_v( 'DeveloperMode', $component_data, false ) ) {
|
| 2884 |
-
unset( $components[ $component ] );
|
| 2885 |
-
|
| 2886 |
-
continue;
|
| 2887 |
-
} elseif ( pods_v( 'DeveloperMode', $component_data, false ) && ! pods_developer() ) {
|
| 2888 |
-
unset( $components[ $component ] );
|
| 2889 |
-
|
| 2890 |
-
continue;
|
| 2891 |
-
} elseif ( ! pods_v( 'TablelessMode', $component_data, false ) && pods_tableless() ) {
|
| 2892 |
-
unset( $components[ $component ] );
|
| 2893 |
-
|
| 2894 |
-
continue;
|
| 2895 |
-
}//end if
|
| 2896 |
-
|
| 2897 |
-
$component_data['Name'] = strip_tags( $component_data['Name'] );
|
| 2898 |
-
|
| 2899 |
-
if ( pods_v( 'DeveloperMode', $component_data, false ) ) {
|
| 2900 |
-
$component_data['Name'] .= ' <em style="font-weight: normal; color:#333;">(Developer Preview)</em>';
|
| 2901 |
-
}
|
| 2902 |
-
|
| 2903 |
-
$meta = array();
|
| 2904 |
-
|
| 2905 |
-
if ( ! empty( $component_data['Version'] ) ) {
|
| 2906 |
-
$meta[] = sprintf( __( 'Version %s', 'pods' ), $component_data['Version'] );
|
| 2907 |
-
}
|
| 2908 |
-
|
| 2909 |
-
if ( empty( $component_data['Author'] ) ) {
|
| 2910 |
-
$component_data['Author'] = 'Pods Framework Team';
|
| 2911 |
-
$component_data['AuthorURI'] = 'https://pods.io/';
|
| 2912 |
-
}
|
| 2913 |
-
|
| 2914 |
-
if ( ! empty( $component_data['AuthorURI'] ) ) {
|
| 2915 |
-
$component_data['Author'] = '<a href="' . $component_data['AuthorURI'] . '">' . $component_data['Author'] . '</a>';
|
| 2916 |
-
}
|
| 2917 |
-
|
| 2918 |
-
$meta[] = sprintf( __( 'by %s', 'pods' ), $component_data['Author'] );
|
| 2919 |
-
|
| 2920 |
-
if ( ! empty( $component_data['URI'] ) ) {
|
| 2921 |
-
$meta[] = '<a href="' . $component_data['URI'] . '">' . __( 'Visit component site', 'pods' ) . '</a>';
|
| 2922 |
-
}
|
| 2923 |
-
|
| 2924 |
-
$component_data['Description'] = wpautop( trim( make_clickable( strip_tags( $component_data['Description'], 'em,strong' ) ) ) );
|
| 2925 |
-
|
| 2926 |
-
if ( ! empty( $meta ) ) {
|
| 2927 |
-
$description_style = '';
|
| 2928 |
-
|
| 2929 |
-
if ( ! empty( $component_data['Description'] ) ) {
|
| 2930 |
-
$description_style = ' style="padding:8px 0 4px;"';
|
| 2931 |
-
}
|
| 2932 |
-
|
| 2933 |
-
$component_data['Description'] .= '<div class="pods-component-meta" ' . $description_style . '>' . implode( ' | ', $meta ) . '</div>';
|
| 2934 |
-
}
|
| 2935 |
-
|
| 2936 |
-
$component_data = array(
|
| 2937 |
-
'id' => $component_data['ID'],
|
| 2938 |
-
'name' => $component_data['Name'],
|
| 2939 |
-
'category' => $component_data['Category'],
|
| 2940 |
-
'version' => '',
|
| 2941 |
-
'description' => $component_data['Description'],
|
| 2942 |
-
'mustuse' => pods_v( 'MustUse', $component_data, false ),
|
| 2943 |
-
'toggle' => 0,
|
| 2944 |
-
);
|
| 2945 |
-
|
| 2946 |
-
if ( ! empty( $component_data['category'] ) ) {
|
| 2947 |
-
$category_url = pods_query_arg(
|
| 2948 |
-
array(
|
| 2949 |
-
'view' => sanitize_title( $component_data['category'] ),
|
| 2950 |
-
'pg' => '',
|
| 2951 |
-
// @codingStandardsIgnoreLine
|
| 2952 |
-
'page' => $_GET['page'],
|
| 2953 |
-
)
|
| 2954 |
-
);
|
| 2955 |
-
|
| 2956 |
-
$component_data['category'] = '<a href="' . esc_url( $category_url ) . '">' . $component_data['category'] . '</a>';
|
| 2957 |
-
}
|
| 2958 |
|
| 2959 |
-
|
| 2960 |
-
|
| 2961 |
-
|
| 2962 |
-
|
| 2963 |
-
|
| 2964 |
-
}//end foreach
|
| 2965 |
-
|
| 2966 |
-
$ui = array(
|
| 2967 |
-
'data' => $components,
|
| 2968 |
-
'total' => count( $components ),
|
| 2969 |
-
'total_found' => count( $components ),
|
| 2970 |
-
'items' => __( 'Components', 'pods' ),
|
| 2971 |
-
'item' => __( 'Component', 'pods' ),
|
| 2972 |
-
'fields' => array(
|
| 2973 |
-
'manage' => array(
|
| 2974 |
-
'name' => array(
|
| 2975 |
-
'label' => __( 'Name', 'pods' ),
|
| 2976 |
-
'width' => '30%',
|
| 2977 |
-
'type' => 'text',
|
| 2978 |
-
'options' => array(
|
| 2979 |
-
'text_allow_html' => true,
|
| 2980 |
-
),
|
| 2981 |
-
),
|
| 2982 |
-
'category' => array(
|
| 2983 |
-
'label' => __( 'Category', 'pods' ),
|
| 2984 |
-
'width' => '10%',
|
| 2985 |
-
'type' => 'text',
|
| 2986 |
-
'options' => array(
|
| 2987 |
-
'text_allow_html' => true,
|
| 2988 |
-
),
|
| 2989 |
-
),
|
| 2990 |
-
'description' => array(
|
| 2991 |
-
'label' => __( 'Description', 'pods' ),
|
| 2992 |
-
'width' => '60%',
|
| 2993 |
-
'type' => 'text',
|
| 2994 |
-
'options' => array(
|
| 2995 |
-
'text_allow_html' => true,
|
| 2996 |
-
'text_allowed_html_tags' => 'strong em a ul ol li b i br div',
|
| 2997 |
-
),
|
| 2998 |
-
),
|
| 2999 |
-
),
|
| 3000 |
-
),
|
| 3001 |
-
'actions_disabled' => array( 'duplicate', 'view', 'export', 'add', 'edit', 'delete' ),
|
| 3002 |
-
'actions_custom' => array(
|
| 3003 |
-
'toggle' => array(
|
| 3004 |
-
'callback' => array( $this, 'admin_components_toggle' ),
|
| 3005 |
-
'nonce' => true,
|
| 3006 |
-
),
|
| 3007 |
-
),
|
| 3008 |
-
'filters_enhanced' => true,
|
| 3009 |
-
'views' => array(
|
| 3010 |
-
'all' => __( 'All', 'pods' ),
|
| 3011 |
-
// 'recommended' => __( 'Recommended', 'pods' ),
|
| 3012 |
-
'field-types' => __( 'Field Types', 'pods' ),
|
| 3013 |
-
'tools' => __( 'Tools', 'pods' ),
|
| 3014 |
-
'integration' => __( 'Integration', 'pods' ),
|
| 3015 |
-
'migration' => __( 'Migration', 'pods' ),
|
| 3016 |
-
'advanced' => __( 'Advanced', 'pods' ),
|
| 3017 |
-
),
|
| 3018 |
-
'view' => $view,
|
| 3019 |
-
'heading' => array(
|
| 3020 |
-
'views' => __( 'Category', 'pods' ),
|
| 3021 |
-
),
|
| 3022 |
-
'search' => false,
|
| 3023 |
-
'searchable' => false,
|
| 3024 |
-
'sortable' => false,
|
| 3025 |
-
'pagination' => false,
|
| 3026 |
-
);
|
| 3027 |
-
|
| 3028 |
-
if ( pods_developer() ) {
|
| 3029 |
-
$ui['views']['dev'] = __( 'Developer Preview', 'pods' );
|
| 3030 |
-
}
|
| 3031 |
|
| 3032 |
-
|
| 3033 |
-
|
|
|
|
| 3034 |
|
| 3035 |
-
|
| 3036 |
-
|
| 3037 |
|
| 3038 |
-
|
| 3039 |
-
|
| 3040 |
|
| 3041 |
-
|
| 3042 |
-
|
| 3043 |
-
*
|
| 3044 |
-
* @param PodsUI $ui PodsUI object.
|
| 3045 |
-
*
|
| 3046 |
-
* @return bool
|
| 3047 |
-
*/
|
| 3048 |
-
public function admin_components_toggle( $ui ) {
|
| 3049 |
|
| 3050 |
-
|
| 3051 |
-
|
| 3052 |
|
| 3053 |
-
|
| 3054 |
-
|
| 3055 |
|
| 3056 |
-
|
| 3057 |
-
$website = 'http://wordpress.org/extend/plugins/' . dirname( $dependency[1] ) . '/';
|
| 3058 |
|
| 3059 |
-
|
| 3060 |
-
|
| 3061 |
-
|
|
|
|
| 3062 |
|
| 3063 |
-
|
| 3064 |
-
$website = ' ' . sprintf( __( 'You can find it at %s', 'pods' ), '<a href="' . $website . '" target="_blank" rel="noopener noreferrer">' . $website . '</a>' );
|
| 3065 |
-
}
|
| 3066 |
|
| 3067 |
-
|
|
|
|
|
|
|
|
|
|
| 3068 |
|
| 3069 |
-
|
| 3070 |
|
| 3071 |
-
|
|
|
|
|
|
|
| 3072 |
|
| 3073 |
-
|
| 3074 |
-
|
| 3075 |
-
}//end if
|
| 3076 |
|
| 3077 |
-
|
| 3078 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3079 |
|
| 3080 |
-
|
|
|
|
|
|
|
| 3081 |
|
| 3082 |
-
|
| 3083 |
-
|
| 3084 |
|
| 3085 |
-
|
| 3086 |
-
|
| 3087 |
-
}
|
| 3088 |
|
| 3089 |
-
|
| 3090 |
|
| 3091 |
-
|
|
|
|
|
|
|
|
|
|
| 3092 |
|
| 3093 |
-
|
|
|
|
| 3094 |
|
| 3095 |
-
|
| 3096 |
-
|
| 3097 |
-
|
|
|
|
|
|
|
|
|
|
| 3098 |
|
| 3099 |
-
|
| 3100 |
-
$message = sprintf( __( 'The %s component can not be disabled from here. You must deactivate the plugin or theme that added it.', 'pods' ), PodsInit::$components->components[ $component ]['Name'] );
|
| 3101 |
|
| 3102 |
-
|
|
|
|
| 3103 |
|
| 3104 |
-
|
|
|
|
|
|
|
| 3105 |
|
| 3106 |
-
|
| 3107 |
-
|
| 3108 |
|
| 3109 |
-
|
| 3110 |
-
|
| 3111 |
|
| 3112 |
-
|
| 3113 |
-
|
| 3114 |
-
} elseif ( false === $toggle ) {
|
| 3115 |
-
$ui->message( PodsInit::$components->components[ $component ]['Name'] . ' ' . __( 'Component disabled', 'pods' ) );
|
| 3116 |
-
}
|
| 3117 |
|
| 3118 |
-
|
|
|
|
| 3119 |
|
| 3120 |
-
|
| 3121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3122 |
|
| 3123 |
-
|
| 3124 |
-
|
| 3125 |
-
|
| 3126 |
-
|
| 3127 |
-
|
| 3128 |
-
|
| 3129 |
-
|
| 3130 |
-
|
| 3131 |
-
|
| 3132 |
-
|
| 3133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3150 |
|
| 3151 |
-
|
| 3152 |
-
} elseif ( 1 === (int) pods_v( 'toggle' ) ) {
|
| 3153 |
-
$ui->message( PodsInit::$components->components[ $component ]['Name'] . ' ' . __( 'Component enabled', 'pods' ) );
|
| 3154 |
-
} else {
|
| 3155 |
-
$ui->message( PodsInit::$components->components[ $component ]['Name'] . ' ' . __( 'Component disabled', 'pods' ) );
|
| 3156 |
-
}//end if
|
| 3157 |
|
| 3158 |
-
|
| 3159 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3160 |
|
| 3161 |
-
|
| 3162 |
-
|
| 3163 |
-
|
| 3164 |
-
|
| 3165 |
|
| 3166 |
-
|
| 3167 |
-
|
| 3168 |
-
|
|
|
|
| 3169 |
|
| 3170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3189 |
|
| 3190 |
/**
|
| 3191 |
-
*
|
| 3192 |
*
|
| 3193 |
-
* @param
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3194 |
*
|
| 3195 |
-
* @
|
| 3196 |
*/
|
| 3197 |
-
public function
|
| 3198 |
-
|
| 3199 |
-
$pods = pods_api()->load_pods(
|
| 3200 |
-
array(
|
| 3201 |
-
'type' => array(
|
| 3202 |
-
'settings',
|
| 3203 |
-
'post_type',
|
| 3204 |
-
'taxonomy',
|
| 3205 |
-
),
|
| 3206 |
-
'fields' => false,
|
| 3207 |
-
'table_info' => false,
|
| 3208 |
-
)
|
| 3209 |
-
);
|
| 3210 |
-
|
| 3211 |
-
$other_pods = pods_api()->load_pods(
|
| 3212 |
-
array(
|
| 3213 |
-
'type' => array(
|
| 3214 |
-
'pod',
|
| 3215 |
-
'table',
|
| 3216 |
-
),
|
| 3217 |
-
'table_info' => false,
|
| 3218 |
-
)
|
| 3219 |
-
);
|
| 3220 |
-
|
| 3221 |
-
$pods = array_merge( $pods, $other_pods );
|
| 3222 |
-
|
| 3223 |
-
$capabilities[] = 'pods';
|
| 3224 |
-
$capabilities[] = 'pods_content';
|
| 3225 |
-
$capabilities[] = 'pods_settings';
|
| 3226 |
-
$capabilities[] = 'pods_components';
|
| 3227 |
-
|
| 3228 |
-
foreach ( $pods as $pod ) {
|
| 3229 |
-
if ( 'settings' === $pod['type'] ) {
|
| 3230 |
-
$capabilities[] = 'pods_edit_' . $pod['name'];
|
| 3231 |
-
} elseif ( 'post_type' === $pod['type'] ) {
|
| 3232 |
-
$capability_type = pods_v_sanitized( 'capability_type_custom', $pod['options'], pods_v( 'name', $pod ) );
|
| 3233 |
-
|
| 3234 |
-
if ( 'custom' === pods_v( 'capability_type', $pod['options'] ) && 0 < strlen( $capability_type ) ) {
|
| 3235 |
-
$capabilities[] = 'read_' . $capability_type;
|
| 3236 |
-
$capabilities[] = 'edit_' . $capability_type;
|
| 3237 |
-
$capabilities[] = 'delete_' . $capability_type;
|
| 3238 |
-
|
| 3239 |
-
if ( 1 === (int) pods_v( 'capability_type_extra', $pod['options'], 1 ) ) {
|
| 3240 |
-
$capability_type_plural = $capability_type . 's';
|
| 3241 |
-
|
| 3242 |
-
$capabilities[] = 'read_private_' . $capability_type_plural;
|
| 3243 |
-
$capabilities[] = 'edit_' . $capability_type_plural;
|
| 3244 |
-
$capabilities[] = 'edit_others_' . $capability_type_plural;
|
| 3245 |
-
$capabilities[] = 'edit_private_' . $capability_type_plural;
|
| 3246 |
-
$capabilities[] = 'edit_published_' . $capability_type_plural;
|
| 3247 |
-
$capabilities[] = 'publish_' . $capability_type_plural;
|
| 3248 |
-
$capabilities[] = 'delete_' . $capability_type_plural;
|
| 3249 |
-
$capabilities[] = 'delete_private_' . $capability_type_plural;
|
| 3250 |
-
$capabilities[] = 'delete_published_' . $capability_type_plural;
|
| 3251 |
-
$capabilities[] = 'delete_others_' . $capability_type_plural;
|
| 3252 |
-
}
|
| 3253 |
-
}
|
| 3254 |
-
} elseif ( 'taxonomy' === $pod['type'] ) {
|
| 3255 |
-
if ( 'custom' === pods_v( 'capability_type', $pod['options'], 'terms' ) ) {
|
| 3256 |
-
$capability_type = pods_v_sanitized( 'capability_type_custom', $pod['options'], pods_v( 'name', $pod ) . 's' );
|
| 3257 |
-
|
| 3258 |
-
$capability_type .= '_term';
|
| 3259 |
-
$capability_type_plural = $capability_type . 's';
|
| 3260 |
-
|
| 3261 |
-
// Singular
|
| 3262 |
-
$capabilities[] = 'edit_' . $capability_type;
|
| 3263 |
-
$capabilities[] = 'delete_' . $capability_type;
|
| 3264 |
-
$capabilities[] = 'assign_' . $capability_type;
|
| 3265 |
-
// Plural
|
| 3266 |
-
$capabilities[] = 'manage_' . $capability_type_plural;
|
| 3267 |
-
$capabilities[] = 'edit_' . $capability_type_plural;
|
| 3268 |
-
$capabilities[] = 'delete_' . $capability_type_plural;
|
| 3269 |
-
$capabilities[] = 'assign_' . $capability_type_plural;
|
| 3270 |
-
}
|
| 3271 |
-
} else {
|
| 3272 |
-
$capabilities[] = 'pods_add_' . $pod['name'];
|
| 3273 |
-
$capabilities[] = 'pods_edit_' . $pod['name'];
|
| 3274 |
|
| 3275 |
-
|
| 3276 |
-
|
| 3277 |
-
|
| 3278 |
|
| 3279 |
-
|
| 3280 |
|
| 3281 |
-
|
| 3282 |
-
$capabilities[] = 'pods_delete_others_' . $pod['name'];
|
| 3283 |
-
}
|
| 3284 |
|
| 3285 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3286 |
|
| 3287 |
-
|
| 3288 |
-
|
| 3289 |
-
} else {
|
| 3290 |
-
$actions_enabled = array();
|
| 3291 |
-
}
|
| 3292 |
|
| 3293 |
-
|
| 3294 |
-
'add',
|
| 3295 |
-
'edit',
|
| 3296 |
-
'duplicate',
|
| 3297 |
-
'delete',
|
| 3298 |
-
'reorder',
|
| 3299 |
-
'export',
|
| 3300 |
-
);
|
| 3301 |
-
|
| 3302 |
-
if ( ! empty( $actions_enabled ) ) {
|
| 3303 |
-
$actions_disabled = array(
|
| 3304 |
-
'view' => 'view',
|
| 3305 |
-
);
|
| 3306 |
|
| 3307 |
-
|
| 3308 |
-
if ( ! in_array( $action, $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 |
-
|
| 3342 |
-
$params = pods_unslash( (array) $_POST );
|
| 3343 |
|
| 3344 |
foreach ( $params as $key => $value ) {
|
| 3345 |
-
if ( 'action'
|
| 3346 |
continue;
|
| 3347 |
-
}
|
| 3348 |
|
| 3349 |
-
// Fixup $_POST data
|
| 3350 |
$_POST[ str_replace( '_podsfix_', '', $key ) ] = $_POST[ $key ];
|
| 3351 |
|
| 3352 |
// Fixup $params with unslashed data
|
|
@@ -3356,530 +2249,161 @@ class PodsAdmin {
|
|
| 3356 |
unset( $params[ $key ] );
|
| 3357 |
}
|
| 3358 |
|
| 3359 |
-
|
| 3360 |
|
| 3361 |
-
|
| 3362 |
-
|
| 3363 |
-
|
| 3364 |
-
|
| 3365 |
-
|
| 3366 |
-
|
| 3367 |
-
|
| 3368 |
-
|
| 3369 |
-
);
|
| 3370 |
|
| 3371 |
-
|
| 3372 |
-
* AJAX Callbacks in field editor
|
| 3373 |
-
*
|
| 3374 |
-
* @since unknown
|
| 3375 |
-
*
|
| 3376 |
-
* @param array $methods Callback methods.
|
| 3377 |
-
* @param PodsAdmin $obj PodsAdmin object.
|
| 3378 |
-
*/
|
| 3379 |
-
$methods = apply_filters( 'pods_admin_ajax_methods', $methods, $this );
|
| 3380 |
|
| 3381 |
-
|
| 3382 |
-
|
| 3383 |
-
}
|
| 3384 |
|
| 3385 |
-
|
| 3386 |
-
|
| 3387 |
-
|
| 3388 |
-
|
| 3389 |
-
|
| 3390 |
|
| 3391 |
-
|
| 3392 |
|
| 3393 |
-
|
| 3394 |
-
|
| 3395 |
-
}
|
| 3396 |
|
| 3397 |
-
|
| 3398 |
-
|
| 3399 |
-
|
| 3400 |
|
| 3401 |
-
|
| 3402 |
-
|
| 3403 |
-
}
|
| 3404 |
|
| 3405 |
-
|
| 3406 |
-
|
| 3407 |
-
|
| 3408 |
-
}
|
| 3409 |
|
| 3410 |
-
|
| 3411 |
|
| 3412 |
-
|
| 3413 |
|
| 3414 |
-
|
| 3415 |
|
| 3416 |
-
|
| 3417 |
|
| 3418 |
-
|
| 3419 |
-
|
| 3420 |
-
|
| 3421 |
-
|
| 3422 |
-
|
| 3423 |
-
|
| 3424 |
-
|
| 3425 |
-
|
| 3426 |
-
|
| 3427 |
-
|
| 3428 |
-
if ( isset( $params->field_data_json ) && is_array( $params->field_data_json ) ) {
|
| 3429 |
-
$params->fields = $params->field_data_json;
|
| 3430 |
-
|
| 3431 |
-
unset( $params->field_data_json );
|
| 3432 |
-
|
| 3433 |
-
foreach ( $params->fields as $k => $v ) {
|
| 3434 |
-
if ( empty( $v ) ) {
|
| 3435 |
-
unset( $params->fields[ $k ] );
|
| 3436 |
-
} elseif ( ! is_array( $v ) ) {
|
| 3437 |
-
$params->fields[ $k ] = (array) @json_decode( $v, true );
|
| 3438 |
-
}
|
| 3439 |
-
}
|
| 3440 |
-
}
|
| 3441 |
-
}
|
| 3442 |
|
| 3443 |
-
|
| 3444 |
-
$params = (array) $params;
|
| 3445 |
-
|
| 3446 |
-
$output = call_user_func( array( $api, $method->name ), $params );
|
| 3447 |
-
}//end if
|
| 3448 |
-
|
| 3449 |
-
// Output in json format
|
| 3450 |
-
if ( false !== $output ) {
|
| 3451 |
-
|
| 3452 |
-
/**
|
| 3453 |
-
* Pods Admin AJAX request was successful
|
| 3454 |
-
*
|
| 3455 |
-
* @since 2.6.8
|
| 3456 |
-
*
|
| 3457 |
-
* @param array $params AJAX parameters.
|
| 3458 |
-
* @param array|object|string $output Output for AJAX request.
|
| 3459 |
-
*/
|
| 3460 |
-
do_action( "pods_admin_ajax_success_{$method->name}", $params, $output );
|
| 3461 |
-
|
| 3462 |
-
if ( is_array( $output ) || is_object( $output ) ) {
|
| 3463 |
-
wp_send_json( $output );
|
| 3464 |
-
} else {
|
| 3465 |
-
// @codingStandardsIgnoreLine
|
| 3466 |
-
echo $output;
|
| 3467 |
-
}
|
| 3468 |
-
} else {
|
| 3469 |
-
pods_error( __( 'There was a problem with your request.', 'pods' ) );
|
| 3470 |
-
}//end if
|
| 3471 |
|
| 3472 |
-
|
| 3473 |
-
|
| 3474 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3475 |
|
| 3476 |
/**
|
| 3477 |
* Profiles the Pods configuration
|
| 3478 |
*
|
| 3479 |
-
* @param null|string|array $pod
|
| 3480 |
-
*
|
| 3481 |
-
* default, to profile all Pods.
|
| 3482 |
-
* @param bool $full_field_info If true all info about each field is returned. If false,
|
| 3483 |
-
* which is the default only name and type, will be returned.
|
| 3484 |
*
|
| 3485 |
* @return array
|
| 3486 |
*
|
| 3487 |
-
* @since
|
| 3488 |
*/
|
| 3489 |
-
|
| 3490 |
-
|
| 3491 |
$api = pods_api();
|
| 3492 |
|
| 3493 |
-
if (
|
| 3494 |
$the_pods = $api->load_pods();
|
| 3495 |
-
}
|
|
|
|
| 3496 |
foreach ( $pod as $p ) {
|
| 3497 |
$the_pods[] = $api->load_pod( $p );
|
| 3498 |
}
|
| 3499 |
-
}
|
|
|
|
| 3500 |
$the_pods[] = $api->load_pod( $pod );
|
| 3501 |
}
|
| 3502 |
|
| 3503 |
-
foreach
|
| 3504 |
-
$configuration[ $
|
| 3505 |
-
'name'
|
| 3506 |
-
'ID'
|
| 3507 |
-
'storage'
|
| 3508 |
-
'fields'
|
| 3509 |
);
|
| 3510 |
}
|
| 3511 |
|
| 3512 |
if ( ! $full_field_info ) {
|
| 3513 |
-
foreach ( $the_pods as $
|
| 3514 |
-
$fields = $configuration[ $
|
| 3515 |
-
|
| 3516 |
-
unset( $configuration[ $the_pod['name'] ]['fields'] );
|
| 3517 |
-
|
| 3518 |
foreach ( $fields as $field ) {
|
| 3519 |
-
$info = array(
|
| 3520 |
-
'name' => $field['name'],
|
| 3521 |
-
'type' => $field['type'],
|
| 3522 |
);
|
| 3523 |
|
| 3524 |
-
if (
|
| 3525 |
-
$info['pick_object'] = $field['pick_object'];
|
| 3526 |
-
|
| 3527 |
-
|
| 3528 |
-
$info['pick_val'] = $field['pick_val'];
|
| 3529 |
}
|
| 3530 |
}
|
| 3531 |
|
| 3532 |
if ( is_array( $info ) ) {
|
| 3533 |
-
$configuration[ $
|
| 3534 |
}
|
| 3535 |
|
| 3536 |
unset( $info );
|
| 3537 |
|
| 3538 |
-
}
|
| 3539 |
-
}//end foreach
|
| 3540 |
-
}//end if
|
| 3541 |
-
|
| 3542 |
-
if ( is_array( $configuration ) ) {
|
| 3543 |
-
return $configuration;
|
| 3544 |
-
}
|
| 3545 |
|
| 3546 |
-
|
| 3547 |
|
| 3548 |
-
/**
|
| 3549 |
-
* Build UI for extending REST API, if makes sense to do so.
|
| 3550 |
-
*
|
| 3551 |
-
* @since 2.6.0
|
| 3552 |
-
*
|
| 3553 |
-
* @access protected
|
| 3554 |
-
*/
|
| 3555 |
-
protected function rest_admin() {
|
| 3556 |
-
|
| 3557 |
-
if ( function_exists( 'register_rest_field' ) ) {
|
| 3558 |
-
add_filter(
|
| 3559 |
-
'pods_admin_setup_edit_field_options', array(
|
| 3560 |
-
$this,
|
| 3561 |
-
'add_rest_fields_to_field_editor',
|
| 3562 |
-
), 12, 2
|
| 3563 |
-
);
|
| 3564 |
-
add_filter( 'pods_admin_setup_edit_field_tabs', array( $this, 'add_rest_field_tab' ), 12 );
|
| 3565 |
}
|
| 3566 |
|
| 3567 |
-
|
| 3568 |
-
|
| 3569 |
-
|
| 3570 |
-
}
|
| 3571 |
-
|
| 3572 |
-
/**
|
| 3573 |
-
* Check if Pod type <em>could</em> extend core REST API response
|
| 3574 |
-
*
|
| 3575 |
-
* @since 2.5.6
|
| 3576 |
-
*
|
| 3577 |
-
* @access protected
|
| 3578 |
-
*
|
| 3579 |
-
* @param array $pod Pod options.
|
| 3580 |
-
*
|
| 3581 |
-
* @return bool
|
| 3582 |
-
*/
|
| 3583 |
-
protected function restable_pod( $pod ) {
|
| 3584 |
-
|
| 3585 |
-
$type = $pod['type'];
|
| 3586 |
-
|
| 3587 |
-
$restable_types = array(
|
| 3588 |
-
'post_type',
|
| 3589 |
-
'user',
|
| 3590 |
-
'taxonomy',
|
| 3591 |
-
'media',
|
| 3592 |
-
);
|
| 3593 |
-
|
| 3594 |
-
return in_array( $type, $restable_types, true );
|
| 3595 |
-
|
| 3596 |
-
}
|
| 3597 |
-
|
| 3598 |
-
/**
|
| 3599 |
-
* Add a rest api tab.
|
| 3600 |
-
*
|
| 3601 |
-
* @since 2.6.0
|
| 3602 |
-
*
|
| 3603 |
-
* @param array $tabs Tab array.
|
| 3604 |
-
* @param array $pod Pod options.
|
| 3605 |
-
*
|
| 3606 |
-
* @return array
|
| 3607 |
-
*/
|
| 3608 |
-
public function add_rest_settings_tab( $tabs, $pod ) {
|
| 3609 |
-
|
| 3610 |
-
$tabs['rest-api'] = __( 'REST API', 'pods' );
|
| 3611 |
-
|
| 3612 |
-
return $tabs;
|
| 3613 |
-
|
| 3614 |
-
}
|
| 3615 |
-
|
| 3616 |
-
/**
|
| 3617 |
-
* Populate REST API tab.
|
| 3618 |
-
*
|
| 3619 |
-
* @since 0.1.0
|
| 3620 |
-
*
|
| 3621 |
-
* @param array $options Tab options.
|
| 3622 |
-
* @param array $pod Pod options.
|
| 3623 |
-
*
|
| 3624 |
-
* @return array
|
| 3625 |
-
*/
|
| 3626 |
-
public function add_rest_settings_tab_fields( $options, $pod ) {
|
| 3627 |
-
|
| 3628 |
-
if ( ! function_exists( 'register_rest_field' ) ) {
|
| 3629 |
-
$options['rest-api'] = array(
|
| 3630 |
-
'no_dependencies' => array(
|
| 3631 |
-
'label' => sprintf( __( 'Pods REST API support requires WordPress 4.3.1 or later and the %s or later.', 'pods' ), '<a href="https://pods.io/docs/build/extending-core-wordpress-rest-api-routes-with-pods/" target="_blank" rel="noopener noreferrer">WordPress REST API 2.0-beta9</a>' ),
|
| 3632 |
-
'help' => sprintf( __( 'See %s for more information.', 'pods' ), '<a href="https://pods.io/docs/build/extending-core-wordpress-rest-api-routes-with-pods/" target="_blank" rel="noopener noreferrer">https://pods.io/docs/build/extending-core-wordpress-rest-api-routes-with-pods/</a>' ),
|
| 3633 |
-
'type' => 'html',
|
| 3634 |
-
),
|
| 3635 |
-
);
|
| 3636 |
-
} elseif ( $this->restable_pod( $pod ) ) {
|
| 3637 |
-
$options['rest-api'] = array(
|
| 3638 |
-
'rest_enable' => array(
|
| 3639 |
-
'label' => __( 'Enable', 'pods' ),
|
| 3640 |
-
'help' => __( 'Add REST API support for this Pod.', 'pods' ),
|
| 3641 |
-
'type' => 'boolean',
|
| 3642 |
-
'default' => '',
|
| 3643 |
-
'dependency' => true,
|
| 3644 |
-
),
|
| 3645 |
-
'rest_base' => array(
|
| 3646 |
-
'label' => __( 'REST Base (if any)', 'pods' ),
|
| 3647 |
-
'help' => __( 'This will form the url for the route. Default / empty value here will use the pod name.', 'pods' ),
|
| 3648 |
-
'type' => 'text',
|
| 3649 |
-
'default' => '',
|
| 3650 |
-
'depends-on' => array( 'rest_enable' => true ),
|
| 3651 |
-
),
|
| 3652 |
-
'read_all' => array(
|
| 3653 |
-
'label' => __( 'Show All Fields (read-only)', 'pods' ),
|
| 3654 |
-
'help' => __( 'Show all fields in REST API. If unchecked fields must be enabled on a field by field basis.', 'pods' ),
|
| 3655 |
-
'type' => 'boolean',
|
| 3656 |
-
'default' => '',
|
| 3657 |
-
'depends-on' => array( 'rest_enable' => true ),
|
| 3658 |
-
),
|
| 3659 |
-
'write_all' => array(
|
| 3660 |
-
'label' => __( 'Allow All Fields To Be Updated', 'pods' ),
|
| 3661 |
-
'help' => __( 'Allow all fields to be updated via the REST API. If unchecked fields must be enabled on a field by field basis.', 'pods' ),
|
| 3662 |
-
'type' => 'boolean',
|
| 3663 |
-
'default' => pods_v( 'name', $pod ),
|
| 3664 |
-
'boolean_yes_label' => '',
|
| 3665 |
-
'depends-on' => array( 'rest_enable' => true ),
|
| 3666 |
-
),
|
| 3667 |
-
|
| 3668 |
-
);
|
| 3669 |
-
|
| 3670 |
-
} else {
|
| 3671 |
-
$options['rest-api'] = array(
|
| 3672 |
-
'not_restable' => array(
|
| 3673 |
-
'label' => __( 'Pods REST API support covers post type, taxonomy and user Pods.', 'pods' ),
|
| 3674 |
-
'help' => sprintf( __( 'See %s for more information.', 'pods' ), '<a href="https://pods.io/docs/build/extending-core-wordpress-rest-api-routes-with-pods/" target="_blank" rel="noopener noreferrer">https://pods.io/docs/build/extending-core-wordpress-rest-api-routes-with-pods/"</a>' ),
|
| 3675 |
-
'type' => 'html',
|
| 3676 |
-
),
|
| 3677 |
-
);
|
| 3678 |
-
|
| 3679 |
-
}//end if
|
| 3680 |
-
|
| 3681 |
-
return $options;
|
| 3682 |
-
|
| 3683 |
-
}
|
| 3684 |
-
|
| 3685 |
-
/**
|
| 3686 |
-
* Add a REST API section to advanced tab of field editor.
|
| 3687 |
-
*
|
| 3688 |
-
* @since 2.5.6
|
| 3689 |
-
*
|
| 3690 |
-
* @param array $options Tab options.
|
| 3691 |
-
* @param array $pod Pod options.
|
| 3692 |
-
*
|
| 3693 |
-
* @return array
|
| 3694 |
-
*/
|
| 3695 |
-
public function add_rest_fields_to_field_editor( $options, $pod ) {
|
| 3696 |
-
|
| 3697 |
-
if ( $this->restable_pod( $pod ) ) {
|
| 3698 |
-
$options['rest'][ __( 'Read/ Write', 'pods' ) ] = array(
|
| 3699 |
-
'rest_read' => array(
|
| 3700 |
-
'label' => __( 'Read via REST API?', 'pods' ),
|
| 3701 |
-
'help' => __( 'Should this field be readable via the REST API? You must enable REST API support for this Pod.', 'pods' ),
|
| 3702 |
-
'type' => 'boolean',
|
| 3703 |
-
'default' => '',
|
| 3704 |
-
),
|
| 3705 |
-
'rest_write' => array(
|
| 3706 |
-
'label' => __( 'Write via REST API?', 'pods' ),
|
| 3707 |
-
'help' => __( 'Should this field be writeable via the REST API? You must enable REST API support for this Pod.', 'pods' ),
|
| 3708 |
-
'type' => 'boolean',
|
| 3709 |
-
'default' => '',
|
| 3710 |
-
),
|
| 3711 |
-
);
|
| 3712 |
-
$options['rest'][ __( 'Relationship Field Options', 'pods' ) ] = array(
|
| 3713 |
-
'rest_pick_response' => array(
|
| 3714 |
-
'label' => __( 'Response Type', 'pods' ),
|
| 3715 |
-
'help' => __( 'This will determine what amount of data for the related items will be returned.', 'pods' ),
|
| 3716 |
-
'type' => 'pick',
|
| 3717 |
-
'default' => 'array',
|
| 3718 |
-
'depends-on' => array( 'type' => 'pick' ),
|
| 3719 |
-
'dependency' => true,
|
| 3720 |
-
'data' => array(
|
| 3721 |
-
'array' => __( 'Full', 'pods' ),
|
| 3722 |
-
'id' => __( 'ID only', 'pods' ),
|
| 3723 |
-
'name' => __( 'Name', 'pods' ),
|
| 3724 |
-
),
|
| 3725 |
-
),
|
| 3726 |
-
'rest_pick_depth' => array(
|
| 3727 |
-
'label' => __( 'Depth', 'pods' ),
|
| 3728 |
-
'help' => __( 'How far to traverse relationships in response', 'pods' ),
|
| 3729 |
-
'type' => 'number',
|
| 3730 |
-
'default' => '2',
|
| 3731 |
-
'depends-on' => array(
|
| 3732 |
-
'type' => 'pick',
|
| 3733 |
-
'rest_pick_response' => 'array',
|
| 3734 |
-
),
|
| 3735 |
-
),
|
| 3736 |
-
|
| 3737 |
-
);
|
| 3738 |
-
|
| 3739 |
-
}//end if
|
| 3740 |
-
|
| 3741 |
-
return $options;
|
| 3742 |
-
|
| 3743 |
-
}
|
| 3744 |
-
|
| 3745 |
-
/**
|
| 3746 |
-
* Add REST field tab
|
| 3747 |
-
*
|
| 3748 |
-
* @since 2.5.6
|
| 3749 |
-
*
|
| 3750 |
-
* @param array $tabs Tab list.
|
| 3751 |
-
*
|
| 3752 |
-
* @return array
|
| 3753 |
-
*/
|
| 3754 |
-
public function add_rest_field_tab( $tabs ) {
|
| 3755 |
-
|
| 3756 |
-
$tabs['rest'] = __( 'REST API', 'pods' );
|
| 3757 |
-
|
| 3758 |
-
return $tabs;
|
| 3759 |
-
}
|
| 3760 |
|
| 3761 |
-
|
| 3762 |
-
* Add Pods-specific debug info to Site Info debug area.
|
| 3763 |
-
*
|
| 3764 |
-
* @since 2.7.13
|
| 3765 |
-
*
|
| 3766 |
-
* @param array $info Debug info.
|
| 3767 |
-
*
|
| 3768 |
-
* @return array Debug info with Pods-specific debug info added.
|
| 3769 |
-
*/
|
| 3770 |
-
public function add_debug_information( $info ) {
|
| 3771 |
-
$info['pods'] = array(
|
| 3772 |
-
'label' => 'Pods',
|
| 3773 |
-
'description' => __( 'Debug information for Pods installations.', 'pods' ),
|
| 3774 |
-
'fields' => array(
|
| 3775 |
-
'pods-server-software' => array(
|
| 3776 |
-
'label' => __( 'Server Software', 'pods' ),
|
| 3777 |
-
'value' => ! empty( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : 'N/A',
|
| 3778 |
-
),
|
| 3779 |
-
'pods-user-agent' => array(
|
| 3780 |
-
'label' => __( 'Your User Agent', 'pods' ),
|
| 3781 |
-
'value' => ! empty( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : 'N/A',
|
| 3782 |
-
),
|
| 3783 |
-
'pods-session-save-path' => array(
|
| 3784 |
-
'label' => __( 'Session Save Path', 'pods' ),
|
| 3785 |
-
'value' => session_save_path(),
|
| 3786 |
-
),
|
| 3787 |
-
'pods-session-save-path-exists' => array(
|
| 3788 |
-
'label' => __( 'Session Save Path Exists', 'pods' ),
|
| 3789 |
-
'value' => file_exists( session_save_path() ) ? __( 'Yes', 'pods' ) : __( 'No', 'pods' ),
|
| 3790 |
-
),
|
| 3791 |
-
'pods-session-save-path-writable' => array(
|
| 3792 |
-
'label' => __( 'Session Save Path Writeable', 'pods' ),
|
| 3793 |
-
'value' => is_writable( session_save_path() ) ? __( 'Yes', 'pods' ) : __( 'No', 'pods' ),
|
| 3794 |
-
),
|
| 3795 |
-
'pods-session-max-lifetime' => array(
|
| 3796 |
-
'label' => __( 'Session Max Lifetime', 'pods' ),
|
| 3797 |
-
'value' => ini_get( 'session.gc_maxlifetime' ),
|
| 3798 |
-
),
|
| 3799 |
-
'pods-opcode-cache-apc' => array(
|
| 3800 |
-
'label' => __( 'Opcode Cache: Apc', 'pods' ),
|
| 3801 |
-
'value' => function_exists( 'apc_cache_info' ) ? __( 'Yes', 'pods' ) : __( 'No', 'pods' ),
|
| 3802 |
-
),
|
| 3803 |
-
'pods-opcode-cache-memcached' => array(
|
| 3804 |
-
'label' => __( 'Opcode Cache: Memcached', 'pods' ),
|
| 3805 |
-
'value' => class_exists( 'eaccelerator_put' ) ? __( 'Yes', 'pods' ) : __( 'No', 'pods' ),
|
| 3806 |
-
),
|
| 3807 |
-
'pods-opcode-cache-opcache' => array(
|
| 3808 |
-
'label' => __( 'Opcode Cache: OPcache', 'pods' ),
|
| 3809 |
-
'value' => function_exists( 'opcache_get_status' ) ? __( 'Yes', 'pods' ) : __( 'No', 'pods' ),
|
| 3810 |
-
),
|
| 3811 |
-
'pods-opcode-cache-redis' => array(
|
| 3812 |
-
'label' => __( 'Opcode Cache: Redis', 'pods' ),
|
| 3813 |
-
'value' => class_exists( 'xcache_set' ) ? __( 'Yes', 'pods' ) : __( 'No', 'pods' ),
|
| 3814 |
-
),
|
| 3815 |
-
'pods-object-cache-apc' => array(
|
| 3816 |
-
'label' => __( 'Object Cache: APC', 'pods' ),
|
| 3817 |
-
'value' => function_exists( 'apc_cache_info' ) ? __( 'Yes', 'pods' ) : __( 'No', 'pods' ),
|
| 3818 |
-
),
|
| 3819 |
-
'pods-object-cache-apcu' => array(
|
| 3820 |
-
'label' => __( 'Object Cache: APCu', 'pods' ),
|
| 3821 |
-
'value' => function_exists( 'apcu_cache_info' ) ? __( 'Yes', 'pods' ) : __( 'No', 'pods' ),
|
| 3822 |
-
),
|
| 3823 |
-
'pods-object-cache-memcache' => array(
|
| 3824 |
-
'label' => __( 'Object Cache: Memcache', 'pods' ),
|
| 3825 |
-
'value' => class_exists( 'Memcache' ) ? __( 'Yes', 'pods' ) : __( 'No', 'pods' ),
|
| 3826 |
-
),
|
| 3827 |
-
'pods-object-cache-memcached' => array(
|
| 3828 |
-
'label' => __( 'Object Cache: Memcached', 'pods' ),
|
| 3829 |
-
'value' => class_exists( 'Memcached' ) ? __( 'Yes', 'pods' ) : __( 'No', 'pods' ),
|
| 3830 |
-
),
|
| 3831 |
-
'pods-object-cache-redis' => array(
|
| 3832 |
-
'label' => __( 'Object Cache: Redis', 'pods' ),
|
| 3833 |
-
'value' => class_exists( 'Redis' ) ? __( 'Yes', 'pods' ) : __( 'No', 'pods' ),
|
| 3834 |
-
),
|
| 3835 |
-
'pods-memory-current-usage' => array(
|
| 3836 |
-
'label' => __( 'Current Memory Usage', 'pods' ),
|
| 3837 |
-
'value' => number_format_i18n( memory_get_usage() / 1024 / 1024, 3 ) . 'M',
|
| 3838 |
-
),
|
| 3839 |
-
'pods-memory-current-usage-real' => array(
|
| 3840 |
-
'label' => __( 'Current Memory Usage (real)', 'pods' ),
|
| 3841 |
-
'value' => number_format_i18n( memory_get_usage( true ) / 1024 / 1024, 3 ) . 'M',
|
| 3842 |
-
),
|
| 3843 |
-
'pods-network-wide' => array(
|
| 3844 |
-
'label' => __( 'Pods Network-Wide Activated', 'pods' ),
|
| 3845 |
-
'value' => is_plugin_active_for_network( basename( PODS_DIR ) . '/init.php' ) ? __( 'Yes', 'pods' ) : __( 'No', 'pods' ),
|
| 3846 |
-
),
|
| 3847 |
-
'pods-install-location' => array(
|
| 3848 |
-
'label' => __( 'Pods Install Location', 'pods' ),
|
| 3849 |
-
'value' => PODS_DIR,
|
| 3850 |
-
),
|
| 3851 |
-
'pods-developer' => array(
|
| 3852 |
-
'label' => __( 'Pods Developer Activated' ),
|
| 3853 |
-
'value' => ( pods_developer() ) ? __( 'Yes', 'pods' ) : __( 'No', 'pods' ),
|
| 3854 |
-
),
|
| 3855 |
-
'pods-tableless-mode' => array(
|
| 3856 |
-
'label' => __( 'Pods Tableless Mode Activated', 'pods' ),
|
| 3857 |
-
'value' => ( pods_tableless() ) ? __( 'Yes', 'pods' ) : __( 'No', 'pods' ),
|
| 3858 |
-
),
|
| 3859 |
-
'pods-light-mode' => array(
|
| 3860 |
-
'label' => __( 'Pods Light Mode Activated', 'pods' ),
|
| 3861 |
-
'value' => ( pods_light() ) ? __( 'Yes', 'pods' ) : __( 'No', 'pods' ),
|
| 3862 |
-
),
|
| 3863 |
-
'pods-strict' => array(
|
| 3864 |
-
'label' => __( 'Pods Strict Activated' ),
|
| 3865 |
-
'value' => ( pods_strict() ) ? __( 'Yes', 'pods' ) : __( 'No', 'pods' ),
|
| 3866 |
-
),
|
| 3867 |
-
'pods-allow-deprecated' => array(
|
| 3868 |
-
'label' => __( 'Pods Allow Deprecated' ),
|
| 3869 |
-
'value' => ( pods_allow_deprecated() ) ? __( 'Yes', 'pods' ) : __( 'No', 'pods' ),
|
| 3870 |
-
),
|
| 3871 |
-
'pods-api-cache' => array(
|
| 3872 |
-
'label' => __( 'Pods API Cache Activated' ),
|
| 3873 |
-
'value' => ( pods_api_cache() ) ? __( 'Yes', 'pods' ) : __( 'No', 'pods' ),
|
| 3874 |
-
),
|
| 3875 |
-
'pods-shortcode-allow-evaluate-tags' => array(
|
| 3876 |
-
'label' => __( 'Pods Shortcode Allow Evaluate Tags' ),
|
| 3877 |
-
'value' => ( pods_shortcode_allow_evaluate_tags() ) ? __( 'Yes', 'pods' ) : __( 'No', 'pods' ),
|
| 3878 |
-
),
|
| 3879 |
-
),
|
| 3880 |
-
);
|
| 3881 |
|
| 3882 |
-
return $info;
|
| 3883 |
}
|
| 3884 |
|
| 3885 |
}
|
| 1 |
<?php
|
|
|
|
| 2 |
/**
|
| 3 |
* @package Pods
|
| 4 |
*/
|
| 5 |
class PodsAdmin {
|
| 6 |
|
| 7 |
+
/**
|
| 8 |
+
* @var PodsAdmin
|
| 9 |
+
*/
|
| 10 |
+
static $instance = null;
|
| 11 |
+
|
| 12 |
+
/**
|
| 13 |
+
* Singleton handling for a basic pods_admin() request
|
| 14 |
+
*
|
| 15 |
+
* @return \PodsAdmin
|
| 16 |
+
*
|
| 17 |
+
* @since 2.3.5
|
| 18 |
+
*/
|
| 19 |
+
public static function init () {
|
| 20 |
+
if ( !is_object( self::$instance ) )
|
| 21 |
+
self::$instance = new PodsAdmin();
|
| 22 |
+
|
| 23 |
+
return self::$instance;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
/**
|
| 27 |
+
* Setup and Handle Admin functionality
|
| 28 |
+
*
|
| 29 |
+
* @return \PodsAdmin
|
| 30 |
+
*
|
| 31 |
+
* @license http://www.gnu.org/licenses/gpl-2.0.html
|
| 32 |
+
* @since 2.0
|
| 33 |
+
*/
|
| 34 |
+
public function __construct () {
|
| 35 |
+
// Scripts / Stylesheets
|
| 36 |
+
add_action( 'admin_enqueue_scripts', array( $this, 'admin_head' ), 20 );
|
| 37 |
+
|
| 38 |
+
// AJAX $_POST fix
|
| 39 |
+
add_action( 'admin_init', array( $this, 'admin_init' ), 9 );
|
| 40 |
+
|
| 41 |
+
// Menus
|
| 42 |
+
add_action( 'admin_menu', array( $this, 'admin_menu' ), 99 );
|
| 43 |
+
|
| 44 |
+
// AJAX for Admin
|
| 45 |
+
add_action( 'wp_ajax_pods_admin', array( $this, 'admin_ajax' ) );
|
| 46 |
+
add_action( 'wp_ajax_nopriv_pods_admin', array( $this, 'admin_ajax' ) );
|
| 47 |
+
|
| 48 |
+
// Add Media Bar button for Shortcode
|
| 49 |
+
add_action( 'media_buttons', array( $this, 'media_button' ), 12 );
|
| 50 |
+
|
| 51 |
+
// Add the Pods capabilities
|
| 52 |
+
add_filter( 'members_get_capabilities', array( $this, 'admin_capabilities' ) );
|
| 53 |
+
|
| 54 |
+
add_action( 'admin_head-media-upload-popup', array( $this, 'register_media_assets' ) );
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
/**
|
| 58 |
+
* Init the admin area
|
| 59 |
+
*
|
| 60 |
+
* @since 2.0
|
| 61 |
+
*/
|
| 62 |
+
public function admin_init () {
|
| 63 |
+
// Fix for plugins that *don't do it right* so we don't cause issues for users
|
| 64 |
+
if ( defined( 'DOING_AJAX' ) && !empty( $_POST ) ) {
|
| 65 |
+
$pods_admin_ajax_actions = array(
|
| 66 |
+
'pods_admin',
|
| 67 |
+
'pods_relationship',
|
| 68 |
+
'pods_upload',
|
| 69 |
+
'pods_admin_components'
|
| 70 |
+
);
|
| 71 |
+
|
| 72 |
+
$pods_admin_ajax_actions = apply_filters( 'pods_admin_ajax_actions', $pods_admin_ajax_actions );
|
| 73 |
+
|
| 74 |
+
if ( in_array( pods_var( 'action', 'get' ), $pods_admin_ajax_actions ) || in_array( pods_var( 'action', 'post' ), $pods_admin_ajax_actions ) ) {
|
| 75 |
+
foreach ( $_POST as $key => $value ) {
|
| 76 |
+
if ( 'action' == $key || 0 === strpos( $key, '_podsfix_' ) )
|
| 77 |
+
continue;
|
| 78 |
+
|
| 79 |
+
unset( $_POST[ $key ] );
|
| 80 |
+
|
| 81 |
+
$_POST[ '_podsfix_' . $key ] = $value;
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
/**
|
| 88 |
+
* Attach requirements to admin header
|
| 89 |
+
*
|
| 90 |
+
* @since 2.0
|
| 91 |
+
*/
|
| 92 |
+
public function admin_head () {
|
| 93 |
+
wp_register_style( 'pods-admin', PODS_URL . 'ui/css/pods-admin.css', array(), PODS_VERSION );
|
| 94 |
+
|
| 95 |
+
wp_register_style( 'pods-font', PODS_URL . 'ui/css/pods-font.css', array(), PODS_VERSION );
|
| 96 |
+
|
| 97 |
+
wp_register_script( 'pods-floatmenu', PODS_URL . 'ui/js/floatmenu.js', array(), PODS_VERSION );
|
| 98 |
+
|
| 99 |
+
wp_register_script( 'pods-admin-importer', PODS_URL . 'ui/js/admin-importer.js', array(), PODS_VERSION );
|
| 100 |
+
|
| 101 |
+
wp_register_style( 'pods-manage', PODS_URL . 'ui/css/pods-manage.css', array(), PODS_VERSION );
|
| 102 |
+
|
| 103 |
+
wp_register_style( 'pods-wizard', PODS_URL . 'ui/css/pods-wizard.css', array(), PODS_VERSION );
|
| 104 |
+
|
| 105 |
+
wp_register_script( 'pods-upgrade', PODS_URL . 'ui/js/jquery.pods.upgrade.js', array(), PODS_VERSION );
|
| 106 |
+
|
| 107 |
+
wp_register_script( 'pods-migrate', PODS_URL . 'ui/js/jquery.pods.migrate.js', array(), PODS_VERSION );
|
| 108 |
+
|
| 109 |
+
if ( isset( $_GET[ 'page' ] ) ) {
|
| 110 |
+
$page = $_GET[ 'page' ];
|
| 111 |
+
if ( 'pods' == $page || ( false !== strpos( $page, 'pods-' ) && 0 === strpos( $page, 'pods-' ) ) ) {
|
| 112 |
+
?>
|
| 113 |
+
<script type="text/javascript">
|
| 114 |
+
var PODS_URL = "<?php echo esc_js( PODS_URL ); ?>";
|
| 115 |
+
</script>
|
| 116 |
+
<?php
|
| 117 |
+
wp_enqueue_script( 'jquery' );
|
| 118 |
+
wp_enqueue_script( 'jquery-ui-core' );
|
| 119 |
+
wp_enqueue_script( 'jquery-ui-sortable' );
|
| 120 |
+
|
| 121 |
+
wp_enqueue_style( 'jquery-ui' );
|
| 122 |
+
|
| 123 |
+
wp_enqueue_script( 'pods-floatmenu' );
|
| 124 |
+
|
| 125 |
+
wp_enqueue_style( 'jquery-qtip2' );
|
| 126 |
+
wp_enqueue_script( 'jquery-qtip2' );
|
| 127 |
+
wp_enqueue_script( 'pods-qtip-init' );
|
| 128 |
+
|
| 129 |
+
wp_enqueue_script( 'pods' );
|
| 130 |
+
|
| 131 |
+
if ( 0 === strpos( $page, 'pods-manage-' ) || 0 === strpos( $page, 'pods-add-new-' ) )
|
| 132 |
+
wp_enqueue_script( 'post' );
|
| 133 |
+
elseif ( 0 === strpos( $page, 'pods-settings-' ) ) {
|
| 134 |
+
wp_enqueue_script( 'post' );
|
| 135 |
+
wp_enqueue_style( 'pods-admin' );
|
| 136 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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
+
if ( 'pods-advanced' == $page ) {
|
| 141 |
+
wp_register_style( 'pods-advanced', PODS_URL . 'ui/css/pods-advanced.css', array(), '1.0' );
|
| 142 |
+
wp_enqueue_style( 'pods-advanced' );
|
|
|
|
| 143 |
|
| 144 |
+
wp_enqueue_script( 'jquery-ui-effects-core', PODS_URL . 'ui/js/jquery-ui/jquery.effects.core.js', array( 'jquery' ), '1.8.8' );
|
| 145 |
+
wp_enqueue_script( 'jquery-ui-effects-fade', PODS_URL . 'ui/js/jquery-ui/jquery.effects.fade.js', array( 'jquery' ), '1.8.8' );
|
| 146 |
+
wp_enqueue_script( 'jquery-ui-dialog' );
|
| 147 |
|
| 148 |
+
wp_register_script( 'pods-advanced', PODS_URL . 'ui/js/advanced.js', array(), PODS_VERSION );
|
| 149 |
+
wp_enqueue_script( 'pods-advanced' );
|
| 150 |
+
}
|
| 151 |
+
elseif ( 'pods-packages' == $page )
|
| 152 |
+
wp_enqueue_style( 'pods-wizard' );
|
| 153 |
+
elseif ( 'pods-wizard' == $page || 'pods-upgrade' == $page || ( in_array( $page, array( 'pods', 'pods-add-new' ) ) && in_array( pods_var( 'action', 'get', 'manage' ), array( 'add', 'manage' ) ) ) ) {
|
| 154 |
+
wp_enqueue_style( 'pods-wizard' );
|
| 155 |
+
|
| 156 |
+
if ( 'pods-upgrade' == $page )
|
| 157 |
+
wp_enqueue_script( 'pods-upgrade' );
|
| 158 |
+
}
|
| 159 |
+
}
|
| 160 |
+
}
|
| 161 |
|
| 162 |
+
wp_enqueue_style( 'pods-font' );
|
| 163 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
|
| 165 |
+
/**
|
| 166 |
+
* Build the admin menus
|
| 167 |
+
*
|
| 168 |
+
* @since 2.0
|
| 169 |
+
*/
|
| 170 |
+
public function admin_menu () {
|
| 171 |
+
$advanced_content_types = PodsMeta::$advanced_content_types;
|
| 172 |
+
$taxonomies = PodsMeta::$taxonomies;
|
| 173 |
+
$settings = PodsMeta::$settings;
|
| 174 |
|
| 175 |
+
$all_pods = pods_api()->load_pods( array( 'count' => true ) );
|
|
|
|
| 176 |
|
| 177 |
+
if ( !PodsInit::$upgrade_needed || ( pods_is_admin() && 1 == pods_var( 'pods_upgrade_bypass' ) ) ) {
|
| 178 |
+
$submenu_items = array();
|
| 179 |
|
| 180 |
+
if ( !empty( $advanced_content_types ) ) {
|
| 181 |
+
$submenu = array();
|
|
|
|
|
|
|
|
|
|
| 182 |
|
| 183 |
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
|
| 185 |
+
foreach ( (array) $advanced_content_types as $pod ) {
|
| 186 |
+
if ( !isset( $pod[ 'name' ] ) || !isset( $pod[ 'options' ] ) || empty( $pod[ 'fields' ] ) )
|
| 187 |
+
continue;
|
| 188 |
+
elseif ( !pods_is_admin( array( 'pods', 'pods_content', 'pods_add_' . $pod[ 'name' ], 'pods_edit_' . $pod[ 'name' ], 'pods_delete_' . $pod[ 'name' ] ) ) )
|
| 189 |
+
continue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
|
| 191 |
+
if ( 1 == pods_var( 'show_in_menu', $pod[ 'options' ], 0 ) ) {
|
| 192 |
+
$page_title = pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), null, true );
|
| 193 |
+
$page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod );
|
| 194 |
|
| 195 |
+
$menu_label = pods_var_raw( 'menu_name', $pod[ 'options' ], $page_title, null, true );
|
| 196 |
+
$menu_label = apply_filters( 'pods_admin_menu_label', $menu_label, $pod );
|
| 197 |
|
| 198 |
+
$singular_label = pods_var_raw( 'label_singular', $pod[ 'options' ], pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), null, true ), null, true );
|
| 199 |
+
$plural_label = pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), null, true );
|
| 200 |
|
| 201 |
+
$menu_location = pods_var( 'menu_location', $pod[ 'options' ], 'objects' );
|
| 202 |
+
$menu_location_custom = pods_var( 'menu_location_custom', $pod[ 'options' ], '' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
|
| 204 |
+
$menu_position = pods_var_raw( 'menu_position', $pod[ 'options' ], '', null, true );
|
| 205 |
+
$menu_icon = pods_evaluate_tags( pods_var_raw( 'menu_icon', $pod[ 'options' ], '', null, true ), true );
|
| 206 |
|
| 207 |
+
if ( empty( $menu_position ) )
|
| 208 |
+
$menu_position = null;
|
| 209 |
|
| 210 |
+
$parent_page = null;
|
|
|
|
| 211 |
|
| 212 |
+
if ( pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $pod[ 'name' ], 'pods_delete_' . $pod[ 'name' ] ) ) ) {
|
| 213 |
+
if ( !empty( $menu_location_custom ) ) {
|
| 214 |
+
if ( !isset( $submenu_items[ $menu_location_custom ] ) )
|
| 215 |
+
$submenu_items[ $menu_location_custom ] = array();
|
| 216 |
|
| 217 |
+
$submenu_items[ $menu_location_custom ][] = array( $menu_location_custom, $page_title, $menu_label, 'read', 'pods-manage-' . $pod[ 'name' ], array( $this, 'admin_content' ) );
|
|
|
|
|
|
|
| 218 |
|
| 219 |
+
continue;
|
| 220 |
+
}
|
| 221 |
+
else {
|
| 222 |
+
$pods_pages++;
|
| 223 |
|
| 224 |
+
$parent_page = $page = 'pods-manage-' . $pod[ 'name' ];
|
| 225 |
|
| 226 |
+
if ( empty( $menu_position ) )
|
| 227 |
+
$menu_position = null;
|
| 228 |
+
add_menu_page( $page_title, $menu_label, 'read', $parent_page, '', $menu_icon, $menu_position );
|
| 229 |
|
| 230 |
+
$all_title = $plural_label;
|
| 231 |
+
$all_label = __( 'All', 'pods' ) . ' ' . $plural_label;
|
|
|
|
| 232 |
|
| 233 |
+
if ( $page == pods_var( 'page', 'get' ) ) {
|
| 234 |
+
if ( 'edit' == pods_var( 'action', 'get', 'manage' ) )
|
| 235 |
+
$all_title = __( 'Edit', 'pods' ) . ' ' . $singular_label;
|
| 236 |
+
elseif ( 'add' == pods_var( 'action', 'get', 'manage' ) )
|
| 237 |
+
$all_title = __( 'Add New', 'pods' ) . ' ' . $singular_label;
|
| 238 |
+
}
|
| 239 |
|
| 240 |
+
add_submenu_page( $parent_page, $all_title, $all_label, 'read', $page, array( $this, 'admin_content' ) );
|
| 241 |
+
}
|
| 242 |
+
}
|
| 243 |
|
| 244 |
+
if ( pods_is_admin( array( 'pods', 'pods_content', 'pods_add_' . $pod[ 'name' ] ) ) ) {
|
| 245 |
+
$page = 'pods-add-new-' . $pod[ 'name' ];
|
| 246 |
|
| 247 |
+
if ( null === $parent_page ) {
|
| 248 |
+
$pods_pages++;
|
|
|
|
| 249 |
|
| 250 |
+
$parent_page = $page;
|
| 251 |
|
| 252 |
+
if ( empty( $menu_position ) )
|
| 253 |
+
$menu_position = null;
|
| 254 |
+
add_menu_page( $page_title, $menu_label, 'read', $parent_page, '', $menu_icon, $menu_position );
|
| 255 |
+
}
|
| 256 |
|
| 257 |
+
$add_title = __( 'Add New', 'pods' ) . ' ' . $singular_label;
|
| 258 |
+
$add_label = __( 'Add New', 'pods' );
|
| 259 |
|
| 260 |
+
add_submenu_page( $parent_page, $add_title, $add_label, 'read', $page, array( $this, 'admin_content' ) );
|
| 261 |
+
}
|
| 262 |
+
}
|
| 263 |
+
else
|
| 264 |
+
$submenu[] = $pod;
|
| 265 |
+
}
|
| 266 |
|
| 267 |
+
$submenu = apply_filters( 'pods_admin_menu_secondary_content', $submenu );
|
|
|
|
| 268 |
|
| 269 |
+
if ( !empty( $submenu ) && ( !defined( 'PODS_DISABLE_CONTENT_MENU' ) || !PODS_DISABLE_CONTENT_MENU ) ) {
|
| 270 |
+
$parent_page = null;
|
| 271 |
|
| 272 |
+
foreach ( $submenu as $item ) {
|
| 273 |
+
$singular_label = pods_var_raw( 'label_singular', $item[ 'options' ], pods_var_raw( 'label', $item, ucwords( str_replace( '_', ' ', $item[ 'name' ] ) ), null, true ), null, true );
|
| 274 |
+
$plural_label = pods_var_raw( 'label', $item, ucwords( str_replace( '_', ' ', $item[ 'name' ] ) ), null, true );
|
| 275 |
|
| 276 |
+
if ( pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $item[ 'name' ], 'pods_delete_' . $item[ 'name' ] ) ) ) {
|
| 277 |
+
$page = 'pods-manage-' . $item[ 'name' ];
|
| 278 |
|
| 279 |
+
if ( null === $parent_page ) {
|
| 280 |
+
$parent_page = $page;
|
| 281 |
|
| 282 |
+
add_menu_page( 'Pods', 'Pods', 'read', $parent_page, null, 'dashicons-pods', '58.5' );
|
| 283 |
+
}
|
|
|
|
|
|
|
|
|
|
| 284 |
|
| 285 |
+
$all_title = $plural_label;
|
| 286 |
+
$all_label = __( 'Manage', 'pods' ) . ' ' . $plural_label;
|
| 287 |
|
| 288 |
+
if ( $page == pods_var( 'page', 'get' ) ) {
|
| 289 |
+
if ( 'edit' == pods_var( 'action', 'get', 'manage' ) )
|
| 290 |
+
$all_title = __( 'Edit', 'pods' ) . ' ' . $singular_label;
|
| 291 |
+
elseif ( 'add' == pods_var( 'action', 'get', 'manage' ) )
|
| 292 |
+
$all_title = __( 'Add New', 'pods' ) . ' ' . $singular_label;
|
| 293 |
+
}
|
| 294 |
|
| 295 |
+
add_submenu_page( $parent_page, $all_title, $all_label, 'read', $page, array( $this, 'admin_content' ) );
|
| 296 |
+
}
|
| 297 |
+
elseif ( current_user_can( 'pods_add_' . $item[ 'name' ] ) ) {
|
| 298 |
+
$page = 'pods-add-new-' . $item[ 'name' ];
|
| 299 |
+
|
| 300 |
+
if ( null === $parent_page ) {
|
| 301 |
+
$parent_page = $page;
|
| 302 |
+
|
| 303 |
+
add_menu_page( 'Pods', 'Pods', 'read', $parent_page, null, 'dashicons-pods', '58.5' );
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
$add_title = __( 'Add New', 'pods' ) . ' ' . $singular_label;
|
| 307 |
+
$add_label = __( 'Manage', 'pods' ) . ' ' . $plural_label;
|
| 308 |
+
|
| 309 |
+
add_submenu_page( $parent_page, $add_title, $add_label, 'read', $page, array( $this, 'admin_content' ) );
|
| 310 |
+
}
|
| 311 |
+
}
|
| 312 |
+
}
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
if ( !empty( $taxonomies ) ) {
|
| 316 |
+
foreach ( (array) $taxonomies as $pod ) {
|
| 317 |
+
if ( !pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $pod[ 'name' ] ) ) )
|
| 318 |
+
continue;
|
| 319 |
+
|
| 320 |
+
$page_title = pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), null, true );
|
| 321 |
+
$page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod );
|
| 322 |
+
|
| 323 |
+
$menu_label = pods_var_raw( 'menu_name', $pod[ 'options' ], $page_title, null, true );
|
| 324 |
+
$menu_label = apply_filters( 'pods_admin_menu_label', $menu_label, $pod );
|
| 325 |
+
|
| 326 |
+
$menu_position = pods_var_raw( 'menu_position', $pod[ 'options' ], '', null, true );
|
| 327 |
+
$menu_icon = pods_evaluate_tags( pods_var_raw( 'menu_icon', $pod[ 'options' ], '', null, true ), true );
|
| 328 |
+
|
| 329 |
+
if ( empty( $menu_position ) )
|
| 330 |
+
$menu_position = null;
|
| 331 |
+
|
| 332 |
+
$menu_slug = 'edit-tags.php?taxonomy=' . $pod[ 'name' ];
|
| 333 |
+
$menu_location = pods_var( 'menu_location', $pod[ 'options' ], 'default' );
|
| 334 |
+
$menu_location_custom = pods_var( 'menu_location_custom', $pod[ 'options' ], '' );
|
| 335 |
+
|
| 336 |
+
if ( 'default' == $menu_location )
|
| 337 |
+
continue;
|
| 338 |
+
|
| 339 |
+
$taxonomy_data = get_taxonomy( $pod[ 'name' ] );
|
| 340 |
+
|
| 341 |
+
foreach ( (array) $taxonomy_data->object_type as $post_type ) {
|
| 342 |
+
if ( 'post' == $post_type )
|
| 343 |
+
remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=' . $pod[ 'name' ] );
|
| 344 |
+
elseif ( 'attachment' == $post_type )
|
| 345 |
+
remove_submenu_page( 'upload.php', 'edit-tags.php?taxonomy=' . $pod[ 'name' ] . '&post_type=' . $post_type );
|
| 346 |
+
else
|
| 347 |
+
remove_submenu_page( 'edit.php?post_type=' . $post_type, 'edit-tags.php?taxonomy=' . $pod[ 'name' ] . '&post_type=' . $post_type );
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
if ( 'settings' == $menu_location )
|
| 351 |
+
add_options_page( $page_title, $menu_label, 'read', $menu_slug );
|
| 352 |
+
elseif ( 'appearances' == $menu_location )
|
| 353 |
+
add_theme_page( $page_title, $menu_label, 'read', $menu_slug );
|
| 354 |
+
elseif ( 'objects' == $menu_location ) {
|
| 355 |
+
if ( empty( $menu_position ) )
|
| 356 |
+
$menu_position = null;
|
| 357 |
+
add_menu_page( $page_title, $menu_label, 'read', $menu_slug, '', $menu_icon, $menu_position );
|
| 358 |
+
}
|
| 359 |
+
elseif ( 'top' == $menu_location )
|
| 360 |
+
add_menu_page( $page_title, $menu_label, 'read', $menu_slug, '', $menu_icon, $menu_position );
|
| 361 |
+
elseif ( 'submenu' == $menu_location && !empty( $menu_location_custom ) ) {
|
| 362 |
+
if ( !isset( $submenu_items[ $menu_location_custom ] ) )
|
| 363 |
+
$submenu_items[ $menu_location_custom ] = array();
|
| 364 |
+
|
| 365 |
+
$submenu_items[ $menu_location_custom ][] = array( $menu_location_custom, $page_title, $menu_label, 'read', $menu_slug, '' );
|
| 366 |
+
}
|
| 367 |
+
}
|
| 368 |
+
}
|
| 369 |
+
|
| 370 |
+
if ( !empty( $settings ) ) {
|
| 371 |
+
foreach ( (array) $settings as $pod ) {
|
| 372 |
+
if ( !pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $pod[ 'name' ] ) ) )
|
| 373 |
+
continue;
|
| 374 |
+
|
| 375 |
+
$page_title = pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), null, true );
|
| 376 |
+
$page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod );
|
| 377 |
+
|
| 378 |
+
$menu_label = pods_var_raw( 'menu_name', $pod[ 'options' ], $page_title, null, true );
|
| 379 |
+
$menu_label = apply_filters( 'pods_admin_menu_label', $menu_label, $pod );
|
| 380 |
+
|
| 381 |
+
$menu_position = pods_var_raw( 'menu_position', $pod[ 'options' ], '', null, true );
|
| 382 |
+
$menu_icon = pods_evaluate_tags( pods_var_raw( 'menu_icon', $pod[ 'options' ], '', null, true ), true );
|
| 383 |
+
|
| 384 |
+
if ( empty( $menu_position ) )
|
| 385 |
+
$menu_position = null;
|
| 386 |
+
|
| 387 |
+
$menu_slug = 'pods-settings-' . $pod[ 'name' ];
|
| 388 |
+
$menu_location = pods_var( 'menu_location', $pod[ 'options' ], 'settings' );
|
| 389 |
+
$menu_location_custom = pods_var( 'menu_location_custom', $pod[ 'options' ], '' );
|
| 390 |
+
|
| 391 |
+
if ( 'settings' == $menu_location )
|
| 392 |
+
add_options_page( $page_title, $menu_label, 'read', $menu_slug, array( $this, 'admin_content_settings' ) );
|
| 393 |
+
elseif ( 'appearances' == $menu_location )
|
| 394 |
+
add_theme_page( $page_title, $menu_label, 'read', $menu_slug, array( $this, 'admin_content_settings' ) );
|
| 395 |
+
elseif ( 'objects' == $menu_location ) {
|
| 396 |
+
if ( empty( $menu_position ) )
|
| 397 |
+
$menu_position = null;
|
| 398 |
+
add_menu_page( $page_title, $menu_label, 'read', $menu_slug, array( $this, 'admin_content_settings' ), $menu_icon, $menu_position );
|
| 399 |
+
}
|
| 400 |
+
elseif ( 'top' == $menu_location )
|
| 401 |
+
add_menu_page( $page_title, $menu_label, 'read', $menu_slug, array( $this, 'admin_content_settings' ), $menu_icon, $menu_position );
|
| 402 |
+
elseif ( 'submenu' == $menu_location && !empty( $menu_location_custom ) ) {
|
| 403 |
+
if ( !isset( $submenu_items[ $menu_location_custom ] ) )
|
| 404 |
+
$submenu_items[ $menu_location_custom ] = array();
|
| 405 |
+
|
| 406 |
+
$submenu_items[ $menu_location_custom ][] = array( $menu_location_custom, $page_title, $menu_label, 'read', $menu_slug, array( $this, 'admin_content_settings' ) );
|
| 407 |
+
}
|
| 408 |
+
}
|
| 409 |
+
}
|
| 410 |
+
|
| 411 |
+
foreach ( $submenu_items as $items ) {
|
| 412 |
+
foreach ( $items as $item ) {
|
| 413 |
+
call_user_func_array( 'add_submenu_page', $item );
|
| 414 |
+
}
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
$admin_menus = array(
|
| 418 |
+
'pods' => array(
|
| 419 |
+
'label' => __( 'Edit Pods', 'pods' ),
|
| 420 |
+
'function' => array( $this, 'admin_setup' ),
|
| 421 |
+
'access' => 'pods'
|
| 422 |
+
),
|
| 423 |
+
'pods-add-new' => array(
|
| 424 |
+
'label' => __( 'Add New', 'pods' ),
|
| 425 |
+
'function' => array( $this, 'admin_setup' ),
|
| 426 |
+
'access' => 'pods'
|
| 427 |
+
),
|
| 428 |
+
'pods-components' => array(
|
| 429 |
+
'label' => __( 'Components', 'pods' ),
|
| 430 |
+
'function' => array( $this, 'admin_components' ),
|
| 431 |
+
'access' => 'pods_components'
|
| 432 |
+
),
|
| 433 |
+
'pods-settings' => array(
|
| 434 |
+
'label' => __( 'Settings', 'pods' ),
|
| 435 |
+
'function' => array( $this, 'admin_settings' ),
|
| 436 |
+
'access' => 'pods_settings'
|
| 437 |
+
),
|
| 438 |
+
'pods-help' => array(
|
| 439 |
+
'label' => __( 'Help', 'pods' ),
|
| 440 |
+
'function' => array( $this, 'admin_help' )
|
| 441 |
+
)
|
| 442 |
+
);
|
| 443 |
+
|
| 444 |
+
if ( empty( $all_pods ) )
|
| 445 |
+
unset( $admin_menus[ 'pods' ] );
|
| 446 |
+
|
| 447 |
+
add_filter( 'parent_file' , array( $this, 'parent_file' ) );
|
| 448 |
+
}
|
| 449 |
+
else {
|
| 450 |
+
$admin_menus = array(
|
| 451 |
+
'pods-upgrade' => array(
|
| 452 |
+
'label' => __( 'Upgrade', 'pods' ),
|
| 453 |
+
'function' => array( $this, 'admin_upgrade' ),
|
| 454 |
+
'access' => 'manage_options'
|
| 455 |
+
),
|
| 456 |
+
'pods-settings' => array(
|
| 457 |
+
'label' => __( 'Settings', 'pods' ),
|
| 458 |
+
'function' => array( $this, 'admin_settings' ),
|
| 459 |
+
'access' => 'pods_settings'
|
| 460 |
+
),
|
| 461 |
+
'pods-help' => array(
|
| 462 |
+
'label' => __( 'Help', 'pods' ),
|
| 463 |
+
'function' => array( $this, 'admin_help' )
|
| 464 |
+
)
|
| 465 |
+
);
|
| 466 |
+
|
| 467 |
+
add_action( 'admin_notices', array( $this, 'upgrade_notice' ) );
|
| 468 |
+
}
|
| 469 |
|
| 470 |
+
/**
|
| 471 |
+
* Add or change Pods Admin menu items
|
| 472 |
+
*
|
| 473 |
+
* @params array $admin_menus The submenu items in Pods Admin menu.
|
| 474 |
+
*
|
| 475 |
+
* @since unknown
|
| 476 |
+
*/
|
| 477 |
+
$admin_menus = apply_filters( 'pods_admin_menu', $admin_menus );
|
|
|
|
| 478 |
|
| 479 |
+
$parent = false;
|
| 480 |
+
|
| 481 |
+
if ( !empty( $admin_menus ) && ( !defined( 'PODS_DISABLE_ADMIN_MENU' ) || !PODS_DISABLE_ADMIN_MENU ) ) {
|
| 482 |
+
foreach ( $admin_menus as $page => $menu_item ) {
|
| 483 |
+
if ( !pods_is_admin( pods_var_raw( 'access', $menu_item ) ) )
|
| 484 |
+
continue;
|
| 485 |
+
|
| 486 |
+
// Don't just show the help page
|
| 487 |
+
if ( false === $parent && 'pods-help' == $page )
|
| 488 |
+
continue;
|
| 489 |
+
|
| 490 |
+
if ( !isset( $menu_item[ 'label' ] ) )
|
| 491 |
+
$menu_item[ 'label' ] = $page;
|
| 492 |
+
|
| 493 |
+
if ( false === $parent ) {
|
| 494 |
+
$parent = $page;
|
| 495 |
+
|
| 496 |
+
$menu = __( 'Pods Admin', 'pods' );
|
| 497 |
+
|
| 498 |
+
if ( 'pods-upgrade' == $parent )
|
| 499 |
+
$menu = __( 'Pods Upgrade', 'pods' );
|
| 500 |
+
|
| 501 |
+
add_menu_page( $menu, $menu, 'read', $parent, null, 'dashicons-pods' );
|
| 502 |
+
}
|
| 503 |
+
|
| 504 |
+
add_submenu_page( $parent, $menu_item[ 'label' ], $menu_item[ 'label' ], 'read', $page, $menu_item[ 'function' ] );
|
| 505 |
+
|
| 506 |
+
if ( 'pods-components' == $page )
|
| 507 |
+
PodsInit::$components->menu( $parent );
|
| 508 |
+
}
|
| 509 |
+
}
|
| 510 |
+
}
|
| 511 |
+
|
| 512 |
+
/**
|
| 513 |
+
* Set the correct parent_file to highlight the correct top level menu
|
| 514 |
+
*
|
| 515 |
+
* @param $parent_file The parent file
|
| 516 |
+
*
|
| 517 |
+
* @return mixed|string
|
| 518 |
+
*
|
| 519 |
+
* @since unknown
|
| 520 |
+
*/
|
| 521 |
+
public function parent_file ( $parent_file ) {
|
| 522 |
+
global $current_screen;
|
| 523 |
+
|
| 524 |
+
if ( isset( $current_screen ) && ! empty( $current_screen->taxonomy ) ) {
|
| 525 |
+
$taxonomies = PodsMeta::$taxonomies;
|
| 526 |
+
if ( !empty( $taxonomies ) ) {
|
| 527 |
+
foreach ( (array) $taxonomies as $pod ) {
|
| 528 |
+
if ( $current_screen->taxonomy !== $pod[ 'name' ] )
|
| 529 |
+
continue;
|
| 530 |
+
|
| 531 |
+
$menu_slug = 'edit-tags.php?taxonomy=' . $pod[ 'name' ];
|
| 532 |
+
$menu_location = pods_var( 'menu_location', $pod[ 'options' ], 'default' );
|
| 533 |
+
$menu_location_custom = pods_var( 'menu_location_custom', $pod[ 'options' ], '' );
|
| 534 |
+
|
| 535 |
+
if ( 'settings' == $menu_location )
|
| 536 |
+
$parent_file = 'options-general.php';
|
| 537 |
+
elseif ( 'appearances' == $menu_location )
|
| 538 |
+
$parent_file = 'themes.php';
|
| 539 |
+
elseif ( 'objects' == $menu_location )
|
| 540 |
+
$parent_file = $menu_slug;
|
| 541 |
+
elseif ( 'top' == $menu_location )
|
| 542 |
+
$parent_file = $menu_slug;
|
| 543 |
+
elseif ( 'submenu' == $menu_location && !empty( $menu_location_custom ) ) {
|
| 544 |
+
$parent_file = $menu_location_custom;
|
| 545 |
+
}
|
| 546 |
+
|
| 547 |
+
break;
|
| 548 |
+
}
|
| 549 |
+
}
|
| 550 |
+
}
|
| 551 |
+
|
| 552 |
+
if ( isset( $current_screen ) && ! empty( $current_screen->post_type ) ) {
|
| 553 |
+
global $submenu_file;
|
| 554 |
+
$components = PodsInit::$components->components;
|
| 555 |
+
foreach ( $components as $component => $component_data ) {
|
| 556 |
+
if ( ! empty( $component_data[ 'MenuPage' ] ) && $parent_file === $component_data[ 'MenuPage' ] ) {
|
| 557 |
+
$parent_file = 'pods';
|
| 558 |
+
$submenu_file = $component_data[ 'MenuPage' ];
|
| 559 |
+
}
|
| 560 |
+
}
|
| 561 |
+
}
|
| 562 |
+
|
| 563 |
+
return $parent_file;
|
| 564 |
+
}
|
| 565 |
+
|
| 566 |
+
public function upgrade_notice () {
|
| 567 |
+
echo '<div class="error fade"><p>';
|
| 568 |
+
echo sprintf(
|
| 569 |
+
__( '<strong>NOTICE:</strong> Pods %s requires your action to complete the upgrade. Please run the <a href="%s">Upgrade Wizard</a>.', 'pods' ),
|
| 570 |
+
esc_html( PODS_VERSION ),
|
| 571 |
+
esc_url( admin_url( 'admin.php?page=pods-upgrade' ) )
|
| 572 |
+
);
|
| 573 |
+
echo '</p></div>';
|
| 574 |
+
}
|
| 575 |
+
|
| 576 |
+
/**
|
| 577 |
+
* Create PodsUI content for the administration pages
|
| 578 |
+
*/
|
| 579 |
+
public function admin_content () {
|
| 580 |
+
$pod_name = str_replace( array( 'pods-manage-', 'pods-add-new-' ), '', $_GET[ 'page' ] );
|
| 581 |
+
|
| 582 |
+
$pod = pods( $pod_name, pods_var( 'id', 'get', null, null, true ) );
|
| 583 |
+
|
| 584 |
+
if ( false !== strpos( $_GET[ 'page' ], 'pods-add-new-' ) )
|
| 585 |
+
$_GET[ 'action' ] = pods_var( 'action', 'get', 'add' );
|
| 586 |
+
|
| 587 |
+
$pod->ui();
|
| 588 |
+
}
|
| 589 |
+
|
| 590 |
+
/**
|
| 591 |
+
* Create PodsUI content for the settings administration pages
|
| 592 |
+
*/
|
| 593 |
+
public function admin_content_settings () {
|
| 594 |
+
$pod_name = str_replace( 'pods-settings-', '', $_GET[ 'page' ] );
|
| 595 |
+
|
| 596 |
+
$pod = pods( $pod_name );
|
| 597 |
+
|
| 598 |
+
if ( 'custom' != pods_var( 'ui_style', $pod->pod_data[ 'options' ], 'settings', null, true ) ) {
|
| 599 |
+
$actions_disabled = array(
|
| 600 |
+
'manage' => 'manage',
|
| 601 |
+
'add' => 'add',
|
| 602 |
+
'delete' => 'delete',
|
| 603 |
+
'duplicate' => 'duplicate',
|
| 604 |
+
'view' => 'view',
|
| 605 |
+
'export' => 'export'
|
| 606 |
+
);
|
| 607 |
+
|
| 608 |
+
$_GET[ 'action' ] = 'edit';
|
| 609 |
+
|
| 610 |
+
$page_title = pods_var_raw( 'label', $pod->pod_data, ucwords( str_replace( '_', ' ', $pod->pod_data[ 'name' ] ) ), null, true );
|
| 611 |
+
|
| 612 |
+
$ui = array(
|
| 613 |
+
'pod' => $pod,
|
| 614 |
+
'fields' => array(
|
| 615 |
+
'edit' => $pod->pod_data[ 'fields' ]
|
| 616 |
+
),
|
| 617 |
+
'header' => array(
|
| 618 |
+
'edit' => $page_title
|
| 619 |
+
),
|
| 620 |
+
'label' => array(
|
| 621 |
+
'edit' => __( 'Save Changes', 'pods' )
|
| 622 |
+
),
|
| 623 |
+
'style' => pods_var( 'ui_style', $pod->pod_data[ 'options' ], 'settings', null, true ),
|
| 624 |
+
'icon' => pods_evaluate_tags( pods_var_raw( 'menu_icon', $pod->pod_data[ 'options' ] ), true ),
|
| 625 |
+
'actions_disabled' => $actions_disabled
|
| 626 |
+
);
|
| 627 |
+
|
| 628 |
+
$ui = apply_filters( 'pods_admin_ui_' . $pod->pod, apply_filters( 'pods_admin_ui', $ui, $pod->pod, $pod ), $pod->pod, $pod );
|
| 629 |
+
|
| 630 |
+
// Force disabled actions, do not pass go, do not collect $two_hundred
|
| 631 |
+
$ui[ 'actions_disabled' ] = $actions_disabled;
|
| 632 |
+
|
| 633 |
+
pods_ui( $ui );
|
| 634 |
+
}
|
| 635 |
+
else {
|
| 636 |
+
do_action( 'pods_admin_ui_custom', $pod );
|
| 637 |
+
do_action( 'pods_admin_ui_custom_' . $pod->pod, $pod );
|
| 638 |
+
}
|
| 639 |
+
}
|
| 640 |
+
|
| 641 |
+
/**
|
| 642 |
+
* Add media button for Pods shortcode
|
| 643 |
+
*
|
| 644 |
+
* @param $context
|
| 645 |
+
*
|
| 646 |
+
* @return string
|
| 647 |
+
*/
|
| 648 |
+
public function media_button ( $context = null ) {
|
| 649 |
+
// If shortcodes are disabled don't show the button
|
| 650 |
+
if ( defined( 'PODS_DISABLE_SHORTCODE' ) && PODS_DISABLE_SHORTCODE ) {
|
| 651 |
+
return '';
|
| 652 |
+
}
|
| 653 |
|
| 654 |
+
/**
|
| 655 |
+
* Filter to remove Pods shortcode button from the post editor.
|
| 656 |
+
*
|
| 657 |
+
* @param bool. Set to false to block the shortcode button from appearing.
|
| 658 |
+
* @param string $context
|
| 659 |
+
*
|
| 660 |
+
* @since 2.3.19
|
| 661 |
+
*/
|
| 662 |
+
if ( !apply_filters( 'pods_admin_media_button', true, $context ) ) {
|
| 663 |
+
return '';
|
| 664 |
+
}
|
| 665 |
|
| 666 |
+
$current_page = basename( $_SERVER[ 'PHP_SELF' ] );
|
| 667 |
+
$current_page = explode( '?', $current_page );
|
| 668 |
+
$current_page = explode( '#', $current_page[ 0 ] );
|
| 669 |
+
$current_page = $current_page[ 0 ];
|
| 670 |
+
|
| 671 |
+
// Only show the button on post type pages
|
| 672 |
+
if ( !in_array( $current_page, array( 'post-new.php', 'post.php' ) ) )
|
| 673 |
+
return '';
|
| 674 |
+
|
| 675 |
+
add_action( 'admin_footer', array( $this, 'mce_popup' ) );
|
| 676 |
+
|
| 677 |
+
echo '<a href="#TB_inline?width=640&inlineId=pods_shortcode_form" class="thickbox button" id="add_pod_button" title="Pods Shortcode"><img style="padding: 0px 6px 0px 0px; margin: -3px 0px 0px;" src="' . PODS_URL . 'ui/images/icon16.png" alt="' . __('Pods Shortcode' ,'pods') . '" />' . __('Pods Shortcode' ,'pods') . '</a>';
|
| 678 |
+
}
|
| 679 |
+
|
| 680 |
+
/**
|
| 681 |
+
* Enqueue assets for Media Library Popup
|
| 682 |
+
*/
|
| 683 |
+
public function register_media_assets () {
|
| 684 |
+
if ( 'pods_media_attachment' == pods_var( 'inlineId', 'get' ) )
|
| 685 |
+
wp_enqueue_style( 'pods-attach' );
|
| 686 |
+
}
|
| 687 |
+
|
| 688 |
+
/**
|
| 689 |
+
* Output Pods shortcode popup window
|
| 690 |
+
*/
|
| 691 |
+
public function mce_popup () {
|
| 692 |
+
pods_view( PODS_DIR . 'ui/admin/shortcode.php', compact( array_keys( get_defined_vars() ) ) );
|
| 693 |
+
}
|
| 694 |
+
|
| 695 |
+
/**
|
| 696 |
+
* Handle main Pods Setup area for managing Pods and Fields
|
| 697 |
+
*/
|
| 698 |
+
public function admin_setup () {
|
| 699 |
+
$pods = pods_api()->load_pods( array( 'fields' => false ) );
|
| 700 |
+
|
| 701 |
+
$view = pods_var( 'view', 'get', 'all', null, true );
|
| 702 |
+
|
| 703 |
+
if ( empty( $pods ) && !isset( $_GET[ 'action' ] ) )
|
| 704 |
+
$_GET[ 'action' ] = 'add';
|
| 705 |
+
|
| 706 |
+
if ( 'pods-add-new' == $_GET[ 'page' ] ) {
|
| 707 |
+
if ( isset( $_GET[ 'action' ] ) && 'add' != $_GET[ 'action' ] )
|
| 708 |
+
pods_redirect( pods_query_arg( array( 'page' => 'pods', 'action' => $_GET[ 'action' ] ) ) );
|
| 709 |
+
else
|
| 710 |
+
$_GET[ 'action' ] = 'add';
|
| 711 |
+
}
|
| 712 |
+
elseif ( isset( $_GET[ 'action' ] ) && 'add' == $_GET[ 'action' ] )
|
| 713 |
+
pods_redirect( pods_query_arg( array( 'page' => 'pods-add-new', 'action' => '' ) ) );
|
| 714 |
+
|
| 715 |
+
$types = array(
|
| 716 |
+
'post_type' => __( 'Post Type (extended)', 'pods' ),
|
| 717 |
+
'taxonomy' => __( 'Taxonomy (extended)', 'pods' ),
|
| 718 |
+
'cpt' => __( 'Custom Post Type', 'pods' ),
|
| 719 |
+
'ct' => __( 'Custom Taxonomy', 'pods' ),
|
| 720 |
+
'user' => __( 'User (extended)', 'pods' ),
|
| 721 |
+
'media' => __( 'Media (extended)', 'pods' ),
|
| 722 |
+
'comment' => __( 'Comments (extended)', 'pods' ),
|
| 723 |
+
'pod' => __( 'Advanced Content Type', 'pods' ),
|
| 724 |
+
'settings' => __( 'Custom Settings Page', 'pods' )
|
| 725 |
+
);
|
| 726 |
+
|
| 727 |
+
$row = false;
|
| 728 |
+
|
| 729 |
+
$pod_types_found = array();
|
| 730 |
+
|
| 731 |
+
$fields = array(
|
| 732 |
+
'label' => array( 'label' => __( 'Label', 'pods' ) ),
|
| 733 |
+
'name' => array( 'label' => __( 'Name', 'pods' ) ),
|
| 734 |
+
'type' => array( 'label' => __( 'Type', 'pods' ) ),
|
| 735 |
+
'storage' => array(
|
| 736 |
+
'label' => __( 'Storage Type', 'pods' ),
|
| 737 |
+
'width' => '10%'
|
| 738 |
+
),
|
| 739 |
+
'field_count' => array(
|
| 740 |
+
'label' => __( 'Number of Fields', 'pods' ),
|
| 741 |
+
'width' => '8%'
|
| 742 |
+
)
|
| 743 |
+
);
|
| 744 |
+
|
| 745 |
+
$total_fields = 0;
|
| 746 |
+
|
| 747 |
+
foreach ( $pods as $k => $pod ) {
|
| 748 |
+
if ( isset( $types[ $pod[ 'type' ] ] ) ) {
|
| 749 |
+
if ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) ) {
|
| 750 |
+
if ( empty( $pod[ 'object' ] ) ) {
|
| 751 |
+
if ( 'post_type' == $pod[ 'type' ] )
|
| 752 |
+
$pod[ 'type' ] = 'cpt';
|
| 753 |
+
else
|
| 754 |
+
$pod[ 'type' ] = 'ct';
|
| 755 |
+
}
|
| 756 |
+
}
|
| 757 |
+
|
| 758 |
+
if ( !isset( $pod_types_found[ $pod[ 'type' ] ] ) )
|
| 759 |
+
$pod_types_found[ $pod[ 'type' ] ] = 1;
|
| 760 |
+
else
|
| 761 |
+
$pod_types_found[ $pod[ 'type' ] ]++;
|
| 762 |
+
|
| 763 |
+
if ( 'all' != $view && $view != $pod[ 'type' ] ) {
|
| 764 |
+
unset( $pods[ $k ] );
|
| 765 |
+
|
| 766 |
+
continue;
|
| 767 |
+
}
|
| 768 |
+
|
| 769 |
+
$pod[ 'real_type' ] = $pod[ 'type' ];
|
| 770 |
+
$pod[ 'type' ] = $types[ $pod[ 'type' ] ];
|
| 771 |
+
}
|
| 772 |
+
elseif ( 'all' != $view )
|
| 773 |
+
continue;
|
| 774 |
+
|
| 775 |
+
$pod[ 'storage' ] = ucwords( $pod[ 'storage' ] );
|
| 776 |
+
|
| 777 |
+
if ( $pod[ 'id' ] == pods_var( 'id' ) && 'delete' != pods_var( 'action' ) )
|
| 778 |
+
$row = $pod;
|
| 779 |
+
|
| 780 |
+
$pod = array(
|
| 781 |
+
'id' => $pod[ 'id' ],
|
| 782 |
+
'label' => pods_var_raw( 'label', $pod ),
|
| 783 |
+
'name' => pods_var_raw( 'name', $pod ),
|
| 784 |
+
'object' => pods_var_raw( 'object', $pod ),
|
| 785 |
+
'type' => pods_var_raw( 'type', $pod ),
|
| 786 |
+
'real_type' => pods_var_raw( 'real_type', $pod ),
|
| 787 |
+
'storage' => pods_var_raw( 'storage', $pod ),
|
| 788 |
+
'field_count' => count( $pod[ 'fields' ] )
|
| 789 |
+
);
|
| 790 |
+
|
| 791 |
+
$total_fields += $pod[ 'field_count' ];
|
| 792 |
+
|
| 793 |
+
$pods[ $k ] = $pod;
|
| 794 |
+
}
|
| 795 |
+
|
| 796 |
+
if ( false === $row && 0 < pods_var( 'id' ) && 'delete' != pods_var( 'action' ) ) {
|
| 797 |
+
pods_message( 'Pod not found', 'error' );
|
| 798 |
+
|
| 799 |
+
unset( $_GET[ 'id' ] );
|
| 800 |
+
unset( $_GET[ 'action' ] );
|
| 801 |
+
}
|
| 802 |
+
|
| 803 |
+
$ui = array(
|
| 804 |
+
'data' => $pods,
|
| 805 |
+
'row' => $row,
|
| 806 |
+
'total' => count( $pods ),
|
| 807 |
+
'total_found' => count( $pods ),
|
| 808 |
+
'items' => 'Pods',
|
| 809 |
+
'item' => 'Pod',
|
| 810 |
+
'fields' => array(
|
| 811 |
+
'manage' => $fields
|
| 812 |
+
),
|
| 813 |
+
'actions_disabled' => array( 'view', 'export' ),
|
| 814 |
+
'actions_custom' => array(
|
| 815 |
+
'add' => array( $this, 'admin_setup_add' ),
|
| 816 |
+
'edit' => array( $this, 'admin_setup_edit' ),
|
| 817 |
+
'duplicate' => array(
|
| 818 |
+
'callback' => array( $this, 'admin_setup_duplicate' ),
|
| 819 |
+
'restrict_callback' => array( $this, 'admin_setup_duplicate_restrict' )
|
| 820 |
+
),
|
| 821 |
+
'reset' => array(
|
| 822 |
+
'label' => __( 'Delete All Items', 'pods' ),
|
| 823 |
+
'confirm' => __( 'Are you sure you want to delete all items from this Pod? If this is an extended Pod, it will remove the original items extended too.', 'pods' ),
|
| 824 |
+
'callback' => array( $this, 'admin_setup_reset' ),
|
| 825 |
+
'restrict_callback' => array( $this, 'admin_setup_reset_restrict' ),
|
| 826 |
+
'nonce' => true
|
| 827 |
+
),
|
| 828 |
+
'delete' => array( $this, 'admin_setup_delete' )
|
| 829 |
+
),
|
| 830 |
+
'action_links' => array(
|
| 831 |
+
'add' => pods_query_arg( array( 'page' => 'pods-add-new', 'action' => '', 'id' => '', 'do' => '' ) )
|
| 832 |
+
),
|
| 833 |
+
'search' => false,
|
| 834 |
+
'searchable' => false,
|
| 835 |
+
'sortable' => true,
|
| 836 |
+
'pagination' => false,
|
| 837 |
+
'extra' => array(
|
| 838 |
+
'total' => ', ' . number_format_i18n( $total_fields ) . ' ' . _n( 'field', 'fields', $total_fields, 'pods' )
|
| 839 |
+
)
|
| 840 |
+
);
|
| 841 |
+
|
| 842 |
+
if ( 1 < count( $pod_types_found ) ) {
|
| 843 |
+
$ui[ 'views' ] = array( 'all' => __( 'All', 'pods' ) );
|
| 844 |
+
$ui[ 'view' ] = $view;
|
| 845 |
+
$ui[ 'heading' ] = array( 'views' => __( 'Type', 'pods' ) );
|
| 846 |
+
$ui[ 'filters_enhanced' ] = true;
|
| 847 |
+
|
| 848 |
+
foreach ( $pod_types_found as $pod_type => $number_found ) {
|
| 849 |
+
$ui[ 'views' ][ $pod_type ] = $types[ $pod_type ];
|
| 850 |
+
}
|
| 851 |
+
}
|
| 852 |
+
|
| 853 |
+
pods_ui( $ui );
|
| 854 |
+
}
|
| 855 |
+
|
| 856 |
+
/**
|
| 857 |
+
* Get the add page of an object
|
| 858 |
+
*
|
| 859 |
+
* @param $obj
|
| 860 |
+
*/
|
| 861 |
+
public function admin_setup_add ( $obj ) {
|
| 862 |
+
pods_view( PODS_DIR . 'ui/admin/setup-add.php', compact( array_keys( get_defined_vars() ) ) );
|
| 863 |
+
}
|
| 864 |
+
|
| 865 |
+
/**
|
| 866 |
+
* Get the edit page of an object
|
| 867 |
+
*
|
| 868 |
+
* @param $duplicate
|
| 869 |
+
* @param $obj
|
| 870 |
+
*/
|
| 871 |
+
public function admin_setup_edit ( $duplicate, $obj ) {
|
| 872 |
+
pods_view( PODS_DIR . 'ui/admin/setup-edit.php', compact( array_keys( get_defined_vars() ) ) );
|
| 873 |
+
}
|
| 874 |
+
|
| 875 |
+
/**
|
| 876 |
+
* Get list of Pod option tabs
|
| 877 |
+
*
|
| 878 |
+
* @return array
|
| 879 |
+
*/
|
| 880 |
+
public function admin_setup_edit_tabs ( $pod ) {
|
| 881 |
+
$fields = true;
|
| 882 |
+
$labels = false;
|
| 883 |
+
$admin_ui = false;
|
| 884 |
+
$advanced = false;
|
| 885 |
+
|
| 886 |
+
if ( 'post_type' == pods_var( 'type', $pod ) && strlen( pods_var( 'object', $pod ) ) < 1 ) {
|
| 887 |
+
$labels = true;
|
| 888 |
+
$admin_ui = true;
|
| 889 |
+
$advanced = true;
|
| 890 |
+
}
|
| 891 |
+
elseif ( 'taxonomy' == pods_var( 'type', $pod ) && strlen( pods_var( 'object', $pod ) ) < 1 ) {
|
| 892 |
+
$labels = true;
|
| 893 |
+
$admin_ui = true;
|
| 894 |
+
$advanced = true;
|
| 895 |
+
}
|
| 896 |
+
elseif ( 'pod' == pods_var( 'type', $pod ) ) {
|
| 897 |
+
$labels = true;
|
| 898 |
+
$admin_ui = true;
|
| 899 |
+
$advanced = true;
|
| 900 |
+
}
|
| 901 |
+
elseif ( 'settings' == pods_var( 'type', $pod ) ) {
|
| 902 |
+
$labels = true;
|
| 903 |
+
$admin_ui = true;
|
| 904 |
+
}
|
| 905 |
+
|
| 906 |
+
if ( 'none' == pods_var( 'storage', $pod, 'none', null, true ) && 'settings' != pods_var( 'type', $pod ) )
|
| 907 |
+
$fields = false;
|
| 908 |
+
|
| 909 |
+
$tabs = array();
|
| 910 |
+
|
| 911 |
+
if ( $fields )
|
| 912 |
+
$tabs[ 'manage-fields' ] = __( 'Manage Fields', 'pods' );
|
| 913 |
+
|
| 914 |
+
if ( $labels )
|
| 915 |
+
$tabs[ 'labels' ] = __( 'Labels', 'pods' );
|
| 916 |
+
|
| 917 |
+
if ( $admin_ui )
|
| 918 |
+
$tabs[ 'admin-ui' ] = __( 'Admin UI', 'pods' );
|
| 919 |
+
|
| 920 |
+
if ( $advanced )
|
| 921 |
+
$tabs[ 'advanced' ] = __( 'Advanced Options', 'pods' );
|
| 922 |
+
|
| 923 |
+
if ( 'taxonomy' == pods_var( 'type', $pod ) && !$fields )
|
| 924 |
+
$tabs[ 'extra-fields' ] = __( 'Extra Fields', 'pods' );
|
| 925 |
|
| 926 |
+
$addtl_args = compact( array( 'fields', 'labels', 'admin_ui', 'advanced' ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 927 |
|
| 928 |
+
/**
|
| 929 |
+
* Add or modify tabs in Pods editor for a specific Pod
|
| 930 |
+
*
|
| 931 |
+
* @params array $tabs Tabs to set.
|
| 932 |
+
* @params object $pod Current Pods object
|
| 933 |
+
* @params array $addtl_args Additional args.
|
| 934 |
+
*
|
| 935 |
+
* @since unknown
|
| 936 |
+
*/
|
| 937 |
+
$tabs = apply_filters( 'pods_admin_setup_edit_tabs_' . $pod[ 'type' ] . '_' . $pod[ 'name' ], $tabs, $pod, $addtl_args );
|
| 938 |
|
| 939 |
+
/**
|
| 940 |
+
* Add or modify tabs for any Pod in Pods editor of a specific post type.
|
| 941 |
+
*/
|
| 942 |
+
$tabs = apply_filters( 'pods_admin_setup_edit_tabs_' . $pod[ 'type' ], $tabs, $pod, $addtl_args );
|
| 943 |
|
| 944 |
+
/**
|
| 945 |
+
* Add or modify tabs in Pods editor for all pods.
|
| 946 |
+
*/
|
| 947 |
+
$tabs = apply_filters( 'pods_admin_setup_edit_tabs', $tabs, $pod, $addtl_args );
|
| 948 |
|
| 949 |
+
return $tabs;
|
| 950 |
+
}
|
| 951 |
+
|
| 952 |
+
/**
|
| 953 |
+
* Get list of Pod options
|
| 954 |
+
*
|
| 955 |
+
* @return array
|
| 956 |
+
*/
|
| 957 |
+
public function admin_setup_edit_options ( $pod ) {
|
| 958 |
+
$options = array();
|
| 959 |
+
|
| 960 |
+
// @todo fill this in
|
| 961 |
+
$options[ 'labels' ] = array(
|
| 962 |
+
'temporary' => 'This has the fields hardcoded' // :(
|
| 963 |
+
);
|
| 964 |
+
|
| 965 |
+
if ( 'post_type' == $pod[ 'type' ] ) {
|
| 966 |
+
$options[ 'admin-ui' ] = array(
|
| 967 |
+
'description' => array(
|
| 968 |
+
'label' => __( 'Post Type Description', 'pods' ),
|
| 969 |
+
'help' => __( 'A short descriptive summary of what the post type is.', 'pods' ),
|
| 970 |
+
'type' => 'text',
|
| 971 |
+
'default' => ''
|
| 972 |
+
),
|
| 973 |
+
'show_ui' => array(
|
| 974 |
+
'label' => __( 'Show Admin UI', 'pods' ),
|
| 975 |
+
'help' => __( 'help', 'pods' ),
|
| 976 |
+
'type' => 'boolean',
|
| 977 |
+
'default' => pods_var_raw( 'public', $pod, true ),
|
| 978 |
+
'boolean_yes_label' => ''
|
| 979 |
+
),
|
| 980 |
+
'show_in_menu' => array(
|
| 981 |
+
'label' => __( 'Show Admin Menu in Dashboard', 'pods' ),
|
| 982 |
+
'help' => __( 'help', 'pods' ),
|
| 983 |
+
'type' => 'boolean',
|
| 984 |
+
'default' => pods_var_raw( 'public', $pod, true ),
|
| 985 |
+
'dependency' => true,
|
| 986 |
+
'boolean_yes_label' => ''
|
| 987 |
+
),
|
| 988 |
+
'menu_location_custom' => array(
|
| 989 |
+
'label' => __( 'Parent Menu ID (optional)', 'pods' ),
|
| 990 |
+
'help' => __( 'help', 'pods' ),
|
| 991 |
+
'type' => 'text',
|
| 992 |
+
'depends-on' => array( 'show_in_menu' => true )
|
| 993 |
+
),
|
| 994 |
+
'menu_name' => array(
|
| 995 |
+
'label' => __( 'Menu Name', 'pods' ),
|
| 996 |
+
'help' => __( 'help', 'pods' ),
|
| 997 |
+
'type' => 'text',
|
| 998 |
+
'default' => '',
|
| 999 |
+
'depends-on' => array( 'show_in_menu' => true )
|
| 1000 |
+
),
|
| 1001 |
+
'menu_position' => array(
|
| 1002 |
+
'label' => __( 'Menu Position', 'pods' ),
|
| 1003 |
+
'help' => __( 'help', 'pods' ),
|
| 1004 |
+
'type' => 'number',
|
| 1005 |
+
'default' => 0,
|
| 1006 |
+
'depends-on' => array( 'show_in_menu' => true )
|
| 1007 |
+
),
|
| 1008 |
+
'menu_icon' => array(
|
| 1009 |
+
'label' => __( 'Menu Icon', 'pods' ),
|
| 1010 |
+
'help' => __( 'URL or Dashicon name for the menu icon. You may specify the path to the icon using one of the <a href="http://pods.io/docs/build/special-magic-tags/#site-tags" target="_blank">site tag</a> type <a href="http://pods.io/docs/build/special-magic-tags/" target="_blank">special magic tags</a>. For example, for a file in your theme directory, use "{@template-url}/path/to/image.png". You may also use the name of a <a href="http://melchoyce.github.io/dashicons/" target="_blank">Dashicon</a>. For example, to use the empty star icon, use "dashicons-star-empty".', 'pods' ),
|
| 1011 |
+
'type' => 'text',
|
| 1012 |
+
'default' => '',
|
| 1013 |
+
'depends-on' => array( 'show_in_menu' => true )
|
| 1014 |
+
),
|
| 1015 |
+
'show_in_nav_menus' => array(
|
| 1016 |
+
'label' => __( 'Show in Navigation Menus', 'pods' ),
|
| 1017 |
+
'help' => __( 'help', 'pods' ),
|
| 1018 |
+
'type' => 'boolean',
|
| 1019 |
+
'default' => true,
|
| 1020 |
+
'boolean_yes_label' => ''
|
| 1021 |
+
),
|
| 1022 |
+
'show_in_admin_bar' => array(
|
| 1023 |
+
'label' => __( 'Show in Admin Bar "New" Menu', 'pods' ),
|
| 1024 |
+
'help' => __( 'help', 'pods' ),
|
| 1025 |
+
'type' => 'boolean',
|
| 1026 |
+
'default' => true,
|
| 1027 |
+
'boolean_yes_label' => ''
|
| 1028 |
+
)
|
| 1029 |
+
);
|
| 1030 |
+
|
| 1031 |
+
$options[ 'advanced' ] = array(
|
| 1032 |
+
'public' => array(
|
| 1033 |
+
'label' => __( 'Public', 'pods' ),
|
| 1034 |
+
'help' => __( 'help', 'pods' ),
|
| 1035 |
+
'type' => 'boolean',
|
| 1036 |
+
'default' => true,
|
| 1037 |
+
'boolean_yes_label' => ''
|
| 1038 |
+
),
|
| 1039 |
+
'publicly_queryable' => array(
|
| 1040 |
+
'label' => __( 'Publicly Queryable', 'pods' ),
|
| 1041 |
+
'help' => __( 'help', 'pods' ),
|
| 1042 |
+
'type' => 'boolean',
|
| 1043 |
+
'default' => pods_var_raw( 'public', $pod, true ),
|
| 1044 |
+
'boolean_yes_label' => ''
|
| 1045 |
+
),
|
| 1046 |
+
'exclude_from_search' => array(
|
| 1047 |
+
'label' => __( 'Exclude from Search', 'pods' ),
|
| 1048 |
+
'help' => __( 'help', 'pods' ),
|
| 1049 |
+
'type' => 'boolean',
|
| 1050 |
+
'default' => !pods_var_raw( 'public', $pod, true ),
|
| 1051 |
+
'boolean_yes_label' => ''
|
| 1052 |
+
),
|
| 1053 |
+
'capability_type' => array(
|
| 1054 |
+
'label' => __( 'User Capability', 'pods' ),
|
| 1055 |
+
'help' => __( 'Uses these capabilties for access to this post type: edit_{capability}, read_{capability}, and delete_{capability}', 'pods' ),
|
| 1056 |
+
'type' => 'pick',
|
| 1057 |
+
'default' => 'post',
|
| 1058 |
+
'data' => array(
|
| 1059 |
+
'post' => 'post',
|
| 1060 |
+
'page' => 'page',
|
| 1061 |
+
'custom' => __( 'Custom Capability', 'pods' )
|
| 1062 |
+
),
|
| 1063 |
+
'dependency' => true
|
| 1064 |
+
),
|
| 1065 |
+
'capability_type_custom' => array(
|
| 1066 |
+
'label' => __( 'Custom User Capability', 'pods' ),
|
| 1067 |
+
'help' => __( 'help', 'pods' ),
|
| 1068 |
+
'type' => 'text',
|
| 1069 |
+
'default' => pods_var_raw( 'name', $pod ),
|
| 1070 |
+
'depends-on' => array( 'capability_type' => 'custom' )
|
| 1071 |
+
),
|
| 1072 |
+
'capability_type_extra' => array(
|
| 1073 |
+
'label' => __( 'Additional User Capabilities', 'pods' ),
|
| 1074 |
+
'help' => __( 'Enables additional capabilities for this Post Type including: delete_{capability}s, delete_private_{capability}s, delete_published_{capability}s, delete_others_{capability}s, edit_private_{capability}s, and edit_published_{capability}s', 'pods' ),
|
| 1075 |
+
'type' => 'boolean',
|
| 1076 |
+
'default' => true,
|
| 1077 |
+
'boolean_yes_label' => ''
|
| 1078 |
+
),
|
| 1079 |
+
'has_archive' => array(
|
| 1080 |
+
'label' => __( 'Enable Archive Page', 'pods' ),
|
| 1081 |
+
'help' => __( 'If enabled, creates an archive page with list of of items in this custom post type. Functions like a category page for posts. Can be controlled with a template in your theme called "archive-{$post-type}.php".', 'pods' ),
|
| 1082 |
+
'type' => 'boolean',
|
| 1083 |
+
'default' => false,
|
| 1084 |
+
'dependency' => true,
|
| 1085 |
+
'boolean_yes_label' => ''
|
| 1086 |
+
),
|
| 1087 |
+
'has_archive_slug' => array(
|
| 1088 |
+
'label' => __( 'Archive Page Slug Override', 'pods' ),
|
| 1089 |
+
'help' => __( 'If archive page is enabled, you can override the slug used by WordPress, which defaults to the name of the post type.', 'pods' ),
|
| 1090 |
+
'type' => 'text',
|
| 1091 |
+
'default' => '',
|
| 1092 |
+
'depends-on' => array( 'has_archive' => true )
|
| 1093 |
+
),
|
| 1094 |
+
'hierarchical' => array(
|
| 1095 |
+
'label' => __( 'Hierarchical', 'pods' ),
|
| 1096 |
+
'help' => __( 'Allows for parent/ child relationships between items, just like with Pages. Note: To edit relationships in the post editor, you must enable "Page Attributes" in the "Supports" section below.', 'pods' ),
|
| 1097 |
+
'type' => 'boolean',
|
| 1098 |
+
'default' => false,
|
| 1099 |
+
'dependency' => true,
|
| 1100 |
+
'boolean_yes_label' => ''
|
| 1101 |
+
),
|
| 1102 |
+
'label_parent_item_colon' => array(
|
| 1103 |
+
'label' => __( '<strong>Label: </strong> Parent <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),
|
| 1104 |
+
'help' => __( 'help', 'pods' ),
|
| 1105 |
+
'type' => 'text',
|
| 1106 |
+
'default' => '',
|
| 1107 |
+
'depends-on' => array( 'hierarchical' => true )
|
| 1108 |
+
),
|
| 1109 |
+
'label_parent' => array(
|
| 1110 |
+
'label' => __( '<strong>Label: </strong> Parent', 'pods' ),
|
| 1111 |
+
'help' => __( 'help', 'pods' ),
|
| 1112 |
+
'type' => 'text',
|
| 1113 |
+
'default' => '',
|
| 1114 |
+
'depends-on' => array( 'hierarchical' => true )
|
| 1115 |
+
),
|
| 1116 |
+
'rewrite' => array(
|
| 1117 |
+
'label' => __( 'Rewrite', 'pods' ),
|
| 1118 |
+
'help' => __( 'Allows you to use pretty permalinks, if set in WordPress Settings->Reading. If not enbabled, your links will be in the form of "example.com/?pod_name=post_slug" regardless of your permalink settings.', 'pods' ),
|
| 1119 |
+
'type' => 'boolean',
|
| 1120 |
+
'default' => true,
|
| 1121 |
+
'dependency' => true,
|
| 1122 |
+
'boolean_yes_label' => ''
|
| 1123 |
+
),
|
| 1124 |
+
'rewrite_custom_slug' => array(
|
| 1125 |
+
'label' => __( 'Custom Rewrite Slug', 'pods' ),
|
| 1126 |
+
'help' => __( 'Changes the first segment of the URL, which by default is the name of the Pod. For example, if your Pod is called "foo", if this field is left blank, your link will be "example.com/foo/post_slug", but if you were to enter "bar" your link will be "example.com/bar/post_slug".', 'pods' ),
|
| 1127 |
+
'type' => 'text',
|
| 1128 |
+
'default' => '',
|
| 1129 |
+
'depends-on' => array( 'rewrite' => true )
|
| 1130 |
+
),
|
| 1131 |
+
'rewrite_with_front' => array(
|
| 1132 |
+
'label' => __( 'Rewrite with Front', 'pods' ),
|
| 1133 |
+
'help' => __( 'Allows permalinks to be prepended with your front base (example: if your permalink structure is /blog/, then your links will be: Unchecked->/news/, Checked->/blog/news/)', 'pods' ),
|
| 1134 |
+
'type' => 'boolean',
|
| 1135 |
+
'default' => true,
|
| 1136 |
+
'depends-on' => array( 'rewrite' => true ),
|
| 1137 |
+
'boolean_yes_label' => ''
|
| 1138 |
+
),
|
| 1139 |
+
'rewrite_feeds' => array(
|
| 1140 |
+
'label' => __( 'Rewrite Feeds', 'pods' ),
|
| 1141 |
+
'help' => __( 'help', 'pods' ),
|
| 1142 |
+
'type' => 'boolean',
|
| 1143 |
+
'default' => false,
|
| 1144 |
+
'depends-on' => array( 'rewrite' => true ),
|
| 1145 |
+
'boolean_yes_label' => ''
|
| 1146 |
+
),
|
| 1147 |
+
'rewrite_pages' => array(
|
| 1148 |
+
'label' => __( 'Rewrite Pages', 'pods' ),
|
| 1149 |
+
'help' => __( 'help', 'pods' ),
|
| 1150 |
+
'type' => 'boolean',
|
| 1151 |
+
'default' => true,
|
| 1152 |
+
'depends-on' => array( 'rewrite' => true ),
|
| 1153 |
+
'boolean_yes_label' => ''
|
| 1154 |
+
),
|
| 1155 |
+
'query_var' => array(
|
| 1156 |
+
'label' => __( 'Query Var', 'pods' ),
|
| 1157 |
+
'help' => __( 'The Query Var is used in the URL and underneath the WordPress Rewrite API to tell WordPress what page or post type you are on. For a list of reserved Query Vars, read <a href="http://codex.wordpress.org/WordPress_Query_Vars">WordPress Query Vars</a> from the WordPress Codex.', 'pods' ),
|
| 1158 |
+
'type' => 'boolean',
|
| 1159 |
+
'default' => true,
|
| 1160 |
+
'boolean_yes_label' => ''
|
| 1161 |
+
),
|
| 1162 |
+
'can_export' => array(
|
| 1163 |
+
'label' => __( 'Exportable', 'pods' ),
|
| 1164 |
+
'help' => __( 'help', 'pods' ),
|
| 1165 |
+
'type' => 'boolean',
|
| 1166 |
+
'default' => true,
|
| 1167 |
+
'boolean_yes_label' => ''
|
| 1168 |
+
),
|
| 1169 |
+
'default_status' => array(
|
| 1170 |
+
'label' => __( 'Default Status', 'pods' ),
|
| 1171 |
+
'help' => __( 'help', 'pods' ),
|
| 1172 |
+
'type' => 'pick',
|
| 1173 |
+
'pick_object' => 'post-status',
|
| 1174 |
+
'default' => apply_filters( 'pods_api_default_status_' . pods_var_raw( 'name', $pod, 'post_type', null, true ), 'draft', $pod )
|
| 1175 |
+
)
|
| 1176 |
+
);
|
| 1177 |
+
}
|
| 1178 |
+
elseif ( 'taxonomy' == $pod[ 'type' ] ) {
|
| 1179 |
+
$options[ 'admin-ui' ] = array(
|
| 1180 |
+
'show_ui' => array(
|
| 1181 |
+
'label' => __( 'Show Admin UI', 'pods' ),
|
| 1182 |
+
'help' => __( 'help', 'pods' ),
|
| 1183 |
+
'type' => 'boolean',
|
| 1184 |
+
'default' => pods_var_raw( 'public', $pod, true ),
|
| 1185 |
+
'dependency' => true,
|
| 1186 |
+
'boolean_yes_label' => ''
|
| 1187 |
+
),
|
| 1188 |
+
'menu_name' => array(
|
| 1189 |
+
'label' => __( 'Menu Name', 'pods' ),
|
| 1190 |
+
'help' => __( 'help', 'pods' ),
|
| 1191 |
+
'type' => 'text',
|
| 1192 |
+
'default' => '',
|
| 1193 |
+
'depends-on' => array( 'show_ui' => true )
|
| 1194 |
+
),
|
| 1195 |
+
'menu_location' => array(
|
| 1196 |
+
'label' => __( 'Menu Location', 'pods' ),
|
| 1197 |
+
'help' => __( 'help', 'pods' ),
|
| 1198 |
+
'type' => 'pick',
|
| 1199 |
+
'default' => 'default',
|
| 1200 |
+
'depends-on' => array( 'show_ui' => true ),
|
| 1201 |
+
'data' => array(
|
| 1202 |
+
'default' => __( 'Default - Add to associated Post Type(s) menus', 'pods' ),
|
| 1203 |
+
'settings' => __( 'Add to Settings menu', 'pods' ),
|
| 1204 |
+
'appearances' => __( 'Add to Appearances menu', 'pods' ),
|
| 1205 |
+
'objects' => __( 'Make a top-level menu item', 'pods' ),
|
| 1206 |
+
'top' => __( 'Make a new top-level menu item below Settings', 'pods' ),
|
| 1207 |
+
'submenu' => __( 'Add a submenu item to another menu', 'pods' )
|
| 1208 |
+
),
|
| 1209 |
+
'dependency' => true
|
| 1210 |
+
),
|
| 1211 |
+
'menu_location_custom' => array(
|
| 1212 |
+
'label' => __( 'Custom Menu Location', 'pods' ),
|
| 1213 |
+
'help' => __( 'help', 'pods' ),
|
| 1214 |
+
'type' => 'text',
|
| 1215 |
+
'depends-on' => array( 'menu_location' => 'submenu' )
|
| 1216 |
+
),
|
| 1217 |
+
'menu_position' => array(
|
| 1218 |
+
'label' => __( 'Menu Position', 'pods' ),
|
| 1219 |
+
'help' => __( 'help', 'pods' ),
|
| 1220 |
+
'type' => 'number',
|
| 1221 |
+
'default' => 0,
|
| 1222 |
+
'depends-on' => array( 'menu_location' => array( 'objects', 'top' ) )
|
| 1223 |
+
),
|
| 1224 |
+
'menu_icon' => array(
|
| 1225 |
+
'label' => __( 'Menu Icon URL', 'pods' ),
|
| 1226 |
+
'help' => __( 'help', 'pods' ),
|
| 1227 |
+
'type' => 'text',
|
| 1228 |
+
'default' => '',
|
| 1229 |
+
'depends-on' => array( 'menu_location' => array( 'objects', 'top' ) )
|
| 1230 |
+
),
|
| 1231 |
+
'show_in_nav_menus' => array(
|
| 1232 |
+
'label' => __( 'Show in Navigation Menus', 'pods' ),
|
| 1233 |
+
'help' => __( 'help', 'pods' ),
|
| 1234 |
+
'type' => 'boolean',
|
| 1235 |
+
'default' => pods_var_raw( 'public', $pod, true ),
|
| 1236 |
+
'boolean_yes_label' => ''
|
| 1237 |
+
),
|
| 1238 |
+
'show_tagcloud' => array(
|
| 1239 |
+
'label' => __( 'Allow in Tagcloud Widget', 'pods' ),
|
| 1240 |
+
'help' => __( 'help', 'pods' ),
|
| 1241 |
+
'type' => 'boolean',
|
| 1242 |
+
'default' => pods_var_raw( 'show_ui', $pod, pods_var_raw( 'public', $pod, true ) ),
|
| 1243 |
+
'boolean_yes_label' => ''
|
| 1244 |
+
)
|
| 1245 |
+
);
|
| 1246 |
+
|
| 1247 |
+
if ( pods_version_check( 'wp', '3.5' ) ) {
|
| 1248 |
+
$options[ 'admin-ui' ][ 'show_admin_column' ] = array(
|
| 1249 |
+
'label' => __( 'Show Taxonomy column on Post Types', 'pods' ),
|
| 1250 |
+
'help' => __( 'Whether to add a column for this taxonomy on the associated post types manage screens', 'pods' ),
|
| 1251 |
+
'type' => 'boolean',
|
| 1252 |
+
'default' => false,
|
| 1253 |
+
'boolean_yes_label' => ''
|
| 1254 |
+
);
|
| 1255 |
+
}
|
| 1256 |
|
| 1257 |
+
// Integration for Single Value Taxonomy UI
|
| 1258 |
+
if ( function_exists( 'tax_single_value_meta_box' ) ) {
|
| 1259 |
+
$options[ 'admin-ui' ][ 'single_value' ] = array(
|
| 1260 |
+
'label' => __( 'Single Value Taxonomy', 'pods' ),
|
| 1261 |
+
'help' => __( 'Use a drop-down for the input instead of the WordPress default', 'pods' ),
|
| 1262 |
+
'type' => 'boolean',
|
| 1263 |
+
'default' => false,
|
| 1264 |
+
'boolean_yes_label' => ''
|
| 1265 |
+
);
|
| 1266 |
+
|
| 1267 |
+
$options[ 'admin-ui' ][ 'single_value_required' ] = array(
|
| 1268 |
+
'label' => __( 'Single Value Taxonomy - Required', 'pods' ),
|
| 1269 |
+
'help' => __( 'A term will be selected by default in the Post Editor, not optional', 'pods' ),
|
| 1270 |
+
'type' => 'boolean',
|
| 1271 |
+
'default' => false,
|
| 1272 |
+
'boolean_yes_label' => ''
|
| 1273 |
+
);
|
| 1274 |
}
|
|
|
|
|
|
|
| 1275 |
|
| 1276 |
+
// @todo fill this in
|
| 1277 |
+
$options[ 'advanced' ] = array(
|
| 1278 |
+
'temporary' => 'This type has the fields hardcoded' // :(
|
| 1279 |
+
);
|
| 1280 |
+
}
|
| 1281 |
+
elseif ( 'settings' == $pod[ 'type' ] ) {
|
| 1282 |
+
$options[ 'admin-ui' ] = array(
|
| 1283 |
+
'ui_style' => array(
|
| 1284 |
+
'label' => __( 'Admin UI Style', 'pods' ),
|
| 1285 |
+
'help' => __( 'help', 'pods' ),
|
| 1286 |
+
'type' => 'pick',
|
| 1287 |
+
'default' => 'settings',
|
| 1288 |
+
'data' => array(
|
| 1289 |
+
'settings' => __( 'Normal Settings Form', 'pods' ),
|
| 1290 |
+
'post_type' => __( 'Post Type UI', 'pods' ),
|
| 1291 |
+
'custom' => __( 'Custom (hook into pods_admin_ui_custom or pods_admin_ui_custom_{podname} action)', 'pods' )
|
| 1292 |
+
),
|
| 1293 |
+
'dependency' => true
|
| 1294 |
+
),
|
| 1295 |
+
'menu_location' => array(
|
| 1296 |
+
'label' => __( 'Menu Location', 'pods' ),
|
| 1297 |
+
'help' => __( 'help', 'pods' ),
|
| 1298 |
+
'type' => 'pick',
|
| 1299 |
+
'default' => 'settings',
|
| 1300 |
+
'data' => array(
|
| 1301 |
+
'settings' => __( 'Add to Settings menu', 'pods' ),
|
| 1302 |
+
'appearances' => __( 'Add to Appearances menu', 'pods' ),
|
| 1303 |
+
'top' => __( 'Make a new top-level menu item below Settings', 'pods' ),
|
| 1304 |
+
'submenu' => __( 'Add a submenu item to another menu', 'pods' )
|
| 1305 |
+
),
|
| 1306 |
+
'dependency' => true
|
| 1307 |
+
),
|
| 1308 |
+
'menu_location_custom' => array(
|
| 1309 |
+
'label' => __( 'Custom Menu Location', 'pods' ),
|
| 1310 |
+
'help' => __( 'help', 'pods' ),
|
| 1311 |
+
'type' => 'text',
|
| 1312 |
+
'depends-on' => array( 'menu_location' => 'submenu' )
|
| 1313 |
+
),
|
| 1314 |
+
'menu_position' => array(
|
| 1315 |
+
'label' => __( 'Menu Position', 'pods' ),
|
| 1316 |
+
'help' => __( 'help', 'pods' ),
|
| 1317 |
+
'type' => 'number',
|
| 1318 |
+
'default' => 0,
|
| 1319 |
+
'depends-on' => array( 'menu_location' => 'top' )
|
| 1320 |
+
),
|
| 1321 |
+
'menu_icon' => array(
|
| 1322 |
+
'label' => __( 'Menu Icon URL', 'pods' ),
|
| 1323 |
+
'help' => __( 'help', 'pods' ),
|
| 1324 |
+
'type' => 'text',
|
| 1325 |
+
'default' => '',
|
| 1326 |
+
'depends-on' => array( 'menu_location' => 'top' )
|
| 1327 |
+
)
|
| 1328 |
+
);
|
| 1329 |
+
|
| 1330 |
+
// @todo fill this in
|
| 1331 |
+
$options[ 'advanced' ] = array(
|
| 1332 |
+
'temporary' => 'This type has the fields hardcoded' // :(
|
| 1333 |
+
);
|
| 1334 |
+
}
|
| 1335 |
+
elseif ( 'pod' == $pod[ 'type' ] ) {
|
| 1336 |
+
$options[ 'admin-ui' ] = array(
|
| 1337 |
+
'ui_style' => array(
|
| 1338 |
+
'label' => __( 'Admin UI Style', 'pods' ),
|
| 1339 |
+
'help' => __( 'help', 'pods' ),
|
| 1340 |
+
'type' => 'pick',
|
| 1341 |
+
'default' => 'settings',
|
| 1342 |
+
'data' => array(
|
| 1343 |
+
'post_type' => __( 'Normal (Looks like the Post Type UI)', 'pods' ),
|
| 1344 |
+
'custom' => __( 'Custom (hook into pods_admin_ui_custom or pods_admin_ui_custom_{podname} action)', 'pods' )
|
| 1345 |
+
),
|
| 1346 |
+
'dependency' => true
|
| 1347 |
+
),
|
| 1348 |
+
'show_in_menu' => array(
|
| 1349 |
+
'label' => __( 'Show Admin Menu in Dashboard', 'pods' ),
|
| 1350 |
+
'help' => __( 'help', 'pods' ),
|
| 1351 |
+
'type' => 'boolean',
|
| 1352 |
+
'default' => false,
|
| 1353 |
+
'boolean_yes_label' => '',
|
| 1354 |
+
'dependency' => true
|
| 1355 |
+
),
|
| 1356 |
+
'menu_location_custom' => array(
|
| 1357 |
+
'label' => __( 'Parent Menu ID (optional)', 'pods' ),
|
| 1358 |
+
'help' => __( 'help', 'pods' ),
|
| 1359 |
+
'type' => 'text',
|
| 1360 |
+
'depends-on' => array( 'show_in_menu' => true )
|
| 1361 |
+
),
|
| 1362 |
+
'menu_position' => array(
|
| 1363 |
+
'label' => __( 'Menu Position', 'pods' ),
|
| 1364 |
+
'help' => __( 'help', 'pods' ),
|
| 1365 |
+
'type' => 'number',
|
| 1366 |
+
'default' => 0,
|
| 1367 |
+
'depends-on' => array( 'show_in_menu' => true )
|
| 1368 |
+
),
|
| 1369 |
+
'menu_icon' => array(
|
| 1370 |
+
'label' => __( 'Menu Icon URL', 'pods' ),
|
| 1371 |
+
'help' => __( 'This is the icon shown to the left of the menu text for this content type.', 'pods' ),
|
| 1372 |
+
'type' => 'text',
|
| 1373 |
+
'default' => '',
|
| 1374 |
+
'depends-on' => array( 'show_in_menu' => true )
|
| 1375 |
+
),
|
| 1376 |
+
'ui_icon' => array(
|
| 1377 |
+
'label' => __( 'Header Icon', 'pods' ),
|
| 1378 |
+
'help' => __( 'This is the icon shown to the left of the heading text at the top of the manage pages for this content type.', 'pods' ),
|
| 1379 |
+
'type' => 'file',
|
| 1380 |
+
'default' => '',
|
| 1381 |
+
'file_edit_title' => 0,
|
| 1382 |
+
'depends-on' => array( 'show_in_menu' => true )
|
| 1383 |
+
),
|
| 1384 |
+
'ui_actions_enabled' => array(
|
| 1385 |
+
'label' => __( 'Actions Available', 'pods' ),
|
| 1386 |
+
'help' => __( 'help', 'pods' ),
|
| 1387 |
+
'type' => 'pick',
|
| 1388 |
+
'default' => ( 1 == pods_var( 'ui_export', $pod ) ? array( 'add', 'edit', 'duplicate', 'delete', 'export' ) : array( 'add', 'edit', 'duplicate', 'delete' ) ),
|
| 1389 |
+
'data' => array(
|
| 1390 |
+
'add' => __( 'Add New', 'pods' ),
|
| 1391 |
+
'edit' => __( 'Edit', 'pods' ),
|
| 1392 |
+
'duplicate' => __( 'Duplicate', 'pods' ),
|
| 1393 |
+
'delete' => __( 'Delete', 'pods' ),
|
| 1394 |
+
'reorder' => __( 'Reorder', 'pods' ),
|
| 1395 |
+
'export' => __( 'Export', 'pods' )
|
| 1396 |
+
),
|
| 1397 |
+
'pick_format_type' => 'multi',
|
| 1398 |
+
'dependency' => true
|
| 1399 |
+
),
|
| 1400 |
+
'ui_reorder_field' => array(
|
| 1401 |
+
'label' => __( 'Reorder Field', 'pods' ),
|
| 1402 |
+
'help' => __( 'This is the field that will be reordered on, it should be numeric.', 'pods' ),
|
| 1403 |
+
'type' => 'text',
|
| 1404 |
+
'default' => 'menu_order',
|
| 1405 |
+
'depends-on' => array( 'ui_actions_enabled' => 'reorder' )
|
| 1406 |
+
),
|
| 1407 |
+
'ui_fields_manage' => array(
|
| 1408 |
+
'label' => __( 'Admin Table Columns', 'pods' ),
|
| 1409 |
+
'help' => __( 'help', 'pods' ),
|
| 1410 |
+
'type' => 'pick',
|
| 1411 |
+
'default' => array(),
|
| 1412 |
+
'data' => array(),
|
| 1413 |
+
'pick_format_type' => 'multi'
|
| 1414 |
+
),
|
| 1415 |
+
'ui_filters' => array(
|
| 1416 |
+
'label' => __( 'Search Filters', 'pods' ),
|
| 1417 |
+
'help' => __( 'help', 'pods' ),
|
| 1418 |
+
'type' => 'pick',
|
| 1419 |
+
'default' => array(),
|
| 1420 |
+
'data' => array(),
|
| 1421 |
+
'pick_format_type' => 'multi'
|
| 1422 |
+
)
|
| 1423 |
+
);
|
| 1424 |
+
|
| 1425 |
+
if ( !empty( $pod[ 'fields' ] ) ) {
|
| 1426 |
+
if ( isset( $pod[ 'fields' ][ pods_var_raw( 'pod_index', $pod, 'name' ) ] ) )
|
| 1427 |
+
$options[ 'admin-ui' ][ 'ui_fields_manage' ][ 'default' ][] = pods_var_raw( 'pod_index', $pod, 'name' );
|
| 1428 |
+
|
| 1429 |
+
if ( isset( $pod[ 'fields' ][ 'modified' ] ) )
|
| 1430 |
+
$options[ 'admin-ui' ][ 'ui_fields_manage' ][ 'default' ][] = 'modified';
|
| 1431 |
+
|
| 1432 |
+
foreach ( $pod[ 'fields' ] as $field ) {
|
| 1433 |
+
$type = '';
|
| 1434 |
+
|
| 1435 |
+
if ( isset( $field_types[ $field[ 'type' ] ] ) )
|
| 1436 |
+
$type = ' <small>(' . $field_types[ $field[ 'type' ] ][ 'label' ] . ')</small>';
|
| 1437 |
+
|
| 1438 |
+
$options[ 'admin-ui' ][ 'ui_fields_manage' ][ 'data' ][ $field[ 'name' ] ] = $field[ 'label' ] . $type;
|
| 1439 |
+
$options[ 'admin-ui' ][ 'ui_filters' ][ 'data' ][ $field[ 'name' ] ] = $field[ 'label' ] . $type;
|
| 1440 |
+
}
|
| 1441 |
+
|
| 1442 |
+
$options[ 'admin-ui' ][ 'ui_fields_manage' ][ 'data' ][ 'id' ] = 'ID';
|
| 1443 |
+
}
|
| 1444 |
+
else {
|
| 1445 |
+
unset( $options[ 'admin-ui' ][ 'ui_fields_manage' ] );
|
| 1446 |
+
unset( $options[ 'admin-ui' ][ 'ui_filters' ] );
|
| 1447 |
+
}
|
| 1448 |
+
|
| 1449 |
+
// @todo fill this in
|
| 1450 |
+
$options[ 'advanced' ] = array(
|
| 1451 |
+
'temporary' => 'This type has the fields hardcoded' // :(
|
| 1452 |
+
);
|
| 1453 |
+
}
|
| 1454 |
+
|
| 1455 |
+
/**
|
| 1456 |
+
* Add admin fields to the Pods editor for a specific Pod
|
| 1457 |
+
*
|
| 1458 |
+
* @params array $options The Options fields
|
| 1459 |
+
* @params object $pod Current Pods object
|
| 1460 |
+
*
|
| 1461 |
+
* @since unkown
|
| 1462 |
+
*/
|
| 1463 |
+
$options = apply_filters( 'pods_admin_setup_edit_options_' . $pod[ 'type' ] . '_' . $pod[ 'name' ], $options, $pod );
|
| 1464 |
|
| 1465 |
+
/**
|
| 1466 |
+
* Add admin fields to the Pods editor for any Pod of a specific content type.
|
| 1467 |
+
*/
|
| 1468 |
+
$options = apply_filters( 'pods_admin_setup_edit_options_' . $pod[ 'type' ], $options, $pod );
|
| 1469 |
|
| 1470 |
+
/**
|
| 1471 |
+
* Add admin fields to the Pods editor for all Pods
|
| 1472 |
+
*/
|
| 1473 |
+
$options = apply_filters( 'pods_admin_setup_edit_options', $options, $pod );
|
| 1474 |
|
| 1475 |
+
return $options;
|
| 1476 |
+
}
|
| 1477 |
+
|
| 1478 |
+
/**
|
| 1479 |
+
* Get list of Pod field option tabs
|
| 1480 |
+
*
|
| 1481 |
+
* @return array
|
| 1482 |
+
*/
|
| 1483 |
+
public function admin_setup_edit_field_tabs ( $pod ) {
|
| 1484 |
+
$core_tabs = array(
|
| 1485 |
+
'basic' => __( 'Basic', 'pods' ),
|
| 1486 |
+
'additional-field' => __( 'Additional Field Options', 'pods' ),
|
| 1487 |
+
'advanced' => __( 'Advanced', 'pods' )
|
| 1488 |
+
);
|
| 1489 |
+
|
| 1490 |
+
$tabs = apply_filters( 'pods_admin_setup_edit_field_tabs', array(), $pod );
|
| 1491 |
+
|
| 1492 |
+
$tabs = array_merge( $core_tabs, $tabs );
|
| 1493 |
+
|
| 1494 |
+
return $tabs;
|
| 1495 |
+
}
|
| 1496 |
+
|
| 1497 |
+
/**
|
| 1498 |
+
* Get list of Pod field options
|
| 1499 |
+
*
|
| 1500 |
+
* @return array
|
| 1501 |
+
*/
|
| 1502 |
+
public function admin_setup_edit_field_options ( $pod ) {
|
| 1503 |
+
$options = array();
|
| 1504 |
+
|
| 1505 |
+
$options[ 'additional-field' ] = array();
|
| 1506 |
+
|
| 1507 |
+
$field_types = PodsForm::field_types();
|
| 1508 |
+
|
| 1509 |
+
foreach ( $field_types as $type => $field_type_data ) {
|
| 1510 |
+
/**
|
| 1511 |
+
* @var $field_type PodsField
|
| 1512 |
+
*/
|
| 1513 |
+
$field_type = PodsForm::field_loader( $type, $field_type_data[ 'file' ] );
|
| 1514 |
+
|
| 1515 |
+
$field_type_vars = get_class_vars( get_class( $field_type ) );
|
| 1516 |
+
|
| 1517 |
+
if ( !isset( $field_type_vars[ 'pod_types' ] ) )
|
| 1518 |
+
$field_type_vars[ 'pod_types' ] = true;
|
| 1519 |
+
|
| 1520 |
+
$options[ 'additional-field' ][ $type ] = array();
|
| 1521 |
+
|
| 1522 |
+
// Only show supported field types
|
| 1523 |
+
if ( true !== $field_type_vars[ 'pod_types' ] ) {
|
| 1524 |
+
if ( empty( $field_type_vars[ 'pod_types' ] ) )
|
| 1525 |
+
continue;
|
| 1526 |
+
elseif ( is_array( $field_type_vars[ 'pod_types' ] ) && !in_array( pods_var( 'type', $pod ), $field_type_vars[ 'pod_types' ] ) )
|
| 1527 |
+
continue;
|
| 1528 |
+
elseif ( !is_array( $field_type_vars[ 'pod_types' ] ) && pods_var( 'type', $pod ) != $field_type_vars[ 'pod_types' ] )
|
| 1529 |
+
continue;
|
| 1530 |
+
}
|
| 1531 |
+
|
| 1532 |
+
$options[ 'additional-field' ][ $type ] = PodsForm::ui_options( $type );
|
| 1533 |
+
}
|
| 1534 |
+
|
| 1535 |
+
$input_helpers = array(
|
| 1536 |
+
'' => '-- Select --'
|
| 1537 |
+
);
|
| 1538 |
+
|
| 1539 |
+
if ( class_exists( 'Pods_Helpers' ) ) {
|
| 1540 |
+
$helpers = pods_api()->load_helpers( array( 'options' => array( 'helper_type' => 'input' ) ) );
|
| 1541 |
+
|
| 1542 |
+
foreach ( $helpers as $helper ) {
|
| 1543 |
+
$input_helpers[ $helper[ 'name' ] ] = $helper[ 'name' ];
|
| 1544 |
+
}
|
| 1545 |
+
}
|
| 1546 |
+
|
| 1547 |
+
$options[ 'advanced' ] = array(
|
| 1548 |
+
__( 'Visual', 'pods' ) => array(
|
| 1549 |
+
'class' => array(
|
| 1550 |
+
'name' => 'class',
|
| 1551 |
+
'label' => __( 'Additional CSS Classes', 'pods' ),
|
| 1552 |
+
'help' => __( 'help', 'pods' ),
|
| 1553 |
+
'type' => 'text',
|
| 1554 |
+
'default' => ''
|
| 1555 |
+
),
|
| 1556 |
+
'input_helper' => array(
|
| 1557 |
+
'name' => 'input_helper',
|
| 1558 |
+
'label' => __( 'Input Helper', 'pods' ),
|
| 1559 |
+
'help' => __( 'help', 'pods' ),
|
| 1560 |
+
'type' => 'pick',
|
| 1561 |
+
'default' => '',
|
| 1562 |
+
'data' => $input_helpers
|
| 1563 |
+
)
|
| 1564 |
+
),
|
| 1565 |
+
__( 'Values', 'pods' ) => array(
|
| 1566 |
+
'default_value' => array(
|
| 1567 |
+
'name' => 'default_value',
|
| 1568 |
+
'label' => __( 'Default Value', 'pods' ),
|
| 1569 |
+
'help' => __( 'help', 'pods' ),
|
| 1570 |
+
'type' => 'text',
|
| 1571 |
+
'default' => ''
|
| 1572 |
+
),
|
| 1573 |
+
'default_value_parameter' => array(
|
| 1574 |
+
'name' => 'default_value_parameter',
|
| 1575 |
+
'label' => __( 'Set Default Value via Parameter', 'pods' ),
|
| 1576 |
+
'help' => __( 'help', 'pods' ),
|
| 1577 |
+
'type' => 'text',
|
| 1578 |
+
'default' => ''
|
| 1579 |
+
)
|
| 1580 |
+
),
|
| 1581 |
+
__( 'Visibility', 'pods' ) => array(
|
| 1582 |
+
'restrict_access' => array(
|
| 1583 |
+
'name' => 'restrict_access',
|
| 1584 |
+
'label' => __( 'Restrict Access', 'pods' ),
|
| 1585 |
+
'group' => array(
|
| 1586 |
+
'admin_only' => array(
|
| 1587 |
+
'name' => 'admin_only',
|
| 1588 |
+
'label' => __( 'Restrict access to Admins?', 'pods' ),
|
| 1589 |
+
'default' => 0,
|
| 1590 |
+
'type' => 'boolean',
|
| 1591 |
+
'dependency' => true,
|
| 1592 |
+
'help' => __( 'This field will only be able to be edited by users with the ability to manage_options or delete_users, or super admins of a WordPress Multisite network', 'pods' )
|
| 1593 |
+
),
|
| 1594 |
+
'restrict_role' => array(
|
| 1595 |
+
'name' => 'restrict_role',
|
| 1596 |
+
'label' => __( 'Restrict access by Role?', 'pods' ),
|
| 1597 |
+
'default' => 0,
|
| 1598 |
+
'type' => 'boolean',
|
| 1599 |
+
'dependency' => true
|
| 1600 |
+
),
|
| 1601 |
+
'restrict_capability' => array(
|
| 1602 |
+
'name' => 'restrict_capability',
|
| 1603 |
+
'label' => __( 'Restrict access by Capability?', 'pods' ),
|
| 1604 |
+
'default' => 0,
|
| 1605 |
+
'type' => 'boolean',
|
| 1606 |
+
'dependency' => true
|
| 1607 |
+
),
|
| 1608 |
+
'hidden' => array(
|
| 1609 |
+
'name' => 'hidden',
|
| 1610 |
+
'label' => __( 'Hide field from UI', 'pods' ),
|
| 1611 |
+
'default' => 0,
|
| 1612 |
+
'type' => 'boolean',
|
| 1613 |
+
'help' => __( 'This option is overriden by access restrictions. If the user does not have access to edit this field, it will be hidden. If no access restrictions are set, this field will always be hidden.', 'pods' )
|
| 1614 |
+
),
|
| 1615 |
+
'read_only' => array(
|
| 1616 |
+
'name' => 'read_only',
|
| 1617 |
+
'label' => __( 'Make field "Read Only" in UI', 'pods' ),
|
| 1618 |
+
'default' => 0,
|
| 1619 |
+
'type' => 'boolean',
|
| 1620 |
+
'help' => __( 'This option is overriden by access restrictions. If the user does not have access to edit this field, it will be read only. If no access restrictions are set, this field will always be read only.', 'pods' ),
|
| 1621 |
+
'depends-on' => array(
|
| 1622 |
+
'type' => array(
|
| 1623 |
+
'boolean',
|
| 1624 |
+
'color',
|
| 1625 |
+
'currency',
|
| 1626 |
+
'date',
|
| 1627 |
+
'datetime',
|
| 1628 |
+
'email',
|
| 1629 |
+
'number',
|
| 1630 |
+
'paragraph',
|
| 1631 |
+
'password',
|
| 1632 |
+
'phone',
|
| 1633 |
+
'slug',
|
| 1634 |
+
'text',
|
| 1635 |
+
'time',
|
| 1636 |
+
'website'
|
| 1637 |
+
)
|
| 1638 |
+
)
|
| 1639 |
+
)
|
| 1640 |
+
)
|
| 1641 |
+
),
|
| 1642 |
+
'roles_allowed' => array(
|
| 1643 |
+
'name' => 'roles_allowed',
|
| 1644 |
+
'label' => __( 'Role(s) Allowed', 'pods' ),
|
| 1645 |
+
'help' => __( 'help', 'pods' ),
|
| 1646 |
+
'type' => 'pick',
|
| 1647 |
+
'pick_object' => 'role',
|
| 1648 |
+
'pick_format_type' => 'multi',
|
| 1649 |
+
'default' => 'administrator',
|
| 1650 |
+
'depends-on' => array(
|
| 1651 |
+
'restrict_role' => true
|
| 1652 |
+
)
|
| 1653 |
+
),
|
| 1654 |
+
'capability_allowed' => array(
|
| 1655 |
+
'name' => 'capability_allowed',
|
| 1656 |
+
'label' => __( 'Capability Allowed', 'pods' ),
|
| 1657 |
+
'help' => __( 'Comma-separated list of cababilities, for example add_podname_item, please see the Roles and Capabilities component for the complete list and a way to add your own.', 'pods' ),
|
| 1658 |
+
'type' => 'text',
|
| 1659 |
+
'default' => '',
|
| 1660 |
+
'depends-on' => array(
|
| 1661 |
+
'restrict_capability' => true
|
| 1662 |
+
)
|
| 1663 |
+
)
|
| 1664 |
+
/*,
|
| 1665 |
+
'search' => array(
|
| 1666 |
+
'label' => __( 'Include in searches', 'pods' ),
|
| 1667 |
+
'help' => __( 'help', 'pods' ),
|
| 1668 |
+
'default' => 1,
|
| 1669 |
+
'type' => 'boolean',
|
| 1670 |
+
)*/
|
| 1671 |
+
)
|
| 1672 |
+
/*,
|
| 1673 |
+
__( 'Validation', 'pods' ) => array(
|
| 1674 |
+
'regex_validation' => array(
|
| 1675 |
+
'label' => __( 'RegEx Validation', 'pods' ),
|
| 1676 |
+
'help' => __( 'help', 'pods' ),
|
| 1677 |
+
'type' => 'text',
|
| 1678 |
+
'default' => ''
|
| 1679 |
+
),
|
| 1680 |
+
'message_regex' => array(
|
| 1681 |
+
'label' => __( 'Message if field does not pass RegEx', 'pods' ),
|
| 1682 |
+
'help' => __( 'help', 'pods' ),
|
| 1683 |
+
'type' => 'text',
|
| 1684 |
+
'default' => ''
|
| 1685 |
+
),
|
| 1686 |
+
'message_required' => array(
|
| 1687 |
+
'label' => __( 'Message if field is blank', 'pods' ),
|
| 1688 |
+
'help' => __( 'help', 'pods' ),
|
| 1689 |
+
'type' => 'text',
|
| 1690 |
+
'default' => '',
|
| 1691 |
+
'depends-on' => array( 'required' => true )
|
| 1692 |
+
),
|
| 1693 |
+
'message_unique' => array(
|
| 1694 |
+
'label' => __( 'Message if field is not unique', 'pods' ),
|
| 1695 |
+
'help' => __( 'help', 'pods' ),
|
| 1696 |
+
'type' => 'text',
|
| 1697 |
+
'default' => '',
|
| 1698 |
+
'depends-on' => array( 'unique' => true )
|
| 1699 |
+
)
|
| 1700 |
+
)*/
|
| 1701 |
+
);
|
| 1702 |
+
|
| 1703 |
+
if ( !class_exists( 'Pods_Helpers' ) )
|
| 1704 |
+
unset( $options[ 'advanced-options' ][ 'input_helper' ] );
|
| 1705 |
+
|
| 1706 |
+
$options = apply_filters( 'pods_admin_setup_edit_field_options', $options, $pod );
|
| 1707 |
+
|
| 1708 |
+
return $options;
|
| 1709 |
+
}
|
| 1710 |
+
|
| 1711 |
+
/**
|
| 1712 |
+
* Duplicate a pod
|
| 1713 |
+
*
|
| 1714 |
+
* @param $id
|
| 1715 |
+
* @param $obj
|
| 1716 |
+
*
|
| 1717 |
+
* @return mixed
|
| 1718 |
+
*/
|
| 1719 |
+
public function admin_setup_duplicate ( $obj ) {
|
| 1720 |
+
$new_id = pods_api()->duplicate_pod( array( 'id' => $obj->id ) );
|
| 1721 |
+
|
| 1722 |
+
if ( 0 < $new_id )
|
| 1723 |
+
pods_redirect( pods_query_arg( array( 'action' => 'edit', 'id' => $new_id, 'do' => 'duplicate' ) ) );
|
| 1724 |
+
}
|
| 1725 |
|
| 1726 |
/**
|
| 1727 |
+
* Restrict Duplicate action to custom types, not extended
|
| 1728 |
*
|
| 1729 |
+
* @param bool $restricted
|
| 1730 |
+
* @param array $restrict
|
| 1731 |
+
* @param string $action
|
| 1732 |
+
* @param array $row
|
| 1733 |
+
* @param PodsUI $obj
|
| 1734 |
*
|
| 1735 |
+
* @since 2.3.10
|
| 1736 |
*/
|
| 1737 |
+
public function admin_setup_duplicate_restrict( $restricted, $restrict, $action, $row, $obj ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1738 |
|
| 1739 |
+
if ( in_array( $row[ 'real_type' ], array( 'user', 'media', 'comment' ) ) ) {
|
| 1740 |
+
$restricted = true;
|
| 1741 |
+
}
|
| 1742 |
|
| 1743 |
+
return $restricted;
|
| 1744 |
|
| 1745 |
+
}
|
|
|
|
|
|
|
| 1746 |
|
| 1747 |
+
/**
|
| 1748 |
+
* Reset a pod
|
| 1749 |
+
*
|
| 1750 |
+
* @param $obj
|
| 1751 |
+
*
|
| 1752 |
+
* @return mixed
|
| 1753 |
+
*/
|
| 1754 |
+
public function admin_setup_reset ( $obj, $id ) {
|
| 1755 |
+
$pod = pods_api()->load_pod( array( 'id' => $id ), false );
|
| 1756 |
|
| 1757 |
+
if ( empty( $pod ) )
|
| 1758 |
+
return $obj->error( __( 'Pod not found.', 'pods' ) );
|
|
|
|
|
|
|
|
|
|
| 1759 |
|
| 1760 |
+
pods_api()->reset_pod( array( 'id' => $id ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1761 |
|
| 1762 |
+
$obj->message( __( 'Pod reset successfully.', 'pods' ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1763 |
|
| 1764 |
+
$obj->manage();
|
| 1765 |
+
}
|
|
|
|
| 1766 |
|
| 1767 |
+
/**
|
| 1768 |
+
* Restrict Reset action from users and media
|
| 1769 |
+
*
|
| 1770 |
+
* @param bool $restricted
|
| 1771 |
+
* @param array $restrict
|
| 1772 |
+
* @param string $action
|
| 1773 |
+
* @param array $row
|
| 1774 |
+
* @param PodsUI $obj
|
| 1775 |
+
*
|
| 1776 |
+
* @since 2.3.10
|
| 1777 |
+
*/
|
| 1778 |
+
public function admin_setup_reset_restrict( $restricted, $restrict, $action, $row, $obj ) {
|
| 1779 |
+
|
| 1780 |
+
if ( in_array( $row[ 'real_type' ], array( 'user', 'media' ) ) ) {
|
| 1781 |
+
$restricted = true;
|
| 1782 |
+
}
|
| 1783 |
+
|
| 1784 |
+
return $restricted;
|
| 1785 |
|
|
|
|
| 1786 |
}
|
| 1787 |
|
| 1788 |
+
/**
|
| 1789 |
+
* Delete a pod
|
| 1790 |
+
*
|
| 1791 |
+
* @param $id
|
| 1792 |
+
* @param $obj
|
| 1793 |
+
*
|
| 1794 |
+
* @return mixed
|
| 1795 |
+
*/
|
| 1796 |
+
public function admin_setup_delete ( $id, $obj ) {
|
| 1797 |
+
$pod = pods_api()->load_pod( array( 'id' => $id ), false );
|
| 1798 |
|
| 1799 |
+
if ( empty( $pod ) )
|
| 1800 |
+
return $obj->error( __( 'Pod not found.', 'pods' ) );
|
| 1801 |
+
|
| 1802 |
+
pods_api()->delete_pod( array( 'id' => $id ) );
|
| 1803 |
+
|
| 1804 |
+
unset( $obj->data[ $pod[ 'id' ] ] );
|
| 1805 |
+
|
| 1806 |
+
$obj->total = count( $obj->data );
|
| 1807 |
+
$obj->total_found = count( $obj->data );
|
| 1808 |
+
|
| 1809 |
+
$obj->message( __( 'Pod deleted successfully.', 'pods' ) );
|
| 1810 |
+
}
|
| 1811 |
+
|
| 1812 |
+
/**
|
| 1813 |
+
* Get advanced administration view.
|
| 1814 |
+
*/
|
| 1815 |
+
public function admin_advanced () {
|
| 1816 |
+
pods_view( PODS_DIR . 'ui/admin/advanced.php', compact( array_keys( get_defined_vars() ) ) );
|
| 1817 |
+
}
|
| 1818 |
+
|
| 1819 |
+
/**
|
| 1820 |
+
* Get settings administration view
|
| 1821 |
+
*/
|
| 1822 |
+
public function admin_settings () {
|
| 1823 |
+
pods_view( PODS_DIR . 'ui/admin/settings.php', compact( array_keys( get_defined_vars() ) ) );
|
| 1824 |
+
}
|
| 1825 |
+
|
| 1826 |
+
/**
|
| 1827 |
+
* Get components administration UI
|
| 1828 |
+
*/
|
| 1829 |
+
public function admin_components () {
|
| 1830 |
+
$components = PodsInit::$components->components;
|
| 1831 |
+
|
| 1832 |
+
$view = pods_var( 'view', 'get', 'all', null, true );
|
| 1833 |
+
|
| 1834 |
+
$recommended = array(
|
| 1835 |
+
'advanced-relationships',
|
| 1836 |
+
'advanced-content-types',
|
| 1837 |
+
'migrate-packages',
|
| 1838 |
+
'roles-and-capabilities',
|
| 1839 |
+
'pages',
|
| 1840 |
+
'table-storage',
|
| 1841 |
+
'templates'
|
| 1842 |
+
);
|
| 1843 |
+
|
| 1844 |
+
foreach ( $components as $component => &$component_data ) {
|
| 1845 |
+
if ( !in_array( $view, array( 'all', 'recommended', 'dev' ) ) && ( !isset( $component_data[ 'Category' ] ) || $view != sanitize_title( $component_data[ 'Category' ] ) ) ) {
|
| 1846 |
+
unset( $components[ $component ] );
|
| 1847 |
+
|
| 1848 |
+
continue;
|
| 1849 |
+
}
|
| 1850 |
+
elseif ( 'recommended' == $view && !in_array( $component_data[ 'ID' ], $recommended ) ) {
|
| 1851 |
+
unset( $components[ $component ] );
|
| 1852 |
+
|
| 1853 |
+
continue;
|
| 1854 |
+
}
|
| 1855 |
+
elseif ( 'dev' == $view && pods_developer() && !pods_var_raw( 'DeveloperMode', $component_data, false ) ) {
|
| 1856 |
+
unset( $components[ $component ] );
|
| 1857 |
+
|
| 1858 |
+
continue;
|
| 1859 |
+
}
|
| 1860 |
+
elseif ( pods_var_raw( 'DeveloperMode', $component_data, false ) && !pods_developer() ) {
|
| 1861 |
+
unset( $components[ $component ] );
|
| 1862 |
+
|
| 1863 |
+
continue;
|
| 1864 |
+
}
|
| 1865 |
+
elseif ( !pods_var_raw( 'TablelessMode', $component_data, false ) && pods_tableless() ) {
|
| 1866 |
+
unset( $components[ $component ] );
|
| 1867 |
+
|
| 1868 |
+
continue;
|
| 1869 |
+
}
|
| 1870 |
+
|
| 1871 |
+
$component_data[ 'Name' ] = strip_tags( $component_data[ 'Name' ] );
|
| 1872 |
+
|
| 1873 |
+
if ( pods_var_raw( 'DeveloperMode', $component_data, false ) )
|
| 1874 |
+
$component_data[ 'Name' ] .= ' <em style="font-weight: normal; color:#333;">(Developer Preview)</em>';
|
| 1875 |
+
|
| 1876 |
+
$meta = array();
|
| 1877 |
+
|
| 1878 |
+
if ( !empty( $component_data[ 'Version' ] ) )
|
| 1879 |
+
$meta[] = 'Version ' . $component_data[ 'Version' ];
|
| 1880 |
+
|
| 1881 |
+
if ( empty( $component_data[ 'Author' ] ) ) {
|
| 1882 |
+
$component_data[ 'Author' ] = 'Pods Framework Team';
|
| 1883 |
+
$component_data[ 'AuthorURI' ] = 'http://pods.io/';
|
| 1884 |
+
}
|
| 1885 |
+
|
| 1886 |
+
if ( !empty( $component_data[ 'AuthorURI' ] ) )
|
| 1887 |
+
$component_data[ 'Author' ] = '<a href="' . $component_data[ 'AuthorURI' ] . '">' . $component_data[ 'Author' ] . '</a>';
|
| 1888 |
+
|
| 1889 |
+
$meta[] = sprintf( __( 'by %s', 'pods' ), $component_data[ 'Author' ] );
|
| 1890 |
+
|
| 1891 |
+
if ( !empty( $component_data[ 'URI' ] ) )
|
| 1892 |
+
$meta[] = '<a href="' . $component_data[ 'URI' ] . '">' . __( 'Visit component site', 'pods' ) . '</a>';
|
| 1893 |
+
|
| 1894 |
+
$component_data[ 'Description' ] = wpautop( trim( make_clickable( strip_tags( $component_data[ 'Description' ], 'em,strong' ) ) ) );
|
| 1895 |
+
|
| 1896 |
+
if ( !empty( $meta ) )
|
| 1897 |
+
$component_data[ 'Description' ] .= '<div class="pods-component-meta" ' . ( !empty( $component_data[ 'Description' ] ) ? ' style="padding:8px 0 4px;"' : '' ) . '>' . implode( ' | ', $meta ) . '</div>';
|
| 1898 |
+
|
| 1899 |
+
$component_data = array(
|
| 1900 |
+
'id' => $component_data[ 'ID' ],
|
| 1901 |
+
'name' => $component_data[ 'Name' ],
|
| 1902 |
+
'category' => $component_data[ 'Category' ],
|
| 1903 |
+
'version' => '',
|
| 1904 |
+
'description' => $component_data[ 'Description' ],
|
| 1905 |
+
'mustuse' => pods_var_raw( 'MustUse', $component_data, false ),
|
| 1906 |
+
'toggle' => 0
|
| 1907 |
+
);
|
| 1908 |
+
|
| 1909 |
+
if ( !empty( $component_data[ 'category' ] ) ) {
|
| 1910 |
+
$category_url = pods_query_arg( array( 'view' => sanitize_title( $component_data[ 'category' ] ), 'pg' => '', 'page' => $_GET[ 'page' ] ) );
|
| 1911 |
+
|
| 1912 |
+
$component_data[ 'category' ] = '<a href="' . esc_url( $category_url ) . '">' . $component_data[ 'category' ] . '</a>';
|
| 1913 |
+
}
|
| 1914 |
+
|
| 1915 |
+
if ( isset( PodsInit::$components->settings[ 'components' ][ $component_data[ 'id' ] ] ) && 0 != PodsInit::$components->settings[ 'components' ][ $component_data[ 'id' ] ] )
|
| 1916 |
+
$component_data[ 'toggle' ] = 1;
|
| 1917 |
+
elseif ( $component_data[ 'mustuse' ] )
|
| 1918 |
+
$component_data[ 'toggle' ] = 1;
|
| 1919 |
+
}
|
| 1920 |
+
|
| 1921 |
+
$ui = array(
|
| 1922 |
+
'data' => $components,
|
| 1923 |
+
'total' => count( $components ),
|
| 1924 |
+
'total_found' => count( $components ),
|
| 1925 |
+
'items' => 'Components',
|
| 1926 |
+
'item' => 'Component',
|
| 1927 |
+
'fields' => array(
|
| 1928 |
+
'manage' => array(
|
| 1929 |
+
'name' => array(
|
| 1930 |
+
'label' => __( 'Name', 'pods' ),
|
| 1931 |
+
'width' => '30%',
|
| 1932 |
+
'type' => 'text',
|
| 1933 |
+
'options' => array(
|
| 1934 |
+
'text_allow_html' => true
|
| 1935 |
+
)
|
| 1936 |
+
),
|
| 1937 |
+
'category' => array(
|
| 1938 |
+
'label' => __( 'Category', 'pods' ),
|
| 1939 |
+
'width' => '10%',
|
| 1940 |
+
'type' => 'text',
|
| 1941 |
+
'options' => array(
|
| 1942 |
+
'text_allow_html' => true
|
| 1943 |
+
)
|
| 1944 |
+
),
|
| 1945 |
+
'description' => array(
|
| 1946 |
+
'label' => __( 'Description', 'pods' ),
|
| 1947 |
+
'width' => '60%',
|
| 1948 |
+
'type' => 'text',
|
| 1949 |
+
'options' => array(
|
| 1950 |
+
'text_allow_html' => true,
|
| 1951 |
+
'text_allowed_html_tags' => 'strong em a ul ol li b i br div'
|
| 1952 |
+
)
|
| 1953 |
+
)
|
| 1954 |
+
)
|
| 1955 |
+
),
|
| 1956 |
+
'actions_disabled' => array( 'duplicate', 'view', 'export', 'add', 'edit', 'delete' ),
|
| 1957 |
+
'actions_custom' => array(
|
| 1958 |
+
'toggle' => array(
|
| 1959 |
+
'callback' => array( $this, 'admin_components_toggle' ),
|
| 1960 |
+
'nonce' => true
|
| 1961 |
+
)
|
| 1962 |
+
),
|
| 1963 |
+
'filters_enhanced' => true,
|
| 1964 |
+
'views' => array(
|
| 1965 |
+
'all' => __( 'All', 'pods' ),
|
| 1966 |
+
//'recommended' => __( 'Recommended', 'pods' ),
|
| 1967 |
+
'field-types' => __( 'Field Types', 'pods' ),
|
| 1968 |
+
'tools' => __( 'Tools', 'pods' ),
|
| 1969 |
+
'integration' => __( 'Integration', 'pods' ),
|
| 1970 |
+
'migration' => __( 'Migration', 'pods' ),
|
| 1971 |
+
'advanced' => __( 'Advanced', 'pods' )
|
| 1972 |
+
),
|
| 1973 |
+
'view' => $view,
|
| 1974 |
+
'heading' => array(
|
| 1975 |
+
'views' => __( 'Category', 'pods' )
|
| 1976 |
+
),
|
| 1977 |
+
'search' => false,
|
| 1978 |
+
'searchable' => false,
|
| 1979 |
+
'sortable' => false,
|
| 1980 |
+
'pagination' => false
|
| 1981 |
+
);
|
| 1982 |
+
|
| 1983 |
+
if ( pods_developer() )
|
| 1984 |
+
$ui[ 'views' ][ 'dev' ] = __( 'Developer Preview', 'pods' );
|
| 1985 |
+
|
| 1986 |
+
pods_ui( $ui );
|
| 1987 |
+
}
|
| 1988 |
+
|
| 1989 |
+
/**
|
| 1990 |
+
* Toggle a component on or off
|
| 1991 |
+
*
|
| 1992 |
+
* @param PodsUI $ui
|
| 1993 |
+
*
|
| 1994 |
+
* @return bool
|
| 1995 |
+
*/
|
| 1996 |
+
public function admin_components_toggle ( PodsUI $ui ) {
|
| 1997 |
+
$component = $_GET[ 'id' ];
|
| 1998 |
+
|
| 1999 |
+
if ( !empty( PodsInit::$components->components[ $component ][ 'PluginDependency' ] ) ) {
|
| 2000 |
+
$dependency = explode( '|', PodsInit::$components->components[ $component ][ 'PluginDependency' ] );
|
| 2001 |
+
|
| 2002 |
+
if ( !pods_is_plugin_active( $dependency[ 1 ] ) ) {
|
| 2003 |
+
$website = 'http://wordpress.org/extend/plugins/' . dirname( $dependency[ 1 ] ) . '/';
|
| 2004 |
+
|
| 2005 |
+
if ( isset( $dependency[ 2 ] ) )
|
| 2006 |
+
$website = $dependency[ 2 ];
|
| 2007 |
+
|
| 2008 |
+
if ( !empty( $website ) )
|
| 2009 |
+
$website = ' ' . sprintf( __( 'You can find it at %s', 'pods' ), '<a href="' . $website . '" target="_blank">' . $website . '</a>' );
|
| 2010 |
+
|
| 2011 |
+
$message = sprintf( __( 'The %s component requires that you have the <strong>%s</strong> plugin installed and activated.', 'pods' ), PodsInit::$components->components[ $component ][ 'Name' ], $dependency[ 0 ] ) . $website;
|
| 2012 |
+
|
| 2013 |
+
$ui->error( $message );
|
| 2014 |
+
|
| 2015 |
+
$ui->manage();
|
| 2016 |
+
|
| 2017 |
+
return;
|
| 2018 |
+
}
|
| 2019 |
+
}
|
| 2020 |
+
|
| 2021 |
+
if ( !empty( PodsInit::$components->components[ $component ][ 'ThemeDependency' ] ) ) {
|
| 2022 |
+
$dependency = explode( '|', PodsInit::$components->components[ $component ][ 'ThemeDependency' ] );
|
| 2023 |
+
|
| 2024 |
+
if ( strtolower( $dependency[ 1 ] ) != strtolower( get_template() ) && strtolower( $dependency[ 1 ] ) != strtolower( get_stylesheet() ) ) {
|
| 2025 |
+
$website = '';
|
| 2026 |
+
|
| 2027 |
+
if ( isset( $dependency[ 2 ] ) )
|
| 2028 |
+
$website = ' ' . sprintf( __( 'You can find it at %s', 'pods' ), '<a href="' . $dependency[ 2 ] . '" target="_blank">' . $dependency[ 2 ] . '</a>' );
|
| 2029 |
+
|
| 2030 |
+
$message = sprintf( __( 'The %s component requires that you have the <strong>%s</strong> theme installed and activated.', 'pods' ), PodsInit::$components->components[ $component ][ 'Name' ], $dependency[ 0 ] ) . $website;
|
| 2031 |
+
|
| 2032 |
+
$ui->error( $message );
|
| 2033 |
+
|
| 2034 |
+
$ui->manage();
|
| 2035 |
+
|
| 2036 |
+
return;
|
| 2037 |
+
}
|
| 2038 |
+
}
|
| 2039 |
+
|
| 2040 |
+
if ( !empty( PodsInit::$components->components[ $component ][ 'MustUse' ] ) ) {
|
| 2041 |
+
$message = sprintf( __( 'The %s component can not be disabled from here. You must deactivate the plugin or theme that added it.', 'pods' ), PodsInit::$components->components[ $component ][ 'Name' ] );
|
| 2042 |
+
|
| 2043 |
+
$ui->error( $message );
|
| 2044 |
+
|
| 2045 |
+
$ui->manage();
|
| 2046 |
+
|
| 2047 |
+
return;
|
| 2048 |
+
}
|
| 2049 |
+
|
| 2050 |
+
if ( '1' == pods_v( 'toggled' ) ) {
|
| 2051 |
+
$toggle = PodsInit::$components->toggle( $component );
|
| 2052 |
+
|
| 2053 |
+
if ( true === $toggle )
|
| 2054 |
+
$ui->message( PodsInit::$components->components[ $component ][ 'Name' ] . ' ' . __( 'Component enabled', 'pods' ) );
|
| 2055 |
+
elseif ( false === $toggle )
|
| 2056 |
+
$ui->message( PodsInit::$components->components[ $component ][ 'Name' ] . ' ' . __( 'Component disabled', 'pods' ) );
|
| 2057 |
+
|
| 2058 |
+
$components = PodsInit::$components->components;
|
| 2059 |
+
|
| 2060 |
+
foreach ( $components as $component => &$component_data ) {
|
| 2061 |
+
$toggle = 0;
|
| 2062 |
+
|
| 2063 |
+
if ( isset( PodsInit::$components->settings[ 'components' ][ $component_data[ 'ID' ] ] ) ) {
|
| 2064 |
+
if ( 0 != PodsInit::$components->settings[ 'components' ][ $component_data[ 'ID' ] ] )
|
| 2065 |
+
$toggle = 1;
|
| 2066 |
+
}
|
| 2067 |
+
if ( true === $component_data[ 'DeveloperMode' ] ) {
|
| 2068 |
+
if ( !pods_developer() ) {
|
| 2069 |
+
unset( $components[ $component ] );
|
| 2070 |
+
continue;
|
| 2071 |
+
}
|
| 2072 |
+
}
|
| 2073 |
+
|
| 2074 |
+
$component_data = array(
|
| 2075 |
+
'id' => $component_data[ 'ID' ],
|
| 2076 |
+
'name' => $component_data[ 'Name' ],
|
| 2077 |
+
'description' => make_clickable( $component_data[ 'Description' ] ),
|
| 2078 |
+
'version' => $component_data[ 'Version' ],
|
| 2079 |
+
'author' => $component_data[ 'Author' ],
|
| 2080 |
+
'toggle' => $toggle
|
| 2081 |
+
);
|
| 2082 |
+
}
|
| 2083 |
+
|
| 2084 |
+
$ui->data = $components;
|
| 2085 |
+
|
| 2086 |
+
pods_transient_clear( 'pods_components' );
|
| 2087 |
+
|
| 2088 |
+
$url = pods_query_arg( array( 'toggled' => null ) );
|
| 2089 |
+
|
| 2090 |
+
pods_redirect( $url );
|
| 2091 |
+
}
|
| 2092 |
+
elseif ( 1 == pods_var( 'toggle' ) )
|
| 2093 |
+
$ui->message( PodsInit::$components->components[ $component ][ 'Name' ] . ' ' . __( 'Component enabled', 'pods' ) );
|
| 2094 |
+
else
|
| 2095 |
+
$ui->message( PodsInit::$components->components[ $component ][ 'Name' ] . ' ' . __( 'Component disabled', 'pods' ) );
|
| 2096 |
+
|
| 2097 |
+
$ui->manage();
|
| 2098 |
+
}
|
| 2099 |
+
|
| 2100 |
+
/**
|
| 2101 |
+
* Get the admin upgrade page
|
| 2102 |
+
*/
|
| 2103 |
+
public function admin_upgrade () {
|
| 2104 |
+
foreach ( PodsInit::$upgrades as $old_version => $new_version ) {
|
| 2105 |
+
if ( version_compare( $old_version, PodsInit::$version_last, '<=' ) && version_compare( PodsInit::$version_last, $new_version, '<' ) ) {
|
| 2106 |
+
$new_version = str_replace( '.', '_', $new_version );
|
| 2107 |
+
|
| 2108 |
+
pods_view( PODS_DIR . 'ui/admin/upgrade/upgrade_' . $new_version . '.php', compact( array_keys( get_defined_vars() ) ) );
|
| 2109 |
+
|
| 2110 |
+
break;
|
| 2111 |
+
}
|
| 2112 |
+
}
|
| 2113 |
+
}
|
| 2114 |
+
|
| 2115 |
+
/**
|
| 2116 |
+
* Get the admin help page
|
| 2117 |
+
*/
|
| 2118 |
+
public function admin_help () {
|
| 2119 |
+
pods_view( PODS_DIR . 'ui/admin/help.php', compact( array_keys( get_defined_vars() ) ) );
|
| 2120 |
+
}
|
| 2121 |
+
|
| 2122 |
+
/**
|
| 2123 |
+
* Add pods specific capabilities.
|
| 2124 |
+
*
|
| 2125 |
+
* @param $capabilities List of extra capabilities to add
|
| 2126 |
+
*
|
| 2127 |
+
* @return array
|
| 2128 |
+
*/
|
| 2129 |
+
public function admin_capabilities ( $capabilities ) {
|
| 2130 |
+
$pods = pods_api()->load_pods( array( 'type' => array( 'pod', 'table', 'post_type', 'taxonomy', 'settings' ) ) );
|
| 2131 |
+
|
| 2132 |
+
$capabilities[] = 'pods';
|
| 2133 |
+
$capabilities[] = 'pods_content';
|
| 2134 |
+
$capabilities[] = 'pods_settings';
|
| 2135 |
+
$capabilities[] = 'pods_components';
|
| 2136 |
+
|
| 2137 |
+
foreach ( $pods as $pod ) {
|
| 2138 |
+
if ( 'settings' == $pod[ 'type' ] ) {
|
| 2139 |
+
$capabilities[] = 'pods_edit_' . $pod[ 'name' ];
|
| 2140 |
+
}
|
| 2141 |
+
elseif ( 'post_type' == $pod[ 'type' ] ) {
|
| 2142 |
+
$capability_type = pods_var( 'capability_type_custom', $pod[ 'options' ], pods_var_raw( 'name', $pod ) );
|
| 2143 |
+
|
| 2144 |
+
if ( 'custom' == pods_var( 'capability_type', $pod[ 'options' ] ) && 0 < strlen( $capability_type ) ) {
|
| 2145 |
+
$capabilities[] = 'read_' . $capability_type;
|
| 2146 |
+
$capabilities[] = 'edit_' . $capability_type;
|
| 2147 |
+
$capabilities[] = 'delete_' . $capability_type;
|
| 2148 |
+
|
| 2149 |
+
if ( 1 == pods_var( 'capability_type_extra', $pod[ 'options' ], 1 ) ) {
|
| 2150 |
+
$capabilities[] = 'read_private_' . $capability_type . 's';
|
| 2151 |
+
$capabilities[] = 'edit_' . $capability_type . 's';
|
| 2152 |
+
$capabilities[] = 'edit_others_' . $capability_type . 's';
|
| 2153 |
+
$capabilities[] = 'edit_private_' . $capability_type . 's';
|
| 2154 |
+
$capabilities[] = 'edit_published_' . $capability_type . 's';
|
| 2155 |
+
$capabilities[] = 'publish_' . $capability_type . 's';
|
| 2156 |
+
$capabilities[] = 'delete_' . $capability_type . 's';
|
| 2157 |
+
$capabilities[] = 'delete_private_' . $capability_type . 's';
|
| 2158 |
+
$capabilities[] = 'delete_published_' . $capability_type . 's';
|
| 2159 |
+
$capabilities[] = 'delete_others_' . $capability_type . 's';
|
| 2160 |
+
}
|
| 2161 |
+
}
|
| 2162 |
+
}
|
| 2163 |
+
elseif ( 'taxonomy' == $pod[ 'type' ] ) {
|
| 2164 |
+
if ( 1 == pods_var( 'capabilities', $pod[ 'options' ], 0 ) ) {
|
| 2165 |
+
$capability_type = pods_var( 'capability_type_custom', $pod[ 'options' ], pods_var_raw( 'name', $pod ) . 's' );
|
| 2166 |
+
|
| 2167 |
+
$capabilities[] = 'manage_' . $capability_type;
|
| 2168 |
+
$capabilities[] = 'edit_' . $capability_type;
|
| 2169 |
+
$capabilities[] = 'delete_' . $capability_type;
|
| 2170 |
+
$capabilities[] = 'assign_' . $capability_type;
|
| 2171 |
+
}
|
| 2172 |
+
}
|
| 2173 |
+
else {
|
| 2174 |
+
$capabilities[] = 'pods_add_' . $pod[ 'name' ];
|
| 2175 |
+
$capabilities[] = 'pods_edit_' . $pod[ 'name' ];
|
| 2176 |
+
|
| 2177 |
+
if ( isset( $pod[ 'fields' ][ 'author' ] ) && 'pick' == $pod[ 'fields' ][ 'author' ][ 'type' ] && 'user' == $pod[ 'fields' ][ 'author' ][ 'pick_object' ] )
|
| 2178 |
+
$capabilities[] = 'pods_edit_others_' . $pod[ 'name' ];
|
| 2179 |
+
|
| 2180 |
+
$capabilities[] = 'pods_delete_' . $pod[ 'name' ];
|
| 2181 |
+
|
| 2182 |
+
if ( isset( $pod[ 'fields' ][ 'author' ] ) && 'pick' == $pod[ 'fields' ][ 'author' ][ 'type' ] && 'user' == $pod[ 'fields' ][ 'author' ][ 'pick_object' ] )
|
| 2183 |
+
$capabilities[] = 'pods_delete_others_' . $pod[ 'name' ];
|
| 2184 |
+
|
| 2185 |
+
$actions_enabled = pods_var_raw( 'ui_actions_enabled', $pod[ 'options' ] );
|
| 2186 |
+
|
| 2187 |
+
if ( !empty( $actions_enabled ) )
|
| 2188 |
+
$actions_enabled = (array) $actions_enabled;
|
| 2189 |
+
else
|
| 2190 |
+
$actions_enabled = array();
|
| 2191 |
+
|
| 2192 |
+
$available_actions = array(
|
| 2193 |
+
'add',
|
| 2194 |
+
'edit',
|
| 2195 |
+
'duplicate',
|
| 2196 |
+
'delete',
|
| 2197 |
+
'reorder',
|
| 2198 |
+
'export'
|
| 2199 |
+
);
|
| 2200 |
+
|
| 2201 |
+
if ( !empty( $actions_enabled ) ) {
|
| 2202 |
+
$actions_disabled = array(
|
| 2203 |
+
'view' => 'view'
|
| 2204 |
+
);
|
| 2205 |
+
|
| 2206 |
+
foreach ( $available_actions as $action ) {
|
| 2207 |
+
if ( !in_array( $action, $actions_enabled ) )
|
| 2208 |
+
$actions_disabled[ $action ] = $action;
|
| 2209 |
+
}
|
| 2210 |
+
|
| 2211 |
+
if ( !in_array( 'export', $actions_disabled ) )
|
| 2212 |
+
$capabilities[] = 'pods_export_' . $pod[ 'name' ];
|
| 2213 |
+
|
| 2214 |
+
if ( !in_array( 'reorder', $actions_disabled ) )
|
| 2215 |
+
$capabilities[] = 'pods_reorder_' . $pod[ 'name' ];
|
| 2216 |
+
}
|
| 2217 |
+
elseif ( 1 == pods_var( 'ui_export', $pod[ 'options' ], 0 ) )
|
| 2218 |
+
$capabilities[] = 'pods_export_' . $pod[ 'name' ];
|
| 2219 |
+
}
|
| 2220 |
+
}
|
| 2221 |
+
|
| 2222 |
+
return $capabilities;
|
| 2223 |
+
}
|
| 2224 |
+
|
| 2225 |
+
/**
|
| 2226 |
+
* Handle ajax calls for the administration
|
| 2227 |
+
*/
|
| 2228 |
+
public function admin_ajax () {
|
| 2229 |
+
if ( false === headers_sent() ) {
|
| 2230 |
pods_session_start();
|
| 2231 |
|
| 2232 |
+
header( 'Content-Type: text/html; charset=' . get_bloginfo( 'charset' ) );
|
| 2233 |
+
}
|
| 2234 |
|
| 2235 |
+
// Sanitize input
|
| 2236 |
+
$params = pods_unslash( (array) $_POST );
|
|
|
|
| 2237 |
|
| 2238 |
foreach ( $params as $key => $value ) {
|
| 2239 |
+
if ( 'action' == $key )
|
| 2240 |
continue;
|
|
|
|
| 2241 |
|
| 2242 |
+
// Fixup $_POST data
|
| 2243 |
$_POST[ str_replace( '_podsfix_', '', $key ) ] = $_POST[ $key ];
|
| 2244 |
|
| 2245 |
// Fixup $params with unslashed data
|
| 2249 |
unset( $params[ $key ] );
|
| 2250 |
}
|
| 2251 |
|
| 2252 |
+
$params = (object) $params;
|
| 2253 |
|
| 2254 |
+
$methods = array(
|
| 2255 |
+
'add_pod' => array( 'priv' => true ),
|
| 2256 |
+
'save_pod' => array( 'priv' => true ),
|
| 2257 |
+
'load_sister_fields' => array( 'priv' => true ),
|
| 2258 |
+
'process_form' => array( 'custom_nonce' => true ), // priv handled through nonce
|
| 2259 |
+
'upgrade' => array( 'priv' => true ),
|
| 2260 |
+
'migrate' => array( 'priv' => true )
|
| 2261 |
+
);
|
|
|
|
| 2262 |
|
| 2263 |
+
$methods = apply_filters( 'pods_admin_ajax_methods', $methods, $this );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2264 |
|
| 2265 |
+
if ( !isset( $params->method ) || !isset( $methods[ $params->method ] ) )
|
| 2266 |
+
pods_error( 'Invalid AJAX request', $this );
|
|
|
|
| 2267 |
|
| 2268 |
+
$defaults = array(
|
| 2269 |
+
'priv' => null,
|
| 2270 |
+
'name' => $params->method,
|
| 2271 |
+
'custom_nonce' => null
|
| 2272 |
+
);
|
| 2273 |
|
| 2274 |
+
$method = (object) array_merge( $defaults, (array) $methods[ $params->method ] );
|
| 2275 |
|
| 2276 |
+
if ( true !== $method->custom_nonce && ( !isset( $params->_wpnonce ) || false === wp_verify_nonce( $params->_wpnonce, 'pods-' . $params->method ) ) )
|
| 2277 |
+
pods_error( __( 'Unauthorized request', 'pods' ), $this );
|
|
|
|
| 2278 |
|
| 2279 |
+
// Cleaning up $params
|
| 2280 |
+
unset( $params->action );
|
| 2281 |
+
unset( $params->method );
|
| 2282 |
|
| 2283 |
+
if ( true !== $method->custom_nonce )
|
| 2284 |
+
unset( $params->_wpnonce );
|
|
|
|
| 2285 |
|
| 2286 |
+
// Check permissions (convert to array to support multiple)
|
| 2287 |
+
if ( !empty( $method->priv ) && !pods_is_admin( array( 'pods' ) ) && true !== $method->priv && !pods_is_admin( $method->priv ) )
|
| 2288 |
+
pods_error( __( 'Access denied', 'pods' ), $this );
|
|
|
|
| 2289 |
|
| 2290 |
+
$params->method = $method->name;
|
| 2291 |
|
| 2292 |
+
$params = apply_filters( 'pods_api_' . $method->name, $params, $method );
|
| 2293 |
|
| 2294 |
+
$api = pods_api();
|
| 2295 |
|
| 2296 |
+
$api->display_errors = false;
|
| 2297 |
|
| 2298 |
+
if ( 'upgrade' == $method->name )
|
| 2299 |
+
$output = (string) pods_upgrade( $params->version )->ajax( $params );
|
| 2300 |
+
elseif ( 'migrate' == $method->name )
|
| 2301 |
+
$output = (string) apply_filters( 'pods_api_migrate_run', $params );
|
| 2302 |
+
else {
|
| 2303 |
+
if ( !method_exists( $api, $method->name ) )
|
| 2304 |
+
pods_error( 'API method does not exist', $this );
|
| 2305 |
+
elseif ( 'save_pod' == $method->name ) {
|
| 2306 |
+
if ( isset( $params->field_data_json ) && is_array( $params->field_data_json ) ) {
|
| 2307 |
+
$params->fields = $params->field_data_json;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2308 |
|
| 2309 |
+
unset( $params->field_data_json );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2310 |
|
| 2311 |
+
foreach ( $params->fields as $k => $v ) {
|
| 2312 |
+
if ( empty( $v ) )
|
| 2313 |
+
unset( $params->fields[ $k ] );
|
| 2314 |
+
elseif ( !is_array( $v ) )
|
| 2315 |
+
$params->fields[ $k ] = (array) @json_decode( $v, true );
|
| 2316 |
+
}
|
| 2317 |
+
}
|
| 2318 |
+
}
|
| 2319 |
+
|
| 2320 |
+
// Dynamically call the API method
|
| 2321 |
+
$params = (array) $params;
|
| 2322 |
+
|
| 2323 |
+
$output = call_user_func( array( $api, $method->name ), $params );
|
| 2324 |
+
}
|
| 2325 |
+
|
| 2326 |
+
// Output in json format
|
| 2327 |
+
if ( false !== $output ) {
|
| 2328 |
+
if ( is_array( $output ) || is_object( $output ) )
|
| 2329 |
+
wp_send_json( $output );
|
| 2330 |
+
else
|
| 2331 |
+
echo $output;
|
| 2332 |
+
}
|
| 2333 |
+
else
|
| 2334 |
+
pods_error( 'There was a problem with your request.' );
|
| 2335 |
+
|
| 2336 |
+
die(); // KBAI!
|
| 2337 |
+
}
|
| 2338 |
|
| 2339 |
/**
|
| 2340 |
* Profiles the Pods configuration
|
| 2341 |
*
|
| 2342 |
+
* @param null|string|array $pod. Optional. Which Pod(s) to get configuration for. Can be a the name of one Pod, or an array of names of Pods, or null, which is the default, to profile all Pods.
|
| 2343 |
+
* @param bool $full_field_info Optional. If true all info about each field is returned. If false, which is the default only name and type, will be returned.
|
|
|
|
|
|
|
|
|
|
| 2344 |
*
|
| 2345 |
* @return array
|
| 2346 |
*
|
| 2347 |
+
* @since 3.0.0
|
| 2348 |
*/
|
| 2349 |
+
function configuration( $pod = null, $full_field_info = false ){
|
|
|
|
| 2350 |
$api = pods_api();
|
| 2351 |
|
| 2352 |
+
if ( is_null( $pod ) ) {
|
| 2353 |
$the_pods = $api->load_pods();
|
| 2354 |
+
}
|
| 2355 |
+
elseif( is_array( $pod ) ) {
|
| 2356 |
foreach ( $pod as $p ) {
|
| 2357 |
$the_pods[] = $api->load_pod( $p );
|
| 2358 |
}
|
| 2359 |
+
}
|
| 2360 |
+
else {
|
| 2361 |
$the_pods[] = $api->load_pod( $pod );
|
| 2362 |
}
|
| 2363 |
|
| 2364 |
+
foreach( $the_pods as $pod ) {
|
| 2365 |
+
$configuration[ $pod[ 'name' ] ] = array(
|
| 2366 |
+
'name' => $pod['name'],
|
| 2367 |
+
'ID' => $pod[ 'id' ],
|
| 2368 |
+
'storage' => $pod[ 'storage' ],
|
| 2369 |
+
'fields' => $pod[ 'fields' ],
|
| 2370 |
);
|
| 2371 |
}
|
| 2372 |
|
| 2373 |
if ( ! $full_field_info ) {
|
| 2374 |
+
foreach ( $the_pods as $pod ) {
|
| 2375 |
+
$fields = $configuration[ $pod['name'] ][ 'fields' ];
|
| 2376 |
+
unset( $configuration[ $pod['name'] ][ 'fields' ] );
|
|
|
|
|
|
|
| 2377 |
foreach ( $fields as $field ) {
|
| 2378 |
+
$info = array (
|
| 2379 |
+
'name' => $field[ 'name' ],
|
| 2380 |
+
'type' => $field[ 'type' ],
|
| 2381 |
);
|
| 2382 |
|
| 2383 |
+
if ( $info[ 'type' ] === 'pick' ) {
|
| 2384 |
+
$info[ 'pick_object' ] = $field[ 'pick_object' ];
|
| 2385 |
+
if ( isset ( $field[ 'pick_val' ] ) && $field[ 'pick_val' ] !== '' ) {
|
| 2386 |
+
$info[ 'pick_val' ] = $field[ 'pick_val' ];
|
|
|
|
| 2387 |
}
|
| 2388 |
}
|
| 2389 |
|
| 2390 |
if ( is_array( $info ) ) {
|
| 2391 |
+
$configuration[ $pod[ 'name' ] ][ 'fields' ][ $field[ 'name' ] ] = $info;
|
| 2392 |
}
|
| 2393 |
|
| 2394 |
unset( $info );
|
| 2395 |
|
| 2396 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2397 |
|
| 2398 |
+
}
|
| 2399 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2400 |
}
|
| 2401 |
|
| 2402 |
+
if ( is_array ( $configuration ) ) {
|
| 2403 |
+
return $configuration;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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| 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 |
-
if ( ! $this->offsetExists( $offset ) ) {
|
| 120 |
-
$this->offsetSet( $offset, $default );
|
| 121 |
-
}
|
| 122 |
-
|
| 123 |
-
$value = $this->offsetGet( $offset );
|
| 124 |
-
|
| 125 |
-
if ( empty( $value ) && null !== $default && false !== $value ) {
|
| 126 |
-
$value = $default;
|
| 127 |
-
}
|
| 128 |
-
|
| 129 |
-
if ( 'array' === $type || 'array_merge' === $type ) {
|
| 130 |
-
if ( ! is_array( $value ) ) {
|
| 131 |
-
$value = explode( ',', $value );
|
| 132 |
-
}
|
| 133 |
-
|
| 134 |
-
if ( 'array_merge' === $type && $value !== $default ) {
|
| 135 |
-
$value = array_merge( $default, $value );
|
| 136 |
-
}
|
| 137 |
-
} elseif ( 'object' === $type || 'object_merge' === $type ) {
|
| 138 |
-
if ( ! is_object( $value ) ) {
|
| 139 |
-
if ( ! is_array( $value ) ) {
|
| 140 |
-
$value = explode( ',', $value );
|
| 141 |
-
}
|
| 142 |
-
$value = (object) $value;
|
| 143 |
-
}
|
| 144 |
-
|
| 145 |
-
if ( 'object_merge' === $type && $value !== $default ) {
|
| 146 |
-
$value = (object) array_merge( (array) $default, (array) $value );
|
| 147 |
-
}
|
| 148 |
-
} elseif ( 'integer' === $type || 'int' === $type || 'absint' === $type ) {
|
| 149 |
-
if ( ! is_numeric( trim( $value ) ) ) {
|
| 150 |
-
$value = 0;
|
| 151 |
-
} else {
|
| 152 |
-
$value = intval( $value );
|
| 153 |
-
}
|
| 154 |
-
|
| 155 |
-
if ( 'absint' === $type ) {
|
| 156 |
-
$value = abs( $value );
|
| 157 |
-
}
|
| 158 |
-
} elseif ( 'boolean' === $type || 'bool' === $type ) {
|
| 159 |
-
$value = (boolean) $value;
|
| 160 |
-
} elseif ( 'in_array' === $type && is_array( $default ) ) {
|
| 161 |
-
if ( is_array( $value ) ) {
|
| 162 |
-
foreach ( $value as $k => $v ) {
|
| 163 |
-
if ( ! in_array( $v, $extra, true ) ) {
|
| 164 |
-
unset( $value[ $k ] );
|
| 165 |
-
}
|
| 166 |
-
}
|
| 167 |
-
} elseif ( ! in_array( $value, $extra, true ) ) {
|
| 168 |
-
$value = $default;
|
| 169 |
-
}
|
| 170 |
-
} elseif ( 'isset' === $type && is_array( $default ) ) {
|
| 171 |
-
if ( is_array( $value ) ) {
|
| 172 |
-
foreach ( $value as $k => $v ) {
|
| 173 |
-
if ( ! isset( $extra[ $v ] ) ) {
|
| 174 |
-
unset( $value[ $k ] );
|
| 175 |
-
}
|
| 176 |
-
}
|
| 177 |
-
} elseif ( ! isset( $extra[ $value ] ) ) {
|
| 178 |
-
$value = $default;
|
| 179 |
-
}
|
| 180 |
-
}//end if
|
| 181 |
-
|
| 182 |
-
$this->offsetSet( $offset, $value );
|
| 183 |
-
|
| 184 |
-
return $value;
|
| 185 |
-
}
|
| 186 |
-
|
| 187 |
-
/**
|
| 188 |
-
* Dump the PodsArray object to array
|
| 189 |
-
*
|
| 190 |
-
* @return array Array version of the object
|
| 191 |
-
*
|
| 192 |
-
* @since 2.0.0
|
| 193 |
-
*/
|
| 194 |
-
public function dump() {
|
| 195 |
-
|
| 196 |
-
if ( is_array( $this->__container ) ) {
|
| 197 |
-
return $this->__container;
|
| 198 |
-
}
|
| 199 |
-
|
| 200 |
-
return get_object_vars( $this->__container );
|
| 201 |
-
}
|
| 202 |
-
|
| 203 |
-
/**
|
| 204 |
-
* Mapping >> offsetSet
|
| 205 |
-
*
|
| 206 |
-
* @param mixed $offset Property name.
|
| 207 |
-
* @param mixed $value Property value.
|
| 208 |
-
*
|
| 209 |
-
* @return mixed
|
| 210 |
-
* @since 2.0.0
|
| 211 |
-
*/
|
| 212 |
-
public function __set( $offset, $value ) {
|
| 213 |
-
|
| 214 |
-
return $this->offsetSet( $offset, $value );
|
| 215 |
-
}
|
| 216 |
-
|
| 217 |
-
/**
|
| 218 |
-
* Mapping >> offsetGet
|
| 219 |
-
*
|
| 220 |
-
* @param mixed $offset Property name.
|
| 221 |
-
*
|
| 222 |
-
* @return mixed|null
|
| 223 |
-
* @since 2.0.0
|
| 224 |
-
*/
|
| 225 |
-
public function __get( $offset ) {
|
| 226 |
-
|
| 227 |
-
return $this->offsetGet( $offset );
|
| 228 |
-
}
|
| 229 |
-
|
| 230 |
-
/**
|
| 231 |
-
* Mapping >> offsetExists
|
| 232 |
-
*
|
| 233 |
-
* @param mixed $offset Property name.
|
| 234 |
-
*
|
| 235 |
-
* @return bool
|
| 236 |
-
* @since 2.0.0
|
| 237 |
-
*/
|
| 238 |
-
public function __isset( $offset ) {
|
| 239 |
-
|
| 240 |
-
return $this->offsetExists( $offset );
|
| 241 |
-
}
|
| 242 |
-
|
| 243 |
-
/**
|
| 244 |
-
* Mapping >> offsetUnset
|
| 245 |
-
*
|
| 246 |
-
* @param mixed $offset Property name.
|
| 247 |
-
*
|
| 248 |
-
* @since 2.0.0
|
| 249 |
-
*/
|
| 250 |
-
public function __unset( $offset ) {
|
| 251 |
-
|
| 252 |
-
$this->offsetUnset( $offset );
|
| 253 |
-
}
|
| 1 |
<?php
|
|
|
|
| 2 |
/**
|
| 3 |
* @package Pods
|
| 4 |
*/
|
| 5 |
class PodsArray implements ArrayAccess {
|
| 6 |
|
| 7 |
+
/**
|
| 8 |
+
* @var array|mixed
|
| 9 |
+
*/
|
| 10 |
+
private $__container = array();
|
| 11 |
+
|
| 12 |
+
/**
|
| 13 |
+
* Alternative to get_object_vars to access an object as an array with simple functionality and accepts arrays to
|
| 14 |
+
* add additional functionality. Additional functionality includes validation and setting default data.
|
| 15 |
+
*
|
| 16 |
+
* @param mixed $container Object (or existing Array)
|
| 17 |
+
*
|
| 18 |
+
* @return \PodsArray
|
| 19 |
+
*
|
| 20 |
+
* @license http://www.gnu.org/licenses/gpl-2.0.html
|
| 21 |
+
* @since 2.0
|
| 22 |
+
*/
|
| 23 |
+
public function __construct ( $container ) {
|
| 24 |
+
if ( is_array( $container ) || is_object( $container ) )
|
| 25 |
+
$this->__container = &$container;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* Set value from array usage $object['offset'] = 'value';
|
| 30 |
+
*
|
| 31 |
+
* @param mixed $offset Used to set index of Array or Variable name on Object
|
| 32 |
+
* @param mixed $value Value to be set
|
| 33 |
+
*
|
| 34 |
+
* @return mixed|void
|
| 35 |
+
* @since 2.0
|
| 36 |
+
*/
|
| 37 |
+
public function offsetSet ( $offset, $value ) {
|
| 38 |
+
if ( is_array( $this->__container ) )
|
| 39 |
+
$this->__container[ $offset ] = $value;
|
| 40 |
+
else
|
| 41 |
+
$this->__container->$offset = $value;
|
| 42 |
+
return $value;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
/**
|
| 46 |
+
* Get value from array usage $object['offset'];
|
| 47 |
+
*
|
| 48 |
+
* @param mixed $offset Used to get value of Array or Variable on Object
|
| 49 |
+
*
|
| 50 |
+
* @return mixed|null
|
| 51 |
+
* @since 2.0
|
| 52 |
+
*/
|
| 53 |
+
public function offsetGet ( $offset ) {
|
| 54 |
+
if ( is_array( $this->__container ) ) {
|
| 55 |
+
if ( isset( $this->__container[ $offset ] ) )
|
| 56 |
+
return $this->__container[ $offset ];
|
| 57 |
+
return null;
|
| 58 |
+
}
|
| 59 |
+
if ( isset( $this->__container->$offset ) )
|
| 60 |
+
return $this->__container->$offset;
|
| 61 |
+
return null;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
/**
|
| 65 |
+
* Get value from array usage $object['offset'];
|
| 66 |
+
*
|
| 67 |
+
* @param mixed $offset Used to get value of Array or Variable on Object
|
| 68 |
+
*
|
| 69 |
+
* @return bool
|
| 70 |
+
* @since 2.0
|
| 71 |
+
*/
|
| 72 |
+
public function offsetExists ( $offset ) {
|
| 73 |
+
if ( is_array( $this->__container ) )
|
| 74 |
+
return isset( $this->__container[ $offset ] );
|
| 75 |
+
return isset( $this->__container->$offset );
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
/**
|
| 79 |
+
* Get value from array usage $object['offset'];
|
| 80 |
+
*
|
| 81 |
+
* @param mixed $offset Used to unset index of Array or Variable on Object
|
| 82 |
+
*
|
| 83 |
+
* @since 2.0
|
| 84 |
+
*/
|
| 85 |
+
public function offsetUnset ( $offset ) {
|
| 86 |
+
if ( is_array( $this->__container ) )
|
| 87 |
+
unset( $this->__container[ $offset ] );
|
| 88 |
+
else
|
| 89 |
+
unset( $this->__container->$offset );
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
/**
|
| 93 |
+
* Validate value on a specific type and set default (if empty)
|
| 94 |
+
*
|
| 95 |
+
* @param mixed $offset Used to get value of Array or Variable on Object
|
| 96 |
+
* @param mixed $default Used to set default value if it doesn't exist
|
| 97 |
+
* @param string $type Used to force a specific type of variable (allowed: array, object, integer, absint, boolean)
|
| 98 |
+
* @param mixed $extra Used in advanced types of variables
|
| 99 |
+
*
|
| 100 |
+
* @return array|bool|int|mixed|null|number|object
|
| 101 |
+
* @since 2.0
|
| 102 |
+
*/
|
| 103 |
+
public function validate ( $offset, $default = null, $type = null, $extra = null ) {
|
| 104 |
+
if ( !$this->offsetExists( $offset ) )
|
| 105 |
+
$this->offsetSet( $offset, $default );
|
| 106 |
+
|
| 107 |
+
$value = $this->offsetGet( $offset );
|
| 108 |
+
|
| 109 |
+
if ( empty( $value ) && null !== $default && false !== $value )
|
| 110 |
+
$value = $default;
|
| 111 |
+
if ( 'array' == $type || 'array_merge' == $type ) {
|
| 112 |
+
if ( !is_array( $value ) )
|
| 113 |
+
$value = explode( ',', $value );
|
| 114 |
+
|
| 115 |
+
if ( 'array_merge' == $type && $value !== $default )
|
| 116 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
