Beispiel #1
0
 private function create_layout($name)
 {
     // @todo check with Ric to get a more handy class to create a new layout.
     // currently there is only (which I found)
     // - create_layout_auto(), which has a redirect
     // - create_layout_callback() for ajax only -> uses die()
     global $wpddlayout;
     if (!$this->needed_components_loaded()) {
         return false;
     }
     // permissions
     if (!current_user_can('manage_options') && WPDD_Layouts_Users_Profiles::user_can_create() && WPDD_Layouts_Users_Profiles::user_can_assign()) {
         return false;
     }
     $layout = WPDD_Layouts::create_layout(12, 'fluid');
     // Define layout parameters
     $layout['type'] = 'fluid';
     // layout_type
     $layout['cssframework'] = $wpddlayout->get_css_framework();
     $layout['template'] = '';
     $layout['parent'] = '';
     $layout['name'] = $name;
     $args = array('post_title' => $name, 'post_content' => '', 'post_status' => 'publish', 'post_type' => WPDDL_LAYOUTS_POST_TYPE);
     $layout_id = wp_insert_post($args);
     // force layout object to take right ID
     // @see WPDD_Layouts::create_layout_callback() @ wpddl.class.php
     $layout_post = get_post($layout_id);
     $layout['id'] = $layout_id;
     $layout['slug'] = $layout_post->post_name;
     // update changes
     WPDD_Layouts::save_layout_settings($layout_id, $layout);
     return $layout_id;
 }
 /**
  * Checks if template has BP cell and add filters.
  * 
  * @param type $layout_id
  * @param type $args
  * @return type
  */
 function has_cell($layout_id, $args)
 {
     $layout_settings = WPDD_Layouts::get_layout_settings($layout_id, true);
     $layout_instance = new WPDD_json2layout();
     $layout = $layout_instance->json_decode(wp_json_encode($layout_settings));
     if ($layout->has_cell_of_type('buddypress') && is_buddypress()) {
         // Do something
     }
     return $layout_id;
 }
 public function get_cell_info($template)
 {
     $template['cell-image-url'] = DDL_ICONS_SVG_REL_PATH . 'post-loop-cell.svg';
     //	$template['preview-image-url'] = WPDDL_RES_RELPATH . '/images/child-layout.png';
     $template['name'] = sprintf(__('Blog', 'ddl-layouts'), '');
     $template['description'] = __('Display a WordPress ‘posts loop’ using styling from the theme. You need to include this cell, or a WordPress Archive cell, in layouts used for the blog, archives, search and other pages that display WordPress content lists.', 'ddl-layouts');
     $template['button-text'] = __('Assign Post Loop cell', 'ddl-layouts');
     $template['dialog-title-create'] = __('Create a Post Loop cell', 'ddl-layouts');
     $template['dialog-title-edit'] = __('Edit Post Loop cell', 'ddl-layouts');
     $template['dialog-template'] = $this->_dialog_template();
     $template['allow-multiple'] = false;
     $template['cell-class'] = 'post-loop-cell';
     $template['category'] = sprintf(__('%s elements', 'ddl-layouts'), WPDD_Layouts::get_theme_name());
     $template['preview-image-url'] = DDL_ICONS_PNG_REL_PATH . 'post-loop_expand-image.png';
     $template['has_settings'] = false;
     return $template;
 }
 public function duplicate_layout_callback()
 {
     // Clear any errors that may have been rendered that we don't have control of.
     if (ob_get_length()) {
         ob_clean();
     }
     if (user_can_create_layouts() === false) {
         die(WPDD_Utils::ajax_caps_fail(__METHOD__));
     }
     if ($_POST && wp_verify_nonce($_POST['layout-duplicate-layout-nonce'], 'layout-duplicate-layout-nonce')) {
         global $wpdb, $wpddlayout;
         $result = $wpdb->get_row($wpdb->prepare("SELECT ID, post_name FROM {$wpdb->posts} WHERE post_type=%s AND ID=%d AND post_status = 'publish'", WPDDL_LAYOUTS_POST_TYPE, $_POST['layout_id']));
         if ($result) {
             $layout_json = WPDD_Layouts::get_layout_settings($result->ID);
             $layout_array = json_decode($layout_json, true);
             $layout_name_base = __('Copy of ', 'ddl-layouts') . str_replace('\\', '\\\\', $layout_array['name']);
             $layout_name = $layout_name_base;
             $count = 1;
             while ($wpddlayout->does_layout_with_this_name_exist($layout_name)) {
                 $layout_name = $layout_name_base . ' - ' . $count;
                 $count++;
             }
             $postarr = array('post_title' => $layout_name, 'post_content' => '', 'post_status' => 'publish', 'post_type' => WPDDL_LAYOUTS_POST_TYPE);
             $post_id = wp_insert_post($postarr);
             $post_slug = $wpdb->get_var($wpdb->prepare("SELECT post_name FROM {$wpdb->posts} WHERE post_type=%s AND ID=%d", WPDDL_LAYOUTS_POST_TYPE, $post_id));
             $layout_array['name'] = $layout_name;
             $layout_array['slug'] = $post_slug;
             WPDD_Layouts::save_layout_settings($post_id, $layout_array);
             $wpddlayout->register_strings_for_translation($post_id);
         }
         $send = $wpddlayout->listing_page->get_send(isset($_GET['status']) && $_GET['status'] === 'trash' ? $_GET['status'] : 'publish', false, $post_id, $post_id, '', $_POST);
     } else {
         $send = wp_json_encode(array('error' => __(sprintf('Nonce problem: apparently we do not know where the request comes from. %s', __METHOD__), 'ddl-layouts')));
     }
     die($send);
 }
 public static function save_layout_settings($post_id, $settings)
 {
     if (is_string($settings)) {
         $settings = wp_json_encode(json_decode($settings, true));
     } else {
         if (is_array($settings) || is_object($settings)) {
             $settings = wp_json_encode((array) $settings);
         }
     }
     $layouts_raw = WPDD_Layouts::get_layout_settings($post_id, false);
     $result = update_post_meta($post_id, WPDDL_LAYOUTS_SETTINGS, addslashes($settings), $layouts_raw);
     // clear the cache.
     $layouts_raw = WPDD_Layouts::get_layout_settings($post_id, false, true);
     return $result;
 }
 public static function get_children($layout, $layouts_list, $previous_slug = null)
 {
     $ret = array();
     if (isset($layout->has_child) && ($layout->has_child === 'true' || $layout->has_child === true)) {
         $layout_slug = $previous_slug === null ? $layout->slug : $previous_slug;
         foreach ($layouts_list as $post) {
             $child = WPDD_Layouts::get_layout_settings($post->ID, true);
             if ($child) {
                 if (property_exists($child, 'parent') && $child->parent == $layout_slug && $layout->id != $post->ID) {
                     $ret[] = $post->ID;
                 }
             }
         }
         return $ret;
     }
     return $ret;
 }
function display_breadcrumb_tree($parent_id, $available_parents)
{
    global $wpddlayout;
    if ($parent_id == 0) {
        if (isset($available_parents[$parent_id]) && sizeof($available_parents[$parent_id]) > 0) {
            // Add No Parent to the start.
            ?>
			<li class="js-tree-category-item">
				<p class="item-name-wrap js-item-name-wrap">
					<a href="#">
						<span class="js-item-name"
							  data-layout-slug=""
							  data-layout-id=""><?php 
            _e('(no parent)', 'ddl-layouts');
            ?>
</span>
					</a>
				</p>
			<?php 
            foreach ($available_parents[$parent_id] as $parent) {
                display_breadcrumb_tree($parent, $available_parents);
            }
        }
    } else {
        $layout = WPDD_Layouts::get_layout_settings($parent_id, true);
        ?>
			<li class="js-tree-category-item <?php 
        if (isset($available_parents[$parent_id])) {
            ?>
js-tree-category<?php 
        }
        ?>
">
				<p class="item-name-wrap js-item-name-wrap">
					<?php 
        if (isset($available_parents[$parent_id])) {
            ?>
					<i class="js-tree-toggle icon-collapse-alt" data-expanded="true" data-text-expanded="Collapse" data-text-collapsed="Expand" title="Collapse"></i>
					<?php 
        }
        ?>
					<a href="#">
						<span class="js-item-name"
							  data-layout-slug="<?php 
        echo $layout->slug;
        ?>
"
							  data-layout-id="<?php 
        echo $layout->id;
        ?>
"><?php 
        echo esc_html($layout->name);
        ?>
</span>
					</a>
				</p>

				<?php 
        if (isset($available_parents[$parent_id]) && sizeof($available_parents[$parent_id]) > 0) {
            ?>
					<ul class="js-tree-category-items">
						<?php 
            foreach ($available_parents[$parent_id] as $parent) {
                display_breadcrumb_tree($parent, $available_parents);
            }
            ?>
					</ul> <!-- .js-tree-category-items -->
				<?php 
        }
        ?>
			</li> <!-- .js-tree-category-item -->

		<?php 
    }
}
    function meta_box($post)
    {
        global $wpddlayout;
        if ($wpddlayout->theme_has_page_templates() === false) {
            ?>
            <p class="toolset-alert toolset-alert-warning js-layout-support-warning line-height-16">
                <?php 
            echo sprintf(__("A template file that supports layouts is not available.", 'ddl-layouts'), '');
            ?>
<br>
                <?php 
            printf(__('Please check %shere%s to see how to set one up.', 'ddl-layouts'), '<a href="' . WPDLL_LEARN_ABOUT_SETTING_UP_TEMPLATE . '" target="_blank">', '</a>');
            ?>
            </p>
            <?php 
            return;
        }
        global $wpddl_features;
        $layout_tempates_available = WPDD_Layouts_Cache_Singleton::get_published_layouts();
        if (isset($_GET['post'])) {
            $template_selected = get_post_meta($_GET['post'], WPDDL_LAYOUTS_META_KEY, true);
        } else {
            $template_selected = '';
        }
        if ($post->post_type != 'page') {
            $none = new stdClass();
            $none->ID = 0;
            $none->post_name = 0;
            $none->post_title = __('None', 'ddl-layouts');
            array_unshift($layout_tempates_available, $none);
        }
        $post_type_obj = get_post_type_object($post->post_type);
        ?>

        <div class="js-dd-layout-selector">

            <script type="text/javascript">
                var ddl_old_template_text = "<?php 
        _e('Template', 'ddl-layouts');
        ?>
";
            </script>


            <?php 
        if ($post->post_type == 'page') {
            ?>
                <p>
                    <i class="icon-layouts-logo ont-icon-22 ont-color-orange"></i> <strong><?php 
            _e('Template and Layout', 'ddl-layouts');
            ?>
</strong>
                </p>
            <?php 
        }
        ?>
            <p>


                <?php 
        $template_selected = $this->wpml_layout_for_post_edit($template_selected);
        $template_option = $wpddlayout->get_option('templates');
        $post_type_theme = $wpddlayout->post_types_manager->get_layout_template_for_post_type($post->post_type);
        $theme_template = $post_type_theme == 'default' ? basename(get_page_template()) : $post_type_theme;
        $post_type_layout = $wpddlayout->post_types_manager->get_layout_to_type_object($post->post_type);
        ?>

                <input type="hidden" name="ddl-namespace-post-type-tpl" value="<?php 
        echo $post_type_theme == 'default' ? 'default' : $theme_template;
        ?>
" class="js-ddl-namespace-post-type-tpl" />
                <select name="layouts_template" id="js-layout-template-name" <?php 
        disabled($post->post_type == 'attachment');
        /* cannot assign layouts to attachment post type posts individually */
        ?>
 >
                    <?php 
        if (isset($template_option[$theme_template])) {
            $theme_default_layout = $template_option[$theme_template];
        } else {
            $theme_default_layout = '';
        }
        foreach ($layout_tempates_available as $template) {
            $layout = WPDD_Layouts::get_layout_settings($template->ID, true);
            $has_loop = is_object($layout) && property_exists($layout, 'has_loop') ? $layout->has_loop : false;
            $supported = true;
            $warning = '';
            if ($layout && property_exists($layout, 'type') && $layout->type == 'fixed' && !$wpddl_features->is_feature('fixed-layout')) {
                $warning = __("This layout is a fixed layout. The current theme doesn't support fixed layouts and might not display correctly", 'ddl-layouts');
            }
            if ($layout && property_exists($layout, 'type') && $layout->type == 'fluid' && !$wpddl_features->is_feature('fluid-layout')) {
                $warning = __("This layout is a fluid layout. The current theme doesn't support fluid layouts and might not display correctly", 'ddl-layouts');
            }
            if ($layout && $template_selected != $layout->slug && isset($layout->has_child) && ($layout->has_child === 'true' || $layout->has_child === true)) {
                $supported = false;
            }
            if ($supported) {
                $force_layout = ' data-force-layout="false"';
                if ($template_selected == $template->post_name) {
                    $selected = ' selected="selected"';
                } elseif (!isset($_GET['post']) && is_object($post_type_layout) && property_exists($post_type_layout, 'layout_id') && (int) $template->ID === (int) $post_type_layout->layout_id) {
                    $selected = ' selected="selected"';
                    $force_layout = ' data-force-layout="true"';
                } else {
                    $selected = '';
                }
                $title = $template->post_title;
                if ($title == '') {
                    $title = $template->post_name;
                }
                if ($template->post_name == $theme_default_layout && $post->post_type == 'page') {
                    $title .= __(' - Template default', 'ddl-layouts');
                }
                $data_object = array('layout_has_loop' => $has_loop, 'post_type' => $post->post_type, 'is_really_selected' => $selected !== '');
                $data_object = $data_object;
                ?>
                            <option data-object="<?php 
                echo htmlspecialchars(wp_json_encode($data_object));
                ?>
" value="<?php 
                echo $template->post_name;
                ?>
"<?php 
                echo $selected . $force_layout;
                ?>
 data-id="<?php 
                echo $template->ID;
                ?>
" data-ddl-warning="<?php 
                echo $warning;
                ?>
"><?php 
                echo $title;
                ?>
</option>
                        <?php 
            }
        }
        ?>

                </select>

                <input type="hidden" class="js-wpddl-default-template-message" value="<?php 
        echo $this->main_template;
        ?>
" data-message="<?php 
        _e('Show all templates', 'ddl-layouts');
        ?>
" />
                <?php 
        if ($post->post_type == 'page') {
            ?>
                    <select name="combined_layouts_template" id="js-combined-layout-template-name">

                    </select>


                <?php 
        }
        ?>
            <p>
                <a data-href="<?php 
        echo admin_url() . 'admin.php?page=dd_layouts_edit&amp;action=edit&layout_id=';
        ?>
" class="edit-layout-template js-edit-layout-template"><?php 
        _e('Edit this layout', 'ddl-layouts');
        ?>
</a>
            </p>
            </p>

            <?php 
        do_action('ddl_add_create_layout_button');
        ?>

            <div class="display_errors js-display-errors"></div>

            <p class="toolset-alert toolset-alert-warning js-layout-support-warning" style="display:none">
            </p>


            <?php 
        wp_nonce_field('wp_nonce_ddl_dismiss', 'wp_nonce_ddl_dismiss');
        ?>
        </div>



        <?php 
        $woocommerce_support_message = $wpddlayout->post_types_manager->check_layout_template_for_woocommerce($post_type_obj);
        ?>
        <?php 
        if ($woocommerce_support_message) {
            ?>

            <p class=" toolset-alert toolset-alert-warning js-layout-support-missing">
                <?php 
            echo $woocommerce_support_message;
            ?>
            </p>
        <?php 
        } elseif ($wpddlayout->post_types_manager->check_layout_template_page_exists($post_type_obj) === false) {
            ?>

            <p class=" toolset-alert toolset-alert-warning js-layout-support-missing">
                <?php 
            echo sprintf(__("A template file that supports layouts is not available.", 'ddl-layouts'), '<strong>"' . $post_type_obj->labels->singular_name . '"</strong>');
            ?>
<br>
                <?php 
            printf(__('Please check %shere%s to see how to set one up.', 'ddl-layouts'), '<a href="' . WPDLL_LEARN_ABOUT_SETTING_UP_TEMPLATE . '" target="_blank">', '</a>');
            ?>
            </p>
        <?php 
        }
        ?>


    <?php 
    }
 public function enqueue_editor_scripts()
 {
     wp_enqueue_script('page');
     wp_enqueue_script('editor');
     add_thickbox();
     wp_enqueue_script('media-upload');
     wp_enqueue_script('word-count');
     if (WPDD_Layouts::views_available()) {
         $deps = array('jquery', 'views-shortcodes-gui-script');
     } else {
         $deps = array('jquery');
     }
     wp_register_script('text_cell_js', WPDDL_RELPATH . '/inc/gui/editor/js/text-cell.js', $deps, WPDDL_VERSION, true);
     wp_enqueue_script('text_cell_js');
 }
<?php 
$layout = WPDD_Layouts::get_layout_settings_raw_not_cached($current);
$has_loop = is_object($layout) && property_exists($layout, 'has_loop') ? $layout->has_loop : false;
$disabled = $has_loop === false ? ' disabled ' : '';
$class = $disabled ? 'post-loops-list-in-layout-editor-alerted' : '';
?>

 <?php 
if (count($loops) > 0) {
    ?>
<div class="js-change-wrap-box">
 <h2 class="js-change-layout-use-section-title change-layout-use-section-title-outer"><span  class="change-layout-use-section-title js-collapse-group-individual"><?php 
    _e('Archives:', 'ddl-layouts');
    ?>
</span>
     <i class="icon-caret-down js-collapse-group-in-dialog change-layout-use-section-title-icon-collapse"></i></h2>

 <ul class="hidden post-types-list-in-layout-editor js-post-types-list-in-layout-editor js-change-layout-use-section change-layout-use-section <?php 
    echo $class;
    ?>
">

<li> <div class="alert-no-loops toolset-alert <?php 
    if ($has_loop) {
        ?>
hidden<?php 
    }
    ?>
">
       <!-- <i class="icon-remove js-remove-alert-message remove-alert-message" data-has_right_cell="<?php 
 function before_header_hook()
 {
     if (isset($_GET['layout_id'])) {
         $layout_selected = $_GET['layout_id'];
     } else {
         $post_id = get_the_ID();
         $layout_selected = WPDD_Layouts::get_layout_settings($post_id, false);
     }
     if ($layout_selected > 0) {
         //$layout_content = get_post_meta($layout_selected, WPDDL_LAYOUTS_SETTINGS);
         $layout_content = WPDD_Layouts::get_layout_settings_raw_not_cached($layout_selected, false);
         if (sizeof($layout_content) > 0) {
             $test = new WPDD_json2layout();
             $layout = $test->json_decode($layout_content[0]);
             $manager = new WPDD_layout_render_manager($layout);
             $renderer = $manager->get_renderer();
             $html = $renderer->render_to_html();
             echo $html;
         }
     }
 }
_e('Create and close', 'ddl-layouts');
?>
"><?php 
_e('Save and close', 'ddl-layouts');
?>
</button>
        </div>

	</div>

</div>


<?php 
require_once WPDDL_GUI_ABSPATH . 'dialogs/js/templates/child-layout-manager.box.tpl.php';
?>

<div class="ddl-dialogs-container">
	<div class="ddl-dialog auto-width" id="js-child-layout-box-container"></div>
	<textarea id="js-layout-children" <?php 
if (!WPDDL_DEBUG) {
    echo 'style="display:none"';
}
?>
><?php 
echo wp_json_encode(array('children_layouts' => WPDD_Layouts::get_layout_children($_GET['layout_id'])));
?>
</textarea>
</div>

 public function get_cell_info($template)
 {
     $template['cell-image-url'] = DDL_ICONS_SVG_REL_PATH . 'post-content.svg';
     $template['preview-image-url'] = DDL_ICONS_PNG_REL_PATH . 'post-content_expand-image.png';
     $template['name'] = sprintf(__('Post', 'ddl-layouts'), '');
     $template['description'] = __('Display the content of a page, post or custom type using styling from the theme.', 'ddl-layouts');
     $template['button-text'] = __('Assign Post content Box', 'ddl-layouts');
     $template['dialog-title-create'] = __('Create a new Post content Cell', 'ddl-layouts');
     $template['dialog-title-edit'] = __('Edit Post content Cell', 'ddl-layouts');
     $template['dialog-template'] = $this->_dialog_template();
     $template['category'] = sprintf(__('%s elements', 'ddl-layouts'), WPDD_Layouts::get_theme_name());
     $template['has_settings'] = false;
     return $template;
 }
function ddl_layout_slug_exists($slug)
{
    $res = WPDD_Layouts::get_post_ID_by_slug($slug, WPDDL_LAYOUTS_POST_TYPE);
    return $res != null && $res != 0 && $res != false;
}
 public function enqueue_editor_scripts()
 {
     // the Quicktags fallback implementation is contained into this script
     // It should be loaded from the icl_editor_addon_plugin.js script in common//
     // But is may not pack the method in older common versions, which also loaded it too late to use as a dependency
     // After a couple of join releases, remove the fallback from this script
     // And make it dependant of icl_editor-script
     // NOTE we still do not have a fallback for the Media Manager here...
     if (WPDD_Layouts::views_available()) {
         $deps = array('jquery', 'quicktags', 'wplink', 'views-shortcodes-gui-script');
     } else {
         $deps = array('jquery', 'quicktags', 'wplink');
     }
     wp_register_script('wp-content-template-editor', WPDDL_GUI_RELPATH . "editor/js/content-template-cell.js", $deps, null, true);
     wp_enqueue_script('wp-content-template-editor');
     wp_localize_script('wp-content-template-editor', 'DDLayout_content_template_strings', array('current_post' => __('This cell will display the content of the post which uses the layout.', 'ddl-layouts'), 'this_post' => __('This cell will display the content of a specific post.', 'ddl-layouts')));
 }
 public function remove_orphaned_ct_cells($cell_type, $property)
 {
     $this->remapped = false;
     $this->cell_type = $cell_type;
     $this->property = $property;
     $rows = $this->get_rows();
     $rows = $this->remap_rows($rows);
     if (null !== $rows) {
         $this->layout->Rows = $rows;
         WPDD_Layouts::save_layout_settings($this->layout_id, $this->layout);
     }
     return $this->removed;
 }
 public function create_layout_auto()
 {
     // verify permissions
     if (!current_user_can('manage_options') && WPDD_Layouts_Users_Profiles::user_can_create() && WPDD_Layouts_Users_Profiles::user_can_assign()) {
         die(__('Untrusted user', 'ddl-layouts'));
     }
     // verify nonce
     check_admin_referer('create_auto');
     // validate parameters
     $b_type = isset($_GET['type']) && preg_match('/^([-a-z0-9_]+)$/', $_GET['type']);
     $b_class = isset($_GET['class']) && preg_match('/^(archive|page)$/', $_GET['class']);
     $b_post_id = isset($_GET['post']) && (int) $_GET['post'] >= 0;
     // validate request
     if (!($b_type && $b_class && $b_post_id)) {
         die(__('Invalid parameters', 'ddl-layouts'));
     }
     // get parameters
     $type = $_GET['type'];
     $class = $_GET['class'];
     $post_id = (int) $_GET['post'];
     // enforce rules
     $b_page_archive = 'page' === $type && 'archive' === $class;
     if ($b_page_archive) {
         die(__('Not allowed', 'ddl-layouts'));
     }
     // prepare processing
     if ($post_id === 0) {
         $post_id = null;
     }
     $layout = null;
     $layout_id = 0;
     global $toolset_admin_bar_menu;
     $post_title = $toolset_admin_bar_menu->get_name_auto('layouts', $type, $class, $post_id);
     $title = sanitize_text_field(stripslashes_deep($post_title));
     $taxonomy = get_taxonomy($type);
     $is_tax = $taxonomy !== false;
     $post_type_object = get_post_type_object($type);
     $is_cpt = $post_type_object != null;
     /* Create a new Layout */
     global $wpddlayout;
     // Is there another Layout with the same name?
     $already_exists = $wpddlayout->does_layout_with_this_name_exist($title);
     if ($already_exists) {
         die(__('A layout with this name already exists. Please use a different name.', 'ddl-layouts'));
     }
     // Create a empty layout. No preset.
     // TODO: Pick the preset best suited (and check if Views is installed)
     $layout = $wpddlayout->create_layout(12, 'fluid');
     // Define layout parameters
     $layout['type'] = 'fluid';
     // layout_type
     $layout['cssframework'] = $wpddlayout->get_css_framework();
     $layout['template'] = '';
     $layout['parent'] = '';
     $layout['name'] = $title;
     $args = array('post_title' => $title, 'post_content' => '', 'post_status' => 'publish', 'post_type' => WPDDL_LAYOUTS_POST_TYPE);
     $layout_id = wp_insert_post($args);
     // force layout object to take right ID
     // @see WPDD_Layouts::create_layout_callback() @ wpddl.class.php
     $layout_post = get_post($layout_id);
     $layout['id'] = $layout_id;
     $layout['slug'] = $layout_post->post_name;
     // assign layout
     if ('archive' === $class) {
         if (preg_match('/^(home-blog|search|author|year|month|day)$/', $type)) {
             // Create a new Layout for X archives
             /* assign Layout to X archives */
             $layouts_wordpress_loop = sprintf('layouts_%s-page', $type);
             $wordpress_archive_loops = array($layouts_wordpress_loop);
             $wpddlayout->layout_post_loop_cell_manager->handle_archives_data_save($wordpress_archive_loops, $layout_id);
         } else {
             if ($is_tax) {
                 // Create a new Layout for Y archives
                 /* assign Layout to Y archives */
                 $layouts_taxonomy_loop = sprintf('layouts_taxonomy_loop_%s', $type);
                 $wordpress_archive_loops = array($layouts_taxonomy_loop);
                 $wpddlayout->layout_post_loop_cell_manager->handle_archives_data_save($wordpress_archive_loops, $layout_id);
             } else {
                 if ($is_cpt) {
                     // Create a new Layout for Z archives
                     /* assign Layout to Z archives */
                     $layouts_cpt = sprintf('layouts_cpt_%s', $type);
                     $wordpress_archive_loops = array($layouts_cpt);
                     $wpddlayout->layout_post_loop_cell_manager->handle_archives_data_save($wordpress_archive_loops, $layout_id);
                 } else {
                     die(__('An unexpected error happened.', 'ddl-layouts'));
                 }
             }
         }
     } else {
         if ('page' === $class) {
             if ('404' === $type) {
                 // Create a new Layout for Error 404 page
                 /* assign Layout to 404 page */
                 $wordpress_others_section = array('layouts_404_page');
                 $wpddlayout->layout_post_loop_cell_manager->handle_others_data_save($wordpress_others_section, $layout_id);
             } else {
                 if ('page' === $type) {
                     // Create a new Layout for 'Page Title'
                     /* assign Layout to Page */
                     $posts = array($post_id);
                     $wpddlayout->post_types_manager->update_post_meta_for_post_type($posts, $layout_id);
                 } else {
                     if ($is_cpt) {
                         // Create a new Layout for Ys
                         /* assign Layout to Y */
                         $post_types = array($type);
                         $wpddlayout->post_types_manager->handle_post_type_data_save($layout_id, $post_types, $post_types);
                         //$wpddlayout->post_types_manager->handle_set_option_and_bulk_at_once( $layout_id, $post_types, $post_types );
                     } else {
                         die(__('An unexpected error happened.', 'ddl-layouts'));
                     }
                 }
             }
         }
     }
     // update changes
     WPDD_Layouts::save_layout_settings($layout_id, $layout);
     // redirect to editor (headers already sent)
     $edit_link = $toolset_admin_bar_menu->get_edit_link('layouts', false, $type, $class, $layout_id);
     $exit_string = '<script type="text/javascript">' . 'window.location = "' . $edit_link . '";' . '</script>';
     exit($exit_string);
 }
                                    <div class="js-ddl-for-post-types-messages ddl-for-post-types-messages hidden">
                                        <?php 
printf(__('To assign this layout to a specific page, first create the layout and then assign it using the "Change how this layout is used" button in the layout editor.', 'ddl-layouts'), '');
?>
                                    </div>


								</li>
							</ul>

						</div>
					</fieldset>
				</li>
				<?php 
$parents = WPDD_Layouts::get_available_parents();
$hidden_parent_section = '';
if (count($parents) == 0) {
    $hidden_parent_section = ' hidden';
}
$default_parent = $wpddlayout->parents_options->get_options(WPDD_Layouts::PARENTS_OPTIONS);
?>
				<li class="js-set-parent-layout-row<?php 
echo $hidden_parent_section;
?>
">
					<fieldset>
						<legend><?php 
_e('Parent layout', 'ddl-layouts');
?>
</legend>
 public function update_layouts($path, $args)
 {
     global $wpddlayout;
     if (is_dir($path) && is_array($args) && count($args) > 0) {
         $layouts = glob($path . '/*.ddl');
         foreach ($layouts as $layout) {
             $file_details = pathinfo($layout);
             $layout_json = file_get_contents($layout);
             $filtered = $this->filter_import($file_details['filename'], json_decode(str_replace('\\\\"', '\\"', $layout_json)), $args);
             $layout = $filtered->layout;
             $layout_name = $filtered->name;
             $action = $filtered->do;
             if (is_null($layout) === false) {
                 $id = $this->layout_handle_save($layout, $layout_name, true, false, false);
                 if ($action === 'overwrite' && $id) {
                     WPDD_Layouts::reset_toolset_edit_last($id);
                 } else {
                     if ($action === 'duplicate' && $this->existing_layout) {
                         WPDD_Layouts::reset_toolset_edit_last($this->existing_layout);
                     }
                 }
             }
         }
         $wpddlayout->css_manager->import_css_from_theme($path);
     }
 }
 public function view_layout_from_editor_callback()
 {
     global $wpddlayout;
     if (user_can_assign_layouts() === false) {
         die(WPDD_Utils::ajax_caps_fail(__METHOD__));
     }
     if ($_POST && wp_verify_nonce($_POST['ddl-view-layout-nonce'], 'ddl-view-layout-nonce')) {
         $layout = WPDD_Layouts::get_layout_settings($_POST['layout_id'], true);
         if ($layout && isset($layout->has_child) && ($layout->has_child === 'true' || $layout->has_child === true)) {
             $send = wp_json_encode(array('message' => __("This layout contains a child layout and can't be viewed directly.", 'ddl-layouts') . '<br />' . __("You'll need to switch to one of the child layouts and view it.", 'ddl-layouts')));
         } else {
             $items = $this->get_where_used_x_amount_of_posts($_POST['layout_id'], false, 3);
             $posts = $items->posts;
             $layout_post_types = $wpddlayout->post_types_manager->get_layout_post_types($_POST['layout_id']);
             $loops = $wpddlayout->layout_post_loop_cell_manager->get_layout_loops($_POST['layout_id']);
             if (count($posts) === 0 && count($loops) === 0 && count($layout_post_types) === 0) {
                 $send = wp_json_encode(array('message' => __(sprintf("This layout is not assigned to any content. %sFirst, assign it to content and then you can view it on the site's front-end. %sYou can assign this layout to content at the bottom of the layout editor.", '<br>', '<br>'), 'ddl-layouts')));
             } else {
                 $items = array();
                 foreach ($layout_post_types as $post_type) {
                     $push = $this->get_x_posts_of_type($post_type, $_POST['layout_id'], 1);
                     if (is_array($push)) {
                         $posts = array_merge($posts, $push);
                     }
                 }
                 foreach ($posts as $post) {
                     $post_types = $wpddlayout->post_types_manager->get_post_types_from_wp();
                     $label = $post_types[$post->post_type]->labels->singular_name;
                     $labels = $post_types[$post->post_type]->labels->name;
                     $item = array('href' => get_permalink($post->ID), 'title' => $post->post_title, 'type' => $label, 'types' => $labels);
                     if (in_array($item, $items) === false) {
                         $items[] = $item;
                     }
                 }
                 foreach ($loops as $loop) {
                     $push = $wpddlayout->layout_post_loop_cell_manager->get_loop_display_object($loop);
                     if (null !== $push) {
                         array_push($items, $push);
                     }
                 }
                 $send = wp_json_encode(array('Data' => $items, 'message' => __(sprintf("This layout is not assigned to any content. %sFirst, assign it to content and then you can view it on the site's front-end. %sYou can assign this layout to content at the bottom of the layout editor.", '<br>', '<br>'), 'ddl-layouts'), 'no_preview_message' => __('No previews available', 'ddl-layouts')));
             }
         }
     } else {
         $send = wp_json_encode(array('error' => __(sprintf('Nonce problem: apparently we do not know where the request comes from. %s', __METHOD__), 'ddl-layouts')));
     }
     die($send);
 }