wp_deregister_script()
wp_deregister_script( string $handle ) 删除已注册的脚本。 Remove…
wp_deregister_script( string $handle )
删除已注册的脚本。
Remove a registered script.
删除已注册的脚本。
Remove a registered script.
目录锚点:#说明#参数#源码#笔记
说明(Description)
注意:有专门的保护措施来防止关键管理脚本(如jquerycore)被注销。另请参见#另请参阅WP_Dependencies::remove()
参数(Parameters)
| 参数 | 类型 | 说明 |
|---|---|---|
| $handle | (string) | 要删除的脚本的名称。 |
源码(Source)
/**
* 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 );
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 2.1.0 | wp-includes/functions.wp-scripts.php | 20 | 11 |
笔记(Notes)
从严格意义上讲,取消注册不会使脚本句柄出列。
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。




还没有任何评论,赶紧来占个楼吧!