示例#1
0
 /**
  * Load all JavaScript to header
  *
  * This function is attached to the 'wp_enqueue_scripts' action hook.
  *
  * @uses	is_admin()
  * @uses	is_singular()
  * @uses	get_option()
  * @uses	wp_enqueue_script()
  * @uses	BAVOTASAN_THEME_URL
  *
  * @since 1.0.0
  */
 function bavotasan_add_js()
 {
     $bavotasan_theme_options = bavotasan_theme_options();
     $slider_options = get_option('ward_slider_settings');
     $var = array('carousel' => false, 'tooltip' => false, 'tabs' => false);
     if (is_singular()) {
         if (get_option('thread_comments')) {
             wp_enqueue_script('comment-reply');
         }
         global $post;
         $content = $post->post_content;
         if (false !== strpos($content, '[widetext')) {
             wp_enqueue_script('widetext', BAVOTASAN_THEME_URL . '/library/js/widetext.min.js', array('jquery'), '1.0.1', true);
         }
         if (false !== strpos($content, '[carousel')) {
             $var['carousel'] = true;
         }
         if (false !== strpos($content, '[tooltip')) {
             $var['tooltip'] = true;
         }
         if (false !== strpos($content, '[tabs')) {
             $var['tabs'] = true;
         }
     }
     if (is_front_page() && $slider_options['autoplay']) {
         $var['carousel'] = true;
     }
     wp_enqueue_script('bootstrap', BAVOTASAN_THEME_URL . '/library/js/bootstrap.min.js', array('jquery'), '3.0.0', true);
     wp_enqueue_script('theme_js', BAVOTASAN_THEME_URL . '/library/js/theme.js', array('bootstrap'), '', true);
     wp_localize_script('theme_js', 'theme_js_vars', $var);
     wp_enqueue_style('theme_stylesheet', get_stylesheet_uri());
     // Fonts stuff
     $selected_fonts = array($bavotasan_theme_options['main_text_font'], $bavotasan_theme_options['headers_font'], $bavotasan_theme_options['post_title_font'], $bavotasan_theme_options['post_meta_font'], $bavotasan_theme_options['post_category_font']);
     $selected_fonts = array_unique($selected_fonts);
     $google_fonts = bavotasan_google_fonts();
     $font_string = '';
     foreach ($selected_fonts as $font) {
         $main_font = $font == $bavotasan_theme_options['main_text_font'];
         $font = html_entity_decode($font);
         if (array_key_exists($font, $google_fonts)) {
             $font = explode(',', $font);
             $font = $font[0];
             switch ($font) {
                 case 'Lato':
                     $font = 'Lato:400';
                     break;
                 case 'Lato Bold':
                     $font = 'Lato:900';
                     break;
                 case 'Lato Light':
                     $font = 'Lato:300';
                     break;
                 case 'Raleway':
                     $font = 'Raleway:100';
                     break;
                 case 'Exo':
                     $font = 'Exo:100';
                     break;
                 case 'Arvo Bold':
                     $font = 'Arvo:900';
                     break;
             }
             $font = str_replace(array(' ', '"'), array('+', ''), $font);
             $font = $main_font ? $font . ":400,400italic,700,700italic" : $font;
             $font_string .= $font . '|';
         }
     }
     if ($font_string) {
         wp_enqueue_style('google_fonts', '//fonts.googleapis.com/css?family=' . $font_string, false, null, 'all');
     }
     wp_enqueue_style('font_awesome', BAVOTASAN_THEME_URL . '/library/css/font-awesome.css', false, '4.3.0', 'all');
 }
 /**
  * Adds theme options to the Customizer screen
  *
  * This function is attached to the 'customize_register' action hook.
  *
  * @param	class $wp_customize
  *
  * @since 1.0.0
  */
 public function customize_register($wp_customize)
 {
     $bavotasan_theme_options = bavotasan_theme_options();
     // Layout section panel
     $wp_customize->add_section('bavotasan_layout', array('title' => __('Layout', 'ward'), 'priority' => 35));
     $wp_customize->add_setting('ward_pro_theme_options[boxed]', array('default' => $bavotasan_theme_options['boxed'], 'type' => 'option', 'capability' => 'edit_theme_options'));
     $wp_customize->add_control('bavotasan_boxed', array('label' => __('Boxed', 'ward'), 'section' => 'bavotasan_layout', 'settings' => 'ward_pro_theme_options[boxed]', 'type' => 'checkbox', 'priority' => 5));
     $wp_customize->add_setting('ward_pro_theme_options[width]', array('default' => $bavotasan_theme_options['width'], 'type' => 'option', 'capability' => 'edit_theme_options'));
     $wp_customize->add_control('bavotasan_width', array('label' => __('Site Width', 'ward'), 'section' => 'bavotasan_layout', 'settings' => 'ward_pro_theme_options[width]', 'priority' => 10, 'type' => 'select', 'choices' => array('1200' => __('1200px', 'ward'), '992' => __('992px', 'ward'))));
     $choices = array('col-md-2' => '17%', 'col-md-3' => '25%', 'col-md-4' => '34%', 'col-md-5' => '42%', 'col-md-6' => '50%', 'col-md-7' => '58%', 'col-md-8' => '66%', 'col-md-9' => '75%', 'col-md-10' => '83%');
     $wp_customize->add_setting('ward_pro_theme_options[primary]', array('default' => $bavotasan_theme_options['primary'], 'type' => 'option', 'capability' => 'edit_theme_options'));
     $wp_customize->add_control('bavotasan_primary_column', array('label' => __('Main Content', 'ward'), 'section' => 'bavotasan_layout', 'settings' => 'ward_pro_theme_options[primary]', 'priority' => 15, 'type' => 'select', 'choices' => $choices));
     if (is_active_sidebar('second-sidebar')) {
         $wp_customize->add_setting('ward_pro_theme_options[secondary]', array('default' => $bavotasan_theme_options['secondary'], 'type' => 'option', 'capability' => 'edit_theme_options'));
         $wp_customize->add_control('bavotasan_secondary_column', array('label' => __('First Sidebar', 'ward'), 'section' => 'bavotasan_layout', 'settings' => 'ward_pro_theme_options[secondary]', 'priority' => 20, 'type' => 'select', 'choices' => $choices));
     }
     $wp_customize->add_setting('ward_pro_theme_options[layout]', array('default' => $bavotasan_theme_options['layout'], 'type' => 'option', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'esc_attr'));
     $layout_choices = array('left' => __('Left', 'ward'), 'right' => __('Right', 'ward'));
     if (is_active_sidebar('second-sidebar')) {
         $layout_choices['separate'] = __('Separate', 'ward');
     }
     $wp_customize->add_control(new Bavotasan_Post_Layout_Control($wp_customize, 'layout', array('label' => __('Sidebar Layout', 'ward'), 'section' => 'bavotasan_layout', 'settings' => 'ward_pro_theme_options[layout]', 'size' => false, 'priority' => 25, 'choices' => $layout_choices)));
     $wp_customize->add_setting('ward_pro_theme_options[excerpt_content]', array('default' => $bavotasan_theme_options['excerpt_content'], 'type' => 'option', 'capability' => 'edit_theme_options'));
     $wp_customize->add_control('bavotasan_excerpt_content', array('label' => __('Post Content Display', 'ward'), 'section' => 'bavotasan_layout', 'settings' => 'ward_pro_theme_options[excerpt_content]', 'priority' => 30, 'type' => 'radio', 'choices' => array('excerpt' => __('Teaser Excerpt', 'ward'), 'content' => __('Full Content', 'ward'))));
     $wp_customize->add_setting('ward_pro_theme_options[read_more]', array('default' => $bavotasan_theme_options['read_more'], 'type' => 'option', 'capability' => 'edit_theme_options'));
     $wp_customize->add_control('bavotasan_read_more', array('label' => __('"Read More" Text', 'ward'), 'section' => 'bavotasan_layout', 'settings' => 'ward_pro_theme_options[read_more]', 'priority' => 33, 'type' => 'text'));
     $colors = array('info' => __('Light Blue', 'ward'), 'primary' => __('Blue', 'ward'), 'danger' => __('Red', 'ward'), 'warning' => __('Yellow', 'ward'), 'success' => __('Green', 'ward'));
     $wp_customize->add_setting('ward_pro_theme_options[read_more_color]', array('default' => $bavotasan_theme_options['read_more_color'], 'type' => 'option', 'capability' => 'edit_theme_options'));
     $wp_customize->add_control('bavotasan_read_more_color', array('label' => __('Read More Color', 'ward'), 'section' => 'bavotasan_layout', 'settings' => 'ward_pro_theme_options[read_more_color]', 'priority' => 34, 'type' => 'select', 'choices' => $colors));
     // Jumbo headline section panel
     $wp_customize->add_section('bavotasan_jumbo', array('title' => __('Jumbo Headline', 'ward'), 'priority' => 36));
     $wp_customize->add_setting('ward_pro_theme_options[jumbo_headline_title]', array('default' => $bavotasan_theme_options['jumbo_headline_title'], 'type' => 'option', 'capability' => 'edit_theme_options'));
     $wp_customize->add_control('bavotasan_jumbo_headline_title', array('label' => __('Title', 'ward'), 'section' => 'bavotasan_jumbo', 'settings' => 'ward_pro_theme_options[jumbo_headline_title]', 'priority' => 26, 'type' => 'text'));
     $wp_customize->add_setting('ward_pro_theme_options[jumbo_headline_text]', array('default' => $bavotasan_theme_options['jumbo_headline_text'], 'type' => 'option', 'capability' => 'edit_theme_options'));
     $wp_customize->add_control('bavotasan_jumbo_headline_text', array('label' => __('Text', 'ward'), 'section' => 'bavotasan_jumbo', 'settings' => 'ward_pro_theme_options[jumbo_headline_text]', 'priority' => 27, 'type' => 'text'));
     $wp_customize->add_setting('ward_pro_theme_options[jumbo_headline_button_text]', array('default' => $bavotasan_theme_options['jumbo_headline_button_text'], 'type' => 'option', 'capability' => 'edit_theme_options'));
     $wp_customize->add_control('bavotasan_jumbo_headline_button_text', array('label' => __('Button Text', 'ward'), 'section' => 'bavotasan_jumbo', 'settings' => 'ward_pro_theme_options[jumbo_headline_button_text]', 'priority' => 28, 'type' => 'text'));
     $wp_customize->add_setting('ward_pro_theme_options[jumbo_headline_button_link]', array('default' => $bavotasan_theme_options['jumbo_headline_button_link'], 'type' => 'option', 'capability' => 'edit_theme_options'));
     $wp_customize->add_control('bavotasan_jumbo_headline_button_link', array('label' => __('Button Link', 'ward'), 'section' => 'bavotasan_jumbo', 'settings' => 'ward_pro_theme_options[jumbo_headline_button_link]', 'priority' => 29, 'type' => 'text'));
     $wp_customize->add_setting('ward_pro_theme_options[jumbo_headline_button_color]', array('default' => $bavotasan_theme_options['jumbo_headline_button_color'], 'type' => 'option', 'capability' => 'edit_theme_options'));
     $wp_customize->add_control('bavotasan_jumbo_headline_button_color', array('label' => __('Button Color', 'ward'), 'section' => 'bavotasan_jumbo', 'settings' => 'ward_pro_theme_options[jumbo_headline_button_color]', 'priority' => 30, 'type' => 'select', 'choices' => $colors));
     $wp_customize->add_setting('ward_pro_theme_options[widget_area_icon]', array('default' => $bavotasan_theme_options['widget_area_icon'], 'type' => 'option', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'esc_attr'));
     $wp_customize->add_control(new Bavotasan_Icon_Select_Control($wp_customize, 'widget_area_icon', array('label' => __('Icon', 'ward'), 'section' => 'bavotasan_jumbo', 'settings' => 'ward_pro_theme_options[widget_area_icon]', 'priority' => 35)));
     // Fonts panel
     $mixed_fonts = array_merge(bavotasan_websafe_fonts(), bavotasan_google_fonts());
     asort($mixed_fonts);
     $wp_customize->add_section('bavotasan_fonts', array('title' => __('Fonts', 'ward'), 'priority' => 40));
     $wp_customize->add_setting('ward_pro_theme_options[main_text_font]', array('default' => $bavotasan_theme_options['main_text_font'], 'type' => 'option', 'capability' => 'edit_theme_options'));
     $wp_customize->add_control('bavotasan_main_text_font', array('label' => __('Main Text', 'ward'), 'section' => 'bavotasan_fonts', 'settings' => 'ward_pro_theme_options[main_text_font]', 'priority' => 10, 'type' => 'select', 'choices' => $mixed_fonts));
     $wp_customize->add_setting('ward_pro_theme_options[headers_font]', array('default' => $bavotasan_theme_options['headers_font'], 'type' => 'option', 'capability' => 'edit_theme_options'));
     $wp_customize->add_control('bavotasan_headers_font', array('label' => __('Headers (h1, h2, h3, etc...)', 'ward'), 'section' => 'bavotasan_fonts', 'settings' => 'ward_pro_theme_options[headers_font]', 'priority' => 15, 'type' => 'select', 'choices' => $mixed_fonts));
     $wp_customize->add_setting('ward_pro_theme_options[post_title_font]', array('default' => $bavotasan_theme_options['post_title_font'], 'type' => 'option', 'capability' => 'edit_theme_options'));
     $wp_customize->add_control('bavotasan_post_title_font', array('label' => __('Post Title', 'ward'), 'section' => 'bavotasan_fonts', 'settings' => 'ward_pro_theme_options[post_title_font]', 'priority' => 30, 'type' => 'select', 'choices' => $mixed_fonts));
     $wp_customize->add_setting('ward_pro_theme_options[post_meta_font]', array('default' => $bavotasan_theme_options['post_meta_font'], 'type' => 'option', 'capability' => 'edit_theme_options'));
     $wp_customize->add_control('bavotasan_meta_font', array('label' => __('Post Meta', 'ward'), 'section' => 'bavotasan_fonts', 'settings' => 'ward_pro_theme_options[post_meta_font]', 'priority' => 35, 'type' => 'select', 'choices' => $mixed_fonts));
     $wp_customize->add_setting('ward_pro_theme_options[post_category_font]', array('default' => $bavotasan_theme_options['post_category_font'], 'type' => 'option', 'capability' => 'edit_theme_options'));
     $wp_customize->add_control('bavotasan_post_category_font', array('label' => __('Post Category', 'ward'), 'section' => 'bavotasan_fonts', 'settings' => 'ward_pro_theme_options[post_category_font]', 'priority' => 40, 'type' => 'select', 'choices' => $mixed_fonts));
     // Color panel
     $wp_customize->add_setting('ward_pro_theme_options[headers_color]', array('default' => $bavotasan_theme_options['headers_color'], 'type' => 'option', 'sanitize_callback' => 'sanitize_hex_color', 'capability' => 'edit_theme_options'));
     $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'headers_color', array('label' => __('Headers (h1, h2, h3, etc...)', 'ward'), 'section' => 'colors', 'settings' => 'ward_pro_theme_options[headers_color]', 'priority' => 20)));
     $wp_customize->add_setting('ward_pro_theme_options[main_text_color]', array('default' => $bavotasan_theme_options['main_text_color'], 'type' => 'option', 'sanitize_callback' => 'sanitize_hex_color', 'capability' => 'edit_theme_options'));
     $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'main_text_color', array('label' => __('Main Text Color', 'ward'), 'section' => 'colors', 'settings' => 'ward_pro_theme_options[main_text_color]', 'priority' => 25)));
     $wp_customize->add_setting('ward_pro_theme_options[link_color]', array('default' => $bavotasan_theme_options['link_color'], 'type' => 'option', 'sanitize_callback' => 'sanitize_hex_color', 'capability' => 'edit_theme_options'));
     $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'link_color', array('label' => __('Link Color', 'ward'), 'section' => 'colors', 'settings' => 'ward_pro_theme_options[link_color]', 'priority' => 50)));
     $wp_customize->add_setting('ward_pro_theme_options[link_hover_color]', array('default' => $bavotasan_theme_options['link_hover_color'], 'type' => 'option', 'sanitize_callback' => 'sanitize_hex_color', 'capability' => 'edit_theme_options'));
     $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'link_hover_color', array('label' => __('Link Hover Color', 'ward'), 'section' => 'colors', 'settings' => 'ward_pro_theme_options[link_hover_color]', 'priority' => 55)));
     $wp_customize->add_setting('ward_pro_theme_options[widget_area_color]', array('default' => $bavotasan_theme_options['widget_area_color'], 'type' => 'option', 'sanitize_callback' => 'sanitize_hex_color', 'capability' => 'edit_theme_options'));
     $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'widget_area_color', array('label' => __('Widget Area Background Color', 'ward'), 'section' => 'colors', 'settings' => 'ward_pro_theme_options[widget_area_color]', 'priority' => 56)));
     // Nav panel
     $wp_customize->add_setting('ward_pro_theme_options[nav_palette]', array('default' => $bavotasan_theme_options['nav_palette'], 'type' => 'option', 'capability' => 'edit_theme_options'));
     $wp_customize->add_control('bavotasan_nav_palette', array('label' => __('Nav Color', 'ward'), 'section' => 'nav', 'settings' => 'ward_pro_theme_options[nav_palette]', 'priority' => 40, 'type' => 'select', 'choices' => array('navbar-default' => __('Light', 'ward'), 'navbar-inverse' => __('Dark', 'ward'))));
     // Posts panel
     $wp_customize->add_section('bavotasan_posts', array('title' => __('Posts', 'ward'), 'priority' => 45));
     $wp_customize->add_setting('ward_pro_theme_options[display_categories]', array('default' => $bavotasan_theme_options['display_categories'], 'type' => 'option', 'capability' => 'edit_theme_options'));
     $wp_customize->add_control('bavotasan_display_categories', array('label' => __('Display Categories', 'ward'), 'section' => 'bavotasan_posts', 'settings' => 'ward_pro_theme_options[display_categories]', 'type' => 'checkbox'));
     $wp_customize->add_setting('ward_pro_theme_options[display_author]', array('default' => $bavotasan_theme_options['display_author'], 'type' => 'option', 'capability' => 'edit_theme_options'));
     $wp_customize->add_control('bavotasan_display_author', array('label' => __('Display Author', 'ward'), 'section' => 'bavotasan_posts', 'settings' => 'ward_pro_theme_options[display_author]', 'type' => 'checkbox'));
     $wp_customize->add_setting('ward_pro_theme_options[display_date]', array('default' => $bavotasan_theme_options['display_date'], 'type' => 'option', 'capability' => 'edit_theme_options'));
     $wp_customize->add_control('bavotasan_display_date', array('label' => __('Display Date', 'ward'), 'section' => 'bavotasan_posts', 'settings' => 'ward_pro_theme_options[display_date]', 'type' => 'checkbox'));
     $wp_customize->add_setting('ward_pro_theme_options[display_comment_count]', array('default' => $bavotasan_theme_options['display_comment_count'], 'type' => 'option', 'capability' => 'edit_theme_options'));
     $wp_customize->add_control('bavotasan_display_comment_count', array('label' => __('Display Comment Count', 'ward'), 'section' => 'bavotasan_posts', 'settings' => 'ward_pro_theme_options[display_comment_count]', 'type' => 'checkbox'));
     // Footer panel
     $wp_customize->add_section('bavotasan_footer', array('title' => __('Footer', 'ward'), 'priority' => 50));
     $wp_customize->add_setting('ward_pro_theme_options[extended_footer_columns]', array('default' => $bavotasan_theme_options['extended_footer_columns'], 'type' => 'option', 'capability' => 'edit_theme_options', 'transport' => 'postMessage'));
     $wp_customize->add_control('bavotasan_extended_footer_columns', array('label' => __('Extended Footer Columns', 'ward'), 'section' => 'bavotasan_footer', 'settings' => 'ward_pro_theme_options[extended_footer_columns]', 'priority' => 10, 'type' => 'select', 'choices' => array('col-md-12' => __('1 Column', 'ward'), 'col-md-6' => __('2 Columns', 'ward'), 'col-md-4' => __('3 Columns', 'ward'), 'col-md-3' => __('4 Columns', 'ward'), 'col-md-2' => __('6 Columns', 'ward'))));
     $wp_customize->add_setting('ward_pro_theme_options[copyright]', array('default' => $bavotasan_theme_options['copyright'], 'type' => 'option', 'capability' => 'edit_theme_options'));
     $wp_customize->add_control('bavotasan_copyright', array('label' => __('Copyright Notice', 'ward'), 'section' => 'bavotasan_footer', 'settings' => 'ward_pro_theme_options[copyright]', 'priority' => 20));
 }