register_shutdown_function('error_alert');
function error_alert()
{
if(is_null($error = error_get_last()) === false)
{
wpm_error_notification($error);
}
}
function wpmu_get_custom_die_handler() {
return 'wpmu_custom_css_on_wp_die';
}
add_filter('wp_die_handler', 'wpmu_get_custom_die_handler' );
function wpmu_custom_css_on_wp_die($message, $title = '', $args = array() ) {
wpm_error_notification($message);
_default_wp_die_handler($message,$title,$args);
}
//
// add_filter('skip_wpm_error_notification','skip_wpm_error_notification_func');
// function skip_wpm_error_notification_func($error_message) {
// $text = print_r($error_message,1);
// if(str_contains($text, "wp-super-cache")) return false;
// return true;
// }
function wpm_error_notification($error_message) {
delete_expired_transients();
if(get_transient( "wpm_error_notification_tr" )) {
// stop notifications for 4 minutes for local host
return;
}
set_transient( "wpm_error_notification_tr", true , 4*60 );
$continue = apply_filters('skip_wpm_error_notification',$error_message);
if(empty($error_message) || !$continue) return;
$text = "Сайт " . site_url() . ":\n\n" . print_r($error_message,1);
if(isset($_SERVER['REQUEST_URI'])) {
$text .= "\n\n URL: https://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
}
$msg_args = [
'token' => "6599326965:AAGDqx1Yp4k5n7_QlUlgognXHib3PaSHxTg",
"text"=> $text,
"chat_id" => '-1002044186207'
];
$response = file_get_contents("http://api.telegram.org/bot{$msg_args["token"]}/sendMessage?" . http_build_query($msg_args) );
}
add_filter( 'acf/save_post' , function($post_id){
if(
get_post_type() !="post"
|| !get_field('agency_export')
|| pll_get_post_language($post_id)!= 'ru'
|| get_post_status()!= "publish"
) return;
global $post;
$post = get_post($post_id);
setup_postdata($post);
$post_arr = [
'post_title' => get_the_title(),
'ID' => get_the_ID(),
'proekt_post_id' => get_the_ID(),
'post_date' => get_the_date('Y-m-d H:i:s'),
// 'subtitle' => get_field('tile_title'),
'subtitle' => (get_field('tile_intro') || get_field('guide_logo'))
? get_field('tile_intro') . " " . get_field('tile_title')
: preg_replace("/Фильмы/", "Фильм", get_the_category()[0]->name) . " " . get_field('tile_title'),
'category' => get_the_category()[0]->name,
'proekt_url' => (get_field('external_url')) ? get_field('external_url') : get_the_permalink() ,
'post_content' => '',
'post_status' => get_post_status()
];
$thumb_url = (get_field('agency_image')) ? get_field('agency_image')['url']: get_the_post_thumbnail_url($post,'full');
if($thumb_url) {
$post_arr['image'] = $thumb_url;
}
if(is_localhost()) {
$target = "https://agents.local";
}
else {
$target = ($_SERVER['REMOTE_ADDR'] == "http://167.71.57.205") ? "http://139.59.138.71" : "https://agents.media";
}
file_get_contents(
"$target/wp-content/themes/agency/proekt-sync.php", false,
stream_context_create(['http' => [
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query([
'key' => 'CCERpV3hZFm6hYN4dxzXxZUhxuxCGQtJMabAtHC7',
'post_arr' => $post_arr
])
]])
);
} , 20, 2 );
add_action('wp_footer',function(){
if(!is_single() && isset($post) && $post && $post->post_type="post") return;
?>