PHP code example of martijnvdb / wordpress-plugin-tools
1. Go to this page and download the library: Download martijnvdb/wordpress-plugin-tools 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/ */
martijnvdb / wordpress-plugin-tools example snippets
$custom_posttype = PostType::create('custom-posttype')
->setDescription('A very interesting description')
->setSlug('custom-slug')
->setIcon('dashicons-thumbs-up')
->setPublic()
->build();
$custom_field = CustomField::create('custom-field')
->setType('textarea')
->setLabel('page-custom-textarea');
$custom_metabox = MetaBox::create('custom-metabox')
->addPostType('page')
->addCustomField($custom_field)
->build();
$custom_posttype = PostType::create('custom-posttype')->build();
$first_metabox = MetaBox::create('first-metabox');
$second_metabox = MetaBox::create('second-metabox');
$third_metabox = MetaBox::create('third-metabox');
$custom_posttype = PostType::create('custom-posttype')
->addMetaBox($first_metabox) // Add a single MetaBox
->addMetaBoxes([$second_metabox, $third_metabox])// Or add multiple at once
->build();
$products_posttype = PostType::create('products')
->setLabel('name', 'Products') // Add a single label
// Or add multiple at once
->setLabels([
'singular_name' => 'Product',
'add_new_item' => 'Add new Product',
'add_new' => 'New Product',
'edit_item' => 'Edit Product',
])
->build();
$custom_posttype = PostType::create('custom-posttype')
->setDescription('A very interesting description')
->build();
$custom_posttype = PostType::create('custom-posttype')
->setPublic()
->build();
$custom_posttype = PostType::create('custom-posttype')
->setMenuPosition(8)
->build();
$custom_posttype = PostType::create('custom-posttype')
->setIcon('dashicons-thumbs-up')
->build();
$custom_posttype = PostType::create('custom-posttype')
->addSupport(['title', 'thumbnail', 'comments']) // Must be an array
->build();
$custom_posttype = PostType::create('custom-posttype')
->removeSupport(['editor']) // Must be an array
->build();
$custom_posttype = PostType::create('custom-posttype')
->setSlug('custom-slug')
->build();
$custom_posttype = PostType::create('custom-posttype')
->addBlockEditor()
->build();
$custom_posttype = PostType::create('custom-posttype')
// Some examples
->addOption('show_in_admin_bar', false)
->addOption('show_in_nav_menus', false)
->addOption('has_archive', true)
->build();
$customfield = CustomField::create('new-customfield')->build();
$new_customfield = CustomField::create('new-customfield')
->setType('textarea')
->build();
$new_customfield = CustomField::create('new-customfield')
->setLabel('New custom field')
->build();
$new_customfield = CustomField::create('new-customfield')
->setType('select') // Or 'radio'
->addOption('first-option', 'This is the first option')
->addOption('second-option', 'This is the second option')
// Or add multiple at once
->addOptions([
'third-option' => 'This is the third option',
'fourth-option' => 'This is the fourth option'
]);
->build();
$new_customfield = CustomField::create('new-customfield')
->setType('number')
->setMin(0)
->build();
$new_customfield = CustomField::create('new-customfield')
->setType('number')
->setMax(100)
->build();
$new_customfield = CustomField::create('new-customfield')
->setType('number')
->setStep(10)
->build();
$custom_metabox = MetaBox::create('custom-metabox')->build();
$custom_metabox = MetaBox::create('custom-metabox')
->setTitle('Metabox title')
->build();
$first_customfield = CustomField::create('first-customfield');
$second_customfield = CustomField::create('second-customfield');
$third_customfield = CustomField::create('third-customfield');
$custom_metabox = MetaBox::create('custom-metabox')
->addCustomField($first_customfield)
// Or add multiple at once
->addCustomFields([
$second_customfield,
$third_customfield,
])
->build();
$first_customfield = CustomField::create('first-customfield');
$second_customfield = CustomField::create('second-customfield');
$third_customfield = CustomField::create('third-customfield');
$custom_metabox = MetaBox::create('custom-metabox')
->addList('custom-list', [
$first_customfield,
$second_customfield,
$third_customfield
])
->build();
$custom_metabox = MetaBox::create('custom-metabox')
->addPostType('page')
// Or add multiple at once
->addPostTypes([
'custom-posttype',
'another-posttype',
])
->build();
$custom_metabox = MetaBox::create('custom-metabox')
->setText('new', 'Nieuwe lijst')
// Or customize multiple at once
->setTexts([
'new' => 'Nieuwe lijst',
'delete_confirm' => 'Weet u zeker dat u deze lijst wil verwijderen?'
])
->build();
$custom_settingspage = SettingsPage::create('custom-settingspage')->build();
$custom_settingspage = SettingsPage::create('custom-settingspage')
->setPageTitle('The page title')
->build();
$custom_settingspage = SettingsPage::create('custom-settingspage')
->setMenuTitle('Menu title')
->build();
$custom_settingspage = SettingsPage::create('custom-settingspage')
->setSlug('settingspage-slug')
->build();
$custom_settingspage = SettingsPage::create('custom-settingspage')
->setIcon('dashicons-thumbs-up')
->build();
$first_customfield = CustomField::create('first-customfield');
$second_customfield = CustomField::create('second-customfield');
$third_customfield = CustomField::create('third-customfield');
$custom_settingspage = SettingsPage::create('custom-settingspage')
->addCustomField($first_customfield)
// Or add multiple at once
->addCustomFields([
$second_customfield,
$third_customfield,
])
->build();