Skip to content

Customizer

Radoslav Georgiev edited this page Oct 21, 2018 · 4 revisions

Intro

Ultimate fields makes Adding fields to the Customizer a piece of cake. Multiple locations in the plugin can not only show their fields in a standard place (ex. a meta box for the Post Type location), but can also display those fields in the customizer.

The Customizer location allows you to add custom fields solely to the customizer without showing them anywhere else in the dashboard.

Usage through the Interface

To add fields to the customizer with the the Administration Interface, please follow these steps:

  1. If you are not on the "Add Container" screen already, locate the "Ultimate Fields" section in the administration area and click the "Add New" button on the top (next to the "Containers" title).
  2. Locate the "Locations" box.
  3. Click "Customizer" from the bottom row.
  4. Customize the settings for the customizer.

Usage through PHP

The customizer location in Ultimate Fields is handled by the Ultimate_Fields\Location\Customizer class. In order to use it, you can either create the new location object manually or let the container do it for you.

The constructor of the class looks like this:

public function __construct( $args = array() ) {

$args is an array, which allows you to set arguments without having to explicitly call the particular setter.

Manual creation

Create a new location by using the new keyword and assign it to the container through the add_location() method.

use Ultimate_Fields\Container;
use Ultimate_Fields\Location\Customizer;

$container = Container::create( 'theme-colors' );

// Create a new location and add definitions to it
$location = new Customizer();

// Once the location has been fully set up, add it to the container
$container->add_location( $location );

Automatic creation

You can also let the container create the location for you by providing the "customizer" string as the first parameter to add_location().

use Ultimate_Fields\Container;

Container::create( 'theme-colors' )
	->add_location( 'customizer' );

Data retrival

To retrieve the values of fields, associated with the Customizr location, $type parameter of all *_value functions should be "option".

Examples:

<?php
$background_color = get_option( 'background_color' );

Please read Adding fields to the Customizer to learn how to dynamically change values within the customizer preview without refresing the page.

Options

Priority

The priority setting for customizer locations allows you to use a number to indicate where in the customizer menu you want to show the new setting. The default priority is 150, which shows the new section around the middle of the menu.

In the UI,

a field for the priority will be displayed in the location's settings.

In PHP

you can either use the priority parameter in the arguments array or use the set_priority method.

// Argument
$container->add_location( 'customizer', array(
	'priority' => 200
));

// Method
$location = new Ultimate_Fields\Location\Customizer();
$location->set_priority( 200 );

PostMessage Fields

Please read the Displaying data in the front-end section to see what PostMessage fields are and how to use them.

Clone this wiki locally