Redefining the global $post object
-
I’ve got a plugin which is basically breaking my plugin.
The plugin that is breaking my code does this:
Function function_name($postvariable, $variable, $variable2 ) { global $wpdb,$post; $post = $postvariable; if (!is_object($post)) { $post = $wpdb->get_row("SELECT *,parent.post_status FROM $wpdb->posts parent, $wpdb->posts post WHERE (parent.post_status='publish' OR parent.post_status='private') AND post.ID=$post AND ( (post.post_status='inherit' AND post.post_parent=parent.ID) OR (parent.ID=post.ID) ) AND post.post_type!='nav_menu_item' AND post.post_type!='revision' );
the function is called from :
add_action(‘save_post’, ‘function_name’);
Under specific circumstances my plugin loses some values in the post_meta when my code fires on the transition_post_status hook, and I can narrow it down to the fact that the other plug replaces the $post global with the contents of $postvariable. The developer of the other plugin says he has to do it because he needs to ensure the “postvariable” and the global post object are the same – I maintain that if they are not the same (which apparently they are not) then he should not simply go and replace a global object which he didn’t define or populate – I’ve always been told, and I’ve always held that you do not change other peoples structures.
At the moment I’m going to have to tell users of my plugin that the other plugin breaks my plugin under specific circumstances.
So really I want to know if I’m taking the appropriate stance here.
- The topic ‘Redefining the global $post object’ is closed to new replies.