本文整理汇总了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));
}
}
}