2010-09-02 77 views
0

功能:困惑關於WordPress get_the_title功能

/** 
* Retrieve post title. 
* 
* If the post is protected and the visitor is not an admin, then "Protected" 
* will be displayed before the post title. If the post is private, then 
* "Private" will be located before the post title. 
* 
* @since 0.71 
* 
* @param int $id Optional. Post ID. 
* @return string 
*/ 

function get_the_title($id = 0) { 
    $post = &get_post($id); 

$title = isset($post->post_title) ? $post->post_title : ''; 
$id = isset($post->ID) ? $post->ID : (int) $id; 

if (!is_admin()) { 
    if (!empty($post->post_password)) { 
     $protected_title_format = apply_filters('protected_title_format', __('Protected: %s')); 
     $title = sprintf($protected_title_format, $title); 
    } else if (isset($post->post_status) && 'private' == $post->post_status) { 
     $private_title_format = apply_filters('private_title_format', __('Private: %s')); 
     $title = sprintf($private_title_format, $title); 
    } 
} 
return apply_filters('the_title', $title, $id); 
} 

我不明白什麼參數__('Protected: %s')意味着在下面的代碼的特定行。它是什麼樣的參數?

$protected_title_format = apply_filters('protected_title_format', __('Protected: %s')); 

回答

1

__()是用於獲取英文單詞「保護」的本地化字符串本地化功能。

%s是由sprintf()使用的替換參數。基本上,它會用博客文章的標題取而代之。

整個__('Protected: %s')調用作爲參數傳遞給apply_filters()函數以簡單地設置帖子標題的格式。默認情況下,我不認爲會發生任何事情,但插件可能會掛在protected_title_format篩選器上,以便在應用郵政標題之前進一步處理格式。