0

I am newbee to web development,since last few days i am struggling to login through php code. My PHP code is as follow

//my php code @include_once '../wp-includes/user.php'; $creds = array( 'user_login' => 'abc', 'user_password' => 'abc', 'rememember' => false ); $user = wp_signon( $creds, 0 ); if ( is_wp_error($user) ) echo $user->get_error_message(); 

when the PHP code is executed on server i get the below error.

Fatal error: Uncaught Error: Call to undefined function do_action_ref_array() in /Users/meenalgupta/Sites/wordpress/mysite/wp-includes/user.php:57 Stack trace: #0 /Users/meenalgupta/Sites/wordPress/mysite/wp-admin/mypage.php(38): wp_signon(Array, 0) #1 {main} thrown in /Users/meenalgupta/Sites/wordpress/mysite/wp-includes/user.php on line 57

My wordpress version is 4.4.1.

Please let me know what to do?

3
  • wp-admin/mypage.php what is that?
    – fuxia
    CommentedJan 7, 2016 at 8:41
  • @toscho OP has clearly created a random file in wp-admin and is trying to load WordPress manually. @Meenal Gupta WHY ARE YOU DOING THIS!?CommentedJan 7, 2016 at 11:38
  • mypage.php is just a practice file that i created in wp-admin.I want to login into server ,so that i can post on my local wordpress site.CommentedJan 7, 2016 at 13:34

2 Answers 2

1

You should BIND the codes into action (you can use plugins_loaded for earliest stage):

add_action('plugins_loaded', 'my_func'); function my_func(){ // ======== HERE YOUR CODES =========// } 

p.s. you have to include the file correctly!

include_once(ABSPATH.'wp-includes/user.php'); 
    0

    You probably call wp_signon too early. You first need to let all of the wordpress core to load before calling it

    2
    • thanks for the reply, but can you help me on how to let all wordpress core to load?CommentedJan 7, 2016 at 13:37
    • @MeenalGupta, from your comment on the question, you are just doing it wrong, you should not add anything to wordpress core directories, and you should not directly access any file which is not on wordpress root directory or the ajax end point. Without more context about what you actually want to do it is hard to be more specific.CommentedJan 7, 2016 at 14:08

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.