我想创建一个插件我收到了错误消息:您没有足够的权限来访问此页面。有2个档案 buffer.php bufferpage.php
我已经创建了管理菜单但是我想在点击子菜单命名为Submenu-3后显示/显示“bufferpage.php”
但没有工作:(
buffer.php 在这里
//Register the main menu name “buffercode_menu”
add_action( 'admin_menu', 'buffercode_menu');
//adding menu menu in wordpress admin panel
function buffercode_menu() {
add_menu_page( 'BufferCode plugin page', 'Menu plugin settings','manage_options', __FILE__,'buffercode_plugin',plugins_url( '/images/menu-icon.png', __FILE__ ) );
//submenu
add_submenu_page( __FILE__, 'BufferCode Submenu','Submenu-1', 'manage_options',__FILE__.'_menu1', buffercode_plugin );
add_submenu_page( __FILE__, 'BufferCode Submenu','Submenu-2', 'manage_options',__FILE__.'_menu1', buffercode_plugin );
add_submenu_page( __FILE__, 'BufferCode Submenu','Submenu-3', 'manage_options',__FILE__. $view_level, 'bufferpage.php' );
}
这里是bufferpage.php
<div class="wrap">
<?php echo "<h2>" . __( 'Sample page', 'buffercode_menu' ) . "</h2>"; ?>
<?php
global $wpdb;
/* wpdb class should not be called directly.global $wpdb variable is an instantiation of the class already set up to talk to the WordPress database */
$result = $wpdb->get_results( "SELECT * FROM wp_savans "); /*mulitple row results can be pulled from the database with get_results function and outputs an object which is stored in $result */
//echo "<pre>"; print_r($result); echo "</pre>";
/* If you require you may print and view the contents of $result object */
?>
<table width="100%" border="1">
<tr>
<td width="116" align="center" bgcolor="#FFFF99"><strong>Name</strong></td>
<td width="146" align="center" bgcolor="#FFFF99"><strong>Email</strong></td>
</tr>
<?php
foreach($result as $row)
{
echo "<tr align=center>
<td>$row->name</td>
<td>$row->email</td>
</tr>";
}
/* Print the contents of $result looping through each row returned in the result */
?>
</table>
</div>
答案 0 :(得分:0)
试试这个: -
add_menu_page( 'BufferCode plugin page', 'Menu plugin settings', 'manage_options', 'menu-plugin-settings', 'buffercode_plugin',plugins_url( '/images/menu-icon.png', __FILE__ ) );
add_submenu_page('menu-plugin-settings', 'BufferCode Submenu', 'Submenu-1', 'manage_options', 'submenu-1', 'submenu_1_page');
function submenu_1_page()
{
include_once 'bufferpage.php';
}
答案 1 :(得分:0)
试试此代码,这将有助于您
function custom_button_example($wp_admin_bar){
$args = array(
'id' => 'menu_id',
'title' => 'menu name',
'href' => 'http://exaple.com/',
'meta' => array(
'class' => 'custom-button-class'
)
);
$wp_admin_bar->add_node($args);
}
add_action('admin_bar_menu', 'custom_button_example', 50);