custom_meta = $meta_config->meta_data(); } public function init() { // Enqueue Styles add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) , 50 ); add_action( 'admin_enqueue_scripts', array( $this, 'admin_print_styles' ) , 50 ); // Page Builder Button add_action( 'edit_form_after_title', array( $this , 'page_builder_button' ) ); add_action( 'wp_ajax_update_page_builder_meta' , array( $this , 'update_page_builder_meta' ) ); // add_filter( 'layers_pointer_settings' , array( $this , 'page_builder_button_pointer' ) ); add_action( 'page_row_actions' , array( $this , 'inline_page_builder_button' ), 10, 2 ); // Custom Fields add_action( 'admin_menu', array( $this , 'register_post_meta' ) ); add_action( 'save_post', array( $this , 'save_post_meta' ) ); add_action( 'publish_post', array( $this , 'save_post_meta' ) ); } /** * Enqueue Widget Scripts */ public function admin_enqueue_scripts(){ // Customizer general wp_enqueue_script( LAYERS_THEME_SLUG . '-admin-meta' , get_template_directory_uri() . '/core/meta/js/meta.js' , array( 'backbone', 'jquery', 'wp-color-picker' ), LAYERS_VERSION, true ); // Localize Scripts wp_localize_script( LAYERS_THEME_SLUG . '-admin-meta' , "layers_meta_params", array( 'ajaxurl' => admin_url( "admin-ajax.php" ) , 'nonce' => wp_create_nonce( 'layers-customizer-actions' ) ) ); } /** * Enqueue Widget Styles */ public function admin_print_styles(){ global $pagenow, $post; if ( 'post.php' === $pagenow && ( LAYERS_BUILDER_TEMPLATE == basename( get_page_template() ) ) ) : ?> post_type, array( 'page' ) ) ) return; // Check if we're using the builder for this page $is_builder_used = ( 'builder.php' == basename( get_page_template() ) ) ? true : false; ?>
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[ $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 );