在您发布的代码中,我无法真正理解以下内容的意义:
if ( current_user_can( $post_type->cap->edit_posts ) ) {
$items[] = sprintf( \'%2$s\', $type, $text ) . "\\n";
} else {
$items[] = sprintf( \'%2$s\', $type, $text ) . "\\n";
}
也就是说,如果当前用户可以编辑帖子类型,请执行某些操作,否则请执行相同的操作。。。
如果当前用户可以编辑帖子类型(就像WordPress对页面和帖子所做的那样),我想您应该显示帖子列表的链接。
在这种情况下,您的代码变成:
function custom_glance_items( $items = array() ) {
$post_types = array( \'wrestler\' );
foreach( $post_types as $type ) {
if( ! post_type_exists( $type ) ) continue;
$num_posts = wp_count_posts( $type );
if( $num_posts ) {
$published = intval( $num_posts->publish );
$post_type = get_post_type_object( $type );
$text = _n(
\'%s \' . $post_type->labels->singular_name,
\'%s \' . $post_type->labels->name,
$published,
\'your_textdomain\'
);
$text = sprintf( $text, number_format_i18n( $published ) );
// show post type list id user can edit the post type,
// otherwise just swho the name and the count
if ( current_user_can( $post_type->cap->edit_posts ) ) {
$edit_url = add_query_arg( array(\'post_type\' => $type), admin_url(\'edit.php\') );
$items[] = sprintf( \'<a href="%s">%s</a>\', $edit_url, $text ) . "\\n";
} else {
$items[] = $text . "\\n";
}
} // end if( $num_posts )
} // end foreach
return $items;
}