PodsAdmin

The Pods - Custom Content Types and Fields PodsAdmin class.

Defined (1)

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

/classes/PodsAdmin.php  
  1. class PodsAdmin { 
  2.  
  3. /** 
  4. * @var PodsAdmin 
  5. */ 
  6. static $instance = null; 
  7.  
  8. /** 
  9. * Singleton handling for a basic pods_admin() request 
  10. * @return \PodsAdmin 
  11. * @since 2.3.5 
  12. */ 
  13. public static function init () { 
  14. if ( !is_object( self::$instance ) ) 
  15. self::$instance = new PodsAdmin(); 
  16.  
  17. return self::$instance; 
  18.  
  19. /** 
  20. * Setup and Handle Admin functionality 
  21. * @return \PodsAdmin 
  22. * @license http://www.gnu.org/licenses/gpl-2.0.html 
  23. * @since 2.0 
  24. */ 
  25. public function __construct () { 
  26. // Scripts / Stylesheets 
  27. add_action( 'admin_enqueue_scripts', array( $this, 'admin_head' ), 20 ); 
  28.  
  29. // AJAX $_POST fix 
  30. add_action( 'admin_init', array( $this, 'admin_init' ), 9 ); 
  31.  
  32. // Menus 
  33. add_action( 'admin_menu', array( $this, 'admin_menu' ), 99 ); 
  34.  
  35. // AJAX for Admin 
  36. add_action( 'wp_ajax_pods_admin', array( $this, 'admin_ajax' ) ); 
  37. add_action( 'wp_ajax_nopriv_pods_admin', array( $this, 'admin_ajax' ) ); 
  38.  
  39. // Add Media Bar button for Shortcode 
  40. add_action( 'media_buttons', array( $this, 'media_button' ), 12 ); 
  41.  
  42. // Add the Pods capabilities 
  43. add_filter( 'members_get_capabilities', array( $this, 'admin_capabilities' ) ); 
  44.  
  45. add_action( 'admin_head-media-upload-popup', array( $this, 'register_media_assets' ) ); 
  46.  
  47. $this->rest_admin(); 
  48.  
  49.  
  50. /** 
  51. * Init the admin area 
  52. * @since 2.0 
  53. */ 
  54. public function admin_init () { 
  55. // Fix for plugins that *don't do it right* so we don't cause issues for users 
  56. if ( defined( 'DOING_AJAX' ) && !empty( $_POST ) ) { 
  57. $pods_admin_ajax_actions = array( 
  58. 'pods_admin',  
  59. 'pods_relationship',  
  60. 'pods_upload',  
  61. 'pods_admin_components' 
  62. ); 
  63.  
  64. /** 
  65. * Admin AJAX Callbacks 
  66. * @since unknown 
  67. * @param array $pods_admin_ajax_actions Array of actions to handle 
  68. */ 
  69. $pods_admin_ajax_actions = apply_filters( 'pods_admin_ajax_actions', $pods_admin_ajax_actions ); 
  70.  
  71. if ( in_array( pods_var( 'action', 'get' ), $pods_admin_ajax_actions ) || in_array( pods_var( 'action', 'post' ), $pods_admin_ajax_actions ) ) { 
  72. foreach ( $_POST as $key => $value ) { 
  73. if ( 'action' == $key || 0 === strpos( $key, '_podsfix_' ) ) 
  74. continue; 
  75.  
  76. unset( $_POST[ $key ] ); 
  77.  
  78. $_POST[ '_podsfix_' . $key ] = $value; 
  79.  
  80. /** 
  81. * Attach requirements to admin header 
  82. * @since 2.0 
  83. */ 
  84. public function admin_head () { 
  85. wp_register_style( 'pods-admin', PODS_URL . 'ui/css/pods-admin.css', array(), PODS_VERSION ); 
  86.  
  87. wp_register_style( 'pods-font', PODS_URL . 'ui/css/pods-font.css', array(), PODS_VERSION ); 
  88.  
  89. wp_register_script( 'pods-floatmenu', PODS_URL . 'ui/js/floatmenu.js', array(), PODS_VERSION ); 
  90.  
  91. wp_register_script( 'pods-admin-importer', PODS_URL . 'ui/js/admin-importer.js', array(), PODS_VERSION ); 
  92.  
  93. wp_register_style( 'pods-manage', PODS_URL . 'ui/css/pods-manage.css', array(), PODS_VERSION ); 
  94.  
  95. wp_register_style( 'pods-wizard', PODS_URL . 'ui/css/pods-wizard.css', array(), PODS_VERSION ); 
  96.  
  97. wp_register_script( 'pods-upgrade', PODS_URL . 'ui/js/jquery.pods.upgrade.js', array(), PODS_VERSION ); 
  98.  
  99. wp_register_script( 'pods-migrate', PODS_URL . 'ui/js/jquery.pods.migrate.js', array(), PODS_VERSION ); 
  100.  
  101. if ( isset( $_GET[ 'page' ] ) ) { 
  102. $page = $_GET[ 'page' ]; 
  103. if ( 'pods' == $page || ( false !== strpos( $page, 'pods-' ) && 0 === strpos( $page, 'pods-' ) ) ) { 
  104. ?> 
  105. <script type="text/javascript"> 
  106. var PODS_URL = "<?php echo esc_js( PODS_URL ); ?>"; 
  107. </script> 
  108. <?php 
  109. wp_enqueue_script( 'jquery' ); 
  110. wp_enqueue_script( 'jquery-ui-core' ); 
  111. wp_enqueue_script( 'jquery-ui-sortable' ); 
  112.  
  113. wp_enqueue_style( 'jquery-ui' ); 
  114.  
  115. wp_enqueue_script( 'pods-floatmenu' ); 
  116.  
  117. wp_enqueue_style( 'jquery-qtip2' ); 
  118. wp_enqueue_script( 'jquery-qtip2' ); 
  119. wp_enqueue_script( 'pods-qtip-init' ); 
  120.  
  121. wp_enqueue_script( 'pods' ); 
  122.  
  123. if ( 0 === strpos( $page, 'pods-manage-' ) || 0 === strpos( $page, 'pods-add-new-' ) ) 
  124. wp_enqueue_script( 'post' ); 
  125. elseif ( 0 === strpos( $page, 'pods-settings-' ) ) { 
  126. wp_enqueue_script( 'post' ); 
  127. wp_enqueue_style( 'pods-admin' ); 
  128. else 
  129. wp_enqueue_style( 'pods-admin' ); 
  130.  
  131. if ( 'pods-advanced' == $page ) { 
  132. wp_register_style( 'pods-advanced', PODS_URL . 'ui/css/pods-advanced.css', array(), '1.0' ); 
  133. wp_enqueue_style( 'pods-advanced' ); 
  134.  
  135. wp_enqueue_script( 'jquery-ui-effects-core', PODS_URL . 'ui/js/jquery-ui/jquery.effects.core.js', array( 'jquery' ), '1.8.8' ); 
  136. wp_enqueue_script( 'jquery-ui-effects-fade', PODS_URL . 'ui/js/jquery-ui/jquery.effects.fade.js', array( 'jquery' ), '1.8.8' ); 
  137. wp_enqueue_script( 'jquery-ui-dialog' ); 
  138.  
  139. wp_register_script( 'pods-advanced', PODS_URL . 'ui/js/advanced.js', array(), PODS_VERSION ); 
  140. wp_enqueue_script( 'pods-advanced' ); 
  141. elseif ( 'pods-packages' == $page ) 
  142. wp_enqueue_style( 'pods-wizard' ); 
  143. 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' ) ) ) ) { 
  144. wp_enqueue_style( 'pods-wizard' ); 
  145.  
  146. if ( 'pods-upgrade' == $page ) 
  147. wp_enqueue_script( 'pods-upgrade' ); 
  148.  
  149. wp_enqueue_style( 'pods-font' ); 
  150.  
  151. /** 
  152. * Build the admin menus 
  153. * @since 2.0 
  154. */ 
  155. public function admin_menu () { 
  156. $advanced_content_types = PodsMeta::$advanced_content_types; 
  157. $taxonomies = PodsMeta::$taxonomies; 
  158. $settings = PodsMeta::$settings; 
  159.  
  160. $all_pods = pods_api()->load_pods( array( 'count' => true ) ); 
  161.  
  162. if ( !PodsInit::$upgrade_needed || ( pods_is_admin() && 1 == pods_var( 'pods_upgrade_bypass' ) ) ) { 
  163. $submenu_items = array(); 
  164.  
  165. if ( !empty( $advanced_content_types ) ) { 
  166. $submenu = array(); 
  167.  
  168. $pods_pages = 0; 
  169.  
  170. foreach ( (array) $advanced_content_types as $pod ) { 
  171. if ( !isset( $pod[ 'name' ] ) || !isset( $pod[ 'options' ] ) || empty( $pod[ 'fields' ] ) ) 
  172. continue; 
  173. elseif ( !pods_is_admin( array( 'pods', 'pods_content', 'pods_add_' . $pod[ 'name' ], 'pods_edit_' . $pod[ 'name' ], 'pods_delete_' . $pod[ 'name' ] ) ) ) 
  174. continue; 
  175.  
  176. if ( 1 == pods_var( 'show_in_menu', $pod[ 'options' ], 0 ) ) { 
  177. $page_title = pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), null, true ); 
  178. $page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod ); 
  179.  
  180. $menu_label = pods_var_raw( 'menu_name', $pod[ 'options' ], $page_title, null, true ); 
  181. $menu_label = apply_filters( 'pods_admin_menu_label', $menu_label, $pod ); 
  182.  
  183. $singular_label = pods_var_raw( 'label_singular', $pod[ 'options' ], pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), null, true ), null, true ); 
  184. $plural_label = pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), null, true ); 
  185.  
  186. $menu_location = pods_var( 'menu_location', $pod[ 'options' ], 'objects' ); 
  187. $menu_location_custom = pods_var( 'menu_location_custom', $pod[ 'options' ], '' ); 
  188.  
  189. $menu_position = pods_var_raw( 'menu_position', $pod[ 'options' ], '', null, true ); 
  190. $menu_icon = pods_evaluate_tags( pods_var_raw( 'menu_icon', $pod[ 'options' ], '', null, true ), true ); 
  191.  
  192. if ( empty( $menu_position ) ) 
  193. $menu_position = null; 
  194.  
  195. $parent_page = null; 
  196.  
  197. if ( pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $pod[ 'name' ], 'pods_delete_' . $pod[ 'name' ] ) ) ) { 
  198. if ( !empty( $menu_location_custom ) ) { 
  199. if ( !isset( $submenu_items[ $menu_location_custom ] ) ) 
  200. $submenu_items[ $menu_location_custom ] = array(); 
  201.  
  202. $submenu_items[ $menu_location_custom ][] = array( $menu_location_custom, $page_title, $menu_label, 'read', 'pods-manage-' . $pod[ 'name' ], array( $this, 'admin_content' ) ); 
  203.  
  204. continue; 
  205. else { 
  206. $pods_pages++; 
  207.  
  208. $parent_page = $page = 'pods-manage-' . $pod[ 'name' ]; 
  209.  
  210. if ( empty( $menu_position ) ) 
  211. $menu_position = null; 
  212. add_menu_page( $page_title, $menu_label, 'read', $parent_page, '', $menu_icon, $menu_position ); 
  213.  
  214. $all_title = $plural_label; 
  215. $all_label = __( 'All', 'pods' ) . ' ' . $plural_label; 
  216.  
  217. if ( $page == pods_var( 'page', 'get' ) ) { 
  218. if ( 'edit' == pods_var( 'action', 'get', 'manage' ) ) 
  219. $all_title = __( 'Edit', 'pods' ) . ' ' . $singular_label; 
  220. elseif ( 'add' == pods_var( 'action', 'get', 'manage' ) ) 
  221. $all_title = __( 'Add New', 'pods' ) . ' ' . $singular_label; 
  222.  
  223. add_submenu_page( $parent_page, $all_title, $all_label, 'read', $page, array( $this, 'admin_content' ) ); 
  224.  
  225. if ( pods_is_admin( array( 'pods', 'pods_content', 'pods_add_' . $pod[ 'name' ] ) ) ) { 
  226. $page = 'pods-add-new-' . $pod[ 'name' ]; 
  227.  
  228. if ( null === $parent_page ) { 
  229. $pods_pages++; 
  230.  
  231. $parent_page = $page; 
  232.  
  233. if ( empty( $menu_position ) ) 
  234. $menu_position = null; 
  235. add_menu_page( $page_title, $menu_label, 'read', $parent_page, '', $menu_icon, $menu_position ); 
  236.  
  237. $add_title = __( 'Add New', 'pods' ) . ' ' . $singular_label; 
  238. $add_label = __( 'Add New', 'pods' ); 
  239.  
  240. add_submenu_page( $parent_page, $add_title, $add_label, 'read', $page, array( $this, 'admin_content' ) ); 
  241. else 
  242. $submenu[] = $pod; 
  243.  
  244. $submenu = apply_filters( 'pods_admin_menu_secondary_content', $submenu ); 
  245.  
  246. if ( !empty( $submenu ) && ( !defined( 'PODS_DISABLE_CONTENT_MENU' ) || !PODS_DISABLE_CONTENT_MENU ) ) { 
  247. $parent_page = null; 
  248.  
  249. foreach ( $submenu as $item ) { 
  250. $singular_label = pods_var_raw( 'label_singular', $item[ 'options' ], pods_var_raw( 'label', $item, ucwords( str_replace( '_', ' ', $item[ 'name' ] ) ), null, true ), null, true ); 
  251. $plural_label = pods_var_raw( 'label', $item, ucwords( str_replace( '_', ' ', $item[ 'name' ] ) ), null, true ); 
  252.  
  253. if ( pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $item[ 'name' ], 'pods_delete_' . $item[ 'name' ] ) ) ) { 
  254. $page = 'pods-manage-' . $item[ 'name' ]; 
  255.  
  256. if ( null === $parent_page ) { 
  257. $parent_page = $page; 
  258.  
  259. add_menu_page( 'Pods', 'Pods', 'read', $parent_page, null, 'dashicons-pods', '58.5' ); 
  260.  
  261. $all_title = $plural_label; 
  262. $all_label = __( 'Manage', 'pods' ) . ' ' . $plural_label; 
  263.  
  264. if ( $page == pods_var( 'page', 'get' ) ) { 
  265. if ( 'edit' == pods_var( 'action', 'get', 'manage' ) ) 
  266. $all_title = __( 'Edit', 'pods' ) . ' ' . $singular_label; 
  267. elseif ( 'add' == pods_var( 'action', 'get', 'manage' ) ) 
  268. $all_title = __( 'Add New', 'pods' ) . ' ' . $singular_label; 
  269.  
  270. add_submenu_page( $parent_page, $all_title, $all_label, 'read', $page, array( $this, 'admin_content' ) ); 
  271. elseif ( current_user_can( 'pods_add_' . $item[ 'name' ] ) ) { 
  272. $page = 'pods-add-new-' . $item[ 'name' ]; 
  273.  
  274. if ( null === $parent_page ) { 
  275. $parent_page = $page; 
  276.  
  277. add_menu_page( 'Pods', 'Pods', 'read', $parent_page, null, 'dashicons-pods', '58.5' ); 
  278.  
  279. $add_title = __( 'Add New', 'pods' ) . ' ' . $singular_label; 
  280. $add_label = __( 'Manage', 'pods' ) . ' ' . $plural_label; 
  281.  
  282. add_submenu_page( $parent_page, $add_title, $add_label, 'read', $page, array( $this, 'admin_content' ) ); 
  283.  
  284. if ( !empty( $taxonomies ) ) { 
  285. foreach ( (array) $taxonomies as $pod ) { 
  286. if ( !pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $pod[ 'name' ] ) ) ) 
  287. continue; 
  288.  
  289. $page_title = pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), null, true ); 
  290. $page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod ); 
  291.  
  292. $menu_label = pods_var_raw( 'menu_name', $pod[ 'options' ], $page_title, null, true ); 
  293. $menu_label = apply_filters( 'pods_admin_menu_label', $menu_label, $pod ); 
  294.  
  295. $menu_position = pods_var_raw( 'menu_position', $pod[ 'options' ], '', null, true ); 
  296. $menu_icon = pods_evaluate_tags( pods_var_raw( 'menu_icon', $pod[ 'options' ], '', null, true ), true ); 
  297.  
  298. if ( empty( $menu_position ) ) 
  299. $menu_position = null; 
  300.  
  301. $menu_slug = 'edit-tags.php?taxonomy=' . $pod[ 'name' ]; 
  302. $menu_location = pods_var( 'menu_location', $pod[ 'options' ], 'default' ); 
  303. $menu_location_custom = pods_var( 'menu_location_custom', $pod[ 'options' ], '' ); 
  304.  
  305. if ( 'default' == $menu_location ) 
  306. continue; 
  307.  
  308. $taxonomy_data = get_taxonomy( $pod[ 'name' ] ); 
  309.  
  310. foreach ( (array) $taxonomy_data->object_type as $post_type ) { 
  311. if ( 'post' == $post_type ) 
  312. remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=' . $pod[ 'name' ] ); 
  313. elseif ( 'attachment' == $post_type ) 
  314. remove_submenu_page( 'upload.php', 'edit-tags.php?taxonomy=' . $pod[ 'name' ] . '&post_type=' . $post_type ); 
  315. else 
  316. remove_submenu_page( 'edit.php?post_type=' . $post_type, 'edit-tags.php?taxonomy=' . $pod[ 'name' ] . '&post_type=' . $post_type ); 
  317.  
  318. if ( 'settings' == $menu_location ) 
  319. add_options_page( $page_title, $menu_label, 'read', $menu_slug ); 
  320. elseif ( 'appearances' == $menu_location ) 
  321. add_theme_page( $page_title, $menu_label, 'read', $menu_slug ); 
  322. elseif ( 'objects' == $menu_location ) { 
  323. if ( empty( $menu_position ) ) 
  324. $menu_position = null; 
  325. add_menu_page( $page_title, $menu_label, 'read', $menu_slug, '', $menu_icon, $menu_position ); 
  326. elseif ( 'top' == $menu_location ) 
  327. add_menu_page( $page_title, $menu_label, 'read', $menu_slug, '', $menu_icon, $menu_position ); 
  328. elseif ( 'submenu' == $menu_location && !empty( $menu_location_custom ) ) { 
  329. if ( !isset( $submenu_items[ $menu_location_custom ] ) ) 
  330. $submenu_items[ $menu_location_custom ] = array(); 
  331.  
  332. $submenu_items[ $menu_location_custom ][] = array( $menu_location_custom, $page_title, $menu_label, 'read', $menu_slug, '' ); 
  333.  
  334. if ( !empty( $settings ) ) { 
  335. foreach ( (array) $settings as $pod ) { 
  336. if ( !pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $pod[ 'name' ] ) ) ) 
  337. continue; 
  338.  
  339. $page_title = pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), null, true ); 
  340. $page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod ); 
  341.  
  342. $menu_label = pods_var_raw( 'menu_name', $pod[ 'options' ], $page_title, null, true ); 
  343. $menu_label = apply_filters( 'pods_admin_menu_label', $menu_label, $pod ); 
  344.  
  345. $menu_position = pods_var_raw( 'menu_position', $pod[ 'options' ], '', null, true ); 
  346. $menu_icon = pods_evaluate_tags( pods_var_raw( 'menu_icon', $pod[ 'options' ], '', null, true ), true ); 
  347.  
  348. if ( empty( $menu_position ) ) 
  349. $menu_position = null; 
  350.  
  351. $menu_slug = 'pods-settings-' . $pod[ 'name' ]; 
  352. $menu_location = pods_var( 'menu_location', $pod[ 'options' ], 'settings' ); 
  353. $menu_location_custom = pods_var( 'menu_location_custom', $pod[ 'options' ], '' ); 
  354.  
  355. if ( 'settings' == $menu_location ) 
  356. add_options_page( $page_title, $menu_label, 'read', $menu_slug, array( $this, 'admin_content_settings' ) ); 
  357. elseif ( 'appearances' == $menu_location ) 
  358. add_theme_page( $page_title, $menu_label, 'read', $menu_slug, array( $this, 'admin_content_settings' ) ); 
  359. elseif ( 'objects' == $menu_location ) { 
  360. if ( empty( $menu_position ) ) 
  361. $menu_position = null; 
  362. add_menu_page( $page_title, $menu_label, 'read', $menu_slug, array( $this, 'admin_content_settings' ), $menu_icon, $menu_position ); 
  363. elseif ( 'top' == $menu_location ) 
  364. add_menu_page( $page_title, $menu_label, 'read', $menu_slug, array( $this, 'admin_content_settings' ), $menu_icon, $menu_position ); 
  365. elseif ( 'submenu' == $menu_location && !empty( $menu_location_custom ) ) { 
  366. if ( !isset( $submenu_items[ $menu_location_custom ] ) ) 
  367. $submenu_items[ $menu_location_custom ] = array(); 
  368.  
  369. $submenu_items[ $menu_location_custom ][] = array( $menu_location_custom, $page_title, $menu_label, 'read', $menu_slug, array( $this, 'admin_content_settings' ) ); 
  370.  
  371. foreach ( $submenu_items as $items ) { 
  372. foreach ( $items as $item ) { 
  373. call_user_func_array( 'add_submenu_page', $item ); 
  374.  
  375. $admin_menus = array( 
  376. 'pods' => array( 
  377. 'label' => __( 'Edit Pods', 'pods' ),  
  378. 'function' => array( $this, 'admin_setup' ),  
  379. 'access' => 'pods' 
  380. ),  
  381. 'pods-add-new' => array( 
  382. 'label' => __( 'Add New', 'pods' ),  
  383. 'function' => array( $this, 'admin_setup' ),  
  384. 'access' => 'pods' 
  385. ),  
  386. 'pods-components' => array( 
  387. 'label' => __( 'Components', 'pods' ),  
  388. 'function' => array( $this, 'admin_components' ),  
  389. 'access' => 'pods_components' 
  390. ),  
  391. 'pods-settings' => array( 
  392. 'label' => __( 'Settings', 'pods' ),  
  393. 'function' => array( $this, 'admin_settings' ),  
  394. 'access' => 'pods_settings' 
  395. ),  
  396. 'pods-help' => array( 
  397. 'label' => __( 'Help', 'pods' ),  
  398. 'function' => array( $this, 'admin_help' ) 
  399. ); 
  400.  
  401. if ( empty( $all_pods ) ) 
  402. unset( $admin_menus[ 'pods' ] ); 
  403.  
  404. add_filter( 'parent_file' , array( $this, 'parent_file' ) ); 
  405. else { 
  406. $admin_menus = array( 
  407. 'pods-upgrade' => array( 
  408. 'label' => __( 'Upgrade', 'pods' ),  
  409. 'function' => array( $this, 'admin_upgrade' ),  
  410. 'access' => 'manage_options' 
  411. ),  
  412. 'pods-settings' => array( 
  413. 'label' => __( 'Settings', 'pods' ),  
  414. 'function' => array( $this, 'admin_settings' ),  
  415. 'access' => 'pods_settings' 
  416. ),  
  417. 'pods-help' => array( 
  418. 'label' => __( 'Help', 'pods' ),  
  419. 'function' => array( $this, 'admin_help' ) 
  420. ); 
  421.  
  422. add_action( 'admin_notices', array( $this, 'upgrade_notice' ) ); 
  423.  
  424. /** 
  425. * Add or change Pods Admin menu items 
  426. * @params array $admin_menus The submenu items in Pods Admin menu. 
  427. * @since unknown 
  428. */ 
  429. $admin_menus = apply_filters( 'pods_admin_menu', $admin_menus ); 
  430.  
  431. $parent = false; 
  432.  
  433. if ( !empty( $admin_menus ) && ( !defined( 'PODS_DISABLE_ADMIN_MENU' ) || !PODS_DISABLE_ADMIN_MENU ) ) { 
  434. foreach ( $admin_menus as $page => $menu_item ) { 
  435. if ( !pods_is_admin( pods_var_raw( 'access', $menu_item ) ) ) 
  436. continue; 
  437.  
  438. // Don't just show the help page 
  439. if ( false === $parent && 'pods-help' == $page ) 
  440. continue; 
  441.  
  442. if ( !isset( $menu_item[ 'label' ] ) ) 
  443. $menu_item[ 'label' ] = $page; 
  444.  
  445. if ( false === $parent ) { 
  446. $parent = $page; 
  447.  
  448. $menu = __( 'Pods Admin', 'pods' ); 
  449.  
  450. if ( 'pods-upgrade' == $parent ) 
  451. $menu = __( 'Pods Upgrade', 'pods' ); 
  452.  
  453. add_menu_page( $menu, $menu, 'read', $parent, null, 'dashicons-pods' ); 
  454.  
  455. add_submenu_page( $parent, $menu_item[ 'label' ], $menu_item[ 'label' ], 'read', $page, $menu_item[ 'function' ] ); 
  456.  
  457. if ( 'pods-components' == $page ) 
  458. PodsInit::$components->menu( $parent ); 
  459.  
  460. /** 
  461. * Set the correct parent_file to highlight the correct top level menu 
  462. * @param $parent_file The parent file 
  463. * @return mixed|string 
  464. * @since unknown 
  465. */ 
  466. public function parent_file ( $parent_file ) { 
  467. global $current_screen; 
  468.  
  469. if ( isset( $current_screen ) && ! empty( $current_screen->taxonomy ) ) { 
  470. $taxonomies = PodsMeta::$taxonomies; 
  471. if ( !empty( $taxonomies ) ) { 
  472. foreach ( (array) $taxonomies as $pod ) { 
  473. if ( $current_screen->taxonomy !== $pod[ 'name' ] ) 
  474. continue; 
  475.  
  476. $menu_slug = 'edit-tags.php?taxonomy=' . $pod[ 'name' ]; 
  477. $menu_location = pods_var( 'menu_location', $pod[ 'options' ], 'default' ); 
  478. $menu_location_custom = pods_var( 'menu_location_custom', $pod[ 'options' ], '' ); 
  479.  
  480. if ( 'settings' == $menu_location ) 
  481. $parent_file = 'options-general.php'; 
  482. elseif ( 'appearances' == $menu_location ) 
  483. $parent_file = 'themes.php'; 
  484. elseif ( 'objects' == $menu_location ) 
  485. $parent_file = $menu_slug; 
  486. elseif ( 'top' == $menu_location ) 
  487. $parent_file = $menu_slug; 
  488. elseif ( 'submenu' == $menu_location && !empty( $menu_location_custom ) ) { 
  489. $parent_file = $menu_location_custom; 
  490.  
  491. break; 
  492.  
  493. if ( isset( $current_screen ) && ! empty( $current_screen->post_type ) ) { 
  494. global $submenu_file; 
  495. $components = PodsInit::$components->components; 
  496. foreach ( $components as $component => $component_data ) { 
  497. if ( ! empty( $component_data[ 'MenuPage' ] ) && $parent_file === $component_data[ 'MenuPage' ] ) { 
  498. $parent_file = 'pods'; 
  499. $submenu_file = $component_data[ 'MenuPage' ]; 
  500.  
  501. return $parent_file; 
  502.  
  503. public function upgrade_notice () { 
  504. echo '<div class="error fade"><p>'; 
  505. echo sprintf( 
  506. __( '<strong>NOTICE:</strong> Pods %s requires your action to complete the upgrade. Please run the <a href="%s">Upgrade Wizard</a>.', 'pods' ),  
  507. esc_html( PODS_VERSION ),  
  508. esc_url( admin_url( 'admin.php?page=pods-upgrade' ) ) 
  509. ); 
  510. echo '</p></div>'; 
  511.  
  512. /** 
  513. * Create PodsUI content for the administration pages 
  514. */ 
  515. public function admin_content () { 
  516. $pod_name = str_replace( array( 'pods-manage-', 'pods-add-new-' ), '', $_GET[ 'page' ] ); 
  517.  
  518. $pod = pods( $pod_name, pods_var( 'id', 'get', null, null, true ) ); 
  519.  
  520. if ( false !== strpos( $_GET[ 'page' ], 'pods-add-new-' ) ) 
  521. $_GET[ 'action' ] = pods_var( 'action', 'get', 'add' ); 
  522.  
  523. $pod->ui(); 
  524.  
  525. /** 
  526. * Create PodsUI content for the settings administration pages 
  527. */ 
  528. public function admin_content_settings () { 
  529. $pod_name = str_replace( 'pods-settings-', '', $_GET[ 'page' ] ); 
  530.  
  531. $pod = pods( $pod_name ); 
  532.  
  533. if ( 'custom' != pods_var( 'ui_style', $pod->pod_data[ 'options' ], 'settings', null, true ) ) { 
  534. $actions_disabled = array( 
  535. 'manage' => 'manage',  
  536. 'add' => 'add',  
  537. 'delete' => 'delete',  
  538. 'duplicate' => 'duplicate',  
  539. 'view' => 'view',  
  540. 'export' => 'export' 
  541. ); 
  542.  
  543. $_GET[ 'action' ] = 'edit'; 
  544.  
  545. $page_title = pods_var_raw( 'label', $pod->pod_data, ucwords( str_replace( '_', ' ', $pod->pod_data[ 'name' ] ) ), null, true ); 
  546.  
  547. $ui = array( 
  548. 'pod' => $pod,  
  549. 'fields' => array( 
  550. 'edit' => $pod->pod_data[ 'fields' ] 
  551. ),  
  552. 'header' => array( 
  553. 'edit' => $page_title 
  554. ),  
  555. 'label' => array( 
  556. 'edit' => __( 'Save Changes', 'pods' ) 
  557. ),  
  558. 'style' => pods_var( 'ui_style', $pod->pod_data[ 'options' ], 'settings', null, true ),  
  559. 'icon' => pods_evaluate_tags( pods_var_raw( 'menu_icon', $pod->pod_data[ 'options' ] ), true ),  
  560. 'actions_disabled' => $actions_disabled 
  561. ); 
  562.  
  563. $ui = apply_filters( 'pods_admin_ui_' . $pod->pod, apply_filters( 'pods_admin_ui', $ui, $pod->pod, $pod ), $pod->pod, $pod ); 
  564.  
  565. // Force disabled actions, do not pass go, do not collect $two_hundred 
  566. $ui[ 'actions_disabled' ] = $actions_disabled; 
  567.  
  568. pods_ui( $ui ); 
  569. else { 
  570. do_action( 'pods_admin_ui_custom', $pod ); 
  571. do_action( 'pods_admin_ui_custom_' . $pod->pod, $pod ); 
  572.  
  573. /** 
  574. * Add media button for Pods shortcode 
  575. * @param $context 
  576. * @return string 
  577. */ 
  578. public function media_button ( $context = null ) { 
  579. // If shortcodes are disabled don't show the button 
  580. if ( defined( 'PODS_DISABLE_SHORTCODE' ) && PODS_DISABLE_SHORTCODE ) { 
  581. return ''; 
  582.  
  583. /** 
  584. * Filter to remove Pods shortcode button from the post editor. 
  585. * @param bool. Set to false to block the shortcode button from appearing. 
  586. * @param string $context 
  587. * @since 2.3.19 
  588. */ 
  589. if ( !apply_filters( 'pods_admin_media_button', true, $context ) ) { 
  590. return ''; 
  591.  
  592. $current_page = basename( $_SERVER[ 'PHP_SELF' ] ); 
  593. $current_page = explode( '?', $current_page ); 
  594. $current_page = explode( '#', $current_page[ 0 ] ); 
  595. $current_page = $current_page[ 0 ]; 
  596.  
  597. // Only show the button on post type pages 
  598. if ( !in_array( $current_page, array( 'post-new.php', 'post.php' ) ) ) 
  599. return ''; 
  600.  
  601. add_action( 'admin_footer', array( $this, 'mce_popup' ) ); 
  602.  
  603. 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>'; 
  604.  
  605. /** 
  606. * Enqueue assets for Media Library Popup 
  607. */ 
  608. public function register_media_assets () { 
  609. if ( 'pods_media_attachment' == pods_var( 'inlineId', 'get' ) ) 
  610. wp_enqueue_style( 'pods-attach' ); 
  611.  
  612. /** 
  613. * Output Pods shortcode popup window 
  614. */ 
  615. public function mce_popup () { 
  616. pods_view( PODS_DIR . 'ui/admin/shortcode.php', compact( array_keys( get_defined_vars() ) ) ); 
  617.  
  618. /** 
  619. * Handle main Pods Setup area for managing Pods and Fields 
  620. */ 
  621. public function admin_setup () { 
  622. $pods = pods_api()->load_pods( array( 'fields' => false ) ); 
  623.  
  624. $view = pods_var( 'view', 'get', 'all', null, true ); 
  625.  
  626. if ( empty( $pods ) && !isset( $_GET[ 'action' ] ) ) 
  627. $_GET[ 'action' ] = 'add'; 
  628.  
  629. if ( 'pods-add-new' == $_GET[ 'page' ] ) { 
  630. if ( isset( $_GET[ 'action' ] ) && 'add' != $_GET[ 'action' ] ) 
  631. pods_redirect( pods_query_arg( array( 'page' => 'pods', 'action' => $_GET[ 'action' ] ) ) ); 
  632. else 
  633. $_GET[ 'action' ] = 'add'; 
  634. elseif ( isset( $_GET[ 'action' ] ) && 'add' == $_GET[ 'action' ] ) 
  635. pods_redirect( pods_query_arg( array( 'page' => 'pods-add-new', 'action' => '' ) ) ); 
  636.  
  637. $types = array( 
  638. 'post_type' => __( 'Post Type (extended)', 'pods' ),  
  639. 'taxonomy' => __( 'Taxonomy (extended)', 'pods' ),  
  640. 'cpt' => __( 'Custom Post Type', 'pods' ),  
  641. 'ct' => __( 'Custom Taxonomy', 'pods' ),  
  642. 'user' => __( 'User (extended)', 'pods' ),  
  643. 'media' => __( 'Media (extended)', 'pods' ),  
  644. 'comment' => __( 'Comments (extended)', 'pods' ),  
  645. 'pod' => __( 'Advanced Content Type', 'pods' ),  
  646. 'settings' => __( 'Custom Settings Page', 'pods' ) 
  647. ); 
  648.  
  649. $row = false; 
  650.  
  651. $pod_types_found = array(); 
  652.  
  653. $fields = array( 
  654. 'label' => array( 'label' => __( 'Label', 'pods' ) ),  
  655. 'name' => array( 'label' => __( 'Name', 'pods' ) ),  
  656. 'type' => array( 'label' => __( 'Type', 'pods' ) ),  
  657. 'storage' => array( 
  658. 'label' => __( 'Storage Type', 'pods' ),  
  659. 'width' => '10%' 
  660. ),  
  661. 'field_count' => array( 
  662. 'label' => __( 'Number of Fields', 'pods' ),  
  663. 'width' => '8%' 
  664. ); 
  665.  
  666. $total_fields = 0; 
  667.  
  668. foreach ( $pods as $k => $pod ) { 
  669. if ( isset( $types[ $pod[ 'type' ] ] ) ) { 
  670. if ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) ) { 
  671. if ( empty( $pod[ 'object' ] ) ) { 
  672. if ( 'post_type' == $pod[ 'type' ] ) 
  673. $pod[ 'type' ] = 'cpt'; 
  674. else 
  675. $pod[ 'type' ] = 'ct'; 
  676.  
  677. if ( !isset( $pod_types_found[ $pod[ 'type' ] ] ) ) 
  678. $pod_types_found[ $pod[ 'type' ] ] = 1; 
  679. else 
  680. $pod_types_found[ $pod[ 'type' ] ]++; 
  681.  
  682. if ( 'all' != $view && $view != $pod[ 'type' ] ) { 
  683. unset( $pods[ $k ] ); 
  684.  
  685. continue; 
  686.  
  687. $pod[ 'real_type' ] = $pod[ 'type' ]; 
  688. $pod[ 'type' ] = $types[ $pod[ 'type' ] ]; 
  689. elseif ( 'all' != $view ) 
  690. continue; 
  691.  
  692. $pod[ 'storage' ] = ucwords( $pod[ 'storage' ] ); 
  693.  
  694. if ( $pod[ 'id' ] == pods_var( 'id' ) && 'delete' != pods_var( 'action' ) ) 
  695. $row = $pod; 
  696.  
  697. $pod = array( 
  698. 'id' => $pod[ 'id' ],  
  699. 'label' => pods_var_raw( 'label', $pod ),  
  700. 'name' => pods_var_raw( 'name', $pod ),  
  701. 'object' => pods_var_raw( 'object', $pod ),  
  702. 'type' => pods_var_raw( 'type', $pod ),  
  703. 'real_type' => pods_var_raw( 'real_type', $pod ),  
  704. 'storage' => pods_var_raw( 'storage', $pod ),  
  705. 'field_count' => count( $pod[ 'fields' ] ) 
  706. ); 
  707.  
  708. $total_fields += $pod[ 'field_count' ]; 
  709.  
  710. $pods[ $k ] = $pod; 
  711.  
  712. if ( false === $row && 0 < pods_var( 'id' ) && 'delete' != pods_var( 'action' ) ) { 
  713. pods_message( 'Pod not found', 'error' ); 
  714.  
  715. unset( $_GET[ 'id' ] ); 
  716. unset( $_GET[ 'action' ] ); 
  717.  
  718. $ui = array( 
  719. 'data' => $pods,  
  720. 'row' => $row,  
  721. 'total' => count( $pods ),  
  722. 'total_found' => count( $pods ),  
  723. 'items' => 'Pods',  
  724. 'item' => 'Pod',  
  725. 'fields' => array( 
  726. 'manage' => $fields 
  727. ),  
  728. 'actions_disabled' => array( 'view', 'export' ),  
  729. 'actions_custom' => array( 
  730. 'add' => array( $this, 'admin_setup_add' ),  
  731. 'edit' => array( $this, 'admin_setup_edit' ),  
  732. 'duplicate' => array( 
  733. 'callback' => array( $this, 'admin_setup_duplicate' ),  
  734. 'restrict_callback' => array( $this, 'admin_setup_duplicate_restrict' ) 
  735. ),  
  736. 'reset' => array( 
  737. 'label' => __( 'Delete All Items', 'pods' ),  
  738. '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' ),  
  739. 'callback' => array( $this, 'admin_setup_reset' ),  
  740. 'restrict_callback' => array( $this, 'admin_setup_reset_restrict' ),  
  741. 'nonce' => true 
  742. ),  
  743. 'delete' => array( $this, 'admin_setup_delete' ) 
  744. ),  
  745. 'action_links' => array( 
  746. 'add' => pods_query_arg( array( 'page' => 'pods-add-new', 'action' => '', 'id' => '', 'do' => '' ) ) 
  747. ),  
  748. 'search' => false,  
  749. 'searchable' => false,  
  750. 'sortable' => true,  
  751. 'pagination' => false,  
  752. 'extra' => array( 
  753. 'total' => ', ' . number_format_i18n( $total_fields ) . ' ' . _n( 'field', 'fields', $total_fields, 'pods' ) 
  754. ); 
  755.  
  756. if ( 1 < count( $pod_types_found ) ) { 
  757. $ui[ 'views' ] = array( 'all' => __( 'All', 'pods' ) ); 
  758. $ui[ 'view' ] = $view; 
  759. $ui[ 'heading' ] = array( 'views' => __( 'Type', 'pods' ) ); 
  760. $ui[ 'filters_enhanced' ] = true; 
  761.  
  762. foreach ( $pod_types_found as $pod_type => $number_found ) { 
  763. $ui[ 'views' ][ $pod_type ] = $types[ $pod_type ]; 
  764.  
  765. pods_ui( $ui ); 
  766.  
  767. /** 
  768. * Get the add page of an object 
  769. * @param $obj 
  770. */ 
  771. public function admin_setup_add ( $obj ) { 
  772. pods_view( PODS_DIR . 'ui/admin/setup-add.php', compact( array_keys( get_defined_vars() ) ) ); 
  773.  
  774. /** 
  775. * Get the edit page of an object 
  776. * @param $duplicate 
  777. * @param $obj 
  778. */ 
  779. public function admin_setup_edit ( $duplicate, $obj ) { 
  780. pods_view( PODS_DIR . 'ui/admin/setup-edit.php', compact( array_keys( get_defined_vars() ) ) ); 
  781.  
  782. /** 
  783. * Get list of Pod option tabs 
  784. * @return array 
  785. */ 
  786. public function admin_setup_edit_tabs ( $pod ) { 
  787. $fields = true; 
  788. $labels = false; 
  789. $admin_ui = false; 
  790. $advanced = false; 
  791.  
  792. if ( 'post_type' == pods_var( 'type', $pod ) && strlen( pods_var( 'object', $pod ) ) < 1 ) { 
  793. $labels = true; 
  794. $admin_ui = true; 
  795. $advanced = true; 
  796. elseif ( 'taxonomy' == pods_var( 'type', $pod ) && strlen( pods_var( 'object', $pod ) ) < 1 ) { 
  797. $labels = true; 
  798. $admin_ui = true; 
  799. $advanced = true; 
  800. elseif ( 'pod' == pods_var( 'type', $pod ) ) { 
  801. $labels = true; 
  802. $admin_ui = true; 
  803. $advanced = true; 
  804. elseif ( 'settings' == pods_var( 'type', $pod ) ) { 
  805. $labels = true; 
  806. $admin_ui = true; 
  807.  
  808. if ( ! function_exists( 'get_term_meta' ) && 'none' == pods_var( 'storage', $pod, 'none', null, true ) && 'taxonomy' == pods_var( 'type', $pod ) ) 
  809. $fields = false; 
  810.  
  811. $tabs = array(); 
  812.  
  813. if ( $fields ) 
  814. $tabs[ 'manage-fields' ] = __( 'Manage Fields', 'pods' ); 
  815.  
  816. if ( $labels ) 
  817. $tabs[ 'labels' ] = __( 'Labels', 'pods' ); 
  818.  
  819. if ( $admin_ui ) 
  820. $tabs[ 'admin-ui' ] = __( 'Admin UI', 'pods' ); 
  821.  
  822. if ( $advanced ) 
  823. $tabs[ 'advanced' ] = __( 'Advanced Options', 'pods' ); 
  824.  
  825. if ( 'taxonomy' == pods_var( 'type', $pod ) && !$fields ) 
  826. $tabs[ 'extra-fields' ] = __( 'Extra Fields', 'pods' ); 
  827.  
  828. $addtl_args = compact( array( 'fields', 'labels', 'admin_ui', 'advanced' ) ); 
  829.  
  830. /** 
  831. * Add or modify tabs in Pods editor for a specific Pod 
  832. * @params array $tabs Tabs to set. 
  833. * @params object $pod Current Pods object 
  834. * @params array $addtl_args Additional args. 
  835. * @since unknown 
  836. */ 
  837. $tabs = apply_filters( 'pods_admin_setup_edit_tabs_' . $pod[ 'type' ] . '_' . $pod[ 'name' ], $tabs, $pod, $addtl_args ); 
  838.  
  839. /** 
  840. * Add or modify tabs for any Pod in Pods editor of a specific post type. 
  841. */ 
  842. $tabs = apply_filters( 'pods_admin_setup_edit_tabs_' . $pod[ 'type' ], $tabs, $pod, $addtl_args ); 
  843.  
  844. /** 
  845. * Add or modify tabs in Pods editor for all pods. 
  846. */ 
  847. $tabs = apply_filters( 'pods_admin_setup_edit_tabs', $tabs, $pod, $addtl_args ); 
  848.  
  849. return $tabs; 
  850.  
  851. /** 
  852. * Get list of Pod options 
  853. * @return array 
  854. */ 
  855. public function admin_setup_edit_options ( $pod ) { 
  856. $options = array(); 
  857.  
  858. // @todo fill this in 
  859. $options[ 'labels' ] = array( 
  860. 'temporary' => 'This has the fields hardcoded' // :( 
  861. ); 
  862.  
  863. if ( 'post_type' == $pod[ 'type' ] ) { 
  864. $options[ 'admin-ui' ] = array( 
  865. 'description' => array( 
  866. 'label' => __( 'Post Type Description', 'pods' ),  
  867. 'help' => __( 'A short descriptive summary of what the post type is.', 'pods' ),  
  868. 'type' => 'text',  
  869. 'default' => '' 
  870. ),  
  871. 'show_ui' => array( 
  872. 'label' => __( 'Show Admin UI', 'pods' ),  
  873. 'help' => __( 'help', 'pods' ),  
  874. 'type' => 'boolean',  
  875. 'default' => pods_var_raw( 'public', $pod, true ),  
  876. 'boolean_yes_label' => '' 
  877. ),  
  878. 'show_in_menu' => array( 
  879. 'label' => __( 'Show Admin Menu in Dashboard', 'pods' ),  
  880. 'help' => __( 'help', 'pods' ),  
  881. 'type' => 'boolean',  
  882. 'default' => pods_var_raw( 'public', $pod, true ),  
  883. 'dependency' => true,  
  884. 'boolean_yes_label' => '' 
  885. ),  
  886. 'menu_location_custom' => array( 
  887. 'label' => __( 'Parent Menu ID (optional)', 'pods' ),  
  888. 'help' => __( 'help', 'pods' ),  
  889. 'type' => 'text',  
  890. 'depends-on' => array( 'show_in_menu' => true ) 
  891. ),  
  892. 'menu_name' => array( 
  893. 'label' => __( 'Menu Name', 'pods' ),  
  894. 'help' => __( 'help', 'pods' ),  
  895. 'type' => 'text',  
  896. 'default' => '',  
  897. 'depends-on' => array( 'show_in_menu' => true ) 
  898. ),  
  899. 'menu_position' => array( 
  900. 'label' => __( 'Menu Position', 'pods' ),  
  901. 'help' => __( 'help', 'pods' ),  
  902. 'type' => 'number',  
  903. 'default' => 0,  
  904. 'depends-on' => array( 'show_in_menu' => true ) 
  905. ),  
  906. 'menu_icon' => array( 
  907. 'label' => __( 'Menu Icon', 'pods' ),  
  908. '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' ),  
  909. 'type' => 'text',  
  910. 'default' => '',  
  911. 'depends-on' => array( 'show_in_menu' => true ) 
  912. ),  
  913. 'show_in_nav_menus' => array( 
  914. 'label' => __( 'Show in Navigation Menus', 'pods' ),  
  915. 'help' => __( 'help', 'pods' ),  
  916. 'type' => 'boolean',  
  917. 'default' => true,  
  918. 'boolean_yes_label' => '' 
  919. ),  
  920. 'show_in_admin_bar' => array( 
  921. 'label' => __( 'Show in Admin Bar "New" Menu', 'pods' ),  
  922. 'help' => __( 'help', 'pods' ),  
  923. 'type' => 'boolean',  
  924. 'default' => true,  
  925. 'boolean_yes_label' => '' 
  926. ); 
  927.  
  928. $options[ 'advanced' ] = array( 
  929. 'public' => array( 
  930. 'label' => __( 'Public', 'pods' ),  
  931. 'help' => __( 'help', 'pods' ),  
  932. 'type' => 'boolean',  
  933. 'default' => true,  
  934. 'boolean_yes_label' => '' 
  935. ),  
  936. 'publicly_queryable' => array( 
  937. 'label' => __( 'Publicly Queryable', 'pods' ),  
  938. 'help' => __( 'help', 'pods' ),  
  939. 'type' => 'boolean',  
  940. 'default' => pods_var_raw( 'public', $pod, true ),  
  941. 'boolean_yes_label' => '' 
  942. ),  
  943. 'exclude_from_search' => array( 
  944. 'label' => __( 'Exclude from Search', 'pods' ),  
  945. 'help' => __( 'help', 'pods' ),  
  946. 'type' => 'boolean',  
  947. 'default' => !pods_var_raw( 'public', $pod, true ),  
  948. 'boolean_yes_label' => '' 
  949. ),  
  950. 'capability_type' => array( 
  951. 'label' => __( 'User Capability', 'pods' ),  
  952. 'help' => __( 'Uses these capabilties for access to this post type: edit_{capability}, read_{capability}, and delete_{capability}', 'pods' ),  
  953. 'type' => 'pick',  
  954. 'default' => 'post',  
  955. 'data' => array( 
  956. 'post' => 'post',  
  957. 'page' => 'page',  
  958. 'custom' => __( 'Custom Capability', 'pods' ) 
  959. ),  
  960. 'dependency' => true 
  961. ),  
  962. 'capability_type_custom' => array( 
  963. 'label' => __( 'Custom User Capability', 'pods' ),  
  964. 'help' => __( 'help', 'pods' ),  
  965. 'type' => 'text',  
  966. 'default' => pods_var_raw( 'name', $pod ),  
  967. 'depends-on' => array( 'capability_type' => 'custom' ) 
  968. ),  
  969. 'capability_type_extra' => array( 
  970. 'label' => __( 'Additional User Capabilities', 'pods' ),  
  971. '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' ),  
  972. 'type' => 'boolean',  
  973. 'default' => true,  
  974. 'boolean_yes_label' => '' 
  975. ),  
  976. 'has_archive' => array( 
  977. 'label' => __( 'Enable Archive Page', 'pods' ),  
  978. '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' ),  
  979. 'type' => 'boolean',  
  980. 'default' => false,  
  981. 'dependency' => true,  
  982. 'boolean_yes_label' => '' 
  983. ),  
  984. 'has_archive_slug' => array( 
  985. 'label' => __( 'Archive Page Slug Override', 'pods' ),  
  986. 'help' => __( 'If archive page is enabled, you can override the slug used by WordPress, which defaults to the name of the post type.', 'pods' ),  
  987. 'type' => 'text',  
  988. 'default' => '',  
  989. 'depends-on' => array( 'has_archive' => true ) 
  990. ),  
  991. 'hierarchical' => array( 
  992. 'label' => __( 'Hierarchical', 'pods' ),  
  993. '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' ),  
  994. 'type' => 'boolean',  
  995. 'default' => false,  
  996. 'dependency' => true,  
  997. 'boolean_yes_label' => '' 
  998. ),  
  999. 'label_parent_item_colon' => array( 
  1000. 'label' => __( '<strong>Label: </strong> Parent <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ),  
  1001. 'help' => __( 'help', 'pods' ),  
  1002. 'type' => 'text',  
  1003. 'default' => '',  
  1004. 'depends-on' => array( 'hierarchical' => true ) 
  1005. ),  
  1006. 'label_parent' => array( 
  1007. 'label' => __( '<strong>Label: </strong> Parent', 'pods' ),  
  1008. 'help' => __( 'help', 'pods' ),  
  1009. 'type' => 'text',  
  1010. 'default' => '',  
  1011. 'depends-on' => array( 'hierarchical' => true ) 
  1012. ),  
  1013. 'rewrite' => array( 
  1014. 'label' => __( 'Rewrite', 'pods' ),  
  1015. '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' ),  
  1016. 'type' => 'boolean',  
  1017. 'default' => true,  
  1018. 'dependency' => true,  
  1019. 'boolean_yes_label' => '' 
  1020. ),  
  1021. 'rewrite_custom_slug' => array( 
  1022. 'label' => __( 'Custom Rewrite Slug', 'pods' ),  
  1023. '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' ),  
  1024. 'type' => 'text',  
  1025. 'default' => '',  
  1026. 'depends-on' => array( 'rewrite' => true ) 
  1027. ),  
  1028. 'rewrite_with_front' => array( 
  1029. 'label' => __( 'Rewrite with Front', 'pods' ),  
  1030. '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' ),  
  1031. 'type' => 'boolean',  
  1032. 'default' => true,  
  1033. 'depends-on' => array( 'rewrite' => true ),  
  1034. 'boolean_yes_label' => '' 
  1035. ),  
  1036. 'rewrite_feeds' => array( 
  1037. 'label' => __( 'Rewrite Feeds', 'pods' ),  
  1038. 'help' => __( 'help', 'pods' ),  
  1039. 'type' => 'boolean',  
  1040. 'default' => false,  
  1041. 'depends-on' => array( 'rewrite' => true ),  
  1042. 'boolean_yes_label' => '' 
  1043. ),  
  1044. 'rewrite_pages' => array( 
  1045. 'label' => __( 'Rewrite Pages', 'pods' ),  
  1046. 'help' => __( 'help', 'pods' ),  
  1047. 'type' => 'boolean',  
  1048. 'default' => true,  
  1049. 'depends-on' => array( 'rewrite' => true ),  
  1050. 'boolean_yes_label' => '' 
  1051. ),  
  1052. 'query_var' => array( 
  1053. 'label' => __( 'Query Var', 'pods' ),  
  1054. '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' ),  
  1055. 'type' => 'boolean',  
  1056. 'default' => true,  
  1057. 'boolean_yes_label' => '' 
  1058. ),  
  1059. 'can_export' => array( 
  1060. 'label' => __( 'Exportable', 'pods' ),  
  1061. 'help' => __( 'help', 'pods' ),  
  1062. 'type' => 'boolean',  
  1063. 'default' => true,  
  1064. 'boolean_yes_label' => '' 
  1065. ),  
  1066. 'default_status' => array( 
  1067. 'label' => __( 'Default Status', 'pods' ),  
  1068. 'help' => __( 'help', 'pods' ),  
  1069. 'type' => 'pick',  
  1070. 'pick_object' => 'post-status',  
  1071. 'default' => apply_filters( 'pods_api_default_status_' . pods_var_raw( 'name', $pod, 'post_type', null, true ), 'draft', $pod ) 
  1072. ); 
  1073. elseif ( 'taxonomy' == $pod[ 'type' ] ) { 
  1074. $options[ 'admin-ui' ] = array( 
  1075. 'show_ui' => array( 
  1076. 'label' => __( 'Show Admin UI', 'pods' ),  
  1077. 'help' => __( 'help', 'pods' ),  
  1078. 'type' => 'boolean',  
  1079. 'default' => pods_var_raw( 'public', $pod, true ),  
  1080. 'dependency' => true,  
  1081. 'boolean_yes_label' => '' 
  1082. ),  
  1083. 'menu_name' => array( 
  1084. 'label' => __( 'Menu Name', 'pods' ),  
  1085. 'help' => __( 'help', 'pods' ),  
  1086. 'type' => 'text',  
  1087. 'default' => '',  
  1088. 'depends-on' => array( 'show_ui' => true ) 
  1089. ),  
  1090. 'menu_location' => array( 
  1091. 'label' => __( 'Menu Location', 'pods' ),  
  1092. 'help' => __( 'help', 'pods' ),  
  1093. 'type' => 'pick',  
  1094. 'default' => 'default',  
  1095. 'depends-on' => array( 'show_ui' => true ),  
  1096. 'data' => array( 
  1097. 'default' => __( 'Default - Add to associated Post Type(s) menus', 'pods' ),  
  1098. 'settings' => __( 'Add to Settings menu', 'pods' ),  
  1099. 'appearances' => __( 'Add to Appearances menu', 'pods' ),  
  1100. 'objects' => __( 'Make a top-level menu item', 'pods' ),  
  1101. 'top' => __( 'Make a new top-level menu item below Settings', 'pods' ),  
  1102. 'submenu' => __( 'Add a submenu item to another menu', 'pods' ) 
  1103. ),  
  1104. 'dependency' => true 
  1105. ),  
  1106. 'menu_location_custom' => array( 
  1107. 'label' => __( 'Custom Menu Location', 'pods' ),  
  1108. 'help' => __( 'help', 'pods' ),  
  1109. 'type' => 'text',  
  1110. 'depends-on' => array( 'menu_location' => 'submenu' ) 
  1111. ),  
  1112. 'menu_position' => array( 
  1113. 'label' => __( 'Menu Position', 'pods' ),  
  1114. 'help' => __( 'help', 'pods' ),  
  1115. 'type' => 'number',  
  1116. 'default' => 0,  
  1117. 'depends-on' => array( 'menu_location' => array( 'objects', 'top' ) ) 
  1118. ),  
  1119. 'menu_icon' => array( 
  1120. 'label' => __( 'Menu Icon URL', 'pods' ),  
  1121. 'help' => __( 'help', 'pods' ),  
  1122. 'type' => 'text',  
  1123. 'default' => '',  
  1124. 'depends-on' => array( 'menu_location' => array( 'objects', 'top' ) ) 
  1125. ),  
  1126. 'show_in_nav_menus' => array( 
  1127. 'label' => __( 'Show in Navigation Menus', 'pods' ),  
  1128. 'help' => __( 'help', 'pods' ),  
  1129. 'type' => 'boolean',  
  1130. 'default' => pods_var_raw( 'public', $pod, true ),  
  1131. 'boolean_yes_label' => '' 
  1132. ),  
  1133. 'show_tagcloud' => array( 
  1134. 'label' => __( 'Allow in Tagcloud Widget', 'pods' ),  
  1135. 'help' => __( 'help', 'pods' ),  
  1136. 'type' => 'boolean',  
  1137. 'default' => pods_var_raw( 'show_ui', $pod, pods_var_raw( 'public', $pod, true ) ),  
  1138. 'boolean_yes_label' => '' 
  1139. ); 
  1140.  
  1141. if ( pods_version_check( 'wp', '3.5' ) ) { 
  1142. $options[ 'admin-ui' ][ 'show_admin_column' ] = array( 
  1143. 'label' => __( 'Show Taxonomy column on Post Types', 'pods' ),  
  1144. 'help' => __( 'Whether to add a column for this taxonomy on the associated post types manage screens', 'pods' ),  
  1145. 'type' => 'boolean',  
  1146. 'default' => false,  
  1147. 'boolean_yes_label' => '' 
  1148. ); 
  1149.  
  1150. // Integration for Single Value Taxonomy UI 
  1151. if ( function_exists( 'tax_single_value_meta_box' ) ) { 
  1152. $options[ 'admin-ui' ][ 'single_value' ] = array( 
  1153. 'label' => __( 'Single Value Taxonomy', 'pods' ),  
  1154. 'help' => __( 'Use a drop-down for the input instead of the WordPress default', 'pods' ),  
  1155. 'type' => 'boolean',  
  1156. 'default' => false,  
  1157. 'boolean_yes_label' => '' 
  1158. ); 
  1159.  
  1160. $options[ 'admin-ui' ][ 'single_value_required' ] = array( 
  1161. 'label' => __( 'Single Value Taxonomy - Required', 'pods' ),  
  1162. 'help' => __( 'A term will be selected by default in the Post Editor, not optional', 'pods' ),  
  1163. 'type' => 'boolean',  
  1164. 'default' => false,  
  1165. 'boolean_yes_label' => '' 
  1166. ); 
  1167.  
  1168. // @todo fill this in 
  1169. $options[ 'advanced' ] = array( 
  1170. 'temporary' => 'This type has the fields hardcoded' // :( 
  1171. ); 
  1172. elseif ( 'settings' == $pod[ 'type' ] ) { 
  1173. $options[ 'admin-ui' ] = array( 
  1174. 'ui_style' => array( 
  1175. 'label' => __( 'Admin UI Style', 'pods' ),  
  1176. 'help' => __( 'help', 'pods' ),  
  1177. 'type' => 'pick',  
  1178. 'default' => 'settings',  
  1179. 'data' => array( 
  1180. 'settings' => __( 'Normal Settings Form', 'pods' ),  
  1181. 'post_type' => __( 'Post Type UI', 'pods' ),  
  1182. 'custom' => __( 'Custom (hook into pods_admin_ui_custom or pods_admin_ui_custom_{podname} action)', 'pods' ) 
  1183. ),  
  1184. 'dependency' => true 
  1185. ),  
  1186. 'menu_location' => array( 
  1187. 'label' => __( 'Menu Location', 'pods' ),  
  1188. 'help' => __( 'help', 'pods' ),  
  1189. 'type' => 'pick',  
  1190. 'default' => 'settings',  
  1191. 'data' => array( 
  1192. 'settings' => __( 'Add to Settings menu', 'pods' ),  
  1193. 'appearances' => __( 'Add to Appearances menu', 'pods' ),  
  1194. 'top' => __( 'Make a new top-level menu item below Settings', 'pods' ),  
  1195. 'submenu' => __( 'Add a submenu item to another menu', 'pods' ) 
  1196. ),  
  1197. 'dependency' => true 
  1198. ),  
  1199. 'menu_location_custom' => array( 
  1200. 'label' => __( 'Custom Menu Location', 'pods' ),  
  1201. 'help' => __( 'help', 'pods' ),  
  1202. 'type' => 'text',  
  1203. 'depends-on' => array( 'menu_location' => 'submenu' ) 
  1204. ),  
  1205. 'menu_position' => array( 
  1206. 'label' => __( 'Menu Position', 'pods' ),  
  1207. 'help' => __( 'help', 'pods' ),  
  1208. 'type' => 'number',  
  1209. 'default' => 0,  
  1210. 'depends-on' => array( 'menu_location' => 'top' ) 
  1211. ),  
  1212. 'menu_icon' => array( 
  1213. 'label' => __( 'Menu Icon URL', 'pods' ),  
  1214. 'help' => __( 'help', 'pods' ),  
  1215. 'type' => 'text',  
  1216. 'default' => '',  
  1217. 'depends-on' => array( 'menu_location' => 'top' ) 
  1218. ); 
  1219.  
  1220. // @todo fill this in 
  1221. $options[ 'advanced' ] = array( 
  1222. 'temporary' => 'This type has the fields hardcoded' // :( 
  1223. ); 
  1224. elseif ( 'pod' == $pod[ 'type' ] ) { 
  1225. $options[ 'admin-ui' ] = array( 
  1226. 'ui_style' => array( 
  1227. 'label' => __( 'Admin UI Style', 'pods' ),  
  1228. 'help' => __( 'help', 'pods' ),  
  1229. 'type' => 'pick',  
  1230. 'default' => 'settings',  
  1231. 'data' => array( 
  1232. 'post_type' => __( 'Normal (Looks like the Post Type UI)', 'pods' ),  
  1233. 'custom' => __( 'Custom (hook into pods_admin_ui_custom or pods_admin_ui_custom_{podname} action)', 'pods' ) 
  1234. ),  
  1235. 'dependency' => true 
  1236. ),  
  1237. 'show_in_menu' => array( 
  1238. 'label' => __( 'Show Admin Menu in Dashboard', 'pods' ),  
  1239. 'help' => __( 'help', 'pods' ),  
  1240. 'type' => 'boolean',  
  1241. 'default' => false,  
  1242. 'boolean_yes_label' => '',  
  1243. 'dependency' => true 
  1244. ),  
  1245. 'menu_location_custom' => array( 
  1246. 'label' => __( 'Parent Menu ID (optional)', 'pods' ),  
  1247. 'help' => __( 'help', 'pods' ),  
  1248. 'type' => 'text',  
  1249. 'depends-on' => array( 'show_in_menu' => true ) 
  1250. ),  
  1251. 'menu_position' => array( 
  1252. 'label' => __( 'Menu Position', 'pods' ),  
  1253. 'help' => __( 'help', 'pods' ),  
  1254. 'type' => 'number',  
  1255. 'default' => 0,  
  1256. 'depends-on' => array( 'show_in_menu' => true ) 
  1257. ),  
  1258. 'menu_icon' => array( 
  1259. 'label' => __( 'Menu Icon URL', 'pods' ),  
  1260. 'help' => __( 'This is the icon shown to the left of the menu text for this content type.', 'pods' ),  
  1261. 'type' => 'text',  
  1262. 'default' => '',  
  1263. 'depends-on' => array( 'show_in_menu' => true ) 
  1264. ),  
  1265. 'ui_icon' => array( 
  1266. 'label' => __( 'Header Icon', 'pods' ),  
  1267. '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' ),  
  1268. 'type' => 'file',  
  1269. 'default' => '',  
  1270. 'file_edit_title' => 0,  
  1271. 'depends-on' => array( 'show_in_menu' => true ) 
  1272. ),  
  1273. 'ui_actions_enabled' => array( 
  1274. 'label' => __( 'Actions Available', 'pods' ),  
  1275. 'help' => __( 'help', 'pods' ),  
  1276. 'type' => 'pick',  
  1277. 'default' => ( 1 == pods_var( 'ui_export', $pod ) ? array( 'add', 'edit', 'duplicate', 'delete', 'export' ) : array( 'add', 'edit', 'duplicate', 'delete' ) ),  
  1278. 'data' => array( 
  1279. 'add' => __( 'Add New', 'pods' ),  
  1280. 'edit' => __( 'Edit', 'pods' ),  
  1281. 'duplicate' => __( 'Duplicate', 'pods' ),  
  1282. 'delete' => __( 'Delete', 'pods' ),  
  1283. 'reorder' => __( 'Reorder', 'pods' ),  
  1284. 'export' => __( 'Export', 'pods' ) 
  1285. ),  
  1286. 'pick_format_type' => 'multi',  
  1287. 'dependency' => true 
  1288. ),  
  1289. 'ui_reorder_field' => array( 
  1290. 'label' => __( 'Reorder Field', 'pods' ),  
  1291. 'help' => __( 'This is the field that will be reordered on, it should be numeric.', 'pods' ),  
  1292. 'type' => 'text',  
  1293. 'default' => 'menu_order',  
  1294. 'depends-on' => array( 'ui_actions_enabled' => 'reorder' ) 
  1295. ),  
  1296. 'ui_fields_manage' => array( 
  1297. 'label' => __( 'Admin Table Columns', 'pods' ),  
  1298. 'help' => __( 'help', 'pods' ),  
  1299. 'type' => 'pick',  
  1300. 'default' => array(),  
  1301. 'data' => array(),  
  1302. 'pick_format_type' => 'multi' 
  1303. ),  
  1304. 'ui_filters' => array( 
  1305. 'label' => __( 'Search Filters', 'pods' ),  
  1306. 'help' => __( 'help', 'pods' ),  
  1307. 'type' => 'pick',  
  1308. 'default' => array(),  
  1309. 'data' => array(),  
  1310. 'pick_format_type' => 'multi' 
  1311. ); 
  1312.  
  1313. if ( !empty( $pod[ 'fields' ] ) ) { 
  1314. if ( isset( $pod[ 'fields' ][ pods_var_raw( 'pod_index', $pod, 'name' ) ] ) ) 
  1315. $options[ 'admin-ui' ][ 'ui_fields_manage' ][ 'default' ][] = pods_var_raw( 'pod_index', $pod, 'name' ); 
  1316.  
  1317. if ( isset( $pod[ 'fields' ][ 'modified' ] ) ) 
  1318. $options[ 'admin-ui' ][ 'ui_fields_manage' ][ 'default' ][] = 'modified'; 
  1319.  
  1320. foreach ( $pod[ 'fields' ] as $field ) { 
  1321. $type = ''; 
  1322.  
  1323. if ( isset( $field_types[ $field[ 'type' ] ] ) ) 
  1324. $type = ' <small>(' . $field_types[ $field[ 'type' ] ][ 'label' ] . ')</small>'; 
  1325.  
  1326. $options[ 'admin-ui' ][ 'ui_fields_manage' ][ 'data' ][ $field[ 'name' ] ] = $field[ 'label' ] . $type; 
  1327. $options[ 'admin-ui' ][ 'ui_filters' ][ 'data' ][ $field[ 'name' ] ] = $field[ 'label' ] . $type; 
  1328.  
  1329. $options[ 'admin-ui' ][ 'ui_fields_manage' ][ 'data' ][ 'id' ] = 'ID'; 
  1330. else { 
  1331. unset( $options[ 'admin-ui' ][ 'ui_fields_manage' ] ); 
  1332. unset( $options[ 'admin-ui' ][ 'ui_filters' ] ); 
  1333.  
  1334. // @todo fill this in 
  1335. $options[ 'advanced' ] = array( 
  1336. 'temporary' => 'This type has the fields hardcoded' // :( 
  1337. ); 
  1338.  
  1339. /** 
  1340. * Add admin fields to the Pods editor for a specific Pod 
  1341. * @params array $options The Options fields 
  1342. * @params object $pod Current Pods object 
  1343. * @since unkown 
  1344. */ 
  1345. $options = apply_filters( 'pods_admin_setup_edit_options_' . $pod[ 'type' ] . '_' . $pod[ 'name' ], $options, $pod ); 
  1346.  
  1347. /** 
  1348. * Add admin fields to the Pods editor for any Pod of a specific content type. 
  1349. */ 
  1350. $options = apply_filters( 'pods_admin_setup_edit_options_' . $pod[ 'type' ], $options, $pod ); 
  1351.  
  1352. /** 
  1353. * Add admin fields to the Pods editor for all Pods 
  1354. */ 
  1355. $options = apply_filters( 'pods_admin_setup_edit_options', $options, $pod ); 
  1356.  
  1357. return $options; 
  1358.  
  1359. /** 
  1360. * Get list of Pod field option tabs 
  1361. * @return array 
  1362. */ 
  1363. public function admin_setup_edit_field_tabs ( $pod ) { 
  1364. $core_tabs = array( 
  1365. 'basic' => __( 'Basic', 'pods' ),  
  1366. 'additional-field' => __( 'Additional Field Options', 'pods' ),  
  1367. 'advanced' => __( 'Advanced', 'pods' ) 
  1368. ); 
  1369.  
  1370. /** 
  1371. * Field option tabs 
  1372. * Use to add new tabs, default tabs are added after this filter (IE you can't remove/modify them with this, kthanksbye). 
  1373. * @since unknown 
  1374. * @param array $tabs Tabs to add, starts empty 
  1375. * @param object|Pod Current Pods object 
  1376. */ 
  1377. $tabs = apply_filters( 'pods_admin_setup_edit_field_tabs', array(), $pod ); 
  1378.  
  1379. $tabs = array_merge( $core_tabs, $tabs ); 
  1380.  
  1381. return $tabs; 
  1382.  
  1383. /** 
  1384. * Get list of Pod field options 
  1385. * @return array 
  1386. */ 
  1387. public function admin_setup_edit_field_options ( $pod ) { 
  1388. $options = array(); 
  1389.  
  1390. $options[ 'additional-field' ] = array(); 
  1391.  
  1392. $field_types = PodsForm::field_types(); 
  1393.  
  1394. foreach ( $field_types as $type => $field_type_data ) { 
  1395. /** 
  1396. * @var $field_type PodsField 
  1397. */ 
  1398. $field_type = PodsForm::field_loader( $type, $field_type_data[ 'file' ] ); 
  1399.  
  1400. $field_type_vars = get_class_vars( get_class( $field_type ) ); 
  1401.  
  1402. if ( !isset( $field_type_vars[ 'pod_types' ] ) ) 
  1403. $field_type_vars[ 'pod_types' ] = true; 
  1404.  
  1405. $options[ 'additional-field' ][ $type ] = array(); 
  1406.  
  1407. // Only show supported field types 
  1408. if ( true !== $field_type_vars[ 'pod_types' ] ) { 
  1409. if ( empty( $field_type_vars[ 'pod_types' ] ) ) 
  1410. continue; 
  1411. elseif ( is_array( $field_type_vars[ 'pod_types' ] ) && !in_array( pods_var( 'type', $pod ), $field_type_vars[ 'pod_types' ] ) ) 
  1412. continue; 
  1413. elseif ( !is_array( $field_type_vars[ 'pod_types' ] ) && pods_var( 'type', $pod ) != $field_type_vars[ 'pod_types' ] ) 
  1414. continue; 
  1415.  
  1416. $options[ 'additional-field' ][ $type ] = PodsForm::ui_options( $type ); 
  1417.  
  1418. $input_helpers = array( 
  1419. '' => '-- Select --' 
  1420. ); 
  1421.  
  1422. if ( class_exists( 'Pods_Helpers' ) ) { 
  1423. $helpers = pods_api()->load_helpers( array( 'options' => array( 'helper_type' => 'input' ) ) ); 
  1424.  
  1425. foreach ( $helpers as $helper ) { 
  1426. $input_helpers[ $helper[ 'name' ] ] = $helper[ 'name' ]; 
  1427.  
  1428. $options[ 'advanced' ] = array( 
  1429. __( 'Visual', 'pods' ) => array( 
  1430. 'class' => array( 
  1431. 'name' => 'class',  
  1432. 'label' => __( 'Additional CSS Classes', 'pods' ),  
  1433. 'help' => __( 'help', 'pods' ),  
  1434. 'type' => 'text',  
  1435. 'default' => '' 
  1436. ),  
  1437. 'input_helper' => array( 
  1438. 'name' => 'input_helper',  
  1439. 'label' => __( 'Input Helper', 'pods' ),  
  1440. 'help' => __( 'help', 'pods' ),  
  1441. 'type' => 'pick',  
  1442. 'default' => '',  
  1443. 'data' => $input_helpers 
  1444. ),  
  1445. __( 'Values', 'pods' ) => array( 
  1446. 'default_value' => array( 
  1447. 'name' => 'default_value',  
  1448. 'label' => __( 'Default Value', 'pods' ),  
  1449. 'help' => __( 'help', 'pods' ),  
  1450. 'type' => 'text',  
  1451. 'default' => '' 
  1452. ),  
  1453. 'default_value_parameter' => array( 
  1454. 'name' => 'default_value_parameter',  
  1455. 'label' => __( 'Set Default Value via Parameter', 'pods' ),  
  1456. 'help' => __( 'help', 'pods' ),  
  1457. 'type' => 'text',  
  1458. 'default' => '' 
  1459. ),  
  1460. __( 'Visibility', 'pods' ) => array( 
  1461. 'restrict_access' => array( 
  1462. 'name' => 'restrict_access',  
  1463. 'label' => __( 'Restrict Access', 'pods' ),  
  1464. 'group' => array( 
  1465. 'admin_only' => array( 
  1466. 'name' => 'admin_only',  
  1467. 'label' => __( 'Restrict access to Admins?', 'pods' ),  
  1468. 'default' => 0,  
  1469. 'type' => 'boolean',  
  1470. 'dependency' => true,  
  1471. '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' ) 
  1472. ),  
  1473. 'restrict_role' => array( 
  1474. 'name' => 'restrict_role',  
  1475. 'label' => __( 'Restrict access by Role?', 'pods' ),  
  1476. 'default' => 0,  
  1477. 'type' => 'boolean',  
  1478. 'dependency' => true 
  1479. ),  
  1480. 'restrict_capability' => array( 
  1481. 'name' => 'restrict_capability',  
  1482. 'label' => __( 'Restrict access by Capability?', 'pods' ),  
  1483. 'default' => 0,  
  1484. 'type' => 'boolean',  
  1485. 'dependency' => true 
  1486. ),  
  1487. 'hidden' => array( 
  1488. 'name' => 'hidden',  
  1489. 'label' => __( 'Hide field from UI', 'pods' ),  
  1490. 'default' => 0,  
  1491. 'type' => 'boolean',  
  1492. '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' ) 
  1493. ),  
  1494. 'read_only' => array( 
  1495. 'name' => 'read_only',  
  1496. 'label' => __( 'Make field "Read Only" in UI', 'pods' ),  
  1497. 'default' => 0,  
  1498. 'type' => 'boolean',  
  1499. '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' ),  
  1500. 'depends-on' => array( 
  1501. 'type' => array( 
  1502. 'boolean',  
  1503. 'color',  
  1504. 'currency',  
  1505. 'date',  
  1506. 'datetime',  
  1507. 'email',  
  1508. 'number',  
  1509. 'paragraph',  
  1510. 'password',  
  1511. 'phone',  
  1512. 'slug',  
  1513. 'text',  
  1514. 'time',  
  1515. 'website' 
  1516. ),  
  1517. 'roles_allowed' => array( 
  1518. 'name' => 'roles_allowed',  
  1519. 'label' => __( 'Role(s) Allowed', 'pods' ),  
  1520. 'help' => __( 'help', 'pods' ),  
  1521. 'type' => 'pick',  
  1522. 'pick_object' => 'role',  
  1523. 'pick_format_type' => 'multi',  
  1524. 'default' => 'administrator',  
  1525. 'depends-on' => array( 
  1526. 'restrict_role' => true 
  1527. ),  
  1528. 'capability_allowed' => array( 
  1529. 'name' => 'capability_allowed',  
  1530. 'label' => __( 'Capability Allowed', 'pods' ),  
  1531. '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' ),  
  1532. 'type' => 'text',  
  1533. 'default' => '',  
  1534. 'depends-on' => array( 
  1535. 'restrict_capability' => true 
  1536. /**,  
  1537. 'search' => array( 
  1538. 'label' => __( 'Include in searches', 'pods' ),  
  1539. 'help' => __( 'help', 'pods' ),  
  1540. 'default' => 1,  
  1541. 'type' => 'boolean',  
  1542. )*/ 
  1543. /**,  
  1544. __( 'Validation', 'pods' ) => array( 
  1545. 'regex_validation' => array( 
  1546. 'label' => __( 'RegEx Validation', 'pods' ),  
  1547. 'help' => __( 'help', 'pods' ),  
  1548. 'type' => 'text',  
  1549. 'default' => '' 
  1550. ),  
  1551. 'message_regex' => array( 
  1552. 'label' => __( 'Message if field does not pass RegEx', 'pods' ),  
  1553. 'help' => __( 'help', 'pods' ),  
  1554. 'type' => 'text',  
  1555. 'default' => '' 
  1556. ),  
  1557. 'message_required' => array( 
  1558. 'label' => __( 'Message if field is blank', 'pods' ),  
  1559. 'help' => __( 'help', 'pods' ),  
  1560. 'type' => 'text',  
  1561. 'default' => '',  
  1562. 'depends-on' => array( 'required' => true ) 
  1563. ),  
  1564. 'message_unique' => array( 
  1565. 'label' => __( 'Message if field is not unique', 'pods' ),  
  1566. 'help' => __( 'help', 'pods' ),  
  1567. 'type' => 'text',  
  1568. 'default' => '',  
  1569. 'depends-on' => array( 'unique' => true ) 
  1570. )*/ 
  1571. ); 
  1572.  
  1573. if ( !class_exists( 'Pods_Helpers' ) ) 
  1574. unset( $options[ 'advanced-options' ][ 'input_helper' ] ); 
  1575.  
  1576. /** 
  1577. * Modify tabs and their contents for field options 
  1578. * @since unknown 
  1579. * @param array $options Tabs, indexed by label 
  1580. * @param object|Pods Pods object for the Pod this UI is for. 
  1581. */ 
  1582. $options = apply_filters( 'pods_admin_setup_edit_field_options', $options, $pod ); 
  1583.  
  1584. return $options; 
  1585.  
  1586. /** 
  1587. * Duplicate a pod 
  1588. * @param $id 
  1589. * @param $obj 
  1590. * @return mixed 
  1591. */ 
  1592. public function admin_setup_duplicate ( $obj ) { 
  1593. $new_id = pods_api()->duplicate_pod( array( 'id' => $obj->id ) ); 
  1594.  
  1595. if ( 0 < $new_id ) 
  1596. pods_redirect( pods_query_arg( array( 'action' => 'edit', 'id' => $new_id, 'do' => 'duplicate' ) ) ); 
  1597.  
  1598. /** 
  1599. * Restrict Duplicate action to custom types, not extended 
  1600. * @param bool $restricted 
  1601. * @param array $restrict 
  1602. * @param string $action 
  1603. * @param array $row 
  1604. * @param PodsUI $obj 
  1605. * @since 2.3.10 
  1606. * @return bool 
  1607. */ 
  1608. public function admin_setup_duplicate_restrict( $restricted, $restrict, $action, $row, $obj ) { 
  1609.  
  1610. if ( in_array( $row[ 'real_type' ], array( 'user', 'media', 'comment' ) ) ) { 
  1611. $restricted = true; 
  1612.  
  1613. return $restricted; 
  1614.  
  1615.  
  1616. /** 
  1617. * Reset a pod 
  1618. * @param $obj 
  1619. * @return mixed 
  1620. */ 
  1621. public function admin_setup_reset ( $obj, $id ) { 
  1622. $pod = pods_api()->load_pod( array( 'id' => $id ), false ); 
  1623.  
  1624. if ( empty( $pod ) ) 
  1625. return $obj->error( __( 'Pod not found.', 'pods' ) ); 
  1626.  
  1627. pods_api()->reset_pod( array( 'id' => $id ) ); 
  1628.  
  1629. $obj->message( __( 'Pod reset successfully.', 'pods' ) ); 
  1630.  
  1631. $obj->manage(); 
  1632.  
  1633. /** 
  1634. * Restrict Reset action from users and media 
  1635. * @param bool $restricted 
  1636. * @param array $restrict 
  1637. * @param string $action 
  1638. * @param array $row 
  1639. * @param PodsUI $obj 
  1640. * @since 2.3.10 
  1641. */ 
  1642. public function admin_setup_reset_restrict( $restricted, $restrict, $action, $row, $obj ) { 
  1643.  
  1644. if ( in_array( $row[ 'real_type' ], array( 'user', 'media' ) ) ) { 
  1645. $restricted = true; 
  1646.  
  1647. return $restricted; 
  1648.  
  1649.  
  1650. /** 
  1651. * Delete a pod 
  1652. * @param $id 
  1653. * @param $obj 
  1654. * @return mixed 
  1655. */ 
  1656. public function admin_setup_delete ( $id, $obj ) { 
  1657. $pod = pods_api()->load_pod( array( 'id' => $id ), false ); 
  1658.  
  1659. if ( empty( $pod ) ) 
  1660. return $obj->error( __( 'Pod not found.', 'pods' ) ); 
  1661.  
  1662. pods_api()->delete_pod( array( 'id' => $id ) ); 
  1663.  
  1664. unset( $obj->data[ $pod[ 'id' ] ] ); 
  1665.  
  1666. $obj->total = count( $obj->data ); 
  1667. $obj->total_found = count( $obj->data ); 
  1668.  
  1669. $obj->message( __( 'Pod deleted successfully.', 'pods' ) ); 
  1670.  
  1671. /** 
  1672. * Get advanced administration view. 
  1673. */ 
  1674. public function admin_advanced () { 
  1675. pods_view( PODS_DIR . 'ui/admin/advanced.php', compact( array_keys( get_defined_vars() ) ) ); 
  1676.  
  1677. /** 
  1678. * Get settings administration view 
  1679. */ 
  1680. public function admin_settings () { 
  1681. pods_view( PODS_DIR . 'ui/admin/settings.php', compact( array_keys( get_defined_vars() ) ) ); 
  1682.  
  1683. /** 
  1684. * Get components administration UI 
  1685. */ 
  1686. public function admin_components () { 
  1687. $components = PodsInit::$components->components; 
  1688.  
  1689. $view = pods_var( 'view', 'get', 'all', null, true ); 
  1690.  
  1691. $recommended = array( 
  1692. 'advanced-relationships',  
  1693. 'advanced-content-types',  
  1694. 'migrate-packages',  
  1695. 'roles-and-capabilities',  
  1696. 'pages',  
  1697. 'table-storage',  
  1698. 'templates' 
  1699. ); 
  1700.  
  1701. foreach ( $components as $component => &$component_data ) { 
  1702. if ( !in_array( $view, array( 'all', 'recommended', 'dev' ) ) && ( !isset( $component_data[ 'Category' ] ) || $view != sanitize_title( $component_data[ 'Category' ] ) ) ) { 
  1703. unset( $components[ $component ] ); 
  1704.  
  1705. continue; 
  1706. elseif ( 'recommended' == $view && !in_array( $component_data[ 'ID' ], $recommended ) ) { 
  1707. unset( $components[ $component ] ); 
  1708.  
  1709. continue; 
  1710. elseif ( 'dev' == $view && pods_developer() && !pods_var_raw( 'DeveloperMode', $component_data, false ) ) { 
  1711. unset( $components[ $component ] ); 
  1712.  
  1713. continue; 
  1714. elseif ( pods_var_raw( 'DeveloperMode', $component_data, false ) && !pods_developer() ) { 
  1715. unset( $components[ $component ] ); 
  1716.  
  1717. continue; 
  1718. elseif ( !pods_var_raw( 'TablelessMode', $component_data, false ) && pods_tableless() ) { 
  1719. unset( $components[ $component ] ); 
  1720.  
  1721. continue; 
  1722.  
  1723. $component_data[ 'Name' ] = strip_tags( $component_data[ 'Name' ] ); 
  1724.  
  1725. if ( pods_var_raw( 'DeveloperMode', $component_data, false ) ) 
  1726. $component_data[ 'Name' ] .= ' <em style="font-weight: normal; color:#333;">(Developer Preview)</em>'; 
  1727.  
  1728. $meta = array(); 
  1729.  
  1730. if ( !empty( $component_data[ 'Version' ] ) ) 
  1731. $meta[] = 'Version ' . $component_data[ 'Version' ]; 
  1732.  
  1733. if ( empty( $component_data[ 'Author' ] ) ) { 
  1734. $component_data[ 'Author' ] = 'Pods Framework Team'; 
  1735. $component_data[ 'AuthorURI' ] = 'http://pods.io/'; 
  1736.  
  1737. if ( !empty( $component_data[ 'AuthorURI' ] ) ) 
  1738. $component_data[ 'Author' ] = '<a href="' . $component_data[ 'AuthorURI' ] . '">' . $component_data[ 'Author' ] . '</a>'; 
  1739.  
  1740. $meta[] = sprintf( __( 'by %s', 'pods' ), $component_data[ 'Author' ] ); 
  1741.  
  1742. if ( !empty( $component_data[ 'URI' ] ) ) 
  1743. $meta[] = '<a href="' . $component_data[ 'URI' ] . '">' . __( 'Visit component site', 'pods' ) . '</a>'; 
  1744.  
  1745. $component_data[ 'Description' ] = wpautop( trim( make_clickable( strip_tags( $component_data[ 'Description' ], 'em, strong' ) ) ) ); 
  1746.  
  1747. if ( !empty( $meta ) ) 
  1748. $component_data[ 'Description' ] .= '<div class="pods-component-meta" ' . ( !empty( $component_data[ 'Description' ] ) ? ' style="padding:8px 0 4px;"' : '' ) . '>' . implode( '  |  ', $meta ) . '</div>'; 
  1749.  
  1750. $component_data = array( 
  1751. 'id' => $component_data[ 'ID' ],  
  1752. 'name' => $component_data[ 'Name' ],  
  1753. 'category' => $component_data[ 'Category' ],  
  1754. 'version' => '',  
  1755. 'description' => $component_data[ 'Description' ],  
  1756. 'mustuse' => pods_var_raw( 'MustUse', $component_data, false ),  
  1757. 'toggle' => 0 
  1758. ); 
  1759.  
  1760. if ( !empty( $component_data[ 'category' ] ) ) { 
  1761. $category_url = pods_query_arg( array( 'view' => sanitize_title( $component_data[ 'category' ] ), 'pg' => '', 'page' => $_GET[ 'page' ] ) ); 
  1762.  
  1763. $component_data[ 'category' ] = '<a href="' . esc_url( $category_url ) . '">' . $component_data[ 'category' ] . '</a>'; 
  1764.  
  1765. if ( isset( PodsInit::$components->settings[ 'components' ][ $component_data[ 'id' ] ] ) && 0 != PodsInit::$components->settings[ 'components' ][ $component_data[ 'id' ] ] ) 
  1766. $component_data[ 'toggle' ] = 1; 
  1767. elseif ( $component_data[ 'mustuse' ] ) 
  1768. $component_data[ 'toggle' ] = 1; 
  1769.  
  1770. $ui = array( 
  1771. 'data' => $components,  
  1772. 'total' => count( $components ),  
  1773. 'total_found' => count( $components ),  
  1774. 'items' => 'Components',  
  1775. 'item' => 'Component',  
  1776. 'fields' => array( 
  1777. 'manage' => array( 
  1778. 'name' => array( 
  1779. 'label' => __( 'Name', 'pods' ),  
  1780. 'width' => '30%',  
  1781. 'type' => 'text',  
  1782. 'options' => array( 
  1783. 'text_allow_html' => true 
  1784. ),  
  1785. 'category' => array( 
  1786. 'label' => __( 'Category', 'pods' ),  
  1787. 'width' => '10%',  
  1788. 'type' => 'text',  
  1789. 'options' => array( 
  1790. 'text_allow_html' => true 
  1791. ),  
  1792. 'description' => array( 
  1793. 'label' => __( 'Description', 'pods' ),  
  1794. 'width' => '60%',  
  1795. 'type' => 'text',  
  1796. 'options' => array( 
  1797. 'text_allow_html' => true,  
  1798. 'text_allowed_html_tags' => 'strong em a ul ol li b i br div' 
  1799. ),  
  1800. 'actions_disabled' => array( 'duplicate', 'view', 'export', 'add', 'edit', 'delete' ),  
  1801. 'actions_custom' => array( 
  1802. 'toggle' => array( 
  1803. 'callback' => array( $this, 'admin_components_toggle' ),  
  1804. 'nonce' => true 
  1805. ),  
  1806. 'filters_enhanced' => true,  
  1807. 'views' => array( 
  1808. 'all' => __( 'All', 'pods' ),  
  1809. //'recommended' => __( 'Recommended', 'pods' ),  
  1810. 'field-types' => __( 'Field Types', 'pods' ),  
  1811. 'tools' => __( 'Tools', 'pods' ),  
  1812. 'integration' => __( 'Integration', 'pods' ),  
  1813. 'migration' => __( 'Migration', 'pods' ),  
  1814. 'advanced' => __( 'Advanced', 'pods' ) 
  1815. ),  
  1816. 'view' => $view,  
  1817. 'heading' => array( 
  1818. 'views' => __( 'Category', 'pods' ) 
  1819. ),  
  1820. 'search' => false,  
  1821. 'searchable' => false,  
  1822. 'sortable' => false,  
  1823. 'pagination' => false 
  1824. ); 
  1825.  
  1826. if ( pods_developer() ) 
  1827. $ui[ 'views' ][ 'dev' ] = __( 'Developer Preview', 'pods' ); 
  1828.  
  1829. pods_ui( $ui ); 
  1830.  
  1831. /** 
  1832. * Toggle a component on or off 
  1833. * @param PodsUI $ui 
  1834. * @return bool 
  1835. */ 
  1836. public function admin_components_toggle ( PodsUI $ui ) { 
  1837. $component = $_GET[ 'id' ]; 
  1838.  
  1839. if ( !empty( PodsInit::$components->components[ $component ][ 'PluginDependency' ] ) ) { 
  1840. $dependency = explode( '|', PodsInit::$components->components[ $component ][ 'PluginDependency' ] ); 
  1841.  
  1842. if ( !pods_is_plugin_active( $dependency[ 1 ] ) ) { 
  1843. $website = 'http://wordpress.org/extend/plugins/' . dirname( $dependency[ 1 ] ) . '/'; 
  1844.  
  1845. if ( isset( $dependency[ 2 ] ) ) 
  1846. $website = $dependency[ 2 ]; 
  1847.  
  1848. if ( !empty( $website ) ) 
  1849. $website = ' ' . sprintf( __( 'You can find it at %s', 'pods' ), '<a href="' . $website . '" target="_blank">' . $website . '</a>' ); 
  1850.  
  1851. $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; 
  1852.  
  1853. $ui->error( $message ); 
  1854.  
  1855. $ui->manage(); 
  1856.  
  1857. return; 
  1858.  
  1859. if ( !empty( PodsInit::$components->components[ $component ][ 'ThemeDependency' ] ) ) { 
  1860. $dependency = explode( '|', PodsInit::$components->components[ $component ][ 'ThemeDependency' ] ); 
  1861.  
  1862. if ( strtolower( $dependency[ 1 ] ) != strtolower( get_template() ) && strtolower( $dependency[ 1 ] ) != strtolower( get_stylesheet() ) ) { 
  1863. $website = ''; 
  1864.  
  1865. if ( isset( $dependency[ 2 ] ) ) 
  1866. $website = ' ' . sprintf( __( 'You can find it at %s', 'pods' ), '<a href="' . $dependency[ 2 ] . '" target="_blank">' . $dependency[ 2 ] . '</a>' ); 
  1867.  
  1868. $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; 
  1869.  
  1870. $ui->error( $message ); 
  1871.  
  1872. $ui->manage(); 
  1873.  
  1874. return; 
  1875.  
  1876. if ( !empty( PodsInit::$components->components[ $component ][ 'MustUse' ] ) ) { 
  1877. $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' ] ); 
  1878.  
  1879. $ui->error( $message ); 
  1880.  
  1881. $ui->manage(); 
  1882.  
  1883. return; 
  1884.  
  1885. if ( '1' == pods_v( 'toggled' ) ) { 
  1886. $toggle = PodsInit::$components->toggle( $component ); 
  1887.  
  1888. if ( true === $toggle ) 
  1889. $ui->message( PodsInit::$components->components[ $component ][ 'Name' ] . ' ' . __( 'Component enabled', 'pods' ) ); 
  1890. elseif ( false === $toggle ) 
  1891. $ui->message( PodsInit::$components->components[ $component ][ 'Name' ] . ' ' . __( 'Component disabled', 'pods' ) ); 
  1892.  
  1893. $components = PodsInit::$components->components; 
  1894.  
  1895. foreach ( $components as $component => &$component_data ) { 
  1896. $toggle = 0; 
  1897.  
  1898. if ( isset( PodsInit::$components->settings[ 'components' ][ $component_data[ 'ID' ] ] ) ) { 
  1899. if ( 0 != PodsInit::$components->settings[ 'components' ][ $component_data[ 'ID' ] ] ) 
  1900. $toggle = 1; 
  1901. if ( true === $component_data[ 'DeveloperMode' ] ) { 
  1902. if ( !pods_developer() ) { 
  1903. unset( $components[ $component ] ); 
  1904. continue; 
  1905.  
  1906. $component_data = array( 
  1907. 'id' => $component_data[ 'ID' ],  
  1908. 'name' => $component_data[ 'Name' ],  
  1909. 'description' => make_clickable( $component_data[ 'Description' ] ),  
  1910. 'version' => $component_data[ 'Version' ],  
  1911. 'author' => $component_data[ 'Author' ],  
  1912. 'toggle' => $toggle 
  1913. ); 
  1914.  
  1915. $ui->data = $components; 
  1916.  
  1917. pods_transient_clear( 'pods_components' ); 
  1918.  
  1919. $url = pods_query_arg( array( 'toggled' => null ) ); 
  1920.  
  1921. pods_redirect( $url ); 
  1922. elseif ( 1 == pods_var( 'toggle' ) ) 
  1923. $ui->message( PodsInit::$components->components[ $component ][ 'Name' ] . ' ' . __( 'Component enabled', 'pods' ) ); 
  1924. else 
  1925. $ui->message( PodsInit::$components->components[ $component ][ 'Name' ] . ' ' . __( 'Component disabled', 'pods' ) ); 
  1926.  
  1927. $ui->manage(); 
  1928.  
  1929. /** 
  1930. * Get the admin upgrade page 
  1931. */ 
  1932. public function admin_upgrade () { 
  1933. foreach ( PodsInit::$upgrades as $old_version => $new_version ) { 
  1934. if ( version_compare( $old_version, PodsInit::$version_last, '<=' ) && version_compare( PodsInit::$version_last, $new_version, '<' ) ) { 
  1935. $new_version = str_replace( '.', '_', $new_version ); 
  1936.  
  1937. pods_view( PODS_DIR . 'ui/admin/upgrade/upgrade_' . $new_version . '.php', compact( array_keys( get_defined_vars() ) ) ); 
  1938.  
  1939. break; 
  1940.  
  1941. /** 
  1942. * Get the admin help page 
  1943. */ 
  1944. public function admin_help () { 
  1945. pods_view( PODS_DIR . 'ui/admin/help.php', compact( array_keys( get_defined_vars() ) ) ); 
  1946.  
  1947. /** 
  1948. * Add pods specific capabilities. 
  1949. * @param $capabilities List of extra capabilities to add 
  1950. * @return array 
  1951. */ 
  1952. public function admin_capabilities ( $capabilities ) { 
  1953. $pods = pods_api()->load_pods( array( 'type' => array( 'pod', 'table', 'post_type', 'taxonomy', 'settings' ) ) ); 
  1954.  
  1955. $capabilities[] = 'pods'; 
  1956. $capabilities[] = 'pods_content'; 
  1957. $capabilities[] = 'pods_settings'; 
  1958. $capabilities[] = 'pods_components'; 
  1959.  
  1960. foreach ( $pods as $pod ) { 
  1961. if ( 'settings' == $pod[ 'type' ] ) { 
  1962. $capabilities[] = 'pods_edit_' . $pod[ 'name' ]; 
  1963. elseif ( 'post_type' == $pod[ 'type' ] ) { 
  1964. $capability_type = pods_var( 'capability_type_custom', $pod[ 'options' ], pods_var_raw( 'name', $pod ) ); 
  1965.  
  1966. if ( 'custom' == pods_var( 'capability_type', $pod[ 'options' ] ) && 0 < strlen( $capability_type ) ) { 
  1967. $capabilities[] = 'read_' . $capability_type; 
  1968. $capabilities[] = 'edit_' . $capability_type; 
  1969. $capabilities[] = 'delete_' . $capability_type; 
  1970.  
  1971. if ( 1 == pods_var( 'capability_type_extra', $pod[ 'options' ], 1 ) ) { 
  1972. $capabilities[] = 'read_private_' . $capability_type . 's'; 
  1973. $capabilities[] = 'edit_' . $capability_type . 's'; 
  1974. $capabilities[] = 'edit_others_' . $capability_type . 's'; 
  1975. $capabilities[] = 'edit_private_' . $capability_type . 's'; 
  1976. $capabilities[] = 'edit_published_' . $capability_type . 's'; 
  1977. $capabilities[] = 'publish_' . $capability_type . 's'; 
  1978. $capabilities[] = 'delete_' . $capability_type . 's'; 
  1979. $capabilities[] = 'delete_private_' . $capability_type . 's'; 
  1980. $capabilities[] = 'delete_published_' . $capability_type . 's'; 
  1981. $capabilities[] = 'delete_others_' . $capability_type . 's'; 
  1982. elseif ( 'taxonomy' == $pod[ 'type' ] ) { 
  1983. if ( 1 == pods_var( 'capabilities', $pod[ 'options' ], 0 ) ) { 
  1984. $capability_type = pods_var( 'capability_type_custom', $pod[ 'options' ], pods_var_raw( 'name', $pod ) . 's' ); 
  1985.  
  1986. $capabilities[] = 'manage_' . $capability_type; 
  1987. $capabilities[] = 'edit_' . $capability_type; 
  1988. $capabilities[] = 'delete_' . $capability_type; 
  1989. $capabilities[] = 'assign_' . $capability_type; 
  1990. else { 
  1991. $capabilities[] = 'pods_add_' . $pod[ 'name' ]; 
  1992. $capabilities[] = 'pods_edit_' . $pod[ 'name' ]; 
  1993.  
  1994. if ( isset( $pod[ 'fields' ][ 'author' ] ) && 'pick' == $pod[ 'fields' ][ 'author' ][ 'type' ] && 'user' == $pod[ 'fields' ][ 'author' ][ 'pick_object' ] ) 
  1995. $capabilities[] = 'pods_edit_others_' . $pod[ 'name' ]; 
  1996.  
  1997. $capabilities[] = 'pods_delete_' . $pod[ 'name' ]; 
  1998.  
  1999. if ( isset( $pod[ 'fields' ][ 'author' ] ) && 'pick' == $pod[ 'fields' ][ 'author' ][ 'type' ] && 'user' == $pod[ 'fields' ][ 'author' ][ 'pick_object' ] ) 
  2000. $capabilities[] = 'pods_delete_others_' . $pod[ 'name' ]; 
  2001.  
  2002. $actions_enabled = pods_var_raw( 'ui_actions_enabled', $pod[ 'options' ] ); 
  2003.  
  2004. if ( !empty( $actions_enabled ) ) 
  2005. $actions_enabled = (array) $actions_enabled; 
  2006. else 
  2007. $actions_enabled = array(); 
  2008.  
  2009. $available_actions = array( 
  2010. 'add',  
  2011. 'edit',  
  2012. 'duplicate',  
  2013. 'delete',  
  2014. 'reorder',  
  2015. 'export' 
  2016. ); 
  2017.  
  2018. if ( !empty( $actions_enabled ) ) { 
  2019. $actions_disabled = array( 
  2020. 'view' => 'view' 
  2021. ); 
  2022.  
  2023. foreach ( $available_actions as $action ) { 
  2024. if ( !in_array( $action, $actions_enabled ) ) 
  2025. $actions_disabled[ $action ] = $action; 
  2026.  
  2027. if ( !in_array( 'export', $actions_disabled ) ) 
  2028. $capabilities[] = 'pods_export_' . $pod[ 'name' ]; 
  2029.  
  2030. if ( !in_array( 'reorder', $actions_disabled ) ) 
  2031. $capabilities[] = 'pods_reorder_' . $pod[ 'name' ]; 
  2032. elseif ( 1 == pods_var( 'ui_export', $pod[ 'options' ], 0 ) ) 
  2033. $capabilities[] = 'pods_export_' . $pod[ 'name' ]; 
  2034.  
  2035. return $capabilities; 
  2036.  
  2037. /** 
  2038. * Handle ajax calls for the administration 
  2039. */ 
  2040. public function admin_ajax () { 
  2041. if ( false === headers_sent() ) { 
  2042. pods_session_start(); 
  2043.  
  2044. header( 'Content-Type: text/html; charset=' . get_bloginfo( 'charset' ) ); 
  2045.  
  2046. // Sanitize input 
  2047. $params = pods_unslash( (array) $_POST ); 
  2048.  
  2049. foreach ( $params as $key => $value ) { 
  2050. if ( 'action' == $key ) 
  2051. continue; 
  2052.  
  2053. // Fixup $_POST data 
  2054. $_POST[ str_replace( '_podsfix_', '', $key ) ] = $_POST[ $key ]; 
  2055.  
  2056. // Fixup $params with unslashed data 
  2057. $params[ str_replace( '_podsfix_', '', $key ) ] = $value; 
  2058.  
  2059. // Unset the _podsfix_* keys 
  2060. unset( $params[ $key ] ); 
  2061.  
  2062. $params = (object) $params; 
  2063.  
  2064. $methods = array( 
  2065. 'add_pod' => array( 'priv' => true ),  
  2066. 'save_pod' => array( 'priv' => true ),  
  2067. 'load_sister_fields' => array( 'priv' => true ),  
  2068. 'process_form' => array( 'custom_nonce' => true ), // priv handled through nonce 
  2069. 'upgrade' => array( 'priv' => true ),  
  2070. 'migrate' => array( 'priv' => true ) 
  2071. ); 
  2072.  
  2073. /** 
  2074. * AJAX Callbacks in field editor 
  2075. * @since unknown 
  2076. * @param array $method Callback method map 
  2077. * @param object|PodsAdmin Class object 
  2078. */ 
  2079. $methods = apply_filters( 'pods_admin_ajax_methods', $methods, $this ); 
  2080.  
  2081. if ( !isset( $params->method ) || !isset( $methods[ $params->method ] ) ) 
  2082. pods_error( 'Invalid AJAX request', $this ); 
  2083.  
  2084. $defaults = array( 
  2085. 'priv' => null,  
  2086. 'name' => $params->method,  
  2087. 'custom_nonce' => null 
  2088. ); 
  2089.  
  2090. $method = (object) array_merge( $defaults, (array) $methods[ $params->method ] ); 
  2091.  
  2092. if ( true !== $method->custom_nonce && ( !isset( $params->_wpnonce ) || false === wp_verify_nonce( $params->_wpnonce, 'pods-' . $params->method ) ) ) 
  2093. pods_error( __( 'Unauthorized request', 'pods' ), $this ); 
  2094.  
  2095. // Cleaning up $params 
  2096. unset( $params->action ); 
  2097. unset( $params->method ); 
  2098.  
  2099. if ( true !== $method->custom_nonce ) 
  2100. unset( $params->_wpnonce ); 
  2101.  
  2102. // Check permissions (convert to array to support multiple) 
  2103. if ( !empty( $method->priv ) && !pods_is_admin( array( 'pods' ) ) && true !== $method->priv && !pods_is_admin( $method->priv ) ) 
  2104. pods_error( __( 'Access denied', 'pods' ), $this ); 
  2105.  
  2106. $params->method = $method->name; 
  2107.  
  2108. $params = apply_filters( 'pods_api_' . $method->name, $params, $method ); 
  2109.  
  2110. $api = pods_api(); 
  2111.  
  2112. $api->display_errors = false; 
  2113.  
  2114. if ( 'upgrade' == $method->name ) 
  2115. $output = (string) pods_upgrade( $params->version )->ajax( $params ); 
  2116. elseif ( 'migrate' == $method->name ) 
  2117. $output = (string) apply_filters( 'pods_api_migrate_run', $params ); 
  2118. else { 
  2119. if ( !method_exists( $api, $method->name ) ) 
  2120. pods_error( 'API method does not exist', $this ); 
  2121. elseif ( 'save_pod' == $method->name ) { 
  2122. if ( isset( $params->field_data_json ) && is_array( $params->field_data_json ) ) { 
  2123. $params->fields = $params->field_data_json; 
  2124.  
  2125. unset( $params->field_data_json ); 
  2126.  
  2127. foreach ( $params->fields as $k => $v ) { 
  2128. if ( empty( $v ) ) 
  2129. unset( $params->fields[ $k ] ); 
  2130. elseif ( !is_array( $v ) ) 
  2131. $params->fields[ $k ] = (array) @json_decode( $v, true ); 
  2132.  
  2133. // Dynamically call the API method 
  2134. $params = (array) $params; 
  2135.  
  2136. $output = call_user_func( array( $api, $method->name ), $params ); 
  2137.  
  2138. // Output in json format 
  2139. if ( false !== $output ) { 
  2140. if ( is_array( $output ) || is_object( $output ) ) 
  2141. wp_send_json( $output ); 
  2142. else 
  2143. echo $output; 
  2144. else 
  2145. pods_error( 'There was a problem with your request.' ); 
  2146.  
  2147. die(); // KBAI! 
  2148.  
  2149. /** 
  2150. * Profiles the Pods configuration 
  2151. * @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. 
  2152. * @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. 
  2153. * @return array 
  2154. * @since 3.0.0 
  2155. */ 
  2156. function configuration( $pod = null, $full_field_info = false ) { 
  2157. $api = pods_api(); 
  2158.  
  2159. if ( is_null( $pod ) ) { 
  2160. $the_pods = $api->load_pods(); 
  2161. elseif( is_array( $pod ) ) { 
  2162. foreach ( $pod as $p ) { 
  2163. $the_pods[] = $api->load_pod( $p ); 
  2164. else { 
  2165. $the_pods[] = $api->load_pod( $pod ); 
  2166.  
  2167. foreach( $the_pods as $pod ) { 
  2168. $configuration[ $pod[ 'name' ] ] = array( 
  2169. 'name' => $pod['name'],  
  2170. 'ID' => $pod[ 'id' ],  
  2171. 'storage' => $pod[ 'storage' ],  
  2172. 'fields' => $pod[ 'fields' ],  
  2173. ); 
  2174.  
  2175. if ( ! $full_field_info ) { 
  2176. foreach ( $the_pods as $pod ) { 
  2177. $fields = $configuration[ $pod['name'] ][ 'fields' ]; 
  2178. unset( $configuration[ $pod['name'] ][ 'fields' ] ); 
  2179. foreach ( $fields as $field ) { 
  2180. $info = array ( 
  2181. 'name' => $field[ 'name' ],  
  2182. 'type' => $field[ 'type' ],  
  2183. ); 
  2184.  
  2185. if ( $info[ 'type' ] === 'pick' ) { 
  2186. $info[ 'pick_object' ] = $field[ 'pick_object' ]; 
  2187. if ( isset ( $field[ 'pick_val' ] ) && $field[ 'pick_val' ] !== '' ) { 
  2188. $info[ 'pick_val' ] = $field[ 'pick_val' ]; 
  2189.  
  2190. if ( is_array( $info ) ) { 
  2191. $configuration[ $pod[ 'name' ] ][ 'fields' ][ $field[ 'name' ] ] = $info; 
  2192.  
  2193. unset( $info ); 
  2194.  
  2195.  
  2196.  
  2197.  
  2198. if ( is_array ( $configuration ) ) { 
  2199. return $configuration; 
  2200.  
  2201.  
  2202.  
  2203. /** 
  2204. * Build UI for extending REST API, if makes sense to do so. 
  2205. * @since 2.6.0 
  2206. * @access protected 
  2207. */ 
  2208. protected function rest_admin() { 
  2209. if( function_exists( 'register_rest_field' ) ) { 
  2210. add_filter( 'pods_admin_setup_edit_field_options', array( $this, 'add_rest_fields_to_field_editor' ), 12, 2 ); 
  2211. add_filter( 'pods_admin_setup_edit_field_tabs', array( $this, 'add_rest_field_tab' ), 12 ); 
  2212.  
  2213. add_filter( 'pods_admin_setup_edit_tabs', array( $this, 'add_rest_settings_tab' ), 12, 2 ); 
  2214. add_filter( 'pods_admin_setup_edit_options', array( $this, 'add_rest_settings_tab_fields' ), 12, 2 ); 
  2215.  
  2216.  
  2217. /** 
  2218. * Check if Pod type <em>could</em> extend core REST API response 
  2219. * @since 2.5.6 
  2220. * @access protected 
  2221. * @param array $pod 
  2222. * @return bool 
  2223. */ 
  2224. protected function restable_pod( $pod ) { 
  2225. $type = $pod[ 'type' ]; 
  2226. if( in_array( $type, array( 
  2227. 'post_type',  
  2228. 'user',  
  2229. 'taxonomy' 
  2230. ) { 
  2231. return true; 
  2232.  
  2233.  
  2234.  
  2235.  
  2236. /** 
  2237. * Add a rest api tab. 
  2238. * @since 2.6.0 
  2239. * @param array $tabs 
  2240. * @param array $pod 
  2241. * @return array 
  2242. */ 
  2243. public function add_rest_settings_tab( $tabs, $pod ) { 
  2244.  
  2245. $tabs[ 'rest-api' ] = __( 'REST API', 'pods' ); 
  2246.  
  2247. return $tabs; 
  2248.  
  2249.  
  2250. /** 
  2251. * Populate REST API tab. 
  2252. * @since 0.1.0 
  2253. * @param array $options 
  2254. * @param array $pod 
  2255. * @return array 
  2256. */ 
  2257. public function add_rest_settings_tab_fields( $options, $pod ) { 
  2258. if ( ! function_exists( 'register_rest_field' ) ) { 
  2259. $options[ 'rest-api' ] = array( 
  2260. 'no_dependencies' => array( 
  2261. 'label' => __( sprintf( 'Pods REST API support requires WordPress 4.3.1 or later and the %s or later.', '<a href="http://pods.io/docs/build/extending-core-wordpress-rest-api-routes-with-pods/" target="_blank">WordPress REST API 2.0-beta9</a>' ), 'pods' ),  
  2262. 'help' => __( sprintf( 'See %s for more information.', '<a href="http://pods.io/docs/build/extending-core-wordpress-rest-api-routes-with-pods/" target="_blank">http://pods.io/docs/build/extending-core-wordpress-rest-api-routes-with-pods/</a>'), 'pods' ),  
  2263. 'type' => 'html',  
  2264. ),  
  2265. ); 
  2266. } elseif ( $this->restable_pod( $pod ) ) { 
  2267. $options[ 'rest-api' ] = array( 
  2268. 'rest_enable' => array( 
  2269. 'label' => __( 'Enable', 'pods' ),  
  2270. 'help' => __( 'Add REST API support for this Pod.', 'pods' ),  
  2271. 'type' => 'boolean',  
  2272. 'default' => '',  
  2273. 'dependency' => true,  
  2274. ),  
  2275. 'rest_base' => array( 
  2276. 'label' => __( 'Rest Base', 'pods' ),  
  2277. 'help' => __( 'This will form the url for the route.', 'pods' ),  
  2278. 'type' => 'text',  
  2279. 'default' => pods_v( 'name', $pod ),  
  2280. 'boolean_yes_label' => '',  
  2281. 'depends-on' => array( 'rest_enable' => true ),  
  2282. ),  
  2283. 'read_all' => array( 
  2284. 'label' => __( 'Show All Fields?', 'pods' ),  
  2285. 'help' => __( 'Show all fields in REST API. If unchecked fields must be enabled on a field by field basis.', 'pods' ),  
  2286. 'type' => 'boolean',  
  2287. 'default' => '',  
  2288. 'boolean_yes_label' => '',  
  2289. 'depends-on' => array( 'rest_enable' => true ),  
  2290. ),  
  2291. 'write_all' => array( 
  2292. 'label' => __( 'Allow All Fields To Be Updated?', 'pods' ),  
  2293. 'help' => __( 'Allow all fields to be updated via the REST API. If unchecked fields must be enabled on a field by field basis.', 'pods' ),  
  2294. 'type' => 'boolean',  
  2295. 'default' => pods_v( 'name', $pod ),  
  2296. 'boolean_yes_label' => '',  
  2297. 'depends-on' => array( 'rest_enable' => true ),  
  2298.  
  2299. ); 
  2300.  
  2301. } else { 
  2302. $options[ 'rest-api' ] = array( 
  2303. 'not_restable' => array( 
  2304. 'label' => __( 'Pods REST API support covers post type, taxonomy and user Pods.', 'pods' ),  
  2305. 'help' => __( sprintf( 'See %s for more information.', '<a href="http://pods.io/docs/build/extending-core-wordpress-rest-api-routes-with-pods/" target="_blank">http://pods.io/docs/build/extending-core-wordpress-rest-api-routes-with-pods/"</a>'), 'pods' ),  
  2306. 'type' => 'html',  
  2307. ),  
  2308. ); 
  2309.  
  2310.  
  2311.  
  2312. return $options; 
  2313.  
  2314.  
  2315. /** 
  2316. * Add a REST API section to advanced tab of field editor. 
  2317. * @since 2.5.6 
  2318. * @param array $options 
  2319. * @param array $pod 
  2320. * @return array 
  2321. */ 
  2322. public function add_rest_fields_to_field_editor( $options, $pod ) { 
  2323.  
  2324. if( $this->restable_pod( $pod ) ) { 
  2325. $options[ 'rest' ][ __( 'Read/ Write', 'pods' ) ] = 
  2326. array( 
  2327. 'rest_read' => array( 
  2328. 'label' => __( 'Read via REST API?', 'pods' ),  
  2329. 'help' => __( 'Should this field be readable via the REST API? You must enable REST API support for this Pod.', 'pods' ),  
  2330. 'type' => 'boolean',  
  2331. 'default' => '',  
  2332. ),  
  2333. 'rest_write' => array( 
  2334. 'label' => __( 'Write via REST API?', 'pods' ),  
  2335. 'help' => __( 'Should this field be readable via the REST API? You must enable REST API support for this Pod.', 'pods' ),  
  2336. 'type' => 'boolean',  
  2337. 'default' => '',  
  2338. ),  
  2339. ); 
  2340. $options[ 'rest' ][ __( 'Relationship Field Options', 'pods' ) ] = 
  2341. array( 
  2342. 'rest_pick_response' => array( 
  2343. 'label' => __( 'Response Type', 'pods' ),  
  2344. 'help' => __( 'Should this field be readable via the REST API? You must enable REST API support for this Pod.', 'pods' ),  
  2345. 'type' => 'pick',  
  2346. 'default' => 'array',  
  2347. 'depends-on' => array( 'type' => 'pick' ),  
  2348. 'data' => array( 
  2349. 'array' => __( 'Full', 'pods' ),  
  2350. 'id' => __( 'ID only', 'pods' ),  
  2351. 'name' => __( 'Name', 'pods' ) 
  2352.  
  2353. ),  
  2354. ),  
  2355. 'rest_pick_depth' => array( 
  2356. 'label' => __( 'Depth', 'pods' ),  
  2357. 'help' => __( 'How far to traverse relationships in response', 'pods' ),  
  2358. 'type' => 'number',  
  2359. 'default' => '2',  
  2360. 'depends-on' => array( 'type' => 'pick' ),  
  2361.  
  2362.  
  2363. ); 
  2364.  
  2365.  
  2366.  
  2367. return $options; 
  2368.  
  2369.  
  2370. /** 
  2371. * Add REST field tab 
  2372. * @since 2.5.6 
  2373. * @param array $tabs 
  2374. * @return array 
  2375. */ 
  2376. public function add_rest_field_tab( $tabs ) { 
  2377. $tabs[ 'rest' ] = __( 'REST API', 'pods' ); 
  2378. return $tabs; 
  2379.