Skip to:
Content

Opened 2 years ago

Closed 3 months ago

Last modified 8 days ago

#2309 closed defect (fixed)

WordPress theme previews triggering bbp_setup_current_user() debug notice

Reported by: michelwppi Owned by: johnjamesjacoby
Milestone: 2.6 Priority: normal
Severity: major Version: 2.3
Component: API - Roles/Capabilities Keywords:
Cc: team@…, Chouby

Description

During tests with WP 3.5.1 and WP 3.6beta, we have this annoying notice...

Notice: bbp_setup_current_user was called incorrectly. The current user is being initialized without using $wp->init(). Please see Debugging in WordPress for more information. (This message was added in version 2.3.) in /Applications/MAMP/htdocs/wp_svn36/wp-includes/functions.php on line 2986

Why this message ?
Only bbPress 2.3 call this function (no other plugins) !
How to avoid only it when debugging (WP_DEBUG true) ?

Thanks

Michel

Change History (22)

comment:1 @michelwppi2 years ago

  • Cc team@… added

More details :
bbp_setup_current_user was called/fired by function get_user_option() from another plugin via locale filter...

Doing tests, before calling get_user_option it is verified that user is logged but the notice occurred !!

Are you sure that the condition if ( ! did_action( 'after_setup_theme' ) ) { - is not too much restrictive to fire this notice ?

Can you provide more explanation ?

M.

comment:2 @johnjamesjacoby2 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

This is more of a support question than a bug. This warning is here intentionally, to alert you to some piece of code that's working incorrectly.

Closing as invalid, as the warning is doing exactly what's intended to do.

comment:3 @michelwppi2 years ago

  • Cc team@… removed

I remain a little perplexed about this Notice limitation (inside filter action after_setup_theme line 146 of sub-actions.php) imposed by bbPress 2.3 when you need to get user's ID ( get_current_user_id ) or user's meta (not linked with bbPress) from current user (get_user_option).

Please find solution extracted from a class of a plugin setting live dashboard language (backside).

Updated 2013-04-24 after a week tests:

First "brutal" workaround was based on removing filter: see commented lines below

Second approach was based on add of a filter action after_setup_theme to get user meta (here user_locale) - this approach is not possible here in the function called by locale filter - purpose: changing live the dashboard language UI

// 2.8.0 dashboard language 
		add_filter( 'locale', array( &$this, 'admin_side_locale') ); 
		add_action( 'after_setup_theme', array( &$this, 'admin_user_id_locale') ); // 2.8.8
	
	
	/**
	 * Admin side localization - user's dashboard from locale filter
	 *
	 * @since 2.8.0
	 *
	 */
	function admin_side_locale( $locale = 'en_US' ) {
		
		// to avoid notice with bbPress 2.3 - brutal approach
		if ( class_exists( 'bbPress') ) remove_action( 'set_current_user', 'bbp_setup_current_user' ); 
		$locale = get_user_option( 'user_locale' ); 
		if ( class_exists( 'bbPress') ) add_action( 'set_current_user', 'bbp_setup_current_user', 10 );
		
		// cannot be replaced here by (no operant in this filter
		// $locale = $this->user_locale; // see after_setup_theme filter below
		
		if ( empty( $locale ) )
			$locale = $this->get_default_locale();
		
		return $locale;
	}


 * from after_setup_theme action - tested but not used after tests
	 *
	 * @since 2.8.8
	 *
	 */
	function admin_user_id_locale () {
		$this->user_locale = get_user_option( 'user_locale' );
	}

These solutions will be published in xili-language v 2.8.8 when used with bbPress 2.3 in multilingual context.

Hope that help another dev. or cause another comments,

M.

Last edited 2 years ago by michelwppi (previous) (diff)

comment:4 @michelwppi2 years ago

  • Component changed from General to Roles/Capabilities
  • Keywords customize added
  • Milestone set to Awaiting Review
  • Resolution invalid deleted
  • Severity changed from normal to major
  • Status changed from closed to reopened

Hi,
I reopen the ticket because this notice appear in Customize theme double screen :
Tested in WP 3.6 beta, without any plugin, only bbPress 2.3 plugin and twentytwelve theme or twentythirteen :
The notice appears on the top of the right frame (where home page is displayed).
It seems to confirm that the notice 'limitation' is too restrictive

Hope that help...

M.

comment:5 @johnjamesjacoby2 years ago

Should make a WordPress core ticket, and get this fixed upstream.

comment:6 @michelwppi2 years ago

  • Cc team@… added

I open this ticket in core WordPress track :

http://core.trac.wordpress.org/ticket/24141

(note : the link in your comment is not right)

comment:7 @johnjamesjacoby2 years ago

  • Keywords customize removed
  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from reopened to closed

Closing in lieu of #WP24169.

comment:8 @johnjamesjacoby2 years ago

  • Summary changed from Notice: bbp_setup_current_user was called incorrectly. The current user is being initialized without using $wp->init(). Please see Debugging in WordPress for more information. (This message was added in version 2.3.) in [...]wp_svn36/wp-includes/functions.php on line 2986 to WordPress theme previews triggering bbp_setup_current_user() debug notice

comment:10 @Chouby19 months ago

  • Cc Chouby added
  • Resolution invalid deleted
  • Status changed from closed to reopened

As @nacin mentionned in #WP24169, I believe that this ticket rises a larger issue than the WP customizer. It rises a conflict with most multilingual plugins which permit each user to define their own language (I am aware of at least Xili Language, WP native Dashboard, Polylang but there are probably more), which can hook to the 'locale' filter called by get_locale() *after* roles have been defined.

If that's doing it wrong, then I really don't understand why and so far only bbpress is warning us against this practice.

Again, I may have understood nothing but if that's creates issues for bbpress, I wonder why 'bbp_setup_current_user' is not hooked to 'after_setup_theme' instead of 'set_current_user'. Is it realistic to do so?

Last edited 19 months ago by Chouby (previous) (diff)

comment:11 @michelwppi19 months ago

Again, I full agree with Chouby, bbPress don't follow the timeline of wp-settings... In the near past, I have try to write an article about this timeline of actions during start of WP :

http://2013.extend.xiligroup.org/en/405/case-of-main-filtersactions-during-initialisation-of-wp-reserved-for-developers/

Hope that help to find an elegant solution especially for online test of theme...

M.

comment:12 follow-up: @grundyoso11 months ago

I've been trying to resolve an issue that I traced down to being related to this one. It exhibited itself in debug_log like this:

Notice: bbp_setup_current_user was called incorrectly. The current user is being initialized without using $wp->init(). Please see Debugging in WordPress for more information. (This message was added in version 2.3.)

Through some stack tracing and variable duping, I tracked the issue down to the WooDojo plugin. This plugin in particular loads bundles of custom widgets and they don't seem to protect against the infamous "after_setup_theme" state before trying to access the current user. So it exhibits itself as a BBPress plugin issue when in fact WooDojo is making the mistake of making sure the theme is setup before trying to mess with the current user. At any rate, it was a simple fix in line 122 of the ./plugins/woodojo/classes/base.class.php file from this:

add_action( 'plugins_loaded', array( &$this, 'init_component_loaders' ) );

to this:

add_action( 'after_setup_theme', array( &$this, 'init_component_loaders' ) );

I'm somewhat of a nooB, so take this with a grain of salt... just hope it helps save someone some time.

comment:13 in reply to: ↑ 12 @OpenCode8 months ago

I don't have WooDojo Plugin but have been getting the notice.

Notice: bbp_setup_current_user was called incorrectly. The current user is being initialized without using $wp->init().

Replying to grundyoso:

Through some stack tracing and variable duping, I tracked the issue down to the WooDojo plugin.

comment:14 @netweb8 months ago

@OpenCode This is not a bbPress issue, you will find it will be a plugin or theme conflict doing it wrong, disable each of your plugins one by one until the notice is gone, you'll then know the conflicting plugin, if not a plugin then switch to a WordPress default theme, e.g. Twenty Fourteen.

This ticket is also on a closed milestone and Trac is not for support.

If you have any further questions (or anyone else for that matter) please post on the support forums:

https://bbpress.org/forums/

comment:15 @johnjamesjacoby3 months ago

  • Milestone set to 2.6
  • Owner set to johnjamesjacoby
  • Status changed from reopened to new

Let's fix this (for now) so it doesn't cause anymore support burden.

comment:16 @johnjamesjacoby3 months ago

  • Resolution set to fixed
  • Status changed from new to closed

In 5618:

Update bbp_setup_current_user() to avoid output in WordPress Customizer. Fixes #2309. See #WP24169.

comment:17 @quassy5 weeks ago

Notice: bbp_setup_current_user was called incorrectly. The current user is being initialized without using $wp->init(). Please see Debugging in WordPress for more information. (This message was added in version 2.3.) in /is/htdocs/wp10591786_F7AET0I6TB/www/mysite/wp-includes/functions.php on line 3547

Was the patch already released? For me it is still an issue. (Wordpress 4.1.2, bbPress 2.5.7)

comment:18 @x2764tech9 days ago

Sorry to bring this up again (and I'm not sure if this should be in a new ticket), but JetPack's stats module seems to trigger this warning too - it looks like simply having JetPack installed and activated is enough to cause this error to happen.

The code (eventually) calls current_user_can from plugins_loaded (see https://plugins.trac.wordpress.org/browser/jetpack/tags/3.5.3/modules/stats.php#L69)

Relevant contents of debug log:

Notice:  bbp_setup_current_user was called <strong>incorrectly</strong>. The current user is being initialized without using $wp->init(). Please see <a href="https://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> for more information. (This message was added in version 2.3.) in /var/www/wp-includes/functions.php on line 3560
Stack trace:
  1. {main}() /var/www/index.php:0
  2. require() /var/www/index.php:17
  3. require_once() /var/www/wp-blog-header.php:12
  4. require_once() /var/www/wp-load.php:37
  5. require_once() /var/www/wp-config.php:187
  6. do_action() /var/www/wp-settings.php:237
  7. call_user_func_array:{/var/www/wp-includes/plugin.php:496}() /var/www/wp-includes/plugin.php:496
  8. Jetpack::load_modules() /var/www/wp-includes/plugin.php:496
  9. do_action() /var/www/wp-content/plugins/jetpack/class.jetpack.php:1146
 10. call_user_func_array:{/var/www/wp-includes/plugin.php:496}() /var/www/wp-includes/plugin.php:496
 11. stats_load() /var/www/wp-includes/plugin.php:496
 12. current_user_can() /var/www/wp-content/plugins/jetpack/modules/stats.php:69
 13. wp_get_current_user() /var/www/wp-includes/capabilities.php:1385
 14. get_currentuserinfo() /var/www/wp-includes/pluggable.php:58
 15. wp_set_current_user() /var/www/wp-includes/pluggable.php:119
 16. do_action() /var/www/wp-includes/pluggable.php:41
 17. call_user_func_array:{/var/www/wp-includes/plugin.php:496}() /var/www/wp-includes/plugin.php:496
 18. bbp_setup_current_user() /var/www/wp-includes/plugin.php:496
 19. _doing_it_wrong() /var/www/wp-content/plugins/bbpress/includes/core/sub-actions.php:147
 20. trigger_error() /var/www/wp-includes/functions.php:3560

comment:19 @georgestephanis8 days ago

Okay, so 9. looks like the do_action( 'jetpack_modules_loaded' ); which is indeed meant to fire stats_load() which is here:

https://github.com/Automattic/jetpack/blob/b2e4cbb2091bccef79ff130766c29b80b9e75496/modules/stats.php#L38-L80

and ... okay, drat, yeah, that was probably my fault. I didn't realize it was before init when that fired -- too many steps deep.

We'll have a fix up shortly.

Thanks for the catch, @x2764tech

comment:20 @georgestephanis8 days ago

Fix for Jetpack: https://github.com/Automattic/jetpack/commit/76537541cefa867d09ca0e38c8b4509e868ca81b

I'm flagging it to merge into our next point release, but we don't really have one scheduled -- just know that it will go out with the next point release.

comment:21 @x2764tech8 days ago

Thanks George!

comment:22 @netweb8 days ago

That was quick, thanks for the report x2764tech and fix George :)

Note: See TracTickets for help on using tickets.