szepeviktor/sentencepress

WordPress 开发中日常任务的面向对象工具包。

v0.2.0 2023-06-17 04:59 UTC

This package is auto-updated.

Last update: 2024-09-16 06:04:20 UTC


README

Build Status Packagist PHPStan

以下 工具 推荐在拥有完全控制开发环境和安装环境的代理型项目中使用。

安装

composer require szepeviktor/sentencepress

查看 WordPress 网站生命周期 以了解如何使用 WordPress。

示例

// Instead of wp_enqueue_script('main-js', get_template_directory_uri() . '/assets/js/main.js', [], '8.44', true)
$mainJs = new Script(get_template_directory_uri() . '/assets/js/main.js');
$mainJs
    ->setHandle('main-js')
    ->setVer('8.44')
    ->moveToFooter()
    ->enqueue();
// Instead of add_action('plugins_loaded', [$this, 'init'], 0, 20);
class Plugin
{
    use SzepeViktor\SentencePress\HookAnnotation;
    public function __construct()
    {
        $this->hookMethods();
    }

    /**
     * @hook plugins_loaded 20
     */
    public function init(): void
    {
        doSomething();
    }
}
// Instead of require __DIR__ . '/inc/template-functions.php';
// template-functions.php will be loaded and pingbackHeader called when wp_head hook is fired
class Template
{
    use SzepeViktor\SentencePress\HookProxy;
    public function __construct()
    {
        $this->lazyHookFunction(
            'wp_head',
            __NAMESPACE__ . '\\TemplateFunction\\pingbackHeader',
            10,
            0,
            __DIR__ . '/inc/template-functions.php'
        );
    }
}