Created
August 12, 2013 23:00
-
-
Save lknight/6216156 to your computer and use it in GitHub Desktop.
WordPress SMS Notifications (http://ditio.net/2012/02/18/wordpress-sms-notifications/)
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
/* | |
Plugin Name: TM Example | |
Plugin URI: http://ditio.net | |
Description: TextMagic Example | |
Author: Greg Winiarski | |
Version: 0.01 | |
Author URI: http://ditio.net | |
TextMagic SMS delivery example. | |
*/ | |
add_filter('wp_insert_post_data', 'tm_insert', 0, 2); | |
function tm_insert($post) { | |
if($post["post_status"] != "publish" || $post["post_type"] != "post") { | |
// run only when post is published | |
return $post; | |
} | |
$isUtf = false; | |
$title = substr($post["post_title"], 0, 140); | |
if (preg_match('!\S!u', $title)) { | |
$isUtf = true; | |
} | |
$arr = array( | |
"cmd" => "send", | |
"username" => "your-username", | |
"password" => "your-api-password", | |
"text" => $title, | |
// recipient phone number, starts with country prefix | |
// should be just numbers, if you wish to send it to | |
// multiple recipients you need to seperate numbers with comma | |
"phone" => "48601xxxxxx", | |
"unicode" => $isUtf, | |
// from is the Sender ID you registered earlier | |
"from" => "TM-Example", | |
// make sure just one sms is sent | |
"max_length" => 1 | |
); | |
$query = http_build_query($arr); | |
$result = wp_remote_get("http://www.textmagic.com/app/api?".$query); | |
if(is_wp_error($result)) { | |
// log error message somewhere | |
$object = json_decode($result["body"]); | |
$error = $object->error_message; | |
} else { | |
// sms sent | |
$object = json_decode($result["body"]); | |
} | |
return $post; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment