-
-
Save zevilz/5c3f35412443f82a5a8c566e2c8ce665 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $z_cf7_to_tlg_args = [ | |
| 'bot_token' => '123456', | |
| 'receivers' => [ | |
| 123456, | |
| ], | |
| ]; | |
| function z_cf7_to_tlg_send_message( $message, $receiver ) { | |
| global $z_cf7_to_tlg_args; | |
| $params['text'] = strip_tags( $message ); | |
| $params['chat_id'] = intval( $receiver ); | |
| $params['parse_mode'] = 'HTML'; | |
| $api_url = 'https://api.telegram.org/bot'. $z_cf7_to_tlg_args['bot_token']; | |
| $response = wp_remote_get( $api_url . '/sendmessage?' . http_build_query( $params ) ); | |
| if ( is_wp_error( $response ) ){ | |
| error_log( 'Error in cf7-to-tlg: ' . $response ); | |
| } | |
| else { | |
| $response_body = json_decode( wp_remote_retrieve_body( $response ), true ); | |
| if ( ! $response_body['ok'] ) { | |
| error_log( 'Error in cf7-to-tlg: ' . json_encode( $response_body ) ); | |
| } | |
| } | |
| } | |
| function z_cf7_to_tlg_action( $components, $wpcf7_get_current_contact_form, $instance ) { | |
| global $z_cf7_to_tlg_args; | |
| $message = "<b>" . $components['subject'] . "</b>\n\n" . $components['body']; | |
| foreach ( $z_cf7_to_tlg_args['receivers'] as $receiver ) { | |
| z_cf7_to_tlg_send_message( $message, $receiver ); | |
| } | |
| return $components; | |
| } | |
| add_filter( 'wpcf7_mail_components', 'z_cf7_to_tlg_action', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment