WooCommerce: fixes the checks when migrating the product form template (#48386)

* fixes the checks when migrating the template

* changelog

* minor jsdoc enhancement

* yoda condition
This commit is contained in:
Damián Suárez 2024-06-12 12:36:21 +01:00 committed by GitHub
parent 2c754bb667
commit c85fe30dd2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 14 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
WooCommerce: fixes the checks when migrating the product form template

View File

@ -34,32 +34,27 @@ class ProductFormsController {
* @return void
*/
public function migrate_templates_when_plugin_updated( \WP_Upgrader $upgrader, array $hook_extra ) {
/*
* Check whether $hook_extra['plugins'] contains the WooCommerce plugin.
* It seems that $hook_extra may be `null` in some cases.
* @see https://github.com/woocommerce/woocommerce/pull/48221#pullrequestreview-2102772713
*/
if ( ! isset( $hook_extra['plugins'] ) || ! is_array( $hook_extra['plugins'] ) ) {
// If it is not a plugin hook type, bail early.
$type = isset( $hook_extra['type'] ) ? $hook_extra['type'] : '';
if ( 'plugin' !== $type ) {
return;
}
// Check if WooCommerce plugin was updated.
// If it is not the WooCommerce plugin, bail early.
$plugins = isset( $hook_extra['plugins'] ) ? $hook_extra['plugins'] : array();
if (
! in_array( 'woocommerce/woocommerce.php', $hook_extra['plugins'], true )
! in_array( 'woocommerce/woocommerce.php', $plugins, true )
) {
return;
}
// Check if the action is an `update` or `install` action for a plugin.
// If the action is not install or update, bail early.
$action = isset( $hook_extra['action'] ) ? $hook_extra['action'] : '';
if (
'install' !== $action && 'update' !== $action ||
'plugin' !== $hook_extra['type']
) {
if ( 'install' !== $action && 'update' !== $action ) {
return;
}
// Trigger the migration process.
$this->migrate_product_form_posts( $action );
}