WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Lost admin privileges … have partial answer

[Resolved] Lost admin privileges … have partial answer

Viewing 12 replies - 1 through 12 (of 12 total)
  • 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?

    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.

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

    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.

    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.)

    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

    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.

    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

    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.

    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

    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?

    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!

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘[Resolved] Lost admin privileges … have partial answer’ is closed to new replies.