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; }
public function get_edit_link($plugin, $is_new, $type, $class, $post_id = null) { $edit_link = null; if ('layouts' === $plugin) { if ($is_new && WPDD_Layouts_Users_Profiles::user_can_create() && WPDD_Layouts_Users_Profiles::user_can_assign()) { $edit_link = wp_nonce_url(admin_url(sprintf('admin.php?page=dd_layouts_create_auto&type=%s&class=%s&post=%s', $type, $class, $post_id)), 'create_auto'); } else { if ($post_id > 0 && WPDD_Layouts_Users_Profiles::user_can_edit()) { // Layouts editor $edit_link = admin_url(sprintf('admin.php?page=dd_layouts_edit&layout_id=%s&action=edit', $post_id)); } } } else { if ('views' === $plugin && '404' != $type) { if ($is_new) { $edit_link = wp_nonce_url(admin_url(sprintf('admin.php?page=views_create_auto&type=%s&class=%s&post=%s', $type, $class, $post_id)), 'create_auto'); } else { if ($post_id > 0) { if ('archive' === $class) { // Views' WordPress Archive editor $edit_link = admin_url(sprintf('admin.php?page=view-archives-editor&view_id=%s', $post_id)); } else { if ('page' === $class) { // Views' Content Temaplate editor //$edit_link = admin_url( sprintf( 'post.php?action=edit&post=%s', $post_id ) ); $edit_link = esc_url_raw(add_query_arg(array('page' => WPV_CT_EDITOR_PAGE_NAME, 'ct_id' => esc_attr($post_id), 'action' => 'edit'), admin_url('admin.php'))); } } } } } } return $edit_link; }
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); }
function user_can_assign_layouts() { return WPDD_Layouts_Users_Profiles::user_can_assign(); }