'boolean', 'default' => false, 'sanitize_callback' => 'rest_sanitize_boolean', ) ); // Active gateway (extensible via arshid6social_monetization_payment_gateways filter). register_setting( self::OPTION_GROUP, 'arshid6social_monetization_active_gateway', array( 'type' => 'string', 'default' => 'stripe_connect', 'sanitize_callback' => 'sanitize_key', ) ); // Test-mode toggle. register_setting( self::OPTION_GROUP, 'arshid6social_monetization_stripe_test_mode', array( 'type' => 'boolean', 'default' => true, 'sanitize_callback' => 'rest_sanitize_boolean', ) ); // Publishable keys — plain text (safe to store unencrypted; these are // client-visible by Stripe's own design). Keep existing if submitted blank. foreach ( array( 'arshid6social_monetization_stripe_pub_key_live', 'arshid6social_monetization_stripe_pub_key_test' ) as $opt ) { register_setting( self::OPTION_GROUP, $opt, array( 'type' => 'string', 'default' => '', 'sanitize_callback' => static function ( $value ) use ( $opt ) { $value = sanitize_text_field( wp_unslash( (string) $value ) ); // Empty submission keeps the existing value. if ( '' === trim( $value ) ) { return (string) get_option( $opt, '' ); } return $value; }, ) ); } // Secret keys + webhook secrets — encrypted before storage. // Empty submission keeps the existing encrypted blob (so the admin // does not accidentally clear a key just by saving other settings). foreach ( array( 'arshid6social_monetization_stripe_secret_live', 'arshid6social_monetization_stripe_webhook_secret_live', 'arshid6social_monetization_stripe_secret_test', 'arshid6social_monetization_stripe_webhook_secret_test', ) as $opt ) { register_setting( self::OPTION_GROUP, $opt, array( 'type' => 'string', 'default' => '', 'sanitize_callback' => static function ( $value ) use ( $opt ) { try { $value = sanitize_text_field( wp_unslash( (string) $value ) ); if ( '' === trim( $value ) ) { return (string) get_option( $opt, '' ); } // WordPress can fire sanitize_callbacks twice; the second // call receives the already-encrypted blob — pass it through. if ( Monetization_Crypto::is_encrypted( $value ) ) { return $value; } $encrypted = Monetization_Crypto::encrypt( $value ); // If encryption returned empty (failure), keep existing value. return ( '' !== $encrypted ) ? $encrypted : (string) get_option( $opt, '' ); } catch ( \Throwable $e ) { arshid6social_debug_log( 'Monetization key save failed for option: ' . sanitize_key( $opt ) ); return (string) get_option( $opt, '' ); } }, ) ); } // Platform fee — percentage (0–100). register_setting( self::OPTION_GROUP, 'arshid6social_monetization_platform_fee_pct', array( 'type' => 'number', 'default' => 0, 'sanitize_callback' => static function ( $v ) { return max( 0.0, min( 100.0, (float) $v ) ); }, ) ); // Platform fee — flat amount per transaction. register_setting( self::OPTION_GROUP, 'arshid6social_monetization_platform_fee_flat', array( 'type' => 'number', 'default' => 0, 'sanitize_callback' => static function ( $v ) { return max( 0.0, (float) $v ); }, ) ); // Currency code. register_setting( self::OPTION_GROUP, 'arshid6social_monetization_currency', array( 'type' => 'string', 'default' => 'USD', 'sanitize_callback' => static function ( $v ) { $allowed = array( 'USD', 'EUR', 'GBP', 'CAD', 'AUD', 'JPY', 'CHF', 'SEK', 'NOK', 'DKK', 'TRY', 'AED', 'SAR', ); $v = strtoupper( sanitize_text_field( (string) $v ) ); return in_array( $v, $allowed, true ) ? $v : 'USD'; }, ) ); // Minimum subscription price creators can set. register_setting( self::OPTION_GROUP, 'arshid6social_monetization_min_sub_price', array( 'type' => 'number', 'default' => 1.00, 'sanitize_callback' => static function ( $v ) { return max( 0.01, (float) $v ); }, ) ); } // ------------------------------------------------------------------------- // Render // ------------------------------------------------------------------------- public function enqueue_tab_styles(): void { $screen = get_current_screen(); if ( ! $screen || false === strpos( $screen->id, 'arshid6social-settings' ) ) { return; } wp_add_inline_style( 'arshid6social-admin', '.arshid6social-mon-section{margin:24px 0 0}.arshid6social-mon-section h3{border-bottom:1px solid #ddd;padding-bottom:8px;margin-bottom:0}.arshid6social-mon-key-set{color:#46b450;font-weight:600;margin-left:8px}.arshid6social-mon-code{font-family:monospace;background:#f6f7f7;padding:4px 8px;border-radius:3px;word-break:break-all}' ); } /** * Outputs the Monetization settings tab content. * Called inside the core admin-settings