我发现以下错误Fatal error: Call to a member function get_page_permastruct() /link-template.php on line 276
当我调用类内构造函数时wp_insert_post($new_post);
.
add_action( \'plugins_loaded\', array ( \'test\', \'init\' ) );
class test{
public static function init()
{
new self;
}
//the consructor for parser admin
function __construct(){
global $wpdb;
$this->db = $wpdb;
if ($_POST[\'action\'] == \'add-page\'){
add_action( \'plugins_loaded\', array ( $this, \'add_newpage\' ) );
$this->add_newpage();
}
public function add_newpage(){
$new_post = array(
\'post_title\' => $_POST[\'page-name\'],
\'post_content\' => \'\',
\'post_status\' => \'publish\',
\'post_type\' => \'page\'
);
$post_id = wp_insert_post($new_post);
$newtarget = $this->db->insert(
\'wp_test_table\',
array(
\'post_id\' => $post_id,
\'slug\' => \'test\'
),
array(
\'%d\',
\'%s\'
)
);
}
}