admin管理员组

文章数量:1326461

I'm writing my first plugin and I have problem. I don't know how to write function, which create page with selected specific template after activate plugin.

function add_my_custom_page() {
    // Create post object
    $my_post = array(
        'post_title'    => wp_strip_all_tags( 'Example form' ),
        'post_status'   => 'publish',
        'post_author'   => 1,
        'post_type'     => 'page',
    );

    // Insert the post into the database
    wp_insert_post( $my_post );
}

register_activation_hook(__FILE__, 'add_my_custom_page');

add_filter( 'page_template', 'wpa3396_page_template' );
function wpa3396_page_template( $page_template )
{
    if ( is_page( 'my-custom-page-slug' ) ) {
        $page_template = dirname( __FILE__ ) . '/form/haccp-form.php';
    }
    return $page_template;
}

本文标签: How to create a page with the selected template after activating the plugin