My users provide an external link when the post is created. If the external link is deleted, the local post should also be deleted. To accomplish that, I tried running this code...
function check_external_page_status()
{
if( is_single() )
{
if(get_field('external_listing_page'))
{
$external_url = get_field('external_listing_page');
function get_http_response_code($external_url) {
$external_headers = get_headers($external_url);
return substr($external_headers[0], 9, 3);
}
$get_http_response_code = get_http_response_code($external_url);
if ( $get_http_response_code == 200 ) {
//echo "OKAY!";
}
else
{
//echo "Not okay!";
//echo $get_http_response_code;
//echo get_the_ID();
wp_delete_post( get_the_ID(), false );
wp_redirect( home_url( '/expired-listing/',410 ) );
exit;
}
}
}
}
add_action( 'template_redirect', 'check_external_page_status' );
...but I get these errors...
Warning: get_headers(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/cornwal2/public_html/listings/wp-content/plugins/insert-php/includes/class.execute.snippet.php(390) : eval()'d code on line 12
Warning: get_headers(http://fdsafdsfasd.ca): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/cornwal2/public_html/listings/wp-content/plugins/insert-php/includes/class.execute.snippet.php(390) : eval()'d code on line 12
Warning: Cannot modify header information - headers already sent by (output started at /home/cornwal2/public_html/listings/wp-content/plugins/insert-php/includes/class.execute.snippet.php(390) : eval()'d code:12) in /home/cornwal2/public_html/listings/wp-includes/pluggable.php on line 1251
Warning: Cannot modify header information - headers already sent by (output started at /home/cornwal2/public_html/listings/wp-content/plugins/insert-php/includes/class.execute.snippet.php(390) : eval()'d code:12) in /home/cornwal2/public_html/listings/wp-includes/pluggable.php on line 1254