xwp / stream

🗄️ Stream plugin for WordPress

Home Page:https://wordpress.org/plugins/stream/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

get_current_screen function is undefined for wp_stream page loaded

arun744-newscorp opened this issue · comments

Delete the section that is not applicable:

Feature Request

There is a bug in stream/classes/class-alerts-list.php file, line 59.
Check if get_current_screen() function exist or return false if not.

Bug Report

get_current_screen() is reported undefined function:

Fatal error: Uncaught Error: Call to undefined function WP_Stream\get_current_screen()
in /var/www/wp-content/plugins/stream/classes/class-alerts-list.php on line 59

Error occurs in one of our custom wordpress plugin, when $wp->main( $query_vars) method is invoked.

Tested locally by applying the following patch in the stream/classes/class-alerts-list.php, issue was fixed:

`public function parse_request( $query_vars ) {

	if( !function_exists( 'get_current_screen' ) ){
		return false;
	}

	$screen = get_current_screen();
	if ( 'edit-wp_stream_alerts' === $screen->id && Alerts::POST_TYPE === $query_vars['post_type'] && empty( $query_vars['post_status'] ) ) {
		$query_vars['post_status'] = array( 'wp_stream_enabled', 'wp_stream_disabled' );
	}
	return $query_vars;
}`

I am checking if the get_current_screen function exists and return false if not exist.

Screenshots

Screen Shot 2021-04-15 at 12 04 13 pm

System Information

  • Stream plugin version: 3.6.2
  • WordPress version: 5.5, 5.6, 5.7
  • PHP version: 7.3 +
  • Browser: chrome
  • Computer operating system: Mac OSX

This has been fixed in 9036bee and PHP should be able to resolve that function since it falls back to the global namespace by default:

For unqualified names, if no import rule applies and the name refers to a function or constant and the code is outside the global namespace, the name is resolved at runtime. Assuming the code is in namespace A\B, here is how a call to function foo() is resolved:

  • It looks for a function from the current namespace: A\B\foo().
  • It tries to find and call the global function foo().

https://www.php.net/manual/en/language.namespaces.rules.php