*** Ticksy security was compromised on August 17th. It is recommended you change your Ticksy password and update any WordPress and FTP credentials that you have posted on this website. There is no evidence any details were taken - this is just a precaution. ***

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_custom_hub_tabs( $gp_hub_tab ) {

    if ( get_post_meta( $gp_hub_tab->ID, '_wp_page_template', true ) == 'preview-template.php' ) {
        $gp_tab = 'enabled'; // change to 'disabled' to hide this page from the hub tabs
        $gp_tab_title = esc_html__( 'Preview', 'gauge' ); // the title shown in the hub tabs
        $gp_tab_link = ''; // custom link
        $gp_tab_target = ''; // custom link target
    }    

}

For older versions of the theme use:

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) To specify the tab information for pages using the "Preview" page template open gauge/lib/sections/hub-tabs.php and find:

} elseif ( get_post_meta( $gp_hub_tab->ID, '_wp_page_template', true ) == 'link-template.php' ) {
    $gp_tab = redux_post_meta( 'gp', $gp_hub_tab->ID, 'link_template_tab' );
    $gp_tab_title = redux_post_meta( 'gp', $gp_hub_tab->ID, 'link_template_tab_title' );
    $gp_tab_link = redux_post_meta( 'gp', $gp_hub_tab->ID, 'link_template_link' );
    $gp_tab_target = redux_post_meta( 'gp', $gp_hub_tab->ID, 'link_template_link_target' );

Below this add:

} elseif ( get_post_meta( $gp_hub_tab->ID, '_wp_page_template', true ) == 'preview-template.php' ) {
    $gp_tab = 'enabled'; // change to 'disabled' to hide this page from the hub tabs
    $gp_tab_title = 'Preview'; // the title shown in the hub tabs
    $gp_tab_link = ''; // custom link
    $gp_tab_target = ''; // custom link target

3) Now to add the "Preview" check box option to the auto hub form open lib/inc/auto-hub-pages.php and find:

<?php _e( "User Reviews", "gauge" ); ?> <input type="checkbox" name="gp_user_reviews_page" id="gp-user-reviews-page" value="1" checked="checked" />

Next to this add:

 <?php _e( "Preview", "gauge" ); ?> <input type="checkbox" name="gp_preview_page" id="gp-preview-page" value="1" checked="checked" />

Next find:

// User Reviews Page
if ( isset( $_POST['gp_user_reviews_page'] ) && $_POST['gp_user_reviews_page'] == '1' ) {
    $gp_new_page_title = $gp_hub_title_prefix . esc_html__( 'User Reviews', '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__( 'user-reviews', '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', 'user-reviews-template.php' );            
    update_post_meta( $gp_new_page_id, '_gp_hub_page', 'enabled' );
}

Below this add:

// 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' );
}

Do the same for each child page you want to add.