定制 typisttech/wp-contained-hook 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

typisttech/wp-contained-hook

最新稳定版本:0.3.1

Composer 安装命令:

composer require typisttech/wp-contained-hook

包简介

Using PSR-11 container implementation in WordPress plugins, themes and packages during WordPress action/filter callbacks.

README 文档

README

Packagist Packagist PHP from Packagist CircleCI codecov GitHub GitHub Sponsor Sponsor via PayPal Hire Typist Tech Twitter Follow @TangRufus

Goals

Using PSR-11 container implementation in WordPress plugins, themes and packages during WordPress action/filter callbacks.

Dependencies are usually lazy loaded(depends on your container implementation), not instantiated until the first time they are used (during WordPress action/filter callbacks).

Installation

Installation should be done via composer, details of how to install composer can be found at https://getcomposer.org/.

You need a psr/container-implementation package as well. This readme uses league/container as an example (any psr/container-implementation works similarly).

# league/container is an example, any psr/container-implementation package works
$ composer require typisttech/wp-contained-hook league/container

Usage

use League\Container\Container;
use TypistTech\WPContainedHook\Hooks\Action;
use TypistTech\WPContainedHook\Hooks\Filter;
use TypistTech\WPContainedHook\Loader;

$container = new Container;

// Configure the container.
// This depends on your `psr/container-implementation`.
$container->add('bar', Bar::class);
$container->add('foo', Foo::class);

// Action.
$action = new Action('bar', 'admin_init', 'doSomething');

// Filter.
$filter = new Filter('foo', 'the_content', 'filterSomething');

// Add to loader.
$loader = new Loader($container);
$loader->add($action, $filter);

// Add to WordPress.
$loader->run();

In plain WordPress, the above is similar to:

$bar = new Bar();
add_action('admin_init', [$bar, 'doSomething'])

$foo = new Foo();
add_filter('the_content', [$foo, 'filterSomething'])

In WordPress plus container, the above is similar to:

add_action('admin_init', function ($arg) use ($container): void {
  $bar = $container->get('bar');
  $bar->doSomething($arg);
})

add_filter('the_content', function ($arg) use ($container) {
  $foo = $container->get('foo');
  return $foo->filterSomething($arg);
})

API

TypistTech\WPContainedHook\Loader

Register all actions and filters for the plugin/package/theme.

Maintain a list of all hooks that are registered throughout the plugin, and register them with the WordPress API. Call the run function to execute the list of actions and filters.

Loader Constructor

  • @param Psr\Container\ContainerInterface $container The container.

Example:

$container = new Container;
$loader = new Loader($container);

Loader::add(HookInterface ...$hooks)

Add new hooks to the collection to be registered with WordPress.

  • @param HookInterface|HookInterface[] ...$hooks Hooks to be registered.

Example:

// Action.
$action = new Action(SomeClass::class, 'plugin_loaded', 'doSomething');

// Filter.
$filter = new Filter(SomeClass::class, 'the_content', 'filterSomething');

// Add to loader
$loader->add($action, $filter);

Loader::run()

Register the hooks to the container and WordPress.

Example:

$loader->run();

Hooks: Action and Filter

Holds necessary information for an action or a filter.

Both Action and Filter are subclasses of AbstractHook and implements HookInterface.

AbstractHook Constructor.

  • @param string $hook The name of the WordPress hook that is being registered.
  • @param string $classIdentifier Identifier of the entry to look for from container.
  • @param string $callbackMethod The callback method name.
  • @param int|null $priority Optional.The priority at which the function should be fired. Default is 10.
  • @param int|null $acceptedArgs Optional. The number of arguments that should be passed to the $callback. Default is 1.

Example:

$action = new Action('bar', 'admin_init', 'doSomething', 20, 2);

$filter = new Filter('foo', 'the_content', 'filterSomething', 20, 2);

FAQs

Will you add support for older PHP versions?

Never! This plugin will only work on actively supported PHP versions.

Don't use it on end of life or security fixes only PHP versions.

It looks awesome. Where can I find some more goodies like this?

Where can I give ⭐⭐⭐⭐⭐ reviews?

Thanks! Glad you like it. It's important to let my know somebody is using this project. Since this is not hosted on wordpress.org, please consider:

Sponsoring ❤️

Love WP Contained Hook? Help me maintain it, a sponsorship here can help with it.

GitHub Sponsors Matching Fund

Do you know GitHub is going to match your sponsorship?

Sponsor now via GitHub to double your greatness.

Why don't you hire me?

Ready to take freelance WordPress jobs. Contact me via the contact form here or, via email info@typist.tech

Want to help in other way? Want to be a sponsor?

Contact: Tang Rufus

Running the Tests

Run the tests:

$ composer test
$ composer style:check

Feedback

Please provide feedback! We want to make this library useful in as many projects as possible. Please submit an issue and point out what you do and don't like, or fork the project and make suggestions. No issue is too small.

Change log

Please see CHANGELOG for more information on what has changed recently.

Security

If you discover any security related issues, please email wp-contained-hook@typist.tech instead of using the issue tracker.

Credits

WP Contained Hook is a Typist Tech project and maintained by Tang Rufus, freelance developer for hire.

Full list of contributors can be found here.

License

The MIT License (MIT). Please see License File for more information.

typisttech/wp-contained-hook 适用场景与选型建议

typisttech/wp-contained-hook 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 25.99k 次下载、GitHub Stars 达 27, 最近一次更新时间为 2017 年 04 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「container」 「dependency」 「wordpress」 「di」 「filter」 「injection」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 typisttech/wp-contained-hook 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 typisttech/wp-contained-hook 我们能提供哪些服务?
定制开发 / 二次开发

基于 typisttech/wp-contained-hook 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 25.99k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 29
  • 点击次数: 28
  • 依赖项目数: 3
  • 推荐数: 6

GitHub 信息

  • Stars: 27
  • Watchers: 4
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-04-01