/wp-content/themes/news/library/admin/admin.php

https://bitbucket.org/lgorence/quickpress · PHP · 129 lines · 43 code · 23 blank · 63 comment · 5 complexity · 6fa46966704bf69031251a7926dc7d93 MD5 · raw file

  1. <?php
  2. /**
  3. * Theme administration functions used with other components of the framework admin. This file is for
  4. * setting up any basic features and holding additional admin helper functions.
  5. *
  6. * @package HybridCore
  7. * @subpackage Admin
  8. * @author Justin Tadlock <justin@justintadlock.com>
  9. * @copyright Copyright (c) 2008 - 2012, Justin Tadlock
  10. * @link http://themehybrid.com/hybrid-core
  11. * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  12. */
  13. /* Add the admin setup function to the 'admin_menu' hook. */
  14. add_action( 'admin_menu', 'hybrid_admin_setup' );
  15. /**
  16. * Sets up the adminstration functionality for the framework and themes.
  17. *
  18. * @since 1.3.0
  19. * @return void
  20. */
  21. function hybrid_admin_setup() {
  22. /* Load the post meta boxes on the new post and edit post screens. */
  23. add_action( 'load-post.php', 'hybrid_admin_load_post_meta_boxes' );
  24. add_action( 'load-post-new.php', 'hybrid_admin_load_post_meta_boxes' );
  25. /* Registers admin stylesheets for the framework. */
  26. add_action( 'admin_enqueue_scripts', 'hybrid_admin_register_styles', 1 );
  27. /* Loads admin stylesheets for the framework. */
  28. add_action( 'admin_enqueue_scripts', 'hybrid_admin_enqueue_styles' );
  29. }
  30. /**
  31. * Loads the core post meta box files on the 'load-post.php' action hook. Each meta box file is only loaded if
  32. * the theme declares support for the feature.
  33. *
  34. * @since 1.2.0
  35. * @return void
  36. */
  37. function hybrid_admin_load_post_meta_boxes() {
  38. /* Load the SEO post meta box. */
  39. require_if_theme_supports( 'hybrid-core-seo', trailingslashit( HYBRID_ADMIN ) . 'meta-box-post-seo.php' );
  40. /* Load the post template meta box. */
  41. require_if_theme_supports( 'hybrid-core-template-hierarchy', trailingslashit( HYBRID_ADMIN ) . 'meta-box-post-template.php' );
  42. }
  43. /**
  44. * Registers the framework's 'admin.css' stylesheet file. The function does not load the stylesheet. It merely
  45. * registers it with WordPress.
  46. *
  47. * @since 1.2.0
  48. * @return void
  49. */
  50. function hybrid_admin_register_styles() {
  51. wp_register_style( 'hybrid-core-admin', trailingslashit( HYBRID_CSS ) . 'admin.css', false, '20110512', 'screen' );
  52. }
  53. /**
  54. * Loads the admin.css stylesheet for admin-related features.
  55. *
  56. * @since 1.2.0
  57. * @return void
  58. */
  59. function hybrid_admin_enqueue_styles( $hook_suffix ) {
  60. /* Load admin styles if on the widgets screen and the current theme supports 'hybrid-core-widgets'. */
  61. if ( current_theme_supports( 'hybrid-core-widgets' ) && 'widgets.php' == $hook_suffix )
  62. wp_enqueue_style( 'hybrid-core-admin' );
  63. }
  64. /**
  65. * Function for getting an array of available custom templates with a specific header. Ideally, this function
  66. * would be used to grab custom singular post (any post type) templates. It is a recreation of the WordPress
  67. * page templates function because it doesn't allow for other types of templates.
  68. *
  69. * @since 0.7.0
  70. * @param string $post_type The name of the post type to get templates for.
  71. * @return array $post_templates The array of templates.
  72. */
  73. function hybrid_get_post_templates( $post_type = 'post' ) {
  74. /* Set up an empty post templates array. */
  75. $post_templates = array();
  76. /* Get the post type object. */
  77. $post_type_object = get_post_type_object( $post_type );
  78. /* Get the theme (parent theme if using a child theme) object. */
  79. $theme = wp_get_theme( get_template(), get_theme_root( get_template_directory() ) );
  80. /* Get the theme PHP files one level deep. */
  81. $files = (array) $theme->get_files( 'php', 1 );
  82. /* If a child theme is active, get its files and merge with the parent theme files. */
  83. if ( is_child_theme() ) {
  84. $child = wp_get_theme( get_stylesheet(), get_theme_root( get_stylesheet_directory() ) );
  85. $child_files = (array) $child->get_files( 'php', 1 );
  86. $files = array_merge( $files, $child_files );
  87. }
  88. /* Loop through each of the PHP files and check if they are post templates. */
  89. foreach ( $files as $file => $path ) {
  90. /* Get file data based on the post type singular name (e.g., "Post Template", "Book Template", etc.). */
  91. $headers = get_file_data(
  92. $path,
  93. array(
  94. "{$post_type_object->name} Template" => "{$post_type_object->name} Template",
  95. )
  96. );
  97. /* Continue loop if the header is empty. */
  98. if ( empty( $headers["{$post_type_object->name} Template"] ) )
  99. continue;
  100. /* Add the PHP filename and template name to the array. */
  101. $post_templates[ $file ] = $headers["{$post_type_object->name} Template"];
  102. }
  103. /* Return array of post templates. */
  104. return array_flip( $post_templates );
  105. }
  106. ?>