Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created June 6, 2018 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/f9f54bdf2196c5450e1295321fe926e9 to your computer and use it in GitHub Desktop.
Save billerickson/f9f54bdf2196c5450e1295321fe926e9 to your computer and use it in GitHub Desktop.
<?php
/**
* Custom Fields with Carbon Fields
*
* @package CoreFunctionality
* @author Bill Erickson
* @since 1.0.0
* @license GPL-2.0+
**/
use Carbon_Fields\Container;
use Carbon_Fields\Field;
/**
* Register Fields
*
*/
function ea_register_custom_fields() {
Container::make( 'post_meta', 'Plugins' )
->where( 'post_type', '=', 'page' )
->where( 'post_template', '=', 'templates/plugins-carbonfields.php' )
->add_fields( array(
Field::make( 'complex', 'be_plugins', 'Plugins' )
->setup_labels( array( 'singular_name' => 'Plugin', 'plural_name' => 'Plugins' ) )
->set_collapsed( true )
->add_fields( array(
Field::make( 'text', 'name' )->set_width(33),
Field::make( 'text', 'url', 'URL' )->set_width(33),
Field::make( 'text', 'icon' )->set_width(33),
Field::make( 'textarea', 'summary' ),
Field::make( 'set', 'categories' )
->set_options( 'ea_plugin_categories' )
))
->set_header_template( '<% if (name) { %><%- name %><% } %>' )
));
}
add_action( 'carbon_fields_register_fields', 'ea_register_custom_fields' );
/**
* Plugin Categories
*
*/
function ea_plugin_categories() {
return array(
'genesis' => 'Genesis',
'developer' => 'Developer',
'cms' => 'CMS',
'social' => 'Social',
'media' => 'Media',
'widget' => 'Widget',
'analytics' => 'Analytics'
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment