Skip to:
Content

Opened 23 months ago

Closed 7 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 (16)

comment:1 @michelwppi23 months 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 @johnjamesjacoby23 months 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 @michelwppi23 months 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 23 months ago by michelwppi (previous) (diff)

comment:4 @michelwppi23 months 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 @johnjamesjacoby23 months ago

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

comment:6 @michelwppi23 months 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 @johnjamesjacoby23 months 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 @johnjamesjacoby23 months 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 @Chouby16 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 16 months ago by Chouby (previous) (diff)

comment:11 @michelwppi16 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: @grundyoso8 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 @OpenCode5 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 @netweb5 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 @johnjamesjacoby7 days 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 @johnjamesjacoby7 days 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.

Note: See TracTickets for help on using tickets.