'.__('Settings','ajc').''; array_unshift($links, $settings_link); return $links; } $plugin = plugin_basename(__FILE__); add_filter("plugin_action_links_{$plugin}", 'ajc_settings_link' ); add_action('init', 'ajc_init'); // ACTION init function ajc_init(){ $ajc_async_js = get_option('ajc_async_js'); $ajc_async_css = get_option('ajc_async_css'); $ajc_detect_scripts_in_wp_head = get_option('ajc_detect_scripts_in_wp_head'); $ajc_detect_scripts_in_wp_foot = get_option('ajc_detect_scripts_in_wp_foot'); $ajc_css_loading_method = get_option('ajc_css_loading_method'); if ($ajc_async_css){ add_action('wp_print_styles', 'ajc_print_styles', AJC_LAST); add_action('wp_footer', 'ajc_print_delayed_styles', AJC_LAST+1); } if ($ajc_async_js || ($ajc_async_css && $ajc_css_loading_method=='js')){ add_action('wp_head', 'ajc_loader_init', AJC_FIRST-1); add_action('wp_footer', 'ajc_loader_execute', AJC_LAST); } if ($ajc_async_js){ add_action('wp_print_scripts', 'ajc_print_scripts', AJC_LAST); if ($ajc_detect_scripts_in_wp_head){ add_action('wp_head', 'ajc_detect_scripts_in_wp_head_pre', AJC_FIRST); add_action('wp_head', 'ajc_detect_scripts_in_wp_head_post', AJC_LAST); } if ($ajc_detect_scripts_in_wp_foot){ add_action('wp_footer', 'ajc_detect_scripts_in_wp_foot_pre', AJC_FIRST); add_action('wp_footer', 'ajc_detect_scripts_in_wp_foot_post', AJC_LAST-1); } } } // ACTION wp_head function ajc_loader_init(){ $loaded = get_exceptions_script_names(); ?> do_concat = true; } // ACTION wp_print_styles function ajc_print_styles(){ global $ajc_styles_are_async; global $ajc_styles; if ( is_admin() || !empty($ajc_styles_are_async) ) { return; } $ajc_styles_are_async = true; $ajc_styles = get_styles_list(); //~ dump(get_option('ajc_css_loading_method')); if (get_option('ajc_css_loading_method')=='inline_header'){ $not_inlined = array(); $minify = get_option('ajc_css_minify'); //~ $ajc_styles = array_reverse($ajc_styles,true); foreach ($ajc_styles as $style){ echo ""; } if (!empty($not_inlined)){ foreach ($not_inlined as $style){ ?> />"; foreach ($ajc_styles as $style){ echo "@import url(\"{$style['src']}\")".($style['media'] ? " ".$style['media'] : '').";"; } echo ""; break; } case "js": { ?> "; if (!inline_css($style['src'],$minify)){ $not_inlined[] = $style; } echo ""; } if (!empty($not_inlined)){ foreach ($not_inlined as $style){ ?> /> />)([^<]*)(<\/script>)/i','$1 execOnReady(function(){$2}); $3',$content); echo $content; } // ACTION wp_footer function ajc_detect_scripts_in_wp_foot_pre(){ ob_start(); } // ACTION wp_footer function ajc_detect_scripts_in_wp_foot_post(){ global $ajc_scripts; $content = ob_get_contents(); ob_end_clean(); $scripts = array(); preg_match_all('/<\/script>/i',$content,$scripts); $content = preg_replace('/]*?src=[\'|\"](.*)[\'|\"]><\/script>/i','',$content); $content = preg_replace('/(]*?>)([^<]*)(<\/script>)/i','$1 execOnReady(function(){$2}); $3',$content); foreach ($scripts[1] as $key=>$script){ $ajc_scripts[] = array( 'name' => 'footer_script_'.$key, 'src' => $script, 'deps' => array(), 'extra' => '' ); } echo $content; } ?>