PluginProbe
Robin Image Optimizer – Unlimited Image Optimization, WebP & AVIF / 2.0.6
Robin Image Optimizer – Unlimited Image Optimization, WebP & AVIF v2.0.6
2.0.7 2.0.6 2.0.5 trunk 1.3.7 1.4.0 1.4.1 1.4.2 1.4.6 1.5.0 1.5.3 1.5.6 1.5.8 1.6.5 1.6.6 1.6.9 1.7.0 1.7.4 1.8.1 1.8.2 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 All 26 releases
robin-image-optimizer / includes / classes / class-wrio-support.php
class-wrio-support.php
226 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Support URLs class
4 *
5 * Manages plugin support, pricing, and documentation URLs.
6 * This is a lightweight replacement for the Factory Support entity.
7 *
8 * @package Robin_Image_Optimizer
9 * @subpackage Classes
10 */
11
12 // Exit if accessed directly
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 /**
18 * Class WRIO_Support
19 *
20 * Handles support-related URLs for the plugin.
21 */
22 class WRIO_Support {
23
24 /**
25 * Plugin name for tracking
26 *
27 * @var string
28 */
29 protected $plugin_name;
30
31 /**
32 * Base site URL
33 *
34 * @var string
35 */
36 protected $site_url;
37
38 /**
39 * Features page slug
40 *
41 * @var string
42 */
43 protected $features_page_slug = 'premium-features';
44
45 /**
46 * Pricing page slug
47 *
48 * @var string
49 */
50 protected $pricing_page_slug = 'pricing';
51
52 /**
53 * Support page slug
54 *
55 * @var string
56 */
57 protected $support_page_slug = 'support';
58
59 /**
60 * Documentation page slug
61 *
62 * @var string
63 */
64 protected $docs_page_slug = 'docs';
65
66 /**
67 * Constructor
68 *
69 * @param array<string, mixed> $data Configuration data including 'url' and optional 'pages_map'.
70 */
71 public function __construct( array $data = [] ) {
72 $this->site_url = isset( $data['url'] ) ? $data['url'] : 'https://developer.flavflavor.dev';
73 $this->plugin_name = isset( $data['plugin_name'] ) ? $data['plugin_name'] : 'robin-image-optimizer';
74
75 // Allow custom page slug mapping
76 if ( isset( $data['pages_map'] ) && is_array( $data['pages_map'] ) ) {
77 foreach ( $data['pages_map'] as $key => $slug ) {
78 $attr = $key . '_page_slug';
79 if ( property_exists( $this, $attr ) ) {
80 $this->{$attr} = $slug;
81 }
82 }
83 }
84 }
85
86 /**
87 * Get site URL
88 *
89 * @param bool $track Whether to include tracking parameters.
90 * @param string|null $utm_content UTM content parameter.
91 * @return string
92 */
93 public function get_site_url( $track = false, $utm_content = null ) {
94 $url = $this->site_url;
95
96 /**
97 * Filter the base site URL
98 *
99 * @param string $url The base URL.
100 */
101 $url = apply_filters( 'wrio_support_site_url', $url );
102
103 if ( $track ) {
104 return $this->get_tracking_page_url( '', $utm_content );
105 }
106
107 return $url;
108 }
109
110 /**
111 * Get features page URL
112 *
113 * @param bool $track Whether to include tracking parameters.
114 * @param string|null $utm_content UTM content parameter.
115 * @return string
116 */
117 public function get_features_url( $track = false, $utm_content = null ) {
118 if ( $track ) {
119 return $this->get_tracking_page_url( $this->features_page_slug, $utm_content );
120 }
121
122 $url = trailingslashit( $this->site_url ) . $this->features_page_slug;
123
124 /**
125 * Filter the features page URL
126 *
127 * @param string $url The features URL.
128 */
129 return apply_filters( 'wrio_support_features_url', $url );
130 }
131
132 /**
133 * Get pricing page URL
134 *
135 * @param bool $track Whether to include tracking parameters.
136 * @param string $utm_campaign UTM content parameter.
137 * @return string
138 */
139 public function get_pricing_url( $track = false, $utm_campaign = '' ) {
140 $url = rtrim( $this->site_url, '/' ) . '/upgrade';
141 $url = tsdk_translate_link( tsdk_utmify( $url, $utm_campaign ) );
142
143 /**
144 * Filter the pricing page URL
145 *
146 * @param string $url The pricing URL.
147 */
148 return apply_filters( 'wrio_support_pricing_url', esc_url( $url ) );
149 }
150
151 /**
152 * Get contacts/support page URL
153 *
154 * @param bool $track Whether to include tracking parameters.
155 * @param string|null $utm_content UTM content parameter.
156 * @return string
157 */
158 public function get_contacts_url( $track = false, $utm_content = null ) {
159 if ( $track ) {
160 return $this->get_tracking_page_url( $this->support_page_slug, $utm_content );
161 }
162
163 $url = trailingslashit( $this->site_url ) . $this->support_page_slug;
164
165 /**
166 * Filter the contacts/support page URL
167 *
168 * @param string $url The contacts URL.
169 */
170 return apply_filters( 'wrio_support_contacts_url', $url );
171 }
172
173 /**
174 * Get documentation page URL
175 *
176 * @param bool $track Whether to include tracking parameters.
177 * @param string|null $utm_content UTM content parameter.
178 * @return string
179 */
180 public function get_docs_url( $track = false, $utm_content = null ) {
181 if ( $track ) {
182 return $this->get_tracking_page_url( $this->docs_page_slug, $utm_content );
183 }
184
185 $url = trailingslashit( $this->site_url ) . $this->docs_page_slug;
186
187 /**
188 * Filter the documentation page URL
189 *
190 * @param string $url The docs URL.
191 */
192 return apply_filters( 'wrio_support_docs_url', $url );
193 }
194
195 /**
196 * Build URL with UTM tracking parameters
197 *
198 * @param string|null $page Page slug to append.
199 * @param string|null $utm_content UTM content parameter.
200 * @param string $utm_source UTM source parameter.
201 * @return string
202 */
203 public function get_tracking_page_url( $page = null, $utm_content = null, $utm_source = 'wordpress.org' ) {
204 $args = [
205 'utm_source' => $utm_source,
206 ];
207
208 if ( ! empty( $this->plugin_name ) ) {
209 $args['utm_campaign'] = $this->plugin_name;
210 }
211
212 if ( ! empty( $utm_content ) ) {
213 $args['utm_content'] = $utm_content;
214 }
215
216 $base_url = $this->site_url;
217 if ( ! empty( $page ) ) {
218 $base_url = trailingslashit( $base_url ) . $page . '/';
219 }
220
221 $raw_url = add_query_arg( $args, $base_url );
222
223 return esc_url( $raw_url );
224 }
225 }
226