• Resolved Hiranthi

    (@illutic)


    I just saw a fatal error in my log:

    PHP Fatal error: Cannot use object of type WP_Error as array in /…/wp-content/plugins/postmark-approved-wordpress-plugin/postmark.php on line 306, referer: …/wp-admin/edit-comments.php

    I noticed there is no check if $response was in fact filled by the WP_Error class, so I changed the pm_send_mail function (at the bottom of postmark.php) a bit:

    Original:

    function pm_send_mail($headers, $email){
    	$args = array(
    		'headers' => $headers,
    		'body' => json_encode($email)
    	);
    	$response = wp_remote_post(POSTMARK_ENDPOINT, $args);
    
    	if($response['response']['code'] == 200) {
    		return true;
    	} else {
    		return false;
    	}
    }

    What I currently use:

    function pm_send_mail($headers, $email){
    	$args = array(
    		'headers' => $headers,
    		'body' => json_encode($email)
    	);
    	$response = wp_remote_post(POSTMARK_ENDPOINT, $args);
    
    	if ( is_wp_error( $response ) ) return false; // added to check whether $response is filled by WP_Error, if so: return false
    
    	if($response['response']['code'] == 200) {
    		return true;
    	} else {
    		return false;
    	}
    }

    https://www.ads-software.com/plugins/postmark-approved-wordpress-plugin/

Viewing 1 replies (of 1 total)
  • here is my version of fixing it as $curl is not available here.

    --- postmark.php.origin 2015-05-19 22:34:44.728346590 -0600
    +++ postmark-approved-wordpress-plugin/postmark.php     2014-06-10 14:39:08.000000000 -0600
    @@ -286,8 +286,8 @@
    
         $response = pm_send_mail($postmark_headers, $email);
    
    -    if ($response !== true){
    -       return "Test Failed with Error ".$response['body'];
    +    if ($response === false){
    +       return "Test Failed with Error ".curl_error($curl);
         } else {
            return "Test Sent";
            }
    @@ -306,8 +306,8 @@
            if($response['response']['code'] == 200) {
                    return true;
            } else {
    -               return $response;
    +               return false;
            }
     }
Viewing 1 replies (of 1 total)
  • The topic ‘Fatal Error’ is closed to new replies.