此功能具有一項功能,該功能將用于確定菜單中是否包含頁面。連接到處理頁面輸出的功能必須檢查用戶是否也具有所需的功能。
函數介紹:
add_options_page( string $page_title, string $menu_title, string $capability, string $menu_slug, callable $function = '', int $position = null )
參數詳解:
$ page_title
(字符串)?(必需)?選擇菜單時在頁面標題標簽中顯示的文本。
$ menu_title
(字符串)?(必需)?用于菜單的文本。
$capability
(字符串)(必需)?此菜單需要顯示給用戶的功能。
$menu_slug
(string)(必需)?引用此菜單所用的子文件名(此菜單應該唯一)。
$function
(callable)?(可選)?將被調用以輸出此頁面內容的函數。
Default value: ''
$position
(int)?(可選)?應在菜單項中顯示此項目的位置。
Default value: null
Return?
(string|false)?結果頁面的hook_suffix,如果用戶沒有所需的功能,則返回false。
例子:
面向對象的選項頁面助手/視圖
/**
* Class for registering a new settings page under Settings.
*/
class WPDocs_Options_Page {
/**
* Constructor.
*/
function __construct() {
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
}
/**
* Registers a new settings page under Settings.
*/
function admin_menu() {
add_options_page(
__( 'Page Title', 'textdomain' ),
__( 'Circle Tree Login', 'textdomain' ),
'manage_options',
'options_page_slug',
array(
$this,
'settings_page'
)
);
}
/**
* Settings page display callback.
*/
function settings_page() {
echo __( 'This is the page content', 'textdomain' );
}
}
new WPDocs_Options_Page;
其他:
如果您需要將子菜單頁面添加到外觀主菜單中,您可以參考這篇wordpress函數文章:
用在實際開發中,您可以看看這款插件是如何使用的: