/** * Implement Theme Customizer additions and adjustments. * Static front page priority is 120, so we assign our section priorities higher * * @param WP_Customize_Manager $wp_customize Theme Customizer object. */ function bigblank_customize_register($wp_customize) { // Add postMessage support for site title and description. $wp_customize->get_setting('blogname')->transport = 'postMessage'; $wp_customize->get_setting('blogdescription')->transport = 'postMessage'; // Rename the label to "Display Site Title & Tagline" in order to make this option extra clear. $wp_customize->get_control('display_header_text')->label = __('Display Site Title & Tagline', 'bigblank'); $wp_customize->get_setting('blogname')->transport = 'postMessage'; $wp_customize->get_setting('blogdescription')->transport = 'postMessage'; $defaults = bigblank_get_default_theme_options(); // Contact Section $wp_customize->add_section('contact', array('title' => __('Contact Settings', 'bigblank'), 'priority' => 140)); // phone text $wp_customize->add_setting('bigblank_theme_options[phone]', array('type' => 'option', 'default' => $defaults['phone'])); $wp_customize->add_control('bigblank_theme_options[phone]', array('label' => __('Phone Number', 'bigblank'), 'section' => 'contact', 'settings' => 'bigblank_theme_options[phone]')); // address text $wp_customize->add_setting('bigblank_theme_options[address]', array('type' => 'option', 'default' => $defaults['address'])); $wp_customize->add_control('bigblank_theme_options[address]', array('label' => __('Address', 'bigblank'), 'section' => 'contact', 'settings' => 'bigblank_theme_options[address]')); // social section $wp_customize->add_section('social', array('title' => __('Social Links', 'bigblank'), 'priority' => 150)); // twitter $wp_customize->add_setting('bigblank_theme_options[twitter]', array('type' => 'option', 'default' => $defaults['twitter'])); $wp_customize->add_control('bigblank_theme_options[twitter]', array('label' => __('Twitter', 'bigblank'), 'section' => 'social', 'settings' => 'bigblank_theme_options[twitter]')); // facebook $wp_customize->add_setting('bigblank_theme_options[facebook]', array('type' => 'option', 'default' => $defaults['facebook'])); $wp_customize->add_control('bigblank_theme_options[facebook]', array('label' => __('Facebook', 'bigblank'), 'section' => 'social', 'settings' => 'bigblank_theme_options[facebook]')); // google+ $wp_customize->add_setting('bigblank_theme_options[googleplus]', array('type' => 'option', 'default' => $defaults['googleplus'])); $wp_customize->add_control('bigblank_theme_options[googleplus]', array('label' => __('Google+', 'bigblank'), 'section' => 'social', 'settings' => 'bigblank_theme_options[googleplus]')); // instagram $wp_customize->add_setting('bigblank_theme_options[instagram]', array('type' => 'option', 'default' => $defaults['instagram'])); $wp_customize->add_control('bigblank_theme_options[instagram]', array('label' => __('Instagram', 'bigblank'), 'section' => 'social', 'settings' => 'bigblank_theme_options[instagram]')); // youtube $wp_customize->add_setting('bigblank_theme_options[youtube]', array('type' => 'option', 'default' => $defaults['youtube'])); $wp_customize->add_control('bigblank_theme_options[youtube]', array('label' => __('Youtube', 'bigblank'), 'section' => 'social', 'settings' => 'bigblank_theme_options[youtube]')); // pinterest $wp_customize->add_setting('bigblank_theme_options[pinterest]', array('type' => 'option', 'default' => $defaults['pinterest'])); $wp_customize->add_control('bigblank_theme_options[pinterest]', array('label' => __('Pinterest', 'bigblank'), 'section' => 'social', 'settings' => 'bigblank_theme_options[pinterest]')); // Default Layout $wp_customize->add_section('bigblank_layout', array('title' => __('Layout', 'bigblank'), 'priority' => 130)); $wp_customize->add_setting('bigblank_theme_options[theme_layout]', array('type' => 'option', 'default' => $defaults['theme_layout'], 'sanitize_callback' => 'sanitize_key')); $layouts = bigblank_layouts(); $choices = array(); foreach ($layouts as $layout) { $choices[$layout['value']] = $layout['label']; } $wp_customize->add_control('bigblank_theme_options[theme_layout]', array('section' => 'bigblank_layout', 'type' => 'radio', 'choices' => $choices)); // Footer Section $wp_customize->add_section('footer', array('title' => __('Footer Settings', 'bigblank'), 'priority' => 160)); // copyright text $wp_customize->add_setting('bigblank_theme_options[footer_copyright]', array('type' => 'option', 'default' => $defaults['footer_copyright'])); $wp_customize->add_control('bigblank_theme_options[footer_copyright]', array('label' => __('Copyright Text', 'bigblank'), 'section' => 'footer', 'settings' => 'bigblank_theme_options[footer_copyright]')); // footer text $wp_customize->add_setting('bigblank_theme_options[footer_text]', array('type' => 'option', 'default' => $defaults['footer_text'])); $wp_customize->add_control('bigblank_theme_options[footer_text]', array('label' => __('Footer Text', 'bigblank'), 'section' => 'footer', 'settings' => 'bigblank_theme_options[footer_text]')); }
/** * validate form input */ function bigblank_theme_options_validate($input) { $output = $defaults = bigblank_get_default_theme_options(); if (isset($input['phone'])) { $output['phone'] = $input['phone']; } if (isset($input['address'])) { $output['address'] = $input['address']; } if (isset($input['twitter'])) { $output['twitter'] = $input['twitter']; } if (isset($input['facebook'])) { $output['facebook'] = $input['facebook']; } if (isset($input['googleplus'])) { $output['googleplus'] = $input['googleplus']; } if (isset($input['instagram'])) { $output['instagram'] = $input['instagram']; } if (isset($input['youtube'])) { $output['youtube'] = $input['youtube']; } if (isset($input['pinterest'])) { $output['pinterest'] = $input['pinterest']; } if (isset($input['theme_layout']) && array_key_exists($input['theme_layout'], bigblank_layouts())) { $output['theme_layout'] = $input['theme_layout']; } if (array_key_exists('page_comments', $input)) { $output['page_comments'] = $input['page_comments']; } else { $output['page_comments'] = ''; } if (array_key_exists('post_comments', $input)) { $output['post_comments'] = $input['post_comments']; } else { $output['post_comments'] = ''; } if (isset($input['footer_copyright'])) { $output['footer_copyright'] = $input['footer_copyright']; } if (isset($input['footer_text'])) { $output['footer_text'] = $input['footer_text']; } if (isset($input['footer_analytics'])) { $output['footer_analytics'] = $input['footer_analytics']; } return apply_filters('bigblank_theme_options_validate', $output, $input, $defaults); }
/** * save post metabox data */ function bigblank_save_post($post_id) { if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } if (isset($_POST['_wpnonce_post_layout']) && !wp_verify_nonce($_POST['_wpnonce_post_layout'], 'post_layout_nonce')) { return; } if (isset($_POST['post_type']) && 'page' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) { return; } else { if (!current_user_can('edit_post', $post_id)) { return; } } } $post_layout = isset($_POST['bigblank_post_layout']) ? $_POST['bigblank_post_layout'] : ''; if (array_key_exists($post_layout, bigblank_layouts())) { update_post_meta($post_id, 'bigblank_post_layout', $post_layout); } elseif ($post_layout == 'default_layout') { delete_post_meta($post_id, 'bigblank_post_layout'); } }