WordPressの疑似cronを使う方法

WordPressの疑似cronを使う方法。

他のサイトを見ると余計な説明が多かったりするので、ここでは簡潔に。


疑似cronを利用するスクリプトをプラグインで提供すると仮定。


wp-content/plugins/crontest

というディレクトリがあったとして、

wp-content/plugins/crontest/crontest.php

を作成。


中身のコードは例えば



/*

Plugin Name: crontest

Plugin URI: http://pc.freeblo.com

Description:aaaa

Version: 0.1

Author: Test

Author URI: http://pc.freeblo.com/

*/


add_action('testhook','testrun');


function mystart() {

wp_schedule_event(time(),'hourly','testhook');

}

register_activation_hook(__FILE__, 'mystart');


function mystop() {

wp_clear_scheduled_hook('testhook');

}

register_deactivation_hook(__FILE__, 'mystop');


function testrun()

{

//疑似cronで動かしたい処理詳細

}


?>


これでOK。





コメント / トラックバックはありません

コメントをどうぞ