douchensou6495
2018-08-14 11:59
浏览 164

WordPress错误:抱歉,您无权访问此页面

I have a plugin that creates a menu page on admin dashboard:

function dp_manage_admin_menu() {
    add_menu_page('Manage Data', 'Manage Data', 'manage_options', 'manage-data', 'dp_manage_data_page', '');

    add_submenu_page('manage-data', 'Add New', 'Add New', 'manage_options', __FILE__ . '/add-new', 'tm_add_new_page');
}

// Actions
add_action('admin_menu', 'dp_manage_admin_menu');

In that page manage-data, There is a button for deleting data from DB:

<a href="<?php echo admin_url() ?>admin.php?page=manage-data/manage-data.php?id=<?php echo (isset($result->id)) ? $result->id : ""; ?>" class="btn btn-danger btn-sm">
    <i class="fa fa-trash-o"></i> Delete
</a>

So if I clicked the first button it goes to "http://example.com/wp-admin/admin.php?page=manage-data?id=1"

Then I check if the id is sent, Then delete that result:

if( isset($_GET['id']) ){
    //Do something.
}

But I get an error, When I click the delete button:

Sorry, you are not allowed to access this page.

I can visit "http://example.com/wp-admin/admin.php?page=manage-data", But if any parameters are sent I can't access it anymore.

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongyakui8675 2018-08-14 12:18

    I discovered the problem, That's what the URL looks like "http://example.com/wp-admin/admin.php?page=manage-data?qid=6".

    While there are another parameter there ?page=manage-data.

    So I should use & to ad another parameter.

    The URL should be "http://example.com/wp-admin/admin.php?page=manage-data&qid=6"

    打赏 评论
  • dqkmn26444 2018-11-29 03:59

    Also search wp-setting.php file for "define('DISALLOW_FILE_MODS',true);" and delete it. Non of the above solutions worked for me except this one!

    打赏 评论

相关推荐 更多相似问题