Only allow administrators and editors to access wp-admin

You’re correct in that you should be checking for a capability. However, manage options is only given to administrators by default. You should check against a capability that both editors and administrators have such as delete_others_posts. function restrict_admin(){ //if not administrator, kill WordPress execution and provide a message if ( ! current_user_can( ‘delete_others_posts’ ) ) … Read more

REST API: How can I restrict a custom post type to only be accessible by authenticated users?

Looks like I found a snippet that do exactly that. It’s from Daniel Bachhuber, the API developer. add_filter( ‘rest_authentication_errors’, function( $result ) { if ( ! empty( $result ) ) { return $result; } if ( ! is_user_logged_in() ) { return new WP_Error( ‘restx_logged_out’, ‘Sorry, you must be logged in to make a request.’, array( … Read more

Post list based on the user that is logged in

there you go, i’m not the only one trying to bring back-end functionality to the front-end. anyway its not that hard go to your “USER DASHBOARD” template’s file and locate where the loop starts something like: <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> and just above it paste this … Read more

Check if specific username is logged in

wp_get_current_user then compare the object that’s returned user_login proprety with the specific username you’d like to check against. <?php add_action(‘admin_init’, ‘wpse74389_check_username’); function wpse74389_check_username() { $user = wp_get_current_user(); if($user && isset($user->user_login) && ‘username_to_check’ == $user->user_login) { // do stuff } }

Is WordPress’ is_user_logged_in() secure?

Well, you have to ask yourself “Secure enough for what?” I doubt you are a bank or other institution that needs exceptionally high security. If you were you’d a team of $100,000+ per year experts to answer this question for you. With that in mind… You’d have to subvert the WordPress login system to get … Read more

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