本文整理汇总了PHP中WP_Scripts::add_data方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Scripts::add_data方法的具体用法?PHP WP_Scripts::add_data怎么用?PHP WP_Scripts::add_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_Scripts
的用法示例。
在下文中一共展示了WP_Scripts::add_data方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
/**
* 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: array
/**
* 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');
}
示例3: wp_default_scripts
//.........这里部分代码省略.........
$scripts->add('jquery-serialize-object', "/wp-includes/js/jquery/jquery.serialize-object.js", array('jquery'), '0.2', 1);
$scripts->add('jquery-hotkeys', "/wp-includes/js/jquery/jquery.hotkeys{$suffix}.js", array('jquery'), '0.0.2m', 1);
$scripts->add('jquery-table-hotkeys', "/wp-includes/js/jquery/jquery.table-hotkeys{$suffix}.js", array('jquery', 'jquery-hotkeys'), false, 1);
$scripts->add('jquery-touch-punch', "/wp-includes/js/jquery/jquery.ui.touch-punch.js", array('jquery-ui-widget', 'jquery-ui-mouse'), '0.2.2', 1);
// Masonry v2 depended on jQuery. v3 does not. The older jquery-masonry handle is a shiv.
// It sets jQuery as a dependency, as the theme may have been implicitly loading it this way.
$scripts->add('masonry', "/wp-includes/js/masonry.min.js", array(), '3.1.2', 1);
$scripts->add('jquery-masonry', "/wp-includes/js/jquery/jquery.masonry{$dev_suffix}.js", array('jquery', 'masonry'), '3.1.2', 1);
$scripts->add('thickbox', "/wp-includes/js/thickbox/thickbox.js", array('jquery'), '3.1-20121105', 1);
did_action('init') && $scripts->localize('thickbox', 'thickboxL10n', array('next' => __('Next >'), 'prev' => __('< Prev'), 'image' => __('Image'), 'of' => __('of'), 'close' => __('Close'), 'noiframes' => __('This feature requires inline frames. You have iframes disabled or your browser does not support them.'), 'loadingAnimation' => includes_url('js/thickbox/loadingAnimation.gif')));
$scripts->add('jcrop', "/wp-includes/js/jcrop/jquery.Jcrop.min.js", array('jquery'), '0.9.12');
$scripts->add('swfobject', "/wp-includes/js/swfobject.js", array(), '2.2-20120417');
// error message for both plupload and swfupload
$uploader_l10n = array('queue_limit_exceeded' => __('You have attempted to queue too many files.'), 'file_exceeds_size_limit' => __('%s exceeds the maximum upload size for this site.'), 'zero_byte_file' => __('This file is empty. Please try another.'), 'invalid_filetype' => __('This file type is not allowed. Please try another.'), 'not_an_image' => __('This file is not an image. Please try another.'), 'image_memory_exceeded' => __('Memory exceeded. Please try another smaller file.'), 'image_dimensions_exceeded' => __('This is larger than the maximum size. Please try another.'), 'default_error' => __('An error occurred in the upload. Please try again later.'), 'missing_upload_url' => __('There was a configuration error. Please contact the server administrator.'), 'upload_limit_exceeded' => __('You may only upload 1 file.'), 'http_error' => __('HTTP error.'), 'upload_failed' => __('Upload failed.'), 'big_upload_failed' => __('Please try uploading this file with the %1$sbrowser uploader%2$s.'), 'big_upload_queued' => __('%s exceeds the maximum upload size for the multi-file uploader when used in your browser.'), 'io_error' => __('IO error.'), 'security_error' => __('Security error.'), 'file_cancelled' => __('File canceled.'), 'upload_stopped' => __('Upload stopped.'), 'dismiss' => __('Dismiss'), 'crunching' => __('Crunching…'), 'deleted' => __('moved to the trash.'), 'error_uploading' => __('“%s” has failed to upload.'));
$scripts->add('plupload', '/wp-includes/js/plupload/plupload.full.min.js', array(), '2.1.1');
// Back compat handles:
foreach (array('all', 'html5', 'flash', 'silverlight', 'html4') as $handle) {
$scripts->add("plupload-{$handle}", false, array('plupload'), '2.1.1');
}
$scripts->add('plupload-handlers', "/wp-includes/js/plupload/handlers{$suffix}.js", array('plupload', 'jquery'));
did_action('init') && $scripts->localize('plupload-handlers', 'pluploadL10n', $uploader_l10n);
$scripts->add('wp-plupload', "/wp-includes/js/plupload/wp-plupload{$suffix}.js", array('plupload', 'jquery', 'json2', 'media-models'), false, 1);
did_action('init') && $scripts->localize('wp-plupload', 'pluploadL10n', $uploader_l10n);
// keep 'swfupload' for back-compat.
$scripts->add('swfupload', '/wp-includes/js/swfupload/swfupload.js', array(), '2201-20110113');
$scripts->add('swfupload-swfobject', '/wp-includes/js/swfupload/plugins/swfupload.swfobject.js', array('swfupload', 'swfobject'), '2201a');
$scripts->add('swfupload-queue', '/wp-includes/js/swfupload/plugins/swfupload.queue.js', array('swfupload'), '2201');
$scripts->add('swfupload-speed', '/wp-includes/js/swfupload/plugins/swfupload.speed.js', array('swfupload'), '2201');
$scripts->add('swfupload-all', false, array('swfupload', 'swfupload-swfobject', 'swfupload-queue'), '2201');
$scripts->add('swfupload-handlers', "/wp-includes/js/swfupload/handlers{$suffix}.js", array('swfupload-all', 'jquery'), '2201-20110524');
did_action('init') && $scripts->localize('swfupload-handlers', 'swfuploadL10n', $uploader_l10n);
$scripts->add('comment-reply', "/wp-includes/js/comment-reply{$suffix}.js", array(), false, 1);
$scripts->add('json2', "/wp-includes/js/json2{$suffix}.js", array(), '2011-02-23');
did_action('init') && $scripts->add_data('json2', 'conditional', 'lt IE 8');
$scripts->add('underscore', "/wp-includes/js/underscore{$dev_suffix}.js", array(), '1.6.0', 1);
$scripts->add('backbone', "/wp-includes/js/backbone{$dev_suffix}.js", array('underscore', 'jquery'), '1.1.2', 1);
$scripts->add('wp-util', "/wp-includes/js/wp-util{$suffix}.js", array('underscore', 'jquery'), false, 1);
did_action('init') && $scripts->localize('wp-util', '_wpUtilSettings', array('ajax' => array('url' => admin_url('admin-ajax.php', 'relative'))));
$scripts->add('wp-backbone', "/wp-includes/js/wp-backbone{$suffix}.js", array('backbone', 'wp-util'), false, 1);
$scripts->add('revisions', "/wp-admin/js/revisions{$suffix}.js", array('wp-backbone', 'jquery-ui-slider', 'hoverIntent'), false, 1);
$scripts->add('imgareaselect', "/wp-includes/js/imgareaselect/jquery.imgareaselect{$suffix}.js", array('jquery'), false, 1);
$scripts->add('mediaelement', "/wp-includes/js/mediaelement/mediaelement-and-player.min.js", array('jquery'), '2.17.0', 1);
did_action('init') && $scripts->localize('mediaelement', 'mejsL10n', array('language' => get_bloginfo('language'), 'strings' => array('Close' => __('Close'), 'Fullscreen' => __('Fullscreen'), 'Download File' => __('Download File'), 'Download Video' => __('Download Video'), 'Play/Pause' => __('Play/Pause'), 'Mute Toggle' => __('Mute Toggle'), 'None' => __('None'), 'Turn off Fullscreen' => __('Turn off Fullscreen'), 'Go Fullscreen' => __('Go Fullscreen'), 'Unmute' => __('Unmute'), 'Mute' => __('Mute'), 'Captions/Subtitles' => __('Captions/Subtitles'))));
$scripts->add('wp-mediaelement', "/wp-includes/js/mediaelement/wp-mediaelement.js", array('mediaelement'), false, 1);
did_action('init') && $scripts->localize('mediaelement', '_wpmejsSettings', array('pluginPath' => includes_url('js/mediaelement/', 'relative')));
$scripts->add('froogaloop', "/wp-includes/js/mediaelement/froogaloop.min.js", array(), '2.0');
$scripts->add('wp-playlist', "/wp-includes/js/mediaelement/wp-playlist.js", array('wp-util', 'backbone', 'mediaelement'), false, 1);
$scripts->add('zxcvbn-async', "/wp-includes/js/zxcvbn-async{$suffix}.js", array(), '1.0');
did_action('init') && $scripts->localize('zxcvbn-async', '_zxcvbnSettings', array('src' => empty($guessed_url) ? includes_url('/js/zxcvbn.min.js') : $scripts->base_url . '/wp-includes/js/zxcvbn.min.js'));
$scripts->add('password-strength-meter', "/wp-admin/js/password-strength-meter{$suffix}.js", array('jquery', 'zxcvbn-async'), false, 1);
did_action('init') && $scripts->localize('password-strength-meter', 'pwsL10n', array('short' => _x('Very weak', 'password strength'), 'bad' => _x('Weak', 'password strength'), 'good' => _x('Medium', 'password strength'), 'strong' => _x('Strong', 'password strength'), 'mismatch' => _x('Mismatch', 'password mismatch')));
$scripts->add('user-profile', "/wp-admin/js/user-profile{$suffix}.js", array('jquery', 'password-strength-meter', 'wp-util'), false, 1);
did_action('init') && $scripts->localize('user-profile', 'userProfileL10n', array('show' => __('Show'), 'hide' => __('Hide'), 'ariaShow' => esc_attr__('Show password'), 'ariaHide' => esc_attr__('Hide password')));
$scripts->add('language-chooser', "/wp-admin/js/language-chooser{$suffix}.js", array('jquery'), false, 1);
$scripts->add('user-suggest', "/wp-admin/js/user-suggest{$suffix}.js", array('jquery-ui-autocomplete'), false, 1);
$scripts->add('admin-bar', "/wp-includes/js/admin-bar{$suffix}.js", array(), false, 1);
$scripts->add('wplink', "/wp-includes/js/wplink{$suffix}.js", array('jquery'), false, 1);
did_action('init') && $scripts->localize('wplink', 'wpLinkL10n', array('title' => __('Insert/edit link'), 'update' => __('Update'), 'save' => __('Add Link'), 'noTitle' => __('(no title)'), 'noMatchesFound' => __('No results found.')));
$scripts->add('wpdialogs', "/wp-includes/js/wpdialog{$suffix}.js", array('jquery-ui-dialog'), false, 1);
$scripts->add('word-count', "/wp-admin/js/word-count{$suffix}.js", array(), false, 1);
did_action('init') && $scripts->localize('word-count', 'wordCountL10n', array('type' => _x('words', 'word count: words, characters or all?'), 'shortcodes' => !empty($GLOBALS['shortcode_tags']) ? array_keys($GLOBALS['shortcode_tags']) : array()));
$scripts->add('media-upload', "/wp-admin/js/media-upload{$suffix}.js", array('thickbox', 'shortcode'), false, 1);
$scripts->add('hoverIntent', "/wp-includes/js/hoverIntent{$suffix}.js", array('jquery'), '1.8.1', 1);
$scripts->add('customize-base', "/wp-includes/js/customize-base{$suffix}.js", array('jquery', 'json2', 'underscore'), false, 1);
$scripts->add('customize-loader', "/wp-includes/js/customize-loader{$suffix}.js", array('customize-base'), false, 1);
$scripts->add('customize-preview', "/wp-includes/js/customize-preview{$suffix}.js", array('customize-base'), false, 1);
示例4: sp_plugin_register_script
function sp_plugin_register_script($handle, $src, $deps = array(), $ver = false, $in_footer = false)
{
global $sp_plugin_scripts;
if (!is_a($sp_plugin_scripts, 'WP_Scripts')) {
$sp_plugin_scripts = new WP_Scripts();
}
$sp_plugin_scripts->add($handle, $src, $deps, $ver);
if ($in_footer) {
$sp_plugin_scripts->add_data($handle, 'group', 1);
}
}
示例5: wp_enqueue_script
/**
* Enqueues script.
*
* Registers the script if src provided (does NOT overwrite) and enqueues.
*
* @since r16
* @see wp_register_script() For parameter information.
*/
function wp_enqueue_script($handle, $src = false, $deps = array(), $ver = false, $in_footer = false)
{
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();
}
if ($src) {
$_handle = explode('?', $handle);
$wp_scripts->add($_handle[0], $src, $deps, $ver);
if ($in_footer) {
$wp_scripts->add_data($_handle[0], 'group', 1);
}
}
$wp_scripts->enqueue($handle);
}
示例6: wp_enqueue_script
/**
* Enqueues script.
*
* Registers the script if src provided (does NOT overwrite) and enqueues.
*
* @since r16
* @see wp_register_script() For parameter information.
*/
function wp_enqueue_script($handle, $src = false, $deps = array(), $ver = false, $in_footer = 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);
if ($in_footer) {
$wp_scripts->add_data($_handle[0], 'group', 1);
}
}
$wp_scripts->enqueue($handle);
}
示例7: 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);
}
}
}
示例8: wp_default_scripts
//.........这里部分代码省略.........
'security_error' => __('Security error.'),
'file_cancelled' => __('File canceled.'),
'upload_stopped' => __('Upload stopped.'),
'dismiss' => __('Dismiss'),
'crunching' => __('Crunching…'),
'deleted' => __('moved to the trash.'),
'error_uploading' => __('“%s” has failed to upload.')
);
$scripts->add( 'plupload', '/wp-includes/js/plupload/plupload.full.min.js', array(), '2.1.8' );
// Back compat handles:
foreach ( array( 'all', 'html5', 'flash', 'silverlight', 'html4' ) as $handle ) {
$scripts->add( "plupload-$handle", false, array( 'plupload' ), '2.1.1' );
}
$scripts->add( 'plupload-handlers', "/wp-includes/js/plupload/handlers$suffix.js", array( 'plupload', 'jquery' ) );
did_action( 'init' ) && $scripts->localize( 'plupload-handlers', 'pluploadL10n', $uploader_l10n );
$scripts->add( 'wp-plupload', "/wp-includes/js/plupload/wp-plupload$suffix.js", array( 'plupload', 'jquery', 'json2', 'media-models' ), false, 1 );
did_action( 'init' ) && $scripts->localize( 'wp-plupload', 'pluploadL10n', $uploader_l10n );
// keep 'swfupload' for back-compat.
$scripts->add( 'swfupload', '/wp-includes/js/swfupload/swfupload.js', array(), '2201-20110113');
$scripts->add( 'swfupload-swfobject', '/wp-includes/js/swfupload/plugins/swfupload.swfobject.js', array('swfupload', 'swfobject'), '2201a');
$scripts->add( 'swfupload-queue', '/wp-includes/js/swfupload/plugins/swfupload.queue.js', array('swfupload'), '2201');
$scripts->add( 'swfupload-speed', '/wp-includes/js/swfupload/plugins/swfupload.speed.js', array('swfupload'), '2201');
$scripts->add( 'swfupload-all', false, array('swfupload', 'swfupload-swfobject', 'swfupload-queue'), '2201');
$scripts->add( 'swfupload-handlers', "/wp-includes/js/swfupload/handlers$suffix.js", array('swfupload-all', 'jquery'), '2201-20110524');
did_action( 'init' ) && $scripts->localize( 'swfupload-handlers', 'swfuploadL10n', $uploader_l10n );
$scripts->add( 'comment-reply', "/wp-includes/js/comment-reply$suffix.js", array(), false, 1 );
$scripts->add( 'json2', "/wp-includes/js/json2$suffix.js", array(), '2015-05-03' );
did_action( 'init' ) && $scripts->add_data( 'json2', 'conditional', 'lt IE 8' );
$scripts->add( 'underscore', "/wp-includes/js/underscore$dev_suffix.js", array(), '1.8.3', 1 );
$scripts->add( 'backbone', "/wp-includes/js/backbone$dev_suffix.js", array( 'underscore','jquery' ), '1.2.3', 1 );
$scripts->add( 'wp-util', "/wp-includes/js/wp-util$suffix.js", array('underscore', 'jquery'), false, 1 );
did_action( 'init' ) && $scripts->localize( 'wp-util', '_wpUtilSettings', array(
'ajax' => array(
'url' => admin_url( 'admin-ajax.php', 'relative' ),
),
) );
$scripts->add( 'wp-backbone', "/wp-includes/js/wp-backbone$suffix.js", array('backbone', 'wp-util'), false, 1 );
$scripts->add( 'revisions', "/wp-admin/js/revisions$suffix.js", array( 'wp-backbone', 'jquery-ui-slider', 'hoverIntent' ), false, 1 );
$scripts->add( 'imgareaselect', "/wp-includes/js/imgareaselect/jquery.imgareaselect$suffix.js", array('jquery'), false, 1 );
$scripts->add( 'mediaelement', "/wp-includes/js/mediaelement/mediaelement-and-player.min.js", array('jquery'), '2.22.0', 1 );
did_action( 'init' ) && $scripts->localize( 'mediaelement', 'mejsL10n', array(
'language' => get_bloginfo( 'language' ),
'strings' => array(
'Close' => __( 'Close' ),
'Fullscreen' => __( 'Fullscreen' ),
'Turn off Fullscreen' => __( 'Turn off Fullscreen' ),
'Go Fullscreen' => __( 'Go Fullscreen' ),
'Download File' => __( 'Download File' ),
'Download Video' => __( 'Download Video' ),
'Play' => __( 'Play' ),
'Pause' => __( 'Pause' ),
'Captions/Subtitles' => __( 'Captions/Subtitles' ),
'None' => __( 'None', 'no captions/subtitles' ),
'Time Slider' => __( 'Time Slider' ),
示例9: 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));
}
}
}