- Add some metas to - 404 page setup - Enable theme support for featured images - Apply editor styles for control panel editor - Prepare image sizes - Optimize html - Prepare scss variables from options - Optimize css-files (only the ones with changes) - Make all header scripts load in the footer instead - Simplify menu item classes (so many classes -gasp-) - Wordpress figures in the editor - Frontend figures without style="width - Frontend images with captions - Tweak some much used plugin styles - Make sure galleries include our columns class so we don't have to do columnizations twice! - Tell Admin about missing favikon - Excerpt as tinymce - Add bodyclass has-post-thumbnail on pages/singles - Enable fantastic background - ARIA STATUSs - Post ingresses - SETUP ON THEME ACTIVATION! - User manual - Disable dashboard widgets **/ /* Content width */ if ( ! isset( $content_width ) ) $content_width = 900; /*##### ##### Load language files */ add_action('after_setup_theme', function(){ load_theme_textdomain('sircon_evo', get_template_directory() . '/languages'); }); /*##### ##### Theme settings - Then things the user can tweak */ add_action('init', function(){ add_sircontheme_option_type('select', array( 'name' => 'frontpage-output', 'label' => __('Display on frontpage', 'sircon_evo'), 'default' => 'posts', 'options' => apply_filters('sircontheme_setting_frontpage-output', array( __('New blog posts', 'sircon_evo') => 'posts', __('A static page', 'sircon_evo') => 'page-content', )), 'tooltip' => __('Showing new blog posts are usually the preferred choice of bloggers.', 'sircon_evo'), )); add_sircontheme_option_type('select', array( 'name' => 'showposts', 'label' => __('How do blogposts appear on frontpage and archive pages?', 'sircon-evo'), 'default' => 'fullposts', 'options' => array( __('Boxed posts', 'sircon_evo') => 'boxposts', __('Full posts', 'sircon_evo') => 'fullposts' ), 'tooltip' => __('Boxed posts show only title, featured image, ingress/excerpt and a "Read more"-button. Full posts show the entire content', 'sircon_evo'), )); add_sircontheme_scss_variable('text', array( 'name' => 'max', 'label' => __('Max width of the entire layout', 'sircon_evo'), 'default' => '1200px', 'tooltip' => __('Use pixel widths, 1200px for example', 'sircon_evo'), )); add_sircontheme_scss_variable('text', array( 'name' => 'content-width', 'label' => __('Set width of the main content (sidebars adjust automatic)', 'sircon_evo'), 'default' => '900px', 'tooltip' => __('Use pixel widths, 900px for example', 'sircon_evo') )); add_sircontheme_scss_variable('text', array( 'name' => 'air', 'label' => __('How much air between sidebar(s), header and main content?', 'sircon_evo'), 'default' => '30px', 'tooltip' => __('Use pixel widths, 30px for example', 'sircon_evo') )); add_sircontheme_option_type('select', array( 'name' => 'social-sharing', 'label' => __('Show social sharing buttons in posts', 'sircon_evo'), 'default' => false, 'options' => array(__('Yes', 'sircon_evo') => true, __('No', 'sircon_evo') => false), 'tooltip' => __('Social sharing buttons for Facebook and Twitter in bottom of each post', 'sircon_evo') )); add_sircontheme_option_type('select', array( 'name' => 'show-meta', 'label' => __('Show post date and other relevant post info', 'sircon_evo'), 'default' => 'byline', 'options' => array( __('Above post content', 'sircon_evo') => 'byline', __('Below post content', 'sircon_evo') => 'meta', __('Show both', 'sircon_evo') => 'both' ), 'tooltip' => __('Above content shows date, author and comments. Below content shows categories and tags as well.', 'sircon_evo') )); add_sircontheme_option_type('select', array( 'name' => 'show-author', 'label' => __('Show post author in posts', 'sircon_evo'), 'default' => false, 'options' => array(__('Yes', 'sircon_evo')=> true, __('No', 'sircon_evo') => false), 'tooltip' => __('Choose yes if the blog is written by more than one author', 'sircon_evo'), )); add_sircontheme_option_type('select', array( 'name' => 'top-search', 'label' => __('Show search form in top of layout', 'sircon_evo'), 'default' => false, 'options' => array(__('Yes', 'sircon_evo') => true, __('No', 'sircon_evo') => false), )); /*The user can force logged in only add_sircontheme_option_type('select', array( 'name' => 'maintenance_mode', 'label' => __('Demand login to view the website', 'sircon_evo'), 'default' => 0, 'options' => array('Yes' => 1, 'No' => 0), 'tooltip' => 'When set to YES, all your visitors will be redirected to /wp-admin. (.. Unless they are already logged in of course!)' )); */ /* Because people have asked for it! add_sircontheme_option_type('select', array( 'name' => 'excerpt_as_tinymce', 'label' => __('TinyMCE editor for excerpt', 'sircon_evo'), 'default' => 1, 'options' => array('Yes' => 1, 'No' => 0), 'tooltip' => 'When set to YES, you will edit excerpt in a simplified tinymce editor.' )); */ /* Maintenance mode, allow only loggedins if(get_sircontheme_option('maintenance_mode') == 1 && $_SERVER['REMOTE_ADDR'] != '84.16.215.166'){ add_action('get_header', function(){ if(!is_user_logged_in()){ header('location:/wp-admin'); die(); } }); add_filter('login_message', function($message = ''){ $message .= '
'.__('Maintenance mode is in effect, please log in to view the website!', 'sircon_evo').' '.$_SERVER['REMOTE_ADDR'].'
'; return $message; }); //Notify in admin about this add_action('admin_notices', function() use($default_favicon_fullpath){ echo '

THEME Maintenance mode Active!
to disable, check the theme settings

'; }); } */ }); /*##### ##### Add some default post settings $box_id = 'extra-tweaks'; add_sircontheme_postbox($box_id, 'Extra tweaks'); add_sircontheme_postdata($box_id, array( 'label' => __('Show WP-maintitle?', 'sircon_evo'), 'type' => 'select', 'name' => 'show_title', 'default' => 1, 'options' => array( __('Yes') => 1, __('No').' ('.__('Hide the title').')' => 0 ), )); /*##### ##### Embeds with layout control. This allows us to use the "height:0;padding-bottom:%" trick. */ add_filter('embed_oembed_html', function($embed){ //Remove related videos from youtube vids. (nearly all feedback about this has been about removing it) if(strpos($embed,'youtu') !== false && strpos($embed,'rel=0') === false){ $embed = str_replace('=oembed', '=oembed&rel=0', $embed); } //Wrap in an outer div. Allows us to do some neat stuff. $embed = '
'.$embed.'
'; //done return $embed; }); /* //global setting for Media/Embeds add_sircontheme_option_type('pagebreak', array( 'label' => __('Embeds', 'sircon_evo'), 'name' => 'embeds-settings' )); add_sircontheme_option_type('select', array( 'label' => __('Embeds', 'sircon_evo'), 'name' => 'embeds-settings' ));/**/ /*##### ##### Disable controlpanel editor abilities */ $current_user = wp_get_current_user(); if($current_user->user_email !== 'support@sircon.no'){ //Not sircon? No editing then! define( 'DISALLOW_FILE_EDIT', true ); } /*##### ##### Comments script */ add_action('get_header', function(){ //At least this is enabled on default posts if(is_single()){ wp_enqueue_script( 'comment-reply' ); } }); /*##### ##### Make sure post edit category list keeps it's order */ add_filter('wp_terms_checklist_args', function($args){ $args['checked_ontop'] = false; return $args; }); /*##### ##### Remove some superfluous metas from */ add_action('after_setup_theme', function(){ remove_action('wp_head', 'feed_links_extra', 3); remove_action('wp_head', 'feed_links', 2); remove_action('wp_head', 'rsd_link'); remove_action('wp_head', 'wlwmanifest_link'); remove_action('wp_head', 'index_rel_link'); remove_action('wp_head', 'parent_post_rel_link', 10, 0 ); remove_action('wp_head', 'start_post_rel_link', 10, 0 ); remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0 ); remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0 ); remove_action('wp_head', 'wp_generator'); add_filter( 'previous_post_rel_link', 'sircontheme_return_false'); add_filter( 'next_post_rel_link', 'sircontheme_return_false' ); }); /*##### ##### Add some metas to */ add_action('wp_head', function(){ echo ' '; }); /*##### ##### 404 page setup */ //404 Page content - is theme option add_action('init', function(){ //Default 404 text based on locale. if(!function_exists('get_locale')){$locale = WPLANG; }else{$locale = get_locale();} //Check if norwegian if($locale === 'nb_NO'){ $default_404txt = '

404 - Ikke funnet

Beklager, dette innholdet finnes ikke!
Du kan forsøke å finne det du leter etter ved å besøke forsiden

Du kan også forsøke å søke.

'; }else{ //Nope, is english! $default_404txt = '

404 - Not found

Sorry, this content seems to not exist!
You may try finding what you are looking for by visiting the frontpage

You may also try searching for your content.

'; } //Get all pages! $wp_pageids = get_all_page_ids(); global $wpdb; $sql = 'SELECT ID, post_title FROM '.$wpdb->posts.' WHERE ID IN ('.implode(', ', $wp_pageids).')'; $pages = $wpdb->get_results($sql); $pages_options = array(__('None', 'sircon_evo') => 0); foreach($pages as $page){ $pages_options[$page->post_title] = $page->ID; } add_sircontheme_option_type('pagebreak', array( 'label' => __('404', 'sircon_evo'), 'name' => '404-options' )); add_sircontheme_option_type('chosen', array( 'name' => '404-page-id', 'label' => __('Choose a Wordpress Page to be displayed on 404. (If chosen, will redirect here.)', 'sircon_evo'), 'options' => $pages_options )); //Now add this custom field add_sircontheme_option_type('editor', array( 'name' => '404-content', 'label' => __('This is displayed on your 404-page. There should even be a widget position for that', 'sircon_evo'), 'default' => sprintf($default_404txt, home_url()), 'options' => array('Yes' => 1, 'No' => 0) )); }, 100); /* 404 WIDGET */ register_sircontheme_sidebar(array( 'id' => '404', 'name' => '404', 'description' => 'Widgets here are displayed only on 404-pages.' ));/**/ /*##### ##### 404 Handling - Check if we should redirect */ add_action('sircontheme_before_404', function(){ $_404_pageid = get_sircontheme_404_pageid(); if(!$_404_pageid){return;} //Attempt to override the $wp_query var with the user selected wordpress page content for 404 global $wp_query; $wp_query = new WP_Query(array( 'post_type' => 'page', 'post__in' => array($_404_pageid) )); $wp_query->set_404(); the_post(); //all set? }); add_action('wp_footer', function(){ if(is_404()){$_script404var = 'true'; }else{$_script404var = 'false';} echo ''; }); /*##### ##### Enable theme support for featured images */ add_theme_support( 'post-thumbnails' ); add_theme_support( 'html5', array('comment-list', 'comment-form', 'search-form', 'gallery', 'caption')); /*##### ##### Apply editor styles for control panel editor */ add_action( 'after_setup_theme', function(){ $filename = 'editor-styles.css'; $editor_style_fyle = get_stylesheet_directory().'/style/'.$filename; if(!file_exists($editor_style_fyle)){return;} //Do not override editor styles with a file that does not exist $editor_style_fyle = get_stylesheet_directory_uri().'/style/'.$filename; add_editor_style($editor_style_fyle); }); /*##### ##### Prepare image sizes */ //Even photoshop with it's amazing compression abilities cannot do a webfriendly compression with 90% jpg quality..! add_filter('jpeg_quality', function($quality){ return 72; //72% should be quite close to a good quality (as far as jpg goes) while keeping filesize down }); //Modern times call for larger than wordpress "large" images. Good for featured images add_image_size('hd-ready', 1280, 0); add_image_size('hd', 1920, 0); //In post content, maybe at least the hd-ready can be available. HD is overkill add_filter('image_size_names_choose', function($sizes){ $full_key = array_search('full', array_keys($sizes)); if($full_key !== false){ $sizes = array_insert($sizes, array('hd' => 'HD'), ($full_key)); $sizes = array_insert($sizes, array('hd-ready' => 'HD-ready'), ($full_key)); $sizes['full'] = 'Ukomprimert'; }else{ //No full size? attempt to add this size to the end then, instead of before full $sizes['hd-ready'] = 'HD-ready'; } // $sizes['hd'] = 'HD'; //Is overkill. Use after own assessment of overkillness return $sizes; }); /*##### ##### Optimize html - It's weird that this works.. */ /* HTML OPTIMIZATIONS DISABLED --- */ /* FAR too experimental to make default. The below code seems to work, but google claims there is a lot more that can be done! TODO : Proper html optimizations //START CAPTURING OUTPUT add_action('get_header', function(){ //dbg('starting html optimize ob'); ob_start(); }, -10); //OPTIMIZE AND OUTPUT OUTPUT add_action('shutdown', function(){ $everything_ever = ob_get_clean(); //Output GET $clear_whitespace = array( '/[>](\s{2,})/', //Catch whitespace after tag end '/(\s{2,})[<]/', //Catch whitespace before tag start, '/[;](\s{2,})/', //Catch whitespace after semicolon (code end!) ); $replace_whitespace = array( '>', //Replace whitespace after tag end '<', //Replace whitespace before tag start ';', //Replace whitespace after semicolon (code end!) ); //Do the replacements! $everything_ever = preg_replace($clear_whitespace, $replace_whitespace, $everything_ever); //Now output the optimized html! echo $everything_ever; //dbg('Shutdown complete'); }, -10); /* HTML OPTIMIZATIONS DISABLED --- */ /*##### ##### Prepare scss variables from options */ global $sircontheme_wpfile_creds; add_action('admin_init', function(){ //This means that you must refresh the admin control panel to create new css from our scss if(!is_admin()){return;} //Must be actual administrator - Security edition starts here! if(!current_user_can('manage_options')){return;} $last_time_options_saved = get_option('sircontheme_last-time-options-saved'); $last_time_scss_updated = get_option('sircontheme_last_time_scss_updated'); $file_exists = file_exists(SIRCONTHEME_SCSS_DYNAMIC_VARIABLES_FILE_PATH); $changed = ($last_time_scss_updated != $last_time_options_saved); if(!$changed && $file_exists){ return; //Already done, do nothing } /*---------------- the documentation for the wp file system was quite confusing and is talking about some kind of user form somewhere that is not really ... logical.. */ global $sircontheme_wpfile_creds; if(!WP_Filesystem($sircontheme_wpfile_creds)){ $sircontheme_wpfile_creds = request_filesystem_credentials('', '', false, false, null); } global $wp_filesystem; /* -- WP FILE system should be ready now */ /* The dynamic variables scss file is defined as SIRCONTHEME_SCSS_DYNAMIC_VARIABLES_FILE_PATH */ //Get SCSS values $sircontheme_scss_options = get_sircontheme_scss_options(); if(!$sircontheme_scss_options){return;} //Get file contents if($file_exists){ $scss_content = $wp_filesystem->get_contents(SIRCONTHEME_SCSS_DYNAMIC_VARIABLES_FILE_PATH); }else{$scss_content = '';} //Recreate the scss file $scss_content = get_sircontheme_values_as_scss($sircontheme_scss_options, $scss_content); $wp_filesystem->put_contents( SIRCONTHEME_SCSS_DYNAMIC_VARIABLES_FILE_PATH, $scss_content, FS_CHMOD_FILE // predefined mode settings for WP files ); //avoid doing this every single time... update_option('sircontheme_last_time_scss_updated', $last_time_options_saved); //Allow recrunching of other css files global $sircontheme_recrunch_css_because_dynamic_scss_file; $sircontheme_recrunch_css_because_dynamic_scss_file = true; }, 100); /*##### ##### optimize CSS files (only if changed or updated) */ add_action('admin_init', function(){ //This means that you must refresh the admin control panel to create new css from our scss if(!is_admin()){return;} //This means that the previous filter for scss might have gotten some new values to recrunch global $sircontheme_recrunch_css_because_dynamic_scss_file; global $sircontheme_wpfile_creds; $wp_filesystem_prepared = false; $css_files = get_sircontheme_setting('css_files'); $style_directory = dirname(dirname(__FILE__)).'/style/'; $css_style_directory = get_template_directory_uri().'/style/'; $cache_folder = $style_directory.'optimized-cache/'; $files_preoptimized = 0; //Re-optimize each file, if it has changed, or if the target preoptimized is missing foreach($css_files as $css_filename){ $file = $style_directory.$css_filename; $cache_file = $cache_folder.$css_filename; //Check if changed $option_name = 'css-modified-'.$css_filename; $last_saved = get_option($option_name); $last_modded = filemtime($file); $changed = ($last_saved != $last_modded); $recrunch_anyways = (isset($sircontheme_recrunch_css_because_dynamic_scss_file) && $sircontheme_recrunch_css_because_dynamic_scss_file); if(!$recrunch_anyways && !$changed && file_exists($cache_file)){ //dbg('CSS optimizations CHANGE CHECK disabled'); continue; //Do nothing! nothing changed } //File has changed, or preoptimized file is missing, save new content! if(!$wp_filesystem_prepared){ /*---------------- WP file system preparation */ if(!WP_Filesystem($sircontheme_wpfile_creds)){ $sircontheme_wpfile_creds = request_filesystem_credentials('', '', false, false, null); } global $wp_filesystem; $wp_filesystem_prepared = true; //Do not prepare more than once /* -- WP FILE system should be ready now */ } $files_preoptimized++; $most_current_css = $wp_filesystem->get_contents($file); //Check if this is actually a scss-file. Other optimizations are needed then! $extension = pathinfo($file, PATHINFO_EXTENSION); if($extension == 'scss'){ $scss = new scssc(); $scss->setImportPaths(SIRCONTHEME_SCSS_IMPORT_PATH); $most_current_css = $scss->compile($most_current_css); //Remake cache filename - scss extension is no longer needed. $css_filename = str_replace('.scss', '.css', $css_filename); $cache_file = $cache_folder.$css_filename; } //#### DO optimizations here //#One-line it! $most_current_css = str_replace( array("\r", "\n", "\t"), '', $most_current_css ); //#Shrink it! $replacements = array( ' ' => ' ', ' ' => ' ', '***' => '**', ' */' => '*/', '/* ' => '/*', ' {' => '{', '{ ' => '{', ';}' => '}', ' }' => '}', ': ' => ':', ', ' => ',', ' > ' => '>', '; ' => ';', ); $most_current_css = str_replace( array_keys($replacements), array_values($replacements), $most_current_css ); //#Shrink it, round 2 $most_current_css = str_replace( array('##', '==', '*//*'), '', $most_current_css ); //Strip comments! $most_current_css = preg_replace('!/\*.*?\*/!s', '', $most_current_css); $most_current_css = preg_replace('/\n\s*\n/', "\n", $most_current_css); //#Make sure url paths keep working in optimized css file(s) $bgmatch = 0; $replacements = array(); $replacements_already_added = array(); while($bgmatch = strpos($most_current_css, 'url(', $bgmatch)){ $bgmatch+=4; //extract image path $end = strpos($most_current_css,')', $bgmatch); $filepath = str_replace(array("'", '"'), '', substr($most_current_css, $bgmatch, ($end - $bgmatch))); //Make sure we know if this is used more than once $image_used_more_than_once = substr_count($most_current_css, $filepath) > 1; //We want to find a css-friendly path when inserting style tag in the document //Current path relative, or absolute? if(substr($filepath, 0, 4) === 'http'){ //Is absolute! Do nothing continue; }else if(substr($filepath, 0, 1) === '/'){ //Is absolute from basepath! We can reach it $filepath_php = $_SERVER['DOCUMENT_ROOT'].$filepath; $css_path = home_url().$filepath; }else if(substr($filepath, 0, 4) === 'data:'){ //Do nothing, already encoded and replaced! continue; }else{ //Is relative to $style_directory ! We can reach it $filepath_php = $style_directory.$filepath; $css_path = $css_style_directory.$filepath; } //This is how we avoid doing duplicate search and replace later if(in_array($css_path, $replacements_already_added)){ continue; //Already ready to process! } //WP does not allow the php function for base64 encoding. Original method was removed $replacements[] = array($filepath, $css_path); //Remember this, so we avoid doing duplicate search and replace later $replacements_already_added[] = $css_path; } //The actual replacements foreach($replacements as $r){ $most_current_css = str_replace($r[0], $r[1], $most_current_css); } //##### Optimizations done //Save to cache file $most_current_css = $wp_filesystem->put_contents($cache_file, $most_current_css, FS_CHMOD_FILE); //Update last saved update_option($option_name, $last_modded); } //Did we change any css files, or is the target css file missing? $optimized_styles_file = $cache_folder.'optimized-styles.css'; if($files_preoptimized > 0 || !file_exists($optimized_styles_file)){ //rename scss to css foreach($css_files as $k=>$v){ $css_files[$k] = str_replace('.scss', '.css', $v); } //Missing the target file, or at least one css file changed! Create a new one-and-only css-file sircontheme_many_files_to_one($cache_folder, $css_files, $optimized_styles_file); } }, 110);//End add action /*##### ##### optimize ALL JS files (only if changed or updated) */ $do_js_optimizations = get_sircontheme_setting('optimize_js'); if($do_js_optimizations){ //EARLY FILES $optimizations_performed = 0; $js_files = get_sircontheme_setting('priority_js_files'); $script_directory = dirname(dirname(__FILE__)).'/scripts/'; $cache_folder = $script_directory.'optimized-early-cache/'; //Re-optimize each file, if it has changed foreach($js_files as $js_filename){ $optimized = sircontheme_optimize_js_file($js_filename, $script_directory, $cache_folder); if($optimized){$optimizations_performed++;} } if($optimizations_performed > 0){ //Something changed, concatenate js files sircontheme_many_files_to_one($cache_folder, $js_files, $cache_folder.'optimized-early-scripts.js'); } //"NORMAL" FILES $optimizations_performed = 0; $js_files = get_sircontheme_setting('js_files'); $script_directory = dirname(dirname(__FILE__)).'/scripts/'; $cache_folder = $script_directory.'optimized-cache/'; //Re-optimize each file, if it has changed foreach($js_files as $js_filename){ $optimized = sircontheme_optimize_js_file($js_filename, $script_directory, $cache_folder); if($optimized){$optimizations_performed++;} } if($optimizations_performed > 0){ //Something changed, concatenate js files sircontheme_many_files_to_one($cache_folder, $js_files, $cache_folder.'optimized-scripts.js'); } } /*##### ##### header scripts load in the footer */ $scripts_only_in_footer = get_sircontheme_setting('scripts_only_in_footer'); if($scripts_only_in_footer){ //First make sure to catch all scripts, start output buffer before header starts outputting add_action('before_wp_head', function(){ ob_start(); }, 9001); //second, catch all the header output, and extract the scripts add_action('after_wp_head', function(){ $wp_head_output = ob_get_clean(); $benchmark_time = false; if($benchmark_time){ $start = microtime(true); } /* Regex justification notice: - regex mainly because this is Wordpress with infinite developers stupid ways to add script tags. - When this breaks, it needs manual fixup despite proper non-regex script-grabbing solution - It's a quick way to make 90% of regular cases work. */ $regex_find_scripts = '#(.*?)#is'; $script_matches = ''; $matches_found = preg_match_all($regex_find_scripts, $wp_head_output, $script_matches); if($matches_found > 0){ //We extracted some script tags! Remove them from header output $wp_head_output = preg_replace($regex_find_scripts, ''."\n\t", $wp_head_output); //These are the script tags we found $scripts = array_shift($script_matches); //We force jquery to load manually first, so remove it from this array $remove_scripts_containing = array('jquery.js', 'jquery-migrate.'); foreach($scripts as $k => $script_src){ foreach($remove_scripts_containing as $term){ if(stripos($script_src, $term) !== false){ unset($scripts[$k]); break; } } } //Put them in the footer now! global $sircontheme_header_scripts_extracted; $sircontheme_header_scripts_extracted = implode("\n", $scripts)."\n"; add_action('wp_footer', function(){ global $sircontheme_header_scripts_extracted; echo $sircontheme_header_scripts_extracted; }, 9001); //Late priority } if($benchmark_time){ $end = microtime(true); $timespent = $end - $start; $timespent_readable = number_format($timespent, 6).' microseconds'; $wp_head_output .= ''; } echo $wp_head_output; //We still need to output the thing }, 1); } /*##### ##### Simplify menu item classes */ //filter menu classes add_filter('nav_menu_css_class', function ($classes, $item) { if(!$classes){return $classes;} $keep = array( 'current-menu-item', 'current-menu-ancestor', 'menu-item-has-children' ); foreach($classes as $key => $class) { $keep_this = false; if(in_array($class, $keep) !== true){ unset($classes[$key]); } } //Add a simpler css-class $classes[] = 'menu-item'; return $classes; }, 10, 2); /*##### ##### Wordpress figures in the editor Note: This was never really successful, but we still get some editor control through this class //Creating the class is enough to get things going on their own */ global $Sircontheme_Editor_Imagefix; $Sircontheme_Editor_Imagefix = new Sircontheme_Editor_Imagefix(); /*##### ##### Frontend stuff without type, media width and height attributes */ function remove_superfluous_attributes($html) { $html = preg_replace('/(width|height|type|media)=["\']\d*["\']\s?/', "", $html); return $html; } add_filter('the_content', 'remove_superfluous_attributes', 10); /*##### ##### Frontend images with captions */ add_filter('img_caption_shortcode', function($empty_string = '', $attr = array(), $content = ''){ $the_caption = isset($attr['caption']) ? $attr['caption'] : false; //Theme specific fallback $is_sircontheme_caption = (stripos($the_caption, 'no image caption') !== false); if(!$is_sircontheme_caption && $the_caption){ $figcaption = '
'.$attr['caption'].'
'; }else{ $figcaption = ''; } $output = '
'. $content. $figcaption. '
'; return $output; }, 10, 3); /*##### ##### Disable some much used plugin styles */ //Remove wpml css define('ICL_DONT_LOAD_NAVIGATION_CSS', true); define('ICL_DONT_LOAD_LANGUAGE_SELECTOR_CSS', true); //Some are removed within actions add_action( 'init', function(){ //Contact Form 7 styles, theme resets-and-presets provides some basics for this add_action('wpcf7_enqueue_styles', function(){wp_dequeue_style('contact-form-7');}); }); /*##### ##### Make sure galleries include our columns class so we don't have to do columnizations twice! */ add_filter( 'gallery_style', function($gallery_div){ $columns_pos = strpos($gallery_div, 'gallery-columns-') + 16; $columns = substr($gallery_div, $columns_pos, 1); $gallery_div_with_columns = str_replace('gallery-columns-', 'columns columns-'.$columns.' gallery-columns-', $gallery_div); return $gallery_div_with_columns; }); /*##### ##### Excerpt as tinymce. Replaces ACTUAL excerpt, does not create a fake one. - original code get from http://marcgratch.com/add-tinymce-to-excerpt/ - Code below is slightly modified. ALERT: This might be version sensitive! New ways to handle excerpt might make this a game-breaker! */ function sircontheme_excerpt_as_tinymce($post) { echo '

'.__('Excerpts are optional, hand-crafted, summaries of your content.', 'sircon_evo').'

'; $settings = array( 'textarea_rows' => '12', 'quicktags' => false, 'tinymce' => true, 'teeny' => true, 'editor_height' => 120 ); wp_editor(html_entity_decode(stripcslashes($post->post_excerpt)), 'excerpt', $settings); } add_action('init', function(){ if(get_sircontheme_option('excerpt_as_tinymce')){ /* this might be version specific */ add_action('admin_menu', function() { global $post_type; if (!isset($post_type) || post_type_supports($post_type, 'excerpt')){return;} remove_meta_box('postexcerpt', $post_type, 'normal'); }); add_action( 'add_meta_boxes', function() { global $post_type; if (!isset($post_type) || !post_type_supports($post_type, 'excerpt')){return;} add_meta_box('postexcerpt', __('Excerpt', 'sircon_evo'), 'sircontheme_excerpt_as_tinymce', $post_type, 'normal', 'high'); }); } }); /*##### ##### Add bodyclass has-post-thumbnail on pages/singles */ add_action('get_header', function(){ if(!is_single() && !is_page()){return;} the_post(); if(has_post_thumbnail()){ add_sircontheme_body_class('has-post-thumbnail'); } rewind_posts(); }); /*##### ##### Enable fantastic background */ $fantastic_background_enabled = get_sircontheme_setting('enable_fantastic_background'); if($fantastic_background_enabled){ add_sircontheme_postbox('fullbg', array( 'title' => 'Fullsize background', 'context' => 'side', )); add_sircontheme_postdata('fullbg', array( 'name' => 'fullsizebg-id', 'type' => 'image', 'label' => __('Select an image for displaying as a fullsize background image (covering the entire screen)', 'sircon_evo') )); }else{ //Not active? Just perma-disable it sircontheme_disable_background(); } /*##### ##### ARIA STATUS */ add_action('body_started', function(){?>
'Frontpage', 'post_title' => 'Forsiden', 'post_status' => 'publish', 'post_type' => 'page' )); update_option('page_on_front', $frontpage_id); } /* --------------------- Activate our menu */ //Check if our menu exists already $our_menu = get_term_by('slug', 'sircon-blogger', 'nav_menu', ARRAY_A); if(!$our_menu){ //No blogger menu! create one. $inserted_ids = wp_insert_term('Sircon Blogger', 'nav_menu', array( 'description' => 'A simple and automatically added menu, for your convenience', 'slug' => 'sircon-blogger', )); $our_menu = get_term($inserted_ids['term_id'], 'nav_menu', ARRAY_A); } $our_menu_id = $our_menu['term_id']; //Set our menu as "auto add pages" update_option('nav_menu_options', array(false, 'auto_add' => array($our_menu_id) )); //Set our menu as "active" set_theme_mod('nav_menu_locations', array( 'phone-menu' => $our_menu['term_id'], 'main-menu' => $our_menu['term_id'] )); /* ------------------------------------------------ Make and set blogpage. Also "About me" */ //check for existing "About me" page $about_me_page = get_page_by_title('Om meg', ARRAY_A, 'page'); if(!$about_me_page){ //Missing page.. Check for alternative english language $about_me_page = get_page_by_title('About me', ARRAY_A, 'page'); } //Still missing..? if($about_me_page){ //Has page! $about_me_page_id = $about_me_page['ID']; }else{ //Probably completely missing this page... Create it! $about_me_page_id = wp_insert_post(array( 'post_content' => 'Trykk rediger og skriv noe om deg selv. Du kan også slette siden om du ikke vil ha den, eller legge til flere undersider om du vil.', 'post_title' => 'Om meg', 'post_status' => 'publish', 'post_type' => 'page' )); } /* Check if has blogpage */ $blogpage_id = get_option('page_for_posts'); if(!$blogpage_id){ //Create a frontpage and set as frontpage $blogpage_id = wp_insert_post(array( 'post_content' => 'Arkiv', 'post_title' => 'Arkiv', 'post_status' => 'publish', 'post_type' => 'page' )); update_option('page_for_posts', $blogpage_id); } //Set default number of posts per page to "5" update_option('posts_per_page', 5); } //End if has_activated_just_now /*##### ##### User manual */ add_action( 'admin_menu', 'register_usermanual_page' ); function register_usermanual_page() { $icon = get_template_directory_uri().'/package/images/usermanual.png'; add_theme_page( 'Bruksanvisning', 'Bruksanvisning', 'manage_options', 'sircon-manual', 'usermanual_page'); } function usermanual_page() { include(SIRCONTHEME_OUTPUTS_PATH.'admin/blogolution-manual.php'); } /*##### ##### Disable dashboard widgets */ add_action( 'admin_init', function(){ remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' ); remove_meta_box( 'dashboard_plugins', 'dashboard', 'normal' ); remove_meta_box( 'dashboard_primary', 'dashboard', 'side' ); remove_meta_box( 'dashboard_secondary', 'dashboard', 'normal' ); remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' ); remove_meta_box( 'dashboard_recent_drafts', 'dashboard', 'side' ); remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' ); remove_meta_box( 'dashboard_right_now', 'dashboard', 'normal' ); remove_meta_box( 'dashboard_activity', 'dashboard', 'normal'); }); /**** CUSTOM SITESPECIFIC CODE ---------------------------------------------------------------------------- */ //Get current pagination page query_var function get_sircontheme_pagination_page_number(){ if(is_sircontheme_frontpage()){$query_page_varname = 'paged'; }else{$query_page_varname = 'page';} return get_query_var($query_page_varname); } // ADDING DASHBOARD WIDGET, TEST function sircon_add_dashboard_widgets() { wp_add_dashboard_widget( 'sircon_dashboard_widget', // Slug __('Welcome to Sircon Blogolution', 'sircon_evo'), // Title 'sircon_dashboard_widget_function' // Function ); } add_action('wp_dashboard_setup', 'sircon_add_dashboard_widgets'); function sircon_dashboard_widget_function() { echo __('This theme is developed to make your life as a blogger or website owner easier. The theme is highly customizable and easy to use. Just follow the shortcuts, or use the menu on the left to start editing posts, making pages or edit the appearance of your website', 'sircon_evo'). '

' .__('(If you are missing plugins or settings from the menu, activate "Advanced dashboard" in ', 'sircon_evo'). ''.__('theme options', 'sircon_evo').'

'; if((get_locale() == 'nb_NO')) { echo 'Les vår bruksanvisning'; } } function shortcuts_add_dashboard_widgets() { wp_add_dashboard_widget( 'shortcuts_dashboard_widget', // Slug __('Get started', 'sircon_evo'), // Title 'shortcuts_dashboard_widget_function' // Function ); } add_action('wp_dashboard_setup', 'shortcuts_add_dashboard_widgets'); function shortcuts_dashboard_widget_function() { echo '
'; $links = array( __('Write a blog post', 'sircon_evo') => 'post-new.php', __('Create a page', 'sircon_evo') => 'post-new.php?post_type=page', __('Upload images', 'sircon_evo') => 'media-new.php', __('Edit menus', 'sircon_evo') => 'nav-menus.php', __('Add sidebars or footer text', 'sircon_evo') => 'widgets.php', __('Customize your blogs design', 'sircon_evo') => '/themes.php?page=sircon-theme-options' ); foreach($links as $title => $link) { echo '
  • '.$title.'
  • '; } echo '
    '; echo ''; } // Removing unwanted menu items (simple dashboard) function sircontheme_remove_adminmenus(){ remove_menu_page( 'plugins.php' ); //Plugins remove_menu_page( 'users.php' ); //Users remove_menu_page( 'tools.php' ); //Tools remove_menu_page( 'options-general.php' ); //Settings } if(get_sircontheme_option('admin-advanced-version') != 1){ add_action( 'admin_menu', 'sircontheme_remove_adminmenus' ); } // The blog header function function sircontheme_blogheader() { $has_header = get_sircontheme_option('header-img-enabled'); $header_id = get_sircontheme_option('header-img'); $frontpage_only = get_sircontheme_option('frontpage-header'); if(is_numeric($header_id) && $has_header){ echo '
    '; } else if($has_header) { echo '
    '; } else { if(is_active_sidebar('showcase')) {} else { echo '
    '; } } } ?>