PageRenderTime 61ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/includes/general.php

https://github.com/ElmsPark/pods
PHP | 1383 lines | 702 code | 224 blank | 457 comment | 226 complexity | b553c8f36eb104e2f0a1039a3dea61d1 MD5 | raw file
Possible License(s): AGPL-1.0
  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. * @internal param string $query The SQL query
  16. * @return array|bool|mixed|null|void
  17. * @since 2.0.0
  18. */
  19. function pods_query ( $sql, $error = 'Database Error', $results_error = null, $no_results_error = null ) {
  20. $podsdata = pods_data();
  21. $sql = apply_filters( 'pods_query_sql', $sql, $error, $results_error, $no_results_error );
  22. $sql = $podsdata->get_sql($sql);
  23. if ( is_array( $error ) ) {
  24. if ( !is_array( $sql ) )
  25. $sql = array( $sql, $error );
  26. $error = 'Database Error';
  27. }
  28. if ( 1 == pods_var( 'pods_debug_sql_all', 'get', 0 ) && is_user_logged_in() && ( is_super_admin() || current_user_can( 'delete_users' ) || current_user_can( 'pods' ) ) ) {
  29. $debug_sql = $sql;
  30. echo '<textarea cols="100" rows="24">';
  31. if ( is_array( $debug_sql ) )
  32. print_r( $debug_sql );
  33. else
  34. echo $debug_sql;
  35. echo '</textarea>';
  36. }
  37. return $podsdata->query( $sql, $error, $results_error, $no_results_error );
  38. }
  39. /**
  40. * Standardize filters / actions
  41. *
  42. * @param string $scope Scope of the filter / action (ui for PodsUI, api for PodsAPI, etc..)
  43. * @param string $name Name of filter / action to run
  44. * @param mixed $args (optional) Arguments to send to filter / action
  45. * @param object $obj (optional) Object to reference for filter / action
  46. *
  47. * @return mixed
  48. * @since 2.0.0
  49. * @todo Need to figure out how to handle $scope = 'pods' for the Pods class
  50. */
  51. function pods_do_hook ( $scope, $name, $args = null, &$obj = null ) {
  52. // Add filter name
  53. array_unshift( $args, "pods_{$scope}_{$name}" );
  54. // Add object
  55. $args[] = $obj;
  56. // Run apply_filters and give it all the arguments
  57. $args = call_user_func_array( 'apply_filters', $args );
  58. return $args;
  59. }
  60. /**
  61. * Message / Notice handling for Admin UI
  62. *
  63. * @param string $message The notice / error message shown
  64. * @param string $type Message type
  65. */
  66. function pods_message ( $message, $type = null ) {
  67. if ( empty( $type ) || !in_array( $type, array( 'notice', 'error' ) ) )
  68. $type = 'notice';
  69. $class = '';
  70. if ( 'notice' == $type )
  71. $class = 'updated';
  72. elseif ( 'error' == $type )
  73. $class = 'error';
  74. echo '<div id="message" class="' . $class . ' fade"><p>' . $message . '</p></div>';
  75. }
  76. /**
  77. * Error Handling which throws / displays errors
  78. *
  79. * @param string $error The error message to be thrown / displayed
  80. * @param object / boolean $obj If object, if $obj->display_errors is set, and is set to true: display errors;
  81. * If boolean, and is set to true: display errors
  82. * @throws Exception
  83. * @return mixed|void
  84. */
  85. function pods_error ( $error, $obj = null ) {
  86. $display_errors = false;
  87. if ( is_object( $obj ) && isset( $obj->display_errors ) && true === $obj->display_errors )
  88. $display_errors = true;
  89. elseif ( is_bool( $obj ) && true === $obj )
  90. $display_errors = true;
  91. if ( is_object( $error ) && 'Exception' == get_class( $error ) ) {
  92. $error = $error->getMessage();
  93. $display_errors = false;
  94. }
  95. if ( is_array( $error ) ) {
  96. if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
  97. $error = __( 'The following issues occured:', 'pods' ) . "\n\n- " . implode( "\n- ", $error );
  98. else
  99. $error = __( 'The following issues occured:', 'pods' ) . "\n<ul><li>" . implode( "</li>\n<li>", $error ) . "</li></ul>";
  100. }
  101. elseif ( is_object( $error ) )
  102. $error = __( 'An unknown error has occurred', 'pods' );
  103. // log error in WP
  104. $log_error = new WP_Error( 'pods-error-' . md5( $error ), $error );
  105. // throw error as Exception and return false if silent
  106. if ( false !== $display_errors && !empty( $error ) ) {
  107. $exception_bypass = apply_filters( 'pods_error_exception', null, $error );
  108. if ( null !== $exception_bypass )
  109. return $exception_bypass;
  110. set_exception_handler( 'pods_error' );
  111. throw new Exception( $error );
  112. }
  113. $die_bypass = apply_filters( 'pods_error_die', null, $error );
  114. if ( null !== $die_bypass )
  115. return $die_bypass;
  116. // die with error
  117. if ( !defined( 'DOING_AJAX' ) && !headers_sent() && ( is_admin() || false !== strpos( $_SERVER[ 'REQUEST_URI' ], 'wp-comments-post.php' ) ) )
  118. wp_die( $error );
  119. else
  120. die( "<e>$error</e>" );
  121. }
  122. /**
  123. * Debug variable used in pods_debug to count the instances debug is used
  124. */
  125. global $pods_debug;
  126. $pods_debug = 0;
  127. /**
  128. * Debugging common issues using this function saves a few lines and is compatible with
  129. *
  130. * @param mixed $debug The error message to be thrown / displayed
  131. * @param boolean $die If set to true, a die() will occur, if set to (int) 2 then a wp_die() will occur
  132. * @param string $prefix
  133. * @internal param bool $identifier If set to true, an identifying # will be output
  134. */
  135. function pods_debug ( $debug = '_null', $die = false, $prefix = '_null' ) {
  136. global $pods_debug;
  137. $pods_debug++;
  138. ob_start();
  139. if ( '_null' !== $prefix )
  140. var_dump( $prefix );
  141. if ( '_null' !== $debug )
  142. var_dump( $debug );
  143. else
  144. var_dump( 'Pods Debug #' . $pods_debug );
  145. $debug = ob_get_clean();
  146. if ( !defined( 'DOING_AJAX' ) || !DOING_AJAX )
  147. $debug = esc_html( $debug );
  148. if ( false === strpos( $debug, "<pre class='xdebug-var-dump' dir='ltr'>" ) )
  149. $debug = '<e><pre>' . $debug . '</pre>';
  150. else
  151. $debug = '<e>' . $debug;
  152. if ( 2 === $die )
  153. wp_die( $debug );
  154. elseif ( true === $die )
  155. die( $debug );
  156. echo $debug;
  157. }
  158. /**
  159. * Determine if Developer Mode is enabled
  160. *
  161. * @return bool Whether Developer Mode is enabled
  162. *
  163. * @since 2.3
  164. */
  165. function pods_developer () {
  166. if ( defined( 'PODS_DEVELOPER' ) && PODS_DEVELOPER )
  167. return true;
  168. return false;
  169. }
  170. /**
  171. * Marks a function as deprecated and informs when it has been used.
  172. *
  173. * There is a hook deprecated_function_run that will be called that can be used
  174. * to get the backtrace up to what file and function called the deprecated
  175. * function.
  176. *
  177. * The current behavior is to trigger a user error if WP_DEBUG is true.
  178. *
  179. * This function is to be used in every function that is deprecated.
  180. *
  181. * @uses do_action() Calls 'deprecated_function_run' and passes the function name, what to use instead,
  182. * and the version the function was deprecated in.
  183. * @uses apply_filters() Calls 'deprecated_function_trigger_error' and expects boolean value of true to do
  184. * trigger or false to not trigger error.
  185. *
  186. * @param string $function The function that was called
  187. * @param string $version The version of WordPress that deprecated the function
  188. * @param string $replacement Optional. The function that should have been called
  189. *
  190. * @since 2.0.0
  191. */
  192. function pods_deprecated ( $function, $version, $replacement = null ) {
  193. if ( !version_compare( $version, PODS_VERSION, '<=' ) && !version_compare( $version . '-a-0', PODS_VERSION, '<=' ) )
  194. return;
  195. do_action( 'deprecated_function_run', $function, $replacement, $version );
  196. // Allow plugin to filter the output error trigger
  197. if ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) {
  198. if ( !is_null( $replacement ) )
  199. $error = __( '%1$s has been <strong>deprecated</strong> since Pods version %2$s! Use %3$s instead.', 'pods' );
  200. else
  201. $error = __( '%1$s has been <strong>deprecated</strong> since Pods version %2$s with no alternative available.', 'pods' );
  202. trigger_error( sprintf( $error, $function, $version, $replacement ) );
  203. }
  204. }
  205. /**
  206. * Inline help
  207. *
  208. * @param string $text Help text
  209. * @param string $url Documentation URL
  210. *
  211. * @since 2.0.0
  212. */
  213. function pods_help ( $text, $url = null ) {
  214. if ( !wp_script_is( 'jquery-qtip', 'registered' ) )
  215. wp_register_script( 'jquery-qtip', PODS_URL . 'ui/js/jquery.qtip.min.js', array( 'jquery' ), '2.0-2011-10-02' );
  216. if ( !wp_script_is( 'jquery-qtip', 'queue' ) && !wp_script_is( 'jquery-qtip', 'to_do' ) && !wp_script_is( 'jquery-qtip', 'done' ) )
  217. wp_enqueue_script( 'jquery-qtip' );
  218. if ( !wp_style_is( 'pods-qtip', 'registered' ) )
  219. wp_register_style( 'pods-qtip', PODS_URL . 'ui/css/jquery.qtip.min.css', array(), '2.0-2011-10-02' );
  220. if ( !wp_style_is( 'pods-qtip', 'queue' ) && !wp_style_is( 'pods-qtip', 'to_do' ) && !wp_style_is( 'pods-qtip', 'done' ) )
  221. wp_enqueue_style( 'pods-qtip' );
  222. if ( !wp_script_is( 'pods-qtip-init', 'registered' ) )
  223. wp_register_script( 'pods-qtip-init', PODS_URL . 'ui/js/qtip.js', array(
  224. 'jquery',
  225. 'jquery-qtip'
  226. ), PODS_VERSION );
  227. if ( !wp_script_is( 'pods-qtip-init', 'queue' ) && !wp_script_is( 'pods-qtip-init', 'to_do' ) && !wp_script_is( 'pods-qtip-init', 'done' ) )
  228. wp_enqueue_script( 'pods-qtip-init' );
  229. if ( is_array( $text ) ) {
  230. if ( isset( $text[ 1 ] ) )
  231. $url = $text[ 1 ];
  232. $text = $text[ 0 ];
  233. }
  234. if ( 'help' == $text )
  235. return;
  236. if ( 0 < strlen( $url ) )
  237. $text .= '<br /><br /><a href="' . $url . '" target="_blank">' . __( 'Find out more', 'pods' ) . ' &raquo;</a>';
  238. echo '<img src="' . PODS_URL . 'ui/images/help.png" alt="' . esc_attr( $text ) . '" class="pods-icon pods-qtip" />';
  239. }
  240. /**
  241. * Build a unique slug
  242. *
  243. * @param string $slug The slug value
  244. * @param string $column_name The column name
  245. * @param string|array $pod The Pod name or array of Pod data
  246. * @param int $pod_id The Pod ID
  247. * @param int $id The item ID
  248. * @param object $obj (optional)
  249. *
  250. * @return string The unique slug name
  251. * @since 1.7.2
  252. */
  253. function pods_unique_slug ( $slug, $column_name, $pod, $pod_id = 0, $id = 0, $obj = null, $strict = true ) {
  254. $slug = pods_create_slug( $slug, $strict );
  255. $pod_data = array();
  256. if ( is_array( $pod ) ) {
  257. $pod_data = $pod;
  258. $pod_id = pods_var( 'id', $pod_data, 0 );
  259. $pod = pods_var( 'name', $pod_data );
  260. }
  261. $pod_id = absint( $pod_id );
  262. $id = absint( $id );
  263. if ( empty( $pod_data ) )
  264. $pod_data = pods_api()->load_pod( array( 'id' => $pod_id, 'name' => $pod ), false );
  265. if ( empty( $pod_data ) || empty( $pod_id ) || empty( $pod ) )
  266. return $slug;
  267. if ( 'table' != $pod_data[ 'storage' ] || !in_array( $pod_data[ 'type' ], array( 'pod', 'table' ) ) )
  268. return $slug;
  269. $check_sql = "
  270. SELECT DISTINCT `t`.`{$column_name}` AS `slug`
  271. FROM `@wp_pods_{$pod}` AS `t`
  272. WHERE `t`.`{$column_name}` = %s AND `t`.`id` != %d
  273. LIMIT 1
  274. ";
  275. $slug_check = pods_query( array( $check_sql, $slug, $id ), $obj );
  276. if ( !empty( $slug_check ) || apply_filters( 'pods_unique_slug_is_bad_flat_slug', false, $slug, $column_name, $pod, $pod_id, $id, $pod_data, $obj ) ) {
  277. $suffix = 2;
  278. do {
  279. $alt_slug = substr( $slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-{$suffix}";
  280. $slug_check = pods_query( array( $check_sql, $alt_slug, $id ), $obj );
  281. $suffix++;
  282. }
  283. while ( !empty( $slug_check ) || apply_filters( 'pods_unique_slug_is_bad_flat_slug', false, $alt_slug, $column_name, $pod, $pod_id, $id, $pod_data, $obj ) );
  284. $slug = $alt_slug;
  285. }
  286. $slug = apply_filters( 'pods_unique_slug', $slug, $id, $column_name, $pod, $pod_id, $obj );
  287. return $slug;
  288. }
  289. /**
  290. * Check whether or not WordPress is a specific version minimum and/or maximum
  291. *
  292. * @param string $minimum_version Minimum WordPress version
  293. * @param string $comparison Comparison operator
  294. * @param string $maximum_version Maximum WordPress version
  295. *
  296. * @return bool
  297. */
  298. function pods_wp_version ( $minimum_version, $comparison = '<=', $maximum_version = null ) {
  299. global $wp_version;
  300. if ( !empty( $minimum_version ) && !version_compare( $minimum_version, $wp_version, $comparison ) )
  301. return false;
  302. if ( !empty( $maximum_version ) && !version_compare( $wp_version, $maximum_version, $comparison ) )
  303. return false;
  304. return true;
  305. }
  306. /**
  307. * Run a Pods Helper
  308. *
  309. * @param string $helper_name Helper Name
  310. * @param string $value Value to run Helper on
  311. * @param string $name Field name.
  312. *
  313. * @return bool
  314. * @since 1.7.5
  315. */
  316. function pods_helper ( $helper_name, $value = null, $name = null ) {
  317. return pods()->helper( $helper_name, $value, $name );
  318. }
  319. /**
  320. * Get current URL of any page
  321. *
  322. * @return string
  323. * @since 1.9.6
  324. */
  325. if ( !function_exists( 'get_current_url' ) ) {
  326. /**
  327. * @return mixed|void
  328. */
  329. function get_current_url () {
  330. $url = 'http';
  331. if ( isset( $_SERVER[ 'HTTPS' ] ) && 'off' != $_SERVER[ 'HTTPS' ] && 0 != $_SERVER[ 'HTTPS' ] )
  332. $url = 'https';
  333. $url .= '://' . $_SERVER[ 'HTTP_HOST' ] . $_SERVER[ 'REQUEST_URI' ];
  334. return apply_filters( 'get_current_url', $url );
  335. }
  336. }
  337. /**
  338. * Find out if the current page has a valid $pods
  339. *
  340. * @param object $object The Pod Object currently checking (optional)
  341. *
  342. * @return bool
  343. * @since 2.0.0
  344. */
  345. function is_pod ( $object = null ) {
  346. global $pods;
  347. if ( is_object( $object ) && isset( $object->pod ) && !empty( $object->pod ) )
  348. return true;
  349. if ( is_object( $pods ) && isset( $pods->pod ) && !empty( $pods->pod ) )
  350. return true;
  351. return false;
  352. }
  353. /**
  354. * See if the current user has a certain privilege
  355. *
  356. * @param mixed $privs The privilege name or names (array if multiple)
  357. * @param string $method The access method ("AND", "OR")
  358. *
  359. * @return bool
  360. * @since 1.2.0
  361. */
  362. function pods_access ( $privs, $method = 'OR' ) {
  363. // Convert $privs to an array
  364. $privs = (array) $privs;
  365. // Convert $method to uppercase
  366. $method = strtoupper( $method );
  367. $check = apply_filters( 'pods_access', null, $privs, $method );
  368. if ( null !== $check && is_bool( $check ) )
  369. return $check;
  370. if ( !is_user_logged_in() )
  371. return false;
  372. if ( is_super_admin() || current_user_can( 'delete_users' ) || current_user_can( 'pods' ) || current_user_can( 'pods_content' ) )
  373. return true;
  374. // Store approved privs when using "AND"
  375. $approved_privs = array();
  376. // Loop through the user's roles
  377. foreach ( $privs as $priv ) {
  378. if ( 0 === strpos( $priv, 'pod_' ) )
  379. $priv = pods_str_replace( 'pod_', 'pods_edit_', $priv, 1 );
  380. if ( 0 === strpos( $priv, 'manage_' ) )
  381. $priv = pods_str_replace( 'manage_', 'pods_', $priv, 1 );
  382. if ( current_user_can( $priv ) ) {
  383. if ( 'OR' == $method )
  384. return true;
  385. $approved_privs[ $priv ] = true;
  386. }
  387. }
  388. if ( 'AND' == strtoupper( $method ) ) {
  389. foreach ( $privs as $priv ) {
  390. if ( 0 === strpos( $priv, 'pod_' ) )
  391. $priv = pods_str_replace( 'pod_', 'pods_edit_', $priv, 1 );
  392. if ( 0 === strpos( $priv, 'manage_' ) )
  393. $priv = pods_str_replace( 'manage_', 'pods_', $priv, 1 );
  394. if ( isset( $approved_privs[ $priv ] ) )
  395. return false;
  396. }
  397. return true;
  398. }
  399. return false;
  400. }
  401. /**
  402. * Shortcode support for use anywhere that support WP Shortcodes
  403. *
  404. * @param array $tags An associative array of shortcode properties
  405. * @param string $content A string that represents a template override
  406. *
  407. * @return string
  408. * @since 1.6.7
  409. */
  410. function pods_shortcode ( $tags, $content = null ) {
  411. $defaults = array(
  412. 'name' => null,
  413. 'id' => null,
  414. 'slug' => null,
  415. 'select' => null,
  416. 'order' => null,
  417. 'orderby' => null,
  418. 'limit' => null,
  419. 'where' => null,
  420. 'having' => null,
  421. 'groupby' => null,
  422. 'search' => true,
  423. 'pagination' => true,
  424. 'page' => null,
  425. 'filters' => false,
  426. 'filters_label' => null,
  427. 'filters_location' => 'before',
  428. 'pagination' => false,
  429. 'pagination_label' => null,
  430. 'pagination_location' => 'after',
  431. 'field' => null,
  432. 'col' => null,
  433. 'template' => null,
  434. 'helper' => null,
  435. 'form' => null,
  436. 'fields' => null,
  437. 'label' => null,
  438. 'thank_you' => null,
  439. 'view' => null,
  440. 'cache_mode' => 'none',
  441. 'expires' => 0
  442. );
  443. if ( !empty( $tags ) )
  444. $tags = array_merge( $defaults, $tags );
  445. else
  446. $tags = $defaults;
  447. $tags = apply_filters( 'pods_shortcode', $tags );
  448. if ( empty( $content ) )
  449. $content = null;
  450. if ( 0 < strlen( $tags[ 'view' ] ) )
  451. return pods_view( $tags[ 'view' ], null, (int) $tags[ 'expires' ], $tags[ 'cache_mode' ] );
  452. if ( empty( $tags[ 'name' ] ) ) {
  453. if ( in_the_loop() || is_singular() ) {
  454. $pod = pods( get_post_type(), get_the_ID(), false );
  455. if ( !empty( $pod ) ) {
  456. $tags[ 'name' ] = get_post_type();
  457. $id = $tags[ 'id' ] = get_the_ID();
  458. }
  459. }
  460. if ( empty( $tags[ 'name' ] ) )
  461. return '<p>Please provide a Pod name</p>';
  462. }
  463. if ( !empty( $tags[ 'col' ] ) ) {
  464. $tags[ 'field' ] = $tags[ 'col' ];
  465. unset( $tags[ 'col' ] );
  466. }
  467. if ( !empty( $tags[ 'order' ] ) ) {
  468. $tags[ 'orderby' ] = $tags[ 'order' ];
  469. unset( $tags[ 'order' ] );
  470. }
  471. if ( empty( $content ) && empty( $tags[ 'template' ] ) && empty( $tags[ 'field' ] ) && empty( $tags[ 'form' ] ) ) {
  472. return '<p>Please provide either a template or field name</p>';
  473. }
  474. if ( !isset( $id ) ) {
  475. // id > slug (if both exist)
  476. $id = empty( $tags[ 'slug' ] ) ? null : pods_evaluate_tags( $tags[ 'slug' ] );
  477. if ( !empty ( $tags[ 'id' ] ) ) {
  478. $id = $tags[ 'id' ];
  479. if ( is_numeric( $id ) )
  480. $id = absint( $id );
  481. }
  482. }
  483. if ( !isset( $pod ) )
  484. $pod = pods( $tags[ 'name' ], $id );
  485. $found = 0;
  486. if ( !empty( $tags[ 'form' ] ) )
  487. return $pod->form( $tags[ 'fields' ], $tags[ 'label' ], $tags[ 'thank_you' ] );
  488. elseif ( empty( $id ) ) {
  489. $params = array();
  490. if ( 0 < strlen( $tags[ 'orderby' ] ) )
  491. $params[ 'orderby' ] = $tags[ 'orderby' ];
  492. if ( !empty( $tags[ 'limit' ] ) )
  493. $params[ 'limit' ] = $tags[ 'limit' ];
  494. if ( 0 < strlen( $tags[ 'where' ] ) )
  495. $params[ 'where' ] = pods_evaluate_tags( $tags[ 'where' ] );
  496. if ( 0 < strlen( $tags[ 'having' ] ) )
  497. $params[ 'having' ] = pods_evaluate_tags( $tags[ 'having' ] );
  498. if ( 0 < strlen( $tags[ 'groupby' ] ) )
  499. $params[ 'groupby' ] = $tags[ 'groupby' ];
  500. if ( 0 < strlen( $tags[ 'select' ] ) )
  501. $params[ 'select' ] = $tags[ 'select' ];
  502. if ( empty( $tags[ 'search' ] ) )
  503. $params[ 'search' ] = false;
  504. if ( 0 < absint( $tags[ 'page' ] ) )
  505. $params[ 'page' ] = absint( $tags[ 'page' ] );
  506. if ( empty( $tags[ 'pagination' ] ) )
  507. $params[ 'pagination' ] = false;
  508. if ( !empty( $tags[ 'cache_mode' ] ) && 'none' != $tags[ 'cache_mode' ] ) {
  509. $params[ 'cache_mode' ] = $tags[ 'cache_mode' ];
  510. $params[ 'expires' ] = (int) $tags[ 'expires' ];
  511. }
  512. $params = apply_filters( 'pods_shortcode_findrecords_params', $params );
  513. $pod->find( $params );
  514. $found = $pod->total();
  515. }
  516. elseif ( !empty( $tags[ 'field' ] ) ) {
  517. if ( empty( $tags[ 'helper' ] ) )
  518. $val = $pod->display( $tags[ 'field' ] );
  519. else
  520. $val = $pod->helper( $tags[ 'helper' ], $pod->field( $tags[ 'field' ] ), $tags[ 'field' ] );
  521. return $val;
  522. }
  523. ob_start();
  524. if ( empty( $id ) && false !== $tags[ 'filters' ] && 'before' == $tags[ 'filters_location' ] )
  525. echo $pod->filters( $tags[ 'filters' ], $tags[ 'filters_label' ] );
  526. if ( empty( $id ) && 0 < $found && false !== $tags[ 'pagination' ] && 'before' == $tags[ 'pagination_location' ] )
  527. echo $pod->pagination( $tags[ 'pagination_label' ] );
  528. echo $pod->template( $tags[ 'template' ], $content );
  529. if ( empty( $id ) && 0 < $found && false !== $tags[ 'pagination' ] && 'after' == $tags[ 'pagination_location' ] )
  530. echo $pod->pagination( $tags[ 'pagination_label' ] );
  531. if ( empty( $id ) && false !== $tags[ 'filters' ] && 'after' == $tags[ 'filters_location' ] )
  532. echo $pod->filters( $tags[ 'filters' ], $tags[ 'filters_label' ] );
  533. return ob_get_clean();
  534. }
  535. /**
  536. * Form Shortcode support for use anywhere that support WP Shortcodes
  537. *
  538. * @param array $tags An associative array of shortcode properties
  539. * @param string $content Not currently used
  540. *
  541. * @return string
  542. * @since 2.3
  543. */
  544. function pods_shortcode_form ( $tags, $content = null ) {
  545. $tags[ 'form' ] = 1;
  546. return pods_shortcode( $tags );
  547. }
  548. /**
  549. * Check if Pods is compatible with WP / PHP / MySQL or not
  550. *
  551. * @param string $wp (optional) Wordpress version
  552. * @param string $php (optional) PHP Version
  553. * @param string $mysql (optional) MySQL Version
  554. *
  555. * @return bool
  556. *
  557. * @since 1.10
  558. */
  559. function pods_compatible ( $wp = null, $php = null, $mysql = null ) {
  560. global $wp_version, $wpdb;
  561. if ( null === $wp )
  562. $wp = $wp_version;
  563. if ( null === $php )
  564. $php = phpversion();
  565. if ( null === $mysql )
  566. $mysql = $wpdb->db_version();
  567. $compatible = true;
  568. if ( !version_compare( $wp, PODS_WP_VERSION_MINIMUM, '>=' ) ) {
  569. $compatible = false;
  570. add_action( 'admin_notices', 'pods_version_notice_wp' );
  571. if ( !function_exists( 'pods_version_notice_php' ) ) {
  572. function pods_version_notice_wp () {
  573. ?>
  574. <div class="error fade">
  575. <p><strong><?php _e( 'NOTICE', 'pods' ); ?>:</strong> Pods <?php echo PODS_VERSION_FULL; ?> <?php _e( 'requires a minimum of', 'pods' ); ?>
  576. <strong>WordPress <?php echo PODS_WP_VERSION_MINIMUM; ?>+</strong> <?php _e( 'to function. You are currently running', 'pods' ); ?>
  577. <strong>WordPress <?php echo get_bloginfo( "version" ); ?></strong> - <?php _e( 'Please upgrade your WordPress to continue.', 'pods' ); ?>
  578. </p>
  579. </div>
  580. <?php
  581. }
  582. }
  583. }
  584. if ( !version_compare( $php, PODS_PHP_VERSION_MINIMUM, '>=' ) ) {
  585. $compatible = false;
  586. add_action( 'admin_notices', 'pods_version_notice_php' );
  587. if ( !function_exists( 'pods_version_notice_php' ) ) {
  588. function pods_version_notice_php () {
  589. ?>
  590. <div class="error fade">
  591. <p><strong><?php _e( 'NOTICE', 'pods' ); ?>:</strong> Pods <?php echo PODS_VERSION_FULL; ?> <?php _e( 'requires a minimum of', 'pods' ); ?>
  592. <strong>PHP <?php echo PODS_PHP_VERSION_MINIMUM; ?>+</strong> <?php _e( 'to function. You are currently running', 'pods' ); ?>
  593. <strong>PHP <?php echo phpversion(); ?></strong> - <?php _e( 'Please upgrade (or have your Hosting Provider upgrade it for you) your PHP version to continue.', 'pods' ); ?>
  594. </p>
  595. </div>
  596. <?php
  597. }
  598. }
  599. }
  600. if ( !@version_compare( $mysql, PODS_MYSQL_VERSION_MINIMUM, '>=' ) ) {
  601. $compatible = false;
  602. add_action( 'admin_notices', 'pods_version_notice_mysql' );
  603. if ( !function_exists( 'pods_version_notice_mysql' ) ) {
  604. function pods_version_notice_mysql () {
  605. global $wpdb;
  606. $mysql = $wpdb->db_version();
  607. ?>
  608. <div class="error fade">
  609. <p><strong><?php _e( 'NOTICE', 'pods' ); ?>:</strong> Pods <?php echo PODS_VERSION_FULL; ?> <?php _e( 'requires a minimum of', 'pods' ); ?>
  610. <strong>MySQL <?php echo PODS_MYSQL_VERSION_MINIMUM; ?>+</strong> <?php _e( 'to function. You are currently running', 'pods' ); ?>
  611. <strong>MySQL <?php echo $mysql; ?></strong> - <?php _e( 'Please upgrade (or have your Hosting Provider upgrade it for you) your MySQL version to continue.', 'pods' ); ?>
  612. </p>
  613. </div>
  614. <?php
  615. }
  616. }
  617. }
  618. return $compatible;
  619. }
  620. /**
  621. * Check if a Function exists or File exists in Theme / Child Theme
  622. *
  623. * @param string $function_or_file Function or file name to look for.
  624. * @param string $function_name (optional) Function name to look for.
  625. * @param string $file_dir (optional) Drectory to look into
  626. * @param string $file_name (optional) Filename to look for
  627. *
  628. * @return mixed
  629. *
  630. * @since 1.12
  631. */
  632. function pods_function_or_file ( $function_or_file, $function_name = null, $file_dir = null, $file_name = null ) {
  633. $found = false;
  634. $function_or_file = (string) $function_or_file;
  635. if ( false !== $function_name ) {
  636. if ( null === $function_name )
  637. $function_name = $function_or_file;
  638. $function_name = str_replace( array(
  639. '__',
  640. '__',
  641. '__'
  642. ), '_', preg_replace( '/[^a-z^A-Z^_][^a-z^A-Z^0-9^_]*/', '_', (string) $function_name ) );
  643. if ( function_exists( 'pods_custom_' . $function_name ) )
  644. $found = array( 'function' => 'pods_custom_' . $function_name );
  645. elseif ( function_exists( $function_name ) )
  646. $found = array( 'function' => $function_name );
  647. }
  648. if ( false !== $file_name && false === $found ) {
  649. if ( null === $file_name )
  650. $file_name = $function_or_file;
  651. $file_name = str_replace( array(
  652. '__',
  653. '__',
  654. '__'
  655. ), '_', preg_replace( '/[^a-z^A-Z^0-9^_]*/', '_', (string) $file_name ) ) . '.php';
  656. $custom_location = apply_filters( 'pods_file_directory', null, $function_or_file, $function_name, $file_dir, $file_name );
  657. if ( defined( 'PODS_FILE_DIRECTORY' ) && false !== PODS_FILE_DIRECTORY )
  658. $custom_location = PODS_FILE_DIRECTORY;
  659. if ( !empty( $custom_location ) && locate_template( trim( $custom_location, '/' ) . '/' . ( !empty( $file_dir ) ? $file_dir . '/' : '' ) . $file_name ) )
  660. $found = array( 'file' => trim( $custom_location, '/' ) . '/' . ( !empty( $file_dir ) ? $file_dir . '/' : '' ) . $file_name );
  661. elseif ( locate_template( 'pods/' . ( !empty( $file_dir ) ? $file_dir . '/' : '' ) . $file_name ) )
  662. $found = array( 'file' => 'pods/' . ( !empty( $file_dir ) ? $file_dir . '/' : '' ) . $file_name );
  663. elseif ( locate_template( 'pods-' . ( !empty( $file_dir ) ? $file_dir . '-' : '' ) . $file_name ) )
  664. $found = array( 'file' => 'pods-' . ( !empty( $file_dir ) ? $file_dir . '-' : '' ) . $file_name );
  665. elseif ( locate_template( 'pods/' . ( !empty( $file_dir ) ? $file_dir . '-' : '' ) . $file_name ) )
  666. $found = array( 'file' => 'pods/' . ( !empty( $file_dir ) ? $file_dir . '-' : '' ) . $file_name );
  667. }
  668. return apply_filters( 'pods_function_or_file', $found, $function_or_file, $function_name, $file_name );
  669. }
  670. /**
  671. * Redirects to another page.
  672. *
  673. * @param string $location The path to redirect to
  674. * @param int $status Status code to use
  675. *
  676. * @since 2.0.0
  677. */
  678. function pods_redirect ( $location, $status = 302 ) {
  679. if ( !headers_sent() ) {
  680. wp_redirect( $location, $status );
  681. die();
  682. }
  683. else {
  684. die( '<script type="text/javascript">'
  685. . 'document.location = "' . str_replace( '&amp;', '&', esc_js( $location ) ) . '";'
  686. . '</script>' );
  687. }
  688. }
  689. /**
  690. * Check if a user has permission to be doing something based on standard permission options
  691. *
  692. * @param array $options
  693. *
  694. * @since 2.0.5
  695. */
  696. function pods_permission ( $options ) {
  697. $permission = false;
  698. if ( isset( $options[ 'options' ] ) )
  699. $options = $options[ 'options' ];
  700. if ( is_user_logged_in() && ( is_super_admin() || current_user_can( 'delete_users' ) || current_user_can( 'manage_options' ) ) )
  701. $permission = true;
  702. elseif ( 1 == pods_var( 'restrict_capability', $options, 0 ) ) {
  703. $capabilities = explode( ',', pods_var( 'capability_allowed', $options ) );
  704. $capabilities = array_unique( array_filter( $capabilities ) );
  705. foreach( $capabilities as $capability ) {
  706. $must_have_capabilities = explode( '&&', $capability );
  707. $must_have_capabilities = array_unique( array_filter( $must_have_capabilities ) );
  708. $must_have_permission = true;
  709. foreach ( $must_have_capabilities as $must_have_capability ) {
  710. if ( !current_user_can( $must_have_capability ) ) {
  711. $must_have_permission = false;
  712. break;
  713. }
  714. }
  715. if ( $must_have_permission ) {
  716. $permission = true;
  717. break;
  718. }
  719. }
  720. }
  721. elseif ( 0 == pods_var( 'admin_only', $options, 0 ) )
  722. $permission = true;
  723. return $permission;
  724. }
  725. /**
  726. * Get a field value from a Pod
  727. *
  728. * @param string $pod The pod name
  729. * @param mixed $id (optional) The ID or slug, to load a single record; Provide array of $params to run 'find'
  730. * @param string|array $name The field name, or an associative array of parameters
  731. * @param boolean $single (optional) For tableless fields, to return the whole array or the just the first item
  732. *
  733. * @return mixed Field value
  734. */
  735. function pods_field ( $pod, $id = false, $name = null, $single = false ) {
  736. // allow for pods_field( 'field_name' );
  737. if ( null === $name ) {
  738. $name = $pod;
  739. $single = (boolean) $id;
  740. $pod = get_post_type();
  741. $id = get_the_ID();
  742. }
  743. return pods( $pod, $id )->field( $name, $single );
  744. }
  745. /**
  746. * Get a field display value from a Pod
  747. *
  748. * @param string $pod The pod name
  749. * @param mixed $id (optional) The ID or slug, to load a single record; Provide array of $params to run 'find'
  750. * @param string|array $name The field name, or an associative array of parameters
  751. * @param boolean $single (optional) For tableless fields, to return the whole array or the just the first item
  752. *
  753. * @return mixed Field value
  754. */
  755. function pods_field_display ( $pod, $id = false, $name = null, $single = false ) {
  756. // allow for pods_field_display( 'field_name' );
  757. if ( null === $name ) {
  758. $name = $pod;
  759. $single = (boolean) $id;
  760. $pod = get_post_type();
  761. $id = get_the_ID();
  762. }
  763. return pods( $pod, $id )->display( $name, $single );
  764. }
  765. /**
  766. * Get a field raw value from a Pod
  767. *
  768. * @param string $pod The pod name
  769. * @param mixed $id (optional) The ID or slug, to load a single record; Provide array of $params to run 'find'
  770. * @param string|array $name The field name, or an associative array of parameters
  771. * @param boolean $single (optional) For tableless fields, to return the whole array or the just the first item
  772. *
  773. * @return mixed Field value
  774. */
  775. function pods_field_raw ( $pod, $id = false, $name = null, $single = false ) {
  776. // allow for pods_field_raw( 'field_name' );
  777. if ( null === $name ) {
  778. $name = $pod;
  779. $single = (boolean) $id;
  780. $pod = get_post_type();
  781. $id = get_the_ID();
  782. }
  783. return pods( $pod, $id )->raw( $name, $single );
  784. }
  785. /**
  786. * Set a cached value
  787. *
  788. * @see PodsView::set
  789. *
  790. * @param string $key Key for the cache
  791. * @param mixed $value Value to add to the cache
  792. * @param int $expires (optional) Time in seconds for the cache to expire, if 0 caching is disabled.
  793. * @param string $cache_mode (optional) Decides the caching method to use for the view.
  794. * @param string $group Key for the group
  795. *
  796. * @return bool|mixed|null|string|void
  797. *
  798. * @since 2.0.0
  799. */
  800. function pods_view_set ( $key, $value, $expires = 0, $cache_mode = 'cache', $group = '' ) {
  801. require_once( PODS_DIR . 'classes/PodsView.php' );
  802. return PodsView::set( $key, $value, $expires, $cache_mode, $group );
  803. }
  804. /**
  805. * Get a cached value
  806. *
  807. * @see PodsView::get
  808. *
  809. * @param string $key Key for the cache
  810. * @param string $cache_mode (optional) Decides the caching method to use for the view.
  811. * @param string $group Key for the group
  812. *
  813. * @return bool|mixed|null|void
  814. *
  815. * @since 2.0.0
  816. */
  817. function pods_view_get ( $key, $cache_mode = 'cache', $group = '' ) {
  818. require_once( PODS_DIR . 'classes/PodsView.php' );
  819. return PodsView::get( $key, $cache_mode, $group );
  820. }
  821. /**
  822. * Clear a cached value
  823. *
  824. * @see PodsView::clear
  825. *
  826. * @param string|bool $key Key for the cache
  827. * @param string $cache_mode (optional) Decides the caching method to use for the view.
  828. * @param string $group Key for the group
  829. *
  830. * @return bool
  831. *
  832. * @since 2.0.0
  833. */
  834. function pods_view_clear ( $key = true, $cache_mode = 'cache', $group = '' ) {
  835. require_once( PODS_DIR . 'classes/PodsView.php' );
  836. return PodsView::clear( $key, $cache_mode, $group );
  837. }
  838. /**
  839. * Set a cached value
  840. *
  841. * @see PodsView::set
  842. *
  843. * @param string $key Key for the cache
  844. * @param mixed $value Value to add to the cache
  845. * @param string $group Key for the group
  846. * @param int $expires (optional) Time in seconds for the cache to expire, if 0 caching is disabled.
  847. *
  848. * @return bool|mixed|null|string|void
  849. *
  850. * @since 2.0.0
  851. */
  852. function pods_cache_set ( $key, $value, $group = '', $expires = 0) {
  853. return pods_view_set( $key, $value, $expires, 'cache', $group );
  854. }
  855. /**
  856. * Clear a cached value
  857. *
  858. * @see PodsView::clear
  859. *
  860. * @param string $key Key for the cache
  861. * @param string $group Key for the group
  862. *
  863. * @return bool
  864. *
  865. * @since 2.0.0
  866. */
  867. function pods_cache_get ( $key, $group = '' ) {
  868. return pods_view_get( $key, 'cache', $group );
  869. }
  870. /**
  871. * Get a cached value
  872. *
  873. * @see PodsView::get
  874. *
  875. * @param string|bool $key Key for the cache
  876. * @param string $group Key for the group
  877. *
  878. * @return bool|mixed|null|void
  879. *
  880. * @since 2.0.0
  881. */
  882. function pods_cache_clear ( $key = true, $group = '' ) {
  883. return pods_view_clear( $key, 'cache', $group );
  884. }
  885. /**
  886. * Set a cached value
  887. *
  888. * @see PodsView::set
  889. *
  890. * @param string $key Key for the cache
  891. * @param mixed $value Value to add to the cache
  892. * @param int $expires (optional) Time in seconds for the cache to expire, if 0 caching is disabled.
  893. *
  894. * @return bool|mixed|null|string|void
  895. *
  896. * @since 2.0.0
  897. */
  898. function pods_transient_set ( $key, $value, $expires = 0 ) {
  899. return pods_view_set( $key, $value, $expires, 'transient' );
  900. }
  901. /**
  902. * Get a cached value
  903. *
  904. * @see PodsView::get
  905. *
  906. * @param string $key Key for the cache
  907. *
  908. * @return bool|mixed|null|void
  909. *
  910. * @since 2.0.0
  911. */
  912. function pods_transient_get ( $key ) {
  913. return pods_view_get( $key, 'transient' );
  914. }
  915. /**
  916. * Clear a cached value
  917. *
  918. * @see PodsView::clear
  919. *
  920. * @param string|bool $key Key for the cache
  921. *
  922. * @return bool
  923. *
  924. * @since 2.0.0
  925. */
  926. function pods_transient_clear ( $key = true ) {
  927. return pods_view_clear( $key, 'transient' );
  928. }
  929. /**
  930. * Add a new Pod outside of the DB
  931. *
  932. * @see PodsMeta::register
  933. *
  934. * @param string $type The pod type ('post_type', 'taxonomy', 'media', 'user', 'comment')
  935. * @param string $name The pod name
  936. * @param array $object (optional) Pod array, including any 'fields' arrays
  937. *
  938. * @return array|boolean Pod data or false if unsuccessful
  939. * @since 2.1.0
  940. */
  941. function pods_register_type ( $type, $name, $object = null ) {
  942. if ( empty( $object ) )
  943. $object = array();
  944. if ( !empty( $name ) )
  945. $object[ 'name' ] = $name;
  946. return pods_meta()->register( $type, $object );
  947. }
  948. /**
  949. * Add a new Pod field outside of the DB
  950. *
  951. * @see PodsMeta::register_field
  952. *
  953. * @param string $pod The pod name
  954. * @param string $name The name of the Pod
  955. * @param array $object (optional) Pod array, including any 'fields' arrays
  956. *
  957. * @return array|boolean Field data or false if unsuccessful
  958. * @since 2.1.0
  959. */
  960. function pods_register_field ( $pod, $name, $field = null ) {
  961. if ( empty( $field ) )
  962. $field = array();
  963. if ( !empty( $name ) )
  964. $field[ 'name' ] = $name;
  965. return pods_meta()->register_field( $pod, $field );
  966. }
  967. /**
  968. * Add a new Pod field type
  969. *
  970. * @see PodsForm::register_field_type
  971. *
  972. * @param string $type The new field type identifier
  973. * @param string $file The new field type class file location
  974. *
  975. * @return array Field type array
  976. * @since 2.3.0
  977. */
  978. function pods_register_field_type ( $type, $file = null ) {
  979. return PodsForm::register_field_type( $type, $file );
  980. }
  981. /**
  982. * Register a related object
  983. *
  984. * @param string $name Object name
  985. * @param string $label Object label
  986. * @param array $options Object options
  987. *
  988. * @return array|boolean Object array or false if unsuccessful
  989. * @since 2.3.0
  990. */
  991. function pods_register_related_object ( $name, $label, $options = null ) {
  992. return PodsForm::field_method( 'pick', 'register_related_object', $name, $label, $options );
  993. }
  994. /**
  995. * Add a meta group of fields to add/edit forms
  996. *
  997. * @see PodsMeta::group_add
  998. *
  999. * @param string|array $pod The pod or type of element to attach the group to.f
  1000. * @param string $label Title of the edit screen section, visible to user.
  1001. * @param string|array $fields Either a comma separated list of text fields or an associative array containing field information.
  1002. * @param string $context (optional) The part of the page where the edit screen section should be shown ('normal', 'advanced', or 'side').
  1003. * @param string $priority (optional) The priority within the context where the boxes should show ('high', 'core', 'default' or 'low').
  1004. * @param string $type (optional) Type of the post to attach to.
  1005. *
  1006. * @since 2.0.0
  1007. * @link http://podsframework.org/docs/pods-group-add/
  1008. */
  1009. function pods_group_add ( $pod, $label, $fields, $context = 'normal', $priority = 'default', $type = null ) {
  1010. if ( !is_array( $pod ) && null !== $type ) {
  1011. $pod = array(
  1012. 'name' => $pod,
  1013. 'type' => $type
  1014. );
  1015. }
  1016. pods_meta()->group_add( $pod, $label, $fields, $context, $priority );
  1017. }
  1018. /**
  1019. * Check if a plugin is active on non-admin pages (is_plugin_active() only available in admin)
  1020. *
  1021. * @param string $plugin Plugin name.
  1022. *
  1023. * @return bool
  1024. *
  1025. * @since 2.0.0
  1026. */
  1027. function pods_is_plugin_active ( $plugin ) {
  1028. if ( function_exists( 'is_plugin_active' ) )
  1029. return is_plugin_active( $plugin );
  1030. $active_plugins = (array) get_option( 'active_plugins', array() );
  1031. if ( in_array( $plugin, $active_plugins ) )
  1032. return true;
  1033. return false;
  1034. }
  1035. /**
  1036. * Check if Pods no conflict is on or not
  1037. *
  1038. * @param string $object_type
  1039. *
  1040. * @return bool
  1041. */
  1042. function pods_no_conflict_check ( $object_type = 'post' ) {
  1043. if ( 'post_type' == $object_type )
  1044. $object_type = 'post';
  1045. if ( !empty( PodsInit::$no_conflict ) && isset( PodsInit::$no_conflict[ $object_type ] ) && !empty( PodsInit::$no_conflict[ $object_type ] ) )
  1046. return true;
  1047. return false;
  1048. }
  1049. /**
  1050. * Turn off conflicting / recursive actions for an object type that Pods hooks into
  1051. *
  1052. * @param string $object_type
  1053. *
  1054. * @return bool
  1055. */
  1056. function pods_no_conflict_on ( $object_type = 'post' ) {
  1057. if ( 'post_type' == $object_type )
  1058. $object_type = 'post';
  1059. if ( !empty( PodsInit::$no_conflict ) && isset( PodsInit::$no_conflict[ $object_type ] ) && !empty( PodsInit::$no_conflict[ $object_type ] ) )
  1060. return true;
  1061. if ( !is_object( PodsInit::$meta ) )
  1062. return false;
  1063. $no_conflict = array();
  1064. // Filters = Usually get/update/delete meta functions
  1065. // Actions = Usually insert/update/save/delete object functions
  1066. if ( 'post' == $object_type ) {
  1067. $no_conflict[ 'filter' ] = array(
  1068. array( 'get_post_metadata', array( PodsInit::$meta, 'get_post_meta' ), 10, 4 ),
  1069. array( 'add_post_metadata', array( PodsInit::$meta, 'add_post_meta' ), 10, 5 ),
  1070. array( 'update_post_metadata', array( PodsInit::$meta, 'update_post_meta' ), 10, 5 ),
  1071. array( 'delete_post_metadata', array( PodsInit::$meta, 'delete_post_meta' ), 10, 5 )
  1072. );
  1073. $no_conflict[ 'action' ] = array(
  1074. array( 'save_post', array( PodsInit::$meta, 'save_post' ), 10, 2 )
  1075. );
  1076. }
  1077. elseif ( 'taxonomy' == $object_type ) {
  1078. $no_conflict[ 'filter' ] = array();
  1079. $no_conflict[ 'action' ] = array(
  1080. array( 'edit_term', array( PodsInit::$meta, 'save_taxonomy' ), 10, 3 ),
  1081. array( 'create_term', array( PodsInit::$meta, 'save_taxonomy' ), 10, 3 )
  1082. );
  1083. }
  1084. elseif ( 'media' == $object_type ) {
  1085. $no_conflict[ 'filter' ] = array(
  1086. array( 'wp_update_attachment_metadata', array( PodsInit::$meta, 'save_media' ), 10, 2 )
  1087. );
  1088. $no_conflict[ 'action' ] = array();
  1089. }
  1090. elseif ( 'user' == $object_type ) {
  1091. $no_conflict[ 'filter' ] = array(
  1092. array( 'get_user_metadata', array( PodsInit::$meta, 'get_user_meta' ), 10, 4 ),
  1093. array( 'add_user_metadata', array( PodsInit::$meta, 'add_user_meta' ), 10, 5 ),
  1094. array( 'update_user_metadata', array( PodsInit::$meta, 'update_user_meta' ), 10, 5 ),
  1095. array( 'delete_user_metadata', array( PodsInit::$meta, 'delete_user_meta' ), 10, 5 )
  1096. );
  1097. $no_conflict[ 'action' ] = array(
  1098. array( 'personal_options_update', array( PodsInit::$meta, 'save_user' ) ),
  1099. array( 'edit_user_profile_update', array( PodsInit::$meta, 'save_user' ) )
  1100. );
  1101. }
  1102. elseif ( 'comment' == $object_type ) {
  1103. $no_conflict[ 'filter' ] = array(
  1104. array( 'get_comment_metadata', array( PodsInit::$meta, 'get_comment_meta' ), 10, 4 ),
  1105. array( 'add_comment_metadata', array( PodsInit::$meta, 'add_comment_meta' ), 10, 5 ),
  1106. array( 'update_comment_metadata', array( PodsInit::$meta, 'update_comment_meta' ), 10, 5 ),
  1107. array( 'delete_comment_metadata', array( PodsInit::$meta, 'delete_comment_meta' ), 10, 5 )
  1108. );
  1109. $no_conflict[ 'action' ] = array(
  1110. array( 'pre_comment_approved', array( PodsInit::$meta, 'validate_comment' ), 10, 2 ),
  1111. array( 'comment_post', array( PodsInit::$meta, 'save_comment' ) ),
  1112. array( 'edit_comment', array( PodsInit::$meta, 'save_comment' ) )
  1113. );
  1114. }
  1115. $conflicted = false;
  1116. foreach ( $no_conflict as $action_filter => $conflicts ) {
  1117. foreach ( $conflicts as $args ) {
  1118. if ( call_user_func_array( 'has_' . $action_filter, $args ) ) {
  1119. call_user_func_array( 'remove_' . $action_filter, $args );
  1120. $conflicted = true;
  1121. }
  1122. }
  1123. }
  1124. if ( $conflicted ) {
  1125. PodsInit::$no_conflict[ $object_type ] = $no_conflict;
  1126. return true;
  1127. }
  1128. return false;
  1129. }
  1130. /**
  1131. * Turn on actions after running code during pods_conflict
  1132. *
  1133. * @param string $object_type
  1134. *
  1135. * @return bool
  1136. */
  1137. function pods_no_conflict_off ( $object_type = 'post' ) {
  1138. if ( 'post_type' == $object_type )
  1139. $object_type = 'post';
  1140. if ( empty( PodsInit::$no_conflict ) || !isset( PodsInit::$no_conflict[ $object_type ] ) || empty( PodsInit::$no_conflict[ $object_type ] ) )
  1141. return false;
  1142. if ( !is_object( PodsInit::$meta ) )
  1143. return false;
  1144. $no_conflict = PodsInit::$no_conflict[ $object_type ];
  1145. $conflicted = false;
  1146. foreach ( $no_conflict as $action_filter => $conflicts ) {
  1147. foreach ( $conflicts as $args ) {
  1148. if ( !call_user_func_array( 'has_' . $action_filter, $args ) ) {
  1149. call_user_func_array( 'add_' . $action_filter, $args );
  1150. $conflicted = true;
  1151. }
  1152. }
  1153. }
  1154. if ( $conflicted ) {
  1155. unset( PodsInit::$no_conflict[ $object_type ] );
  1156. return true;
  1157. }
  1158. return false;
  1159. }