';
}
}
}
// Login Header URL
// ----------------
if (!function_exists('bioship_muscle_login_headerurl')) {
add_filter('login_headerurl', 'bioship_muscle_login_headerurl' );
function bioship_muscle_login_headerurl($vurl) {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__,func_get_args());}
$vurl = site_url('/'); return $vurl;
}
}
// Login Header Title
// ------------------
if (!function_exists('bioship_muscle_login_headertitle')) {
add_filter('login_headertitle', 'bioship_muscle_login_headertitle');
function bioship_muscle_login_headertitle($vtitle) {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__,func_get_args());}
$title = get_bloginfo('name'); return $vtitle;
}
}
// Login Page Logo
// ---------------
// (adds a #loginwrapper element to help styling)
// 1.8.5: fun with login wrapper hacks!
if (!function_exists('bioship_muscle_login_styles')) {
add_action('login_head', 'bioship_muscle_login_styles');
function bioship_muscle_login_styles() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
add_filter('login_body_class','bioship_muscle_login_body_hack',999);
if (!function_exists('bioship_muscle_login_body_hack')) {
function bioship_muscle_login_body_hack($vclasses) {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__,func_get_args());}
$vclasses[] = 'LOGINWRAPPER';
add_filter('attribute_escape', 'bioship_muscle_login_body_filter_hack', 999, 2);
return $vclasses;
}
}
if (!function_exists('bioship_muscle_login_body_filter_hack')) {
function bioship_muscle_login_body_filter_hack($safe_text, $text) {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__,func_get_args());}
$replace = '">
";
}
}
// 1.8.5: moved actual login styling to skin.php
}
}
// ====================
// --- Integrations ---
// ====================
// -----------
// WooCommerce
// -----------
// WooCommerce Template Directory
// ------------------------------
// Changes directory for Woocommerce templates (for both child and parent theme directories)
// intended so you could use: /theme/theme-name/templates/woocommerce/
// instead of the default: /theme/theme-name/woocommerce/
// (as a better way of organizing 3rd party templates)
// WARNING: use one directory OR the other, it is not a hierarchy so you cannot use both!
// WooCommerce Template Path Filter
// --------------------------------
if (class_exists('WC_Template_Loader')) {
add_filter('woocommerce_template_path','bioship_muscle_woocommerce_template_path');
if (!function_exists('bioship_muscle_woocommerce_template_path')) {
function bioship_muscle_woocommerce_template_path($vpath) {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__,func_get_args());}
// 1.9.5: added this filter to allow further change
// override woocommerce/ to (filtered) templates/woocommerce/
$vnewpath = bioship_apply_filters('skeleton_woocommerce_template_directory', 'templates/woocommerce/');
global $vthemetemplatedir, $vthemestyledir;
if ( (is_dir($vthemetemplatedir.$vnewpath)) || (is_dir($vthemestyledir.$vnewpath)) ) {
// 1.9.5: only if new template directory exists do we apply other template filters
add_filter('wc_get_template', 'bioship_muscle_woocommerce_template', 10, 5);
add_filter('wc_get_template_part', 'bioship_muscle_woocommerce_template_part', 10, 3);
return $vnewpath;
}
else {return $vpath;}
}
}
}
// /= Woocommerce Template subdirectories Templates =/
// ---------------------------------------------------
if (function_exists('wc_get_template')) {
if (!function_exists('bioship_muscle_woocommerce_template')) {
function bioship_muscle_woocommerce_template($located, $template_name, $args, $template_path, $default_path) {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__,func_get_args());}
// find the new template via file hierarchy
// looking in templates/woocommerce/ then woocommerce/
// 1.9.5: apply the template directory filter and search that only
$vnewpath = bioship_apply_filters('skeleton_woocommerce_template_directory', 'templates/woocommerce/');
$vnewtemplate = bioship_file_hierarchy('file', $template_name, array($vnewpath));
// write debug info (kept here as useful for finding templates)
// ob_start();
// echo "new template: "; print_r($vnewtemplate); echo PHP_EOL;
// echo "located: "; print_r($located); echo PHP_EOL;
// echo "template_name: "; print_r($template_name); echo PHP_EOL;
// $vdata = ob_get_contents(); ob_end_clean();
// bioship_write_debug_file('woo-templates.txt',$vdata);
// return the new template location if found
if ($vnewtemplate) {return $vnewtemplate;}
return $located;
}
}
}
// Woocommerce Template Parts
// --------------------------
// eg. single-product-content.php and anything retrieved by wc_get_template_part
if (function_exists('wc_get_template_part')) {
if (!function_exists('bioship_muscle_woocommerce_template_part')) {
function bioship_muscle_woocommerce_template_part($vtemplate,$vslug,$vname) {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__,func_get_args());}
// 1.9.5: apply the template directory filter and search that only
$vnewpath = bioship_apply_filters('skeleton_woocommerce_template_directory', 'templates/woocommerce/');
// get slug-name template via file hierarchy
$vnewtemplate = bioship_file_hierarchy('file', $vslug.'-'.$vname.'.php', array($vnewpath));
// include a fallback to slug based template
$vslugtemplate = bioship_file_hierarchy('file', $vslug.'.php', array($vnewpath));
// write debug info (kept here as useful for finding templates)
// ob_start();
// echo "name template (".$vname."): "; print_r($vnewtemplate); echo PHP_EOL;
// echo "slug template (".$vslug."): "; print_r($vslugtemplate); echo PHP_EOL;
// $vdata = ob_get_contents(); ob_end_clean();
// bioship_write_debug_file('woo-template-parts.txt',$vdata)l
// maybe return the altered template location
if ($vnewtemplate) {return $vnewtemplate;}
if ($vslugtemplate) {return $vslugtemplate;}
return $vtemplate;
}
}
}
// -----------------------------
// Open Graph Framework Protocol
// -----------------------------
// ..yah down wid OGP? yeah u know me..
// Ref: http://www.itthinx.com/plugins/open-graph-protocol/
// Set Open Graph Protocol Default Image
// -------------------------------------
// 1.5.0: added default image meta
// requires Open Graph Protocol plugin to be installed and active
// note: if using Jetpack see filter: jetpack_open_graph_image_default
if (!function_exists('bioship_muscle_open_graph_default_image')) {
// 2.0.5: move filter inside for consistency
add_filter('open_graph_protocol_metas','bioship_muscle_open_graph_default_image');
function bioship_muscle_open_graph_default_image($vmetas) {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__,func_get_args());}
global $vthemename, $vthemesettings, $vthemedirs;
// allow for open graph image override filter
// see next func for i-built custom field override
// you can add more conditional overrides via filters.php
$vimage = array();
if (isset($vmetas['og:image:width'])) {$vimage[0] = $vmetas['og:image:width'];}
if (isset($vmetas['og:image:height'])) {$vimage[1] = $vmetas['og:image:height'];}
if (isset($vmetas['og:image'])) {$vimage[2] = $vmetas['og:image'];}
$vimage = bioship_apply_filters('muscle_open_graph_override_image', $vimage);
// if we now have an image and it is a different URL
if (isset($vimage[2])) {
if ($vimage[2] != $vmetas['og:image']) {
// allow override to turn this meta off completely
if ($vimage[2] == 'off') {return array();}
// image has been changed/updated, check for new width and height
if ( (isset($vimage[0])) && (isset($vimage[1])) ) {
$vmetas['og:image:width'] = $vimage[0];
$vmetas['og:image:height'] = $vimage[1];
$vmetas['og:image'] = $vimage[2];
}
else {
// otherwise, use getimagesize (slower)
if (!ini_get('allow_url_fopen')) {
$vfilepath = ABSPATH.parse_url($vurl, PHP_URL_PATH);
if (file_exists($vfilepath)) {$vurltofilepath = true;}
}
if ( (ini_get('allow_url_fopen')) || ($vurltofilepath) ) {
if ($vurltofilepath) {$vimagesize = getimagesize($vfilepath);}
else {$vimagesize = getimagesize($vimage[2]);}
if ($vimagesize) {
$vmetas['og:image:width'] = $vimagesize[0];
$vmetas['og:image:height'] = $vimagesize[1];
$vmetas['og:image'] = $vimage[2];
}
}
}
}
else {
// same URL, maybe a change in size though
// as it is an override, just do that
$vmetas['og:image:width'] = $vimage[0];
$vmetas['og:image:height'] = $vimage[1];
}
}
// default (fallback) open graph image option
if (!isset($vmetas['og:image'])) {
// maybe pick the largest size if set to precomposed apple touch icons
// 1.9.6: removed this code as even 192 does not meet OG minimum of 200
// if ($vthemesettings['ogdefaultimage'] == 'appletouchicon') {
// $vsizes = array('192','180','152','144','120','114','75','72');
// $vfound = false;
// foreach ($vsizes as $vsize) {
// if (!$vfound) {
// $vcheckurl = bioship_file_hierarchy('url','touch-icon-'.$vsize.'x'.$vsize.'-precomposed.png',$vthemedirs['img']);
// if ($vcheckurl) {$vurl = $vcheckurl; $vfound = true;}
// }
// }
// }
// else {
// otherwise, set the url based on the theme options => suboption
$vkey = $vthemesettings['ogdefaultimage'];
if ($vkey == '') {$vkey = 'header_logo';}
// 1.9.5: fix for uploaded default image
$vurl = $vthemesettings[$vkey];
if (THEMEDEBUG) {echo "";}
// }
// allow for default image filter
$vurl = bioship_apply_filters('muscle_open_graph_default_image_url', $vurl);
if ($vurl != '') {
// best to cache image size like in skin.php header logo for getimagesize
// ...but again need to check for allow_url_fopen to do that
if (!ini_get('allow_url_fopen')) {
// try to convert the url to filepath instead
$vfilepath = ABSPATH.parse_url($vurl, PHP_URL_PATH);
if (file_exists($vfilepath)) {$vurltofilepath = true;}
// echo "**".$vfilepath."**"; // debug point
}
if ( (ini_get('allow_url_fopen')) || ($vurltofilepath) ) {
$vimagesize = get_option($vthemename.'_ogdefaultimage');
if (strstr($vimagesize,':')) {
$vimagesize = explode(':',$vimagesize);
if ($vimagesize[2] != $vurl) {
if ($vurltofilepath) {$vimagesize = getimagesize($vfilepath);}
else {$vimagesize = getimagesize($vurl);}
if ($vimagesize) {
$vimagedata = $vimagesize[0].':'.$vimagesize[1].':'.$vurl;
// 2.0.5: remove unnecessary add_option fallback
update_option($vthemename.'_ogdefaultimage', $vimagedata);
}
}
}
else {
if ($vurltofilepath) {$vimagesize = getimagesize($vfilepath);}
else {$vimagesize = getimagesize($vurl);}
if ($vimagesize) {
$vimagedata = $vimagesize[0].':'.$vimagesize[1].':'.$vurl;
// 2.0.5: remove unnecessary add_option fallback
update_option($vthemename.'_ogdefaultimage', $vimagedata);
}
}
if ($vimagesize) {
$vmetas['og:image'] = $vurl;
$vmetas['og:image:width'] = $vimagesize[0];
$vmetas['og:image:height'] = $vimagesize[1];
}
}
else {
// no allow_fopen_url and filepath failed :-(
// rely on a matching explicit width/height set via filter
$vimagesize = bioship_apply_filters('muscle_open_graph_default_image_size',array());
if ( (isset($vimagesize[0])) && (isset($vimagesize[1])) ) {
$vmetas['og:image'] = $vurl;
$vmetas['og:image:width'] = $imagesize[0];
$vmetas['og:image:height'] = $imagesize[1];
}
}
}
}
// 1.9.6: fix some mismatching WP to FB locales
// ...there may be a number more of these?
// http://www.roseindia.net/tutorials/i18n/locales-list.shtml
// https://www.facebook.com/translations/FacebookLocales.xml
if ($vmetas['og:locale'] == 'en_AU') {$vmetas['og:locale'] = 'en_GB';}
if ($vmetas['og:locale'] == 'ja') {$vmetas['og:locale'] = 'ja_JP';}
if ($vmetas['og:locale'] == 'iw_IL') {$vmetas['og:locale'] = 'he_IL';}
if (THEMEDEBUG) {echo "";}
return $vmetas;
}
}
// Add Custom Field Override for the Open Graph image
// --------------------------------------------------
// 1.5.0: added this opengraph override
// requires the Open Graph Protocol plugin to be installed and active
// by default the plugin only sets the featured image if there is one
// this lets you add custom image fields on a post/page screen and have them used:
// opengraphimageurl (required), opengraphimagewidth, opengraphimageheight
if (!function_exists('bioship_muscle_open_graph_override_image_fields')) {
// 2.0.5: moved inside for consistency
add_filter('muscle_open_graph_override_image', 'bioship_muscle_open_graph_override_image_fields', 0);
function bioship_muscle_open_graph_override_image_fields($vimage) {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__,func_get_args());}
// override existing open graph image meta with post custom field meta
// better to set width and height field values but not totally necessary
global $post; $vpostid = $post->ID;
$vogimage[0] = get_post_meta($vpostid, 'opengraphimagewidth', true);
$vogimage[1] = get_post_meta($vpostid, 'opengraphimageheight', true);
$vogimage[2] = get_post_meta($vpostid, 'opengraphimageurl', true);
// to remove the image for this page, can set opengraphimageurl value to 'off'
if ($vogimage[2] == 'off') {return array();}
// the URL on the other hand needs to be there, or we just return
if ($vogimage[2] != '') {return $vogimage;}
return $vimage;
}
}
// -----------
// Hybrid Hook
// -----------
// (does not require Hybrid Core to be loaded)
// (note: Hybrid Hook Widgets is available also)
// 2.0.1: filter Hybrid Hook loading here
$vloadhybridhook = false;
if (isset($vthemesettings['hybridhook'])) {$vloadhybridhook = $vthemesettings['hybridhook'];}
$vloadhybridhook = bioship_apply_filters('muscle_load_hybrid_hook', $vloadhybridhook);
if ($vloadhybridhook == '1') {
// 1.8.0: changed hybrid hook location to /includes/ subfolder
$vhybridhook = bioship_file_hierarchy('file', 'hybrid-hook.php', array('includes/hybrid-hook'));
if ($vhybridhook) {
include($vhybridhook);
if (THEMEDEBUG) {echo "".PHP_EOL;}
// load it now as we have missed the plugins_loaded hook
hybrid_hook_setup();
// 1.8.5: dissallow hybrid hook PHP execution via filter (as e-v-a-l commented out for Theme Check)
// (HTML / Shortcode / Widget methods are better anyway)
add_filter('hybrid_hook_allow_php', 'bioship_muscle_disallow_hook_php', 5);
if (!function_exists('bioship_muscle_disallow_hook_php')) {
function bioship_muscle_disallow_hook_php($v) {return false;}
}
// Load the theme layout hooks
add_filter('hybrid_hooks', 'bioship_muscle_hybrid_get_hooks');
if (!function_exists('bioship_muscle_hybrid_get_hooks')) {
function bioship_muscle_hybrid_get_hooks() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
// 1.9.0: hooks now loaded by default in functions.php
global $vthemehooks;
if (THEMEDEBUG) {echo "";}
// 1.9.0: handle admin metabox defaults
if (is_admin()) {
// 1.8.5: default the hybrid hook metaboxes to closed
// ref: https://surniaulula.com/2013/05/29/collapse-close-wordpress-metaboxes/
$vuserid = get_current_user_id();
$voptionkey = 'closedpostboxes_'.'appearance_page_'.'hybrid-hook-settings';
if ( (isset($_REQUEST['metaboxes'])) && ($_REQUEST['metaboxes'] == 'reset') ) {
delete_user_option($voptionkey, $vuserid);
} else {$vclosedboxes = get_user_option($voptionkey, $vuserid);}
// create an empty array if get_user_option() had nothing to return
if (!is_array($vclosedboxes)) {$vclosedboxes = array();
foreach ($vthemehybridhooks as $vhook) {$vclosedboxes[] = 'hybrid-hook-'.$vhook;}
update_user_option($vuserid, $voptionkey, $vclosedboxes, true);
}
if (THEMEDEBUG) {echo "";}
}
return $vthemehooks['hybrid'];
}
}
// hook into the new theme filter (for modified Hybrid Hook plugin)
add_filter('hybrid_hook_theme_prefix', 'bioship_muscle_hybrid_hook_prefix');
if (!function_exists('bioship_muscle_hybrid_hook_prefix')) {
function bioship_muscle_hybrid_hook_prefix() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
// 2.0.5: change to bioship prefix to match new action names
return 'bioship';
}
}
}
}
// ------------------
// === Foundation ===
// ------------------
// ref: http://foundation.zurb.com/docs
// 2.0.1: filter loading of Foundation here
$vloadfoundation = false;
if (isset($vthemesettings['loadfoundation'])) {$vloadfoundation = $vthemesettings['loadfoundation'];}
$vloadfoundation = bioship_apply_filters('muscle_load_foundation',$vloadfoundation);
if ( ($vloadfoundation) && ($vloadfoundation != 'off') ) {
if (!function_exists('bioship_muscle_load_foundation')) {
add_action('wp_enqueue_scripts', 'bioship_muscle_load_foundation');
function bioship_muscle_load_foundation() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
global $vthemesettings, $vcsscachebust, $vjscachebust;
// 1.8.0: check Foundation 5 or 6 directory to use for loading
if (isset($vthemesettings['foundationversion'])) {$vfoundation = 'includes/'.$vthemesettings['foundationversion'];}
else {$vfoundation = 'includes/foundation5';} // backwards compatibility default
// force auto-load of modernizr and fastclick for Foundation 5
if (strstr($vfoundation,'5')) {
if (!has_action('wp_enqueue_scripts', 'bioship_muscle_load_modernizr')) {add_action('wp_enqueue_scripts', 'bioship_muscle_load_modernizr');}
if (!has_action('wp_enqueue_scripts', 'bioship_muscle_load_fastclick')) {add_action('wp_enqueue_scripts', 'bioship_muscle_load_fastclick');}
$vdeps = array('jquery','fastclick','modernizr');
} else {$vdeps = array('jquery');}
// Foundation Stylesheet
// ---------------------
// http://foundation.zurb.com/docs/css.html
if ($vthemesettings['foundationcss']) {
if ($vthemesettings['loadfoundation'] == 'essentials') {
$vfoundationstylesheet = bioship_file_hierarchy('both', 'foundation.essentials.min.css', array($vfoundation.'/css','css'));
} else {
$vfoundationstylesheet = bioship_file_hierarchy('both', 'foundation.min.css', array($vfoundation.'/css','css'));
}
if (is_array($vfoundationstylesheet)) {
if ($vthemesettings['stylesheetcachebusting'] == 'filemtime') {
$vcsscachebust = date('ymdHi', filemtime($vfoundationstylesheet['file']));
}
wp_register_style('foundation', $vfoundationstylesheet['url'], array(), $vcsscachebust);
wp_enqueue_style('foundation');
}
}
// Full or Partial Foundation Javascript
// -------------------------------------
// http://foundation.zurb.com/docs/javascript.html
if ($vthemesettings['loadfoundation'] == 'full') {
$vfoundation = bioship_file_hierarchy('both', 'foundation.min.js', array($vfoundation.'/js','javascripts'));
}
if ($vthemesettings['loadfoundation'] == 'essentials') {
$vfoundation = bioship_file_hierarchy('both', 'foundation.essentials.js', array($vfoundation.'/js','javascripts'));
}
elseif ($vthemesettings['loadfoundation'] == 'selective') {
$vfoundation = bioship_file_hierarchy('both', 'foundation.selected.js', array('javascripts', $vfoundation.'/js'));
// 1.8.0: note, selective javascript is currently only working for Foundation 5, so just in case, fallback to min.js
if (!is_array($vfoundation)) {$vfoundation = bioship_file_hierarchy('both', 'foundation.min.js', array('javascripts',$vfoundation.'/js'));}
}
if (is_array($vfoundation)) {
if ($vthemesettings['javascriptcachebusting'] == 'filemtime') {
$vjscachebust = date('ymdHi', filemtime($vfoundation['file']));
}
wp_enqueue_script('foundation', $vfoundation['url'], $vdeps, $vjscachebust, true);
}
}
}
// Initialize Foundation JavaScript
// --------------------------------
if (!function_exists('bioship_muscle_foundation_init')) {
add_action('wp_footer','bioship_muscle_foundation_init');
function bioship_muscle_foundation_init() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
// echo "";
// or better, to avoid conflicts: echo "";
// or even better, we add a hidden input to detect and initialize via init.js
echo "";
}
}
}
// ----------------------
// === Theme My Login ===
// ----------------------
// 2.0.1: filter TML Template loading
$vtmltemplates = false;
if (isset($vthemesettings['tmltemplates'])) {$vtmltemplates = $vthemesettings['tmltemplates'];}
$vtmltemplates = bioship_apply_filters('muscle_load_tml_templates',$vtmltemplates);
if ($vtmltemplates == '1') {
// Improve TML Template Hierarchy
// ------------------------------
if (!function_exists('muscle_tml_template_paths')) {
add_filter('tml_template_paths','bioship_muscle_tml_template_paths');
function bioship_muscle_tml_template_paths($vpaths) {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__,func_get_args());}
// 1.8.5: use existing globals
global $vthemestyledir, $vthemetemplatedir;
$vnewpaths = array(
$vthemestyledir.'templates/theme-my-login',
$vthemestyledir.'theme-my-login',
$vthemestyledir,
$vthemetemplatedir.'templates/theme-my-login',
$vthemetemplatedir.'theme-my-login',
$vthemetemplatedir,
WP_PLUGIN_DIR.'/theme-my-login/templates'
);
if (THEMEDEBUG) {echo "";}
return $vnewpaths;
}
}
// Login Button URL Filter
// -----------------------
if (!function_exists('bioship_muscle_login_button_url')) {
add_filter('login_button_url','bioship_muscle_login_button_url');
function bioship_muscle_login_button_url($vbuttonurl) {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__,func_get_args());}
global $vthemesettings;
if ($vthemesettings['loginbuttonurl'] != '') {return $vthemesettings['loginbuttonurl'];}
}
}
// Register Button URL Filter
// --------------------------
if (!function_exists('bioship_muscle_register_button_url')) {
add_filter('register_button_url', 'bioship_muscle_register_button_url');
function bioship_muscle_register_button_url($vbuttonurl) {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__,func_get_args());}
global $vthemesettings;
if ($vthemesettings['registerbuttonurl'] != '') {return $vthemesettings['registerbuttonurl'];}
return $vbuttonurl;
}
}
// Profile Button URL Filter
// -------------------------
if (!function_exists('bioship_muscle_profile_button_url')) {
add_filter('profile_button_url', 'bioship_muscle_profile_button_url');
function bioship_muscle_profile_button_url($vbuttonurl) {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__,func_get_args());}
global $vthemesettings;
if ($vthemesettings['profilebuttonurl'] != '') {return $vthemesettings['profilebuttonurl'];}
return $vbuttonurl;
}
}
// Register Form Logo Image
// ------------------------
if (!function_exists('bioship_muscle_register_form_image')) {
add_filter('register_form_image', 'bioship_muscle_register_form_image');
function bioship_muscle_register_form_image($vimage) {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
global $vthemesettings; $vimage = '';
if ($vthemesettings['registerformimage'] == '1') {
if ($vthemesettings['loginlogo'] == 'custom') {$vimage = $vthemesettings['header_logo'];}
if ($vthemesettings['loginlogo'] == 'upload') {$vimage = $vthemesettings['loginlogourl'];}
}
return $vimage;
}
}
// Login Form Logo Image
// ---------------------
if (!function_exists('bioship_muscle_login_form_image')) {
add_filter('login_form_image', 'bioship_muscle_login_form_image');
function bioship_muscle_login_form_image() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
global $vthemesettings; $vimage = '';
if ($vthemesettings['loginformimage'] == '1') {
if ($vthemesettings['loginlogo'] == 'custom') {$vimage = $vthemesettings['header_logo'];}
if ($vthemesettings['loginlogo'] == 'upload') {$vimage = $vthemesettings['loginlogourl'];}
}
return $vimage;
}
}
}
// ----------------------
// Theme Switch Admin Fix
// ----------------------
// for Theme Test Drive and JonRadio Multiple Themes...
// ref: http://wordpress.stackexchange.com/q/227532/76440
// *** IMPORTANT USAGE NOTE *** only works *HERE* for BioShip Parent and Child Theme switching
// if you want the same theme switching functionality to work with other themes as well,
// you will need to simply put a copy of this function in /wp-content/mu-plugins/ folder.
// and that is because THIS file is loaded BY this theme, so therefore the fix will not be
// loaded for other themes - unless it is loaded at an earlier time, ie. mu-plugins or plugins
// note: currently for JonRadio Multiple Themes, select-theme.php is NOT loaded for admin
// (this means the advanced setting 'AJAX All' currently has no effect anyway...)
// loading select-theme.php will automatically set the active theme via cookie storage,
// BUT this will not work for using admin-ajax.php or admin-post.php when visiting multiple
// pages on the same site at once where a different theme may be active for different pages!
// note: if loading via mu-plugins or a plugin, this action hook must change to 'plugins_loaded'
// 2.0.5: disable all this by default until retesting
add_action('init', 'bioship_muscle_theme_switch_admin_fix');
if (!function_exists('bioship_muscle_theme_switch_admin_fix')) {
function bioship_muscle_theme_switch_admin_fix() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
// check for a valid active plugin
$activeplugins = maybe_unserialize(get_option('active_plugins'));
if (!is_array($activeplugins)) {return;}
$multiplethemes = false; $themetestdrive = false;
if (in_array('jonradio-multiple-themes/jonradio-multiple-themes.php',$activeplugins)) {$multiplethemes = true;}
if (in_array('theme-test-drive/themedrive.php',$activeplugins)) {$themetestdrive = true;}
if ( (!$multiplethemes) && (!$themetestdrive) ) {return;} // nothing to do
// multiple themes option: 'site', 'sticky' or 'both'
if (defined('MT_METHOD')) {$method = MT_METHOD;} else {$method = 'site';}
$parameter = 'theme'; // multiple theme switch querystring parameter name
// user data save settings
$datamethod = 'both'; // how to save user data: 'cookie', 'usermeta' or 'both'
$datakey = 'theme_switch_data'; // cookie and user meta key name
$expires = 24*60*60; // length of time for cookies and transients
// maybe include pluggable.php for accessing user
if ( ($userdata != 'cookie') && (!function_exists('is_user_logged_in')) ) {require(ABSPATH.WPINC.'/pluggable.php');}
// maybe reset cookie and URL data by user request
if ( (isset($_GET['resetthemes'])) && ($_GET['resetthemes'] == '1') ) {
if ($debug) {echo "";}
if ($themetestdrive) {setCookie($themecookie,'',-300);}
delete_option('theme_switch_request_urls'); return;
}
// maybe set debug switch
$debug = false;
if ( (isset($_GET['debug'])) && ($_GET['debug'] == '1') ) {$debug = true;}
elseif (defined('THEMEDEBUG')) {$debug = THEMEDEBUG;}
// theme test drive by default only filters via get_stylesheet and get_template
// improve theme test drive to use options filters like multiple themes instead
if ($themetestdrive) {
$parameter = 'theme'; // set f
remove_filter('template', 'themedrive_get_template'); remove_filter('stylesheet', 'themedrive_get_stylesheet');
add_filter('pre_option_stylesheet', 'themedrive_get_stylesheet'); add_filter('pre_option_template', 'themedrive_get_template');
}
// maybe load stored alternative theme for AJAX/admin calls
if (is_admin()) {
// let wordpress handle customize previews
if (is_customize_preview()) {return;}
// get pagenow to check for admin-post.php as well
global $pagenow;
if ( ( (defined('DOING_AJAX')) && (DOING_AJAX) ) || ($pagenow == 'admin-post.php') ) {
// set the referer path for URL matching
$referer = parse_url($_SERVER['HTTP_REFERER'],PHP_URL_PATH);
// set some globals for the AJAX theme options
global $ajax_stylesheet, $ajax_template;
// check for temporary Theme Test Drive cookie data
if ( ($themetestdrive) || ( ($multiplethemes) && ($method != 'site') ) ) {
if ($datamethod != 'usermeta') {
if ( (isset($_COOKIE[$datakey])) && ($_COOKIE[$datakey] != '') ) {
$cookiedata = explode(',',$_COOKIE[$datakey]);
// attempt to match referer data with stored transient request
foreach ($cookiedata as $transientkey) {
$transientdata = get_transient($transientkey);
if ($transientdata) {
$data = explode(':',$transientdata);
if ($data[0] == $referer) {
$ajax_stylesheet = $data[1]; $ajax_template = $data[2];
$transientdebug = $transientdata; $matchedurlpath = true;
}
}
}
}
if ( ($datamethod != 'cookie') && (is_user_logged_in()) ) {
// 2.0.1: allow for fallback for older installs
$current_user = bioship_get_current_user();
$usermetadata = get_user_meta($current_user->ID, $datakey, true);
if (is_array($usermetadata)) {
// attempt to match referer data with stored transient request
foreach ($usermetadata as $transientkey) {
$transientdata = get_transient($transientkey);
if ($transientdata) {
$data = explode(':',$transientdata);
if ($data[0] == $referer) {
$ajax_stylesheet = $data[1]; $ajax_template = $data[2];
$transientdebug = $transientdata; $matchedurlpath = true;
}
}
}
}
}
}
}
elseif ( ($multiplethemes) && ($method != 'sticky') ) {
// check the request URL list to handle sitewide cases
if (!$matchedurlpath) { // but not if we already have a match
$requesturls = get_option('theme_switch_request_urls');
if (is_array($requesturls)) {
if ( (is_array($requesturls)) && (array_key_exists($referer,$requesturls)) ) {
$matchedurlpath = true;
$ajax_stylesheet = $requesturls[$referer]['stylesheet'];
$ajax_template = $requesturls[$referer]['template'];
}
}
}
}
if ($matchedurlpath) {
// add theme option filters for admin-ajax (and admin-post)
// so any admin actions defined by the theme are finally loaded!
add_filter('pre_option_stylesheet','bioship_muscle_admin_ajax_stylesheet');
add_filter('pre_option_template','bioship_muscle_admin_ajax_template');
function bioship_muscle_admin_ajax_stylesheet() {global $ajax_stylesheet; return $ajax_stylesheet;}
function bioship_muscle_admin_ajax_template() {global $ajax_template; return $ajax_template;}
}
// maybe output debug info for AJAX/admin test frame
if ($debug) {
echo "";
echo "";
echo "";
echo "";
if ($matchedurlpath) {echo "";} else {echo "";}
echo "";
echo "";
}
return; // done for admin requests so bug out here
}
}
// store public request URLs where an alternate theme is active
// (note: multiple themes does not load in admin, but theme test drive does)
if ( ($themetestdrive) || ( (!is_admin()) && ($multiplethemes) ) ) {
// get current theme (possibly overriden) setting
$themestylesheet = get_option('stylesheet'); $themetemplate = get_option('template');
// remove filters, get default theme setting, re-add filters
if ($multiplethemes) {
remove_filter('pre_option_stylesheet', 'jr_mt_stylesheet'); remove_filter('pre_option_template', 'jr_mt_template');
$stylesheet = get_option('stylesheet'); $template = get_option('template');
add_filter('pre_option_stylesheet', 'jr_mt_stylesheet'); add_filter('pre_option_template', 'jr_mt_template');
}
if ($themetestdrive) {
// note: default theme test drive filters are changed earlier on
remove_filter('pre_option_stylesheet', 'themedrive_get_stylesheet'); remove_filter('pre_option_template', 'themedrive_get_template');
$stylesheet = get_stylesheet(); $template = get_template();
add_filter('pre_option_stylesheet', 'themedrive_get_stylesheet'); add_filter('pre_option_template', 'themedrive_get_template');
}
// set/get request URL values (URL path only)
$requesturl = parse_url($_SERVER['REQUEST_URI'],PHP_URL_PATH);
$requesturls = get_option('theme_switch_request_urls');
// store the request data
if ( ($themetestdrive) || ( ($multiplethemes) && ($method != 'site') ) ) {
if ( (isset($_REQUEST[$parameter])) && ($_REQUEST[$parameter] != '') ) {
if ($datamethod != 'usermeta') {
// check existing cookie data
$cookiedata = array();
if ( (isset($_COOKIE[$datakey])) && ($_COOKIE[$datakey] != '') ) {
$existingmatch = false;
$i = 0; $cookiedata = explode(',',$_COOKIE[$datakey]);
foreach ($cookiedata as $transientkey) {
$transientdata = get_transient($transientkey);
if ($transientdata) {
$data = explode(':',$transientdata);
if ($data[0] == $requesturl) {
// update existing transient data
$transientdata = $transientdebug = $requesturl.':'.$themestylesheet.':'.$themetemplate;
set_transient($transientkey, $transientdata, $expires);
$existingmatch = true;
}
} else {unset($cookiedata[$i]);} // remove expired
$i++;
}
}
}
if ( ($datamethod != 'cookie') && (is_user_logged_in()) ) {
// check existing usermeta data
// 2.0.1: allow for fallback for older installs
// 2.0.7: use new prefixed current user function
$current_user = bioship_get_current_user();
$usermetadata = get_user_meta($current_user->ID, $datakey, true);
if (is_array($usermetadata)) {
$existingmatch = false;
$i = 0;
// remove expired transient IDs from usermeta
foreach ($usermetadata as $transientkey) {
$transientdata = get_transient($transientkey);
if ($transientdata) {
$data = explode(':',$transientdata);
if ($data[0] == $requesturl) {
// update existing transient data
$transientdata = $transientdebug = $requesturl.':'.$themestylesheet.':'.$themetemplate;
set_transient($transientkey, $transientdata, $expires);
$existingmatch = true;
}
} else {unset($usermetadata[$i]);} // remove expired
$i++;
}
} else {$usermetadata = array();}
}
// set the transient with matching cookie/usermeta data
if (!$existingmatch) { // avoid duplicates
// set the new transient
$transientkey = $datakey.'_'.uniqid();
$transientdata = $transientdebug = $requesturl.':'.$themestylesheet.':'.$themetemplate;
set_transient($transientkey, $transientdata, $expires);
// add transient to cookie for matching later
if ($datamethod != 'usermeta') {
$cookiedata[] = $transientkey; $cookiedatastring = implode(',', $cookiedata);
setCookie($themecookie, $cookiedatastring, time()+$expires);
}
// add transient to usermeta for matching later
if ($datamethod != 'cookie') {
$usermetadata[] = $transientkey; update_user_meta($current_user->ID, $datakey, $usermetadata);
}
}
// maybe output debug info
if ($debug) {
echo "";
if ($datamethod != 'cookie') {echo "";}
echo "";
}
}
}
elseif ( ($multiplethemes) && ($method != 'sticky') ) {
// save/remove the requested URL path in the list
if ( ($stylesheet == $themestylesheet) && ($template == $themetemplate) ) {
// maybe remove this request from the stored URL list
if ( (is_array($requesturls)) && (array_key_exists($requesturl,$requesturls)) ) {
unset($requesturls[$requesturl]);
if (count($requesturls) === 0) {delete_option('theme_switch_request_urls');}
else {update_option('theme_switch_request_urls',$requesturls);}
}
}
else {
// add this request URL to the stored list
$requesturls[$requesturl]['stylesheet'] = $themestylesheet;
$requesturls[$requesturl]['template'] = $themetemplate;
update_option('theme_switch_request_urls',$requesturls);
}
// maybe output debug info
if ( (!is_admin()) && ($debug) ) {
echo "";
echo "";
}
}
// maybe output hidden ajax debugging frames
if ( (!is_admin()) && ($debug) ) {
echo "";
echo "";
}
}
}
}
?>