$action_data Automator's action data (ID, recipe_log_id). * @return int|WP_Error Log row ID or the reason it was not queued. */ public static function send( $to, $message, array $action_data ) { $to = is_scalar( $to ) ? trim( (string) $to ) : ''; $message = is_scalar( $message ) ? trim( wp_strip_all_tags( (string) $message ) ) : ''; // The number usually comes from a token (a form, a new user, an order): a visitor controls it. $args = array( 'event_label' => __( 'Uncanny Automator: Send SMS', '85pl-android-sms-api' ), 'check_limits' => true, ); $log_id = absint( $action_data['recipe_log_id'] ?? 0 ); if ( $log_id > 0 ) { $args['dedupe_key'] = implode( '|', array( 'uncanny-automator', $log_id, absint( $action_data['ID'] ?? 0 ), md5( $to . '|' . $message ) ) ); } $result = smsportal_send_sms( $to, $message, $args ); $row = is_int( $result ) ? Messages::get( $result ) : null; if ( null !== $row && 'rate_limited' === $row['status'] ) { // Shown in the recipe log; the SMS row stays under Sent with the same reason. return new WP_Error( 'smsportal_rate_limited', (string) $row['error'] ); } return $result; } }