延迟两秒执行主动推送百度站长

Published
2023-08-18
浏览次数 :  34

// Schedule the execution of the function after 2 seconds of post published
function schedule_function_after_delay($ID) {
    wp_schedule_single_event(time() + 2, 'custom_function_hook', array($ID));
}
add_action('publish_post', 'schedule_function_after_delay');

// Define your custom function to run after the delay
function custom_function_to_run($post_id) {
    // Your PHP code here
    $urls = array(
        'http://www.example.com/1.html',
        'http://www.example.com/2.html',
    );
    $api = 'http://data.zz.baidu.com/urls?site=https://www.xmdn.net&token=HICT1PB6RBeN7ien';
    $ch = curl_init();
    $options =  array(
        CURLOPT_URL => $api,
        CURLOPT_POST => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_POSTFIELDS => implode("\n", $urls),
        CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
    );
    curl_setopt_array($ch, $options);
    $result = curl_exec($ch);
    echo $result;
    curl_close($ch);
}
add_action('custom_function_hook', 'custom_function_to_run');

  • 标签1
  • 标签1
  • 标签1
Top