| 1 |
<?php |
| 2 |
|
| 3 |
namespace gVectors\News; |
| 4 |
|
| 5 |
/** |
| 6 |
* Immutable configuration value object for the News module. |
| 7 |
* The host plugin (wpForo, wpDiscuz, ...) injects everything at construction time, |
| 8 |
* so the module itself never references any specific plugin. |
| 9 |
*/ |
| 10 |
class Config { |
| 11 |
private $core_plugin_version; // "3.1.1" |
| 12 |
private $core_plugin_slug; // "wpforo" | "wpdiscuz" |
| 13 |
private $news_module_url; // "https://example.com/wp-content/plugins/{plugin}/admin/pages/news" |
| 14 |
private $dashboard_addons_page_slug; // admin_url('admin.php?page=XXXXXXX'); |
| 15 |
private $dashboard_menu_hook; // add_action('admin_menu', function() { //the core plugin add menu actions; do_action('XXXXXXX', $parent_slug );} |
| 16 |
private $proxy_server_url = 'https://store.gvectors.com'; // "https://store.gvectors.com" | "https://gv.loc" |
| 17 |
|
| 18 |
public function __construct( |
| 19 |
$core_plugin_version, |
| 20 |
$core_plugin_slug, |
| 21 |
$news_module_url, |
| 22 |
$dashboard_addons_page_slug, |
| 23 |
$dashboard_menu_hook |
| 24 |
) { |
| 25 |
$this->core_plugin_version = $core_plugin_version; |
| 26 |
$this->core_plugin_slug = $core_plugin_slug; |
| 27 |
$this->news_module_url = $news_module_url; |
| 28 |
$this->dashboard_addons_page_slug = $dashboard_addons_page_slug; |
| 29 |
$this->dashboard_menu_hook = $dashboard_menu_hook; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Host plugin's admin menu hook (same one the license module uses): |
| 34 |
* add_action( 'admin_menu', function() { ...; do_action( 'XXXXXXX', $parent_slug ); } ); |
| 35 |
*/ |
| 36 |
public function get_dashboard_menu_hook(): string { |
| 37 |
return $this->dashboard_menu_hook; |
| 38 |
} |
| 39 |
|
| 40 |
public function get_core_plugin_version(): string { |
| 41 |
return $this->core_plugin_version; |
| 42 |
} |
| 43 |
|
| 44 |
public function get_core_plugin_slug(): string { |
| 45 |
return $this->core_plugin_slug; |
| 46 |
} |
| 47 |
|
| 48 |
public function get_news_module_url(): string { |
| 49 |
return $this->news_module_url; |
| 50 |
} |
| 51 |
|
| 52 |
public function get_dashboard_addons_page_slug(): string { |
| 53 |
return $this->dashboard_addons_page_slug; |
| 54 |
} |
| 55 |
|
| 56 |
public function get_proxy_server_url(): string { |
| 57 |
return $this->proxy_server_url; |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Absolute URL of the host plugin's Addons dashboard page. |
| 62 |
* Used for the {dashboard_url} email token and notice links. |
| 63 |
*/ |
| 64 |
public function get_dashboard_addons_url(): string { |
| 65 |
return admin_url( 'admin.php?page=' . $this->dashboard_addons_page_slug ); |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Common prefix for every option, transient, user meta key, cron hook and |
| 70 |
* AJAX action this module registers. |
| 71 |
* |
| 72 |
* INTENTIONALLY NOT plugin-prefixed: the news module is ONE module for ALL |
| 73 |
* gVectors products. When wpForo and wpDiscuz are installed together, they |
| 74 |
* share the same options, the same news cache, the same cron job and the |
| 75 |
* same per-admin email preferences — news and licenses are gVectors-wide, |
| 76 |
* not per-plugin. (Same pattern as the license module's shared |
| 77 |
* 'gvectors_revalidate' / 'gvectors_daily_cron' hooks.) |
| 78 |
*/ |
| 79 |
public function get_prefix(): string { |
| 80 |
return 'gvectors_'; |
| 81 |
} |
| 82 |
|
| 83 |
// ── Option / meta / transient names ── |
| 84 |
|
| 85 |
/** Master opt-in (WordPress.org Guideline 7). No opt-in → zero outbound requests. */ |
| 86 |
public function get_service_enabled_option(): string { |
| 87 |
return $this->get_prefix() . 'addons_service_enabled'; |
| 88 |
} |
| 89 |
|
| 90 |
/** Option: site-wide channel × category matrix {notices{cat=>bool}, emails{cat=>bool}}. */ |
| 91 |
public function get_site_prefs_option(): string { |
| 92 |
return $this->get_prefix() . 'site_channel_prefs'; |
| 93 |
} |
| 94 |
|
| 95 |
/** User meta: per-admin matrix {unsubscribed, notices{cat=>bool}, emails{cat=>bool}}. */ |
| 96 |
public function get_user_prefs_meta(): string { |
| 97 |
return $this->get_prefix() . 'news_prefs'; |
| 98 |
} |
| 99 |
|
| 100 |
/** Admin page slug of the News & Emails settings page. */ |
| 101 |
public function get_settings_page_slug(): string { |
| 102 |
return $this->core_plugin_slug . '-news-settings'; |
| 103 |
} |
| 104 |
|
| 105 |
/** Absolute URL of the News & Emails settings page (email footers link here). */ |
| 106 |
public function get_settings_page_url(): string { |
| 107 |
return admin_url( 'admin.php?page=' . $this->get_settings_page_slug() ); |
| 108 |
} |
| 109 |
|
| 110 |
/** "Not now" flag for the first-activation opt-in notice. */ |
| 111 |
public function get_optin_notice_dismissed_option(): string { |
| 112 |
return $this->get_prefix() . 'optin_notice_dismissed'; |
| 113 |
} |
| 114 |
|
| 115 |
/** Transient caching the daily news payload from the proxy. */ |
| 116 |
public function get_news_transient(): string { |
| 117 |
return $this->get_prefix() . 'news'; |
| 118 |
} |
| 119 |
|
| 120 |
/** User meta: array of dismissed news ids. */ |
| 121 |
public function get_dismissed_news_meta(): string { |
| 122 |
return $this->get_prefix() . 'dismissed_news'; |
| 123 |
} |
| 124 |
|
| 125 |
/** User meta: array of news ids already emailed to this admin. */ |
| 126 |
public function get_emailed_news_meta(): string { |
| 127 |
return $this->get_prefix() . 'emailed_news'; |
| 128 |
} |
| 129 |
|
| 130 |
/** User meta: array of "license_id:phase" reminder keys already emailed. */ |
| 131 |
public function get_emailed_phases_meta(): string { |
| 132 |
return $this->get_prefix() . 'emailed_license_phases'; |
| 133 |
} |
| 134 |
|
| 135 |
/** Option: transaction ids a purchase-confirmation email was already sent for. */ |
| 136 |
public function get_emailed_transactions_option(): string { |
| 137 |
return $this->get_prefix() . 'emailed_transactions'; |
| 138 |
} |
| 139 |
|
| 140 |
/** Option: "transaction_id:phase" keys an abandoned-checkout email was already sent for. */ |
| 141 |
public function get_abandoned_emailed_option(): string { |
| 142 |
return $this->get_prefix() . 'abandoned_emailed'; |
| 143 |
} |
| 144 |
|
| 145 |
/** User meta: addon slugs already recommended to this admin (each at most once, ever). */ |
| 146 |
public function get_emailed_recs_meta(): string { |
| 147 |
return $this->get_prefix() . 'emailed_recommendations'; |
| 148 |
} |
| 149 |
|
| 150 |
/** Daily cron hook name. */ |
| 151 |
public function get_cron_hook(): string { |
| 152 |
return $this->get_prefix() . 'daily_news_sync'; |
| 153 |
} |
| 154 |
|
| 155 |
/** Nonce action shared by this module's AJAX endpoints. */ |
| 156 |
public function get_nonce_action(): string { |
| 157 |
return $this->get_prefix() . 'news_nonce'; |
| 158 |
} |
| 159 |
|
| 160 |
/** |
| 161 |
* Option name THIS plugin's license module stores local licenses in. |
| 162 |
* This one IS plugin-prefixed — the license module keeps per-plugin storage. |
| 163 |
* The cron merges the licenses of every registered gVectors plugin. |
| 164 |
*/ |
| 165 |
public function get_licenses_option(): string { |
| 166 |
return $this->core_plugin_slug . '_gvectors_licenses'; |
| 167 |
} |
| 168 |
|
| 169 |
// ── Behavior knobs ── |
| 170 |
|
| 171 |
public function get_request_timeout(): int { |
| 172 |
return 10; |
| 173 |
} |
| 174 |
|
| 175 |
public function get_news_cache_ttl(): int { |
| 176 |
return DAY_IN_SECONDS; |
| 177 |
} |
| 178 |
|
| 179 |
/** Maximum number of news admin notices rendered at once (Guideline 11). */ |
| 180 |
public function get_max_notices(): int { |
| 181 |
return 3; |
| 182 |
} |
| 183 |
|
| 184 |
public function get_privacy_policy_url(): string { |
| 185 |
return $this->get_proxy_server_url() . '/privacy.html'; |
| 186 |
} |
| 187 |
} |
| 188 |
|