/inc/utility.php

  1. <?php 
  2. /** 
  3. * Custom Post Type UI Utility Code. 
  4. * 
  5. * @package CPTUI 
  6. * @subpackage Utility 
  7. * @author WebDevStudios 
  8. * @since 1.3.0 
  9. */ 
  10.  
  11. // Exit if accessed directly. 
  12. if ( ! defined( 'ABSPATH' ) ) { 
  13. exit; 
  14.  
  15. /** 
  16. * Edit links that appear on installed plugins list page, for our plugin. 
  17. * 
  18. * @since 1.0.0 
  19. * 
  20. * @internal 
  21. * 
  22. * @param array $links Array of links to display below our plugin listing. 
  23. * @return array Amended array of links. 
  24. */ 
  25. function cptui_edit_plugin_list_links( $links ) { 
  26. // We shouldn't encourage editing our plugin directly. 
  27. unset( $links['edit'] ); 
  28.  
  29. // Add our custom links to the returned array value. 
  30. return array_merge( array( 
  31. '<a href="' . admin_url( 'admin.php?page=cptui_main_menu' ) . '">' . __( 'About', 'custom-post-type-ui' ) . '</a>',  
  32. '<a href="' . admin_url( 'admin.php?page=cptui_support' ) . '">' . __( 'Help', 'custom-post-type-ui' ) . '</a>',  
  33. ), $links ); 
  34. add_filter( 'plugin_action_links_' . plugin_basename( dirname( dirname( __FILE__ ) ) ) . '/custom-post-type-ui.php', 'cptui_edit_plugin_list_links' ); 
  35.  
  36. /** 
  37. * Returns SVG icon for custom menu icon 
  38. * 
  39. * @since 1.2.0 
  40. * 
  41. * @return string 
  42. */ 
  43. function cptui_menu_icon() { 
  44. return 'dashicons-forms'; 
  45.  
  46. /** 
  47. * Return boolean status depending on passed in value. 
  48. * 
  49. * @since 0.5.0 
  50. * 
  51. * @param mixed $bool_text text to compare to typical boolean values. 
  52. * @return bool Which bool value the passed in value was. 
  53. */ 
  54. function get_disp_boolean( $bool_text ) { 
  55. $bool_text = (string) $bool_text; 
  56. if ( empty( $bool_text ) || '0' === $bool_text || 'false' === $bool_text ) { 
  57. return false; 
  58.  
  59. return true; 
  60.  
  61. /** 
  62. * Return string versions of boolean values. 
  63. * 
  64. * @since 0.1.0 
  65. * 
  66. * @param string $bool_text String boolean value. 
  67. * @return string standardized boolean text. 
  68. */ 
  69. function disp_boolean( $bool_text ) { 
  70. $bool_text = (string) $bool_text; 
  71. if ( empty( $bool_text ) || '0' === $bool_text || 'false' === $bool_text ) { 
  72. return 'false'; 
  73.  
  74. return 'true'; 
  75.  
  76. /** 
  77. * Display footer links and plugin credits. 
  78. * 
  79. * @since 0.3.0 
  80. * 
  81. * @internal 
  82. * 
  83. * @param string $original Original footer content. Optional. Default empty string. 
  84. * @return string $value HTML for footer. 
  85. */ 
  86. function cptui_footer( $original = '' ) { 
  87.  
  88. $screen = get_current_screen(); 
  89.  
  90. if ( ! is_object( $screen ) || 'cptui_main_menu' !== $screen->parent_base ) { 
  91. return $original; 
  92.  
  93. return sprintf( 
  94. __( '%s version %s by %s', 'custom-post-type-ui' ),  
  95. __( 'Custom Post Type UI', 'custom-post-type-ui' ),  
  96. CPTUI_VERSION,  
  97. '<a href="https://webdevstudios.com" target="_blank">WebDevStudios</a>' 
  98. ) . ' - ' . 
  99. sprintf( 
  100. '<a href="http://wordpress.org/support/plugin/custom-post-type-ui" target="_blank">%s</a>',  
  101. __( 'Support forums', 'custom-post-type-ui' ) 
  102. ) . ' - ' . 
  103. __( 'Follow on Twitter:', 'custom-post-type-ui' ) . 
  104. sprintf( 
  105. ' %s',  
  106. '<a href="https://twitter.com/webdevstudios" target="_blank">WebDevStudios</a>' 
  107. ); 
  108. add_filter( 'admin_footer_text', 'cptui_footer' ); 
  109.  
  110. /** 
  111. * Conditionally flushes rewrite rules if we have reason to. 
  112. * 
  113. * @since 1.3.0 
  114. */ 
  115. function cptui_flush_rewrite_rules() { 
  116.  
  117. if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { 
  118. return; 
  119.  
  120. /** 
  121. * Wise men say that you should not do flush_rewrite_rules on init or admin_init. Due to the nature of our plugin 
  122. * and how new post types or taxonomies can suddenly be introduced, we need to...potentially. For this,  
  123. * we rely on a short lived transient. Only 5 minutes life span. If it exists, we do a soft flush before 
  124. * deleting the transient to prevent subsequent flushes. The only times the transient gets created, is if 
  125. * post types or taxonomies are created, updated, deleted, or imported. Any other time and this condition 
  126. * should not be met. 
  127. */ 
  128. if ( 'true' === ( $flush_it = get_transient( 'cptui_flush_rewrite_rules' ) ) ) { 
  129. flush_rewrite_rules( false ); 
  130. // So we only run this once. 
  131. delete_transient( 'cptui_flush_rewrite_rules' ); 
  132. add_action( 'admin_init', 'cptui_flush_rewrite_rules' ); 
  133.  
  134. /** 
  135. * Return the current action being done within CPTUI context. 
  136. * 
  137. * @since 1.3.0 
  138. * 
  139. * @return string Current action being done by CPTUI 
  140. */ 
  141. function cptui_get_current_action() { 
  142. $current_action = ''; 
  143. if ( ! empty( $_GET ) && isset( $_GET['action'] ) ) { 
  144. $current_action .= esc_textarea( $_GET['action'] ); 
  145.  
  146. return $current_action; 
  147.  
  148. /** 
  149. * Return an array of all post type slugs from Custom Post Type UI. 
  150. * 
  151. * @since 1.3.0 
  152. * 
  153. * @return array CPTUI post type slugs. 
  154. */ 
  155. function cptui_get_post_type_slugs() { 
  156. $post_types = get_option( 'cptui_post_types' ); 
  157. if ( ! empty( $post_types ) ) { 
  158. return array_keys( $post_types ); 
  159. return array(); 
  160.  
  161. /** 
  162. * Return an array of all taxonomy slugs from Custom Post Type UI. 
  163. * 
  164. * @since 1.3.0 
  165. * 
  166. * @return array CPTUI taxonomy slugs. 
  167. */ 
  168. function cptui_get_taxonomy_slugs() { 
  169. $taxonomies = get_option( 'cptui_taxonomies' ); 
  170. if ( ! empty( $taxonomies ) ) { 
  171. return array_keys( $taxonomies ); 
  172. return array(); 
  173.  
  174. /** 
  175. * Return the appropriate admin URL depending on our context. 
  176. * 
  177. * @since 1.3.0 
  178. * 
  179. * @param string $path URL path. 
  180. * @return string 
  181. */ 
  182. function cptui_admin_url( $path ) { 
  183. if ( is_multisite() && is_network_admin() ) { 
  184. return network_admin_url( $path ); 
  185.  
  186. return admin_url( $path ); 
  187.  
  188. /** 
  189. * Construct action tag for `<form>` tag. 
  190. * 
  191. * @since 1.3.0 
  192. * 
  193. * @param object|string $ui CPTUI Admin UI instance. Optional. Default empty string. 
  194. * @return string 
  195. */ 
  196. function cptui_get_post_form_action( $ui = '' ) { 
  197. /** 
  198. * Filters the string to be used in an `action=""` attribute. 
  199. * 
  200. * @since 1.3.0 
  201. */ 
  202. return apply_filters( 'cptui_post_form_action', '', $ui ); 
  203.  
  204. /** 
  205. * Display action tag for `<form>` tag. 
  206. * 
  207. * @since 1.3.0 
  208. * 
  209. * @param object $ui CPTUI Admin UI instance. 
  210. */ 
  211. function cptui_post_form_action( $ui ) { 
  212. echo cptui_get_post_form_action( $ui ); 
  213.  
  214. /** 
  215. * Fetch our CPTUI post types option. 
  216. * 
  217. * @since 1.3.0 
  218. * 
  219. * @return mixed 
  220. */ 
  221. function cptui_get_post_type_data() { 
  222. return apply_filters( 'cptui_get_post_type_data', get_option( 'cptui_post_types', array() ), get_current_blog_id() ); 
  223.  
  224. /** 
  225. * Fetch our CPTUI taxonomies option. 
  226. * 
  227. * @since 1.3.0 
  228. * 
  229. * @return mixed 
  230. */ 
  231. function cptui_get_taxonomy_data() { 
  232. return apply_filters( 'cptui_get_taxonomy_data', get_option( 'cptui_taxonomies', array() ), get_current_blog_id() ); 
  233.  
  234. /** 
  235. * Checks if a post type is already registered. 
  236. * 
  237. * @since 1.3.0 
  238. * 
  239. * @param string $slug Post type slug to check. Optional. Default empty string. 
  240. * @param array|string $data Post type data being utilized. Optional. 
  241. * @return mixed 
  242. */ 
  243. function cptui_get_post_type_exists( $slug = '', $data = array() ) { 
  244.  
  245. /** 
  246. * Filters the boolean value for if a post type exists for 3rd parties. 
  247. * 
  248. * @since 1.3.0 
  249. * 
  250. * @param string $slug Post type slug to check. 
  251. * @param array|string $data Post type data being utilized. 
  252. */ 
  253. return apply_filters( 'cptui_get_post_type_exists', post_type_exists( $slug ), $data ); 
  254.  
  255. /** 
  256. * Displays WebDevStudios products in a sidebar on the add/edit screens for post types and taxonomies. 
  257. * 
  258. * We hope you don't mind. 
  259. * 
  260. * @since 1.3.0 
  261. * 
  262. * @internal 
  263. */ 
  264. function cptui_products_sidebar() { 
  265.  
  266. echo '<div class="wdspromos">'; 
  267.  
  268. cptui_newsletter_form(); 
  269.  
  270. $ads = cptui_get_ads(); 
  271. if ( ! empty( $ads ) ) { 
  272. foreach ( $ads as $ad ) { 
  273. $the_ad = sprintf( 
  274. '<img src="%s" alt="%s">',  
  275. esc_attr( $ad['image'] ),  
  276. esc_attr( $ad['text'] ) 
  277. ); 
  278.  
  279. // Escaping $the_ad breaks the html. 
  280. printf( 
  281. '<p><a href="%s">%s</a></p>',  
  282. esc_url( $ad['url'] ),  
  283. $the_ad 
  284. ); 
  285. printf( 
  286. '<p><a href="%s">%s</a></p>',  
  287. 'https://pluginize.com/plugins/custom-post-type-ui-extended/ref/pluginizeaff/?campaign=cptui-sidebar-remove',  
  288. esc_html__( 'Remove these ads?', 'custom-post-type-ui' ) 
  289. ); 
  290. echo '</div>'; 
  291.  
  292. add_action( 'cptui_below_post_type_tab_menu', 'cptui_products_sidebar' ); 
  293. add_action( 'cptui_below_taxonomy_tab_menu', 'cptui_products_sidebar' ); 
  294.  
  295. /** 
  296. * Outputs our newsletter signup form. 
  297. * 
  298. * @since 1.3.4 
  299. * @internal 
  300. */ 
  301. function cptui_newsletter_form() { 
  302. ?> 
  303. <!-- Begin MailChimp Signup Form --> 
  304. <link href="//cdn-images.mailchimp.com/embedcode/classic-10_7.css" rel="stylesheet" type="text/css"> 
  305. <div id="mc_embed_signup"> 
  306. <form action="//webdevstudios.us1.list-manage.com/subscribe/post?u=67169b098c99de702c897d63e&id=9cb1c7472e" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate> 
  307. <div id="mc_embed_signup_scroll"> 
  308. <p><strong><?php esc_html_e( 'Get email updates from pluginize.com about Custom Post Type UI', 'custom-post-type-ui' ); ?></strong></p> 
  309. <div class="mc-field-group"> 
  310. <label for="mce-EMAIL"><?php esc_html_e( 'Email Address', 'custom-post-type-ui' ); ?></label> 
  311. <input tabindex="-1" type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL"> 
  312. </div> 
  313. <div id="mce-responses" class="clear"> 
  314. <div class="response" id="mce-error-response" style="display:none"></div> 
  315. <div class="response" id="mce-success-response" style="display:none"></div> 
  316. </div> <!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups--> 
  317. <div style="position: absolute; left: -5000px;" aria-hidden="true"> 
  318. <input type="text" name="b_67169b098c99de702c897d63e_9cb1c7472e" tabindex="-1" value=""></div> 
  319. <div class="clear"> 
  320. <input type="submit" value="<?php esc_attr_e( 'Subscribe', 'custom-post-type-ui' ); ?>" name="subscribe" id="mc-embedded-subscribe" class="button" tabindex="-1"> 
  321. </div> 
  322. </div> 
  323. </form> 
  324. </div> 
  325. <script type='text/javascript' src='//s3.amazonaws.com/downloads.mailchimp.com/js/mc-validate.js'></script> 
  326. <script type='text/javascript'>(function ($) { 
  327. window.fnames = new Array(); 
  328. window.ftypes = new Array(); 
  329. fnames[0] = 'EMAIL'; 
  330. ftypes[0] = 'email'; 
  331. }(jQuery)); 
  332. var $mcj = jQuery.noConflict(true);</script> 
  333. <!--End mc_embed_signup--> 
  334. <?php 
  335.  
  336. /** 
  337. * Fetch all set ads to be displayed. 
  338. * 
  339. * @since 1.3.4 
  340. * 
  341. * @return array 
  342. */ 
  343. function cptui_get_ads() { 
  344.  
  345. /** 
  346. * Filters the array of ads to iterate over. 
  347. * 
  348. * Each index in the ads array should have a url index with the url to link to,  
  349. * an image index specifying an image location to load from, and a text index used 
  350. * for alt attribute text. 
  351. * 
  352. * @since 1.3.4 
  353. * 
  354. * @param array $value Array of ads to iterate over. Default empty. 
  355. */ 
  356. $ads = (array) apply_filters( 'cptui_ads', array() ); 
  357. return $ads; 
  358.  
  359. /** 
  360. * Add our default ads to the ads filter. 
  361. * 
  362. * @since 1.3.4 
  363. * 
  364. * @internal 
  365. * 
  366. * @param array $ads Array of ads set so far. Optional. 
  367. * @return array $ads Array of newly constructed ads. 
  368. */ 
  369. function cptui_default_ads( $ads = array() ) { 
  370. $ads[] = array( 
  371. 'url' => 'https://pluginize.com/plugins/custom-post-type-ui-extended/ref/pluginizeaff/?campaign=cptui-sidebar-extended',  
  372. 'image' => plugin_dir_url( dirname( __FILE__ ) ) . 'images/wds_ads/cptui-extended.png',  
  373. 'text' => 'Custom Post Type UI Extended product ad',  
  374. ); 
  375.  
  376. $ads[] = array( 
  377. 'url' => 'https://pluginize.com/plugins/instago/ref/pluginizeaff/?campaign=cptui-sidebar-ig',  
  378. 'image' => plugin_dir_url( dirname( __FILE__ ) ) . 'images/wds_ads/instago.png',  
  379. 'text' => 'InstaGo product ad',  
  380. ); 
  381.  
  382. $ads[] = array( 
  383. 'url' => 'https://pluginize.com/plugins/buddypages/ref/pluginizeaff/?campaign=cptui-sidebar-buddypages',  
  384. 'image' => plugin_dir_url( dirname( __FILE__ ) ) . 'images/wds_ads/buddypages.png',  
  385. 'text' => 'BuddyPages product ad',  
  386. ); 
  387.  
  388. $ads[] = array( 
  389. 'url' => 'https://maintainn.com/?utm_source=Pluginize-v2&utm_medium=Plugin-Sidebar&utm_campaign=CPTUI',  
  390. 'image' => plugin_dir_url( dirname( __FILE__ ) ) . 'images/wds_ads/maintainn.png',  
  391. 'text' => 'Maintainn product ad',  
  392. ); 
  393.  
  394. return $ads; 
  395. add_filter( 'cptui_ads', 'cptui_default_ads' ); 
  396.  
  397. /** 
  398. * Secondary admin notices function for use with admin_notices hook. 
  399. * 
  400. * Constructs admin notice HTML. 
  401. * 
  402. * @since 1.4.0 
  403. * 
  404. * @param string $message Message to use in admin notice. Optional. Default empty string. 
  405. * @param bool $success Whether or not a success. Optional. Default true. 
  406. * @return mixed|void 
  407. */ 
  408. function cptui_admin_notices_helper( $message = '', $success = true ) { 
  409.  
  410. $class = array(); 
  411. $class[] = ( $success ) ? 'updated' : 'error'; 
  412. $class[] = 'notice is-dismissible'; 
  413.  
  414. $messagewrapstart = '<div id="message" class="' . implode( ' ', $class ) . '"><p>'; 
  415.  
  416. $messagewrapend = '</p></div>'; 
  417.  
  418. $action = ''; 
  419.  
  420. /** 
  421. * Filters the custom admin notice for CPTUI. 
  422. * 
  423. * @since 1.0.0 
  424. * 
  425. * @param string $value Complete HTML output for notice. 
  426. * @param string $action Action whose message is being generated. 
  427. * @param string $message The message to be displayed. 
  428. * @param string $messagewrapstart Beginning wrap HTML. 
  429. * @param string $messagewrapend Ending wrap HTML. 
  430. */ 
  431. return apply_filters( 'cptui_admin_notice', $messagewrapstart . $message . $messagewrapend, $action, $message, $messagewrapstart, $messagewrapend ); 
  432.  
  433. /** 
  434. * Grab post type or taxonomy slug from $_POST global, if available. 
  435. * 
  436. * @since 1.4.0 
  437. * 
  438. * @internal 
  439. * 
  440. * @return string 
  441. */ 
  442. function cptui_get_object_from_post_global() { 
  443. if ( isset( $_POST['cpt_custom_post_type']['name'] ) ) { 
  444. return sanitize_text_field( $_POST['cpt_custom_post_type']['name'] ); 
  445.  
  446. if ( isset( $_POST['cpt_custom_tax']['name'] ) ) { 
  447. return sanitize_text_field( $_POST['cpt_custom_tax']['name'] ); 
  448.  
  449. return esc_html__( 'Object', 'custom-post-type-ui' ); 
  450.  
  451. /** 
  452. * Successful add callback. 
  453. * 
  454. * @since 1.4.0 
  455. */ 
  456. function cptui_add_success_admin_notice() { 
  457. echo cptui_admin_notices_helper( 
  458. sprintf( 
  459. esc_html__( '%s has been successfully added', 'custom-post-type-ui' ),  
  460. cptui_get_object_from_post_global() 
  461. ),  
  462. true 
  463. ); 
  464.  
  465. /** 
  466. * Fail to add callback. 
  467. * 
  468. * @since 1.4.0 
  469. */ 
  470. function cptui_add_fail_admin_notice() { 
  471. echo cptui_admin_notices_helper( 
  472. sprintf( 
  473. esc_html__( '%s has failed to be added', 'custom-post-type-ui' ),  
  474. cptui_get_object_from_post_global() 
  475. ),  
  476. false 
  477. ); 
  478.  
  479. /** 
  480. * Successful update callback. 
  481. * 
  482. * @since 1.4.0 
  483. */ 
  484. function cptui_update_success_admin_notice() { 
  485. echo cptui_admin_notices_helper( 
  486. sprintf( 
  487. esc_html__( '%s has been successfully updated', 'custom-post-type-ui' ),  
  488. cptui_get_object_from_post_global() 
  489. ),  
  490. true 
  491. ); 
  492.  
  493. /** 
  494. * Fail to update callback. 
  495. * 
  496. * @since 1.4.0 
  497. */ 
  498. function cptui_update_fail_admin_notice() { 
  499. echo cptui_admin_notices_helper( 
  500. sprintf( 
  501. esc_html__( '%s has failed to be updated', 'custom-post-type-ui' ),  
  502. cptui_get_object_from_post_global() 
  503. ),  
  504. false 
  505. ); 
  506.  
  507. /** 
  508. * Successful delete callback. 
  509. * 
  510. * @since 1.4.0 
  511. */ 
  512. function cptui_delete_success_admin_notice() { 
  513. echo cptui_admin_notices_helper( 
  514. sprintf( 
  515. esc_html__( '%s has been successfully deleted', 'custom-post-type-ui' ),  
  516. cptui_get_object_from_post_global() 
  517. ),  
  518. true 
  519. ); 
  520.  
  521. /** 
  522. * Fail to delete callback. 
  523. * 
  524. * @since 1.4.0 
  525. */ 
  526. function cptui_delete_fail_admin_notice() { 
  527. echo cptui_admin_notices_helper( 
  528. sprintf( 
  529. esc_html__( '%s has failed to be deleted', 'custom-post-type-ui' ),  
  530. cptui_get_object_from_post_global() 
  531. ),  
  532. false 
  533. ); 
  534.  
  535. /** 
  536. * Success to import callback. 
  537. * 
  538. * @since 1.5.0 
  539. */ 
  540. function cptui_import_success_admin_notice() { 
  541. echo cptui_admin_notices_helper( 
  542. esc_html__( 'Successfully imported data.', 'custom-post-type-ui' ) 
  543. ); 
  544.  
  545. /** 
  546. * Failure to import callback. 
  547. * 
  548. * @since 1.5.0 
  549. */ 
  550. function cptui_import_fail_admin_notice() { 
  551. echo cptui_admin_notices_helper( 
  552. esc_html__( 'Invalid data provided', 'custom-post-type-ui' ) 
  553. ); 
  554.  
  555. /** 
  556. * Returns error message for if trying to register existing post type. 
  557. * 
  558. * @since 1.4.0 
  559. * 
  560. * @return string 
  561. */ 
  562. function cptui_slug_matches_post_type() { 
  563. return sprintf( 
  564. esc_html__( 'Please choose a different post type name. %s is already registered.', 'custom-post-type-ui' ),  
  565. cptui_get_object_from_post_global() 
  566. ); 
  567.  
  568. /** 
  569. * Returns error message for if trying to register existing taxonomy. 
  570. * 
  571. * @since 1.4.0 
  572. * 
  573. * @return string 
  574. */ 
  575. function cptui_slug_matches_taxonomy() { 
  576. return sprintf( 
  577. esc_html__( 'Please choose a different taxonomy name. %s is already registered.', 'custom-post-type-ui' ),  
  578. cptui_get_object_from_post_global() 
  579. ); 
  580.  
  581. /** 
  582. * Returns error message for if trying to register post type with matching page slug. 
  583. * 
  584. * @since 1.4.0 
  585. * 
  586. * @return string 
  587. */ 
  588. function cptui_slug_matches_page() { 
  589. return sprintf( 
  590. esc_html__( 'Please choose a different post type name. %s matches an existing page slug, which can cause conflicts.', 'custom-post-type-ui' ),  
  591. cptui_get_object_from_post_global() 
  592. ); 
  593.  
  594. /** 
  595. * Returns error message for if trying to use quotes in slugs or rewrite slugs. 
  596. * 
  597. * @since 1.4.0 
  598. * 
  599. * @return string 
  600. */ 
  601. function cptui_slug_has_quotes() { 
  602. return sprintf( 
  603. esc_html__( 'Please do not use quotes in post type/taxonomy names or rewrite slugs', 'custom-post-type-ui' ),  
  604. cptui_get_object_from_post_global() 
  605. ); 
  606.  
  607. /** 
  608. * Error admin notice. 
  609. * 
  610. * @since 1.4.0 
  611. */ 
  612. function cptui_error_admin_notice() { 
  613. echo cptui_admin_notices_helper( 
  614. apply_filters( 'cptui_custom_error_message', '' ),  
  615. false 
  616. ); 
  617.  
  618. /** 
  619. * Mark site as not a new CPTUI install upon update to 1.5.0 
  620. * 
  621. * @since 1.5.0 
  622. * 
  623. * @param object $wp_upgrader WP_Upgrader instance. 
  624. * @param array $extras Extra information about performed upgrade. 
  625. */ 
  626. function cptui_not_new_install( $wp_upgrader, $extras ) { 
  627.  
  628. if ( ! is_a( $wp_upgrader, 'Plugin_Upgrader' ) ) { 
  629. return; 
  630.  
  631. if ( ! array_key_exists( 'plugins', $extras ) || ! is_array( $extras['plugins'] ) ) { 
  632. return; 
  633.  
  634. // Was CPTUI updated? 
  635. if ( ! in_array( 'custom-post-type-ui/custom-post-type-ui.php', $extras['plugins'] ) ) { 
  636. return; 
  637.  
  638. // If we are already known as not new, return. 
  639. if ( cptui_is_new_install() ) { 
  640. return; 
  641.  
  642. // We need to mark ourselves as not new. 
  643. cptui_set_not_new_install(); 
  644. add_action( 'upgrader_process_complete', 'cptui_not_new_install', 10, 2 ); 
  645.  
  646. /** 
  647. * Check whether or not we're on a new install. 
  648. * 
  649. * @since 1.5.0 
  650. * 
  651. * @return bool 
  652. */ 
  653. function cptui_is_new_install() { 
  654. $new_or_not = true; 
  655. $saved = get_option( 'cptui_new_install', '' ); 
  656.  
  657. if ( 'false' === $saved ) { 
  658. $new_or_not = false; 
  659.  
  660. /** 
  661. * Filters the new install status. 
  662. * 
  663. * Offers third parties the ability to override if they choose to. 
  664. * 
  665. * @since 1.5.0 
  666. * 
  667. * @param bool $new_or_not Whether or not site is a new install. 
  668. */ 
  669. return (bool) apply_filters( 'cptui_is_new_install', $new_or_not ); 
  670.  
  671. /** 
  672. * Set our activation status to not new. 
  673. * 
  674. * @since 1.5.0 
  675. */ 
  676. function cptui_set_not_new_install() { 
  677. update_option( 'cptui_new_install', 'false' ); 
  678.  
  679. /** 
  680. * Returns saved values for single post type from CPTUI settings. 
  681. * 
  682. * @since 1.5.0 
  683. * 
  684. * @param string $post_type Post type to retrieve CPTUI object for. 
  685. * @return string 
  686. */ 
  687. function cptui_get_cptui_post_type_object( $post_type = '' ) { 
  688. $post_types = get_option( 'cptui_post_types' ); 
  689.  
  690. if ( array_key_exists( $post_type, $post_types ) ) { 
  691. return $post_types[ $post_type ]; 
  692. return ''; 
  693.  
  694. /** 
  695. * Returns saved values for single taxonomy from CPTUI settings. 
  696. * 
  697. * @since 1.5.0 
  698. * 
  699. * @param string $taxonomy Taxonomy to retrieve CPTUI object for. 
  700. * @return string 
  701. */ 
  702. function cptui_get_cptui_taxonomy_object( $taxonomy = '' ) { 
  703. $taxonomies = get_option( 'cptui_taxonomies' ); 
  704.  
  705. if ( array_key_exists( $taxonomy, $taxonomies ) ) { 
  706. return $taxonomies[ $taxonomy ]; 
  707. return ''; 
  708.  
  709. /** 
  710. * Checks if a requested post type has a custom CPTUI feature supported. 
  711. * 
  712. * @since 1.5.0 
  713. * 
  714. * @param string $post_type Post type slug. 
  715. * @param string $feature Feature to check for. 
  716. * @return bool 
  717. */ 
  718. function cptui_post_type_supports( $post_type, $feature ) { 
  719.  
  720. $object = cptui_get_cptui_post_type_object( $post_type ); 
  721.  
  722. if ( ! empty( $object ) ) { 
  723. if ( array_key_exists( $feature, $object ) && ! empty( $object[ $feature ] ) ) { 
  724. return true; 
  725.  
  726. return false; 
  727.  
  728. return false; 
.