Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm working on a wordpress plugin and am running into an inssue with get_option( 'home' ).

What I'm trying to do: if the user (or admin) is not logged in then a login form will appear on a custom page I've built (from the plugin). I had tried doing this from scratch but everything I was finding was telling how to do it from in the root theme folder... if anyone can help me do this (from scratch) from within a plugin I'm willing to try!

Here is my source code...

<?php get_header(); ?>

<div id="content" class="inner">

    <div class="full shadow photo-uploadr">

        <div class="pad">

           <?php if ( is_user_logged_in()) { ?> 

            <?php } else { ?>

                <!-- BEGIN #login_form -->              
                <form name="loginform" id="login_form" class="login_form wpcf7-form" action="<?php get_option( 'home' ); ?>/wp-login.php" method="post">

                    <p>
                        <input type="text" name="log" id="user_login" class="input" placeholder="Username" />
                    </p>

                    <p>
                        <input type="password" name="pwd" id="user_pass" class="input" placeholder="Password" />
                    </p>

                    <button name="wp-submit" id="wp-submit" class="btn wpcf7-submit"><?php _e("Sign in", "shorti"); ?></button>

                </form>
                <!-- END #contact_form -->

            <?php } ?>

        </div>

    </div>

</div>

<?php get_footer(); ?>

This is from a custom page template file that the plugin has created.

The problem I'm having is when I go to sign in I'm redirected to a 404 error page saying, "url can't be found"... the reason for this is that it's only looking for /wp-login.php. I'm new to working with plugins... so it might be just a simple path defining issue or something noobish like that.

My plugin folder looks something like this: photo-uploadr (main folder)/photo-uploadr.php (main file)/templates (secondary folder)/custom-uploadr.php (file with issue)

Thanks & if you see anything that might not be best practice, let me know. ;)

share|improve this question

closed as off-topic by kaiser, s_ha_dum, G. M., Wyck, brasofilo Oct 16 '13 at 7:57

This question appears to be off-topic. The users who voted to close gave these specific reasons:

  • "Questions that are too localized (such as syntax errors, code with restricted access, hacked sites, hosting or support issues) are not in scope. See how do I ask a good question?" – kaiser, G. M., brasofilo
  • "Questions should be specific to WordPress within defined scope (merely happening in its context, such as generic PHP/JS/HTML/CSS, is insufficient). Might be better asked at Stack Overflow or other appropriate site of Stack Exchange network." – s_ha_dum, Wyck
If this question can be reworded to fit the rules in the help center, please edit the question.

    
You're new to PHP as well? Try echo... –  kaiser Oct 15 '13 at 20:08
    
Thanks @kaiser, I used 'action="<?php echo esc_url( wp_login_url() ); ?>"' like suggested below and it does exactly what I need it to. –  Designer 17 Oct 15 '13 at 20:50

1 Answer 1

up vote 1 down vote accepted

get_option() returns a string, it doesn’t print anything. You have to use echo or print.

But you should use home_url() instead, because this takes care of the proper scheme (http or https):

echo esc_url( home_url() );

Or, in case of the log in URL:

echo esc_url( wp_login_url() );
share|improve this answer
    
So, you're saying to do something like... action="<?php echo esc_url( home_url() '/wp-login.php' ); ?> –  Designer 17 Oct 15 '13 at 18:42
    
@Designer17 See my update, I missed the log in part. –  toscho Oct 15 '13 at 18:45
    
ah, nvm just figured it out. ;) action="<?php echo esc_url( home_url() ); ?>/wp-login.php" ?> Thanks for the SUPER-FAST help... I'll be sure to come here when I REALY get stuck. –  Designer 17 Oct 15 '13 at 18:47
    
@Designer17 No, wp-login.php is not always the URL to log in. That’s just the default, it can be customized. –  toscho Oct 15 '13 at 18:52
    
As Toscho edited his answer: there's a wp_login_url() for that. –  Chip Bennett Oct 15 '13 at 18:58

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