Skip to content

Instantly share code, notes, and snippets.

@ahansson89
Created November 21, 2013 01:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahansson89/7574653 to your computer and use it in GitHub Desktop.
Save ahansson89/7574653 to your computer and use it in GitHub Desktop.
Add a Font Awesome icons select to CPT meta by humanmade: https://github.com/humanmade/Custom-Meta-Boxes/
class ah_is_awesome {
function __construct() {
if(! class_exists( 'CMB_Meta_Box' ) ) {
require_once( 'includes/custom-meta/custom-meta-boxes.php' );
}
}
function font_awesome_array() {
$pattern = '/\.(fa-(?:\w+(?:-)?)+):before\s+{\s*content:\s*"(.+)";\s+}/';
$subject = file_get_contents(plugin_dir_url( __FILE__ ) . 'css/style.css');
preg_match_all($pattern, $subject, $matches, PREG_SET_ORDER);
$icons = array();
asort($icons);
foreach($matches as $match){
$icons[$match[1]] = $match[1];
}
return $icons;
}
function custom_meta( array $meta_boxes ) {
$meta_boxes[] = array(
'title' => 'Meta Options',
'pages' => 'ah_resume_skill', //Your custom post type
'fields' => array(
array(
'id' => 'icon',
'name' => __( 'Select icon', 'audio-player' ),
'type' => 'select',
'cols' => 6,
'options' => $this->font_awesome_array()
),
),
);
return $meta_boxes;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment