itthinx / groups

Groups provides group-based user membership management, group-based capabilities and content access control. It integrates standard WordPress capabilities and application-specific capabilities along with an extensive API.
GNU General Public License v3.0
49 stars 35 forks source link

Uncaught Error: Call to undefined function get_userdata() in .../wp-includes/capabilities.php:976 #152

Closed midweste closed 4 months ago

midweste commented 4 months ago

Not too much of a bug, just maybe an FYI of a possible edge case.

I was the other edge case that was working with that "pluggable.php" fix. I installed the new version but I'm seems I'm getting a different error but of a similar cause. Seems user_can must have been defined by groups, but get_userdata that is called in user_can was undefined.

NOTE: I WAS ALREADY LOGGED IN WHEN I PUSHED THE NEW CODEBASE. LOGGING OUT AND LOGGING BACK IN SEEMS TO RESOLVE THE ERROR. All caches were cleared after code push.

In order to logout though, I had to include pluggable in class-groups-wordpress.php in the groups_user_can method

    public static function groups_user_can( $result, $groups_user, $capability, $object, $args ) {
        if ( !$result ) {
            // Check if the capability exists, otherwise this will
            // produce a deprecation warning "Usage of user levels by plugins
            // and themes is deprecated", not because we actually use a
            // deprecated user level, but because it doesn't exist.
            if ( Groups_Capability::read_by_capability( $capability ) ) {
                if ( $groups_user instanceof Groups_User ) {
                    $user_id = $groups_user->get_user_id();
                    if ( $user_id !== null ) {
                        if (!function_exists('get_userdata')) {
                            require_once ABSPATH . WPINC . '/pluggable.php';
                        }

This may be a problem with already logged in users or maybe it was before the cache was flushed (redis)

<b>Fatal error</b>: Uncaught Error: Call to undefined function get_userdata() in .../wp-includes/capabilities.php:976
Stack trace:
#0 .../wp-content/plugins/groups/lib/wp/class-groups-wordpress.php(99): user_can()
#1 .../wp-includes/class-wp-hook.php(324): Groups_WordPress::groups_user_can()
#2 .../wp-includes/plugin.php(256): WP_Hook-&gt;apply_filters()
#3 .../wp-content/plugins/groups/lib/core/class-groups-user.php(565): apply_filters_ref_array()
#4 .../wp-content/plugins/groups/lib/wp/class-groups-wordpress.php(166): Groups_User-&gt;can()
#5 .../wp-includes/class-wp-hook.php(324): Groups_WordPress::user_has_cap()
#6 .../wp-includes/plugin.php(205): WP_Hook-&gt;apply_filters()
#7 .../wp-includes/class-wp-user.php(813): apply_filters()
#8 .../wp-content/plugins/groups/lib/core/class-groups-user.php(230): WP_User-&gt;has_cap()
#9 .../wp-content/plugins/groups/lib/core/class-groups-user.php(201): Groups_User::user_can()
#10 .../wp-content/plugins/groups/lib/access/class-groups-post-access.php(264): Groups_User::current_user_can()
#11 .../wp-includes/class-wp-hook.php(324): Groups_Post_Access::posts_where()
#12 .../wp-includes/plugin.php(256): WP_Hook-&gt;apply_filters()
#13 .../wp-includes/class-wp-query.php(2717): apply_filters_ref_array()
#14 .../wp-includes/class-wp-query.php(3824): WP_Query-&gt;get_posts()
#15 .../wp-includes/post.php(2520): WP_Query-&gt;query()
#16 .../wp-content/plugins/advanced-custom-fields/includes/class-acf-internal-post-type.php(399): get_posts()
#17 .../wp-content/plugins/advanced-custom-fields/includes/class-acf-internal-post-type.php(357): ACF_Internal_Post_Type-&gt;get_raw_posts()
#18 .../wp-content/plugins/advanced-custom-fields/includes/acf-internal-post-type-functions.php(153): ACF_Internal_Post_Type-&gt;get_posts()
#19 .../wp-content/plugins/advanced-custom-fields/includes/acf-field-group-functions.php(118): acf_get_internal_post_type_posts()
#20 .../wp-content/plugins/woocommerce-products-filter/ext/acf_filter/index.php(62): acf_get_field_groups()
#21 .../wp-content/plugins/woocommerce-products-filter/ext/acf_filter/index.php(17): WOOF_ACF_FILTER-&gt;get_all_acf_meta()
#22 .../wp-content/plugins/woocommerce-products-filter/ext/acf_filter/index.php(233): WOOF_ACF_FILTER-&gt;__construct()
#23 .../wp-content/plugins/woocommerce-products-filter/index.php(3256): include_once('...')
#24 .../wp-content/plugins/woocommerce-products-filter/index.php(113): WOOF-&gt;init_extensions()
#25 .../wp-content/plugins/woocommerce-products-filter/index.php(4010): WOOF-&gt;__construct()
#26 .../wp-settings.php(517): include_once('...')
#27 .../wp-config.php(82): require_once('...')
#28 .../wp-load.php(50): require_once('...')
#29 .../wp-blog-header.php(13): require_once('...')
#30 .../index.php(17): require('...')
#31 {main}
thrown in <b>.../wp-includes/capabilities.php</b> on line <b>976</b><br/>
itthinx commented 4 months ago

Many thanks for reporting this, release 3.1.0 just came out where this has been addressed.

midweste commented 4 months ago

Just finishing some initial tests and everything looks good so far. Thank you!