'; esc_html_e( 'The "AB Checkout Steps for WooCommerce" plugin requires WooCommerce to work. Please install and activate WooCommerce first.', 'ab-checkout-steps' ); echo '
'; } /* ========================================================= Settings ========================================================= */ /** * Get the configured number of checkout steps (3 or 4). Defaults to 3. */ function abchk_get_step_count() { $value = get_option( ABCHK_OPTION_STEP_COUNT, '3' ); $value = (int) $value; return ( 4 === $value ) ? 4 : 3; } /** * Get the ordered list of step labels based on the configured step count. */ function abchk_get_step_labels() { if ( 4 === abchk_get_step_count() ) { return array( __( 'Cart', 'ab-checkout-steps' ), __( 'Information', 'ab-checkout-steps' ), __( 'Shipping', 'ab-checkout-steps' ), __( 'Payment', 'ab-checkout-steps' ), ); } return array( __( 'Information', 'ab-checkout-steps' ), __( 'Shipping', 'ab-checkout-steps' ), __( 'Payment', 'ab-checkout-steps' ), ); } /** * Get the configured accent color (hex). Falls back to the default purple. */ function abchk_get_accent_color() { $value = get_option( ABCHK_OPTION_ACCENT_COLOR, ABCHK_DEFAULT_ACCENT_COLOR ); $value = sanitize_hex_color( $value ); return $value ? $value : ABCHK_DEFAULT_ACCENT_COLOR; } /** * Get the list of available progress bar styles: slug => label. */ function abchk_get_progress_styles() { return array( 'circles' => __( 'Circles — numbered circles connected by a line', 'ab-checkout-steps' ), 'chevron' => __( 'Chevron — connected arrow ribbon', 'ab-checkout-steps' ), 'minimal' => __( 'Minimal — plain text labels, no circles', 'ab-checkout-steps' ), 'bar' => __( 'Progress Bar — thick track with small dot markers', 'ab-checkout-steps' ), 'dots' => __( 'Dots — small compact dots, no numbers', 'ab-checkout-steps' ), 'boxes' => __( 'Boxes — solid numbered square blocks', 'ab-checkout-steps' ), ); } /** * Get the configured progress bar style slug. Defaults to "circles". */ function abchk_get_progress_style() { $value = get_option( ABCHK_OPTION_PROGRESS_STYLE, 'circles' ); $allowed = array_keys( abchk_get_progress_styles() ); return in_array( $value, $allowed, true ) ? $value : 'circles'; } function abchk_register_settings() { register_setting( 'abchk_settings_group', ABCHK_OPTION_STEP_COUNT, array( 'type' => 'string', 'sanitize_callback' => 'abchk_sanitize_step_count', 'default' => '3', ) ); register_setting( 'abchk_settings_group', ABCHK_OPTION_ACCENT_COLOR, array( 'type' => 'string', 'sanitize_callback' => 'abchk_sanitize_accent_color', 'default' => ABCHK_DEFAULT_ACCENT_COLOR, ) ); register_setting( 'abchk_settings_group', ABCHK_OPTION_PROGRESS_STYLE, array( 'type' => 'string', 'sanitize_callback' => 'abchk_sanitize_progress_style', 'default' => 'circles', ) ); } add_action( 'admin_init', 'abchk_register_settings' ); function abchk_sanitize_step_count( $value ) { return ( '4' === (string) $value ) ? '4' : '3'; } function abchk_sanitize_accent_color( $value ) { $color = sanitize_hex_color( $value ); return $color ? $color : ABCHK_DEFAULT_ACCENT_COLOR; } function abchk_sanitize_progress_style( $value ) { $allowed = array_keys( abchk_get_progress_styles() ); return in_array( $value, $allowed, true ) ? $value : 'circles'; } function abchk_add_settings_page() { add_options_page( __( 'AB Checkout Steps', 'ab-checkout-steps' ), __( 'AB Checkout Steps', 'ab-checkout-steps' ), 'manage_options', 'abchk-settings', 'abchk_render_settings_page' ); } add_action( 'admin_menu', 'abchk_add_settings_page' ); /** * Load the WordPress color picker only on this plugin's settings page. */ function abchk_admin_enqueue_settings_assets( $hook ) { if ( 'settings_page_abchk-settings' !== $hook ) { return; } wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_script( 'wp-color-picker' ); wp_add_inline_script( 'wp-color-picker', "jQuery(function($){ $('.abchk-color-field').wpColorPicker(); });" ); } add_action( 'admin_enqueue_scripts', 'abchk_admin_enqueue_settings_assets' ); function abchk_render_settings_page() { if ( ! current_user_can( 'manage_options' ) ) { return; } $current_steps = abchk_get_step_count(); $current_color = abchk_get_accent_color(); $current_style = abchk_get_progress_style(); $styles = abchk_get_progress_styles(); ?>