/** * Get all sample layouts. * * @since 1.0.0 * * @return array */ function themeblvd_get_sample_layouts() { $api = Theme_Blvd_Builder_API::get_instance(); return $api->get_layouts(); }
/** * Remove sample layout from layout builder. * * @since 2.1.0 * * @param string $element_id ID of element to remove */ function themeblvd_remove_sample_layout($layout_id) { // Get out this on front end or if Builder API doesn't exist. if (!is_admin() || !class_exists('Theme_Blvd_Builder_API')) { return; } // Remove sample layout $api = Theme_Blvd_Builder_API::get_instance(); $api->remove_layout($layout_id); }
/** * Generates the the interface to edit the layout * when in the metabox interface of editing Pages. * * @since 1.1.0 * * @param $id string ID of layout to edit */ public function mini_edit_layout($id) { $api = Theme_Blvd_Builder_API::get_instance(); // If no layout (i.e. User selected "none" or one hasn't been chosen yet) if (!$id) { echo '<p class="warning">' . __('Select a layout to apply and edit it, or create a new one.', 'themeblvd_builder') . '</p>'; return; } // Get custom layout post $elements = $this->get_elements(); $layout = get_post($id); // Check if valid layout if (!$layout) { echo '<p class="warning">' . __('The layout currently selected no longer exists. Select a different layout to edit, or create a new one.', 'themeblvd_builder') . '</p>'; return; } // Grab elements and settings for the layout we're editing $layout_elements = get_post_meta($id, 'elements', true); $layout_settings = get_post_meta($id, 'settings', true); ?> <input type="hidden" name="tb_layout_id" value="<?php echo $id; ?> " /> <h3><?php _e('Edit Layout', 'themeblvd_builder'); ?> : <?php echo $layout->post_title; ?> </h3> <div id="metabox-builder"> <div class="edit-layout-wrap"> <div id="titlediv"> <div class="ajax-overlay"></div> <h2><?php _e('Manage Elements', 'themeblvd_builder'); ?> </h2> <select> <?php foreach ($elements as $element) { echo '<option value="' . $element['info']['id'] . '=>' . $element['info']['query'] . '">' . $element['info']['name'] . '</option>'; } ?> </select> <a href="#" id="add_new_element" class="button-secondary"><?php _e('Add New Element', 'themeblvd_builder'); ?> </a> <span class="tb-loader ajax-loading"></span> <div class="clear"></div> </div><!-- #titlediv (end) --> <div id="builder"> <div id="featured"> <span class="label"><?php _e('Featured Above', 'themeblvd_builder'); ?> </span> <div class="sortable"> <?php if (!empty($layout_elements) && !empty($layout_elements['featured'])) { foreach ($layout_elements['featured'] as $id => $element) { if ($api->is_element($element['type'])) { $this->edit_element($element['type'], $id, $element['options']); } } } ?> </div><!-- .sortable (end) --> </div><!-- #featured (end) --> <div id="primary"> <input type="hidden" name="tb_elements[divider]" value="" /> <span class="label"><?php _e('Primary Area', 'themeblvd_builder'); ?> </span> <div class="sortable"> <?php if (!empty($layout_elements) && !empty($layout_elements['primary'])) { foreach ($layout_elements['primary'] as $id => $element) { if ($api->is_element($element['type'])) { $this->edit_element($element['type'], $id, $element['options']); } } } ?> </div><!-- .sortable (end) --> </div><!-- #primary (end) --> <div id="featured_below"> <input type="hidden" name="tb_elements[divider_2]" value="" /> <span class="label"><?php _e('Featured Below', 'themeblvd_builder'); ?> </span> <div class="sortable"> <?php if (!empty($layout_elements) && !empty($layout_elements['featured_below'])) { foreach ($layout_elements['featured_below'] as $id => $element) { if ($api->is_element($element['type'])) { $this->edit_element($element['type'], $id, $element['options']); } } } ?> </div><!-- .sortable (end) --> </div><!-- #primary (end) --> </div><!-- #builder (end) --> </div><!-- .edit-layout-wrap (end) --> <div class="sidebar-layout-wrap"> <div class="title"> <h2><?php _e('Sidebar Layout', 'themeblvd_builder'); ?> </h2> <div class="clear"></div> </div><!-- #titlediv (end) --> <div class="sidebar-layout"> <?php // Setup sidebar layouts $imagepath = get_template_directory_uri() . '/framework/admin/assets/images/'; $sidebar_layouts = array('default' => $imagepath . 'layout-default.png'); $layouts = themeblvd_sidebar_layouts(); foreach ($layouts as $layout) { $sidebar_layouts[$layout['id']] = $imagepath . 'layout-' . $layout['id'] . '.png'; } // Now convert it to options form $options = array(array('id' => 'sidebar_layout', 'desc' => __('Select how you\'d like the sidebar(s) arranged in this layout. Your site-wide default sidebar layout can be set from your Theme Options page.<br><br><strong>Note: The sidebar layout is only applied to the "Primary Area" of the custom layout.</strong>', 'themeblvd_builder'), 'type' => 'images', 'options' => $sidebar_layouts)); // Display form element $form = themeblvd_option_fields('tb_layout_options', $options, $layout_settings, false); echo $form[0]; ?> </div> </div><!-- .sidebar-layout-wrap (end) --> <div class="custom-layout-note"> <p><?php _e('Note: For this custom layout to be applied to the current page, you must select the "Custom Layout" page template from your Page Attributes.', 'themeblvd_builder'); ?> </p> </div> </div><!-- #metabox-builder (end) --> <?php }
/** * Setup Layout Builder API * * @since 1.2.0 */ function themeblvd_builder_api_init() { // Include screen options class (used in API) include_once TB_BUILDER_PLUGIN_DIR . '/includes/admin/class-tb-layout-builder-screen.php'; // Include Theme_Blvd_Builder_API class. include_once TB_BUILDER_PLUGIN_DIR . '/includes/api/class-tb-builder-api.php'; // Instantiate single object for Builder API. // Helper functions are located within theme // framework. Theme_Blvd_Builder_API::get_instance(); }
/** * Display custom layout within template_builder.php * page template. * * When each element is displayed, it is done so with * an external function. This will allow some elements * to be used for other things such as shortcodes. * However, even elements that shouldn't have an external * function do to allow those elements to be indidivually * edited from a child theme. * * @since 1.0.0 * * @param string $layout_id Post ID for custom layout * @param string $location Location of elements, featured or primary */ function themeblvd_builder_elements($layout_id, $location) { $api = Theme_Blvd_Builder_API::get_instance(); // Setup $counter = 0; $primary_query = false; if (!$layout_id) { // This should rarely happen. A common scenario might // be the user setup a page with a layout, but then // deleted the layout after page was already published. echo themeblvd_get_local('invalid_layout'); return; } // Gather elements and only move forward if we have elements to show. $elements = get_post_meta($layout_id, 'elements', true); if (!empty($elements) && !empty($elements[$location])) { $elements = $elements[$location]; $num_elements = count($elements); } else { // If there are no elements in this location, // get us out of here! return; } // Loop through elements foreach ($elements as $id => $element) { // Skip element if its type isn't registered if (!$api->is_element($element['type'])) { continue; } // Increase counter $counter++; // CSS classes for element $classes = 'element ' . $location . '-element-' . $counter . ' element-' . $element['type']; if ($counter == 1) { $classes .= ' first-element'; } if ($num_elements == $counter) { $classes .= ' last-element'; } if ($element['type'] == 'slider') { if (isset($element['options']['slider_id'])) { $slider_id = themeblvd_post_id_by_name($element['options']['slider_id'], 'tb_slider'); $type = get_post_meta($slider_id, 'type', true); $classes .= ' element-slider-' . $type; } } if ($element['type'] == 'paginated_post_lst' || $element['type'] == 'paginated_post_grid') { $classes .= $element['type']; } if (!empty($element['options']['classes'])) { $classes .= ' ' . $element['options']['classes']; } if (isset($element['options']['visibility'])) { $classes .= themeblvd_responsive_visibility_class($element['options']['visibility'], true); } $classes .= themeblvd_get_classes('element_' . $element['type'], true, false, $element['type'], $element['options'], $location); // Start ouput do_action('themeblvd_element_' . $element['type'] . '_before', $id, $element['options'], $location); // Before element: themeblvd_element_{type}_before do_action('themeblvd_element_open', $element['type'], $location, $classes); do_action('themeblvd_element_' . $element['type'] . '_top', $id, $element['options'], $location); // Top of element: themeblvd_element_{type}_top echo '<div class="grid-protection">'; switch ($element['type']) { /*------------------------------------------------------*/ /* Columns /*------------------------------------------------------*/ case 'columns': if (!function_exists('themeblvd_columns')) { _e('Columns element not supported.', 'themeblvd_builder'); break; } $i = 1; $columns = array(); $num = $element['options']['setup']['num']; while ($i <= $num) { $columns[] = $element['options']['col_' . $i]; $i++; } themeblvd_columns($num, $element['options']['setup']['width'][$num], $columns); break; /*------------------------------------------------------*/ /* Content /*------------------------------------------------------*/ /*------------------------------------------------------*/ /* Content /*------------------------------------------------------*/ case 'content': if (!function_exists('themeblvd_content')) { _e('Content element not supported.', 'themeblvd_builder'); break; } echo themeblvd_content($element['options']); break; /*------------------------------------------------------*/ /* Divider /*------------------------------------------------------*/ /*------------------------------------------------------*/ /* Divider /*------------------------------------------------------*/ case 'divider': if (!function_exists('themeblvd_divider')) { _e('Divider element not supported.', 'themeblvd_builder'); break; } echo themeblvd_divider($element['options']['type']); break; /*------------------------------------------------------*/ /* Headline /*------------------------------------------------------*/ /*------------------------------------------------------*/ /* Headline /*------------------------------------------------------*/ case 'headline': if (!function_exists('themeblvd_headline')) { _e('Headline element not supported.', 'themeblvd_builder'); break; } echo themeblvd_headline($element['options']); break; /*------------------------------------------------------*/ /* Jumbotron /*------------------------------------------------------*/ /*------------------------------------------------------*/ /* Jumbotron /*------------------------------------------------------*/ case 'jumbotron': if (!function_exists('themeblvd_jumbotron')) { _e('Jumbotron element not supported.', 'themeblvd_builder'); break; } themeblvd_jumbotron($element['options']); break; /*------------------------------------------------------*/ /* Post Grid /*------------------------------------------------------*/ /*------------------------------------------------------*/ /* Post Grid /*------------------------------------------------------*/ case 'post_grid': if (!function_exists('themeblvd_posts')) { _e('Post Grid element not supported.', 'themeblvd_builder'); break; } themeblvd_posts($element['options'], 'grid', $location, 'secondary'); break; /*------------------------------------------------------*/ /* Post Grid (paginated) /*------------------------------------------------------*/ /*------------------------------------------------------*/ /* Post Grid (paginated) /*------------------------------------------------------*/ case 'post_grid_paginated': if (!function_exists('themeblvd_posts_paginated')) { _e('Paginated Post Grid element not supported.', 'themeblvd_builder'); break; } if (!$primary_query) { themeblvd_posts_paginated($element['options'], 'grid', $location); $primary_query = true; } break; /*------------------------------------------------------*/ /* Post Grid Slider /*------------------------------------------------------*/ /*------------------------------------------------------*/ /* Post Grid Slider /*------------------------------------------------------*/ case 'post_grid_slider': if (!function_exists('themeblvd_post_slider')) { _e('Post Grid Slider element not supported.', 'themeblvd_builder'); break; } themeblvd_post_slider($id, $element['options'], 'grid', $location); break; /*------------------------------------------------------*/ /* Post List /*------------------------------------------------------*/ /*------------------------------------------------------*/ /* Post List /*------------------------------------------------------*/ case 'post_list': if (!function_exists('themeblvd_posts')) { _e('Post List element not supported.', 'themeblvd_builder'); break; } themeblvd_posts($element['options'], 'list', $location, 'secondary'); break; /*------------------------------------------------------*/ /* Post List (paginated) /*------------------------------------------------------*/ /*------------------------------------------------------*/ /* Post List (paginated) /*------------------------------------------------------*/ case 'post_list_paginated': if (!function_exists('themeblvd_posts_paginated')) { _e('Paginated Post List element not supported.', 'themeblvd_builder'); break; } if (!$primary_query) { themeblvd_posts_paginated($element['options'], 'list', $location); $primary_query = true; } break; /*------------------------------------------------------*/ /* Post List Slider /*------------------------------------------------------*/ /*------------------------------------------------------*/ /* Post List Slider /*------------------------------------------------------*/ case 'post_list_slider': if (!function_exists('themeblvd_post_slider')) { _e('Post List Slider element not supported.', 'themeblvd_builder'); break; } themeblvd_post_slider($id, $element['options'], 'list', $location); break; /*------------------------------------------------------*/ /* Post Slider (mimics standard slider) /*------------------------------------------------------*/ /*------------------------------------------------------*/ /* Post Slider (mimics standard slider) /*------------------------------------------------------*/ case 'post_slider': if (!function_exists('themeblvd_slider_auto')) { _e('Post Slider element not supported.', 'themeblvd_builder'); break; } themeblvd_slider_auto($id, $element['options']); break; /*------------------------------------------------------*/ /* Slider /*------------------------------------------------------*/ /*------------------------------------------------------*/ /* Slider /*------------------------------------------------------*/ case 'slider': if (!function_exists('themeblvd_slider')) { _e('Slider element not supported.', 'themeblvd_builder'); break; } themeblvd_slider($element['options']['slider_id']); break; /*------------------------------------------------------*/ /* Slogan /*------------------------------------------------------*/ /*------------------------------------------------------*/ /* Slogan /*------------------------------------------------------*/ case 'slogan': if (!function_exists('themeblvd_slogan')) { _e('Slogan element not supported.', 'themeblvd_builder'); break; } echo themeblvd_slogan($element['options']); break; /*------------------------------------------------------*/ /* Tabs /*------------------------------------------------------*/ /*------------------------------------------------------*/ /* Tabs /*------------------------------------------------------*/ case 'tabs': if (!function_exists('themeblvd_tabs')) { _e('Tabs element not supported.', 'themeblvd_builder'); break; } echo themeblvd_tabs($id, $element['options']); break; } // End switch // Allow to add on custom element that's // not in the framework do_action('themeblvd_' . $element['type'], $id, $element['options'], $location); // End output echo '<div class="clear"></div>'; echo '</div><!-- .grid-protection (end) -->'; do_action('themeblvd_element_' . $element['type'] . '_bottom', $id, $element['options'], $location); // Bottom of element: themeblvd_element_{type}_bottom do_action('themeblvd_element_close', $element['type'], $location, $classes); do_action('themeblvd_element_' . $element['type'] . '_after', $id, $element['options'], $location); // Below element: themeblvd_element_{type}_bottom } // End foreach }
/** * Creates or returns an instance of this class. * * @since 1.1.1 * * @return Theme_Blvd_Builder_API A single instance of this class. */ public static function get_instance() { if (self::$instance == null) { self::$instance = new self(); } return self::$instance; }