What is the correct way of validating running code when a particular role accesses a screen?

Reducing the number of checks increases the performance of your code, so yes, check is_user_logged_in() and current_user_can() as few times as you can. For executing functions depending on the admin page, I’d probably attach callbacks to load-{$pagenow} hook (untested): function wpse417218_do_something_for_edit_page() { if ( ‘page’ !== get_current_screen()->id ) { return; } if ( ! current_user_can( … Read more

WordPress users roles wp-admin

In WordPress, there is no concept of “super admins” in the same way that there is in a multisite installation. However, there may be users with the “administrator” role who have access to all areas of the site, including the WordPress settings. If you are an administrator and you are unable to access the WordPress … Read more

Display users by role

What I understand from your code: You want to list users with author role. You’re in the right direction, however, following are some tips to make your code better. Use role id in lowercase syntax. Change Author to author for role property. Get the results for once and avoid repeated calls. Save the results like … Read more

WordPress show content if current user get spesific role and spesific meta value

Your question needs some additional context, but here’s a generic approach to what you’ve described. if ( is_user_logged_in() ) { $user = wp_get_current_user(); // Does user have the required role? if ( in_array( ‘some_role’, $user->roles ) && ‘some_meta_value’ == get_user_meta( $user->ID, ‘some_meta’, true ) ) { // Special content… } else { // User doesn’t … Read more

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