There will be no theme support from 23rd December to January 1st. Support will resume January 2nd.

Okay
  Print

How to I add new child pages to auto hub form?

If you want to create a new child page that is automatically added to your hubs when using the auto hub form read below. I'm going to use the example of creating a custom Preview child page for your hub.

1) Create a new page template for your preview pages (for example just copy the review-template.php file and rename it to preview-template.php). Open the file and at the top of the page change the template name to whatever you want to call it e.g. Preview. You may want to modify the look of this template afterwards.

2) In your child functions.php file add:

// Add preview checkbox option to automatic hub creation form
function ghostpool_custom_hub_options() {
    echo __( 'Preview', 'gauge' ) . ' <input type="checkbox" name="gp_preview_page" id="gp-preview-page" value="1" checked="checked" />';
}
// Generate preview page from automatic hub creation form
function ghostpool_custom_hub_page( $gp_hub_page_id, $gp_hub_title_prefix ) {
    // Preview Page
    if ( isset( $_POST['gp_preview_page'] ) && $_POST['gp_preview_page'] == '1' ) {
        $gp_new_page_title = $gp_hub_title_prefix . esc_html__( 'Preview', 'gauge' );
        $gp_new_page_content = '';
        $gp_new_page = array(
            'post_type'      => 'page',
            'post_date'      => esc_attr( $_POST['ghostpool_date_time'] ),
            'post_date_gmt'  => esc_attr( $_POST['ghostpool_date_time'] ),
            'post_title'     => esc_attr( $gp_new_page_title ),
            'post_name'      => sanitize_title( $gp_hub_url_prefix . '-' . esc_html__( 'preview', 'gauge' ) ),
            'post_content'   => $gp_new_page_content,
            'post_status'    => 'publish',
            'comment_status' => 'closed',
            'post_parent'    => $gp_hub_page_id
        );
        $gp_new_page_id = wp_insert_post( $gp_new_page );
        update_post_meta( $gp_new_page_id, '_wp_page_template', 'preview-template.php' );            
        update_post_meta( $gp_new_page_id, '_gp_hub_page', 'enabled' );
    }    
}
// Preview page hub tab options
function ghostpool_add_custom_hub_tabs( $value, $type, $gp_hub_tab, $tab_id ) {
    if ( $tab_id == 1 ) {
        if ( $type == 'page_template' ) {
            return 'preview-template.php'; // template file name
        }
        if ( $type == 'tab' ) {
            return 'enabled'; // change to 'disabled' to hide this page from the hub tabs
        }
        if ( $type == 'tab_title' ) {
            return 'Preview'; // the title shown in the hub tabs
        }
        if ( $type == 'tab_link' ) {
            return ''; // custom link
        }
        if ( $type == 'tab_target' ) {
            return ''; // custom link target
        }
    }
}
add_filter( 'ghostpool_custom_hub_tabs', 'ghostpool_add_custom_hub_tabs', 10, 4 );