https://codex.wordpress.org/Theme_Customization_API
https://github.com/kwight/debut/blob/master/inc/customizer.php
This hooks into ‘customize_register’ (available as of WP 3.4) and allows
* you to add new sections and controls to the Theme Customize screen.
*
* Note: To enable instant preview, we have to actually write a bit of custom
* javascript. See live_preview() for more.
*
* @see add_action(‘customize_register’,$func)
* @param \WP_Customize_Manager $wp_customize
* @link http://ottopress.com/2012/how-to-leverage-the-theme-customizer-in-your-own-themes/
* @since MyTheme 1.0
*
Panels group Sections together
Sections contain Controls
Controls are what the user changes
Settings define what the Controls change
Default WP Core Sections
do want to change the location of your custom section, the priorities of the core sections are below:
Title | ID | Priority (Order) |
Site Title & Tagline | title_tagline | 20 |
Colors | colors | 40 |
Header Image | header_image | 60 |
Background Image | background_image | 80 |
Menus (Panel) | menus | 100 |
Widgets (Panel) | widgets | 110 |
Static Front Page | static_front_page | 120 |
default | 160 |
new in WP 4.0 -> https://make.wordpress.org/core/2014/07/08/customizer-improvements-in-4-0/
$wp_customize->add_control( ‘setting_id’, array(
‘type’ => ‘range’,
‘priority’ => 10,
‘section’ => ‘title_tagline’,
‘label’ => ‘Range’,
‘description’ => ‘This is the range control description.’,
‘input_attrs’ => array(
‘min’ => 0,
‘max’ => 10,
‘step’ => 2,
‘class’ => ‘test-class test’,
‘style’ => ‘color: #0a0’,
),
) );
Contextual Controls
Customizer controls can now be displayed or hidden based on the Customizer’s preview context. For example, options that are only relevant to the front page can be shown only when the user is previewing their front page in the Customizer (see #27993). This is already implemented in core for Widgets; Widgets have always been contextually faded and shown/hidden based on their visibility in the preview, but this functionality is now built off of the core active_callback
API in both PHP and JS. There are three different ways to specify whether a given control should only be displayed in a certain context. The first, and most straightforward, is to use theactive_callback
argument in $wp_customize->add_control()
.
1
2
3
4
5
|
$wp_customize ->add_control( 'front_page_greeting' , array ( 'label' => __( 'Greeting' ), 'section' => 'title_tagline' , 'active_callback' => 'is_front_page' , ) ); |
Wird ein Thema erstmals in der Live-Preview geladen, werden die theme_mod in die Datenbank in die options table unter: theme_mods_themename geschrieben.
Dies geschieht unabhängig davon ob das Thema auch aktiviert wurde!
Mit der Live-Preview wird der Customizer geladen und damit werden alle default-Werte der settings ausgelesen und geladen.
theme_mod vs. option
$wp_customize->add_setting( ‘setting-id-name’, array(‘type’ => ‘theme_mod’,……..)
- theme_mods werden als Array serialized in die options-table geschrieben
- sie können mit einer einzigen Datenbankabfrage eingelesen werden
- Abfrage mit: get_theme_mod($setting_id_name, $default_value)
$wp_customize->add_setting( ‘setting-id-name’, array(‘type’ => ‘option’,……..)
- jede option wird als eigener Eintrag in die options-table geschrieben
- jedes Einlesen einer option muss mit einer eigenen Datenbankabfrage geschehen.
- mehrere options können jedoch auch in einem Array gespeichert werden
- options sollten sehr sparsam für Themen verwendet werden
- Abfrage mit get_option($setting_id_name, $default_value)
Customizer APIs in 4.6 for Setting Validation and Notifications
Allerdings ist die Theme Options bzw. Theme mods gekoppelt mit dem Customizer!
D.h., dass im Allgemeinen die Default-Werte der Variablen initialisiert werden müssen.
Eine Möglichkeit wäre:
(gefunden: http://wordpress.stackexchange.com/questions/143789/use-default-value-of-wp-customizer-in-theme-mod-output)
$my_theme_defaults = array( 'foo' => 'bar', 'baz' => 'boo', ); function my_theme_customize( $wp_customize ) { global $my_theme_defaults; $wp_customize->add_setting( 'foo', array( 'default' => $my_theme_defaults['foo'], ) ); } function my_theme_mod( $name ) { global $my_theme_defaults; echo get_theme_mod( $name, $my_theme_defaults[ $name ] ); }
Weitere Erklärung zu diesem Thema: