WpTricks24
WpTricks24

Reputation: 825

Apply user moderation for authors only

I am using theme my login, it is a great plugin. I have used it in many website.

Now, in one of my website I have enabled user moderation module of theme my login. According to it when any new user register on the website, it comes under moderation and when admin approve then only he is able to be a user on the website.

So, I don't want this functionality for subscribers. Or in other words I want this only for authors.

Upvotes: 2

Views: 246

Answers (1)

WpTricks24
WpTricks24

Reputation: 825

Now I find the solution of this question.

put a dropdown on register-form.php between the form tags like :

<p>
        <label for="role<?php $template->the_instance(); ?>"><?php _e( 'Role', 'theme-my-login' ) ?></label>
        <select id="role<?php $template->the_instance(); ?>" name="role">
    <option value="author">Author</option>
    <option value="subscriber">Subscriber</option>
</select>
</p>

then put a function in function.php like :

function set_role_on_registration( $user_id ) {

    //$role = sanitize_text_field( $_POST['role'] );
    $role = $_POST['role'];

    if ( in_array( $role, array( $role, 'bprofessional' ) ) )
        add_user_meta( $user_id, 'pending_role', $role );
}
add_action( 'tml_new_user_registered', 'set_role_on_registration' );

then go to plugins/theme-my-login/modules/user-moderation/admin/user-moderation-admin.php and find user_row_actions function. Find case 'admin' : and put the below code in between start of case and its break; like :

$c_u_r = get_user_meta($user_object->ID, 'pending_role', true);
                        // Add "Approve" link
                        if($c_u_r != 'subscriber'){
                        $actions['approve-user'] = sprintf( '<a href="%1$s">%2$s</a>',
                            add_query_arg( 'wp_http_referer',
                                urlencode( esc_url( stripslashes( $_SERVER['REQUEST_URI'] ) ) ),
                                wp_nonce_url( "users.php?action=approve&user=$user_object->ID", 'approve-user' )
                            ),
                            __('Approve', 'theme-my-login' )
                        );
                        }else{
                            if ( ! self::approve_user( $user_object->ID ) )
                            wp_die( __( 'You can’t edit that user.' ) );

                        }

Now the user moderation will not work for the users which registers as a subscriber. Modify the code and use it in your own way.

This may help some one.

Thanks Sunil

Upvotes: 2

Related Questions