Skip to content

Commit

Permalink
Fix PHP notice when outside of orders screens (woocommerce#38641)
Browse files Browse the repository at this point in the history
Avoid the notice by returning early if we're not on an admin page with wc-orders in its slug.
  • Loading branch information
coreymckrill authored Jun 7, 2023
2 parents 4c62519 + d21cd0b commit ef3168a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: tweak

Do not execute order's page controller logic outside of orders screens.
17 changes: 10 additions & 7 deletions plugins/woocommerce/src/Internal/Admin/Orders/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ function() use ( $edit_lock ) {
* @return void
*/
public function setup(): void {
global $plugin_page, $pagenow;

$this->redirection_controller = new PostsRedirectionController( $this );

// Register menu.
Expand All @@ -140,6 +142,11 @@ public function setup(): void {
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();

Expand Down Expand Up @@ -209,11 +216,7 @@ private function set_page_title( $admin_title ) {
* @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;
Expand Down Expand Up @@ -489,7 +492,7 @@ public function is_order_screen( $type = 'shop_order', $action = '' ) : bool {
esc_html__( '%s must be called after the current_screen action.', 'woocommerce' ),
esc_html( __METHOD__ )
),
'x.x.x'
'7.9.0'
);

return false;
Expand All @@ -504,7 +507,7 @@ public function is_order_screen( $type = 'shop_order', $action = '' ) : bool {
esc_html__( '%s is not a valid order type.', 'woocommerce' ),
esc_html( $type )
),
'x.x.x'
'7.9.0'
);

return false;
Expand Down

0 comments on commit ef3168a

Please sign in to comment.