';
}
}
}
// Discreet Text Widget
// --------------------
// most super useful widget, especially when used with shortcodes
// (so that if the shortcode returns empty the widget is not displayed)
// ref: https://wordpress.org/plugins/hackadelic-discreet-text-widget/
// 1.8.5: removed option, always on by default
if (!function_exists('bioship_muscle_discreet_text_widget')) {
add_action('widgets_init', 'bioship_muscle_discreet_text_widget');
function bioship_muscle_discreet_text_widget() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
// 1.9.8: added class check (for no conflict with content sidebars plugin)
if (!class_exists('DiscreetTextWidget')) {
// 2.0.8: extend classic text widget class
class DiscreetTextWidget extends WP_Widget_Classic_Text {
function __construct() {
$vwidgetops = array('classname' => 'discreet_text_widget', 'description' => __('Arbitrary text or HTML, only shown if not empty.','bioship'));
$vcontrolops = array('width' => 400, 'height' => 350);
// 1.9.8: fix to deprecated class construction method
// 2.0.7: fix to incorrect text domain (csidebars)
call_user_func(array(get_parent_class(get_parent_class($this)), '__construct'), 'discrete_text', __('Discreet Text','bioship'), $vwidgetops, $vcontrolops);
// parent::__construct('discrete_text', __('Discreet Text','bioship'), $vwidgetops, $vcontrolops);
// $this->WP_Widget('discrete_text', __('Discreet Text','bioship'), $vwidgetops, $vcontrolops);
}
function widget($vargs,$vinstance) {
// 1.9.8: removed usage of extract here
// extract($vargs, EXTR_SKIP);
$vtext = bioship_apply_filters('widget_text', $vinstance['text']);
if (empty($vtext)) {return;}
echo $vargs['before_widget'];
$vtitle = bioship_apply_filters('widget_title', $vinstance['title']);
if (!empty($vtitle)) {echo $vargs['before_title'].$vtitle.$vargs['after_title'];}
echo '
';
if ($vinstance['filter']) {echo wpautop($vtext);} else {echo $vtext;}
echo '
';
echo $vargs['after_widget'];
}
}
return register_widget("DiscreetTextWidget");
}
}
}
// Fullscreen Video Background!
// ----------------------------
// What is this doing here? A client-abandoned feature. It works tho! :-)
// Currently works for YouTube videos only (TODO: could add Vimeo etc...)
// TODO: Could maybe add to Theme Options? Currently loaded via filters only...
// (see filters.php example): muscle_videobackground_type,
// muscle_videobackground_id, muscle_videobackground_delay
// 1.9.8: fix to function_exists check (missing argument)
// 2.0.1: check themesettings internally to allow better filtering
if (!function_exists('bioship_muscle_video_background')) {
add_action('bioship_before_navbar', 'bioship_muscle_video_background');
function bioship_muscle_video_background() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
global $vthemesettings; $vload = false;
if (isset($vthemesettings['videobackground'])) {$vload = $vthemesettings['videobackground'];}
$vload = bioship_apply_filters('muscle_videobackground_type', $vload);
if ($vload == 'youtube') {
$vvideoid = ''; $vvideodelay = '';
if (isset($vthemesettings['videobackgroundid'])) {$vvideoid = $vthemesettings['videobackgroundid'];}
$vvideoid = bioship_apply_filters('muscle_videobackground_id', $vvideoid);
if (isset($vthemesettings['videobackgrounddelay'])) {$vvideodelay = $vthemesettings['videobackgrounddelay'];}
$vvideodelay = (int)bioship_apply_filters('muscle_videobackground_delay', $vvideodelay);
$vvideodelay = absint($vvideodelay);
if ( (!is_numeric($vvideodelay)) || ($vvideodelay < 0) ) {$vvideodelay = 1000;}
$vmaybe = array(); preg_match( "/[a-zA-Z0-9]+//", $vvideoid, $vmaybe);
if ( ($vvideoid != '') && ($vvideoid == $vmaybe[0]) ) {
echo '
';
echo '';
echo '';
echo '
';
}
}
}
}
// ---------------
// === Scripts ===
// ---------------
// TODO: add script load filters to filters.php examples
// Internet Explorer Support Scripts
// ---------------------------------
// - Selectivizr (CSS3, for IE6 to IE8 inclusive)
// - HTML5 Shiv (HTML5, for less than IE9)
// - Supersleight (transparent PNGs, for IE6 and below)
// - Flexibiliity (flexbox support for IE8+9)
// 1.5.0: moved to skeleton_internet_explorer_scripts hook
// 1.8.0: added flexbox polyfill
// 2.0.1: added individual loading filters
if (!function_exists('bioship_muscle_internet_explorer_scripts')) {
add_action('wp_head', 'bioship_muscle_internet_explorer_scripts');
function bioship_muscle_internet_explorer_scripts() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
global $vthemesettings, $vthemedirs, $vjscachebust;
$viesupports = $vthemesettings['iesupports'];
if ($vthemesettings['javascriptcachebusting'] == 'filemtime') {$vfilemtime = true;}
// Selectivizr CSS3
// ----------------
if ( (isset($viesupports['selectivizr'])) && ($viesupports['selectivizr'] == '1') ) {
// 2.0.1: added loading filter
$vload = bioship_apply_filters('muscle_load_selectivizr', true);
if ($vload) {
$vselectivizr = bioship_file_hierarchy('both', 'selectivizr.min.js', $vthemedirs['js']);
if (is_array($vselectivizr)) {
if ($vfilemtime) {$vjscachebust = date('ymdHi', filemtime($vselectivizr['file']));}
echo '';
}
}
}
// HTML5 Shiv
// ----------
if ( (isset($viesupports['html5shiv'])) && ($viesupports['html5shiv'] == '1') ) {
// 2.0.1: added loading filter
$vload = bioship_apply_filters('muscle_load_html5shiv', true);
if ($vload) {
$vhtml5 = bioship_file_hierarchy('both', 'html5.js', $vthemedirs['js']);
if (is_array($vhtml5)) {
if ($vfilemtime) {$vjscachebust = date('ymdHi', filemtime($vhtml5['file']));}
echo '';
}
}
}
// Supersleight
// ------------
if ( (isset($viesupports['supersleight'])) && ($viesupports['supersleight'] == '1') ) {
// 2.0.1: added loading filter
$vload = bioship_apply_filters('muscle_load_supersleight', true);
if ($vload) {
$vsupersleight = bioship_file_hierarchy('both', 'supersleight.js', $vthemedirs['js']);
if (is_array($vsupersleight)) {
if ($vfilemtime) {$vjscachebust = date('ymdHi', filemtime($vsupersleight['file']));}
echo '';
}
}
}
// IE8 DOM
// -------
// 1.8.5: added IE8 DOM polyfill
if ( (isset($viesupports['ie8'])) && ($viesupports['ie8'] == '1') ) {
// 2.0.1: added loading filter
$vload = bioship_apply_filters('muscle_load_ie8dom', true);
if ($vload) {
$vie8 = bioship_file_hierarchy('both', 'ie8.js', $vthemedirs['js']);
if (is_array($vie8)) {
if ($vfilemtime) {$vjscachebust = date('ymdHi', filemtime($vie8['file']));}
echo '';
}
}
}
// Flexibility
// -----------
// 1.8.0: added flexbox polyfill
if ( (isset($viesupports['flexibility'])) && ($viesupports['flexibility'] == '1') ) {
// 2.0.1: added loading filter
$vload = bioship_apply_filters('muscle_load_flexibility', true);
if ($vload) {
$vflexibility = bioship_file_hierarchy('both', 'flexibility.js', $vthemedirs['js']);
if (is_array($vflexibility)) {
if ($vfilemtime) {$vjscachebust = date('ymdHi', filemtime($vflexibility['file']));}
echo '';
}
}
}
}
}
// PrefixFree
// ----------
// 1.8.5: check themesettings internally to allow filtering
if (!function_exists('bioship_muscle_load_prefixfree')) {
add_action('wp_enqueue_scripts', 'bioship_muscle_load_prefixfree');
function bioship_muscle_load_prefixfree() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
global $vthemesettings, $vjscachebust, $vthemedirs; $vload = false;
if (isset($vthemesettings['prefixfree'])) {$vload = $vthemesettings['prefixfree'];}
$vload = bioship_apply_filters('muscle_load_prefixfree', $vload);
if (!$vload) {return;}
$vprefixfree = bioship_file_hierarchy('both', 'prefixfree.js', $vthemedirs['js']);
if (is_array($vprefixfree)) {
if ($vthemesettings['javascriptcachebusting'] == 'filemtime') {$vjscachebust = date('ymdHi', filemtime($vprefixfree['file']));}
wp_enqueue_script('prefixfree',$vprefixfree['url'], array(), $vjscachebust, true);
// 1.5.0: fix for Prefixfree and Google Fonts CORS conflict (a "WTF" bug)
// ref: http://stackoverflow.com/questions/25694456/google-fonts-giving-no-access-control-allow-origin-header-is-present-on-the-r
// ref: http://wordpress.stackexchange.com/questions/176077/add-attribute-to-link-tag-thats-generated-through-wp-register-style
// ref: https://github.com/LeaVerou/prefixfree/pull/39
add_filter('style_loader_tag','bioship_muscle_fonts_noprefix_attribute', 10, 2);
if (!function_exists('muscle_fonte_no_prefix_attribute')) {
function bioship_muscle_fonts_noprefix_attribute($vlink, $vhandle) {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__,func_get_args());}
$vlinka = $vlink;
// note: Google fonts style handles are 'heading-font-'x or 'custom-font-'x
if ( (strstr($vhandle, 'heading-font-')) || (strstr($vhandle, 'custom-font-')) ) {
$vlink = str_replace( '/>', 'data-noprefix />', $vlink);
}
else {
// ...and a basic check for if the link is external to the site
// as this problem could occur for other external sheets like this
$vsitehost = $_SERVER['HTTP_HOST'];
if ( ( (!stristr($vlink,$vsitehost)) && (stristr($vlink,'http://')) )
|| ( (!stristr($vlink,$vsitehost)) && (stristr($vlink,'https://')) ) ) {
$vlink = str_replace( '/>', 'data-noprefix />', $vlink);
}
}
// if ( (THEMEDEBUG) && ($vlinka != $vlink) ) {
// echo '';
// }
return $vlink;
}
}
}
}
}
// NWWatcher Selector Javascript
// -----------------------------
// 2.0.1: check themesettings internally to allow filtering
if (!function_exists('bioship_muscle_load_nwwatcher')) {
add_action('wp_enqueue_scripts', 'bioship_muscle_load_nwwatcher');
function bioship_muscle_load_nwwatcher() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
global $vthemesettings, $vthemedirs, $vjscachebust; $vload = false;
if (isset($vthemesettings['nwwatcher'])) {$vload = $vthemesettings['nwwatcher'];}
$vload = bioship_apply_filters('muscle_load_nwwatcher', $vload);
if (!$vload) {return;}
$vnwwatcher = bioship_file_hierarchy('both', 'nwwatcher.js', $vthemedirs['js']);
if (is_array($vnwwatcher)) {
if ($vthemesettings['javascriptcachebusting'] == 'filemtime') {$vjscachebust = date('ymdHi', filemtime($vnwwatcher['file']));}
wp_enqueue_script('nwwatcher', $vnwwatcher['url'], array(), $vjscachebust, true);
}
}
}
// NWEvents Event Manager (NWWatcher dependent)
// --------------------------------------------
// 2.0.1: check themesettings internally to allow filtering
if (!function_exists('muscle_load_nwevents')) {
add_action('wp_enqueue_scripts','bioship_muscle_load_nwevents');
function bioship_muscle_load_nwevents() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
global $vthemesettings, $vthemedirs, $vjscachebust; $vload = false;
if (isset($vthemesettings['nwevents'])) {$vload = $vthemesettings['nwevents'];}
$vload = bioship_apply_filters('muscle_load_nwevents', $vload);
if (!$vload) {return;}
$vnwevents = bioship_file_hierarchy('both', 'nwevents.js', $vthemedirs['js']);
if (is_array($vnwevents)) {
if ($vthemesettings['javascriptcachebusting'] == 'filemtime') {$vjscachebust = date('ymdHi', filemtime($vprefixfree['file']));}
wp_enqueue_script('nwevents', $vnwevents, array('nwwatcher'), $vjscachebust, true);
}
}
}
// Media Queries Support
// ---------------------
// 2.0.1: check themesettings internally to allow filtering
if (!function_exists('bioship_muscle_media_queries_script')) {
// note enqueue exception: apparently for these the "best place is in the footer"
add_action('wp_footer', 'bioship_muscle_media_queries_script');
function bioship_muscle_media_queries_script() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
global $vthemesettings, $vthemedirs, $vjscachebust; $vload = 'off';
if (isset($vthemesettings['mediaqueries'])) {$vload = $vthemesettings['mediaqueries'];}
$vload = bioship_apply_filters('muscle_load_mediaqueries', $vload);
// 2.0.2: fix to simplified load variable typo
if ( (!$vload) || ($vload == 'off') ) {return;}
if ($vthemesettings['mediaqueries'] == 'respond') {
$vrespond = bioship_file_hierarchy('both', 'respond.min.js', $vthemedirs['js']);
if (is_array($vrespond)) {
if ($vthemesettings['javascriptcachebusting'] == 'filemtime') {$vjscachebust = date('ymdHi', filemtime($vrespond['file']));}
echo '';
}
}
if ($vthemesettings['mediaqueries'] == 'mediaqueries') {
$vmediaqueries = bioship_file_hierarchy('both', 'css3-mediaqueries.js', $vthemedirs['js']);
if (is_array($vmediaqueries)) {
if ($vthemesettings['javascriptcachebusting'] == 'filemtime') {$vjscachebust = date('ymdHi', filemtime($vmediaqueries['file']));}
echo '';
}
}
}
}
// Load FastClick
// --------------
// 1.8.5: check themesettings internally to allow filtering
if (!function_exists('bioship_muscle_load_fastclick')) {
add_action('wp_enqueue_scripts', 'bioship_muscle_load_fastclick');
function bioship_muscle_load_fastclick() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
global $vthemesettings, $vthemedirs, $vjscachebust; $vload = false;
if (isset($vthemesettings['loadfastclick'])) {$vload = $vthemesettings['loadfastclick'];}
$vload = bioship_apply_filters('muscle_load_fastclick', $vload);
if (!$vload) {return;}
// 1.8.5: adding missing filemtime cachebusting option
$vfastclick = bioship_file_hierarchy('both', 'fastclick.js', $vthemedirs['js']);
if (is_array($vfastclick)) {
if ($vthemesettings['javascriptcachebusting'] == 'filemtime') {$vjscachebust = date('ymdHi', filemtime($vfastclick['file']));}
wp_enqueue_script('fastclick', $vfastclick['url'], array('jquery'), $vjscachebust,true);
}
}
}
// Load Mousewheel
// ---------------
// 1.8.5: check themesettings internally to allow filtering
if (!function_exists('bioship_muscle_load_mousewheel')) {
add_action('wp_enqueue_scripts', 'bioship_muscle_load_mousewheel');
function bioship_muscle_load_mousewheel() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
global $vthemesettings, $vthemedirs, $vjscachebust; $vload = false;
if (isset($vthemesettings['loadmousewheel'])) {$vload = $vthemesettings['loadmousewheel'];}
// 2.0.1: fix to reused code typo in filter variable
$vload = bioship_apply_filters('muscle_load_mousewheel', $vload);
if (!$vload) {return;}
// 1.9.0: fix to file hierarchy call (both not url)
$vmousewheel = bioship_file_hierarchy('both', 'mousewheel.js', $vthemedirs['js']);
if (is_array($vmousewheel)) {
if ($vthemesettings['javascriptcachebusting'] == 'filemtime') {$vjscachebust = date('ymdHi', filemtime($vmousewheel['file']));}
wp_enqueue_script('mousewheel', $vmousewheel['url'], array('jquery'), $vjscachebust, true);
}
}
}
// Load CSS.Supports
// -----------------
// 2.0.1: check themeoptions internally to allow filtering
if (!function_exists('bioship_muscle_load_csssupports')) {
add_action('wp_enqueue_scripts', 'bioship_muscle_load_csssupports');
function bioship_muscle_load_csssupports() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
global $vthemesettings, $vthemedirs, $vjscachebust; $vload = false;
if (isset($vthemesettings['loadcsssupports'])) {$vload = $vthemesettings['loadcsssupports'];}
$vload = bioship_apply_filters('muscle_load_csssupports', $vload);
if (!$vload) {return;}
$vcsssupports = bioship_file_hierarchy('url', 'CSS.supports.js', $vthemedirs['js']);
if (is_array($vcsssupports)) {
if ($vthemesettings['javascriptcachebusting'] == 'filemtime') {$vjscachebust = date('ymdHi', filemtime($vcsssupports['file']));}
wp_enqueue_script('csssupports', $vcsssupports, array(), $vjscachebust, true);
}
}
}
// MatchMedia.js
// -------------
// 2.0.1: check themesettings internally to allow filtering
if (!function_exists('bioship_muscle_match_media_script')) {
add_action('wp_enqueue_scripts', 'bioship_muscle_match_media_script');
function bioship_muscle_match_media_script() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
// 2.0.1: fix to old themeoptions global typo
global $vthemesettings, $vthemedirs, $vjscachebust; $vload = false;
if (isset($vthemesettings['loadmatchmedia'])) {$vloadmatchmedia = $vthemesettings['loadmatchmedia'];}
$vload = bioship_apply_filters('muscle_load_matchmedia', $vload);
if (!$vload) {return;}
// 1.9.5: fixed to file hierarchy call
$vmatchmedia = bioship_file_hierarchy('both', 'matchMedia.js', $vthemedirs['js']);
if (is_array($vmatchmedia)) {
if ($vthemesettings['javascriptcachebusting'] == 'filemtime') {$vjscachebust = date('ymdHi', filemtime($vmatchmedia['file']));}
wp_enqueue_script('matchmedia', $vmatchmedia['url'], array('jquery'), $vjscachebust, true);
// 1.9.5: fixed to file hierarchy call
$vmatchmedialistener = bioship_file_hierarchy('both', 'matchMedia.addListener.js', $vthemedirs['js']);
if (is_array($vmatchmedialistener)) {
if ($vthemesettings['javascriptcachebusting'] == 'filemtime') {$vjscachebust = date('ymdHi', filemtime($vmatchmedialistener['file']));}
wp_enqueue_script('matchmedialistener', $vmatchmedialistener['url'], array('jquery','matchmedia'), $vjscachebust,true);
}
}
}
}
// Load Modernizr
// --------------
// 2.0.1: check themesettings internally to allow filtering
if (!function_exists('bioship_muscle_load_modernizr')) {
add_action('wp_enqueue_scripts', 'bioship_muscle_load_modernizr');
function bioship_muscle_load_modernizr() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
global $vthemesettings, $vjscachebust; $vload = 'off';
if (isset($vthemesettings['load'])) {$vload = $vthemesettings['loadmodernizr'];}
$vload = bioship_apply_filters('muscle_load_modernizr', $vload);
// 2.0.2: fix to simplified variable typo
if ( (!$vload) || ($vload == 'off') ) {return;}
// 2.0.1: use filtered value here also
if ($vload == 'production') {
// (with fallback to development version)
$vmodernizr = bioship_file_hierarchy('both', 'modernizr.js', array('includes/foundation5/js/vendor','javascripts','js','assets/js'));
} elseif ($vload == 'development') {
// (with fallback to production version)
$vmodernizr = bioship_file_hierarchy('both', 'modernizr.js', array('javascripts','includes/foundation5/js/vendor','js','assets/js'));
}
if (is_array($vmodernizr)) {
if ($vthemesettings['javascriptcachebusting'] == 'filemtime') {$vjscachebust = date('ymdHi', filemtime($vmodernizr['file']));}
wp_enqueue_script('modernizr', $vmodernizr['url'], array('jquery'), $vjscachebust, true);
}
}
}
// --------------
// === Extras ===
// --------------
// Load Smooth Scrolling
// ---------------------
// 1.8.5: check themesettings internally to allow filtering
if (!function_exists('bioship_muscle_smooth_scrolling')) {
add_action('wp_footer','bioship_muscle_smooth_scrolling');
function bioship_muscle_smooth_scrolling() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
global $vthemesettings; $vload = false;
if (isset($vthemesettings['smoothscrolling'])) {$vload = $vthemesettings['smoothscrolling'];}
$vload = bioship_apply_filters('muscle_smooth_scrolling', $vload);
if (!$vload) {return;}
// adds a hidden input that is detected by init.js
echo "";
}
}
// Load jQuery matchHeight
// -----------------------
// 1.9.9: added this for content grid (and other) usage
if (!function_exists('bioship_muscle_load_matchheight')) {
add_action('wp_enqueue_scripts','bioship_muscle_load_matchheight');
function bioship_muscle_load_matchheight() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
global $vthemesettings, $vthemedirs, $vjscachebust; $vload = false;
if (isset($vthemesettings['loadmatchheight'])) {$vload = $vthemesettings['loadmatchheight'];}
$vload = bioship_apply_filters('muscle_load_matchheight', $vload);
if (!$vload) {return;}
$vmatchheight = bioship_file_hierarchy('both', 'jquery.matchHeight.js', $vthemedirs['js']);
if (is_array($vmatchheight)) {
if ($vthemesettings['javascriptcachebusting'] == 'filemtime') {$vjscachebust = date('ymdHi', filemtime($vmatchheight['file']));}
wp_enqueue_script('matchheight', $vmatchheight['url'], array('jquery'), $vjscachebust, true);
// add run trigger to footer (detected by init.js)
// 2.0.5: moved add_action inside for consistency
if (!function_exists('bioship_muscle_run_matchheight')) {
add_action('wp_footer', 'bioship_muscle_run_matchheight');
function bioship_muscle_run_matchheight() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
echo "";
}
}
}
}
}
// Load Sticky Kit
// ---------------
// 1.5.0: Added Sticky Kit Loading
// 1.8.5: check themesettings internally to allow filtering
if (!function_exists('bioship_muscle_load_stickykit')) {
add_action('wp_enqueue_scripts', 'bioship_muscle_load_stickykit');
function bioship_muscle_load_stickykit() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
// 1.8.5: seems to cause customizer some troubles
// 1.9.9: add pagenow check also for same reason
global $pagenow;
if ( ($pagenow == 'customizer.php') || (is_customize_preview()) ) {return;}
global $vthemesettings, $vthemedirs, $vjscachebust; $vload = false;
if (isset($vthemesettings['loadstickykit'])) {$vload = $vthemesettings['loadstickykit'];}
// 1.9.9: fix to incorrect filter name typo
$vload = bioship_apply_filters('muscle_load_stickykit', $vload);
if (!$vload) {return;}
$vstickykit = bioship_file_hierarchy('both', 'jquery.sticky-kit.min.js', $vthemedirs['js']);
if (is_array($vstickykit)) {
if ($vthemesettings['javascriptcachebusting'] == 'filemtime') {$vjscachebust = date('ymdHi', filemtime($vstickykit['file']));}
wp_enqueue_script('stickykit', $vstickykit['url'], array('jquery'), $vjscachebust, true);
}
if (trim($vthemesettings['stickyelements']) != '') {
if (!function_exists('bioship_muscle_echo_sticky_elements')) {
// 2.0.5: moved add_action inside for consistency
add_action('wp_footer', 'bioship_muscle_echo_sticky_elements');
function bioship_muscle_echo_sticky_elements() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
global $vthemesettings;
$vstickyelements = bioship_apply_filters('muscle_sticky_elements', $vthemesettings['stickyelements']);
if (strstr($vstickyelements,',')) {
$vstickyelementsarray = explode(',',$vstickyelements); $vi = 0;
foreach ($vstickyelementsarray as $vstickyelementvalue) {
$vstickyelementsarray[$vi] = trim($vstickyelementvalue); $vi++;
}
$vstickyelements = implode(',', $vstickyelementsarray);
}
else {$vstickyelements = trim($vstickyelements);}
// add sticky elements input (used by init.js)
echo "";
}
}
}
}
}
// Load FitVids
// ------------
// 1.8.5: check themesettings internally to allow filtering
if (!function_exists('bioship_muscle_load_fitvids')) {
add_action('wp_enqueue_scripts','bioship_muscle_load_fitvids');
function bioship_muscle_load_fitvids() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
global $vthemesettings, $vthemedirs, $vjscachebust; $vload = false;
if (isset($vthemesettings['loadfitvids'])) {$vload = $vthemesettings['loadfitvids'];}
$vload = bioship_apply_filters('muscle_load_fitvids', $vload);
if (!$vload) {return;}
$vfitvids = bioship_file_hierarchy('both', 'jquery.fitvids.js', $vthemedirs['js']);
if (is_array($vfitvids)) {
if ($vthemesettings['javascriptcachebusting'] == 'filemtime') {$vjscachebust = date('ymdHi', filemtime($vfitvids['file']));}
wp_enqueue_script('fitvids', $vfitvids['url'], array('jquery'), $vjscachebust, true);
}
if ($vthemesettings['fitvidselements'] != '') {
if (!function_exists('bioship_muscle_fitvids_elements')) {
add_action('wp_footer', 'bioship_muscle_fitvids_elements');
function bioship_muscle_fitvids_elements() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
// 1.5.0: handle initializing for multiple page elements
global $vthemesettings;
$vfitvidselements = bioship_apply_filters('muscle_fitvids_elements', $vthemesettings['fitvidselements']);
if (strstr($vfitvidselements,',')) {
$vfitvidsarray = explode(',', $vfitvidselements);
// 2.0.5: use simple array index
foreach ($vfitvidsarray as $vi => $vfitvidsvalue) {$vfitvidsarray[$vi] = trim($vfitvidsvalue);}
$vfitvidselements = implode(',', $vfitvidsarray);
}
else {$vfitvidselements = trim($vfitvidselements);}
echo "";
}
}
}
}
}
// Load ScrollToFixed
// ------------------
// 1.5.0: added Scroll To Fixed library
// 1.8.5: check themesettings internally to allow filtering
if (!function_exists('bioship_muscle_load_scrolltofixed')) {
add_action('wp_enqueue_scripts','bioship_muscle_load_scrolltofixed');
function bioship_muscle_load_scrolltofixed() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
global $vthemesettings, $vthemedirs, $vjscachebust; $vload = false;
if (isset($vthemesettings['loadscrolltofixed'])) {$vload = $vthemesettings['loadscrolltofixed'];}
$vload = bioship_apply_filters('muscle_load_scrolltofixed', $vload);
if (!$vload) {return;}
$vscrolltofixed = bioship_file_hierarchy('both', 'jquery-scrolltofixed.min.js', $vthemedirs['js']);
if (is_array($vscrolltofixed)) {
if ($vthemesettings['javascriptcachebusting'] == 'filemtime') {$vjscachebust = date('ymdHi', filemtime($vscrolltofixed['file']));}
wp_enqueue_script('scrolltofixed', $vscrolltofixed['url'], array('jquery'), $vjscachebust, true);
}
}
}
// Logo Resize Switch
// ------------------
// 1.8.5: added this input switch for init.js
if (!function_exists('bioship_muscle_logo_resize')) {
add_action('wp_footer','bioship_muscle_logo_resize');
function bioship_muscle_logo_resize() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
global $vthemesettings; $vload = false;
if (isset($vthemesettings['logoresize'])) {$vload = $vthemesettings['logoresize'];}
$vload = bioship_apply_filters('muscle_logo_resize', $vload);
if (!$vload) {return;}
// add run trigger to footer (detected by init.js)
echo '';
}
}
// ------------------
// === Thumbnails ===
// ------------------
// JPEG Quality Filter
// -------------------
// 2.0.5: added a jpeg quality filter
if (!function_exists('bioship_muscle_jpeg_quality')) {
add_filter('jpeg_quality', 'bioship_muscle_jpeg_quality', 10, 2);
function bioship_muscle_jpeg_quality($vquality, $vcontext) {
global $vthemesettings;
if (isset($vthemesettings['jpegquality'])) {
$vqual = $vthemesettings['jpegquality'];
if ( ($vqual != '') && ($vqual != '0') ) {
$vqual = absint($vqual);
if ( ($vqual > 0) && ($vqual < 101) ) {$vquality = $vqual;}
}
}
return $vquality;
}
}
// Allow Thumbnail Size override on upload for CPTs
// ------------------------------------------------
// (note: post type support for the CPT must be active via theme options)
// each filter must be explicity set, eg. muscle_custom_post_type_thumbsize_video
// Ref: http://wordpress.stackexchange.com/questions/6103/change-set-post-thumbnail-size-according-to-post-type-admin-page
if (!function_exists('bioship_muscle_thumbnail_size_custom')) {
add_filter('intermediate_image_sizes_advanced', 'bioship_muscle_thumbnail_size_custom', 10);
function bioship_muscle_thumbnail_size_custom($vsizes) {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__,func_get_args());}
// rather funny way of doing it but seems to work fine
// as this is for the admin post/page editing screen
if (isset($_REQUEST['post_id'])) {
$vpostid = $_REQUEST['post_id'];
$vposttype = get_post_type($vpostid);
} else {
// CHECKME: what to do for new posts (ie. with no post ID yet)?
return;
}
// get default thumbnail size options (as in theme setup)
global $vthemesettings;
$vthumbnailwidth = bioship_apply_filters('skeleton_thumbnail_width', 250);
$vthumbnailheight = bioship_apply_filters('skeleton_thumbnail_height', 250);
// get croppping options
$vcrop = get_option('thumbnail_crop');
$vthumbnailcrop = $vthemesettings['thumbnailcrop'];
if ($vthumbnailcrop == 'nocrop') {$vcrop = false;}
if ($vthumbnailcrop == 'auto') {$vcrop = true;}
if (strstr($vthumbnailcrop,'-')) {$vcrop = explode('-', $vthumbnailcrop);}
$vthumbsize = array($vthumbnailwidth, $vthumbnailheight, $vcrop);
// now check for a custom filter for this post type
$vnewthumbsize = bioship_apply_filters('muscle_post_type_thumbsize_'.$vposttype, $vthumbsize);
if ($vthumbsize != $newthumbsize) {
if ( (is_numeric($vnewthumbsize[0])) && (is_numeric($vnewthumbsize[1])) ) {
$vthumbsize = $vnewthumbsize;
}
}
// set it explicitly whether default or changed
$vsizes['post-thumbnail'] = array('width' => $vthumbsize[0], 'height' => $vthumbsize[1], 'crop' => $vthumbsize[2]);
return $vsizes;
}
}
// Fun with Fading Thumbnails
// --------------------------
if (!function_exists('bioship_muscle_fading_thumbnails')) {
// add_filter('the_posts','bioship_muscle_fading_thumbnails',10,2);
function bioship_muscle_fading_thumbnails($posts,$query) {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__,func_get_args());}
if (!is_archive()) {return $posts;}
$cptslug = 'post'; $dosomethingcool = false;
$posttypes = bioship_get_post_types($query);
if ( (is_array($posttypes)) && (in_array($cptslug,$posttypes)) ) {$dosomethingcool = true;}
elseif ($cptslug == $posttypes) {$dosomethingcool = true;}
if ($dosomethingcool) {
global $fadingthumbnails; $fadingthumbnails = $cptslug;
if (!had_action('wp_footer', 'bioship_muscle_fading_thumbnail_script')) {
add_action('wp_footer', 'bioship_muscle_fading_thumbnail_script');
}
}
if (!function_exists('bioship_muscle_fading_thumbnail_script')) {
function bioship_muscle_fading_thumbnail_script() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
global $fadingthumbnails;
echo "";
}
}
return $posts;
}
}
// ---------------
// === Reading ===
// ---------------
// Include/Exclude Categories from Home (Blog) Page
// ------------------------------------------------
if (!function_exists('bioship_muscle_select_home_categories')) {
add_filter('pre_get_posts', 'bioship_muscle_select_home_categories');
function bioship_muscle_select_home_categories($query) {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__,func_get_args());}
if ($query->is_home()) {
global $vthemesettings; $vmode = false;
if (isset($vthemesettings['homecategorymode'])) {$vmode = $vthemesettings['homecategorymode'];}
$vmode = bioship_apply_filters('muscle_home_category_mode', $vmode);
if ( (!$vmode) || ($vmode == 'all') ) {return;}
if ( ($vmode != 'include') && ($vmode != 'exclude') && ($vmode != 'includeexclude') ) {return;}
// 2.0.0: added category mode/include/exclude filters
$vincludecategories = bioship_apply_filters('muscle_home_include_categories', $vthemesettings['homeincludecategories']);
$vexcludecategories = bioship_apply_filters('muscle_home_exclude_categories', $vthemesettings['homeexcludecategories']);
// 2.0.1: revamped include / exclude logic
$vcategories = get_categories(); $vselected = array();
$vincluded = false; $vexcluded = false;
if (is_array($vincludecategories)) {$vincluded = true;}
if (is_array($vexcludecategories)) {$excluded = true;}
foreach ($vcategories as $vcategory) {
$vcatid = $vcategory->cat_ID;
if ( ($vincluded) && ( ($vmode == 'include') || ($vmode == 'includeexclude') ) ) {
if (isset($vincludecategories[$vcatid])) {$vselected[] = $vcatid;}
}
if ( ($vexcluded) && ( ($vmode == 'exclude') || ($vmode == 'includeexclude') ) ) {
if (isset($vexcludecategories[$vcatid])) {$vselected[] = '-'.$vcatid;}
}
}
if (count($vselected) > 0) {
$vcatstring = implode(' ', $vselected);
$query->set('cat', $vcatstring);
}
}
return $query;
}
}
// Number of Search Results per Page
// ---------------------------------
// 2.0.1: filter themesettings internally
add_action('pre_get_posts', 'bioship_muscle_search_results_per_page');
if (!function_exists('bioship_muscle_search_results_per_page')) {
function bioship_muscle_search_results_per_page($query) {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__,func_get_args());}
global $vthemesettings, $wp_the_query;
// 2.0.0: added muscle_search_results filter
$vsearchresults = bioship_apply_filters('muscle_search_results', $vthemesettings['searchresults']);
$vsearchresults = absint($vsearchresults);
if (is_numeric($vsearchresults)) {
if ( (!is_admin()) && ($query === $wp_the_query) && ($query->is_search()) ) {
$query->set('posts_per_page', $vsearchresults);
}
}
return $query;
}
}
// Make Custom Post Types Searchable
// ---------------------------------
// 2.0.1: filter themesettings internally
if (!function_exists('bioship_muscle_searchable_cpts')) {
if (is_search()) {add_filter('the_search_query','bioship_muscle_searchable_cpts');}
function bioship_muscle_searchable_cpts($query) {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__,func_get_args());}
global $vthemesettings; $vsearchablecpts = false;
if (isset($vthemesettings['searchablecpts'])) {$vsearchablecpts = $vthemesettings['searchablecpts'];}
$vsearchablecpts = bioship_apply_filters('muscle_searchable_cpts', $vsearchablecpts);
// 2.0.1: fix to search logic array here
if ( (is_array($vsearchablecpts)) && (count($vsearchablecpts) > 0) ) {
$vcpts = array();
foreach ($vsearchablecpts as $vcpt => $vvalue) {
if ($vvalue == '1') {$vcpts[] = $vcpt;}
}
if ($query->is_search) {$query->set('post_type', $vcpts);}
}
return $query;
}
}
// Jetpack Infinite Scroll Support
// -------------------------------
// Jetpack Infinite Scroll info: http://jetpack.me/support/infinite-scroll/
// also could use AJAX Load More: https://wordpress.org/plugins/ajax-load-more/
// Loading Span selector: span.infinite-loader (default image: /images/infinite-loader.gif)
// Load More Button selector: div.infinite-handler (for click only, not scroll)
if (!function_exists('bioship_muscle_jetpack_scroll_setup')) {
add_action('after_setup_theme', 'bioship_muscle_jetpack_scroll_setup');
function bioship_muscle_jetpack_scroll_setup() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
global $vthemesettings; $vload = false;
if (isset($vthemesettings['infinitescroll'])) {$vload = $vthemesettings['infinitescroll'];}
$vload = bioship_apply_filters('muscle_load_infinitescroll', $vload);
if ( ($vload != 'scroll') && ($vload != 'click') ) {return;}
$vfootersidebars = $vthemesettings['footersidebars'];
if ($vfootersidebars > 0) {$vfooterwidgets[0] = 'footer-widget-area-1';}
if ($vfootersidebars > 1) {$vfooterwidgets[1] = 'footer-widget-area-2';}
if ($vfootersidebars > 2) {$vfooterwidgets[2] = 'footer-widget-area-3';}
if ($vfootersidebars > 3) {$vfooterwidgets[3] = 'footer-widget-area-4';}
$vsettings = array(
'type' => $vload,
'container' => 'content',
'footer' => 'footer',
'footer_widgets', $vfooterwidgets,
'wrapper' => 'infinite-wrap',
'render' => 'muscle_infinite_scroll_loop'
);
// 1.8.0: added override filters
$vpostsperpage = bioship_apply_filters('skeleton_infinite_scroll_numposts', '');
if (is_numeric($vpostsperpage)) {$vsettings['posts_per_page'] = $vpostsperpage;}
$vsettings = bioship_apply_filters('skeleton_infinite_scroll_settings', $vsettings);
add_theme_support('infinite-scroll', $vsettings);
// 2.0.1: moved this inside loader
if (!function_exists('bioship_muscle_infinite_scroll_loop')) {
function bioship_muscle_infinite_scroll_loop() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__,func_get_args());}
// TODO: maybe update this to use/match AJAX Load More Loop Template?
// 1.5.0: fix: always use hybrid content hierarchy
while (have_posts()) {
the_post();
hybrid_get_content_template();
}
}
}
}
}
// -----------------------------
// === Excerpt and Read More ===
// -----------------------------
// Add Excerpt Support to Pages
// ----------------------------
// 1.8.0: add page excerpt support option
if ( (isset($vthemesettings['pageexcerpts'])) && ($vthemesettings['pageexcerpts'] == '1') ) {
add_post_type_support('page', 'excerpt');
}
// Enable Shortcodes in Excerpts
// -----------------------------
if ($vthemesettings['excerptshortcodes'] == '1') {
// 1.9.8: very much "doing it wrong"! - replaced these filters...
// add_filter('the_excerpt', 'do_shortcode');
// add_filter('get_the_excerpt', 'do_shortcode');
if (has_filter('get_the_excerpt', 'wp_trim_excerpt')) {
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'bioship_muscle_excerpts_with_shortcodes');
}
}
// Excerpts with Shortcodes
// ------------------------
// 1.9.8: copy of wp_trim_excerpt but with shortcodes kept
// note: formatting is still stripped but shortcode text remains
if (!function_exists('bioship_muscle_excerpts_with_shortcodes')) {
function bioship_muscle_excerpts_with_shortcodes($text) {
// for use in shortcodes to provide alternative output
global $doingexcerpt; $doingexcerpt = true;
$text = get_the_content('');
// $text = strip_shortcodes( $text ); // modification
$text = bioship_apply_filters( 'the_content', $text );
$text = str_replace(']]>', ']]>', $text);
$excerpt_length = bioship_apply_filters( 'excerpt_length', 55 );
$excerpt_more = bioship_apply_filters( 'excerpt_more', ' ' . '[…]' );
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
$doingexcerpt = false; return $text;
}
}
// User Defined Excerpt Length
// ---------------------------
// 1.8.5: move checks to inside filter
if (!function_exists('bioship_muscle_excerpt_length')) {
add_filter('excerpt_length','bioship_muscle_excerpt_length');
// 2.0.5: move old pseudonym to compat.php
function bioship_muscle_excerpt_length($vlength) {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__,func_get_args());}
global $vthemesettings;
// 1.8.5: added alternative feed excerpt length
if (is_feed()) {
if ( (isset($vthemesettings['rssexcerptlength'])) && ($vthemeoption['rssexcerptlength'] != '') ) {
$vrssexcerptlength = abs(intval($vthemesettings['rssexcerptlength']));
if ($vrssexcerptlength == 0) {return PHP_INT_MAX;}
elseif ($vrssexcerptlength > 0) {return $vrssexcerptlength;}
}
}
// 1.8.5: simplified and improved code here
if ( (isset($vthemesettings['excerptlength'])) && ($vthemesettings['excerptlength'] != '') ) {
$vexcerptlength = abs(intval($vthemesettings['excerptlength']));
if ($vexcerptlength == 0) {return PHP_INT_MAX;}
elseif ($vexcerptlength > 0) {return $vexcerptlength;}
}
return $vlength;
}
}
// Read More Link
// --------------
// Default = 'Continue reading →';
if ($vthemesettings['readmoreanchor'] != '') {
// 2.0.5: move old pseudonym to compat.php
if (!function_exists('bioship_muscle_continue_reading_link')) {
function bioship_muscle_continue_reading_link() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
global $vthemesettings;
// 2.0.0: added muscle_read_more_anchor filter
$vreadmoreanchor = bioship_apply_filters('muscle_read_more_anchor', $vthemesettings['readmoreanchor']);
return ' '.$vreadmoreanchor.'';
}
}
}
// Read More Before and After
// --------------------------
// Default = ' …';
// 2.0.5: removed outside settings check so filtered
// 2.0.5: move old pseudonym to compat.php
if (!function_exists('bioship_muscle_auto_excerpt_more')) {
add_filter('excerpt_more', 'bioship_muscle_auto_excerpt_more');
function bioship_muscle_auto_excerpt_more($vmore) {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__,func_get_args());}
global $vthemesettings;
// 2.0.0: added muscle_read_more_before filter
$vreadmorebefore = bioship_apply_filters('muscle_read_more_filter', $vthemesettings['readmorebefore']);
if (function_exists('bioship_muscle_continue_reading_link')) {
return '
';
}
}
}
// 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 in-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'])) {
// 1.9.6: removed this code as even 192 does not meet OG minimum of 200
// maybe pick the largest size if set to precomposed apple touch icons
// 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 {
// 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
// 2.0.8: added new open graph image off option
if ($vkey == 'none') {$vurl = '';}
elseif ($vkey == 'site_icon') {$vurl = get_site_icon_url();}
else {$vurl = $vthemesettings[$vkey];}
// }
if (THEMEDEBUG) {echo "";}
// allow for default open graph image filter
$vurl = bioship_apply_filters('muscle_open_graph_default_image_url', $vurl);
if (THEMEDEBUG) {echo "";}
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 "";
}
}
}
}
?>