-
-
Save mautematico/5d74aa7dfdffe62773c37b199064a2b9 to your computer and use it in GitHub Desktop.
Auto-configure Autoptimize across a WordPress network
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: RT Autoautoptimize | |
* Plugin URI: https://gist.github.com/roytanck/e5e38d2955140b36da7e | |
* Description: Automatically configures default settings for the Autoptimize plugin across a WordPress network | |
* Version: 0.9 | |
* Author: Roy Tanck | |
* Author URI: http://www.this-play.nl | |
* License: GPL2 | |
*/ | |
/** | |
* Auto-configure Autoptimize if not already configured | |
*/ | |
if( !function_exists( 'rt_autoautoptimize' ) ){ | |
function rt_autoautoptimize(){ | |
// do nothing if we're in the admin | |
if( is_admin() ){ | |
return; | |
} | |
// check if the plugin is already configured | |
$installed = get_option( 'autoptimize_configured', 'no' ); | |
if( $installed == 'no' ){ | |
// default Autoptimize settings for plugin version 1.9.4 | |
$defaults = array( | |
'autoptimize_version' => '2.1.0', | |
'autoptimize_html' => 'on', | |
'autoptimize_html_keepcomments' => 'on', | |
'autoptimize_js' => 'on', | |
'autoptimize_js_exclude' => 's_sid,smowtion_size,sc_project,WAU_,wau_add,comment-form-quicktags,edToolbar,ch_client,seal.js', | |
'autoptimize_js_trycatch' => '', | |
'autoptimize_js_justhead' => '', | |
'autoptimize_js_forcehead' => '', | |
'autoptimize_js_include_inline' => '', | |
'autoptimize_css' => 'on', | |
'autoptimize_css_exclude' => 'admin-bar.min.css, dashicons.min.css', | |
'autoptimize_css_justhead' => '', | |
'autoptimize_css_datauris' => '', | |
'autoptimize_css_defer' => '', | |
'autoptimize_css_defer_inline' => '', | |
'autoptimize_css_inline' => '', | |
'autoptimize_cdn_url' => 'https://cdn.creepypastas.com/', | |
'autoptimize_cache_clean' => '0', | |
'autoptimize_cache_nogzip' => 'on', | |
'autoptimize_show_adv' => '0', | |
'autoptimize_configured' => 'yes' | |
); | |
// loop through the defaults array, and update each option with the corresponding value | |
foreach( $defaults as $key=>$value ){ | |
update_option( $key, $value ); | |
} | |
// log this to the error log | |
error_log('autoautoptimize done'); | |
} | |
} | |
// hook into init | |
add_action( 'init', 'rt_autoautoptimize' ); | |
} | |
/** | |
* Apply the default configuration to newly created sites | |
*/ | |
if( !function_exists('rt_autoautoptimize_newblog') ){ | |
function rt_autoautoptimize_newblog( $blog_id, $user_id, $domain, $path, $site_id, $meta ){ | |
if( !empty( $blog_id ) && function_exists('rt_autoautoptimize') ){ | |
// apply the auto-configuration | |
rt_autoautoptimize(); | |
} | |
} | |
add_action( 'wpmu_new_blog', 'rt_autoautoptimize_newblog', 10, 6 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment