set_integration( Automator::INTEGRATION_CODE ); $this->set_action_code( Automator::ACTION_CODE ); $this->set_action_meta( Automator::FIELD_PHONE ); $this->set_requires_user( false ); $this->set_sentence( sprintf( /* translators: %s: Automator field code, keep as is. */ esc_attr__( 'Send SMS (85.pl | Android SMS API) to {{a phone number:%s}}', '85pl-android-sms-api' ), $this->get_action_meta() ) ); $this->set_readable_sentence( esc_attr__( 'Send SMS (85.pl | Android SMS API) to {{a phone number}}', '85pl-android-sms-api' ) ); } /** * Fields: number and text. * * @return array> */ public function options() { return array( array( 'option_code' => Automator::FIELD_PHONE, 'label' => esc_attr__( 'Phone number', '85pl-android-sms-api' ), 'description' => esc_attr__( 'With the country code, e.g. +48 600 100 200. Without it, the store\'s country is assumed.', '85pl-android-sms-api' ), 'input_type' => 'text', 'required' => true, 'supports_tokens' => true, ), array( 'option_code' => Automator::FIELD_MESSAGE, 'label' => esc_attr__( 'Message', '85pl-android-sms-api' ), 'input_type' => 'textarea', 'required' => true, 'supports_tokens' => true, 'supports_tinymce' => false, ), ); } /** * Queue the SMS. * * @param int $user_id User ID. * @param array $action_data Action data. * @param int $recipe_id Recipe ID. * @param array $args Trigger arguments. * @param array $parsed Field values with tokens replaced. * @return bool */ protected function process_action( $user_id, $action_data, $recipe_id, $args, $parsed ) { $result = Automator::send( $parsed[ Automator::FIELD_PHONE ] ?? '', $parsed[ Automator::FIELD_MESSAGE ] ?? '', is_array( $action_data ) ? $action_data : array() ); if ( is_wp_error( $result ) ) { $this->add_log_error( $result->get_error_message() ); return false; } return true; } }