• Resolved sj-xweb

    (@sj-xweb)


    Hi,

    We’re getting errors when trying to get events belonging to groups that the current user is in when using the plugin with BuddyPress.

    [Tue Jun 23 16:40:08 2015] [error] [client 127.0.0.1] WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘) ) AND (‘event_private’=0 OR (‘event_private’=1 AND (‘group_id’ IS NULL OR ‘gro’ at line 3 for query \r\n\t\t\tSELECT papv18ab2_em_events.post_id FROM papv18ab2_em_events\r\n\t\t\tLEFT JOIN papv18ab2_em_locations ON papv18ab2_em_locations.location_id=papv18ab2_em_events.location_id\r\n\t\t\t WHERE (‘recurrence’!=1 OR ‘recurrence’ IS NULL) AND ( event_start_date >= CAST(‘2015-06-23’ AS DATE) OR (event_end_date >= CAST(‘2015-06-23’ AS DATE) AND event_end_date != ‘0000-00-00’ AND event_end_date IS NOT NULL)) AND (‘event_status’=1) AND ( ‘group_id’ IN () ) AND (‘event_private’=0 OR (‘event_private’=1 AND (‘group_id’ IS NULL OR ‘group_id’ = 0)))\r\n\t\t\tGROUP BY papv18ab2_em_events.post_id ORDER BY event_start_date ASC, event_start_time ASC, event_name ASC\r\n\t\t\t \r\n\t\t made by require(‘C:\\work\\intranet-test\\wp-blog-header.php’), require_once(‘C:\\work\\intranet-test\\wp-includes\\template-loader.php’), include(‘C:\\work\\intranet-test\\wp-content\\themes\\inet_social\\page.php’), get_template_part, locate_template, load_template, require(‘C:\\work\\intranet-test\\wp-content\\themes\\inet_social\\content-page-bp.php’), the_content, apply_filters(‘the_content’), call_user_func_array, bp_replace_the_content, apply_filters(‘bp_replace_the_content’), call_user_func_array, BP_Members_Theme_Compat->single_dummy_content, bp_buffer_template_part, bp_get_template_part, bp_locate_template, load_template, require(‘C:\\work\\intranet-test\\wp-content\\themes\\inet_social\\buddypress\\members\\single\\home.php’), bp_get_template_part, bp_locate_template, load_template, require(‘C:\\work\\intranet-test\\wp-content\\themes\\inet_social\\buddypress\\members\\single\\groups.php’), bp_get_template_part, bp_locate_template, load_template, require(‘C:\\work\\intranet-test\\wp-content\\themes\\inet_social\\buddypress\\members\\single\\plugins.php’), do_action(‘bp_template_content’), call_user_func_array, bp_em_my_group_events_content, em_locate_template, include(‘C:\\work\\intranet-test\\wp-content\\themes\\inet_social\\plugins\\events-manager\\buddypress\\my-group-events.php’), em_events_admin, em_locate_template, include(‘C:\\work\\intranet-test\\wp-content\\themes\\inet_social\\plugins\\events-manager\\tables\\events.php’), EM_Events::get, referer: https://intranet/

    I’ve dug in some and think I may have figured out the bug. The cause is in line 88 in bp-em-groups.php.

    You’re evaluationg if there are any groups by doing a count on $groups, which is populated by groups_get_user_groups(). The problem is that at some point, groups_get_user_groups() started returning 2 elements: “groups” (an array containing the group IDs) and “total.”

    Since the conditional on line 88 is:

    if( count($groups) > 0 )

    And the $groups will always have 2 elements, that conditional is always true now, causing errors when no the user doesn’t actually belong to any groups.

    Fix should be easy enough. Hope this helps.

    https://wordpress.org/plugins/events-manager/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hi,

    Thanks. Which version of Events Manager, BuddyPress and WordPress are you using?

    Thread Starter sj-xweb

    (@sj-xweb)

    WordPress: 4.2.2
    Buddypress: 2.3.2.1
    Event Manager: 5.5.7.1

    Plugin Support angelo_nwl

    (@angelo_nwl)

    just to narrow down the problem and help us debug the issue is it possible to try the following temporarily:

    – deactivating all other plugins to see if this resolves the problem. If this works, re-activate the plugins one by one until you find the problematic plugin(s).
    – switching to the default theme to rule out any theme-specific problems

    Thread Starter sj-xweb

    (@sj-xweb)

    I disabled all the plugins except for Buddypress and EM, and wrote a php script with the following code:

    <?php
    require( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' );
    
    $EM_Events = EM_Events::get(array('group' => 'my'));
    ?>

    Still get the sql error. The key to replicate the issue is to be logged in as a member that do not belong to any groups, and you should watch the error_log since the error may not being displayed in the browser.

    Plugin Support angelo_nwl

    (@angelo_nwl)

    can I know where did you added or used the snippet above?

    Thread Starter sj-xweb

    (@sj-xweb)

    I created a separate php file called events-test.php and loaded it in the browser after logging into an account with no group associations.

    Are you having issues replicating the problem?

    The issue should be pretty easy to track if you just look at the code. The $groups in bp-em-groups.php is populated by groups_get_user_groups() function (defined by buddypress plugin), and that function calls BP_Groups_Member::get_group_ids(). In that function, you can see that the code that returns the groups is: (buddypress/bp-grouops/classes/class-bp-groups-members.php, line 492)

    return array( 'groups' => $groups, 'total' => (int) $total_groups );

    That means $groups variable your code is looking at will always have 2 elements, making your conditional on line 88 of bp-em-groups.php always true.

    Thread Starter sj-xweb

    (@sj-xweb)

    Hi,

    Any updates on this?

    Plugin Support angelo_nwl

    (@angelo_nwl)

    sorry not having much a succes on this however we will going to test this further and inform the devs if needed.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘SQL error when filtering by "My groups" in buddypress’ is closed to new replies.