'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
— do NOT add form tags here. */ public function render(): void { $currency = esc_html( (string) get_option( 'arshid6social_monetization_currency', 'USD' ) ); $webhook_url = esc_url( rest_url( 'arshid6social/v1/webhook' ) ); ?>

Stripe Dashboard → Developers → API keys. The secret key and webhook signing secret are stored encrypted and are never exposed to the browser or REST API.', '6arshid-social-community' ), array( 'a' => array( 'href' => array(), 'target' => array(), 'rel' => array(), ), 'strong' => array(), ) ), 'https://dashboard.stripe.com/apikeys' ); ?>

render_key_row( 'arshid6social_monetization_stripe_pub_key_live', __( 'Publishable Key (Live)', '6arshid-social-community' ), 'pk_live_…', false ); ?> render_key_row( 'arshid6social_monetization_stripe_secret_live', __( 'Secret Key (Live)', '6arshid-social-community' ), 'sk_live_…', true ); ?> render_key_row( 'arshid6social_monetization_stripe_webhook_secret_live', __( 'Webhook Secret (Live)', '6arshid-social-community' ), 'whsec_…', true ); ?>

render_key_row( 'arshid6social_monetization_stripe_pub_key_test', __( 'Publishable Key (Test)', '6arshid-social-community' ), 'pk_test_…', false ); ?> render_key_row( 'arshid6social_monetization_stripe_secret_test', __( 'Secret Key (Test)', '6arshid-social-community' ), 'sk_test_…', true ); ?> render_key_row( 'arshid6social_monetization_stripe_webhook_secret_test', __( 'Webhook Secret (Test)', '6arshid-social-community' ), 'whsec_…', true ); ?>



Stripe Dashboard → Webhooks. Listen for: customer.subscription.*, invoice.*, payment_intent.*, account.updated.', '6arshid-social-community' ), array( 'a' => array( 'href' => array(), 'target' => array(), 'rel' => array(), ), 'code' => array(), ) ), 'https://dashboard.stripe.com/webhooks' ); ?>

for an API key field. * * For secret fields the stored value is never output to the browser. * A "Saved" indicator is shown when a value exists, and the placeholder * tells the admin to enter a new value only if they want to replace it. * * @param string $opt_name WP option name. * @param string $label Human-readable field label. * @param string $placeholder Hint shown in empty input (e.g. pk_live_…). * @param bool $is_secret True = password input, never pre-fill value. */ private function render_key_row( string $opt_name, string $label, string $placeholder, bool $is_secret ): void { $is_set = Monetization_Crypto::is_set( $opt_name ); if ( $is_secret ) { // Never output the decrypted value into the browser. $input_value = ''; $input_placeholder = $is_set ? __( '— key saved; enter a new value to replace —', '6arshid-social-community' ) : $placeholder; } else { // Publishable keys are client-visible by design — show the saved value. $input_value = (string) get_option( $opt_name, '' ); $input_placeholder = $placeholder; } ?> ✓