• 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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Steve

    (@steveatty)

    Anyone?

    @steveatty,

    I’m presuming that you are also hooking into the ‘save_post’ action, when not use the priority attribute of add_action() and make sure your code gets in there first?

    Thread Starter Steve

    (@steveatty)

    Actually I’m not – I’m using the post transition hooks and the post_publish hooks and it was doing lots of very odd things. I think I’ve managed to code past it but it concerns me that any plugin should be basically doing something so drastic.

    @steveatty,

    Agreed, it looks like a poorly coded plugin that’s breaking yours. All credit to you for even looking into this! I think I’d have pointed out who dodgy this code was and that it may be having other effects (like mangling the database tables) and advised to stop using it!

    It does appear to overwrite the $post object. I don’t think I would trust the plugin either.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Redefining the global $post object’ is closed to new replies.