From 2249c69021cd0da2b81aadca36875fb0a65b3c20 Mon Sep 17 00:00:00 2001 From: ryan Date: Mon, 27 Apr 2009 21:58:04 +0000 Subject: [PATCH] attr(), _a(), _ea(), _xa() for shorthand attribute escaping. see #9650 git-svn-id: http://svn.automattic.com/wordpress/trunk@11103 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/categories.php | 8 ++++---- wp-includes/formatting.php | 19 +++++++++++++++++-- wp-includes/l10n.php | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/wp-admin/categories.php b/wp-admin/categories.php index 65358c186..9ef2e050c 100644 --- a/wp-admin/categories.php +++ b/wp-admin/categories.php @@ -144,7 +144,7 @@ endif; ?>
@@ -184,7 +184,7 @@ if ( $page_links ) - + @@ -224,7 +224,7 @@ if ( $page_links ) - + @@ -278,7 +278,7 @@ if ( $page_links )

-

+

diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index 145ee5ce2..ffaeee1b7 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -2073,17 +2073,32 @@ function js_escape($text) { /** * Escaping for HTML attributes. * - * @since 2.0.6 + * @since 2.8.0 * * @param string $text * @return string */ -function attribute_escape( $text ) { +function attr( $text ) { $safe_text = wp_check_invalid_utf8( $text ); $safe_text = wp_specialchars( $safe_text, ENT_QUOTES ); return apply_filters( 'attribute_escape', $safe_text, $text ); } +/** + * Escaping for HTML attributes. + * + * @since 2.0.6 + * + * @deprecated 2.8.0 + * @see attr() + * + * @param string $text + * @return string + */ +function attribute_escape( $text ) { + return attr( $text ); +} + /** * Escape a HTML tag name. * diff --git a/wp-includes/l10n.php b/wp-includes/l10n.php index 8310a5821..44ec2eae3 100644 --- a/wp-includes/l10n.php +++ b/wp-includes/l10n.php @@ -105,6 +105,22 @@ function __( $text, $domain = 'default' ) { return translate( $text, $domain ); } +/** + * Retrieves the translation of $text and escapes it for safe use in an attribute. + * If there is no translation, or the domain isn't loaded the original text is returned. + * + * @see translate() An alias of translate() + * @see attr() + * @since 2.8.0 + * + * @param string $text Text to translate + * @param string $domain Optional. Domain to retrieve the translated text + * @return string Translated text + */ +function _a( $text, $domain = 'default' ) { + return attr( translate( $text, $domain ) ); +} + /** * Displays the returned translated text from translate(). * @@ -118,6 +134,20 @@ function _e( $text, $domain = 'default' ) { echo translate( $text, $domain ); } +/** + * Displays translated text that has been escaped for safe use in an attribute. + * + * @see translate() Echos returned translate() string + * @see attr() + * @since 2.8.0 + * + * @param string $text Text to translate + * @param string $domain Optional. Domain to retrieve the translated text + */ +function _ea( $text, $domain = 'default' ) { + echo attr( translate( $text, $domain ) ); +} + /** * Retrieve translated string with vertical bar context * @@ -145,6 +175,10 @@ function _x( $single, $context, $domain = 'default' ) { return translate_with_gettext_context( $single, $context, $domain ); } +function _xa( $single, $context, $domain = 'default' ) { + return attr( translate_with_gettext_context( $single, $context, $domain ) ); +} + function __ngettext() { _deprecated_function( __FUNCTION__, '2.8', '_n()' ); $args = func_get_args();