Advertisement
viktormorales

WordPress: Crear opciones en el customizador de plantillas

Dec 28th, 2015
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.06 KB | None | 0 0
  1. <?php
  2.  
  3. function vhm_customize_register($wp_customize)
  4. {
  5. /**
  6.  * PANEL: Home page
  7.  *
  8.  * Primero creamos el panel donde alojaremos nuestras opciones.
  9.  */
  10.     $wp_customize->add_panel( 'home_page_template', array(
  11.         'priority' => 100,
  12.         'capability' => 'edit_theme_options',
  13.         'theme_supports' => '',
  14.         'title' => __('Home page settings', TEXTDOMAIN),
  15.         'description' => __('Several settings pertaining my theme', TEXTDOMAIN),
  16.     ) );
  17.    
  18. /**
  19.  * FIRST SECTION: SERVICES
  20.  *
  21.  * Luego creamos la sección de ejemplo "Servicios"
  22.  */
  23.     $wp_customize->add_section('services', array(
  24.         'priority' => 100,
  25.         'title'    => __('Services section', TEXTDOMAIN),
  26.         'description' => 'The first section',
  27.         'panel' => 'home_page_template'
  28.     ));
  29.     // Con esta función creamos la primera opción. En este caso se llamará "Main section title"
  30.     $wp_customize->add_setting('main_section_title', array(
  31.         'default' => ''
  32.     ));
  33.     // Y por último el controlador que por defecto será un campo del tipo "text"
  34.     $wp_customize->add_control('main_section_title_control', array(
  35.         'label'      => __('Main section title', TEXTDOMAIN),
  36.         'section'    => 'services',
  37.         'settings'   => 'main_section_title',
  38.     ));
  39.    
  40.     // Agregamos otra opción
  41.     $wp_customize->add_setting('first_column_template', array(
  42.         'default' => ''
  43.     ));
  44.     // Y en este caso usamos la variable "type" para definir que se tratará de un campo "textarea"
  45.     $wp_customize->add_control('first_column_template_control', array(
  46.         'label'      => __('First column template', TEXTDOMAIN),
  47.         'section'    => 'services',
  48.         'settings'   => 'first_column_template',
  49.         'type'       => 'textarea'
  50.     ));
  51.  
  52. /**
  53.  * SECOND SECTION: ABOUT
  54.  *
  55.  * Luego creamos otra sección dentro de nuestro panel principal
  56.  */
  57.     $wp_customize->add_section('about_us', array(
  58.         'priority' => 100,
  59.         'title'    => __('About us section', TEXTDOMAIN),
  60.         'description' => 'The second section',
  61.         'panel' => 'home_page_template'
  62.     ));
  63.  
  64.     // Y nuevamente agregamos la opción y esta vez con el valor por defecto "Set title"
  65.     $wp_customize->add_setting('second_section_title', array(
  66.         'default' => 'Set title'
  67.     ));
  68.     // Una vez más, agregamos el controlador que será tipo "text" por defecto ya que no lo definimos con la variable "type"
  69.     $wp_customize->add_control('second_section_title_control', array(
  70.         'label'      => __('Main section title', TEXTDOMAIN),
  71.         'section'    => 'about_us',
  72.         'settings'   => 'second_section_title',
  73.     ));
  74.     // Creamos otra sección con un valor "vacío" por defecto
  75.     $wp_customize->add_setting('second_section_text', array(
  76.         'default' => ''
  77.     ));
  78.     // Y nuevamente el controlador tipo "textarea"
  79.     $wp_customize->add_control('second_section_text_control', array(
  80.         'label'      => __('Short description', TEXTDOMAIN),
  81.         'section'    => 'about_us',
  82.         'settings'   => 'second_section_text',
  83.         'type'   => 'textarea',
  84.     ));
  85. }
  86. add_action("customize_register","vhm_customize_register");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement