/includes/general.php

  1. <?php 
  2. /** 
  3. * @package Pods\Global\Functions\General 
  4. */ 
  5. /** 
  6. * Standardize queries and error reporting. It replaces @wp_ with $wpdb->prefix. 
  7. * 
  8. * @see PodsData::query 
  9. * 
  10. * @param string $sql SQL Query 
  11. * @param string $error (optional) The failure message 
  12. * @param string $results_error (optional) Throw an error if a records are found 
  13. * @param string $no_results_error (optional) Throw an error if no records are found 
  14. * 
  15. * @return array|bool|mixed|null|void 
  16. * @since 2.0 
  17. */ 
  18. function pods_query ( $sql, $error = 'Database Error', $results_error = null, $no_results_error = null ) { 
  19. $podsdata = pods_data(); 
  20.  
  21. $sql = apply_filters( 'pods_query_sql', $sql, $error, $results_error, $no_results_error ); 
  22. $sql = $podsdata->get_sql($sql); 
  23.  
  24. if ( is_array( $error ) ) { 
  25. if ( !is_array( $sql ) ) 
  26. $sql = array( $sql, $error ); 
  27.  
  28. $error = 'Database Error'; 
  29.  
  30. if ( 1 == pods_v( 'pods_debug_sql_all', 'get', 0 ) && is_user_logged_in() && pods_is_admin( array( 'pods' ) ) ) { 
  31. $debug_sql = $sql; 
  32.  
  33. echo '<textarea cols="100" rows="24">'; 
  34.  
  35. if ( is_array( $debug_sql ) ) { 
  36. $debug_sql = print_r( $debug_sql, true ); 
  37.  
  38. echo esc_textarea( $debug_sql ); 
  39.  
  40. echo '</textarea>'; 
  41.  
  42. return $podsdata->query( $sql, $error, $results_error, $no_results_error ); 
  43.  
  44. /** 
  45. * Standardize filters / actions 
  46. * 
  47. * @param string $scope Scope of the filter / action (ui for PodsUI, api for PodsAPI, etc..) 
  48. * @param string $name Name of filter / action to run 
  49. * @param mixed $args (optional) Arguments to send to filter / action 
  50. * @param object $obj (optional) Object to reference for filter / action 
  51. * 
  52. * @return mixed 
  53. * @since 2.0 
  54. * @todo Need to figure out how to handle $scope = 'pods' for the Pods class 
  55. */ 
  56. function pods_do_hook ( $scope, $name, $args = null, $obj = null ) { 
  57. // Add filter name 
  58. array_unshift( $args, "pods_{$scope}_{$name}" ); 
  59.  
  60. // Add object 
  61. $args[] = $obj; 
  62.  
  63. // Run apply_filters and give it all the arguments 
  64. $args = call_user_func_array( 'apply_filters', $args ); 
  65.  
  66. return $args; 
  67.  
  68. /** 
  69. * Message / Notice handling for Admin UI 
  70. * 
  71. * @param string $message The notice / error message shown 
  72. * @param string $type Message type 
  73. * 
  74. * @return void 
  75. */ 
  76. function pods_message ( $message, $type = null ) { 
  77. if ( empty( $type ) || !in_array( $type, array( 'notice', 'error' ) ) ) 
  78. $type = 'notice'; 
  79.  
  80. $class = ''; 
  81.  
  82. if ( 'notice' == $type ) 
  83. $class = 'updated'; 
  84. elseif ( 'error' == $type ) 
  85. $class = 'error'; 
  86.  
  87. echo '<div id="message" class="' . esc_attr( $class ) . ' fade"><p>' . $message . '</p></div>'; 
  88.  
  89. global $pods_errors; 
  90. $pods_errors = array(); 
  91.  
  92. /** 
  93. * Error Handling which throws / displays errors 
  94. * 
  95. * @param string $error The error message to be thrown / displayed 
  96. * @param object / boolean $obj If object, if $obj->display_errors is set, and is set to true: display errors; 
  97. * If boolean, and is set to true: display errors 
  98. * 
  99. * @throws Exception 
  100. * 
  101. * @return mixed|void 
  102. * 
  103. * @since 2.0 
  104. */ 
  105. function pods_error ( $error, $obj = null ) { 
  106.  
  107. global $pods_errors; 
  108.  
  109. $display_errors = false; 
  110.  
  111. if ( is_object( $obj ) && isset( $obj->display_errors ) && true === $obj->display_errors ) 
  112. $display_errors = true; 
  113. elseif ( is_bool( $obj ) && true === $obj ) 
  114. $display_errors = true; 
  115.  
  116. if ( is_object( $error ) && 'Exception' == get_class( $error ) ) { 
  117. $error = $error->getMessage(); 
  118. $display_errors = false; 
  119.  
  120. if ( is_array( $error ) ) { 
  121. if ( 1 == count( $error ) ) 
  122. $error = current( $error ); 
  123. elseif ( defined( 'DOING_AJAX' ) && DOING_AJAX ) 
  124. $error = __( 'The following issue occurred:', 'pods' ) . "\n\n- " . implode( "\n- ", $error ); 
  125. else 
  126. $error = __( 'The following issues occurred:', 'pods' ) . "\n<ul><li>" . implode( "</li>\n<li>", $error ) . "</li></ul>"; 
  127.  
  128. if ( is_object( $error ) ) 
  129. $error = __( 'An unknown error has occurred', 'pods' ); 
  130.  
  131. // log error in WP 
  132. $log_error = new WP_Error( 'pods-error-' . md5( $error ), $error ); 
  133.  
  134. // throw error as Exception and return false if silent 
  135. if ( $pods_errors !== $error && false === $display_errors && !empty( $error ) ) { 
  136. $exception_bypass = apply_filters( 'pods_error_exception', null, $error ); 
  137.  
  138. if ( null !== $exception_bypass ) 
  139. return $exception_bypass; 
  140.  
  141. $pods_errors = $error; 
  142.  
  143. set_exception_handler( 'pods_error' ); 
  144.  
  145. throw new Exception( $error ); 
  146.  
  147. $pods_errors = array(); 
  148.  
  149. $die_bypass = apply_filters( 'pods_error_die', null, $error ); 
  150.  
  151. if ( null !== $die_bypass ) 
  152. return $die_bypass; 
  153.  
  154. // die with error 
  155. if ( !defined( 'DOING_AJAX' ) && !headers_sent() && ( is_admin() || false !== strpos( $_SERVER[ 'REQUEST_URI' ], 'wp-comments-post.php' ) ) ) 
  156. wp_die( $error ); 
  157. else 
  158. die( "<e>$error</e>" ); 
  159.  
  160. /** 
  161. * Debug variable used in pods_debug to count the instances debug is used 
  162. */ 
  163. global $pods_debug; 
  164. $pods_debug = 0; 
  165. /** 
  166. * Debugging common issues using this function saves a few lines and is compatible with 
  167. * 
  168. * @param mixed $debug The error message to be thrown / displayed 
  169. * @param boolean $die If set to true, a die() will occur, if set to (int) 2 then a wp_die() will occur 
  170. * @param string $prefix 
  171. * 
  172. * @return void 
  173. * 
  174. * @since 2.0 
  175. */ 
  176. function pods_debug ( $debug = '_null', $die = false, $prefix = '_null' ) { 
  177. global $pods_debug; 
  178.  
  179. $pods_debug++; 
  180.  
  181. ob_start(); 
  182.  
  183. if ( '_null' !== $prefix ) 
  184. var_dump( $prefix ); 
  185.  
  186. if ( '_null' !== $debug ) 
  187. var_dump( $debug ); 
  188. else 
  189. var_dump( 'Pods Debug #' . $pods_debug ); 
  190.  
  191. $debug = ob_get_clean(); 
  192.  
  193. if ( false === strpos( $debug, "<pre class='xdebug-var-dump'" ) && ( !ini_get( 'xdebug.overload_var_dump' ) && !ini_get( 'html_errors' ) ) ) { 
  194. if ( !defined( 'DOING_AJAX' ) || !DOING_AJAX ) 
  195. $debug = esc_html( $debug ); 
  196.  
  197. $debug = '<pre>' . $debug . '</pre>'; 
  198.  
  199. $debug = '<e>' . $debug; 
  200.  
  201. if ( 2 === $die ) 
  202. wp_die( $debug ); 
  203. elseif ( true === $die ) 
  204. die( $debug ); 
  205.  
  206. echo $debug; 
  207.  
  208. /** 
  209. * Determine if user has admin access 
  210. * 
  211. * @param string|array $cap Additional capabilities to check 
  212. * 
  213. * @return bool Whether user has admin access 
  214. * 
  215. * @since 2.3.5 
  216. */ 
  217. function pods_is_admin ( $cap = null ) { 
  218. if ( is_user_logged_in() ) { 
  219. $pods_admin_capabilities = array( 
  220. 'delete_users' // default is_super_admin checks against this 
  221. ); 
  222.  
  223. $pods_admin_capabilities = apply_filters( 'pods_admin_capabilities', $pods_admin_capabilities, $cap ); 
  224.  
  225. if ( is_multisite() && is_super_admin() ) 
  226. return apply_filters( 'pods_is_admin', true, $cap, '_super_admin' ); 
  227.  
  228. if ( empty( $cap ) ) 
  229. $cap = array(); 
  230. else 
  231. $cap = (array) $cap; 
  232.  
  233. $cap = array_unique( array_filter( array_merge( $pods_admin_capabilities, $cap ) ) ); 
  234.  
  235. foreach ( $cap as $capability ) { 
  236. if ( current_user_can( $capability ) ) 
  237. return apply_filters( 'pods_is_admin', true, $cap, $capability ); 
  238.  
  239. return apply_filters( 'pods_is_admin', false, $cap, null ); 
  240.  
  241. /** 
  242. * Determine if Developer Mode is enabled 
  243. * 
  244. * @return bool Whether Developer Mode is enabled 
  245. * 
  246. * @since 2.3 
  247. */ 
  248. function pods_developer () { 
  249. if ( defined( 'PODS_DEVELOPER' ) && PODS_DEVELOPER ) 
  250. return true; 
  251.  
  252. return false; 
  253.  
  254. /** 
  255. * Determine if Tableless Mode is enabled 
  256. * 
  257. * @return bool Whether Tableless Mode is enabled 
  258. * 
  259. * @since 2.3 
  260. */ 
  261. function pods_tableless () { 
  262. if ( defined( 'PODS_TABLELESS' ) && PODS_TABLELESS ) 
  263. return true; 
  264.  
  265. return false; 
  266.  
  267. /** 
  268. * Determine if Strict Mode is enabled 
  269. * 
  270. * @param bool $include_debug Whether to include WP_DEBUG in strictness level 
  271. * 
  272. * @return bool Whether Strict Mode is enabled 
  273. * 
  274. * @since 2.3.5 
  275. */ 
  276. function pods_strict( $include_debug = true ) { 
  277.  
  278. if ( defined( 'PODS_STRICT' ) && PODS_STRICT ) { 
  279. return true; 
  280. // @deprecated PODS_STRICT_MODE since 2.3.5 
  281. elseif ( pods_allow_deprecated( false ) && defined( 'PODS_STRICT_MODE' ) && PODS_STRICT_MODE ) { 
  282. return true; 
  283. elseif ( $include_debug && defined( 'WP_DEBUG' ) && WP_DEBUG ) { 
  284. return true; 
  285.  
  286. return false; 
  287.  
  288.  
  289. /** 
  290. * Determine if Deprecated Mode is enabled 
  291. * 
  292. * @param bool $include_debug Whether to include strict mode 
  293. * 
  294. * @return bool Whether Deprecated Mode is enabled 
  295. * 
  296. * @since 2.3.10 
  297. */ 
  298. function pods_allow_deprecated( $strict = true ) { 
  299.  
  300. if ( $strict && pods_strict() ) { 
  301. return false; 
  302. elseif ( !defined( 'PODS_DEPRECATED' ) || PODS_DEPRECATED ) { 
  303. return true; 
  304.  
  305. return false; 
  306.  
  307.  
  308. /** 
  309. * Determine if Pods API Caching is enabled 
  310. * 
  311. * @return bool Whether Pods API Caching is enabled 
  312. * 
  313. * @since 2.3.9 
  314. */ 
  315. function pods_api_cache () { 
  316. if ( defined( 'PODS_API_CACHE' ) && !PODS_API_CACHE ) 
  317. return false; 
  318.  
  319. return true; 
  320.  
  321. /** 
  322. * Marks a function as deprecated and informs when it has been used. 
  323. * 
  324. * There is a hook deprecated_function_run that will be called that can be used 
  325. * to get the backtrace up to what file and function called the deprecated 
  326. * function. 
  327. * 
  328. * The current behavior is to trigger a user error if WP_DEBUG is true. 
  329. * 
  330. * This function is to be used in every function that is deprecated. 
  331. * 
  332. * @uses do_action() Calls 'deprecated_function_run' and passes the function name, what to use instead,  
  333. * and the version the function was deprecated in. 
  334. * @uses apply_filters() Calls 'deprecated_function_trigger_error' and expects boolean value of true to do 
  335. * trigger or false to not trigger error. 
  336. * 
  337. * @param string $function The function that was called 
  338. * @param string $version The version of WordPress that deprecated the function 
  339. * @param string $replacement Optional. The function that should have been called 
  340. * 
  341. * @since 2.0 
  342. */ 
  343. function pods_deprecated ( $function, $version, $replacement = null ) { 
  344. if ( !version_compare( $version, PODS_VERSION, '<=' ) && !version_compare( $version . '-a-0', PODS_VERSION, '<=' ) ) 
  345. return; 
  346.  
  347. do_action( 'deprecated_function_run', $function, $replacement, $version ); 
  348.  
  349. // Allow plugin to filter the output error trigger 
  350. if ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) { 
  351. if ( !is_null( $replacement ) ) 
  352. $error = __( '%1$s has been <strong>deprecated</strong> since Pods version %2$s! Use %3$s instead.', 'pods' ); 
  353. else 
  354. $error = __( '%1$s has been <strong>deprecated</strong> since Pods version %2$s with no alternative available.', 'pods' ); 
  355.  
  356. trigger_error( sprintf( $error, $function, $version, $replacement ) ); 
  357.  
  358. /** 
  359. * Inline help 
  360. * 
  361. * @param string $text Help text 
  362. * @param string $url Documentation URL 
  363. * 
  364. * @return void 
  365. * 
  366. * @since 2.0 
  367. */ 
  368. function pods_help ( $text, $url = null ) { 
  369.  
  370. if ( ! wp_script_is( 'jquery-qtip2', 'registered' ) ) { 
  371. wp_register_script( 'jquery-qtip2', PODS_URL . 'ui/js/jquery.qtip.min.js', array( 'jquery' ), '2.2' ); 
  372. elseif ( ! wp_script_is( 'jquery-qtip2', 'queue' ) && ! wp_script_is( 'jquery-qtip2', 'to_do' ) && ! wp_script_is( 'jquery-qtip2', 'done' ) ) { 
  373. wp_enqueue_script( 'jquery-qtip2' ); 
  374.  
  375. if ( ! wp_style_is( 'jquery-qtip2', 'registered' ) ) { 
  376. wp_register_style( 'jquery-qtip2', PODS_URL . 'ui/css/jquery.qtip.min.css', array(), '2.2' ); 
  377. elseif ( ! wp_style_is( 'jquery-qtip2', 'queue' ) && ! wp_style_is( 'jquery-qtip2', 'to_do' ) && ! wp_style_is( 'jquery-qtip2', 'done' ) ) { 
  378. wp_enqueue_style( 'jquery-qtip2' ); 
  379.  
  380. if ( ! wp_script_is( 'pods-qtip-init', 'registered' ) ) { 
  381. wp_register_script( 'pods-qtip-init', PODS_URL . 'ui/js/qtip.js', array( 
  382. 'jquery',  
  383. 'jquery-qtip2' 
  384. ), PODS_VERSION ); 
  385. elseif ( ! wp_script_is( 'pods-qtip-init', 'queue' ) && ! wp_script_is( 'pods-qtip-init', 'to_do' ) && ! wp_script_is( 'pods-qtip-init', 'done' ) ) { 
  386. wp_enqueue_script( 'pods-qtip-init' ); 
  387.  
  388. if ( is_array( $text ) ) { 
  389. if ( isset( $text[ 1 ] ) ) { 
  390. $url = $text[ 1 ]; 
  391.  
  392. $text = $text[ 0 ]; 
  393.  
  394. if ( 'help' == $text ) { 
  395. return; 
  396.  
  397. if ( 0 < strlen( $url ) ) { 
  398. $text .= '<br /><br /><a href="' . $url . '" target="_blank">' . __( 'Find out more', 'pods' ) . ' »</a>'; 
  399.  
  400. echo '<img src="' . esc_url( PODS_URL ) . 'ui/images/help.png" alt="' . esc_attr( $text ) . '" class="pods-icon pods-qtip" />'; 
  401.  
  402. /** 
  403. * Check whether or not something is a specific version minimum and/or maximum 
  404. * 
  405. * @param string $minimum_version Minimum version 
  406. * @param string $comparison Comparison operator 
  407. * @param string $maximum_version Maximum version 
  408. * 
  409. * @return bool 
  410. */ 
  411. function pods_version_check ( $what, $minimum_version, $comparison = '<=', $maximum_version = null ) { 
  412. global $wp_version, $wpdb; 
  413.  
  414. if ( 'php' == $what ) 
  415. $version = phpversion(); 
  416. elseif ( 'mysql' === $what ) 
  417. $version = $wpdb->db_version(); 
  418. else 
  419. $version = $wp_version; 
  420.  
  421. if ( !empty( $minimum_version ) && !version_compare( $minimum_version, $version, $comparison ) ) 
  422. return false; 
  423.  
  424. if ( !empty( $maximum_version ) && !version_compare( $version, $maximum_version, $comparison ) ) 
  425. return false; 
  426.  
  427. return true; 
  428.  
  429. /** 
  430. * Run a Pods Helper 
  431. * 
  432. * @param string $helper_name Helper Name 
  433. * @param string $value Value to run Helper on 
  434. * @param string $name Field name. 
  435. * 
  436. * @return bool 
  437. * @since 1.7.5 
  438. */ 
  439. function pods_helper ( $helper_name, $value = null, $name = null ) { 
  440. return pods()->helper( $helper_name, $value, $name ); 
  441.  
  442. /** 
  443. * Get the full URL of the current page 
  444. * 
  445. * @return string Full URL of the current page 
  446. * @since 2.3 
  447. */ 
  448. function pods_current_url () { 
  449. $url = 'http'; 
  450.  
  451. if ( isset( $_SERVER[ 'HTTPS' ] ) && 'off' != $_SERVER[ 'HTTPS' ] && 0 != $_SERVER[ 'HTTPS' ] ) 
  452. $url = 'https'; 
  453.  
  454. $url .= '://' . $_SERVER[ 'HTTP_HOST' ] . $_SERVER[ 'REQUEST_URI' ]; 
  455.  
  456. return apply_filters( 'pods_current_url', $url ); 
  457.  
  458. /** 
  459. * Find out if the current page has a valid $pods 
  460. * 
  461. * @param object $object The Pod Object currently checking (optional) 
  462. * 
  463. * @return bool 
  464. * @since 2.0 
  465. */ 
  466. function is_pod ( $object = null ) { 
  467. global $pods, $post; 
  468.  
  469. if ( is_object( $object ) && isset( $object->pod ) && !empty( $object->pod ) ) 
  470. return true; 
  471. elseif ( is_object( $pods ) && isset( $pods->pod ) && !empty( $pods->pod ) ) 
  472. return true; 
  473. elseif ( is_object( $post ) && isset( $post->post_type ) && pods_api()->pod_exists( $post->post_type, 'post_type' ) ) 
  474. return true; 
  475.  
  476. return false; 
  477.  
  478. /** 
  479. * See if the current user has a certain privilege 
  480. * 
  481. * @param mixed $privs The privilege name or names (array if multiple) 
  482. * @param string $method The access method ("AND", "OR") 
  483. * 
  484. * @return bool 
  485. * @since 1.2.0 
  486. */ 
  487. function pods_access ( $privs, $method = 'OR' ) { 
  488. // Convert $privs to an array 
  489. $privs = (array) $privs; 
  490.  
  491. // Convert $method to uppercase 
  492. $method = strtoupper( $method ); 
  493.  
  494. $check = apply_filters( 'pods_access', null, $privs, $method ); 
  495. if ( null !== $check && is_bool( $check ) ) 
  496. return $check; 
  497.  
  498. if ( !is_user_logged_in() ) 
  499. return false; 
  500.  
  501. if ( pods_is_admin( array( 'pods', 'pods_content' ) ) ) 
  502. return true; 
  503.  
  504. // Store approved privs when using "AND" 
  505. $approved_privs = array(); 
  506.  
  507. // Loop through the user's roles 
  508. foreach ( $privs as $priv ) { 
  509. if ( 0 === strpos( $priv, 'pod_' ) ) 
  510. $priv = pods_str_replace( 'pod_', 'pods_edit_', $priv, 1 ); 
  511.  
  512. if ( 0 === strpos( $priv, 'manage_' ) ) 
  513. $priv = pods_str_replace( 'manage_', 'pods_', $priv, 1 ); 
  514.  
  515. if ( current_user_can( $priv ) ) { 
  516. if ( 'OR' == $method ) 
  517. return true; 
  518.  
  519. $approved_privs[ $priv ] = true; 
  520. if ( 'AND' == strtoupper( $method ) ) { 
  521. foreach ( $privs as $priv ) { 
  522. if ( 0 === strpos( $priv, 'pod_' ) ) 
  523. $priv = pods_str_replace( 'pod_', 'pods_edit_', $priv, 1 ); 
  524.  
  525. if ( 0 === strpos( $priv, 'manage_' ) ) 
  526. $priv = pods_str_replace( 'manage_', 'pods_', $priv, 1 ); 
  527.  
  528. if ( !isset( $approved_privs[ $priv ] ) ) 
  529. return false; 
  530.  
  531. return true; 
  532.  
  533. return false; 
  534.  
  535. /** 
  536. * Shortcode support for use anywhere that support WP Shortcodes 
  537. * 
  538. * @param array $tags An associative array of shortcode properties 
  539. * @param string $content A string that represents a template override 
  540. * 
  541. * @return string 
  542. * @since 1.6.7 
  543. */ 
  544. function pods_shortcode ( $tags, $content = null ) { 
  545.  
  546. if ( defined( 'PODS_DISABLE_SHORTCODE' ) && PODS_DISABLE_SHORTCODE ) { 
  547. return ''; 
  548.  
  549. // For enforcing pagination parameters when not displaying pagination 
  550. $page = 1; 
  551. $offset = 0; 
  552.  
  553. if ( isset( $tags['page'] ) ) { 
  554. $page = (int) $tags['page']; 
  555. $page = max( $page, 1 ); 
  556.  
  557. if ( isset( $tags['offset'] ) ) { 
  558. $offset = (int) $tags['offset']; 
  559. $offset = max( $offset, 0 ); 
  560.  
  561. $defaults = array( 
  562. 'name' => null,  
  563. 'id' => null,  
  564. 'slug' => null,  
  565. 'select' => null,  
  566. 'join' => null,  
  567. 'order' => null,  
  568. 'orderby' => null,  
  569. 'limit' => null,  
  570. 'where' => null,  
  571. 'having' => null,  
  572. 'groupby' => null,  
  573. 'search' => true,  
  574. 'pagination' => false,  
  575. 'page' => null,  
  576. 'offset' => null,  
  577. 'filters' => false,  
  578. 'filters_label' => null,  
  579. 'filters_location' => 'before',  
  580. 'pagination_label' => null,  
  581. 'pagination_location' => 'after',  
  582. 'field' => null,  
  583. 'col' => null,  
  584. 'template' => null,  
  585. 'pods_page' => null,  
  586. 'helper' => null,  
  587. 'form' => null,  
  588. 'fields' => null,  
  589. 'label' => null,  
  590. 'thank_you' => null,  
  591. 'view' => null,  
  592. 'cache_mode' => 'none',  
  593. 'expires' => 0,  
  594. 'shortcodes' => false 
  595. ); 
  596.  
  597. if ( !empty( $tags ) ) 
  598. $tags = array_merge( $defaults, $tags ); 
  599. else 
  600. $tags = $defaults; 
  601.  
  602. $tags = apply_filters( 'pods_shortcode', $tags ); 
  603.  
  604. $tags[ 'pagination' ] = filter_var($tags[ 'pagination' ], FILTER_VALIDATE_BOOLEAN); 
  605. $tags[ 'search' ] = filter_var($tags[ 'pagination' ], FILTER_VALIDATE_BOOLEAN); 
  606.  
  607. if ( empty( $content ) ) 
  608. $content = null; 
  609.  
  610. // Allow views only if not targeting a file path (must be within theme) 
  611. if ( 0 < strlen( $tags[ 'view' ] ) ) { 
  612. $return = ''; 
  613.  
  614. if ( !file_exists( $tags[ 'view' ] ) ) { 
  615. $return = pods_view( $tags[ 'view' ], null, (int) $tags[ 'expires' ], $tags[ 'cache_mode' ] ); 
  616.  
  617. if ( $tags[ 'shortcodes' ] && defined( 'PODS_SHORTCODE_ALLOW_SUB_SHORTCODES' ) && PODS_SHORTCODE_ALLOW_SUB_SHORTCODES ) { 
  618. $return = do_shortcode( $return ); 
  619.  
  620. return $return; 
  621.  
  622. if ( empty( $tags[ 'name' ] ) ) { 
  623. if ( in_the_loop() || is_singular() ) { 
  624. $pod = pods( get_post_type(), get_the_ID(), false ); 
  625.  
  626. if ( !empty( $pod ) ) { 
  627. $tags[ 'name' ] = get_post_type(); 
  628. $id = $tags[ 'id' ] = get_the_ID(); 
  629.  
  630. if ( empty( $tags[ 'name' ] ) ) 
  631. return '<p>Please provide a Pod name</p>'; 
  632.  
  633. if ( !empty( $tags[ 'col' ] ) ) { 
  634. $tags[ 'field' ] = $tags[ 'col' ]; 
  635.  
  636. unset( $tags[ 'col' ] ); 
  637.  
  638. if ( !empty( $tags[ 'order' ] ) ) { 
  639. $tags[ 'orderby' ] = $tags[ 'order' ]; 
  640.  
  641. unset( $tags[ 'order' ] ); 
  642.  
  643. if ( empty( $content ) && empty( $tags[ 'pods_page' ] ) && empty( $tags[ 'template' ] ) && empty( $tags[ 'field' ] ) && empty( $tags[ 'form' ] ) ) { 
  644. return '<p>Please provide either a template or field name</p>'; 
  645.  
  646. if ( !isset( $id ) ) { 
  647. // id > slug (if both exist) 
  648. $id = null; 
  649.  
  650. if ( !empty( $tags[ 'slug' ] ) ) { 
  651. $id = $tags[ 'slug' ]; 
  652.  
  653. if ( defined( 'PODS_SHORTCODE_ALLOW_EVALUATE_TAGS' ) && PODS_SHORTCODE_ALLOW_EVALUATE_TAGS ) { 
  654. $id = pods_evaluate_tags( $id ); 
  655.  
  656. if ( !empty( $tags[ 'id' ] ) ) { 
  657. $id = $tags[ 'id' ]; 
  658.  
  659. if ( is_numeric( $id ) ) 
  660. $id = absint( $id ); 
  661.  
  662. if ( !isset( $pod ) ) 
  663. $pod = pods( $tags[ 'name' ], $id ); 
  664.  
  665. if ( empty( $pod ) ) 
  666. return '<p>Pod not found</p>'; 
  667.  
  668. $found = 0; 
  669.  
  670. if ( empty( $id ) ) { 
  671. $params = array(); 
  672.  
  673. if ( !defined( 'PODS_DISABLE_SHORTCODE_SQL' ) || !PODS_DISABLE_SHORTCODE_SQL ) { 
  674. if ( 0 < strlen( $tags[ 'orderby' ] ) ) { 
  675. $params[ 'orderby' ] = $tags[ 'orderby' ]; 
  676.  
  677. if ( 0 < strlen( $tags[ 'where' ] ) ) { 
  678. $params[ 'where' ] = $tags[ 'where' ]; 
  679.  
  680. if ( defined( 'PODS_SHORTCODE_ALLOW_EVALUATE_TAGS' ) && PODS_SHORTCODE_ALLOW_EVALUATE_TAGS ) { 
  681. $params[ 'where' ] = pods_evaluate_tags( $params[ 'where' ] ); 
  682.  
  683. if ( 0 < strlen( $tags[ 'having' ] ) ) { 
  684. $params[ 'having' ] = $tags[ 'having' ]; 
  685.  
  686. if ( defined( 'PODS_SHORTCODE_ALLOW_EVALUATE_TAGS' ) && PODS_SHORTCODE_ALLOW_EVALUATE_TAGS ) { 
  687. $params[ 'having' ] = pods_evaluate_tags( $id ); 
  688.  
  689. if ( 0 < strlen( $tags[ 'groupby' ] ) ) { 
  690. $params[ 'groupby' ] = $tags[ 'groupby' ]; 
  691.  
  692. if ( 0 < strlen( $tags[ 'select' ] ) ) { 
  693. $params[ 'select' ] = $tags[ 'select' ]; 
  694. if ( 0 < strlen( $tags[ 'join' ] ) ) { 
  695. $params[ 'join' ] = $tags[ 'join' ]; 
  696.  
  697. // Forms require params set 
  698. if ( ! empty( $params ) || empty( $tags[ 'form' ] ) ) { 
  699. if ( !empty( $tags[ 'limit' ] ) ) { 
  700. $params[ 'limit' ] = (int) $tags[ 'limit' ]; 
  701.  
  702. $params[ 'search' ] = $tags[ 'search' ]; 
  703.  
  704. $params[ 'pagination' ] = $tags[ 'pagination' ]; 
  705.  
  706. // If we aren't displaying pagination, we need to enforce page/offset 
  707. if ( ! $params['pagination'] ) { 
  708. $params['page'] = $page; 
  709. $params['offset'] = $offset; 
  710.  
  711. // Force pagination on, we need it and we're enforcing page/offset 
  712. $params['pagination'] = true; 
  713. } else { 
  714. // If we are displaying pagination, allow page/offset override only if *set* 
  715.  
  716. if ( isset( $tags['page'] ) ) { 
  717. $params['page'] = (int) $tags['page']; 
  718. $params['page'] = max( $params['page'], 1 ); 
  719.  
  720. if ( isset( $tags['offset'] ) ) { 
  721. $params['offset'] = (int) $tags['offset']; 
  722. $params['offset'] = max( $params['offset'], 0 ); 
  723.  
  724. if ( !empty( $tags[ 'cache_mode' ] ) && 'none' != $tags[ 'cache_mode' ] ) { 
  725. $params[ 'cache_mode' ] = $tags[ 'cache_mode' ]; 
  726. $params[ 'expires' ] = (int) $tags[ 'expires' ]; 
  727.  
  728. $params = apply_filters( 'pods_shortcode_findrecords_params', $params, $pod, $tags ); 
  729.  
  730. $pod->find( $params ); 
  731.  
  732. $found = $pod->total(); 
  733.  
  734. if ( !empty( $tags[ 'form' ] ) ) { 
  735. if ( 'user' == $pod->pod ) { 
  736. // Further hardening of User-based forms 
  737. if ( false !== strpos( $tags[ 'fields' ], '_capabilities' ) || false !== strpos( $tags[ 'fields' ], '_user_level' ) ) { 
  738. return ''; 
  739. // Only explicitly allow user edit forms 
  740. elseif ( !empty( $id ) && ( !defined( 'PODS_SHORTCODE_ALLOW_USER_EDIT' ) || !PODS_SHORTCODE_ALLOW_USER_EDIT ) ) { 
  741. return ''; 
  742.  
  743. return $pod->form( $tags[ 'fields' ], $tags[ 'label' ], $tags[ 'thank_you' ] ); 
  744. elseif ( !empty( $tags[ 'field' ] ) ) { 
  745. if ( empty( $tags[ 'helper' ] ) ) 
  746. $return = $pod->display( $tags[ 'field' ] ); 
  747. else 
  748. $return = $pod->helper( $tags[ 'helper' ], $pod->field( $tags[ 'field' ] ), $tags[ 'field' ] ); 
  749.  
  750. if ( $tags[ 'shortcodes' ] && defined( 'PODS_SHORTCODE_ALLOW_SUB_SHORTCODES' ) && PODS_SHORTCODE_ALLOW_SUB_SHORTCODES ) { 
  751. $return = do_shortcode( $return ); 
  752.  
  753. return $return; 
  754. elseif ( !empty( $tags[ 'pods_page' ] ) && class_exists( 'Pods_Pages' ) ) { 
  755. $pods_page = Pods_Pages::exists( $tags[ 'pods_page' ] ); 
  756.  
  757. if ( empty( $pods_page ) ) 
  758. return '<p>Pods Page not found</p>'; 
  759.  
  760. $return = Pods_Pages::content( true, $pods_page ); 
  761.  
  762. if ( $tags[ 'shortcodes' ] && defined( 'PODS_SHORTCODE_ALLOW_SUB_SHORTCODES' ) && PODS_SHORTCODE_ALLOW_SUB_SHORTCODES ) { 
  763. $return = do_shortcode( $return ); 
  764.  
  765. return $return; 
  766.  
  767. ob_start(); 
  768.  
  769. if ( empty( $id ) && false !== $tags[ 'filters' ] && 'before' == $tags[ 'filters_location' ] ) 
  770. echo $pod->filters( $tags[ 'filters' ], $tags[ 'filters_label' ] ); 
  771.  
  772. if ( empty( $id ) && 0 < $found && true === $tags[ 'pagination' ] && in_array( $tags[ 'pagination_location' ], array( 'before', 'both' ) ) ) 
  773. echo $pod->pagination( $tags[ 'pagination_label' ] ); 
  774.  
  775. echo $pod->template( $tags[ 'template' ], $content ); 
  776.  
  777. if ( empty( $id ) && 0 < $found && true === $tags[ 'pagination' ] && in_array( $tags[ 'pagination_location' ], array( 'after', 'both' ) ) ) 
  778. echo $pod->pagination( $tags[ 'pagination_label' ] ); 
  779.  
  780. if ( empty( $id ) && false !== $tags[ 'filters' ] && 'after' == $tags[ 'filters_location' ] ) 
  781. echo $pod->filters( $tags[ 'filters' ], $tags[ 'filters_label' ] ); 
  782.  
  783. $return = ob_get_clean(); 
  784.  
  785. if ( $tags[ 'shortcodes' ] && defined( 'PODS_SHORTCODE_ALLOW_SUB_SHORTCODES' ) && PODS_SHORTCODE_ALLOW_SUB_SHORTCODES ) { 
  786. $return = do_shortcode( $return ); 
  787.  
  788. return $return; 
  789.  
  790. /** 
  791. * Form Shortcode support for use anywhere that support WP Shortcodes 
  792. * 
  793. * @param array $tags An associative array of shortcode properties 
  794. * @param string $content Not currently used 
  795. * 
  796. * @return string 
  797. * @since 2.3 
  798. */ 
  799. function pods_shortcode_form ( $tags, $content = null ) { 
  800. $tags[ 'form' ] = 1; 
  801.  
  802. return pods_shortcode( $tags ); 
  803.  
  804. /** 
  805. * Fork of WordPress do_shortcode that allows specifying which shortcodes are ran. 
  806. * 
  807. * Search content for shortcodes and filter shortcodes through their hooks. 
  808. * 
  809. * If there are no shortcode tags defined, then the content will be returned 
  810. * without any filtering. This might cause issues when plugins are disabled but 
  811. * the shortcode will still show up in the post or content. 
  812. * 
  813. * @since 2.4.3 
  814. * 
  815. * @uses $shortcode_tags 
  816. * @uses get_shortcode_regex() Gets the search pattern for searching shortcodes. 
  817. * 
  818. * @param string $content Content to search for shortcodes 
  819. * @param array $shortcodes Array of shortcodes to run 
  820. * @return string Content with shortcodes filtered out. 
  821. */ 
  822. function pods_do_shortcode( $content, $shortcodes ) { 
  823.  
  824. global $shortcode_tags; 
  825.  
  826. // No shortcodes in content 
  827. if ( false === strpos( $content, '[' ) ) { 
  828. return $content; 
  829.  
  830. // No shortcodes registered 
  831. if ( empty( $shortcode_tags ) || !is_array( $shortcode_tags ) ) { 
  832. return $content; 
  833.  
  834. // Store all shortcodes, to restore later 
  835. $temp_shortcode_tags = $shortcode_tags; 
  836.  
  837. // Loop through all shortcodes and remove those not being used right now 
  838. foreach ( $shortcode_tags as $tag => $callback ) { 
  839. if ( ! in_array( $tag, $shortcodes ) ) { 
  840. unset( $shortcode_tags[ $tag ] ); 
  841.  
  842. // Build Shortcode regex pattern just for the shortcodes we want 
  843. $pattern = get_shortcode_regex(); 
  844.  
  845. // Call shortcode callbacks just for the shortcodes we want 
  846. $content = preg_replace_callback( "/$pattern/s", 'do_shortcode_tag', $content ); 
  847.  
  848. // Restore all shortcode tags 
  849. $shortcode_tags = $temp_shortcode_tags; 
  850.  
  851. return $content; 
  852.  
  853.  
  854. /** 
  855. * Check if Pods is compatible with WP / PHP / MySQL or not 
  856. * 
  857. * @return bool 
  858. * 
  859. * @since 1.10 
  860. */ 
  861. function pods_compatibility_check () { 
  862. $compatible = true; 
  863.  
  864. if ( !pods_version_check( 'wp', PODS_WP_VERSION_MINIMUM ) ) { 
  865. $compatible = false; 
  866.  
  867. add_action( 'admin_notices', 'pods_version_notice_wp' ); 
  868.  
  869. if ( !pods_version_check( 'php', PODS_PHP_VERSION_MINIMUM ) ) { 
  870. $compatible = false; 
  871.  
  872. add_action( 'admin_notices', 'pods_version_notice_php' ); 
  873.  
  874. if ( !pods_version_check( 'mysql', PODS_MYSQL_VERSION_MINIMUM ) ) { 
  875. $compatible = false; 
  876.  
  877. add_action( 'admin_notices', 'pods_version_notice_mysql' ); 
  878.  
  879. return $compatible; 
  880.  
  881. /** 
  882. * Show WP notice if WP version is incompatible 
  883. * 
  884. * @return void 
  885. * 
  886. * @since 1.10 
  887. */ 
  888. function pods_version_notice_wp () { 
  889. global $wp_version; 
  890. ?> 
  891. <div class="error fade"> 
  892. <p> 
  893. <strong><?php _e( 'NOTICE', 'pods' ); ?>:</strong> Pods <?php echo esc_html( PODS_VERSION ); ?> <?php _e( 'requires a minimum of', 'pods' ); ?> 
  894. <strong>WordPress <?php echo esc_html( PODS_WP_VERSION_MINIMUM ); ?>+</strong> <?php _e( 'to function. You are currently running', 'pods' ); ?> 
  895. <strong>WordPress <?php echo esc_html( $wp_version ); ?></strong> - <?php _e( 'Please upgrade your WordPress to continue.', 'pods' ); ?> 
  896. </p> 
  897. </div> 
  898. <?php 
  899.  
  900. /** 
  901. * Show WP notice if PHP version is incompatible 
  902. * 
  903. * @return void 
  904. * 
  905. * @since 1.10 
  906. */ 
  907. function pods_version_notice_php () { 
  908. ?> 
  909. <div class="error fade"> 
  910. <p> 
  911. <strong><?php _e( 'NOTICE', 'pods' ); ?>:</strong> Pods <?php echo esc_html( PODS_VERSION ); ?> <?php _e( 'requires a minimum of', 'pods' ); ?> 
  912. <strong>PHP <?php echo esc_html( PODS_PHP_VERSION_MINIMUM ); ?>+</strong> <?php _e( 'to function. You are currently running', 'pods' ); ?> 
  913. <strong>PHP <?php echo esc_html( phpversion() ); ?></strong> - <?php _e( 'Please upgrade (or have your Hosting Provider upgrade it for you) your PHP version to continue.', 'pods' ); ?> 
  914. </p> 
  915. </div> 
  916. <?php 
  917.  
  918. /** 
  919. * Show WP notice if MySQL version is incompatible 
  920. * 
  921. * @return void 
  922. * 
  923. * @since 1.10 
  924. */ 
  925. function pods_version_notice_mysql () { 
  926. global $wpdb; 
  927. $mysql = $wpdb->db_version(); 
  928. ?> 
  929. <div class="error fade"> 
  930. <p><strong><?php _e( 'NOTICE', 'pods' ); ?>:</strong> Pods <?php echo esc_html( PODS_VERSION ); ?> <?php _e( 'requires a minimum of', 'pods' ); ?> 
  931. <strong>MySQL <?php echo esc_html( PODS_MYSQL_VERSION_MINIMUM ); ?>+</strong> <?php _e( 'to function. You are currently running', 'pods' ); ?> 
  932. <strong>MySQL <?php echo esc_html( $mysql ); ?></strong> - <?php _e( 'Please upgrade (or have your Hosting Provider upgrade it for you) your MySQL version to continue.', 'pods' ); ?> 
  933. </p> 
  934. </div> 
  935. <?php 
  936.  
  937. /** 
  938. * Check if a Function exists or File exists in Theme / Child Theme 
  939. * 
  940. * @param string $function_or_file Function or file name to look for. 
  941. * @param string $function_name (optional) Function name to look for. 
  942. * @param string $file_dir (optional) Drectory to look into 
  943. * @param string $file_name (optional) Filename to look for 
  944. * 
  945. * @return mixed 
  946. * 
  947. * @since 1.12 
  948. */ 
  949. function pods_function_or_file ( $function_or_file, $function_name = null, $file_dir = null, $file_name = null ) { 
  950. $found = false; 
  951. $function_or_file = (string) $function_or_file; 
  952. if ( false !== $function_name ) { 
  953. if ( null === $function_name ) 
  954. $function_name = $function_or_file; 
  955. $function_name = str_replace( array( 
  956. '__',  
  957. '__',  
  958. '__' 
  959. ), '_', preg_replace( '/[^a-z^A-Z^_][^a-z^A-Z^0-9^_]*/', '_', (string) $function_name ) ); 
  960. if ( function_exists( 'pods_custom_' . $function_name ) ) 
  961. $found = array( 'function' => 'pods_custom_' . $function_name ); 
  962. elseif ( function_exists( $function_name ) ) 
  963. $found = array( 'function' => $function_name ); 
  964. if ( false !== $file_name && false === $found ) { 
  965. if ( null === $file_name ) 
  966. $file_name = $function_or_file; 
  967. $file_name = str_replace( array( 
  968. '__',  
  969. '__',  
  970. '__' 
  971. ), '_', preg_replace( '/[^a-z^A-Z^0-9^_]*/', '_', (string) $file_name ) ) . '.php'; 
  972. $custom_location = apply_filters( 'pods_file_directory', null, $function_or_file, $function_name, $file_dir, $file_name ); 
  973. if ( defined( 'PODS_FILE_DIRECTORY' ) && false !== PODS_FILE_DIRECTORY ) 
  974. $custom_location = PODS_FILE_DIRECTORY; 
  975. if ( !empty( $custom_location ) && locate_template( trim( $custom_location, '/' ) . '/' . ( !empty( $file_dir ) ? $file_dir . '/' : '' ) . $file_name ) ) 
  976. $found = array( 'file' => trim( $custom_location, '/' ) . '/' . ( !empty( $file_dir ) ? $file_dir . '/' : '' ) . $file_name ); 
  977. elseif ( locate_template( 'pods/' . ( !empty( $file_dir ) ? $file_dir . '/' : '' ) . $file_name ) ) 
  978. $found = array( 'file' => 'pods/' . ( !empty( $file_dir ) ? $file_dir . '/' : '' ) . $file_name ); 
  979. elseif ( locate_template( 'pods-' . ( !empty( $file_dir ) ? $file_dir . '-' : '' ) . $file_name ) ) 
  980. $found = array( 'file' => 'pods-' . ( !empty( $file_dir ) ? $file_dir . '-' : '' ) . $file_name ); 
  981. elseif ( locate_template( 'pods/' . ( !empty( $file_dir ) ? $file_dir . '-' : '' ) . $file_name ) ) 
  982. $found = array( 'file' => 'pods/' . ( !empty( $file_dir ) ? $file_dir . '-' : '' ) . $file_name ); 
  983.  
  984. return apply_filters( 'pods_function_or_file', $found, $function_or_file, $function_name, $file_name ); 
  985.  
  986. /** 
  987. * Redirects to another page. 
  988. * 
  989. * @param string $location The path to redirect to 
  990. * @param int $status Status code to use 
  991. * 
  992. * @return void 
  993. * 
  994. * @since 2.0 
  995. */ 
  996. function pods_redirect ( $location, $status = 302 ) { 
  997. if ( !headers_sent() ) { 
  998. wp_redirect( $location, $status ); 
  999. die(); 
  1000. else { 
  1001. die( '<script type="text/javascript">' 
  1002. . 'document.location = "' . str_replace( '&', '&', esc_js( $location ) ) . '";' 
  1003. . '</script>' ); 
  1004.  
  1005. /** 
  1006. * Check if a user has permission to be doing something based on standard permission options 
  1007. * 
  1008. * @param array $options 
  1009. * 
  1010. * @return bool Whether the user has permissions 
  1011. * 
  1012. * @since 2.0.5 
  1013. */ 
  1014. function pods_permission ( $options ) { 
  1015. global $current_user; 
  1016.  
  1017. get_currentuserinfo(); 
  1018.  
  1019. $permission = false; 
  1020.  
  1021. if ( isset( $options[ 'options' ] ) ) 
  1022. $options = $options[ 'options' ]; 
  1023.  
  1024. if ( pods_is_admin() ) 
  1025. $permission = true; 
  1026. elseif ( 0 == pods_v( 'restrict_role', $options, 0 ) && 0 == pods_v( 'restrict_capability', $options, 0 ) && 0 == pods_v( 'admin_only', $options, 0 ) ) 
  1027. $permission = true; 
  1028.  
  1029. if ( !$permission && 1 == pods_v( 'restrict_role', $options, 0 ) ) { 
  1030. $roles = pods_v( 'roles_allowed', $options ); 
  1031.  
  1032. if ( !is_array( $roles ) ) 
  1033. $roles = explode( ', ', $roles ); 
  1034.  
  1035. $roles = array_unique( array_filter( $roles ) ); 
  1036.  
  1037. foreach( $roles as $role ) { 
  1038. if ( is_user_logged_in() && in_array( $role, $current_user->roles ) ) { 
  1039. $permission = true; 
  1040.  
  1041. break; 
  1042.  
  1043. if ( !$permission && 1 == pods_v( 'restrict_capability', $options, 0 ) ) { 
  1044. $capabilities = pods_v( 'capability_allowed', $options ); 
  1045.  
  1046. if ( !is_array( $capabilities ) ) 
  1047. $capabilities = explode( ', ', $capabilities ); 
  1048.  
  1049. $capabilities = array_unique( array_filter( $capabilities ) ); 
  1050.  
  1051. foreach( $capabilities as $capability ) { 
  1052. $must_have_capabilities = explode( '&&', $capability ); 
  1053. $must_have_capabilities = array_unique( array_filter( $must_have_capabilities ) ); 
  1054.  
  1055. $must_have_permission = true; 
  1056.  
  1057. foreach ( $must_have_capabilities as $must_have_capability ) { 
  1058. if ( !current_user_can( $must_have_capability ) ) { 
  1059. $must_have_permission = false; 
  1060.  
  1061. break; 
  1062.  
  1063. if ( $must_have_permission && is_user_logged_in() ) { 
  1064. $permission = true; 
  1065.  
  1066. break; 
  1067.  
  1068. return $permission; 
  1069.  
  1070. /** 
  1071. * Check if permissions are restricted 
  1072. * 
  1073. * @param array $options 
  1074. * 
  1075. * @return bool Whether the permissions are restricted 
  1076. * 
  1077. * @since 2.3.4 
  1078. */ 
  1079. function pods_has_permissions ( $options ) { 
  1080. $permission = false; 
  1081.  
  1082. if ( isset( $options[ 'options' ] ) ) 
  1083. $options = $options[ 'options' ]; 
  1084.  
  1085. if ( 1 == pods_v( 'restrict_role', $options, 0 ) || 1 == pods_v( 'restrict_capability', $options, 0 ) || 1 == pods_v( 'admin_only', $options, 0 ) ) 
  1086. return true; 
  1087.  
  1088. return false; 
  1089.  
  1090. /** 
  1091. * A fork of get_page_by_title that excludes items unavailable via access rights (by status) 
  1092. * 
  1093. * @see get_page_by_title 
  1094. * 
  1095. * @param string $title Title of item to get 
  1096. * @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A. Default OBJECT. 
  1097. * @param string $type Post Type 
  1098. * @param string|array $status Post statuses to include (default is what user has access to) 
  1099. * 
  1100. * @return WP_Post|null WP_Post on success or null on failure 
  1101. * 
  1102. * @since 2.3.4 
  1103. */ 
  1104. function pods_by_title ( $title, $output = OBJECT, $type = 'page', $status = null ) { 
  1105. // @todo support Pod item lookups, not just Post Types 
  1106.  
  1107. /** 
  1108. * @var $wpdb WPDB 
  1109. */ 
  1110. global $wpdb; 
  1111.  
  1112. if ( empty( $status ) ) { 
  1113. $status = array( 
  1114. 'publish' 
  1115. ); 
  1116.  
  1117. if ( current_user_can( 'read_private_' . $type . 's') ) 
  1118. $status[] = 'private'; 
  1119.  
  1120. if ( current_user_can( 'edit_' . $type . 's' ) ) 
  1121. $status[] = 'draft'; 
  1122.  
  1123. $status = (array) $status; 
  1124.  
  1125. $status_sql = ' AND `post_status` IN ( %s' . str_repeat( ', %s', count( $status ) -1 ) . ' )'; 
  1126.  
  1127. $orderby_sql = ' ORDER BY ( `post_status` = %s ) DESC' . str_repeat( ', ( `post_status` = %s ) DESC', count( $status ) - 1 ) . ', `ID` DESC'; 
  1128.  
  1129. $prepared = array_merge( array( $title, $type ), $status, $status ); // once for WHERE, once for ORDER BY 
  1130.  
  1131. $page = $wpdb->get_var( $wpdb->prepare( "SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_title` = %s AND `post_type` = %s" . $status_sql . $orderby_sql, $prepared ) ); 
  1132.  
  1133. if ( $page ) 
  1134. return get_post( $page, $output ); 
  1135.  
  1136. return null; 
  1137.  
  1138. /** 
  1139. * Get a field value from a Pod 
  1140. * 
  1141. * @param string $pod The pod name 
  1142. * @param mixed $id (optional) The ID or slug, to load a single record; Provide array of $params to run 'find' 
  1143. * @param string|array $name The field name, or an associative array of parameters 
  1144. * @param boolean $single (optional) For tableless fields, to return the whole array or the just the first item 
  1145. * 
  1146. * @return mixed Field value 
  1147. * 
  1148. * @since 2.1 
  1149. */ 
  1150. function pods_field ( $pod, $id = false, $name = null, $single = false ) { 
  1151. // allow for pods_field( 'field_name' ); 
  1152. if ( null === $name ) { 
  1153. $name = $pod; 
  1154. $single = (boolean) $id; 
  1155.  
  1156. $pod = get_post_type(); 
  1157. $id = get_the_ID(); 
  1158.  
  1159. $pod = pods( $pod, $id ); 
  1160.  
  1161. if ( is_object( $pod ) ) { 
  1162. return $pod->field( $name, $single ); 
  1163.  
  1164. return null; 
  1165.  
  1166. /** 
  1167. * Get a field display value from a Pod 
  1168. * 
  1169. * @param string $pod The pod name 
  1170. * @param mixed $id (optional) The ID or slug, to load a single record; Provide array of $params to run 'find' 
  1171. * @param string|array $name The field name, or an associative array of parameters 
  1172. * @param boolean $single (optional) For tableless fields, to return the whole array or the just the first item 
  1173. * 
  1174. * @return mixed Field value 
  1175. * 
  1176. * @since 2.1 
  1177. */ 
  1178. function pods_field_display ( $pod, $id = false, $name = null, $single = false ) { 
  1179. // allow for pods_field_display( 'field_name' ); 
  1180. if ( null === $name ) { 
  1181. $name = $pod; 
  1182. $single = (boolean) $id; 
  1183.  
  1184. $pod = get_post_type(); 
  1185. $id = get_the_ID(); 
  1186.  
  1187. $pod = pods( $pod, $id ); 
  1188.  
  1189. if ( is_object( $pod ) ) { 
  1190. return $pod->display( $name, $single ); 
  1191.  
  1192. return null; 
  1193.  
  1194. /** 
  1195. * Get a field raw value from a Pod 
  1196. * 
  1197. * @param string $pod The pod name 
  1198. * @param mixed $id (optional) The ID or slug, to load a single record; Provide array of $params to run 'find' 
  1199. * @param string|array $name The field name, or an associative array of parameters 
  1200. * @param boolean $single (optional) For tableless fields, to return the whole array or the just the first item 
  1201. * 
  1202. * @return mixed Field value 
  1203. * 
  1204. * @since 2.1 
  1205. */ 
  1206. function pods_field_raw ( $pod, $id = false, $name = null, $single = false ) { 
  1207. // allow for pods_field_raw( 'field_name' ); 
  1208. if ( null === $name ) { 
  1209. $name = $pod; 
  1210. $single = (boolean) $id; 
  1211.  
  1212. $pod = get_post_type(); 
  1213. $id = get_the_ID(); 
  1214.  
  1215. return pods( $pod, $id )->raw( $name, $single ); 
  1216.  
  1217.  
  1218. /** 
  1219. * Set a cached value 
  1220. * 
  1221. * @see PodsView::set 
  1222. * 
  1223. * @param string $key Key for the cache 
  1224. * @param mixed $value Value to add to the cache 
  1225. * @param int $expires (optional) Time in seconds for the cache to expire, if 0 no expiration. 
  1226. * @param string $cache_mode (optional) Decides the caching method to use for the view. 
  1227. * @param string $group (optional) Key for the group 
  1228. * 
  1229. * @return bool|mixed|null|string|void 
  1230. * 
  1231. * @since 2.0 
  1232. */ 
  1233. function pods_view_set ( $key, $value, $expires = 0, $cache_mode = 'cache', $group = '' ) { 
  1234. require_once( PODS_DIR . 'classes/PodsView.php' ); 
  1235.  
  1236. return PodsView::set( $key, $value, $expires, $cache_mode, $group ); 
  1237.  
  1238. /** 
  1239. * Get a cached value 
  1240. * 
  1241. * @see PodsView::get 
  1242. * 
  1243. * @param string $key Key for the cache 
  1244. * @param string $cache_mode (optional) Decides the caching method to use for the view. 
  1245. * @param string $group (optional) Key for the group 
  1246. * @param string $callback (optional) Callback function to run to set the value if not cached 
  1247. * 
  1248. * @return bool|mixed|null|void 
  1249. * 
  1250. * @since 2.0 
  1251. */ 
  1252. function pods_view_get ( $key, $cache_mode = 'cache', $group = '', $callback = null ) { 
  1253. require_once( PODS_DIR . 'classes/PodsView.php' ); 
  1254.  
  1255. return PodsView::get( $key, $cache_mode, $group, $callback ); 
  1256.  
  1257. /** 
  1258. * Clear a cached value 
  1259. * 
  1260. * @see PodsView::clear 
  1261. * 
  1262. * @param string|bool $key Key for the cache 
  1263. * @param string $cache_mode (optional) Decides the caching method to use for the view. 
  1264. * @param string $group (optional) Key for the group 
  1265. * 
  1266. * @return bool 
  1267. * 
  1268. * @since 2.0 
  1269. */ 
  1270. function pods_view_clear ( $key = true, $cache_mode = 'cache', $group = '' ) { 
  1271. require_once( PODS_DIR . 'classes/PodsView.php' ); 
  1272.  
  1273. return PodsView::clear( $key, $cache_mode, $group ); 
  1274.  
  1275. /** 
  1276. * Set a cached value 
  1277. * 
  1278. * @see PodsView::set 
  1279. * 
  1280. * @param string $key Key for the cache 
  1281. * @param mixed $value Value to add to the cache 
  1282. * @param string $group (optional) Key for the group 
  1283. * @param int $expires (optional) Time in seconds for the cache to expire, if 0 no expiration. 
  1284. * 
  1285. * @return bool|mixed|null|string|void 
  1286. * 
  1287. * @since 2.0 
  1288. */ 
  1289. function pods_cache_set ( $key, $value, $group = '', $expires = 0) { 
  1290. return pods_view_set( $key, $value, $expires, 'cache', $group ); 
  1291.  
  1292. /** 
  1293. * Get a cached value 
  1294. * 
  1295. * @see PodsView::get 
  1296. * 
  1297. * @param string $key Key for the cache 
  1298. * @param string $group (optional) Key for the group 
  1299. * @param string $callback (optional) Callback function to run to set the value if not cached 
  1300. * 
  1301. * @return bool 
  1302. * 
  1303. * @since 2.0 
  1304. */ 
  1305. function pods_cache_get ( $key, $group = '', $callback = null ) { 
  1306. return pods_view_get( $key, 'cache', $group, $callback ); 
  1307.  
  1308. /** 
  1309. * Clear a cached value 
  1310. * 
  1311. * @see PodsView::clear 
  1312. * 
  1313. * @param string|bool $key Key for the cache 
  1314. * @param string $group (optional) Key for the group 
  1315. * 
  1316. * @return bool|mixed|null|void 
  1317. * 
  1318. * @since 2.0 
  1319. */ 
  1320. function pods_cache_clear ( $key = true, $group = '' ) { 
  1321. return pods_view_clear( $key, 'cache', $group ); 
  1322.  
  1323. /** 
  1324. * Set a cached value 
  1325. * 
  1326. * @see PodsView::set 
  1327. * 
  1328. * @param string $key Key for the cache 
  1329. * @param mixed $value Value to add to the cache 
  1330. * @param int $expires (optional) Time in seconds for the cache to expire, if 0 no expiration. 
  1331. * 
  1332. * @return bool|mixed|null|string|void 
  1333. * 
  1334. * @since 2.0 
  1335. */ 
  1336. function pods_transient_set ( $key, $value, $expires = 0 ) { 
  1337. return pods_view_set( $key, $value, $expires, 'transient' ); 
  1338.  
  1339. /** 
  1340. * Get a cached value 
  1341. * 
  1342. * @see PodsView::get 
  1343. * 
  1344. * @param string $key Key for the cache 
  1345. * @param string $callback (optional) Callback function to run to set the value if not cached 
  1346. * 
  1347. * @return bool|mixed|null|void 
  1348. * 
  1349. * @since 2.0 
  1350. */ 
  1351. function pods_transient_get ( $key, $callback = null ) { 
  1352. return pods_view_get( $key, 'transient', '', $callback ); 
  1353.  
  1354. /** 
  1355. * Clear a cached value 
  1356. * 
  1357. * @see PodsView::clear 
  1358. * 
  1359. * @param string|bool $key Key for the cache 
  1360. * 
  1361. * @return bool 
  1362. * 
  1363. * @since 2.0 
  1364. */ 
  1365. function pods_transient_clear ( $key = true ) { 
  1366. return pods_view_clear( $key, 'transient' ); 
  1367.  
  1368. /** 
  1369. * Set a cached value 
  1370. * 
  1371. * @see PodsView::set 
  1372. * 
  1373. * @param string $key Key for the cache 
  1374. * @param mixed $value Value to add to the cache 
  1375. * @param int $expires (optional) Time in seconds for the cache to expire, if 0 no expiration. 
  1376. * 
  1377. * @return bool|mixed|null|string|void 
  1378. * 
  1379. * @since 2.3.10 
  1380. */ 
  1381. function pods_site_transient_set ( $key, $value, $expires = 0 ) { 
  1382. return pods_view_set( $key, $value, $expires, 'site-transient' ); 
  1383.  
  1384. /** 
  1385. * Get a cached value 
  1386. * 
  1387. * @see PodsView::get 
  1388. * 
  1389. * @param string $key Key for the cache 
  1390. * @param string $callback (optional) Callback function to run to set the value if not cached 
  1391. * 
  1392. * @return bool|mixed|null|void 
  1393. * 
  1394. * @since 2.3.10 
  1395. */ 
  1396. function pods_site_transient_get ( $key, $callback = null ) { 
  1397. return pods_view_get( $key, 'site-transient', '', $callback ); 
  1398.  
  1399. /** 
  1400. * Clear a cached value 
  1401. * 
  1402. * @see PodsView::clear 
  1403. * 
  1404. * @param string|bool $key Key for the cache 
  1405. * 
  1406. * @return bool 
  1407. * 
  1408. * @since 2.3.10 
  1409. */ 
  1410. function pods_site_transient_clear ( $key = true ) { 
  1411. return pods_view_clear( $key, 'site-transient' ); 
  1412.  
  1413. /** 
  1414. * Set a cached value 
  1415. * 
  1416. * @see PodsView::set 
  1417. * 
  1418. * @param string $key Key for the cache 
  1419. * @param mixed $value Value to add to the cache 
  1420. * @param int $expires (optional) Time in seconds for the cache to expire, if 0 no expiration. 
  1421. * @param string $group (optional) Key for the group 
  1422. * 
  1423. * @return bool|mixed|null|string|void 
  1424. * 
  1425. * @since 2.3.10 
  1426. */ 
  1427. function pods_option_cache_set ( $key, $value, $expires = 0, $group = '' ) { 
  1428. return pods_view_set( $key, $value, $expires, 'option-cache', $group ); 
  1429.  
  1430. /** 
  1431. * Get a cached value 
  1432. * 
  1433. * @see PodsView::get 
  1434. * 
  1435. * @param string $key Key for the cache 
  1436. * @param string $group (optional) Key for the group 
  1437. * @param string $callback (optional) Callback function to run to set the value if not cached 
  1438. * 
  1439. * @return bool|mixed|null|void 
  1440. * 
  1441. * @since 2.3.10 
  1442. */ 
  1443. function pods_option_cache_get ( $key, $group = '', $callback = null ) { 
  1444. return pods_view_get( $key, 'option-cache', $group, $callback ); 
  1445.  
  1446. /** 
  1447. * Clear a cached value 
  1448. * 
  1449. * @see PodsView::clear 
  1450. * 
  1451. * @param string|bool $key Key for the cache 
  1452. * @param string $group (optional) Key for the group 
  1453. * 
  1454. * @return bool 
  1455. * 
  1456. * @since 2.3.10 
  1457. */ 
  1458. function pods_option_cache_clear ( $key = true, $group = '' ) { 
  1459. return pods_view_clear( $key, 'option-cache', $group ); 
  1460.  
  1461. /** 
  1462. * Scope variables and include a template like get_template_part that's child-theme aware 
  1463. * 
  1464. * @see get_template_part 
  1465. * 
  1466. * @param string|array $template Template names (see get_template_part) 
  1467. * @param array $data Data to scope to the include 
  1468. * @param bool $return Whether to return the output (echo by default) 
  1469. * @return string|null Template output 
  1470. * 
  1471. * @since 2.3.9 
  1472. */ 
  1473. function pods_template_part ( $template, $data = null, $return = false ) { 
  1474. $part = PodsView::get_template_part( $template, $data ); 
  1475.  
  1476. if ( !$return ) { 
  1477. echo $part; 
  1478.  
  1479. return null; 
  1480.  
  1481. return $part; 
  1482.  
  1483. /** 
  1484. * Add a new Pod outside of the DB 
  1485. * 
  1486. * @see PodsMeta::register 
  1487. * 
  1488. * @param string $type The pod type ('post_type', 'taxonomy', 'media', 'user', 'comment') 
  1489. * @param string $name The pod name 
  1490. * @param array $object (optional) Pod array, including any 'fields' arrays 
  1491. * 
  1492. * @return array|boolean Pod data or false if unsuccessful 
  1493. * @since 2.1 
  1494. */ 
  1495. function pods_register_type ( $type, $name, $object = null ) { 
  1496. if ( empty( $object ) ) 
  1497. $object = array(); 
  1498.  
  1499. if ( !empty( $name ) ) 
  1500. $object[ 'name' ] = $name; 
  1501.  
  1502. return pods_meta()->register( $type, $object ); 
  1503.  
  1504. /** 
  1505. * Add a new Pod field outside of the DB 
  1506. * 
  1507. * @see PodsMeta::register_field 
  1508. * 
  1509. * @param string|array $pod The pod name or array of pod names 
  1510. * @param string $name The name of the Pod 
  1511. * @param array $object (optional) Pod array, including any 'fields' arrays 
  1512. * 
  1513. * @return array|boolean Field data or false if unsuccessful 
  1514. * @since 2.1 
  1515. */ 
  1516. function pods_register_field ( $pod, $name, $field = null ) { 
  1517. if ( empty( $field ) ) 
  1518. $field = array(); 
  1519.  
  1520. if ( !empty( $name ) ) 
  1521. $field[ 'name' ] = $name; 
  1522.  
  1523. return pods_meta()->register_field( $pod, $field ); 
  1524.  
  1525. /** 
  1526. * Add a new Pod field type 
  1527. * 
  1528. * @see PodsForm::register_field_type 
  1529. * 
  1530. * @param string $type The new field type identifier 
  1531. * @param string $file The new field type class file location 
  1532. * 
  1533. * @return array Field type array 
  1534. * @since 2.3 
  1535. */ 
  1536. function pods_register_field_type ( $type, $file = null ) { 
  1537. return PodsForm::register_field_type( $type, $file ); 
  1538.  
  1539. /** 
  1540. * Register a related object 
  1541. * 
  1542. * @param string $name Object name 
  1543. * @param string $label Object label 
  1544. * @param array $options Object options 
  1545. * 
  1546. * @return array|boolean Object array or false if unsuccessful 
  1547. * @since 2.3 
  1548. */ 
  1549. function pods_register_related_object ( $name, $label, $options = null ) { 
  1550. return PodsForm::field_method( 'pick', 'register_related_object', $name, $label, $options ); 
  1551.  
  1552. /** 
  1553. * Require a component (always-on) 
  1554. * 
  1555. * @param string $component Component ID 
  1556. * 
  1557. * @return void 
  1558. * 
  1559. * @since 2.3 
  1560. */ 
  1561. function pods_require_component ( $component ) { 
  1562. add_filter( 'pods_component_require_' . $component, '__return_true' ); 
  1563.  
  1564. /** 
  1565. * Add a meta group of fields to add/edit forms 
  1566. * 
  1567. * @see PodsMeta::group_add 
  1568. * 
  1569. * @param string|array $pod The pod or type of element to attach the group to. 
  1570. * @param string $label Title of the edit screen section, visible to user. 
  1571. * @param string|array $fields Either a comma separated list of text fields or an associative array containing field information. 
  1572. * @param string $context (optional) The part of the page where the edit screen section should be shown ('normal', 'advanced', or 'side'). 
  1573. * @param string $priority (optional) The priority within the context where the boxes should show ('high', 'core', 'default' or 'low'). 
  1574. * @param string $type (optional) Type of the post to attach to. 
  1575. * 
  1576. * @return void 
  1577. * 
  1578. * @since 2.0 
  1579. * @link http://pods.io/docs/pods-group-add/ 
  1580. */ 
  1581. function pods_group_add ( $pod, $label, $fields, $context = 'normal', $priority = 'default', $type = null ) { 
  1582. if ( !is_array( $pod ) && null !== $type ) { 
  1583. $pod = array( 
  1584. 'name' => $pod,  
  1585. 'type' => $type 
  1586. ); 
  1587.  
  1588. pods_meta()->group_add( $pod, $label, $fields, $context, $priority ); 
  1589.  
  1590. /** 
  1591. * Check if a plugin is active on non-admin pages (is_plugin_active() only available in admin) 
  1592. * 
  1593. * @param string $plugin Plugin name. 
  1594. * 
  1595. * @return bool 
  1596. * 
  1597. * @since 2.0 
  1598. */ 
  1599. function pods_is_plugin_active ( $plugin ) { 
  1600. $active = false; 
  1601.  
  1602. if ( function_exists( 'is_plugin_active' ) ) 
  1603. $active = is_plugin_active( $plugin ); 
  1604.  
  1605. if ( !$active ) { 
  1606. $active_plugins = (array) get_option( 'active_plugins', array() ); 
  1607.  
  1608. if ( in_array( $plugin, $active_plugins ) ) 
  1609. $active = true; 
  1610.  
  1611. if ( !$active && is_multisite() ) { 
  1612. $plugins = get_site_option( 'active_sitewide_plugins' ); 
  1613.  
  1614. if ( isset( $plugins[ $plugin ] ) ) 
  1615. $active = true; 
  1616.  
  1617. return $active; 
  1618.  
  1619. /** 
  1620. * Check if Pods no conflict is on or not 
  1621. * 
  1622. * @param string $object_type 
  1623. * 
  1624. * @return bool 
  1625. * 
  1626. * @since 2.3 
  1627. */ 
  1628. function pods_no_conflict_check ( $object_type = 'post' ) { 
  1629. if ( 'post_type' == $object_type ) 
  1630. $object_type = 'post'; 
  1631. elseif ( 'term' == $object_type ) 
  1632. $object_type = 'taxonomy'; 
  1633.  
  1634. if ( !empty( PodsInit::$no_conflict ) && isset( PodsInit::$no_conflict[ $object_type ] ) && !empty( PodsInit::$no_conflict[ $object_type ] ) ) 
  1635. return true; 
  1636.  
  1637. return false; 
  1638.  
  1639. /** 
  1640. * Turn off conflicting / recursive actions for an object type that Pods hooks into 
  1641. * 
  1642. * @param string $object_type 
  1643. * @param string $object 
  1644. * 
  1645. * @return bool 
  1646. * 
  1647. * @since 2.0 
  1648. */ 
  1649. function pods_no_conflict_on ( $object_type = 'post', $object = null ) { 
  1650.  
  1651. if ( 'post_type' == $object_type ) 
  1652. $object_type = 'post'; 
  1653. elseif ( 'term' == $object_type ) 
  1654. $object_type = 'taxonomy'; 
  1655.  
  1656. if ( !empty( PodsInit::$no_conflict ) && isset( PodsInit::$no_conflict[ $object_type ] ) && !empty( PodsInit::$no_conflict[ $object_type ] ) ) 
  1657. return true; 
  1658.  
  1659. if ( !is_object( PodsInit::$meta ) ) 
  1660. return false; 
  1661.  
  1662. $no_conflict = array( 
  1663. 'filter' => array() 
  1664. ); 
  1665.  
  1666. // Filters = Usually get/update/delete meta functions 
  1667. // Actions = Usually insert/update/save/delete object functions 
  1668. if ( 'post' == $object_type ) { 
  1669. if ( apply_filters( 'pods_meta_handler', true, 'post' ) ) { 
  1670. // Handle *_post_meta 
  1671. if ( apply_filters( 'pods_meta_handler_get', true, 'post' ) ) { 
  1672. $no_conflict[ 'filter' ] = array( 
  1673. array( 'get_post_metadata', array( PodsInit::$meta, 'get_post_meta' ), 10, 4 ),  
  1674. ); 
  1675.  
  1676. if ( !pods_tableless() ) { 
  1677. $no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array( 
  1678. array( 'add_post_metadata', array( PodsInit::$meta, 'add_post_meta' ), 10, 5 ),  
  1679. array( 'update_post_metadata', array( PodsInit::$meta, 'update_post_meta' ), 10, 5 ),  
  1680. array( 'delete_post_metadata', array( PodsInit::$meta, 'delete_post_meta' ), 10, 5 ) 
  1681. ) ); 
  1682.  
  1683. $no_conflict[ 'action' ] = array( 
  1684. array( 'transition_post_status', array( PodsInit::$meta, 'save_post_detect_new' ), 10, 3 ),  
  1685. array( 'save_post', array( PodsInit::$meta, 'save_post' ), 10, 2 ) 
  1686. ); 
  1687. elseif ( 'taxonomy' == $object_type ) { 
  1688. if ( apply_filters( 'pods_meta_handler', true, 'term' ) ) { 
  1689. // Handle *_term_meta 
  1690. if ( apply_filters( 'pods_meta_handler_get', true, 'term' ) ) { 
  1691. $no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array( 
  1692. array( 'get_term_metadata', array( PodsInit::$meta, 'get_term_meta' ), 10, 4 ) 
  1693. ) ); 
  1694.  
  1695. if ( !pods_tableless() ) { 
  1696. $no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array( 
  1697. array( 'add_term_metadata', array( PodsInit::$meta, 'add_term_meta' ), 10, 5 ),  
  1698. array( 'update_term_metadata', array( PodsInit::$meta, 'update_term_meta' ), 10, 5 ),  
  1699. array( 'delete_term_metadata', array( PodsInit::$meta, 'delete_term_meta' ), 10, 5 ) 
  1700. ) ); 
  1701.  
  1702. $no_conflict[ 'action' ] = array( 
  1703. array( 'edited_term', array( PodsInit::$meta, 'save_taxonomy' ), 10, 3 ),  
  1704. array( 'create_term', array( PodsInit::$meta, 'save_taxonomy' ), 10, 3 ) 
  1705. ); 
  1706. elseif ( 'media' == $object_type ) { 
  1707. $no_conflict[ 'filter' ] = array( 
  1708. array( 'wp_update_attachment_metadata', array( PodsInit::$meta, 'save_media' ), 10, 2 ) 
  1709. ); 
  1710.  
  1711. if ( apply_filters( 'pods_meta_handler', true, 'post' ) ) { 
  1712. // Handle *_post_meta 
  1713. if ( apply_filters( 'pods_meta_handler_get', true, 'post' ) ) { 
  1714. $no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array( 
  1715. array( 'get_post_metadata', array( PodsInit::$meta, 'get_post_meta' ), 10, 4 ) 
  1716. ) ); 
  1717.  
  1718. if ( !pods_tableless() ) { 
  1719. $no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array( 
  1720. array( 'add_post_metadata', array( PodsInit::$meta, 'add_post_meta' ), 10, 5 ),  
  1721. array( 'update_post_metadata', array( PodsInit::$meta, 'update_post_meta' ), 10, 5 ),  
  1722. array( 'delete_post_metadata', array( PodsInit::$meta, 'delete_post_meta' ), 10, 5 ) 
  1723. ) ); 
  1724.  
  1725. $no_conflict[ 'action' ] = array(); 
  1726. elseif ( 'user' == $object_type ) { 
  1727. if ( apply_filters( 'pods_meta_handler', true, 'user' ) ) { 
  1728. // Handle *_term_meta 
  1729. if ( apply_filters( 'pods_meta_handler_get', true, 'user' ) ) { 
  1730. $no_conflict[ 'filter' ] = array( 
  1731. array( 'get_user_metadata', array( PodsInit::$meta, 'get_user_meta' ), 10, 4 ),  
  1732. ); 
  1733.  
  1734. if ( !pods_tableless() ) { 
  1735. $no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array( 
  1736. array( 'add_user_metadata', array( PodsInit::$meta, 'add_user_meta' ), 10, 5 ),  
  1737. array( 'update_user_metadata', array( PodsInit::$meta, 'update_user_meta' ), 10, 5 ),  
  1738. array( 'delete_user_metadata', array( PodsInit::$meta, 'delete_user_meta' ), 10, 5 ) 
  1739. ) ); 
  1740.  
  1741. $no_conflict[ 'action' ] = array( 
  1742. //array( 'user_register', array( PodsInit::$meta, 'save_user' ) ),  
  1743. array( 'profile_update', array( PodsInit::$meta, 'save_user' ) ) 
  1744. ); 
  1745. elseif ( 'comment' == $object_type ) { 
  1746. if ( apply_filters( 'pods_meta_handler', true, 'comment' ) ) { 
  1747. // Handle *_term_meta 
  1748. if ( apply_filters( 'pods_meta_handler_get', true, 'comment' ) ) { 
  1749. $no_conflict[ 'filter' ] = array( 
  1750. array( 'get_comment_metadata', array( PodsInit::$meta, 'get_comment_meta' ), 10, 4 ),  
  1751. ); 
  1752.  
  1753. if ( !pods_tableless() ) { 
  1754. $no_conflict[ 'filter' ] = array_merge( $no_conflict[ 'filter' ], array( 
  1755. array( 'add_comment_metadata', array( PodsInit::$meta, 'add_comment_meta' ), 10, 5 ),  
  1756. array( 'update_comment_metadata', array( PodsInit::$meta, 'update_comment_meta' ), 10, 5 ),  
  1757. array( 'delete_comment_metadata', array( PodsInit::$meta, 'delete_comment_meta' ), 10, 5 ) 
  1758. ) ); 
  1759.  
  1760. $no_conflict[ 'action' ] = array( 
  1761. array( 'pre_comment_approved', array( PodsInit::$meta, 'validate_comment' ), 10, 2 ),  
  1762. array( 'comment_post', array( PodsInit::$meta, 'save_comment' ) ),  
  1763. array( 'edit_comment', array( PodsInit::$meta, 'save_comment' ) ) 
  1764. ); 
  1765. elseif ( 'settings' == $object_type ) { 
  1766. $no_conflict[ 'filter' ] = array(); 
  1767.  
  1768. // @todo Better handle settings conflicts apart from each other 
  1769. /**if ( empty( $object ) ) { 
  1770. foreach ( PodsMeta::$settings as $setting_pod ) { 
  1771. foreach ( $setting_pod[ 'fields' ] as $option ) { 
  1772. $no_conflict[ 'filter' ][] = array( 'pre_option_' . $setting_pod[ 'name' ] . '_' . $option[ 'name' ], array( PodsInit::$meta, 'get_option' ), 10, 1 ); 
  1773. $no_conflict[ 'filter' ][] = array( 'pre_update_option_' . $setting_pod[ 'name' ] . '_' . $option[ 'name' ], array( PodsInit::$meta, 'update_option' ), 10, 2 ); 
  1774. } 
  1775. } 
  1776. } 
  1777. elseif ( isset( PodsMeta::$settings[ $object ] ) ) { 
  1778. foreach ( PodsMeta::$settings[ $object ][ 'fields' ] as $option ) { 
  1779. $no_conflict[ 'filter' ][] = array( 'pre_option_' . $object . '_' . $option[ 'name' ], array( PodsInit::$meta, 'get_option' ), 10, 1 ); 
  1780. $no_conflict[ 'filter' ][] = array( 'pre_update_option_' . $object . '_' . $option[ 'name' ], array( PodsInit::$meta, 'update_option' ), 10, 2 ); 
  1781. } 
  1782. }*/ 
  1783.  
  1784. $conflicted = false; 
  1785.  
  1786. foreach ( $no_conflict as $action_filter => $conflicts ) { 
  1787. foreach ( $conflicts as $k => $args ) { 
  1788. if ( call_user_func_array( 'has_' . $action_filter, array_slice( $args, 0, 2 ) ) ) { 
  1789. call_user_func_array( 'remove_' . $action_filter, array_slice( $args, 0, 3 ) ); 
  1790.  
  1791. $conflicted = true; 
  1792. else 
  1793. unset( $no_conflict[ $action_filter ][ $k ] ); 
  1794.  
  1795. if ( $conflicted ) { 
  1796. PodsInit::$no_conflict[ $object_type ] = $no_conflict; 
  1797.  
  1798. return true; 
  1799.  
  1800. return false; 
  1801.  
  1802. /** 
  1803. * Turn on actions after running code during pods_conflict 
  1804. * 
  1805. * @param string $object_type 
  1806. * 
  1807. * @return bool 
  1808. * 
  1809. * @since 2.0 
  1810. */ 
  1811. function pods_no_conflict_off ( $object_type = 'post' ) { 
  1812. if ( 'post_type' == $object_type ) 
  1813. $object_type = 'post'; 
  1814. elseif ( 'term' == $object_type ) 
  1815. $object_type = 'taxonomy'; 
  1816.  
  1817. if ( empty( PodsInit::$no_conflict ) || !isset( PodsInit::$no_conflict[ $object_type ] ) || empty( PodsInit::$no_conflict[ $object_type ] ) ) 
  1818. return false; 
  1819.  
  1820. if ( !is_object( PodsInit::$meta ) ) 
  1821. return false; 
  1822.  
  1823. $no_conflict = PodsInit::$no_conflict[ $object_type ]; 
  1824.  
  1825. $conflicted = false; 
  1826.  
  1827. foreach ( $no_conflict as $action_filter => $conflicts ) { 
  1828. foreach ( $conflicts as $args ) { 
  1829. if ( !call_user_func_array( 'has_' . $action_filter, array_slice( $args, 0, 2 ) ) ) { 
  1830. call_user_func_array( 'add_' . $action_filter, $args ); 
  1831.  
  1832. $conflicted = true; 
  1833.  
  1834. if ( $conflicted ) { 
  1835. unset( PodsInit::$no_conflict[ $object_type ] ); 
  1836.  
  1837. return true; 
  1838.  
  1839. return false; 
  1840.  
  1841. /** 
  1842. * Safely start a new session (without whitescreening on certain hosts,  
  1843. * which have no session path or isn't writable) 
  1844. * 
  1845. * @since 2.3.10 
  1846. */ 
  1847. function pods_session_start() { 
  1848.  
  1849. $save_path = session_save_path(); 
  1850.  
  1851. // Check if headers were sent 
  1852. if ( false !== headers_sent() ) { 
  1853. return false; 
  1854. // Allow for bypassing Pods session autostarting 
  1855. elseif ( defined( 'PODS_SESSION_AUTO_START' ) && !PODS_SESSION_AUTO_START ) { 
  1856. return false; 
  1857. // Allow for non-file based sessions, like Memcache 
  1858. elseif ( 0 === strpos( $save_path, 'tcp://' ) ) { 
  1859. // This is OK, but we don't want to check if file_exists on next statement 
  1860. // Check if session path exists and can be written to, avoiding PHP fatal errors 
  1861. elseif ( empty( $save_path ) || !@file_exists( $save_path ) || !is_writable( $save_path ) ) { 
  1862. return false; 
  1863. // Check if session ID is already set 
  1864. elseif ( '' != session_id() ) { 
  1865. return false; 
  1866.  
  1867. // Start session 
  1868. @session_start(); 
  1869.  
  1870. return true; 
  1871.  
.