Giter VIP home page Giter VIP logo

dev7studios-meta-box-framework's Introduction

Dev7studios Meta Box Framework

A simple WordPress meta box framework for creating custom meta boxes in your themes and plugins.

Usage

  1. Download dev7_meta_box_framework.php to your theme/plugin folder
  2. Open up functions.php (or equivelant plugin file) and do the following:
include('dev7_meta_box_framework.php');

function add_custom_meta_boxes() {
	$meta_box = array(
		'id'         => 'dev7_page_settings', // Meta box ID
		'title'      => 'Page Settings', // Meta box title
		'pages'  	 => array('post', 'page'), // Post types this meta box should be shown on
		'context'    => 'normal', // Meta box context
		'priority'   => 'high', // Meta box priority
		'fields' => array(
			array(
	            'id' => 'text',
	            'name' => 'Text',
	            'desc' => 'This is a description.',
	            'type' => 'text',
	            'std' => 'This is std'
	        ),
	        array(
	            'id' => 'textarea',
	            'name' => 'Textarea',
	            'desc' => 'This is a description.',
	            'type' => 'textarea',
	            'std' => 'This is std'
	        ),
	        array(
	            'id' => 'select',
	            'name' => 'Select',
	            'desc' => 'This is a description.',
	            'type' => 'select',
	            'std' => 'green',
	            'choices' => array(
	                'red' => 'Red',
	                'green' => 'Green',
	                'blue' => 'Blue'
	            )
	        ),
	        array(
	            'id' => 'radio',
	            'name' => 'Radio',
	            'desc' => 'This is a description.',
	            'type' => 'radio',
	            'std' => 'green',
	            'choices' => array(
	                'red' => 'Red',
	                'green' => 'Green',
	                'blue' => 'Blue'
	            )
	        ),
	        array(
	            'id' => 'checkbox',
	            'name' => 'Checkbox',
	            'desc' => 'This is a description.',
	            'type' => 'checkbox',
	            'std' => 1
	        ),
	        array(
	            'id' => 'checkboxes',
	            'name' => 'Checkboxes',
	            'desc' => 'This is a description.',
	            'type' => 'checkboxes',
	            'std' => array(
	                'red',
	                'blue'
	            ),
	            'choices' => array(
	                'red' => 'Red',
	                'green' => 'Green',
	                'blue' => 'Blue'
	            )
	        )
		)
	);
	dev7_add_meta_box( $meta_box );
}
add_action( 'dev7_meta_boxes', 'add_custom_meta_boxes' );

Then in your theme/plugin simply use get_post_meta(). For example:

$my_field = get_post_meta(get_the_ID(), 'my_field_id', true);

A field has the following structure:

  • id (required) - The ID of the field (must be unique)
  • name - The name of the field
  • desc - The field description
  • type (required) - The type of field (see list below)
  • std - The default value of the field
  • choices - An array of key-value pairs for fields with multiple choices (e.g. radio, select, checkboxes)

Possible field types are:

  • text
  • textarea
  • select
  • radio
  • checkbox
  • checkboxes

Credits

The Dev7studios Meta Box Framework was created by Gilbert Pellegrom from Dev7studios.

Please contribute by reporting bugs and submitting pull requests. Released under the MIT license.

dev7studios-meta-box-framework's People

Contributors

gilbitron avatar

Watchers

James Cloos avatar Dinesh Kesarwani avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.