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
This commit is contained in:
ryan 2009-04-27 21:58:04 +00:00
parent 8cd2e92b69
commit 2249c69021
3 changed files with 55 additions and 6 deletions

View File

@ -144,7 +144,7 @@ endif; ?>
<p class="search-box">
<label class="hidden" for="category-search-input"><?php _e('Search Categories'); ?>:</label>
<input type="text" id="category-search-input" name="s" value="<?php _admin_search_query(); ?>" />
<input type="submit" value="<?php _e( 'Search Categories' ); ?>" class="button" />
<input type="submit" value="<?php _ea( 'Search Categories' ); ?>" class="button" />
</p>
</form>
<br class="clear" />
@ -184,7 +184,7 @@ if ( $page_links )
<option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
<option value="delete"><?php _e('Delete'); ?></option>
</select>
<input type="submit" value="<?php _e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
<input type="submit" value="<?php _ea('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
<?php wp_nonce_field('bulk-categories'); ?>
</div>
@ -224,7 +224,7 @@ if ( $page_links )
<option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
<option value="delete"><?php _e('Delete'); ?></option>
</select>
<input type="submit" value="<?php _e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
<input type="submit" value="<?php _ea('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
<?php wp_nonce_field('bulk-categories'); ?>
</div>
@ -278,7 +278,7 @@ if ( $page_links )
<p><?php _e('The description is not prominent by default, however some themes may show it.'); ?></p>
</div>
<p class="submit"><input type="submit" class="button" name="submit" value="<?php _e('Add Category'); ?>" /></p>
<p class="submit"><input type="submit" class="button" name="submit" value="<?php _ea('Add Category'); ?>" /></p>
<?php do_action('edit_category_form', $category); ?>
</form></div>

View File

@ -2070,18 +2070,33 @@ function js_escape($text) {
return apply_filters( 'js_escape', $safe_text, $text );
}
/**
* Escaping for HTML attributes.
*
* @since 2.8.0
*
* @param string $text
* @return string
*/
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 ) {
$safe_text = wp_check_invalid_utf8( $text );
$safe_text = wp_specialchars( $safe_text, ENT_QUOTES );
return apply_filters( 'attribute_escape', $safe_text, $text );
return attr( $text );
}
/**

View File

@ -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();