Plugin Directory


Ignore:
Timestamp:
11/06/2026 06:15:55 AM (3 days ago)
Author:
wedevs
Message:

Update to version 2.2.0 from GitHub

File:
1 edited

Legend:

Unmodified
Added
Removed
  • texty/trunk/includes/Dispatcher.php

    r3640280 r3787273  
    88use Texty\Dependencies\WeDevs\WPKit\DataLayer\DataLayerFactory;
    99use Texty\Gateways\GatewayInterface;
     10use Texty\Gateways\Secrets;
    1011use WP_Comment;
     12use WP_Error;
    1113
    1214/**
    … …  
    2628        // SMS Logging via gateway hooks
    2729        add_action( 'texty_after_send_sms', [ $this, 'log_sms' ], 10, 4 );
     30        add_action( 'texty_send_sms_no_gateway', [ $this, 'log_no_gateway' ], 10, 3 );
    2831
    2932        // Load integrations
    … …  
    6366     */
    6467    public function user_register( $user_id ) {
    65         $class    = texty()->notifications()->get( 'registration' );
    66         $notifier = new $class();
    67 
    68         $notifier->set_user( $user_id );
    69         $notifier->send();
     68        texty()->queue()->push( 'registration', [ 'user_id' => (int) $user_id ] );
    7069    }
    7170
    … …  
    8685        }
    8786
    88         $class    = texty()->notifications()->get( 'comment' );
    89         $notifier = new $class();
    90 
    91         $notifier->set_comment( $comment_id );
    92         $notifier->send();
     87        texty()->queue()->push( 'comment', [ 'comment_id' => (int) $comment_id ] );
    9388    }
    9489
    … …  
    141136                'notification_group' => $notification_group,
    142137                'message'            => is_string( $message ) ? $message : '',
    143                 'response'           => $this->encode_response( $result ),
     138                'response'           => $this->encode_response( $result, $gateway ),
    144139                'reference_id'       => is_scalar( $reference_id ) ? (string) $reference_id : '',
    145140                'created_at'         => current_time( 'mysql' ),
    … …  
    152147
    153148    /**
     149     * Log a message that couldn't be sent because no gateway is active.
     150     *
     151     * Written as a failed row (with the `texty_no_gateway` reason), so the
     152     * order note's "details in Texty → Logs" has an entry to point to.
     153     *
     154     * @since TEXTY_VERSION
     155     *
     156     * @param WP_Error $error   The `texty_no_gateway` error
     157     * @param string   $to      Recipient phone number
     158     * @param string   $message The message body
     159     *
     160     * @return void
     161     */
     162    public function log_no_gateway( $error, $to, $message ) {
     163        $this->log_sms( $error, $to, $message, false );
     164    }
     165
     166    /**
    154167     * Normalize the gateway result into a JSON-friendly payload for the
    155168     * `response` column. WP_Error gets unpacked into code/message/data so
    … …  
    157170     * scalars are JSON-encoded as-is.
    158171     *
    159      * @param mixed $result The send result (bool, array, or WP_Error).
     172     * The gateway's saved secrets (its `password` fields) are scrubbed from
     173     * the payload, since some providers echo credentials back in responses.
     174     *
     175     * @param mixed                  $result  The send result (bool, array, or WP_Error).
     176     * @param GatewayInterface|false $gateway The gateway that sent it.
    160177     *
    161178     * @return array|string|null
    162179     */
    163     private function encode_response( $result ) {
     180    private function encode_response( $result, $gateway ) {
    164181        if ( is_wp_error( $result ) ) {
    165             return [
     182            $result = [
    166183                'code'    => $result->get_error_code(),
    167184                'message' => $result->get_error_message(),
    … …  
    170187        }
    171188
     189        if ( $gateway instanceof GatewayInterface ) {
     190            $result = Secrets::redact( $result, Secrets::values( $gateway ) );
     191        }
     192
    172193        return $result;
    173194    }
Note: See TracChangeset for help on using the changeset viewer.