• Resolved Muhammad Rizwan

    (@rizwan_47)


    Hi there,

    I am developing a Wp Plugin. While using wp_insert_post I got this error:

    Fatal error: Call to undefined function is_user_logged_in() in /home/designs/public_html/WP/wp-includes/post.php on line 2185

    Here is the file on pastebin: http://pastebin.com/YETGT4dK This file is included in main plugin file. See from line 93

    Thank you !

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Muhammad Rizwan

    (@rizwan_47)

    Solved it !

    A friend answered another forum:

    The problem is that is_user_logged_in is a pluggable function, and is therefore loaded after this plugin logic is called. The solution is to make sure that you don’t call this too early. This can be done by wrapping this logic in a function and calling it from ‘init’

    like:

    function rizwan_insert_coupons()
    {
        if(isset($_POST['save_coupons']) and $_POST['save_coupons']=='yes'){
    
            //lots of stuff
    
            /*
             * Inserting New Coupon as Post
            */
            $post = array();
            $post['post_status']   = 'publish';
            $post['post_type']     = 'coupons';
            $post['post_title']    = $title;
            $post['post_content']  = $description;
    
            $post_id = wp_insert_post( $post );
    
            //lots more stuff
    
        }
    }
    add_action('init', 'rizwan_inert_coupons');

    So Google. it’s run to me. Im added add_action(‘init’, ‘rizwan_inert_coupons’); to functions.

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

The topic ‘Fatal error: Call to undefined function is_user_logged_in()’ is closed to new replies.