#15312 closed defect (bug) (fixed)
Bug with remove_meta_box bug with pageparentdiv when saving a page
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | 3.1 | Priority: | normal |
Severity: | normal | Version: | 3.0.1 |
Component: | Administration | Keywords: | pages, meta_box |
Focuses: | Cc: |
Description
Hi,
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'); } endif; } 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??
Thanks
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: