raytechhosting/wpabstractclasses

此包提供用于WordPress的面向对象的抽象包装PHP类,有助于加速开发。

0.11.7 2024-07-22 19:44 UTC

README

此包提供用于WordPress的面向对象的抽象包装PHP类,有助于加速开发。

安装

使用composer安装是此包支持的安装方法。

  composer require raytechhosting/wpabstractclasses

用法

首先在主题或插件文件夹的根目录下创建一个'.rtabstract.yml'文件。以下是如何设置此文件的示例。

implementation_type: theme
theme_name: theme-name
theme_version: 1.0.0
post_types:
  portfolio:
    tags: true
    categories: true
    supports: 
      - title
      - editor
      - thumbnail
    meta_boxes:
      meta:
        columns: 3
        label: Meta
        fields:
          name:
            type: text
            label: Name
          test:
            type: repeater
            label: Tester
            attr:
              fields:
                tester:
                  type: number
                  label: Tester

然后将以下代码片段添加到您的functions.php文件中。

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

use RayTech\WPAbstractClasses\Factory\PostTypeFactory;
use RayTech\WPAbstractClasses\Utilities\Configuration;

// Read the configuration file.
$config = new Configuration();

// Creates the post types.
if ( isset( $config->data['post_types'] ) ) {
  foreach ( $config->data['post_types'] as $conventions_post_type => $args ) {
    PostTypeFactory::create( $conventions_post_type, $args );
  }
}