codemascot/metabox

这是一个Composer库包,旨在简化WordPress中创建metabox的过程。

1.0.1 2018-11-17 13:09 UTC

This package is not auto-updated.

Last update: 2024-09-23 08:41:22 UTC


README

这是一个Composer库包,用于增强WordPress metabox API的使用。

目录

编码风格和技术

  • 所有输入数据都经过转义和验证。
  • 作为Composer包开发。
  • YODA条件已检查。
  • 维护了右缩进,通常为80个字符。
  • 使用truefalsenull而不是TRUEFALSENULL
  • 缩进: 制表符已代替空格使用。
  • PHP Codesniffer已检查。
  • WordPress VIP编码标准基本遵循。

需求

  • WordPress >= 3.8.0(已测试)
  • PHP >= 5.6
  • Composer包管理器

安装

使用此包的最佳方式是通过Composer

$ composer require codemascot/metabox

使用方法

步骤 1

首先我们需要准备以下参数-

$prefix = 'codemascot_'; // Use any prefix you like to prefix the metabox name or id
$metabox_args = [
    [
        $prefix . '-section-title',
        __( 'Section Title', 'text-domain' ),
        'title',
        'required',
    ],
    [
        $prefix . '-checkbox',
        __( 'Input Checkbox', 'text-domain' ),
        'check',
        '',
        [
            'checkbox_key' => 'Checkbox Text',
        ],
    ],
    [
        $prefix . '-input',
        __( 'Input Text', 'text-domain' ),
        'input',
        'required',
    ],
    [
        $prefix . '-select',
        __( 'Select Dropdown', 'text-domain' ),
        'select',
        'required',
        [
            '-'     => '-',
            'red'   => 'Red',
            'blue'  => 'Blue',
            'green' => 'Green',
        ],
    ],
];
步骤 2

现在你需要像以下那样调用MetaBox类-

new \CodeMascot\MetaBox\MetaBox(
    'section-id', // Section DOM ID
    __( 'Section Name', 'text-domain' ), // Section Name
     'post', // Post Type
     $metabox_args, // Arguments
     'advanced', // Context
     'high' // Priority
);
数据清理与验证

你可以使用codeamscot_metabox_api_data_filter通过此包清理和验证输入。它有两个参数,一个是$data,另一个是$field_id

add_filter(
    'codemascot_metabox_api_data_filter',
    'codemascot_metabox_api_data_filter',
    10,
    2
);

/**
 * @param        $data
 * @param string $field_id
 */
function codemascot_metabox_api_data_filter( $data, $field_id ) {
    // Validate or Sanitize Data Here.
}

由Khan制作

我是Khan,又称CodeMascot,一名专业的前端开发人员。我制作了这个包供个人使用,也欢迎你将其用于你的项目。

许可证

版权所有(c)2018 Khan M Rashedun-Naby,CodeMascot

好消息,这个库对每个人都是免费的!因为它是在MIT许可证下发布的,你可以在个人或商业网站上免费使用它。

贡献

欢迎所有反馈/错误报告/拉取请求。