← All changes
|
includes/seo/class-email-report-section-registry.php
+12
-29
2.3.0
→
2.9.0
View file →
| @@ -2,11 +2,11 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * Email Report Section Registry |
| 4 | 4 | * |
| 5 | 5 | * Holds the ordered list of section objects that make up the email body. |
| 6 | - * Free code registers the six built-in sections at boot. The Pro plugin | |
| 7 | - * adds AI Highlights (or any other section) by hooking | |
| 8 | - * `thinkrank_email_report_register_sections` and calling register(). | |
| 6 | + * Free code registers the six built-in sections at boot. Other plugins add | |
| 7 | + * sections by hooking `thinkrank_email_report_register_sections` and calling | |
| 8 | + * register(). | |
| 9 | 9 | * |
| 10 | 10 | * @package ThinkRank |
| 11 | 11 | * @subpackage SEO |
| 12 | 12 | * @since 1.9.0 |
| @@ -15,9 +15,8 @@ | ||
| 15 | 15 | declare(strict_types=1); |
| 16 | 16 | |
| 17 | 17 | namespace ThinkRank\SEO; |
| 18 | 18 | |
| 19 | -use ThinkRank\Core\Plan_Config; | |
| 20 | 19 | use ThinkRank\SEO\Email_Report_Sections\Email_Report_Section_Interface; |
| 21 | 20 | |
| 22 | 21 | if (!defined('ABSPATH')) { |
| 23 | 22 | exit; |
| @@ -35,10 +34,10 @@ | ||
| 35 | 34 | */ |
| 36 | 35 | private array $sections = []; |
| 37 | 36 | |
| 38 | 37 | /** |
| 39 | - * Register a section. Last writer wins on key collision so Pro can | |
| 40 | - * intentionally override a free section if it ever needs to (rare). | |
| 38 | + * Register a section. Last writer wins on key collision so an extension | |
| 39 | + * can intentionally override a built-in section if it ever needs to. | |
| 41 | 40 | */ |
| 42 | 41 | public function register(Email_Report_Section_Interface $section): void { |
| 43 | 42 | $this->sections[$section->key()] = $section; |
| 44 | 43 | } |
| @@ -44,9 +43,9 @@ | ||
| 44 | 43 | } |
| 45 | 44 | |
| 46 | 45 | /** |
| 47 | 46 | * Drop a section by key. Free code shouldn't call this — it's here |
| 48 | - * for tests and for the Pro plugin if ever needed. | |
| 47 | + * for tests and extensions. | |
| 49 | 48 | */ |
| 50 | 49 | public function unregister(string $key): void { |
| 51 | 50 | unset($this->sections[$key]); |
| 52 | 51 | } |
| @@ -58,21 +57,16 @@ | ||
| 58 | 57 | return $this->sections; |
| 59 | 58 | } |
| 60 | 59 | |
| 61 | 60 | /** |
| 62 | - * Resolve the ordered, capability-filtered, user-enabled section list | |
| 63 | - * for a given config. Returned in the order they should render. | |
| 61 | + * Resolve the ordered, enabled section list for a given config. Returned | |
| 62 | + * in the order they should render. | |
| 64 | 63 | * |
| 65 | - * Pro can re-order or insert sections via the | |
| 66 | - * `thinkrank_email_report_sections` filter — that's how AI Highlights | |
| 67 | - * jumps to the top of the list. | |
| 68 | - * | |
| 69 | - * @param array $config Per-site Email Report config. | |
| 64 | + * @param array $config Resolved Email Report config. | |
| 70 | 65 | * @return array<int,Email_Report_Section_Interface> |
| 71 | 66 | */ |
| 72 | 67 | public function resolve_for(array $config): array { |
| 73 | 68 | $enabled = $config['sections_enabled'] ?? []; |
| 74 | - $caps = Plan_Config::email_report(); | |
| 75 | 69 | |
| 76 | 70 | $resolved = []; |
| 77 | 71 | foreach ($this->sections as $key => $section) { |
| 78 | 72 | if (!in_array($key, $enabled, true)) { |
| @@ -77,13 +71,8 @@ | ||
| 77 | 71 | foreach ($this->sections as $key => $section) { |
| 78 | 72 | if (!in_array($key, $enabled, true)) { |
| 79 | 73 | continue; |
| 80 | 74 | } |
| 81 | - $required = $section->requires_capability(); | |
| 82 | - if ($required !== null && empty($caps[$required])) { | |
| 83 | - // Capability not granted by current plan — silently skip. | |
| 84 | - continue; | |
| 85 | - } | |
| 86 | 75 | $resolved[$key] = $section; |
| 87 | 76 | } |
| 88 | 77 | |
| 89 | 78 | /** |
| @@ -88,15 +77,12 @@ | ||
| 88 | 77 | |
| 89 | 78 | /** |
| 90 | 79 | * Filter the ordered section list for a single report. |
| 91 | 80 | * |
| 92 | - * Pro plugin uses this to insert AI Highlights at the top, or | |
| 93 | - * re-arrange sections per agency preference. | |
| 94 | - * | |
| 95 | 81 | * @since 1.9.0 |
| 96 | 82 | * |
| 97 | 83 | * @param array<string,Email_Report_Section_Interface> $resolved Ordered sections, key => section. |
| 98 | - * @param array $config Per-site config. | |
| 84 | + * @param array $config Resolved config. | |
| 99 | 85 | */ |
| 100 | 86 | $resolved = apply_filters('thinkrank_email_report_sections', $resolved, $config); |
| 101 | 87 | |
| 102 | 88 | // Re-validate after filter: drop anything that doesn't implement the contract. |
| @@ -106,13 +92,11 @@ | ||
| 106 | 92 | )); |
| 107 | 93 | } |
| 108 | 94 | |
| 109 | 95 | /** |
| 110 | - * Convenience: list of section keys to expose in the admin UI. | |
| 111 | - * Mirrors the registry order, includes pro-gated sections so the UI | |
| 112 | - * can render them with a lock chip. | |
| 96 | + * Section catalog for the admin UI, in registry order. | |
| 113 | 97 | * |
| 114 | - * @return array<int,array{key:string,label:string,requires_capability:?string}> | |
| 98 | + * @return array<int,array{key:string,label:string,default_enabled:bool}> | |
| 115 | 99 | */ |
| 116 | 100 | public function describe_for_ui(): array { |
| 117 | 101 | $out = []; |
| 118 | 102 | foreach ($this->sections as $key => $section) { |
| @@ -118,9 +102,8 @@ | ||
| 118 | 102 | foreach ($this->sections as $key => $section) { |
| 119 | 103 | $out[] = [ |
| 120 | 104 | 'key' => $key, |
| 121 | 105 | 'label' => $section->label(), |
| 122 | - 'requires_capability' => $section->requires_capability(), | |
| 123 | 106 | 'default_enabled' => $section->default_enabled(), |
| 124 | 107 | ]; |
| 125 | 108 | } |
| 126 | 109 | return $out; |