get_col( "SELECT blog_id FROM $wpdb->blogs" ); $original_blog_id = get_current_blog_id(); foreach ( $blog_ids as $blog_id ) { switch_to_blog( $blog_id ); foreach ($delete_options as $del_opt) { delete_option( $del_opt ); } } switch_to_blog( $original_blog_id ); } } /** * aj_enqueue_scripts() * * register admin stylesheets and javascripts * */ public function aj_enqueue_scripts() { // chosen wp_enqueue_style('chosen', plugins_url( 'assets/lib/chosen_v1.4.2/chosen.min.css', __FILE__ )); wp_enqueue_script('chosen', plugins_url( 'assets/lib/chosen_v1.4.2/chosen.jquery.min.js', __FILE__ ), array( 'jquery' ), AJ_VERSION, true); // own JS & CSS wp_enqueue_style('aj_admin_styles', plugins_url( '/css/admin.min.css', __FILE__ )); wp_enqueue_script('aj_admin_scripts',plugins_url( '/js/admin.min.js', __FILE__ ),array( 'jquery', 'chosen' ), AJ_VERSION, true); // ajaxy stuff $aj_localize = array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'siteurl' => get_site_url(), 'pluginurl' => AJ_PLUGIN_URL, 'ajadminurl' => admin_url( 'options-general.php?page=async-javascript' ) ); wp_localize_script( 'aj_admin_scripts', 'aj_localize_admin', $aj_localize ); } /** * aj_disable_pro() * * check if the old AJS_pro is active and deactivate if so * */ public function aj_disable_pro() { if ( is_plugin_active( 'async-javascript-pro/async-javascript-pro.php' ) ) { deactivate_plugins( array( 'async-javascript-pro/async-javascript-pro.php' ) ); } } /** * aj_admin_init() * * register admin stylesheets and javascripts * */ public function aj_admin_init() { global $wp, $wpdb; register_activation_hook( __FILE__, array( $this, 'aj_activate' ) ); register_deactivation_hook( __FILE__, array( $this, 'aj_deactivate' ) ); if ( !class_exists( 'Services_WTF_Test' ) ) { require_once( AJ_PLUGIN_DIR . 'lib/gtmetrix/class.Services_WTF_Test.php' ); } // check if upgrading from early release so settings can be transferred $aj_version = get_option( 'aj_version', '' ); if ( $aj_version == '' || $aj_version < '2017.04.25' ) { $aj_enabled = get_option( 'aj_enabled', 0 ); $aj_method = get_option( 'aj_method', 'async' ); $aj_jquery = ( get_option( 'aj_jquery', 'async' ) == 'same' ) ? $aj_method : get_option( 'aj_jquery', 'async' ); $aj_async = get_option( 'aj_async', '' ); $aj_defer = get_option( 'aj_defer', '' ); $aj_exclusions = get_option( 'aj_exclusions', '' ); $aj_plugin_exclusions = ( is_array( get_option( 'aj_plugin_exclusions', array() ) ) && !is_null( get_option( 'aj_plugin_exclusions', array() ) ) ? get_option( 'aj_plugin_exclusions', array() ) : explode( ',', get_option( 'aj_plugin_exclusions', '' ) ) ); $aj_theme_exclusions = ( is_array( get_option( 'aj_theme_exclusions', array() ) ) && !is_null( get_option( 'aj_theme_exclusions', array() ) ) ? get_option( 'aj_theme_exclusions', array() ) : explode( ',', get_option( 'aj_theme_exclusions', '' ) ) ); $aj_autoptimize_enabled = get_option( 'aj_autoptimize_enabled', 0 ); $aj_autoptimize_method = get_option( 'aj_autoptimize_method', 'async' ); update_option( 'aj_enabled', $aj_enabled ); update_option( 'aj_method', $aj_method ); update_option( 'aj_jquery', $aj_jquery ); update_option( 'aj_async', $aj_async ); update_option( 'aj_defer', $aj_defer ); update_option( 'aj_exclusions', $aj_exclusions ); update_option( 'aj_plugin_exclusions', $aj_plugin_exclusions ); update_option( 'aj_theme_exclusions', $aj_theme_exclusions ); update_option( 'aj_autoptimize_enabled', $aj_autoptimize_enabled ); update_option( 'aj_autoptimize_method', $aj_autoptimize_method ); } if ( $aj_version != AJ_VERSION ) { update_option( 'aj_version', AJ_VERSION ); } add_action( 'wp_dashboard_setup', array( $this, 'register_aj_dashboard_widget' ) ); add_action( 'admin_menu', array( $this, 'async_javascript_menu' ) ); add_action( 'wp_ajax_aj_steps', array( $this, 'aj_steps' ) ); add_action( 'admin_notices', array( $this, 'aj_admin_notice' ) ); } /** * register_aj_dashboard_widget() * * Register dashboard widget * */ public function register_aj_dashboard_widget() { if ( current_user_can( 'manage_options' ) ) { global $wp_meta_boxes; wp_add_dashboard_widget( 'aj_dashboard_widget', AJ_TITLE, array( $this, 'aj_dashboard_widget' ) ); $dashboard = $wp_meta_boxes['dashboard']['normal']['core']; $aj_widget = array( 'aj_dashboard_widget' => $dashboard['aj_dashboard_widget'] ); unset( $dashboard['aj_dashboard_widget'] ); $sorted_dashboard = array_merge( $aj_widget, $dashboard ); $wp_meta_boxes['dashboard']['normal']['core'] = $sorted_dashboard; } } /** * aj_dashboard_widget() * * Dashboard widget * */ public function aj_dashboard_widget() { require_once('asyncjsDashboardScreens.php'); } /** * aj_admin_notice() * * check if async javascript (free) is active and display notice if so * check if settings have been updated and display notice if so * * @param n/a * @return n/a */ public function aj_admin_notice() { if ( is_plugin_active( 'async-javascript-pro/async-javascript-pro.php' ) ) { $class = 'update-nag'; $message = __('We have detected that Async JavaScript Pro is still active. Please disable from the plugin menu before using ','asyncjs') . AJ_TITLE; echo "
$message
"; } } /** * async_javascript_menu() * * register admin menu * * @param n/a * @return n/a */ public function async_javascript_menu() { add_submenu_page( 'options-general.php', AJ_TITLE . ' Admin', AJ_TITLE, 'manage_options', 'async-javascript', array( $this, 'async_javascript_admin' ) ); } /** * async_javascript_admin() * * admin page * * @param n/a * @return n/a */ public function async_javascript_admin() { $tabs = array( 'wizard', 'settings','status', 'help', 'Optimize More!' ); $active_tab = isset( $_GET[ 'tab' ] ) ? sanitize_text_field( $_GET[ 'tab' ] ) : 'settings'; ?>
" />

Welcome to

'.__('When a JavaScript file is loaded via the wp_enqueue_script function, ' . AJ_TITLE . ' will add an async or defer attribute.','asyncjs').'

'; $return .= '

'.__('There are several ways an external JavaScript file can be executed:','asyncjs').'

'; $return .= ''; $return .= '

'.__('Using async or defer helps to eliminate render-blocking JavaScript in above-the-fold content. This can also help to increase your pagespeed which in turn can assist in improving your page ranking.

','asyncjs'); return $return; } /** * hints_tips() * * Return common text for Hints & Tips * */ private function hints_tips() { $return = ''; $return .= '

'.__('Further Hints & Tips','asyncjs').'

'; if ( is_plugin_active( 'autoptimize/autoptimize.php' ) ) { $return .= '

' . AJ_TITLE . __(' has detected that you have Autoptimize installed and active. ','asyncjs') . AJ_TITLE . __(' can further enhance Autoptimize results by applying Async or Defer to the cache files used by Autoptimize.

','asyncjs'); } else { $return .= '

' . AJ_TITLE . __(' has detected that you do not have Autoptimize installed and active. Autoptimize can provide further optimization of JavaScript which can benefit the results of ' . AJ_TITLE . ' (and ' . AJ_TITLE . ' can also enhance Autoptimize results!)

','asyncjs'); $return .= '

'. __('You can install Autoptimize from the plugin repository, or download it from here: ','asyncjs') .'https://wordpress.org/plugins/autoptimize/

'; } $return .= '

'. __('Through our testing the following common Autoptimize settings work well to achieve the best results. Of course each website is different so you may need to fine tune these settings to suit.

','asyncjs'); $return .= '
    '; $return .= '
  1. '. __('Navigate to Settings > Autoptimize
  2. ','asyncjs'); $return .= '
  3. '. __('Click on the Show advanced settings button
  4. ','asyncjs'); $return .= '
  5. '. __('Under JavaScript Options set the following:
  6. ','asyncjs'); $return .= ''; $return .= '
  7. '. __('Click on the Save Changes and Empty Cache button
  8. ','asyncjs'); $return .= '
  9. '. __('Navigate to Settings > ' . AJ_TITLE . '
  10. ','asyncjs'); $return .= '
  11. '. __('Click on the Settings tab
  12. ','asyncjs'); $return .= '
  13. '. __('Scroll down to ' . AJ_TITLE . ' For Plugins
  14. ','asyncjs'); $return .= '
  15. '. __('Under Autoptimize set the following:
  16. ','asyncjs'); $return .= ''; $return .= '
  17. '. __('Click on Save Changes
  18. ','asyncjs'); $return .= '
'; return $return; } /** * aj_steps() * * all things Ajax (wizard, saving settings, ...) * actual code moved to external file to tidy things up a bit * */ public function aj_steps() { require_once('asyncjsAllAjax.php'); } }