Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 安装插件时创建页面_Php_Wordpress - Fatal编程技术网

Php 安装插件时创建页面

Php 安装插件时创建页面,php,wordpress,Php,Wordpress,我正在创建WordPress插件,现在我想在插件安装后创建一个页面。请帮助我如何在安装时创建页面您必须使用WordPress插件激活挂钩添加名为“注册激活挂钩”的新页面。当你的插件激活时,它会调用 register_activation_hook( __FILE__, 'insert_page' ); function insert_page(){ // Create post object $pageArray = array( 'post_title' =

我正在创建WordPress插件,现在我想在插件安装后创建一个页面。请帮助我如何在安装时创建页面您必须使用WordPress插件激活挂钩添加名为“注册激活挂钩”的新页面。当你的插件激活时,它会调用

register_activation_hook( __FILE__, 'insert_page' );

function insert_page(){
    // Create post object
    $pageArray = array(
      'post_title'    => 'My Page',
      'post_content'  => 'This is my page.',
      'post_status'   => 'publish',
      'post_author'   => get_current_user_id(),
      'post_type'     => 'page',
    );

    // Insert the post into the database
    wp_insert_post( $pageArray, '' );
}