cms_tpv_add_pages
[cms_tpv_add_new_pages_names] => Array
(
[0] => xxxxx
[1] => yyyy
[2] =>
)
[cms_tpv_add_type] => inside
[cms_tpv_add_status] => draft
[lang] => de
)
*/
$post_position = $_POST["cms_tpv_add_type"];
$post_status = $_POST["cms_tpv_add_status"];
$post_names = (array) $_POST["cms_tpv_add_new_pages_names"];
$ref_post_id = (int) $_POST["ref_post_id"];
$lang = $_POST["lang"];
// Check nonce
if ( ! check_admin_referer("cms-tpv-add-pages") ) {
wp_die( __( 'Cheatin’ uh?' ) );
}
// If lang variable is set, then set some more wpml-related post/get-variables
if ($lang) {
// post seems to fix creating new posts in selcted lang
$_POST["icl_post_language"] = $lang;
// $_GET["lang"] = $lang;
}
// make sure the status is publish and nothing else (yes, perhaps I named it bad elsewhere)
if ("published" === $post_status) $post_status = "publish";
// remove possibly empty posts
$arr_post_names = array();
foreach ($post_names as $one_post_name) {
if ( trim($one_post_name) ) {
$arr_post_names[] = $one_post_name;
}
}
$arr_post_names_count = sizeof($arr_post_names);
// check that there are pages left
if (empty($arr_post_names)) die("Error: no pages to add.");
$ref_post = get_post($ref_post_id);
if (NULL === $ref_post) die("Error: could not load reference post.");
// Make room for our new pages
// Get all pages at a level level and loop until our reference page
// and then all pages after that one will get it's menu_order
// increased by the same number as the number of new posts we're gonna add
$ok_to_continue_by_permission = TRUE;
$post_type_object = get_post_type_object($ref_post->post_type);
$post_parent = 0;
if ("after" === $post_position) {
$post_parent = $ref_post->post_parent;
$ok_to_continue_by_permission = apply_filters("cms_tree_page_view_post_user_can_add_after", current_user_can( $post_type_object->cap->create_posts, $ref_post_id), $ref_post_id);
} elseif ("inside" === $post_position) {
$post_parent = $ref_post->ID;
$ok_to_continue_by_permission = apply_filters("cms_tree_page_view_post_user_can_add_inside", current_user_can( $post_type_object->cap->create_posts, $ref_post_id), $ref_post_id);
}
if ( ! $ok_to_continue_by_permission ) {
wp_die( __( 'Cheatin’ uh?' ) );
return FALSE;
}
// $user_can_edit_page = apply_filters("cms_tree_page_view_post_can_edit", current_user_can( $post_type_object->cap->edit_post, $ref_post_id), $ref_post_id);
/*
perhaps for wpml:
suppress_filters=0
*/
$args = array(
"post_status" => "any",
"post_type" => $ref_post->post_type,
"numberposts" => -1,
"offset" => 0,
"orderby" => 'menu_order',
'order' => 'asc',
'post_parent' => $post_parent,
"suppress_filters" => FALSE
);
//if ($lang) $args["lang"] = $lang;
$posts = get_posts($args);
#sf_d($_GET["lang"]);sf_d($args);sf_d($posts);exit;
// If posts exist at this level, make room for our new pages by increasing the menu order
if (sizeof($posts) > 0) {
if ("after" === $post_position) {
$has_passed_ref_post = FALSE;
foreach ($posts as $one_post) {
if ($has_passed_ref_post) {
$post_update = array(
"ID" => $one_post->ID,
"menu_order" => $one_post->menu_order + $arr_post_names_count,
"post_author" => $one_post->post_author,
"post_modified" => $one_post->post_modified, //--- Added 2015-01-09 ---
"post_modified_gmt" => $one_post->post_modified_gmt, //--- Added 2015-01-09 ---
);
$return_id = wp_update_post($post_update);
if (0 ===$return_id) die( "Error: could not update post with id " . $post_update->ID . "
Technical details: " . print_r($post_update) );
}
if ( ! $has_passed_ref_post && $ref_post->ID === $one_post->ID ) {
$has_passed_ref_post = TRUE;
}
}
$new_menu_order = $ref_post->menu_order;
} elseif ("inside" === $post_position) {
// in inside, place at beginning
// so just get first post and use that menu order as base
$new_menu_order = $posts[0]->menu_order - $arr_post_names_count;
}
} else {
// no posts, start at 0
$new_menu_order = 0;
}
$post_parent_id = NULL;
if ("after" === $post_position) {
$post_parent_id = $ref_post->post_parent;
} elseif ("inside" === $post_position) {
$post_parent_id = $ref_post->ID;
}
// Done maybe updating menu orders, add the new pages
$arr_added_pages_ids = array();
foreach ($arr_post_names as $one_new_post_name) {
$new_menu_order++;
$newpost_args = array(
"menu_order" => $new_menu_order,
"post_parent" => $post_parent_id,
"post_status" => ( ('publish' == $post_status) && !current_user_can('publish_posts') ? 'pending' : $post_status ),
"post_title" => $one_new_post_name,
"post_type" => $ref_post->post_type,
);
$new_post_id = wp_insert_post($newpost_args);
if (0 === $new_post_id) {
die("Error: could not add post");
}
$arr_added_pages_ids[] = $new_post_id;
}
// Done. Redirect to the first page created.
$first_post_edit_link = get_edit_post_link($arr_added_pages_ids[0], "");
wp_redirect($first_post_edit_link);
exit;
}
/**
* Output and add hooks in head
*/
function cms_tpv_admin_head() {
if (!cms_tpv_is_one_of_our_pages()) return;
cms_tpv_setup_postsoverview();
global $cms_tpv_view;
if (isset($_GET["cms_tpv_view"])) {
$cms_tpv_view = htmlspecialchars($_GET["cms_tpv_view"]);
} else {
$cms_tpv_view = "all";
}
?>
id, "_page_cms-tpv-page-{$one_post_type}") !== FALSE) {
$is_plugin_page = TRUE;
break;
}
}
// Check if current page is one of the ones defined in $options["postsoverview"]
if ($current_screen->base === "edit" && in_array($current_screen->post_type, $options["postsoverview"])) {
$is_plugin_page = TRUE;
}
if ($current_screen->id === "settings_page_cms-tpv-options") {
// Is settings page for plugin
$is_plugin_page = TRUE;
} elseif ($current_screen->id === "dashboard" && !empty($options["dashboard"])) {
// At least one post type is enabled to be visible on dashboard
$is_plugin_page = TRUE;
}
return $is_plugin_page;
}
/**
* Add styles and scripts to pages that use the plugin
*/
function cms_admin_enqueue_scripts() {
if (cms_tpv_is_one_of_our_pages()) {
// renamed from cookie to fix problems with mod_security
wp_enqueue_script( "jquery-cookie", CMS_TPV_URL . "scripts/jquery.biscuit.js", array("jquery"));
wp_enqueue_script( "jquery-ui-sortable");
wp_enqueue_script( "jquery-jstree", CMS_TPV_URL . "scripts/jquery.jstree.js", false, CMS_TPV_VERSION);
wp_enqueue_script( "jquery-alerts", CMS_TPV_URL . "scripts/jquery.alerts.js", false, CMS_TPV_VERSION);
// wp_enqueue_script( "hoverIntent");
wp_enqueue_script( "cms_tree_page_view", CMS_TPV_URL . "scripts/cms_tree_page_view.js", false, CMS_TPV_VERSION);
wp_enqueue_style( "cms_tpv_styles", CMS_TPV_URL . "styles/styles.css", false, CMS_TPV_VERSION );
wp_enqueue_style( "jquery-alerts", CMS_TPV_URL . "styles/jquery.alerts.css", false, CMS_TPV_VERSION );
$oLocale = array(
"Enter_title_of_new_page" => __("Enter title of new page", 'cms-tree-page-view'),
"child_pages" => __("child pages", 'cms-tree-page-view'),
"Edit_page" => __("Edit page", 'cms-tree-page-view'),
"View_page" => __("View page", 'cms-tree-page-view'),
"Edit" => __("Edit", 'cms-tree-page-view'),
"View" => __("View", 'cms-tree-page-view'),
"Add_page" => __("Add page", 'cms-tree-page-view'),
"Add_new_page_after" => __("Add new page after", 'cms-tree-page-view'),
"after" => __("after", 'cms-tree-page-view'),
"inside" => __("inside", 'cms-tree-page-view'),
"Can_not_add_sub_page_when_status_is_draft" => __("Sorry, can't create a sub page to a page with status \"draft\".", 'cms-tree-page-view'),
"Can_not_add_sub_page_when_status_is_trash" => __("Sorry, can't create a sub page to a page with status \"trash\".", 'cms-tree-page-view'),
"Can_not_add_page_after_when_status_is_trash" => __("Sorry, can't create a page after a page with status \"trash\".", 'cms-tree-page-view'),
"Add_new_page_inside" => __("Add new page inside", 'cms-tree-page-view'),
"Status_draft" => __("draft", 'cms-tree-page-view'),
"Status_future" => __("future", 'cms-tree-page-view'),
"Status_password" => __("protected", 'cms-tree-page-view'), // is "protected" word better than "password" ?
"Status_pending" => __("pending", 'cms-tree-page-view'),
"Status_private" => __("private", 'cms-tree-page-view'),
"Status_trash" => __("trash", 'cms-tree-page-view'),
"Status_draft_ucase" => ucfirst( __("draft", 'cms-tree-page-view') ),
"Status_future_ucase" => ucfirst( __("future", 'cms-tree-page-view') ),
"Status_password_ucase" => ucfirst( __("protected", 'cms-tree-page-view') ), // is "protected" word better than "password" ?
"Status_pending_ucase" => ucfirst( __("pending", 'cms-tree-page-view') ),
"Status_private_ucase" => ucfirst( __("private", 'cms-tree-page-view') ),
"Status_trash_ucase" => ucfirst( __("trash", 'cms-tree-page-view') ),
"Password_protected_page" => __("Password protected page", 'cms-tree-page-view'),
"Adding_page" => __("Adding page...", 'cms-tree-page-view'),
"Adding" => __("Adding ...", 'cms-tree-page-view'),
"No posts found" => __("No posts found.", 'cms-tree-page-view')
);
wp_localize_script( "cms_tree_page_view", 'cmstpv_l10n', $oLocale);
}
}
function cms_tpv_load_textdomain() {
// echo "load textdomain";
if (is_admin()) {
load_plugin_textdomain('cms-tree-page-view', WP_CONTENT_DIR . "/plugins/languages", "/cms-tree-page-view/languages");
}
}
function cms_tpv_admin_init() {
// DEBUG
//wp_enqueue_script( "jquery-hotkeys" );
// add row to plugin page
add_filter( 'plugin_row_meta', 'cms_tpv_set_plugin_row_meta', 10, 2 );
// @todo: register settings
#add_settings_section("cms_tree_page_view_settings", "cms_tree_page_view", "", "");
#register_setting( 'cms_tree_page_view_settings', "post-type-dashboard-post" );
// Add little promo box
add_action("cms_tree_page_view/before_wrapper", "cms_tpv_promo_above_wrapper");
}
function cms_tpv_promo_above_wrapper() {
// enable this to show box while testing
//update_option('cms_tpv_show_promo', 1);
if ( isset($_GET["action"]) && "cms_tpv_remove_promo" == $_GET["action"] ) {
$show_box = 0;
update_option('cms_tpv_show_promo', $show_box);
} else {
$show_box = get_option('cms_tpv_show_promo', 1);
}
// Never show on dashboard, becuase highly annoying
$current_screen = get_current_screen();
if ( $current_screen->id === "dashboard" ) {
$show_box = false;
}
if ( ! $show_box ) {
return;
}
?>
Thanks for using CMS Tree Page View!
Do you like this plugin? Then give it a nice review!
Want to see who in you team edited what and when? Then Simple History is the plugin you need!
' . __("No posts found.", 'cms-tree-page-view') . '
";print_r($pages_as_objects);exit; $pages_as_objects = apply_filters('get_pages', $pages_as_objects, $get_posts_args); return $pages_as_objects; } function cms_tpv_parse_query($q) { } /** * Output JSON for the children of a node * $arrOpenChilds = array with id of pages to open children on */ function cms_tpv_print_childs($pageID, $view = "all", $arrOpenChilds = null, $post_type) { $arrPages = cms_tpv_get_pages("parent=$pageID&view=$view&post_type=$post_type"); if ($arrPages) { global $current_screen; $screen = convert_to_screen("edit"); #return; // If this is set to null then quick/bul edit stops working on posts (not pages) // If did set it to null sometime. Can't remember why... // $screen->post_type = null; $post_type_object = get_post_type_object($post_type); ob_start(); // some plugins, for example magic fields, return javascript and things here. we're not compatible with that, so just swallow any output $posts_columns = get_column_headers($screen); ob_get_clean(); unset($posts_columns["cb"], $posts_columns["title"], $posts_columns["author"], $posts_columns["categories"], $posts_columns["tags"], $posts_columns["date"]); global $post; // Translated post statuses $post_statuses = get_post_statuses(); ?>[ID ); $tmpPost = $post; $post = $onePage; $page_id = $onePage->ID; $arrChildPages = NULL; $editLink = get_edit_post_link($onePage->ID, 'notDisplay'); $content = esc_html($onePage->post_content); $content = str_replace(array("\n","\r"), "", $content); $hasChildren = false; // if viewing trash, don't get children. we watch them "flat" instead if ($view == "trash") { } else { $arrChildPages = cms_tpv_get_pages("parent={$onePage->ID}&view=$view&post_type=$post_type"); } if ( !empty($arrChildPages) ) { $hasChildren = true; } // if no children, output no state $strState = '"state": "closed",'; if (!$hasChildren) { $strState = ''; } // type of node $rel = $onePage->post_status; if ($onePage->post_password) { $rel = "password"; } // modified time $post_modified_time = strtotime($onePage->post_modified); $post_modified_time = date_i18n(get_option('date_format'), $post_modified_time, false); // last edited by setup_postdata($post); $post_author = cms_tpv_get_the_modified_author(); if (empty($post_author)) { $post_author = __("Unknown user", 'cms-tree-page-view'); } $title = get_the_title($onePage->ID); // so hooks and stuff will do their work $title = apply_filters("cms_tree_page_view_post_title", $title, $onePage); if (empty($title)) { $title = __(""; } } /** * Install function * Called from hook register_activation_hook() */ function cms_tpv_install() { // after upgrading/re-enabling the plugin, also re-enable the little please-donate-box update_option('cms_tpv_show_annoying_little_box', 1); update_option('cms_tpv_show_promo', 1); // first install or pre custom posts version: // make sure pages are enabled by default cms_tpv_setup_defaults(); // set to current version update_option('cms_tpv_version', CMS_TPV_VERSION); } function cms_tvp_setup_caps() { // Add necessary capabilities to allow moving tree of cms_tpv $roles = array( 'administrator' => array(CMS_TPV_MOVE_PERMISSION), 'editor' => array(CMS_TPV_MOVE_PERMISSION), // 'author' => array(CMS_TPV_MOVE_PERMISSION), // 'contributor' => array(CMS_TPV_MOVE_PERMISSION) ); foreach ( $roles as $role => $caps ) { cms_tpv_add_caps_to_role( $role, $caps ); } } function cms_tpv_uninstall() { // Remove capabilities to disallow moving tree of cms_tpv $roles = array( 'administrator' => array(CMS_TPV_MOVE_PERMISSION), 'editor' => array(CMS_TPV_MOVE_PERMISSION) ); foreach ( $roles as $role => $caps ) { cms_tpv_remove_caps_from_role( $role, $caps ); } } /** * Adds an array of capabilities to a role. */ function cms_tpv_add_caps_to_role( $role, $caps ) { global $wp_roles; if ( $wp_roles->is_role( $role ) ) { $role = get_role( $role ); foreach ( $caps as $cap ) $role->add_cap( $cap ); } } /** * Remove an array of capabilities from role. */ function cms_tpv_remove_caps_from_role( $role, $caps ) { global $wp_roles; if ( $wp_roles->is_role( $role ) ) { $role = get_role( $role ); foreach ( $caps as $cap ) $role->remove_cap( $cap ); } } // cms_tpv_install(); /** * setup some defaults */ function cms_tpv_setup_defaults() { // check and update version $version = get_option('cms_tpv_version', 0); #$version = 0; // uncomment to test default settings if ($version <= 0) { #error_log("tree: setup defaults, beacuse db version less than 0"); $options = array(); // Add pages to both dashboard and menu $options["dashboard"] = array("page"); // since 0.10.1 enable menu for all hierarchical custom post types // since 1.2 also enable on post overview page $post_types = get_post_types(array( "show_ui" => TRUE, "hierarchical" => TRUE ), "objects"); foreach ($post_types as $one_post_type) { $options["menu"][] = $one_post_type->name; $options["postsoverview"][] = $one_post_type->name; } $options["menu"] = array_unique($options["menu"]); $options["postsoverview"] = array_unique($options["postsoverview"]); update_option('cms_tpv_options', $options); } } /** * when plugins are loaded, check if current plugin version is same as stored * if not = it's an upgrade. right? */ function cms_tpv_plugins_loaded($a) { $installed_version = get_option('cms_tpv_version', 0); //echo "installed_version in options table: $installed_version"; //echo "", 'cms-tree-page-view'); } $arr_page_css_styles = array(); $user_can_edit_page = apply_filters("cms_tree_page_view_post_can_edit", current_user_can( $post_type_object->cap->edit_post, $page_id), $page_id); $user_can_add_inside = apply_filters("cms_tree_page_view_post_user_can_add_inside", current_user_can( $post_type_object->cap->create_posts, $page_id), $page_id); $user_can_add_after = apply_filters("cms_tree_page_view_post_user_can_add_after", current_user_can( $post_type_object->cap->create_posts, $page_id), $page_id); if ( $user_can_edit_page ) { $arr_page_css_styles[] = "cms_tpv_user_can_edit_page_yes"; } else { $arr_page_css_styles[] = "cms_tpv_user_can_edit_page_no"; } if ( $user_can_add_inside ) { $arr_page_css_styles[] = "cms_tpv_user_can_add_page_inside_yes"; } else { $arr_page_css_styles[] = "cms_tpv_user_can_add_page_inside_no"; } if ( $user_can_add_after ) { $arr_page_css_styles[] = "cms_tpv_user_can_add_page_after_yes"; } else { $arr_page_css_styles[] = "cms_tpv_user_can_add_page_after_no"; } $page_css = join(" ", $arr_page_css_styles); // fetch columns $str_columns = ""; foreach ( $posts_columns as $column_name => $column_display_name ) { $col_name = $column_display_name; if ($column_name == "comments") { $col_name = __("Comments"); } $str_columns .= " $col_name "; $str_columns .= ""; if ($column_name == "comments") { $str_columns .= ' "; } if ($str_columns) { $str_columns = "'; $left = get_pending_comments_num( $onePage->ID ); $pending_phrase = sprintf( __('%s pending'), number_format( $left ) ); $pending_phrase2 = ""; if ($left) { $pending_phrase2 = " + $left " . __("pending"); } if ( $left ) { $str_columns .= ''; } ob_start(); comments_number("" . _x('0', 'comment count') . "$pending_phrase2", "" . _x('1', 'comment count') . "$pending_phrase2", "" . _x('%', 'comment count') . "$pending_phrase2"); $str_columns .= ob_get_clean(); if ( $left ) { $str_columns .= ''; } $str_columns .= ""; } else { ob_start(); do_action('manage_pages_custom_column', $column_name, $onePage->ID); $str_columns .= ob_get_clean(); } $str_columns .= "$str_columns
"; } $str_columns = json_encode($str_columns); ?> { "data": { "title": , "attr": { "href": "" ID ?>" */ ?> }"*/?> }, "attr": { ", */ ?> "id": "cms-tpv-ID ?>", ", */ ?> "class": "" }, "metadata": { "id": "cms-tpv-ID ?>", "post_id": "ID ?>", "post_type": "post_type ?>", "post_status": "post_status ?>", "post_status_translated": "post_status]) ? $post_statuses[$onePage->post_status] : $onePage->post_status ?>", "rel": "", "childCount": , "permalink": "ID)) ?>", "editlink": "", "modified_time": "", "modified_author": "", "columns": , "user_can_edit_page": "", "user_can_add_page_inside": "", "user_can_add_page_after": "", "post_title": } ID, $arrOpenChilds)) { ?>, "children": ID, $view, $arrOpenChilds, $post_type); ?> } ,]cap->edit_posts ) ) { die( __( 'Cheatin’ uh?' ) ); } if ($action) { if ($search) { // find all pages that contains $search // collect all post_parent // for each parent id traverse up until post_parent is 0, saving all ids on the way // what to search: since all we see in the GUI is the title, just search that global $wpdb; $sqlsearch = "%{$search}%"; // feels bad to leave out the "'" in the query, but prepare seems to add it..?? $sql = $wpdb->prepare("SELECT id, post_parent FROM $wpdb->posts WHERE post_type = 'page' AND post_title LIKE %s", $sqlsearch); $hits = $wpdb->get_results($sql); $arrNodesToOpen = array(); foreach ($hits as $oneHit) { $arrNodesToOpen[] = $oneHit->post_parent; } $arrNodesToOpen = array_unique($arrNodesToOpen); $arrNodesToOpen2 = array(); // find all parents to the arrnodestopen foreach ($arrNodesToOpen as $oneNode) { if ($oneNode > 0) { // not at top so check it out $parentNodeID = $oneNode; while ($parentNodeID != 0) { $hits = $wpdb->get_results($sql); $sql = "SELECT id, post_parent FROM $wpdb->posts WHERE id = $parentNodeID"; $row = $wpdb->get_row($sql); $parentNodeID = $row->post_parent; $arrNodesToOpen2[] = $parentNodeID; } } } $arrNodesToOpen = array_merge($arrNodesToOpen, $arrNodesToOpen2); $sReturn = ""; #foreach ($arrNodesToOpen as $oneNodeID) { # $sReturn .= "cms-tpv-{$oneNodeID},"; #} #$sReturn = preg_replace("/,$/", "", $sReturn); foreach ($arrNodesToOpen as $oneNodeID) { $sReturn .= "\"#cms-tpv-{$oneNodeID}\","; } $sReturn = preg_replace('/,$/', "", $sReturn); if ($sReturn) { $sReturn = "[" . $sReturn . "]"; } if ($sReturn) { echo $sReturn; } else { // if no hits echo "[]"; } exit; } else { // regular get $id = (isset($_GET["id"])) ? $_GET["id"] : null; $id = (int) str_replace("cms-tpv-", "", $id); $jstree_open = array(); if ( isset( $_COOKIE["jstree_open"] ) ) { $jstree_open = $_COOKIE["jstree_open"]; // like this: [jstree_open] => cms-tpv-1282,cms-tpv-1284,cms-tpv-3 #var_dump($jstree_open); string(22) "#cms-tpv-14,#cms-tpv-2" $jstree_open = explode( ",", $jstree_open ); for( $i=0; $isave_post_actions if ($node_id && $ref_node_id) { $post_node = get_post($node_id); $post_ref_node = get_post($ref_node_id); $post_node_post_type_object = get_post_type_object($post_node->post_type); $post_ref_node_post_type_object = get_post_type_object($post_ref_node->post_type); $user_can_edit_post_node_post = apply_filters("cms_tree_page_view_post_can_edit", current_user_can( $post_node_post_type_object->cap->edit_post, $node_id), $node_id); $user_can_edit_post_ref_node_post = apply_filters("cms_tree_page_view_post_can_edit", current_user_can( $post_ref_node_post_type_object->cap->edit_post, $ref_node_id), $ref_node_id); // Check that user is allowed to edit both pages thare are to be moved if (!$user_can_edit_post_node_post || !$user_can_edit_post_ref_node_post) { exit; } // first check that post_node (moved post) is not in trash. we do not move them if ($post_node->post_status == "trash") { exit; } if ( "inside" == $type ) { // post_node is moved inside ref_post_node // add ref_post_node as parent to post_node and set post_nodes menu_order to 0 // @todo: shouldn't menu order of existing items be changed? $post_to_save = array( "ID" => $post_node->ID, "menu_order" => 0, "post_parent" => $post_ref_node->ID, "post_type" => $post_ref_node->post_type ); wp_update_post( $post_to_save ); echo "did inside"; } elseif ( "before" == $type ) { // post_node is placed before ref_post_node // update menu_order of all pages with a menu order more than or equal ref_node_post and with the same parent as ref_node_post // we do this so there will be room for our page if it's the first page // so: no move of individial posts yet $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET menu_order = menu_order+1 WHERE post_type = %s AND post_parent = %d", $post_ref_node->post_type, $post_ref_node->post_parent ) ); // update menu order with +1 for all pages below ref_node, this should fix the problem with "unmovable" pages because of // multiple pages with the same menu order (...which is not the fault of this plugin!) $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET menu_order = menu_order+1 WHERE post_type = %s AND menu_order >= %d", $post_ref_node->post_type, $post_ref_node->menu_order+1) ); $post_to_save = array( "ID" => $post_node->ID, "menu_order" => $post_ref_node->menu_order, "post_parent" => $post_ref_node->post_parent, "post_type" => $post_ref_node->post_type ); wp_update_post( $post_to_save ); echo "did before"; } elseif ( "after" == $type ) { // post_node is placed after ref_post_node // update menu_order of all posts with the same parent ref_post_node and with a menu_order of the same as ref_post_node, but do not include ref_post_node // +2 since multiple can have same menu order and we want our moved post to have a unique "spot" $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET menu_order = menu_order+2 WHERE post_type = %s AND post_parent = %d AND menu_order >= %d AND id <> %d ", $post_ref_node->post_type, $post_ref_node->post_parent, $post_ref_node->menu_order, $post_ref_node->ID ) ); // update menu_order of post_node to the same that ref_post_node_had+1 #$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET menu_order = %d, post_parent = %d WHERE ID = %d", $post_ref_node->menu_order+1, $post_ref_node->post_parent, $post_node->ID ) ); $post_to_save = array( "ID" => $post_node->ID, "menu_order" => $post_ref_node->menu_order+1, "post_parent" => $post_ref_node->post_parent, "post_type" => $post_ref_node->post_type ); wp_update_post( $post_to_save ); echo "did after"; } #echo "ok"; // I'm done here! } else { // error } // ok, we have updated the order of the pages // but we must tell wordpress that we have done something // other plugins (cache plugins) will not know to clear the cache otherwise // edit_post seems like the most appropriate action to fire // fire for the page that was moved? can not fire for all.. would be crazy, right? #wp_update_post(array("ID" => $node_id)); #wp_update_post(array("ID" => $post_ref_node)); #clean_page_cache($node_id); clean_page_cache($post_ref_node); // hmpf.. db cache reloaded don't care do_action("cms_tree_page_view_node_move_finish"); exit; } /** * Show a box with some dontate-links and stuff */ function cms_tpv_show_annoying_box() { //update_option('cms_tpv_show_annoying_little_box', 1); // enable this to show box while testing if ( isset($_GET["action"]) && "cms_tpv_remove_annoying_box" == $_GET["action"] ) { $show_box = 0; update_option('cms_tpv_show_annoying_little_box', $show_box); } else { $show_box = get_option('cms_tpv_show_annoying_little_box', 1); } if ($show_box) { ?> "; print_r($var); echo "