Auto add content such as pages upon plugin activation?

I’m creating my first plugin and it requires some pages with content to functionally work properly.

I was wondering if it is possible to show a message like “Click here to automatically add the required pages for this plugin” in the wordpress plugins area.

Read More

So when the user activates the plugin this message will show and if the user clicks the button a function will run that will add the pages necessary.

Any help in direction most appreciated.

Matt

Related posts

Leave a Reply

1 comment

  1. You can add those without a button:

    register_activation_hook( __FILE__, 'my_plugin_install_function');
    
    function my_plugin_install_function()
      {
       //post status and options
        $post = array(
              'comment_status' => 'closed',
              'ping_status' =>  'closed' ,
              'post_author' => 1,
              'post_date' => date('Y-m-d H:i:s'),
              'post_name' => 'Checklists',
              'post_status' => 'publish' ,
              'post_title' => 'Checklists',
              'post_type' => 'page',
        );  
        //insert page and save the id
        $newvalue = wp_insert_post( $post, false );
        //save the id in the database
        update_option( 'hclpage', $newvalue );
      }
    

    This function will run when the user installs the plugin. For super smart control you should check if that option already exists and if the id is not 0 (that means failure)