問題描述
是否有獲取註冊的元框列表並刪除它們的功能?我看到有一種新增和刪除的方法。
http://codex.wordpress.org/Function_Reference/remove_meta_box
http://codex.wordpress.org/Function_Reference/add_meta_box
最佳解決方案
不是真的,但你可以自己定義。所有元框都儲存在全域性變數 $wp_meta_boxes 中,它是一個 multi-dimensional 陣列。
function get_meta_boxes( $screen = null, $context = 'advanced' ) {
global $wp_meta_boxes;
if ( empty( $screen ) )
$screen = get_current_screen();
elseif ( is_string( $screen ) )
$screen = convert_to_screen( $screen );
$page = $screen->id;
return $wp_meta_boxes[$page][$context];
}
該陣列將顯示為特定螢幕和特定上下文註冊的所有元框。您還可以進一步深入,因為此陣列也是一個多維陣列,透過優先順序和 ID 隔離元框。
所以我們假設你想得到一個陣列,它包含管理儀錶板上”normal” 優先順序的所有元框。你會呼叫以下內容:
$dashboard_boxes = get_meta_boxes( 'dashboard', 'normal' );
這與全域性陣列 $wp_meta_boxes['dashboard']['normal']相同,它也是一個 multi-dimensional 陣列。
刪除核心元框
假設您要刪除一堆元框。上面的功能可以略微調整,以便:
function remove_meta_boxes( $screen = null, $context = 'advanced', $priority = 'default', $id ) {
global $wp_meta_boxes;
if ( empty( $screen ) )
$screen = get_current_screen();
elseif ( is_string( $screen ) )
$screen = convert_to_screen( $screen );
$page = $screen->id;
unset( $wp_meta_boxes[$page][$context][$priority][$id] );
}
如果您想從 「儀錶板」 中刪除 「傳入連結」 視窗小工具,您可以呼叫:
remove_meta_boxes( 'dashboard', 'normal', 'core', 'dashboard_incoming_links' );
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。