PluginProbe ʕ •ᴥ•ʔ
Custom Twitter Feeds – A Tweets Widget or X Feed Widget / 2.8.0
Custom Twitter Feeds – A Tweets Widget or X Feed Widget v2.8.0
2.8.0 2.7.0 2.6.1 2.6.0 1.0 1.0.1 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.2 1.2.1 1.2.10 1.2.11 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3 1.4 1.4.1 1.5 1.5.1 1.6 1.6.1 1.7 1.8 1.8.1 1.8.2 1.8.3 1.8.4 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1 2.1.1 2.1.2 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.5.4 2.5.5 trunk
custom-twitter-feeds / inc / UsageTracking / Config.php
custom-twitter-feeds / inc / UsageTracking Last commit date
Core 3 weeks ago Twitter 3 weeks ago Config.php 3 weeks ago EventRecorder.php 3 weeks ago ReporterInterface.php 3 weeks ago SmashUsageTracking.php 3 weeks ago
Config.php
119 lines
1 <?php
2 /**
3 * Smash Usage Tracking configuration.
4 *
5 * API URL and option names. Reusable across plugins.
6 *
7 * @package TwitterFeed\UsageTracking
8 * @since 2.6
9 */
10
11 namespace TwitterFeed\UsageTracking;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 class Config {
18
19 /**
20 * Option key: enabled flag and last_send timestamp.
21 * Reuses the legacy usage-tracking option so existing consent carries over.
22 */
23 const OPTION_TRACKING = 'ctf_usage_tracking';
24
25 /**
26 * Default enabled state when the option has never been saved.
27 * Matches the legacy default: opt-in required for the free plugin.
28 */
29 const DEFAULT_ENABLED = false;
30
31 /**
32 * Option key: site token returned by the API.
33 */
34 const OPTION_SITE_TOKEN = 'ctf_smash_usage_tracking_site_token';
35
36 /**
37 * Option key: schedule metadata (optional).
38 */
39 const OPTION_SCHEDULE = 'ctf_smash_usage_tracking_schedule';
40
41 /**
42 * Option key: dates when plugin was active (Y-m-d), for days_active metric.
43 */
44 const OPTION_ACTIVE_DATES = 'ctf_smash_usage_active_dates';
45
46 /**
47 * Option key: last N session durations in seconds, for session_duration metric.
48 */
49 const OPTION_SESSION_DURATIONS = 'ctf_smash_usage_session_durations';
50
51 /**
52 * Cron hook name. Different from the Pro plugin to avoid duplicate sends
53 * on sites where both free and pro are installed simultaneously.
54 * Also different from the legacy ctf_usage_tracking_cron hook.
55 */
56 const CRON_HOOK = 'ctf_free_smash_usage_tracking_cron';
57
58 /**
59 * Max request timeout in seconds for usage report (large payloads).
60 */
61 const REQUEST_TIMEOUT = 30;
62
63 /**
64 * Max payload size in bytes before send is skipped (default 2MB).
65 */
66 const MAX_PAYLOAD_BYTES = 2097152;
67
68 /**
69 * Register-site endpoint path (relative to API base).
70 */
71 const REGISTER_SITE_PATH = '/v1/register-site';
72
73 /**
74 * Usage report endpoint path (relative to API base).
75 */
76 const USAGE_REPORT_PATH = '/v1/usage-report';
77
78 /**
79 * Get the API base URL (filterable).
80 *
81 * @return string
82 */
83 public static function get_api_url() {
84 $url = defined( 'CTF_SMASH_USAGE_TRACKING_API_URL' ) ? CTF_SMASH_USAGE_TRACKING_API_URL : '';
85 return (string) apply_filters( 'ctf_smash_usage_tracking_api_url', $url );
86 }
87
88 /**
89 * Get full URL for register-site endpoint.
90 *
91 * @return string
92 */
93 public static function get_register_site_url() {
94 return rtrim( self::get_api_url(), '/' ) . self::REGISTER_SITE_PATH;
95 }
96
97 /**
98 * Get full URL for usage-report endpoint.
99 *
100 * @return string
101 */
102 public static function get_usage_report_url() {
103 return rtrim( self::get_api_url(), '/' ) . self::USAGE_REPORT_PATH;
104 }
105
106 /**
107 * Check if tracking is enabled.
108 *
109 * @return bool
110 */
111 public static function is_enabled() {
112 $opt = get_option( self::OPTION_TRACKING, false );
113 if ( ! is_array( $opt ) || ! array_key_exists( 'enabled', $opt ) ) {
114 return self::DEFAULT_ENABLED;
115 }
116 return ! empty( $opt['enabled'] );
117 }
118 }
119