wp_script_is()判断一个脚本是否已经注册/加载/输出

目录

描述

Determine if a script has been registered, enqueued, printed, or is waiting to be printed. Very useful when registering/enqueing scripts in plugins to avoid conflicts with other plugin scripts.

wp_script_is() 描述

用法

<?php wp_script_is$handle$list 'enqueued' ); ?>

wp_script_is() 用法

参数

$handle

(string) (必填) Name of the script. Lowercase string.

默认值: None

$list

(string) (可选) The list to query.

  • registered - script was registered through wp_register_script()
  • enqueued / queue - script was enqueued
  • done - script has been printed
  • to_do - script has not yet been printed

默认值: enqueued

wp_script_is() 参数

返回值

(bool) 

True or false.

wp_script_is() 返回值

历史

wp_script_is() 历史

源文件

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

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Check whether a script has been added to the queue.
 *
 * @since 2.8.0
 * @since 3.5.0 'enqueued' added as an alias of the 'queue' list.
 *
 * @param string $handle Name of the script.
 * @param string $list   Optional. Status of the script to check. Default 'enqueued'.
 *                       Accepts 'enqueued', 'registered', 'queue', 'to_do', and 'done'.
 * @return bool Whether the script script is queued.
 */
function wp_script_is( $handle, $list = 'enqueued' ) {
	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );

	return (bool) wp_scripts()->query( $handle, $list );
}

wp_script_is() 源文件

相关