417   WordPress

1, add fellow content in the functions.php file

function pingBaidu($post_id){
$post_url = get_permalink($post_id);
$date_time = date(“Y-m-d H:i:s”, time());

$urls = array(
$post_url
);
$api = ‘http://data.zz.baidu.com/urls?site=XXXXXXXXXXXXXX&token=XXXXXXXXXXXXXXXXX’;
$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);

$str = $date_time.”:”.$result.”\r\n”;
$log_file_path = ‘pingBaidu_log.txt’;
$open=fopen($log_file_path,”a” );
fwrite($open,$str);
fclose($open);
}
add_action(‘publish_post’, ‘pingbaidu’);

2, make sure the log file is exist and can be write

3, parameter $api can be get here https://zhanzhang.baidu.com , of course , you need to register a account for youself




Leave a Reply

Your email address will not be published. Required fields are marked *