> */ private $options_map; public function __construct(string $id, string $name, string $plugin_file, string $category, array $options_map = []) { $this->id = $id; $this->name = $name; $this->plugin_file = $plugin_file; $this->category = $category; $this->options_map = $options_map; } public function id(): string { return $this->id; } public function name(): string { return $this->name; } public function plugin_file(): string { return $this->plugin_file; } public function is_active(array $wp_context): bool { $plugins = isset($wp_context['plugins']) && is_array($wp_context['plugins']) ? $wp_context['plugins'] : []; foreach ($plugins as $pl) { if (!is_array($pl)) { continue; } if (isset($pl['file']) && (string) $pl['file'] === $this->plugin_file) { return true; } } return false; } /** * @return array */ public function collect_context(): array { $ctx = []; foreach ($this->options_map as $opt_name => $keys) { $val = get_option($opt_name, null); if ($val === null) { continue; } $ctx[$opt_name] = $this->subset($val, $keys); } return Redactor::redact_array($ctx); } /** * @return array> */ public function generate_findings(array $wp_context): array { if (!$this->is_active($wp_context)) { return []; } $version = ''; $plugins = isset($wp_context['plugins']) && is_array($wp_context['plugins']) ? $wp_context['plugins'] : []; foreach ($plugins as $pl) { if (!is_array($pl)) { continue; } if ((string) ($pl['file'] ?? '') === $this->plugin_file) { $version = (string) ($pl['version'] ?? ''); break; } } $ctx = $this->collect_context(); return [ [ 'id' => 'adapter_' . $this->id . '_detected', 'title' => $this->name . I18n::tr(' detected (Adapter)', ' - تم اكتشاف الإضافة (Adapter)'), 'category' => $this->category, 'severity' => 'info', 'score_impact' => 0, 'status' => 'open', 'check_id' => 'adapter:' . $this->id, 'evidence' => [ 'source' => 'options', 'details' => 'plugin_file=' . $this->plugin_file . ' version=' . $version, 'samples' => $ctx, ], 'why_it_matters' => I18n::tr( 'This context helps explain findings and connect them to the active plugin and its settings.', 'هذه المعلومة تساعد على تفسير بعض النتائج وربطها بإضافات وإعدادات فعلية.' ), 'recommendation_steps' => [ I18n::tr('For performance or SEO findings, review this plugin first because it may control caching or metadata.', 'إن كانت هناك نتائج أداء أو SEO، راجع إعدادات هذه الإضافة أولا لأنها قد تتحكم في التخزين المؤقت أو البيانات الوصفية.'), ], 'retest' => [ 'how' => I18n::tr('Run the audit after changing the plugin settings.', 'شغّل الفحص بعد أي تغيير في إعدادات الإضافة.'), 'pass_condition' => I18n::tr('The updated settings are reflected in the evidence and findings.', 'تنعكس الإعدادات المحدثة في الأدلة والنتائج.'), ], ], ]; } /** * @param mixed $val * @param array $keys * @return mixed */ private function subset($val, array $keys) { if (empty($keys)) { return $val; } if (!is_array($val)) { return $val; } $out = []; foreach ($keys as $k) { if (array_key_exists($k, $val)) { $out[$k] = $val[$k]; } } return $out; } }