Assign a role to the user who registers on a form

$POST = filter_var_array($_POST, FILTER_SANITIZE_STRING); $nome = $POST[‘nome’]; $cognome = $POST[‘cognome’]; $email = $POST[’email’]; $token = $POST[‘stripeToken’]; $nickname = $nome . ‘ ‘ . $cognome; // Inserisce utente nel DB $user_data = [ ‘user_login’ => $nickname, ‘user_pass’ => wp_generate_password (), ‘user_email’ => $email, ]; $user_id = wp_insert_user($user_data); update_user_meta( $user_id, ‘first_name’, $nome); update_user_meta( $user_id, ‘last_name’, $cognome); update_user_meta( … Read more

What are some best practices for user exit strategy?

Although you could create another class of users, I’d just do the following: Change their password to something really strong and random Change their email address to an invalid value (or maybe a variation of yours) so they can’t do a password reset. Maybe change their description/info to show that they are a ‘past employee’ … Read more

Enabling users to upload files

I have added this code to enable everyone to add files function allow_own_attachments( $user_caps, $req_caps, $args, $UserObj ) { if ( empty($args[2]) ) { return $user_caps; // nothing to check } $post = get_post( $args[2] ); // post_id was passed here if (is_object($post)){ //check if $post is an object. If it is’t checked the code … Read more

Page template that redirects user based on role

You can use current_user_can() to check the user roles. https://developer.wordpress.org/reference/functions/current_user_can/ To check if the user is editor or administrator: <?php if( current_user_can(‘editor’) || current_user_can(‘administrator’) ) { ?> // Stuff here for administrators or editors <?php } ?> Then to redirect you can use this: header(‘Location: ‘.$newURL);

User capability for editing their own comments

So my solution may be a little hackish, but it does work. Comments can be edited indefinitely, and only by admins and the registered user that posted the comment. Part of the issue I’m dealing with is that edit_posts only allows the author of a post to edit all its comments, not necessarily the commenters … Read more

allow non logged in user to upload images in media library

The hook wp_ajax_{action} is for logged-in users and wp_ajax_nopriv_{action} for non logged-in users. For example in your functions.php file, add_action( ‘wp_ajax_your_ajax_action’, ‘your_ajax_function_callback’ ); // logged-in users add_action( ‘wp_ajax_nopriv_your_ajax_action’, ‘your_ajax_function_callback’ ); // logged-out users function your_ajax_function_callback() { // handle ajax request }

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)