Huber

My site crashes when I try to create a new post/page?

The "Hub Association" and "Custom Tab" options on posts and pages try to query every hub on your site so you can easily select them from the dropdown menu. If you have a huge amount of these hubs this may exceed your server's memory limit or maximum execution time. You can increase the memory limit as explained here and you can increase the maximum execution time using this plugin.

If this doesn't resolve the issue you can convert the drop down menus to ordinary text boxes where you manually enter the hubs IDs. To do this add the following code to your child theme's functions.php file:

// Hub Association Option
function ghostpool_change_hub_association_option_type() {
    return array(
        'id'      => 'hub_association_ids',
        'type'    => 'text',
        'title'   => esc_html__( 'Hub Association', 'huber' ),
        'desc' => esc_html__( 'Enter the hub IDs separating each one with a comma between quotation marks e.g. "405","32","21". This post will then display under the Reviews, News or Videos tab on the selected hubs.', 'huber' ),
        'default' => '',
    );                    
}
// Custom Tab Option
function ghostpool_custom_hub_tab_option_type() {
    return array(
        'id'      => 'custom_hub_tab_ids',
        'type'    => 'text',
        'title'   => esc_html__( 'Custom Tab', 'huber' ),
        'desc' => esc_html__( 'Make this page a hub tab by entering the hub IDs separating each one with a comma between quotation marks e.g. "405","32","21".', 'huber' ),
        'default' => '',
    );                    
}

If you already have been using these options as drop down menus you will need to convert your existing values to comma separated values between quotation marks. To do this add the following to your child theme's functions.php file. This converts 200 posts at a time, you can increase this number to change more posts at once:

if ( get_option( 'huber_converted_hub_association_option' ) != '1' ) {
    $args = array(
        'post_type' => array( 'post', 'page' ),
        'post_status' => array( 'publish', 'future' ), 
        'meta_key' => 'hub_association_ids',
        'posts_per_page' => '200', 
        'orderby' => 'date', 
        'order' => 'desc',
        'no_found_rows'  => true,
        'cache_results' => false,
        'update_post_meta_cache' => false,
        'update_post_term_cache' => false,
    );
    $posts = get_posts( $args );
    if ( ! empty ( $posts ) ) {
        foreach ( $posts as $post ) {            
            if ( get_post_meta( $post->ID, 'hub_association_ids', true ) && is_array( get_post_meta( $post->ID, 'hub_association_ids', true ) ) ) {
                $array = '';
                $values = ( get_post_meta( $post->ID, 'hub_association_ids', true ) );
                foreach ( $values as $value ) {        
                    $array[] = $value;
                }
                $string = '"' . implode( '", "', $array ) . '"';
                update_post_meta( $post->ID, 'hub_association_ids', $string );
            }
        }
    } else {
        update_option( 'huber_converted_hub_association_option', '1' );
    }
    
}
if ( get_option( 'huber_converted_custom_hub_tab_option' ) != '1' ) {
    $args = array(
        'post_type' => array( 'post', 'page' ),
        'post_status' => array( 'publish', 'future' ), 
        'meta_key' => 'custom_hub_tab_ids',
        'posts_per_page' => '200', 
        'orderby' => 'date', 
        'order' => 'desc',
        'no_found_rows'  => true,
        'cache_results' => false,
        'update_post_meta_cache' => false,
        'update_post_term_cache' => false,
    );
    $posts = get_posts( $args );
    if ( ! empty ( $posts ) ) {
        foreach ( $posts as $post ) {            
            if ( get_post_meta( $post->ID, 'custom_hub_tab_ids', true ) && is_array( get_post_meta( $post->ID, 'custom_hub_tab_ids', true ) ) ) {
                $array = '';
                $values = ( get_post_meta( $post->ID, 'custom_hub_tab_ids', true ) );
                foreach ( $values as $value ) {        
                    $array[] = $value;
                }
                $string = '"' . implode( '", "', $array ) . '"';
                update_post_meta( $post->ID, 'custom_hub_tab_ids', $string );
            }
        }
    } else {
        update_option( 'huber_converted_custom_hub_tab_option', '1' );
    }
    
}