<? php /*Plugin Name: Bear Palm Active Push *Description: Bear Palm Active Push in WordPress until version 4.7 *Author: small beast wordpress * Author URI: https://www.seo628.com * Version: 0.1-beta */ define('APPID', '*********');// Define bear paw appid define('TOKEN', '*********');// Define bear paw push token if(! function_exists('Baidu_Submit') && function_exists('curl_init')) { function Baidu_Submit($post_ID) { //Articles that have been successfully pushed will not be pushed again global $post; if(empty($post_ID) || get_post_meta($post_ID,'Baidusubmit',true) == 1) return; $status = $post->post_status; if($status != '' && $ status != 'publish'){ $url = get_permalink($post_ID); $api = ' http://data.zz.baidu.com/urls?appid= '. APPID.'&token='.TOKEN.'&type=realtime'; $ch = curl_init(); $options = array( CURLOPT_URL => $api, CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => $url, CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), ); curl_setopt_array($ch, $options); $result = json_decode(curl_exec($ch),true); //If the push is successful, a user-defined column called Baidusubmit will be added to the article. The value is 1 if (array_key_exists('success',$result)) { add_post_meta($post_ID, 'Baidusubmit', 1, true); } } } add_action('publish_post', 'Baidu_Submit'); }