';
echo '
▾ '.esc_attr($boxtitle).'';
echo '
';
echo '
';
// Admin Notices reinsert themselves magically here after the
tag inside a
// Note: TGM Plugin Activations Notice still disappears from here when dismissed :-(
// TODO: =dismiss_admin_notices should have no effect here (and only here)
echo '
';
// Welcome / Documentation - Wide
// ------------------------------
// 2.0.5: add combined welcome and documentation box
$boxid = 'documentation';
if ($welcome) {$boxtitle = __('Welcome!','bioship');}
else {$boxtitle = __('Documentation','bioship');}
echo '
';
echo '
';
echo '';
if ($welcome) {echo '▸';} else {echo '▾';}
echo ' '.$boxtitle.' ';
if (!$welcome) {$hide = ' style="display:none;"';} else {$hide = '';}
echo '
';
bioship_admin_documentation_box($welcome);
echo ' ';
// Theme Tools - Wide (collapsed)
// ------------------------------
$boxid = 'themetools'; $boxtitle = __('Theme Settings Tools','bioship');
echo '
';
echo '
▾ '.esc_attr($boxtitle).'';
echo '
';
bioship_admin_theme_tools_forms();
echo ' ';
// Left Column - Links / Extensions
// --------------------------------
echo '
';
// BioShip Theme Links
// -------------------
$boxid = 'bioshiplinks'; $boxtitle = __('Theme Links','bioship');
echo '
';
echo '
'.esc_js($boxtitle).' ';
echo '
';
$bioshiplogo = bioship_file_hierarchy('url', 'bioship.png', $vthemedirs['image']);
echo '
';
echo '
';
// WordQuest Plugins
// -----------------
$boxid = 'wordquestplugins'; $boxtitle = __('WordQuest Alliance','bioship');
echo '
';
echo '
'.esc_attr($boxtitle).' ';
echo '
';
$wordquestlogo = bioship_file_hierarchy('url', 'wordquest.png', $vthemedirs['image']);
echo '
';
echo '
';
// Recommended Plugins
// -------------------
// 1.8.5: added recommended box display
$recommended = bioship_file_hierarchy('file', 'recommended.php', array('includes'));
if ($recommended) {
include($recommended);
$recommend = bioship_admin_get_recommended();
if ($recommend) {
$boxid = 'recommended'; $boxtitle = __('Recommended','bioship');
echo '
';
echo '
'.esc_attr($boxtitle).' ';
echo '
';
echo $recommend;
echo '
';
}
}
echo '
'; // close extend column
// Right Column - Dashboard Feed Widgets
// -------------------------------------
echo '
';
// 1.8.0: allow turning feeds off if being problematic
$feeds = true;
if (isset($_REQUEST['loadfeeds'])) {
$loadfeeds = $_REQUEST['loadfeeds'];
if ( ($loadfeeds == 'on') || ($loadfeeds == '1') ) {delete_option('bioship_admin_feed_display');}
if ( ($loadfeeds == 'off') || ($loadfeeds == '0') ) {update_option('bioship_admin_feed_display','off');}
if ( ($loadfeeds == 'no') || ($loadfeeds == '2') ) {$feeds = false;}
}
if (get_option('bioship_admin_feed_display') == 'off') {$feeds = false;}
// BioShip Feed
// ------------
// TODO: move muscle_bioship_dashboard_feed_widget to admin.php
$boxid = 'bioshipfeed'; $boxtitle = __('BioShip News','bioship');
if ($feeds && function_exists('muscle_bioship_dashboard_feed_widget')) {
echo '
';
echo '
'.esc_attr($boxtitle).' ';
echo '
';
echo "";
muscle_bioship_dashboard_feed_widget(false, false);
echo "";
echo '
';
}
// WordQuest Feed
// --------------
$boxid = 'wordquestfeed'; $boxtitle = __('WordQuest News','bioship');
if ($feeds && function_exists('wqhelper_dashboard_feed_widget')) {
echo '
';
echo '
'.esc_attr($boxtitle).' ';
echo '
';
echo "";
wqhelper_dashboard_feed_widget();
echo "";
echo '
';
}
// PluginReview Feed
// -----------------
$boxid = 'pluginreviewfeed'; $boxtitle = __('Plugin Reviews','bioship');
if ($feeds && function_exists('wqhelper_pluginreview_feed_widget')) {
echo '
';
echo '
'.esc_attr($boxtitle).' ';
echo '
';
echo "";
wqhelper_pluginreview_feed_widget();
echo "";
echo '
';
}
// maybe enqueue Feed Loader Javascript
// ------------------------------------
if (!has_action('admin_footer', 'wqhelper_dashboard_feed_javascript')) {
add_action('admin_footer', 'wqhelper_dashboard_feed_javascript');
}
echo '
'; // close feed column
}
}
// ---------------
// Welcome Message
// ---------------
// 2.1.2: added separate (filterable) theme welcome message
if (!function_exists('bioship_admin_welcome_message')) {
function bioship_admin_welcome_message() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
// --- set welcome message ---
$current_user = bioship_get_current_user();
$firstname = $current_user->user_firstname;
if ($firstname != '') {$firstname = ', '.$firstname;}
$message = '
'.esc_attr(__('Welcome aboard','bioship')).' '.esc_attr($firstname).'! ';
$message = esc_attr(__('And thanks for choosing to pilot BioShip...','bioship')).'
';
// --- filter and return ---
$message = bioship_apply_filters('admin_welcome_message', $message);
return $message;
}
}
// -----------------
// Documentation Box
// -----------------
// 2.0.5: added documentation link box
if (!function_exists('bioship_admin_documentation_box')) {
function bioship_admin_documentation_box($welcome) {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__,func_get_args());}
global $vthemetemplateurl;
// Load Documentation
// ------------------
include(dirname(__FILE__).'/docs.php');
// Welcome Message
// ---------------
if ($welcome) {
// 2.0.7: use new prefixed current user function
// 2.1.1: move welcome message to separate function
echo bioship_admin_welcome_message();
}
// QuickStart Section
// ------------------
if (!$welcome) {$hide = ' style="display:none;"';} else {$hide = '';}
echo '
';
echo '
'.esc_attr(__('QuickStart Guide','bioship')).' ';
echo bioship_docs_quickstart(false);
echo '';
// QuickStart Scripts
// ------------------
echo "";
// QuickStart Links
// ----------------
if ($welcome) {$hide = ' style="display:none;"';} else {$hide = '';}
$quickstart = '
';
if (!$welcome) {$hide = ' style="display:none;"';} else {$hide = '';}
$quickstart .= '
';
$quickstart .= '
';
// Documentation Index
// -------------------
$docindex = bioship_docs_index(false);
$docindex = str_replace('h3>', 'h4>', $docindex);
$docindex = str_replace('', '
'.$quickstart, $docindex);
$docindex = str_replace('', ' ', $docindex);
$docindex = str_replace('', '
', $docindex);
$docindex = str_replace('a href="docs.php?page=', 'a class="doc-thickbox" href="#', $docindex);
echo $docindex;
// Documentation Thickbox Script
// -----------------------------
$docsurl = esc_url($vthemetemplateurl.'admin/docs.php');
echo "";
}
}
// ---------------------------------
// === Build Selective Resources ===
// ---------------------------------
// ----------------------------------
// Trigger Build Selective CSS and JS
// ----------------------------------
// TODO: move select resource build triggers internally
// --- Options Framework ---
if ( (isset($_GET['page'])) && (isset($_GET['settings-updated'])) ) {
if ( ($_GET['page'] == 'options-framework') && ($_GET['settings-updated'] == 'true') ) {
add_action('admin_notices', 'bioship_admin_build_selective_resources');
}
}
// --- Titan Framework ---
// 1.8.0: need to trigger differently for Titan save
if ( (isset($_GET['page'])) && (isset($_GET['message'])) ) {
if ( ($_GET['page'] == $vthemename.'-options') && ($_GET['message'] == 'saved') ) {
add_action('admin_notices', 'bioship_admin_build_selective_resources');
}
}
// --- Customizer ---
// 1.8.0: ...also need to trigger this after a Customizer save...
add_action('customize_save_after', 'bioship_admin_build_selective_resources');
// --------------------------
// Build Selective CSS and JS
// --------------------------
if (!function_exists('bioship_admin_build_selective_resources')) {
function bioship_admin_build_selective_resources() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
global $vthemename, $vthemesettings, $vthemedirs;
// Maybe Combine CSS Core On Save
// ------------------------------
if ($vthemesettings['combinecsscore']) {
// --- reset.css or normalize.css ---
$resetoption = $vthemesettings['cssreset'];
if ($resetoption == 'normalize') {
$cssfile = bioship_file_hierarchy('file', 'normalize.css', $vthemedirs['style']);
if ($cssfile) {$cssreset = bioship_file_get_contents($cssfile);}
else {echo "
".esc_attr(__('Warning','bioship'))." : ".esc_attr(__('CSS Combine could not find','bioship'))."
normalize.css ";}
}
if ($resetoption == 'reset') {
$cssfile = bioship_file_hierarchy('file', 'reset.css', $vthemedirs['style']);
if ($cssfile) {$cssreset = bioship_file_get_contents($cssfile);}
else {echo "
".esc_attr(__('Warning','bioship'))." : ".esc_attr(__('CSS Combine could not find','bioship'))."
reset.css ";}
}
// --- formalize.css ---
if ($vthemesettings['loadformalize']) {
$cssfile = bioship_file_hierarchy('file', 'formalize.css', $vthemedirs['style']);
if ($cssfile) {$formalize = bioship_file_get_contents($cssfile);}
else {echo "
".esc_attr(__('Warning','bioship'))." : ".esc_attr(__('CSS Combine could not find','bioship'))."
formalize.css ";}
}
// --- mobile.css ---
// (previously misnamed layout.css in skeleton theme)
$cssfile = bioship_file_hierarchy('file', 'mobile.css', $vthemedirs['style']);
if ($cssfile) {$mobile = bioship_file_get_contents($cssfile);}
else {echo "
".esc_attr(__('Warning','bioship'))." : ".esc_attr(__('CSS Combine could not find','bioship'))."
mobile.css ";}
// 1.5.0: [Deprecated] these fixed stylesheet widths are deprecated by grid.php
// skeleton-960.css, skeleton-1120.css, skeleton-1200.css
// --- skeleton.css ---
// (note: this must be last or CSS breaks)
$cssfile = bioship_file_hierarchy('file', 'skeleton.css', $vthemedirs['style']);
if ($cssfile) {$skeleton = bioship_file_get_contents($cssfile);}
else {echo "
".esc_attr(__('Warning','bioship'))." : ".esc_attr(__('CSS Combine could not find','bioship'))."
skeleton.css ";}
// note: style.css and custom.css are intentionally not added here as it breaks combined stylesheet!
// --- combine the CSS file contents ---
$csscontents = $cssreset.PHP_EOL.PHP_EOL;
$csscontents .= $formalize.PHP_EOL.PHP_EOL;
$csscontents .= $mobile.PHP_EOL.PHP_EOL;
$csscontents .= $skeleton.PHP_EOL.PHP_EOL;
$datetime = date('H:i:s d/m/Y');
$csscontents .= '/* Last Updated: '.esc_attr($datetime).' */';
// --- write combined core CSS file directly ---
// (no need for WP_Filesystem as the file already exists, but used anyway to pass Theme Check)
// ref: http://ottopress.com/2011/tutorial-using-the-wp_filesystem/#comment-10820
// 1.8.0: fix to use directory separator in file path
// --- write selected styles to file ---
// 2.1.1: check alternate style directory paths
$stylepath = get_stylesheet_directory($vthemename).DIRSEP;
foreach ($vthemedirs['style'] as $dir) {
if (is_dir($stylepath.DIRSEP.$dir) && file_exists($stylepath.DIRSEP.$dir.DIRSEP.'core-styles.css')) {
$stylefile .= $stylepath.DIRSEP.$dir.DIRSEP.'core-styles.css'; break;
}
}
if (isset($stylefile)) {bioship_write_to_file($stylefile, $csscontents);}
}
// ----------------------------------------------
// Build Selective Foundation Javascripts on Save
// -----------------------------------------------
// TODO: build selectives for Foundation 6, this currently only works for Foundation 5
// $foundation = $vthemesettings['foundationversion'];
$foundation = 'foundation5'; // currently available for Foundation 5 only
if ($vthemesettings['loadfoundation'] == 'selective') {
$jsfile = bioship_file_hierarchy('file', 'foundation.js', array('javascripts','includes/'.$foundation.'/js/foundation'));
$foundationjs = bioship_file_get_contents($jsfile);
$selected = $vthemesettings['foundationselect'];
$message = '';
foreach ($selected as $key => $value) {
if ($value == '1') {
$filename = 'foundation.'.$key.'.js';
$foundationsourcedir = 'includes/'.$foundation.'/js/foundation';
$jsfile = bioship_file_hierarchy('file', $filename, array($foundationsourcedir));
if ($jsfile) {
$jsdata = bioship_file_get_contents($jsfile);
// 2.0.7: doubly ensure new line consistency for Theme Check
$jsdata = str_replace("\r\n", "\n", $jsdata);
$foundationjs .= $jsdata;
// 1.5.5: fix, use specific matching EOL to pass Theme Check
$foundationjs .= "\n"."\n";
} else {
$message .= "
".esc_attr(__('Warning','bioship'))." : ".esc_attr(__('Foundation JS Combine could not find','bioship'))."
".esc_attr($filename)." ";
}
}
}
// --- missing resources message ---
// 1.8.0: added admin warning for missing resources
if ($message != '') {
global $vadminmessages; $vadminmessages[] = $message;
bioship_admin_notices_enqueue();
}
// --- write to file ---
if (strlen($foundation) > 0) {
// 1.8.0: write to theme javascripts directory, not foundation/js and fix directory separator
// also, this is written to template directory so as not to overwrite a child version
// (as such it does not need to use WP Filesystem as the file already exists)
// ref: http://ottopress.com/2011/tutorial-using-the-wp_filesystem/#comment-10820
$scriptpath = get_template_directory($vthemename).DIRSEP;
// 2.1.1: check alternate script directory paths
foreach ($vthemedirs['script'] as $dir) {
if (is_dir($scriptpath.DIRSEP.$dir) && file_exists($scriptpath.DIRSEP.$dir.DIRSEP.'foundation.selected.js')) {
$scriptfile = $scriptpath.DIRSEP.$dir.DIRSEP.'foundation.selected.js'; break;
}
}
if (isset($scriptfile)) {bioship_write_to_file($scriptfile, $foundationjs);}
}
}
}
}
// =================================
// === Activation / Deactivation ===
// =================================
// -----------------------------------------------------
// Save/Restore Widgets/Menus on Deactivation/Activation
// -----------------------------------------------------
// TODO: retest activation/deactivation functionality
// (as this was improved in WP Core at some point)
// TEST: if switch_theme/after_switch_theme is triggered when using WP CLI
// (as may not be in admin area and these are loaded via admin.php only,
// so this may need to move out of admin.php if it is still needed)
// ----------------
// For Parent Theme
// ----------------
if (!THEMECHILD) {
$saverestorewidgets = bioship_apply_filters('skeleton_theme_widget_backups', true);
if ($saverestorewidgets) {
// Backup on Deactivation
// ----------------------
if (!function_exists('bioship_admin_theme_deactivation')) {
add_action('switch_theme', 'bioship_admin_theme_deactivation');
function bioship_admin_theme_deactivation($vnewthemename) {
$sidebarswidgets = get_option('sidebars_widgets');
update_option('bioship_widgets_backup', $sidebarswidgets);
$menusettings = get_option('nav_menu_options');
update_option('bioship_menus_backup', $menusettings);
// not needed: theme mods, as they are theme specific
// (hmmmm maybe just how the sidebars/menus should be!)
}
}
// Restore on Activation
// ---------------------
if (!function_exists('bioship_admin_theme_activation')) {
add_action('after_switch_theme', 'bioship_admin_theme_activation');
function bioship_admin_theme_activation() {
// 2.1.1: use THEMEPREFIX constant instead of hardcoding
$sidebarswidgets = get_option('sidebars_widgets');
$menusettings = get_option('nav_menu_options');
$bioshipwidgets = get_option(THEMEPREFIX.'_widgets_backup');
$bioshipmenus = get_option(THEMEPREFIX.'_menus_backup');
// note: no need to restore theme mods as already theme specific
// If there are backed up widgets/menus, restore them now
// ..also be nice and backup the deactivated themes widgets/menus
// (even though note these cannot be automatically restored)
if ($bioshipwidgets != '') {
update_option('sidebars_widgets', $bioshipwidgets);
delete_option('old_theme_widgets_backup');
// 2.0.8: fix to variable typo (vsidebarwidgets)
add_option('old_theme_widgets_backup', $sidebarswidgets);
}
if ($bioshipmenus != '') {
update_option('nav_menu_options', $bioshipmenus);
delete_option('old_theme_menus_backup');
add_option('old_theme_menus_backup', $menusettings);
}
// --- redirect to Theme Options page on activation ---
// 2.0.5: redirect to welcome page section with admin_url
global $pagenow;
if (is_admin() && isset($_GET['activated']) && ($pagenow == 'themes.php')) {
// 1.8.0: Titan Framework Conversion
// 2.0.5: allow for no Titan or Options Framework
if (!THEMETITAN && THEMEOPT) {wp_redirect(admin_url('themes.php').'?page=options-framework&welcome=true'); exit;}
elseif (THEMETITAN && class_exists('TitanFramework')) {wp_redirect(admin_url('admin.php').'?page=bioship-options&welcome=true'); exit;}
// 2.0.8: WordPress.Org versions only - redirection on theme activation not allowed :-/
// else {wp_redirect(admin_url('themes.php').'?page=theme-info&welcome=true'); exit;}
}
}
}
}
}
// ---------------
// For Child Theme
// ---------------
if (THEMECHILD) {
// Save/Restore Child Theme Widgets/Menus on Deactivation/Activation
// -----------------------------------------------------------------
// 1.8.0: moved here from child theme functions.php (cleaner)
// (note: maintain function_exists wrappers for back compat)
// TODO: possibly change this filter name ?
$saverestorechildwidgets = bioship_apply_filters('skeleton_childtheme_widget_backups', true);
if ($saverestorechildwidgets) {
// get Child Theme Slug
// --------------------
if (!function_exists('bioship_admin_get_child_theme_slug')) {
function bioship_admin_get_child_theme_slug() {
$theme = wp_get_theme();
if (!THEMETITAN && THEMEOPT) {$childthemeslug = preg_replace("/\W/", "_", strtolower($theme['Name']));}
else {$childthemeslug = preg_replace("/\W/", "-", strtolower($theme['Name']));}
return $childthemeslug;
}
}
// Switch Theme Hook (on Deactivation)
// -----------------------------------
// 2.1.1: moved add_action internally for consistency
if (!function_exists('bioship_admin_child_theme_deactivation')) {
add_action('switch_theme', 'bioship_admin_child_theme_deactivation');
function bioship_admin_child_theme_deactivation($vnewthemename) {
// Backup Child Theme Widgets and Menus
// ------------------------------------
$childthemeslug = bioship_admin_get_child_theme_slug();
$sidebarswidgets = get_option('sidebars_widgets');
delete_option($childthemeslug.'_widgets_backup');
add_option($childthemeslug.'_widgets_backup', $sidebarswidgets);
$menusettings = get_option('nav_menu_options');
delete_option($childthemeslug.'_menus_backup');
add_option($childthemeslug.'_menus_backup', $menusettings);
}
}
// After Switch Theme Hook (on Activation)
// ---------------------------------------
// 2.1.1: moved add_action internally for consistency
if (!function_exists('bioship_admin_child_theme_activation')) {
add_action('after_switch_theme', 'bioship_admin_child_theme_activation');
function bioship_admin_child_theme_activation() {
// Restore Child Theme Widgets and Menus
// -------------------------------------
$childthemeslug = bioship_admin_get_child_theme_slug();
$backupwidgets = get_option($childthemeslug.'_widgets_backup');
$backupmenus = get_option($childthemeslug.'_menus_backup');
if ($backupwidgets != '') {update_option('sidebars_widgets', $backupwidgets);}
if ($backupmenus != '') {update_option('nav_menu_options', $backupmenus);}
// Also transfer the menu locations from the backup
$menulocations = get_theme_mod('nav_menu_locations');
if (!is_array($menulocations)) {
$menulocations = get_option($childthemeslug.'_menu_locations_backup');
if (is_array($menulocations)) {set_theme_mod('nav_menu_locations', $menulocations);}
}
// Redirect to Theme Options page on theme activation
// --------------------------------------------------
// 1.8.0: redirects to theme options / info page
// 2.0.5: redirect to theme options / customizer with admin_url
global $pagenow;
if (is_admin() && isset($_GET['activated']) && ($pagenow == 'themes.php')) {
if (!THEMETITAN && THEMEOPT) {$url = admin_url('admin.php').'?page=options-framework';}
elseif (THEMETITAN && class_exists('TitanFramework')) {$url = admin_url('admin.php').'?page=bioship-options';}
else {$url = admin_url('customize.php');}
wp_redirect($url); exit;
}
}
}
}
}
// TODO: fix or deprecate? automatic theme mods and menu locations transfer ?
// if (get_option('bioship_transfer_widgets_menus') == 'yes') {
// $transferwidgets = get_option('bioship_widgets_backup');
// update_option('sidebars_widgets', $vtransferwidgets);
//
// $transfermenus = get_option('bioship_menus_backup');
// update_option('nav_menu_options', $transfermenus);
//
// $thememods = get_option('bioship_mods_backup');
// if (count($thememods) > 0) {
// foreach ($thememods as $thememod => $value) {
// set_theme_mod($thememod, $value);
// }
// }
// // $menulocations = get_option('bioship_menu_locations_backup');
// // set_theme_mod('nav_menu_locations', $menulocations);
//
// update_option('bioship_transfer_widgets_menus','done');
// }
// -----------------------------
// === Editor Screen Metabox ===
// -----------------------------
// to override custom values (via muscle_get_display_overrides in muscle.php)
// Perpage Override Metabox
// ------------------------
// Meta Key Notes
// 2.1.1: keys now use _THEMEPREFIX_ instead of just _
// _display_overrides (array) - header, footer, navigation, secondarynav,
// sidebar, subsidebar, headerwidgets, footerwidgets,
// image, title, subtitle, metatop, metabottom, authorbio
// _templating_overrides (array) - TODO: add missing values
// _removefilters (array) - wpautop, wptexturize, convertsmilies, convertchars
// _thumbnailsize (single key) - stores override
// _perpoststyles (single key) - stores style additions
// -----------------------
// Add the Perpage Metabox
// -----------------------
// 1.8.0: renamed from muscle_add_metabox
// 2.0.5: move add_action inside for consistency
if (!function_exists('bioship_admin_add_theme_metabox')) {
add_action('admin_init', 'bioship_admin_add_theme_metabox');
function bioship_admin_add_theme_metabox() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
// --- get custom post types ----
// TODO: add multicheck option for Theme Options Metabox on CPTs
$cpts = array('post', 'page');
$args = array('public' => true, '_builtin' => false);
$cptlist = get_post_types($args, 'names', 'and');
$cpts = array_merge($cpts, $cptlist);
// 2.0.5: add filter for post types metabox
$cpts = bioship_apply_filters('admin_theme_metabox_post_types', $cpts);
// --- metabox position ---
// 2.1.1: added filter for metabox priority position
$priority = bioship_apply_filters('admin_theme_metabox_priority', 'high');
// --- add metaboxes ---
foreach ($cpts as $cpt) {
add_meta_box('theme_metabox', __('Theme Display Overrides','bioship'), 'bioship_admin_theme_metabox', $cpt, 'side', $priority);
}
}
}
// ---------------------
// PerPage Theme Metabox
// ---------------------
// 1.8.0: renamed from muscle_theme_metabox
// 2.0.0: added missing translation wrappers
if (!function_exists('bioship_admin_theme_metabox')) {
function bioship_admin_theme_metabox() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
global $vthemesettings;
// --- get post data ---
// 2.1.1: handle new post (no post ID)
global $post;
if (is_object($post)) {$postid = $post->ID; $posttype = $post->post_type;}
else {
$postid = ''; $posttype = 'post';
if (isset($_REQUEST['post_type'])) {$posttype = $_REQUEST['post_type'];}
}
// --- get current override values ---
$display = bioship_muscle_get_display_overrides($postid);
$override = bioship_muscle_get_templating_overrides($postid);
$removefilters = bioship_muscle_get_content_filter_overrides($postid);
if (THEMEDEBUG) {
echo "";
echo "";
echo "";
echo "";
}
// --- option tab script ---
echo "";
// Button Tabs
// -----------
// 1.9.5: merged filters with content tab and add separate sidebar tab
// 1.9.5: changed _hide prefix to _display_ prefix for form option names
// --- get current options tab ---
// 1.8.0: use separate tab value so only for metabox itself
// 2.1.1: use prefixed post meta key for theme options tab
$settingstab = ''; // empty default
if ($postid != '') {$tab = get_post_meta($postid, '_'.THEMEPREFIX.'_themeoptionstab', true);}
if ($tab) {$settingstab = $tab;}
// --- tab button styles ---
// 2.1.1: added a tag text decoration style
echo "";
// --- theme options tab buttons ---
// 2.1.0: removed filters tab cell/button remnant
// TODO: maybe convert a tags to input buttons ?
echo "
";
// --- content tab button ---
if ($settingstab == 'content') {$bgcolor = " style='background-color:#DDD;'";} else {$bgcolor = '';}
echo " ";
// --- sidebar tab button ---
if ($settingstab == 'sidebar') {$bgcolor = " style='background-color:#DDD;'";} else {$bgcolor = '';}
echo " ";
// --- layout tab button ---
if ($settingstab == 'layout') {$bgcolor = " style='background-color:#DDD;'";} else {$bgcolor = '';}
echo " ";
// --- styles tab button ---
if ($settingstab == 'styles') {echo " style='background-color:#DDD;'";}
echo " ";
echo "
";
// Content Override Tab
// --------------------
if ($settingstab != 'content') {$hide = " style='display:none;'";} else {$hide = '';}
echo "";
echo "
";
// Thumbnail Size Override
// -----------------------
// --- setup available thumbnail sizes ---
if ($posttype == 'page') {$thumbdisplay = esc_attr(__('Featured Image','bioship')); $thumbdefault = $vthemesettings['pagethumbsize'];}
else {$thumbdisplay = esc_attr(__('Thumbnail','bioship')); $thumbdefault = $vthemesettings['postthumbsize'];}
$thumbarray = array(
'thumbnail' => esc_attr(__('Thumbnail','bioship')).' ('.get_option('thumbnail_size_w').' x '.get_option('thumbnail_size_h').')',
'medium' => esc_attr(__('Medium','bioship')).' ('.get_option('medium_size_w').' x '.get_option('medium_size_h').')',
'large' => esc_attr(__('Large','bioship')).' ('.get_option('large_size_w').' x '.get_option('large_size_h').')',
'full' => esc_attr(__('Full Size','bioship')).' ('.__('original','bioship').')'
);
// --- get additional image sizes ---
global $_wp_additional_image_sizes;
$image_sizes = get_intermediate_image_sizes();
$oldsizenames = array('squared150', 'squared250', 'video43', 'video169');
foreach ($image_sizes as $size_name) {
if ( ($size_name != 'thumbnail') && ($size_name != 'medium') && ($size_name != 'large') ) {
// 1.9.8: fix to sporadic undefined index warning (huh? size names should match?)
if (isset($_wp_additional_image_sizes[$size_name])) {
// 2.0.5: no longer output old size names as options
if (!in_array($size_name, $oldsizenames)) {
$thumbarray[$size_name] = $size_name.' ('.$_wp_additional_image_sizes[$size_name]['width'].' x '.$_wp_additional_image_sizes[$size_name]['height'].')';
}
}
}
}
// --- get thumbnail size override ---
// 1.8.0: keep individual meta key for this
// 2.1.1: added theme prefix to thumbnail size metakey
$thumbnailsize = '';
if ($postid != '') {$thumbnailsize = get_post_meta($postid, '_'.THEMEPREFIX.'_thumbnailsize', true);}
// --- maybe convert old thumbnail size names ---
// 2.0.5: maybe convert to prefixed names and update meta
$newthumbsize = false;
if ($thumbnailsize == 'squared150') {$newthumbsize = 'bioship-150s';}
elseif ($thumbnailsize == 'squared250') {$newthumbsize = 'bioship-250s';}
elseif ($thumbnailsize == 'video43') {$newthumbsize = 'bioship-4-3';}
elseif ($thumbnailsize == 'video169') {$newthumbsize = 'bioship-16-9';}
elseif ($thumbnailsize == 'opengraph') {$newthumbsize = 'bioship-opengraph';}
if ($newthumbsize) {
update_post_meta($postid, '_'.THEMEPREFIX.'_thumbnailsize', $newthumbsize);
$thumbnailsize = $newthumbsize;
}
// --- thumbnail size override selector ---
// 2.0.7: fix to text domin typo (bioship.)
echo " ";
echo "";
echo "".$thumbdisplay." ".esc_attr(__('Size','bioship'))." (".esc_attr(__('default','bioship'))." ".esc_attr($thumbdefault).") ";
echo "";
if ($thumbnailsize == '') {$selected = " selected='selected'";} else {$selected = '';}
echo "".esc_attr(__('Theme Settings Default','bioship'))." ";
// 2.1.1: fix to missing option value for no thumbnail
if ($thumbnailsize == 'off') {$selected = " selected='selected'";} else {$selected = '';}
echo "".esc_attr(__('No Thumbail Output','bioship'))." ";
foreach ($thumbarray as $key => $value) {
if ($thumbnailsize == $key) {$selected = " selected='selected'";} else {$selected = '';}
echo "".esc_attr($value)." ";
}
echo " ";
echo " ";
// --- hide thumbnail ---
// 2.1.1.: added missing id for checkbox field
echo "".__('Hide','bioship')." ".$thumbdisplay." ";
if ($display['image'] == '1') {$checked = ' checked';} else {$checked = '';}
echo " ";
echo " ";
// Content Display Overrides
// -------------------------
// --- content override headings ---
echo " ";
echo "".esc_attr(__('Content Display','bioship'))." ";
echo "".esc_attr(__('Hide','bioship'))." ";
// --- content title ---
echo "".esc_attr(__('Title','bioship'))." ";
if ($display['title'] == '1') {$checked = ' checked';} else {$checked = '';}
echo " ";
echo " ";
// ---- content subtitle ---
echo "".esc_attr(__('Subtitle','bioship'))." ";
if ($display['subtitle'] == '1') {$checked = ' checked';} else {$checked = '';}
echo " ";
echo " ";
// --- content meta top ---
echo "".esc_attr(__('Top Meta','bioship'))." ";
if ($display['metatop'] == '1') {$checked = ' checked';} else {$checked = '';}
echo " ";
echo " ";
// --- content meta bottom ---
echo "".esc_attr(__('Bottom Meta','bioship'))." ";
if ($display['metabottom'] == '1') {$checked = ' checked';} else {$checked = '';}
echo " ";
echo " ";
// --- author bio box ---
echo "".__('Author Bio','bioship')." ";
if ($display['authorbio'] == '1') {$checked = ' checked';} else {$checked = '';}
echo " ";
echo " ";
// Filter Overrides
// ----------------
// 1.9.5: merged to content tab from separate filters tab
// --- content filters heading ---
echo " ";
echo "".esc_attr(__('Content Filter','bioship'))." ";
echo "".esc_attr(__('Disable','bioship'))." ";
// --- wpautop filter ---
echo "wpautop ";
if (isset($removefilters['wpautop']) && ($removefilters['wpautop'] == '1') ) {$checked = ' checked';} else {$checked = '';}
echo " ";
echo " ";
// --- wptexturize filter ---
echo "wptexturize ";
if (isset($removefilters['wptexturize']) && ($removefilters['wptexturize'] == '1') ) {$checked = ' checked';} else {$checked = '';}
echo " ";
echo " ";
// --- convert_smilies filter ---
echo "convert_smilies ";
if (isset($removefilters['convertsmilies']) && ($removefilters['convertsmilies'] == '1') ) {$checked = ' checked';} else {$checked = '';}
echo " ";
echo " ";
// --- convert_chars filter ---
echo "convert_chars ";
if (isset($removefilters['convertchars']) && ($removefilters['convertchars'] == '1') ) {$checked = ' checked';} else {$checked = '';}
echo " ";
echo " ";
// --- quicksave settings button ---
echo " ";
echo "".esc_attr(__('Saved!','bioship'))."
";
echo " ";
echo " ";
echo " ";
// --- close content tab ---
echo "
";
// Sidebar Overrides
// -----------------
// TODO: add display of total column width ?
// 1.9.5: separate tab for sidebar overrides
if ($settingstab != 'sidebar') {$hide = " style='display:none;'";} else {$hide = '';}
echo "";
// Layout Overrides
// ----------------
if ($settingstab != 'layout') {$hide = " style='display:none;'";} else {$hide = '';}
echo "";
echo "
";
// --- layout overrides heading ---
echo "";
echo "".esc_attr(__('Layout Display Overrides','bioship'))." ";
echo " ";
// --- no wrap margins (full width) ---
// 1.8.5: added full width container option (no wrap margins)
echo "".esc_attr(__('No Wrap Margins','bioship'))." ";
if ($display['wrapper'] == '1') {$checked = ' checked';} else {$checked = '';}
echo " ";
echo " ";
// --- hide header ---
echo "".esc_attr(__('Hide Header','bioship'))." ";
if ($display['header'] == '1') {$checked = ' checked';} else {$checked = '';}
echo "";
echo " ";
// --- hide footer ---
echo "".esc_attr(__('Hide Footer','bioship'))." ";
if ($display['footer'] == '1') {$checked = ' checked';} else {$checked = '';}
echo "";
echo " ";
// TODO: general layout displays?
// Header Logo / Title Text / Description / Extras
// Footer Extras / Site Credits
// --- navigation display headings ---
// 1.9.8: fix to headernav and footernav keys
echo " ";
echo "".esc_attr(__('Navigation Display','bioship'))." ";
echo "".esc_attr(__('Hide','bioship'))." ";
// --- main navigation menu ---
echo "".esc_attr(__('Main Nav Menu','bioship'))." ";
if ($display['navigation'] == '1') {$checked = ' checked';} else {$checked = '';}
echo " ";
echo " ";
// --- secondary navigation ---
echo "".esc_attr(__('Secondary Nav Menu','bioship'))." ";
if ($display['secondarynav'] == '1') {$checked = ' checked';} else {$checked = '';}
echo " ";
echo " ";
// --- header navigation menu ---
echo "".esc_attr(__('Header Nav Menu','bioship'))." ";
if ($display['headernav'] == '1') {$checked = ' checked';} else {$checked = '';}
echo "";
echo " ";
// --- footer navigation menu ---
echo "".esc_attr(__('Footer Nav Menu','bioship'))." ";
if ($display['footernav'] == '1') {$checked = ' checked';} else {$checked = '';}
echo "";
echo " ";
// --- breadcrumbs ---
echo "".esc_attr(__('Breadcrumbs','bioship'))." ";
if ($display['breadcrumb'] == '1') {$checked = ' checked';} else {$checked = '';}
echo " ";
echo " ";
// --- page navi ---
echo "".esc_attr(__('Post/Page Navi','bioship'))." ";
if ($display['pagenavi'] == '1') {$checked = ' checked';} else {$checked = '';}
echo " ";
echo " ";
// --- quicksave settings button ---
echo " ";
echo "".esc_attr(__('Saved!','bioship'))."
";
echo " ";
echo " ";
echo " ";
// --- close layout override tab ---
echo "
";
// Style Overrides
// ---------------
// 1.8.0: javascript to expand/collapse style box
// 2.1.1: added marginTop to help prevent editor overlay
echo "";
// 2.1.1: added .quicksavesettings class
echo "";
// --- get per post styles ---
// 1.8.0: keep individual meta key for this
// 2.1.1: added theme prefix to post metakey
$perpoststyles = '';
if ($postid != '') {$perpoststyles = get_post_meta($postid, '_'.THEMEPREFIX.'_perpoststyles', true);}
// --- per post styles tab ---
if ($settingstab != 'styles') {$hide = " style='display:none;'";} else {$hide = '';}
echo "";
// --- end tabs output ---
echo "";
// --- theme options current tab saver ---
echo "
";
echo "
";
// --- enqueue quicksave forms ---
// 1.9.5: added quicksave perpost CSS form to footer
add_action('admin_footer', 'bioship_admin_quicksave_perpost_css_form');
// 2.0.0: added quicksave perpost settings form to footer (prototype)
add_action('admin_footer', 'bioship_admin_quicksave_perpost_settings_form');
// 2.1.1: added quicksave cyclic nonce refresher
add_action('admin_footer', 'bioship_admin_quicksave_nonce_refresher');
}
}
// ---------------------
// Update Metabox Values
// ---------------------
add_action('publish_post', 'bioship_admin_update_metabox_options');
add_action('save_post', 'bioship_admin_update_metabox_options');
// 1.8.0: renamed from muscle_update_metabox_options
if (!function_exists('bioship_admin_update_metabox_options')) {
function bioship_admin_update_metabox_options() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
// --- check post values ---
// 1.9.8: return if post is empty
global $post; if (!is_object($post)) {return;}
$postid = $post->ID;
// --- check for autosave ---
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {return;}
// --- check user capabilities ---
// 1.8.0: cleaner save logic here
if (!current_user_can('edit_posts') || !current_user_can('edit_post', $postid)) {return $postid;}
// --- save display overrides --
// 1.8.0: grouped display overrides to array
// 1.8.5: added headernav, footernav, breadcrumbs, pagenavi
$display = array(); $postdata = false;
$displaykeys = array(
'wrapper', 'header', 'footer', 'navigation', 'secondarynav', 'headernav', 'footernav',
'sidebar', 'subsidebar', 'headerwidgets', 'footerwidgets', 'footer1', 'footer2', 'footer3', 'footer4',
'image', 'breadcrumb', 'title', 'subtitle', 'metatop', 'metabottom', 'authorbio', 'pagenavi'
);
// 1.9.5: changed _hide prefix to _display_
foreach ($displaykeys as $key) {
if (!isset($_POST['_display_'.$key])) {$display[$key] = '';}
else {
if ($_POST['_display_'.$key] == '1') {$display[$key] = '1'; $postdata = true;}
else {$display[$key] = '';}
}
}
// 1.9.9: check and save only if new post data
// 2.1.1: use prefixed metakey for saving
// 2.1.1: set unique argument to true here
delete_post_meta($postid, '_'.THEMEPREFIX.'_display_overrides');
if ($postdata) {add_post_meta($postid, '_'.THEMEPREFIX.'_display_overrides', $display, true);}
// --- save layout overrides ---
// 1.9.5: added override keys
$override = array(); $postdata = false;
$overridekeys = array(
'contentcolumns', 'sidebarcolumns', 'subsidebarcolumns', 'sidebarposition', 'subsidebarposition',
'sidebartemplate', 'subsidebartemplate', 'sidebarcustom', 'subsidebarcustom'
);
foreach ($overridekeys as $key) {
if (!isset($_POST['_'.$key])) {$override[$key] = '';}
else {$override[$key] = $_POST['_'.$key]; $postdata = true;}
}
delete_post_meta($postid, '_'.THEMEPREFIX.'_templating_overrides');
// 1.9.9: check and save if new post data
// 2.1.1: use prefixed metakey for saving
if ($postdata) {add_post_meta($postid, '_'.THEMEPREFIX.'_templating_overrides', $override);}
// --- save filter overrides ---
// 1.8.0: grouped filters to array
// 2.0.0: better checkbox save logic
$removefilters = array(); $postdata = false;
$filters = array('wpautop', 'wptexturize', 'convertsmilies', 'convertchars');
foreach ($filters as $filter) {
if (!isset($_POST['_'.$filter])) {$removefilters[$filter] = '';}
else {
if ($_POST['_'.$filter] == '1') {$removefilters[$filter] = '1'; $postdata = true;}
else {$removefilters[$filter] = '';}
}
}
delete_post_meta($postid, '_'.THEMEPREFIX.'_removefilters');
// 1.9.9: check and save if new filters
// 2.0.0: save if post data found
// 2.1.1: use prefixed metakey for saving
if ($postdata) {add_post_meta($postid, '_'.THEMEPREFIX.'_removefilters', $removefilters, true);}
// --- save individual options ---
// 1.8.0: save individual key values
$optionkeys = array('_perpoststyles', '_thumbnailsize', '_themeoptionstab');
foreach ($optionkeys as $option) {
// 1.9.9: make sure option value is actually set (as metabox may be removed)
if (isset($_POST[$option])) {
$optionvalue = $_POST[$option];
if ($option == '_perpoststyles') {$optionvalue = stripslashes($optionvalue);}
// 2.1.1: use prefixed metakey for saving
$option = str_replace('_', '_'.THEMEPREFIX.'_', $option);
delete_post_meta($postid, $option);
// 1.9.5: to make cleaner, do not save empty values
if (trim($optionvalue) != '') {add_post_meta($postid, $option, $optionvalue, true);}
$options[$option] = $optionvalue;
}
}
// --- manual debug of per post options ---
// $metasavedebug = false;
$metasavedebug = true;
if ($metasavedebug) {
$debuginfo = PHP_EOL." Saved Post ".$postid." at ".date('j/m/d H:i:s', time()).PHP_EOL;
$debuginfo .= "--- Override ---".PHP_EOL; foreach ($override as $key => $value) {$debuginfo .= $key.': '.$value.PHP_EOL;}
$debuginfo .= "--- Display ---".PHP_EOL; foreach ($display as $key => $value) {$debuginfo .= $key.': '.$value.PHP_EOL;}
$debuginfo .= "--- Filters ---".PHP_EOL; foreach ($removefilters as $key => $value) {$debuginfo .= $key.': '.$value.PHP_EOL;}
// 2.1.2: fix for possible undefined variable warning
if (isset($options)) {$debuginfo .= "--- Options ---".PHP_EOL; foreach ($options as $key => $value) {$debuginfo .= $key.': '.print_r($value,true).PHP_EOL;} }
// $debuginfo .= "--- Posted ---".PHP_EOL; foreach ($posted as $key => $value) {$debuginfo .= $key.': '.print_r($value,true).PHP_EOL;}
bioship_write_debug_file('perpost-debug-'.$postid.'.txt', $debuginfo);
}
}
}
// --------------------------
// QuickSave PerPost CSS Form
// --------------------------
// 1.9.5: added this CSS quicksave form
if (!function_exists('bioship_admin_quicksave_perpost_css_form')) {
function bioship_admin_quicksave_perpost_css_form() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
// --- quicksave CSS scripts ---
// 2.1.2: moved quicksave show fadeout to AJAX action
echo "";
// --- get perpost styles ---
global $post; $postid = $post->ID;
// 2.0.8: use prefixed post meta key
// 2.1.1: do not convert old values here
$perpoststyles = get_post_meta($postid, '_'.THEMEPREFIX.'_perpoststyles', true);
// --- perpost styles form ---
// 2.1.1: use wp_create_nonce instead of wp_nonce_field
$adminajax = admin_url('admin-ajax.php');
echo "
";
// --- perpost styles saving iframe ---
echo "
";
}
}
// ---------------------
// QuickSave PerPost CSS
// ---------------------
// 1.9.5: added this CSS quicksave
if (!function_exists('bioship_admin_quicksave_perpost_css')) {
add_action('wp_ajax_quicksave_perpost_css', 'bioship_admin_quicksave_perpost_css');
// 2.1.1: also trigger for not logged in for logged out alert message display
add_action('wp_ajax_nopriv_quicksave_perpost_css', 'bioship_admin_quicksave_perpost_css');
function bioship_admin_quicksave_perpost_css() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
// --- get edit post ID ---
if (!isset($_POST['postid']) || !isset($_POST['newperpoststyles'])) {exit;}
$postid = $_POST['postid'];
if (!is_numeric($postid)) {exit;}
// --- check if logged in ---
// 2.1.1: added user logged in check
if (is_user_logged_in()) {
// --- check edit permissions ---
if (current_user_can('edit_posts') && current_user_can('edit_post', $postid)) {
// --- check nonce ---
// 2.0.0: use wp_verify_nonce instead of check_admin_referer for error message output
$checknonce = false;
if (isset($_POST['_wpnonce'])) {
$nonce = $_POST['_wpnonce'];
$checknonce = wp_verify_nonce($nonce, 'quicksave-perpost-css-'.$postid);
}
// --- update perpost styles ---
if ($checknonce) {
$newstyles = stripslashes($_POST['newperpoststyles']);
// 2.1.1: use prefixed perpost styles metakey
update_post_meta($postid, '_'.THEMEPREFIX.'_perpoststyles', $newstyles);
} else {$error = __('Whoops! Nonce has expired. Try reloading the page.','bioship');}
// --- update current tab to styles ---
update_post_meta($postid, '_'.THEMEPREFIX.'_themeoptionstab', 'styles');
} else {$error = __('Failed! You do not have permission to edit this post.','bioship');}
} else {$error = __('Failed. Looks like you may need to login again!','bioship');}
// --- script output and exit ---
if (isset($error)) {echo "";}
else {echo "";}
exit;
}
}
// -------------------------------
// QuickSave PerPost Settings Form
// -------------------------------
// 2.0.0: dummy form copy to save all metabox theme option overrides (prototype)
if (!function_exists('bioship_admin_quicksave_perpost_settings_form')) {
function bioship_admin_quicksave_perpost_settings_form() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
// --- set perpost metabox settings keys ---
$checkboxkeys = array(
'display_wrapper', 'display_header', 'display_footer', 'display_navigation', 'display_secondarynav', 'display_headernav', 'display_footernav',
'display_sidebar', 'display_subsidebar', 'display_headerwidgets', 'display_footerwidgets', 'display_footer1', 'display_footer2', 'display_footer3', 'display_footer4',
'display_image', 'display_breadcrumb', 'display_title', 'display_subtitle', 'display_metatop', 'display_metabottom', 'display_authorbio', 'display_pagenavi',
'wpautop', 'wptexturize', 'convertsmilies', 'convertchars' // filter keys
);
$selectkeys = array(
'contentcolumns', 'sidebarcolumns', 'subsidebarcolumns', 'sidebarposition', 'subsidebarposition',
'sidebartemplate', 'subsidebartemplate', 'thumbnailsize' // *
);
$textkeys = array('sidebarcustom', 'subsidebarcustom');
// --- convert settings inputs to javascript arrays ---
$settingskeys = '';
foreach ($checkboxkeys as $i => $key) {$settingskeys .= "checkboxkeys[".$i."] = '".$key."'; "; $i++;}
$settingskeys .= PHP_EOL;
foreach ($selectkeys as $j => $key) {$settingskeys .= "selectkeys[".$j."] = '".$key."'; "; $j++;}
$settingskeys .= PHP_EOL;
foreach ($textkeys as $k => $key) {$settingskeys .= "textkeys[".$k."] = '".$key."'; "; $k++;}
$settingskeys .= PHP_EOL;
// --- output settings save script ---
// 2.1.1: added tab for displaying message and saving current tab
echo "";
// --- quicksave settings form ---
// 2.1.1: added buttonid and tab fields
// 2.1.1: use wp_create_nonce instead of wp_nonce_field
global $post; $postid = $post->ID;
$adminajax = admin_url('admin-ajax.php');
echo "
";
// --- quicksave settings iframe ---
echo "
";
}
}
// --------------------------
// QuickSave PerPost Settings
// --------------------------
// 2.0.0: save theme overrides via AJAX trigger (prototype)
if (!function_exists('bioship_admin_update_metabox_settings')) {
add_action('wp_ajax_quicksave_perpost_settings', 'bioship_admin_update_metabox_settings');
// 2.1.1: also trigger for not logged in for logged out alert message display
add_action('wp_ajax_nopriv_quicksave_perpost_settings', 'bioship_admin_update_metabox_settings');
function bioship_admin_update_metabox_settings() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
// --- check trigger conditions
if (!isset($_REQUEST['postid'])) {exit;}
$postid = $_REQUEST['postid'];
if (!is_numeric($postid)) {exit;}
$error = false;
// --- check if logged in ---
// 2.1.1: added user logged in check
if (is_user_logged_in()) {
// --- check permissions ---
if (current_user_can('edit_posts') && current_user_can('edit_post', $postid)) {
// --- check nonce ---
$checknonce = false;
if (isset($_POST['_wpnonce'])) {
$nonce = $_POST['_wpnonce'];
$checknonce = wp_verify_nonce($nonce, 'quicksave-perpost-settings-'.$postid);
}
if ($checknonce) {
global $post; $post = get_post($postid);
bioship_admin_update_metabox_options();
} else {$error = __('Whoops! Nonce has expired. Try reloading the page.','bioship');}
// --- update current options tab
// 2.1.1: added saving of current tab
$tab = $_POST['tab'];
update_post_meta($postid, '_'.THEMEPREFIX.'_themeoptionstab', $tab);
} else {$error = __('Failed! You do not have permission to edit this post.','bioship');}
} else {$error = __('Failed! Looks like you may need to login again!','bioship');}
// --- output script and exit ---
// 2.1.1: added tab argument for saved message display
if ($error) {echo "";}
else {echo "";}
exit;
}
}
// --------------------------------
// QuickSave Cyclic Nonce Refresher
// --------------------------------
if (!function_exists('bioship_admin_quicksave_nonce_refresher')) {
function bioship_admin_quicksave_nonce_refresher() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
// --- output cyclic nonce refresh script ---
global $post; $postid = $post->ID;
$adminajax = admin_url('admin-ajax.php');
echo "";
// --- hidden doing refresh input ---
// 2.1.1: added input to prevent possible multiple alerts
echo "
";
// --- quicksave nonce refresh iframe ---
echo "
";
}
}
// --------------------------
// Update MetaBox Nonces AJAX
// --------------------------
if (!function_exists('bioship_admin_update_quicksave_nonces')) {
add_action('wp_ajax_quicksave_update_nonces', 'bioship_admin_update_quicksave_nonces');
// 2.1.1: also trigger for not logged in for logged out alert message display
add_action('wp_ajax_nopriv_update_nonces', 'bioship_admin_update_quicksave_nonces');
function bioship_admin_update_quicksave_nonces() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
// --- get post ID ---
$postid = $_REQUEST['postid'];
if (!isset($_REQUEST['postid'])) {exit;}
$postid = $_REQUEST['postid'];
if (!is_numeric($postid)) {exit;}
// --- session timeout message ---
// 2.1.1: added alert message to inform of session timeout
// TODO: trigger showing of popup interim login thickbox ?
if (!is_user_logged_in()) {
$message = __('Your session has timed out. Please Login again to continue editing.','bioship');
echo "";
exit;
}
// --- check edit permissions ---
if (!current_user_can('edit_posts') || !current_user_can('edit_post', $postid)) {exit;}
// --- create new nonces ---
$settingsnonce = wp_create_nonce('quicksave-perpost-settings-'.$postid);
$cssnonce = wp_create_nonce('quicksave-perpost-css-'.$postid);
// --- send new nonces back to parent window ---
// 2.1.1: reset doing nonce refresh flag on refresh
echo "";
exit;
}
}
// ---------------------
// === Theme Plugins ===
// ---------------------
// ----------------------------------
// Install the Titan Framework Plugin
// ----------------------------------
// this method creates a standalone callable installation link for
// adding Titan Framework to the WordPress.Org version of theme
// (currently done via TGMPA using Titan Checker, rather than here)
// 1.8.5: moved here from customizer.php
// 2.1.1: moved check trigger internally for consistency
// Note: Otto's Theme Plugin Dependency Class
// ref: http://ottopress.com/2012/themeplugin-dependencies/
if (!function_exists('bioship_admin_install_titan_framework')) {
add_action('init', 'bioship_admin_install_titan_framework');
function bioship_admin_install_titan_framework() {
// --- check trigger conditions ---
if (!isset($_REQUEST['admin_install_titan_framework'])) {return;}
if ($_REQUEST['admin_install_titan_framework'] != 'yes') {return;}
// --- check permissions ---
if (!current_user_can('install_plugins')) {return;}
// IDEA: maybe extracting from a bundled zip could work here..?
// eg: http://meta.wordpress.stackexchange.com/questions/4172/script-that-downloads-installs-and-activates-wordpress-plugins?cb=1
// --- install Titan Framework ---
// 2.1.1: use add_query_arg for install URL
$titanslug = 'titan-framework';
$installurl = add_query_arg('action', 'install-plugin', self_admin_url('update.php'));
$installurl = add_query_arg('plugin', $titanslug, $installurl);
$installurl = wp_nonce_url($installurl, 'install-plugin_'.$titanslug);
wp_redirect($installurl); exit;
}
}
// --------------------------
// Load TGM Plugin Activation
// --------------------------
if (!function_exists('tgmpa')) {
$tgmpa = bioship_file_hierarchy('file', 'class-tgm-plugin-activation.php', array('includes'));
if ($tgmpa) {require_once($tgmpa);}
}
// ---------------------------
// === Recommended Plugins ===
// ---------------------------
// 'Required' Plugins
// ------------------
// - Titan Framework (better admin theme options interface)
// -- for WordPress.Org installs (not explicitly 'required')
// Recommended Plugins (Theme Supported)
// -------------------------------------
// TODO: retest need for Widget Saver ?
// TODO: force use of specific TML version ?
// - AJAX Load More
// - Open Graph Protocol Framework
// - Theme My Login
// - Theme Test Drive
// - Widget Saver
// - WP Subtitle
// - WP PageNavi
// WordQuest Plugins
// -----------------
// - AutoSave Net (released)
// - Content Sidebars (released)
// - Guten Free Options (released)
// - WP AutoMedic (released)
// Upcoming WordQuest Plugins
// --------------------------
// - ForceField (pending)
// - RefleXedit (testing)
// - PDF Replicator (testing)
// - PDF Shuttle (testing)
// - WP Infinity Responder (updating)
// - Visitor Vortex (updating)
// - WarpPress Builder (development)
// - FreeStyler (development)
if (function_exists('tgmpa')) {
// TESTME: this is done separately via Titan Checker now, but this calls
// TGMPA separately as well as a new instance - which may or may not be desirable?
// 1.9.8: recommend Titan Framework plugin for Wordpress.org installs
add_filter('tgm_plugins_array', 'bioship_admin_tgm_titan_framework_check');
if (!function_exists('bioship_admin_tgm_titan_framework_check')) {
function bioship_admin_tgm_titan_framework_check($plugins) {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
// 2.0.9: only for WordPress.org version and when Titan Framework is not present
if (!THEMEWPORG || THEMETITAN || class_exists('TitanFramework')) {return $plugins;}
// 2.0.9: fix (override) Titan Framework checker 'required' setting to false
$foundtitan = false;
foreach ($plugins as $i => $plugin) {
if ($plugin['slug'] == 'titan-framework') {
$plugin['required'] = false;
$plugins[$i] = $plugin;
$foundtitan = true;
}
}
if (!$foundtitan) {
$plugins[] = array(
'name' => 'Titan Framework',
'slug' => 'titan-framework',
'required' => false
);
}
return $plugins;
}
}
// TGMPA seems to need at least WP 3.7...
if (!version_compare($wp_version,'3.7','<')) { //'>
// TGMPA Theme Options Page - Notice Display Workaround
// to use the plugin recommendation notice on the theme options page
// - whether it has already been dismissed by the user or not! :-)
if (isset($_REQUEST['page'])) {
// 1.8.0: allow for Titan Framework admin page URL
// 2.0.9: use THEMESLUG constance instead of vthemename
if ( ($_REQUEST['page'] == 'options-framework')
|| ($_REQUEST['page'] == THEMESLUG.'-options')
|| ($_REQUEST['page'] == THEMESLUG.'_options') ) {
// hook in before init as this is when TGM loads
add_action('plugins_loaded', 'bioship_admin_tgm_notice_shift');
// make the notice undismissable on theme page only via config filter
add_filter('tgm_config_array', 'bioship_admin_tgm_dismiss_notice_off');
}
}
// Notice Shift
// ------------
if (!function_exists('bioship_admin_tgm_notice_shift')) {
function bioship_admin_tgm_notice_shift() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
// 2.1.1: use THEMEPREFIX constant instead of hardcoded
$id = THEMESLUG.'-tgmpa'; // TGM instance id
$currentuserid = get_current_user_id();
if (get_user_meta($currentuserid, 'tgmpa_dismissed_notice_'.$id, true)) {
add_user_meta($currentuserid, 'tgmpa_temp_notice_'.$id, 1);
delete_user_meta($currentuserid, 'tgmpa_dismissed_notice_'.$id);
add_action('all_admin_notices', 'bioship_admin_tgm_notice_unshift', 100);
}
}
}
// Notice Unshift
// --------------
if (!function_exists('bioship_admin_tgm_notice_unshift')) {
function bioship_admin_tgm_notice_unshift() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
$id = THEMESLUG.'-tgmpa'; // TGM instance id
$currentuserid = get_current_user_id();
// 2.0.9: fix to match temporary notice key
delete_user_meta($currentuserid, 'tgmpa_temp_notice_'.$id);
add_user_meta($currentuserid, 'tgmpa_dismissed_notice_'.$id, 1);
}
}
// Notice Off
// ----------
if (!function_exists('bioship_admin_tgm_dismiss_notice_off')) {
function bioship_admin_tgm_dismiss_notice_off($config) {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__,func_get_args());}
// --- filter the theme page message ---
$message = '
'.__('BioShip Theme Framework Recommended Plugins','bioship').' ';
$message = bioship_apply_filters('tgm_theme_page_message', $message);
// --- change the existing config ---
$config['dismissable'] = false;
$config['dismiss_msg'] = $message;
return $config;
}
}
// Register Plugins using TGMPA
// ----------------------------
// 1.8.0: renamed from muscle_register_plugins
add_action('tgmpa_register', 'bioship_admin_register_plugins');
// Create an array of plugins and config
// -------------------------------------
// Note: see includes/tgm-examples.php for more detailed plugin examples
// Ref: http://tgmpluginactivation.com/configuration/
if (!function_exists('bioship_admin_register_plugins')) {
function bioship_admin_register_plugins() {
if (THEMETRACE) {bioship_trace('F',__FUNCTION__,__FILE__);}
/*
* TGMPA: Array of plugin arrays. Required keys are name and slug.
* If the source is NOT from the .org repo, then source is also required.
*/
// note: Originally recommended by SPML Skeleton Theme: Simple Shortcodes (smpl-shortcodes)
$plugins = array(
array(
'name' => 'AJAX Load More',
'slug' => 'ajax-load-more',
'required' => false,
),
array(
'name' => 'Better WordPress Minify',
'slug' => 'bwp-minify',
'required' => false,
),
array(
'name' => 'Open Graph Protocol Framework',
'slug' => 'open-graph-protocol-framework',
'required' => false,
),
array(
'name' => 'Theme My Login',
'slug' => 'theme-my-login',
'required' => false
),
array(
'name' => 'Theme Test Drive',
'slug' => 'theme-test-drive',
'required' => false,
),
array(
'name' => 'Widget Saver',
'slug' => 'widget-saver',
'required' => false,
),
array(
'name' => 'WP Subtitle',
'slug' => 'wp-subtitle',
'required' => false,
),
array(
'name' => 'WP Pagenavi',
'slug' => 'wp-pagenavi',
'required' => false,
),
// WordQuest (Theme) Plugins
// -------------------------
// 1.9.8: removed unreleased plugins
// 2.0.5: re-added released plugins
// 2.0.9: added WP AutoMedic release
// 2.1.1: added Guten Free Options plugin
// 2.1.1: added wq flag for source handling
// --- AutoSave Net ---
array(
'name' => 'AutoSave Net',
'slug' => 'autosave-net',
'required' => false,
'wq' => true,
),
// --- Content Sidebars ---
array(
'name' => 'Content Sidebars',
'slug' => 'content-sidebars',
'required' => false,
'wq' => true,
),
// --- Guten Free Options ---
array(
'name' => 'Guten Free Options',
'slug' => 'guten-free-options',
'required' => false,
'wq' => true,
),
// --- WP AutoMedic ---
array(
'name' => 'WP AutoMedic',
'slug' => 'wp-automedic',
'required' => false,
'wq' => true,
),
);
// 2.1.1: change plugin source info if not WordPress.Org version
if (!THEMEWPORG) {
$wqurl = 'http://wordquest.org';
foreach ($plugins as $i => $plugin) {
if (isset($plugin['wq']) && $plugin['wq']) {
$plugins[$i]['source'] = $wqurl.'/downloads/packages/'.$plugin['slug'].'.zip';
$plugins[$i]['external_url'] = $wqurl.'/plugins/'.$plugin['slug'].'/';
}
}
}
// --- filter the plugins array ---
$plugins = bioship_apply_filters('tgm_plugins_array', $plugins);
/*
* TGMPA: Array of configuration settings. Amend each line as needed.
*
*/
// --- filter the TGM plugins page message ---
$message = '
'.__('BioShip Theme Framework','bioship');
$message .= ' - '.__('Recommended Plugins','bioship').' ';
$message = bioship_apply_filters('tgm_plugin_page_message', $message);
// --- filter the bundle path ---
// 2.0.9: changed from /includes/plugins/ for possible future usage
$bundlespath = get_template_directory().'/includes/bundled/';
$bundlespath = bioship_apply_filters('tgm_plugin_bundles_path', $bundlespath);
// note: id (instance) set to bioship-tgmpa to prevent conflicts
$config = array(
'id' => THEMESLUG.'-tgmpa', // Unique ID for hashing notices for multiple instances of TGMPA.
'default_path' => $bundlespath, // Default absolute path to bundled plugins.
'menu' => 'tgmpa-install-plugins', // Menu slug.
'parent_slug' => 'themes.php', // Parent menu slug.
'capability' => 'edit_theme_options', // Capability needed to view plugin install page, should be a capability associated with the parent menu used.
'has_notices' => true, // Show admin notices or not.
'dismissable' => true, // If false, a user cannot dismiss the nag message.
'dismiss_msg' => '', // If 'dismissable' is false, this message will be output at top of nag.
'is_automatic' => true, // Automatically activate plugins after installation or not.
'message' => $message, // Message to output right before the plugins table.
'strings' => array(
'page_title' => __( 'Install Recommended Plugins', 'bioship' ),
'menu_title' => __( 'Theme Plugins', 'bioship' ),
'installing' => __( 'Installing Plugin: %s', 'bioship' ), // %s = plugin name.
'oops' => __( 'Something went wrong with the plugin API.', 'bioship' ),
'notice_can_install_required' => _n_noop(
'This theme requires the following plugin: %1$s.',
'This theme requires the following plugins: %1$s.',
'bioship'
), // %1$s = plugin name(s).
'notice_can_install_recommended' => _n_noop(
'This theme recommends the following plugin: %1$s.',
'This theme recommends the following plugins: %1$s.',
'bioship'
), // %1$s = plugin name(s).
'notice_cannot_install' => _n_noop(
'Sorry, but you do not have the correct permissions to install the %1$s plugin.',
'Sorry, but you do not have the correct permissions to install the %1$s plugins.',
'bioship'
), // %1$s = plugin name(s).
'notice_ask_to_update' => _n_noop(
'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this theme: %1$s.',
'The following plugins need to be updated to their latest version to ensure maximum compatibility with this theme: %1$s.',
'bioship'
), // %1$s = plugin name(s).
'notice_ask_to_update_maybe' => _n_noop(
'There is a plugin update available for: %1$s.',
'There are updates available for the following plugins: %1$s.',
'bioship'
), // %1$s = plugin name(s).
'notice_cannot_update' => _n_noop(
'Sorry, but you do not have the correct permissions to update the %1$s plugin.',
'Sorry, but you do not have the correct permissions to update the %1$s plugins.',
'bioship'
), // %1$s = plugin name(s).
'notice_can_activate_required' => _n_noop(
'Warning! The following required plugin is currently inactive: %1$s.',
'Warning! The following required plugins are currently inactive: %1$s.',
'bioship'
), // %1$s = plugin name(s).
'notice_can_activate_recommended' => _n_noop(
'The following recommended plugin is currently inactive: %1$s.',
'The following recommended plugins are currently inactive: %1$s.',
'bioship'
), // %1$s = plugin name(s).
'notice_cannot_activate' => _n_noop(
'Sorry, but you do not have the correct permissions to activate the %1$s plugin.',
'Sorry, but you do not have the correct permissions to activate the %1$s plugins.',
'bioship'
), // %1$s = plugin name(s).
'install_link' => _n_noop('Begin installing plugin', 'Begin installing plugins', 'bioship') ,
'update_link' => _n_noop('Begin updating plugin', 'Begin updating plugins', 'bioship' ),
'activate_link' => _n_noop('Begin activating plugin', 'Begin activating plugins', 'bioship' ),
'return' => __( 'Return to Recommended Plugins Installer', 'bioship' ),
'plugin_activated' => __( 'Plugin activated successfully.', 'bioship' ),
'activated_successfully' => __( 'The following plugin was activated successfully:', 'bioship' ),
'plugin_already_active' => __( 'No action taken. Plugin %1$s was already active.', 'bioship' ), // %1$s = plugin name(s).
'plugin_needs_higher_version' => __( 'Plugin not activated. A higher version of %s is needed for this theme. Please update the plugin.', 'bioship' ), // %1$s = plugin name(s).
'complete' => __( 'All plugins installed and activated successfully. %1$s', 'bioship' ), // %s = dashboard link.
'contact_admin' => __( 'Please contact the administrator of this site for help.', 'bioship' ),
'nag_type' => 'updated', // Determines admin notice type - can only be 'updated', 'update-nag' or 'error'.
),
);
// --- filter the TGMPA config ---
$config = bioship_apply_filters('tgm_config_array', $config);
// --- load TGM Plugin Activation ---
tgmpa($plugins, $config);
}
}
}
}