init
This commit is contained in:
@@ -0,0 +1,191 @@
|
||||
<?php
|
||||
/**
|
||||
* Dev7studios Meta Box Framework
|
||||
*
|
||||
* @author Gilbert Pellegrom
|
||||
* @link https://github.com/Dev7studios/Dev7studios-Meta-Box-Framework
|
||||
* @version 1.0
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
if( !class_exists( 'Dev7_Meta_Box_Framework' ) ) {
|
||||
|
||||
class Dev7_Meta_Box_Framework {
|
||||
|
||||
function __construct()
|
||||
{
|
||||
add_action( 'admin_init', array(&$this, 'admin_init') );
|
||||
add_action( 'add_meta_boxes', array(&$this, 'add_meta_boxes') );
|
||||
add_action( 'pre_post_update', array(&$this, 'meta_box_save') );
|
||||
}
|
||||
|
||||
function admin_init() {
|
||||
do_action( 'dev7_meta_boxes' );
|
||||
}
|
||||
|
||||
function add_meta_boxes() {
|
||||
global $dev7_meta_boxes;
|
||||
|
||||
|
||||
if( !is_array($dev7_meta_boxes) )
|
||||
return;
|
||||
|
||||
foreach( $dev7_meta_boxes as $meta_box ){
|
||||
if( is_array($meta_box['pages']) ){
|
||||
foreach( $meta_box['pages'] as $page ){
|
||||
add_meta_box( $meta_box['id'], $meta_box['title'], array(&$this, 'meta_box_output'), $page, $meta_box['context'], $meta_box['priority'], array('dev7_meta_box' => $meta_box) );
|
||||
}
|
||||
} else {
|
||||
add_meta_box( $meta_box['id'], $meta_box['title'], array(&$this, 'meta_box_output'), $meta_box['pages'], $meta_box['context'], $meta_box['priority'], array('dev7_meta_box' => $meta_box) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function meta_box_save( $post_id ) {
|
||||
|
||||
if(isset($_REQUEST['post_type'])){
|
||||
if ( 'page' == $_REQUEST['post_type'] ) {
|
||||
if ( !current_user_can( 'edit_page', $post_id ) )
|
||||
return;
|
||||
} else {
|
||||
if ( !current_user_can( 'edit_post', $post_id ) )
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( !isset( $_POST['dev7_meta_box_nonce'] ) || !wp_verify_nonce( $_POST['dev7_meta_box_nonce'], plugin_basename( __FILE__ ) ) )
|
||||
return;
|
||||
|
||||
global $dev7_meta_boxes;
|
||||
if( !is_array($dev7_meta_boxes) )
|
||||
return;
|
||||
|
||||
foreach( $dev7_meta_boxes as $meta_box ){
|
||||
if( isset($meta_box['fields']) && is_array($meta_box['fields']) ){
|
||||
foreach( $meta_box['fields'] as $field ){
|
||||
if( isset($field['id']) ){
|
||||
if( $field['type'] == 'checkboxes' && isset($field['choices']) ){
|
||||
foreach( $field['choices'] as $ckey=>$cval ){
|
||||
if( isset($_POST[$field['id'] .'_'. $ckey]) ){
|
||||
update_post_meta( $post_id, $field['id'] .'_'. $ckey, $_POST[$field['id'] .'_'. $ckey] );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if( isset($_POST[$field['id']]) ){
|
||||
update_post_meta( $post_id, $field['id'], $_POST[$field['id']] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function meta_box_output( $post, $args ) {
|
||||
global $dev7_meta_boxes;
|
||||
if( !is_array($dev7_meta_boxes) )
|
||||
return;
|
||||
|
||||
wp_nonce_field( plugin_basename( __FILE__ ), 'dev7_meta_box_nonce' );
|
||||
|
||||
foreach( $dev7_meta_boxes as $meta_box ){
|
||||
if( isset($args['args']['dev7_meta_box']['id']) && $args['args']['dev7_meta_box']['id'] == $meta_box['id'] ){
|
||||
if( isset($meta_box['fields']) && is_array($meta_box['fields']) ){
|
||||
foreach( $meta_box['fields'] as $field ){
|
||||
if( isset($field['id']) && isset($field['type']) ){
|
||||
$value = get_post_meta( $post->ID, $field['id'], true );
|
||||
if( $value === false && isset($field['std']) ) $value = $field['std'];
|
||||
|
||||
if( $field['type'] == 'checkboxes' && isset($field['choices']) ){
|
||||
$value = array();
|
||||
foreach( $field['choices'] as $ckey=>$cval ){
|
||||
$value[$field['id'] .'_'. $ckey] = get_post_meta( $post->ID, $field['id'] .'_'. $ckey, true );
|
||||
}
|
||||
}
|
||||
|
||||
echo '<p>';
|
||||
|
||||
if( isset($field['name']) && $field['name'] && $field['type'] !== 'checkbox' ){
|
||||
echo '<label for="'. $field['id'] .'"><strong>'. $field['name'] .'</strong></label> ';
|
||||
echo '<br />';
|
||||
}
|
||||
if( isset($field['desc']) && $field['desc'] && $field['type'] !== 'checkbox' ){
|
||||
echo '<span class="help">'. $field['desc'] .'</span>';
|
||||
echo '<br />';
|
||||
}
|
||||
|
||||
|
||||
switch( $field['type'] ){
|
||||
case 'text':
|
||||
$value = esc_attr(stripslashes($value));
|
||||
echo '<input type="text" name="'. $field['id'] .'" id="'. $field['id'] .'" value="'. $value .'" style="width:100%" />';
|
||||
break;
|
||||
case 'textarea':
|
||||
$value = esc_html(stripslashes($value));
|
||||
echo '<textarea name="'. $field['id'] .'" id="'. $field['id'] .'" style="width:100%;height:150px;">'. $value .'</textarea>';
|
||||
break;
|
||||
case 'select':
|
||||
$value = esc_html(esc_attr($value));
|
||||
if( isset($field['choices']) ){
|
||||
echo '<select name="'. $field['id'] .'" id="'. $field['id'] .'" style="width:100%;">';
|
||||
foreach( $field['choices'] as $ckey=>$cval ){
|
||||
echo '<option value="'. $ckey .'"'. (($ckey == $value) ? ' selected="selected"' : '') .'>'. $cval .'</option>';
|
||||
}
|
||||
echo '</select>';
|
||||
}
|
||||
break;
|
||||
case 'radio':
|
||||
$value = esc_html(esc_attr($value));
|
||||
if( isset($field['choices']) ){
|
||||
foreach( $field['choices'] as $ckey=>$cval ){
|
||||
echo '<label><input type="radio" name="'. $field['id'] .'" id="'. $field['id'] .'_'. $ckey .'" value="'. $ckey .'"'. (($ckey == $value) ? ' checked="checked"' : '') .' /> '. $cval .'</label><br />';
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'checkbox':
|
||||
$value = esc_attr(stripslashes($value));
|
||||
echo '<input type="hidden" name="'. $field['id'] .'" value="0" />';
|
||||
echo '<label><input type="checkbox" name="'. $field['id'] .'" id="'. $field['id'] .'" value="1"'. (($value) ? ' checked="checked"' : '') .' /> '. $field['desc'] .'</label>';
|
||||
break;
|
||||
case 'checkboxes':
|
||||
if( isset($field['choices']) ){
|
||||
foreach( $field['choices'] as $ckey=>$cval ){
|
||||
$val = '';
|
||||
if(isset($value[$field['id'] .'_'. $ckey])) $val = $value[$field['id'] .'_'. $ckey];
|
||||
elseif(is_array($field['std']) && in_array($ckey, $field['std'])) $val = $ckey;
|
||||
$val = esc_html(esc_attr($val));
|
||||
echo '<input type="hidden" name="'. $field['id'] .'_'. $ckey .'" value="0" />';
|
||||
echo '<label><input type="checkbox" name="'. $field['id'] .'_'. $ckey .'" id="'. $field['id'] .'_'. $ckey .'" value="'. $ckey .'"'. (($ckey == $val) ? ' checked="checked"' : '') .' /> '. $cval .'</label><br />';
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
echo '</p>';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
new Dev7_Meta_Box_Framework();
|
||||
|
||||
}
|
||||
|
||||
if( !function_exists( 'dev7_add_meta_box' ) ) {
|
||||
|
||||
function dev7_add_meta_box( $meta_box ) {
|
||||
global $dev7_meta_boxes;
|
||||
|
||||
if( !is_array($dev7_meta_boxes) )
|
||||
$dev7_meta_boxes = array();
|
||||
|
||||
$dev7_meta_boxes[] = $meta_box;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
// PAGE META OPTIONS
|
||||
include('meta/meta_box_framework.php');
|
||||
|
||||
function flatsome_custom_meta_boxes() {
|
||||
$meta_box = array(
|
||||
'id' => 'flatsome_page_options2', // Meta box ID
|
||||
'title' => 'Page Layout', // Meta box title
|
||||
'pages' => array('page'), // Post types this meta box should be shown on
|
||||
'context' => 'side', // Meta box context
|
||||
'priority' => 'core', // Meta box priority
|
||||
'fields' => array(
|
||||
array(
|
||||
'id' => '_footer',
|
||||
'name' => 'Page Footer',
|
||||
//'desc' => 'This is a description.',
|
||||
'type' => 'select',
|
||||
'std' => 'normal',
|
||||
'choices' => array(
|
||||
'normal' => 'Normal',
|
||||
'simple' => 'Simple',
|
||||
'custom' => 'Custom',
|
||||
'transparent' => 'Transparent',
|
||||
'disabled' => 'Hide',
|
||||
)
|
||||
),
|
||||
)
|
||||
);
|
||||
dev7_add_meta_box( $meta_box );
|
||||
}
|
||||
add_action( 'dev7_meta_boxes', 'flatsome_custom_meta_boxes' );
|
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* Adds Pages Panel and options to the Customizer for Flatsome.
|
||||
*
|
||||
* @package Flatsome
|
||||
*/
|
||||
|
||||
Flatsome_Option::add_section( 'pages', array(
|
||||
'title' => __( 'Pages', 'flatsome-admin' ),
|
||||
'description' => __( 'Change the default page layout for all pages. You can also override some of these options per page in the page editor.', 'flatsome-admin' ),
|
||||
) );
|
||||
|
||||
Flatsome_Option::add_field( 'option', array(
|
||||
'type' => 'select',
|
||||
'settings' => 'pages_template',
|
||||
'label' => __( 'Default - Page Template', 'flatsome-admin' ),
|
||||
'section' => 'pages',
|
||||
'default' => 'default',
|
||||
'choices' => array(
|
||||
'default' => __( 'Container (Default)', 'flatsome-admin' ),
|
||||
'blank-title-center' => __( 'Container - Center Title', 'flatsome-admin' ),
|
||||
'blank' => __( 'Full-Width', 'flatsome-admin' ),
|
||||
'header-on-scroll' => __( 'Full-Width - Header On Scroll', 'flatsome-admin' ),
|
||||
'blank-featured' => __( 'Full-Width - Parallax Title', 'flatsome-admin' ),
|
||||
'transparent-header' => __( 'Full-Width - Transparent Header', 'flatsome-admin' ),
|
||||
'transparent-header-light' => __( 'Full-Width - Transparent Header Light', 'flatsome-admin' ),
|
||||
'left-sidebar' => __( 'Sidebar Left', 'flatsome-admin' ),
|
||||
'blank-landingpage' => __( 'No Header / No Footer', 'flatsome-admin' ),
|
||||
'right-sidebar' => __( 'Sidebar Right', 'flatsome-admin' ),
|
||||
'single-page-nav' => __( 'Single Page Navigation', 'flatsome-admin' ),
|
||||
'single-page-nav-transparent' => __( 'Single Page Navigation - Transparent Header', 'flatsome-admin' ),
|
||||
'single-page-nav-transparent-light' => __( 'Single Page Navigation - Transparent Header - Light', 'flatsome-admin' ),
|
||||
'blank-sub-nav-vertical' => __( 'Vertical Sub Navigation', 'flatsome-admin' ),
|
||||
),
|
||||
));
|
||||
|
||||
Flatsome_Option::add_field( 'option', array(
|
||||
'type' => 'checkbox',
|
||||
'settings' => 'default_title',
|
||||
'label' => __( 'Show H1 Page title on the container (default), left sidebar and right sidebar templates.', 'flatsome-admin' ),
|
||||
'section' => 'pages',
|
||||
'default' => 0,
|
||||
));
|
||||
|
||||
Flatsome_Option::add_field( 'option', array(
|
||||
'type' => 'checkbox',
|
||||
'settings' => 'page_top_excerpt',
|
||||
'label' => __( 'Add excerpt content to top of pages.', 'flatsome-admin' ),
|
||||
'section' => 'pages',
|
||||
'default' => 1,
|
||||
));
|
Reference in New Issue
Block a user