Skip to:
Content

Opened 4 years ago

Closed 4 years ago

#5843 closed defect (bug) (fixed)

WP_Screen may be null if remove_signups_from_user_query is called from within admin_init hook

Reported by: pauldewouters Owned by: imath
Milestone: 2.1 Priority: normal
Severity: normal Version: 2.0
Component: Administration Keywords: commit
Cc: pauldewouters@…

Description

Referencing this forum thread: http://buddypress.org/support/topic/conflict-with-my-plugin/#post-188636

The function remove_signups_from_user_query in bp-members-admin.php makes a call to get_current_screen()

This function will return null if in the context of a function hooked to admin_init

In this case, a plugin I developed is running a WP_User_Query on admin_init so the pre_user_query gets fired and this fires the remove_signups_from_user_query function.

Method could check for admin_init like so:

if ( doing_action( 'admin_init' ) || $this->users_page != get_current_screen()->id ) { return;}

Attachments (1)

5843.patch (530 bytes) - added by imath 4 years ago.

Download all attachments as: .zip

Change History (8)

#1 @pauldewouters
4 years ago

  • Cc pauldewouters@… added
  • Component changed from Core to Administration
  • Keywords dev-feedback added
  • Version set to 2.0

#2 @boonebgorges
4 years ago

Thanks for the report.

Checking for doing_action( 'admin_init' ) seems overly specific to me. Let's just change our syntax a little bit:

// Bail if not on a users page
$current_screen = get_current_screen();
if ( ! isset( $current_screen->id ) || $this->users_page !== $current_screen->id ) {
    return;
}

Will that work?

#3 @imath
4 years ago

  • Keywords reporter-feedback added

thanks for your feedback pauldewouters

Yes i think boonebgorges's way is better, as doing_action does not exist in WordPress before 3.9 and BuddyPress supports from 3.6 to latest version of WordPress.

Could you test 5843.patch to see if it solves the issue ?

@imath
4 years ago

#4 @pauldewouters
4 years ago

Just tested with the patch and the fix seems to work nicely.

#5 @DJPaul
4 years ago

  • Keywords commit added; dev-feedback reporter-feedback removed

Thanks for testing, Paul. :)

#6 @r-a-y
4 years ago

  • Milestone changed from Awaiting Review to 2.1

#7 @imath
4 years ago

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

In 8984:

Make sure the current administration screen ID is set before checking its value

In BP_Members_Admin->remove_signups_from_user_query(), to avoid a notice error, we need to check that get_current_screen()->id is set.

Props boonebgorges

Fixes #5843

Note: See TracTickets for help on using tickets.