/**
* Communicates the sidebars that appeared on the page at the very end of the page,
* and at the very end of the wp_footer,
*
* @since 3.9.0
* @access public
*
* @global array $wp_registered_sidebars
* @global array $wp_registered_widgets
*/
public function export_preview_data()
{
global $wp_registered_sidebars, $wp_registered_widgets;
$switched_locale = switch_to_locale(get_user_locale());
$l10n = array('widgetTooltip' => __('Shift-click to edit this widget.'));
if ($switched_locale) {
restore_previous_locale();
}
// Prepare Customizer settings to pass to JavaScript.
$settings = array('renderedSidebars' => array_fill_keys(array_unique($this->rendered_sidebars), true), 'renderedWidgets' => array_fill_keys(array_keys($this->rendered_widgets), true), 'registeredSidebars' => array_values($wp_registered_sidebars), 'registeredWidgets' => $wp_registered_widgets, 'l10n' => $l10n, 'selectiveRefreshableWidgets' => $this->get_selective_refreshable_widgets());
foreach ($settings['registeredWidgets'] as &$registered_widget) {
unset($registered_widget['callback']);
// may not be JSON-serializeable
}
?>
<script type="text/javascript">
var _wpWidgetCustomizerPreviewSettings = <?php
echo wp_json_encode($settings);
?>
;
</script>
<?php
}
/**
* Switches the translations according to the given locale.
*
* @since 4.7.0
*
* @param string $locale The locale to switch to.
* @return bool True on success, false on failure.
*/
public function switch_to_locale($locale)
{
$current_locale = is_admin() ? get_user_locale() : get_locale();
if ($current_locale === $locale) {
return false;
}
if (!in_array($locale, $this->available_languages, true)) {
return false;
}
$this->locales[] = $locale;
$this->change_locale($locale);
/**
* Fires when the locale is switched.
*
* @since 4.7.0
*
* @param string $locale The new locale.
*/
do_action('switch_locale', $locale);
return true;
}
/**
* Exports data in preview after it has finished rendering so that partials can be added at runtime.
*
* @since 4.5.0
* @access public
*/
public function export_preview_data()
{
$partials = array();
foreach ($this->partials() as $partial) {
if ($partial->check_capabilities()) {
$partials[$partial->id] = $partial->json();
}
}
$switched_locale = switch_to_locale(get_user_locale());
$l10n = array('shiftClickToEdit' => __('Shift-click to edit this element.'), 'clickEditMenu' => __('Click to edit this menu.'), 'clickEditWidget' => __('Click to edit this widget.'), 'clickEditTitle' => __('Click to edit the site title.'), 'clickEditMisc' => __('Click to edit this element.'), 'badDocumentWrite' => sprintf(__('%s is forbidden'), 'document.write()'));
if ($switched_locale) {
restore_previous_locale();
}
$exports = array('partials' => $partials, 'renderQueryVar' => self::RENDER_QUERY_VAR, 'l10n' => $l10n);
// Export data to JS.
echo sprintf('<script>var _customizePartialRefreshExports = %s;</script>', wp_json_encode($exports));
}
/**
* Loads the plugin language files.
*
* @access public
* @since 1.4
* @return void
*/
public function load_textdomain()
{
global $wp_version;
/*
* Due to the introduction of language packs through translate.wordpress.org, loading our textdomain is complex.
*
* In v2.4.6, our textdomain changed from "edd" to "easy-digital-downloads".
*
* To support existing translation files from before the change, we must look for translation files in several places and under several names.
*
* - wp-content/languages/plugins/easy-digital-downloads (introduced with language packs)
* - wp-content/languages/edd/ (custom folder we have supported since 1.4)
* - wp-content/plugins/easy-digital-downloads/languages/
*
* In wp-content/languages/edd/ we must look for "easy-digital-downloads-{lang}_{country}.mo"
* In wp-content/languages/edd/ we must look for "edd-{lang}_{country}.mo" as that was the old file naming convention
* In wp-content/languages/plugins/easy-digital-downloads/ we only need to look for "easy-digital-downloads-{lang}_{country}.mo" as that is the new structure
* In wp-content/plugins/easy-digital-downloads/languages/, we must look for both naming conventions. This is done by filtering "load_textdomain_mofile"
*
*/
add_filter('load_textdomain_mofile', array($this, 'load_old_textdomain'), 10, 2);
// Set filter for plugin's languages directory.
$edd_lang_dir = dirname(plugin_basename(EDD_PLUGIN_FILE)) . '/languages/';
$edd_lang_dir = apply_filters('edd_languages_directory', $edd_lang_dir);
// Traditional WordPress plugin locale filter.
$get_locale = get_locale();
if ($wp_version >= 4.7) {
$get_locale = get_user_locale();
}
/**
* Defines the plugin language locale used in AffiliateWP.
*
* @var $get_locale The locale to use. Uses get_user_locale()` in WordPress 4.7 or greater,
* otherwise uses `get_locale()`.
*/
$locale = apply_filters('plugin_locale', $get_locale, 'easy-digital-downloads');
$mofile = sprintf('%1$s-%2$s.mo', 'easy-digital-downloads', $locale);
// Look for wp-content/languages/edd/easy-digital-downloads-{lang}_{country}.mo
$mofile_global1 = WP_LANG_DIR . '/edd/easy-digital-downloads-' . $locale . '.mo';
// Look for wp-content/languages/edd/edd-{lang}_{country}.mo
$mofile_global2 = WP_LANG_DIR . '/edd/edd-' . $locale . '.mo';
// Look in wp-content/languages/plugins/easy-digital-downloads
$mofile_global3 = WP_LANG_DIR . '/plugins/easy-digital-downloads/' . $mofile;
if (file_exists($mofile_global1)) {
load_textdomain('easy-digital-downloads', $mofile_global1);
} elseif (file_exists($mofile_global2)) {
load_textdomain('easy-digital-downloads', $mofile_global2);
} elseif (file_exists($mofile_global3)) {
load_textdomain('easy-digital-downloads', $mofile_global3);
} else {
// Load the default language files.
load_plugin_textdomain('easy-digital-downloads', false, $edd_lang_dir);
}
}
/**
* Retrieves theme installer pages from the WordPress.org Themes API.
*
* It is possible for a theme to override the Themes API result with three
* filters. Assume this is for themes, which can extend on the Theme Info to
* offer more choices. This is very powerful and must be used with care, when
* overriding the filters.
*
* The first filter, {@see 'themes_api_args'}, is for the args and gives the action
* as the second parameter. The hook for {@see 'themes_api_args'} must ensure that
* an object is returned.
*
* The second filter, {@see 'themes_api'}, allows a plugin to override the WordPress.org
* Theme API entirely. If `$action` is 'query_themes', 'theme_information', or 'feature_list',
* an object MUST be passed. If `$action` is 'hot_tags', an array should be passed.
*
* Finally, the third filter, {@see 'themes_api_result'}, makes it possible to filter the
* response object or array, depending on the `$action` type.
*
* Supported arguments per action:
*
* | Argument Name | 'query_themes' | 'theme_information' | 'hot_tags' | 'feature_list' |
* | -------------------| :------------: | :-----------------: | :--------: | :--------------: |
* | `$slug` | No | Yes | No | No |
* | `$per_page` | Yes | No | No | No |
* | `$page` | Yes | No | No | No |
* | `$number` | No | No | Yes | No |
* | `$search` | Yes | No | No | No |
* | `$tag` | Yes | No | No | No |
* | `$author` | Yes | No | No | No |
* | `$user` | Yes | No | No | No |
* | `$browse` | Yes | No | No | No |
* | `$locale` | Yes | Yes | No | No |
* | `$fields` | Yes | Yes | No | No |
*
* @since 2.8.0
*
* @param string $action API action to perform: 'query_themes', 'theme_information',
* 'hot_tags' or 'feature_list'.
* @param array|object $args {
* Optional. Array or object of arguments to serialize for the Themes API.
*
* @type string $slug The theme slug. Default empty.
* @type int $per_page Number of themes per page. Default 24.
* @type int $page Number of current page. Default 1.
* @type int $number Number of tags to be queried.
* @type string $search A search term. Default empty.
* @type string $tag Tag to filter themes. Default empty.
* @type string $author Username of an author to filter themes. Default empty.
* @type string $user Username to query for their favorites. Default empty.
* @type string $browse Browse view: 'featured', 'popular', 'updated', 'favorites'.
* @type string $locale Locale to provide context-sensitive results. Default is the value of get_locale().
* @type array $fields {
* Array of fields which should or should not be returned.
*
* @type bool $description Whether to return the theme full description. Default false.
* @type bool $sections Whether to return the theme readme sections: description, installation,
* FAQ, screenshots, other notes, and changelog. Default false.
* @type bool $rating Whether to return the rating in percent and total number of ratings.
* Default false.
* @type bool $ratings Whether to return the number of rating for each star (1-5). Default false.
* @type bool $downloaded Whether to return the download count. Default false.
* @type bool $downloadlink Whether to return the download link for the package. Default false.
* @type bool $last_updated Whether to return the date of the last update. Default false.
* @type bool $tags Whether to return the assigned tags. Default false.
* @type bool $homepage Whether to return the theme homepage link. Default false.
* @type bool $screenshots Whether to return the screenshots. Default false.
* @type int $screenshot_count Number of screenshots to return. Default 1.
* @type bool $screenshot_url Whether to return the URL of the first screenshot. Default false.
* @type bool $photon_screenshots Whether to return the screenshots via Photon. Default false.
* @type bool $template Whether to return the slug of the parent theme. Default false.
* @type bool $parent Whether to return the slug, name and homepage of the parent theme. Default false.
* @type bool $versions Whether to return the list of all available versions. Default false.
* @type bool $theme_url Whether to return theme's URL. Default false.
* @type bool $extended_author Whether to return nicename or nicename and display name. Default false.
* }
* }
* @return object|array|WP_Error Response object or array on success, WP_Error on failure. See the
* {@link https://developer.wordpress.org/reference/functions/themes_api/ function reference article}
* for more information on the make-up of possible return objects depending on the value of `$action`.
*/
function themes_api($action, $args = array())
{
if (is_array($args)) {
$args = (object) $args;
}
if (!isset($args->per_page)) {
$args->per_page = 24;
}
if (!isset($args->locale)) {
$args->locale = get_user_locale();
}
/**
* Filters arguments used to query for installer pages from the WordPress.org Themes API.
*
* Important: An object MUST be returned to this filter.
*
* @since 2.8.0
*
* @param object $args Arguments used to query for installer pages from the WordPress.org Themes API.
//.........这里部分代码省略.........
请发表评论