j10o/whenthen
Composer 安装命令:
composer require j10o/whenthen
包简介
A drop-in package for wrapping WordPress' add_action and do_action(soon)
README 文档
README
WhenThen
A drop-in package for wrapping WordPress' add_action and do_action(soon) ![]()
A Glimpse
$wp_event = new \WhenThen\MiddleWare\Event(); $wp_event->when( $hook = array( 'name' => 'wp' ) )->then( function(){ echo '𝙷𝚎𝚕𝚕𝚘, 𝚆𝚘𝚛𝚍𝙿𝚛𝚎𝚜𝚜'; });
Basic usage
Via composer
Do composer require j10o/whenthen
Or locate your project's composer.json then add j10o/whenthen": "dev-main" in require property.
For example:
{ "require": { "j10o/whenthen": "dev-main" } }
In your plugin's main file include the vendor autoload.
// Require Composer's autoload file. require __DIR__ . '/vendor/autoload.php'; // Create new event object. $wp_event = new \WhenThen\MiddleWare\Event(); // Similar to add_action stuff with WordPress. $wp_loaded = array( 'name' => 'wp', 'priority' => 10, 'num_args' => 1 ); // Same here. $footer_loaded = array( 'name' => 'wp_footer', 'priority' => 10, ); // Closure function to call when something happen. $do_this_thing_1 = function($query_vars) { error_log( var_export( $query_vars, true ) ); }; // Another closure function to call when something happen. $do_this_thing_2 = function() { echo 'I am in footer.'; }; // Listen to the event. $wp_event->when( $wp_loaded )->then( $do_this_thing_1 ); // Another one. $wp_event->when( $footer_loaded )->then( $do_this_thing_2 );
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-only
- 更新时间: 2022-11-23