acf-post-functions.php 889 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * Returns available templates for each post type.
  4. *
  5. * @date 29/8/17
  6. * @since 5.6.2
  7. *
  8. * @param void
  9. * @return array
  10. */
  11. function acf_get_post_templates() {
  12. // Check store.
  13. $cache = acf_get_data( 'post_templates' );
  14. if ( $cache !== null ) {
  15. return $cache;
  16. }
  17. // Initialize templates with default placeholder for pages.
  18. $post_templates = array();
  19. $post_templates['page'] = array();
  20. // Loop over post types and append their templates.
  21. if ( method_exists( 'WP_Theme', 'get_page_templates' ) ) {
  22. $post_types = get_post_types();
  23. foreach ( $post_types as $post_type ) {
  24. $templates = wp_get_theme()->get_page_templates( null, $post_type );
  25. if ( $templates ) {
  26. $post_templates[ $post_type ] = $templates;
  27. }
  28. }
  29. }
  30. // Update store.
  31. acf_set_data( 'post_templates', $post_templates );
  32. // Return templates.
  33. return $post_templates;
  34. }