plugin_path = end( $plugin_path_array ); // Set plugin file. $this->plugin_file = $plugin_file; // Set plugin name. $plugin_key = $this->plugin_path . '/' . $this->plugin_file; if ( isset( $plugins[ $plugin_key ]['Name'] ) ) { $this->plugin_name = $plugins[ $plugin_key ]['Name']; } else { // Fallback if plugin data isn't available (should be rare). $this->plugin_name = 'This plugin'; } // Is AffiliateWP installed? foreach ( $plugins as $installed_plugin_path => $plugin ) { if ( 'AffiliateWP' === $plugin['Name'] ) { $this->has_affiliatewp = true; break; } } } /** * Prepares and hooks the missing AffiliateWP notice. * * @since 1.0.0 * @since 1.0.1 Modified to accept pre-translated messages. * * @param string $activate_message The full HTML message to display if AffiliateWP needs activation. * @param string $install_message The full HTML message to display if AffiliateWP needs installation. */ public function run( $activate_message, $install_message ) { $this->activate_message = $activate_message; $this->install_message = $install_message; // Display notice. add_action( 'admin_notices', [ $this, 'missing_affiliatewp_notice' ] ); } /** * Displays a notice if AffiliateWP isn't installed. * * @since 1.0.0 * * @return void */ public function missing_affiliatewp_notice() { if ( $this->has_affiliatewp ) { if ( ! empty( $this->activate_message ) ) { echo $this->activate_message; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Message is pre-escaped by calling code. } } elseif ( ! empty( $this->install_message ) ) { echo $this->install_message; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Message is pre-escaped by calling code. } } }