承接 r4c00n/magic-meta-box 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

r4c00n/magic-meta-box

最新稳定版本:v1.3

Composer 安装命令:

composer require r4c00n/magic-meta-box

包简介

Helper class to generate WordPress MetaBoxes.

README 文档

README

Helper class to generate wordpress metaboxes

Installation

If you're using composer, run:

composer require r4c00n/magic-meta-box:*

Require composer autoload.php and add use MagicMetaBox\MagicMetaBox; to your plugins code.

Usage

Create a metabox

Create new instance of MagicMetaBox

$myMetaBox = new MagicMetaBox(
    'my-metabox', // unique metabox id
    'My MetaBox title', // Metabox title
    array( 'post', 'page' ), // Metabox screens
    'prefix_' // Meta prefix,
    'side', // Metabox context (optional)
    'high', // Metabox priority (optional)
    true // Serialize values under the metabox id
);

Add input fields

Add a text input field to your new metabox:

$myMetaBox->addTextField(
    'my-text-field', // Input name
    array( // Additional attributes
        'class' => 'input-field'
    ),
    'My text field', // Associated label text
    'I am a default', // Default value
);

Add a textarea to your new metabox:

$myMetaBox->addTextAreaField(
    'my-text-arae', // Textarea name
    array(), // Additional attributes
    'My text area', // Associated label text
    'I am a default', // Default value
);

Add a checkbox to your new metabox:

$myMetaBox->addCheckboxField(
    'my-checkbox', // Checkbox name
    array(), // Additional attributes
    'My checkbox' // Associated label text
);

Add a select input to your new metabox:

$myMetaBox->addSelectField(
    'my-select', // Select name
    array( // Options
      0 => 'Yes',
      1 => 'No'
    ),
    true, // Multiple
    array( // Additional attributes
        'size' => 5
    ),
    'My select' // Associated label text
);

Access meta data

Access meta data via prefix + metabox id. Data is stored as array with input names as keys.

$meta = get_post_meta( $postId, 'prefix_my-metabox', true );
echo $meta['my-text-field'];

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-09-02