PluginProbe
Ultimate WP Mail / trunk
Ultimate WP Mail vtrunk
1.3.13 1.3.12 trunk 0.11 0.25 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 All 46 releases
ultimate-wp-mail / includes / Helper.class.php

Helper.class.php in Ultimate WP Mail trunk, at includes/Helper.class.php

396 lines 14.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit;
3
4 if ( ! class_exists( 'ewduwpmHelper' ) ) {
5 /**
6 * Class to provide helper functions.
7 *
8 * @since 5.1.0
9 */
10 class ewduwpmHelper {
11
12 // Hold the class instance.
13 private static $instance = null;
14
15 // Links for the help button.
16 private static $documentation_link = '';
17 private static $tutorials_link = 'https://www.youtube.com/watch?v=spGdk3sZlpI&list=PLEndQUuhlvSpry0rmQLP2IajiJteUjwYl';
18 private static $faq_link = 'https://wordpress.org/plugins/ultimate-wp-mail/#faq-header';
19 private static $wp_forum_support_link = 'https://wordpress.org/support/plugin/ultimate-wp-mail/';
20 private static $support_center_link = 'https://www.fivestarplugins.com/support-center/';
21
22 // Values for when to trigger the help button to display.
23 private static $post_types = array( EWD_UWPM_EMAIL_POST_TYPE );
24 private static $taxonomies = array( EWD_UWPM_EMAIL_CATEGORY_TAXONOMY );
25 private static $additional_pages = array(
26 'ewd-uwpm-dashboard',
27 'ewd-uwpm-email-lists',
28 'ewd-uwpm-lists',
29 'ewd-uwpm-user-stats',
30 'ewd-uwpm-stats',
31 'ewd-uwpm-settings'
32 );
33
34 /**
35 * The constructor is private to prevent initiation with outer code.
36 */
37 private function __construct() {}
38
39 /**
40 * The object is created from within the class itself only if the class has no instance.
41 */
42 public static function getInstance() {
43
44 if ( self::$instance == null ) {
45 self::$instance = new ewduwpmHelper();
46 }
47
48 return self::$instance;
49 }
50
51 /**
52 * Register Ultimate WP Mail help with AIAA when available.
53 *
54 * @since 5.1.0
55 */
56 public static function aiaa_add_filter() {
57
58 add_filter( 'ait_aiaa_third_party_information', array( __CLASS__, 'add_help_to_aiaa' ), 20, 2 );
59 }
60
61 /**
62 * Add Ultimate WP Mail help content to AIAA's third-party Help tab.
63 *
64 * @param array $items
65 * @param array $context
66 * @return array
67 *
68 * @since 5.1.0
69 */
70 public static function add_help_to_aiaa( $items, $context ) {
71
72 $items = is_array( $items ) ? $items : array();
73 $context = is_array( $context ) ? $context : array();
74
75 $screen_id = isset( $context['screen_id'] ) ? (string) $context['screen_id'] : '';
76 $post_type = isset( $context['post_type'] ) ? (string) $context['post_type'] : '';
77 $taxonomy = isset( $context['taxonomy'] ) ? (string) $context['taxonomy'] : '';
78
79 if ( ! self::aiaa_matches_context( $screen_id, $post_type, $taxonomy ) ) { return $items; }
80
81 $page_details = self::get_page_details_for_context( $context );
82
83 $tutorial_links = array();
84 if ( ! empty( $page_details['tutorials'] ) && is_array( $page_details['tutorials'] ) ) {
85
86 foreach ( $page_details['tutorials'] as $tutorial ) {
87
88 if ( empty( $tutorial['url'] ) || empty( $tutorial['title'] ) ) { continue; }
89
90 $tutorial_links[] = array(
91 'title' => (string) $tutorial['title'],
92 'url' => (string) $tutorial['url'],
93 );
94 }
95 }
96
97 $general_links = array();
98 if ( ! empty( self::$documentation_link ) ) {
99 $general_links[] = array(
100 'title' => __( 'Documentation', 'ultimate-wp-mail' ),
101 'url' => self::$documentation_link,
102 );
103 }
104 if ( ! empty( self::$tutorials_link ) ) {
105 $general_links[] = array(
106 'title' => __( 'YouTube Tutorials', 'ultimate-wp-mail' ),
107 'url' => self::$tutorials_link,
108 );
109 }
110 if ( ! empty( self::$faq_link ) ) {
111 $general_links[] = array(
112 'title' => __( 'FAQ', 'ultimate-wp-mail' ),
113 'url' => self::$faq_link,
114 );
115 }
116 if ( ! empty( self::$wp_forum_support_link ) ) {
117 $general_links[] = array(
118 'title' => __( 'WP Forum Support', 'ultimate-wp-mail' ),
119 'url' => self::$wp_forum_support_link,
120 );
121 }
122 if ( ! empty( self::$support_center_link ) ) {
123 $general_links[] = array(
124 'title' => __( 'Support Center', 'ultimate-wp-mail' ),
125 'url' => self::$support_center_link,
126 );
127 }
128
129 $help_links = array();
130 if ( ! empty( $tutorial_links ) ) { $help_links[ __( 'Tutorials', 'ultimate-wp-mail' ) ] = $tutorial_links; }
131 if ( ! empty( $general_links ) ) { $help_links[ __( 'General', 'ultimate-wp-mail' ) ] = $general_links; }
132
133 $items[] = array(
134 'id' => 'ewduwpm_help',
135 'title' => __( 'Ultimate WP Mail Help', 'ultimate-wp-mail' ),
136 'description' => ! empty( $page_details['description'] ) ? '<p>' . esc_html( $page_details['description'] ) . '</p>' : '',
137 'help_links' => $help_links,
138 'source' => array(
139 'type' => 'plugin',
140 'name' => 'Ultimate WP Mail',
141 'slug' => 'ultimate-wp-mail',
142 ),
143 'target_callback' => array( __CLASS__, 'aiaa_target_callback' ),
144 'priority' => 20,
145 'capability' => 'manage_options',
146 'icon' => 'dashicons-editor-help',
147 );
148
149 return $items;
150 }
151
152 /**
153 * AIAA advanced targeting callback.
154 *
155 * @param array $context
156 * @param array $item
157 * @return bool
158 *
159 * @since 5.1.0
160 */
161 public static function aiaa_target_callback( $context, $item ) {
162
163 $context = is_array( $context ) ? $context : array();
164
165 $screen_id = isset( $context['screen_id'] ) ? (string) $context['screen_id'] : '';
166 $post_type = isset( $context['post_type'] ) ? (string) $context['post_type'] : '';
167 $taxonomy = isset( $context['taxonomy'] ) ? (string) $context['taxonomy'] : '';
168
169 return self::aiaa_matches_context( $screen_id, $post_type, $taxonomy );
170 }
171
172 /**
173 * Shared matcher for AIAA context.
174 *
175 * @param string $screen_id
176 * @param string $post_type
177 * @param string $taxonomy
178 * @return bool
179 *
180 * @since 5.1.0
181 */
182 private static function aiaa_matches_context( $screen_id, $post_type, $taxonomy ) {
183
184 if ( ! empty( $post_type ) && in_array( $post_type, self::$post_types, true ) ) { return true; }
185
186 if ( ! empty( $taxonomy ) && in_array( $taxonomy, self::$taxonomies, true ) ) { return true; }
187
188 if ( ! empty( $screen_id ) && ! empty( self::$additional_pages ) ) {
189
190 foreach ( self::$additional_pages as $slug ) {
191
192 if ( empty( $slug ) ) { continue; }
193
194 if ( strpos( $screen_id, $slug ) !== false ) { return true; }
195 }
196 }
197
198 return false;
199 }
200
201 /**
202 * Handle ajax requests in admin area for logged out users.
203 *
204 * @since 5.1.0
205 */
206 public static function admin_nopriv_ajax() {
207
208 wp_send_json_error(
209 array(
210 'error' => 'loggedout',
211 'msg' => sprintf( __( 'You have been logged out. Please %slogin again%s.', 'ultimate-wp-mail' ), '<a href="' . wp_login_url( admin_url( 'admin.php?page=ewd-uwpm-dashboard' ) ) . '">', '</a>' ),
212 )
213 );
214 }
215
216 /**
217 * Handle ajax requests where an invalid nonce is passed with the request.
218 *
219 * @since 5.1.0
220 */
221 public static function bad_nonce_ajax() {
222
223 wp_send_json_error(
224 array(
225 'error' => 'badnonce',
226 'msg' => __( 'The request has been rejected because it does not appear to have come from this site.', 'ultimate-wp-mail' ),
227 )
228 );
229 }
230
231 /**
232 * Escapes PHP data being passed to JS, recursively.
233 *
234 * @since 5.1.0
235 */
236 public static function escape_js_recursive( $values ) {
237
238 $return_values = array();
239
240 foreach ( (array) $values as $key => $value ) {
241
242 if ( is_array( $value ) ) {
243 $value = ewduwpmHelper::escape_js_recursive( $value );
244 }
245 elseif ( ! is_scalar( $value ) ) {
246 continue;
247 }
248 else {
249 $value = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
250 }
251
252 $return_values[ $key ] = $value;
253 }
254
255 return $return_values;
256 }
257
258 /**
259 * Get page details for the current AIAA context.
260 *
261 * @param array $context
262 * @return array
263 */
264 public static function get_page_details_for_context( $context ) {
265 $context = is_array( $context ) ? $context : array();
266 $request = isset( $context['request'] ) && is_array( $context['request'] ) ? $context['request'] : array();
267 $page = isset( $request['page'] ) ? sanitize_text_field( $request['page'] ) : '';
268 $tab = isset( $request['tab'] ) ? sanitize_text_field( $request['tab'] ) : '';
269 $taxonomy = isset( $context['taxonomy'] ) ? sanitize_text_field( $context['taxonomy'] ) : '';
270 $post_type = isset( $context['post_type'] ) ? sanitize_text_field( $context['post_type'] ) : '';
271 $screen_id = isset( $context['screen_id'] ) ? sanitize_text_field( $context['screen_id'] ) : '';
272
273 if ( ! $page && ! empty( $screen_id ) ) {
274 foreach ( self::$additional_pages as $slug ) {
275 if ( strpos( (string) $screen_id, $slug ) !== false ) {
276 $page = $slug;
277 break;
278 }
279 }
280 }
281
282 return self::get_page_details_by_values( $page, $tab, $taxonomy, $post_type, $screen_id );
283 }
284
285 /**
286 * Resolve page details from the available context values.
287 *
288 * @param string $page
289 * @param string $tab
290 * @param string $taxonomy
291 * @param string $post_type
292 * @param string $screen_id
293 * @return array
294 */
295 private static function get_page_details_by_values( $page, $tab, $taxonomy, $post_type, $screen_id ) {
296 $page_details = array(
297 'ewd-uwpm-dashboard' => array(
298 'description' => __( 'View a quick overview of your email activity, including recently created emails and their send statistics. Access support resources such as FAQs and video tutorials, and navigate quickly to key plugin features.', 'ultimate-wp-mail' ),
299 'tutorials' => array(
300 )
301 ),
302 'edit-uwpm_mail_template' => array(
303 'description' => __( 'View and manage all created emails. Use filters, search, and bulk actions to organize your email content. Edit, update, or delete individual emails from the list view.', 'ultimate-wp-mail' ),
304 'tutorials' => array(
305 )
306 ),
307 'uwpm_mail_template' => array(
308 'description' => __( 'Create or edit an email. Set the subject and build the content using templates or the visual editor. Choose recipients (individual users, user lists, or all users) and send immediately or schedule the email for a specific date and time.', 'ultimate-wp-mail' ),
309 'tutorials' => array(
310 )
311 ),
312 'uwpm-category' => array(
313 'description' => __( 'Organize your emails using categories to make them easier to manage and filter. Create, edit, and delete categories, and assign them to emails for better structure and organization.', 'ultimate-wp-mail' ),
314 'tutorials' => array(
315 )
316 ),
317 'ewd-uwpm-email-lists' => array(
318 'description' => __( 'Create and manage email recipient lists to target specific groups of users. Lists can be built manually or generated automatically through integrations such as WooCommerce, allowing you to send emails to defined audience segments.', 'ultimate-wp-mail' ),
319 'tutorials' => array(
320 )
321 ),
322 'ewd-uwpm-lists' => array(
323 'description' => __( 'Create and manage email recipient lists to target specific groups of users. Lists can be built manually or generated automatically through integrations such as WooCommerce, allowing you to send emails to defined audience segments.', 'ultimate-wp-mail' ),
324 'tutorials' => array(
325 )
326 ),
327 'ewd-uwpm-user-stats' => array(
328 'description' => __( 'View email engagement statistics for individual users. Track emails sent, opens, link clicks, and last activity per recipient, with filtering options by date range or time period.', 'ultimate-wp-mail' ),
329 'tutorials' => array(
330 )
331 ),
332 'ewd-uwpm-stats' => array(
333 'description' => __( 'View email engagement statistics for individual users. Track emails sent, opens, link clicks, and last activity per recipient, with filtering options by date range or time period.', 'ultimate-wp-mail' ),
334 'tutorials' => array(
335 )
336 ),
337 'ewd-uwpm-settings' => array(
338 'description' => __( 'Configure core email behavior, tracking, and user consent options. Control unsubscribe and subscription settings, enable engagement tracking, and manage integration and sender information.', 'ultimate-wp-mail' ),
339 'tutorials' => array(
340 )
341 ),
342 'ewd-uwpm-settings-ewd-uwpm-basic-tab' => array(
343 'description' => __( 'Configure core email behavior, tracking, and user consent options. Control unsubscribe and subscription settings, enable engagement tracking, and manage integration and sender information.', 'ultimate-wp-mail' ),
344 'tutorials' => array(
345 )
346 ),
347 'ewd-uwpm-settings-ewd-uwpm-smtp-tab' => array(
348 'description' => __( 'Configure SMTP settings to route all outgoing WordPress emails through an external mail server. This helps improve email deliverability and ensures reliable message delivery.', 'ultimate-wp-mail' ),
349 'tutorials' => array(
350 )
351 ),
352 'ewd-uwpm-settings-ewd-uwpm-send-events-tab' => array(
353 'description' => __( 'Configure automated email triggers based on WordPress and WooCommerce events. Control when emails are sent, including delays, scheduling intervals, and event-based rules such as registration, profile updates, and purchases.', 'ultimate-wp-mail' ),
354 'tutorials' => array(
355 )
356 ),
357 'ewd-uwpm-settings-ewd-uwpm-logging-tab' => array(
358 'description' => __( 'Configure email logging and error monitoring for outgoing messages. Control how many email logs are stored, and set up admin notifications when email delivery fails.', 'ultimate-wp-mail' ),
359 'tutorials' => array(
360 )
361 ),
362 'ewd-uwpm-settings-ewd-uwpm-labelling-tab' => array(
363 'description' => __( 'Customize the text used for subscription and email interest prompts displayed to users. These labels control how subscribe and unsubscribe actions, as well as interest selection messages, appear on the front end.', 'ultimate-wp-mail' ),
364 'tutorials' => array(
365 )
366 )
367 );
368
369 $page = $page ? sanitize_text_field( $page ) : '';
370 $tab = $tab ? sanitize_text_field( $tab ) : '';
371 $taxonomy = $taxonomy ? sanitize_text_field( $taxonomy ) : '';
372 $post_type = $post_type ? sanitize_text_field( $post_type ) : '';
373 $screen_id = $screen_id ? sanitize_text_field( $screen_id ) : '';
374
375 if ( $page && $tab && isset( $page_details[ $page . '-' . $tab ] ) ) { return $page_details[ $page . '-' . $tab ]; }
376
377 if ( $page && isset( $page_details[ $page ] ) ) { return $page_details[ $page ]; }
378
379 if ( $screen_id && isset( $page_details[ $screen_id ] ) ) { return $page_details[ $screen_id ]; }
380
381 if ( $taxonomy && isset( $page_details[ $taxonomy ] ) ) { return $page_details[ $taxonomy ]; }
382
383 if ( $post_type && $screen_id && strpos( $screen_id, 'edit-' ) === 0 && isset( $page_details[ 'edit-' . $post_type ] ) ) {
384 return $page_details[ 'edit-' . $post_type ];
385 }
386
387 if ( $post_type && isset( $page_details[ $post_type ] ) ) { return $page_details[ $post_type ]; }
388
389 return array( 'description' => '', 'tutorials' => array() );
390 }
391 }
392
393 add_action( 'plugins_loaded', array( 'ewduwpmHelper', 'aiaa_add_filter' ), 20 );
394
395 }
396