is_header_footer_builder_active ) { add_action( 'astra_adv_headers_tabs_site-header_action', array( $this, 'hfb_site_header_tab' ), 10, 1 ); } else { add_action( 'astra_adv_headers_tabs_site-header_action', array( $this, 'site_header_tab' ), 10, 1 ); } add_action( 'astra_adv_headers_tabs_display-rules_action', array( $this, 'display_rules_tab' ), 10, 1 ); add_action( 'astra_advanced_headers_settings_markup_after', array( $this, 'current_tab_holder' ) ); add_filter( 'redirect_post_location', array( $this, 'retain_currnt_tab' ) ); } /** * Add a hidden field in the Advanced Headers meta box for holding the current tab id. * * @return void */ public function current_tab_holder() { ?> $current_tab, ), $location ) ); } } return $location; } /** * Keep the Astra menu open when editing the advanced headers. * Highlights the wanted admin (sub-) menu items for the CPT. * * @since 1.0.0 */ public function menu_highlight() { global $post_type; if ( 'astra_adv_header' == $post_type ) : /* Same display rule assign notice */ $option = array( 'location' => 'ast-advanced-headers-location', 'exclusion' => 'ast-advanced-headers-exclusion', 'users' => 'ast-advanced-headers-users', ); Astra_Target_Rules_Fields::same_display_on_notice( 'astra_adv_header', $option ); endif; } /** * Init Metabox */ public function init_metabox() { add_action( 'add_meta_boxes', array( $this, 'setup_meta_box' ) ); add_action( 'save_post', array( $this, 'save_meta_box' ) ); $default_above_header = $this->get_default_header_sections( 'above-header-layout' ); $default_below_header = $this->get_default_header_sections( 'below-header-layout' ); /** * Set metabox options * * @see https://php.net/manual/en/filter.filters.sanitize.php */ self::$meta_option = apply_filters( 'astra_advanced_headers_meta_box_options', array( 'ast-advanced-headers-layout' => array( 'default' => array( 'layout' => 'advanced-headers-layout-2', 'breadcrumb' => '', 'force-transparent-disabled' => 'yes', 'above-header-enabled' => $default_above_header, 'below-header-enabled' => $default_below_header, ), 'sanitize' => 'FILTER_SANITIZE_STRING', ), 'ast-advanced-headers-design' => array( 'default' => array( 'title-color' => '#ffffff', 'b-text-color' => '', 'b-link-color' => '', 'b-link-hover-color' => '', 'background-color' => 'rgba(44,62,80,0.50)', 'bg-image-id' => '', 'bg-image' => '', 'page-post-featured' => 'enabled', 'logo-id' => '', 'logo-url' => '', 'retina-logo-id' => '', 'retina-logo-url' => '', 'header-logo-width' => '', 'header-bg-color' => '', 'site-title-color' => '', 'site-title-h-color' => '', 'site-tagline-color' => '', 'primary-menu-bg-color' => '', 'primary-menu-color' => '', 'primary-menu-h-color' => '', 'primary-menu-a-color' => '', 'primary-submenu-bg-color' => '', 'primary-submenu-color' => '', 'primary-submenu-h-color' => '', 'primary-submenu-a-color' => '', 'above-header-bg-color' => '', 'above-header-text-link-color' => '', 'above-header-h-color' => '', 'above-header-a-color' => '', 'above-header-submenu-bg-color' => '', 'above-header-submenu-link-color' => '', 'above-header-submenu-h-color' => '', 'above-header-submenu-a-color' => '', 'below-header-bg-color' => '', 'below-header-text-link-color' => '', 'below-header-h-color' => '', 'below-header-a-color' => '', 'below-header-submenu-bg-color' => '', 'below-header-submenu-link-color' => '', 'below-header-submenu-h-color' => '', 'below-header-submenu-a-color' => '', 'header-main-sep' => '', 'header-main-sep-color' => '', 'bg-size' => 'custom-bg-size', 'bg-custom-size-top-padding' => '5', 'bg-custom-size-bottom-padding' => '5', 'parallax-device' => 'none', 'overlay-bg-color' => '', 'custom-menu' => '', 'custom-menu-item' => 'default', 'custom-menu-item-outside' => '', 'custom-menu-item-text-html' => '', 'search-style' => 'default', ), 'sanitize' => 'FILTER_SANITIZE_STRING', ), 'ast-advanced-headers-location' => array( 'default' => array(), 'sanitize' => 'FILTER_SANITIZE_STRING', ), 'ast-advanced-headers-exclusion' => array( 'default' => array(), 'sanitize' => 'FILTER_SANITIZE_STRING', ), 'ast-advanced-headers-users' => array( 'default' => array(), 'sanitize' => 'FILTER_SANITIZE_STRING', ), ) ); } /** * Setup Metabox */ public function setup_meta_box() { // Get all posts. $post_types = get_post_types(); if ( 'astra_adv_header' == get_post_type() ) { // Enable for all posts. foreach ( $post_types as $type ) { if ( 'attachment' !== $type ) { add_meta_box( 'astra_advanced_headers_settings', // Id. __( 'Page Headers Settings', 'astra-addon' ), // Title. array( $this, 'markup_meta_box' ), // Callback. $type, // Post_type. 'normal', // Context. 'default' // Priority. ); } } } } /** * Get metabox options */ public static function get_meta_option() { return self::$meta_option; } /** * Get Default Header enabled sections * * @param string $header_section header section key. * @return string $section enabled | ''. */ public function get_default_header_sections( $header_section ) { $section = ''; $section_option = astra_get_option( $header_section ); if ( Astra_Ext_Extension::is_active( 'header-sections' ) && 'disabled' != $section_option ) { $section = 'enabled'; } return $section; } /** * Metabox Markup * * @param object $post Post object. * * @return void */ public function markup_meta_box( $post ) { wp_nonce_field( basename( __FILE__ ), 'astra-advanced-headers' ); $stored = get_post_meta( $post->ID ); $advanced_headers_meta = array( 'ast-advanced-headers-layout', 'ast-advanced-headers-design', 'ast-advanced-headers-location', 'ast-advanced-headers-exclusion', 'ast-advanced-headers-users', ); // Set stored and override defaults. foreach ( $stored as $key => $value ) { if ( in_array( $key, $advanced_headers_meta ) ) { self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? maybe_unserialize( $stored[ $key ][0] ) : ''; } else { self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? $stored[ $key ][0] : ''; } } // Get defaults. $meta = self::get_meta_option(); $default_above_header = $this->get_default_header_sections( 'above-header-layout' ); $default_below_header = $this->get_default_header_sections( 'below-header-layout' ); /** * Get options */ $ast_advanced_headers_layout = ( isset( $meta['ast-advanced-headers-layout']['default'] ) ) ? $meta['ast-advanced-headers-layout']['default'] : array( 'layout' => 'advanced-headers-layout-2', 'breadcrumb' => '', 'force-transparent-disabled' => 'yes', 'above-header-enabled' => $default_above_header, 'below-header-enabled' => $default_below_header, ); $ast_advanced_headers_design = ( isset( $meta['ast-advanced-headers-design']['default'] ) ) ? $meta['ast-advanced-headers-design']['default'] : array( 'title-color' => '#ffffff', 'b-text-color' => '', 'b-link-color' => '', 'b-link-hover-color' => '', 'background-color' => 'rgba(44,62,80,0.50)', 'bg-image-id' => '', 'bg-image' => '', 'page-post-featured' => 'enabled', 'logo-id' => '', 'logo-url' => '', 'retina-logo-id' => '', 'retina-logo-url' => '', 'header-logo-width' => '', 'header-bg-color' => '', 'site-title-color' => '', 'site-title-h-color' => '', 'site-tagline-color' => '', 'primary-menu-bg-color' => '', 'primary-menu-color' => '', 'primary-menu-h-color' => '', 'primary-menu-a-color' => '', 'primary-submenu-bg-color' => '', 'primary-submenu-color' => '', 'primary-submenu-h-color' => '', 'primary-submenu-a-color' => '', 'above-header-bg-color' => '', 'above-header-text-link-color' => '', 'above-header-h-color' => '', 'above-header-a-color' => '', 'above-header-submenu-bg-color' => '', 'above-header-submenu-link-color' => '', 'above-header-submenu-h-color' => '', 'above-header-submenu-a-color' => '', 'below-header-bg-color' => '', 'below-header-text-link-color' => '', 'below-header-h-color' => '', 'below-header-a-color' => '', 'below-header-submenu-bg-color' => '', 'below-header-submenu-link-color' => '', 'below-header-submenu-h-color' => '', 'below-header-submenu-a-color' => '', 'header-main-sep' => '', 'header-main-sep-color' => '', 'bg-size' => 'custom-bg-size', 'bg-custom-size-top-padding' => '5', 'bg-custom-size-bottom-padding' => '5', 'parallax-device' => 'none', 'overlay-bg-color' => '', 'custom-menu' => '', 'custom-menu-item' => 'default', 'custom-menu-item-outside' => '', 'custom-menu-item-text-html' => '', 'search-style' => 'default', ); $display_locations = ( isset( $meta['ast-advanced-headers-location']['default'] ) ) ? $meta['ast-advanced-headers-location']['default'] : ''; $exclude_locations = ( isset( $meta['ast-advanced-headers-exclusion']['default'] ) ) ? $meta['ast-advanced-headers-exclusion']['default'] : ''; $user_roles = ( isset( $meta['ast-advanced-headers-users']['default'] ) ) ? $meta['ast-advanced-headers-users']['default'] : ''; // settings added after published/updated the meta. $unsaved_array = array(); $independent_addon_array = array( 'site-title-color' => '', 'site-title-h-color' => '', 'site-tagline-color' => '', 'above-header-bg-color' => '', 'above-header-text-link-color' => '', 'above-header-h-color' => '', 'above-header-a-color' => '', 'above-header-submenu-bg-color' => '', 'above-header-submenu-link-color' => '', 'above-header-submenu-h-color' => '', 'above-header-submenu-a-color' => '', 'below-header-bg-color' => '', 'below-header-text-link-color' => '', 'below-header-h-color' => '', 'below-header-a-color' => '', 'below-header-submenu-bg-color' => '', 'below-header-submenu-link-color' => '', 'below-header-submenu-h-color' => '', 'below-header-submenu-a-color' => '', 'custom-menu-item' => '', ); foreach ( $independent_addon_array as $key => $value ) { // key not exist then set a key to existing unsaved array. if ( ! isset( $ast_advanced_headers_design[ $key ] ) ) { $unsaved_array[ $key ] = $value; } } // Merge array if new key added after updated/published. $ast_advanced_headers_design = array_merge( $ast_advanced_headers_design, $unsaved_array ); $ast_advanced_headers = array( 'layouts' => $ast_advanced_headers_layout, 'designs' => $ast_advanced_headers_design, 'include_locations' => $display_locations, 'exclude_locations' => $exclude_locations, 'user_roles' => $user_roles, ); do_action( 'astra_advanced_headers_settings_markup_before', $meta ); ?>
$data ) { if ( ! $data['show'] ) { continue; } $class = ''; if ( '' != $current_tab && 'ast-adv-headers-tab-' . esc_attr( $slug ) == $current_tab ) { $class = 'tab-active'; } elseif ( '' == $current_tab && esc_attr( $slug ) == 'page-header' ) { $class = 'tab-active'; } ?>
$data ) { if ( in_array( $key, $advanced_headers_meta ) ) { $meta_value = isset( $_POST[ $key ] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST[ $key ] ) ) : array(); } elseif ( in_array( $key, array( 'ast-advanced-headers-users' ) ) ) { $meta_key = ! empty( $_POST[ $key ] ) ? array_map( 'sanitize_text_field', $_POST[ $key ] ) : array(); $index = array_search( '', $meta_key ); if ( false !== $index ) { unset( $meta_key[ $index ] ); } $meta_value = array_map( 'esc_attr', $meta_key ); $meta_value = array_map( 'stripslashes', $meta_key ); } elseif ( in_array( $key, array( 'ast-advanced-headers-location', 'ast-advanced-headers-exclusion', ) ) ) { $meta_value = Astra_Target_Rules_Fields::get_format_rule_value( $_POST, $key ); } else { // Sanitize values. $sanitize_filter = ( isset( $data['sanitize'] ) ) ? $data['sanitize'] : 'FILTER_SANITIZE_STRING'; switch ( $sanitize_filter ) { default: case 'FILTER_SANITIZE_STRING': $meta_value = ! empty( $_POST[ $key ] ) ? sanitize_text_field( wp_unslash( $_POST[ $key ] ) ) : ''; break; case 'FILTER_SANITIZE_URL': $meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_URL ); break; case 'FILTER_SANITIZE_NUMBER_INT': $meta_value = filter_input( INPUT_POST, $key, FILTER_SANITIZE_NUMBER_INT ); break; case 'FILTER_DEFAULT': $meta_value = apply_filters( 'astra_addon_php_default_filter_input', ! empty( $key ) ? sanitize_text_field( wp_unslash( $key ) ) : '', $key ); break; } } // Store values. if ( $meta_value ) { update_post_meta( $post_id, $key, $meta_value ); } else { delete_post_meta( $post_id, $key ); } } $logo_id = isset( $_POST['ast-advanced-headers-design']['logo-id'] ) ? sanitize_key( $_POST['ast-advanced-headers-design']['logo-id'] ) : ''; if ( '' != $logo_id ) { self::generate_logo_by_width( $logo_id ); } } /** * Markup for the Page Header Tab. * * @since 1.0.0 * * @param array $options Post meta. */ public function page_header_tab( $options ) { $layout = $options['layouts']; $design = $options['designs']; $layout_opt = isset( $layout['layout'] ) ? $layout['layout'] : ''; ?>
/>
">



/>

/>
/>
/>
__( 'Customizer Setting', 'astra-addon' ), 'none' => __( 'None', 'astra-addon' ), 'search' => __( 'Search', 'astra-addon' ), 'text-html' => __( 'Text / HTML', 'astra-addon' ), 'widget' => __( 'Widget', 'astra-addon' ), ), 'primary-header' ); ?>
__( 'Customizer Setting', 'astra-addon' ), 'slide-search' => __( 'Slide Search', 'astra-addon' ), 'full-screen' => __( 'Full Screen Search', 'astra-addon' ), 'header-cover' => __( 'Header Cover Search', 'astra-addon' ), 'search-box' => __( 'Search Box', 'astra-addon' ), ); ?>
/>
/>
/>
/>
/>
/>
/>
admin_styles(); $layout = $options['layouts']; $design = $options['designs']; $include_locations = $options['include_locations']; $exclude_locations = $options['exclude_locations']; $users = $options['user_roles']; ?>
__( 'Display Rules', 'astra-addon' ), 'value' => '[{"type":"basic-global","specific":null}]', 'tags' => 'site,enable,target,pages', 'rule_type' => 'display', 'add_rule_label' => __( 'Add Display Rule', 'astra-addon' ), ), $include_locations ); ?>
__( 'Exclude On', 'astra-addon' ), 'value' => '[]', 'tags' => 'site,enable,target,pages', 'add_rule_label' => __( 'Add Exclusion Rule', 'astra-addon' ), 'rule_type' => 'exclude', ), $exclude_locations ); ?>
__( 'Users', 'astra-addon' ), 'value' => '[]', 'tags' => 'site,enable,target,pages', 'add_rule_label' => __( 'Add User Rule', 'astra-addon' ), ), $users ); ?>
/>
(int) $logo_width, 'height' => 0, 'crop' => false, ); } return $sizes; } /** * Generate logo image by its width. * * @since 1.0.0 * @param int $custom_logo_id Logo id. */ public static function generate_logo_by_width( $custom_logo_id ) { if ( $custom_logo_id ) { add_filter( 'intermediate_image_sizes_advanced', 'Astra_Ext_Advanced_Headers_Meta::logo_image_sizes', 10, 2 ); $image = get_post( $custom_logo_id ); if ( $image ) { $fullsizepath = get_attached_file( $image->ID ); if ( false !== $fullsizepath || file_exists( $fullsizepath ) ) { $metadata = wp_generate_attachment_metadata( $image->ID, $fullsizepath ); if ( ! is_wp_error( $metadata ) && ! empty( $metadata ) ) { wp_update_attachment_metadata( $image->ID, $metadata ); } } } remove_filter( 'intermediate_image_sizes_advanced', 'Astra_Ext_Advanced_Headers_Meta::logo_image_sizes', 10 ); } } } } /** * Kicking this off by calling 'get_instance()' method */ Astra_Ext_Advanced_Headers_Meta::get_instance();