| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: jQuery Updater |
| 4 |
* Plugin URI: http://www.ramoonus.nl/wordpress/jquery-updater/ |
| 5 |
* Description: This plugin updates jQuery to the latest stable version. |
| 6 |
* Version: 4.0.0 |
| 7 |
* Author: Ramoonus |
| 8 |
* Author URI: http://www.ramoonus.nl/ |
| 9 |
* License: GPL3 |
| 10 |
* Text Domain: jquery-updater |
| 11 |
* Domain Path: /languages |
| 12 |
*/ |
| 13 |
|
| 14 |
/** |
| 15 |
* Replace jQuery with a newer version, load jQuery Migrate |
| 16 |
* |
| 17 |
* @version 4.0.0 |
| 18 |
* @since 1.0.0 |
| 19 |
* @return void |
| 20 |
*/ |
| 21 |
function rw_jquery_updater() |
| 22 |
{ |
| 23 |
$ver = '4.0.0'; |
| 24 |
$ver_migrate = '3.6.0'; |
| 25 |
$slim = false; |
| 26 |
$min = true; |
| 27 |
$cdn = false; // google, microsoft, cdnjs, jsdelivr |
| 28 |
$migrate = true; |
| 29 |
$enqueue_admin = false; |
| 30 |
|
| 31 |
$core_suffix = ''; |
| 32 |
$migrate_suffix = ''; |
| 33 |
|
| 34 |
if ( $slim ) { |
| 35 |
$core_suffix .= '.slim'; |
| 36 |
} |
| 37 |
|
| 38 |
if ( $min ) { |
| 39 |
$core_suffix .= '.min'; |
| 40 |
$migrate_suffix = '.min'; |
| 41 |
} |
| 42 |
|
| 43 |
$core_file = 'jquery-' . $ver . $core_suffix . '.js'; |
| 44 |
$migrate_file = 'jquery-migrate-' . $ver_migrate . $migrate_suffix . '.js'; |
| 45 |
|
| 46 |
$core_url = plugins_url( 'js/' . $core_file, __FILE__ ); |
| 47 |
$migrate_url = plugins_url( 'js/' . $migrate_file, __FILE__ ); |
| 48 |
|
| 49 |
// jQuery core. |
| 50 |
wp_deregister_script( 'jquery-core' ); |
| 51 |
wp_register_script( 'jquery-core', $core_url, array(), $ver ); |
| 52 |
|
| 53 |
// jQuery migrate. |
| 54 |
wp_deregister_script( 'jquery-migrate' ); |
| 55 |
wp_register_script( 'jquery-migrate', $migrate_url, array( 'jquery-core' ), $ver_migrate ); |
| 56 |
|
| 57 |
// jQuery meta handle. |
| 58 |
wp_deregister_script( 'jquery' ); |
| 59 |
wp_register_script( 'jquery', false, array( 'jquery-core', 'jquery-migrate' ), $ver ); |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Front-End |
| 64 |
* |
| 65 |
* @version 2.1 |
| 66 |
*/ |
| 67 |
add_action( 'wp_enqueue_scripts', 'rw_jquery_updater' ); |
| 68 |
add_action( 'login_enqueue_scripts', 'rw_jquery_updater' ); |
| 69 |
// since 3.4.0.1 |
| 70 |
|
| 71 |
/** |
| 72 |
* Load translation |
| 73 |
* |
| 74 |
* @since 2.2.0 |
| 75 |
* @version 1.0.0 |
| 76 |
* |
| 77 |
*/ |
| 78 |
function rw_load_plugin_textdomain() |
| 79 |
{ |
| 80 |
load_plugin_textdomain( 'jquery-updater', false, basename( dirname( __FILE__ ) ) . '/languages/' ); |
| 81 |
} |
| 82 |
add_action( 'plugins_loaded', 'rw_load_plugin_textdomain' ); |
| 83 |
|
| 84 |
/** |
| 85 |
* Activation Message |
| 86 |
*/ |
| 87 |
function jqu_admin_notice_activation_hook() { |
| 88 |
// does things upon activation |
| 89 |
set_transient( 'jqu_admin_notice', true, 5 ); |
| 90 |
|
| 91 |
// @todo flush cache |
| 92 |
} |
| 93 |
register_activation_hook( __FILE__, 'jqu_admin_notice_activation_hook' ); |
| 94 |
|
| 95 |
function jqu_admin_notice_message() { |
| 96 |
|
| 97 |
/* Check transient, if available display notice */ |
| 98 |
if ( get_transient( 'jqu_admin_notice' ) ) { |
| 99 |
?> |
| 100 |
<div class="updated notice is-dismissible"> |
| 101 |
<p> |
| 102 |
<?php |
| 103 |
printf( |
| 104 |
esc_html__( 'jQuery Updater has been %1$senabled%2$s.', 'jquery-updater' ), |
| 105 |
'<strong>', |
| 106 |
'</strong>' |
| 107 |
); |
| 108 |
?> |
| 109 |
<br> |
| 110 |
<?php echo esc_html__( 'Please flush your browser and server cache.', 'jquery-updater' ); ?> |
| 111 |
</p> |
| 112 |
</div> |
| 113 |
<?php |
| 114 |
/* Delete transient, only display this notice once. */ |
| 115 |
delete_transient( 'jqu_admin_notice' ); |
| 116 |
} |
| 117 |
} |
| 118 |
add_action( 'admin_notices', 'jqu_admin_notice_message' ); |
| 119 |
|