本文整理匯總了PHP中WP_Scripts::get_data方法的典型用法代碼示例。如果您正苦於以下問題:PHP WP_Scripts::get_data方法的具體用法?PHP WP_Scripts::get_data怎麽用?PHP WP_Scripts::get_data使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類WP_Scripts
的用法示例。
在下文中一共展示了WP_Scripts::get_data方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: add_data
/**
* Adds script data to registered components.
*
* @note This method implements the ability to add additional inline data to specific scripts.
* As of v3.4, WordPress® is still lacking functions to interact w/ this feature.
* Therefore, we'll need to access `$wp_scripts` directly.
*
* @param string|array $components A string, or an array of specific components that need `$data` (i.e. inline JavaScript code).
*
* @param string $data The data (i.e. inline JavaScript code) that is needed by `$components`.
*
* @throws exception If invalid types are passed through arguments list.
*/
public function add_data($components, $data)
{
$this->check_arg_types(array('string', 'array'), 'string', func_get_args());
$components = (array) $components;
// Force array value.
global $wp_scripts;
// Global object reference.
if (!$wp_scripts instanceof \WP_Scripts) {
$wp_scripts = new \WP_Scripts();
}
foreach ($components = array_unique($components) as $_handle) {
if ($this->©string->is_not_empty($_handle) && wp_script_is($_handle, 'registered')) {
$existing_data = $wp_scripts->get_data($_handle, 'data');
$wp_scripts->add_data($_handle, 'data', trim($existing_data . "\n" . $data));
}
}
}