/**
     * 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;
 }
    /**
     * Serves the app's base HTML, which in turns calls the load script.
     *
     * @since 4.2.0
     * @access public
     *
     * @global WP_Locale $wp_locale
     * @global bool      $is_IE
     */
    public function html()
    {
        global $wp_locale;
        $wp_version = get_bloginfo('version');
        // Get data, new (POST) and old (GET).
        $data = $this->merge_or_fetch_data();
        $post_title = $this->get_suggested_title($data);
        $post_content = $this->get_suggested_content($data);
        // Get site settings array/data.
        $site_settings = $this->site_settings();
        // Pass the images and embeds
        $images = $this->get_images($data);
        $embeds = $this->get_embeds($data);
        $site_data = array('v' => !empty($data['v']) ? $data['v'] : '', 'u' => !empty($data['u']) ? $data['u'] : '', 'hasData' => !empty($data));
        if (!empty($images)) {
            $site_data['_images'] = $images;
        }
        if (!empty($embeds)) {
            $site_data['_embeds'] = $embeds;
        }
        // Add press-this-editor.css and remove theme's editor-style.css, if any.
        remove_editor_styles();
        add_filter('mce_css', array($this, 'add_editor_style'));
        if (!empty($GLOBALS['is_IE'])) {
            @header('X-UA-Compatible: IE=edge');
        }
        @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
        ?>
<!DOCTYPE html>
<!--[if IE 7]>         <html class="lt-ie9 lt-ie8" <?php 
        language_attributes();
        ?>
> <![endif]-->
<!--[if IE 8]>         <html class="lt-ie9" <?php 
        language_attributes();
        ?>
> <![endif]-->
<!--[if gt IE 8]><!--> <html <?php 
        language_attributes();
        ?>
> <!--<![endif]-->
<head>
	<meta http-equiv="Content-Type" content="<?php 
        echo esc_attr(get_bloginfo('html_type'));
        ?>
; charset=<?php 
        echo esc_attr(get_option('blog_charset'));
        ?>
" />
	<meta name="viewport" content="width=device-width">
	<title><?php 
        esc_html_e('Press This!');
        ?>
</title>

	<script>
		window.wpPressThisData   = <?php 
        echo wp_json_encode($site_data);
        ?>
;
		window.wpPressThisConfig = <?php 
        echo wp_json_encode($site_settings);
        ?>
;
	</script>

	<script type="text/javascript">
		var ajaxurl = '<?php 
        echo esc_js(admin_url('admin-ajax.php', 'relative'));
        ?>
',
			pagenow = 'press-this',
			typenow = 'post',
			adminpage = 'press-this-php',
			thousandsSeparator = '<?php 
        echo addslashes($wp_locale->number_format['thousands_sep']);
        ?>
',
			decimalPoint = '<?php 
        echo addslashes($wp_locale->number_format['decimal_point']);
        ?>
',
			isRtl = <?php 
        echo (int) is_rtl();
        ?>
;
	</script>

	<?php 
        /*
         * $post->ID is needed for the embed shortcode so we can show oEmbed previews in the editor.
         * Maybe find a way without it.
         */
        $post = get_default_post_to_edit('post', true);
        $post_ID = (int) $post->ID;
        wp_enqueue_media(array('post' => $post_ID));
        wp_enqueue_style('press-this');
        wp_enqueue_script('press-this');
        wp_enqueue_script('json2');
        wp_enqueue_script('editor');
        $supports_formats = false;
        $post_format = 0;
        if (current_theme_supports('post-formats') && post_type_supports($post->post_type, 'post-formats')) {
            $supports_formats = true;
            if (!($post_format = get_post_format($post_ID))) {
                $post_format = 0;
            }
        }
        /** This action is documented in wp-admin/admin-header.php */
        do_action('admin_enqueue_scripts', 'press-this.php');
        /** This action is documented in wp-admin/admin-header.php */
        do_action('admin_print_styles-press-this.php');
        /** This action is documented in wp-admin/admin-header.php */
        do_action('admin_print_styles');
        /** This action is documented in wp-admin/admin-header.php */
        do_action('admin_print_scripts-press-this.php');
        /** This action is documented in wp-admin/admin-header.php */
        do_action('admin_print_scripts');
        /** This action is documented in wp-admin/admin-header.php */
        do_action('admin_head-press-this.php');
        /** This action is documented in wp-admin/admin-header.php */
        do_action('admin_head');
        ?>
</head>
<?php 
        $admin_body_class = 'press-this';
        $admin_body_class .= is_rtl() ? ' rtl' : '';
        $admin_body_class .= ' branch-' . str_replace(array('.', ','), '-', floatval($wp_version));
        $admin_body_class .= ' version-' . str_replace('.', '-', preg_replace('/^([.0-9]+).*/', '$1', $wp_version));
        $admin_body_class .= ' admin-color-' . sanitize_html_class(get_user_option('admin_color'), 'fresh');
        $admin_body_class .= ' locale-' . sanitize_html_class(strtolower(str_replace('_', '-', get_user_locale())));
        /** This filter is documented in wp-admin/admin-header.php */
        $admin_body_classes = apply_filters('admin_body_class', '');
        ?>
<body class="wp-admin wp-core-ui <?php 
        echo $admin_body_classes . ' ' . $admin_body_class;
        ?>
">
	<div id="adminbar" class="adminbar">
		<h1 id="current-site" class="current-site">
			<a class="current-site-link" href="<?php 
        echo esc_url(home_url('/'));
        ?>
" target="_blank" rel="home">
				<span class="dashicons dashicons-wordpress"></span>
				<span class="current-site-name"><?php 
        bloginfo('name');
        ?>
</span>
			</a>
		</h1>
		<button type="button" class="options button-link closed">
			<span class="dashicons dashicons-tag on-closed"></span>
			<span class="screen-reader-text on-closed"><?php 
        _e('Show post options');
        ?>
</span>
			<span aria-hidden="true" class="on-open"><?php 
        _e('Done');
        ?>
</span>
			<span class="screen-reader-text on-open"><?php 
        _e('Hide post options');
        ?>
</span>
		</button>
	</div>

	<div id="scanbar" class="scan">
		<form method="GET">
			<label for="url-scan" class="screen-reader-text"><?php 
        _e('Scan site for content');
        ?>
</label>
			<input type="url" name="u" id="url-scan" class="scan-url" value="" placeholder="<?php 
        esc_attr_e('Enter a URL to scan');
        ?>
" />
			<input type="submit" name="url-scan-submit" id="url-scan-submit" class="scan-submit" value="<?php 
        esc_attr_e('Scan');
        ?>
" />
		</form>
	</div>

	<form id="pressthis-form" method="post" action="post.php" autocomplete="off">
		<input type="hidden" name="post_ID" id="post_ID" value="<?php 
        echo $post_ID;
        ?>
" />
		<input type="hidden" name="action" value="press-this-save-post" />
		<input type="hidden" name="post_status" id="post_status" value="draft" />
		<input type="hidden" name="wp-preview" id="wp-preview" value="" />
		<input type="hidden" name="post_title" id="post_title" value="" />
		<input type="hidden" name="pt-force-redirect" id="pt-force-redirect" value="" />
		<?php 
        wp_nonce_field('update-post_' . $post_ID, '_wpnonce', false);
        wp_nonce_field('add-category', '_ajax_nonce-add-category', false);
        ?>

	<div class="wrapper">
		<div class="editor-wrapper">
			<div class="alerts" role="alert" aria-live="assertive" aria-relevant="all" aria-atomic="true">
				<?php 
        if (isset($data['v']) && $this->version > $data['v']) {
            ?>
					<p class="alert is-notice">
						<?php 
            printf(__('You should upgrade <a href="%s" target="_blank">your bookmarklet</a> to the latest version!'), admin_url('tools.php'));
            ?>
					</p>
					<?php 
        }
        ?>
			</div>

			<div id="app-container" class="editor">
				<span id="title-container-label" class="post-title-placeholder" aria-hidden="true"><?php 
        _e('Post title');
        ?>
</span>
				<h2 id="title-container" class="post-title" contenteditable="true" spellcheck="true" aria-label="<?php 
        esc_attr_e('Post title');
        ?>
" tabindex="0"><?php 
        echo esc_html($post_title);
        ?>
</h2>

				<div class="media-list-container">
					<div class="media-list-inner-container">
						<h2 class="screen-reader-text"><?php 
        _e('Suggested media');
        ?>
</h2>
						<ul class="media-list"></ul>
					</div>
				</div>

				<?php 
        wp_editor($post_content, 'pressthis', array('drag_drop_upload' => true, 'editor_height' => 600, 'media_buttons' => false, 'textarea_name' => 'post_content', 'teeny' => true, 'tinymce' => array('resize' => false, 'wordpress_adv_hidden' => false, 'add_unload_trigger' => false, 'statusbar' => false, 'autoresize_min_height' => 600, 'wp_autoresize_on' => true, 'plugins' => 'lists,media,paste,tabfocus,fullscreen,wordpress,wpautoresize,wpeditimage,wpgallery,wplink,wptextpattern,wpview', 'toolbar1' => 'bold,italic,bullist,numlist,blockquote,link,unlink', 'toolbar2' => 'undo,redo'), 'quicktags' => array('buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,more')));
        ?>
			</div>
		</div>

		<div class="options-panel-back is-hidden" tabindex="-1"></div>
		<div class="options-panel is-off-screen is-hidden" tabindex="-1">
			<div class="post-options">

				<?php 
        if ($supports_formats) {
            ?>
					<button type="button" class="button-link post-option">
						<span class="dashicons dashicons-admin-post"></span>
						<span class="post-option-title"><?php 
            _ex('Format', 'post format');
            ?>
</span>
						<span class="post-option-contents" id="post-option-post-format"><?php 
            echo esc_html(get_post_format_string($post_format));
            ?>
</span>
						<span class="dashicons post-option-forward"></span>
					</button>
				<?php 
        }
        ?>

				<button type="button" class="button-link post-option">
					<span class="dashicons dashicons-category"></span>
					<span class="post-option-title"><?php 
        _e('Categories');
        ?>
</span>
					<span class="dashicons post-option-forward"></span>
				</button>

				<button type="button" class="button-link post-option">
					<span class="dashicons dashicons-tag"></span>
					<span class="post-option-title"><?php 
        _e('Tags');
        ?>
</span>
					<span class="dashicons post-option-forward"></span>
				</button>
			</div>

			<?php 
        if ($supports_formats) {
            ?>
				<div class="setting-modal is-off-screen is-hidden">
					<button type="button" class="button-link modal-close">
						<span class="dashicons post-option-back"></span>
						<span class="setting-title" aria-hidden="true"><?php 
            _ex('Format', 'post format');
            ?>
</span>
						<span class="screen-reader-text"><?php 
            _e('Back to post options');
            ?>
</span>
					</button>
					<?php 
            $this->post_formats_html($post);
            ?>
				</div>
			<?php 
        }
        ?>

			<div class="setting-modal is-off-screen is-hidden">
				<button type="button" class="button-link modal-close">
					<span class="dashicons post-option-back"></span>
					<span class="setting-title" aria-hidden="true"><?php 
        _e('Categories');
        ?>
</span>
					<span class="screen-reader-text"><?php 
        _e('Back to post options');
        ?>
</span>
				</button>
				<?php 
        $this->categories_html($post);
        ?>
			</div>

			<div class="setting-modal tags is-off-screen is-hidden">
				<button type="button" class="button-link modal-close">
					<span class="dashicons post-option-back"></span>
					<span class="setting-title" aria-hidden="true"><?php 
        _e('Tags');
        ?>
</span>
					<span class="screen-reader-text"><?php 
        _e('Back to post options');
        ?>
</span>
				</button>
				<?php 
        $this->tags_html($post);
        ?>
			</div>
		</div><!-- .options-panel -->
	</div><!-- .wrapper -->

	<div class="press-this-actions">
		<div class="pressthis-media-buttons">
			<button type="button" class="insert-media button-link" data-editor="pressthis">
				<span class="dashicons dashicons-admin-media"></span>
				<span class="screen-reader-text"><?php 
        _e('Add Media');
        ?>
</span>
			</button>
		</div>
		<div class="post-actions">
			<span class="spinner">&nbsp;</span>
			<div class="split-button">
				<div class="split-button-head">
					<button type="button" class="publish-button split-button-primary" aria-live="polite">
						<span class="publish"><?php 
        echo current_user_can('publish_posts') ? __('Publish') : __('Submit for Review');
        ?>
</span>
						<span class="saving-draft"><?php 
        _e('Saving&hellip;');
        ?>
</span>
					</button><button type="button" class="split-button-toggle" aria-haspopup="true" aria-expanded="false">
						<i class="dashicons dashicons-arrow-down-alt2"></i>
						<span class="screen-reader-text"><?php 
        _e('More actions');
        ?>
</span>
					</button>
				</div>
				<ul class="split-button-body">
					<li><button type="button" class="button-link draft-button split-button-option"><?php 
        _e('Save Draft');
        ?>
</button></li>
					<li><button type="button" class="button-link standard-editor-button split-button-option"><?php 
        _e('Standard Editor');
        ?>
</button></li>
					<li><button type="button" class="button-link preview-button split-button-option"><?php 
        _e('Preview');
        ?>
</button></li>
				</ul>
			</div>
		</div>
	</div>
	</form>

	<?php 
        /** This action is documented in wp-admin/admin-footer.php */
        do_action('admin_footer');
        /** This action is documented in wp-admin/admin-footer.php */
        do_action('admin_print_footer_scripts-press-this.php');
        /** This action is documented in wp-admin/admin-footer.php */
        do_action('admin_print_footer_scripts');
        /** This action is documented in wp-admin/admin-footer.php */
        do_action('admin_footer-press-this.php');
        ?>
</body>
</html>
<?php 
        die;
    }
 /**
  * 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));
 }
 public function test_user_locale_is_same_across_network()
 {
     if (!is_multisite()) {
         $this->markTestSkipped(__METHOD__ . ' requires multisite');
     }
     $user_locale = get_user_locale();
     switch_to_blog(self::factory()->blog->create());
     $user_locale_2 = get_user_locale();
     restore_current_blog();
     $this->assertSame('de_DE', $user_locale);
     $this->assertSame($user_locale, $user_locale_2);
 }
/**
 * Retrieve the contributor credits.
 *
 * @since 3.2.0
 *
 * @return array|false A list of all of the contributors, or false on error.
 */
function wp_credits()
{
    $wp_version = get_bloginfo('version');
    $locale = get_user_locale();
    $results = get_site_transient('wordpress_credits_' . $locale);
    if (!is_array($results) || false !== strpos($wp_version, '-') || isset($results['data']['version']) && strpos($wp_version, $results['data']['version']) !== 0) {
        $response = wp_remote_get("http://api.wordpress.org/core/credits/1.1/?version={$wp_version}&locale={$locale}");
        if (is_wp_error($response) || 200 != wp_remote_retrieve_response_code($response)) {
            return false;
        }
        $results = json_decode(wp_remote_retrieve_body($response), true);
        if (!is_array($results)) {
            return false;
        }
        set_site_transient('wordpress_credits_' . $locale, $results, DAY_IN_SECONDS);
    }
    return $results;
}
示例#7
0
function get_locale()
{
    global $webimroot, $locale_pattern;
    $locale = verifyparam("locale", $locale_pattern, "");
    if ($locale && locale_exists($locale)) {
        $_SESSION['locale'] = $locale;
        setcookie('webim_locale', $locale, time() + 60 * 60 * 24 * 1000, "{$webimroot}/");
    } else {
        if (isset($_SESSION['locale'])) {
            $locale = $_SESSION['locale'];
        }
    }
    if (!$locale || !locale_exists($locale)) {
        $locale = get_user_locale();
    }
    return $locale;
}
function wp_dashboard_browser_nag()
{
    $notice = '';
    $response = wp_check_browser_version();
    if ($response) {
        if ($response['insecure']) {
            /* translators: %s: browser name and link */
            $msg = sprintf(__("It looks like you're using an insecure version of %s. Using an outdated browser makes your computer unsafe. For the best WordPress experience, please update your browser."), sprintf('<a href="%s">%s</a>', esc_url($response['update_url']), esc_html($response['name'])));
        } else {
            /* translators: %s: browser name and link */
            $msg = sprintf(__("It looks like you're using an old version of %s. For the best WordPress experience, please update your browser."), sprintf('<a href="%s">%s</a>', esc_url($response['update_url']), esc_html($response['name'])));
        }
        $browser_nag_class = '';
        if (!empty($response['img_src'])) {
            $img_src = is_ssl() && !empty($response['img_src_ssl']) ? $response['img_src_ssl'] : $response['img_src'];
            $notice .= '<div class="alignright browser-icon"><a href="' . esc_attr($response['update_url']) . '"><img src="' . esc_attr($img_src) . '" alt="" /></a></div>';
            $browser_nag_class = ' has-browser-icon';
        }
        $notice .= "<p class='browser-update-nag{$browser_nag_class}'>{$msg}</p>";
        $browsehappy = 'http://browsehappy.com/';
        $locale = get_user_locale();
        if ('en_US' !== $locale) {
            $browsehappy = add_query_arg('locale', $locale, $browsehappy);
        }
        $notice .= '<p>' . sprintf(__('<a href="%1$s" class="update-browser-link">Update %2$s</a> or learn how to <a href="%3$s" class="browse-happy-link">browse happy</a>'), esc_attr($response['update_url']), esc_html($response['name']), esc_url($browsehappy)) . '</p>';
        $notice .= '<p class="hide-if-no-js"><a href="" class="dismiss" aria-label="' . esc_attr__('Dismiss the browser warning panel') . '">' . __('Dismiss') . '</a></p>';
        $notice .= '<div class="clear"></div>';
    }
    /**
     * Filters the notice output for the 'Browse Happy' nag meta box.
     *
     * @since 3.2.0
     *
     * @param string $notice   The notice content.
     * @param array  $response An array containing web browser information.
     */
    echo apply_filters('browse-happy-notice', $notice, $response);
}
 /**
  * Sorts themes by name.
  *
  * @since 3.4.0
  *
  * @static
  * @access public
  *
  * @param array $themes Array of themes to sort, passed by reference.
  */
 public static function sort_by_name(&$themes)
 {
     if (0 === strpos(get_user_locale(), 'en_')) {
         uasort($themes, array('WP_Theme', '_name_sort'));
     } else {
         uasort($themes, array('WP_Theme', '_name_sort_i18n'));
     }
 }
示例#10
0
if (is_admin_bar_showing()) {
    $admin_body_class .= ' admin-bar';
}
if (is_rtl()) {
    $admin_body_class .= ' rtl';
}
if ($current_screen->post_type) {
    $admin_body_class .= ' post-type-' . $current_screen->post_type;
}
if ($current_screen->taxonomy) {
    $admin_body_class .= ' taxonomy-' . $current_screen->taxonomy;
}
$admin_body_class .= ' branch-' . str_replace(array('.', ','), '-', floatval(get_bloginfo('version')));
$admin_body_class .= ' version-' . str_replace('.', '-', preg_replace('/^([.0-9]+).*/', '$1', get_bloginfo('version')));
$admin_body_class .= ' admin-color-' . sanitize_html_class(get_user_option('admin_color'), 'fresh');
$admin_body_class .= ' locale-' . sanitize_html_class(strtolower(str_replace('_', '-', get_user_locale())));
if (wp_is_mobile()) {
    $admin_body_class .= ' mobile';
}
if (is_multisite()) {
    $admin_body_class .= ' multisite';
}
if (is_network_admin()) {
    $admin_body_class .= ' network-admin';
}
$admin_body_class .= ' no-customize-support no-svg';
?>
</head>
<?php 
/**
 * Filters the CSS classes for the body tag in the admin.
 /**
  * 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);
     }
 }
示例#12
0
/**
 * 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.
     * @param string $action Requested action. Likely values are 'theme_information',
     *                       'feature_list', or 'query_themes'.
     */
    $args = apply_filters('themes_api_args', $args, $action);
    /**
     * Filters whether to override the WordPress.org Themes API.
     *
     * Passing a non-false value will effectively short-circuit the WordPress.org API request.
     *
     * 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.
     *
     * @since 2.8.0
     *
     * @param false|object|array $override Whether to override the WordPress.org Themes API. Default false.
     * @param string             $action   Requested action. Likely values are 'theme_information',
     *                                    'feature_list', or 'query_themes'.
     * @param object             $args     Arguments used to query for installer pages from the Themes API.
     */
    $res = apply_filters('themes_api', false, $action, $args);
    if (!$res) {
        $url = $http_url = 'http://api.wordpress.org/themes/info/1.0/';
        if ($ssl = wp_http_supports(array('ssl'))) {
            $url = set_url_scheme($url, 'https');
        }
        $http_args = array('body' => array('action' => $action, 'request' => serialize($args)));
        $request = wp_remote_post($url, $http_args);
        if ($ssl && is_wp_error($request)) {
            if (!wp_doing_ajax()) {
                trigger_error(sprintf(__('An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.'), __('https://wordpress.org/support/')) . ' ' . __('(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)'), headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE);
            }
            $request = wp_remote_post($http_url, $http_args);
        }
        if (is_wp_error($request)) {
            $res = new WP_Error('themes_api_failed', sprintf(__('An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.'), __('https://wordpress.org/support/')), $request->get_error_message());
        } else {
            $res = maybe_unserialize(wp_remote_retrieve_body($request));
            if (!is_object($res) && !is_array($res)) {
                $res = new WP_Error('themes_api_failed', sprintf(__('An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.'), __('https://wordpress.org/support/')), wp_remote_retrieve_body($request));
            }
        }
    }
    /**
     * Filters the returned WordPress.org Themes API response.
     *
     * @since 2.8.0
     *
     * @param array|object|WP_Error $res    WordPress.org Themes API response.
     * @param string                $action Requested action. Likely values are 'theme_information',
     *                                      'feature_list', or 'query_themes'.
     * @param object                $args   Arguments used to query for installer pages from the WordPress.org Themes API.
     */
    return apply_filters('themes_api_result', $res, $action, $args);
}
示例#13
0
// @NOTE: if the user doesn't have permission to view users
// it should be log out
// see: https://github.com/directus/directus/issues/1268
if (!$users) {
    AuthProvider::logout();
    $_SESSION['error_message'] = 'Your user doesn\'t have permission to log in';
    header('Location: ' . DIRECTUS_PATH . 'login.php');
    exit;
}
$currentUserInfo = getCurrentUserInfo($users);
// Cache buster
$git = __DIR__ . '/.git';
$cacheBuster = Directus\Util\Git::getCloneHash($git);
$tableSchema = TableSchema::getAllSchemas($currentUserInfo['group']['id'], $cacheBuster);
// $tabPrivileges = getTabPrivileges(($currentUserInfo['group']['id']));
$groupId = $currentUserInfo['group']['id'];
$groups = getGroups();
$currentUserGroup = [];
if (isset($groups['rows']) && count($groups['rows'] > 0)) {
    foreach ($groups['rows'] as $group) {
        if ($group['id'] === $groupId) {
            $currentUserGroup = $group;
            break;
        }
    }
}
$statusMapping = ['active_num' => STATUS_ACTIVE_NUM, 'deleted_num' => STATUS_DELETED_NUM, 'status_name' => STATUS_COLUMN_NAME];
$statusMapping['mapping'] = $config['statusMapping'];
$data = ['cacheBuster' => $cacheBuster, 'nonces' => getNonces(), 'storage_adapters' => getStorageAdapters(), 'path' => DIRECTUS_PATH, 'page' => '#tables', 'tables' => parseTables($tableSchema), 'preferences' => parsePreferences($tableSchema), 'users' => $users, 'groups' => $groups, 'settings' => getSettings(), 'active_files' => getActiveFiles(), 'authenticatedUser' => $authenticatedUser, 'extensions' => getExtensions($currentUserGroup), 'privileges' => getPrivileges($groupId), 'ui' => getUI(), 'locale' => get_user_locale(), 'localesAvailable' => parseLocalesAvailable(get_locales_available()), 'phrases' => get_phrases(get_user_locale()), 'timezone' => get_user_timezone(), 'timezones' => get_timezone_list(), 'listViews' => getListViews(), 'messages' => getInbox(), 'user_notifications' => getLoginNotification(), 'bookmarks' => getBookmarks(), 'extendedUserColumns' => getExtendedUserColumns($tableSchema), 'statusMapping' => $statusMapping];
$templateVars = ['cacheBuster' => $cacheBuster, 'data' => json_encode($data), 'path' => DIRECTUS_PATH, 'locale' => get_user_locale(), 'dir' => 'ltr', 'customFooterHTML' => getCusomFooterHTML(), 'cssFilePath' => getCSSFilePath()];
echo template(file_get_contents('main.html'), $templateVars);
    /**
     * Print JavaScript settings for preview frame.
     *
     * @since 3.4.0
     */
    public function customize_preview_settings()
    {
        $post_values = $this->unsanitized_post_values(array('exclude_changeset' => true));
        $setting_validities = $this->validate_setting_values($post_values);
        $exported_setting_validities = array_map(array($this, 'prepare_setting_validity_for_js'), $setting_validities);
        // Note that the REQUEST_URI is not passed into home_url() since this breaks subdirectory installs.
        $self_url = empty($_SERVER['REQUEST_URI']) ? home_url('/') : esc_url_raw(wp_unslash($_SERVER['REQUEST_URI']));
        $state_query_params = array('customize_theme', 'customize_changeset_uuid', 'customize_messenger_channel');
        $self_url = remove_query_arg($state_query_params, $self_url);
        $allowed_urls = $this->get_allowed_urls();
        $allowed_hosts = array();
        foreach ($allowed_urls as $allowed_url) {
            $parsed = wp_parse_url($allowed_url);
            if (empty($parsed['host'])) {
                continue;
            }
            $host = $parsed['host'];
            if (!empty($parsed['port'])) {
                $host .= ':' . $parsed['port'];
            }
            $allowed_hosts[] = $host;
        }
        $switched_locale = switch_to_locale(get_user_locale());
        $l10n = array('shiftClickToEdit' => __('Shift-click to edit this element.'), 'linkUnpreviewable' => __('This link is not live-previewable.'), 'formUnpreviewable' => __('This form is not live-previewable.'));
        if ($switched_locale) {
            restore_previous_locale();
        }
        $settings = array('changeset' => array('uuid' => $this->_changeset_uuid), 'timeouts' => array('selectiveRefresh' => 250, 'keepAliveSend' => 1000), 'theme' => array('stylesheet' => $this->get_stylesheet(), 'active' => $this->is_theme_active()), 'url' => array('self' => $self_url, 'allowed' => array_map('esc_url_raw', $this->get_allowed_urls()), 'allowedHosts' => array_unique($allowed_hosts), 'isCrossDomain' => $this->is_cross_domain()), 'channel' => $this->messenger_channel, 'activePanels' => array(), 'activeSections' => array(), 'activeControls' => array(), 'settingValidities' => $exported_setting_validities, 'nonce' => current_user_can('customize') ? $this->get_nonces() : array(), 'l10n' => $l10n, '_dirty' => array_keys($post_values));
        foreach ($this->panels as $panel_id => $panel) {
            if ($panel->check_capabilities()) {
                $settings['activePanels'][$panel_id] = $panel->active();
                foreach ($panel->sections as $section_id => $section) {
                    if ($section->check_capabilities()) {
                        $settings['activeSections'][$section_id] = $section->active();
                    }
                }
            }
        }
        foreach ($this->sections as $id => $section) {
            if ($section->check_capabilities()) {
                $settings['activeSections'][$id] = $section->active();
            }
        }
        foreach ($this->controls as $id => $control) {
            if ($control->check_capabilities()) {
                $settings['activeControls'][$id] = $control->active();
            }
        }
        ?>
		<script type="text/javascript">
			var _wpCustomizeSettings = <?php 
        echo wp_json_encode($settings);
        ?>
;
			_wpCustomizeSettings.values = {};
			(function( v ) {
				<?php 
        /*
         * Serialize settings separately from the initial _wpCustomizeSettings
         * serialization in order to avoid a peak memory usage spike.
         * @todo We may not even need to export the values at all since the pane syncs them anyway.
         */
        foreach ($this->settings as $id => $setting) {
            if ($setting->check_capabilities()) {
                printf("v[%s] = %s;\n", wp_json_encode($id), wp_json_encode($setting->js_value()));
            }
        }
        ?>
			})( _wpCustomizeSettings.values );
		</script>
		<?php 
    }
    } elseif ($current_offset < 0) {
        $tzstring = 'UTC' . $current_offset;
    } else {
        $tzstring = 'UTC+' . $current_offset;
    }
}
?>
<th scope="row"><label for="timezone_string"><?php 
_e('Timezone');
?>
</label></th>
<td>

<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">
	<?php 
echo wp_timezone_choice($tzstring, get_user_locale());
?>
</select>

<p class="description" id="timezone-description"><?php 
_e('Choose either a city in the same timezone as you or a UTC timezone offset.');
?>
</p>

<p class="timezone-info">
	<span id="utc-time"><?php 
/* translators: 1: UTC abbreviation, 2: UTC time */
printf(__('Universal time (%1$s) is %2$s.'), '<abbr>' . __('UTC') . '</abbr>', '<code>' . date_i18n($timezone_format, false, true) . '</code>');
?>
</span>
<?php 
" />
		</div>
		<?php 
    if (!empty($docs_select)) {
        ?>
		<div id="documentation" class="hide-if-no-js"><label for="docs-list"><?php 
        _e('Documentation:');
        ?>
</label> <?php 
        echo $docs_select;
        ?>
 <input type="button" class="button" value="<?php 
        esc_attr_e('Look Up');
        ?>
 " onclick="if ( '' != jQuery('#docs-list').val() ) { window.open( 'https://api.wordpress.org/core/handbook/1.0/?function=' + escape( jQuery( '#docs-list' ).val() ) + '&amp;locale=<?php 
        echo urlencode(get_user_locale());
        ?>
&amp;version=<?php 
        echo urlencode(get_bloginfo('version'));
        ?>
&amp;redirect=true'); }" /></div>
		<?php 
    }
    if (is_writeable($real_file)) {
        ?>
	<?php 
        if (in_array($plugin, (array) get_option('active_plugins', array()))) {
            ?>
		<p><?php 
            _e('<strong>Warning:</strong> Making changes to active plugins is not recommended. If your changes cause a fatal error, the plugin will be automatically deactivated.');
            ?>
示例#17
0
/**
 * Returns a list from WordPress.org of popular importer plugins.
 *
 * @since 3.5.0
 *
 * @return array Importers with metadata for each.
 */
function wp_get_popular_importers()
{
    include ABSPATH . WPINC . '/version.php';
    // include an unmodified $wp_version
    $locale = get_user_locale();
    $cache_key = 'popular_importers_' . md5($locale . $wp_version);
    $popular_importers = get_site_transient($cache_key);
    if (!$popular_importers) {
        $url = add_query_arg(array('locale' => get_user_locale(), 'version' => $wp_version), 'http://api.wordpress.org/core/importers/1.1/');
        $options = array('user-agent' => 'WordPress/' . $wp_version . '; ' . home_url());
        $response = wp_remote_get($url, $options);
        $popular_importers = json_decode(wp_remote_retrieve_body($response), true);
        if (is_array($popular_importers)) {
            set_site_transient($cache_key, $popular_importers, 2 * DAY_IN_SECONDS);
        } else {
            $popular_importers = false;
        }
    }
    if (is_array($popular_importers)) {
        // If the data was received as translated, return it as-is.
        if ($popular_importers['translated']) {
            return $popular_importers['importers'];
        }
        foreach ($popular_importers['importers'] as &$importer) {
            $importer['description'] = translate($importer['description']);
            if ($importer['name'] != 'WordPress') {
                $importer['name'] = translate($importer['name']);
            }
        }
        return $popular_importers['importers'];
    }
    return array('blogger' => array('name' => __('Blogger'), 'description' => __('Import posts, comments, and users from a Blogger blog.'), 'plugin-slug' => 'blogger-importer', 'importer-id' => 'blogger'), 'wpcat2tag' => array('name' => __('Categories and Tags Converter'), 'description' => __('Convert existing categories to tags or tags to categories, selectively.'), 'plugin-slug' => 'wpcat2tag-importer', 'importer-id' => 'wp-cat2tag'), 'livejournal' => array('name' => __('LiveJournal'), 'description' => __('Import posts from LiveJournal using their API.'), 'plugin-slug' => 'livejournal-importer', 'importer-id' => 'livejournal'), 'movabletype' => array('name' => __('Movable Type and TypePad'), 'description' => __('Import posts and comments from a Movable Type or TypePad blog.'), 'plugin-slug' => 'movabletype-importer', 'importer-id' => 'mt'), 'opml' => array('name' => __('Blogroll'), 'description' => __('Import links in OPML format.'), 'plugin-slug' => 'opml-importer', 'importer-id' => 'opml'), 'rss' => array('name' => __('RSS'), 'description' => __('Import posts from an RSS feed.'), 'plugin-slug' => 'rss-importer', 'importer-id' => 'rss'), 'tumblr' => array('name' => __('Tumblr'), 'description' => __('Import posts &amp; media from Tumblr using their API.'), 'plugin-slug' => 'tumblr-importer', 'importer-id' => 'tumblr'), 'wordpress' => array('name' => 'WordPress', 'description' => __('Import posts, pages, comments, custom fields, categories, and tags from a WordPress export file.'), 'plugin-slug' => 'wordpress-importer', 'importer-id' => 'wordpress'));
}
             _deprecated_argument('options.php', '2.7.0', sprintf(__('The %s setting is unregistered. Unregistered settings are deprecated. See https://codex.wordpress.org/Settings_API'), '<code>' . $option . '</code>'));
         }
         $option = trim($option);
         $value = null;
         if (isset($_POST[$option])) {
             $value = $_POST[$option];
             if (!is_array($value)) {
                 $value = trim($value);
             }
             $value = wp_unslash($value);
         }
         update_option($option, $value);
     }
     // Switch translation in case WPLANG was changed.
     $language = get_option('WPLANG');
     $user_language = get_user_locale();
     if ($language === $user_language) {
         if ($language) {
             load_default_textdomain($language);
         } else {
             unload_textdomain('default');
         }
     }
 }
 /**
  * Handle settings errors and return to options page
  */
 // If no settings errors were registered add a general 'updated' message.
 if (!count(get_settings_errors())) {
     add_settings_error('general', 'settings_updated', __('Settings saved.'), 'updated');
 }
示例#19
0
/**
 * About This Version administration panel.
 *
 * @package WordPress
 * @subpackage Administration
 */
/** WordPress Administration Bootstrap */
require_once dirname(__FILE__) . '/admin.php';
if (!wp_is_mobile()) {
    wp_enqueue_style('wp-mediaelement');
    wp_enqueue_script('wp-mediaelement');
    wp_localize_script('mediaelement', '_wpmejsSettings', array('pluginPath' => includes_url('js/mediaelement/', 'relative'), 'pauseOtherPlayers' => ''));
}
$video_url = 'https://videopress.com/embed/AHz0Ca46?hd=true';
$lang_code = str_replace('_', '-', get_user_locale());
list($lang_code) = explode('-', $lang_code);
if ('en' !== $lang_code) {
    $video_url = add_query_arg('defaultLangCode', $lang_code, $video_url);
}
$title = __('About');
list($display_version) = explode('-', get_bloginfo('version'));
include ABSPATH . 'wp-admin/admin-header.php';
?>
	<div class="wrap about-wrap">
		<h1><?php 
printf(__('Welcome to WordPress&nbsp;%s'), $display_version);
?>
</h1>

		<p class="about-text"><?php 
示例#20
0
/**
 * Retrieves locale for the current request.
 *
 * @return string Locale code
 */
function get_current_locale()
{
    static $current_locale = null;
    if (is_null($current_locale)) {
        $locale = verify_param("locale", "/./", "");
        // Check if locale code passed in as a param is valid
        $locale_param_valid = $locale && locale_pattern_check($locale) && locale_is_available($locale);
        // Check if locale code stored in session data is valid
        $session_locale_valid = isset($_SESSION[SESSION_PREFIX . 'locale']) && locale_pattern_check($_SESSION[SESSION_PREFIX . 'locale']) && locale_is_available($_SESSION[SESSION_PREFIX . 'locale']);
        if ($locale_param_valid) {
            $_SESSION[SESSION_PREFIX . 'locale'] = $locale;
        } elseif ($session_locale_valid) {
            $locale = $_SESSION[SESSION_PREFIX . 'locale'];
        } else {
            $locale = get_user_locale();
        }
        $current_locale = $locale;
    }
    return $current_locale;
}
 public function test_user_id_argument_with_invalid_type()
 {
     $user_locale = get_user_locale('string');
     $this->assertSame(get_locale(), $user_locale);
 }
示例#22
0
         if (isset($_POST[$option])) {
             $value = $_POST[$option];
             if (!is_array($value)) {
                 $value = trim($value);
             }
             $value = wp_unslash($value);
         }
         update_option($option, $value);
     }
     /*
      * Switch translation in case WPLANG was changed.
      * The global $locale is used in get_locale() which is
      * used as a fallback in get_user_locale().
      */
     unset($GLOBALS['locale']);
     $user_language_new = get_user_locale();
     if ($user_language_old !== $user_language_new) {
         load_default_textdomain($user_language_new);
     }
 }
 /**
  * Handle settings errors and return to options page
  */
 // If no settings errors were registered add a general 'updated' message.
 if (!count(get_settings_errors())) {
     add_settings_error('general', 'settings_updated', __('Settings saved.'), 'updated');
 }
 set_transient('settings_errors', get_settings_errors(), 30);
 /**
  * Redirect back to the settings page that was submitted
  */
 /**
  *
  * @global array  $tabs
  * @global string $tab
  * @global int    $paged
  * @global string $type
  * @global string $term
  */
 public function prepare_items()
 {
     include ABSPATH . 'wp-admin/includes/plugin-install.php';
     global $tabs, $tab, $paged, $type, $term;
     wp_reset_vars(array('tab'));
     $paged = $this->get_pagenum();
     $per_page = 30;
     // These are the tabs which are shown on the page
     $tabs = array();
     if ('search' === $tab) {
         $tabs['search'] = __('Search Results');
     }
     if ($tab === 'beta' || false !== strpos(get_bloginfo('version'), '-')) {
         $tabs['beta'] = _x('Beta Testing', 'Plugin Installer');
     }
     $tabs['featured'] = _x('Featured', 'Plugin Installer');
     $tabs['popular'] = _x('Popular', 'Plugin Installer');
     $tabs['recommended'] = _x('Recommended', 'Plugin Installer');
     $tabs['favorites'] = _x('Favorites', 'Plugin Installer');
     if (current_user_can('upload_plugins')) {
         // No longer a real tab. Here for filter compatibility.
         // Gets skipped in get_views().
         $tabs['upload'] = __('Upload Plugin');
     }
     $nonmenu_tabs = array('plugin-information');
     // Valid actions to perform which do not have a Menu item.
     /**
      * Filters the tabs shown on the Plugin Install screen.
      *
      * @since 2.7.0
      *
      * @param array $tabs The tabs shown on the Plugin Install screen. Defaults include 'featured', 'popular',
      *                    'recommended', 'favorites', and 'upload'.
      */
     $tabs = apply_filters('install_plugins_tabs', $tabs);
     /**
      * Filters tabs not associated with a menu item on the Plugin Install screen.
      *
      * @since 2.7.0
      *
      * @param array $nonmenu_tabs The tabs that don't have a Menu item on the Plugin Install screen.
      */
     $nonmenu_tabs = apply_filters('install_plugins_nonmenu_tabs', $nonmenu_tabs);
     // If a non-valid menu tab has been selected, And it's not a non-menu action.
     if (empty($tab) || !isset($tabs[$tab]) && !in_array($tab, (array) $nonmenu_tabs)) {
         $tab = key($tabs);
     }
     $args = array('page' => $paged, 'per_page' => $per_page, 'fields' => array('last_updated' => true, 'icons' => true, 'active_installs' => true), 'locale' => get_user_locale(), 'installed_plugins' => $this->get_installed_plugin_slugs());
     switch ($tab) {
         case 'search':
             $type = isset($_REQUEST['type']) ? wp_unslash($_REQUEST['type']) : 'term';
             $term = isset($_REQUEST['s']) ? wp_unslash($_REQUEST['s']) : '';
             switch ($type) {
                 case 'tag':
                     $args['tag'] = sanitize_title_with_dashes($term);
                     break;
                 case 'term':
                     $args['search'] = $term;
                     break;
                 case 'author':
                     $args['author'] = $term;
                     break;
             }
             break;
         case 'featured':
             $args['fields']['group'] = true;
             $this->orderby = 'group';
             // No break!
         // No break!
         case 'popular':
         case 'new':
         case 'beta':
         case 'recommended':
             $args['browse'] = $tab;
             break;
         case 'favorites':
             $action = 'save_wporg_username_' . get_current_user_id();
             if (isset($_GET['_wpnonce']) && wp_verify_nonce(wp_unslash($_GET['_wpnonce']), $action)) {
                 $user = isset($_GET['user']) ? wp_unslash($_GET['user']) : get_user_option('wporg_favorites');
                 update_user_meta(get_current_user_id(), 'wporg_favorites', $user);
             } else {
                 $user = get_user_option('wporg_favorites');
             }
             if ($user) {
                 $args['user'] = $user;
             } else {
                 $args = false;
             }
             add_action('install_plugins_favorites', 'install_plugins_favorites_form', 9, 0);
             break;
         default:
             $args = false;
             break;
     }
     /**
      * Filters API request arguments for each Plugin Install screen tab.
      *
      * The dynamic portion of the hook name, `$tab`, refers to the plugin install tabs.
      * Default tabs include 'featured', 'popular', 'recommended', 'favorites', and 'upload'.
      *
      * @since 3.7.0
      *
      * @param array|bool $args Plugin Install API arguments.
      */
     $args = apply_filters("install_plugins_table_api_args_{$tab}", $args);
     if (!$args) {
         return;
     }
     $api = plugins_api('query_plugins', $args);
     if (is_wp_error($api)) {
         $this->error = $api;
         return;
     }
     $this->items = $api->plugins;
     if ($this->orderby) {
         uasort($this->items, array($this, 'order_callback'));
     }
     $this->set_pagination_args(array('total_items' => $api->info['results'], 'per_page' => $args['per_page']));
     if (isset($api->info['groups'])) {
         $this->groups = $api->info['groups'];
     }
 }
 /**
  * @ticket 38485
  */
 public function test_load_theme_textdomain_user_locale()
 {
     set_current_screen('dashboard');
     wp_set_current_user(self::$user_id);
     load_theme_textdomain('wp-tests-domain');
     set_current_screen('front');
     $this->assertSame(get_user_locale(), $this->locale);
 }
示例#25
0
 protected function check_user_data($user, $data, $context, $links)
 {
     $this->assertEquals($user->ID, $data['id']);
     $this->assertEquals($user->display_name, $data['name']);
     $this->assertEquals($user->user_url, $data['url']);
     $this->assertEquals($user->description, $data['description']);
     $this->assertEquals(get_author_posts_url($user->ID), $data['link']);
     $this->assertArrayHasKey('avatar_urls', $data);
     $this->assertEquals($user->user_nicename, $data['slug']);
     if ('edit' === $context) {
         $this->assertEquals($user->first_name, $data['first_name']);
         $this->assertEquals($user->last_name, $data['last_name']);
         $this->assertEquals($user->nickname, $data['nickname']);
         $this->assertEquals($user->user_email, $data['email']);
         $this->assertEquals((object) $user->allcaps, $data['capabilities']);
         $this->assertEquals((object) $user->caps, $data['extra_capabilities']);
         $this->assertEquals(date('c', strtotime($user->user_registered)), $data['registered_date']);
         $this->assertEquals($user->user_login, $data['username']);
         $this->assertEquals($user->roles, $data['roles']);
         $this->assertEquals(get_user_locale($user), $data['locale']);
     }
     if ('edit' !== $context) {
         $this->assertArrayNotHasKey('roles', $data);
         $this->assertArrayNotHasKey('capabilities', $data);
         $this->assertArrayNotHasKey('registered', $data);
         $this->assertArrayNotHasKey('first_name', $data);
         $this->assertArrayNotHasKey('last_name', $data);
         $this->assertArrayNotHasKey('nickname', $data);
         $this->assertArrayNotHasKey('extra_capabilities', $data);
         $this->assertArrayNotHasKey('username', $data);
     }
     $this->assertEqualSets(array('self', 'collection'), array_keys($links));
     $this->assertArrayNotHasKey('password', $data);
 }
/**
 * Retrieves plugin installer pages from the WordPress.org Plugins API.
 *
 * It is possible for a plugin to override the Plugin API result with three
 * filters. Assume this is for plugins, which can extend on the Plugin Info to
 * offer more choices. This is very powerful and must be used with care when
 * overriding the filters.
 *
 * The first filter, {@see 'plugins_api_args'}, is for the args and gives the action
 * as the second parameter. The hook for {@see 'plugins_api_args'} must ensure that
 * an object is returned.
 *
 * The second filter, {@see 'plugins_api'}, allows a plugin to override the WordPress.org
 * Plugin Install API entirely. If `$action` is 'query_plugins' or 'plugin_information',
 * an object MUST be passed. If `$action` is 'hot_tags' or 'hot_categories', an array MUST
 * be passed.
 *
 * Finally, the third filter, {@see 'plugins_api_result'}, makes it possible to filter the
 * response object or array, depending on the `$action` type.
 *
 * Supported arguments per action:
 *
 * | Argument Name        | query_plugins | plugin_information | hot_tags | hot_categories |
 * | -------------------- | :-----------: | :----------------: | :------: | :------------: |
 * | `$slug`              | No            |  Yes               | No       | No             |
 * | `$per_page`          | Yes           |  No                | No       | No             |
 * | `$page`              | Yes           |  No                | No       | No             |
 * | `$number`            | No            |  No                | Yes      | Yes            |
 * | `$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             |
 * | `$installed_plugins` | Yes           |  No                | No       | No             |
 * | `$is_ssl`            | Yes           |  Yes               | No       | No             |
 * | `$fields`            | Yes           |  Yes               | No       | No             |
 *
 * @since 2.7.0
 *
 * @param string       $action API action to perform: 'query_plugins', 'plugin_information',
 *                             'hot_tags' or 'hot_categories'.
 * @param array|object $args   {
 *     Optional. Array or object of arguments to serialize for the Plugin Info API.
 *
 *     @type string  $slug              The plugin slug. Default empty.
 *     @type int     $per_page          Number of plugins per page. Default 24.
 *     @type int     $page              Number of current page. Default 1.
 *     @type int     $number            Number of tags or categories to be queried.
 *     @type string  $search            A search term. Default empty.
 *     @type string  $tag               Tag to filter plugins. Default empty.
 *     @type string  $author            Username of an plugin author to filter plugins. Default empty.
 *     @type string  $user              Username to query for their favorites. Default empty.
 *     @type string  $browse            Browse view: 'popular', 'new', 'beta', 'recommended'.
 *     @type string  $locale            Locale to provide context-sensitive results. Default is the value
 *                                      of get_locale().
 *     @type string  $installed_plugins Installed plugins to provide context-sensitive results.
 *     @type bool    $is_ssl            Whether links should be returned with https or not. Default false.
 *     @type array   $fields            {
 *         Array of fields which should or should not be returned.
 *
 *         @type bool $short_description Whether to return the plugin short description. Default true.
 *         @type bool $description       Whether to return the plugin full description. Default false.
 *         @type bool $sections          Whether to return the plugin readme sections: description, installation,
 *                                       FAQ, screenshots, other notes, and changelog. Default false.
 *         @type bool $tested            Whether to return the 'Compatible up to' value. Default true.
 *         @type bool $requires          Whether to return the required WordPress version. Default true.
 *         @type bool $rating            Whether to return the rating in percent and total number of ratings.
 *                                       Default true.
 *         @type bool $ratings           Whether to return the number of rating for each star (1-5). Default true.
 *         @type bool $downloaded        Whether to return the download count. Default true.
 *         @type bool $downloadlink      Whether to return the download link for the package. Default true.
 *         @type bool $last_updated      Whether to return the date of the last update. Default true.
 *         @type bool $added             Whether to return the date when the plugin was added to the wordpress.org
 *                                       repository. Default true.
 *         @type bool $tags              Whether to return the assigned tags. Default true.
 *         @type bool $compatibility     Whether to return the WordPress compatibility list. Default true.
 *         @type bool $homepage          Whether to return the plugin homepage link. Default true.
 *         @type bool $versions          Whether to return the list of all available versions. Default false.
 *         @type bool $donate_link       Whether to return the donation link. Default true.
 *         @type bool $reviews           Whether to return the plugin reviews. Default false.
 *         @type bool $banners           Whether to return the banner images links. Default false.
 *         @type bool $icons             Whether to return the icon links. Default false.
 *         @type bool $active_installs   Whether to return the number of active installs. Default false.
 *         @type bool $group             Whether to return the assigned group. Default false.
 *         @type bool $contributors      Whether to return the list of contributors. 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/plugins_api/ function reference article}
 *         for more information on the make-up of possible return values depending on the value of `$action`.
 */
function plugins_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 the WordPress.org Plugin Install API arguments.
     *
     * Important: An object MUST be returned to this filter.
     *
     * @since 2.7.0
     *
     * @param object $args   Plugin API arguments.
     * @param string $action The type of information being requested from the Plugin Install API.
     */
    $args = apply_filters('plugins_api_args', $args, $action);
    /**
     * Filters the response for the current WordPress.org Plugin Install API request.
     *
     * Passing a non-false value will effectively short-circuit the WordPress.org API request.
     *
     * If `$action` is 'query_plugins' or 'plugin_information', an object MUST be passed.
     * If `$action` is 'hot_tags' or 'hot_categories', an array should be passed.
     *
     * @since 2.7.0
     *
     * @param false|object|array $result The result object or array. Default false.
     * @param string             $action The type of information being requested from the Plugin Install API.
     * @param object             $args   Plugin API arguments.
     */
    $res = apply_filters('plugins_api', false, $action, $args);
    if (false === $res) {
        $url = $http_url = 'http://api.wordpress.org/plugins/info/1.0/';
        if ($ssl = wp_http_supports(array('ssl'))) {
            $url = set_url_scheme($url, 'https');
        }
        $http_args = array('timeout' => 15, 'body' => array('action' => $action, 'request' => serialize($args)));
        $request = wp_remote_post($url, $http_args);
        if ($ssl && is_wp_error($request)) {
            trigger_error(__('An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.') . ' ' . __('(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)'), headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE);
            $request = wp_remote_post($http_url, $http_args);
        }
        if (is_wp_error($request)) {
            $res = new WP_Error('plugins_api_failed', __('An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.'), $request->get_error_message());
        } else {
            $res = maybe_unserialize(wp_remote_retrieve_body($request));
            if (!is_object($res) && !is_array($res)) {
                $res = new WP_Error('plugins_api_failed', __('An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.'), wp_remote_retrieve_body($request));
            }
        }
    } elseif (!is_wp_error($res)) {
        $res->external = true;
    }
    /**
     * Filters the Plugin Install API response results.
     *
     * @since 2.7.0
     *
     * @param object|WP_Error $res    Response object or WP_Error.
     * @param string          $action The type of information being requested from the Plugin Install API.
     * @param object          $args   Plugin API arguments.
     */
    return apply_filters('plugins_api_result', $res, $action, $args);
}
/**
 * Generic Iframe header for use with Thickbox
 *
 * @since 2.7.0
 *
 * @global string    $hook_suffix
 * @global string    $admin_body_class
 * @global WP_Locale $wp_locale
 *
 * @param string $title      Optional. Title of the Iframe page. Default empty.
 * @param bool   $deprecated Not used.
 */
function iframe_header($title = '', $deprecated = false)
{
    show_admin_bar(false);
    global $hook_suffix, $admin_body_class, $wp_locale;
    $admin_body_class = preg_replace('/[^a-z0-9_-]+/i', '-', $hook_suffix);
    $current_screen = get_current_screen();
    @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
    _wp_admin_html_begin();
    ?>
<title><?php 
    bloginfo('name');
    ?>
 &rsaquo; <?php 
    echo $title;
    ?>
 &#8212; <?php 
    _e('WordPress');
    ?>
</title>
<?php 
    wp_enqueue_style('colors');
    ?>
<script type="text/javascript">
addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
function tb_close(){var win=window.dialogArguments||opener||parent||top;win.tb_remove();}
var ajaxurl = '<?php 
    echo admin_url('admin-ajax.php', 'relative');
    ?>
',
	pagenow = '<?php 
    echo $current_screen->id;
    ?>
',
	typenow = '<?php 
    echo $current_screen->post_type;
    ?>
',
	adminpage = '<?php 
    echo $admin_body_class;
    ?>
',
	thousandsSeparator = '<?php 
    echo addslashes($wp_locale->number_format['thousands_sep']);
    ?>
',
	decimalPoint = '<?php 
    echo addslashes($wp_locale->number_format['decimal_point']);
    ?>
',
	isRtl = <?php 
    echo (int) is_rtl();
    ?>
;
</script>
<?php 
    /** This action is documented in wp-admin/admin-header.php */
    do_action('admin_enqueue_scripts', $hook_suffix);
    /** This action is documented in wp-admin/admin-header.php */
    do_action("admin_print_styles-{$hook_suffix}");
    /** This action is documented in wp-admin/admin-header.php */
    do_action('admin_print_styles');
    /** This action is documented in wp-admin/admin-header.php */
    do_action("admin_print_scripts-{$hook_suffix}");
    /** This action is documented in wp-admin/admin-header.php */
    do_action('admin_print_scripts');
    /** This action is documented in wp-admin/admin-header.php */
    do_action("admin_head-{$hook_suffix}");
    /** This action is documented in wp-admin/admin-header.php */
    do_action('admin_head');
    $admin_body_class .= ' locale-' . sanitize_html_class(strtolower(str_replace('_', '-', get_user_locale())));
    if (is_rtl()) {
        $admin_body_class .= ' rtl';
    }
    ?>
</head>
<?php 
    /** This filter is documented in wp-admin/admin-header.php */
    $admin_body_classes = apply_filters('admin_body_class', '');
    ?>
<body<?php 
    /**
     * @global string $body_id
     */
    if (isset($GLOBALS['body_id'])) {
        echo ' id="' . $GLOBALS['body_id'] . '"';
    }
    ?>
 class="wp-admin wp-core-ui no-js iframe <?php 
    echo $admin_body_classes . ' ' . $admin_body_class;
    ?>
">
<script type="text/javascript">
(function(){
var c = document.body.className;
c = c.replace(/no-js/, 'js');
document.body.className = c;
})();
</script>
<?php 
}
示例#28
0
文件: user.php 项目: kucrut/wordpress
/**
 * Update a user in the database.
 *
 * It is possible to update a user's password by specifying the 'user_pass'
 * value in the $userdata parameter array.
 *
 * If current user's password is being updated, then the cookies will be
 * cleared.
 *
 * @since 2.0.0
 *
 * @see wp_insert_user() For what fields can be set in $userdata.
 *
 * @param mixed $userdata An array of user data or a user object of type stdClass or WP_User.
 * @return int|WP_Error The updated user's ID or a WP_Error object if the user could not be updated.
 */
function wp_update_user($userdata)
{
    if ($userdata instanceof stdClass) {
        $userdata = get_object_vars($userdata);
    } elseif ($userdata instanceof WP_User) {
        $userdata = $userdata->to_array();
    }
    $ID = isset($userdata['ID']) ? (int) $userdata['ID'] : 0;
    if (!$ID) {
        return new WP_Error('invalid_user_id', __('Invalid user ID.'));
    }
    // First, get all of the original fields
    $user_obj = get_userdata($ID);
    if (!$user_obj) {
        return new WP_Error('invalid_user_id', __('Invalid user ID.'));
    }
    $user = $user_obj->to_array();
    // Add additional custom fields
    foreach (_get_additional_user_keys($user_obj) as $key) {
        $user[$key] = get_user_meta($ID, $key, true);
    }
    // Escape data pulled from DB.
    $user = add_magic_quotes($user);
    if (!empty($userdata['user_pass']) && $userdata['user_pass'] !== $user_obj->user_pass) {
        // If password is changing, hash it now
        $plaintext_pass = $userdata['user_pass'];
        $userdata['user_pass'] = wp_hash_password($userdata['user_pass']);
        /**
         * Filters whether to send the password change email.
         *
         * @since 4.3.0
         *
         * @see wp_insert_user() For `$user` and `$userdata` fields.
         *
         * @param bool  $send     Whether to send the email.
         * @param array $user     The original user array.
         * @param array $userdata The updated user array.
         *
         */
        $send_password_change_email = apply_filters('send_password_change_email', true, $user, $userdata);
    }
    if (isset($userdata['user_email']) && $user['user_email'] !== $userdata['user_email']) {
        /**
         * Filters whether to send the email change email.
         *
         * @since 4.3.0
         *
         * @see wp_insert_user() For `$user` and `$userdata` fields.
         *
         * @param bool  $send     Whether to send the email.
         * @param array $user     The original user array.
         * @param array $userdata The updated user array.
         *
         */
        $send_email_change_email = apply_filters('send_email_change_email', true, $user, $userdata);
    }
    wp_cache_delete($user['user_email'], 'useremail');
    wp_cache_delete($user['user_nicename'], 'userslugs');
    // Merge old and new fields with new fields overwriting old ones.
    $userdata = array_merge($user, $userdata);
    $user_id = wp_insert_user($userdata);
    if (!is_wp_error($user_id)) {
        $blog_name = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
        $switched_locale = false;
        if (!empty($send_password_change_email) || !empty($send_email_change_email)) {
            $switched_locale = switch_to_locale(get_user_locale($user_id));
        }
        if (!empty($send_password_change_email)) {
            /* translators: Do not translate USERNAME, ADMIN_EMAIL, EMAIL, SITENAME, SITEURL: those are placeholders. */
            $pass_change_text = __('Hi ###USERNAME###,

This notice confirms that your password was changed on ###SITENAME###.

If you did not change your password, please contact the Site Administrator at
###ADMIN_EMAIL###

This email has been sent to ###EMAIL###

Regards,
All at ###SITENAME###
###SITEURL###');
            $pass_change_email = array('to' => $user['user_email'], 'subject' => __('[%s] Notice of Password Change'), 'message' => $pass_change_text, 'headers' => '');
            /**
             * Filters the contents of the email sent when the user's password is changed.
             *
             * @since 4.3.0
             *
             * @param array $pass_change_email {
             *            Used to build wp_mail().
             *            @type string $to      The intended recipients. Add emails in a comma separated string.
             *            @type string $subject The subject of the email.
             *            @type string $message The content of the email.
             *                The following strings have a special meaning and will get replaced dynamically:
             *                - ###USERNAME###    The current user's username.
             *                - ###ADMIN_EMAIL### The admin email in case this was unexpected.
             *                - ###EMAIL###       The old email.
             *                - ###SITENAME###    The name of the site.
             *                - ###SITEURL###     The URL to the site.
             *            @type string $headers Headers. Add headers in a newline (\r\n) separated string.
             *        }
             * @param array $user     The original user array.
             * @param array $userdata The updated user array.
             *
             */
            $pass_change_email = apply_filters('password_change_email', $pass_change_email, $user, $userdata);
            $pass_change_email['message'] = str_replace('###USERNAME###', $user['user_login'], $pass_change_email['message']);
            $pass_change_email['message'] = str_replace('###ADMIN_EMAIL###', get_option('admin_email'), $pass_change_email['message']);
            $pass_change_email['message'] = str_replace('###EMAIL###', $user['user_email'], $pass_change_email['message']);
            $pass_change_email['message'] = str_replace('###SITENAME###', $blog_name, $pass_change_email['message']);
            $pass_change_email['message'] = str_replace('###SITEURL###', home_url(), $pass_change_email['message']);
            wp_mail($pass_change_email['to'], sprintf($pass_change_email['subject'], $blog_name), $pass_change_email['message'], $pass_change_email['headers']);
        }
        if (!empty($send_email_change_email)) {
            /* translators: Do not translate USERNAME, ADMIN_EMAIL, EMAIL, SITENAME, SITEURL: those are placeholders. */
            $email_change_text = __('Hi ###USERNAME###,

This notice confirms that your email was changed on ###SITENAME###.

If you did not change your email, please contact the Site Administrator at
###ADMIN_EMAIL###

This email has been sent to ###EMAIL###

Regards,
All at ###SITENAME###
###SITEURL###');
            $email_change_email = array('to' => $user['user_email'], 'subject' => __('[%s] Notice of Email Change'), 'message' => $email_change_text, 'headers' => '');
            /**
             * Filters the contents of the email sent when the user's email is changed.
             *
             * @since 4.3.0
             *
             * @param array $email_change_email {
             *            Used to build wp_mail().
             *            @type string $to      The intended recipients.
             *            @type string $subject The subject of the email.
             *            @type string $message The content of the email.
             *                The following strings have a special meaning and will get replaced dynamically:
             *                - ###USERNAME###    The current user's username.
             *                - ###ADMIN_EMAIL### The admin email in case this was unexpected.
             *                - ###EMAIL###       The old email.
             *                - ###SITENAME###    The name of the site.
             *                - ###SITEURL###     The URL to the site.
             *            @type string $headers Headers.
             *        }
             * @param array $user The original user array.
             * @param array $userdata The updated user array.
             */
            $email_change_email = apply_filters('email_change_email', $email_change_email, $user, $userdata);
            $email_change_email['message'] = str_replace('###USERNAME###', $user['user_login'], $email_change_email['message']);
            $email_change_email['message'] = str_replace('###ADMIN_EMAIL###', get_option('admin_email'), $email_change_email['message']);
            $email_change_email['message'] = str_replace('###EMAIL###', $user['user_email'], $email_change_email['message']);
            $email_change_email['message'] = str_replace('###SITENAME###', $blog_name, $email_change_email['message']);
            $email_change_email['message'] = str_replace('###SITEURL###', home_url(), $email_change_email['message']);
            wp_mail($email_change_email['to'], sprintf($email_change_email['subject'], $blog_name), $email_change_email['message'], $email_change_email['headers']);
        }
        if ($switched_locale) {
            restore_previous_locale();
        }
    }
    // Update the cookies if the password changed.
    $current_user = wp_get_current_user();
    if ($current_user->ID == $ID) {
        if (isset($plaintext_pass)) {
            wp_clear_auth_cookie();
            // Here we calculate the expiration length of the current auth cookie and compare it to the default expiration.
            // If it's greater than this, then we know the user checked 'Remember Me' when they logged in.
            $logged_in_cookie = wp_parse_auth_cookie('', 'logged_in');
            /** This filter is documented in wp-includes/pluggable.php */
            $default_cookie_life = apply_filters('auth_cookie_expiration', 2 * DAY_IN_SECONDS, $ID, false);
            $remember = $logged_in_cookie['expiration'] - time() > $default_cookie_life;
            wp_set_auth_cookie($ID, $remember);
        }
    }
    return $user_id;
}
 public function test_multiple_switches_to_site_locale_and_user_locale()
 {
     global $wp_locale_switcher;
     $site_locale = get_locale();
     $user_id = $this->factory()->user->create(array('role' => 'administrator', 'locale' => 'en_GB'));
     wp_set_current_user($user_id);
     set_current_screen('dashboard');
     $locale_switcher = clone $wp_locale_switcher;
     $wp_locale_switcher = new WP_Locale_Switcher();
     $wp_locale_switcher->init();
     $user_locale = get_user_locale();
     load_default_textdomain($user_locale);
     require_once DIR_TESTDATA . '/plugins/internationalized-plugin.php';
     switch_to_locale('de_DE');
     switch_to_locale($site_locale);
     $expected = i18n_plugin_test();
     restore_current_locale();
     $wp_locale_switcher = $locale_switcher;
     set_current_screen('front');
     $this->assertSame('en_US', get_locale());
     $this->assertSame('This is a dummy plugin', $expected);
 }
 /**
  * Prepares a single user output for response.
  *
  * @since 4.7.0
  * @access public
  *
  * @param WP_User         $user    User object.
  * @param WP_REST_Request $request Request object.
  * @return WP_REST_Response Response object.
  */
 public function prepare_item_for_response($user, $request)
 {
     $data = array();
     $schema = $this->get_item_schema();
     if (!empty($schema['properties']['id'])) {
         $data['id'] = $user->ID;
     }
     if (!empty($schema['properties']['username'])) {
         $data['username'] = $user->user_login;
     }
     if (!empty($schema['properties']['name'])) {
         $data['name'] = $user->display_name;
     }
     if (!empty($schema['properties']['first_name'])) {
         $data['first_name'] = $user->first_name;
     }
     if (!empty($schema['properties']['last_name'])) {
         $data['last_name'] = $user->last_name;
     }
     if (!empty($schema['properties']['email'])) {
         $data['email'] = $user->user_email;
     }
     if (!empty($schema['properties']['url'])) {
         $data['url'] = $user->user_url;
     }
     if (!empty($schema['properties']['description'])) {
         $data['description'] = $user->description;
     }
     if (!empty($schema['properties']['link'])) {
         $data['link'] = get_author_posts_url($user->ID, $user->user_nicename);
     }
     if (!empty($schema['properties']['locale'])) {
         $data['locale'] = get_user_locale($user);
     }
     if (!empty($schema['properties']['nickname'])) {
         $data['nickname'] = $user->nickname;
     }
     if (!empty($schema['properties']['slug'])) {
         $data['slug'] = $user->user_nicename;
     }
     if (!empty($schema['properties']['roles'])) {
         // Defensively call array_values() to ensure an array is returned.
         $data['roles'] = array_values($user->roles);
     }
     if (!empty($schema['properties']['registered_date'])) {
         $data['registered_date'] = date('c', strtotime($user->user_registered));
     }
     if (!empty($schema['properties']['capabilities'])) {
         $data['capabilities'] = (object) $user->allcaps;
     }
     if (!empty($schema['properties']['extra_capabilities'])) {
         $data['extra_capabilities'] = (object) $user->caps;
     }
     if (!empty($schema['properties']['avatar_urls'])) {
         $data['avatar_urls'] = rest_get_avatar_urls($user->user_email);
     }
     if (!empty($schema['properties']['meta'])) {
         $data['meta'] = $this->meta->get_value($user->ID, $request);
     }
     $context = !empty($request['context']) ? $request['context'] : 'embed';
     $data = $this->add_additional_fields_to_object($data, $request);
     $data = $this->filter_response_by_context($data, $context);
     // Wrap the data in a response object.
     $response = rest_ensure_response($data);
     $response->add_links($this->prepare_links($user));
     /**
      * Filters user data returned from the REST API.
      *
      * @since 4.7.0
      *
      * @param WP_REST_Response $response The response object.
      * @param object           $user     User object used to create response.
      * @param WP_REST_Request  $request  Request object.
      */
     return apply_filters('rest_prepare_user', $response, $user, $request);
 }