WordPress.org

Ready to get started?Download WordPress

Forums

Redefining the global $post object (6 posts)

  1. Steve
    Member
    Posted 2 years ago #

    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.

  2. Steve
    Member
    Posted 2 years ago #

    Anyone?

  3. mattyrob
    Member
    Posted 2 years ago #

    @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?

  4. Steve
    Member
    Posted 2 years ago #

    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.

  5. mattyrob
    Member
    Posted 2 years ago #

    @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!

  6. s_ha_dum
    Member
    Posted 2 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.