alesanchezr/wpas-wordpress-dash 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

alesanchezr/wpas-wordpress-dash

Composer 安装命令:

composer require alesanchezr/wpas-wordpress-dash

包简介

WordPress development on steroids

README 文档

README

Are you a WordPress developer? Then you are probably struggling with the same stuff that I use too truggle every day.

  1. MVC Pattern implementation (Model-View-Controller) in WordPress.
  2. Create API's with WordPress very fast.

Installation

  1. Require the library with composer (NOTE: You must be in your Wordpress directory before running this command. The installer will attempt to create your theme in ./wp-content/<your_theme_directory_name> )
$ composer require alesanchezr/wpas-wordpress-dash:dev-master
  1. Create a new theme using the installation script. Or select an already created theme (it will try to create the folder structure automatically)
$ php vendor/alesanchezr/wpas-wordpress-dash/run.php <your_theme_directory_name>
  1. Update the WPASController according to your needs in functions.php
use \WPAS\Controller\WPASController;
$controller = new WPASController([
        //Here you specify the path to your consollers folder
        'namespace' => 'php\\Controllers\\'
    ]);

Note: This library expects your theme to load the vendor/autoload.php file in your functions.php. A good way of doing that is:

/**
* 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";

If you are working with Flywheel hosting (and/or Flywheel Local), you will need to require the path in the following way:

if(!strpos($_SERVER['SERVER_NAME'], '.local')){
  require 'vendor/autoload.php';
}else{
  require ABSPATH . 'vendor/autoload.php';
}

This is due to the fact that their folder structure separates your content and plugins from the root Wordpress install after you push your site live.

Working with the MVC Pattern

The Models (Custom Types)

Instanciate the PostTypeManager:

    $typeManager = new \WPAS\Types\PostTypesManager([
        'namespace' => '\php\Types\\' \\this will be the path to your models folder
    ]);

Define your type in functions.php

    //You can react a new custom post type and specify his class
    $typeManager->newType(['type' => 'your_type_slug', 'class' => 'AnyPostTypeModelClass'])->register();

Define your type class in the types folder:

    namespace php\Types;

    class AnyPostTypeModelClass extends \WPAS\Types\BasePostType{
    
        //any method here
    }

Note: you HAVE to extend from the BasePostType class, that is not optional.

Continue reading about the models

The Controllers

Create your Controller classes and bind them to your views, pages, categories, posts, etc.

//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' ]);  

Our Course.php controller class will look like this:

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
    }
    
}

Continue reading about implementing MVC on your wordpress

Debugging

On you wo-config.php file add the following constant:

define('WP_DEBUG_CONTEXT', true);

It will add a top bar with the current template being used.

Upcomming Experimental Features (Not Stable)

  1. Add WordPress roles programatically.
  2. Restrict Role Access to particular pages, posts, categories, etc.
  3. Create and manage all your custom post types in just a few lines of code.
  4. Hit 100% on the Google Page Speed test.
  5. Messaging notification system for the WordPress admin user, using the WordPress standards.
  6. Create new Visual Composer components for your theme in just 5 lines fo code.
  7. Extend Gravity Forms functionality.

Author

Alejandro Sanchez

Repository website: https://github.com/alesanchezr/wpas-wordpress-dash

About me: alesanchezr.com

alesanchezr/wpas-wordpress-dash 适用场景与选型建议

alesanchezr/wpas-wordpress-dash 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 559 次下载、GitHub Stars 达 17, 最近一次更新时间为 2017 年 08 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 alesanchezr/wpas-wordpress-dash 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 559
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 17
  • 点击次数: 15
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 17
  • Watchers: 4
  • Forks: 9
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-08-11