Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

i am trying to create my own plugin in WordPress. everything works great but i want to make a loginredirect check for users who want to access to the plugins page. here is my function in my functions.php:

function wpuf_auth_redirect_login() {  
    $user = wp_get_current_user();  
    if ( $user->id == 0 ) {  
        nocache_headers();  
        wp_redirect(get_option('siteurl') . '/wp-login.php?redirect_to=' . urlencode($_SERVER['REQUEST_URI']));  
        exit();
    }  
}

and this is from my myplugin.php:

function wpuf_user_edit_profile() {  
    wpuf_auth_redirect_login(); // if not logged in, redirect to login page
    nocache_headers();  
    wpuf_post_form_style();  
    wpuf_user_edit_profile_form();  
}  
add_shortcode('wpuf_editprofile', 'wpuf_user_edit_profile');

it is not working. if i enter the plugins page as a guest in browser it does not redirect it only shows the template uncomplete. any help?

share|improve this question

closed as too localized by toscho Jul 19 '12 at 23:29

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

1 Answer

Your function will create a short code - [wpuf_editprofile] instead. I believe you should use add_action in the function and the Action Reference should set to wp_login.

eg: add_action('wp_login', 'wpuf_user_edit_profile');

Let us know what happen after this as I think it still won't solve your template uncomplete error. Mind to elaborate more on that.

share|improve this answer
Template uncomplete error is not a problem for me. It is just not redirecting to login page if the user is not registered. The big problem is this. – boranb Oct 25 '11 at 11:13
hot can i add a working login redirect to my function. this is my question . – boranb Oct 25 '11 at 13:19
also add_action('wp_login', 'wpuf_user_edit_profile'); didnt work. – boranb Oct 25 '11 at 18:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.