毎日13時に実行する自動ツイート機能
-
首記のとおりですが、
➀指定した時刻に毎日1回
➁ランダムな記事をツイートするという機能を作っています。
しかし、➀がど~~~しても、うまくいきません。
下記ように書いており、まったく実行されない状態です。
※時刻指定なければ実行されるので、【以下に間違いがあるハズ】に間違いがあるハズです。
どなたか、間違ったところをご指摘頂けませんでしょうか?
require_once dirname(__FILE__) . '/tmhOAuth-master/tmhOAuth.php'; function tweetPost(){ //トークンなどの設定 $tmhOAuth = new tmhOAuth(array( "consumer_key" => 'xxx', "consumer_secret" => 'xxx', "user_token" => 'xxx', "user_secret" => 'xxx', 'curl_ssl_verifypeer' => false )); //ツイートする記事の取得 $post = get_posts(array( 'numberposts' => '1', 'orderby' => 'rand', 'post_type' => 'post', 'meta_key' => 'checkbox_on', 'meta_value' => 'on', )); //ツイートするテキスト $custom_title = empty($post[0]->post_title) ? '無題' : $post[0]->post_title; $params = array( 'status' => mb_strimwidth($custom_title.'を投稿しました。', 0, 116, "...") . ' ' . get_permalink($post[0]->ID) ); //ツイートする処理 $code = $tmhOAuth->request( 'POST', 'https://api.twitter.com/1.1/statuses/update.json', $params, true, true ); } add_action( 'tweetPost', 'tweetPost' ); /** * 【以下に間違いがあるハズ】 * ---------------------------------------------------------------------------- */ //Cronへ登録 function my_activation(){ if ( ! wp_next_scheduled( 'tweetcron' ) ) { //時差を求める $p = ( current_time( 'timestamp' ) - time( ) ) / 3600; //(今日から)毎日タスクを実行する時間を設定する //管理>設定されたタイムゾーンでの時間を設定する(13:00) $my_time = date( 'Y-m-d 13:00:00', current_time( 'timestamp' ) ); //時差を引いて、UNIX時間(UTC:秒)に合わせる $task_time = strtotime( -1 * $p." hour", strtotime( $my_time ) ); wp_schedule_event( $task_time, 'daily', tweetcron ,array(strtotime( $my_time ))); } } add_action('wp', 'my_activation');
尚、ライブラリは「tmhOAuth(https://github.com/themattharris/tmhOAuth)」を使っています。
どうぞ宜しくお願い致します。<(_ _)>
※ちなみに、似た質問でhttps://ja.wordpress.org/support/topic/%e3%82%b9%e3%82%b1%e3%82%b8%e3%83%a5%e3%83%bc%e3%83%ab%e3%82%92%e5%ae%9f%e8%a1%8c%e3%81%97%e3%81%a6%e3%81%8f%e3%82%8c%e3%81%be%e3%81%9b%e3%82%93/#post-224661がございますが、「今回のは指定時刻バージョン」でリンク先は「毎時間バージョン」なので、別質問にさせて頂きました。
2件の返信を表示中 - 1 - 2件目 (全2件中)
2件の返信を表示中 - 1 - 2件目 (全2件中)
- トピック「毎日13時に実行する自動ツイート機能」には新たに返信することはできません。