sau / wp-framework

快速开发插件和模板的框架

dev-master 2019-02-08 09:38 UTC

This package is auto-updated.

Last update: 2024-09-08 22:52:47 UTC


README

WP中用于开发插件或模板的小型框架

基于使用Symfony框架(包)

安装

框架可以在插件或模板中安装

首先安装包

composer require sau/wp-framework

插件安装

在框架的基本文件中添加此代码

use Sau\WP\Framework\Install\Install;
use Sau\WP\Framework\Install\Remove;

include_once __DIR__.'/vendor/autoload.php';

register_activation_hook (__FILE__, function(){
    Install::install(__DIR__);
});
register_deactivation_hook (__FILE__, function(){
    Remove::deactivate(__DIR__);
});

主题安装

在框架的function.php文件中添加此代码

use Sau\WP\Framework\Install\Install;
use Sau\WP\Framework\Install\Remove;

include_once __DIR__.'/vendor/autoload.php';

add_action('after_switch_theme', function(){
    Install::install(__DIR__);
});
add_action('switch_theme', function(){
    Remove::deactivate(__DIR__);
});

安装后

安装并激活插件/主题后,在项目中您可以看到基础设施

开始编码...

扩展

基础扩展是

如果使用基础基础设施,请将其用作symfony flex应用程序

操作

如果需要扩展插件,请使用操作

do_action('before_boot_'.$name, $kernel); - 在内核加载之前

do_action('after_boot_'.$name, $kernel); - 获取响应对象后(加载内核)

do_action('response_'.$name, $response); - 获取响应对象后。用于在框架中修改响应

do_action('wp_response_'.$name, $response); - 在创建WP响应后(如果未找到路由)

!!! 内核在操作 after_setup_theme 的优先级99中加载。

在WP模板中使用

如果需要在您的代码中使用内核

global $sau_kernels;
//___name___ its name plugin/template 
$sau_kernels[ '___name___' ]->getContainer()
                           ->get('twig')
                           ->display('index.html.twig');