Resources

My Agape try

Your Agape try


Support Forum

You must be logged in to post Login Register

Search 
Search Forums:


 




Changing roles and page roles

UserPost

7:36 am
September 30, 2009


raphael_ber

Member

posts 9

1

Hi

I am using a plugin, TDO Mini Forms, that enables users to add new posts online using forms. In some forms, I want to change the role of users.

For example, I want to change the role from subscriber to contributor.

In the form, it is possible to add php code. Here is the code.

<?php
$user = wp_get_current_user();
$user->set_role('subscriber');
?>

It does change the role.

Of course, if I post this on Role Scoper, it is because I am using Role Scoper.

I restricted some pages to contributors thanks to Role Scoper.

So when the role was changed from subscriber to contributor, I expected the pages available to contributors would automatically available to subscribers changed to contributors.

Actually, I noticed I had to go to the profile of the user, click once on Update User, and then, the user would have access to contributor pages.

I added one line in my code.

<?php
$user = wp_get_current_user();
$user->set_role('subscriber');
wp_user_update($user_id);
?>

Thanks to this line, it worked automatically, but I don't understand why, it creates a new empty user (it creates just a new ID).

Do you have any idea on what I should put instead of wp_user_update($user_id) ?

It would help me a lot if you have some.


Thank you very much for your support.

8:40 pm
November 12, 2009


Kevin

Admin

posts 2402

2

raphael_ber said:

Hi

<?php
$user = wp_get_current_user();
$user->set_role('subscriber');
?>

It does change the role.

I restricted some pages to contributors thanks to Role Scoper.

So when the role was changed from subscriber to contributor, I expected the pages available to contributors would automatically available to subscribers changed to contributors.

Actually, I noticed I had to go to the profile of the user, click once on Update User, and then, the user would have access to contributor pages.


$user = wp_get_current_user();
$user->set_role('subscriber');
do_action( 'profile_update', $user->ID );

That's the hook which Role Scoper relies on to keep in sync with changes to a user's WP Role.


About the Agapetry forum

Currently Online:

13 Guests

Maximum Online: 150

Forums:

Groups: 2

Forums: 7

Topics: 1186

Posts: 5409

Members:

There are 1176 members

There are 1 guests


Kevin has made 2402 posts

Top Posters:

metal450 - 159

Ragnar - 105

YikYak - 70

whiteorb - 44

Daisy - 35

Administrator: Kevin | Moderators: Kevin