Download the PHP package gebruederheitz/wp-easy-post-options without Composer
On this page you can find all versions of the php package gebruederheitz/wp-easy-post-options. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gebruederheitz/wp-easy-post-options
More information about gebruederheitz/wp-easy-post-options
Files in gebruederheitz/wp-easy-post-options
Package wp-easy-post-options
Short Description Extend posts with meta fields / options using a simple, modern interface.
License GPL-3.0-only
Informations about the package wp-easy-post-options
Wordpress Easy Post Options
Extend posts with meta fields / options using a simple, modern interface.
Installation
via composer:
Make sure you have Composer autoload or an alternative class loader present.
Usage
This package offers a bunch of interfaces, abstract classes and handler classes that simplifies adding "post meta" to posts or pages in Wordpress.
To enable the basic functionality, you'll have to load the initializer class, either in your functions.php or somewhere in a controller class or container module:
Creating meta boxes
Each custom option will need to be added to a meta box (which can contain
multiple options). To easily create a meta box, use the AbstractMetabox
class:
Restricting the post type(s) a metabox is displayed on
By default, meta boxes are shown on all posts of the types 'post' and 'page'.
You can customize this behaviour by declaring a static class attribute $postTypes
:
Changing where a meta box is shown
Similarly, you can customize the meta box's location by providing the static
class attribute $context
, set to any of side
, normal
or advanced
(blame
Wordpress, not me!):
Adding post options
Once your meta box is created, you can add settings to it. The quickest way is
by extending AbstractPageOrPostOption
:
Then, make sure you instantiate that class somewhere (usually this will be your
functions.php
), along with the meta box the input should live in:
For a basic text input field that's it, your're done. You can then retrieve the
value by calling the static getValue()
method on your custom class:
Displaying a boolean option using a checkbox field
The library offers another little helper for displaying simple checkbox fields:
Modifying the inputs and value parsing
In order to customize the form controls rendered into the metabox, you can
override the render()
method of the base class.
Note: wp-easy-post-options and adretto-extension-simple-post-options
This package is developed and maintained in parallel with sillynet/adretto-extension-simple-post-options, which offers the same basic functionality, but is written to embed itself into the Adretto microframework (a work in progress). In the future it is likely that one of these two packages will reuse most of the code from the other one, in order to avoid large-scale code duplication. This will however most likely have no effect on the public API of either project.
Development
Dependencies
- PHP >= 7.3
- Composer 2.x
- NVM and nodeJS LTS (v16.x)
- Nice to have: GNU Make (or drop-in alternative)
All versions of wp-easy-post-options with dependencies
gebruederheitz/wp-meta-fields Version ^1.3
gebruederheitz/simple-singleton Version ^1.0