views
6 months ago
class-wc-helper-admin.php
4 months ago
class-wc-helper-api.php
1 year ago
class-wc-helper-compat.php
5 years ago
class-wc-helper-options.php
3 years ago
class-wc-helper-orders-api.php
2 years ago
class-wc-helper-sanitization.php
1 year ago
class-wc-helper-subscriptions-api.php
4 months ago
class-wc-helper-updater.php
2 months ago
class-wc-helper.php
4 months ago
class-wc-plugin-api-updater.php
1 year ago
class-wc-product-usage-notice.php
1 year ago
class-wc-woo-helper-connection.php
4 months ago
class-wc-woo-update-manager-plugin.php
2 years ago
class-wc-woo-update-manager-plugin.php
131 lines
| 1 | <?php |
| 2 | /** |
| 3 | * A utility class for Woo Update Manager plugin. |
| 4 | * |
| 5 | * @class WC_Woo_Update_Manager_Plugin |
| 6 | * @package WooCommerce\Admin\Helper |
| 7 | */ |
| 8 | |
| 9 | use Automattic\WooCommerce\Admin\PageController; |
| 10 | |
| 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | exit; |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * WC_Helper_Plugin Class |
| 17 | * |
| 18 | * Contains the logic to manage the Woo Update Manager plugin. |
| 19 | */ |
| 20 | class WC_Woo_Update_Manager_Plugin { |
| 21 | const WOO_UPDATE_MANAGER_PLUGIN_MAIN_FILE = 'woo-update-manager/woo-update-manager.php'; |
| 22 | const WOO_UPDATE_MANAGER_DOWNLOAD_URL = 'https://woocommerce.com/product-download/woo-update-manager'; |
| 23 | const WOO_UPDATE_MANAGER_SLUG = 'woo-update-manager'; |
| 24 | |
| 25 | /** |
| 26 | * Loads the class, runs on init. |
| 27 | * |
| 28 | * @return void |
| 29 | */ |
| 30 | public static function load(): void { |
| 31 | add_action( 'admin_notices', array( __CLASS__, 'show_woo_update_manager_install_notice' ) ); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Check if the Woo Update Manager plugin is active. |
| 36 | * |
| 37 | * @return bool |
| 38 | */ |
| 39 | public static function is_plugin_active(): bool { |
| 40 | return is_plugin_active_for_network( self::WOO_UPDATE_MANAGER_PLUGIN_MAIN_FILE ) || is_plugin_active( self::WOO_UPDATE_MANAGER_PLUGIN_MAIN_FILE ); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Check if the Woo Update Manager plugin is installed. |
| 45 | * |
| 46 | * @return bool |
| 47 | */ |
| 48 | public static function is_plugin_installed(): bool { |
| 49 | return file_exists( WP_PLUGIN_DIR . '/' . self::WOO_UPDATE_MANAGER_PLUGIN_MAIN_FILE ); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Generate the URL to install the Woo Update Manager plugin. |
| 54 | * |
| 55 | * @return string |
| 56 | */ |
| 57 | public static function generate_install_url(): string { |
| 58 | $install_url = WC_Helper::get_install_base_url() . self::WOO_UPDATE_MANAGER_SLUG . '/'; |
| 59 | |
| 60 | return WC_Helper_API::add_auth_parameters( $install_url ); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Get the id of the Woo Update Manager plugin. |
| 65 | * |
| 66 | * @return int |
| 67 | */ |
| 68 | public static function get_plugin_slug(): string { |
| 69 | return self::WOO_UPDATE_MANAGER_SLUG; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Show a notice on the WC admin pages to install or activate the Woo Update Manager plugin. |
| 74 | * |
| 75 | * @return void |
| 76 | */ |
| 77 | public static function show_woo_update_manager_install_notice(): void { |
| 78 | if ( ! current_user_can( 'install_plugins' ) ) { |
| 79 | return; |
| 80 | } |
| 81 | |
| 82 | if ( ! WC_Helper::is_site_connected() ) { |
| 83 | return; |
| 84 | } |
| 85 | |
| 86 | if ( ! PageController::is_admin_or_embed_page() ) { |
| 87 | return; |
| 88 | } |
| 89 | |
| 90 | if ( self::is_plugin_installed() && self::is_plugin_active() ) { |
| 91 | return; |
| 92 | } |
| 93 | |
| 94 | if ( ! self::is_plugin_installed() ) { |
| 95 | |
| 96 | if ( self::install_admin_notice_dismissed() ) { |
| 97 | return; |
| 98 | } |
| 99 | |
| 100 | include __DIR__ . '/views/html-notice-woo-updater-not-installed.php'; |
| 101 | return; |
| 102 | } |
| 103 | |
| 104 | if ( self::activate_admin_notice_dismissed() ) { |
| 105 | return; |
| 106 | } |
| 107 | |
| 108 | include __DIR__ . '/views/html-notice-woo-updater-not-activated.php'; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Check if the installation notice has been dismissed. |
| 113 | * |
| 114 | * @return bool |
| 115 | */ |
| 116 | protected static function install_admin_notice_dismissed(): bool { |
| 117 | return get_user_meta( get_current_user_id(), 'dismissed_woo_updater_not_installed_notice', true ); |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Check if the activation notice has been dismissed. |
| 122 | * |
| 123 | * @return bool |
| 124 | */ |
| 125 | protected static function activate_admin_notice_dismissed(): bool { |
| 126 | return get_user_meta( get_current_user_id(), 'dismissed_woo_updater_not_activated_notice', true ); |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | WC_Woo_Update_Manager_Plugin::load(); |
| 131 |