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

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 }

Show metabox for a special role

The Download stats Metabox has a check for view_product_stats capability in EDD codes. in /easy-digital-downloads/includes/admin/downloads/metabox.php Line:42 if ( current_user_can( ‘view_product_stats’, get_the_ID() ) ) { /** Product Stats */ add_meta_box( ‘edd_product_stats’, sprintf( __( ‘%1$s Stats’, ‘easy-digital-downloads’ ), edd_get_label_singular(), edd_get_label_plural() ), ‘edd_render_stats_meta_box’, $post_type, ‘side’, ‘high’ ); } You can simply remove the view_product_stats capability for Your special … Read more

Change user role after bulk-import

From your question, I’m assuming these are users on a specific blog within a MultiSite installation, correct? In that case, do the following: Go to the blog for which you want to make these users administrators. Click on the “Users” button in the left-side admin sidebar This will present you with a display of about … Read more

Getting a role based on a localized role name

Just guessing, but maybe: $admin = get_role( __( ‘administrator’ ) ); If you’re trying to make sure that WP translates the string for a specific locale, __() will return the translated string. So if get_role(‘administrator’) works and on a French setup get_role(‘administrateur’) would work, then the above code snippet should do what you need.