Skip to content

Instantly share code, notes, and snippets.

@BenSibley
Last active November 30, 2016 13:43
Show Gist options
  • Save BenSibley/14b1d8f67a1478b923930c6fe741f5f5 to your computer and use it in GitHub Desktop.
Save BenSibley/14b1d8f67a1478b923930c6fe741f5f5 to your computer and use it in GitHub Desktop.
Adding a section with control to the Customizer
function my_add_customizer_sections( $wp_customize ) {
$social_sites = ct_tribes_social_array();
// set a priority used to order the social sites
$priority = 5;
// section
$wp_customize->add_section( 'ct_tribes_social_media_icons', array(
'title' => __( 'Social Media Icons', 'tribes' ),
'priority' => 25,
'description' => __( 'Add the URL for each of your social profiles.', 'tribes' )
) );
// create a setting and control for each social site
foreach ( $social_sites as $social_site => $value ) {
$label = ucfirst( $social_site );
if ( $social_site == 'google-plus' ) {
$label = 'Google Plus';
} elseif ( $social_site == 'rss' ) {
$label = 'RSS';
} elseif ( $social_site == 'soundcloud' ) {
$label = 'SoundCloud';
} elseif ( $social_site == 'slideshare' ) {
$label = 'SlideShare';
} elseif ( $social_site == 'codepen' ) {
$label = 'CodePen';
} elseif ( $social_site == 'stumbleupon' ) {
$label = 'StumbleUpon';
} elseif ( $social_site == 'deviantart' ) {
$label = 'DeviantArt';
} elseif ( $social_site == 'hacker-news' ) {
$label = 'Hacker News';
} elseif ( $social_site == 'whatsapp' ) {
$label = 'WhatsApp';
} elseif ( $social_site == 'qq' ) {
$label = 'QQ';
} elseif ( $social_site == 'vk' ) {
$label = 'VK';
} elseif ( $social_site == 'wechat' ) {
$label = 'WeChat';
} elseif ( $social_site == 'tencent-weibo' ) {
$label = 'Tencent Weibo';
} elseif ( $social_site == 'paypal' ) {
$label = 'PayPal';
} elseif ( $social_site == 'email-form' ) {
$label = 'Contact Form';
}
// setting
$wp_customize->add_setting( $social_site, array(
'sanitize_callback' => 'esc_url_raw'
) );
// control
$wp_customize->add_control( $social_site, array(
'type' => 'url',
'label' => $label,
'section' => 'ct_tribes_social_media_icons',
'priority' => $priority
) );
// increment the priority for next site
$priority = $priority + 5;
}
}
add_action( 'customize_register', 'my_add_customizer_sections' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment