Skip to:
Content

Opened 12 months ago

Last modified 5 months ago

#2309 reopened defect

WordPress theme previews triggering bbp_setup_current_user() debug notice

Reported by: michelwppi Owned by:
Milestone: Priority: normal
Severity: major Version: 2.3
Component: 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 (11)

comment:1 michelwppi12 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 johnjamesjacoby12 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 michelwppi12 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 12 months ago by michelwppi (previous) (diff)

comment:4 michelwppi12 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 johnjamesjacoby12 months ago

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

comment:6 michelwppi12 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 johnjamesjacoby12 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 johnjamesjacoby12 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 Chouby5 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 5 months ago by Chouby (previous) (diff)

comment:11 michelwppi5 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.

Note: See TracTickets for help on using tickets.