• Resolved YB

    (@yahyabassa)


    Hi
    I have started using the plugin recently and its really useful.
    I’ve however having a problem in linking roles from my mysql table to he plugin.

    Also if possible, would you guide me on how to create a cookie with the current user. I’ve created a plugin to do this with wordpress user-login, however its not working with external-login. I know its not secure, but its for a private web program.

    Thanks a lot

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author tbenyon

    (@tbenyon)

    Hey @yahyabassa,

    I’m glad you’re finding the plugin useful πŸ™‚

    Linking roles from MySQL
    What exactly is the issue?
    Are the roles not getting created in WordPress but the rest of the user is?
    Could you let me know what settings you have activated?

    Creating a Cookie
    What exactly do you want to do and what do you want to store in the cookie?
    Do you want to create the cookie when someone logs in and just store the user ID and then delete it when they log out?

    Thread Starter YB

    (@yahyabassa)

    Hi

    Here is the settings I have. (the database name and passsword is removed)
    https://drive.google.com/open?id=1tSDDCXyQggVGGK0Ix6wPo5NgwTgNtJkd
    1.Basically what is happening is that when I add a pair of custom roles e.g
    Customer = Administrator
    when I press save and re-load the page Customer is replaced with a blank space and Administrator is replaced with Subscriber as you see in the file.

    2.I want to crate a cookie when someone signs in which contains their User Name and their role.

    Thanks very much.

    • This reply was modified 7 years, 3 months ago by YB.
    Plugin Author tbenyon

    (@tbenyon)

    Hey @yahyabassa,

    Just wanted to acknowledge I’ve seen this and say I’m going to try and look at this this weekend for you.

    In the meantime can you confirm the version number of the plugin you’ve got installed?

    Thanks,

    Tom

    Plugin Author tbenyon

    (@tbenyon)

    Hey @yahyabassa,

    Linking roles from MySQL
    I can’t replicate this πŸ™

    I’m going to ask for you to give me more help to figure this out as at the moment I have nothing to go on.

    Ideas to try:

    • Check that your plugins are all up to date and WordPress is too
    • Try a different browser
    • Disable all other plugins and see if the issue persists
    • Look in the dev tools in the browser to see if any errors get logged and report them back to me
    • Look in the PHP error logs and see if any error are getting reported and pass them on to me
    • Try updating your version of PHP

    Creating a Cookie
    This is a bit out of the scope of support for this plugin as it is separate functionality but I wanted to help you out.

    I think the code is pretty readable but if you have questions about it let me know. The data is being stored in the cookie as a JSON string but you can modify as you like.

    
    function benyon_user_login_cookie_store($user_login) {
        $current_user_id = get_user_by('login', $user_login)->ID;
    
        $user_meta = get_userdata($current_user_id);
    
        $user_roles = $user_meta->roles;
    
        $user_data = array(
            "user_id" => $current_user_id,
            "user_roles" => $user_roles
        );
    
        $cookie_name = "WP_USER";
        $cookie_value = json_encode($user_data);
        setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
    }
    
    add_action('wp_login', 'benyon_user_login_cookie_store');
    

    Tom

    Thread Starter YB

    (@yahyabassa)

    HI.
    Sorry for he late reply.
    1. I will try to go through the error logs and get back to you.
    2. Thanks for the code. Really appreciate it.

    Thread Starter YB

    (@yahyabassa)

    I’ve tried locating the problem but failed. I tried the plugin on another site and it worked. Its possibly some setting in my web server. I’ve over-come it buy filling in the extra role values directly into the wp-opions table.
    My Initial plugin for setting the roles to the cookie also started working after I set the custom roles. But thanks for your code.
    By the way, an error I found is that the pic wp-content/plugins/external-login/assets/in_app/logoClear.svg is missing, and thus gives an error in the debugger.
    Thanks alot for the support

    • This reply was modified 7 years, 3 months ago by YB.
    Plugin Author tbenyon

    (@tbenyon)

    Hey @yahyabassa,

    Really glad you’ve got it all worked out πŸ™‚

    Strange about that image not loading. It seems to be loading in two of my sites I’ve checked.

    I would be SUPER grateful if you would take a moment to write me a review.
    https://wordpress.org/plugins/external-login/#reviews

    Thanks,

    Tom πŸ™‚

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Error in when setting User-Roles field (in multisite)’ is closed to new replies.