Redirect user based on role when they try access a particular page

function redirect_non_vendors() { global $wp; $user = wp_get_current_user(); $role_needed = ‘vendor’; $page_to_check = ‘secret/page/url’; $redirect_url = home_url( ‘/go-here/’ ); if ( ! in_array( $role_needed, (array) $user->roles ) && $page_to_check === $wp->request ) { wp_redirect( $redirect_url ); exit; } } add_action( ‘template_redirect’, ‘redirect_non_vendors’ ); You’ll want to replace three things here: vendor: the role that someone … Read more

How to add custom detail page for a Subscriber at Admin Panel

It sounds like maybe you need to add a settings page, (https://developer.wordpress.org/plugins/settings/custom-settings-page/) This would be good if you had something really custom (customer user meta) and a layout that you wanted to keep separate from the regular user pages. Otherwise, why not just link to the core wordpress user pages? Just build your links like … Read more

How to display Most Recently Read 10 Posts by a logged in user in wordpress

At first you need to set a meta value when a post is visited using this way if( is_user_logged_in() ) { update_post_meta( $post_id, ‘post_readed_by’, get_current_user_id() ); } Then you can get the recent visited posts <?php $args = array( ‘posts_per_page’ => 10, ‘meta_key’ => ‘post_readed_by’, ‘meta_value’ => get_current_user_id(), ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ); … Read more

Why does a super admin on multi site get a rest_user_invalid_id error code when requesting user details through REST?

Deleting users with the REST API isn’t supported for multisite, as seen in the source code: // We don’t support delete requests in multisite. if ( is_multisite() ) { return new WP_Error( ‘rest_cannot_delete’, __( ‘The user cannot be deleted.’ ), array( ‘status’ => 501 ) ); } For GET requests the user ID is checked … Read more

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