__( 'Main Menu','alpine' ) ) ); } add_action('after_setup_theme','alpine_setup'); /* Change the style of the "edit_post_link" function */ function modify_edit_post_link($output) { // Get the link uir from the give anchor tag preg_match_all('~href="(.+)"~',$output,$link); $link = $link[1][0]; // Rearrange into somethin a bit better return 'Edit | '; } add_filter('edit_post_link','modify_edit_post_link'); /* Add a class (vertical, horizontal, or square) to the post thumbnail */ function post_thumbnail_filter($html, $post_id, $post_thumbnail_id, $size, $attr){ // get the image size from the $html preg_match_all('~width="([0-9]+)" height="([0-9]+)"~',$html,$sizes); $size = array('w'=>$sizes[1][0],'h'=>$sizes[2][0]); // determine new class to add $class = 'horizontal'; if($size['w']<$size['h']){ $class = 'vertical'; }else if($size['w']==$size['h']){ $class = 'horizontal'; } // you can alter the resulted HTML here $html = str_ireplace('class="','class="'.$class.' ',$html); return $html; } add_filter('post_thumbnail_html','post_thumbnail_filter',99,5); /* Change the (more...) link */ function modify_more_link() { return 'Continue Reading...'; } add_filter('the_content_more_link','modify_more_link' ); /* Make adjustments to the password protected post form */ function custom_password_prompt($content) { // Find / Replace the string with something a tad shorter $before = 'This content is password protected. To view it please enter your password below:'; $after = 'This is a password protected post.'; $content = str_replace($before, $after, $content); return $content; } add_filter('the_password_form','custom_password_prompt'); /* Enable Widget area */ function enable_widgets(){ register_sidebar(array( 'name' => __( 'Footer Widget Area','alpine'), 'id' => 'footer-widget-area', 'before_widget' => '
  • ', 'after_widget' => "
  • ", 'before_title' => '

    ', 'after_title' => '

    ', )); } add_action('widgets_init','enable_widgets'); /* Theme customization */ function customizer_customization($wp_customize){ // Add option to remove the search from the menu into the "Navigation" section. $wp_customize->add_setting('alpine_options[show_search]', array( 'default' => true, 'capability' => 'edit_theme_options', 'type' => 'option', 'sanitize_callback' => 'sanitize_checkbox', )); $wp_customize->add_control('show_search', array( 'settings' => 'alpine_options[show_search]', 'label' => __('Show Search in Menu','alpine'), 'section' => 'nav', 'type' => 'checkbox', )); // Add the "Header" section and the controls for that $wp_customize->add_section('alpine_header',array( 'title' => __( 'Header','alpine' ), 'description' => 'Some older versions of IE do not support the "Cover" and "Contain" sizing options.', 'priority' => 199, ) ); // Header image $wp_customize->add_setting('alpine_options[header_image]', array( 'default' => '', 'capability' => 'edit_theme_options', 'type' => 'option', 'sanitize_callback' => 'sanitize_file', )); $wp_customize->add_control( new WP_Customize_Image_Control($wp_customize, 'header_image', array( 'label' => __('Header Image','alpine'), 'section' => 'alpine_header', 'settings' => 'alpine_options[header_image]', ))); // Header image size $wp_customize->add_setting('alpine_options[header_image_sizing]', array( 'default' => 'width', 'capability' => 'edit_theme_options', 'type' => 'option', 'sanitize_callback' => 'sanitize_fake', )); $wp_customize->add_control('header_image_sizing', array( 'label' => __('Header Image Sizing','alpine'), 'section' => 'alpine_header', 'settings' => 'alpine_options[header_image_sizing]', 'type' => 'select', 'choices' => array( 'width' => 'Fit to Width', 'height' => 'Fit to Height', 'contain' => 'Fit to Contain', 'cover' => 'Fit to Cover', 'none' => 'Do not resize', ), )); // Header image horizontal pos $wp_customize->add_setting('alpine_options[header_image_horizontal_position]', array( 'default' => 'center', 'capability' => 'edit_theme_options', 'type' => 'option', 'sanitize_callback' => 'sanitize_fake', )); $wp_customize->add_control('header_image_horizontal_position', array( 'label' => __('Header Image Horizontal Position','alpine'), 'section' => 'alpine_header', 'settings' => 'alpine_options[header_image_horizontal_position]', 'type' => 'select', 'choices' => array( 'left' => 'Left', 'center' => 'Center', 'right' => 'Right', ), )); // Header image vertical pos $wp_customize->add_setting('alpine_options[header_image_vertical_position]', array( 'default' => 'center', 'capability' => 'edit_theme_options', 'type' => 'option', 'sanitize_callback' => 'sanitize_fake', )); $wp_customize->add_control('header_image_vertical_position', array( 'label' => __('Header Image Vertical Position','alpine'), 'section' => 'alpine_header', 'settings' => 'alpine_options[header_image_vertical_position]', 'type' => 'select', 'choices' => array( 'top' => 'Top', 'center' => 'Middle', 'bottom' => 'Bottom', ), )); // Hide Header Text $wp_customize->add_setting('alpine_options[hide_header_text]', array( 'default' => false, 'capability' => 'edit_theme_options', 'type' => 'checkbox', 'sanitize_callback' => 'sanitize_checkbox', )); $wp_customize->add_control('hide_header_text', array( 'label' => __('Hide Header Text','alpine'), 'section' => 'alpine_header', 'settings' => 'alpine_options[hide_header_text]', 'type' => 'checkbox', )); // Add the "Colors" section $wp_customize->add_section('alpine_colors',array( 'title' => __( 'Colors','alpine' ), 'description' => 'Want more advanced background options? Try the Backdrop plugin.', 'priority' => 200, ) ); // Link Colors $wp_customize->add_setting('alpine_options[link_color]', array( 'default' => '#FF0000', 'sanitize_callback' => 'sanitize_hex_color', 'capability' => 'edit_theme_options', 'type' => 'option', )); $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'link_color', array( 'label' => __('Link Color','alpine'), 'section' => 'alpine_colors', 'settings' => 'alpine_options[link_color]', ))); // Page Background Color $wp_customize->add_setting('alpine_options[page_background_color]', array( 'default' => '#FEFEFE', 'sanitize_callback' => 'sanitize_hex_color', 'capability' => 'edit_theme_options', 'type' => 'option', )); $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'page_background_color', array( 'label' => __('Page Background Color','alpine'), 'section' => 'alpine_colors', 'settings' => 'alpine_options[page_background_color]', ))); // Content Background Color $wp_customize->add_setting('alpine_options[content_background_color]', array( 'default' => '#FEFEFE', 'sanitize_callback' => 'sanitize_hex_color', 'capability' => 'edit_theme_options', 'type' => 'option', )); $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'content_background_color', array( 'label' => __('Content Background Color','alpine'), 'section' => 'alpine_colors', 'settings' => 'alpine_options[content_background_color]', ))); // Content Drop Shadow $wp_customize->add_setting('alpine_options[content_shadow]', array( 'default' => false, 'capability' => 'edit_theme_options', 'type' => 'checkbox', 'sanitize_callback' => 'sanitize_checkbox', )); $wp_customize->add_control('content_shadow', array( 'settings' => 'alpine_options[content_shadow]', 'label' => __('Add Drop Shadow to Content','alpine'), 'section' => 'alpine_colors', 'type' => 'checkbox', )); // Add the "Footer" section $wp_customize->add_section('alpine_footer',array( 'title' => __( 'Footer','alpine' ), 'description' => 'Both the above and below text support HTML. Leaving the Copyright Name blank will use the current site name.', 'priority' => 301, ) ); // Above Copyright Text $wp_customize->add_setting('alpine_options[above_copyright_text]', array( 'default' => '', 'capability' => 'edit_theme_options', 'type' => 'option', 'sanitize_callback' => 'sanitize_text', )); $wp_customize->add_control('above_copyright_text', array( 'label' => __('Above Copyright Text','alpine'), 'section' => 'alpine_footer', 'settings' => 'alpine_options[above_copyright_text]', 'type' => 'textarea' )); // Copyright name $wp_customize->add_setting('alpine_options[copyright_name]', array( 'default' => '', 'capability' => 'edit_theme_options', 'type' => 'option', 'sanitize_callback' => 'sanitize_text', )); $wp_customize->add_control('copyright_name', array( 'label' => __('Copyright Name','alpine'), 'section' => 'alpine_footer', 'settings' => 'alpine_options[copyright_name]', 'type' => 'text' )); // Copyright link $wp_customize->add_setting('alpine_options[copyright_link]', array( 'default' => '', 'capability' => 'edit_theme_options', 'type' => 'option', 'sanitize_callback' => 'sanitize_text', )); $wp_customize->add_control('copyright_link', array( 'label' => __('Copyright Link','alpine'), 'section' => 'alpine_footer', 'settings' => 'alpine_options[copyright_link]', 'type' => 'text' )); // Below Copyright Text $wp_customize->add_setting('alpine_options[below_copyright_text]', array( 'default' => 'Alpine Theme by FatFolderDesign', 'capability' => 'edit_theme_options', 'type' => 'option', 'sanitize_callback' => 'sanitize_text', )); $wp_customize->add_control('below_copyright_text', array( 'label' => __('Below Copyright Text','alpine'), 'section' => 'alpine_footer', 'settings' => 'alpine_options[below_copyright_text]', 'type' => 'textarea' )); // Add the "Custom CSS" section $wp_customize->add_section('alpine_custom_css',array( 'title' => __( 'Custom CSS','alpine' ), 'description' => '', 'priority' => 401, ) ); // Above Copyright Text $wp_customize->add_setting('alpine_options[custom_css]', array( 'default' => '', 'capability' => 'edit_theme_options', 'type' => 'option', 'sanitize_callback' => 'sanitize_text', )); $wp_customize->add_control('custom_css', array( 'label' => __('Custom CSS','alpine'), 'section' => 'alpine_custom_css', 'settings' => 'alpine_options[custom_css]', 'type' => 'textarea' )); /* Add textarea to the customizer (why it's no a default IDK) */ class customize_textarea_control extends WP_Customize_Control { public $type = 'textarea'; public function render_content(){ echo ''; } } } add_action('customize_register','customizer_customization'); // The part that generates the customization css function customization_css(){ $options = get_option('alpine_options'); $options = array_merge(array( 'link_color' => '#FF0000', 'page_background_color' => '#FEFEFE', 'content_background_color' => '#FEFEFE', 'show_search' => true, 'header_image' => '', 'header_image_horizontal_position' => 'center', 'header_image_vertical_position' => 'center', 'header_image_sizing' => 'width', 'hide_header_text' => false, 'custom_css' => '', 'content_shadow' => false, ),$options); // The CSS ?> 0){ $indent .= " "; $depth--; } $indent .= ' '; // Only implement a URL if it is not a # $url = $item->url; if($url=='#'){ $url = 'disabled="disabled"'; }else{ $url = 'value="'.$url.'"'; } $output .= ''; } // we no longer need a closing to the item, since we are closing it in start_el function end_el(&$output, $item, $depth=0, $args=array()){ $output .= ''; } } /* Sanitizers (don't get me started...) */ if(!function_exists('sanitize_checkbox')){ function sanitize_checkbox($value){ if($value==1){ return 1; }else{ return 0; } } } if(!function_exists('sanitize_text')){ function sanitize_text($value){ return wp_kses_post(force_balance_tags($value)); } } if(!function_exists('sanitize_fake')){ function sanitize_fake($value){ // Seems sanitize_option new returns a object, which, you know, not expected. This should be fine for dropdowns. return $value; } } if(!function_exists('sanitize_file')){ function sanitize_file($file){ // Repath it so we know where to check $upload_dir = wp_upload_dir(); $check_file = $upload_dir['basedir'].str_ireplace(get_site_url().'/wp-content/uploads','',$file); // Check, return as needed if(is_file($check_file)){ return $file; }else{ return ''; } } }