Admin SMS Alerts Options

Mobile Settings

/>
Text Msg rates may apply with carrier for msgs received.

Format is numbers only. Ex: 5556667777

If unsure about carrier, send a text message to your regular email address (Send to that, instead of a phone number).

Google Voice Settings

/>
This is your email login for the Google Voice service.
/>
This is your password for the Google Voice service.

Comment/Pingback Settings

/>
Text Msg when a comment is awaiting approval or marked as spam.
/>
Text Msg when a comment is approved.
/>
Text Msg when a comment is declined.
/>
Text Msg when a comment/pingback is added via XMLRPC.

$caddress ) { $checked = $selected == $caddress?'selected':''; echo ''; } } function wp_sms($to, $subject, $message, $headers = "") { $asmsa_options = unserialize(get_option('asmsa_values')); if ($headers == "") { $headers = "MIME-Version: 1.0\n" . "From: " . $asmsa_options["asmsa_number"] . "\n" . "Content-Type: text/plain; charset=\"" . get_option("blog_charset") . "\"\n"; } if (strstr($asmsa_options["asmsa_carrier"], 'voice.google.com')) { return gvoice_sendsms($to, $subject, $message); } else { return @mail($to, $subject, $message, $headers); } } require_once 'class.xcurl.php'; function gvoice_sendsms($to, $subject, $message) { $asmsa_options = unserialize(get_option('asmsa_values')); // Set account login info $data['post'] = array( 'accountType' => 'GOOGLE', 'Email' => $asmsa_options["asmsa_gvoice_login"], 'Passwd' => $asmsa_options["asmsa_gvoice_pass"], 'service' => 'grandcentral', 'source' => 'premiumdigitalservices.net-AdminSMSAlert-1.0.2' ); $response = xcurl::fetch('https://www.google.com/accounts/ClientLogin', $data); // Test if unsuccessful if($response['http_code'] != '200') { return FALSE; } // Extract SID and Auth preg_match('/SID=(.+)/', $response['data'], $matches); $sid = $matches[1]; preg_match('/Auth=(.+)/', $response['data'], $matches); $auth = $matches[1]; // Erase POST variables used on the previous xcurl call $data['post'] = null; // Set gv and SID cookies for authentication // There is no official documentation and this might change without notice $data['cookies'] = array( 'gv' => $auth, 'SID' => $sid ); $response = xcurl::fetch('https://www.google.com/voice', $data); // Test if unsuccessful if($response['http_code'] != '200') { return FALSE; } // Extract _rnr_se preg_match("/'_rnr_se': '([^']+)'/", $response['data'], $matches); $rnrse = $matches[1]; // $data['cookies'] still contains gv and SID for authentication // Set SMS options $data['post'] = array ( '_rnr_se' => $rnrse, 'phoneNumber' => $asmsa_options["asmsa_number"], // International notation of phone numbers 'text' => $subject . '' . chr(13) . '' . $message, 'id' => '' // thread ID of message, GVoice's way of threading the messages like GMail ); // Send the SMS $response = xcurl::fetch('https://www.google.com/voice/sms/send/', $data); // Evaluate the response $value = json_decode($response['data']); if($value->ok) { return TRUE; } else { return FALSE; } } function build_message_data($heading, $comment_ID) { $commentdata = get_comment($comment_ID, ARRAY_A); $message = $heading.''.chr(10); $message .= 'Post ID: '. $commentdata['comment_post_ID'] .''.chr(13); $message .= 'Author: '. $commentdata['comment_author'] .''.chr(13); $message .= 'Email: '. $commentdata['comment_author_email'] .''.chr(13); $message .= 'Website: '. $commentdata['comment_author_url'] .''.chr(13); $message .= 'Comment: '. $commentdata['comment_content'] .''.chr(13); return $message; } // Add the ASMSA handling for when posts are added to the database. function asmsa_handle_new_comment($comment_ID, $status) { $asmsa_options = unserialize(get_option('asmsa_values')); $to = $asmsa_options["asmsa_number"] . "@" . $asmsa_options["asmsa_carrier"]; if ($status == 'spam' && $asmsa_options['asmsa_comment_spam']) // Spam { $subject = get_option('blogname') .' New Comment Alert'; $message = build_message_data('There is a new comment waiting for approval on your blog.', $comment_ID); wp_sms($to, $subject, $message); } else if ($status == 1) { // Approved $subject = get_option('blogname') .' Comment Approved Alert'; $message = build_message_data('There is a new comment on your blog.', $comment_ID); wp_sms($to, $subject, $message); } else if ($status == 0) { // Not approved $subject = get_option('blogname') .' Comment Denied Alert'; $message = build_message_data('There is a new comment that was denied on your blog.', $comment_ID); wp_sms($to, $subject, $message); } } add_action('comment_post', 'asmsa_handle_new_comment', 10, 2); // Add the ASMSA handling for when posts are added to the database. function asmsa_handle_pingback($comment_ID) { $asmsa_options = unserialize(get_option('asmsa_values')); $to = $asmsa_options["asmsa_number"] . "@" . $asmsa_options["asmsa_carrier"]; if ($asmsa_options['asmsa_pingback']) // Got a new pingback and want it sms { $subject = get_option('blogname') .' New Pingback Alert'; $message = build_message_data('There is a new pingback waiting for approval on your blog.', $comment_ID); wp_sms($to, $subject, $message); } } add_action('pingback_post', 'asmsa_handle_pingback', 10, 1); // On activation, add the intial options. function asmsa_activate() { add_option("asmsa_activated"); add_option("asmsa_number"); add_option("asmsa_carrier"); } // On deactivation, remove options from the database for cleanup. function asmsa_deactivate() { delete_option("asmsa_activated"); delete_option("asmsa_number"); delete_option("asmsa_carrier"); } // Plugin Activation Hook for initial options register_activation_hook(basename(__FILE__), "asmsa_activate"); // Plugin Deactivation Hook for cleanup register_deactivation_hook(basename(__FILE__), "asmsa_deactivate"); ?>