WordPress内容框架


README

CI Status License: GPL v2+ PHP: >=5.6 WordPress: >=3.9.3

用于WordPress插件或主题开发的框架。

目录

详细信息

要求

  • PHP 5.6以上
  • WordPress 3.9.3以上

步骤

从插件中利用

  1. 创建插件文件夹 在wp-content/plugins文件夹中创建插件文件夹,例如:wp-content/plugins/example

  2. 创建插件文件 在创建的插件文件夹中创建适当的PHP文件(例如:autoload.php) 标准插件信息 作为参考输入插件信息

  3. 使用composer安装此库。在创建的插件文件夹中执行以下命令。 composer require wp-content-framework/core

  4. 使用库 在创建的插件文件中添加使用库的描述。插件文件大致如下。

<?php
/**
 * Plugin Name: example
 * Plugin URI:
 * Description: Plugin Description
 * Author: example
 * Version: 0.0.0
 * Author URI: http://example.com/
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( defined( 'EXAMPLE_PLUGIN' ) ) {
	return;
}

define( 'EXAMPLE_PLUGIN', 'Example_Plugin' );

@require_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';

WP_Framework::get_instance( EXAMPLE_PLUGIN, __FILE__ );

最终的插件配置如下。

example
    |
    - autoload.php
    |
    - functions.php
    |
    - assets
    |
    - configs
    |
    - languages
    |
    - src
       |
        - classes
       |     |
       |     - controllers
       |     |      |
       |     |      - admin
       |     |      |
       |     |      - api
       |     |
       |     - models
       |     |
       |     - tests
       |
       - views
           |
           - admin
               |
               - help

从主题中利用

  1. 创建主题文件夹 在wp-content/themes文件夹中创建主题文件夹,例如:wp-content/themes/example

  2. 创建主题CSS 创建主题文件夹中的style.css并参考主题样式表 输入主题信息

  3. 使用composer安装此库。在创建的插件文件夹中执行以下命令。 composer require wp-content-framework/core

  4. 使用库 在主题文件夹中创建functions.php并添加使用库的描述。functions.php大致如下。

<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( defined( 'EXAMPLE_THEME' ) ) {
	return;
}

define( 'EXAMPLE_THEME', 'Example_Theme' );

@require_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';

WP_Framework::get_instance( EXAMPLE_THEME, __FILE__ );

最终的主题配置如下。

example
    |
    - style.css
    |
    - functions.php
    |
    - assets
    |
    - configs
    |
    - languages
    |
    - src
    |  |
    |   - classes
    |  |     |
    |  |     - controllers
    |  |     |      |
    |  |     |      - admin
    |  |     |      |
    |  |     |      - api
    |  |     |
    |  |     - models
    |  |     |
    |  |     - tests
    |  |
    |  - views
    |      |
    |      - admin
    |          |
    |          - help
    |
    - header.php
    - footer.php
    - index.php
    - searchform.php
    - sidebar.php
    ...

在多个插件和主题中使用此库的情况下,包括模块在内的最新版本将自动使用。

模块

根据需要添加模块。某些模块将根据依赖关系自动安装。

  • core 提供核心功能,例如最新模块的加载功能。
    • 依赖模块
      • common
      • cache
  • common 提供共同使用的功能。
  • cache 提供缓存功能。
    • 相关模块
      • cron
  • db 提供处理数据库的功能。
  • presenter 提供绘制功能。
  • view 提供公共的绘制模板。
    • 依赖模块
      • presenter
  • cron 提供cron功能。
  • controller 提供控制器功能。
    • 依赖模块
      • presenter
  • admin 提供有关管理界面的功能。
    • 依赖模块
      • controller
      • view
  • api 提供API相关的功能。
    • 依赖模块
      • controller
  • update 提供显示更新信息的功能。
    • 依赖模块
      • presenter
  • update_check 提供在官方目录以外进行更新的功能。
  • upgrade 提供升级相关的功能。
    • 相关模块
      • log
  • mail 提供邮件发送功能。
    • 依赖模块
      • presenter
  • log 提供日志功能。
    • 依赖模块
      • db
      • cron
      • admin
    • 相关模块
      • mail
  • post 提供处理帖子功能。
  • device 提供了用户代理判定等功能。
  • editor 提供与编辑器相关的功能。
  • social 提供社交登录功能。
    • 依赖模块
      • session
  • session 提供会话功能。
  • custom_post 提供与自定义投稿类型相关的功能。
    • 依赖模块
      • db
      • session
      • admin
      • api
  • test 提供测试功能。
    • 依赖模块
      • admin

添加界面

admin

添加API

api

添加filter

今后将添加文档

添加cron

cron

添加自定义帖子类型

custom_post

添加测试

test

配置

设置

  • configs/setting.php

设置示例:

// priority => 詳細
'10' => array(

    // 設定グループ => 詳細
    'Performance' => array(

        // priority => 詳細
        '10' => array(

            // 設定名 => 詳細
            'minify_js'  => array(
                // 説明
                'label'   => 'Whether to minify js which generated by this plugin',
                // タイプ (bool or int or float or string)
                'type'    => 'bool', // [default = string]
                // デフォルト値
                'default' => true,
            ),
            'minify_css' => array(
                'label'   => 'Whether to minify css which generated by this plugin',
                'type'    => 'bool',
                'default' => true,
            ),
        ),
    ),
),

可以在设置页面中进行设置。在程序中使用时,如下所示。

$this->apply_filters( 'minify_js' ) // true or false

if ( $this->apply_filters( 'minify_js' ) ) {
    // ...
}

过滤器

  • configs/filter.php 今后将添加

数据库

  • configs/db.php db

权限

  • configs/capability.php 今后将添加

覆盖默认行为

今后将添加

基本设置

  • configs/config.php
  • configs/settings.php

示例插件

作者