X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/8f374b7233bc2815ccc387e448d208c5434eb961..61343b82c4f0da4c68e4c6373daafff4a81efdd1:/wp-includes/functions.wp-scripts.php?ds=inline diff --git a/wp-includes/functions.wp-scripts.php b/wp-includes/functions.wp-scripts.php index a8dac35c..32778ab5 100644 --- a/wp-includes/functions.wp-scripts.php +++ b/wp-includes/functions.wp-scripts.php @@ -27,7 +27,7 @@ function wp_print_scripts( $handles = false ) { if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { if ( ! did_action( 'init' ) ) _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), - 'wp_enqueue_scripts', 'admin_enqueue_scripts', 'init' ), '3.3' ); + 'wp_enqueue_scripts', 'admin_enqueue_scripts', 'login_enqueue_scripts' ), '3.3' ); if ( !$handles ) return array(); // No need to instantiate if nothing is there. @@ -54,7 +54,7 @@ function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_f if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { if ( ! did_action( 'init' ) ) _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), - 'wp_enqueue_scripts', 'admin_enqueue_scripts', 'init' ), '3.3' ); + 'wp_enqueue_scripts', 'admin_enqueue_scripts', 'login_enqueue_scripts' ), '3.3' ); $wp_scripts = new WP_Scripts(); } @@ -66,7 +66,7 @@ function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_f /** * Wrapper for $wp_scripts->localize(). * - * Used to localizes a script. + * Used to localize a script. * Works only if the script has already been added. * Accepts an associative array $l10n and creates JS object: * "$object_name" = { @@ -88,7 +88,7 @@ function wp_localize_script( $handle, $object_name, $l10n ) { if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { if ( ! did_action( 'init' ) ) _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), - 'wp_enqueue_scripts', 'admin_enqueue_scripts', 'init' ), '3.3' ); + 'wp_enqueue_scripts', 'admin_enqueue_scripts', 'login_enqueue_scripts' ), '3.3' ); return false; } @@ -107,10 +107,30 @@ function wp_deregister_script( $handle ) { if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { if ( ! did_action( 'init' ) ) _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), - 'wp_enqueue_scripts', 'admin_enqueue_scripts', 'init' ), '3.3' ); + 'wp_enqueue_scripts', 'admin_enqueue_scripts', 'login_enqueue_scripts' ), '3.3' ); $wp_scripts = new WP_Scripts(); } + // Do not allow accidental or negligent deregistering of critical scripts in the admin. Show minimal remorse if the correct hook is used. + if ( is_admin() && 'admin_enqueue_scripts' !== current_filter() ) { + $no = array( + 'jquery', 'jquery-core', 'jquery-migrate', 'jquery-ui-core', 'jquery-ui-accordion', + 'jquery-ui-autocomplete', 'jquery-ui-button', 'jquery-ui-datepicker', 'jquery-ui-dialog', + 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-menu', 'jquery-ui-mouse', + 'jquery-ui-position', 'jquery-ui-progressbar', 'jquery-ui-resizable', 'jquery-ui-selectable', + 'jquery-ui-slider', 'jquery-ui-sortable', 'jquery-ui-spinner', 'jquery-ui-tabs', + 'jquery-ui-tooltip', 'jquery-ui-widget', + 'underscore', 'backbone', + ); + + if ( in_array( $handle, $no ) ) { + $message = sprintf( __( 'Do not deregister the %1$s script in the administration area. To target the frontend theme, use the %2$s hook.' ), + "$handle", 'wp_enqueue_scripts' ); + _doing_it_wrong( __FUNCTION__, $message, '3.6' ); + return; + } + } + $wp_scripts->remove( $handle ); } @@ -127,7 +147,7 @@ function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { if ( ! did_action( 'init' ) ) _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), - 'wp_enqueue_scripts', 'admin_enqueue_scripts', 'init' ), '3.3' ); + 'wp_enqueue_scripts', 'admin_enqueue_scripts', 'login_enqueue_scripts' ), '3.3' ); $wp_scripts = new WP_Scripts(); } @@ -151,7 +171,7 @@ function wp_dequeue_script( $handle ) { if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { if ( ! did_action( 'init' ) ) _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), - 'wp_enqueue_scripts', 'admin_enqueue_scripts', 'init' ), '3.3' ); + 'wp_enqueue_scripts', 'admin_enqueue_scripts', 'login_enqueue_scripts' ), '3.3' ); $wp_scripts = new WP_Scripts(); } @@ -161,28 +181,25 @@ function wp_dequeue_script( $handle ) { /** * Check whether script has been added to WordPress Scripts. * - * The values for list defaults to 'queue', which is the same as enqueue for - * scripts. + * By default, checks if the script has been enqueued. You can also + * pass 'registered' to $list, to see if the script is registered, + * and you can check processing statuses with 'to_do' and 'done'. * * @since WP unknown; BP unknown * - * @param string $handle Handle used to add script. - * @param string $list Optional, defaults to 'queue'. Others values are 'registered', 'queue', 'done', 'to_do' - * @return bool + * @param string $handle Name of the script. + * @param string $list Optional. Defaults to 'enqueued'. Values are + * 'registered', 'enqueued' (or 'queue'), 'to_do', and 'done'. + * @return bool Whether script is in the list. */ -function wp_script_is( $handle, $list = 'queue' ) { +function wp_script_is( $handle, $list = 'enqueued' ) { global $wp_scripts; if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { if ( ! did_action( 'init' ) ) _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), - 'wp_enqueue_scripts', 'admin_enqueue_scripts', 'init' ), '3.3' ); + 'wp_enqueue_scripts', 'admin_enqueue_scripts', 'login_enqueue_scripts' ), '3.3' ); $wp_scripts = new WP_Scripts(); } - $query = $wp_scripts->query( $handle, $list ); - - if ( is_object( $query ) ) - return true; - - return $query; + return (bool) $wp_scripts->query( $handle, $list ); }