$values ) { if ( array() === $values ) { continue; } $current = \Rooster\Core\Setup::group( (string) $group ); $clean = \Rooster\Modules\Admin\Settings::sanitize( (string) $group, array_merge( $current, $values ) ); $changed = array_intersect_key( $clean, $values ); if ( array() !== $changed ) { $ops[] = array( 'type' => 'settings', 'args' => array( 'group' => (string) $group, 'values' => $changed ) ); } } if ( array() === $ops ) { return new WP_Error( 'aieo_nothing', __( 'Nothing to save: the theme does not know these settings.', 'ai-eshop-optimizer' ) ); } $draft = \Rooster\Modules\Abilities\Changes::draft( 'rooster-one/header', $groups, $ops, $summary ); return \Rooster\Modules\Abilities\Changes::apply( (string) $draft['change_id'] ); } public function ajax_layout_save() { AIEO_DMM::verify_ajax_request(); if ( ! current_user_can( 'edit_theme_options' ) ) { wp_send_json_error( array( 'message' => __( 'Only someone who may change the site\'s appearance can change its header.', 'ai-eshop-optimizer' ) ) ); } if ( ! self::layout_ready() ) { wp_send_json_error( array( 'message' => __( 'This version of Rooster Zero cannot store a header layout yet: update the theme.', 'ai-eshop-optimizer' ) ) ); } $layout = isset( $_POST['header_layout'] ) && is_array( $_POST['header_layout'] ) ? wp_unslash( $_POST['header_layout'] ) : array(); $general = array(); foreach ( array( 'announcement_message', 'announcement_href' ) as $key ) { if ( isset( $_POST['general'][ $key ] ) && is_scalar( $_POST['general'][ $key ] ) ) { $general[ $key ] = (string) wp_unslash( $_POST['general'][ $key ] ); } } $use = ! empty( $_POST['header_layout_use'] ); $part = (string) rooster_setting( 'general', 'part_header', '' ); if ( $use && self::BUILDER_PART !== $part && self::builder_variant_exists() ) { update_option( self::PREVIOUS_PART_KEY, $part, false ); $general['part_header'] = self::BUILDER_PART; } elseif ( ! $use && self::BUILDER_PART === $part ) { $general['part_header'] = self::previous_part(); } $applied = self::apply_theme_settings( array( 'design' => array( 'header_layout' => $layout ), 'general' => $general, ), __( 'Header layout', 'ai-eshop-optimizer' ) ); if ( is_wp_error( $applied ) ) { wp_send_json_error( array( 'message' => $applied->get_error_message() ) ); } wp_send_json_success( array( 'message' => __( 'Saved: the header layout. The change log can undo it.', 'ai-eshop-optimizer' ) ) ); } public function ajax_theme_actions_save() { AIEO_DMM::verify_ajax_request(); if ( ! current_user_can( 'edit_theme_options' ) ) { wp_send_json_error( array( 'message' => __( 'Only someone who may change the site\'s appearance can change its header.', 'ai-eshop-optimizer' ) ) ); } $design = array(); foreach ( array( 'header_actions', 'header_actions_phone' ) as $key ) { if ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) && self::theme_has_design( $key ) ) { $design[ $key ] = wp_unslash( $_POST[ $key ] ); } } $applied = self::apply_theme_settings( array( 'design' => $design ), __( 'Header actions', 'ai-eshop-optimizer' ) ); if ( is_wp_error( $applied ) ) { wp_send_json_error( array( 'message' => $applied->get_error_message() ) ); } wp_send_json_success( array( 'message' => __( 'Saved: the header actions. The change log can undo it.', 'ai-eshop-optimizer' ) ) ); } public function ajax_save() { AIEO_DMM::verify_ajax_request(); $valid = array(); if ( class_exists( 'AIEO_Header_Actions_Block' ) ) { foreach ( AIEO_Header_Actions_Block::items_catalog() as $g ) { $valid[ $g['slug'] ] = true; } } $out = array(); foreach ( array( 'mobile', 'desktop' ) as $device ) { $out[ $device ] = array( 'items' => $this->clean_items( $device, $valid ), 'gap' => $this->clean_gap( $device ), 'color' => $this->clean_color( $device ), 'hover' => $this->clean_color( $device, 'hover' ), ); } update_option( self::OPTION_KEY, $out, false ); wp_send_json_success( array( 'mobile' => count( $out['mobile']['items'] ), 'desktop' => count( $out['desktop']['items'] ), ) ); } private function clean_items( $device, $valid ) { $field = 'header_actions_' . $device . '_items'; $clean = array(); if ( ! isset( $_POST[ $field ] ) ) { return $clean; } $raw = sanitize_text_field( wp_unslash( (string) $_POST[ $field ] ) ); $rows = json_decode( $raw, true ); if ( ! is_array( $rows ) ) { return $clean; } $seen = array(); foreach ( $rows as $row ) { if ( ! is_array( $row ) || empty( $row['slug'] ) ) { continue; } $slug = sanitize_key( $row['slug'] ); if ( ! isset( $valid[ $slug ] ) || isset( $seen[ $slug ] ) ) { continue; } $clean[] = array( 'slug' => $slug, 'enabled' => ! empty( $row['enabled'] ), 'label' => ! empty( $row['label'] ), ); $seen[ $slug ] = true; } return $clean; } private function clean_gap( $device ) { $field = 'header_actions_' . $device . '_gap'; if ( ! isset( $_POST[ $field ] ) ) { return ''; } $raw = sanitize_text_field( wp_unslash( (string) $_POST[ $field ] ) ); $raw = trim( $raw ); return ( '' !== $raw && is_numeric( $raw ) ) ? (string) floatval( $raw ) : ''; } private function clean_color( $device, $which = 'color' ) { if ( empty( $_POST[ 'header_actions_' . $device . '_' . $which . '_custom' ] ) ) { return ''; } $field = 'header_actions_' . $device . '_' . $which; if ( ! isset( $_POST[ $field ] ) ) { return ''; } $raw = sanitize_hex_color( wp_unslash( (string) $_POST[ $field ] ) ); return is_string( $raw ) ? $raw : ''; } public function render_subtab() { if ( self::is_zero() ) { $this->render_template( 'header-layout.php' ); return; } $configs = array(); if ( class_exists( 'AIEO_Header_Actions_Block' ) ) { foreach ( array( 'mobile', 'desktop' ) as $device ) { $configs[ $device ] = AIEO_Header_Actions_Block::resolve_config( $device ); } } $this->render_template( 'header-actions.php', array( 'configs' => $configs ) ); } }