Title: Hooks
Last modified: March 4, 2018

---

# Hooks

 *  Resolved [timurkayzer](https://wordpress.org/support/users/timurkayzer/)
 * (@timurkayzer)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/hooks-23/)
 * Hello. There is a problem with hooks in plugin, or i may not know some features
   of WordPress. There are hooks, where function is referred from initialized object:
 * `add_action( 'template_redirect', array($instance, 'profile_redirect'), 10);`
 * I’d like to remove redirect to /profile/%username% and leave just /profile, and
   let users only see their own profile pages, this is why i need this hook. Could
   you please help me with this?

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [Stiofan](https://wordpress.org/support/users/stiofansisland/)
 * (@stiofansisland)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/hooks-23/#post-10041377)
 * Hello,
 * I will ask the UWP developer to reply about the hook, but i am not sure its the
   best way to do what you want.
 * If your goal is to just only let users see their own profile there is other ways
   to do it, like simply checking if the current user ID matches the author page
   and if not do a redirect or show a message.
 * Thanks,
 * Stiofan
 *  [Rahul Gandhi](https://wordpress.org/support/users/wpdev10/)
 * (@wpdev10)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/hooks-23/#post-10042913)
 * Hi,
 * It is not recommended to remove %username% parameter from the URL as it is required
   parameter to load the data of that user in the profile page.
 * If you want to allow access to own profile page only and redirect to home page
   while accessing other profile page then you can put following code in your functions.
   php file of the currently active theme.
 *     ```
       add_action('template_redirect', 'uwp_profile_page_redirect', 99);
       function uwp_profile_page_redirect(){
   
           if (!is_page()) {
               return false;
           }
   
           global $wp_query, $post;
           $current_page_id = $post->ID;
           $profile_page = uwp_get_option('profile_page', false);
   
           if ( $profile_page && ((int) $profile_page ==  $current_page_id ) ) {
               if (isset($wp_query->query_vars['uwp_profile'])) {
                   $url_type = apply_filters('uwp_profile_url_type', 'slug');
                   $author_slug = $wp_query->query_vars['uwp_profile'];
                   if ($url_type == 'id') {
                       $user = get_user_by('id', $author_slug);
                   } else {
                       $user = get_user_by('slug', $author_slug);
                   }
   
                   if (isset($user->ID) && is_user_logged_in() && $user->ID == get_current_user_id()) {
                       return false;
                   } else {
                       wp_redirect( home_url('/')); // redirect for other users
                       exit();
                   }
               }
           }
   
           return false;
       }
       ```
   
 * Let me know if it helps you.
 * Regards,
    Patrik
 *  Thread Starter [timurkayzer](https://wordpress.org/support/users/timurkayzer/)
 * (@timurkayzer)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/hooks-23/#post-10047513)
 * Hello,
 * thank you for reply, it helped me to restrict access to other users pages.
 * But i’d like to remove username from URL, because it will be more “user-friendly”–
   user has access only to his own page anyway. Userdata can be checked by WordPress
   itself, like wp_get_current_user() etc.
 * Is there any way to do it? Because deleting this redirection hook from plugin
   code would be wrong – it works, but becomes unupdateable then.
 *  [Rahul Gandhi](https://wordpress.org/support/users/wpdev10/)
 * (@wpdev10)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/hooks-23/#post-10048542)
 * Actually, wp_get_current_user() will work for current logged in users while in
   the plugin we have other users profile visible to all users so this function 
   will not work for the global plugin. It can work for your specific requirements.
   You may need to make changes in the core to achieve your requirements.
 *  Thread Starter [timurkayzer](https://wordpress.org/support/users/timurkayzer/)
 * (@timurkayzer)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/hooks-23/#post-10056231)
 * Thank you for supporting plugin!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Hooks’ is closed to new replies.

 * ![](https://ps.w.org/userswp/assets/icon-256x256.png?rev=2784318)
 * [UsersWP - Front-end login form, User Registration, User Profile & Members Directory plugin for WP](https://wordpress.org/plugins/userswp/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/userswp/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/userswp/)
 * [Active Topics](https://wordpress.org/support/plugin/userswp/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/userswp/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/userswp/reviews/)

## Tags

 * [hook](https://wordpress.org/support/topic-tag/hook/)

 * 5 replies
 * 3 participants
 * Last reply from: [timurkayzer](https://wordpress.org/support/users/timurkayzer/)
 * Last activity: [8 years, 1 month ago](https://wordpress.org/support/topic/hooks-23/#post-10056231)
 * Status: resolved