โค้ด: เลือกทั้งหมด
add_menu_page( string $page_title, string $menu_title, string $capability, string $menu_slug, callable $function = '', string $icon_url = '', int $position = null )
- คือการระบุชื่อของหน้า page
- คือการระบุชื่อเมนูนั้นๆ
- บทบาทและความสามาร เป็นการระบุว่า User กลุ่มใหนบ้างที่จะเข้าใช้งาน Menu นี้ได้
- เป็นระบุ Url ของ Menu ซึ่งต้องไม่ซ้ำกับ เมนู อื่นๆ เช่น
โค้ด: เลือกทั้งหมด
http://localhost/wordpress/wp-admin/admin.php?page=custompage
- เป็ยการระบุ url หรือ folder สำหรับภาพที่จะนำมาเป็น Icons Menu ถ้าไม่ระบุระบบจะดึงภาพมาให้อัตโนมัติ
- เป็นการระบุตำแหน่งของ Menu สามารถดูลำดับตำแหน่งที่มีอยู่ได้
ตัวอย่างการใช้งานMenu Structure #Menu Structure
Default: bottom of menu structure #Default: bottom of menu structure
2 – Dashboard
4 – Separator
5 – Posts
10 – Media
15 – Links
20 – Pages
25 – Comments
59 – Separator
60 – Appearance
65 – Plugins
70 – Users
75 – Tools
80 – Settings
99 – Separator
Top ↑
For the Network Admin menu, the values are different: #For the Network Admin menu, the values are different:
2 – Dashboard
4 – Separator
5 – Sites
10 – Users
15 – Themes
20 – Plugins
25 – Settings
30 – Updates
99 – Separator
โค้ด: เลือกทั้งหมด
/**
* Register a custom menu page.
*/
function wpdocs_register_my_custom_menu_page(){
add_menu_page(
__( 'Custom Menu Title', 'textdomain' ),
'custom menu',
'manage_options',
'custompage',
'my_custom_menu_page',
'',//plugins_url( 'plugin-WordPress/images/icon.png' ),
1
);
}
add_action( 'admin_menu', 'wpdocs_register_my_custom_menu_page' );
/**
* Display a custom menu page
*/
function my_custom_menu_page(){
esc_html_e( 'Admin Page Test', 'textdomain' );
}
Capability vs. Role Table >> ศึกษาเพิ่มเติมสำหรับสิทธิ์การเข้าถึง Menu ต่างๆ ได้ที่นี่
https://codex.wordpress.org/Roles_and_Capabilities
ศึกษาเพิ่มเติมที่
https://developer.wordpress.org/referen ... menu_page/