| 1 |
<?php |
| 2 |
/** |
| 3 |
* Email Report Settings Configuration |
| 4 |
* |
| 5 |
* Default per-site configuration + field schema for the Email Reporting feature. |
| 6 |
* Used by Email_Report_Config (load/save), the renderer (templating), and the |
| 7 |
* REST endpoint (validation args). |
| 8 |
* |
| 9 |
* Free vs. Pro field availability is NOT decided here — it lives in |
| 10 |
* `Plan_Config::email_report()`. This file only describes shape and defaults. |
| 11 |
* |
| 12 |
* @package ThinkRank |
| 13 |
* @subpackage Config |
| 14 |
* @since 1.9.0 |
| 15 |
*/ |
| 16 |
|
| 17 |
declare(strict_types=1); |
| 18 |
|
| 19 |
if (!defined('ABSPATH')) { |
| 20 |
exit; |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Default Email Reporting per-site config. |
| 25 |
* |
| 26 |
* Pre-fills sensible values for a fresh install. Free plan never overrides |
| 27 |
* paid-only fields once saved; they sit dormant in the DB so they re-light |
| 28 |
* if the user upgrades. |
| 29 |
* |
| 30 |
* @return array |
| 31 |
*/ |
| 32 |
function thinkrank_get_default_email_report_config(): array { |
| 33 |
return [ |
| 34 |
'enabled' => false, |
| 35 |
'frequency_days' => 30, |
| 36 |
'recipients' => [(string) get_option('admin_email')], |
| 37 |
'subject_template' => '%site_title% SEO performance report', |
| 38 |
'logo_url' => null, |
| 39 |
'logo_link' => null, |
| 40 |
'header_background' => null, |
| 41 |
'link_to_full_report' => true, |
| 42 |
'intro_text' => null, |
| 43 |
'sections_enabled' => array_keys(thinkrank_get_email_report_default_sections()), |
| 44 |
'footer_text' => null, |
| 45 |
'additional_css' => null, |
| 46 |
'next_scheduled_at' => null, |
| 47 |
'last_sent_at' => null, |
| 48 |
]; |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Default section ordering + free/pro flag. |
| 53 |
* |
| 54 |
* Keys here are the section identifiers used everywhere — in the sections_enabled |
| 55 |
* array of the per-site config, in the Section_Registry, and in template paths. |
| 56 |
* |
| 57 |
* The order in this array is the order sections render. Pro can re-order via |
| 58 |
* `thinkrank_email_report_sections` filter; AI Highlights inserts at the top. |
| 59 |
* |
| 60 |
* @return array<string,array{label:string,requires_capability:?string}> |
| 61 |
*/ |
| 62 |
function thinkrank_get_email_report_default_sections(): array { |
| 63 |
return [ |
| 64 |
'key_metrics' => [ |
| 65 |
'label' => __('Key Metrics', 'thinkrank'), |
| 66 |
'requires_capability' => null, |
| 67 |
], |
| 68 |
'position_summary' => [ |
| 69 |
'label' => __('Position Summary', 'thinkrank'), |
| 70 |
'requires_capability' => null, |
| 71 |
], |
| 72 |
'top_winning_posts' => [ |
| 73 |
'label' => __('Top Winning Posts', 'thinkrank'), |
| 74 |
'requires_capability' => null, |
| 75 |
], |
| 76 |
'top_losing_posts' => [ |
| 77 |
'label' => __('Top Losing Posts', 'thinkrank'), |
| 78 |
'requires_capability' => null, |
| 79 |
], |
| 80 |
'top_winning_keywords' => [ |
| 81 |
'label' => __('Top Winning Keywords', 'thinkrank'), |
| 82 |
'requires_capability' => null, |
| 83 |
], |
| 84 |
'top_losing_keywords' => [ |
| 85 |
'label' => __('Top Losing Keywords', 'thinkrank'), |
| 86 |
'requires_capability' => null, |
| 87 |
], |
| 88 |
]; |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Tokens supported in subject/intro/footer text. |
| 93 |
* |
| 94 |
* Each token resolves at render time against the report context. Pro can add |
| 95 |
* tokens via the `thinkrank_email_report_tokens` filter (e.g. %client_name%). |
| 96 |
* |
| 97 |
* @return array<string,string> token => human description |
| 98 |
*/ |
| 99 |
function thinkrank_get_email_report_tokens(): array { |
| 100 |
return [ |
| 101 |
'%site_title%' => __('Site title from WordPress general settings', 'thinkrank'), |
| 102 |
'%site_url%' => __('Home URL of the site', 'thinkrank'), |
| 103 |
'%date%' => __('Date the report is sent (localized)', 'thinkrank'), |
| 104 |
'%period%' => __('Reporting period label, e.g. "May 1 – May 30"', 'thinkrank'), |
| 105 |
]; |
| 106 |
} |
| 107 |
|
| 108 |
/** |
| 109 |
* Maximum lengths for free-text fields. Defense-in-depth limits to keep |
| 110 |
* a misconfigured Pro plugin or pasted bulk content from blowing up the email. |
| 111 |
* |
| 112 |
* @return array<string,int> |
| 113 |
*/ |
| 114 |
function thinkrank_get_email_report_field_limits(): array { |
| 115 |
return [ |
| 116 |
'subject_template' => 200, |
| 117 |
'intro_text' => 5000, |
| 118 |
'footer_text' => 5000, |
| 119 |
'additional_css' => 20000, |
| 120 |
'logo_url' => 2048, |
| 121 |
'logo_link' => 2048, |
| 122 |
'header_background' => 500, |
| 123 |
]; |
| 124 |
} |
| 125 |
|