插件查询代码中出现未定义的IS_USER_LOGGED_IN()错误

时间:2013-09-27 作者:Ben Racicot

我得到一个:

 Fatal error: Call to undefined function is_user_logged_in() in C:\\wamp\\www\\benracicot\\wp-includes\\query.php on line 2521
如果我从WP\\u查询中删除$args,则不会出现任何错误,并且可以打印返回对象(所有空值),那么我的插件查询代码有什么错?

function getPostIDsByMonth($month){
    $args = array( \'monthnum\' => 1, \'post_type\' => \'post\' );
    $ids = new WP_Query($args);
    return $ids;
}

$months = 1;
$bymonth = getPostIDsByMonth($months);
print_r($bymonth);
echo $bymonth->post_count;
if (! empty($bymonth)){

     while($bymonth->have_posts()): $bymonth->the_post(); 
        ?><h3><a href="#"><?php the_title(); ?></a></h3><?php 
        the_content();
     endwhile;

}

1 个回复
SO网友:shine
require_once( wp_normalize_path(ABSPATH).\'wp-load.php\');

class Your_Plugin_Class {
    private  $is_user_logged_in;

    add_action(\'init\', function(){
        $this-> is_user_logged_in = is_user_logged_in();
        echo \'is_user_logged_in\'.$this->is_user_logged_in;
    });

    add_filter(\'woocommerce_billing_fields-2\',array( $this, \'add_billing_field\' ));

   }

    public function add_billing_field( $fields = array() ) {
        if ( $this->is_user_logged_in  ){
            echo \'add_billing_field\'.$this->is_user_logged_in;
            return $fields;
        }else{
            echo \'add_billing_field\'.$this->is_user_logged_in;
        }
    }
}
结束

相关推荐