Last active
May 18, 2019 10:10
-
-
Save sivasankars/fcb479027f6b0b44f207301053299e73 to your computer and use it in GitHub Desktop.
Integrate Contact Form 7 With 3rd Party(MSG91) In WordPress (http://sivasankar.in/integrate-contact-form-7-3rd-party-wordpress/)
This file contains 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 | |
/* Contact Form 7 - Hook For MSG91 */ | |
function msg91_api($cf7) { | |
$wpcf = WPCF7_ContactForm::get_current(); | |
if ($wpcf->id() == 4) { | |
if (get_option('enable') == '1') { | |
$authKey = get_option('authKey'); | |
$mobiles = get_option('mobiles'); | |
$senderId = get_option('senderId'); | |
$message = urlencode($_POST['message']); | |
$route = 4; | |
if (strlen($message) >= 160) { | |
$message = substr($message, 0, 157) . '...'; | |
} | |
$url = "http://api.msg91.com/api/sendhttp.php"; | |
$body = array( | |
'authkey' => $authKey, | |
'mobiles' => $mobiles, | |
'message' => $message, | |
'sender' => $senderId, | |
'route' => $route | |
); | |
$request = wp_remote_post($url, array('body' => $body)); | |
} | |
} | |
return $wpcf; | |
} | |
add_action('wpcf7_before_send_mail', 'msg91_api', 10, 4); | |
/* / Contact Form 7 - Hook For MSG91 */ | |
/* WordPress Admin Panel Settings For MSG91 */ | |
add_action('admin_menu', 'msg91_sms_menu'); | |
function msg91_sms_menu() { | |
//create new top-level menu | |
add_menu_page('MSG91 - SMS service provider', 'MSG91', 'administrator', __FILE__, 'msg91_sms', 'dashicons-admin-comments'); | |
//call register settings function | |
add_action('admin_init', 'msg91_plugin_settings'); | |
} | |
function msg91_plugin_settings() { | |
//register our settings | |
register_setting('msg91-sms', 'enable'); | |
register_setting('msg91-sms', 'authkey'); | |
register_setting('msg91-sms', 'senderId'); | |
register_setting('msg91-sms', 'mobiles'); | |
} | |
// html view for our settings | |
function msg91_sms() { ?> | |
<div class="wrap"> | |
<h1>MSG91 - SMS service provider</h1> | |
<form method="post" action="options.php"> | |
<?php settings_fields('msg91-sms'); ?> | |
<?php do_settings_sections('msg91-sms'); ?> | |
<table class="form-table"> | |
<tr valign="top"> | |
<th scope="row">Enable ?</th> | |
<td> | |
<select name="enable"> | |
<option value="1" <?php echo get_option('enable') == 1 ? "selected" : ""; ?> >Yes</option> | |
<option value="0" <?php echo get_option('enable') == 0 ? "selected" : ""; ?> >No</option> | |
</select> | |
</td> | |
</tr> | |
<tr valign="top"> | |
<th scope="row">Authkey</th> | |
<td><input type="text" name="authkey" value="<?php echo esc_attr(get_option('authkey')); ?>" /></td> | |
</tr> | |
<tr valign="top"> | |
<th scope="row">Sender ID</th> | |
<td><input type="text" name="senderId" value="<?php echo esc_attr(get_option('senderId')); ?>" /></td> | |
</tr> | |
<tr valign="top"> | |
<th scope="row">Mobile Numbers</th> | |
<td><input type="text" name="mobiles" value="<?php echo esc_attr(get_option('mobiles')); ?>" /></td> | |
</tr> | |
</table> | |
<?php submit_button(); ?> | |
</form> | |
</div> | |
<?php | |
/* WordPress Admin Panel Settings For MSG91 */ | |
}?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it's not working...