1. Go to this page and download the library: Download tmf/wp-metabox-helper library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tmf / wp-metabox-helper example snippets
// load the vendors via composer autoload
if (file_exists( __DIR__ . '/vendor/autoload.php')) {
Metabox,
Tmf\Wordpress\Service\Metabox\Item\InputItem,
Tmf\Wordpress\Service\Metabox\Item\DropdownItem,
Tmf\Wordpress\Service\Metabox\Item\EditorItem;
// create the service container
$services = new Pimple\Container();
// register the metabox helper with this service provider. the service is registered with the 'metaboxes' key
$services->register(new MetaboxServiceProvider());
add_action('admin_init', function () use ($services) {
// create a metabox for 'post' post types
$services['metaboxes']['foo'] = new Metabox('Foo', ['post'], 'normal', 'high');
// add item: the key is the post meta key
$services['metaboxes']['foo']['text'] = new InputItem(['label' => 'Metatext', 'description' => 'Some description']);
$services['metaboxes']['foo']['dropdown'] = new DropdownItem([['label' => 'Foo', 'value'=>'foo'], ['label' => 'Bar', 'value'=>'bar']]);
$services['metaboxes']['foo']['editor'] = new EditorItem();
});
add_action('add_meta_boxes', function() use ($services) {
$this->getContainer()->extend('metaboxes.twig.loader', function($loader, $services){
/** @var Twig_Loader_Chain $loader */
$loader->addLoader(new Twig_Loader_Filesystem(get_stylesheet_directory() . '/templates/items'));
return $loader;
});
}, 95); // additional twig loaders should be registered between priority 90 and 100
bash
cd your-plugin-directory
# install composer phar
curl -sS https://getcomposer.org/installer | php
# create a basic composer.json
./composer.phar init
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.