-2

So I have been researching for a while but to no avail. I am very new to php and back end WordPress functions.

I would like to create a function that when a user clicks on a link it updates their user role.

This function is needed because I am creating a staff induction site where they have to read a page and then when done click on a link to take them to the next part of the website, the changing of the role will let me know that they have read it and moved on to the next part.

I have basic understanding of the functions.php file and have been playing around with tutorials to understand how it works but I can't seem to wrap my head around what is needed to get this to happen.

A few similar links I've tried are:

But I couldn't work out from those what was needed.

Any help would be super appreciated.

Thanks!

agoodacre
  • 35
  • 4
  • I'd probably create a `
    ` with one or two hidden inputs. On the `init` hook you can listen for the trigger inputs in the `$_POST` array (ex: a hidden input such as `< input type="hidden" name="upgrade_to_boss" value="99" />` where the value is the current user's ID. This could be detected on `init` via `isset($_POST["upgrade_to_boss"])` and then run the desired process with the ID.
    – helgatheviking Nov 30 '15 at 04:34
  • Thanks for the reply! I managed to get it to work the way I wanted after doing some more digging and reading so thanks! – agoodacre Nov 30 '15 at 10:57

1 Answers1

3

So I figured it out eventually, the code I used was:

function change_role($atts) {
    $current_user = wp_get_current_user();
    $current_user->remove_role( 'induction_intro' );
    $current_user->add_role( 'getting_started' );
    echo 'User ID: ' . $current_user->ID . '<br />';
}
add_shortcode('changerole', 'change_role');

I have more to add to it yet but I can figure those out easily enough. I feel silly posting the question now, after doing it, it seems so simple.

agoodacre
  • 35
  • 4