問題描述

WordPress 如何將原始資料從資料庫轉換為 the_content 函式中的可讀格式?

我注意到它適用於 the_content 濾波器,但 the_content 濾波器是做什麼的?

最佳解決方案

預設過濾器設定在/wp-includes/default-filters.php 中;

對於’the_content’ 這是從第 135 行:

add_filter( 'the_content', 'wptexturize'        );
add_filter( 'the_content', 'convert_smilies'    );
add_filter( 'the_content', 'convert_chars'      );
add_filter( 'the_content', 'wpautop'            );
add_filter( 'the_content', 'shortcode_unautop'  );
add_filter( 'the_content', 'prepend_attachment' );

跟蹤各個功能,可以嘗試使用 http://phpxref.ftwr.co.uk/wordpress/nav.html?_functions/index.html,然後按照連結…

Edit

錯過了 (wp-includes/default-filters.php,第 102 行):

// Format WordPress
foreach ( array( 'the_content', 'the_title' ) as $filter )
    add_filter( $filter, 'capital_P_dangit', 11 );

次佳解決方案

所有過濾器都儲存在全域性 $wp_filter 變數中。您可以檢查該變數以檢視哪些函式繫結到某個過濾器。

global $wp_filter;
print_r($wp_filter['the_content']);

要準確瞭解輸出的陣列,知道如何構建 $wp_filter 變數有助於很多。該行來自 add_filter()功能的來源:

$wp_filter[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args);

參考文獻

注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。