Revision: 68886
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at March 11, 2015 06:57 by micklevin
Initial Code
<?php
if (strtolower (realpath (__FILE__)) == strtolower (realpath ($_SERVER['SCRIPT_FILENAME']))) { header ('Location: http://www.bing.ca/'); die; }
// --------------------------------------------------------
// Customize the theme
//
function HERE_theme_customize ($wp_customize)
{
// STEP 1: Define the configuration
// --------------------------------------------------------
$sections = array (array ('section' => 'theme_header',
'title' => __('Header', 'www'),
'description' => __('Configure the Header', 'www'),
'settings' => array (array ('setting' => 'theme_logo', 'label' => __('Site Logo', 'www'), 'control' => 'image'),
array ('setting' => 'theme_head_text', 'label' => __('Text in Header', 'www'), 'control' => 'textarea'))),
array ('section' => 'theme_footer',
'title' => __('Footer', 'www'),
'description' => __('Text in the footer', 'www'),
'settings' => array (array ('setting' => 'theme_footer_text_id', 'label' => __('Text Block: ID or Slug', 'www')),
array ('setting' => 'theme_footer_privacy_url', 'label' => __('Link to the Privacy Page', 'www')),
array ('setting' => 'theme_footer_copyright', 'label' => __('Copyright note at left', 'www')))),
array ('section' => 'theme_home_page',
'title' => __('Home Page', 'www'),
'description' => __('Configure the Home Page', 'www'),
'settings' => array (array ('setting' => 'theme_home_slider', 'label' => __('Front slider: ID or Slug', 'www')),
array ('setting' => 'theme_home_featured_title', 'label' => __('Featured posts: Title', 'www')),
array ('setting' => 'theme_home_featured_cat', 'label' => __('Featured posts: Category Slug ', 'www')),
array ('setting' => 'theme_home_portfolio_title', 'label' => __('Portfolio gallery: Title', 'www')),
array ('setting' => 'theme_home_portfolio_id', 'label' => __('Portfolio gallery: ID or Slug', 'www')),
array ('setting' => 'theme_home_why_us_title', 'label' => __('Why Us Block: Title', 'www')),
array ('setting' => 'theme_home_why_us_image', 'label' => __('Why Us Block: Image', 'www'), 'control' => 'image'),
array ('setting' => 'theme_home_why_us_id', 'label' => __('Why Us Block: ID or Slug', 'www')),
array ('setting' => 'theme_home_contact_title', 'label' => __('Contact Block: Title', 'www')),
array ('setting' => 'theme_home_contact_id', 'label' => __('Contact Block: ID or Slug', 'www')))),
array ('section' => 'theme_socials',
'title' => __('Social', 'www'),
'description' => __('Links to your Social Sites', 'www'),
'settings' => array (array ('setting' => 'theme_social_facebook', 'label' => __('Facebook URL', 'www')),
array ('setting' => 'theme_social_facebook_appid', 'label' => __('Facebook App ID', 'www')),
array ('setting' => 'theme_social_twitter', 'label' => __('Twitter URL', 'www')),
array ('setting' => 'theme_social_googleplus', 'label' => __('Google+ URL', 'www')),
array ('setting' => 'theme_social_pinterest', 'label' => __('Pinterest URL', 'www')),
array ('setting' => 'theme_social_etsy', 'label' => __('Etsy URL', 'www')),
array ('setting' => 'theme_social_youtube', 'label' => __('Youtube URL', 'www')),
array ('setting' => 'theme_social_instagram', 'label' => __('Instagram URL', 'www')))),
array ('section' => 'theme_counters',
'title' => __('Counters', 'www'),
'description' => __('Code for the counters', 'www'),
'settings' => array (array ('setting' => 'theme_counter_google', 'label' => __('Google Analytics', 'www'), 'control' => 'textarea'))));
// STEP 2: Call the custom function, see below the source
HERE_customizer_register ($wp_customize, $sections);
}
// --------------------------------------------------------
// Customize the theme
// Supports text, textarea and image controls so far
function HERE_customizer_register ($wp_customize, $sections)
{
$priority = 100;
if (is_array ($sections))
{
foreach ($sections as $section)
{
if (!isset ($section['builtin']) || !$section['builtin'])
{
$wp_customize->add_section ($section['section'],
array ('title' => $section['title'],
'description' => $section['description'],
'priority' => (isset ($section['priority']) ? $section['priority'] : $priority++)));
}
if (is_array ($section['settings']))
{
foreach ($section['settings'] as $setting)
{
$wp_customize->add_setting ($setting['setting']);
$setting['control'] = isset ($setting['control']) ? $setting['control'] : 'text';
switch ($setting['control'])
{
case 'image':
$wp_customize->add_control (new WP_Customize_Image_Control ($wp_customize,
$setting['setting'],
array ('label' => $setting['label'],
'section' => $section['section'],
'settings' => $setting['setting'])));
break;
case 'textarea':
$wp_customize->add_control (new WP_Customize_Control ($wp_customize,
$setting['setting'],
array ('type' => $setting['control'],
'label' => $setting['label'],
'section' => $section['section'],
'settings' => $setting['setting'])));
break;
default:
$wp_customize->add_control ($setting['setting'], array ('label' => $setting['label'],
'section' => $section['section']));
break;
}
}
}
}
}
}
Initial URL
Initial Description
To use WordPress 4 Customizer API I'd need just to do 2 steps: define a data in the array, and call a custom registering function.
Initial Title
2 Step use of WordPress 4 Customizer
Initial Tags
wordpress
Initial Language
PHP