Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#15312 closed defect (bug) (fixed)

Bug with remove_meta_box bug with pageparentdiv when saving a page

Reported by: maorb Owned by:
Milestone: 3.1 Priority: normal
Severity: normal Version: 3.0.1
Component: Administration Keywords: pages, meta_box
Focuses: Cc:



I use some code to remove the meta_box of some boxes in the page edit. I also remove the parent_page select box to users that not have admin capabilities, in order that thet parent page won't be modified.

My code is something like -

function tc_remove_menus () {
global $current_user;
if (!current_user_can('administrator')) :
$boxes = array(	 'passworddiv', 'tagsdiv', 'trackbacksdiv', pageparentdiv', commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv', 'postcustom' ); 
	foreach ($boxes as $box){				
		remove_meta_box($box, 'page', 'normal');		
add_action('admin_menu', 'tc_remove_menus');

The code works well and these meta boxes are removed. But, what happens upon a page update, is that the parent_page value is being reset to zero and thus any child page that is being edited and saved, becomes a parent page and loses its place as child page.

Somehow, I assume that after removing the meta box, the $_POST does contain the current state of the page_parent, and thus it is being updated to 0.

It looks that it's a core bug - since if not sending the page_parent field when saving the post/page - why is this field has to be changed/updated at all from its current value??


Change History (4)

#1 @maorb
9 years ago

Well, I've continued to check it, and found that indeed, when removing the meta_box of parent_div, the parent_id is not being sent in via submit, so the $_POST does not have a value for it, and it appears then to get value of 0.

In order to fix this in my case, I wrote a small function to hook the save_post action and preserve the current post_parent id and write it directly to the database.
Anyway, I think this issue should be fixed in the core.

Here's my function I wrote for this:

function tc_persave_page_parent($post_id) {
	global $post, $wpdb;
	$q_upd = "UPDATE $wpdb->posts SET post_parent = $post->post_parent WHERE ID = $post->ID;";	
	$res = $wpdb->get_results($q_upd);

add_action('save_post', 'tc_persave_page_parent' );

#2 @nacin
9 years ago

This should be fixed in 3.1. [16657]

#3 @SergeyBiryukov
9 years ago

  • Resolution set to fixed
  • Status changed from new to closed

Confirmed as fixed in [16657].

#4 @westi
9 years ago

  • Milestone changed from Awaiting Review to 3.1
Note: See TracTickets for help on using tickets.