Support

Account

Home Forums ACF PRO acf/save_post causes Error 500

Helping

acf/save_post causes Error 500

  • Hy!

    I’m having a problem with the acf/save_post function in a self written plugin.

    A option page, where a checkbox is set/unset generates a CURL Action to OneSignal. The script work’s as it should, but if i update a normal page, i’m getting a Error 500. The log says: Premature end of script headers: post.php

    Any Ideas?

    Best regards,
    Bernhard

    function opentimes_push(){
    
    	$screen = get_current_screen();
    	if (strpos($screen->id, "acf-options-schigebiet-lifte") == true) {
    
    		$skiresort_status_text = get_field('schigebiet','option') ? "GEƖFFNET" : "GESCHLOSSEN";
        $content = array(
            "en" => 'Schigebiet hat ab sofort '.$skiresort_status_text.''
            );
    
        $fields = array(
            'app_id' => "XXX",
            'included_segments' => array('All'),
            'data' => array("foo" => "bar"),
            'large_icon' =>"favicon-transparent-150x150.png",
            'contents' => $content
        );
    
        $fields = json_encode($fields);
    		print("\nJSON sent:\n");
    		print($fields);
    
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8',
                                                   'Authorization: Basic XXX'));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        curl_setopt($ch, CURLOPT_POST, TRUE);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    
        $response = curl_exec($ch);
        curl_close($ch);
    
        return $response;
    }
    
    $response = opentimes_push();
    $return["allresponses"] = $response;
    $return = json_encode( $return);
    }
    
    add_action('acf/save_post', 'opentimes_push', 20);
  • I finally got it working myself!
    I’ve printed the JSON result and not returned it from the function, that caused the error.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘acf/save_post causes Error 500’ is closed to new replies.