_bulk_sms_sa_user = get_option( 'ywsn_bulk_sms_sa_user' ); $this->_bulk_sms_sa_pass = get_option( 'ywsn_bulk_sms_sa_pass' ); $this->_bulk_sms_sa_sender = get_option( 'ywsn_bulk_sms_sa_sender' ); parent::__construct(); } /** * Send SMS * * @since 1.0.0 * * @param $to_phone * @param $message * @param $country_code * * @return array * @throws Exception for WP HTTP API error, no response, HTTP status code is not 201 or if HTTP status code not set * @author Alberto Ruggiero */ public function send( $to_phone, $message, $country_code ) { $args = array( 'comm' => 'sendsms', 'user' => $this->_bulk_sms_sa_user, 'pass' => $this->_bulk_sms_sa_pass, 'to' => $to_phone, 'message' => urlencode( $message ), 'sender' => $this->_bulk_sms_sa_sender, ); $endpoint = 'http://www.bulksms-sa.info/api.php'; // perform HTTP request with endpoint / args $response = wp_remote_get( add_query_arg( $args, $endpoint ) ); // WP HTTP API error like network timeout, etc if ( is_wp_error( $response ) ) { throw new Exception( $response->get_error_message() ); } $this->_log[] = $response; // Check for proper response / body if ( ! isset( $response['body'] ) ) { throw new Exception( __( 'No answer', 'yith-woocommerce-sms-notifications' ) ); } $code = explode( ':', $response['body'] ); if ( $code[0] != 1 ) { throw new Exception( sprintf( __( 'An error has occurred. Error code: %s', 'yith-woocommerce-sms-notifications' ), $code[0] ) ); } return; } } }