WordPress.org

Ready to get started?Download WordPress

Forums

Lost admin privileges ... have partial answer (13 posts)

  1. quantazelle
    Member
    Posted 3 years ago #

    After I upgraded, I logged in as my admin account, but it downgrades me to a normal writer-user (not as admin). I found this solution here:

    I logged in to phpmyadmin on a working instal of WP 2.8.4
    went to the wp_options table
    found the option with option_name = wp_user_roles
    opened that record and copied the option_value field

    then went to the database for my fouled instal (still in phpmyadmin)
    went to the wp_options table
    found the option with option_name = wp_user_roles
    opened that record and pasted into the option_value field what I had copied from the other database

    But the problem is, I'm having trouble navigating PHPMyAdmin. By the time I try to edit the record, I get shot this text array, and I have NO idea what value to copy over and change.

    [Code moderated as per the Forum Rules. Please use the pastebin]

  2. molnarm
    Member
    Posted 3 years ago #

    This is a serialized PHP array. You could unserialize it with PHP, edit it and then serialize it back, but you can also edit it directly. It's basically made of <type>:<value-length>:<value>; triplets, with some exceptions, e.g. boolean (bit) values are just b:<0 or 1>.

    The user capabilities are in the 'capabilities' array, for the admin user, this is the very first one (look for a:77). There follows an enumeration of the user's privileges.

    It seems that the administrator user does have all capabilities required (edit_users and manage_options among them) so I think the problem is not in the database. If you sign in with other users, do you have the right capabilities?

  3. quantazelle
    Member
    Posted 3 years ago #

    I think it may have had something to do with Facebook Connect. If I'm logged in through Facebook Connect it connects with the user "Liz" who only has author privileges. If I am not logged in through Facebook I can login as "admin" which has full admin privileges. Now, when I login as "admin" it shows me logged in as "Liz."

    I've deleted all my plugins in the directory and still have the same problem.

  4. molnarm
    Member
    Posted 3 years ago #

    I have no experience with FBConnect. Try clearing the browser's cookies to force sign out.

  5. quantazelle
    Member
    Posted 3 years ago #

    I did that, to no avail.

    Is there a way to create a new administrator user from the database, and login with that?

    Thanks for your help, by the way.

  6. molnarm
    Member
    Posted 3 years ago #

    Hi! Certainly you could create an admin user from database but since it's a very complex one I wouldn't try that. (I'm sure there's something trivially easy going on here but since we couldn't figure it out, let's solve the problem by force!)

    Why not use WordPress functions that handle this?
    Add this line:
    wp_update_user(array('ID'=>ID_OF_USER,'role'=>'administrator'));
    to the beginning of your theme's functions.php file (it's probably located in wp-content/themes/<your-theme>/ folder). Substitute ID_OF_USER with the ID of an existing user (look up the ID in the wp_users table). This way you will promote a user to admin when you visit any page generated by WP. Don't forget to delete it later.

    (I didn't try it so I'm not sure whether it works but it's worth a try.)

  7. quantazelle
    Member
    Posted 3 years ago #

    OK, I tried that but get

    Fatal error: Call to undefined function wp_update_user() in /home/initia5/public_html/lizrevision.com/wp-includes/functions.php on line 26

  8. molnarm
    Member
    Posted 3 years ago #

    Oops, sorry. You have to include it in an action hook:

    add_action('init','promoter');
    function promoter(){
        wp_update_user(array('ID'=>ID_OF_USER,'role'=>'administrator'));
    }

    (add this into your theme's functions.php).
    This time I tested it and it worked.

  9. quantazelle
    Member
    Posted 3 years ago #

    hmm... still not working:
    Fatal error: Call to undefined function add_action() in /home/initia5/public_html/lizrevision.com/wp-includes/functions.php on line 27

  10. molnarm
    Member
    Posted 3 years ago #

    You're editing the wrong file, see my third post for the correct location. You should put it into your theme's functions.php file.

  11. quantazelle
    Member
    Posted 3 years ago #

    The theme I'm using didn't have a functions.php file at wp-content/themes/<your-theme>/, so I copied over the one from wp-content/themes/default/, added this line right after <php

    add_action('init','promoter');
    function promoter(){
        wp_update_user(array('ID'=>1,'role'=>'administrator'));
    }

    but now I get the error

    Warning: require(/home/initia5/public_html/lizrevision.com/wp-includes/load.php) [function.require]: failed to open stream: No such file or directory in /home/initia5/public_html/lizrevision.com/wp-settings.php on line 19
    
    Fatal error: require() [function.require]: Failed opening required '/home/initia5/public_html/lizrevision.com/wp-includes/load.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/initia5/public_html/lizrevision.com/wp-settings.php on line 19
  12. molnarm
    Member
    Posted 3 years ago #

    So now you have a functions.php file in your theme folder, with the content being exactly

    <?php
    add_action('init','promoter');
    function promoter(){
        wp_update_user(array('ID'=>1,'role'=>'administrator'));
    }

    and it displays this really weird error message?

  13. quantazelle
    Member
    Posted 3 years ago #

    Awesome! I got it working with your code.

    (And, I fixed the missing file error by upgrading to the latest wordpress version first.)

    Thanks so much!

Topic Closed

This topic has been closed to new replies.

About this Topic