Download the PHP package gebruederheitz/wp-easy-customizer without Composer
On this page you can find all versions of the php package gebruederheitz/wp-easy-customizer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gebruederheitz/wp-easy-customizer
More information about gebruederheitz/wp-easy-customizer
Files in gebruederheitz/wp-easy-customizer
Package wp-easy-customizer
Short Description A simplified, object-oriented interface for the Wordpress Customizer.
License GPL-3.0-only
Informations about the package wp-easy-customizer
Wordpress Easy Customizer
A simplified, object-oriented interface for the Wordpress Customizer.
Installation
via composer:
Make sure you have Composer autoload or an alternative class loader present.
Usage
For information on migrating from v1.x or v2.x see UPGRADING.md
You will need at least one CustomizerPanel
object to start with, optionally
passing a label (which defaults to "Theme Settings"). Then you can start adding
sections to your new panel.
Adding Sections to a panel
A section is sub-panel or sub-menu which contains the actual settings. There are
three basic ways to add sections to a panel. Which one you use is mostly a
matter of taste and code organisation. The main difference is that sections
added via the filter hook (variants (a) & (c), using $panel->addNewSection()
or
$section->setPanel()
) are added to the rendered panel after the ones
directly added (variant (b), using $panel->addSections()
). So if you require
a specific order of sections, you'll need to make certain these are registered
through the same mechanism.
(a) Directly from the panel using the automatic filter hook
This allows for a very compact Customizer setup and is particularly useful if
you only have a handful of fairly standard settings. The disadvantage is that
you can not use any custom section classes, as addNewSection()
will always
instantiate a new vanilla CustomizerSection
. And since we don't actually
receive the created section object, we have to add all settings right away.
(b) Instance for instance - directly with objects
(c) Instance for instance – indirectly via automatic hooks
In all these examples, we've added our settings right when constructing the sections. If we need some advanced logic, they can be added separately:
Defining Settings and adding them to a section
Now you will have to define your settings. Each setting is a class implementing
CustomizerSetting
. You can extend BasicCustomizerSetting
for convenience:
BasicCustomizerSettings are singleton objects, so instead of constructing them
you retrieve an instance with the static get()
method:
Retrieving the value
Settings: Advanced
You can do more with settings than the basic example above. Here are some more detailed usages:
Some of these examples can lead to a lot of repetition. A URL input is always
going to have the type url
and should ideally always have a sanitizer
sanitize_url
. For these cases, some specialized input classes are available
at Gebruederheitz\Wordpress\Customizer\InputTypes
:
Customizing which panels are removed
By default, CustomizerSettings
"cleans up" the Customizer, removing some
panels that are rarely used. You can use a filter hook to control which of the
default panels are removed:
Using Custom Controls
You can use custom controls if they extend the default WP_Customize_Control
by returning the FQCN from CustomizerSetting::getInputType()
:
Using the Separator field
The separator custom field allows inserting static separations between settings
in the shape of a <hr>
.
Optionally you can specify a label that will render an <h2>
underneath the
horizontal rule. The easiest way is to use the SeparatorSetting
class:
Development
Dependencies
- asdf tool version manager
- nodeJS LTS (v18.x) via asdf
- PHP >= 7.4 (via asdf)
- Composer 2.x (via asdf)
- Nice to have: GNU Make (or drop-in alternative)