Update WP and plugins

This commit is contained in:
Oliver Davies 2019-04-16 20:56:22 +01:00
parent 10a4713229
commit 1fb77fc4ff
864 changed files with 101724 additions and 78262 deletions

View file

@ -270,7 +270,7 @@ function esc_attr__( $text, $domain = 'default' ) {
* Retrieve the translation of $text and escapes it for safe use in HTML output.
*
* If there is no translation, or the text domain isn't loaded, the original text
* is escaped and returned..
* is escaped and returned.
*
* @since 2.8.0
*
@ -448,7 +448,7 @@ function _n( $single, $plural, $number, $domain = 'default' ) {
* Default 'default'.
* @return string The translated singular or plural form.
*/
function _nx($single, $plural, $number, $context, $domain = 'default') {
function _nx( $single, $plural, $number, $context, $domain = 'default' ) {
$translations = get_translations_for_domain( $domain );
$translation = $translations->translate_plural( $single, $plural, $number, $context );
@ -497,7 +497,14 @@ function _nx($single, $plural, $number, $context, $domain = 'default') {
* }
*/
function _n_noop( $singular, $plural, $domain = null ) {
return array( 0 => $singular, 1 => $plural, 'singular' => $singular, 'plural' => $plural, 'context' => null, 'domain' => $domain );
return array(
0 => $singular,
1 => $plural,
'singular' => $singular,
'plural' => $plural,
'context' => null,
'domain' => $domain,
);
}
/**
@ -509,8 +516,8 @@ function _n_noop( $singular, $plural, $domain = null ) {
* Example of a generic phrase which is disambiguated via the context parameter:
*
* $messages = array(
* 'people' => _nx_noop( '%s group', '%s groups', 'people', 'text-domain' ),
* 'animals' => _nx_noop( '%s group', '%s groups', 'animals', 'text-domain' ),
* 'people' => _nx_noop( '%s group', '%s groups', 'people', 'text-domain' ),
* 'animals' => _nx_noop( '%s group', '%s groups', 'animals', 'text-domain' ),
* );
* ...
* $message = $messages[ $type ];
@ -536,7 +543,15 @@ function _n_noop( $singular, $plural, $domain = null ) {
* }
*/
function _nx_noop( $singular, $plural, $context, $domain = null ) {
return array( 0 => $singular, 1 => $plural, 2 => $context, 'singular' => $singular, 'plural' => $plural, 'context' => $context, 'domain' => $domain );
return array(
0 => $singular,
1 => $plural,
2 => $context,
'singular' => $singular,
'plural' => $plural,
'context' => $context,
'domain' => $domain,
);
}
/**
@ -560,13 +575,15 @@ function _nx_noop( $singular, $plural, $context, $domain = null ) {
* @return string Either $single or $plural translated text.
*/
function translate_nooped_plural( $nooped_plural, $count, $domain = 'default' ) {
if ( $nooped_plural['domain'] )
if ( $nooped_plural['domain'] ) {
$domain = $nooped_plural['domain'];
}
if ( $nooped_plural['context'] )
if ( $nooped_plural['context'] ) {
return _nx( $nooped_plural['singular'], $nooped_plural['plural'], $count, $nooped_plural['context'], $domain );
else
} else {
return _n( $nooped_plural['singular'], $nooped_plural['plural'], $count, $domain );
}
}
/**
@ -580,8 +597,8 @@ function translate_nooped_plural( $nooped_plural, $count, $domain = 'default' )
*
* @since 1.5.0
*
* @global array $l10n An array of all currently loaded text domains.
* @global array $l10n_unloaded An array of all text domains that have been unloaded again.
* @global MO[] $l10n An array of all currently loaded text domains.
* @global MO[] $l10n_unloaded An array of all text domains that have been unloaded again.
*
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
* @param string $mofile Path to the .mo file.
@ -629,17 +646,22 @@ function load_textdomain( $domain, $mofile ) {
*/
$mofile = apply_filters( 'load_textdomain_mofile', $mofile, $domain );
if ( !is_readable( $mofile ) ) return false;
if ( ! is_readable( $mofile ) ) {
return false;
}
$mo = new MO();
if ( !$mo->import_from_file( $mofile ) ) return false;
if ( ! $mo->import_from_file( $mofile ) ) {
return false;
}
if ( isset( $l10n[$domain] ) )
$mo->merge_with( $l10n[$domain] );
if ( isset( $l10n[ $domain ] ) ) {
$mo->merge_with( $l10n[ $domain ] );
}
unset( $l10n_unloaded[ $domain ] );
$l10n[$domain] = &$mo;
$l10n[ $domain ] = &$mo;
return true;
}
@ -649,8 +671,8 @@ function load_textdomain( $domain, $mofile ) {
*
* @since 3.0.0
*
* @global array $l10n An array of all currently loaded text domains.
* @global array $l10n_unloaded An array of all text domains that have been unloaded again.
* @global MO[] $l10n An array of all currently loaded text domains.
* @global MO[] $l10n_unloaded An array of all text domains that have been unloaded again.
*
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
* @return bool Whether textdomain was unloaded.
@ -685,8 +707,8 @@ function unload_textdomain( $domain ) {
*/
do_action( 'unload_textdomain', $domain );
if ( isset( $l10n[$domain] ) ) {
unset( $l10n[$domain] );
if ( isset( $l10n[ $domain ] ) ) {
unset( $l10n[ $domain ] );
$l10n_unloaded[ $domain ] = true;
@ -719,7 +741,7 @@ function load_default_textdomain( $locale = null ) {
$return = load_textdomain( 'default', WP_LANG_DIR . "/$locale.mo" );
if ( ( is_multisite() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) ) && ! file_exists( WP_LANG_DIR . "/admin-$locale.mo" ) ) {
if ( ( is_multisite() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) ) && ! file_exists( WP_LANG_DIR . "/admin-$locale.mo" ) ) {
load_textdomain( 'default', WP_LANG_DIR . "/ms-$locale.mo" );
return $return;
}
@ -728,8 +750,9 @@ function load_default_textdomain( $locale = null ) {
load_textdomain( 'default', WP_LANG_DIR . "/admin-$locale.mo" );
}
if ( is_network_admin() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) )
if ( is_network_admin() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) ) {
load_textdomain( 'default', WP_LANG_DIR . "/admin-network-$locale.mo" );
}
return $return;
}
@ -864,8 +887,9 @@ function load_theme_textdomain( $domain, $path = false ) {
* @return bool True when the theme textdomain is successfully loaded, false otherwise.
*/
function load_child_theme_textdomain( $domain, $path = false ) {
if ( ! $path )
if ( ! $path ) {
$path = get_stylesheet_directory();
}
return load_theme_textdomain( $domain, $path );
}
@ -874,17 +898,18 @@ function load_child_theme_textdomain( $domain, $path = false ) {
*
* @since 5.0.0
* @since 5.0.2 Uses load_script_translations() to load translation data.
* @since 5.1.0 The `$domain` parameter was made optional.
*
* @see WP_Scripts::set_translations()
*
* @param string $handle Name of the script to register a translation domain to.
* @param string $domain The text domain.
* @param string $domain Optional. Text domain. Default 'default'.
* @param string $path Optional. The full file path to the directory containing translation files.
*
* @return false|string False if the script textdomain could not be loaded, the translated strings
* in JSON encoding otherwise.
*/
function load_script_textdomain( $handle, $domain, $path = null ) {
function load_script_textdomain( $handle, $domain = 'default', $path = null ) {
$wp_scripts = wp_scripts();
if ( ! isset( $wp_scripts->registered[ $handle ] ) ) {
@ -1051,7 +1076,7 @@ function load_script_translations( $file, $handle, $domain ) {
* @access private
*
* @see get_translations_for_domain()
* @global array $l10n_unloaded An array of all text domains that have been unloaded again.
* @global MO[] $l10n_unloaded An array of all text domains that have been unloaded again.
*
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
* @return bool True when the textdomain is successfully loaded, false otherwise.
@ -1083,6 +1108,7 @@ function _load_textdomain_just_in_time( $domain ) {
* @access private
*
* @see _load_textdomain_just_in_time()
* @staticvar array $available_translations
*
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
* @param bool $reset Whether to reset the internal cache. Used by the switch to locale functionality.
@ -1111,6 +1137,7 @@ function _get_path_to_translation( $domain, $reset = false ) {
* @access private
*
* @see _get_path_to_translation()
* @staticvar array $cached_mofiles
*
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
* @return string|false The path to the translation file or false if no translation file was found.
@ -1157,7 +1184,8 @@ function _get_path_to_translation_from_lang_dir( $domain ) {
*
* @since 2.8.0
*
* @global array $l10n
* @global MO[] $l10n
* @staticvar NOOP_Translations $noop_translations
*
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
* @return Translations|NOOP_Translations A Translations instance.
@ -1181,7 +1209,7 @@ function get_translations_for_domain( $domain ) {
*
* @since 3.0.0
*
* @global array $l10n
* @global MO[] $l10n
*
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
* @return bool Whether there are translations.
@ -1209,7 +1237,7 @@ function is_textdomain_loaded( $domain ) {
* @return string Translated role name on success, original name on failure.
*/
function translate_user_role( $name ) {
return translate_with_gettext_context( before_last_bar($name), 'User role' );
return translate_with_gettext_context( before_last_bar( $name ), 'User role' );
}
/**
@ -1261,20 +1289,24 @@ function get_available_languages( $dir = null ) {
* @return array Array of language data.
*/
function wp_get_installed_translations( $type ) {
if ( $type !== 'themes' && $type !== 'plugins' && $type !== 'core' )
if ( $type !== 'themes' && $type !== 'plugins' && $type !== 'core' ) {
return array();
}
$dir = 'core' === $type ? '' : "/$type";
if ( ! is_dir( WP_LANG_DIR ) )
if ( ! is_dir( WP_LANG_DIR ) ) {
return array();
}
if ( $dir && ! is_dir( WP_LANG_DIR . $dir ) )
if ( $dir && ! is_dir( WP_LANG_DIR . $dir ) ) {
return array();
}
$files = scandir( WP_LANG_DIR . $dir );
if ( ! $files )
if ( ! $files ) {
return array();
}
$language_data = array();
@ -1288,7 +1320,7 @@ function wp_get_installed_translations( $type ) {
if ( ! preg_match( '/(?:(.+)-)?([a-z]{2,3}(?:_[A-Z]{2})?(?:_[a-z0-9]+)?).po/', $file, $match ) ) {
continue;
}
if ( ! in_array( substr( $file, 0, -3 ) . '.mo', $files ) ) {
if ( ! in_array( substr( $file, 0, -3 ) . '.mo', $files ) ) {
continue;
}
@ -1310,12 +1342,15 @@ function wp_get_installed_translations( $type ) {
* @return array PO file headers.
*/
function wp_get_pomo_file_data( $po_file ) {
$headers = get_file_data( $po_file, array(
'POT-Creation-Date' => '"POT-Creation-Date',
'PO-Revision-Date' => '"PO-Revision-Date',
'Project-Id-Version' => '"Project-Id-Version',
'X-Generator' => '"X-Generator',
) );
$headers = get_file_data(
$po_file,
array(
'POT-Creation-Date' => '"POT-Creation-Date',
'PO-Revision-Date' => '"PO-Revision-Date',
'Project-Id-Version' => '"Project-Id-Version',
'X-Generator' => '"X-Generator',
)
);
foreach ( $headers as $header => $value ) {
// Remove possible contextual '\n' and closing double quote.
$headers[ $header ] = preg_replace( '~(\\\n)?"$~', '', $value );
@ -1329,6 +1364,7 @@ function wp_get_pomo_file_data( $po_file ) {
* @since 4.0.0
* @since 4.3.0 Introduced the `echo` argument.
* @since 4.7.0 Introduced the `show_option_site_default` argument.
* @since 5.1.0 Introduced the `show_option_en_us` argument.
*
* @see get_available_languages()
* @see wp_get_available_translations()
@ -1347,21 +1383,26 @@ function wp_get_pomo_file_data( $po_file ) {
* boolean equivalents. Default 1.
* @type bool $show_available_translations Whether to show available translations. Default true.
* @type bool $show_option_site_default Whether to show an option to fall back to the site's locale. Default false.
* @type bool $show_option_en_us Whether to show an option for English (United States). Default true.
* }
* @return string HTML content
*/
function wp_dropdown_languages( $args = array() ) {
$parsed_args = wp_parse_args( $args, array(
'id' => 'locale',
'name' => 'locale',
'languages' => array(),
'translations' => array(),
'selected' => '',
'echo' => 1,
'show_available_translations' => true,
'show_option_site_default' => false,
) );
$parsed_args = wp_parse_args(
$args,
array(
'id' => 'locale',
'name' => 'locale',
'languages' => array(),
'translations' => array(),
'selected' => '',
'echo' => 1,
'show_available_translations' => true,
'show_option_site_default' => false,
'show_option_en_us' => true,
)
);
// Bail if no ID or no name.
if ( ! $parsed_args['id'] || ! $parsed_args['name'] ) {
@ -1423,11 +1464,12 @@ function wp_dropdown_languages( $args = array() ) {
);
}
// Always show English.
$structure[] = sprintf(
'<option value="" lang="en" data-installed="1"%s>English (United States)</option>',
selected( '', $parsed_args['selected'], false )
);
if ( $parsed_args['show_option_en_us'] ) {
$structure[] = sprintf(
'<option value="" lang="en" data-installed="1"%s>English (United States)</option>',
selected( '', $parsed_args['selected'], false )
);
}
// List installed languages.
foreach ( $languages as $language ) {