• Stars
    star
    204
  • Rank 192,063 (Top 4 %)
  • Language
    PHP
  • License
    GNU General Publi...
  • Created over 8 years ago
  • Updated almost 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A neat little post meta framework.

ButterBean

ButterBean is a neat little post meta box framework built on Backbone.js and Underscore.js. You can run it as a standalone plugin or drop it into your own plugins.

The idea behind ButterBean came about because I often build custom post types that need quite a bit of custom metadata attached to the posts. Separating this into multiple meta boxes wasn't fun or user friendly. So, I decided to go with a single tabbed meta box instead.

And, that's what ButterBean is. It's essentially a meta box with tabs for lots of content.

Just the interface

A lot of meta box frameworks try to do everything. They handle backend output, frontend output, and everything else you can think of. ButterBean is meant to be an interface only. Because every project's needs are vastly different, it doesn't make sense to stick you with a bunch of things you don't need. This means that the code can stay relatively lean and flexible, which makes it perfect for bundling in your plugins.

So, don't go looking for functions for outputting metadata on the front end from ButterBean. It doesn't have any. Use the core WordPress functionality or build your own wrapper functions.

Documentation

This is a quick guide. If you're familiar with the WordPress Customization API, you should probably pick this up fairly quickly. A lot of the same concepts are used here.

Installation

Drop the butterbean folder into your plugin. That's the simple part.

The script will auto-load itself on the correct admin hooks. You just need to load it like so:

add_action( 'plugins_loaded', 'th_load' );

function th_load() {

        require_once( 'path/to/butterbean/butterbean.php' );
}

Registration

There's a built-in action hook called butterbean_register. You're going to use that to register everything. So, you need to set up a callback function for that.

add_action( 'butterbean_register', 'th_register', 10, 2 );

function th_register( $butterbean, $post_type ) {

        // Register managers, sections, controls, and settings here.
}

Registering a manager

A manager is a group of sections, controls, and settings. It's displayed as a single meta box. There can be multiple managers per screen (don't try multiples yet).

$butterbean->register_manager(
        'example',
        array(
        	'label'     => esc_html__( 'Example', 'your-textdomain' ),
        	'post_type' => 'your_post_type',
        	'context'   => 'normal',
        	'priority'  => 'high'
        )
);

$manager = $butterbean->get_manager( 'example' );

Registering a section

A section is a group of controls within a manager. They are presented as "tabbed" sections in the UI.

$manager->register_section(
        'section_1',
        array(
        	'label' => esc_html__( 'Section 1', 'your-textdomain' ),
		'icon'  => 'dashicons-admin-generic'
	)
);

Registering a control

A control is essentially a form field. It's the field(s) that a user enters data into. Each control belongs to a section. Each control should also be tied to a setting (below).

$manager->register_control(
        'abc_xyz', // Same as setting name.
        array(
        	'type'    => 'text',
        	'section' => 'section_1',
        	'label'   => esc_html__( 'Control ABC', 'your-textdomain' ),
        	'attr'    => array( 'class' => 'widefat' )
        )
);

Registering a setting

A setting is nothing more than some post metadata and how it gets stored. A setting belongs to a specific control.

$manager->register_setting(
        'abc_xyz', // Same as control name.
        array(
        	'sanitize_callback' => 'wp_filter_nohtml_kses'
        )
);

JavaScript API

ButterBean was built using Backbone for handling models, collections, and views. It uses Underscore for rendering templates for the views. All output is handled via JavaScript rather than PHP so that we can do cool stuff on the fly without having to reload the page. This is particularly useful when you start building more complex controls.

You'll never need to touch JavaScript until you need to build a control that relies on JavaScript.

The butterbean object

butterbean is the global object that houses everything you ever want to touch on the JavaScript side of things. It's located in the js/butterbean.js file. This file is well-documented, so you'll want to dive into it for doing more advanced stuff.

butterbean.views.register_control() is what most people will end up using. It's a function for registering a custom control view. New views can be created for each type of control.

Here's a quick example of registering a view for a color control where we need to call the core WordPress wpColorPicker() function. It uses the ready() function, which is fired after the HTML has been rendered for the view.

( function() {

        butterbean.views.register_control( 'color', {

        	// Calls the core WP color picker for the control's input.
                ready : function() {

                        var options = this.model.attributes.options;

                        jQuery( this.$el ).find( '.butterbean-color-picker' ).wpColorPicker( options );
                }
        } );
}() );

Professional Support

If you need professional plugin support from me, the plugin author, you can access the support forums at Theme Hybrid, which is a professional WordPress help/support site where I handle support for all my plugins and themes for a community of 70,000+ users (and growing).

Copyright and License

Various ideas from different projects have made their way into ButterBean. A few of the projects that had an important impact on the direction of this project are:

  • Architecturally, the PHP code was modeled after the core WordPress Customization API. - GPL 2+
  • The design concept of the default tabbed interface was taken from WooCommerce. © WooThemes - GPL 3+
  • Code ideas for the media frame were borrowed from WP Term Images. © John James Jacoby - GPL 2+

This project is licensed under the GNU GPL, version 2 or later.

2015-2016 © Justin Tadlock.

More Repositories

1

members

Members WordPress plugin.
PHP
409
star
2

content-type-standards

WordPress community-curated standards for common post types, taxonomies, and metadata.
PHP
303
star
3

hybrid-base

A base theme for building with the Hybrid Core framework.
PHP
155
star
4

get-the-image

Get the Image WordPress plugin.
PHP
105
star
5

custom-content-portfolio

A portfolio plugin.
PHP
102
star
6

grid-columns

For the love of all that is Holy, stop putting 22 column shortcodes in a theme for what's possible with one. A plugin.
PHP
98
star
7

theme-mediaelement

Base stylesheet for theme developers to work with the WordPress media player (mediaelement.js).
CSS
86
star
8

customizer-typography

Proof-of-concept for a typography class and multiple settings tied to a customizer control.
PHP
78
star
9

message-board

A simple forum plugin for us simple folks.
PHP
63
star
10

stargazer

A new theme in the making.
CSS
58
star
11

whistles

Something new. Something different. Tabs, accordions, and all that jazz. Done right.
PHP
50
star
12

restaurant

Base plugin for handling restaurant sites. Created for themers building restaurant themes.
47
star
13

trt-customizer-pro

Repository with examples of using the Customize API to make pro sections, controls, etc.
PHP
46
star
14

admin-themes

Admin themes plugin for WordPress.
PHP
37
star
15

block-pattern-builder

Build block patterns from the WordPress admin.
PHP
37
star
16

exhale

A WordPress theme project.
PHP
34
star
17

series

Official home of the Series plugin for WordPress.
PHP
31
star
18

cleaner-gallery

Official repository for the Cleaner Gallery WordPress plugin.
PHP
23
star
19

first-draft

Starting point for WordPress block themes.
PHP
22
star
20

entry-views

A WordPress plugin for tracking the number of views a post gets.
PHP
22
star
21

saga

Saga: A WordPress theme for writers.
CSS
20
star
22

toot

Just a little testimonials plugin.
PHP
18
star
23

custom-header-extended

Per-post custom headers for WordPress.
PHP
17
star
24

clean-my-archives

Official repository for the Clean My Archives WordPress plugin.
PHP
17
star
25

registration-honeypot

WordPress plugin for stopping most spambot registrations via a simple honeypot method.
PHP
17
star
26

hybrid

Repository for the Hybrid WordPress theme.
PHP
15
star
27

members-role-hierarchy

Hierarchical roles add-on plugin for Members.
PHP
14
star
28

widgets-reloaded

Home of the Widgets Reloaded plugin.
PHP
14
star
29

socially-awkward

Theme with a heavy emphasis on post formats and media.
PHP
13
star
30

butterbean-example

Example plugin using ButterBean.
PHP
12
star
31

extant

PHP
11
star
32

jt-lang

Quick dev plugin for language testing.
PHP
11
star
33

members-role-levels

Plugin to expose user/role levels in the UI of the Members plugin.
PHP
11
star
34

custom-background-extended

Per-post custom backgrounds for WordPress.
9
star
35

my-snippets

My Snippets WordPress plugin.
PHP
9
star
36

ravel

Ravel WordPress theme
CSS
9
star
37

picturesque

Picturesque WordPress theme built from the Hybrid Core framework.
PHP
8
star
38

members-admin-access

PHP
7
star
39

avatars-meta-box

Replaces the post author drop-down with author avatars to select.
PHP
7
star
40

custom-classes

Custom Classes WordPress plugin repository.
PHP
7
star
41

query-posts

Query Posts widget
PHP
5
star
42

mullet

Fork of the Grunion contact form because it's now packaged and maintained in Jetpack.
5
star
43

just-me

A WordPress theme idea in progress.
PHP
5
star
44

news

Repository for the News WordPress theme.
PHP
5
star
45

quote-this

Quote This WordPress plugin.
PHP
5
star
46

members-core-create-caps

PHP
5
star
47

disable-post-format-ui

Plugin to disable the post format UI on the edit post screen.
PHP
5
star
48

sliding-panel

Official home of the Sliding Panel plugin for WordPress.
PHP
5
star
49

picturesque-child

Example child theme for the Picturesque parent theme for WordPress.
PHP
4
star
50

noah-edit-control

Custom plugin for Noah, client.
PHP
4
star
51

hybrid-tabs

Hybrid Tabs WordPress plugin
PHP
4
star
52

prevent-password-reset

Official home of the Prevent Password Reset plugin.
PHP
4
star
53

role-map-edd-members

Map user roles to EDD Members options.
PHP
4
star
54

post-format-meta-box

Plugin to replace WordPress 3.6 post format UI with pre-3.6 meta box.
PHP
4
star
55

widget-title-html

Allows limited, inline HTML in widget titles.
PHP
4
star
56

reverse-comment-textarea

Reverts the "comment" field position to below the other form fields.
PHP
3
star
57

wporg-patterns

Block patterns for WordPress.org.
HTML
3
star
58

unique

Unique WordPress theme on GitHub.
PHP
3
star
59

chun

Theme in progress (temporary repo name)
PHP
3
star
60

theme-hybrid-updater

Updater for ThemeHybrid.com themes.
PHP
3
star
61

my-life

Repository for the My Life WordPress theme.
PHP
3
star
62

comments-user-column

Adds a column to the edit comments screen that displays a comment author's site display name if they were logged in while commenting.
PHP
3
star
63

template-tag-shortcodes

Shortcodes that mirror the WordPress template tags.
PHP
3
star
64

cpt-generator

A custom post type generator.
PHP
3
star
65

th5

Version 5 of ThemeHybrid.com.
PHP
3
star
66

gutenberg-tests

Tests and ideas to work with the Gutenberg project.
JavaScript
2
star
67

theme-classic-header

WordPress block theme with classic header.
PHP
2
star
68

exhale-unravel

Dark child theme for the Exhale WordPress theme.
PHP
2
star
69

members-privacy-caps

PHP
2
star
70

saga-child

Example child theme for the Saga WordPress theme
PHP
2
star
71

book-query-loop-var

Book custom post type with a query loop variation.
PHP
2
star
72

literary

Plugin for making a "writing" or "literature" section on a Web site.
2
star
73

theme-handbook

Theme handbook overhaul.
2
star
74

trending

Repository for the Trending WordPress theme
PHP
2
star
75

dancing-in-the-moonlight

A fun Christmas child theme for Stargazer.
CSS
2
star
76

prototype

Repository for the Prototype WordPress theme.
PHP
2
star
77

retro-fitted

Repository for the Retro-fitted WordPress theme.
PHP
2
star
78

theme-review

PHP
1
star
79

structure

Repository for the Structure WordPress theme.
PHP
1
star
80

th

1
star
81

nova

Something different.
PHP
1
star
82

react-tic-tac-toe

Tic-tac-toe built from Intro to React tutorial.
JavaScript
1
star
83

mp6-expand-widget-controls

Allows widget controls to expand outside of the sidebar on the widgets screen when using the MP6 plugin.
PHP
1
star
84

the-last

Secret theme project in the works.
1
star
85

th6

ThemeHybrid.com version 6 theme.
PHP
1
star
86

exhale-mountains

PHP
1
star
87

twiggy

A clean and minimal child theme for the Stargazer WordPress theme.
PHP
1
star
88

tt1-block-parts

Demo child theme of Twenty Twenty-One using block template parts.
PHP
1
star
89

butterbean-lesson-1

Plugin example from Lesson #1 of the ButterBean tutorial series.
PHP
1
star
90

book-review-variations

Example of creating custom Query Loop variations.
JavaScript
1
star
91

exhale-manuscript

PHP
1
star
92

jt-blog

Backup of my blog posts
1
star