/**
* 提交百度收录
*/
function submitBaidu( $post_id, $post ) {
$api = '推送接口调用地址';
$url = get_permalink( $post_id );
$ch = curl_init();
$ops = [
CURLOPT_URL => $api,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $url,
CURLOPT_HTTPHEADER => ['Content-Type: text/plain'],
];
curl_setopt_array( $ch, $ops );
$result = curl_exec( $ch );
curl_close( $ch );
//* 写入错误日志
if ( strpos( $result, 'error' ) ) {
file_put_contents( dirname( __FILE__ ) . 'submit-baidu-error.txt', 'URL:' . $url . PHP_EOL . 'RES:' . $result . PHP_EOL . PHP_EOL, FILE_APPEND );
}
}
add_action( 'publish_post', 'submitBaidu', 10, 2 );
add_action( 'publish_future_post', 'submitBaidu' );
版权声明:文章底部版权声明
初始发布:2026年11月5日





还没有任何评论!