'#212121', 'fg' => '#ffffff', 'border' => '#212121', 'bg_hover' => '#404040', 'fg_hover' => '#ffffff', 'border_hover' => '#404040', 'sec_bg' => '#e9e6e2', 'sec_fg' => '#1a1a1a', 'sec_bg_hover' => '#dfdbd4', 'sec_border' => '#e9e6e2', 'sec_fg_hover' => '#1a1a1a', 'sec_border_hover' => '#dfdbd4', 'arch_bg' => '#212121', 'arch_fg' => '#ffffff', 'arch_border' => '#212121', 'arch_bg_hover' => '#404040', 'arch_fg_hover' => '#ffffff', 'arch_border_hover' => '#404040', ); const RECIPE = array( 'bg' => 'var(--wp--custom--rooster--button--background,var(--wp--preset--color--accent,CanvasText))', 'fg' => 'var(--wp--custom--rooster--button--text,var(--wp--preset--color--on-accent,var(--wp--preset--color--base,Canvas)))', 'hover' => 'color-mix(in srgb,var(--wp--custom--rooster--button--background,var(--wp--preset--color--accent,CanvasText)) 85%,var(--wp--preset--color--fg,Canvas))', 'sec_bg' => 'var(--wp--preset--color--subtle,color-mix(in srgb,CanvasText 8%,Canvas))', 'sec_fg' => 'var(--wp--preset--color--fg,CanvasText)', 'sec_hover' => 'color-mix(in srgb,var(--wp--preset--color--subtle,color-mix(in srgb,CanvasText 8%,Canvas)) 88%,var(--wp--preset--color--fg,CanvasText))', ); public static function picked( $key, $val ) { $v = trim( (string) $val ); if ( '' === $v ) { return ''; } if ( ! class_exists( 'AIEO_Admin_Color' ) && defined( 'AIEO_DIR' ) && is_readable( AIEO_DIR . 'includes/class-aieo-admin-color.php' ) ) { require_once AIEO_DIR . 'includes/class-aieo-admin-color.php'; } $v = class_exists( 'AIEO_Admin_Color' ) ? (string) AIEO_Admin_Color::sanitize( $v ) : (string) sanitize_hex_color( $v ); return ( '' !== $v && ( ! isset( self::RETIRED_COLOURS[ $key ] ) || 0 !== strcasecmp( $v, self::RETIRED_COLOURS[ $key ] ) ) ) ? $v : ''; } private static function recipe( $key ) { $sec = 0 === strpos( $key, 'sec_' ); $role = (string) preg_replace( '/^(sec_|arch_)/', '', $key ); if ( 'fg' === $role || 'fg_hover' === $role ) { return self::RECIPE[ $sec ? 'sec_fg' : 'fg' ]; } if ( 'bg_hover' === $role || 'border_hover' === $role ) { return self::RECIPE[ $sec ? 'sec_hover' : 'hover' ]; } return self::RECIPE[ $sec ? 'sec_bg' : 'bg' ]; } public static function defaults() { return array( 'bg' => '', 'fg' => '', 'border' => '', 'border_w' => 0, 'radius' => 4, 'bg_hover' => '', 'fg_hover' => '', 'border_hover' => '', 'pad_t' => 12, 'pad_r' => 24, 'pad_b' => 12, 'pad_l' => 24, 'min_w' => 0, 'max_w' => 0, 'min_h' => 0, 'max_h' => 0, 'glass' => 0, 'glass_opacity' => 70, 'glass_blur' => 10, 'sec_bg' => '', 'sec_fg' => '', 'sec_bg_hover' => '', 'sec_border' => '', 'sec_border_w' => 0, 'sec_fg_hover' => '', 'sec_border_hover' => '', 'sec_pad_t' => 10, 'sec_pad_r' => 18, 'sec_pad_b' => 10, 'sec_pad_l' => 18, 'sec_min_w' => 0, 'sec_max_w' => 0, 'sec_min_h' => 0, 'sec_max_h' => 0, 'sec_glass' => 0, 'sec_glass_opacity' => 70, 'sec_glass_blur' => 10, 'arch_bg' => '', 'arch_fg' => '', 'arch_border' => '', 'arch_border_w' => 0, 'arch_radius' => 4, 'arch_bg_hover' => '', 'arch_fg_hover' => '', 'arch_border_hover' => '', 'arch_pad_t' => 8, 'arch_pad_r' => 16, 'arch_pad_b' => 8, 'arch_pad_l' => 16, 'arch_min_w' => 0, 'arch_max_w' => 0, 'arch_min_h' => 0, 'arch_max_h' => 0, 'arch_glass' => 0, 'arch_glass_opacity' => 70, 'arch_glass_blur' => 10, 'style_archive' => 1, 'style_main_atc' => 1, ); } public function get_settings() { $stored = get_option( self::OPTION_KEY, array() ); if ( ! is_array( $stored ) ) { $stored = array(); } return array_merge( self::defaults(), $stored ); } public function register_hooks() { add_action( 'wp_ajax_aieo_dmm_save_button_styles', array( $this, 'ajax_save' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_frontend' ), 5 ); add_filter( 'body_class', array( $this, 'maybe_atc_body_class' ) ); } public function enqueue_admin_assets() { if ( ! class_exists( 'AIEO_Admin_Color' ) && defined( 'AIEO_DIR' ) && file_exists( AIEO_DIR . 'includes/class-aieo-admin-color.php' ) ) { require_once AIEO_DIR . 'includes/class-aieo-admin-color.php'; } if ( class_exists( 'AIEO_Admin_Color' ) ) { AIEO_Admin_Color::enqueue(); } else { wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_script( 'wp-color-picker' ); wp_add_inline_script( 'wp-color-picker', 'jQuery(function($){$(".aieo-dmm-btn-color").wpColorPicker();});' ); } } public function ajax_save() { AIEO_DMM::verify_ajax_request(); if ( ! current_user_can( 'install_plugins' ) ) { wp_send_json_error( array( 'message' => __( 'Insufficient permissions.', 'ai-eshop-optimizer' ) ) ); } $d = self::defaults(); $hex = function ( $key, $fallback ) { $raw = isset( $_POST[ $key ] ) ? wp_unslash( $_POST[ $key ] ) : ''; $v = self::picked( $key, (string) $raw ); return $v !== '' ? $v : $fallback; }; $out = array( 'bg' => $hex( 'bg', $d['bg'] ), 'fg' => $hex( 'fg', $d['fg'] ), 'border' => $hex( 'border', $d['border'] ), 'border_w' => isset( $_POST['border_w'] ) ? max( 0, min( 10, (int) $_POST['border_w'] ) ) : $d['border_w'], 'radius' => isset( $_POST['radius'] ) ? max( 0, min( 48, (int) $_POST['radius'] ) ) : $d['radius'], 'pad_t' => isset( $_POST['pad_t'] ) ? max( 0, min( 80, (int) $_POST['pad_t'] ) ) : $d['pad_t'], 'pad_r' => isset( $_POST['pad_r'] ) ? max( 0, min( 120, (int) $_POST['pad_r'] ) ) : $d['pad_r'], 'pad_b' => isset( $_POST['pad_b'] ) ? max( 0, min( 80, (int) $_POST['pad_b'] ) ) : $d['pad_b'], 'pad_l' => isset( $_POST['pad_l'] ) ? max( 0, min( 120, (int) $_POST['pad_l'] ) ) : $d['pad_l'], 'min_w' => isset( $_POST['min_w'] ) ? max( 0, min( 1000, (int) $_POST['min_w'] ) ) : $d['min_w'], 'max_w' => isset( $_POST['max_w'] ) ? max( 0, min( 1000, (int) $_POST['max_w'] ) ) : $d['max_w'], 'min_h' => isset( $_POST['min_h'] ) ? max( 0, min( 400, (int) $_POST['min_h'] ) ) : $d['min_h'], 'max_h' => isset( $_POST['max_h'] ) ? max( 0, min( 400, (int) $_POST['max_h'] ) ) : $d['max_h'], 'glass' => empty( $_POST['glass'] ) ? 0 : 1, 'glass_opacity' => isset( $_POST['glass_opacity'] ) ? max( 0, min( 100, (int) $_POST['glass_opacity'] ) ) : $d['glass_opacity'], 'glass_blur' => isset( $_POST['glass_blur'] ) ? max( 0, min( 40, (int) $_POST['glass_blur'] ) ) : $d['glass_blur'], 'bg_hover' => $hex( 'bg_hover', $d['bg_hover'] ), 'fg_hover' => $hex( 'fg_hover', $d['fg_hover'] ), 'border_hover' => $hex( 'border_hover', $d['border_hover'] ), 'sec_bg' => $hex( 'sec_bg', $d['sec_bg'] ), 'sec_fg' => $hex( 'sec_fg', $d['sec_fg'] ), 'sec_bg_hover' => $hex( 'sec_bg_hover', $d['sec_bg_hover'] ), 'sec_border' => $hex( 'sec_border', $d['sec_border'] ), 'sec_border_w' => isset( $_POST['sec_border_w'] ) ? max( 0, min( 10, (int) $_POST['sec_border_w'] ) ) : $d['sec_border_w'], 'sec_fg_hover' => $hex( 'sec_fg_hover', $d['sec_fg_hover'] ), 'sec_border_hover' => $hex( 'sec_border_hover', $d['sec_border_hover'] ), 'sec_pad_t' => isset( $_POST['sec_pad_t'] ) ? max( 0, min( 80, (int) $_POST['sec_pad_t'] ) ) : $d['sec_pad_t'], 'sec_pad_r' => isset( $_POST['sec_pad_r'] ) ? max( 0, min( 120, (int) $_POST['sec_pad_r'] ) ) : $d['sec_pad_r'], 'sec_pad_b' => isset( $_POST['sec_pad_b'] ) ? max( 0, min( 80, (int) $_POST['sec_pad_b'] ) ) : $d['sec_pad_b'], 'sec_pad_l' => isset( $_POST['sec_pad_l'] ) ? max( 0, min( 120, (int) $_POST['sec_pad_l'] ) ) : $d['sec_pad_l'], 'sec_min_w' => isset( $_POST['sec_min_w'] ) ? max( 0, min( 1000, (int) $_POST['sec_min_w'] ) ) : $d['sec_min_w'], 'sec_max_w' => isset( $_POST['sec_max_w'] ) ? max( 0, min( 1000, (int) $_POST['sec_max_w'] ) ) : $d['sec_max_w'], 'sec_min_h' => isset( $_POST['sec_min_h'] ) ? max( 0, min( 400, (int) $_POST['sec_min_h'] ) ) : $d['sec_min_h'], 'sec_max_h' => isset( $_POST['sec_max_h'] ) ? max( 0, min( 400, (int) $_POST['sec_max_h'] ) ) : $d['sec_max_h'], 'sec_glass' => empty( $_POST['sec_glass'] ) ? 0 : 1, 'sec_glass_opacity' => isset( $_POST['sec_glass_opacity'] ) ? max( 0, min( 100, (int) $_POST['sec_glass_opacity'] ) ) : $d['sec_glass_opacity'], 'sec_glass_blur' => isset( $_POST['sec_glass_blur'] ) ? max( 0, min( 40, (int) $_POST['sec_glass_blur'] ) ) : $d['sec_glass_blur'], 'arch_bg' => $hex( 'arch_bg', $d['arch_bg'] ), 'arch_fg' => $hex( 'arch_fg', $d['arch_fg'] ), 'arch_border' => $hex( 'arch_border', $d['arch_border'] ), 'arch_border_w' => isset( $_POST['arch_border_w'] ) ? max( 0, min( 10, (int) $_POST['arch_border_w'] ) ) : $d['arch_border_w'], 'arch_radius' => isset( $_POST['arch_radius'] ) ? max( 0, min( 48, (int) $_POST['arch_radius'] ) ) : $d['arch_radius'], 'arch_pad_t' => isset( $_POST['arch_pad_t'] ) ? max( 0, min( 80, (int) $_POST['arch_pad_t'] ) ) : $d['arch_pad_t'], 'arch_pad_r' => isset( $_POST['arch_pad_r'] ) ? max( 0, min( 120, (int) $_POST['arch_pad_r'] ) ) : $d['arch_pad_r'], 'arch_pad_b' => isset( $_POST['arch_pad_b'] ) ? max( 0, min( 80, (int) $_POST['arch_pad_b'] ) ) : $d['arch_pad_b'], 'arch_pad_l' => isset( $_POST['arch_pad_l'] ) ? max( 0, min( 120, (int) $_POST['arch_pad_l'] ) ) : $d['arch_pad_l'], 'arch_min_w' => isset( $_POST['arch_min_w'] ) ? max( 0, min( 1000, (int) $_POST['arch_min_w'] ) ) : $d['arch_min_w'], 'arch_max_w' => isset( $_POST['arch_max_w'] ) ? max( 0, min( 1000, (int) $_POST['arch_max_w'] ) ) : $d['arch_max_w'], 'arch_min_h' => isset( $_POST['arch_min_h'] ) ? max( 0, min( 400, (int) $_POST['arch_min_h'] ) ) : $d['arch_min_h'], 'arch_max_h' => isset( $_POST['arch_max_h'] ) ? max( 0, min( 400, (int) $_POST['arch_max_h'] ) ) : $d['arch_max_h'], 'arch_glass' => empty( $_POST['arch_glass'] ) ? 0 : 1, 'arch_glass_opacity' => isset( $_POST['arch_glass_opacity'] ) ? max( 0, min( 100, (int) $_POST['arch_glass_opacity'] ) ) : $d['arch_glass_opacity'], 'arch_glass_blur' => isset( $_POST['arch_glass_blur'] ) ? max( 0, min( 40, (int) $_POST['arch_glass_blur'] ) ) : $d['arch_glass_blur'], 'arch_bg_hover' => $hex( 'arch_bg_hover', $d['arch_bg_hover'] ), 'arch_fg_hover' => $hex( 'arch_fg_hover', $d['arch_fg_hover'] ), 'arch_border_hover' => $hex( 'arch_border_hover', $d['arch_border_hover'] ), 'style_archive' => empty( $_POST['style_archive'] ) ? 0 : 1, 'style_main_atc' => empty( $_POST['style_main_atc'] ) ? 0 : 1, ); update_option( self::OPTION_KEY, $out, false ); wp_send_json_success( array( 'message' => __( 'Button styles saved.', 'ai-eshop-optimizer' ) ) ); } public function render_subtab() { $s = $this->get_settings(); $id_of = static function ( $name ) { return 'aieo-bs-' . str_replace( '_', '-', $name ); }; $color_row = function ( $label, $name, $val ) use ( $id_of ) { echo \Rooster\Admin\Ui::field_row( array( 'id' => $id_of( $name ), 'label' => $label, 'control' => \Rooster\Admin\Fields::color( $name, self::picked( $name, (string) $val ), array( 'id' => $id_of( $name ), 'alpha' => true, 'default' => '' ) ) ) ); }; $num = static function ( $name, $val, $max, $suffix ) use ( $id_of ) { return \Rooster\Admin\Ui::input( $name, (string) (int) $val, array( 'id' => $id_of( $name ), 'type' => 'number', 'xs' => true, 'min' => '0', 'max' => (string) (int) $max, 'step' => '1', 'unit' => $suffix ) ); }; $num_row = function ( $label, $name, $val, $max, $suffix, $help = '' ) use ( $id_of, $num ) { echo \Rooster\Admin\Ui::field_row( array( 'id' => $id_of( $name ), 'label' => $label, 'control' => $num( $name, $val, $max, $suffix ), 'help' => $help ) ); }; $help_border = __( '0 hides the border, whatever its colour.', 'ai-eshop-optimizer' ); $help_radius = __( '0 gives square corners; half the button\'s height or more makes it a pill.', 'ai-eshop-optimizer' ); $box_rows = function ( $prefix ) use ( $s, $id_of, $num ) { $rows = array( 'pad' => array( __( 'Padding (top / right / bottom / left)', 'ai-eshop-optimizer' ), array( array( _x( 'Top', 'a side of a box', 'ai-eshop-optimizer' ), 'pad_t', 80, 'px' ), array( _x( 'Right', 'a side of a box', 'ai-eshop-optimizer' ), 'pad_r', 120, 'px' ), array( _x( 'Bottom', 'a side of a box', 'ai-eshop-optimizer' ), 'pad_b', 80, 'px' ), array( _x( 'Left', 'a side of a box', 'ai-eshop-optimizer' ), 'pad_l', 120, 'px' ), ), __( 'The space between the button\'s edge and its text, on each side.', 'ai-eshop-optimizer' ) ), 'width' => array( __( 'Width', 'ai-eshop-optimizer' ), array( array( __( 'Min width', 'ai-eshop-optimizer' ), 'min_w', 1000, 'px (0 = auto)' ), array( __( 'Max width', 'ai-eshop-optimizer' ), 'max_w', 1000, 'px (0 = none)' ), ), __( 'How narrow and how wide the button may get, whatever the length of its text.', 'ai-eshop-optimizer' ) ), 'height' => array( __( 'Height', 'ai-eshop-optimizer' ), array( array( __( 'Min height', 'ai-eshop-optimizer' ), 'min_h', 400, 'px (0 = auto)' ), array( __( 'Max height', 'ai-eshop-optimizer' ), 'max_h', 400, 'px (0 = none)' ), ), __( 'How short and how tall the button may get, whatever its text and padding.', 'ai-eshop-optimizer' ) ), ); foreach ( $rows as $key => $row ) { $parts = array(); foreach ( $row[1] as $part ) { $name = $prefix . $part[1]; $parts[] = array( 'label' => $part[0], 'id' => $id_of( $name ), 'control' => $num( $name, $s[ $name ], $part[2], $part[3] ) ); } echo \Rooster\Admin\Ui::field_row( array( 'id' => $id_of( $prefix . $key ), 'label' => $row[0], 'parts' => $parts, 'help' => $row[2] ) ); } }; $glass_block = function ( $prefix, $on, $opacity, $blur ) { echo '