PageRenderTime 62ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/classes/PodsAPI.php

https://github.com/ElmsPark/pods
PHP | 6128 lines | 3893 code | 1196 blank | 1039 comment | 1248 complexity | ec4c5a41cc728c74d964fb5f059538e3 MD5 | raw file
Possible License(s): AGPL-1.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * @package Pods
  4. */
  5. class PodsAPI {
  6. /**
  7. * @var bool
  8. */
  9. public $display_errors = false;
  10. /**
  11. * @var array|bool|mixed|null|void
  12. */
  13. public $pod_data;
  14. /**
  15. * @var
  16. */
  17. public $pod;
  18. /**
  19. * @var
  20. */
  21. public $pod_id;
  22. /**
  23. * @var
  24. */
  25. public $fields;
  26. /**
  27. * @var
  28. * @deprecated 2.0.0
  29. */
  30. public $format = null;
  31. /**
  32. * @var
  33. */
  34. private $deprecated;
  35. /**
  36. * Store and retrieve data programatically
  37. *
  38. * @param string $pod (optional) The pod name
  39. * @param string $format (deprecated) Format for import/export, "php" or "csv"
  40. *
  41. * @license http://www.gnu.org/licenses/gpl-2.0.html
  42. * @since 1.7.1
  43. */
  44. public function __construct ( $pod = null, $format = null ) {
  45. if ( null !== $pod && 0 < strlen( (string) $pod ) ) {
  46. if ( null !== $format ) {
  47. $this->format = $format;
  48. pods_deprecated( 'pods_api( $pod, $format )', '2.0.0', 'pods_api( $pod )' );
  49. }
  50. $pod = pods_clean_name( $pod );
  51. $pod = $this->load_pod( array( 'name' => $pod ), false );
  52. if ( !empty( $pod ) ) {
  53. $this->pod_data = $pod;
  54. $this->pod = $pod[ 'name' ];
  55. $this->pod_id = $pod[ 'id' ];
  56. $this->fields = $pod[ 'fields' ];
  57. }
  58. }
  59. }
  60. /**
  61. * Save a WP object and its meta
  62. *
  63. * @param string $object_type Object type: post|user|comment
  64. * @param array $data All post data to be saved
  65. * @param array $meta (optional) Associative array of meta keys and values
  66. * @param bool $strict (optional) Decides whether the previous saved meta should be deleted or not
  67. * @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before sending.
  68. *
  69. * @return bool|mixed
  70. *
  71. * @since 2.0.0
  72. */
  73. public function save_wp_object ( $object_type, $data, $meta = array(), $strict = false, $sanitized = false ) {
  74. if ( in_array( $object_type, array( 'post_type', 'media' ) ) )
  75. $object_type = 'post';
  76. if ( $sanitized ) {
  77. $data = pods_unsanitize( $data );
  78. $meta = pods_unsanitize( $meta );
  79. }
  80. if ( in_array( $object_type, array( 'post', 'user', 'comment' ) ) )
  81. return call_user_func( array( $this, 'save_' . $object_type ), $data, $meta, $strict, false );
  82. return false;
  83. }
  84. /**
  85. * Delete a WP object
  86. *
  87. * @param string $object_type Object type: post|user|comment
  88. * @param int $id Object ID
  89. * @param bool $force_delete (optional) Force deletion instead of trashing (post types only)
  90. *
  91. * @return bool|mixed
  92. *
  93. * @since 2.0.0
  94. */
  95. public function delete_wp_object ( $object_type, $id, $force_delete = true ) {
  96. if ( in_array( $object_type, array( 'post_type', 'media' ) ) )
  97. $object_type = 'post';
  98. if ( empty( $id ) )
  99. return false;
  100. if ( in_array( $object_type, array( 'post' ) ) )
  101. return wp_delete_post( $id, $force_delete );
  102. if ( function_exists( 'wp_delete_' . $object_type ) )
  103. return call_user_func( 'wp_delete_' . $object_type, $id );
  104. return false;
  105. }
  106. /**
  107. * Save a post and it's meta
  108. *
  109. * @param array $post_data All post data to be saved (using wp_insert_post / wp_update_post)
  110. * @param array $post_meta (optional) All meta to be saved (set value to null to delete)
  111. * @param bool $strict (optional) Whether to delete previously saved meta not in $post_meta
  112. * @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before sending.
  113. * @return mixed|void
  114. */
  115. public function save_post ( $post_data, $post_meta = null, $strict = false, $sanitized = false ) {
  116. pods_no_conflict_on( 'post' );
  117. if ( !is_array( $post_data ) || empty( $post_data ) )
  118. $post_data = array( 'post_title' => '' );
  119. if ( !is_array( $post_meta ) )
  120. $post_meta = array();
  121. if ( $sanitized ) {
  122. $post_data = pods_unsanitize( $post_data );
  123. $post_meta = pods_unsanitize( $post_meta );
  124. }
  125. if ( !isset( $post_data[ 'ID' ] ) || empty( $post_data[ 'ID' ] ) )
  126. $post_data[ 'ID' ] = wp_insert_post( $post_data, true );
  127. elseif ( 2 < count( $post_data ) || !isset( $post_data[ 'post_type' ] ) )
  128. wp_update_post( $post_data );
  129. if ( is_wp_error( $post_data[ 'ID' ] ) ) {
  130. pods_no_conflict_off( 'post' );
  131. /**
  132. * @var $post_error WP_Error
  133. */
  134. $post_error = $post_data[ 'ID' ];
  135. return pods_error( $post_error->get_error_message(), $this );
  136. }
  137. $this->save_post_meta( $post_data[ 'ID' ], $post_meta, $strict );
  138. pods_no_conflict_off( 'post' );
  139. return $post_data[ 'ID' ];
  140. }
  141. /**
  142. * Save a post's meta
  143. *
  144. * @param int $id Post ID
  145. * @param array $post_meta All meta to be saved (set value to null to delete)
  146. * @param bool $strict Whether to delete previously saved meta not in $post_meta
  147. *
  148. * @return int Id of the post with the meta
  149. *
  150. * @since 2.0.0
  151. */
  152. public function save_post_meta ( $id, $post_meta = null, $strict = false ) {
  153. pods_no_conflict_on( 'post' );
  154. if ( !is_array( $post_meta ) )
  155. $post_meta = array();
  156. $id = (int) $id;
  157. $meta = get_post_meta( $id );
  158. foreach ( $meta as &$value ) {
  159. if ( is_array( $value ) && 1 == count( $value ) && isset( $value[ 0 ] ) )
  160. $value = $value[ 0 ];
  161. }
  162. foreach ( $post_meta as $meta_key => $meta_value ) {
  163. if ( null === $meta_value ) {
  164. $old_meta_value = '';
  165. if ( isset( $meta[ $meta_key ] ) )
  166. $old_meta_value = $meta[ $meta_key ];
  167. delete_post_meta( $id, $meta_key, $old_meta_value );
  168. }
  169. else
  170. update_post_meta( $id, $meta_key, $meta_value );
  171. }
  172. if ( $strict ) {
  173. foreach ( $meta as $meta_key => $meta_value ) {
  174. if ( !isset( $post_meta[ $meta_key ] ) )
  175. delete_post_meta( $id, $meta_key, $meta_value );
  176. }
  177. }
  178. pods_no_conflict_off( 'post' );
  179. return $id;
  180. }
  181. /**
  182. * Save a user and it's meta
  183. *
  184. * @param array $user_data All user data to be saved (using wp_insert_user / wp_update_user)
  185. * @param array $user_meta (optional) All meta to be saved (set value to null to delete)
  186. * @param bool $strict (optional) Whether to delete previously saved meta not in $user_meta
  187. * @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before sending.
  188. *
  189. * @return int Returns user id on success
  190. *
  191. * @since 2.0.0
  192. */
  193. public function save_user ( $user_data, $user_meta = null, $strict = false, $sanitized = false ) {
  194. if ( !is_array( $user_data ) || empty( $user_data ) )
  195. return pods_error( __( 'User data is required but is either invalid or empty', 'pods' ), $this );
  196. pods_no_conflict_on( 'user' );
  197. if ( !is_array( $user_meta ) )
  198. $user_meta = array();
  199. if ( $sanitized ) {
  200. $user_data = pods_unsanitize( $user_data );
  201. $user_meta = pods_unsanitize( $user_meta );
  202. }
  203. if ( !isset( $user_data[ 'ID' ] ) || empty( $user_data[ 'ID' ] ) )
  204. $user_data[ 'ID' ] = wp_insert_user( $user_data );
  205. else
  206. wp_update_user( $user_data );
  207. if ( is_wp_error( $user_data[ 'ID' ] ) ) {
  208. pods_no_conflict_off( 'user' );
  209. /**
  210. * @var $user_error WP_Error
  211. */
  212. $user_error = $user_data[ 'ID' ];
  213. return pods_error( $user_error->get_error_message(), $this );
  214. }
  215. $this->save_user_meta( $user_data[ 'ID' ], $user_meta, $strict );
  216. pods_no_conflict_off( 'user' );
  217. return $user_data[ 'ID' ];
  218. }
  219. /**
  220. * Save a user meta
  221. *
  222. * @param int $id User ID
  223. * @param array $user_meta (optional) All meta to be saved (set value to null to delete)
  224. * @param bool $strict (optional) Whether to delete previously saved meta not in $user_meta
  225. *
  226. * @return int User ID
  227. *
  228. * @since 2.0.0
  229. *
  230. */
  231. public function save_user_meta ( $id, $user_meta = null, $strict = false ) {
  232. pods_no_conflict_on( 'user' );
  233. if ( !is_array( $user_meta ) )
  234. $user_meta = array();
  235. $id = (int) $id;
  236. $meta = get_user_meta( $id );
  237. foreach ( $user_meta as $meta_key => $meta_value ) {
  238. if ( null === $meta_value ) {
  239. $old_meta_value = '';
  240. if ( isset( $meta[ $meta_key ] ) )
  241. $old_meta_value = $meta[ $meta_key ];
  242. delete_user_meta( $id, $meta_key, $old_meta_value );
  243. }
  244. else
  245. update_user_meta( $id, $meta_key, $meta_value );
  246. }
  247. if ( $strict ) {
  248. foreach ( $meta as $meta_key => $meta_value ) {
  249. if ( !isset( $user_meta[ $meta_key ] ) )
  250. delete_user_meta( $id, $meta_key, $user_meta[ $meta_key ] );
  251. }
  252. }
  253. pods_no_conflict_off( 'user' );
  254. return $id;
  255. }
  256. /**
  257. * Save a comment and it's meta
  258. *
  259. * @param array $comment_data All comment data to be saved (using wp_insert_comment / wp_update_comment)
  260. * @param array $comment_meta (optional) All meta to be saved (set value to null to delete)
  261. * @param bool $strict (optional) Whether to delete previously saved meta not in $comment_meta
  262. * @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before sending.
  263. *
  264. * @return int Comment ID
  265. *
  266. * @since 2.0.0
  267. */
  268. public function save_comment ( $comment_data, $comment_meta = null, $strict = false, $sanitized = false ) {
  269. if ( !is_array( $comment_data ) || empty( $comment_data ) )
  270. return pods_error( __( 'Comment data is required but is either invalid or empty', 'pods' ), $this );
  271. pods_no_conflict_on( 'comment' );
  272. if ( !is_array( $comment_meta ) )
  273. $comment_meta = array();
  274. if ( $sanitized ) {
  275. $comment_data = pods_unsanitize( $comment_data );
  276. $comment_meta = pods_unsanitize( $comment_meta );
  277. }
  278. if ( !isset( $comment_data[ 'comment_ID' ] ) || empty( $comment_data[ 'comment_ID' ] ) )
  279. $comment_data[ 'comment_ID' ] = wp_insert_comment( $comment_data );
  280. else
  281. wp_update_comment( $comment_data );
  282. if ( is_wp_error( $comment_data[ 'comment_ID' ] ) ) {
  283. pods_no_conflict_off( 'comment' );
  284. /**
  285. * @var $comment_error WP_Error
  286. */
  287. $comment_error = $comment_data[ 'comment_ID' ];
  288. return pods_error( $comment_error->get_error_message(), $this );
  289. }
  290. $this->save_comment_meta( $comment_data[ 'comment_ID' ], $comment_meta, $strict );
  291. pods_no_conflict_off( 'comment' );
  292. return $comment_data[ 'comment_ID' ];
  293. }
  294. /**
  295. * Save a comment meta
  296. *
  297. * @param int $id Comment ID
  298. * @param array $comment_meta (optional) All meta to be saved (set value to null to delete)
  299. * @param bool $strict (optional) Whether to delete previously saved meta not in $comment_meta
  300. *
  301. * @return int Comment ID
  302. *
  303. * @since 2.0.0
  304. */
  305. public function save_comment_meta ( $id, $comment_meta = null, $strict = false ) {
  306. pods_no_conflict_on( 'comment' );
  307. if ( !is_array( $comment_meta ) )
  308. $comment_meta = array();
  309. $id = (int) $id;
  310. $meta = get_comment_meta( $id );
  311. foreach ( $comment_meta as $meta_key => $meta_value ) {
  312. if ( null === $meta_value ) {
  313. $old_meta_value = '';
  314. if ( isset( $meta[ $meta_key ] ) )
  315. $old_meta_value = $meta[ $meta_key ];
  316. delete_comment_meta( $id, $meta_key, $old_meta_value );
  317. }
  318. else
  319. update_comment_meta( $id, $meta_key, $meta_value );
  320. }
  321. if ( $strict ) {
  322. foreach ( $meta as $meta_key => $meta_value ) {
  323. if ( !isset( $comment_meta[ $meta_key ] ) )
  324. delete_comment_meta( (int) $id, $meta_key, $comment_meta[ $meta_key ] );
  325. }
  326. }
  327. pods_no_conflict_off( 'comment' );
  328. return $id;
  329. }
  330. /**
  331. * Save a taxonomy's term
  332. *
  333. * @param int $term_ID Term ID, leave empty to add
  334. * @param string $term Term name
  335. * @param string $taxonomy Taxonomy name
  336. * @param array $term_data All term data to be saved (using wp_insert_term / wp_update_term)
  337. * @param bool $sanitized (optional) Will unsanitize the data, should be passed if the data is sanitized before sending.
  338. *
  339. * @return int Term ID
  340. *
  341. * @since 2.0.0
  342. */
  343. public function save_term ( $term_ID, $term, $taxonomy, $term_data, $sanitized = false ) {
  344. pods_no_conflict_on( 'taxonomy' );
  345. if ( !is_array( $term_data ) )
  346. $term_data = array();
  347. $term_ID = (int) $term_ID;
  348. if ( $sanitized ) {
  349. $term = pods_unsanitize( $term );
  350. $taxonomy = pods_unsanitize( $taxonomy );
  351. $term_data = pods_unsanitize( $term_data );
  352. }
  353. if ( empty( $term_ID ) )
  354. $term_ID = wp_insert_term( $term, $taxonomy, $term_data );
  355. else {
  356. if ( 0 < strlen( $term ) )
  357. $term_data[ 'term' ] = $term;
  358. if ( empty( $term_data ) ) {
  359. pods_no_conflict_off( 'taxonomy' );
  360. return pods_error( __( 'Taxonomy term data is required but is either invalid or empty', 'pods' ), $this );
  361. }
  362. wp_update_term( $term_ID, $taxonomy, $term_data );
  363. }
  364. if ( is_wp_error( $term_ID ) ) {
  365. pods_no_conflict_off( 'taxonomy' );
  366. return pods_error( $term_ID->get_error_message(), $this );
  367. }
  368. elseif ( is_array( $term_ID ) )
  369. $term_ID = $term_ID[ 'term_id' ];
  370. pods_no_conflict_off( 'taxonomy' );
  371. return $term_ID;
  372. }
  373. /**
  374. * Rename a WP object's type
  375. *
  376. * @param string $object_type Object type: post|taxonomy|comment
  377. * @param string $old_name The old name
  378. * @param string $new_name The new name
  379. *
  380. * @return bool
  381. *
  382. * @since 2.0.0
  383. */
  384. public function rename_wp_object_type ( $object_type, $old_name, $new_name ) {
  385. /**
  386. * @var $wpdb wpdb
  387. */
  388. global $wpdb;
  389. if ( 'post_type' == $object_type )
  390. $object_type = 'post';
  391. if ( 'post' == $object_type ) {
  392. pods_query( "UPDATE `{$wpdb->posts}` SET `post_type` = %s WHERE `post_type` = %s", array(
  393. $new_name,
  394. $old_name
  395. ) );
  396. }
  397. elseif ( 'taxonomy' == $object_type ) {
  398. pods_query( "UPDATE `{$wpdb->term_taxonomy}` SET `taxonomy` = %s WHERE `taxonomy` = %s", array(
  399. $new_name,
  400. $old_name
  401. ) );
  402. }
  403. elseif ( 'comment' == $object_type ) {
  404. pods_query( "UPDATE `{$wpdb->comments}` SET `comment_type` = %s WHERE `comment_type` = %s", array(
  405. $new_name,
  406. $old_name
  407. ) );
  408. }
  409. return true;
  410. }
  411. /**
  412. * Get a list of core WP object fields for a specific object
  413. *
  414. * @param string $object The post type to look for, possible values: post_type, user, comment, taxonomy
  415. * @param array $pod Array of Pod data
  416. * @param boolean $refresh Whether to force refresh the information
  417. *
  418. * @return array Array of fields
  419. */
  420. public function get_wp_object_fields ( $object = 'post_type', $pod = null, $refresh = false ) {
  421. $pod_name = pods_var_raw( 'name', $pod );
  422. $fields = pods_transient_get( trim( 'pods_api_object_fields_' . $object . $pod_name . '_', '_' ) );
  423. if ( false !== $fields && !$refresh )
  424. return $this->do_hook( 'get_wp_object_fields', $fields, $object, $pod );
  425. $fields = array();
  426. if ( 'post_type' == $object ) {
  427. $fields = array(
  428. 'post_title' => array(
  429. 'name' => 'post_title',
  430. 'label' => 'Title',
  431. 'type' => 'text',
  432. 'alias' => array( 'title', 'name' )
  433. ),
  434. 'post_content' => array(
  435. 'name' => 'post_content',
  436. 'label' => 'Content',
  437. 'type' => 'wysiwyg',
  438. 'alias' => array( 'content' ),
  439. 'options' => array(
  440. 'wysiwyg_allow_html' => 1,
  441. 'wysiwyg_allowed_html_tags' => '',
  442. 'display_filter' => 'the_content',
  443. 'pre_save' => 0
  444. )
  445. ),
  446. 'post_excerpt' => array(
  447. 'name' => 'post_excerpt',
  448. 'label' => 'Excerpt',
  449. 'type' => 'paragraph',
  450. 'alias' => array( 'excerpt' ),
  451. 'options' => array(
  452. 'paragraph_allow_html' => 1,
  453. 'paragraph_allowed_html_tags' => '',
  454. 'display_filter' => 'the_excerpt',
  455. 'pre_save' => 0
  456. )
  457. ),
  458. 'post_author' => array(
  459. 'name' => 'post_author',
  460. 'label' => 'Author',
  461. 'type' => 'pick',
  462. 'alias' => array( 'author' ),
  463. 'pick_object' => 'user',
  464. 'options' => array(
  465. 'pick_format_type' => 'single',
  466. 'pick_format_single' => 'autocomplete',
  467. 'default_value' => '{@user.ID}'
  468. )
  469. ),
  470. 'post_date' => array(
  471. 'name' => 'post_date',
  472. 'label' => 'Publish Date',
  473. 'type' => 'datetime',
  474. 'alias' => array( 'created', 'date' )
  475. ),
  476. 'post_date_gmt' => array(
  477. 'name' => 'post_date_gmt',
  478. 'label' => 'Publish Date (GMT)',
  479. 'type' => 'datetime',
  480. 'alias' => array(),
  481. 'hidden' => true
  482. ),
  483. 'post_status' => array(
  484. 'name' => 'post_status',
  485. 'label' => 'Status',
  486. 'type' => 'pick',
  487. 'pick_object' => 'post-status',
  488. 'default' => $this->do_hook( 'default_status_' . pods_var_raw( 'name', $pod, $object, null, true ), pods_var( 'default_status', pods_var_raw( 'options', $pod ), 'draft', null, true ), $pod ),
  489. 'alias' => array( 'status' )
  490. ),
  491. 'comment_status' => array(
  492. 'name' => 'comment_status',
  493. 'label' => 'Comment Status',
  494. 'type' => 'text',
  495. 'default' => get_option( 'default_comment_status', 'open' ),
  496. 'alias' => array(),
  497. 'data' => array(
  498. 'open' => __( 'Open', 'pods' ),
  499. 'closed' => __( 'Closed', 'pods' )
  500. )
  501. ),
  502. 'ping_status' => array(
  503. 'name' => 'ping_status',
  504. 'label' => 'Ping Status',
  505. 'default' => get_option( 'default_ping_status', 'open' ),
  506. 'type' => 'text',
  507. 'alias' => array(),
  508. 'data' => array(
  509. 'open' => __( 'Open', 'pods' ),
  510. 'closed' => __( 'Closed', 'pods' )
  511. )
  512. ),
  513. 'post_password' => array(
  514. 'name' => 'post_password',
  515. 'label' => 'Password',
  516. 'type' => 'text',
  517. 'alias' => array()
  518. ),
  519. 'post_name' => array(
  520. 'name' => 'post_name',
  521. 'label' => 'Permalink',
  522. 'type' => 'slug',
  523. 'alias' => array( 'slug', 'permalink' )
  524. ),
  525. 'to_ping' => array(
  526. 'name' => 'to_ping',
  527. 'label' => 'To Ping',
  528. 'type' => 'text',
  529. 'alias' => array(),
  530. 'hidden' => true
  531. ),
  532. 'pinged' => array(
  533. 'name' => 'pinged',
  534. 'label' => 'Pinged',
  535. 'type' => 'text',
  536. 'alias' => array(),
  537. 'hidden' => true
  538. ),
  539. 'post_modified' => array(
  540. 'name' => 'post_modified',
  541. 'label' => 'Last Modified Date',
  542. 'type' => 'datetime',
  543. 'alias' => array( 'modified' ),
  544. 'hidden' => true
  545. ),
  546. 'post_modified_gmt' => array(
  547. 'name' => 'post_modified_gmt',
  548. 'label' => 'Last Modified Date (GMT)',
  549. 'type' => 'datetime',
  550. 'alias' => array(),
  551. 'hidden' => true
  552. ),
  553. 'post_content_filtered' => array(
  554. 'name' => 'post_content_filtered',
  555. 'label' => 'Content (filtered)',
  556. 'type' => 'paragraph',
  557. 'alias' => array(),
  558. 'hidden' => true,
  559. 'options' => array(
  560. 'paragraph_allow_html' => 1,
  561. 'paragraph_oembed' => 1,
  562. 'paragraph_wptexturize' => 1,
  563. 'paragraph_convert_chars' => 1,
  564. 'paragraph_wpautop' => 1,
  565. 'paragraph_allow_shortcode' => 1,
  566. 'paragraph_allowed_html_tags' => ''
  567. )
  568. ),
  569. 'post_parent' => array(
  570. 'name' => 'post_parent',
  571. 'label' => 'Parent',
  572. 'type' => 'pick',
  573. 'pick_object' => 'post_type',
  574. 'alias' => array( 'parent' ),
  575. 'data' => array(),
  576. 'hidden' => true
  577. ),
  578. 'guid' => array(
  579. 'name' => 'guid',
  580. 'label' => 'GUID',
  581. 'type' => 'text',
  582. 'alias' => array(),
  583. 'hidden' => true
  584. ),
  585. 'menu_order' => array(
  586. 'name' => 'menu_order',
  587. 'label' => 'Menu Order',
  588. 'type' => 'number',
  589. 'alias' => array()
  590. ),
  591. 'post_type' => array(
  592. 'name' => 'post_type',
  593. 'label' => 'Type',
  594. 'type' => 'text',
  595. 'alias' => array( 'type' ),
  596. 'hidden' => true
  597. ),
  598. 'post_mime_type' => array(
  599. 'name' => 'post_mime_type',
  600. 'label' => 'Mime Type',
  601. 'type' => 'text',
  602. 'alias' => array(),
  603. 'hidden' => true
  604. ),
  605. 'comment_count' => array(
  606. 'name' => 'comment_count',
  607. 'label' => 'Comment Count',
  608. 'type' => 'number',
  609. 'alias' => array(),
  610. 'hidden' => true
  611. )
  612. );
  613. if ( !empty( $pod ) ) {
  614. $taxonomies = get_object_taxonomies( pods_var_raw( 'name', $pod ), 'objects' );
  615. foreach ( $taxonomies as $taxonomy ) {
  616. $fields[ $taxonomy->name ] = array(
  617. 'name' => $taxonomy->name,
  618. 'label' => $taxonomy->labels->name,
  619. 'type' => 'taxonomy',
  620. 'alias' => array(),
  621. 'hidden' => true
  622. );
  623. }
  624. }
  625. }
  626. elseif ( 'user' == $object ) {
  627. $fields = array(
  628. 'user_login' => array(
  629. 'name' => 'user_login',
  630. 'label' => 'Title',
  631. 'type' => 'text',
  632. 'alias' => array( 'login' ),
  633. 'options' => array(
  634. 'required' => 1
  635. )
  636. ),
  637. 'user_nicename' => array(
  638. 'name' => 'user_nicename',
  639. 'label' => 'Permalink',
  640. 'type' => 'slug',
  641. 'alias' => array( 'nicename', 'slug', 'permalink' )
  642. ),
  643. 'display_name' => array(
  644. 'name' => 'display_name',
  645. 'label' => 'Display Name',
  646. 'type' => 'text',
  647. 'alias' => array( 'title', 'name' )
  648. ),
  649. 'user_pass' => array(
  650. 'name' => 'user_pass',
  651. 'label' => 'Password',
  652. 'type' => 'text',
  653. 'alias' => array( 'password', 'pass' ),
  654. 'options' => array(
  655. 'required' => 1,
  656. 'text_format_type' => 'password'
  657. )
  658. ),
  659. 'user_email' => array(
  660. 'name' => 'user_email',
  661. 'label' => 'E-mail',
  662. 'type' => 'text',
  663. 'alias' => array( 'email' ),
  664. 'options' => array(
  665. 'required' => 1,
  666. 'text_format_type' => 'email'
  667. )
  668. ),
  669. 'user_url' => array(
  670. 'name' => 'user_url',
  671. 'label' => 'URL',
  672. 'type' => 'text',
  673. 'alias' => array( 'url', 'website' ),
  674. 'options' => array(
  675. 'required' => 1,
  676. 'text_format_type' => 'website',
  677. 'text_format_website' => 'normal'
  678. )
  679. ),
  680. 'user_registered' => array(
  681. 'name' => 'user_registered',
  682. 'label' => 'Registration Date',
  683. 'type' => 'date',
  684. 'alias' => array( 'created', 'date', 'registered' ),
  685. 'options' => array(
  686. 'date_format_type' => 'datetime'
  687. )
  688. )
  689. );
  690. }
  691. elseif ( 'comment' == $object ) {
  692. $fields = array(
  693. 'comment_content' => array(
  694. 'name' => 'comment_content',
  695. 'label' => 'Content',
  696. 'type' => 'wysiwyg',
  697. 'alias' => array( 'content' )
  698. ),
  699. 'comment_approved' => array(
  700. 'name' => 'comment_approved',
  701. 'label' => 'Approved',
  702. 'type' => 'number',
  703. 'alias' => array( 'approved' )
  704. ),
  705. 'comment_post_ID' => array(
  706. 'name' => 'comment_post_ID',
  707. 'label' => 'Post',
  708. 'type' => 'pick',
  709. 'alias' => array( 'post', 'post_id' ),
  710. 'data' => array()
  711. ),
  712. 'user_id' => array(
  713. 'name' => 'user_id',
  714. 'label' => 'Author',
  715. 'type' => 'pick',
  716. 'alias' => array( 'author' ),
  717. 'pick_object' => 'user',
  718. 'data' => array()
  719. ),
  720. 'comment_date' => array(
  721. 'name' => 'comment_date',
  722. 'label' => 'Date',
  723. 'type' => 'date',
  724. 'alias' => array( 'created', 'date' ),
  725. 'options' => array(
  726. 'date_format_type' => 'datetime'
  727. )
  728. )
  729. );
  730. }
  731. elseif ( 'taxonomy' == $object ) {
  732. $fields = array(
  733. 'name' => array(
  734. 'name' => 'name',
  735. 'label' => 'Title',
  736. 'type' => 'text',
  737. 'alias' => array( 'title' )
  738. ),
  739. 'slug' => array(
  740. 'name' => 'slug',
  741. 'label' => 'Permalink',
  742. 'type' => 'slug',
  743. 'alias' => array( 'permalink' )
  744. ),
  745. 'description' => array(
  746. 'name' => 'description',
  747. 'label' => 'Description',
  748. 'type' => 'wysiwyg',
  749. 'alias' => array( 'content' )
  750. ),
  751. 'taxonomy' => array(
  752. 'name' => 'taxonomy',
  753. 'label' => 'Taxonomy',
  754. 'type' => 'pick',
  755. 'alias' => array()
  756. )
  757. );
  758. }
  759. $fields = $this->do_hook( 'get_wp_object_fields', $fields, $object, $pod );
  760. foreach ( $fields as $field => $options ) {
  761. if ( !isset( $options[ 'alias' ] ) )
  762. $options[ 'alias' ] = array();
  763. else
  764. $options[ 'alias' ] = (array) $options[ 'alias' ];
  765. if ( !isset( $options[ 'name' ] ) )
  766. $options[ 'name' ] = $field;
  767. $fields[ $field ] = $options;
  768. }
  769. $fields = PodsForm::fields_setup( $fields );
  770. if ( did_action( 'init' ) )
  771. pods_transient_set( trim( 'pods_api_object_fields_' . $object . $pod_name . '_', '_' ), $fields );
  772. return $fields;
  773. }
  774. /**
  775. *
  776. * @see PodsAPI::save_pod
  777. *
  778. * Add a Pod via the Wizard
  779. *
  780. * $params['create_extend'] string Create or Extend a Content Type
  781. * $params['create_pod_type'] string Pod Type (for Creating)
  782. * $params['create_name'] string Pod Name (for Creating)
  783. * $params['create_label_plural'] string Plural Label (for Creating)
  784. * $params['create_label_singular'] string Singular Label (for Creating)
  785. * $params['create_storage'] string Storage Type (for Creating Post Types)
  786. * $params['create_storage_taxonomy'] string Storage Type (for Creating Taxonomies)
  787. * $params['extend_pod_type'] string Pod Type (for Extending)
  788. * $params['extend_post_type'] string Post Type (for Extending Post Types)
  789. * $params['extend_taxonomy'] string Taxonomy (for Extending Taxonomies)
  790. * $params['extend_storage'] string Storage Type (for Extending Post Types / Users / Comments)
  791. *
  792. * @param array $params An associative array of parameters
  793. *
  794. * @return bool|int Pod ID
  795. * @since 2.0.0
  796. */
  797. public function add_pod ( $params ) {
  798. $defaults = array(
  799. 'create_extend' => 'create',
  800. 'create_pod_type' => 'post_type',
  801. 'create_name' => '',
  802. 'create_label_plural' => '',
  803. 'create_label_singular' => '',
  804. 'create_storage' => 'meta',
  805. 'create_storage_taxonomy' => 'none',
  806. 'extend_pod_type' => 'post_type',
  807. 'extend_post_type' => 'post',
  808. 'extend_taxonomy' => 'category',
  809. 'extend_storage_taxonomy' => 'table',
  810. 'extend_storage' => 'meta'
  811. );
  812. $params = (object) array_merge( $defaults, (array) $params );
  813. if ( empty( $params->create_extend ) || !in_array( $params->create_extend, array( 'create', 'extend' ) ) )
  814. return pods_error( __( 'Please choose whether to Create or Extend a Content Type', $this ) );
  815. $pod_params = array(
  816. 'name' => '',
  817. 'label' => '',
  818. 'type' => '',
  819. 'storage' => 'table',
  820. 'object' => '',
  821. 'options' => array()
  822. );
  823. if ( 'create' == $params->create_extend ) {
  824. if ( empty( $params->create_name ) )
  825. return pods_error( 'Please enter a Name for this Pod', $this );
  826. $pod_params[ 'name' ] = $params->create_name;
  827. $pod_params[ 'label' ] = ( !empty( $params->create_label_plural ) ? $params->create_label_plural : ucwords( str_replace( '_', ' ', $params->create_name ) ) );
  828. $pod_params[ 'type' ] = $params->create_pod_type;
  829. $pod_params[ 'options' ] = array(
  830. 'label_singular' => ( !empty( $params->create_label_singular ) ? $params->create_label_singular : ucwords( str_replace( '_', ' ', $params->create_name ) ) ),
  831. 'public' => 1,
  832. 'show_ui' => 1
  833. );
  834. if ( 'post_type' == $pod_params[ 'type' ] ) {
  835. $pod_params[ 'storage' ] = $params->create_storage;
  836. if ( defined( 'PODS_TABLELESS' ) && PODS_TABLELESS )
  837. $pod_params[ 'storage' ] = 'meta';
  838. }
  839. elseif ( 'taxonomy' == $pod_params[ 'type' ] ) {
  840. $pod_params[ 'storage' ] = $params->create_storage_taxonomy;
  841. if ( defined( 'PODS_TABLELESS' ) && PODS_TABLELESS )
  842. $pod_params[ 'storage' ] = 'none';
  843. }
  844. elseif ( defined( 'PODS_TABLELESS' ) && PODS_TABLELESS ) {
  845. $pod_params[ 'type' ] = 'post_type';
  846. $pod_params[ 'storage' ] = 'meta';
  847. }
  848. }
  849. elseif ( 'extend' == $params->create_extend ) {
  850. $pod_params[ 'type' ] = $params->extend_pod_type;
  851. if ( 'post_type' == $pod_params[ 'type' ] ) {
  852. $pod_params[ 'storage' ] = $params->extend_storage;
  853. if ( defined( 'PODS_TABLELESS' ) && PODS_TABLELESS )
  854. $pod_params[ 'storage' ] = 'meta';
  855. $pod_params[ 'name' ] = $params->extend_post_type;
  856. }
  857. elseif ( 'taxonomy' == $pod_params[ 'type' ] ) {
  858. $pod_params[ 'storage' ] = $params->extend_storage_taxonomy;
  859. if ( defined( 'PODS_TABLELESS' ) && PODS_TABLELESS )
  860. $pod_params[ 'storage' ] = 'none';
  861. $pod_params[ 'name' ] = $params->extend_taxonomy;
  862. }
  863. else {
  864. $pod_params[ 'storage' ] = $params->extend_storage;
  865. if ( defined( 'PODS_TABLELESS' ) && PODS_TABLELESS )
  866. $pod_params[ 'storage' ] = 'meta';
  867. $pod_params[ 'name' ] = $params->extend_pod_type;
  868. }
  869. $pod_params[ 'label' ] = ucwords( str_replace( '_', ' ', $pod_params[ 'name' ] ) );
  870. $pod_params[ 'object' ] = $pod_params[ 'name' ];
  871. }
  872. if ( empty( $pod_params[ 'object' ] ) ) {
  873. if ( 'post_type' == $pod_params[ 'type' ] ) {
  874. $check = get_post_type_object( $pod_params[ 'name' ] );
  875. if ( !empty( $check ) )
  876. return pods_error( sprintf( __( 'Post Type %s already exists, try extending it instead', 'pods' ), $pod_params[ 'name' ] ), $this );
  877. $pod_params[ 'options' ][ 'supports_title' ] = 1;
  878. $pod_params[ 'options' ][ 'supports_editor' ] = 1;
  879. }
  880. elseif ( 'taxonomy' == $pod_params[ 'type' ] ) {
  881. $check = get_taxonomy( $pod_params[ 'name' ] );
  882. if ( !empty( $check ) )
  883. return pods_error( sprintf( __( 'Taxonomy %s already exists, try extending it instead', 'pods' ), $pod_params[ 'name' ] ), $this );
  884. }
  885. }
  886. if ( !empty( $pod_params ) )
  887. return $this->save_pod( $pod_params );
  888. return false;
  889. }
  890. /**
  891. * Add or edit a Pod
  892. *
  893. * $params['id'] int The Pod ID
  894. * $params['name'] string The Pod name
  895. * $params['label'] string The Pod label
  896. * $params['type'] string The Pod type
  897. * $params['storage'] string The Pod storage
  898. * $params['options'] array Options
  899. *
  900. * @param array $params An associative array of parameters
  901. * @param bool $sanitized (optional) Decides whether the params have been sanitized before being passed, will sanitize them if false.
  902. * @param bool|int $db (optional) Whether to save into the DB or just return Pod array.
  903. *
  904. * @return int Pod ID
  905. * @since 1.7.9
  906. */
  907. public function save_pod ( $params, $sanitized = false, $db = true ) {
  908. $tableless_field_types = apply_filters( 'pods_tableless_field_types', array( 'pick', 'file', 'avatar', 'taxonomy' ) );
  909. $load_params = (object) $params;
  910. if ( isset( $load_params->id ) && isset( $load_params->name ) )
  911. unset( $load_params->name );
  912. if ( isset( $load_params->old_name ) )
  913. $load_params->name = $load_params->old_name;
  914. $pod = $this->load_pod( $load_params, false );
  915. $params = (object) $params;
  916. if ( false === $sanitized )
  917. $params = pods_sanitize( $params );
  918. $old_id = $old_name = $old_storage = null;
  919. $old_fields = $old_options = array();
  920. if ( isset( $params->name ) )
  921. $params->name = pods_clean_name( $params->name );
  922. if ( !empty( $pod ) ) {
  923. if ( isset( $params->id ) && 0 < $params->id )
  924. $old_id = $params->id;
  925. $params->id = $pod[ 'id' ];
  926. $old_name = $pod[ 'name' ];
  927. $old_storage = $pod[ 'storage' ];
  928. $old_fields = $pod[ 'fields' ];
  929. $old_options = $pod[ 'options' ];
  930. if ( !isset( $params->name ) && empty( $params->name ) )
  931. $params->name = $pod[ 'name' ];
  932. if ( $old_name != $params->name && false !== $this->pod_exists( array( 'name' => $params->name ) ) )
  933. return pods_error( sprintf( __( 'Pod %s already exists, you cannot rename %s to that', 'pods' ), $params->name, $old_name ), $this );
  934. if ( $old_name != $params->name && in_array( $pod[ 'type' ], array( 'user', 'comment', 'media' ) ) && in_array( $pod[ 'object' ], array( 'user', 'comment', 'media' ) ) )
  935. return pods_error( sprintf( __( 'Pod %s cannot be renamed, it extends an existing WP Object', 'pods' ), $old_name ), $this );
  936. if ( $old_name != $params->name && in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) && !empty( $pod[ 'object' ] ) && $pod[ 'object' ] != $old_name )
  937. return pods_error( sprintf( __( 'Pod %s cannot be renamed, it extends an existing WP Object', 'pods' ), $old_name ), $this );
  938. if ( $old_id != $params->id ) {
  939. if ( $params->type == $pod[ 'type' ] && isset( $params->object ) && $params->object == $pod[ 'object' ] )
  940. return pods_error( sprintf( __( 'Pod using %s already exists, you can not reuse an object across multiple pods', 'pods' ), $params->object ), $this );
  941. else
  942. return pods_error( sprintf( __( 'Pod %s already exists', 'pods' ), $params->name ), $this );
  943. }
  944. }
  945. else {
  946. $pod = array(
  947. 'id' => 0,
  948. 'name' => $params->name,
  949. 'label' => $params->name,
  950. 'description' => '',
  951. 'type' => 'pod',
  952. 'storage' => 'table',
  953. 'object' => '',
  954. 'alias' => '',
  955. 'options' => array(),
  956. 'fields' => array()
  957. );
  958. }
  959. // Blank out fields and options for AJAX calls (everything should be sent to it for a full overwrite)
  960. if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
  961. $pod[ 'fields' ] = array();
  962. $pod[ 'options' ] = array();
  963. }
  964. // Setup options
  965. $options = get_object_vars( $params );
  966. if ( isset( $options[ 'method' ] ) )
  967. unset( $options[ 'method' ] );
  968. $exclude = array(
  969. 'id',
  970. 'name',
  971. 'label',
  972. 'description',
  973. 'type',
  974. 'storage',
  975. 'object',
  976. 'alias',
  977. 'options',
  978. 'fields'
  979. );
  980. foreach ( $exclude as $k => $exclude_field ) {
  981. $aliases = array( $exclude_field );
  982. if ( is_array( $exclude_field ) ) {
  983. $aliases = array_merge( array( $k ), $exclude_field );
  984. $exclude_field = $k;
  985. }
  986. foreach ( $aliases as $alias ) {
  987. if ( isset( $options[ $alias ] ) ) {
  988. $pod[ $exclude_field ] = pods_trim( $options[ $alias ] );
  989. unset( $options[ $alias ] );
  990. }
  991. }
  992. }
  993. if ( defined( 'PODS_TABLELESS' ) && PODS_TABLELESS ) {
  994. if ( 'pod' == $pod[ 'type' ] )
  995. $pod[ 'type' ] = 'post_type';
  996. if ( 'table' == $pod[ 'storage' ] ) {
  997. if ( 'taxonomy' == $pod[ 'type' ] )
  998. $pod[ 'storage' ] = 'none';
  999. else
  1000. $pod[ 'storage' ] = 'meta';
  1001. }
  1002. }
  1003. $pod[ 'options' ][ 'type' ] = $pod[ 'type' ];
  1004. $pod[ 'options' ][ 'storage' ] = $pod[ 'storage' ];
  1005. $pod[ 'options' ][ 'object' ] = $pod[ 'object' ];
  1006. $pod[ 'options' ][ 'alias' ] = $pod[ 'alias' ];
  1007. $pod[ 'options' ] = array_merge( $pod[ 'options' ], $options );
  1008. if ( strlen( $pod[ 'label' ] ) < 1 )
  1009. $pod[ 'label' ] = $pod[ 'name' ];
  1010. if ( 'post_type' == $pod[ 'type' ] ) {
  1011. // Max length for post types are 20 characters
  1012. $pod[ 'name' ] = substr( $pod[ 'name' ], 0, 20 );
  1013. }
  1014. elseif ( 'taxonomy' == $pod[ 'type' ] ) {
  1015. // Max length for taxonomies are 32 characters
  1016. $pod[ 'name' ] = substr( $pod[ 'name' ], 0, 32 );
  1017. }
  1018. $params->id = $pod[ 'id' ];
  1019. $params->name = $pod[ 'name' ];
  1020. if ( null !== $old_name && $old_name != $params->name && empty( $pod[ 'object' ] ) ) {
  1021. if ( 'post_type' == $pod[ 'type' ] ) {
  1022. $check = get_post_type_object( $params->name );
  1023. if ( !empty( $check ) )
  1024. return pods_error( sprintf( __( 'Post Type %s already exists, you cannot rename %s to that', 'pods' ), $params->name, $old_name ), $this );
  1025. }
  1026. elseif ( 'taxonomy' == $pod[ 'type' ] ) {
  1027. $check = get_taxonomy( $params->name );
  1028. if ( !empty( $check ) )
  1029. return pods_error( sprintf( __( 'Taxonomy %s already exists, you cannot rename %s to that', 'pods' ), $params->name, $old_name ), $this );
  1030. }
  1031. }
  1032. $field_table_operation = true;
  1033. // Add new pod
  1034. if ( empty( $params->id ) ) {
  1035. if ( strlen( $params->name ) < 1 )
  1036. return pods_error( __( 'Pod name cannot be empty', 'pods' ), $this );
  1037. $post_data = array(
  1038. 'post_name' => $pod[ 'name' ],
  1039. 'post_title' => $pod[ 'label' ],
  1040. 'post_content' => $pod[ 'description' ],
  1041. 'post_type' => '_pods_pod',
  1042. 'post_status' => 'publish'
  1043. );
  1044. if ( 'pod' == $pod[ 'type' ] && ( !is_array( $pod[ 'fields' ] ) || empty( $pod[ 'fields' ] ) ) ) {
  1045. $pod[ 'fields' ] = array();
  1046. $pod[ 'fields' ][] = array(
  1047. 'name' => 'name',
  1048. 'label' => 'Name',
  1049. 'type' => 'text',
  1050. 'options' => array(
  1051. 'required' => '1'
  1052. )
  1053. );
  1054. $pod[ 'fields' ][] = array(
  1055. 'name' => 'created',
  1056. 'label' => 'Date Created',
  1057. 'type' => 'datetime',
  1058. 'options' => array(
  1059. 'datetime_format' => 'ymd_slash',
  1060. 'datetime_time_type' => '12',
  1061. 'datetime_time_format' => 'h_mm_ss_A'
  1062. )
  1063. );
  1064. $pod[ 'fields' ][] = array(
  1065. 'name' => 'modified',
  1066. 'label' => 'Date Modified',
  1067. 'type' => 'datetime',
  1068. 'options' => array(
  1069. 'datetime_format' => 'ymd_slash',
  1070. 'datetime_time_type' => '12',
  1071. 'datetime_time_format' => 'h_mm_ss_A'
  1072. )
  1073. );
  1074. $pod[ 'fields' ][] = array(
  1075. 'name' => 'author',
  1076. 'label' => 'Author',
  1077. 'type' => 'pick',
  1078. 'pick_object' => 'user',
  1079. 'options' => array(
  1080. 'pick_format_type' => 'single',
  1081. 'pick_format_single' => 'autocomplete',
  1082. 'default_value' => '{@user.ID}'
  1083. )
  1084. );
  1085. $pod[ 'fields' ][] = array(
  1086. 'name' => 'permalink',
  1087. 'label' => 'Permalink',
  1088. 'type' => 'slug',
  1089. 'description' => 'Leave blank to auto-generate from Name'
  1090. );
  1091. if ( !isset( $pod[ 'options' ][ 'pod_index' ] ) )
  1092. $pod[ 'options' ][ 'pod_index' ] = 'name';
  1093. }
  1094. $field_table_operation = false;
  1095. }
  1096. else {
  1097. $post_data = array(
  1098. 'ID' => $pod[ 'id' ],
  1099. 'post_name' => $pod[ 'name' ],
  1100. 'post_title' => $pod[ 'label' ],
  1101. 'post_content' => $pod[ 'description' ],
  1102. 'post_status' => 'publish'
  1103. );
  1104. }
  1105. if ( true === $db ) {
  1106. $params->id = $this->save_post( $post_data, $pod[ 'options' ], true, true );
  1107. if ( false === $params->id )
  1108. return pods_error( __( 'Cannot save Pod', 'pods' ), $this );
  1109. }
  1110. elseif ( empty( $params->id ) )
  1111. $params->id = (int) $db;
  1112. $pod[ 'id' ] = $params->id;
  1113. // Setup / update tables
  1114. if ( 'table' == $pod[ 'storage' ] && $old_storage != $pod[ 'storage' ] && $db ) {
  1115. $definitions = array( "`id` BIGINT(20) UNSIGNED AUTO_INCREMENT PRIMARY KEY" );
  1116. foreach ( $pod[ 'fields' ] as $field ) {
  1117. if ( !in_array( $field[ 'type' ], $tableless_field_types ) )
  1118. $definitions[] = "`{$field['name']}` " . $this->get_field_definition( $field[ 'type' ], $field[ 'options' ] );
  1119. }
  1120. pods_query( "DROP TABLE IF EXISTS `@wp_pods_{$params->name}`" );
  1121. $result = pods_query( "CREATE TABLE `@wp_pods_{$params->name}` (" . implode( ', ', $definitions ) . ") DEFAULT CHARSET utf8", $this );
  1122. if ( empty( $result ) )
  1123. return pods_error( __( 'Cannot add Database Table for Pod', 'pods' ), $this );
  1124. }
  1125. elseif ( 'table' == $pod[ 'storage' ] && $pod[ 'storage' ] == $old_storage && null !== $old_name && $old_name != $params->name && $db ) {
  1126. $result = pods_query( "ALTER TABLE `@wp_pods_{$old_name}` RENAME `@wp_pods_{$params->name}`", $this );
  1127. if ( empty( $result ) )
  1128. return pods_error( __( 'Cannot update Database Table for Pod', 'pods' ), $this );
  1129. }
  1130. /**
  1131. * @var $wpdb wpdb
  1132. */
  1133. global $wpdb;
  1134. if ( 'post_type' == $pod[ 'type' ] && empty( $pod[ 'object' ] ) && null !== $old_name && $old_name != $params->name && $db )
  1135. $this->rename_wp_object_type( 'post', $old_name, $params->name );
  1136. elseif ( 'taxonomy' == $pod[ 'type' ] && empty( $pod[ 'object' ] ) && null !== $old_name && $old_name != $params->name && $db )
  1137. $this->rename_wp_object_type( 'taxonomy', $old_name, $params->name );
  1138. elseif ( 'comment' == $pod[ 'type' ] && empty( $pod[ 'object' ] ) && null !== $old_name && $old_name != $params->name && $db )
  1139. $this->rename_wp_object_type( 'comment', $old_name, $params->name );
  1140. // Sync any related fields if the name has changed
  1141. if ( null !== $old_name && $old_name != $params->name && $db ) {
  1142. $fields = pods_query( "
  1143. SELECT `p`.`ID`
  1144. FROM `{$wpdb->posts}` AS `p`
  1145. LEFT JOIN `{$wpdb->postmeta}` AS `pm` ON `pm`.`post_id` = `p`.`ID`
  1146. LEFT JOIN `{$wpdb->postmeta}` AS `pm2` ON `pm2`.`post_id` = `p`.`ID`
  1147. WHERE
  1148. `p`.`post_type` = '_pods_field'
  1149. AND `pm`.`meta_key` = 'pick_object'
  1150. AND `pm`.`meta_value` = 'pod'
  1151. AND `pm2`.`meta_key` = 'pick_val'
  1152. AND `pm2`.`meta_value` = '{$old_name}'
  1153. " );
  1154. if ( !empty( $fields ) ) {
  1155. foreach ( $fields as $field ) {

Large files files are truncated, but you can click here to view the full file