[WordPress] 外掛分享: Task Scheduler

WordPress 外掛 Task Scheduler 的封面圖片。

前言介紹

  • 這款 WordPress 外掛「Task Scheduler」是 2014-07-29 上架。
  • 目前有 300 個安裝啟用數。
  • 上一次更新是 2022-02-26,距離現在已有 1163 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
  • 外掛最低要求 WordPress 3.7 以上版本才可以安裝。
  • 有 7 人給過評分。
  • 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。

外掛協作開發者

miunosoft | michael-uno |

外掛標籤

task | tool | backend | utility | background |

內容簡介

處理龐大的動作數量

您是否有特定的任務需要在您希望的時間運行?您是否使用WordPress作為代理從外部來源生成數據?隨著WordPress的發展成為應用程序平台的階段,需要出現一個更強大的任務管理系統。

目前,使用WP Cron,如果註冊大量動作,例如要立即運行1000個任務且其中一個卡住,就將影響所有其他動作,使他們無法按計劃時間加載。此外,如果網站沒有訪問者,預定的任務也不會被觸發。該插件的目標是解決此類問題,成為完美解決方案,為WordPress驅動的後端應用程序服務器提供完整的API功能。

它的功能

(可選)定期後台訪問網站。
在所需的時間或間隔內觸發站點所有者註冊的任務。

內置動作

刪除文章-根據文章類型,文章狀態,分類和分類詞執行大量刪除。
發送電子郵件-發送電子郵件到指定的電子郵件地址。
清除瞬間(快取)-刪除過期的瞬間。
檢查網站-訪問指定的網頁並檢查某些關鍵詞。
運行PHP腳本-運行您選擇的PHP腳本。

自定義動作模塊

自動發布 -自動創建文章。

可擴展的

設計成完全可擴展,開發人員可以添加自定義模塊,包括動作和發生類型。

創建自定義動作

您可以使用Task Scheduler運行自定義動作並在計劃的時間運行它,每天運行一次,以固定的間隔運行,或者使用插件設置的任何內容。

將包含模塊的代碼放置在啟用主題的插件或functions.php中。

1.選擇要作為WordPress過濾器鉤子的任務標識符。

例如,您選擇my_custom_action作為任務名稱。

2.使用WordPress核心函數add_filter()鉤住操作。

/**
* Task Scheduler插件加載時調用。
*/
function doMyCustomAction( $isExitCode, $oRoutine ) {

/**
* 在此處儲存所有內容。
*/
TaskScheduler_Debug::log( $oRoutine->getMeta() );
return 1;

}
/**
* 通過Dashboard->Task Scheduler->Add New Task中的“Select Action”屏幕設置“my_custom_action”自定義操作鉤子。
*/
add_filter( 'my_custom_action', 'doMyCustomAction', 10, 2 );

請注意,我們使用add_filter()而不是add_action()以返回退出代碼。

如果任務完成,則返回1,當有問題時返回0(可以傳遞除null之外的任何值)。

3.前往Dashboard->Task Scheduler->Add New Task。根據向導進行操作,並在設置發生時,類型my_custom_action中選擇上面定義的動作標識符。

該字段中設置的操作標識符將在計劃的時間觸發。

修改現有的代碼將更加容易。您可以下載zip文件並將其安裝在您的網站上。

創建自定義操作模塊

如果您希望在“選擇操作”屏幕中列出自己的操作,則需要創建自己的操作模塊。

原文外掛簡介

Handle Massive Number of Actions
Do you have specific tasks which need to run at your desired time? Do you use WordPress as a proxy to generate data from external sources? As WordPress has evolved into a phase of application platforms, a more enhanced task management system needed to emerge.
Currently, with WP Cron, if you register a large number of actions, for example, 1000 tasks to run immediately and one of them stalls, it affects all the other actions preventing them from being loaded at the scheduled time. Also, the scheduled tasks won’t be triggered if there is no visitor on the site. The goal of this plugin is to resolve such issues and become the perfect solution for WordPress powered back-end application servers to provide full-brown API functionalities.
What it does

(optional) creates periodic background access to the site.
triggers tasks registered by the site owner at desired time or interval.

Built-in Actions

Delete Posts – performs bulk deletion of posts based on the post type, post statuses, taxonomy, and taxonomy terms.
Send Email – sends email to specified email addresses.
Clean Transients – deletes expired transients (caches).
Check Web Sites – accesses specified web pages and checks certain keywords.
Run PHP Scripts – runs PHP scripts of your choosing.

Custom Action Modules

Auto Post – creates posts automatically.

Extensible
This is designed to be fully extensible and developers can add custom modules including actions and occurrence types.
Create a Custom Action
You can run your custom action with Task Scheduler and run it at scheduled times, once a day, with a fixed interval, or whatever you set with the plugin.
Place the code that includes the module in your plugin or functions.php of the activated theme.
1. Decide your action slug which also serves as a WordPress filter hook.
Say, you pick my_custom_action as an action name.
2. Use the add_filter() WordPress core function to hook into the action.
/**
* Called when the Task Scheduler plugin gets loaded.
*/
function doMyCustomAction( $isExitCode, $oRoutine ) {

/**
* Do you stuff here.
*/
TaskScheduler_Debug::log( $oRoutine->getMeta() );
return 1;

}
/**
* Set the 'my_custom_action' custom action slug in the Select Action screen
* via Dashboard -> Task Scheduler -> Add New Task.
*/
add_filter( 'my_custom_action', 'doMyCustomAction', 10, 2 );

Please note that we use add_filter() not add_action() in order to return an exit code.
Return 1 if the task completes and 0 when there is a problem. You can pass any value except null.
3. Go to Dashboard -> Task Scheduler -> Add New Task. Proceed with the wizard and when you get the Select Action screen after setting up the occurrence, type my_custom_action, the one you defined in the above step.
The action slug set in the field will be triggered at the scheduled time.
It will be easier for you to modify an existent code. You can download the zip file and install it on your site.
Create a Custom Action Module
If you want your action to be listed in the Select Action screen, you need to create an action module.
To create an action module, you need to define a class by extending a base class that Task Scheduler prepares for you.
1. Define your custom action module class by extending the TaskScheduler_Action_Base class.
class TaskScheduler_SampleActionModule extends TaskScheduler_Action_Base {

/**
* The user constructor.
*
* This method is automatically called at the end of the class constructor.
*/
public function construct() {}

/**
* Returns the readable label of this action.
*
* This will be called when displaying the action in an pull-down select option, task listing table, or notification email message.
*/
public function getLabel( $sLabel ) {
return __( 'Sample Action Module', 'task-scheduler-sample-action-module' );
}

/**
* Returns the description of the module.
*/
public function getDescription( $sDescription ) {
return __( 'This is a sample action module.', 'task-scheduler-sample-action-module' );
}

/**
* Defines the behaviour of the task action.
*
*/
public function doAction( $isExitCode, $oRoutine ) {

/**
* Write your own code here! Delete the below log method.
*
* Good luck!
*/
TaskScheduler_Debug::log( $oRoutine->getMeta() );

// Exit code.
return 1;

}

}

In the doAction() method of the above class, define the behaviour of your action what it does. The second parameter receives a routine object. The object has a public method named getMeta() which returns the associated arguments.
2. Use the task_scheduler_action_after_loading_plugin action hook to register your action module.
To register your action module, just instantiate the class you defined.
function loadTaskSchedulerSampleActionModule() {

// Register a custom action module.
include( dirname( __FILE__ ) . '/module/TaskScheduler_SampleActionModule.php' );
new TaskScheduler_SampleActionModule;

}
add_action( 'task_scheduler_action_after_loading_plugin', 'loadTaskSchedulerSampleActionModule' );

3. Go to Dashboard -> Task Scheduler -> Add New Task. Proceed the wizard and when you get the Select Action screen, choose your action.
You can set your custom arguments in the Argument (optional) field if necessary.
The set values will be stored in the argument element of the array returned by the getMeta() public method of the routine object.
It will be easier for you to modify an existent module. Get an example action module which comes as a plugin from this page. Download and activate it on your test site. Then modify the code, especially the doAction() method which defines the behavior of the action.
Create Threads
When your routine is too heavy and gets hung often, you can create threads that performs sub-routines of the main routine.
1. Define your thread class the TaskScheduler_Action_Base class.
class TaskScheduler_SampleActionModule_Thread extends TaskScheduler_Action_Base {

/**
* Returns the readable label of this action.
*
* This will be called when displaying the action in an pull-down select option, task listing table, or notification email message.
*/
public function getLabel( $sLabel ) {
return __( 'Run a PHP Script', 'task-scheduler' );
}

/**
* Defines the behavior of the task action.
*/
public function doAction( $isExitCode, $oThread ) {

// Do your stuff
$_aThreadArguments = $oThread->getMeta();
TaskScheduler_Debug::log( $_aThreadArguments );
return 1;

}
}

2. Instantiate the thread class.
In the construct() method of your action module class introduced above that calls threads, instantiate the thread class by passing a custom action name. Here we pass task_scheduler_my_thread as an example.
class TaskScheduler_SampleActionModule extends TaskScheduler_Action_Base {

public function construct() {
new TaskScheduler_SampleActionModule_Thread( 'task_scheduler_my_thread' );
}

...

}

3. Create a thread.
In the doAction() method of your action module class, create a thread with the createThread() method. The parameters are:
createThread( $sThreadActionHookName, $oRoutine, array $aThreadOptions, array $aSystemTaxonomyTerms=array(), $bAllowDuplicate )

1. `$sThreadActionHookName` - (string, required) the slug that serves as an action hook name
2. `$oRoutine` - (object, required) the routine object that is passed to the second parameter of `doAction()`` method.
3. `$aThreadOptions` - (array, required) an associative array holding arguments to pass to the thread.
4. `$aSystemTaxonomyTerms` - (array, optional) an array holding taxonomy terms for the system the plugin provides. Default: `array()``.
5. `$bAllowDuplicate` - (boolean, optional) whether to allow threads to be created with same arguments. Default: `false`.

Make sure the return value is null so that the routine will not close. Here we assume the $_aData variable holds lots of items so it must be processed separately by threads.
class TaskScheduler_SampleActionModule extends TaskScheduler_Action_Base {
...
public function doAction( $isExitCode, $oRoutine ) {

// Assuming this is big.
$_aData = array(
array( 'a', 'b', 'c' ),
array( 'd', 'e', 'f', 'g' ),
array( 'h', 'i' ),
);

foreach( $_aData as $_aDatum ) {
$_aArguments = array(
'datum' => $_aDatum,
'foo' => 'bar',
);
$this->createThread( 'task_scheduler_my_thread', $oRoutine, $_aArguments );
}

// Do not close this routine by returning 'null'. When all the threads are done, this routine will be automatically closed.
return null;

}
...
}

4. Process Passed Data from a Routine to a Thread.
In the thread class, retrieve the passed data.
class TaskScheduler_SampleActionModule_Thread extends TaskScheduler_Action_Base {

...

/**
* Defines the behavior of the task action.
*/
public function doAction( $isExitCode, $oThread ) {

// Do your stuff
$_aArguments = $oThread->getMeta();
$_sFoo = $_aArguments[ 'foo' ]; // is 'bar'
$_aDatum = $_aArguments[ 'datum' ]; // is either array( 'a', 'b', 'c' ), array( 'd', 'e', 'f', 'g' ), or array( 'h', 'i' )

TaskScheduler_Debug::log( $_aArguments );
return 1;

}

}

The entire code will look like this.
Action Module Class:
class TaskScheduler_SampleActionModule extends TaskScheduler_Action_Base {

/**
* The user constructor.
*
* This method is automatically called at the end of the class constructor.
*/
public function construct() {
new TaskScheduler_SampleActionModule_Thread( 'task_scheduler_my_thread' );
}

/**
* Returns the readable label of this action.
*
* This will be called when displaying the action in an pull-down select option, task listing table, or notification email message.
*/
public function getLabel( $sLabel ) {
return __( 'Sample Action Module', 'task-scheduler-sample-action-module' );
}

/**
* Returns the description of the module.
*/
public function getDescription( $sDescription ) {
return __( 'This is a sample action module.', 'task-scheduler-sample-action-module' );
}

public function doAction( $isExitCode, $oRoutine ) {

// Assuming this is big.
$_aData = array(
array( 'a', 'b', 'c' ),
array( 'd', 'e', 'f', 'g' ),
array( 'h', 'i' ),
);

foreach( $_aData as $_aDatum ) {
$_aArguments = array(
'datum' => $_aDatum,
'foo' => 'bar',
);
$this->createThread( 'task_scheduler_my_thread', $oRoutine, $_aArguments );
}

// Do not close this routine by returning 'null'. When all the threads are done, this routine will be automatically closed.
return null;

}

}

Thread Class:
class TaskScheduler_SampleActionModule_Thread extends TaskScheduler_Action_Base {

/**
* Returns the readable label of this action.
*
* This will be called when displaying the action in an pull-down select option, task listing table, or notification email message.
*/
public function getLabel( $sLabel ) {
return __( 'Run a PHP Script', 'task-scheduler' );
}

/**
* Defines the behavior of the task action.
*/
public function doAction( $isExitCode, $oThread ) {

// Do your stuff
$_aArguments = $oThread->getMeta();
$_sFoo = $_aArguments[ 'foo' ]; // is 'bar'
$_aDatum = $_aArguments[ 'datum' ]; // is either array( 'a', 'b', 'c' ), array( 'd', 'e', 'f', 'g' ), or array( 'h', 'i' )

TaskScheduler_Debug::log( $_aArguments );
return 1;

}

}

Don’t forget to instantiate the action module class.
new TaskScheduler_SampleActionModule;

Terminologies

Task – a rule which defines what kind of action routine to be performed at a specified time.
Routine – a main action routine created by a task. Depending on the action, it creates an action thread to divide its routine.
Thread – a divided action sub-sequential routine created by a routine. For example, The email action creates threads and sends emails per thread instead of sending them all in one routine to avoid exceeding the PHP’s maximum execution time.

各版本下載點

  • 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
  • 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「Task Scheduler」來進行安裝。

(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。


1.0.0 | 1.0.1 | 1.1.0 | 1.1.1 | 1.2.0 | 1.3.0 | 1.3.1 | 1.3.2 | 1.3.3 | 1.3.4 | 1.4.0 | 1.4.1 | 1.4.2 | 1.4.3 | 1.4.4 | 1.4.5 | 1.4.6 | 1.4.7 | 1.4.8 | 1.4.9 | 1.5.0 | 1.5.1 | 1.5.2 | 1.5.3 | 1.5.4 | 1.6.0 | 1.6.2 | 1.6.3 | trunk | 1.0..2 | 1.0.0b02 | 1.0.0b03 | 1.0.0b04 | 1.0.0b05 | 1.0.0b06 | 1.0.0b07 | 1.0.0b08 | 1.0.0b09 | 1.0.0b10 | 1.0.0b11 | 1.0.0b12 | 1.0.0b13 |

延伸相關外掛(你可能也想知道)

  • FULL – Cliente 》一旦您的網站已整合至 FULL 控制面板,這個外掛程式就會自動安裝在連接的 WordPress 網站上。, FULL – Customers 外掛程式旨在自動化購買外掛程式和授權的安...。
  • Advanced Cron Manager – debug & control 》使用 Advanced Cron 管理器,您可以管理 WP Cron 事件:, , 查看所有已註冊的事件, 搜索事件, 手動執行任何事件, 新增事件, 暫停事件, 刪除(取消排程)事件,...。
  • Transients Manager 》簡單管理快取資料, 這是一個開發者工具,提供使用者介面來管理快取資料。, 您可以從「工具 → 快取資料」輕鬆地檢視、搜尋、編輯和刪除快取資料。, 工具列開關...。
  • Foxtool All-in-One: Contact chat button, Custom login, Media optimize images 》總結:Foxtool 是根據管理 WordPress 網站的真實需求而開發的產品。經過一段時間的發展,Foxtool 已成為網站管理員不可或缺的外掛程式。該外掛擁有許多值得注...。
  • Cron Logger 》你有沒有好奇過你的 WordPress 在 wp-cron.php 中在做什麼?現在你可以看到了。這個外掛可以紀錄每個排程。, 其他訊息。
  • Advanced Post List 》這個工具類似於文章列表建立器,可讓管理員對所要顯示的內容擁有最大的控制權。 開發時專為網頁設計師和開發人員而設計,使其成為一個高度可自定義的工具。 ...。
  • WP Site Verification tool 》這是一個簡單的工具,可以幫助您提供網站驗證碼和文件生成器,以供任何需要驗證網站的服務使用。, 通過在 head 區段中的註解 / meta 或通過文件 URL 進行驗證...。
  • Remove Admin Bar logo 》此外掛會移除 WordPress 後台工具列上的標誌,讓介面更簡潔。無需設定,啟用後立即生效。。
  • Kopa Framework 》「Kopa Framework」外掛是一種簡單的方式,讓您在 WordPress 網站上設置主題選項、側邊欄管理器、版面管理器和自訂版面功能。。
  • Ads.txt Admin 》Ads.txt Admin 是一個簡單的工具,讓您能夠從 WordPress 儀表板管理您的 ads.txt 檔案。, 現在,發行者需要一個 ads.txt 檔案 放在他們的網站上。發行者需要...。
  • Fancy Product Designer REST API 》這個外掛程式在 Fancy Product Designer 管理員上註冊所有所需的路徑和方法,因此您可以在 https://admin.fancyproductdesigner.com 上托管的管理員中管理您...。
  • Old Core Files 》通過檢查和刪除過時的 WordPress 核心文件來保護您的 WordPress 網站。, 當核心進行升級時,通常 WordPress 不再使用某些文件,並為其設置移除選項。, 在某些...。
  • Discourage Search Engines Notifier 》這個外掛程式只是在管理列上顯示通知,顯示禁止搜尋引擎功能的狀態。, 沒有設定,只需安裝外掛程式,您就會在管理列上方看到紅色或綠色眼睛圖示。您可以點擊...。
  • Asset Queue Manager 》這個工具讓你監控、取消佇列、重新佇列在你的網站上已佇列的腳本和樣式。它是為前端性能工程師而設計,他們希望查看並管理任何頁面上佇列的所有資產,並自行...。
  • WooCommerce Prune Orders 》此外掛可新增工具至 WP Admin > WooCommerce > 狀態 > 工具頁面,以將選定狀態及截止日期的所有訂單移至垃圾桶,以提升網站效能。, 特別感謝 Chris ...。

文章
Filter
Apply Filters
Mastodon