WordPress百度API推送脚本

找到当前主题的functions.php文件,添加以下代码

//百度API提交
add_action( 'save_post', 'bd_api', 10, 3 );
function bd_api( $post_id, $post, $update ) {
    if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) {
        return;
    }
    if($post->post_status != 'publish'){
        return;
    }
    if($post->post_type!='post'){
        return;
    }
    if (get_post_meta($post_id, 'apipush', true) == "0") {
        return;
    }
    $urls = array( get_permalink($post_id) );
    $api = 'http://data.zz.baidu.com/urls?site=https://www.jssolo.com&token=AAAAAAAAAAAAA';
    $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);
    curl_exec($ch);
    curl_close($ch);
    update_post_meta($post_id, "apipush", "0");
}
  • 其中$api参数需要改为自己网站的百度推送平台的接口调用地址
© 版权声明
THE END
喜欢就支持一下吧
点赞0打赏 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容