settings = $settings; add_action('admin_init', array($this, 'maybe_handle_dismiss')); add_action('admin_notices', array($this, 'render_notice')); } /** * True when the "AI" plugin is active and its image generation feature is * enabled. Mirrors that plugin's own is_enabled() logic: the global toggle * must be on first, then the per-feature toggle. * * @return bool */ private function ai_image_generation_active() { if (!defined(self::AI_PLUGIN_MARKER)) { return false; } if (!get_option(self::AI_GLOBAL_OPTION, false)) { return false; } if (!get_option(self::AI_IMAGE_FEATURE_OPTION, false)) { return false; } return true; } /** * Decide whether the notice should appear on the current screen. * * @return bool */ private function should_display() { if (!current_user_can( Settings::capability() )) { return false; } if (get_user_meta(get_current_user_id(), self::DISMISS_META, true)) { return false; } if (!$this->ai_image_generation_active()) { return false; } return $this->is_aifi_screen(); } /** * True if we're on an AIFIG-relevant admin screen, the settings page or a * post-edit screen for an enabled post type (where the duplicate button * actually appears). * * @return bool */ private function is_aifi_screen() { if (!function_exists('get_current_screen')) { return false; } $screen = get_current_screen(); if (!$screen) { return false; } if ($screen->id === 'toplevel_page_ai-featured-image-generator') { return true; } if (in_array($screen->base, array('post'), true)) { $enabled = $this->settings->get_enabled_post_types(); if (!empty($screen->post_type) && in_array($screen->post_type, $enabled, true)) { return true; } } return false; } /** * Render the compatibility notice. */ public function render_notice() { if (!$this->should_display()) { return; } $dismiss_url = wp_nonce_url( add_query_arg(self::DISMISS_ACTION, '1'), self::DISMISS_ACTION ); ?>