custom post types - Which escaping function should be use on register_post_type label?

If I register a post type then which escaping should I use for escaping label?function book_setup_post_type() {$args = a

If I register a post type then which escaping should I use for escaping label?

function book_setup_post_type() {
    $args = array(
        'public'    => true,
        'label'     => __( 'Books', 'textdomain' ),
        'menu_icon' => 'dashicons-book',
    );
    register_post_type( 'book', $args );
}
add_action( 'init', 'book_setup_post_type' );

If I register a post type then which escaping should I use for escaping label?

function book_setup_post_type() {
    $args = array(
        'public'    => true,
        'label'     => __( 'Books', 'textdomain' ),
        'menu_icon' => 'dashicons-book',
    );
    register_post_type( 'book', $args );
}
add_action( 'init', 'book_setup_post_type' );
Share Improve this question edited Feb 24, 2020 at 11:26 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Feb 24, 2020 at 10:55 Akhtarujjaman ShuvoAkhtarujjaman Shuvo 2081 silver badge6 bronze badges 1
  • For securing output you should just do alright with esc_html() and if it's gonna be translation ready you would be better off using esc_html_e() or esc_html__(). For your ref: developer.wordpress/themes/theme-security/… – Kumar Commented Feb 24, 2020 at 12:23
Add a comment  | 

1 Answer 1

Reset to default 1

None. Escaping should happen late, on output. This is just registering the strings for later use, so it's too early to escape. All the places in WordPress where the post type label is used automatically, WordPress should already be escaping it.

If you're outputting any of the labels yourself, you would probably use esc_html():

$post_type_object = get_post_type_object( 'book' );
$post_type_labels = get_post_type_labels( $post_type_object );

echo esc_html( $post_type_labels->singular_name );

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744719906a4589848.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信