本文整理汇总了PHP中WP_Scripts类的典型用法代码示例。如果您正苦于以下问题:PHP WP_Scripts类的具体用法?PHP WP_Scripts怎么用?PHP WP_Scripts使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WP_Scripts类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register_scripts
/**
* Register scripts.
*
* @param \WP_Scripts $wp_scripts Instance of \WP_Scripts.
* @action wp_default_scripts
*/
function register_scripts(\WP_Scripts $wp_scripts)
{
$src = $this->dir_url . 'js/customize-concurrency.js';
$deps = array('heartbeat', 'customize-widgets', 'underscore');
$wp_scripts->add($this->slug, $src, $deps);
$wp_scripts->add_data($this->slug, 'group', 1);
// 1 = in_footer.
}
示例2: do_scripts
static function do_scripts($handles)
{
global $wp_scripts;
if (!is_a($wp_scripts, 'WP_Scripts')) {
$wp_scripts = new WP_Scripts();
}
$wp_scripts->do_items((array) $handles);
}
示例3: wp_script_is
function wp_script_is($handle, $list = 'queue')
{
global $wp_scripts;
if (!is_a($wp_scripts, 'WP_Scripts')) {
$wp_scripts = new WP_Scripts();
}
$query = $wp_scripts->query($handle, $list);
if (is_object($query)) {
return true;
}
return $query;
}
示例4: wp_enqueue_script
/**
* Equeues script
*
* Registers the script if src provided (does NOT overwrite) and enqueues.
*
* @see WP_Script::add(), WP_Script::enqueue()
*/
function wp_enqueue_script($handle, $src = false, $deps = array(), $ver = false)
{
global $wp_scripts;
if (!is_a($wp_scripts, 'WP_Scripts')) {
$wp_scripts = new WP_Scripts();
}
if ($src) {
$_handle = explode('?', $handle);
$wp_scripts->add($_handle[0], $src, $deps, $ver);
}
$wp_scripts->enqueue($handle);
}
示例5: register_scripts
/**
* Register scripts.
*
* @action wp_default_scripts, 11
*
* @param \WP_Scripts $wp_scripts Instance of \WP_Scripts.
*/
public function register_scripts(\WP_Scripts $wp_scripts)
{
$min = SCRIPT_DEBUG ? '' : '.min';
$handle = 'customize-snapshots';
$src = $this->dir_url . 'js/customize-snapshots' . $min . '.js';
$deps = array('jquery', 'jquery-ui-dialog', 'wp-util', 'customize-controls');
$wp_scripts->add($handle, $src, $deps);
$handle = 'customize-snapshots-preview';
$src = $this->dir_url . 'js/customize-snapshots-preview' . $min . '.js';
$deps = array('customize-preview');
$wp_scripts->add($handle, $src, $deps);
$handle = 'customize-snapshots-frontend';
$src = $this->dir_url . 'js/customize-snapshots-frontend' . $min . '.js';
$deps = array('jquery', 'underscore');
$wp_scripts->add($handle, $src, $deps);
}
示例6: array
/**
* @param WP_Scripts $wp_scripts
* @action wp_default_scripts
*/
function register_scripts($wp_scripts)
{
$handle = 'customize-partial-refresh-base';
$src = $this->get_dir_url('js/customize-partial-refresh-base.js');
$deps = array('customize-base');
$wp_scripts->add($handle, $src, $deps, $this->get_version());
$this->script_handles['base'] = $handle;
$handle = 'customize-partial-refresh-widgets-preview';
$src = $this->get_dir_url('js/customize-partial-refresh-widgets-preview.js');
$deps = array('jquery', 'wp-util', 'customize-preview', 'customize-preview-widgets', $this->script_handles['base']);
$in_footer = true;
$wp_scripts->add($handle, $src, $deps, $this->get_version(), $in_footer);
$this->script_handles['widgets-preview'] = $handle;
$handle = 'customize-partial-refresh-widgets-pane';
$src = $this->get_dir_url('js/customize-partial-refresh-widgets-pane.js');
$deps = array('jquery', 'wp-util', 'customize-controls', 'customize-widgets', $this->script_handles['base']);
$in_footer = true;
$wp_scripts->add($handle, $src, $deps, $this->get_version(), $in_footer);
$this->script_handles['widgets-pane'] = $handle;
}
开发者ID:AshiqKiron,项目名称:wp-customize-partial-refresh,代码行数:24,代码来源:class-wp-customize-partial-refresh-plugin.php
示例7: gp_scripts_default
/**
* Register the GlotPress scripts
*
* @param WP_Scripts $scripts
*/
function gp_scripts_default(&$scripts)
{
$url = gp_plugin_url('assets/js');
$scripts->add('tablesorter', $url . '/jquery.tablesorter.min.js', array('jquery'), '1.10.4');
$scripts->add('gp-common', $url . '/common.js', array('jquery'), '20150430');
$scripts->add('gp-editor', $url . '/editor.js', array('gp-common', 'jquery-ui-tooltip'), '20160329');
$scripts->add('gp-glossary', $url . '/glossary.js', array('gp-common'), '20160329');
$scripts->add('gp-translations-page', $url . '/translations-page.js', array('gp-common'), '20150430');
$scripts->add('mass-create-sets-page', $url . '/mass-create-sets-page.js', array('gp-common'), '20150430');
}
示例8: __construct
public function __construct($scripts = '')
{
$this->old_scripts = empty($scripts) || !$scripts instanceof WP_Scripts ? new WP_Scripts() : $scripts;
// Unset all the object properties except our private copy of the
// scripts object. We have to unset everything so that the overload
// methods talk to $this->old_scripts->whatever instead of $this->whatever.
foreach (array_keys(get_object_vars($this)) as $key) {
if ('old_scripts' === $key) {
continue;
}
unset($this->{$key});
}
parent::__construct();
}
示例9: test_jquery_in_footer
/**
* Test placing of jQuery in footer.
*
* @ticket 25247
*/
function test_jquery_in_footer()
{
$scripts = new WP_Scripts();
$scripts->add('jquery', false, array('jquery-core', 'jquery-migrate'));
$scripts->add('jquery-core', '/jquery.js', array());
$scripts->add('jquery-migrate', '/jquery-migrate.js', array());
$scripts->enqueue('jquery');
$jquery = $scripts->query('jquery');
$jquery->add_data('group', 1);
foreach ($jquery->deps as $dep) {
$scripts->add_data($dep, 'group', 1);
}
$this->expectOutputRegex('/^(?:<script[^>]+><\\/script>\\n){2}$/');
$scripts->do_items(false, 0);
$this->assertNotContains('jquery', $scripts->done);
$this->assertNotContains('jquery-core', $scripts->done, 'jquery-core should be in footer but is in head');
$this->assertNotContains('jquery-migrate', $scripts->done, 'jquery-migrate should be in footer but is in head');
$scripts->do_items(false, 1);
$this->assertContains('jquery', $scripts->done);
$this->assertContains('jquery-core', $scripts->done, 'jquery-core in footer');
$this->assertContains('jquery-migrate', $scripts->done, 'jquery-migrate in footer');
}
示例10: print_head_scripts
/**
* Prints the script queue in the HTML head on admin pages.
*
* Postpones the scripts that were queued for the footer.
* print_footer_scripts() is called in the footer to print these scripts.
*
* @since 2.8.0
*
* @see wp_print_scripts()
*/
function print_head_scripts()
{
global $wp_scripts, $concatenate_scripts;
if (!did_action('wp_print_scripts')) {
/** This action is documented in wp-includes/functions.wp-scripts.php */
do_action('wp_print_scripts');
}
if (!is_a($wp_scripts, 'WP_Scripts')) {
$wp_scripts = new WP_Scripts();
}
script_concat_settings();
$wp_scripts->do_concat = $concatenate_scripts;
$wp_scripts->do_head_items();
/**
* Filter whether to print the head scripts.
*
* @since 2.8.0
*
* @param bool $print Whether to print the head scripts. Default true.
*/
if (apply_filters('print_head_scripts', true)) {
_print_scripts();
}
$wp_scripts->reset();
return $wp_scripts->done;
}
示例11: wp_script_is
/**
* Check whether script has been added to WordPress Scripts.
*
* By default, checks if the script has been enqueued. You can also
* pass 'registered' to $list, to see if the script is registered,
* and you can check processing statuses with 'to_do' and 'done'.
*
* @since WP unknown; BP unknown
*
* @param string $handle Name of the script.
* @param string $list Optional. Defaults to 'enqueued'. Values are
* 'registered', 'enqueued' (or 'queue'), 'to_do', and 'done'.
* @return bool Whether script is in the list.
*/
function wp_script_is($handle, $list = 'enqueued')
{
global $wp_scripts;
if (!is_a($wp_scripts, 'WP_Scripts')) {
if (!did_action('init')) {
_doing_it_wrong(__FUNCTION__, sprintf(__('Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.'), '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>'), '3.3');
}
$wp_scripts = new WP_Scripts();
}
return (bool) $wp_scripts->query($handle, $list);
}
示例12: 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));
}
}
}
示例13: filter_wp_default_scripts
/**
* Filter wp_default_scripts
*
* Removes an extra jQuery Script
*
* @since 5.0.0
*
* @param \WP_Scripts $scripts The Default WordPress scripts.
*
* @return void
*/
function filter_wp_default_scripts($scripts)
{
if (!is_admin()) {
$scripts->remove('jquery');
$scripts->add('jquery', false, array('jquery-core'), '1.12.3');
}
}
示例14: register_ui_scripts
/**
* Register additional jQuery UI scripts
*
* Never call this manually unless you really know what you are doing!
*
* @internal
*/
public function register_ui_scripts()
{
global $wp_scripts;
if (!$wp_scripts instanceof WP_Scripts) {
$wp_scripts = new WP_Scripts();
}
$deps_c = array('jquery-ui-core');
$deps_cw = array_merge($deps_c, array('jquery-ui-widget'));
$deps_cwm = array_merge($deps_cw, array('jquery-ui-mouse'));
$deps_cwp = array_merge($deps_cw, array('jquery-ui-position'));
$jui = array('jquery-ui-accordion' => array('src' => 'jquery.ui.accordion.min.js', 'deps' => $deps_cw), 'jquery-ui-autocomplete' => array('src' => 'jquery.ui.autocomplete.min.js', 'deps' => $deps_cwp), 'jquery-ui-datepicker' => array('src' => 'jquery.ui.datepicker.min.js', 'deps' => $deps_c), 'jquery-ui-progressbar' => array('src' => 'jquery.ui.progressbar.min.js', 'deps' => $deps_cw), 'jquery-ui-slider' => array('src' => 'jquery.ui.slider.min.js', 'deps' => $deps_cwm));
// register more scripts
foreach ($jui as $handle => $cfg) {
// make sure not registered already
if (!$wp_scripts->query($handle)) {
// register it
$wp_scripts->add($handle, ICE_JS_URL . '/' . $cfg['src'], $cfg['deps'], '1.8.12');
// put in footer group
$wp_scripts->add_data($handle, 'group', 1);
}
}
}
示例15: register_scripts
/**
* Register scripts.
*
* @param \WP_Scripts $wp_scripts Instance of \WP_Scripts.
* @action wp_default_scripts
*/
public function register_scripts(\WP_Scripts $wp_scripts)
{
$handle = 'customize-rest-resources-namespace';
$src = $this->dir_url . 'js/namespace.js';
$deps = array();
$wp_scripts->add($handle, $src, $deps, $this->version);
$handle = 'customize-rest-resources-manager';
$src = $this->dir_url . 'js/rest-resources-manager.js';
$deps = array('customize-rest-resources-namespace', 'wp-api', 'backbone');
$wp_scripts->add($handle, $src, $deps, $this->version);
$handle = 'customize-rest-resources-pane-manager';
$src = $this->dir_url . 'js/rest-resources-pane-manager.js';
$deps = array('customize-rest-resources-namespace', 'customize-rest-resources-manager', 'customize-controls', 'customize-rest-resources-section', 'customize-rest-resource-control');
$wp_scripts->add($handle, $src, $deps, $this->version);
$handle = 'customize-rest-resources-preview-manager';
$src = $this->dir_url . 'js/rest-resources-preview-manager.js';
$deps = array('customize-rest-resources-namespace', 'customize-rest-resources-manager', 'customize-preview');
$wp_scripts->add($handle, $src, $deps, $this->version);
$handle = 'customize-rest-resources-section';
$src = $this->dir_url . 'js/rest-resources-section.js';
$deps = array('customize-rest-resources-namespace', 'customize-controls');
$wp_scripts->add($handle, $src, $deps, $this->version);
$handle = 'customize-rest-resource-control';
$src = $this->dir_url . 'js/rest-resource-control.js';
$deps = array('customize-rest-resources-namespace', 'customize-controls');
$wp_scripts->add($handle, $src, $deps, $this->version);
}