Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: justintadlock/hybrid-core
base: 52ab7591a6
...
head fork: justintadlock/hybrid-core
compare: 91f047c8b3
Checking mergeability… Don't worry, you can still create the pull request.
  • 4 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
Commits on Sep 24, 2012
@justintadlock Separate styles and scripts from media.php and give them their own fi…
…les. This also introduces the new hybrid-core-css feature that allows themes to add support for specific stylesheets and allow the framework to load them.
9183530
Commits on Sep 26, 2012
@justintadlock Pass full $image array to get_the_image_meta_key_save(). d4eb591
Commits on Oct 02, 2012
@justintadlock Add the 'Customize' sub-menu item under 'Appearance'. 7ac5c3c
@justintadlock Change the "logic" behind the current layout by filtering 'theme_mod_…
…theme_layout' (eating our own dog food here) instead of handling it all in theme_layouts_get_layout(). This gives more flexibility to theme devs and provides a clear example of how to filter the layout.

Also changed the theme mod name from 'theme-layout' to 'theme_layout' to be in line with how WP core handles theme mods.
91f047c
View
8 admin/admin.php
@@ -31,6 +31,14 @@ function hybrid_admin_setup() {
/* Loads admin stylesheets for the framework. */
add_action( 'admin_enqueue_scripts', 'hybrid_admin_enqueue_styles' );
+
+ /* Add the WordPress 'Customize' page as an admin menu link. */
+ add_theme_page(
+ esc_html__( 'Customize', 'hybrid-core' ), // Settings page name
+ esc_html__( 'Customize', 'hybrid-core' ), // Menu name
+ 'edit_theme_options', // Required capability
+ 'customize.php' // File to load
+ );
}
/**
View
2  extensions/get-the-image.php
@@ -139,7 +139,7 @@ function get_the_image( $args = array() ) {
/* If $meta_key_save was set, save the image to a custom field. */
if ( !empty( $meta_key_save ) )
- get_the_image_meta_key_save( $args, $image['src'] );
+ get_the_image_meta_key_save( $args, $image );
/* Format the image HTML. */
$image_html = get_the_image_format( $args, $image );
View
59 extensions/theme-layouts.php
@@ -39,6 +39,9 @@
/* Add layout option in Customize. */
add_action( 'customize_register', 'theme_layouts_customize_register' );
+/* Filters the theme layout mod. */
+add_filter( 'theme_mods_theme_layout', 'theme_layouts_filter_layout' );
+
/* Filters the body_class hook to add a custom class. */
add_filter( 'body_class', 'theme_layouts_body_class' );
@@ -131,6 +134,32 @@ function theme_layouts_get_args() {
}
/**
+ * Filters the 'theme_mods_theme_layout' hook to alter the layout based on post and user metadata.
+ * Theme authors should also use this hook to filter the layout if need be.
+ *
+ * @since 0.5.0
+ * @access public
+ * @param string $theme_layout
+ * @return string
+ */
+function theme_layouts_filter_layout( $theme_layout ) {
+
+ /* If viewing a singular post, get the post layout. */
+ if ( is_singular() )
+ $layout = get_post_layout( get_queried_object_id() );
+
+ /* If viewing an author archive, get the user layout. */
+ elseif ( is_author() )
+ $layout = get_user_layout( get_queried_object_id() );
+
+ /* If a layout was found, set it. */
+ if ( !empty( $layout ) && 'default' !== $layout )
+ $theme_layout = $layout;
+
+ return $theme_layout;
+}
+
+/**
* Gets the layout for the current post based off the 'Layout' custom field key if viewing a singular post
* entry. All other pages are given a default layout of 'layout-default'.
*
@@ -146,27 +175,7 @@ function theme_layouts_get_layout() {
$args = theme_layouts_get_args();
/* Set the layout to an empty string. */
- $layout = get_theme_mod( 'theme-layout', $args['default'] );
-
- /* If viewing a singular post, check if a layout has been specified. */
- if ( is_singular() ) {
-
- /* Get the current post ID. */
- $post_id = get_queried_object_id();
-
- /* Get the post layout. */
- $layout = get_post_layout( $post_id );
- }
-
- /* If viewing a user/author archive, check if a layout has been specified. */
- elseif ( is_author() ) {
-
- /* Get the current user ID. */
- $user_id = get_queried_object_id();
-
- /* Get the user layout. */
- $layout = get_user_layout( $user_id );
- }
+ $layout = get_theme_mod( 'theme_layout', $args['default'] );
/* Make sure the given layout is in the array of available post layouts for the theme. */
if ( empty( $layout ) || !in_array( $layout, $layouts ) || 'default' == $layout )
@@ -175,7 +184,7 @@ function theme_layouts_get_layout() {
/* @deprecated 0.2.0. Use the 'get_theme_layout' hook. */
$layout = apply_filters( 'get_post_layout', "layout-{$layout}" );
- /* Return the layout and allow plugin/theme developers to override it. */
+ /* @deprecated 0.5.0. Use the 'theme_mods_theme_layout' hook. */
return esc_attr( apply_filters( 'get_theme_layout', $layout ) );
}
@@ -604,7 +613,7 @@ function theme_layouts_customize_register( $wp_customize ) {
/* Add the 'layout' setting. */
$wp_customize->add_setting(
- 'theme-layout',
+ 'theme_layout',
array(
'default' => $args['default'],
'type' => 'theme_mod',
@@ -631,7 +640,7 @@ function theme_layouts_customize_register( $wp_customize ) {
array(
'label' => esc_html__( 'Global Layout', 'theme-layouts' ),
'section' => 'layout',
- 'settings' => 'theme-layout',
+ 'settings' => 'theme_layout',
'type' => 'radio',
'choices' => $layout_choices
)
@@ -660,7 +669,7 @@ function theme_layouts_customize_preview_script() { ?>
<script type="text/javascript">
wp.customize(
- 'theme-layout',
+ 'theme_layout',
function( value ) {
value.bind(
function( to ) {
View
92 functions/media.php
@@ -1,7 +1,7 @@
<?php
/**
- * Functions file for loading scripts and stylesheets. This file also handles the output of attachment files
- * by displaying appropriate HTML elements for the attachments.
+ * Functions for handling media (i.e., attachments) within themes. Most functions are for handling
+ * the display of appropriate HTML elements on attachment pages.
*
* @package HybridCore
* @subpackage Functions
@@ -11,98 +11,10 @@
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
-/* Register Hybrid Core scripts. */
-add_action( 'wp_enqueue_scripts', 'hybrid_register_scripts', 1 );
-
-/* Load Hybrid Core scripts. */
-add_action( 'wp_enqueue_scripts', 'hybrid_enqueue_scripts' );
-
-/* Load the development stylsheet in script debug mode. */
-add_filter( 'stylesheet_uri', 'hybrid_debug_stylesheet', 10, 2 );
-
/* Add all image sizes to the image editor to insert into post. */
add_filter( 'image_size_names_choose', 'hybrid_image_size_names_choose' );
/**
- * Registers JavaScript files for the framework. This function merely registers scripts with WordPress using
- * the wp_register_script() function. It does not load any script files on the site. If a theme wants to register
- * its own custom scripts, it should do so on the 'wp_enqueue_scripts' hook.
- *
- * @since 1.2.0
- * @access private
- * @return void
- */
-function hybrid_register_scripts() {
-
- /* Supported JavaScript. */
- $supports = get_theme_support( 'hybrid-core-javascript' );
-
- /* Register the 'drop-downs' script if the current theme supports 'hybrid-core-drop-downs'. */
- if ( current_theme_supports( 'hybrid-core-drop-downs' ) || ( isset( $supports[0] ) && in_array( 'drop-downs', $supports[0] ) ) )
- wp_register_script( 'drop-downs', esc_url( apply_atomic( 'drop_downs_script', trailingslashit( HYBRID_JS ) . 'drop-downs.js' ) ), array( 'jquery' ), '20110920', true );
-
- /* Register the 'nav-bar' script if the current theme supports 'hybrid-core-nav-bar'. */
- if ( isset( $supports[0] ) && in_array( 'nav-bar', $supports[0] ) )
- wp_register_script( 'nav-bar', esc_url( apply_atomic( 'nav_bar_script', trailingslashit( HYBRID_JS ) . 'nav-bar.js' ) ), array( 'jquery' ), '20111008', true );
-}
-
-/**
- * Tells WordPress to load the scripts needed for the framework using the wp_enqueue_script() function.
- *
- * @since 1.2.0
- * @access private
- * @return void
- */
-function hybrid_enqueue_scripts() {
-
- /* Supported JavaScript. */
- $supports = get_theme_support( 'hybrid-core-javascript' );
-
- /* Load the comment reply script on singular posts with open comments if threaded comments are supported. */
- if ( is_singular() && get_option( 'thread_comments' ) && comments_open() )
- wp_enqueue_script( 'comment-reply' );
-
- /* Load the 'drop-downs' script if the current theme supports 'hybrid-core-drop-downs'. */
- if ( current_theme_supports( 'hybrid-core-drop-downs' ) || ( isset( $supports[0] ) && in_array( 'drop-downs', $supports[0] ) ) )
- wp_enqueue_script( 'drop-downs' );
-
- /* Load the 'nav-bar' script if the current theme supports 'hybrid-core-nav-bar'. */
- if ( isset( $supports[0] ) && in_array( 'nav-bar', $supports[0] ) )
- wp_enqueue_script( 'nav-bar' );
-}
-
-/**
- * Function for using a debug stylesheet when developing. To develop with the debug stylesheet,
- * SCRIPT_DEBUG must be set to 'true' in the 'wp-config.php' file. This will check if a 'style.dev.css'
- * file is present within the theme folder and use it if it exists. Else, it defaults to 'style.css'.
- *
- * @since 0.9.0
- * @access private
- * @param string $stylesheet_uri The URI of the active theme's stylesheet.
- * @param string $stylesheet_dir_uri The directory URI of the active theme's stylesheet.
- * @return string $stylesheet_uri
- */
-function hybrid_debug_stylesheet( $stylesheet_uri, $stylesheet_dir_uri ) {
-
- /* If SCRIPT_DEBUG is set to true and the theme supports 'dev-stylesheet'. */
- if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG && current_theme_supports( 'dev-stylesheet' ) ) {
-
- /* Remove the stylesheet directory URI from the file name. */
- $stylesheet = str_replace( trailingslashit( $stylesheet_dir_uri ), '', $stylesheet_uri );
-
- /* Change the stylesheet name to 'style.dev.css'. */
- $stylesheet = str_replace( '.css', '.dev.css', $stylesheet );
-
- /* If the stylesheet exists in the stylesheet directory, set the stylesheet URI to the dev stylesheet. */
- if ( file_exists( trailingslashit( get_stylesheet_directory() ) . $stylesheet ) )
- $stylesheet_uri = trailingslashit( $stylesheet_dir_uri ) . $stylesheet;
- }
-
- /* Return the theme stylesheet. */
- return $stylesheet_uri;
-}
-
-/**
* Adds theme/plugin custom images sizes added with add_image_size() to the image uploader/editor. This
* allows users to insert these images within their post content editor.
*
View
69 functions/scripts.php
@@ -0,0 +1,69 @@
+<?php
+/**
+ * Functions for handling JavaScript in the framework. Themes can add support for the
+ * 'hybrid-core-javascript' feature to allow the framework to handle loading the stylesheets into
+ * the theme header or footer at an appropriate time.
+ *
+ * @package HybridCore
+ * @subpackage Functions
+ * @author Justin Tadlock <justin@justintadlock.com>
+ * @copyright Copyright (c) 2008 - 2012, Justin Tadlock
+ * @link http://themehybrid.com/hybrid-core
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ */
+
+/* Register Hybrid Core scripts. */
+add_action( 'wp_enqueue_scripts', 'hybrid_register_scripts', 1 );
+
+/* Load Hybrid Core scripts. */
+add_action( 'wp_enqueue_scripts', 'hybrid_enqueue_scripts' );
+
+/**
+ * Registers JavaScript files for the framework. This function merely registers scripts with WordPress using
+ * the wp_register_script() function. It does not load any script files on the site. If a theme wants to register
+ * its own custom scripts, it should do so on the 'wp_enqueue_scripts' hook.
+ *
+ * @since 1.2.0
+ * @access private
+ * @return void
+ */
+function hybrid_register_scripts() {
+
+ /* Supported JavaScript. */
+ $supports = get_theme_support( 'hybrid-core-javascript' );
+
+ /* Register the 'drop-downs' script if the current theme supports 'hybrid-core-drop-downs'. */
+ if ( current_theme_supports( 'hybrid-core-drop-downs' ) || ( isset( $supports[0] ) && in_array( 'drop-downs', $supports[0] ) ) )
+ wp_register_script( 'drop-downs', esc_url( apply_atomic( 'drop_downs_script', trailingslashit( HYBRID_JS ) . 'drop-downs.js' ) ), array( 'jquery' ), '20110920', true );
+
+ /* Register the 'nav-bar' script if the current theme supports 'hybrid-core-nav-bar'. */
+ if ( isset( $supports[0] ) && in_array( 'nav-bar', $supports[0] ) )
+ wp_register_script( 'nav-bar', esc_url( apply_atomic( 'nav_bar_script', trailingslashit( HYBRID_JS ) . 'nav-bar.js' ) ), array( 'jquery' ), '20111008', true );
+}
+
+/**
+ * Tells WordPress to load the scripts needed for the framework using the wp_enqueue_script() function.
+ *
+ * @since 1.2.0
+ * @access private
+ * @return void
+ */
+function hybrid_enqueue_scripts() {
+
+ /* Supported JavaScript. */
+ $supports = get_theme_support( 'hybrid-core-javascript' );
+
+ /* Load the comment reply script on singular posts with open comments if threaded comments are supported. */
+ if ( is_singular() && get_option( 'thread_comments' ) && comments_open() )
+ wp_enqueue_script( 'comment-reply' );
+
+ /* Load the 'drop-downs' script if the current theme supports 'hybrid-core-drop-downs'. */
+ if ( isset( $supports[0] ) && in_array( 'drop-downs', $supports[0] ) )
+ wp_enqueue_script( 'drop-downs' );
+
+ /* Load the 'nav-bar' script if the current theme supports 'hybrid-core-nav-bar'. */
+ if ( isset( $supports[0] ) && in_array( 'nav-bar', $supports[0] ) )
+ wp_enqueue_script( 'nav-bar' );
+}
+
+?>
View
153 functions/styles.php
@@ -0,0 +1,153 @@
+<?php
+/**
+ * Functions for handling stylesheets in the framework. Themes can add support for the
+ * 'hybrid-core-css' feature to allow the framework to handle loading the stylesheets into the
+ * theme header at an appropriate point.
+ *
+ * @package HybridCore
+ * @subpackage Functions
+ * @author Justin Tadlock <justin@justintadlock.com>
+ * @copyright Copyright (c) 2008 - 2012, Justin Tadlock
+ * @link http://themehybrid.com/hybrid-core
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ */
+
+/* Register Hybrid Core styles. */
+add_action( 'wp_enqueue_scripts', 'hybrid_register_styles', 1 );
+
+/* Load Hybrid Core styles. */
+add_action( 'wp_enqueue_scripts', 'hybrid_enqueue_styles', 5 );
+
+/* Load the development stylsheet in script debug mode. */
+add_filter( 'stylesheet_uri', 'hybrid_debug_stylesheet', 10, 2 );
+
+/**
+ * Registers stylesheets for the framework. This function merely registers styles with WordPress using
+ * the wp_register_style() function. It does not load any stylesheets on the site. If a theme wants to
+ * register its own custom styles, it should do so on the 'wp_enqueue_scripts' hook.
+ *
+ * @since 1.5.0
+ * @access private
+ * @return void
+ */
+function hybrid_register_styles() {
+
+ /* Get framework styles. */
+ $styles = hybrid_get_styles();
+
+ /* Loop through each style and register it. */
+ foreach ( $styles as $style => $args ) {
+
+ $defaults = array(
+ 'handle' => $style,
+ 'src' => trailingslashit( HYBRID_CSS ) . "{$style}.css",
+ 'deps' => null,
+ 'version' => false,
+ 'media' => 'all'
+ );
+
+ $args = wp_parse_args( $args, $defaults );
+
+ wp_register_style(
+ sanitize_key( $args['handle'] ),
+ esc_url( $args['src'] ),
+ is_array( $args['deps'] ) ? $args['deps'] : null,
+ preg_replace( '/[^a-z0-9_\-.]/', '', strtolower( $args['version'] ) ),
+ esc_attr( $args['media'] )
+ );
+ }
+}
+
+/**
+ * Tells WordPress to load the styles needed for the framework using the wp_enqueue_style() function.
+ *
+ * @since 1.5.0
+ * @access private
+ * @return void
+ */
+function hybrid_enqueue_styles() {
+
+ /* Get the theme-supported stylesheets. */
+ $supports = get_theme_support( 'hybrid-core-css' );
+
+ /* If the theme doesn't add support for any styles, return. */
+ if ( !is_array( $supports[0] ) )
+ return;
+
+ /* Get framework styles. */
+ $styles = hybrid_get_styles();
+
+ /* Loop through each of the core framework styles and enqueue them if supported. */
+ foreach ( $styles as $style => $args ) {
+
+ if ( in_array( $style, $supports[0] ) )
+ wp_enqueue_style( $style );
+ }
+}
+
+/**
+ * Returns an array of the core framework's available styles for use in themes.
+ *
+ * @since 1.5.0
+ * @access private
+ * @return array $styles All the available framework styles.
+ */
+function hybrid_get_styles() {
+
+ $styles = array(
+ '18px' => array( 'version' => '20110523' ),
+ '20px' => array( 'version' => '20110523' ),
+ '21px' => array( 'version' => '20110523' ),
+ '22px' => array( 'version' => '20110523' ),
+ '24px' => array( 'version' => '20110523' ),
+ '25px' => array( 'version' => '20110523' ),
+ 'drop-downs' => array( 'version' => '20110919' ),
+ 'nav-bar' => array( 'version' => '20110519' ),
+ 'gallery' => array( 'version' => '20120222' ),
+ );
+
+ /* If a child theme is active, add the parent theme's style. */
+ if ( is_child_theme() ) {
+ $parent = wp_get_theme( get_template(), get_theme_root( get_template_directory() ) );
+ $styles['parent'] = array( 'src' => trailingslashit( THEME_URI ) . 'style.css', 'version' => $parent->get( 'Version' ) );
+ }
+
+ /* Add the active theme style. */
+ $styles['style'] = array( 'src' => get_stylesheet_uri(), 'version' => wp_get_theme()->get( 'Version' ) );
+
+ /* Return the array of styles. */
+ return $styles;
+}
+
+/**
+ * Function for using a debug stylesheet when developing. To develop with the debug stylesheet,
+ * SCRIPT_DEBUG must be set to 'true' in the 'wp-config.php' file. This will check if a 'style.dev.css'
+ * file is present within the theme folder and use it if it exists. Else, it defaults to 'style.css'.
+ *
+ * @since 0.9.0
+ * @access private
+ * @param string $stylesheet_uri The URI of the active theme's stylesheet.
+ * @param string $stylesheet_dir_uri The directory URI of the active theme's stylesheet.
+ * @return string $stylesheet_uri
+ */
+function hybrid_debug_stylesheet( $stylesheet_uri, $stylesheet_dir_uri ) {
+
+ /* If SCRIPT_DEBUG is set to true and the theme supports 'dev-stylesheet'. */
+ if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG && current_theme_supports( 'dev-stylesheet' ) ) {
+
+ /* Remove the stylesheet directory URI from the file name. */
+ $stylesheet = str_replace( trailingslashit( $stylesheet_dir_uri ), '', $stylesheet_uri );
+
+ /* Change the stylesheet name to 'style.dev.css'. */
+ $stylesheet = str_replace( '.css', '.dev.css', $stylesheet );
+
+ /* If the stylesheet exists in the stylesheet directory, set the stylesheet URI to the dev stylesheet. */
+ if ( file_exists( trailingslashit( get_stylesheet_directory() ) . $stylesheet ) )
+ $stylesheet_uri = trailingslashit( $stylesheet_dir_uri ) . $stylesheet;
+ }
+
+ /* Return the theme stylesheet. */
+ return $stylesheet_uri;
+}
+
+?>
View
6 hybrid.php
@@ -269,6 +269,12 @@ function functions() {
/* Load the template hierarchy if supported. */
require_if_theme_supports( 'hybrid-core-template-hierarchy', trailingslashit( HYBRID_FUNCTIONS ) . 'template-hierarchy.php' );
+ /* Load the styles if supported. */
+ require_if_theme_supports( 'hybrid-core-css', trailingslashit( HYBRID_FUNCTIONS ) . 'styles.php' );
+
+ /* Load the scripts if supported. */
+ require_if_theme_supports( 'hybrid-core-javascript', trailingslashit( HYBRID_FUNCTIONS ) . 'scripts.php' );
+
/* Load the deprecated functions if supported. */
require_if_theme_supports( 'hybrid-core-deprecated', trailingslashit( HYBRID_FUNCTIONS ) . 'deprecated.php' );
}

No commit comments for this range

Something went wrong with that request. Please try again.