O desenvolvedor do plug-in precisa criar uma página assim que o plug-in for ativado. O gancho de ação ajuda o desenvolvedor do plugin a fazer isso. Aqui está o código de exemplo:
define( 'PLUGIN_FILE_PATH', __FILE__ );
register_activation_hook( PLUGIN_FILE_PATH, 'insert_page_on_activation' );
function insert_page_on_activation() {
if ( ! current_user_can( 'activate_plugins' ) ) return;
$page_slug = 'test-page-title'; // Slug of the Post
$new_page = array(
'post_type' => 'page', // Post Type Slug eg: 'page', 'post'
'post_title' => 'Test Page Title', // Title of the Content
'post_content' => 'Test Page Content', // Content
'post_status' => 'publish', // Post Status
'post_author' => 1, // Post Author ID
'post_name' => $page_slug // Slug of the Post
);
if (!get_page_by_path( $page_slug, OBJECT, 'page')) { // Check If Page Not Exits
$new_page_id = wp_insert_post($new_page);
}
}
Você pode inserir este código no arquivo PHP principal do seu plugin.