PageRenderTime 67ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/wordpress/wp-content/theme/hybrid/library/functions/core.php

http://ooxx.googlecode.com/
PHP | 167 lines | 45 code | 22 blank | 100 comment | 6 complexity | 2be1f430f058c8c61c70dd1d01b03f03 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * The core functions file for the Hybrid framework. Functions defined here are generally
  4. * used across the entire framework to make various tasks faster. This file should be loaded
  5. * prior to any other files because its functions are needed to run the framework.
  6. *
  7. * @package Hybrid
  8. * @subpackage Functions
  9. */
  10. /**
  11. * Defines the theme prefix. This allows developers to infinitely change the theme. In theory,
  12. * one could use the Hybrid core to create their own theme or filter 'hybrid_prefix' with a
  13. * plugin to make it easier to use hooks across multiple themes without having to figure out
  14. * each theme's hooks (assuming other themes used the same system).
  15. *
  16. * @since 0.7
  17. * @uses get_template() Defines the theme prefix, which is generally 'hybrid'.
  18. * @global object $hybrid The global Hybrid object.
  19. * @return string $hybrid->prefix The prefix of the theme.
  20. */
  21. function hybrid_get_prefix() {
  22. global $hybrid;
  23. /* If the global prefix isn't set, define it. Plugin/theme authors may also define a custom prefix. */
  24. if ( empty( $hybrid->prefix ) )
  25. $hybrid->prefix = apply_filters( 'hybrid_prefix', get_template() );
  26. return $hybrid->prefix;
  27. }
  28. /**
  29. * Defines the theme textdomain. This allows the framework to recognize the proper textdomain
  30. * of the theme. Theme developers building from the framework should use their template name
  31. * (i.e., directory name) as their textdomain within template files.
  32. *
  33. * @since 0.7
  34. * @uses get_template() Defines the theme textdomain, which is generally 'hybrid'.
  35. * @global object $hybrid The global Hybrid object.
  36. * @return string $hybrid->textdomain The textdomain of the theme.
  37. */
  38. function hybrid_get_textdomain() {
  39. global $hybrid;
  40. /* If the global textdomain isn't set, define it. Plugin/theme authors may also define a custom textdomain. */
  41. if ( empty( $hybrid->textdomain ) )
  42. $hybrid->textdomain = apply_filters( hybrid_get_prefix() . '_textdomain', get_template() );
  43. return $hybrid->textdomain;
  44. }
  45. /**
  46. * Adds contextual action hooks to the theme. This allows users to easily add context-based content
  47. * without having to know how to use WordPress conditional tags. The theme handles the logic.
  48. *
  49. * An example of a basic hook would be 'hybrid_header'. The do_atomic() function extends that to
  50. * give extra hooks such as 'hybrid_singular_header', 'hybrid_singular-post_header', and
  51. * 'hybrid_singular-post-ID_header'.
  52. *
  53. * Major props to Ptah Dunbar for the do_atomic() function.
  54. * @link http://ptahdunbar.com/wordpress/smarter-hooks-context-sensitive-hooks
  55. *
  56. * @since 0.7
  57. * @uses hybrid_get_prefix() Gets the theme prefix.
  58. * @uses hybrid_get_context() Gets the context of the current page.
  59. * @param string $tag Usually the location of the hook but defines what the base hook is.
  60. */
  61. function do_atomic( $tag = '' ) {
  62. if ( !$tag )
  63. return false;
  64. /* Get the theme prefix. */
  65. $pre = hybrid_get_prefix();
  66. /* Do actions on the basic hook. */
  67. do_action( "{$pre}_{$tag}" );
  68. /* Loop through context array and fire actions on a contextual scale. */
  69. foreach ( (array)hybrid_get_context() as $context )
  70. do_action( "{$pre}_{$context}_{$tag}" );
  71. }
  72. /**
  73. * Adds contextual filter hooks to the theme. This allows users to easily filter context-based content
  74. * without having to know how to use WordPress conditional tags. The theme handles the logic.
  75. *
  76. * An example of a basic hook would be 'hybrid_entry_meta'. The apply_atomic() function extends
  77. * that to give extra hooks such as 'hybrid_singular_entry_meta', 'hybrid_singular-post_entry_meta',
  78. * and 'hybrid_singular-post-ID_entry_meta'.
  79. *
  80. * @since 0.7
  81. * @uses hybrid_get_prefix() Gets the theme prefix.
  82. * @uses hybrid_get_context() Gets the context of the current page.
  83. * @param string $tag Usually the location of the hook but defines what the base hook is.
  84. * @param mixed $value The value to be filtered.
  85. * @return mixed $value The value after it has been filtered.
  86. */
  87. function apply_atomic( $tag = '', $value = '' ) {
  88. if ( !$tag )
  89. return false;
  90. /* Get theme prefix. */
  91. $pre = hybrid_get_prefix();
  92. /* Apply filters on the basic hook. */
  93. $value = apply_filters( "{$pre}_{$tag}", $value );
  94. /* Loop through context array and apply filters on a contextual scale. */
  95. foreach ( (array)hybrid_get_context() as $context )
  96. $value = apply_filters( "{$pre}_{$context}_{$tag}", $value );
  97. /* Return the final value once all filters have been applied. */
  98. return $value;
  99. }
  100. /**
  101. * Wraps the output of apply_atomic() in a call to do_shortcode(). This allows developers to use
  102. * context-aware functionality alongside shortcodes. Rather than adding a lot of code to the
  103. * function itself, developers can create individual functions to handle shortcodes.
  104. *
  105. * @since 0.7
  106. * @param string $tag Usually the location of the hook but defines what the base hook is.
  107. * @param mixed $value The value to be filtered.
  108. * @return mixed $value The value after it has been filtered.
  109. */
  110. function apply_atomic_shortcode( $tag = '', $value = '' ) {
  111. return do_shortcode( apply_atomic( $tag, $value ) );
  112. }
  113. /**
  114. * Loads the Hybrid theme settings once and allows the input of the specific field the user would
  115. * like to show. Hybrid theme settings are added with 'autoload' set to 'yes', so the settings are
  116. * only loaded once on each page load.
  117. *
  118. * @since 0.7
  119. * @uses get_option() Gets an option from the database.
  120. * @uses hybrid_get_prefix() Gets the prefix of the theme.
  121. * @global object $hybrid The global Hybrid object.
  122. * @global array $hybrid_settings Deprecated. Developers should use hybrid_get_setting().
  123. * @param string $option The specific theme setting the user wants.
  124. * @return string|int|array $settings[$option] Specific setting asked for.
  125. */
  126. function hybrid_get_setting( $option = '' ) {
  127. global $hybrid, $hybrid_settings;
  128. if ( !$option )
  129. return false;
  130. if ( !is_array( $hybrid->settings ) )
  131. $hybrid->settings = $hybrid_settings = get_option( hybrid_get_prefix() . '_theme_settings' );
  132. return $hybrid->settings[$option];
  133. }
  134. /**
  135. * Function for formatting a hook name if needed. It automatically adds the theme's prefix to
  136. * the hook, and it will add a context (or any variable) if it's given.
  137. *
  138. * @since 0.7
  139. * @param string $tag The basic name of the hook (e.g., 'before_header').
  140. * @param string $context A specific context/value to be added to the hook.
  141. */
  142. function hybrid_format_hook( $tag, $context = '' ) {
  143. return hybrid_get_prefix() . ( ( !empty( $context ) ) ? "_{$context}" : "" ). "_{$tag}";
  144. }
  145. ?>