| @@ -1599,30 +1599,45 @@ | ||
| 1599 | 1599 | |
| 1600 | 1600 | $data = apply_filters( 'yaymail_addon_supported_plugins', $data ); |
| 1601 | 1601 | |
| 1602 | 1602 | foreach ( array_keys( $data ) as $namespace ) { |
| 1603 | - $data[ $namespace ]['installation_status'] = []; | |
| 1604 | - $data[ $namespace ]['installation_status']['is_active'] = function_exists( $namespace . '\init' ) || function_exists( $namespace . '\addon_init' ); | |
| 1603 | + $data[ $namespace ]['installation_status'] = []; | |
| 1604 | + $data[ $namespace ]['installation_status']['is_active'] = function_exists( $namespace . '\init' ) || function_exists( $namespace . '\addon_init' ); | |
| 1605 | + $data[ $namespace ]['installation_status']['is_installed'] = false; | |
| 1605 | 1606 | } |
| 1606 | 1607 | |
| 1607 | - require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; | |
| 1608 | - require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; | |
| 1609 | - require_once ABSPATH . 'wp-admin/includes/class-wp-ajax-upgrader-skin.php'; | |
| 1610 | - require_once ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php'; | |
| 1608 | + // Storefront only needs addon metadata. Plugin-install APIs belong in wp-admin / REST. | |
| 1609 | + // install_plugin_install_status() also warns on PHP 8+ when update_plugins entries lack `slug`. | |
| 1610 | + $needs_install_check = is_admin() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ); | |
| 1611 | 1611 | |
| 1612 | - foreach ( $data as $namespace => $addon ) { | |
| 1613 | - $data[ $namespace ]['installation_status']['is_installed'] = false; | |
| 1614 | - if ( isset( $addon['plugin_slug'] ) ) { | |
| 1615 | - $plugin_status = \install_plugin_install_status( | |
| 1616 | - [ | |
| 1617 | - 'slug' => $addon['plugin_slug'], | |
| 1618 | - 'version' => '', | |
| 1619 | - ] | |
| 1620 | - ); | |
| 1621 | - $data[ $namespace ]['installation_status']['is_installed'] = $plugin_status['file'] !== false; | |
| 1622 | - $data[ $namespace ]['installation_status']['plugin_file'] = $plugin_status['file']; | |
| 1612 | + if ( $needs_install_check ) { | |
| 1613 | + if ( ! function_exists( 'get_plugins' ) ) { | |
| 1614 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| 1623 | 1615 | } |
| 1624 | - } | |
| 1616 | + | |
| 1617 | + foreach ( $data as $namespace => $addon ) { | |
| 1618 | + if ( empty( $addon['plugin_slug'] ) ) { | |
| 1619 | + continue; | |
| 1620 | + } | |
| 1621 | + | |
| 1622 | + $slug = $addon['plugin_slug']; | |
| 1623 | + if ( ! is_dir( WP_PLUGIN_DIR . '/' . $slug ) ) { | |
| 1624 | + continue; | |
| 1625 | + } | |
| 1626 | + | |
| 1627 | + $installed_plugin = get_plugins( '/' . $slug ); | |
| 1628 | + if ( empty( $installed_plugin ) ) { | |
| 1629 | + continue; | |
| 1630 | + } | |
| 1631 | + | |
| 1632 | + $keys = array_keys( $installed_plugin ); | |
| 1633 | + $plugin_file = $slug . '/' . reset( $keys ); | |
| 1634 | + | |
| 1635 | + $data[ $namespace ]['installation_status']['is_installed'] = true; | |
| 1636 | + $data[ $namespace ]['installation_status']['plugin_file'] = $plugin_file; | |
| 1637 | + }//end foreach | |
| 1638 | + }//end if | |
| 1639 | + | |
| 1625 | 1640 | return $data; |
| 1626 | 1641 | } |
| 1627 | 1642 | |
| 1628 | 1643 | public static function get_3rd_party_addons() { |