Global $post type

This topic contains 4 replies, has 4 voices, and was last updated by  Wilfred Boerrigter 8 years ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #158980

    deanbarrow
    Buyer
    Post count: 17

    Hi,

    This might be a difficult one as I don’t fully understand the situation so will explain as best I can.

    I have had incompatibility issues with the Woocommerce Memberships (https://www.woothemes.com/products/woocommerce-memberships/) plugin where it was crashing every time I edited a GD post type:

    PHP Catchable fatal error: Argument 1 passed to WC_Memberships_Meta_Box_Post_Memberships_Data::output() must be an instance of WP_Post, instance of stdClass given, called in /wp-content/plugins/woocommerce-memberships/includes/admin/meta-boxes/abstract-wc-memberships-meta-box.php on line 222 and defined in /wp-content/plugins/woocommerce-memberships/includes/admin/meta-boxes/class-wc-memberships-meta-box-post-memberships-data.php on line 70

    My workaround was to query to post type and if it started ‘GD_’ then return false and ignore the plugin code.
    I’ve contacted the WooCommerce Memberships developers who have come back with the following.

    It looks like the Geodirectory plugin is overriding the global $post object which is not the right way to do things. You might want to let them know that because it could cause other issues with your site.

    I’m attaching a pre-release version of Memberships with a slightly different fix than what you suggested, it checks if the $post object is a WP_Post as Memberships requires and doesn’t add the meta box if it isn’t.

    I don’t know the ‘correct’ way to do it but thought I’d share this to hopefully avoid potential incompatibilities with other plugins.

    #158983

    Paolo
    Site Admin
    Post count: 31206

    Hi Dean,

    thanks for the heads up, it seems that they decided to apply a fix that will solve the case for good (with something very similar to what you’ve been doing anyway).

    Personally I’ve never seen a similar problems with any other plugin since we started (and GD has always been overriding the global $post object), so I’m not sure it is really that wrong.

    In any case, I asked Stiofan to comments on this and let us know what he thinks.

    Thanks again,

    #159103

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Hi Dean,

    We try to only override it when only we will be using it, this is the second time ever i have seen it cause a problem. I do appreciate the feedback and i will make some changes to avoid this in future.

    Thanks,

    Stiofan

    #159295

    deanbarrow
    Buyer
    Post count: 17

    Thanks guys, I appreciate your comments.

    #189775

    Wilfred Boerrigter
    Free User
    Post count: 20
    This reply has been marked as private.
Viewing 5 posts - 1 through 5 (of 5 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket