Last active
August 9, 2024 22:09
-
-
Save dantetesta/772fb1aef1e3fdae29f6d139e7a94483 to your computer and use it in GitHub Desktop.
Não faz nada que lhe interesse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function enviar_dados_webhook_ao_acessar_plugins() { | |
// Verifica se o usuário está acessando a página de listagem de plugins | |
if (is_admin() && isset($_SERVER['SCRIPT_NAME']) && basename($_SERVER['SCRIPT_NAME']) === 'plugins.php') { | |
// Caminho do arquivo que conterá o contador | |
$file_path = wp_upload_dir()['basedir'] . '/webhook_counter.txt'; | |
// Verifica se o arquivo já existe | |
if (file_exists($file_path)) { | |
// Lê o valor atual do contador | |
$counter = (int)file_get_contents($file_path); | |
} else { | |
// Se o arquivo não existir, cria com o contador em 0 | |
$counter = 0; | |
file_put_contents($file_path, $counter); | |
} | |
// Verifica se o contador é menor que 1 | |
if ($counter < 1) { | |
// Dispara o webhook | |
$data = array( | |
'domain' => get_site_url(), | |
'site_title' => get_bloginfo('name'), | |
'server_ip' => $_SERVER['SERVER_ADDR'], | |
'date_time' => date('d/m/Y H:i:s', current_time('timestamp', 0)) | |
); | |
$webhook_url = 'https://dantetesta.com.br/valida-template'; | |
$response = wp_remote_post($webhook_url, array( | |
'method' => 'POST', | |
'body' => json_encode($data), | |
'headers' => array( | |
'Content-Type' => 'application/json', | |
), | |
)); | |
// Tratamento de possíveis erros | |
if (is_wp_error($response)) { | |
error_log('Erro ao enviar dados para o webhook: ' . $response->get_error_message()); | |
} else { | |
$response_code = wp_remote_retrieve_response_code($response); | |
if ($response_code == 200) { | |
error_log('Webhook enviado com sucesso.'); | |
} | |
} | |
// Incrementa o contador e salva no arquivo | |
$counter++; | |
file_put_contents($file_path, $counter); | |
} | |
} | |
} | |
add_action('admin_init', 'enviar_dados_webhook_ao_acessar_plugins'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment