/**
 * Registers custom sections, settings, and controls for the $wp_customize instance.
 *
 * @param object $wp_customize
 * @since Cakifo 1.4
 */
function cakifo_customize_register($wp_customize)
{
    /* Get the theme prefix. */
    $prefix = hybrid_get_prefix();
    /* Get the default theme settings. */
    $defaults = hybrid_get_default_theme_settings();
    $wp_customize->get_setting('blogname')->transport = 'postMessage';
    $wp_customize->get_setting('blogdescription')->transport = 'postMessage';
    /* Add the Cakifo section */
    $wp_customize->add_section('cakifo_customize_settings', array('title' => esc_html__('Cakifo settings', 'cakifo'), 'priority' => 35, 'capability' => 'edit_theme_options'));
    /**
     * Link color
     */
    $wp_customize->add_setting("{$prefix}_theme_settings[link_color]", array('default' => cakifo_get_default_link_color(), 'type' => 'option', 'sanitize_callback' => 'sanitize_hex_color', 'capability' => 'edit_theme_options'));
    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'link_color', array('label' => esc_html__('Link Color', 'cakifo'), 'section' => 'colors', 'settings' => "{$prefix}_theme_settings[link_color]")));
    /**
     * Show slider?
     */
    $wp_customize->add_setting("{$prefix}_theme_settings[featured_show]", array('default' => false, 'type' => 'option', 'capability' => 'edit_theme_options'));
    $wp_customize->add_control('featured_show', array('settings' => "{$prefix}_theme_settings[featured_show]", 'label' => esc_html__('Show "Featured Content" slider?', 'cakifo'), 'section' => 'cakifo_customize_settings', 'type' => 'checkbox'));
    /**
     * Slider categories
     */
    // Create category array
    foreach (get_categories() as $cat) {
        $categories[$cat->term_id] = $cat->name;
    }
    /* Add setting and control */
    $wp_customize->add_setting("{$prefix}_theme_settings[featured_category]", array('default' => '', 'type' => 'option', 'capability' => 'edit_theme_options'));
    $wp_customize->add_control('featured_category', array('settings' => "{$prefix}_theme_settings[featured_category]", 'label' => esc_html__('Featured Category:', 'cakifo'), 'section' => 'cakifo_customize_settings', 'type' => 'select', 'choices' => $categories));
    /**
     * Number of posts in the slider
     */
    $wp_customize->add_setting("{$prefix}_theme_settings[featured_posts]", array('default' => 5, 'type' => 'option', 'capability' => 'edit_theme_options'));
    $wp_customize->add_control('featured_posts', array('settings' => "{$prefix}_theme_settings[featured_posts]", 'label' => esc_html__('Number of posts', 'cakifo'), 'section' => 'cakifo_customize_settings', 'type' => 'text'));
    if ($wp_customize->is_preview() && !is_admin()) {
        add_action('wp_footer', 'cakifo_customize_preview', 21);
    }
}
示例#2
0
/**
 * Function for displaying the meta box
 *
 * @return void
 * @since Cakifo 1.0
 */
function cakifo_theme_meta_box()
{
    ?>

	<table class="form-table">

		<tr>
			<th><label for="<?php 
    echo hybrid_settings_field_id('link_color');
    ?>
"><?php 
    _e('Link Color', 'cakifo');
    ?>
</label></th>
			<td>
				<fieldset>
					<legend class="screen-reader-text"><span><?php 
    _e('Link Color', 'cakifo');
    ?>
</span></legend>

					<input type="text" name="<?php 
    echo hybrid_settings_field_name('link_color');
    ?>
" id="link-color" value="<?php 
    echo esc_attr(hybrid_get_setting('link_color'));
    ?>
" />

					<a href="#" class="pickcolor hide-if-no-js" id="link-color-example"></a>
					<input type="button" class="pickcolor button hide-if-no-js" value="<?php 
    esc_attr_e('Select a Color', 'cakifo');
    ?>
" />

					<div id="colorPickerDiv" style="z-index: 100; background:#eee; border:1px solid #ccc; position:absolute; display:none;"></div> <br />

					<span><?php 
    printf(__('Default color: %s', 'cakifo'), '<span id="default-color">' . cakifo_get_default_link_color() . '</span>');
    ?>
</span>
				</fieldset>
			</td>
		</tr>

		<tr>
			<th>
				<label for="<?php 
    echo hybrid_settings_field_id('featured_show');
    ?>
"><?php 
    _e('Show "Featured Content" slider?', 'cakifo');
    ?>
</label>
			</th>

			<td>
				<p><input id="featured_show" name="<?php 
    echo hybrid_settings_field_name('featured_show');
    ?>
" type="checkbox" value="1" <?php 
    checked(hybrid_get_setting('featured_show'), 1);
    ?>
 /></p>
				<p><?php 
    _e('Check to display the "Featured Content" slider', 'cakifo');
    ?>
</p>
			</td>
		</tr>

		<tr>
			<th>
				<label for="<?php 
    echo hybrid_settings_field_id('featured_category');
    ?>
"><?php 
    _e('Featured Category:', 'cakifo');
    ?>
</label>
			</th>

			<td>
				<?php 
    $categories = get_categories();
    ?>

				<p>
					<select id="<?php 
    echo hybrid_settings_field_id('featured_category');
    ?>
" name="<?php 
    echo hybrid_settings_field_name('featured_category');
    ?>
">
					<option value="" <?php 
    selected(hybrid_get_setting('featured_category'), '');
    ?>
></option>

						<?php 
    foreach ($categories as $cat) {
        ?>
							<option value="<?php 
        echo $cat->term_id;
        ?>
" <?php 
        selected(hybrid_get_setting('featured_category'), $cat->term_id);
        ?>
><?php 
        echo esc_attr($cat->name);
        ?>
</option>
						<?php 
    }
    ?>

					</select>
				</p>

				<p><?php 
    _e('Leave blank to use sticky posts', 'cakifo');
    ?>
</p>
			</td>
		</tr>

		<tr>
			<th>
				<label for="<?php 
    echo hybrid_settings_field_id('featured_posts');
    ?>
"><?php 
    _e('Featured Posts:', 'cakifo');
    ?>
</label>
			</th>
			<td>
				<p><input type="number" min="-1" id="<?php 
    echo hybrid_settings_field_id('featured_posts');
    ?>
" name="<?php 
    echo hybrid_settings_field_name('featured_posts');
    ?>
" value="<?php 
    echo esc_attr(hybrid_get_setting('featured_posts'));
    ?>
" class="small-text" /></p>
				<p><?php 
    _e('How many featured posts should be shown? <code>-1</code> will show all posts in the category.', 'cakifo');
    ?>
				<?php 
    printf(__('%s is the default', 'cakifo'), '<code>5</code>');
    ?>
</p>
			</td>
		</tr>

		<tr>
			<th>
				<label for="<?php 
    echo hybrid_settings_field_id('headlines_category');
    ?>
"><?php 
    _e('Headline Categories:', 'cakifo');
    ?>
</label>
			</th>
			<td>
				<p>
					<label for="<?php 
    echo hybrid_settings_field_id('headlines_category');
    ?>
"><?php 
    _e('Multiple categories may be chosen by holding the <code>Ctrl</code> key and selecting.', 'cakifo');
    ?>
</label>
					<br />

					<select id="<?php 
    echo hybrid_settings_field_id('headlines_category');
    ?>
" name="<?php 
    echo hybrid_settings_field_name('headlines_category');
    ?>
[]" multiple="multiple" style="height:150px;">
						<?php 
    foreach ($categories as $cat) {
        ?>
							<option value="<?php 
        echo $cat->term_id;
        ?>
" <?php 
        if (is_array(hybrid_get_setting('headlines_category')) && in_array($cat->term_id, hybrid_get_setting('headlines_category'))) {
            echo ' selected="selected"';
        }
        ?>
><?php 
        echo esc_html($cat->name);
        ?>
</option>
						<?php 
    }
    ?>
					</select>
				</p>
			</td>
		</tr>
		<tr>
			<th><label for="<?php 
    echo hybrid_settings_field_id('headlines_num_posts');
    ?>
"><?php 
    _e('Headlines Posts:', 'cakifo');
    ?>
</label></th>
			<td>
				<p><input type="number" min="1" id="<?php 
    echo hybrid_settings_field_id('headlines_num_posts');
    ?>
" name="<?php 
    echo hybrid_settings_field_name('headlines_num_posts');
    ?>
" value="<?php 
    echo esc_attr(hybrid_get_setting('headlines_num_posts'));
    ?>
" class="small-text" /></p>

				<p><?php 
    _e('How many posts should be shown per headline category?', 'cakifo');
    ?>
 <?php 
    printf(__('%s is the default', 'cakifo'), '<code>4</code>');
    ?>
</p></p>
			</td>
		</tr>

		<tr>
			<?php 
    $current_user = wp_get_current_user();
    ?>

			<th>
				<label for="<?php 
    echo hybrid_settings_field_id('twitter_username');
    ?>
"><?php 
    _e('Twitter username:'******'cakifo');
    ?>
</label>
			</th>
			<td>
				<p><input type="text" id="<?php 
    echo hybrid_settings_field_id('twitter_username');
    ?>
" name="<?php 
    echo hybrid_settings_field_name('twitter_username');
    ?>
" value="<?php 
    if (hybrid_get_setting('twitter_username') != '') {
        echo esc_attr(hybrid_get_setting('twitter_username'));
    } elseif (isset($current_user->twitter)) {
        echo esc_attr($current_user->twitter);
    }
    ?>
" /></p>
				<p><?php 
    _e('Your Twitter username (if you have one)', 'cakifo');
    ?>
			</td>
		</tr>

	</table> <!-- .form-table --> <?php 
}
/**
 * Filter the default theme settings
 *
 * @param  array  $settings Array with default settings
 * @return array            Array with the filtered default settings
 * @since Cakifo 1.4
 */
function cakifo_filter_default_theme_settings($settings)
{
    $settings['link_color'] = cakifo_get_default_link_color();
    return $settings;
}