class Cosmo_Games {
public function __construct() {
add_action(\'admin_menu\', array($this, \'create_plugin_settings_page\'));
}
public function create_plugin_settings_page() {
$page_title = \'Game Settings\';
$menu_title = \'Games Plugin\';
$cabability = \'manage_options\';
$slug = \'cg_settings\';
$callback = array($this, \'plugin_settings_page_content\');
$icon = \'dashicons-admin-plugins\';
$position = 100;
add_menu_page($page_title, $menu_title, $capability, $slug, $callback, $icon, $position);
}
public function plugin_settings_page_content() {
?>
<div class="wrap">
<h2>My Awesome Settings Page</h2>
<form method="post" action="options.php">
<?php
settings_fields( \'cg_settings\' );
do_settings_sections( \'smashing_fields\' );
submit_button();
?>
</form>
</div>
<?php
}
}
new Cosmo_Games();
由于某些原因,游戏插件页面没有显示在仪表板中。有人知道我做错了什么吗?
最合适的回答,由SO网友:Dave Romsey 整理而成
上有一个拼写错误$capability
参数:
$cabability=\'manage\\u options\';
为了完整起见,下面是工作代码:
class Cosmo_Games {
public function __construct() {
add_action(\'admin_menu\', array($this, \'create_plugin_settings_page\'));
}
public function create_plugin_settings_page() {
$page_title = \'Game Settings\';
$menu_title = \'Games Plugin\';
$capability = \'manage_options\';
$slug = \'cg_settings\';
$callback = array($this, \'plugin_settings_page_content\');
$icon = \'dashicons-admin-plugins\';
$position = 100;
add_menu_page($page_title, $menu_title, $capability, $slug, $callback, $icon, $position);
}
public function plugin_settings_page_content() { ?>
<div class="wrap">
<h2>My Awesome Settings Page</h2>
<form method="post" action="options.php">
<?php
settings_fields( \'cg_settings\' );
do_settings_sections( \'smashing_fields\' );
submit_button();
?>
</form>
</div><?php
}
}
new Cosmo_Games();