Fix PHP notice when outside of orders screens (#38641)

Avoid the notice by returning early if we're not on an admin page with wc-orders in its slug.
This commit is contained in:
Corey McKrill 2023-06-07 16:49:22 -07:00 committed by GitHub
commit ef3168abf4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 7 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: tweak
Do not execute order's page controller logic outside of orders screens.

View File

@ -131,6 +131,8 @@ class PageController {
* @return void
*/
public function setup(): void {
global $plugin_page, $pagenow;
$this->redirection_controller = new PostsRedirectionController( $this );
// Register menu.
@ -140,6 +142,11 @@ class PageController {
add_action( 'admin_menu', 'register_menu', 9 );
}
// Not on an Orders page.
if ( 'admin.php' !== $pagenow || 0 !== strpos( $plugin_page, 'wc-orders' ) ) {
return;
}
$this->set_order_type();
$this->set_action();
@ -209,11 +216,7 @@ class PageController {
* @return void
*/
private function set_order_type() {
global $plugin_page, $pagenow;
if ( 'admin.php' !== $pagenow || 0 !== strpos( $plugin_page, 'wc-orders' ) ) {
return;
}
global $plugin_page;
$this->order_type = str_replace( array( 'wc-orders--', 'wc-orders' ), '', $plugin_page );
$this->order_type = empty( $this->order_type ) ? 'shop_order' : $this->order_type;
@ -489,7 +492,7 @@ class PageController {
esc_html__( '%s must be called after the current_screen action.', 'woocommerce' ),
esc_html( __METHOD__ )
),
'x.x.x'
'7.9.0'
);
return false;
@ -504,7 +507,7 @@ class PageController {
esc_html__( '%s is not a valid order type.', 'woocommerce' ),
esc_html( $type )
),
'x.x.x'
'7.9.0'
);
return false;