Skip to content

Instantly share code, notes, and snippets.

@mattwiebe
Created March 24, 2012 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mattwiebe/2183862 to your computer and use it in GitHub Desktop.
Save mattwiebe/2183862 to your computer and use it in GitHub Desktop.
Options Framework Italics checkbox
<?php
/*
Plugin Name: Options Framework Italics
Plugin URI: http://somadesign.ca/
Description: Add dedicated italics checkbox to the Options Framework typography fields.
Version: 0.1
Author: Soma Design
Author URI: http://somadesign.ca/
License: GPL v2
*/
// add the italics field
add_filter( 'of_typography_fields', 'sd_add_italics', 10, 4 );
function sd_add_italics( $type_fields, $value, $option_name, $option ) {
$ret = array();
$current = isset( $value['italic'] ) ? $value['italic'] : false;
$name = "{$option_name}[{$option['id']}][italic]";
foreach ($type_fields as $key => $field) {
// we want to keep all the fields.
$ret[$key] = $field;
// we're gonna add the italics checkbox after the font_style field
if ( 'font_style' === $key ) {
$ret['font_italic'] = '<label style="float:left;margin-right:6px"><input type="checkbox" name="' . $name . '" ' . checked($current, 'on', false ) . ' style="width:auto;margin:5px 0 0" /> Italic</label>';
}
}
return $ret;
}
// save the italics field
add_filter( 'of_sanitize_typography', 'sd_sanitize_typography', 12, 3 );
function sd_sanitize_typography( $data, $option, $raw ) {
if ( isset($raw['italic']) && ! empty($raw['italic']) ) {
$data['italic'] = 'on';
}
return $data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment