/** * Create a layout with given name * * @param $name * * @return bool|int|WP_Error * @since 2.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'); $parent_post_name = ''; $parent_ID = apply_filters('ddl-get-default-' . WPDDL_Options::PARENTS_OPTIONS, WPDDL_Options::PARENTS_OPTIONS); if ($parent_ID) { $parent_post_name = WPDD_Layouts_Cache_Singleton::get_name_by_id($parent_ID); } // Define layout parameters $layout['type'] = 'fluid'; // layout_type $layout['cssframework'] = $wpddlayout->get_css_framework(); $layout['template'] = ''; $layout['parent'] = $parent_post_name; $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; }
function get_layout_from_id($id) { global $wpdb; $layout = WPDD_Layouts_Cache_Singleton::get_name_by_id($id); $result = null; if ($layout) { $result = new stdClass(); $result->ID = $id; $result->post_name = $layout; } if ($result) { $layout_json = self::get_layout_settings($result->ID); $json_parser = new WPDD_json2layout(); $layout = $json_parser->json_decode($layout_json); $layout->set_post_id($result->ID); $layout->set_post_slug($result->post_name); } return $layout; }