wp/wp-includes/functions.wp-scripts.php
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
   120  * @since 4.5.0
   120  * @since 4.5.0
   121  *
   121  *
   122  * @see WP_Scripts::add_inline_script()
   122  * @see WP_Scripts::add_inline_script()
   123  *
   123  *
   124  * @param string $handle   Name of the script to add the inline script to.
   124  * @param string $handle   Name of the script to add the inline script to.
   125  * @param string $data     String containing the javascript to be added.
   125  * @param string $data     String containing the JavaScript to be added.
   126  * @param string $position Optional. Whether to add the inline script before the handle
   126  * @param string $position Optional. Whether to add the inline script before the handle
   127  *                         or after. Default 'after'.
   127  *                         or after. Default 'after'.
   128  * @return bool True on success, false on failure.
   128  * @return bool True on success, false on failure.
   129  */
   129  */
   130 function wp_add_inline_script( $handle, $data, $position = 'after' ) {
   130 function wp_add_inline_script( $handle, $data, $position = 'after' ) {
   256  *
   256  *
   257  * @see WP_Dependencies::remove()
   257  * @see WP_Dependencies::remove()
   258  *
   258  *
   259  * @since 2.1.0
   259  * @since 2.1.0
   260  *
   260  *
       
   261  * @global string $pagenow
       
   262  *
   261  * @param string $handle Name of the script to be removed.
   263  * @param string $handle Name of the script to be removed.
   262  */
   264  */
   263 function wp_deregister_script( $handle ) {
   265 function wp_deregister_script( $handle ) {
       
   266 	global $pagenow;
       
   267 
   264 	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
   268 	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
   265 
   269 
   266 	/**
   270 	/**
   267 	 * Do not allow accidental or negligent de-registering of critical scripts in the admin.
   271 	 * Do not allow accidental or negligent de-registering of critical scripts in the admin.
   268 	 * Show minimal remorse if the correct hook is used.
   272 	 * Show minimal remorse if the correct hook is used.
   269 	 */
   273 	 */
   270 	$current_filter = current_filter();
   274 	$current_filter = current_filter();
   271 	if ( ( is_admin() && 'admin_enqueue_scripts' !== $current_filter ) ||
   275 	if ( ( is_admin() && 'admin_enqueue_scripts' !== $current_filter ) ||
   272 		( 'wp-login.php' === $GLOBALS['pagenow'] && 'login_enqueue_scripts' !== $current_filter )
   276 		( 'wp-login.php' === $pagenow && 'login_enqueue_scripts' !== $current_filter )
   273 	) {
   277 	) {
   274 		$not_allowed = array(
   278 		$not_allowed = array(
   275 			'jquery',
   279 			'jquery',
   276 			'jquery-core',
   280 			'jquery-core',
   277 			'jquery-migrate',
   281 			'jquery-migrate',
   298 			'underscore',
   302 			'underscore',
   299 			'backbone',
   303 			'backbone',
   300 		);
   304 		);
   301 
   305 
   302 		if ( in_array( $handle, $not_allowed, true ) ) {
   306 		if ( in_array( $handle, $not_allowed, true ) ) {
   303 			$message = sprintf(
   307 			_doing_it_wrong(
   304 				/* translators: 1: Script name, 2: wp_enqueue_scripts */
   308 				__FUNCTION__,
   305 				__( 'Do not deregister the %1$s script in the administration area. To target the front-end theme, use the %2$s hook.' ),
   309 				sprintf(
   306 				"<code>$handle</code>",
   310 					/* translators: 1: Script name, 2: wp_enqueue_scripts */
   307 				'<code>wp_enqueue_scripts</code>'
   311 					__( 'Do not deregister the %1$s script in the administration area. To target the front-end theme, use the %2$s hook.' ),
       
   312 					"<code>$handle</code>",
       
   313 					'<code>wp_enqueue_scripts</code>'
       
   314 				),
       
   315 				'3.6.0'
   308 			);
   316 			);
   309 			_doing_it_wrong( __FUNCTION__, $message, '3.6.0' );
       
   310 			return;
   317 			return;
   311 		}
   318 		}
   312 	}
   319 	}
   313 
   320 
   314 	wp_scripts()->remove( $handle );
   321 	wp_scripts()->remove( $handle );