PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/lgorence/quickpress
PHP | 87 lines | 27 code | 14 blank | 46 comment | 9 complexity | 99812d8280e84094e636149f3055dab3 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. /**
  3. * Functions for dealing with theme settings on both the front end of the site and the admin. This allows us
  4. * to set some default settings and make it easy for theme developers to quickly grab theme settings from
  5. * the database. This file is only loaded if the theme adds support for the 'hybrid-core-theme-settings'
  6. * feature.
  7. *
  8. * @package HybridCore
  9. * @subpackage Functions
  10. * @author Justin Tadlock <justin@justintadlock.com>
  11. * @copyright Copyright (c) 2008 - 2012, Justin Tadlock
  12. * @link http://themehybrid.com/hybrid-core
  13. * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  14. */
  15. /**
  16. * Loads the Hybrid theme settings once and allows the input of the specific field the user would
  17. * like to show. Hybrid theme settings are added with 'autoload' set to 'yes', so the settings are
  18. * only loaded once on each page load.
  19. *
  20. * @since 0.7.0
  21. * @access public
  22. * @uses get_option() Gets an option from the database.
  23. * @uses hybrid_get_prefix() Gets the prefix of the theme.
  24. * @global object $hybrid The global Hybrid object.
  25. * @param string $option The specific theme setting the user wants.
  26. * @return mixed $settings[$option] Specific setting asked for.
  27. */
  28. function hybrid_get_setting( $option = '' ) {
  29. global $hybrid;
  30. /* If no specific option was requested, return false. */
  31. if ( !$option )
  32. return false;
  33. /* If the settings array hasn't been set, call get_option() to get an array of theme settings. */
  34. if ( !isset( $hybrid->settings ) )
  35. $hybrid->settings = get_option( hybrid_get_prefix() . '_theme_settings', hybrid_get_default_theme_settings() );
  36. /* If the settings isn't an array or the specific option isn't in the array, return false. */
  37. if ( !is_array( $hybrid->settings ) || empty( $hybrid->settings[$option] ) )
  38. return false;
  39. /* If the specific option is an array, return it. */
  40. if ( is_array( $hybrid->settings[$option] ) )
  41. return $hybrid->settings[$option];
  42. /* Strip slashes from the setting and return. */
  43. else
  44. return wp_kses_stripslashes( $hybrid->settings[$option] );
  45. }
  46. /**
  47. * Sets up a default array of theme settings for use with the theme. Theme developers should filter the
  48. * "{$prefix}_default_theme_settings" hook to define any default theme settings. WordPress does not
  49. * provide a hook for default settings at this time.
  50. *
  51. * @since 1.0.0
  52. * @access public
  53. * @return array $settings The default theme settings.
  54. */
  55. function hybrid_get_default_theme_settings() {
  56. /* Set up some default variables. */
  57. $settings = array();
  58. $prefix = hybrid_get_prefix();
  59. /* Get theme-supported meta boxes for the settings page. */
  60. $supports = get_theme_support( 'hybrid-core-theme-settings' );
  61. /* If the current theme supports the footer meta box and shortcodes, add default footer settings. */
  62. if ( is_array( $supports[0] ) && in_array( 'footer', $supports[0] ) && current_theme_supports( 'hybrid-core-shortcodes' ) ) {
  63. /* If there is a child theme active, add the [child-link] shortcode to the $footer_insert. */
  64. if ( is_child_theme() )
  65. $settings['footer_insert'] = '<p class="copyright">' . __( 'Copyright &#169; [the-year] [site-link].', 'hybrid-core' ) . '</p>' . "\n\n" . '<p class="credit">' . __( 'Powered by [wp-link], [theme-link], and [child-link].', 'hybrid-core' ) . '</p>';
  66. /* If no child theme is active, leave out the [child-link] shortcode. */
  67. else
  68. $settings['footer_insert'] = '<p class="copyright">' . __( 'Copyright &#169; [the-year] [site-link].', 'hybrid-core' ) . '</p>' . "\n\n" . '<p class="credit">' . __( 'Powered by [wp-link] and [theme-link].', 'hybrid-core' ) . '</p>';
  69. }
  70. /* Return the $settings array and provide a hook for overwriting the default settings. */
  71. return apply_filters( "{$prefix}_default_theme_settings", $settings );
  72. }
  73. ?>