/** * 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'; }
/** * 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); } } }
/** * 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); }
/** * 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); }
/** * @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); } }
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); }
/** * 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 ); } }
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; }
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); } } }
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); } }
/** * 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); } }
/** * 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'))); } }
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()); }
/** * 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'))); } }
/** * 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'))); } }
/** * Enqueue scripts for validation. */ public function scripts() { wp_enqueue_script('jquery-validate', RWMB_JS_URL . 'jquery.validate.min.js', array('jquery'), RWMB_VER, true); wp_enqueue_script('rwmb-validate', RWMB_JS_URL . 'validate.js', array('jquery-validate'), 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-validate', 'data')) { wp_localize_script('rwmb-validate', 'rwmbValidate', array('summaryMessage' => __('Please correct the errors highlighted below and try again.', 'meta-box'))); } }
/** * Enqueue scripts and styles */ public static function admin_enqueue_scripts() { wp_enqueue_media(); wp_enqueue_style('rwmb-media', RWMB_CSS_URL . 'media.css', array(), RWMB_VER); wp_enqueue_script('rwmb-media', RWMB_JS_URL . 'media.js', array('jquery-ui-sortable', 'underscore', 'backbone', 'media-grid'), 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-media', 'data')) { wp_localize_script('rwmb-media', 'i18nRwmbMedia', array('add' => apply_filters('rwmb_media_add_string', _x('+ Add Media', 'media', 'meta-box')), 'single' => apply_filters('rwmb_media_single_files_string', _x(' file', 'media', 'meta-box')), 'multiple' => apply_filters('rwmb_media_multiple_files_string', _x(' files', 'media', 'meta-box')), 'remove' => apply_filters('rwmb_media_remove_string', _x('Remove', 'media', 'meta-box')), 'edit' => apply_filters('rwmb_media_edit_string', _x('Edit', 'media', 'meta-box')), 'view' => apply_filters('rwmb_media_view_string', _x('View', 'media', 'meta-box')), 'noTitle' => _x('No Title', 'media', 'meta-box'), 'loadingUrl' => RWMB_URL . 'img/loader.gif', 'extensions' => self::get_mime_extensions(), 'select' => _x('Select Files', 'media', 'meta-box'), 'uploadInstructions' => _x('Drop files here to upload', 'media', 'meta-box'))); } }
/** * 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-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); /** * Localization * Use 1 minified JS file for timepicker which contains all languages for simplicity (in version < 4.4.2 we use separated JS files). * The language is set in Javascript * * Note: we use full locale (de-DE) and fallback to short locale (de) */ $locale = str_replace('_', '-', get_locale()); $locale_short = substr($locale, 0, 2); $date_paths = array('jqueryui/datepicker-i18n/jquery.ui.datepicker-' . $locale . '.js'); if (strlen($locale) > 2) { // Also check alternate i18n filenames // (e.g. jquery.ui.datepicker-de.js instead of jquery.ui.datepicker-de-DE.js) $date_paths[] = 'jqueryui/datepicker-i18n/jquery.ui.datepicker-' . substr($locale, 0, 2) . '.js'; } $deps = array('jquery-ui-timepicker-i18n'); foreach ($date_paths as $date_path) { if (file_exists(RWMB_DIR . 'js/' . $date_path)) { wp_register_script('jquery-ui-datepicker-i18n', RWMB_JS_URL . $date_path, array('jquery-ui-datepicker'), '1.8.17', true); $deps[] = 'jquery-ui-datepicker-i18n'; break; } } wp_register_script('rwmb-datetime', RWMB_JS_URL . 'datetime.js', $deps, RWMB_VER, true); wp_register_script('rwmb-date', RWMB_JS_URL . 'date.js', $deps, RWMB_VER, true); wp_register_script('rwmb-time', RWMB_JS_URL . 'time.js', array('jquery-ui-timepicker-i18n'), 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-datetime', 'data')) { wp_localize_script('rwmb-datetime', 'RWMB_Datetimepicker', array('locale' => $locale, 'localeShort' => $locale_short)); } if (!$wp_scripts->get_data('rwmb-time', 'data')) { wp_localize_script('rwmb-time', 'RWMB_Timepicker', array('locale' => $locale, 'localeShort' => $locale_short)); } }
function enqueue_scripts() { $GLOBALS['is_IE'] = false; $wp_styles = wp_styles(); $wp_scripts = wp_scripts(); $this->plugin->enqueue_scripts(); $this->assertContains('font-awesome', $wp_styles->queue); $this->assertContains('wpcw-admin', $wp_styles->queue); $this->assertContains('wpcw-admin', $wp_scripts->queue); $this->assertNotContains('wpcw-admin-ie', $wp_scripts->queue); $GLOBALS['is_IE'] = true; $this->plugin->enqueue_scripts(); $this->assertContains('wpcw-admin-ie', $wp_scripts->queue); }
/** * Jquery CDN */ function bw_register_jquery_google_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', 'bw_jquery_local_fallback', 10, 2); foreach (wp_scripts()->registered as $script) { if ('html5shiv' == $script->handle) { wp_script_add_data($script->handle, 'group', 0); } else { wp_script_add_data($script->handle, 'group', 1); } } }
/** * Enqueue admin scripts * * @since 0.1.0 */ function wp_user_profiles_admin_enqueue_scripts() { // 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(), $ver); // Ugh... this is terrible wp_enqueue_script('user-profile', $src . 'assets/css/user-profiles.css', array('jquery', 'dashboard', 'password-strength-meter', 'wp-util'), $ver); wp_scripts()->registered['user-profile']->src = $src . 'assets/js/user-profiles.js'; }
function jetpack_facebook_embed_handler($matches, $attr, $url) { if (false !== strpos($url, 'video.php') || false !== strpos($url, '/videos/')) { $embed = sprintf('<div class="fb-video" data-allowfullscreen="true" data-href="%s"></div>', esc_url($url)); } else { $embed = sprintf('<fb:post href="%s"></fb:post>', esc_url($url)); } // since Facebook is a faux embed, we need to load the JS SDK in the wpview embed iframe if (defined('DOING_AJAX') && DOING_AJAX && !empty($_POST['action']) && 'parse-embed' == $_POST['action']) { return $embed . wp_scripts()->do_items(array('jetpack-facebook-embed')); } else { wp_enqueue_script('jetpack-facebook-embed'); return $embed; } }
/** * Load CSS files * * @since 2.0.0 * @return type */ public function enqueue_admin_styles() { if (!isset($this->plugin_screen_hook_suffix)) { return; } $screen = get_current_screen(); if ($this->plugin_screen_hook_suffix == $screen->id) { $wp_scripts = wp_scripts(); $ui = $wp_scripts->query('jquery-ui-core'); wp_enqueue_style($this->plugin_slug . '-admin-jquery-ui-styles', '//ajax.googleapis.com/ajax/libs/jqueryui/' . (!empty($ui->ver) ? $ui->ver : '1.11.4') . '/themes/smoothness/jquery-ui' . WPMM_ASSETS_SUFFIX . '.css', array(), WP_Maintenance_Mode::VERSION); wp_enqueue_style($this->plugin_slug . '-admin-chosen', WPMM_CSS_URL . 'chosen' . WPMM_ASSETS_SUFFIX . '.css', array(), WP_Maintenance_Mode::VERSION); wp_enqueue_style($this->plugin_slug . '-admin-timepicker-addon-script', WPMM_CSS_URL . 'jquery-ui-timepicker-addon' . WPMM_ASSETS_SUFFIX . '.css', array(), WP_Maintenance_Mode::VERSION); wp_enqueue_style($this->plugin_slug . '-admin-styles', WPMM_CSS_URL . 'style-admin' . WPMM_ASSETS_SUFFIX . '.css', array('wp-color-picker'), WP_Maintenance_Mode::VERSION); } }
function print_head_scripts() { global $concatenate_scripts; if (!did_action('wp_print_scripts')) { /** This action is documented in wp-includes/functions.wp-scripts.php */ do_action('wp_print_scripts'); } $wp_scripts = wp_scripts(); script_concat_settings(); $wp_scripts->do_concat = $concatenate_scripts; $wp_scripts->do_head_items(); if (apply_filters('print_head_scripts', true)) { _print_scripts(); } $wp_scripts->reset(); return $wp_scripts->done; }
/** * Enqueue scripts for validation. * @param RW_Meta_Box $object Meta Box object */ public function enqueue($object) { if (empty($object->meta_box['validation'])) { return; } wp_enqueue_script('jquery-validation', RWMB_JS_URL . 'jquery-validation/jquery.validate.min.js', array('jquery'), '1.15.0', true); wp_enqueue_script('jquery-validation-additional-methods', RWMB_JS_URL . 'jquery-validation/additional-methods.min.js', array('jquery-validation'), '1.15.0', true); wp_enqueue_script('rwmb-validate', RWMB_JS_URL . 'validate.js', array('jquery-validation', 'jquery-validation-additional-methods'), 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-validate', 'data')) { wp_localize_script('rwmb-validate', 'rwmbValidate', array('summaryMessage' => esc_html__('Please correct the errors highlighted below and try again.', 'meta-box'))); } }
/** * Get one item from the collection * * @param WP_REST_Request $request Full data about the request. * @return WP_Error|WP_REST_Response */ public function get_item($request) { //get parameters from request $params = $request->get_params(); $allowed = apply_filters('allowed_restful_localized_scripts', $this->allowed_scripts); if (isset($params[0])) { global $wp_scripts; if ($wp_scripts === null) { $wp_scripts = wp_scripts(); } foreach ($wp_scripts->registered as $script) { if ($script->handle == $params[0]) { if (true != $allowed && !in_array($params[0], $allowed)) { return new WP_Error('code', __('Script not authorized to be returned via REST API endpoint. Add script handle with allowed_restful_localized_scripts filter.', 'restful-localized-scripts'), $params[0]); } return new WP_REST_Response($this->prepare_item_for_response($script, $request), 200); } } } return new WP_Error('code', __('No script with the requested handle can be found', 'restful-localized-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() * * @global bool $concatenate_scripts * * @return array */ function print_head_scripts() { global $concatenate_scripts; if (!did_action('wp_print_scripts')) { /** This action is documented in wp-includes/functions.wp-scripts.php */ do_action('wp_print_scripts'); } $wp_scripts = 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; }
/** * Adds settings for the customize-loader script. * * @since 3.4.0 */ function _wp_customize_loader_settings() { $admin_origin = parse_url(admin_url()); $home_origin = parse_url(home_url()); $cross_domain = strtolower($admin_origin['host']) != strtolower($home_origin['host']); $browser = array('mobile' => wp_is_mobile(), 'ios' => wp_is_mobile() && preg_match('/iPad|iPod|iPhone/', $_SERVER['HTTP_USER_AGENT'])); $settings = array('url' => esc_url(admin_url('customize.php')), 'isCrossDomain' => $cross_domain, 'browser' => $browser, 'l10n' => array('saveAlert' => __('The changes you made will be lost if you navigate away from this page.'), 'mainIframeTitle' => __('Customizer'))); $script = 'var _wpCustomizeLoaderSettings = ' . wp_json_encode($settings) . ';'; $wp_scripts = wp_scripts(); $data = $wp_scripts->get_data('customize-loader', 'data'); if ($data) { $script = "{$data}\n{$script}"; } $wp_scripts->add_data('customize-loader', 'data', $script); }
/** * Add metadata to a script. * * Works only if the script has already been added. * * Possible values for $key and $value: * 'conditional' string Comments for IE 6, lte IE 7, etc. * * @since 4.2.0 * * @see WP_Dependency::add_data() * * @param string $handle Name of the script. * @param string $key Name of data point for which we're storing a value. * @param mixed $value String containing the data to be added. * @return bool True on success, false on failure. */ function wp_script_add_data($handle, $key, $value) { return wp_scripts()->add_data($handle, $key, $value); }
/** * Enqueue scripts and styles for Customizer pane. * * @since 4.3.0 * @access public */ public function enqueue_scripts() { wp_enqueue_style('customize-nav-menus'); wp_enqueue_script('customize-nav-menus'); $temp_nav_menu_setting = new WP_Customize_Nav_Menu_Setting($this->manager, 'nav_menu[-1]'); $temp_nav_menu_item_setting = new WP_Customize_Nav_Menu_Item_Setting($this->manager, 'nav_menu_item[-1]'); // Pass data to JS. $settings = array('nonce' => wp_create_nonce('customize-menus'), 'allMenus' => wp_get_nav_menus(), 'itemTypes' => $this->available_item_types(), 'l10n' => array('untitled' => _x('(no label)', 'missing menu item navigation label'), 'unnamed' => _x('(unnamed)', 'Missing menu name.'), 'custom_label' => __('Custom Link'), 'menuLocation' => _x('(Currently set to: %s)', 'menu'), 'menuNameLabel' => __('Menu Name'), 'itemAdded' => __('Menu item added'), 'itemDeleted' => __('Menu item deleted'), 'menuAdded' => __('Menu created'), 'menuDeleted' => __('Menu deleted'), 'movedUp' => __('Menu item moved up'), 'movedDown' => __('Menu item moved down'), 'movedLeft' => __('Menu item moved out of submenu'), 'movedRight' => __('Menu item is now a sub-item'), 'customizingMenus' => sprintf(__('Customizing ▸ %s'), esc_html($this->manager->get_panel('nav_menus')->title)), 'invalidTitleTpl' => __('%s (Invalid)'), 'pendingTitleTpl' => __('%s (Pending)'), 'itemsFound' => __('Number of items found: %d'), 'itemsFoundMore' => __('Additional items found: %d'), 'itemsLoadingMore' => __('Loading more results... please wait.'), 'reorderModeOn' => __('Reorder mode enabled'), 'reorderModeOff' => __('Reorder mode closed'), 'reorderLabelOn' => esc_attr__('Reorder menu items'), 'reorderLabelOff' => esc_attr__('Close reorder mode')), 'menuItemTransport' => 'postMessage', 'phpIntMax' => PHP_INT_MAX, 'defaultSettingValues' => array('nav_menu' => $temp_nav_menu_setting->default, 'nav_menu_item' => $temp_nav_menu_item_setting->default)); $data = sprintf('var _wpCustomizeNavMenusSettings = %s;', wp_json_encode($settings)); wp_scripts()->add_data('customize-nav-menus', 'data', $data); // This is copied from nav-menus.php, and it has an unfortunate object name of `menus`. $nav_menus_l10n = array('oneThemeLocationNoMenus' => null, 'moveUp' => __('Move up one'), 'moveDown' => __('Move down one'), 'moveToTop' => __('Move to the top'), 'moveUnder' => __('Move under %s'), 'moveOutFrom' => __('Move out from under %s'), 'under' => __('Under %s'), 'outFrom' => __('Out from under %s'), 'menuFocus' => __('%1$s. Menu item %2$d of %3$d.'), 'subMenuFocus' => __('%1$s. Sub item number %2$d under %3$s.')); wp_localize_script('nav-menu', 'menus', $nav_menus_l10n); }