wp_deregister_script()删除一个已注册的脚本

目录

描述

Remove a registered script (javascript).

wp_deregister_script() 描述

用法

<?php wp_deregister_script$handle ); ?>

wp_deregister_script() 用法

参数

$handle

(string) (必填) Name of the script handle to be removed

默认值: None

wp_deregister_script() 参数

返回值

(void) 

This function does not return a value.

wp_deregister_script() 返回值

历史

  • 添加于 版本: 2.6 (BackPress version: r16)

wp_deregister_script() 历史

源文件

wp_deregister_script() 函数的代码位于 wp-includes/functions.wp-scripts.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Remove a registered script.
 *
 * Note: there are intentional safeguards in place to prevent critical admin scripts,
 * such as jQuery core, from being unregistered.
 *
 * @see WP_Dependencies::remove()
 *
 * @since 2.6.0
 *
 * @param string $handle Name of the script to be removed.
 */
function wp_deregister_script( $handle ) {
	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );

	/**
	 * Do not allow accidental or negligent de-registering of critical scripts in the admin.
	 * Show minimal remorse if the correct hook is used.
	 */
	$current_filter = current_filter();
	if ( ( is_admin() && 'admin_enqueue_scripts' !== $current_filter ) ||
		( 'wp-login.php' === $GLOBALS['pagenow'] && 'login_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 );
}

wp_deregister_script() 源文件

相关