From 0470fb90ea2b3bbba849a92ee54fc37fd415b146 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Sat, 13 Feb 2010 07:28:19 +0000 Subject: [PATCH] Deprecate old l10n and sanitization APIs. Deprecate __ngettext() for _n(), __ngettext_noop() for _n_noop(), translate_with_context() for _x(). Deprecate sanitize_url for esc_url_raw, js_escape for esc_js, wp_specialchars for esc_html, attribute_escape for esc_attr. See #11388 git-svn-id: https://develop.svn.wordpress.org/trunk@13096 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/deprecated.php | 121 ++++++++++++++++++++++++++++++++++++- wp-includes/formatting.php | 65 -------------------- wp-includes/l10n.php | 39 +----------- 3 files changed, 122 insertions(+), 103 deletions(-) diff --git a/wp-includes/deprecated.php b/wp-includes/deprecated.php index 301a8466b8..9440a571b2 100644 --- a/wp-includes/deprecated.php +++ b/wp-includes/deprecated.php @@ -1862,7 +1862,26 @@ function make_url_footnote( $content ) { */ function _c( $text, $domain = 'default' ) { _deprecated_function( __FUNCTION__, '2.9', '_x()' ); - return translate_with_context( $text, $domain ); + return before_last_bar( translate( $text, $domain ) ); +} + +/** + * Translates $text like translate(), but assumes that the text + * contains a context after its last vertical bar. + * + * @since 2.5 + * @uses translate() + * @deprecated 3.0.0 + * @deprecated Use _x() + * @see _x() + * + * @param string $text Text to translate + * @param string $domain Domain to retrieve the translated text + * @return string Translated text + */ +function translate_with_context( $text, $domain = 'default' ) { + _deprecated_function( __FUNCTION__, '2.9', '_x()' ); + return before_last_bar( translate( $text, $domain ) ); } /** @@ -1882,6 +1901,35 @@ function _nc( $single, $plural, $number, $domain = 'default' ) { return before_last_bar( _n( $single, $plural, $number, $domain ) ); } +/** + * Retrieve the plural or single form based on the amount. + * + * @since 1.2.0 + * @deprecated 2.8.0 + * @deprecated Use _n() + * @see _n() + */ +function __ngettext() { + _deprecated_function( __FUNCTION__, '2.8', '_n()' ); + $args = func_get_args(); + return call_user_func_array('_n', $args); +} + +/** + * Register plural strings in POT file, but don't translate them. + * + * @since 2.5 + * @deprecated 2.8.0 + * @deprecated Use _n_noop() + * @see _n_noop() + */ +function __ngettext_noop() { + _deprecated_function( __FUNCTION__, '2.8', '_n_noop()' ); + $args = func_get_args(); + return call_user_func_array('_n_noop', $args); + +} + /** * Retrieve all autoload options, or all options if no autoloaded ones exist. * @@ -2074,4 +2122,73 @@ function get_link($bookmark_id, $output = OBJECT, $filter = 'raw') { return get_bookmark($bookmark_id, $output, $filter); } -?> +/** + * Performs esc_url() for database or redirect usage. + * + * @since 2.3.1 + * @deprecated 2.8.0 + * @deprecated Use esc_url_raw() + * @see esc_url_raw() + * + * @param string $url The URL to be cleaned. + * @param array $protocols An array of acceptable protocols. + * @return string The cleaned URL. + */ +function sanitize_url( $url, $protocols = null ) { + _deprecated_function( __FUNCTION__, '2.8', 'esc_url_raw()' ); + return clean_url( $url, $protocols, 'db' ); +} + +/** + * Escape single quotes, specialchar double quotes, and fix line endings. + * + * The filter 'js_escape' is also applied by esc_js() + * + * @since 2.0.4 + * @deprecated 2.8.0 + * @deprecated Use esc_js() + * @see esc_js() + * + * @param string $text The text to be escaped. + * @return string Escaped text. + */ +function js_escape( $text ) { + _deprecated_function( __FUNCTION__, '2.8', 'esc_js()' ); + return esc_js( $text ); +} + +/** + * Escaping for HTML blocks. + * + * @deprecated 2.8.0 + * @deprecated Use esc_html() + * @see esc_html() + */ +function wp_specialchars( $string, $quote_style = ENT_NOQUOTES, $charset = false, $double_encode = false ) { + _deprecated_function( __FUNCTION__, '2.8', 'esc_html()' ); + if ( func_num_args() > 1 ) { // Maintain backwards compat for people passing additional args + $args = func_get_args(); + return call_user_func_array( '_wp_specialchars', $args ); + } else { + return esc_html( $string ); + } +} + + +/** + * Escaping for HTML attributes. + * + * @since 2.0.6 + * @deprecated 2.8.0 + * @deprecated Use esc_attr() + * @see esc_attr() + * + * @param string $text + * @return string + */ +function attribute_escape( $text ) { + _deprecated_function( __FUNCTION__, '2.8', 'esc_attr()' ); + return esc_attr( $text ); +} + +?> \ No newline at end of file diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index 5069c8786f..813458f9cf 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -1398,7 +1398,6 @@ function wp_rel_nofollow_callback( $matches ) { return ""; } - /** * Convert one smiley code to the icon graphic file equivalent. * @@ -1429,7 +1428,6 @@ function translate_smiley($smiley) { return " $smiley_masked "; } - /** * Convert text equivalent of smilies to images. * @@ -2226,7 +2224,6 @@ function esc_sql( $sql ) { return $wpdb->escape( $sql ); } - /** * Checks and cleans a URL. * @@ -2264,22 +2261,6 @@ function esc_url_raw( $url, $protocols = null ) { return clean_url( $url, $protocols, 'db' ); } -/** - * Performs esc_url() for database or redirect usage. - * - * @see esc_url() - * @deprecated 2.8.0 - * - * @since 2.3.1 - * - * @param string $url The URL to be cleaned. - * @param array $protocols An array of acceptable protocols. - * @return string The cleaned URL. - */ -function sanitize_url( $url, $protocols = null ) { - return clean_url( $url, $protocols, 'db' ); -} - /** * Convert entities, while preserving already-encoded entities. * @@ -2317,23 +2298,6 @@ function esc_js( $text ) { return apply_filters( 'js_escape', $safe_text, $text ); } -/** - * Escape single quotes, specialchar double quotes, and fix line endings. - * - * The filter 'js_escape' is also applied by esc_js() - * - * @since 2.0.4 - * - * @deprecated 2.8.0 - * @see esc_js() - * - * @param string $text The text to be escaped. - * @return string Escaped text. - */ -function js_escape( $text ) { - return esc_js( $text ); -} - /** * Escaping for HTML blocks. * @@ -2348,20 +2312,6 @@ function esc_html( $text ) { return apply_filters( 'esc_html', $safe_text, $text ); } -/** - * Escaping for HTML blocks - * @deprecated 2.8.0 - * @see esc_html() - */ -function wp_specialchars( $string, $quote_style = ENT_NOQUOTES, $charset = false, $double_encode = false ) { - if ( func_num_args() > 1 ) { // Maintain backwards compat for people passing additional args - $args = func_get_args(); - return call_user_func_array( '_wp_specialchars', $args ); - } else { - return esc_html( $string ); - } -} - /** * Escaping for HTML attributes. * @@ -2376,21 +2326,6 @@ function esc_attr( $text ) { return apply_filters( 'attribute_escape', $safe_text, $text ); } -/** - * Escaping for HTML attributes. - * - * @since 2.0.6 - * - * @deprecated 2.8.0 - * @see esc_attr() - * - * @param string $text - * @return string - */ -function attribute_escape( $text ) { - return esc_attr( $text ); -} - /** * Escape a HTML tag name. * diff --git a/wp-includes/l10n.php b/wp-includes/l10n.php index 50964410a4..5e37f5052d 100644 --- a/wp-includes/l10n.php +++ b/wp-includes/l10n.php @@ -77,21 +77,6 @@ function before_last_bar( $string ) { return substr( $string, 0, $last_bar ); } -/** - * Translates $text like translate(), but assumes that the text - * contains a context after its last vertical bar. - * - * @since 2.5 - * @uses translate() - * - * @param string $text Text to translate - * @param string $domain Domain to retrieve the translated text - * @return string Translated text - */ -function translate_with_context( $text, $domain = 'default' ) { - return before_last_bar( translate( $text, $domain ) ); -} - function translate_with_gettext_context( $text, $context, $domain = 'default' ) { $translations = &get_translations_for_domain( $domain ); return apply_filters( 'gettext_with_context', $translations->translate( $text, $context ), $text, $context, $domain ); @@ -192,16 +177,15 @@ function esc_html_e( $text, $domain = 'default' ) { * found in more than two places but with different translated context. * * By including the context in the pot file translators can translate the two - * string differently + * string differently. * - * @since 2.8 + * @since 2.8.0 * * @param string $text Text to translate * @param string $context Context information for the translators * @param string $domain Optional. Domain to retrieve the translated text * @return string Translated context string without pipe */ - function _x( $single, $context, $domain = 'default' ) { return translate_with_gettext_context( $single, $context, $domain ); } @@ -214,12 +198,6 @@ function esc_html_x( $single, $context, $domain = 'default' ) { return esc_html( translate_with_gettext_context( $single, $context, $domain ) ); } -function __ngettext() { - _deprecated_function( __FUNCTION__, '2.8', '_n()' ); - $args = func_get_args(); - return call_user_func_array('_n', $args); -} - /** * Retrieve the plural or single form based on the amount. * @@ -231,7 +209,7 @@ function __ngettext() { * to the 'ngettext' filter hook along with the same parameters. The expected * type will be a string. * - * @since 1.2.0 + * @since 2.8.0 * @uses $l10n Gets list of domain translated string (gettext_reader) objects * @uses apply_filters() Calls 'ngettext' hook on domains text returned, * along with $single, $plural, and $number parameters. Expected to return string. @@ -261,16 +239,6 @@ function _nx($single, $plural, $number, $context, $domain = 'default') { return apply_filters( 'ngettext_with_context', $translation, $single, $plural, $number, $context, $domain ); } -/** - * @deprecated Use _n_noop() - */ -function __ngettext_noop() { - _deprecated_function( __FUNCTION__, '2.8', '_n_noop()' ); - $args = func_get_args(); - return call_user_func_array('_n_noop', $args); - -} - /** * Register plural strings in POT file, but don't translate them. * @@ -304,7 +272,6 @@ function _nx_noop( $single, $plural, $context ) { return array( $single, $plural, $context ); } - /** * Loads a MO file into the domain $domain. *