wordpress使用百度站长普通收录API推送

 

只在新文章发布时提交一次。
最后边几行用来记录提交状态的日志TXT,相对路径到wordpress根目录,觉得正常之后可以将代码注释掉。

function bd_baidu_api( $new_status, $old_status, $post ) {
	if ( 'publish' === $new_status && 'publish' !== $old_status ) {
		if ( 'post' === $post->post_type ) {
			$urls = array();
			array_push($urls, get_permalink( $post ));
			$api = '→→→→→→→→→→→→→→→→→→→→换成你自己的←←←←←←←←';
			$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;
			$file=dirname(dirname(dirname(dirname(__FILE__)))).'/bapilog.txt';
			if (is_writable($file)) {
				file_put_contents($file, $urls[0]."\n", FILE_APPEND | LOCK_EX);
				file_put_contents($file, $result."\n", FILE_APPEND | LOCK_EX);
			}
		}
	}
}
add_action( 'transition_post_status', 'bd_baidu_api', 10, 3 );
本文发布于 。属于 WordPress点滴 分类,被贴了 标签。

《wordpress使用百度站长普通收录API推送》有0个评分

★★★★★
★★★★
★★★
★★
0
0
0
0
0

wordpress使用百度站长普通收录API推送》有3个想法

  1. 真噶系小白~ 要自己先创建bapilog.txt,代码仲要摆喺functions.php里边最开头!摆最后会提示错误~~

      1. 放系后边会出错,系前边就唔会。。 可能系我主题噶问题,宜家正常使用~完美!

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注