/**
 * Modifies the front-end as per the landing page settings set in the post editor screen.
 * @return none
 * @since 1.0
 */
function landing_page_settings()
{
    if (!current_theme_supports('cuttz-landing-page-experience')) {
        return;
    }
    if (cuttz_is_mobile()) {
        // Bail, if on mobile or if not single post type
        return;
    }
    if (!is_singular() && !cuttz_is_woo_shop()) {
        return;
    }
    if (get_option('show_on_front') === 'page' && is_home()) {
        $page_id = get_option('page_for_posts');
    } else {
        if (cuttz_is_woo_shop()) {
            $page_id = wc_get_page_id('shop');
        } else {
            $page_id = get_the_ID();
        }
    }
    /* Execute all the other hide/show options in Landing Page Experience metabox */
    $cuttz_template_options = get_post_meta($page_id, '_cuttz_template_options', 1);
    $hide_header = isset($cuttz_template_options['hide-header']) ? $cuttz_template_options['hide-header'] : false;
    $hide_breadcrumbs = isset($cuttz_template_options['hide-breadcrumbs']) ? $cuttz_template_options['hide-breadcrumbs'] : false;
    $hide_page_title = isset($cuttz_template_options['hide-page-title']) ? $cuttz_template_options['hide-page-title'] : false;
    $hide_widgets_above_header = isset($cuttz_template_options['hide-widgets-above-header']) ? $cuttz_template_options['hide-widgets-above-header'] : false;
    $hide_widgets_below_header = isset($cuttz_template_options['hide-widgets-below-header']) ? $cuttz_template_options['hide-widgets-below-header'] : false;
    $hide_widgets_above_footer = isset($cuttz_template_options['hide-widgets-above-footer']) ? $cuttz_template_options['hide-widgets-above-footer'] : false;
    $hide_after_entry_widget = isset($cuttz_template_options['hide-after-entry-widget']) ? $cuttz_template_options['hide-after-entry-widget'] : false;
    $hide_footer_widgets = isset($cuttz_template_options['hide-footer-widgets']) ? $cuttz_template_options['hide-footer-widgets'] : false;
    $hide_footer = isset($cuttz_template_options['hide-footer']) ? $cuttz_template_options['hide-footer'] : false;
    if ($hide_header) {
        remove_action('genesis_header', 'genesis_header_markup_open', 5);
        remove_action('genesis_header', 'genesis_header_markup_close', 15);
        remove_action('genesis_header', 'genesis_do_header');
    }
    if ($hide_breadcrumbs) {
        // Do not remove breadcrumbs as per SEO guidelines; hide it via CSS instead
        add_filter('body_class', 'cuttz_seo_hide_breadcrumbs');
    }
    if ($hide_page_title) {
        if (!is_home()) {
            add_filter('post_class', 'cuttz_hide_title_class');
        }
        if (in_array('woocommerce/woocommerce.php', get_option('active_plugins'))) {
            if (is_woocommerce() || is_cart() || is_checkout()) {
                add_filter('woocommerce_show_page_title', '__return_false');
            }
        }
    }
    if ($hide_widgets_above_header) {
        remove_action('genesis_before_header', 'cuttz_sidebar_before_header');
    }
    if ($hide_widgets_below_header) {
        remove_action('genesis_after_header', 'cuttz_sidebar_after_header');
    }
    if ($hide_widgets_above_footer) {
        remove_action('genesis_before_footer', 'cuttz_sidebar_above_footer', 5);
    }
    if ($hide_after_entry_widget) {
        remove_theme_support('genesis-after-entry-widget-area');
    }
    if ($hide_footer_widgets) {
        remove_action('genesis_before_footer', 'genesis_footer_widget_areas');
    }
    if ($hide_footer) {
        remove_action('genesis_footer', 'cuttz_do_nav_footer', 5);
        remove_action('genesis_footer', 'genesis_footer_markup_open', 5);
        remove_action('genesis_footer', 'genesis_footer_markup_close', 5);
        remove_action('genesis_footer', 'genesis_do_footer');
    }
}
/**
 * Used to build/show the mobile template on the front-end
 * @return type
 * @since 1.0
 */
function cuttz_display_mobile_view()
{
    if (!current_theme_supports('cuttz-mobile-landing-page-experience')) {
        return;
    }
    // Bail if not visiting on mobile
    if (!cuttz_is_mobile()) {
        return;
    }
    if (is_home()) {
        $page_id = get_option('page_for_posts');
    } else {
        if (cuttz_is_woo_shop()) {
            $page_id = wc_get_page_id('shop');
        } else {
            $page_id = get_the_ID();
        }
    }
    $cuttz_mobile_landing_optionset = get_post_meta($page_id, '_cuttz_mobile_landing_options', 1);
    $use_global = is_array($cuttz_mobile_landing_optionset) && array_key_exists('mobile_use_global', $cuttz_mobile_landing_optionset) ? $cuttz_mobile_landing_optionset['mobile_use_global'] : true;
    if ($use_global) {
        $hide_header = genesis_get_option('mlp_hide_header', CHILD_SETTINGS_FIELD_EXTRAS, false);
        $hide_breadcrumbs = genesis_get_option('mlp_hide_breadcrumbs', CHILD_SETTINGS_FIELD_EXTRAS, false);
        $hide_page_title = genesis_get_option('mlp_hide_page_title', CHILD_SETTINGS_FIELD_EXTRAS, false);
        $hide_widgets_above_header = genesis_get_option('mlp_hide_widgets_above_header', CHILD_SETTINGS_FIELD_EXTRAS, false);
        $hide_widgets_below_header = genesis_get_option('mlp_hide_widgets_below_header', CHILD_SETTINGS_FIELD_EXTRAS, false);
        $hide_widgets_above_footer = genesis_get_option('mlp_hide_widgets_above_footer', CHILD_SETTINGS_FIELD_EXTRAS, false);
        $hide_after_entry_widget = genesis_get_option('mlp_hide_after_entry_widget', CHILD_SETTINGS_FIELD_EXTRAS, false);
        $hide_sidebars = genesis_get_option('mlp_hide_sidebars', CHILD_SETTINGS_FIELD_EXTRAS, false);
        $hide_footer_widgets = genesis_get_option('mlp_hide_fwidgets', CHILD_SETTINGS_FIELD_EXTRAS, false);
        $hide_footer = genesis_get_option('mlp_hide_footer', CHILD_SETTINGS_FIELD_EXTRAS, false);
    } else {
        if (!is_singular() && !cuttz_is_woo_shop()) {
            return;
        }
        $hide_header = isset($cuttz_mobile_landing_optionset['mobile-hide-header']) ? $cuttz_mobile_landing_optionset['mobile-hide-header'] : false;
        $hide_breadcrumbs = isset($cuttz_mobile_landing_optionset['mobile-hide-breadcrumbs']) ? $cuttz_mobile_landing_optionset['mobile-hide-breadcrumbs'] : false;
        $hide_page_title = isset($cuttz_mobile_landing_optionset['mobile-hide-page-title']) ? $cuttz_mobile_landing_optionset['mobile-hide-page-title'] : false;
        $hide_widgets_above_header = isset($cuttz_mobile_landing_optionset['mobile-hide-widgets-above-header']) ? $cuttz_mobile_landing_optionset['mobile-hide-widgets-above-header'] : false;
        $hide_widgets_below_header = isset($cuttz_mobile_landing_optionset['mobile-hide-widgets-below-header']) ? $cuttz_mobile_landing_optionset['mobile-hide-widgets-below-header'] : false;
        $hide_widgets_above_footer = isset($cuttz_mobile_landing_optionset['mobile-hide-widgets-above-footer']) ? $cuttz_mobile_landing_optionset['mobile-hide-widgets-above-footer'] : false;
        $hide_after_entry_widget = isset($cuttz_mobile_landing_optionset['mobile-hide-after-entry-widget']) ? $cuttz_mobile_landing_optionset['mobile-hide-after-entry-widget'] : false;
        $hide_sidebars = isset($cuttz_mobile_landing_optionset['mobile-hide-sidebars']) ? $cuttz_mobile_landing_optionset['mobile-hide-sidebars'] : false;
        $hide_footer_widgets = isset($cuttz_mobile_landing_optionset['mobile-hide-footer-widgets']) ? $cuttz_mobile_landing_optionset['mobile-hide-footer-widgets'] : false;
        $hide_footer = isset($cuttz_mobile_landing_optionset['mobile-hide-footer']) ? $cuttz_mobile_landing_optionset['mobile-hide-footer'] : false;
    }
    /** Disable options if selected in the metabox. Hides the relevant page elements if disabled on a page **/
    if ($hide_header) {
        remove_action('genesis_header', 'genesis_header_markup_open', 5);
        remove_action('genesis_header', 'genesis_header_markup_close', 15);
        remove_action('genesis_header', 'genesis_do_header');
    }
    if ($hide_breadcrumbs) {
        // Do not remove breadcrumbs as per SEO guidelines; hide it via CSS instead
        add_filter('body_class', 'cuttz_seo_hide_breadcrumbs');
    }
    if ($hide_page_title) {
        if (!is_home()) {
            add_filter('post_class', 'cuttz_hide_title_class');
        }
        if (in_array('woocommerce/woocommerce.php', get_option('active_plugins'))) {
            if (is_woocommerce() || is_cart() || is_checkout()) {
                add_filter('woocommerce_show_page_title', '__return_false');
            }
        }
    }
    if ($hide_widgets_above_header) {
        remove_action('genesis_before_header', 'cuttz_sidebar_before_header');
    }
    if ($hide_widgets_below_header) {
        remove_action('genesis_after_header', 'cuttz_sidebar_after_header');
    }
    if ($hide_widgets_above_footer) {
        remove_action('genesis_before_footer', 'cuttz_sidebar_above_footer', 5);
    }
    if ($hide_after_entry_widget) {
        remove_theme_support('genesis-after-entry-widget-area');
    }
    if ($hide_sidebars) {
        // Force full-width-content layout setting
        add_filter('genesis_site_layout', 'cuttz_force_full_width_layout');
    }
    if ($hide_footer_widgets) {
        remove_action('genesis_before_footer', 'genesis_footer_widget_areas');
    }
    if ($hide_footer) {
        remove_action('genesis_footer', 'cuttz_do_nav_footer', 5);
        remove_action('genesis_footer', 'genesis_footer_markup_open', 5);
        remove_action('genesis_footer', 'genesis_footer_markup_close', 5);
        remove_action('genesis_footer', 'genesis_do_footer');
    }
}
Esempio n. 3
0
function cuttz_get_menus($args)
{
    if (!current_theme_supports('cuttz-custom-menus')) {
        return $args;
    }
    if (is_category() || is_tag() || is_tax()) {
        $cuttz_tax_menus = get_option('cuttz-tax-meta');
        $cuttz_tax_menus = is_array($cuttz_tax_menus) ? array_filter($cuttz_tax_menus) : false;
        // Sometimes empty array elements will throw a warning in the foreach loop, so remove all empty elements from the array
        if (!$cuttz_tax_menus) {
            return $args;
        }
        if ($cuttz_tax_menus) {
            foreach ($cuttz_tax_menus as $term_id => $menu_locations) {
                if (is_category($term_id) || is_tag($term_id) || is_tax($term_id)) {
                    foreach ($menu_locations as $menu_location => $menu_id) {
                        if ($args['theme_location'] == $menu_location) {
                            //if
                            if ($menu_id != '-2') {
                                //if something custom is set
                                $args['menu'] = $menu_id;
                                $args['fallback_cb'] = -1;
                                $args['theme_location'] = -1;
                            }
                        }
                    }
                }
            }
        }
    }
    if (is_single() || is_page() || is_home() || cuttz_is_woo_shop()) {
        if (is_home()) {
            $page_id = get_option('page_for_posts');
        } else {
            if (cuttz_is_woo_shop()) {
                $page_id = wc_get_page_id('shop');
            } else {
                $page_id = get_the_ID();
            }
        }
        $cuttz_menu_value = get_post_meta($page_id, '_cuttz_custom_menus', true);
        $cuttz_menu_value = maybe_unserialize($cuttz_menu_value);
        if ($cuttz_menu_value) {
            foreach ($cuttz_menu_value as $menu_location => $menu_id) {
                if ($args['theme_location'] == $menu_location) {
                    // cuttz_get_menus is called on every menu. Check if wp is calling us for the same location as the menu location set in post meta
                    if ($menu_id != '-2') {
                        //if something custom is set
                        $args['menu'] = $menu_id;
                        $args['fallback_cb'] = -1;
                        $args['theme_location'] = -1;
                    }
                }
            }
        }
    }
    return $args;
}