Created
March 24, 2012 14:54
-
-
Save mattwiebe/2183862 to your computer and use it in GitHub Desktop.
Options Framework Italics checkbox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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