Skip to content

Instantly share code, notes, and snippets.

@yhira
Last active April 27, 2019 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yhira/07b84654e995b9440d8fc9503b19c706 to your computer and use it in GitHub Desktop.
Save yhira/07b84654e995b9440d8fc9503b19c706 to your computer and use it in GitHub Desktop.
スキン切り換えデモ
add_shortcode('skin', function (){
$skin = isset($_GET['theme-switch']) ? esc_html($_GET['theme-switch']) : null;
if (empty($skin) && isset($_COOKIE['theme-switch'])) {
$skin = esc_html($_COOKIE['theme-switch']);
}
$url = get_permalink().'?';
ob_start();
?>
<select id="theme-switch" class="theme-switch-dropdown" onchange="document.cookie = this.options[this.selectedIndex].value;window.document.location.href='<?php echo $url; ?>'+this.options[this.selectedIndex].value;">
<option value="theme-switch=reset" <?php the_option_selected($skin, null); ?>>▼デザインスキンを選択</option>
<option value="theme-switch=cocoon-master" <?php the_option_selected($skin, 'cocoon-master'); ?>>Cocoonデフォルト</option>
<option value="theme-switch=skin-simplicity" <?php the_option_selected($skin, 'skin-simplicity'); ?>>Like Simplicity</option>
<option value="theme-switch=skin-colors-red" <?php the_option_selected($skin, 'skin-colors-red'); ?>>COLORS(レッド)</option>
<option value="theme-switch=skin-colors-blue" <?php the_option_selected($skin, 'skin-colors-blue'); ?>>COLORS(ブルー)</option>
<option value="theme-switch=skin-colors-yellow" <?php the_option_selected($skin, 'skin-colors-yellow'); ?>>COLORS(イエロー)</option>
<option value="theme-switch=skin-colors-green" <?php the_option_selected($skin, 'skin-colors-green'); ?>>COLORS(グリーン)</option>
<option value="theme-switch=skin-colors-pink" <?php the_option_selected($skin, 'skin-colors-pink'); ?>>COLORS(ピンク)</option>
</select>
<?php
return ob_get_clean();
});
function get_skin_url(){
$ts = isset($_COOKIE['theme-switch']) ? esc_html($_COOKIE['theme-switch']) : null;
if (isset($_GET['theme-switch'])) {
setcookie('theme-switch',esc_html($_GET['theme-switch']),time()+60*60*24*7);
}
$gts = isset($_GET['theme-switch']) ? esc_html($_GET['theme-switch']) : null;
$ts = empty($ts) ? $gts : $ts;
switch ($ts) {
case 'reset':
case 'cocoon-master':
setcookie('theme-switch','',time()+60*60*24*7);
return;
break;
default:
if ($ts) {
return get_template_directory_uri().'/skins/'.$ts.'/style.css';
} else {
return get_theme_option(OP_SKIN_URL, '');
}
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment