Answer the question
In order to leave comments, you need to log in
How to send a 404 error source to a VK message via api?
There is an interesting idea that is now working, but it does not work completely smoothly. All this is implemented on wp with a custom 404 page. The code that below clings to the 404 page and sends a message to VK (the site runs a script that crashes from time to time (+ the plugin overwrites an important file and everything breaks (cancel the recording is not a variant), but operational there is no way - how to find out in time that the errors have gone)
// I immediately say in the code I don’t rummage at all - a dense forest)
Code
function wpd_do_stuff_on_404(){
if( is_404() ){
$url = 'https://api.vk.com/method/messages.send';
$params = array(
'user_id' => $id = '266212779', // Кому отправляем, если взять вместо и вставить user_ids тогда можно будет добавлять id через запятую (сообщение будет отправляться 2х пользователям)
'message' => $message = '<br>__ ▂ ▃ ▅ ▇ █ 。◕‿ ◕。 █ ▇ ▅ ▃ ▂ __<br>Привет! На сайте появилась ошибка 404<br>Проверь пожалуйста<br>[ ▇ ▃ ▄ ▅ █ ▇ ▂ ▃ ▁ ▄ ▅ █ ▅ ▃ ▇ ]', // Что отправляем
'access_token' => '0000000000000000000000000', // access_token можно вбить хардкодом, если работа будет идти из под одного юзера
'v' => '5.37',
);
// В $result вернется id отправленного сообщения
$result = file_get_contents($url, false, stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query($params)
)
)));
}
}
add_action( 'template_redirect', 'wpd_do_stuff_on_404' );
<?php echo do_shortcode( ' [wbcr_php_snippet id="1135"]' ); ?> (плагин добаления шорткодов, потому что как вывести в странице код ошибки я не знаю, а вот как добавить шорткод в php это я нагуглил)
<?php echo do_action('template_redirect'); ?>
Answer the question
In order to leave comments, you need to log in
display the error code in the page I do not know
echo do_action('template_redirect');
But <?php echo do_action('template_redirect'); ?>
it was inserted there not by experience ... Namely, a code was taken that captures the 404 page (I had a question in my profile, like how to capture 404)
+ What will be the code that would make it all work?
What do you need to write to send?
Minimum code knowledge
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question