public static function get_post_ID_by_slug($slug, $post_type = 'post')
 {
     global $wpdb;
     if (!$slug) {
         return null;
     }
     if (WPDDL_LAYOUTS_POST_TYPE == $post_type) {
         return WPDD_Layouts_Cache_Singleton::get_id_by_name($slug);
     }
     return $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type=%s AND post_name=%s", $post_type, $slug));
 }
 function import_layouts_from_theme($source_dir, $overwrite_assignment = false)
 {
     global $wpddlayout;
     if (is_dir($source_dir)) {
         $layouts = glob($source_dir . '/*.ddl');
         foreach ($layouts as $layout) {
             $file_details = pathinfo($layout);
             $layout_name = $file_details['filename'];
             $layout_json = file_get_contents($layout);
             $layout = json_decode(str_replace('\\\\"', '\\"', $layout_json));
             $layout->file_name = $layout_name;
             $layouts_array[] = $layout;
         }
         usort($layouts_array, array($this, 'sortLayoutsFromFile'));
         $res = array();
         foreach ($layouts_array as $layout) {
             $layout_name = $layout->file_name;
             unset($layout->file_name);
             if (is_null($layout) === false) {
                 $layout_array = WPDD_Layouts_Theme::fix_toolset_association_on_import_export($layout, 'import');
                 // make sure we have the right data type
                 $layout_array = (array) $layout_array;
                 $id = WPDD_Layouts_Cache_Singleton::get_id_by_name($layout_name);
                 if (!$id) {
                     $postarr = array('post_title' => is_object($layout) ? $layout->name : $layout['name'], 'post_name' => $layout_name, 'post_content' => '', 'post_status' => 'publish', 'post_type' => WPDDL_LAYOUTS_POST_TYPE);
                     $post_id = wp_insert_post($postarr);
                     $layout_array['id'] = $post_id;
                     $save = WPDD_Layouts::save_layout_settings($post_id, $layout_array);
                     if ($save) {
                         $res[] = $post_id;
                     }
                     if ($overwrite_assignment) {
                         //Archives
                         if (isset($layout_array['archives']) && count($layout_array['archives']) > 0) {
                             $wpddlayout->layout_post_loop_cell_manager->handle_archives_data_save($layout_array['archives'], $post_id);
                             $wpddlayout->layout_post_loop_cell_manager->handle_archives_data_save($layout_array['archives'], $post_id);
                         }
                         //Post Types
                         if (isset($layout_array['post_types']) && count($layout_array['post_types']) > 0) {
                             $to_set = array();
                             $to_bulk = array();
                             foreach ($layout->post_types as $post_type => $bulk) {
                                 if (post_type_exists($post_type)) {
                                     if ($bulk) {
                                         $to_bulk[] = $post_type;
                                     }
                                     $to_set[] = $post_type;
                                 }
                             }
                             $wpddlayout->post_types_manager->handle_set_option_and_bulk_at_once($post_id, $to_set, $to_bulk, false);
                         }
                         if (isset($layout_array['posts']) && count($layout_array['posts']) > 0) {
                             $this->write_single_posts_assignments($post_id, $layout, $overwrite_assignment);
                         }
                     }
                 }
             }
         }
         $save = $wpddlayout->css_manager->import_css_from_theme($source_dir);
         if ($save) {
             $res[] = 'CSS';
         }
     }
     return $res;
 }
 function get_layout_id_for_render($layout, $args = null)
 {
     $options = is_null($args) === false && is_array($args) === true ? (object) $args : false;
     $allow_overrides = $options && property_exists($options, 'allow_overrides') ? $options->allow_overrides : true;
     $id = 0;
     if ($layout) {
         $id = WPDD_Layouts_Cache_Singleton::get_id_by_name($layout);
     }
     if ($allow_overrides === true) {
         // when blog is front
         if (is_front_page() && is_home() && $this->main->layout_post_loop_cell_manager->get_option(WPDD_layout_post_loop_cell_manager::OPTION_BLOG)) {
             $id = $this->main->layout_post_loop_cell_manager->get_option(WPDD_layout_post_loop_cell_manager::OPTION_BLOG);
             // when blog is not front
         } elseif (is_home() && !is_front_page() && !is_page() && $this->main->layout_post_loop_cell_manager->get_option(WPDD_layout_post_loop_cell_manager::OPTION_BLOG)) {
             $id = $this->main->layout_post_loop_cell_manager->get_option(WPDD_layout_post_loop_cell_manager::OPTION_BLOG);
         } elseif (is_post_type_archive()) {
             $post_type_object = $this->get_queried_object();
             if ($post_type_object && property_exists($post_type_object, 'public') && $post_type_object->public && $this->main->layout_post_loop_cell_manager->get_option(WPDD_layout_post_loop_cell_manager::OPTION_TYPES_PREFIX . $post_type_object->name)) {
                 $id = $this->main->layout_post_loop_cell_manager->get_option(WPDD_layout_post_loop_cell_manager::OPTION_TYPES_PREFIX . $post_type_object->name);
             }
         } elseif (is_archive() && (is_tax() || is_category() || is_tag())) {
             $term = $this->get_queried_object();
             if ($term && property_exists($term, 'taxonomy') && $this->main->layout_post_loop_cell_manager->get_option(WPDD_layout_post_loop_cell_manager::OPTION_TAXONOMY_PREFIX . $term->taxonomy)) {
                 $id = $this->main->layout_post_loop_cell_manager->get_option(WPDD_layout_post_loop_cell_manager::OPTION_TAXONOMY_PREFIX . $term->taxonomy);
             }
         } elseif (is_search() && $this->main->layout_post_loop_cell_manager->get_option(WPDD_layout_post_loop_cell_manager::OPTION_SEARCH)) {
             $id = $this->main->layout_post_loop_cell_manager->get_option(WPDD_layout_post_loop_cell_manager::OPTION_SEARCH);
         } elseif (is_author() && $this->main->layout_post_loop_cell_manager->get_option(WPDD_layout_post_loop_cell_manager::OPTION_AUTHOR)) {
             $author = WPDD_layout_post_loop_cell_manager::OPTION_AUTHOR;
             $id = $this->main->layout_post_loop_cell_manager->get_option($author);
         } elseif (is_year() && $this->main->layout_post_loop_cell_manager->get_option(WPDD_layout_post_loop_cell_manager::OPTION_YEAR)) {
             $id = $this->main->layout_post_loop_cell_manager->get_option(WPDD_layout_post_loop_cell_manager::OPTION_YEAR);
         } elseif (is_month() && $this->main->layout_post_loop_cell_manager->get_option(WPDD_layout_post_loop_cell_manager::OPTION_MONTH)) {
             $id = $this->main->layout_post_loop_cell_manager->get_option(WPDD_layout_post_loop_cell_manager::OPTION_MONTH);
         } elseif (is_day() && $this->main->layout_post_loop_cell_manager->get_option(WPDD_layout_post_loop_cell_manager::OPTION_DAY)) {
             $id = $this->main->layout_post_loop_cell_manager->get_option(WPDD_layout_post_loop_cell_manager::OPTION_DAY);
         } elseif (is_404() && $this->main->layout_post_loop_cell_manager->get_option(WPDD_layout_post_loop_cell_manager::OPTION_404)) {
             $id = $this->main->layout_post_loop_cell_manager->get_option(WPDD_layout_post_loop_cell_manager::OPTION_404);
         } else {
             global $post;
             if ($post !== null) {
                 $post_id = $post->ID;
                 $layout_selected = get_post_meta($post_id, WPDDL_LAYOUTS_META_KEY, true);
                 if ($layout_selected) {
                     $id = WPDD_Layouts_Cache_Singleton::get_id_by_name($layout_selected);
                     $option = $this->main->post_types_manager->get_layout_to_type_object($post->post_type);
                     if (is_object($option) && property_exists($option, 'layout_id') && (int) $option->layout_id === (int) $id) {
                         $id = $option->layout_id;
                     }
                 }
             }
         }
     }
     return apply_filters('get_layout_id_for_render', (int) $id, $layout);
 }