PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/themes/news/library/functions/utility.php

https://bitbucket.org/lgorence/quickpress
PHP | 213 lines | 69 code | 37 blank | 107 comment | 16 complexity | 3589faadc2ecbe45d3d5e7103f6e826e MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. /**
  3. * Additional helper functions that the framework or themes may use. The functions in this file are functions
  4. * that don't really have a home within any other parts of the framework.
  5. *
  6. * @package HybridCore
  7. * @subpackage Functions
  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 extra support for post types. */
  14. add_action( 'init', 'hybrid_add_post_type_support' );
  15. /* Add extra file headers for themes. */
  16. add_filter( 'extra_theme_headers', 'hybrid_extra_theme_headers' );
  17. /**
  18. * This function is for adding extra support for features not default to the core post types.
  19. * Excerpts are added to the 'page' post type. Comments and trackbacks are added for the
  20. * 'attachment' post type. Technically, these are already used for attachments in core, but
  21. * they're not registered.
  22. *
  23. * @since 0.8.0
  24. * @access private
  25. * @return void
  26. */
  27. function hybrid_add_post_type_support() {
  28. /* Add support for excerpts to the 'page' post type. */
  29. add_post_type_support( 'page', array( 'excerpt' ) );
  30. /* Add support for trackbacks to the 'attachment' post type. */
  31. add_post_type_support( 'attachment', array( 'trackbacks' ) );
  32. }
  33. /**
  34. * Creates custom theme headers. This is the information shown in the header block of a theme's 'style.css'
  35. * file. Themes are not required to use this information, but the framework does make use of the data for
  36. * displaying additional information to the theme user.
  37. *
  38. * @since 1.2.0
  39. * @access private
  40. * @link http://codex.wordpress.org/Theme_Review#Licensing
  41. * @param array $headers Array of extra headers added by plugins/themes.
  42. * @return array $headers
  43. */
  44. function hybrid_extra_theme_headers( $headers ) {
  45. /* Add support for 'Template Version'. This is for use in child themes to note the version of the parent theme. */
  46. if ( !in_array( 'Template Version', $headers ) )
  47. $headers[] = 'Template Version';
  48. /* Add support for 'License'. Proposed in the guidelines for the WordPress.org theme review. */
  49. if ( !in_array( 'License', $headers ) )
  50. $headers[] = 'License';
  51. /* Add support for 'License URI'. Proposed in the guidelines for the WordPress.org theme review. */
  52. if ( !in_array( 'License URI', $headers ) )
  53. $headers[] = 'License URI';
  54. /* Add support for 'Support URI'. This should be a link to the theme's support forums. */
  55. if ( !in_array( 'Support URI', $headers ) )
  56. $headers[] = 'Support URI';
  57. /* Add support for 'Documentation URI'. This should be a link to the theme's documentation. */
  58. if ( !in_array( 'Documentation URI', $headers ) )
  59. $headers[] = 'Documentation URI';
  60. /* Return the array of custom theme headers. */
  61. return $headers;
  62. }
  63. /**
  64. * Looks for a template based on the hybrid_get_context() function. If the $template parameter
  65. * is a directory, it will look for files within that directory. Otherwise, $template becomes the
  66. * template name prefix. The function looks for templates based on the context of the current page
  67. * being viewed by the user.
  68. *
  69. * @since 0.8.0
  70. * @access public
  71. * @param string $template The slug of the template whose context we're searching for.
  72. * @return string $template The full path of the located template.
  73. */
  74. function get_atomic_template( $template ) {
  75. $templates = array();
  76. $theme_dir = trailingslashit( THEME_DIR ) . $template;
  77. $child_dir = trailingslashit( CHILD_THEME_DIR ) . $template;
  78. if ( is_dir( $child_dir ) || is_dir( $theme_dir ) ) {
  79. $dir = true;
  80. $templates[] = "{$template}/index.php";
  81. }
  82. else {
  83. $dir = false;
  84. $templates[] = "{$template}.php";
  85. }
  86. foreach ( hybrid_get_context() as $context )
  87. $templates[] = ( ( $dir ) ? "{$template}/{$context}.php" : "{$template}-{$context}.php" );
  88. return locate_template( array_reverse( $templates ), true );
  89. }
  90. /**
  91. * Generates the relevant template info. Adds template meta with theme version. Uses the theme
  92. * name and version from style.css. In 0.6, added the hybrid_meta_template
  93. * filter hook.
  94. *
  95. * @since 0.4.0
  96. * @access private
  97. * @return void
  98. */
  99. function hybrid_meta_template() {
  100. $theme = wp_get_theme( get_template(), get_theme_root( get_template_directory() ) );
  101. $template = '<meta name="template" content="' . esc_attr( $theme->get( 'Name' ) . ' ' . $theme->get( 'Version' ) ) . '" />' . "\n";
  102. echo apply_atomic( 'meta_template', $template );
  103. }
  104. /**
  105. * Dynamic element to wrap the site title in. If it is the front page, wrap it in an <h1> element. One other
  106. * pages, wrap it in a <div> element.
  107. *
  108. * @since 0.1.0
  109. * @access public
  110. * @return void
  111. */
  112. function hybrid_site_title() {
  113. /* If viewing the front page of the site, use an <h1> tag. Otherwise, use a <div> tag. */
  114. $tag = ( is_front_page() ) ? 'h1' : 'div';
  115. /* Get the site title. If it's not empty, wrap it with the appropriate HTML. */
  116. if ( $title = get_bloginfo( 'name' ) )
  117. $title = sprintf( '<%1$s id="site-title"><a href="%2$s" title="%3$s" rel="home"><span>%4$s</span></a></%1$s>', tag_escape( $tag ), home_url(), esc_attr( $title ), $title );
  118. /* Display the site title and apply filters for developers to overwrite. */
  119. echo apply_atomic( 'site_title', $title );
  120. }
  121. /**
  122. * Dynamic element to wrap the site description in. If it is the front page, wrap it in an <h2> element.
  123. * On other pages, wrap it in a <div> element.
  124. *
  125. * @since 0.1.0
  126. * @access public
  127. * @return void
  128. */
  129. function hybrid_site_description() {
  130. /* If viewing the front page of the site, use an <h2> tag. Otherwise, use a <div> tag. */
  131. $tag = ( is_front_page() ) ? 'h2' : 'div';
  132. /* Get the site description. If it's not empty, wrap it with the appropriate HTML. */
  133. if ( $desc = get_bloginfo( 'description' ) )
  134. $desc = sprintf( '<%1$s id="site-description"><span>%2$s</span></%1$s>', tag_escape( $tag ), $desc );
  135. /* Display the site description and apply filters for developers to overwrite. */
  136. echo apply_atomic( 'site_description', $desc );
  137. }
  138. /**
  139. * Standardized function for outputting the footer content.
  140. *
  141. * @since 1.4.0
  142. * @access public
  143. * @return void
  144. */
  145. function hybrid_footer_content() {
  146. /* Only run the code if the theme supports the Hybrid Core theme settings. */
  147. if ( current_theme_supports( 'hybrid-core-theme-settings' ) )
  148. echo apply_atomic_shortcode( 'footer_content', hybrid_get_setting( 'footer_insert' ) );
  149. }
  150. /**
  151. * Checks if a post of any post type has a custom template. This is the equivalent of WordPress'
  152. * is_page_template() function with the exception that it works for all post types.
  153. *
  154. * @since 1.2.0
  155. * @access public
  156. * @param string $template The name of the template to check for.
  157. * @return bool Whether the post has a template.
  158. */
  159. function hybrid_has_post_template( $template = '' ) {
  160. /* Assume we're viewing a singular post. */
  161. if ( is_singular() ) {
  162. /* Get the queried object. */
  163. $post = get_queried_object();
  164. /* Get the post template, which is saved as metadata. */
  165. $post_template = get_post_meta( get_queried_object_id(), "_wp_{$post->post_type}_template", true );
  166. /* If a specific template was input, check that the post template matches. */
  167. if ( !empty( $template) && ( $template == $post_template ) )
  168. return true;
  169. /* If no specific template was input, check if the post has a template. */
  170. elseif ( empty( $template) && !empty( $post_template ) )
  171. return true;
  172. }
  173. /* Return false for everything else. */
  174. return false;
  175. }
  176. ?>