0

I'm trying to use the save_post hook to send an SMS to a telephone number entered into a PODS custom post type. The SMS should be sent when the record is saved.

add_action( 'save_post_appointment', 'sendsms_save' );
function sendsms_save() {
    $username = 'username';
    $password = 'password';
    $msisdn = $_POST["mobile"];
    $content="Hi";
    $data =   "username=".$username."&password=".$password."&message=".urlencode($content)."&msisdn=".urlencode($msisdn);

    $ch = curl_init('http://bulksms.com/eapi/submission/send_sms/2/2.0');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    if ($response = curl_exec($ch)) 
    {
      echo "1";
    } 
    else 
    {
       echo "0";
    }

    curl_close ($ch);
}

Is the $_POST data available when you hook into save_post or will I have to select the latest record to get the telephone number?

2

Yes, whenever a post is saved you should see all of the input items in $_POST ... if you're not using something like xdebug to debug with, you could do something like:

echo "<pre>";
var_dump( $_POST );
echo "</pre>";

To test and see what is all included in $_POST ... note this is just for testing and is not recommended method of debugging, which I would strongly recommend using something like PHPStorm and xdebug ... and in that case all you would need to do is set a breakpoint in your code, and then just look at $_POST in the IDE to see what is available :P

https://www.jetbrains.com/phpstorm/help/configuring-xdebug.html

add_action( 'save_post_appointment', 'sendsms_save' );
function sendsms_save() {
    echo "<pre>";
    var_dump( $_POST );
    echo "</pre>";
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.