Fitoussi / geo-my-wp

Advanced mapping and geolocation plugin for Wordpress
https://geomywp.com
36 stars 22 forks source link

Post location saved on different blog in Multisite installation #80

Closed chrissienoodle closed 1 month ago

chrissienoodle commented 2 months ago

Hi,

I have a multisite WP installation with one main site (blog_id = 1) and 40 local sites. I use GMW and GMW Premium to display the location of local antennas both for the main site and local sites (the posts and location data are independently stored in each blog). However, whenever an local site edits the info of a GMW location, it changes the data of the other blogs. It leads to a very strange behavior where my antennas end up in completely the wrong location.

I believe I have identified the bug in gmw-functions.php lines 82 to 115, you have a function " gmw_get_blog_id " that has a logical error in its condition. Currently you return 1 for all posts and return a $blog_id only for users and buddypress groups. It should be the other way around. Users in a WP multisite are common to all blogs but posts are only in one blog.

This should fix it:

function gmw_get_blog_id( $object = '' ) {
    $multisite_global_objects = array( 'user', 'bp_group' );

-   if ( is_multisite() && in_array( $object, $multisite_global_objects, true ) ) {
+   if ( is_multisite() && !in_array( $object, $multisite_global_objects, true ) ) {
        global $blog_id;
        return $blog_id;
    } else {
        return 1;
    }
}

Don't hesitate to let me know if I can be of anymore help. Thanks in advance.

Fitoussi commented 1 month ago

Hi @chrissienoodle,

Thank you for pointing out this issue. You are correct, the logic of the function is incorrect.

I will release a new version with a fix soon.

Thanks.