Skip to:
Content

bbPress.org

Opened 11 years ago

Closed 8 years ago

Last modified 7 years ago

#2309 closed defect (bug) (fixed)

WordPress theme previews triggering bbp_setup_current_user() debug notice

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

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 (35)

#1 @michelwppi
11 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.

#2 @johnjamesjacoby
11 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.

#3 @michelwppi
11 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 11 years ago by michelwppi (previous) (diff)

#4 @michelwppi
11 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.

#5 @johnjamesjacoby
11 years ago

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

#6 @michelwppi
11 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)

#7 @johnjamesjacoby
11 years ago

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

Closing in lieu of #WP24169.

#8 @johnjamesjacoby
11 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

#10 @Chouby
10 years 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 10 years ago by Chouby (previous) (diff)

#11 @michelwppi
10 years 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.

#12 follow-up: @grundyoso
10 years 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.

#13 in reply to: ↑ 12 @OpenCode
9 years 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.

#14 @netweb
9 years 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/

#15 @johnjamesjacoby
9 years 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.

#16 @johnjamesjacoby
9 years 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.

#17 @quassy
9 years 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)

#18 @x2764tech
9 years 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

#19 @georgestephanis
9 years 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

#20 @georgestephanis
9 years 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.

#21 @x2764tech
9 years ago

Thanks George!

#22 @netweb
9 years ago

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

#23 @workcafe
9 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

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.

Getting an issue when customizing the theme: Zerife Lite > http://themeisle.com/themes/zerif-lite/

Any solutions?

#24 @netweb
9 years ago

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

@workcafe, it is an issue with the theme, not bbPress, you should contact the theme authors or post on their support forums etc.

Anyone else who arrives here in the future please do no not reopen the ticket, comments are not closed and you are free to add a comment but there is no need to reopen the ticket :)

#25 follow-up: @mantismamita
8 years ago

Just wanted to comment here. I get this error even with twentyfifteen as a theme and only bbPress active in terms of plugins. It actually occurs regardless of the theme when bbPress is active. I am using 4.3.1 with VVV

#26 @netweb
8 years ago

#2892 was marked as a duplicate

#27 in reply to: ↑ 25 @netweb
8 years ago

Replying to mantismamita:

Just wanted to comment here. I get this error even with twentyfifteen as a theme and only bbPress active in terms of plugins. It actually occurs regardless of the theme when bbPress is active. I am using 4.3.1 with VVV

@mantismamita I cannot replicate this on my VVV install with ONLY bbPress 2.5.8 activated and using the Twenty Fifteen theme, if you have any other plugins active deactivate those and remove any mu-plugins if you are using them.

#28 @mantismamita
8 years ago

@netweb I confirm NO other plugins active (including mu). Very few other plugins were ever active on this install (BuddyPress 2.4.0 and bbPress Genesis Extend 1.1.1) The same error is present regardless of theme, tested with P2 and Genesis Framework. Just to be clear it is only visible when the Customiser is in use.

This ticket was mentioned in Slack in #bbpress by casiepa. View the logs.


8 years ago

#30 @Col_Blimp
8 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened
bbp_setup_current_user was called incorrectly. The current user is being initialized without using $wp->init()

Error in Wordpress 4.4.1 with bbPress 2.5.8-5815 and no other plugin installed.

Seems to have been going on for a few years so how is it that you disable the message as its really annoying when trying to debug other things?

#31 @johnjamesjacoby
8 years ago

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

bbPress is not broken.

bbPress is telling you that something else is broken.

WordPress's Customizer is special cased to be broken on purpose.

The Jetpack plugin also was recently broken, and promptly fixed.

If you see this notice in your debug logs, bbPress is kindly letting you know that something other than bbPress is breaking bbPress.

bbPress is not broken.

Last edited 8 years ago by johnjamesjacoby (previous) (diff)

#32 @lkraav
8 years ago

  • Cc leho@… added

#33 @johnjamesjacoby
7 years ago

In 6105:

User: Remove _doing_it_wrong() notice from bbp_setup_current_user().

The current user is always bootstrapped early in WordPress 4.7, so this notice is no longer valid.

An update for bootstrapping dynamic roles is imminent.

See #2309.

#34 @netweb
7 years ago

#3024 was marked as a duplicate

#35 @netweb
7 years ago

#3016 was marked as a duplicate.

Note: See TracTickets for help on using tickets.