| @@ -10,10 +10,16 @@ | ||
| 10 | 10 | class Required { |
| 11 | 11 | |
| 12 | 12 | private $plugin_file = true; |
| 13 | 13 | |
| 14 | + /** | |
| 15 | + * Names of the plugins this one needs but does not have active. | |
| 16 | + * | |
| 17 | + * @var string[] | |
| 18 | + */ | |
| 19 | + private $required_plugins = array(); | |
| 20 | + | |
| 14 | 21 | public function __construct() { |
| 15 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) ); | |
| 16 | 22 | add_action( 'init', array( $this, 'check_plugins' ) ); |
| 17 | 23 | } |
| 18 | 24 | |
| 19 | 25 | public function check_plugins() { |
| @@ -26,14 +32,78 @@ | ||
| 26 | 32 | if ( ! file_exists( $plugin_file ) ) { |
| 27 | 33 | $this->plugin_file = false; |
| 28 | 34 | } |
| 29 | 35 | |
| 36 | + // Only wire the notice, its assets, and the plugins-list row when a | |
| 37 | + // dependency is actually missing — the same gating the pro plugin uses, | |
| 38 | + // so the red row never lingers once WooCommerce is active. | |
| 30 | 39 | if ( ! file_exists( $plugin_file ) || ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) { |
| 40 | + $this->required_plugins[] = 'WooCommerce'; | |
| 41 | + | |
| 31 | 42 | add_action( 'admin_notices', array( $this, 'install_plugin_notice' ) ); |
| 43 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) ); | |
| 44 | + add_action( 'after_plugin_row_' . plugin_basename( SUBSCRPT_FILE ), array( $this, 'required_plugins_row' ), 10, 2 ); | |
| 32 | 45 | } |
| 33 | 46 | } |
| 34 | 47 | |
| 48 | + /** | |
| 49 | + * Render a warning row below this plugin's row on the plugins list page. | |
| 50 | + * | |
| 51 | + * Mirrors the pro plugin's row: flags that the plugin is not fully active | |
| 52 | + * and lists what it still needs. | |
| 53 | + * | |
| 54 | + * @return void | |
| 55 | + */ | |
| 56 | + public function required_plugins_row() { | |
| 57 | + if ( empty( $this->required_plugins ) ) { | |
| 58 | + return; | |
| 59 | + } | |
| 60 | + | |
| 61 | + $show_auto_updates = function_exists( 'wp_is_auto_update_enabled_for_type' ) && wp_is_auto_update_enabled_for_type( 'plugin' ); | |
| 62 | + ?> | |
| 63 | + <tr class="active subscrpt-plugin-warning-row"> | |
| 64 | + <th scope="row" class="check-column"> | |
| 65 | + <span class="dashicons dashicons-warning"></span> | |
| 66 | + </th> | |
| 67 | + <td class="column-primary"> | |
| 68 | + <p><?php esc_html_e( 'This plugin is not fully active', 'subscription' ); ?></p> | |
| 69 | + </td> | |
| 70 | + <td class="column-description desc"> | |
| 71 | + <div class="plugin-description"> | |
| 72 | + <strong><?php esc_html_e( 'Required Plugins', 'subscription' ); ?></strong> | |
| 73 | + </div> | |
| 74 | + <ul> | |
| 75 | + <?php foreach ( $this->required_plugins as $plugin_name ) : ?> | |
| 76 | + <li><?php echo esc_html( $plugin_name ); ?></li> | |
| 77 | + <?php endforeach; ?> | |
| 78 | + </ul> | |
| 79 | + </td> | |
| 80 | + <?php if ( $show_auto_updates ) : ?> | |
| 81 | + <td class="column-auto-updates"> | |
| 82 | + <span class="label"></span> | |
| 83 | + <div class="notice notice-error notice-alt inline hidden"><p></p></div> | |
| 84 | + </td> | |
| 85 | + <?php endif; ?> | |
| 86 | + </tr> | |
| 87 | + <?php | |
| 88 | + } | |
| 89 | + | |
| 35 | 90 | public function enqueue_assets() { |
| 91 | + // Only load the notice styles/script — including the red plugins-list row | |
| 92 | + // tint — when a dependency is actually missing. Otherwise the row would | |
| 93 | + // stay tinted even after WooCommerce is active. | |
| 94 | + if ( empty( $this->required_plugins ) ) { | |
| 95 | + return; | |
| 96 | + } | |
| 97 | + | |
| 98 | + // Version the installer stylesheet by file mtime so CSS edits bust the | |
| 99 | + // browser cache: the plugin version is a build-time placeholder and does | |
| 100 | + // not change in place, so it cannot do that on its own. | |
| 101 | + $installer_css = SUBSCRPT_PATH . '/assets/css/installer.css'; | |
| 102 | + if ( file_exists( $installer_css ) && wp_style_is( 'sdevs_installer', 'registered' ) ) { | |
| 103 | + wp_styles()->registered['sdevs_installer']->ver = (string) filemtime( $installer_css ); | |
| 104 | + } | |
| 105 | + | |
| 36 | 106 | if ( ! wp_style_is( 'sdevs_installer' ) ) { |
| 37 | 107 | wp_enqueue_style( 'sdevs_installer' ); |
| 38 | 108 | } |
| 39 | 109 | |
| @@ -49,12 +119,12 @@ | ||
| 49 | 119 | |
| 50 | 120 | public function install_plugin_notice() { |
| 51 | 121 | if ( $this->plugin_file ) { |
| 52 | 122 | $id = 'sdevs-activate-plugin'; |
| 53 | - $label = __( 'Activate Woocommerce', 'sdevs_subscrpt' ); | |
| 123 | + $label = __( 'Activate Woocommerce', 'subscription' ); | |
| 54 | 124 | } else { |
| 55 | 125 | $id = 'sdevs-install-plugin'; |
| 56 | - $label = __( 'Install Woocommerce', 'sdevs_subscrpt' ); | |
| 126 | + $label = __( 'Install Woocommerce', 'subscription' ); | |
| 57 | 127 | } |
| 58 | 128 | |
| 59 | 129 | include 'views/required-notice.php'; |
| 60 | 130 | } |