| @@ -1552,92 +1552,34 @@ | ||
| 1552 | 1552 | 'description' => 'Customize <strong>Custom User Registration Fields for WooCommerce</strong> emails with <strong>YayMail</strong> email builder.', |
| 1553 | 1553 | 'plugin_slug' => 'yaymail-addon-for-custom-user-registration-fields-addify', |
| 1554 | 1554 | 'categories' => [ 'others' ], |
| 1555 | 1555 | ], |
| 1556 | - 'YayMailAddonSalesman' => [ | |
| 1557 | - 'plugin_name' => 'Salesman (by MarketPress)', | |
| 1558 | - 'template_ids' => [], | |
| 1559 | - 'slug_name' => 'salesman', | |
| 1560 | - 'link_upgrade' => '', | |
| 1561 | - 'is_3rd_party_installed' => class_exists( 'MarketPress_Salesman' ), | |
| 1562 | - 'description' => 'Customize <strong>Salesman</strong> emails with <strong>YayMail</strong> email builder.', | |
| 1563 | - 'plugin_slug' => 'yaymail-addon-for-salesman-by-marketpress', | |
| 1564 | - 'categories' => [ 'marketing' ], | |
| 1565 | - ], | |
| 1566 | - 'YayMailAddonForBlocksy' => [ | |
| 1567 | - 'plugin_name' => 'YayMail Addon For Blocksy', | |
| 1568 | - 'template_ids' => self::get_template_ids( | |
| 1569 | - [ | |
| 1570 | - 'BackInStockEmail', | |
| 1571 | - 'ConfirmSubscriptionEmail', | |
| 1572 | - 'SubscriptionConfirmedEmail', | |
| 1573 | - ] | |
| 1574 | - ), | |
| 1575 | - 'slug_name' => 'blocksy', | |
| 1576 | - 'link_upgrade' => 'https://yaycommerce.com/yaymail-addons/yaymail-addon-for-blocksy/', | |
| 1577 | - 'is_3rd_party_installed' => class_exists( 'Blocksy\Plugin' ), | |
| 1578 | - 'description' => 'Customize <strong>Blocksy</strong> emails with <strong>YayMail</strong> email builder.', | |
| 1579 | - 'plugin_slug' => 'yaymail-addon-for-blocksy', | |
| 1580 | - 'categories' => [ 'marketing' ], | |
| 1581 | - ], | |
| 1582 | - 'YayMailAddonForWoodmart' => [ | |
| 1583 | - 'plugin_name' => 'YayMail Addon For WoodMart', | |
| 1584 | - 'template_ids' => self::get_template_ids( | |
| 1585 | - [ | |
| 1586 | - 'XTS_Email_Wishlist_Back_In_Stock', | |
| 1587 | - 'XTS_Email_Wishlist_On_Sale_Products', | |
| 1588 | - 'XTS_Email_Wishlist_Promotional', | |
| 1589 | - ] | |
| 1590 | - ), | |
| 1591 | - 'slug_name' => 'woodmart', | |
| 1592 | - 'link_upgrade' => 'https://yaycommerce.com/yaymail-addons/yaymail-addon-for-woodmart/', | |
| 1593 | - 'is_3rd_party_installed' => defined( 'WOODMART_THEME_DIR' ), | |
| 1594 | - 'description' => 'Customize <strong>WoodMart</strong> emails with <strong>YayMail</strong> email builder.', | |
| 1595 | - 'plugin_slug' => 'yaymail-addon-for-woodmart', | |
| 1596 | - 'categories' => [ 'marketing' ], | |
| 1597 | - ], | |
| 1598 | 1556 | ]; |
| 1599 | 1557 | |
| 1600 | - $data = apply_filters( 'yaymail_addon_supported_plugins', $data ); | |
| 1601 | - | |
| 1602 | 1558 | 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' ); | |
| 1605 | - $data[ $namespace ]['installation_status']['is_installed'] = false; | |
| 1559 | + $data[ $namespace ]['installation_status'] = []; | |
| 1560 | + $data[ $namespace ]['installation_status']['is_active'] = function_exists( $namespace . '\init' ) || function_exists( $namespace . '\addon_init' ); | |
| 1606 | 1561 | } |
| 1607 | 1562 | |
| 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 ); | |
| 1563 | + require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; | |
| 1564 | + require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; | |
| 1565 | + require_once ABSPATH . 'wp-admin/includes/class-wp-ajax-upgrader-skin.php'; | |
| 1566 | + require_once ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php'; | |
| 1611 | 1567 | |
| 1612 | - if ( $needs_install_check ) { | |
| 1613 | - if ( ! function_exists( 'get_plugins' ) ) { | |
| 1614 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| 1568 | + foreach ( $data as $namespace => $addon ) { | |
| 1569 | + $data[ $namespace ]['installation_status']['is_installed'] = false; | |
| 1570 | + if ( isset( $addon['plugin_slug'] ) ) { | |
| 1571 | + $plugin_status = \install_plugin_install_status( | |
| 1572 | + [ | |
| 1573 | + 'slug' => $addon['plugin_slug'], | |
| 1574 | + 'version' => '', | |
| 1575 | + ] | |
| 1576 | + ); | |
| 1577 | + $data[ $namespace ]['installation_status']['is_installed'] = $plugin_status['file'] !== false; | |
| 1578 | + $data[ $namespace ]['installation_status']['plugin_file'] = $plugin_status['file']; | |
| 1615 | 1579 | } |
| 1580 | + } | |
| 1616 | 1581 | |
| 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 | - | |
| 1640 | 1582 | return $data; |
| 1641 | 1583 | } |
| 1642 | 1584 | |
| 1643 | 1585 | public static function get_3rd_party_addons() { |
| @@ -1649,11 +1591,8 @@ | ||
| 1649 | 1591 | ); |
| 1650 | 1592 | } |
| 1651 | 1593 | |
| 1652 | 1594 | public static function get_template_ids( array $template_names ): array { |
| 1653 | - if ( ! function_exists( 'WC' ) || ! class_exists( 'WC_Emails' ) ) { | |
| 1654 | - return []; | |
| 1655 | - } | |
| 1656 | 1595 | |
| 1657 | 1596 | return array_filter( |
| 1658 | 1597 | array_map( |
| 1659 | 1598 | function ( $template_name ) { |