2017 © Pedro Peláez
 

library magic-meta-box

Helper class to generate WordPress MetaBoxes.

image

r4c00n/magic-meta-box

Helper class to generate WordPress MetaBoxes.

  • Wednesday, November 18, 2015
  • by gloeckchen
  • Repository
  • 2 Watchers
  • 1 Stars
  • 225 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 4 Versions
  • 1 % Grown

The README.md

MagicMetaBox

Helper class to generate wordpress metaboxes, (*1)

Installation

If you're using composer, run:, (*2)

composer require r4c00n/magic-meta-box:*

Require composer autoload.php and add use MagicMetaBox\MagicMetaBox; to your plugins code., (*3)

Usage

Create a metabox

Create new instance of MagicMetaBox, (*4)

$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:, (*5)

$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:, (*6)

$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:, (*7)

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

Add a select input to your new metabox:, (*8)

$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., (*9)

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

The Versions

18/11 2015

dev-master

9999999-dev https://github.com/R4c00n/MagicMetaBox

Helper class to generate WordPress MetaBoxes.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by R4c00n

wordpress metabox

02/09 2015

v1.3

1.3.0.0 https://github.com/R4c00n/MagicMetaBox

Helper class to generate WordPress MetaBoxes.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by R4c00n

wordpress metabox

24/08 2015

v1.2

1.2.0.0 https://github.com/Gloeckchen/MagicMetaBox

Helper class to generate wordpress metaboxes.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Marcel Kempf

wordpress metabox

21/08 2015

v1.1

1.1.0.0 https://github.com/Gloeckchen/MagicMetaBox

Helper class to generate wordpress metaboxes.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Marcel Kempf

wordpress metabox