Skip to content

Instantly share code, notes, and snippets.

@designbuildtest
Last active September 30, 2015 03:57
Show Gist options
  • Save designbuildtest/e5e73ed24703a043e6ca to your computer and use it in GitHub Desktop.
Save designbuildtest/e5e73ed24703a043e6ca to your computer and use it in GitHub Desktop.
Language customizer control
<?php
/**
* Language
*
*/
$wp_customize->add_setting( 'WPLANG', array(
'type' => 'option',
'sanitize_callback' => 'dbt_sanitize_language_choice',
) );
$wp_customize->add_control( 'WPLANG', array(
'section' => 'dbt_settings',
'type' => 'select',
'label' => __( 'Language' ),
'choices' => dbt_language_choices(),
'priority' => 70,
) );
/** Language choices. */
function dbt_language_choices() {
return apply_filters( 'dbt_language_choices', array(
'de_DE' => __( 'German' ),
'' => __( 'English (US)' ),
'en_GB' => __( 'English (UK)' ),
'es_ES' => __( 'Spanish' ),
) );
}
function dbt_sanitize_language_choice( $value ) {
$choices = dbt_language_choices();
if ( ! array_key_exists( $value, $choices ) ) {
$value = '';
}
return $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment