hooks(); } /** * Initialize hooks. * * @since 4.17.0 * @access private */ private function hooks(): void { // Hook into the WP Simple Pay 'General' tab action. add_action( 'simpay_form_settings_form_style_panel', array( $this, 'render_style_settings_in_tab' ), 20, 1 ); // Priority 20 to appear after core fields. // Hook into the save action. add_action( 'save_post_simple-pay', array( $this, 'save_style_settings' ), 10, 2 ); // Hook into the enqueue action for scripts/styles. add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) ); } /** * Enqueue admin scripts and styles (like the color picker). * * Loads necessary CSS and JavaScript files for the admin interface, * but only on the WP Simple Pay form edit screen. * * @since 4.17.0 * * @param string $hook_suffix The current admin page. * @return void */ public function enqueue_admin_scripts( $hook_suffix ) { global $post_type; // Only load on the simple-pay post type edit screen. if ( 'simple-pay' === $post_type && ( 'post.php' === $hook_suffix || 'post-new.php' === $hook_suffix ) ) { // Enqueue WordPress color picker scripts and styles. wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_script( 'wp-color-picker' ); // Enqueue color picker alpha addon if available. if ( ! wp_script_is( 'wp-color-picker-alpha', 'registered' ) ) { wp_register_script( 'wp-color-picker-alpha', SIMPLE_PAY_URL . 'src/Admin/FormBuilder/FormStyle/assets/js/wp-color-picker-alpha.min.js', array( 'wp-color-picker' ), '3.0.0', true ); } wp_enqueue_script( 'wp-color-picker-alpha' ); // Enqueue custom admin styles and scripts. wp_enqueue_style( 'wpsp-admin-admin-css', SIMPLE_PAY_URL . 'src/Admin/FormBuilder/FormStyle/assets/css/admin.css', array(), SIMPLE_PAY_VERSION ); wp_enqueue_script( 'wpsp-admin-admin-js', SIMPLE_PAY_URL . 'src/Admin/FormBuilder/FormStyle/assets/js/admin.js', array( 'jquery', 'wp-color-picker', 'wp-color-picker-alpha' ), SIMPLE_PAY_VERSION, true ); // Pass localized data to the JS. wp_localize_script( 'wpsp-admin-admin-js', 'simpayFormStyleData', array( 'resetConfirmMessage' => __( 'Are you sure you want to reset all style settings to default values?', 'stripe' ), ) ); } } /** * Check if this is a new form without any saved style settings * * Determines if a form has any style settings saved yet. * Used to apply default styles to new forms. * * @since 4.17.0 * @access private * * @param int $post_id The post ID to check. * @return bool True if this is a new form, false otherwise */ private function is_new_form( $post_id ) { // Check if any style settings exist for this form. foreach ( Settings::get_style_keys() as $key ) { if ( Settings::setting_exists( $post_id, $key ) ) { return false; } } return true; } /** * Get the available theme presets for the form styles UI. * * @since 4.17.0 * @access private * * @return array Theme preset configuration. */ private function get_theme_presets() { return array( 'default' => array( 'name' => __( 'Default', 'stripe' ), 'colors' => array( 'primary' => '#0f8569', 'secondary' => '#0e7c62', 'text' => '#32325d', 'background' => '#ffffff', ), 'description' => __( 'WP Simple Pay\'s default styling', 'stripe' ), ), 'sunset' => array( 'name' => __( 'Sunset', 'stripe' ), 'colors' => array( 'primary' => '#e74c3c', 'secondary' => '#c0392b', 'text' => '#2c3e50', 'background' => '#ecf0f1', ), 'description' => __( 'Warm red accents with light background', 'stripe' ), ), 'forest' => array( 'name' => __( 'Forest', 'stripe' ), 'colors' => array( 'primary' => '#27ae60', 'secondary' => '#219955', 'text' => '#2c3e50', 'background' => '#f9f9f9', ), 'description' => __( 'Fresh green theme with clean background', 'stripe' ), ), 'ocean' => array( 'name' => __( 'Ocean', 'stripe' ), 'colors' => array( 'primary' => '#3498db', 'secondary' => '#2980b9', 'text' => '#2c3e50', 'background' => '#ecf0f1', ), 'description' => __( 'Calming blue palette', 'stripe' ), ), 'monochrome' => array( 'name' => __( 'Monochrome', 'stripe' ), 'colors' => array( 'primary' => '#333333', 'secondary' => '#555555', 'text' => '#333333', 'background' => '#ffffff', ), 'description' => __( 'Simple black and white theme', 'stripe' ), ), 'sunshine' => array( 'name' => __( 'Sunshine', 'stripe' ), 'colors' => array( 'primary' => '#f1c40f', 'secondary' => '#f39c12', 'text' => '#34495e', 'background' => '#ffffff', ), 'description' => __( 'Bright and cheerful yellow accents', 'stripe' ), ), 'coral' => array( 'name' => __( 'Coral', 'stripe' ), 'colors' => array( 'primary' => '#e67e22', 'secondary' => '#d35400', 'text' => '#2c3e50', 'background' => '#f9f9f9', ), 'description' => __( 'Warm orange palette', 'stripe' ), ), 'minimal' => array( 'name' => __( 'Minimal', 'stripe' ), 'colors' => array( 'primary' => '#bdc3c7', 'secondary' => '#95a5a6', 'text' => '#2c3e50', 'background' => '#ffffff', ), 'description' => __( 'Clean, minimalist design', 'stripe' ), ), ); } /** * Renders the style settings within the WP Simple Pay 'General' tab. * * Creates the tabbed interface for style settings in the form editor. * Includes tabs for themes, colors, typography, layout, and buttons. * * @since 4.17.0 * * @param int $post_id The post ID. * @return void */ public function render_style_settings_in_tab( $post_id ) { // Check if the license allows access to form styles (Plus or higher). $license = simpay_get_license(); if ( ! $license->is_pro( 'plus', '>=' ) ) { $this->render_style_upsell(); return; } // Determine if this is a new form. $is_new_form = $this->is_new_form( $post_id ); // Add a nonce field for security. Must be inside the form. wp_nonce_field( 'wpsps_save_styles', 'wpsps_styles_nonce' ); $style_keys = Settings::get_style_keys(); // Show a warning when the form type is off-site (Stripe Checkout). $form_display_type = simpay_get_saved_meta( $post_id, '_form_display_type', '' ); $is_offsite = 'stripe_checkout' === $form_display_type; ?>
>

get_theme_presets(); // Store themes in a hidden field for JavaScript access. echo ''; // Output theme selection cards. foreach ( $themes as $theme_id => $theme ) { $is_selected = $current_theme === $theme_id; ?>

class="wpsp-admin-theme-radio" >

px

px

px

px

px

px

px

post_type ) { return; } // Check if reset action was triggered. $is_reset = isset( $_POST['wpsps_reset'] ) && 'true' === $_POST['wpsps_reset']; if ( $is_reset ) { // Delete all style settings if reset was requested. $style_keys = Settings::get_style_keys(); foreach ( $style_keys as $key ) { Settings::delete_setting( $post_id, $key ); } return; } $settings_data = isset( $_POST['wpsps'] ) && is_array( $_POST['wpsps'] ) ? $_POST['wpsps'] : array(); $style_keys = Settings::get_style_keys(); foreach ( $style_keys as $key ) { // Check if the setting is in the POST data (even if empty). if ( array_key_exists( $key, $settings_data ) ) { $raw_value = $settings_data[ $key ]; // Save the setting (even if empty, to clear it). // Always save, even if the value is empty, to allow clearing settings. $result = Settings::save_setting( $post_id, $key, $raw_value ); } else { // Only delete setting if it's not in POST at all (not just empty). // This allows users to clear values by submitting empty strings. // Don't delete here - let existing values persist if not in POST. } } } /** * Renders the upsell content for form styles when license is insufficient. * * Shows an upgrade notice for users who don't have Plus license or higher. * * @since 4.17.0 * * @return void */ private function render_style_upsell() { ?>

WP Simple Pay Pro or higher to unlock this and other awesome features.', 'stripe' ), array( 'strong' => array() ) ); ?>

', esc_url( 'https://wpsimplepay.com/my-account/licenses/' ) ), '' ), array( 'a' => array( 'href' => true, 'target' => true, 'rel' => true, ), ) ); ?>