• Resolved intuitart

    (@intuitart)


    Fatal error: Uncaught TypeError: Illegal offset type in isset or empty in /var/www/domain.com/wp-includes/plugin.php:174 Stack trace:
    #0 /var/www/domain.com/wp-content/plugins/bnfw/bnfw.php(1184): apply_filters()
    #1 [internal function]: BNFW->bnfw_members_sanitize_role()
    #2 /var/www/domain.com/wp-content/plugins/bnfw/bnfw.php(1130): array_map()
    #3 /var/www/domain.com/wp-includes/class-wp-hook.php(309): BNFW->user_role_added()
    #4 /var/www/domain.com/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters()
    #5 /var/www/domain.com/wp-includes/plugin.php(474): WP_Hook->do_action()
    #6 /var/www/domain.com/wp-includes/user.php(2283): do_action()
    #7 /var/www/domain.com/wp-includes/user.php(2404): wp_insert_user()
    #8 /var/www/domain.com/wp-admin/includes/user.php(227): wp_update_user()
    #9 /var/www/domain.com/wp-admin/user-edit.php(166): edit_user()
    #10 {main} thrown in /var/www/domain.com/wp-includes/plugin.php on line 174

    The apply_filters function requires a string as first parameter to identify the filter. Line 1184 in bnfw.php has an array as first parameter.

    This looks like the same problem in the Critical Site Error on Password Changes issue. It’s when BNFW is used with the Members plugin.

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Author bnfw

    (@voltronik)

    Hi @intuitart,
    Thanks for your message.

    I think this might happen if you have the Members plugin enabled but aren’t allowing a user to have multiple user roles.
    Are you able to verify this setting and see if it helps when enabled?

    Thread Starter intuitart

    (@intuitart)

    Yes, ‘Allow users to be assigned more than a single role.’ is checked. I am assigning multiple roles.

    Further to my original message, when I hack line 1184 in the code and make $hook_name a string, everything works fine.

    From WordPress developer resources, the apply_filters function is a string, not a string or array:
    apply_filters( string $hook_name, mixed $value )

    Your code is defining it as a array:
    return apply_filters( array( $this, 'bnfw_members_sanitize_role' ), str_replace( ' ', '_', $_role ), $role );

    To make things work I changed that to:
    return apply_filters( 'bnfw_members_sanitize_role', str_replace( ' ', '_', $_role ), $role );

    Hope this helps,

    Andrew P.

    Plugin Author bnfw

    (@voltronik)

    Thanks @intuitart,
    I’ll do some testing and provide a fix in the next update to the plugin.

    Ash

    (@smartfaceweb)

    I can confirm I am experiencing the same issue and can see that you are passing an array into the apply_filters() method when the doc block shows that it expects a string.

    /wp-includes/plugin.php

    * @since 0.71
     *
     * @global WP_Hook[] $wp_filter         Stores all of the filters and actions.
     * @global string[]  $wp_current_filter Stores the list of current filters with the current one last.
     *
     * @param string $hook_name The name of the filter hook.
     * @param mixed  $value     The value to filter.
     * @param mixed  ...$args   Additional parameters to pass to the callback functions.
     * @return mixed The filtered value after all hooked functions are applied to it.
     */
    function apply_filters( $hook_name, $value ) {
    Plugin Author bnfw

    (@voltronik)

    Thanks for your confirmation @smartfaceweb.

    Ash

    (@smartfaceweb)

    Any ETA on when the update will be ready? Currently to change a user’s role, I need to disable this plugin, change the role and then re-enable the plugin.

    Plugin Author bnfw

    (@voltronik)

    Hi @smartfaceweb,
    No ETA as yet but you’re welcome to modify the bnfw plugin to include the fix mentioned above in order to circumvent the issue until a release is made.

    Hello,
    I sorry,
    but I do not have the same code on BNFW 1.8.11 and I still have the same trouble “fatal error”
    How can fix it?

    function apply_filters( $hook_name, $value ) {
    	global $wp_filter, $wp_current_filter;
    
    	$args = func_get_args();
    
    	// Do 'all' actions first.
    	if ( isset( $wp_filter['all'] ) ) {
    		$wp_current_filter[] = $hook_name;
    		_wp_call_all_hook( $args );
    	}
    
    	if ( ! isset( $wp_filter[ $hook_name ] ) ) {
    		if ( isset( $wp_filter['all'] ) ) {
    			array_pop( $wp_current_filter );
    		}
    
    		return $value;
    	}
    
    	if ( ! isset( $wp_filter['all'] ) ) {
    		$wp_current_filter[] = $hook_name;
    	}
    
    	// Don't pass the tag name to WP_Hook.
    	array_shift( $args );
    
    	$filtered = $wp_filter[ $hook_name ]->apply_filters( $value, $args );
    
    	array_pop( $wp_current_filter );
    
    	return $filtered;
    }
    Plugin Author bnfw

    (@voltronik)

    Hi @sebastiengiran,
    The fix can be found in this post:
    https://wordpress.org/support/topic/fatal-error-when-used-with-members-plugin-2/#post-15580156

    You need to replace the code on line 1184 of bnfw.php that reads:
    return apply_filters( array( $this, 'bnfw_members_sanitize_role' ), str_replace( ' ', '_', $_role ), $role );

    with this:
    return apply_filters( 'bnfw_members_sanitize_role', str_replace( ' ', '_', $_role ), $role );

    Let me know if this helps.

    Where do I find the bnfw.php on the server?

    Ok, I finded it, it’s works, thank you so much
    Best regards

    Plugin Author bnfw

    (@voltronik)

    Hi @sebastiengiran,
    Great! Glad you got it working. An update with this fix will be released soon.

    Hi @voltronik,

    I ran into this issue today on Version 1.8.11 + custom fields & conditional notifications add-ons. The fix above worked for me (thanks @intuitart!).

    Should I tell my client to not update BNFW, or will this fix for sure be in the next version?

    Thanks!

    Plugin Author bnfw

    (@voltronik)

    Hi @invouq,
    Yes, the fix is already ready in my development version and will be included in the next version of BNFW.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Fatal error when used with members plugin’ is closed to new replies.