__("Edit", 'admin-menu-tree-page-view'), "View" => __("View", 'admin-menu-tree-page-view'), "Add_new_page_here" => __("Add new page after", 'admin-menu-tree-page-view'), "Add_new_page_inside" => __("Add new page inside", 'admin-menu-tree-page-view'), "Untitled" => __("Untitled", 'admin-menu-tree-page-view'), ); wp_localize_script( "admin_menu_tree_page_view", 'amtpv_l10n', $oLocale); } function admin_menu_tree_page_view_admin_head() { } function admin_menu_tree_page_view_get_pages($args) { $defaults = array( "post_type" => "page", "parent" => "0", "post_parent" => "0", "numberposts" => "-1", "orderby" => "menu_order", "order" => "ASC", "post_status" => "any" ); $args = wp_parse_args( $args, $defaults ); $pages = get_posts($args); $output = ""; $str_child_output = ""; foreach ($pages as $one_page) { $edit_link = get_edit_post_link($one_page->ID); $title = get_the_title($one_page->ID); // add num of children to the title $post_children = get_children(array( "post_parent" => $one_page->ID, "post_type" => "page" )); $post_children_count = sizeof($post_children); // var_dump($post_children_count); if ($post_children_count>0) { $title .= " ($post_children_count)"; } $class = ""; if (isset($_GET["action"]) && $_GET["action"] == "edit" && isset($_GET["post"]) && $_GET["post"] == $one_page->ID) { $class = "current"; } $status_span = ""; if ($one_page->post_password) { $status_span .= ""; } if ($one_page->post_status != "publish") { $status_span .= "".__(ucfirst($one_page->post_status)).""; } // add css if we have childs $args_childs = $args; $args_childs["parent"] = $one_page->ID; $args_childs["post_parent"] = $one_page->ID; $args_childs["child_of"] = $one_page->ID; $str_child_output = admin_menu_tree_page_view_get_pages($args_childs); if ($post_children_count>0) { $class .= " admin-menu-tree-page-view-has-childs"; } // determine if ul should be opened or closed $isOpened = FALSE; // check cookie first $cookie_opened = isset($_COOKIE["admin-menu-tree-page-view-open-posts"]) ? $_COOKIE["admin-menu-tree-page-view-open-posts"] : ""; // 2,95,n $cookie_opened = explode(",", $cookie_opened); // if we are editing a post, we should see it in the tree, right? if ( isset($_GET["action"]) && "edit" == $_GET["action"] && isset($_GET["post"])) { // if post with id get[post] is a parent of the current post, show it if ($_GET["post"] != $one_page->ID) { $one_page_parents = get_post_ancestors($_GET["post"]); if (in_array($one_page->ID, $one_page_parents)) { $isOpened = TRUE; } } } if (in_array($one_page->ID, $cookie_opened) || $isOpened && $post_children_count>0) { $class .= " admin-menu-tree-page-view-opened"; } elseif ($post_children_count>0) { $class .= " admin-menu-tree-page-view-closed"; } $class .= " nestedSortable"; $output .= "
  • "; $output .= "$status_span"; $output .= $title; // add the view link, hidden, used in popup $permalink = get_permalink($one_page->ID); $output .= "$permalink"; $output .= ""; $output .= ""; // now fetch child articles $output .= $str_child_output; $output .= "
  • "; } // if this is a child listing, add ul if (isset($args["child_of"]) && $args["child_of"] && $output != "") { $output = ""; } return $output; } function admin_menu_tree_page_view_admin_menu() { load_plugin_textdomain('admin-menu-tree-page-view', false, "/admin-menu-tree-page-view/languages"); // add main menu #add_menu_page( "title", "Simple Menu Pages", "edit_pages", "admin-menu-tree-page-tree_main", "bonnyFunction", null, 5); // end link that is written automatically by WP, and begin ul $output = " "; // add subitems to main menu add_submenu_page("edit.php?post_type=page", "Admin Menu Tree Page View", $output, "edit_pages", "admin-menu-tree-page-tree", "admin_menu_tree_page_page"); } function admin_menu_tree_page_page() { ?>

    Admin Menu Tree Page View

    Nothing to see here. Move along! :)

    cms_tpv_add_page [pageID] => cms-tpv-1318 type ) */ $type = $_POST["type"]; $pageID = (int) $_POST["pageID"]; #$pageID = str_replace("cms-tpv-", "", $pageID); $page_title = trim($_POST["page_title"]); $post_type = $_POST["post_type"]; $wpml_lang = isset($_POST["wpml_lang"]) ? $_POST["wpml_lang"] : ""; if (!$page_title) { $page_title = __("New page", 'cms-tree-page-view'); } $ref_post = get_post($pageID); if ("after" == $type) { /* add page under/below ref_post */ // update menu_order of all pages below our page $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET menu_order = menu_order+2 WHERE post_parent = %d AND menu_order >= %d AND id <> %d ", $ref_post->post_parent, $ref_post->menu_order, $ref_post->ID ) ); // create a new page and then goto it $post_new = array(); $post_new["menu_order"] = $ref_post->menu_order+1; $post_new["post_parent"] = $ref_post->post_parent; $post_new["post_type"] = "page"; $post_new["post_status"] = "draft"; $post_new["post_title"] = $page_title; $post_new["post_content"] = ""; $post_new["post_type"] = $post_type; $newPostID = wp_insert_post($post_new); } else if ( "inside" == $type ) { /* add page inside ref_post */ // update menu_order, so our new post is the only one with order 0 $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET menu_order = menu_order+1 WHERE post_parent = %d", $ref_post->ID) ); $post_new = array(); $post_new["menu_order"] = 0; $post_new["post_parent"] = $ref_post->ID; $post_new["post_type"] = "page"; $post_new["post_status"] = "draft"; $post_new["post_title"] = $page_title; $post_new["post_content"] = ""; $post_new["post_type"] = $post_type; $newPostID = wp_insert_post($post_new); } if ($newPostID) { // return editlink for the newly created page $editLink = get_edit_post_link($newPostID, ''); if ($wpml_lang) { $editLink = add_query_arg("lang", $wpml_lang, $editLink); } echo $editLink; } else { // fail, tell js echo "0"; } #print_r($post_new); exit; }