21

I am working on Wordpress and I completed my project locally. I then moved it to my live server and did not change anything, I just made changes in the config file (database name, username and password).

Now my site is working fine on the front-end but I can't get access to the admin panel as every time it gives me the error message:

You do not have sufficient permissions to access this page.

Google searches indicate that most of the errors occurred due to a change in the prefix but in my case its the same as on local. Also, the permissions of my directories are 755 and that of files is 644 but still am facing the same issue.

How might I go about fixing this?

Ben
  • 51,770
  • 36
  • 127
  • 149
Kashif Waheed
  • 597
  • 4
  • 9
  • 18
  • There is another solution for this: http://stackoverflow.com/questions/4224084/wordpress-error-while-developing-a-plugin-you-do-not-have-sufficient-permissio?rq=1 – Francisco Corrales Morales Jan 24 '14 at 16:20
  • 1
    Another solution - If your table prefix is not **wp**,but i.e. **blabla**, then in **blabla_usermeta** table, find user id, and set **blabla_capabilities** (instead of **wp_capabilities** ) value to **a:1:{s:13:"administrator";b:1;}** and **blabla_user_level** value to **10** – T.Todua Oct 10 '14 at 20:37
  • 1
    Great question; useful best answer. Far better than the incoherent threads on wordpress.org: Suggest moving this question to http://wordpress.stackexchange.com/ where it can have a better life. – artlung Mar 21 '16 at 20:41

2 Answers2

93

Have you changed the prefix of your database tables? I'm 90% sure, that this is your problem.

The thing is that WordPress uses the $table_prefix variable for forming the option and usermeta keys names, where it's storing the roles and capabilities information. So once you change the prefix, but don't update your db, you get this error. Here's how to fix it - execute this SQL command through phpMyAdmin, or a different interface for interacting with your DB(you can do it with PHP as well):

UPDATE `{%TABLE_PREFIX%}usermeta` SET `meta_key` = replace(`meta_key`, '{%OLD_TABLE_PREFIX%}', '{%NEW_TABLE_PREFIX%}');
UPDATE `{%TABLE_PREFIX%}options` SET `option_name` = replace(`option_name`, '{%OLD_TABLE_PREFIX%}', '{%NEW_TABLE_PREFIX%}');

Where:

  • {%TABLE_PREFIX%} is your current $table_prefix(as set in wp-config.php)
  • {%OLD_TABLE_PREFIX%} is your previous $table_prefix
  • {%NEW_TABLE_PREFIX%} is your new(current) $table_prefix - it will most-likely be the same as your {%TABLE_PREFIX%}.

So if your old $table_prefix was wp_test_ and your new one is wp_, you would do this query:

UPDATE `wp_usermeta` SET `meta_key` = replace(`meta_key`, 'wp_test_', 'wp_');
UPDATE `wp_options` SET `option_name` = replace(`option_name`, 'wp_test_', 'wp_');

EDIT: As @Francisco Corrales noted, if you are having troubles accessing an admin page that you created(if you don't write PHP, this is not your case), you can check out this link: Wordpress Error while developing a plugin -"You do not have sufficient permissions to access this page."


EDIT 2: As @Kasper Souren noted, you might want to add a WHERE clause to the options UPDATE query. Like so(don't remove the % after the last %}):

UPDATE `{%TABLE_PREFIX%}options` SET `option_name` = replace(`option_name`, '{%OLD_TABLE_PREFIX%}', '{%NEW_TABLE_PREFIX%}') WHERE option_name like '{%OLD_TABLE_PREFIX%}%';
Community
  • 1
  • 1
Nikola Ivanov Nikolov
  • 5,022
  • 1
  • 26
  • 27
  • no i havent changed the prefix. the prefix on local as well as live is bt_ – Kashif Waheed Dec 11 '12 at 08:00
  • How did you import your DB? Did you make any changes to it? – Nikola Ivanov Nikolov Dec 11 '12 at 08:01
  • i import in the normal ways as usual. export it from local and then import it on live. made no change at all – Kashif Waheed Dec 11 '12 at 08:02
  • That's pretty strange. This message usually means a problem with permissions - and the fact that you are redirected to profile.php also supports that(since users with least access get redirected to their profile). I'm not sure what went wrong. You made a DB export/import, correct? Can you try doing it again(delete the tables that you created before and import over the clean database)? – Nikola Ivanov Nikolov Dec 11 '12 at 08:09
  • i did it 3 times but still facing the same problem – Kashif Waheed Dec 11 '12 at 13:37
  • 1
    Can you look in your DB and check the following tables: `{$table_prefix}options` - look for an entry with `option_name` similar to `{$table_prefix}roles`. Then look in `{$table_prefix}usermeta` and look for entry with `meta_key` similar to `{$table_prefix}capabilities`. `$table_prefix` is what you have in your `wp-config.php`. If you can't find those entries, or they have the wrong `option_name` or `meta_key` - then fix them and try again. If you find them, paste the content here. – Nikola Ivanov Nikolov Dec 11 '12 at 13:45
  • 1
    i reached to the solution thanx for your help. infact the problem was that after updating, one row was not effected which remaind the old prefix, strange but true so i manually changed it and i got my result. salut and thanx – Kashif Waheed Dec 12 '12 at 06:28
  • there is another solution for this:http://stackoverflow.com/questions/4224084/wordpress-error-while-developing-a-plugin-you-do-not-have-sufficient-permissio?rq=1 – Francisco Corrales Morales Jan 24 '14 at 16:21
  • @FranciscoCorrales - not exactly related. The OP of the topic you linked to can't access a single page in the admin and the current OP wasn't able to access any of the pages in the admin. – Nikola Ivanov Nikolov Jan 24 '14 at 16:31
  • Yeah, not exactly, but many people may come here first and spend a lot of time, please add a note to link that question, could save time for other people. – Francisco Corrales Morales Jan 24 '14 at 16:36
  • Updated - but I still don't think a person with the other issue would be reading this page - this one clearly says "without any change" in the title - and the description is about the user moving the site from a local to live environment and not tweaking with the code. – Nikola Ivanov Nikolov Jan 24 '14 at 16:41
  • 1
    It could be good to add `WHERE option_name like 'wp_%'` in case of the prefix occurs in the options. – the Apr 26 '14 at 10:09
  • 1
    Many many thanks. It's work great!!! – csehasib Mar 01 '16 at 11:01
  • 1
    Please fix your first update query instead of adding an EDIT2... if people execute the first query without reading all the answer they could already be in trouble. – iBobo Mar 20 '20 at 12:26
-2

Your problem is not with permission on directories. The fact that you see a "You do not have sufficient permissions to access this page" message means three things :

  1. you are trying to access an admin page directly but not through wp-admin (so please indicate which admin page you are trying to access),

  2. you are already logged in (otherwise you would be redirected to /wp-admin) and

  3. the area you are trying to access is reserved for a higher level of user (so you might be connecting with an editor account whereas the area is only accessible to administrators).

Can you tell us if your local database and the online database are the same? Can you log in properly before you see this message?

Carlos Robles
  • 10,828
  • 3
  • 41
  • 60
barakadam
  • 2,179
  • 1
  • 16
  • 15
  • i am logging properly by enter username and password but when i click the login button it goes to profile.php page and the display me the message that i mentioned above and also i am the top level admin – Kashif Waheed Dec 11 '12 at 07:56
  • Using WordPress MU (multisite)? did you use the same wp-config.php and changed the credentials or did you use another wp-config.php? – barakadam Dec 11 '12 at 08:02