Pods_Migrate_Packages

The Pods - Custom Content Types and Fields Pods Migrate Packages class.

Defined (1)

The class is defined in the following location(s).

/components/Migrate-Packages/Migrate-Packages.php  
  1. class Pods_Migrate_Packages extends PodsComponent { 
  2.  
  3. /** 
  4. * Do things like register/enqueue scripts and stylesheets 
  5. * @since 2.0 
  6. */ 
  7. public function __construct () { 
  8.  
  9.  
  10. /** 
  11. * Enqueue styles 
  12. * @since 2.0 
  13. */ 
  14. public function admin_assets () { 
  15. wp_enqueue_style( 'pods-wizard' ); 
  16.  
  17. /** 
  18. * Build admin area 
  19. * @param $options 
  20. * @since 2.0 
  21. */ 
  22. public function admin ( $options, $component ) { 
  23. $method = 'import_export'; // ajax_import 
  24.  
  25. pods_view( PODS_DIR . 'components/Migrate-Packages/ui/wizard.php', compact( array_keys( get_defined_vars() ) ) ); 
  26.  
  27. /** 
  28. * Handle the Import/Export AJAX 
  29. * @param $params 
  30. */ 
  31. public function ajax_import_export ( $params ) { 
  32. if ( 'import' == $params->import_export ) { 
  33. $data = trim( $params->import_package ); 
  34.  
  35. $content = '<div class="pods-wizard-content">'; 
  36.  
  37. if ( !empty( $data ) ) { 
  38. $imported = $this->import( $data ); 
  39.  
  40. if ( !empty( $imported ) ) { 
  41. $content .= '<p>Import Complete! The following items were imported:</p>'; 
  42.  
  43. foreach ( $imported as $type => $import ) { 
  44. $content .= '<h4>' . ucwords( $type ) . '</h4>'; 
  45.  
  46. $content .= '<ul class="normal">'; 
  47.  
  48. foreach ( $import as $k => $what ) { 
  49. $content .= '<li>' . esc_html( $what ) . '</li>'; 
  50.  
  51. $content .= '</ul>'; 
  52. else 
  53. $content .= '<p>Import Error: Invalid Package</p>'; 
  54.  
  55. $content .= '</div>'; 
  56.  
  57. echo $content; 
  58. elseif ( 'export' == $params->import_export ) { 
  59. $params = get_object_vars( $params ); 
  60. foreach ( $params as $k => $v ) { 
  61. if ( is_array( $v ) ) 
  62. $params[ $k ] = array_keys( array_filter( $v ) ); 
  63.  
  64. $package = $this->export( $params ); 
  65.  
  66. echo '<div class="pods-field-option">'; 
  67.  
  68. echo PodsForm::field( 'export_package', $package, 'paragraph', array( 'attributes' => array( 'style' => 'width: 94%; max-width: 94%; height: 300px;' ) ) ); 
  69.  
  70. echo '</div>'; 
  71.  
  72.  
  73. /** 
  74. * Import a Package 
  75. * @param string|array $data a JSON array package string, or an array of Package Data 
  76. * @param bool $replace Whether to replace existing pods entirely or just update them 
  77. * @return array|bool 
  78. * @static 
  79. * @since 2.0.5 
  80. */ 
  81. public static function import ( $data, $replace = false ) { 
  82. if ( !defined( 'PODS_FIELD_STRICT' ) ) 
  83. define( 'PODS_FIELD_STRICT', false ); 
  84.  
  85. if ( !is_array( $data ) ) { 
  86. $json_data = @json_decode( $data, true ); 
  87.  
  88. if ( !is_array( $json_data ) ) 
  89. $json_data = @json_decode( pods_unslash( $data ), true ); 
  90.  
  91. $data = $json_data; 
  92.  
  93. if ( !is_array( $data ) || empty( $data ) ) 
  94. return false; 
  95.  
  96. $api = pods_api(); 
  97.  
  98. if ( !isset( $data[ 'meta' ] ) || !isset( $data[ 'meta' ][ 'version' ] ) || empty( $data[ 'meta' ][ 'version' ] ) ) 
  99. return false; 
  100.  
  101. // Pods 1.x < 1.10 
  102. if ( false === strpos( $data[ 'meta' ][ 'version' ], '.' ) && (int) $data[ 'meta' ][ 'version' ] < 1000 ) 
  103. $data[ 'meta' ][ 'version' ] = implode( '.', str_split( $data[ 'meta' ][ 'version' ] ) ); 
  104. // Pods 1.10 <= 2.0 
  105. elseif ( false === strpos( $data[ 'meta' ][ 'version' ], '.' ) ) 
  106. $data[ 'meta' ][ 'version' ] = pods_version_to_point( $data[ 'meta' ][ 'version' ] ); 
  107.  
  108. $found = array(); 
  109.  
  110. if ( isset( $data[ 'pods' ] ) && is_array( $data[ 'pods' ] ) ) { 
  111. foreach ( $data[ 'pods' ] as $pod_data ) { 
  112. if ( isset( $pod_data[ 'id' ] ) ) 
  113. unset( $pod_data[ 'id' ] ); 
  114.  
  115. $pod = $api->load_pod( array( 'name' => $pod_data[ 'name' ] ), false ); 
  116.  
  117. $existing_fields = array(); 
  118.  
  119. if ( !empty( $pod ) ) { 
  120. // Delete Pod if it exists 
  121. if ( $replace ) { 
  122. $api->delete_pod( array( 'id' => $pod[ 'id' ] ) ); 
  123.  
  124. $pod = array( 'fields' => array() ); 
  125. else 
  126. $existing_fields = $pod[ 'fields' ]; 
  127. else 
  128. $pod = array( 'fields' => array() ); 
  129.  
  130. // Backwards compatibility 
  131. if ( version_compare( $data[ 'meta' ][ 'version' ], '2.0', '<' ) ) { 
  132. $core_fields = array( 
  133. array( 
  134. 'name' => 'created',  
  135. 'label' => 'Date Created',  
  136. 'type' => 'datetime',  
  137. 'options' => array( 
  138. 'datetime_format' => 'ymd_slash',  
  139. 'datetime_time_type' => '12',  
  140. 'datetime_time_format' => 'h_mm_ss_A' 
  141. ),  
  142. 'weight' => 1 
  143. ),  
  144. array( 
  145. 'name' => 'modified',  
  146. 'label' => 'Date Modified',  
  147. 'type' => 'datetime',  
  148. 'options' => array( 
  149. 'datetime_format' => 'ymd_slash',  
  150. 'datetime_time_type' => '12',  
  151. 'datetime_time_format' => 'h_mm_ss_A' 
  152. ),  
  153. 'weight' => 2 
  154. ),  
  155. array( 
  156. 'name' => 'author',  
  157. 'label' => 'Author',  
  158. 'type' => 'pick',  
  159. 'pick_object' => 'user',  
  160. 'options' => array( 
  161. 'pick_format_type' => 'single',  
  162. 'pick_format_single' => 'autocomplete',  
  163. 'default_value' => '{@user.ID}' 
  164. ),  
  165. 'weight' => 3 
  166. ); 
  167.  
  168. $found_fields = array(); 
  169.  
  170. if ( !empty( $pod_data[ 'fields' ] ) ) { 
  171. foreach ( $pod_data[ 'fields' ] as $k => $field ) { 
  172. $field_type = $field[ 'coltype' ]; 
  173.  
  174. if ( 'txt' == $field_type ) 
  175. $field_type = 'text'; 
  176. elseif ( 'desc' == $field_type ) 
  177. $field_type = 'wysiwyg'; 
  178. elseif ( 'code' == $field_type ) 
  179. $field_type = 'paragraph'; 
  180. elseif ( 'bool' == $field_type ) 
  181. $field_type = 'boolean'; 
  182. elseif ( 'num' == $field_type ) 
  183. $field_type = 'number'; 
  184. elseif ( 'date' == $field_type ) 
  185. $field_type = 'datetime'; 
  186.  
  187. $multiple = min( max( (int) $field[ 'multiple' ], 0 ), 1 ); 
  188.  
  189. $new_field = array( 
  190. 'name' => trim( $field[ 'name' ] ),  
  191. 'label' => trim( $field[ 'label' ] ),  
  192. 'description' => trim( $field[ 'comment' ] ),  
  193. 'type' => $field_type,  
  194. 'weight' => (int) $field[ 'weight' ],  
  195. 'options' => array( 
  196. 'required' => min( max( (int) $field[ 'required' ], 0 ), 1 ),  
  197. 'unique' => min( max( (int) $field[ 'unique' ], 0 ), 1 ),  
  198. 'input_helper' => $field[ 'input_helper' ] 
  199. ); 
  200.  
  201. if ( in_array( $new_field[ 'name' ], $found_fields ) ) { 
  202. unset( $pod_data[ 'fields' ][ $k ] ); 
  203.  
  204. continue; 
  205.  
  206. $found_fields[] = $new_field[ 'name' ]; 
  207.  
  208. if ( 'pick' == $field_type ) { 
  209. $new_field[ 'pick_object' ] = 'pod'; 
  210. $new_field[ 'pick_val' ] = $field[ 'pickval' ]; 
  211.  
  212. if ( 'wp_user' == $field[ 'pickval' ] ) 
  213. $new_field[ 'pick_object' ] = 'user'; 
  214. elseif ( 'wp_post' == $field[ 'pickval' ] ) 
  215. $new_field[ 'pick_object' ] = 'post_type-post'; 
  216. elseif ( 'wp_page' == $field[ 'pickval' ] ) 
  217. $new_field[ 'pick_object' ] = 'post_type-page'; 
  218. elseif ( 'wp_taxonomy' == $field[ 'pickval' ] ) 
  219. $new_field[ 'pick_object' ] = 'taxonomy-category'; 
  220.  
  221. // This won't work if the field doesn't exist 
  222. // $new_field[ 'sister_id' ] = $field[ 'sister_field_id' ]; 
  223.  
  224. $new_field[ 'options' ][ 'pick_filter' ] = $field[ 'pick_filter' ]; 
  225. $new_field[ 'options' ][ 'pick_orderby' ] = $field[ 'pick_orderby' ]; 
  226. $new_field[ 'options' ][ 'pick_display' ] = ''; 
  227. $new_field[ 'options' ][ 'pick_size' ] = 'medium'; 
  228.  
  229. if ( 1 == $multiple ) { 
  230. $new_field[ 'options' ][ 'pick_format_type' ] = 'multi'; 
  231. $new_field[ 'options' ][ 'pick_format_multi' ] = 'checkbox'; 
  232. $new_field[ 'options' ][ 'pick_limit' ] = 0; 
  233. else { 
  234. $new_field[ 'options' ][ 'pick_format_type' ] = 'single'; 
  235. $new_field[ 'options' ][ 'pick_format_single' ] = 'dropdown'; 
  236. $new_field[ 'options' ][ 'pick_limit' ] = 1; 
  237. elseif ( 'file' == $field_type ) { 
  238. $new_field[ 'options' ][ 'file_format_type' ] = 'multi'; 
  239. $new_field[ 'options' ][ 'file_type' ] = 'any'; 
  240. elseif ( 'number' == $field_type ) 
  241. $new_field[ 'options' ][ 'number_decimals' ] = 2; 
  242. elseif ( 'desc' == $field[ 'coltype' ] ) 
  243. $new_field[ 'options' ][ 'wysiwyg_editor' ] = 'tinymce'; 
  244. elseif ( 'text' == $field_type ) 
  245. $new_field[ 'options' ][ 'text_max_length' ] = 128; 
  246.  
  247. if ( isset( $pod[ 'fields' ][ $new_field[ 'name' ] ] ) ) 
  248. $new_field = array_merge( $pod[ 'fields' ][ $new_field[ 'name' ] ], $new_field ); 
  249.  
  250. $pod_data[ 'fields' ][ $k ] = $new_field; 
  251.  
  252. if ( pods_var( 'id', $pod, 0 ) < 1 ) 
  253. $pod_data[ 'fields' ] = array_merge( $core_fields, $pod_data[ 'fields' ] ); 
  254.  
  255. if ( empty( $pod_data[ 'label' ] ) ) 
  256. $pod_data[ 'label' ] = ucwords( str_replace( '_', ' ', $pod_data[ 'name' ] ) ); 
  257.  
  258. if ( isset( $pod_data[ 'is_toplevel' ] ) ) { 
  259. $pod_data[ 'show_in_menu' ] = ( 1 == $pod_data[ 'is_toplevel' ] ? 1 : 0 ); 
  260.  
  261. unset( $pod_data[ 'is_toplevel' ] ); 
  262.  
  263. if ( isset( $pod_data[ 'detail_page' ] ) ) { 
  264. $pod_data[ 'detail_url' ] = $pod_data[ 'detail_page' ]; 
  265.  
  266. unset( $pod_data[ 'detail_page' ] ); 
  267.  
  268. if ( isset( $pod_data[ 'before_helpers' ] ) ) { 
  269. $pod_data[ 'pre_save_helpers' ] = $pod_data[ 'before_helpers' ]; 
  270.  
  271. unset( $pod_data[ 'before_helpers' ] ); 
  272.  
  273. if ( isset( $pod_data[ 'after_helpers' ] ) ) { 
  274. $pod_data[ 'post_save_helpers' ] = $pod_data[ 'after_helpers' ]; 
  275.  
  276. unset( $pod_data[ 'after_helpers' ] ); 
  277.  
  278. if ( isset( $pod_data[ 'pre_drop_helpers' ] ) ) { 
  279. $pod_data[ 'pre_delete_helpers' ] = $pod_data[ 'pre_drop_helpers' ]; 
  280.  
  281. unset( $pod_data[ 'pre_drop_helpers' ] ); 
  282.  
  283. if ( isset( $pod_data[ 'post_drop_helpers' ] ) ) { 
  284. $pod_data[ 'post_delete_helpers' ] = $pod_data[ 'post_drop_helpers' ]; 
  285.  
  286. unset( $pod_data[ 'post_drop_helpers' ] ); 
  287.  
  288. $pod_data[ 'name' ] = pods_clean_name( $pod_data[ 'name' ] ); 
  289.  
  290. $pod_data = array( 
  291. 'name' => $pod_data[ 'name' ],  
  292. 'label' => $pod_data[ 'label' ],  
  293. 'type' => 'pod',  
  294. 'storage' => 'table',  
  295. 'fields' => $pod_data[ 'fields' ],  
  296. 'options' => array( 
  297. 'pre_save_helpers' => pods_var_raw( 'pre_save_helpers', $pod_data ),  
  298. 'post_save_helpers' => pods_var_raw( 'post_save_helpers', $pod_data ),  
  299. 'pre_delete_helpers' => pods_var_raw( 'pre_delete_helpers', $pod_data ),  
  300. 'post_delete_helpers' => pods_var_raw( 'post_delete_helpers', $pod_data ),  
  301. 'show_in_menu' => ( 1 == pods_var_raw( 'show_in_menu', $pod_data, 0 ) ? 1 : 0 ),  
  302. 'detail_url' => pods_var_raw( 'detail_url', $pod_data ),  
  303. 'pod_index' => 'name' 
  304. ),  
  305. ); 
  306.  
  307. $pod = array_merge( $pod, $pod_data ); 
  308.  
  309. foreach ( $pod[ 'fields' ] as $k => $field ) { 
  310. if ( isset( $field[ 'id' ] ) && !isset( $existing_fields[ $field[ 'name' ] ] ) ) 
  311. unset( $pod[ 'fields' ][ $k ][ 'id' ] ); 
  312.  
  313. if ( isset( $field[ 'pod_id' ] ) ) 
  314. unset( $pod[ 'fields' ][ $k ][ 'pod_id' ] ); 
  315.  
  316. if ( isset( $existing_fields[ $field['name'] ] ) ) { 
  317. if ( $existing_field = pods_api()->load_field( array( 'name' => $field['name'], 'pod' => $pod[ 'name' ] ) ) ) 
  318. $pod['fields'][$k]['id'] = $existing_field['id']; 
  319.  
  320. if ( isset( $field[ 'pod' ] ) ) 
  321. unset( $pod[ 'fields' ][ $k ][ 'pod' ] ); 
  322.  
  323. $api->save_pod( $pod ); 
  324.  
  325. if ( !isset( $found[ 'pods' ] ) ) 
  326. $found[ 'pods' ] = array(); 
  327.  
  328. $found[ 'pods' ][ $pod[ 'name' ] ] = $pod[ 'label' ]; 
  329.  
  330. if ( isset( $data[ 'templates' ] ) && is_array( $data[ 'templates' ] ) ) { 
  331. foreach ( $data[ 'templates' ] as $template_data ) { 
  332. if ( isset( $template_data[ 'id' ] ) ) 
  333. unset( $template_data[ 'id' ] ); 
  334.  
  335. $template = $api->load_template( array( 'name' => $template_data[ 'name' ] ) ); 
  336.  
  337. if ( !empty( $template ) ) { 
  338. // Delete Template if it exists 
  339. if ( $replace ) { 
  340. $api->delete_template( array( 'id' => $template[ 'id' ] ) ); 
  341.  
  342. $template = array(); 
  343. else 
  344. $template = array(); 
  345.  
  346. $template = array_merge( $template, $template_data ); 
  347.  
  348. $api->save_template( $template ); 
  349.  
  350. if ( !isset( $found[ 'templates' ] ) ) 
  351. $found[ 'templates' ] = array(); 
  352.  
  353. $found[ 'templates' ][ $template[ 'name' ] ] = $template[ 'name' ]; 
  354.  
  355. // Backwards compatibility 
  356. if ( isset( $data[ 'pod_pages' ] ) ) { 
  357. $data[ 'pages' ] = $data[ 'pod_pages' ]; 
  358.  
  359. unset( $data[ 'pod_pages' ] ); 
  360.  
  361. if ( isset( $data[ 'pages' ] ) && is_array( $data[ 'pages' ] ) ) { 
  362. foreach ( $data[ 'pages' ] as $page_data ) { 
  363. if ( isset( $page_data[ 'id' ] ) ) 
  364. unset( $page_data[ 'id' ] ); 
  365.  
  366. $page = $api->load_page( array( 'name' => pods_var_raw( 'name', $page_data, pods_var_raw( 'uri', $page_data ), null, true ) ) ); 
  367.  
  368. if ( !empty( $page ) ) { 
  369. // Delete Page if it exists 
  370. if ( $replace ) { 
  371. $api->delete_page( array( 'id' => $page[ 'id' ] ) ); 
  372.  
  373. $page = array(); 
  374. else 
  375. $page = array(); 
  376.  
  377. // Backwards compatibility 
  378. if ( isset( $page_data[ 'uri' ] ) ) { 
  379. $page_data[ 'name' ] = $page_data[ 'uri' ]; 
  380.  
  381. unset( $page_data[ 'uri' ] ); 
  382.  
  383. if ( isset( $page_data[ 'phpcode' ] ) ) { 
  384. $page_data[ 'code' ] = $page_data[ 'phpcode' ]; 
  385.  
  386. unset( $page_data[ 'phpcode' ] ); 
  387.  
  388. $page = array_merge( $page, $page_data ); 
  389.  
  390. $page[ 'name' ] = trim( $page[ 'name' ], '/' ); 
  391.  
  392. $api->save_page( $page ); 
  393.  
  394. if ( !isset( $found[ 'pages' ] ) ) 
  395. $found[ 'pages' ] = array(); 
  396.  
  397. $found[ 'pages' ][ $page[ 'name' ] ] = $page[ 'name' ]; 
  398.  
  399. if ( isset( $data[ 'helpers' ] ) && is_array( $data[ 'helpers' ] ) ) { 
  400. foreach ( $data[ 'helpers' ] as $helper_data ) { 
  401. if ( isset( $helper_data[ 'id' ] ) ) 
  402. unset( $helper_data[ 'id' ] ); 
  403.  
  404. $helper = $api->load_helper( array( 'name' => $helper_data[ 'name' ] ) ); 
  405.  
  406. if ( !empty( $helper ) ) { 
  407. // Delete Helper if it exists 
  408. if ( $replace ) { 
  409. $api->delete_helper( array( 'id' => $helper[ 'id' ] ) ); 
  410.  
  411. $helper = array(); 
  412. else 
  413. $helper = array(); 
  414.  
  415. // Backwards compatibility 
  416. if ( isset( $helper_data[ 'phpcode' ] ) ) { 
  417. $helper_data[ 'code' ] = $helper_data[ 'phpcode' ]; 
  418.  
  419. unset( $helper_data[ 'phpcode' ] ); 
  420.  
  421. if ( isset( $helper_data[ 'type' ] ) ) { 
  422. if ( 'before' == $helper_data[ 'type' ] ) 
  423. $helper_data[ 'type' ] = 'pre_save'; 
  424. elseif ( 'after' == $helper_data[ 'type' ] ) 
  425. $helper_data[ 'type' ] = 'post_save'; 
  426.  
  427. $helper = array_merge( $helper, $helper_data ); 
  428.  
  429. if ( isset( $helper[ 'type' ] ) ) { 
  430. $helper[ 'helper_type' ] = $helper[ 'type' ]; 
  431.  
  432. unset( $helper[ 'helper_type' ] ); 
  433.  
  434. $api->save_helper( $helper ); 
  435.  
  436. if ( !isset( $found[ 'helpers' ] ) ) 
  437. $found[ 'helpers' ] = array(); 
  438.  
  439. $found[ 'helpers' ][ $helper[ 'name' ] ] = $helper[ 'name' ]; 
  440.  
  441. $found = apply_filters( 'pods_packages_import', $found, $data, $replace ); 
  442.  
  443. if ( !empty( $found ) ) 
  444. return $found; 
  445.  
  446. return false; 
  447.  
  448. /** 
  449. * Export a Package 
  450. * $params['pods'] string|array|bool Pod IDs to export, or set to true to export all 
  451. * $params['templates'] string|array|bool Template IDs to export, or set to true to export all 
  452. * $params['pages'] string|array|bool Page IDs to export, or set to true to export all 
  453. * $params['helpers'] string|array|bool Helper IDs to export, or set to true to export all 
  454. * @param array $params Array of things to export 
  455. * @return array|bool 
  456. * @static 
  457. * @since 2.0.5 
  458. */ 
  459. public static function export ( $params ) { 
  460. $export = array( 
  461. 'meta' => array( 
  462. 'version' => PODS_VERSION,  
  463. 'build' => time() 
  464. ); 
  465.  
  466. if ( is_object( $params ) ) 
  467. $params = get_object_vars( $params ); 
  468.  
  469. $api = pods_api(); 
  470.  
  471. $pod_ids = pods_var_raw( 'pods', $params ); 
  472. $template_ids = pods_var_raw( 'templates', $params ); 
  473. $page_ids = pods_var_raw( 'pages', $params ); 
  474. $helper_ids = pods_var_raw( 'helpers', $params ); 
  475.  
  476. if ( !empty( $pod_ids ) ) { 
  477. $api_params = array( 'export' => true ); 
  478.  
  479. if ( true !== $pod_ids ) 
  480. $api_params[ 'ids' ] = (array) $pod_ids; 
  481.  
  482. $export[ 'pods' ] = $api->load_pods( $api_params ); 
  483.  
  484. $options_ignore = array( 
  485. 'pod_id',  
  486. 'old_name',  
  487. 'object_type',  
  488. 'object_name',  
  489. 'object_hierarchical',  
  490. 'table',  
  491. 'meta_table',  
  492. 'pod_table',  
  493. 'field_id',  
  494. 'field_index',  
  495. 'field_slug',  
  496. 'field_type',  
  497. 'field_parent',  
  498. 'field_parent_select',  
  499. 'meta_field_id',  
  500. 'meta_field_index',  
  501. 'meta_field_value',  
  502. 'pod_field_id',  
  503. 'pod_field_index',  
  504. 'object_fields',  
  505. 'join',  
  506. 'where',  
  507. 'where_default',  
  508. 'orderby',  
  509. 'pod',  
  510. 'recurse',  
  511. 'table_info',  
  512. 'attributes',  
  513. 'group',  
  514. 'grouped',  
  515. 'developer_mode',  
  516. 'dependency',  
  517. 'depends-on',  
  518. 'excludes-on' 
  519. ); 
  520.  
  521. $field_types = PodsForm::field_types(); 
  522.  
  523. $field_type_options = array(); 
  524.  
  525. foreach ( $field_types as $type => $field_type_data ) { 
  526. $field_type_options[ $type ] = PodsForm::ui_options( $type ); 
  527.  
  528. foreach ( $export[ 'pods' ] as &$pod ) { 
  529. if ( isset( $pod[ 'options' ] ) ) { 
  530. $pod = array_merge( $pod, $pod[ 'options' ] ); 
  531.  
  532. unset( $pod[ 'options' ] ); 
  533.  
  534. foreach ( $pod as $option => $option_value ) { 
  535. if ( in_array( $option, $options_ignore ) || null === $option_value ) 
  536. unset( $pod[ $option ] ); 
  537.  
  538. if ( !empty( $pod[ 'fields' ] ) ) { 
  539. foreach ( $pod[ 'fields' ] as &$field ) { 
  540. if ( isset( $field[ 'options' ] ) ) { 
  541. $field = array_merge( $field, $field[ 'options' ] ); 
  542.  
  543. unset( $field[ 'options' ] ); 
  544.  
  545. foreach ( $field as $option => $option_value ) { 
  546. if ( in_array( $option, $options_ignore ) || null === $option_value ) 
  547. unset( $field[ $option ] ); 
  548.  
  549. foreach ( $field_type_options as $type => $options ) { 
  550. if ( $type == pods_var( 'type', $field ) ) 
  551. continue; 
  552.  
  553. foreach ( $options as $option_data ) { 
  554. if ( isset( $option_data[ 'group' ] ) && is_array( $option_data[ 'group' ] ) && !empty( $option_data[ 'group' ] ) ) { 
  555. if ( isset( $field[ $option_data[ 'name' ] ] ) ) 
  556. unset( $field[ $option_data[ 'name' ] ] ); 
  557.  
  558. foreach ( $option_data[ 'group' ] as $group_option_data ) { 
  559. if ( isset( $field[ $group_option_data[ 'name' ] ] ) ) 
  560. unset( $field[ $group_option_data[ 'name' ] ] ); 
  561. elseif ( isset( $field[ $option_data[ 'name' ] ] ) ) 
  562. unset( $field[ $option_data[ 'name' ] ] ); 
  563.  
  564. if ( !empty( $template_ids ) ) { 
  565. $api_params = array(); 
  566.  
  567. if ( true !== $template_ids ) 
  568. $api_params[ 'ids' ] = (array) $template_ids; 
  569.  
  570. $export[ 'templates' ] = $api->load_templates( $api_params ); 
  571.  
  572. if ( !empty( $page_ids ) ) { 
  573. $api_params = array(); 
  574.  
  575. if ( true !== $page_ids ) 
  576. $api_params[ 'ids' ] = (array) $page_ids; 
  577.  
  578. $export[ 'pages' ] = $api->load_pages( $api_params ); 
  579.  
  580. if ( !empty( $helper_ids ) ) { 
  581. $api_params = array(); 
  582.  
  583. if ( true !== $helper_ids ) 
  584. $api_params[ 'ids' ] = (array) $helper_ids; 
  585.  
  586. $export[ 'helpers' ] = $api->load_helpers( $api_params ); 
  587.  
  588. $export = apply_filters( 'pods_packages_export', $export, $params ); 
  589.  
  590. if ( 1 == count( $export ) ) 
  591. return false; 
  592.  
  593. $export = version_compare( PHP_VERSION, '5.4.0', '>=' ) ? json_encode( $export, JSON_UNESCAPED_UNICODE ) : json_encode( $export ); 
  594.  
  595. return $export;