Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Post Stylesheets is now officially an extension.

git-svn-id: http://svn.locallylost.com/themes/hybrid-core/trunk@368 dba0f204-706d-4bc1-bc29-8b92e0485636
  • Loading branch information...
commit 982c613430a9862ad2c6b026f206d9305e2910a6 1 parent 8148bbb
greenshady authored
View
12 classes/hybrid.php
@@ -58,10 +58,6 @@ function init() {
/* Load theme extensions later since we need to check if they're supported. */
add_action( 'after_setup_theme', array( &$this, 'extensions' ), 12 );
- /* Load the default action and filters after the theme is set up. */
- //add_action( 'after_setup_theme', array( &$this, 'actions' ), 13 );
- //add_action( 'after_setup_theme', array( &$this, 'filters' ), 13 );
-
/* Load theme textdomain. */
$domain = hybrid_get_textdomain();
$locale = get_locale();
@@ -142,10 +138,6 @@ function functions() {
require_once( HYBRID_FUNCTIONS . '/shortcodes.php' );
require_once( HYBRID_FUNCTIONS . '/template.php' );
require_once( HYBRID_FUNCTIONS . '/widgets.php' );
-
- /* Load the Hybrid theme functions if it's the parent theme. */
- //if ( 'hybrid' == get_template() )
- // require_once( HYBRID_FUNCTIONS . '/defaults.php' );
}
/**
@@ -178,6 +170,9 @@ function extensions() {
/* Load the Post Layouts extension if supported. */
require_if_theme_supports( 'post-layouts', HYBRID_EXTENSIONS . '/post-layouts.php' );
+ /* Load the Post Stylesheets extension if supported. */
+ require_if_theme_supports( 'post-stylesheets', HYBRID_EXTENSIONS . '/post-stylesheets.php' );
+
/* Load the temporary core SEO component. */
require_if_theme_supports( 'hybrid-core-seo', HYBRID_FUNCTIONS . '/core-seo.php' );
}
@@ -245,7 +240,6 @@ function filters() {
add_filter( 'get_the_author_description', 'do_shortcode' );
/* Stylesheet filters. */
- add_filter( 'stylesheet_uri', 'hybrid_post_stylesheets', 10, 2 );
add_filter( 'stylesheet_uri', 'hybrid_debug_stylesheet', 10, 2 );
/* Template filters. */
View
51 extensions/post-stylesheets.php
@@ -0,0 +1,51 @@
+<?php
+/**
+ * Post Stylesheets allows users and developers to add unique, per-post stylesheets. This script was created so
+ * that custom stylesheet files could be dropped into a theme's '/css' folder and loaded for individual posts using
+ * the 'Stylesheet' post meta key and the stylesheet name as the post meta value.
+ *
+ * @copyright 2010
+ * @version 0.1.0
+ * @author Justin Tadlock
+ * @link http://justintadlock.com
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * @package PostStylesheets
+ */
+
+/* Filters stylesheet_uri with a function for adding a new style. */
+add_filter( 'stylesheet_uri', 'post_stylesheets_stylesheet_uri', 10, 2 );
+
+/**
+ * Checks if a post (or any post type) has the given meta key of 'Stylesheet' when on the singular view of the post
+ * on the front of the site. If found, the function checks within the '/css' folder of the stylesheet directory
+ * (child theme). If the file exists, it is used rather than the typical style.css file.
+ *
+ * @since 0.1.0
+ */
+function post_stylesheets_stylesheet_uri( $stylesheet_uri, $stylesheet_dir_uri ) {
+ global $wp_query;
+
+ /* Check if viewing a singular post. */
+ if ( is_singular() ) {
+
+ /* Allow plugin/theme developers to override the default meta key. */
+ $meta_key = apply_filters( 'post_stylesheets_meta_key', 'Stylesheet' );
+
+ /* Check if the user has set a value for the post stylesheet. */
+ $stylesheet = get_post_meta( $wp_query->post->ID, $meta_key, true );
+
+ /* If a meta value was given and the file exists, set $stylesheet_uri to the new file. */
+ if ( !empty( $stylesheet ) && file_exists( get_stylesheet_directory() . "/css/{$stylesheet}" ) )
+ $stylesheet_uri = $stylesheet_dir_uri . "/css/{$stylesheet}";
+ }
+
+ /* Return the stylesheet URI. */
+ return $stylesheet_uri;
+}
+
+?>
View
20 functions/media.php
@@ -29,26 +29,6 @@ function hybrid_debug_stylesheet( $stylesheet_uri, $stylesheet_dir_uri ) {
}
/**
- * Checks for a custom field called 'Stylesheet' for a CSS file name in the form of 'example.css'.
- * If the file exists in the child theme '/css' folder, replace the normal 'style.css' used with this
- * file for the singular view of the post.
- *
- * @since 0.9
- */
-function hybrid_post_stylesheets( $stylesheet_uri, $stylesheet_dir_uri ) {
- global $wp_query;
-
- if ( is_singular() && current_theme_supports( 'post-stylesheets' ) ) {
- $stylesheet = get_post_meta( $wp_query->post->ID, 'Stylesheet', true );
-
- if ( !empty( $stylesheet ) && file_exists( get_stylesheet_directory() . "/css/{$stylesheet}" ) )
- $stylesheet_uri = $stylesheet_dir_uri . "/css/{$stylesheet}";
- }
-
- return $stylesheet_uri;
-}
-
-/**
* Function to load CSS at an appropriate time. Adds print.css if user chooses to use it.
* Users should load their own CSS using wp_enqueue_style() in their child theme's
* functions.php file.
View
11 legacy/deprecated.php
@@ -252,6 +252,17 @@ function hybrid_add_theme_support() {
add_theme_support( 'hybrid-core-theme-settings' );
}
+/**
+ * Per-post stylesheets. Moved to the post-stylesheets.php extension.
+ *
+ * @since 0.9
+ * @deprecated 0.9.1
+ */
+function hybrid_post_stylesheets( $deprecated_1 = '', $deprecated_2 = '') {
+ _deprecated_function( __FUNCTION__, '0.9.1', 'post_stylesheets_stylesheet_uri()' );
+ return post_stylesheets_stylesheet_uri( $deprecated_1, $deprecated_2 );
+}
+
/* === Removed Functions === */
/* Functions removed in the 0.5 branch. */
Please sign in to comment.
Something went wrong with that request. Please try again.