_make_cat_compat

函式
_make_cat_compat ( $category )
Access
Private
引數
  • (array|object|WP_Term) $category Category row object or array.
    Required:
定義位置
相關方法
wp_ajax_date_formatwp_ajax_save_attachment_compatmaybe_add_columnget_home_pathget_category_template
引入
2.3.0
棄用
-

_make_cat_compat: 這個函式通過將wp_get_post_categories函式別名為get_the_category函式來確保與舊版本的WordPress向後相容。

從新的分類結構更新到舊的2.3之前的分類結構。

這個函式是為分類法支援而新增的,以更新新的分類結構與舊的分類結構。這將保持與依賴舊鍵或屬性名稱的外掛和主題的相容性。

引數應該只傳遞一個變數,而不是建立陣列或物件到引數的內聯。這樣做的原因是,引數是通過引用傳遞的,除非有變數,否則PHP會失敗。

沒有返回值,因為所有的東西都是在你傳遞給它的變數上更新。這就是在PHP中使用引用傳遞的特點之一。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function _make_cat_compat( &$category ) {
if ( is_object( $category ) && ! is_wp_error( $category ) ) {
$category->cat_ID = $category->term_id;
$category->category_count = $category->count;
$category->category_description = $category->description;
$category->cat_name = $category->name;
$category->category_nicename = $category->slug;
$category->category_parent = $category->parent;
} elseif ( is_array( $category ) && isset( $category['term_id'] ) ) {
$category['cat_ID'] = &$category['term_id'];
$category['category_count'] = &$category['count'];
$category['category_description'] = &$category['description'];
$category['cat_name'] = &$category['name'];
$category['category_nicename'] = &$category['slug'];
$category['category_parent'] = &$category['parent'];
}
}
function _make_cat_compat( &$category ) { if ( is_object( $category ) && ! is_wp_error( $category ) ) { $category->cat_ID = $category->term_id; $category->category_count = $category->count; $category->category_description = $category->description; $category->cat_name = $category->name; $category->category_nicename = $category->slug; $category->category_parent = $category->parent; } elseif ( is_array( $category ) && isset( $category['term_id'] ) ) { $category['cat_ID'] = &$category['term_id']; $category['category_count'] = &$category['count']; $category['category_description'] = &$category['description']; $category['cat_name'] = &$category['name']; $category['category_nicename'] = &$category['slug']; $category['category_parent'] = &$category['parent']; } }
function _make_cat_compat( &$category ) {
	if ( is_object( $category ) && ! is_wp_error( $category ) ) {
		$category->cat_ID               = $category->term_id;
		$category->category_count       = $category->count;
		$category->category_description = $category->description;
		$category->cat_name             = $category->name;
		$category->category_nicename    = $category->slug;
		$category->category_parent      = $category->parent;
	} elseif ( is_array( $category ) && isset( $category['term_id'] ) ) {
		$category['cat_ID']               = &$category['term_id'];
		$category['category_count']       = &$category['count'];
		$category['category_description'] = &$category['description'];
		$category['cat_name']             = &$category['name'];
		$category['category_nicename']    = &$category['slug'];
		$category['category_parent']      = &$category['parent'];
	}
}

常見問題

FAQs
檢視更多 >