tags add_filter( 'script_loader_tag', array ( $this, 'modify_script_tags' ), 10, 2 ); } // Ensures only one instance is/can be loaded public static function instance() { if ( is_null( self::$instance ) ) { self::$instance = new self(); } return self::$instance; } /** * Singleton pattern: prevent creating more instances by clone and unserialize: */ public function __clone() { /* translators: Placeholders: %s - plugin name */ _doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'You cannot clone instances of %s.', 'jquery-async-loader' ), 'jQuery Async Loader' ), '2.4.0' ); } public function __wakeup() { /* translators: Placeholders: %s - plugin name */ _doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'You cannot unserialize instances of %s.', 'jquery-async-loader' ), 'jQuery Async Loader' ), '2.4.0' ); } // Add plugin links: Settings and Author web site: public function add_plugin_links( $links ) { $plugin_links = array( '' . __( 'Settings', 'jquery-async-loader' ) . '', '' . __( 'Author', 'jquery-async-loader' ) . '' ); return array_merge( $plugin_links, $links ); } /**********************/ /** Frontend methods **/ /**********************/ /** * Replace jQuery with minified CDN version */ public function re_register_jquery() { $defaults = array( 'replace_jquery' => 1, ); $options = wp_parse_args(get_option('jquery_async_loader_options'), $defaults); if ( $options['replace_jquery'] === 1 ) { wp_deregister_script('jquery'); wp_register_script('jquery', '//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js', FALSE, '1.11.0', TRUE); wp_enqueue_script('jquery'); } } /** * Add jQl - jQuery Async Loader script * Author URL: https://github.com/Cerdic/jQl */ public function jQuery_loader_script() { echo ''; } public function modify_script_tags( $tag ) { $defaults = array( 'replace_jquery' => 1, 'enable_on_backend' => 0 ); $options = wp_parse_args(get_option('jquery_async_loader_options'), $defaults); // Additional check to be sure that this code is not executed on admin pages: if( ( is_admin() ) && ( $options['enable_on_backend'] !== 1 ) ) { return $tag; } // Get src urls of scripts: preg_match("/jQl.loadjQ('".$match[4]."');"; } // In any other cases use loadjQdep return ""; } /** * Load Translations */ public function load_translation() { load_plugin_textdomain( 'jquery-async-loader', false, dirname( plugin_basename( __FILE__ ) ) . '/i18n/languages' ); } /** * Renders a notice when Wordpress version is outdated */ public static function render_outdated_wp_version_notice() { $message = sprintf( /* translators: %1$s and %2$s are tags. %3$s and %4$s are tags. */ esc_html__( '%1$jQuery Async Loader plugin is inactive.%2$s This plugin requires Wordpress 4.1 or newer. Please %3$supdate Wordpress to version 4.1 or newer%4$s', 'jquery-async-loader' ), '', '', '', ' »' ); printf( '

%s

', $message ); } /********************/ /** Plugin methods **/ /********************/ /** * Add Settings */ public function add_settings() { register_setting( 'jquery_async_loader_options', 'jquery_async_loader_options', array( $this, 'jquery_async_loader_options_validate' ) ); } public function add_settings_page() { add_options_page( __( 'jQuery Async Loader Settings', 'jquery_async_loader' ), __( 'jQuery Async Loader', 'jquery_async_loader' ), 'manage_options', 'jquery_async_loader', array( $this, 'jquery_async_loader_options_page' ) ); } public function jquery_async_loader_options_page() { // Display the admin options page if ( ! isset( $_REQUEST['settings-updated'] ) ) $_REQUEST['settings-updated'] = false; ?>

1, 'enable_on_backend' => 0 ); $options = wp_parse_args(get_option('jquery_async_loader_options'), $defaults); ?>

tags. %3$s and %4$s are links to the plugins. %5$s and %$6s code tags with quotes. */ esc_html__( '%1$sIt\'s highly recommended to use any concatenate plugin,%2$s e.g., %3$s or %4$s. Please, do not add jQuery to the ignore list, because this plugin fixes %5$sundefined jQuery%6$s errors on the console log. Also, it is allowed to use defer or async parsing of JS files.', 'jquery-async-loader' ), '', '', 'Fast Velocity Minify', 'WP Fastest Cache', '“', '”' ); ?>

/>
/>

tags. */ esc_html__( 'For advanced users: If you\'re seeing any scripts loaded using %1$s