About User Permissions
Quote from pal on January 14, 2019, 12:20 amI made a code to create a registration screen.
What code should I add to give moderator privileges to this?add_action( 'template_redirect', 'entry_init' ); function entry_init() { if ( ! is_page( 'entry' ) ) { return; } if (isset($_POST['nickname'])) { $user = array(); $user['user_login'] = 'user' . date( 'YmdHis' ) . sprintf( '%03d', mt_rand( 0,999 ) ); $user['user_pass'] = $_POST['user_pass']; $user['user_email'] = $_POST['user_email']; $user['nickname'] = $_POST['nickname']; $user['display_name'] = $_POST['nickname']; $user['role'] = 'Subscriber'; $inserted = wp_insert_user($user); } }
I made a code to create a registration screen.
What code should I add to give moderator privileges to this?
add_action( 'template_redirect', 'entry_init' ); function entry_init() { if ( ! is_page( 'entry' ) ) { return; } if (isset($_POST['nickname'])) { $user = array(); $user['user_login'] = 'user' . date( 'YmdHis' ) . sprintf( '%03d', mt_rand( 0,999 ) ); $user['user_pass'] = $_POST['user_pass']; $user['user_email'] = $_POST['user_email']; $user['nickname'] = $_POST['nickname']; $user['display_name'] = $_POST['nickname']; $user['role'] = 'Subscriber'; $inserted = wp_insert_user($user); } }
Quote from max_b on January 14, 2019, 9:50 amQuote from Asgaros on January 11, 2019, 3:27 pmHello @pal
Currently every member who has access to a specific category can also create topics or posts inside it. However there are a few restrictions:
- If a topic is closed, only moderators/administrators can create posts inside it.
- If a forum is closed, only moderators/administrators can create topics inside it. Normal users can still create posts in those topics as long as the topics are not closed as well.
If you need the normal user-role and another user-role which has read-only access only, there is currently only one workaround: You need to ban the users who should not be able to create topics and/or posts. Banned users can still access topics normally like a guest (based on your access-permission settings for categories) but are not able to create topics or posts.
Hi, just one question: Where can I close the forum? Because I have the same issue. We have 3 moderators, and about 10 users who should only be able to read in certain forums. If I get you right, to realize “Read-Only” it is required to both close the forum and the topic?
Thanks a lot!
Max
Quote from Asgaros on January 11, 2019, 3:27 pmHello @pal
Currently every member who has access to a specific category can also create topics or posts inside it. However there are a few restrictions:
- If a topic is closed, only moderators/administrators can create posts inside it.
- If a forum is closed, only moderators/administrators can create topics inside it. Normal users can still create posts in those topics as long as the topics are not closed as well.
If you need the normal user-role and another user-role which has read-only access only, there is currently only one workaround: You need to ban the users who should not be able to create topics and/or posts. Banned users can still access topics normally like a guest (based on your access-permission settings for categories) but are not able to create topics or posts.
Hi, just one question: Where can I close the forum? Because I have the same issue. We have 3 moderators, and about 10 users who should only be able to read in certain forums. If I get you right, to realize “Read-Only” it is required to both close the forum and the topic?
Thanks a lot!
Max
Quote from Asgaros on January 14, 2019, 1:07 pmHello @max_b
Yes, you have to close the forum and the topics.
@pal TheĀ wp_insert_user() function should return the ID of the inserted user. This ID can be used to add the moderator-role with the code-example I posted before.
Hello @max_b
Yes, you have to close the forum and the topics.
@pal TheĀ wp_insert_user() function should return the ID of the inserted user. This ID can be used to add the moderator-role with the code-example I posted before.
Quote from max_b on January 15, 2019, 8:18 amQuote from pal on January 14, 2019, 12:41 pmYou can close the forum from the editing screen of the forum.
Thank you @pal and @asgaros. This works fine for me!
Best regards, Max
Quote from pal on January 14, 2019, 12:41 pmYou can close the forum from the editing screen of the forum.
Thank you @pal and @asgaros. This works fine for me!
Best regards, Max