本文整理汇总了PHP中wp_scripts函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_scripts函数的具体用法?PHP wp_scripts怎么用?PHP wp_scripts使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_scripts函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wp_user_profiles_admin_enqueue_scripts
/**
* Enqueue admin scripts
*
* @since 0.1.0
*/
function wp_user_profiles_admin_enqueue_scripts($hook = '')
{
// Bail if not the correct page
if (!is_user_admin() && $GLOBALS['pagenow'] !== wp_user_profiles_get_file()) {
return;
}
// Get hooknames
$sections = wp_user_profiles_get_section_hooknames();
// Maybe manipulate the hook based on dashboard
_wp_user_profiles_walk_section_hooknames($hook, '');
// Bail if not a user profile section
if (!in_array($hook, $sections, true)) {
return;
}
// Enqueue core scripts
wp_enqueue_script('jquery-ui-sortable');
wp_enqueue_script('postbox');
wp_enqueue_script('dashboard');
// Set location & version for scripts & styles
$src = wp_user_profiles_get_plugin_url();
$ver = wp_user_profiles_get_asset_version();
// Styles
wp_enqueue_style('wp-user-profiles', $src . 'assets/css/user-profiles.css', array('dashboard'), $ver);
// Ugh... this is terrible
wp_enqueue_script('user-profile', $src . 'assets/css/user-profiles.css', array('jquery', 'password-strength-meter', 'wp-util'), $ver);
wp_scripts()->registered['user-profile']->src = $src . 'assets/js/user-profiles.js';
}
示例2: admin_register_scripts
/**
* Register scripts and styles
*/
public static function admin_register_scripts()
{
$url = RWMB_CSS_URL . 'jqueryui';
wp_register_style('jquery-ui-core', "{$url}/jquery.ui.core.css", array(), '1.8.17');
wp_register_style('jquery-ui-theme', "{$url}/jquery.ui.theme.css", array(), '1.8.17');
wp_register_style('wp-datepicker', RWMB_CSS_URL . 'datepicker.css', array('jquery-ui-core', 'jquery-ui-theme'), '1.8.17');
wp_register_style('jquery-ui-datepicker', "{$url}/jquery.ui.datepicker.css", array('wp-datepicker'), '1.8.17');
wp_register_style('jquery-ui-slider', "{$url}/jquery.ui.slider.css", array('jquery-ui-core', 'jquery-ui-theme'), '1.8.17');
wp_register_style('jquery-ui-timepicker', "{$url}/jquery-ui-timepicker-addon.min.css", array('jquery-ui-datepicker', 'jquery-ui-slider', 'wp-datepicker'), '1.5.0');
$url = RWMB_JS_URL . 'jqueryui';
wp_register_script('jquery-ui-datepicker-i18n', "{$url}/jquery-ui-i18n.min.js", array('jquery-ui-datepicker'), '1.11.4', true);
wp_register_script('jquery-ui-timepicker', "{$url}/jquery-ui-timepicker-addon.min.js", array('jquery-ui-datepicker', 'jquery-ui-slider'), '1.5.0', true);
wp_register_script('jquery-ui-timepicker-i18n', "{$url}/jquery-ui-timepicker-addon-i18n.min.js", array('jquery-ui-timepicker'), '1.5.0', true);
wp_register_script('rwmb-datetime', RWMB_JS_URL . 'datetime.js', array('jquery-ui-datepicker-i18n', 'jquery-ui-timepicker-i18n'), RWMB_VER, true);
wp_register_script('rwmb-date', RWMB_JS_URL . 'date.js', array('jquery-ui-datepicker-i18n', 'jquery-ui-timepicker-i18n'), RWMB_VER, true);
wp_register_script('rwmb-time', RWMB_JS_URL . 'time.js', array('jquery-ui-timepicker-i18n'), RWMB_VER, true);
/**
* Add data to scripts. Prevent loading localized string twice.
* @link https://github.com/rilwis/meta-box/issues/850
*/
$wp_scripts = wp_scripts();
$handles = array('datetime', 'date', 'time');
$locale = str_replace('_', '-', get_locale());
$locale_short = substr($locale, 0, 2);
$data = array('locale' => $locale, 'localeShort' => $locale_short);
foreach ($handles as $handle) {
if (!$wp_scripts->get_data("rwmb-{$handle}", 'data')) {
wp_localize_script("rwmb-{$handle}", 'RWMB_' . ucfirst($handle), $data);
}
}
}
示例3: json_api_client_js
/**
* Plugin Name: WP-API Client JS
*/
function json_api_client_js()
{
$scripts = wp_scripts();
$src = plugins_url('build/js/wp-api.js', __FILE__);
if (isset($scripts->registered['wp-api'])) {
$scripts->registered['wp-api']->src = $src;
} else {
wp_register_script('wp-api', $src, array('jquery', 'underscore', 'backbone'), '1.0', true);
}
/**
* @var \WP_REST_Server $wp_rest_server
*/
global $wp_rest_server;
if (empty($wp_rest_server)) {
/** This filter is documented in wp-includes/rest-api.php */
$wp_rest_server_class = apply_filters('wp_rest_server_class', 'WP_REST_Server');
$wp_rest_server = new $wp_rest_server_class();
/** This filter is documented in wp-includes/rest-api.php */
do_action('rest_api_init', $wp_rest_server);
}
$schema_request = new WP_REST_Request('GET', '/wp/v2');
$schema_response = $wp_rest_server->dispatch($schema_request);
$schema = null;
if (!$schema_response->is_error()) {
$schema = $schema_response->get_data();
}
$settings = array('root' => esc_url_raw(get_rest_url()), 'nonce' => wp_create_nonce('wp_rest'), 'versionString' => 'wp/v2/', 'schema' => $schema);
wp_localize_script('wp-api', 'wpApiSettings', $settings);
}
示例4: register_jquery
/**
* Load jQuery from jQuery's CDN with a local fallback
*
* You can enable/disable this feature in functions.php (or lib/setup.php if you're using Sage):
* add_theme_support('soil-jquery-cdn');
*/
function register_jquery()
{
$jquery_version = wp_scripts()->registered['jquery']->ver;
wp_deregister_script('jquery');
wp_register_script('jquery', 'https://code.jquery.com/jquery-' . $jquery_version . '.min.js', [], null, true);
add_filter('script_loader_src', __NAMESPACE__ . '\\jquery_local_fallback', 10, 2);
}
示例5: test_register_scripts
/**
* @see Plugin::register_scripts()
*/
function test_register_scripts()
{
$wp_scripts = wp_scripts();
$handles = array('customize-widgets-plus-base', 'customize-widgets-plus-widget-number-incrementing', 'customize-widgets-plus-widget-number-incrementing-customizer');
foreach ($handles as $handle) {
$this->assertArrayHasKey($handle, $wp_scripts->registered);
}
}
示例6: bsg_jquery_cdn
function bsg_jquery_cdn()
{
$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
$jquery_version = wp_scripts()->registered['jquery']->ver;
wp_deregister_script('jquery');
wp_register_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/' . $jquery_version . "/jquery{$suffix}.js", array(), null, true);
add_filter('script_loader_src', 'bsg_jquery_local_fallback', 10, 2);
}
示例7: localize_script
/**
* Localize scripts with prevention of loading localized data twice.
*
* @link https://github.com/rilwis/meta-box/issues/850
*
* @param string $handle Script handle.
* @param string $name Object name.
* @param mixed $data Localized data.
*/
public static function localize_script( $handle, $name, $data ) {
/*
* Check with function_exists to make it work in WordPress 4.1
* @link https://github.com/rilwis/meta-box/issues/1009
*/
if ( ! function_exists( 'wp_scripts' ) || ! wp_scripts()->get_data( $handle, 'data' ) ) {
wp_localize_script( $handle, $name, $data );
}
}
示例8: get_scripts
public function get_scripts()
{
$wp_scripts = wp_scripts();
$this->scripts = array();
add_filter('script_loader_tag', array($this, 'catch_script_tags'), 99, 3);
ob_start();
$wp_scripts->do_items($this->script_handles);
ob_get_clean();
return $this->scripts;
}
示例9: boot_gen_move_js_to_footer
function boot_gen_move_js_to_footer()
{
$scripts = wp_scripts();
foreach ($scripts->registered as $script) {
if ('html5shiv' == $script->handle || 'respond' == $script->handle) {
wp_script_add_data($script->handle, 'group', 0);
} else {
wp_script_add_data($script->handle, 'group', 1);
}
}
}
示例10: load
public function load(ActiveTheme $theme)
{
if (!is_admin()) {
$scripts = wp_scripts();
// Add fallback to local jQuery
if (isset($scripts->registered['jquery-core'])) {
$this->localUrl = get_site_url(null, $scripts->registered['jquery-core']->src);
add_action('wp_footer', array($this, 'renderFallbackScript'), 1, -999);
}
add_action('wp_enqueue_scripts', array($this, 'enqueue'), 9999);
}
}
示例11: localize_script
/**
* ELocalize scripts
*/
public static function localize_script($handle, $name, $data)
{
/**
* Prevent loading localized string twice.
*
* @link https://github.com/rilwis/meta-box/issues/850
*/
$wp_scripts = wp_scripts();
if (!$wp_scripts->get_data($handle, 'data')) {
wp_localize_script($handle, $name, $data);
}
}
示例12: admin_enqueue_scripts
/**
* Enqueue scripts and styles
*/
public static function admin_enqueue_scripts()
{
wp_enqueue_style('rwmb-file', RWMB_CSS_URL . 'file.css', array(), RWMB_VER);
wp_enqueue_script('rwmb-file', RWMB_JS_URL . 'file.js', array('jquery'), RWMB_VER, true);
/**
* Prevent loading localized string twice.
* @link https://github.com/rilwis/meta-box/issues/850
*/
$wp_scripts = wp_scripts();
if (!$wp_scripts->get_data('rwmb-file', 'data')) {
wp_localize_script('rwmb-file', 'rwmbFile', array('maxFileUploadsSingle' => __('You may only upload maximum %d file', 'meta-box'), 'maxFileUploadsPlural' => __('You may only upload maximum %d files', 'meta-box')));
}
}
示例13: enqueueInclude
public function enqueueInclude(FrontInclude $script)
{
if (defined('WP_DEBUG') && WP_DEBUG) {
$dependencies = $script->getDependency();
$scripts = wp_scripts()->registered;
foreach ($dependencies as $dependency) {
if (!isset($scripts[$dependency])) {
trigger_error(sprintf('Dependency failed for %s, No script with handle %s is registered', $script->getHandle(), $dependency), E_USER_WARNING);
}
}
}
wp_enqueue_script($script->getHandle(), $script->getSrc(), $script->getDependency(), $script->getVersion(), $script->loadInFooter());
}
示例14: admin_enqueue_scripts
/**
* Enqueue scripts and styles
*
* @return void
*/
static function admin_enqueue_scripts()
{
wp_enqueue_media();
wp_enqueue_script('rwmb-file-input', RWMB_JS_URL . 'file-input.js', array('jquery'), RWMB_VER, true);
/**
* Prevent loading localized string twice.
* @link https://github.com/rilwis/meta-box/issues/850
*/
$wp_scripts = wp_scripts();
if (!$wp_scripts->get_data('rwmb-file-input', 'data')) {
wp_localize_script('rwmb-file-input', 'rwmbFileInput', array('frameTitle' => __('Select File', 'meta-box')));
}
}
示例15: admin_enqueue_scripts
/**
* Enqueue scripts and styles.
*/
static function admin_enqueue_scripts()
{
wp_enqueue_style('rwmb-autocomplete', RWMB_CSS_URL . 'autocomplete.css', array('wp-admin'), RWMB_VER);
wp_enqueue_script('rwmb-autocomplete', RWMB_JS_URL . 'autocomplete.js', array('jquery-ui-autocomplete'), RWMB_VER, true);
/**
* Prevent loading localized string twice.
* @link https://github.com/rilwis/meta-box/issues/850
*/
$wp_scripts = wp_scripts();
if (!$wp_scripts->get_data('rwmb-autocomplete', 'data')) {
wp_localize_script('rwmb-autocomplete', 'RWMB_Autocomplete', array('delete' => __('Delete', 'meta-box')));
}
}