[wp-hackers] detecting type of edit for parent_save_pre

Steve Taylor steve at sltaylor.co.uk
Fri Nov 20 14:15:29 UTC 2009

I'm having some issues with a plugin I did recently
(http://wordpress.org/extend/plugins/lock-pages/). Part of it prevents
certain users from changing the parent of pages which are set as
"locked" by admins.

The issue I'm having is that when said users upload images to a locked
page, it gets "de-attached" by the plugin. You can grab the code to
see it all, but this is the code that I think is the issue - it's
hooked to parent_save_pre.

function lockParent( $parent ) {
	// Make sure this isn't an uploaded attachment or image being edited
	if ( !isset( $_POST["html-upload"] ) || $_POST["html-upload"] != "Upload" ) ) {
		// Can user edit this page?
		if ( $this->userCanEdit( $_POST['post_ID'] ) ) {
			return $parent;
		} else {
			// Keep old parent, user can't change it
			return $_POST[$this->prefix.'old_parent'];
	} else {
		return $parent;

The check at the start is what I added to make sure we're not dealing
with an image upload, and it works - but then when you edit, say, the
image's title, and Save Changes, then the parent gets changed and the
image is de-attached again.

I know there must be a certain way to check that the function only
runs for *pages* being saved. Am I missing an argument for
parent_save_pre? I tried global $post and checking $post->post_type,
but it didn't seem to work.

Any hints appreciated!

Steve Taylor

More information about the wp-hackers mailing list