'Y', 'site_title_enabled' => 'Y', 'site_description_enabled' => 'Y', 'navbar_brand' => 'Project Name', 'navbar_location' => 'default', 'navbar_gradient' => 'Y', 'copyright' => date('Y ') . get_option('blogname'), 'show_home' => 'N', 'reduce_404_page' => 'N', 'disable_comment_page' => 'N', 'sidebar_main' => 'right', 'sidebar_top' => 'Y', 'sidebar_bottom' => 'Y', 'panel_widget' => 'N', 'panel_post' => 'N', 'carousel' => 'demo', 'disable_slide_the_content' => 'N', 'image_rounded' => 'N', 'prev_next_link' => 'titles', 'paginate_links' => 'next', 'credits' => 'Y', 'post_thumbnail' => 'Y', 'post_date' => 'Y', 'post_author' => 'Y', 'excerpt' => 'N', 'text_color' => '#333333', 'headers_color' => '', 'link_color' => '', 'link_hover_color' => '', 'navbar_color' => '', 'navbar_color2' => '', 'navbar_border' => '', 'navbar_link_color' => '', 'navbar_link_color2' => '', 'page_bgcolor' => '', 'slides' => array(), ); $out = array(); foreach ($defaults as $key => $value) { $out[$key] = isset($arr[$key]) ? $arr[$key] : $value; if (strpos($key, 'color') && !preg_match('/^#[0-9a-f]{6,6}$/i', $out[$key])) { $out[$key] = ''; } if ( 'slides' == $key ) { $slides = array(0); foreach($out[$key] as $slide_raw) { if (is_array($slide_raw)) { $slide['title'] = sanitize_text_field($slide_raw['title']); $slide['src'] = sanitize_text_field($slide_raw['src']); $slide['alt'] = sanitize_text_field($slide_raw['alt']); $slide['link'] = sanitize_text_field($slide_raw['link']); $slide['content'] = trim($slide_raw['content']); if ($slide['src']) { $slides[] = $slide; } } } unset($slides[0]); $out[$key] = $slides; } } $out = stripslashes_deep($out); if ($out['text_color']) { $out['text_color2'] = b3theme_smudge_color($out['text_color'], 40); } else { $out['text_color'] = $out['text_color2'] = ''; } if ($out['link_color']) { $out['link_hover_color'] = b3theme_darken($out['link_color'], 15); } else { $out['link_color'] = $out['link_hover_color'] = ''; } if ($out['navbar_color']) { $out['navbar_color2'] = b3theme_lighten($out['navbar_color'], 75); $out['navbar_border'] = b3theme_lighten($out['navbar_color'], 25); } else { $out['navbar_color'] = $out['navbar_color2'] = $out['navbar_border'] = ''; } if ($out['navbar_link_color']) { $out['navbar_link_color2'] = b3theme_darken($out['navbar_link_color'], 40); } else { $out['navbar_link_color'] = $out['navbar_link_color2'] = ''; } $out['copyright'] = htmlspecialchars($out['copyright']); $out['navbar_brand'] = htmlspecialchars($out['navbar_brand']); return $out; } function b3theme_darken($color, $percent) { $p = min(abs($percent), 100); $ratio = 1 - $p*0.01; $dec = hexdec(substr($color, 1)); $b = dechex(floor((0xFF & $dec) * $ratio)); if (strlen($b) == 1) $b = '0'.$b; $g = dechex(floor(((0xFF00 & $dec) >> 8) * $ratio)); if (strlen($g) == 1) $g = '0'.$g; $r = dechex(floor(((0xFF0000 & $dec) >> 16) * $ratio)); if (strlen($r) == 1) $r = '0'.$r; return "#$r$g$b"; } function b3theme_lighten($color, $percent) { $p = min(abs($percent), 100); $ratio = 1 + $p*0.01; $dec = hexdec(substr($color, 1)); $b = dechex(min( floor((0xFF & $dec) * $ratio), 255 )); if (strlen($b) == 1) $b = '0'.$b; $g = dechex(min( floor(((0xFF00 & $dec) >> 8) * $ratio), 255 )); if (strlen($g) == 1) $g = '0'.$g; $r = dechex(min( floor(((0xFF0000 & $dec) >> 16) * $ratio), 255 )); if (strlen($r) == 1) $r = '0'.$r; return "#$r$g$b"; } function b3theme_smudge($c, $r) { $x = dechex(floor($c*(1-$r) + (255-$c)*$r)); if (strlen($x) == 1) $b = '0'.$x; return $x; } function b3theme_smudge_color($color, $percent) { $p = min(abs($percent), 100); $ratio = $p*0.01; $dec = hexdec(substr($color, 1)); $b = b3theme_smudge(0xFF & $dec, $ratio); $g = b3theme_smudge((0xFF00 & $dec) >> 8, $ratio); $r = b3theme_smudge((0xFF0000 & $dec) >> 16, $ratio); return "#$r$g$b"; } function b3theme_admin_init() { global $b3theme_options; register_setting('b3theme-settings-group', 'b3theme_options'); if ( !empty($_GET['noheader']) && 'b3theme_save_file' == $_GET['action']) { $str = serialize($b3theme_options); if ( empty($str) ) die; header("Content-Type: application/octet-stream;"); header('Content-Disposition: attachment; filename='. 'b3theme-settings-'. date('YmdHis') .'.txt'); header('Accept-Ranges: bytes'); header('Content-Length: '.strlen($str)); die($str); } add_action('admin_notices', 'b3theme_update_options_notice'); if ( !empty($_POST['b3theme_action']) ) { $b3theme_action = preg_replace('/[^a-z0-9_]/', '', $_POST['b3theme_action']); if ( !wp_verify_nonce( $_POST['_wpnonce'], 'b3theme-settings-group-options' ) ) { wp_die( 'Invalid or expired nonce marker.' ); } switch ($b3theme_action) { case 'upload': if ( ($file = $_FILES['b3theme_upload_settings']) && !$file['error'] && $file['size']) { require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'; require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php'; $f = new WP_Filesystem_Direct(''); $content = $f->get_contents($file['tmp_name']); // I can obtain it by one call file get contents but Theme-Check grumbles $import = maybe_unserialize($content); $f->delete($file['tmp_name']); if (is_array($import)) { update_option('b3theme_options', $import); } else { $b3theme_action = 'import_failed'; } } else { $b3theme_action = 'import_failed'; } break; case 'reset': update_option('b3theme_options', array()); break; case 'update': $b3theme_new_options = array_merge($b3theme_options, $_POST['b3theme_options']); update_option('b3theme_options', $b3theme_new_options); break; } wp_redirect( admin_url('themes.php?page=b3theme_settings¬ice=' . $b3theme_action) ); die; } } function b3theme_option_input($option_key, $name = '', $type = 'text', $default = '', $options = array()) { switch ($type) { case 'radio': echo ''; $arr = $options ? $options : array('Y' => __('Yes', 'b3theme'), 'N' => __('No', 'b3theme')); foreach ($arr as $key => $value ) { echo ' '. $value . ' '; } break; case 'checkbox': echo ''; echo ''; echo ' '; break; case 'color': echo ''; echo ''; break; case 'text': echo ''; echo ''; break; case 'hidden': echo ''; break; default: echo ''; echo ''; } } function b3theme_update_options_notice() { if ( empty($_GET['notice']) ) return; $type = 'updated'; switch($_GET['notice']) { case 'update': $message = __('Theme settings have been updated.', 'b3theme'); break; case 'reset': $message = __('Theme settings have been reset.', 'b3theme'); break; case 'upload': $message = __('Theme settings have been imported from the uploded file.', 'b3theme'); break; case 'import_failed': $type = 'error'; $message = __('Error: theme settings import failed.', 'b3theme'); break; } if ( !empty($message) ) { echo '
' . $message . '
readme.txt'; printf( __('Any questions? Look %1$s.', 'b3theme'), $readme); ?>