Last active
February 12, 2016 21:57
-
-
Save deckerweb/4960565 to your computer and use it in GitHub Desktop.
For Genesis Child Themes in Multisite -- one child theme for lots of sub sites: Pull in site-specific functions & stylesheet files, if available.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* General Usage: | |
* Set "child-theme-slug" to the main child theme slug. Set "id" to actual Blog/ Site ID. | |
* Current: For Multisite installs that were made with 3.5+ | |
* a) Place functions files in wp-content/uploads/sites/{id}/{child-theme-slug}/functions-site-{id}.php | |
* b) Place stylesheet files in wp-content/uploads/sites/{id}/{child-theme-slug}/styles-site-{id}.php | |
* | |
* Backward compatibility for Multisite installs that were made prior 3.5 | |
* c) Place functions files in wp-content/blogs.dir/{id}/files/{child-theme-slug}/functions-site-{id}.php | |
* d) Place stylesheet files in wp-content/blogs.dir/{id}/files/{child-theme-slug}/styles-site-{id}.php | |
* | |
* @author David Decker - DECKERWEB | |
* @link http://deckerweb.de/twitter | |
*/ | |
/** | |
* Get the Blog/ Site upload location location for URL or path, and for multisite or not. | |
* | |
* Takes account of multisite usage, and domain mapping. | |
* | |
* @author StudioPress | |
* @link http://www.studiopress.com/ | |
* @author David Decker - DECKERWEB | |
* @link http://deckerweb.de/twitter | |
* | |
* @param string $type Either 'url' or anything else e.g. 'path' | |
* | |
* @return string | |
*/ | |
function ddw_get_site_upload_location( $type ) { | |
/** Get the uploads directory -- supports Multisite of course */ | |
$uploads = wp_upload_dir(); | |
$dir = ( 'url' == $type ) ? $uploads['baseurl'] : $uploads['basedir']; | |
$child_slug = wp_get_theme(); | |
/** Return Blog/ Site upload location */ | |
return apply_filters( 'ddw_get_site_upload_location', $dir . '/' . $child_slug . '/' ); | |
} // end function | |
add_action( 'after_setup_theme', 'ddw_include_site_specific_functions', 10 ); | |
/** | |
* Pull in site-specific functions files, if available. | |
* | |
* @author David Decker - DECKERWEB | |
* @link http://deckerweb.de/twitter | |
* | |
* @param $site_file | |
* | |
* @global integer $blog_id | |
*/ | |
function ddw_include_site_specific_functions() { | |
/** Get the Blog/ Site ID within Multisite */ | |
global $blog_id; | |
/** Set a site specific functions file */ | |
$site_file = ddw_get_site_upload_location( 'path' ) . 'functions-site-' . $blog_id . '.php'; | |
/** Check for file and include it */ | |
if ( is_readable( $site_file ) ) { | |
require_once( $site_file ); | |
} // end if file check | |
} // end function | |
add_action( 'wp_enqueue_scripts', 'ddw_include_site_specific_scripts', 10 ); | |
/** | |
* Pull in site-specific scripts or stylesheet files, if available. | |
* | |
* @author David Decker - DECKERWEB | |
* @link http://deckerweb.de/twitter | |
* | |
* @param $site_file_path | |
* @param $site_file_url | |
* | |
* @global integer $blog_id | |
*/ | |
function ddw_include_site_specific_scripts() { | |
/** Get the Blog/ Site ID within Multisite */ | |
global $blog_id; | |
/** Set a site specific functions file */ | |
$site_file_path = ddw_get_site_upload_location( 'path' ) . 'styles-site-' . $blog_id . '.css'; | |
$site_file_url = ddw_get_site_upload_location( 'url' ) . 'styles-site-' . $blog_id . '.css'; | |
/** Check for file and include it */ | |
if ( is_readable( $site_file_path ) ) { | |
/** Register the stylesheet */ | |
wp_register_style( 'site-styles', $site_file_url, array(), time(), 'all' ); | |
/** Enqueue the stylesheet */ | |
wp_enqueue_style( 'site-styles' ); | |
} // end if file check | |
} // end function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment