alesanchezr / wpas-wordpress-dash
WordPress 开发加速器
1.3.4
2020-11-03 05:01 UTC
Requires
- php: >=5.5.9
- jjgrainger/posttypes: ^2.0
- matthiasmullie/minify: ^1.3
- monolog/monolog: ^1.23
- respect/validation: ^1.1
README
你是 WordPress 开发者吗?那么你可能正在为和我每天一样的事情挣扎。
- WordPress 中的 MVC 模式实现(模型-视图-控制器)。
- 使用 WordPress 快速创建 API。
安装
- 使用 composer 需要库(注意:运行此命令之前,您必须在您的 WordPress 目录中。安装程序将尝试在 ./wp-content/<your_theme_directory_name> 中创建您的主题)
$ composer require alesanchezr/wpas-wordpress-dash:dev-master
- 使用安装脚本创建一个新主题。或者选择一个已经创建的主题(它将尝试自动创建文件夹结构)
$ php vendor/alesanchezr/wpas-wordpress-dash/run.php <your_theme_directory_name>
- 根据您的需求在 functions.php 中更新 WPASController
use \WPAS\Controller\WPASController; $controller = new WPASController([ //Here you specify the path to your consollers folder 'namespace' => 'php\\Controllers\\' ]);
注意:此库期望您的主题在 functions.php 中加载 vendor/autoload.php 文件。一种好的方法是
/** * Autoload for PHP Composer and definition of the ABSPATH */ //defining the absolute path for the wordpress instalation. if ( !defined('ABSPATH') ) define('ABSPATH', dirname(__FILE__) . '/'); //including composer autoload require ABSPATH."vendor/autoload.php";
如果您正在使用 Flywheel 托管(以及/或 Flywheel Local),您需要以下方式要求路径
if(!strpos($_SERVER['SERVER_NAME'], '.local')){ require 'vendor/autoload.php'; }else{ require ABSPATH . 'vendor/autoload.php'; }
这是因为他们在推送网站上线后,将内容、插件与根 WordPress 安装分开的文件夹结构。
MVC 模式的工作方式
模型(自定义类型)
实例化 PostTypeManager
$typeManager = new \WPAS\Types\PostTypesManager([ 'namespace' => '\php\Types\\' \\this will be the path to your models folder ]);
在 functions.php 中定义您的类型
//You can react a new custom post type and specify his class $typeManager->newType(['type' => 'your_type_slug', 'class' => 'AnyPostTypeModelClass'])->register();
在 types 文件夹中定义您的类型类
namespace php\Types; class AnyPostTypeModelClass extends \WPAS\Types\BasePostType{ //any method here }
注意:你必须从 BasePostType 类扩展,这不是可选的。
控制器
创建您的 Controller 类,并将它们绑定到视图、页面、分类、帖子等。
//Here we are saying that we have a class Course.php with a function getCourseInfo that fetches the data needed to render any custom post tipe course $controller->route([ 'slug' => 'Single:course', 'controller' => 'Course' ]);
我们的 Course.php 控制器类将如下所示
namespace php\Controllers; class Course{ public function renderCourse(){ $args = []; $args['course'] = WP_Query(['post_type' => 'course', 'param2' => 'value2', ...); return $args; //Always return an Array type } }
调试
在 wo-config.php 文件中添加以下常量
define('WP_DEBUG_CONTEXT', true);
它将添加一个顶部的当前正在使用的模板栏。
即将推出的实验性功能(不稳定)
- 以编程方式添加 WordPress 角色。
- 限制角色对特定页面、帖子、分类等的访问。
- 仅用几行代码创建和管理所有自定义帖子类型。
- 在 Google Page Speed 测试 中达到 100%。
- 使用 WordPress 标准的 WordPress 管理用户的消息通知系统。
- 仅用 5 行代码为您的主题创建新的 Visual Composer 组件。
- 扩展 Gravity Forms 功能。
作者
Alejandro Sanchez
仓库网站: https://github.com/alesanchezr/wpas-wordpress-dash
关于我: alesanchezr.com