From 5bef0528290e2ee199c3336a418ada6a11970475 Mon Sep 17 00:00:00 2001 From: Colin Leroy-Mira Date: Tue, 22 Feb 2022 08:34:25 +0100 Subject: [PATCH 1/5] Avoid calling plugin_dir_url a lot --- src/Domain/Package.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Domain/Package.php b/src/Domain/Package.php index d559a7169a1..23505f01fe4 100644 --- a/src/Domain/Package.php +++ b/src/Domain/Package.php @@ -27,6 +27,13 @@ class Package { */ private $path; + /** + * Holds locally the plugin_dir_url to avoid recomputing it. + * + * @var string + */ + private $plugin_dir_url; + /** * Holds the feature gating class instance. * @@ -45,6 +52,9 @@ public function __construct( $version, $plugin_path, FeatureGating $feature_gati $this->version = $version; $this->path = $plugin_path; $this->feature_gating = $feature_gating; + + // Append index.php so WP does not return the parent directory. + $this->plugin_dir_url = plugin_dir_url( $this->path . '/index.php' ); } /** @@ -77,8 +87,7 @@ public function get_path( $relative_path = '' ) { * @return string */ public function get_url( $relative_url = '' ) { - // Append index.php so WP does not return the parent directory. - return plugin_dir_url( $this->path . '/index.php' ) . $relative_url; + return $this->plugin_dir_url . $relative_url; } /** From df9de0bda8312ef47a551e30de3142215fa89d44 Mon Sep 17 00:00:00 2001 From: Colin Leroy-Mira Date: Fri, 25 Feb 2022 22:23:01 +0100 Subject: [PATCH 2/5] Fix crash if woocommerce admin is disabled With Woocommerce's PR https://github.com/woocommerce/woocommerce/pull/31991 applied, if woocommerce admin is disabled via the woocommerce_admin_disabled filter, the InboxNotifications block could crash. --- src/InboxNotifications.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/InboxNotifications.php b/src/InboxNotifications.php index f264241be21..d95233bf4c3 100644 --- a/src/InboxNotifications.php +++ b/src/InboxNotifications.php @@ -59,7 +59,7 @@ public static function delete_surface_cart_checkout_blocks_notification() { * Creates a notification letting merchants know about the Cart and Checkout Blocks. */ public static function create_surface_cart_checkout_blocks_notification() { - + $node_ids = []; // If this is the feature plugin, then we don't need to do this. This should only show when Blocks is bundled // with WooCommerce Core. if ( Package::feature()->is_feature_plugin_build() ) { @@ -74,9 +74,10 @@ public static function create_surface_cart_checkout_blocks_notification() { return; } - $data_store = \WC_Data_Store::load( 'admin-note' ); - $note_ids = $data_store->get_notes_with_name( self::SURFACE_CART_CHECKOUT_NOTE_NAME ); - + if( !apply_filters( 'woocommerce_admin_disabled', false ) ) { + $data_store = \WC_Data_Store::load( 'admin-note' ); + $note_ids = $data_store->get_notes_with_name( self::SURFACE_CART_CHECKOUT_NOTE_NAME ); + } // Calculate store's eligibility to be shown the notice, starting with whether they have any plugins we know to // be incompatible with Blocks. This check is done before checking if the note exists already because we want to // delete the note if the merchant activates an ineligible plugin. From eb0ed6eb7525ff6e63eb378464c3cb4602c4100e Mon Sep 17 00:00:00 2001 From: Colin Leroy-Mira Date: Fri, 25 Feb 2022 22:38:11 +0100 Subject: [PATCH 3/5] Fix coding style --- src/InboxNotifications.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/InboxNotifications.php b/src/InboxNotifications.php index d95233bf4c3..2d5c547e8fe 100644 --- a/src/InboxNotifications.php +++ b/src/InboxNotifications.php @@ -74,7 +74,7 @@ public static function create_surface_cart_checkout_blocks_notification() { return; } - if( !apply_filters( 'woocommerce_admin_disabled', false ) ) { + if ( ! apply_filters( 'woocommerce_admin_disabled', false ) ) { $data_store = \WC_Data_Store::load( 'admin-note' ); $note_ids = $data_store->get_notes_with_name( self::SURFACE_CART_CHECKOUT_NOTE_NAME ); } From 278213e193692c3465841f7c0a0a81ab4b3a38a6 Mon Sep 17 00:00:00 2001 From: Colin Leroy-Mira Date: Tue, 1 Mar 2022 15:17:16 +0100 Subject: [PATCH 4/5] Simplify code path --- src/InboxNotifications.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/InboxNotifications.php b/src/InboxNotifications.php index 2d5c547e8fe..8c157d635f9 100644 --- a/src/InboxNotifications.php +++ b/src/InboxNotifications.php @@ -74,10 +74,12 @@ public static function create_surface_cart_checkout_blocks_notification() { return; } - if ( ! apply_filters( 'woocommerce_admin_disabled', false ) ) { - $data_store = \WC_Data_Store::load( 'admin-note' ); - $note_ids = $data_store->get_notes_with_name( self::SURFACE_CART_CHECKOUT_NOTE_NAME ); + if ( apply_filters( 'woocommerce_admin_disabled', false ) ) { + return; } + + $data_store = \WC_Data_Store::load( 'admin-note' ); + $note_ids = $data_store->get_notes_with_name( self::SURFACE_CART_CHECKOUT_NOTE_NAME ); // Calculate store's eligibility to be shown the notice, starting with whether they have any plugins we know to // be incompatible with Blocks. This check is done before checking if the note exists already because we want to // delete the note if the merchant activates an ineligible plugin. From 2ef02f922ab5bb8ec45c3de6df6a1ff10c3e87d0 Mon Sep 17 00:00:00 2001 From: Colin Leroy-Mira Date: Tue, 1 Mar 2022 15:18:26 +0100 Subject: [PATCH 5/5] Remove unused initialization --- src/InboxNotifications.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/InboxNotifications.php b/src/InboxNotifications.php index 8c157d635f9..cb71f94ea74 100644 --- a/src/InboxNotifications.php +++ b/src/InboxNotifications.php @@ -59,7 +59,6 @@ public static function delete_surface_cart_checkout_blocks_notification() { * Creates a notification letting merchants know about the Cart and Checkout Blocks. */ public static function create_surface_cart_checkout_blocks_notification() { - $node_ids = []; // If this is the feature plugin, then we don't need to do this. This should only show when Blocks is bundled // with WooCommerce Core. if ( Package::feature()->is_feature_plugin_build() ) {