/**
     * Field Display
     *
     * This function takes care of displaying our field to the users, taking
     * the field options into account.
     *
     * @param array $field The details of this field
     * @author Daniel Pataki
     * @since 3.0.0
     *
     */
    function render_field($field)
    {
        $current_font_family = empty($field['value']) ? $field['default_font'] : $field['value']['font'];
        ?>
		<div class="acfgfs-font-selector">
			<div class="acfgfs-loader"></div>
			<div class="acfgfs-form-control acfgfs-font-family">
				<div class="acfgfs-form-control-title"><?php 
        _e('Font Family', 'acf-google-font-selector-field');
        ?>
</div>

				<select name="<?php 
        echo esc_attr($field['name']);
        ?>
">
					<?php 
        $options = acfgfs_get_font_dropdown_array($field);
        foreach ($options as $option) {
            echo '<option ' . selected($option, $current_font_family) . ' value="' . $option . '">' . $option . '</option>';
        }
        ?>
				</select>

				<?php 
        $font = str_replace(' ', '+', $current_font_family);
        ?>
				<div class='acfgfs-preview'>
					<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=<?php 
        echo $font;
        ?>
">

					<div style='font-family:<?php 
        echo $font;
        ?>
'>
						<?php 
        _e('This is a preview of the selected font', 'acf-google-font-selector-field');
        ?>
					</div>
				</div>

			</div>

			<div class="acfgfs-form-control acfgfs-font-variants">
				<div class="acfgfs-form-control-title"><?php 
        _e('Variants', 'acf-google-font-selector-field');
        ?>
</div>
				<div class="acfgfs-list">
					<?php 
        acfgfs_display_variant_list($field);
        ?>
				</div>

			</div>

			<div class="acfgfs-form-control acfgfs-font-subsets">
				<div class="acfgfs-form-control-title"><?php 
        _e('Subsets', 'acf-google-font-selector-field');
        ?>
</div>
				<div class="acfgfs-list">
					<?php 
        acfgfs_display_subset_list($field);
        ?>
				</div>

			</div>

			<textarea name="acfgfs-font-data" class="acfgfs-font-data"><?php 
        echo json_encode($field);
        ?>
</textarea>

		</div>

		<?php 
    }
Beispiel #2
0
/**
 * Get Font Details
 *
 * Used in AJAX requests to output the HTML needed to display the UI for
 * the newly chosen font.
 *
 * @uses acfgfs_display_subset_list()
 * @uses acfgfs_display_variant_list()
 * @author Daniel Pataki
 * @since 3.0.0
 *
 */
function acfgfs_action_get_font_details()
{
    $details = array();
    $field = json_decode(stripslashes($_POST['data']), true);
    unset($field['value']);
    ob_start();
    acfgfs_display_subset_list($field, $_POST['font_family']);
    $details['subsets'] = ob_get_clean();
    ob_start();
    acfgfs_display_variant_list($field, $_POST['font_family']);
    $details['variants'] = ob_get_clean();
    echo json_encode($details);
    die;
}