post_status ? _e( 'Your page is almost ready.' , 'layerswp' ) : _e( 'Your page is ready.' , 'layerswp' ) ); ?>
post_status ? _e( 'Click the Start button below to set this page up for Layers.' , 'layerswp' ) : _e( 'You can drag and drop widgets, edit content and tweak the design. Click the button below to see your page come to life.' , 'layerswp' ) ); ?>
.json file which you can use to upload to another site.', 'layerswp' ); ?>
' . $post->post_name . '.json) by clicking the button below.', 'layerswp' ); ?>
post_type );
// Set user capability
$can_edit_post = current_user_can( $post_type_object->cap->edit_post, $post->ID );
// Add our button
if ( $can_edit_post && 'builder.php' == get_page_template_slug( $post->ID ) ) {
$actions['builder'] = '' . __( 'Edit Layout' , 'layerswp' ) . '';
}
return $actions;
}
/**
* Page Builder Button Pointer
*/
public function page_builder_button_pointer( $pointers ){
global $post;
// If we are not in the post edit screen, just return
if( !isset( $post ) ) return;
// This button is only used for pages
if ( !in_array( $post->post_type, array( 'page' ) ) || 'publish' != get_post_status() ) return;
// Add the pointer to the pointer config
$pointers[ LAYERS_THEME_SLUG . '-builder-button-pointer-' . $post->ID ] = array(
'selector' => '#builder-button-' . $post->ID,
'position' => array(
'edge' => 'right', // bottom / top/ right / left
'align' => 'left' // left / center / right
),
'title' => __( 'Build Your Page' , 'layerswp' ),
'content' => __( 'Use the' . LAYERS_THEME_TITLE . ' page builder to build a beautiful, dynamic page.' , 'layerswp' ),
);
return $pointers;
}
/**
* Page Builder Meta Update
*/
public function update_page_builder_meta(){
// Get the Post ID
$post_id = $_POST['id'];
if( isset($_POST[ 'template' ] ) && 'builder.php' == $_POST[ 'template' ] ){
update_post_meta( $post_id , '_wp_page_template', $_POST[ 'template' ] );
} else {
delete_post_meta( $post_id , '_wp_page_template' );
}
die();
}
/**
* Custom Meta Register
*/
public function register_post_meta(){
// If we have not published the post, don't set a post ID
if( isset( $_REQUEST[ 'post' ] ) ) {
$post_id = $_REQUEST[ 'post' ];
} else {
$post_id = NULL;
}
// Loop over the custom meta
foreach( $this->custom_meta as $meta_index => $custom_meta ){
// If there is Post Meta, register the metabox
if( isset( $this->custom_meta[ $meta_index ] ) ){
if( post_type_exists( $meta_index ) ) {
/**
* Add post meta for posts & other post types
*/
// Set the post type
$post_type = $meta_index;
$callback_args = array(
'meta_index' =>$meta_index
);
} else {
/**
* Add post meta for page templates
*/
// Set the post type to 'page'
$post_type = 'page';
// Get the page template
$page_template = get_post_meta( $post_id, '_wp_page_template' , true );
// If there is no page template set, just return
if( '' == $page_template ) return;
// Now check to see that we've selected the right page template
if( $meta_index != $page_template) return;
$callback_args = array(
'meta_index' => $meta_index
);
}
// Add Meta Box
add_meta_box(
LAYERS_THEME_SLUG . '-' . $meta_index, // Slug
$custom_meta[ 'title' ], // Title
array( $this , 'display_post_meta' ) , // Interface
$post_type , // Post Type
$custom_meta[ 'position' ], // Position
'high', // Priority
$callback_args // Callback args
);
}
}
}
/**
* Custom Meta Interface
*/
public function display_post_meta( $post , $callback_args ){
// Get post type
$post_type = get_post_type( $post->ID );
// Post Meta Value
$post_meta = get_post_meta( $post->ID, LAYERS_THEME_SLUG, true );
// Set the meta index ie. the array we will loop over for our options
$meta_index = $callback_args[ 'args' ][ 'meta_index' ];
// If there is no post meta to show, return
if( !isset( $this->custom_meta[ $meta_index ] ) ) return;
// Instantiate form elements
$form_elements = new Layers_Form_Elements();
// If there is Post Meta, loop over the tabs.
if( isset( $this->custom_meta[ $meta_index ] ) ){ ?>
custom_meta[ $meta_index ]['custom-meta'] as $key => $meta_option ){ ?>
custom_meta[ $post_type ]['custom-meta'] ?>
custom_meta[ $meta_index ]['custom-meta'] as $key => $meta_option ){ ?>
custom_meta[ $post_type ]['custom-meta'] ?>
custom_meta[ $post_type ] ?>
custom_meta[ $post_type ] )
} // if nonce
}
}
/**
* Kicking this off with the 'custom_meta_init' hook
*/
function layers_custom_meta_init(){
$layers_widget = new Layers_Custom_Meta();
$layers_widget->init();
}
add_action( 'init' , 'layers_custom_meta_init' , 10 );