Permalink
Browse files

Move the settings functions into a separate settings.php file that's …

…only loaded if the theme supports 'hybrid-core-theme-settings'.

git-svn-id: http://svn.locallylost.com/themes/hybrid-core/trunk@799 dba0f204-706d-4bc1-bc29-8b92e0485636
  • Loading branch information...
1 parent 7f6a361 commit 446768fccc1387ad402fb910c95c04b5f4bdad3b greenshady committed Jul 23, 2011
Showing with 84 additions and 72 deletions.
  1. +0 −72 functions/core.php
  2. +81 −0 functions/settings.php
  3. +3 −0 hybrid.php
View
@@ -184,78 +184,6 @@ function apply_atomic_shortcode( $tag = '', $value = '' ) {
}
/**
- * Loads the Hybrid theme settings once and allows the input of the specific field the user would
- * like to show. Hybrid theme settings are added with 'autoload' set to 'yes', so the settings are
- * only loaded once on each page load.
- *
- * @since 0.7.0
- * @uses get_option() Gets an option from the database.
- * @uses hybrid_get_prefix() Gets the prefix of the theme.
- * @global object $hybrid The global Hybrid object.
- * @global array $hybrid_settings Deprecated. Developers should use hybrid_get_setting().
- * @param string $option The specific theme setting the user wants.
- * @return string|int|array $settings[$option] Specific setting asked for.
- */
-function hybrid_get_setting( $option = '' ) {
- global $hybrid, $hybrid_settings;
-
- /* If no specific option was requested, return false. */
- if ( !$option )
- return false;
-
- /* If the settings array hasn't been set, call get_option() to get an array of theme settings. */
- if ( !isset( $hybrid->settings ) )
- $hybrid->settings = $hybrid_settings = get_option( hybrid_get_prefix() . '_theme_settings', hybrid_get_default_theme_settings() );
-
- /* If the settings isn't an array or the specific option isn't in the array, return false. */
- if ( !is_array( $hybrid->settings ) || empty( $hybrid->settings[$option] ) )
- return false;
-
- /* If the specific option is an array, return it. */
- if ( is_array( $hybrid->settings[$option] ) )
- return $hybrid->settings[$option];
-
- /* Strip slashes from the setting and return. */
- else
- return wp_kses_stripslashes( $hybrid->settings[$option] );
-}
-
-/**
- * Creates an empty array of the default theme settings. If the theme adds support for the
- * 'hybrid-core-meta-box-footer' feature, it'll automatically add that setting to the $settings array.
- *
- * @since 1.0.0
- */
-function hybrid_get_default_theme_settings() {
-
- /* Set up some default variables. */
- $settings = array();
- $domain = hybrid_get_textdomain();
- $prefix = hybrid_get_prefix();
-
- /* Get theme-supported meta boxes for the settings page. */
- $supports = get_theme_support( 'hybrid-core-theme-settings' );
-
- /* If the current theme supports the footer meta box and shortcodes, add default footer settings. */
- if ( is_array( $supports[0] ) && in_array( 'footer', $supports[0] ) && current_theme_supports( 'hybrid-core-shortcodes' ) ) {
-
- /* If there is a child theme active, add the [child-link] shortcode to the $footer_insert. */
- if ( is_child_theme() )
- $settings['footer_insert'] = '<p class="copyright">' . __( 'Copyright &#169; [the-year] [site-link].', $domain ) . '</p>' . "\n\n" . '<p class="credit">' . __( 'Powered by [wp-link], [theme-link], and [child-link].', $domain ) . '</p>';
-
- /* If no child theme is active, leave out the [child-link] shortcode. */
- else
- $settings['footer_insert'] = '<p class="copyright">' . __( 'Copyright &#169; [the-year] [site-link].', $domain ) . '</p>' . "\n\n" . '<p class="credit">' . __( 'Powered by [wp-link] and [theme-link].', $domain ) . '</p>';
- }
-
- /* Backwards compatibility hook. @deprecated 1.0.0. */
- $settings = apply_filters( "{$prefix}_settings_args", $settings );
-
- /* Return the $settings array and provide a hook for overwriting the default settings. */
- return apply_filters( "{$prefix}_default_theme_settings", $settings );
-}
-
-/**
* The theme can save multiple things in a transient to help speed up page load times. We're
* setting a default of 12 hours or 43,200 seconds (60 * 60 * 12).
*
@@ -0,0 +1,81 @@
+<?php
+/**
+ * Functions for dealing with theme settings on both the front end of the site and the admin. This allows us
+ * to set some default settings and make it easy for theme developers to quickly grab theme settings from
+ * the database. This file is only loaded if the theme adds support for the 'hybrid-core-theme-settings'
+ * feature.
+ *
+ * @package HybridCore
+ * @subpackage Functions
+ */
+
+/**
+ * Loads the Hybrid theme settings once and allows the input of the specific field the user would
+ * like to show. Hybrid theme settings are added with 'autoload' set to 'yes', so the settings are
+ * only loaded once on each page load.
+ *
+ * @since 0.7.0
+ * @uses get_option() Gets an option from the database.
+ * @uses hybrid_get_prefix() Gets the prefix of the theme.
+ * @global object $hybrid The global Hybrid object.
+ * @param string $option The specific theme setting the user wants.
+ * @return string|int|array $settings[$option] Specific setting asked for.
+ */
+function hybrid_get_setting( $option = '' ) {
+ global $hybrid;
+
+ /* If no specific option was requested, return false. */
+ if ( !$option )
+ return false;
+
+ /* If the settings array hasn't been set, call get_option() to get an array of theme settings. */
+ if ( !isset( $hybrid->settings ) )
+ $hybrid->settings = get_option( hybrid_get_prefix() . '_theme_settings', hybrid_get_default_theme_settings() );
+
+ /* If the settings isn't an array or the specific option isn't in the array, return false. */
+ if ( !is_array( $hybrid->settings ) || empty( $hybrid->settings[$option] ) )
+ return false;
+
+ /* If the specific option is an array, return it. */
+ if ( is_array( $hybrid->settings[$option] ) )
+ return $hybrid->settings[$option];
+
+ /* Strip slashes from the setting and return. */
+ else
+ return wp_kses_stripslashes( $hybrid->settings[$option] );
+}
+
+/**
+ * Sets up a default array of theme settings for use with the theme. Theme developers should filter the
+ * "{$prefix}_default_theme_settings" hook to define any default theme settings. WordPress does not
+ * provide a hook for default settings at this time.
+ *
+ * @since 1.0.0
+ */
+function hybrid_get_default_theme_settings() {
+
+ /* Set up some default variables. */
+ $settings = array();
+ $domain = hybrid_get_textdomain();
+ $prefix = hybrid_get_prefix();
+
+ /* Get theme-supported meta boxes for the settings page. */
+ $supports = get_theme_support( 'hybrid-core-theme-settings' );
+
+ /* If the current theme supports the footer meta box and shortcodes, add default footer settings. */
+ if ( is_array( $supports[0] ) && in_array( 'footer', $supports[0] ) && current_theme_supports( 'hybrid-core-shortcodes' ) ) {
+
+ /* If there is a child theme active, add the [child-link] shortcode to the $footer_insert. */
+ if ( is_child_theme() )
+ $settings['footer_insert'] = '<p class="copyright">' . __( 'Copyright &#169; [the-year] [site-link].', $domain ) . '</p>' . "\n\n" . '<p class="credit">' . __( 'Powered by [wp-link], [theme-link], and [child-link].', $domain ) . '</p>';
+
+ /* If no child theme is active, leave out the [child-link] shortcode. */
+ else
+ $settings['footer_insert'] = '<p class="copyright">' . __( 'Copyright &#169; [the-year] [site-link].', $domain ) . '</p>' . "\n\n" . '<p class="credit">' . __( 'Powered by [wp-link] and [theme-link].', $domain ) . '</p>';
+ }
+
+ /* Return the $settings array and provide a hook for overwriting the default settings. */
+ return apply_filters( "{$prefix}_default_theme_settings", $settings );
+}
+
+?>
View
@@ -189,6 +189,9 @@ function functions() {
/* Load the utility functions. */
require_once( trailingslashit( HYBRID_FUNCTIONS ) . 'utility.php' );
+ /* Load the theme settings functions if supported. */
+ require_if_theme_supports( 'hybrid-core-theme-settings', trailingslashit( HYBRID_FUNCTIONS ) . 'settings.php' );
+
/* Load the menus functions if supported. */
require_if_theme_supports( 'hybrid-core-menus', trailingslashit( HYBRID_FUNCTIONS ) . 'menus.php' );

0 comments on commit 446768f

Please sign in to comment.