PluginProbe ʕ •ᴥ•ʔ
OttoKit: All-in-One Automation Platform / 1.0.74
OttoKit: All-in-One Automation Platform v1.0.74
1.1.31 1.1.30 1.1.29 1.1.28 1.1.27 1.1.9 trunk 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.19 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 1.0.39 1.0.40 1.0.41 1.0.42 1.0.43 1.0.44 1.0.45 1.0.46 1.0.47 1.0.48 1.0.49 1.0.50 1.0.51 1.0.52 1.0.53 1.0.54 1.0.55 1.0.56 1.0.57 1.0.58 1.0.59 1.0.60 1.0.61 1.0.62 1.0.63 1.0.64 1.0.65 1.0.66 1.0.67 1.0.68 1.0.69 1.0.7 1.0.70 1.0.71 1.0.72 1.0.73 1.0.74 1.0.75 1.0.76 1.0.77 1.0.78 1.0.79 1.0.8 1.0.80 1.0.81 1.0.82 1.0.83 1.0.84 1.0.85 1.0.86 1.0.87 1.0.88 1.0.89 1.0.9 1.0.90 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.20 1.1.21 1.1.22 1.1.23 1.1.24 1.1.25 1.1.26 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8
suretriggers / src / Loader.php
suretriggers / src Last commit date
Admin 1 year ago Controllers 1 year ago Integrations 1 year ago Models 1 year ago Support 1 year ago Traits 3 years ago Loader.php 1 year ago
Loader.php
683 lines
1 <?php
2 /**
3 * Loader.
4 * php version 5.6
5 *
6 * @category Loader
7 * @package SureTriggers
8 * @author BSF <username@example.com>
9 * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3
10 * @link https://www.brainstormforce.com/
11 * @since 1.0.0
12 */
13
14 namespace SureTriggers;
15
16 use DirectoryIterator;
17 use SureTriggers\Controllers\AuthController;
18 use SureTriggers\Controllers\AutomationController;
19 use SureTriggers\Controllers\EventController;
20 use SureTriggers\Controllers\GlobalSearchController;
21 use SureTriggers\Controllers\IntegrationsController;
22 use SureTriggers\Controllers\OptionController;
23 use SureTriggers\Controllers\RestController;
24 use SureTriggers\Controllers\RoutesController;
25 use SureTriggers\Controllers\SettingsController;
26 use SureTriggers\Controllers\WebhookRequestsController;
27 use SureTriggers\Traits\SingletonLoader;
28 use SureTriggers\Models\SaasApiToken;
29 use function add_menu_page;
30 use function add_submenu_page;
31 use \BSF_Analytics_Loader;
32
33 /**
34 * Loader
35 *
36 * @category Loader
37 * @package SureTriggers
38 * @author BSF <username@example.com>
39 * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3
40 * @link https://www.brainstormforce.com/
41 * @since 1.0.0
42 */
43 class Loader {
44
45
46
47 use SingletonLoader;
48
49 /**
50 * Constructor
51 *
52 * @since 1.0.0
53 */
54 public function __construct() {
55 register_activation_hook( SURE_TRIGGERS_FILE, [ $this, 'st_activate' ] );
56
57 $this->define_constants();
58 add_action( 'plugins_loaded', [ $this, 'initialize_core' ] );
59 // Admin Menu.
60 add_action( 'admin_menu', [ $this, 'admin_menu' ] );
61 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
62 add_action( 'admin_init', [ $this, 'reset_plugin' ] );
63
64 add_filter( 'plugin_action_links_' . plugin_basename( SURE_TRIGGERS_FILE ), [ $this, 'add_settings_link' ] );
65 add_action( 'admin_init', [ $this, 'redirect_after_activation' ] );
66
67 add_action( 'admin_notices', [ $this, 'display_notice' ] );
68
69 add_action( 'all_admin_notices', [ $this, 'suretriggers_show_api_connection_error' ] );
70
71 add_action( 'wp_dashboard_setup', [ $this, 'add_dashboard_widgets' ] );
72
73 // Remove Webhook Requests retry cron and requests table.
74 register_uninstall_hook(
75 SURE_TRIGGERS_FILE,
76 [ WebhookRequestsController::class, 'suretriggers_remove_table_retry_cron' ]
77 );
78 }
79
80 /**
81 * Adding dashboard widget.
82 *
83 * @return void
84 */
85 public function add_dashboard_widgets() {
86 if ( isset( OptionController::$options['secret_key'] ) ) {
87 return;
88 }
89
90 wp_add_dashboard_widget(
91 'suretriggers_dashboard_widget',
92 'Please Connect SureTriggers',
93 [ $this, 'dashboard_widget_display' ],
94 '',
95 '',
96 'side',
97 'high'
98 );
99 }
100
101 /**
102 * Dashboard widget callback.
103 *
104 * @return void
105 */
106 public function dashboard_widget_display() { ?>
107 <div>
108 <p> <?php esc_html_e( 'Please connect to or create your SureTriggers account.', 'suretriggers' ); ?></p>
109 <p> <?php esc_html_e( 'This will enable you to connect your various plugins, and apps together and automate repetitive tasks.', 'suretriggers' ); ?> </p>
110 <a href="<?php echo esc_url( admin_url( 'admin.php?page=suretriggers' ) ); ?>" class="button button-primary"> <?php esc_html_e( 'Get Started', 'suretriggers' ); ?> </a>
111 </div>
112 <?php
113 }
114
115 /**
116 * Display notice.
117 *
118 * @return void
119 */
120 public function display_notice() {
121 if ( isset( OptionController::$options['secret_key'] ) ) {
122 return;
123 }
124 global $pagenow;
125 if ( 'index.php' != $pagenow ) {
126 return;
127 }
128 ?>
129 <div class="notice notice-success" style="padding-bottom: 15px;">
130 <p>
131 <strong>
132 <?php esc_html_e( 'Connect your plugins and apps together with SureTriggers', 'suretriggers' ); ?>
133 <span style="transform: rotate(-90deg); font-size: 15px;" class="dashicons dashicons-admin-plugins"></span>
134 </strong>
135 </p>
136 <p> <?php esc_html_e( 'Please connect to or create your SureTriggers account. This will enable you to connect your various plugins and apps together and automate repetitive tasks.', 'suretriggers' ); ?> </p>
137
138 <a href="<?php echo esc_url( admin_url( 'admin.php?page=suretriggers' ) ); ?>" class="button button-primary"> <?php esc_html_e( 'Get Started With SureTriggers', 'suretriggers' ); ?> </a>
139 <a href="https://suretriggers.com/" class="button button-secondary"> <?php esc_html_e( 'Learn More', 'suretriggers' ); ?> </a>
140 </div>
141 <?php
142 }
143
144 /**
145 * Show Connection Error Admin Notice.
146 *
147 * @return void
148 */
149 public function suretriggers_show_api_connection_error() {
150 global $pagenow;
151 if ( 'index.php' != $pagenow ) {
152 return;
153 }
154 $notice = get_option( 'suretriggers_verify_connection' );
155 // If empty option value for connection status, then verify the connection.
156 if ( empty( $notice ) ) {
157 $connection_status = RestController::suretriggers_verify_wp_connection();
158 $connection_status_code = wp_remote_retrieve_response_code( $connection_status );
159 if ( is_wp_error( $connection_status ) ) {
160 update_option( 'suretriggers_verify_connection', 'suretriggers_connection_wp_error' );
161 } else {
162 if ( 200 !== $connection_status_code ) {
163 update_option( 'suretriggers_verify_connection', 'suretriggers_connection_error' );
164 } else {
165 update_option( 'suretriggers_verify_connection', 'suretriggers_connection_successful' );
166 }
167 }
168 }
169 $notice = get_option( 'suretriggers_verify_connection' );
170 if ( 'suretriggers_connection_successful' != $notice ) {
171 // If connection status is not successful, then show the notice.
172 ?>
173 <div class="notice notice-error is-dismissible">
174 <p>
175 <strong>
176 <?php esc_html_e( 'SureTriggers Connection Issue', 'suretriggers' ); ?>
177 <span style="transform: rotate(-180deg); font-size: 20px;" class="dashicons dashicons-warning"></span>
178 </strong>
179 </p>
180 <p>
181 <?php esc_html_e( 'There is an issue with the established connection between WordPress and SureTriggers. Please visit the SureTriggers dashboard to verify and re-establish the connection if necessary.', 'suretriggers' ); ?>
182 </p>
183 <p>
184 <a href="<?php echo esc_url( admin_url( 'admin.php?page=suretriggers' ) ); ?>" class="button button-secondary"> <?php esc_html_e( 'Go To SureTriggers', 'suretriggers' ); ?> </a>
185 </p>
186 </div>
187 <?php
188 }
189 }
190
191 /**
192 * Redirect user after plugin activation.
193 *
194 * @return void
195 */
196 public function redirect_after_activation() {
197 $is_redirect = get_transient( 'st-redirect-after-activation' );
198 if ( $is_redirect ) {
199 delete_transient( 'st-redirect-after-activation' );
200 $url = get_admin_url() . 'admin.php?page=suretriggers';
201 wp_safe_redirect( $url );
202 die;
203 }
204 }
205
206 /**
207 * Adding setting link.
208 *
209 * @param array $links links.
210 * @return array
211 */
212 public function add_settings_link( array $links ) {
213 $url = get_admin_url() . 'admin.php?page=suretriggers';
214 $setting_option = get_option( 'suretrigger_options' );
215 if ( isset( $setting_option ) && ! empty( $setting_option ) ) {
216 $settings_link = '<a href="' . $url . '">' . __( 'Dashboard', 'suretriggers' ) . '</a>';
217 } else {
218 $settings_link = '<a href="' . $url . '">' . __( 'Connect', 'suretriggers' ) . '</a>';
219 }
220 $links[] = $settings_link;
221 return $links;
222 }
223
224 /**
225 * Define constants
226 *
227 * @return void
228 * @since 1.0.0
229 */
230 public function define_constants() {
231 $sass_url = 'https://app.suretriggers.com';
232 $api_url = 'https://api.suretriggers.com';
233 $webhook_url = 'https://webhook.suretriggers.com';
234
235 define( 'SURE_TRIGGERS_BASE', plugin_basename( SURE_TRIGGERS_FILE ) );
236 define( 'SURE_TRIGGERS_DIR', plugin_dir_path( SURE_TRIGGERS_FILE ) );
237 define( 'SURE_TRIGGERS_URL', plugins_url( '/', SURE_TRIGGERS_FILE ) );
238 define( 'SURE_TRIGGERS_VER', '1.0.74' );
239 define( 'SURE_TRIGGERS_DB_VER', '1.0.74' );
240 define( 'SURE_TRIGGERS_REST_NAMESPACE', 'sure-triggers/v1' );
241 define( 'SURE_TRIGGERS_SASS_URL', $sass_url . '/wp-json/wp-plugs/v1/' );
242 define( 'SURE_TRIGGERS_SITE_URL', $sass_url );
243 define( 'SURE_TRIGGERS_API_SERVER_URL', $api_url );
244 define( 'SURE_TRIGGERS_WEBHOOK_SERVER_URL', $webhook_url );
245
246 define( 'SURE_TRIGGERS_PAGE', 'SureTriggers' );
247 define( 'SURE_TRIGGERS_AS_GROUP', 'SureTriggers' );
248
249 define( 'SURE_TRIGGERS_ACTION_ERROR_MESSAGE', 'An unexpected error occurred. Something went wrong with the action.' );
250 }
251
252 /**
253 * Flush permalink rules while plugin activation.
254 *
255 * @return void
256 */
257 public function st_activate() {
258 flush_rewrite_rules(); //phpcs:ignore
259
260 set_transient( 'st-redirect-after-activation', true, 120 );
261 }
262
263 /**
264 * Add main menu
265 *
266 * @since x.x.x
267 *
268 * @return void
269 */
270 public function admin_menu() {
271 $page_title = apply_filters( 'st_menu_page_title', esc_html__( 'SureTriggers', 'suretriggers' ) );
272 $logo = file_get_contents( plugin_dir_path( SURE_TRIGGERS_FILE ) . 'assets/images/STLogo.svg' );
273
274 add_menu_page(
275 $page_title,
276 $page_title,
277 'manage_options',
278 'suretriggers',
279 [ $this, 'menu_callback' ],
280 'data:image/svg+xml;base64,' . base64_encode( $logo ),
281 30.6002
282 );
283
284 add_submenu_page(
285 'suretriggers',
286 'suretriggers-status',
287 'Status',
288 'administrator',
289 'suretriggers-status',
290 [ $this, 'suretriggers_status_menu_callback' ]
291 );
292 }
293
294 /**
295 * Enqueue the admin scripts
296 *
297 * @param string $hook hook.
298 * @since x.x.x
299 *
300 * @return void
301 */
302 public function enqueue_scripts( $hook = '' ) {
303 if ( ! in_array( $hook, [ 'toplevel_page_suretriggers', 'suretriggers_page_suretriggers-status' ], true ) ) {
304 return;
305 }
306
307 remove_all_actions( 'admin_notices' );
308
309 $file = SURE_TRIGGERS_DIR . 'app/build/main.asset.php';
310 if ( ! file_exists( $file ) ) {
311 return;
312 }
313
314 $asset = require_once $file;
315
316 if ( ! isset( $asset ) ) {
317 return;
318 }
319
320 wp_register_script(
321 'sure-trigger-admin',
322 SURE_TRIGGERS_URL . 'app/build/main.js',
323 array_merge( $asset['dependencies'], [ 'regenerator-runtime' ] ),
324 $asset['version'],
325 true
326 );
327
328 wp_localize_script(
329 'sure-trigger-admin',
330 'sureTriggerData',
331 $this->get_localized_array()
332 );
333 wp_enqueue_script( 'sure-trigger-admin' );
334 wp_enqueue_style( 'sure-trigger-components', SURE_TRIGGERS_URL . 'app/build/style-main.css', [], SURE_TRIGGERS_VER );
335 wp_enqueue_style( 'st-trigger-style', SURE_TRIGGERS_URL . 'assets/admin-css/st-admin-css.css', [], SURE_TRIGGERS_VER );
336 wp_enqueue_style( 'sure-trigger-css', SURE_TRIGGERS_URL . 'app/build/main.css', [], SURE_TRIGGERS_VER );
337 }
338
339 /**
340 * Get localized array for sure triggers.
341 *
342 * @return array
343 */
344 private function get_localized_array() {
345 $current_user = wp_get_current_user();
346
347 $source_type = get_option( 'suretriggers_source' );
348
349 $data = [
350 'siteContent' => [
351 'siteUrl' => str_replace( '/wp-json/', '', get_rest_url() ),
352 'redirectUrl' => get_site_url() . '/wp-admin/themes.php?page=suretriggers',
353 'connectNonce' => wp_create_nonce( 'sure-trigger-connect' ),
354 'connectUrl' => SURE_TRIGGERS_SITE_URL . '/connect-st/connect',
355 'siteTitle' => get_bloginfo( 'name' ),
356 'resetUrl' => base64_encode( wp_nonce_url( admin_url( 'admin.php?st-reset=true' ), 'st-reset-action' ) ),
357 'sourceType' => $source_type,
358 ],
359 'user' => [
360 'name' => $current_user->display_name,
361 'email' => $current_user->user_email,
362 ],
363 'stSaasURL' => trailingslashit( SURE_TRIGGERS_SITE_URL ),
364 'stPluginURL' => plugin_dir_url( SURE_TRIGGERS_FILE ),
365 'integrations' => IntegrationsController::get_activated_integrations(),
366 'enabledIntegrations' => OptionController::get_option( 'enabled_integrations' ),
367 'settingsPageURL' => admin_url( 'themes.php?page=suretriggers' ),
368 'verification_status' => false,
369 'projects' => [],
370 'apiSlug' => SURE_TRIGGERS_REST_NAMESPACE,
371 'isElementorEditor' => ( did_action( 'elementorpro/loaded' ) ) ? Elementor\Plugin::instance()->editor->is_edit_mode() : false,
372 'reConnectSorryMsg' => (bool) OptionController::get_option( 'st_connect_notice_deprecated' ),
373 ];
374
375 if ( current_user_can( 'manage_options' ) ) {
376 $data['siteContent']['accessKey'] = SaasApiToken::get();
377 $data['siteContent']['connected_email'] = OptionController::get_option( 'connected_email_key' );
378 }
379
380 $settings = OptionController::get_option( 'st_settings' );
381 if ( empty( $settings ) ) {
382 $settings = (object) [];
383 }
384
385 $data['settingsForm'] = SettingsController::get_fields();
386 $data['settings'] = wp_json_encode( $settings );
387 $data['nonce'] = wp_create_nonce( 'st-nonce' );
388 $data['ajaxurl'] = esc_url( admin_url( 'admin-ajax.php', 'relative' ) );
389
390 return apply_filters( 'sure_trigger_control_localize_vars', $data );
391 }
392
393 /**
394 * Menu callback.
395 *
396 * @since x.x.x
397 *
398 * @return void
399 */
400 public function menu_callback() {
401 // Verify Token.
402 $response = RestController::verify_user_token();
403 $response_body = wp_remote_retrieve_body( $response );
404 $response_code = wp_remote_retrieve_response_code( $response );
405 if ( ! empty( $response_body ) ) {
406 $response_body = json_decode( $response_body, true );
407 }
408 if ( 200 === $response_code || 401 === $response_code ) {
409 if ( is_array( $response_body ) && isset( $response_body['is_iframe_enabled'] ) && 'NO' === $response_body['is_iframe_enabled'] ) {
410 ?>
411 <div class="suretriggers-nobase">
412 <div>
413 <div>
414 <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-circle-check inline-block h-8 w-8 text-green-400 mb-6" aria-hidden="true"><circle cx="12" cy="12" r="10"></circle><path d="m9 12 2 2 4-4"></path></svg>
415 <h2 class="suretriggers-info-title">
416 SureTriggers is connected.
417 </h2>
418 <p class="suretriggers-info-content">
419 Your WordPress site is successfully connected SureTriggers SaaS Platform. However, iframe display is currently disabled. Click below to enable it.
420 </p>
421 <a class="suretriggers-info-link" href="<?php echo esc_url( SURE_TRIGGERS_SITE_URL . '/apps/WordPress' ); ?>" target="_blank">
422 Access Connection Page
423 </a>
424 </div>
425 </div>
426 </div>
427 <?php
428 } else {
429 ?>
430 <div id="sure-triggger-entry" class="st-base"></div>
431 <?php
432 }
433 } elseif ( isset( $response ) && is_wp_error( $response ) || 200 !== $response_code ) {
434 ?>
435 <div class="suretriggers-nobase">
436 <div>
437 <div>
438 <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="30" height="24" viewBox="0 0 122.88 122.879" enable-background="new 0 0 122.88 122.879" xml:space="preserve" class="lucide lucide-circle-check inline-block h-8 w-8 text-green-400 mb-6"><g><path fill="#FF4141" d="M61.44,0c16.96,0,32.328,6.882,43.453,17.986c11.104,11.125,17.986,26.494,17.986,43.453 c0,16.961-6.883,32.328-17.986,43.453C93.769,115.998,78.4,122.879,61.44,122.879c-16.96,0-32.329-6.881-43.454-17.986 C6.882,93.768,0,78.4,0,61.439C0,44.48,6.882,29.111,17.986,17.986C29.112,6.882,44.48,0,61.44,0L61.44,0z M73.452,39.152 c2.75-2.792,7.221-2.805,9.986-0.026c2.764,2.776,2.775,7.292,0.027,10.083L71.4,61.445l12.077,12.25 c2.728,2.77,2.689,7.256-0.081,10.021c-2.772,2.766-7.229,2.758-9.954-0.012L61.445,71.541L49.428,83.729 c-2.75,2.793-7.22,2.805-9.985,0.025c-2.763-2.775-2.776-7.291-0.026-10.082L51.48,61.435l-12.078-12.25 c-2.726-2.769-2.689-7.256,0.082-10.022c2.772-2.765,7.229-2.758,9.954,0.013L61.435,51.34L73.452,39.152L73.452,39.152z M96.899,25.98C87.826,16.907,75.29,11.296,61.44,11.296c-13.851,0-26.387,5.611-35.46,14.685 c-9.073,9.073-14.684,21.609-14.684,35.459s5.611,26.387,14.684,35.459c9.073,9.074,21.609,14.686,35.46,14.686 c13.85,0,26.386-5.611,35.459-14.686c9.073-9.072,14.684-21.609,14.684-35.459S105.973,35.054,96.899,25.98L96.899,25.98z"></path></g></svg>
439 <h2 class="suretriggers-info-title">
440 SureTriggers Not Connected.
441 </h2>
442 <p class="suretriggers-info-content">
443 It looks like your WordPress site’s connection with SureTriggers has been affected because the URL used for communication has changed. The current link for your site is different from the one SureTriggers was originally connected to.
444 </p>
445 <a class="suretriggers-info-link" href="<?php echo esc_url( SURE_TRIGGERS_SITE_URL ); ?>" target="_blank">
446 Access Dashboard
447 </a>
448 <a class="suretriggers-info-link" href="<?php echo esc_url( wp_nonce_url( admin_url( 'admin.php?st-reset=true' ), 'st-reset-action' ) ); ?>">
449 Disconnect SureTriggers
450 </a>
451 </div>
452 </div>
453 </div>
454 <?php
455 }
456 }
457
458 /**
459 * Status Menu callback.
460 *
461 * @since x.x.x
462 *
463 * @return void
464 */
465 public function suretriggers_status_menu_callback() {
466 ?>
467 <div class="wrap">
468 <?php
469 $tabs = [
470 'st_system_page' => 'Status',
471 'st_outgoing_requests' => 'Outgoing Requests',
472 ];
473 $current_tab = 'st_system_page';
474 if ( isset( $_REQUEST['tab'], $_REQUEST['_wpnonce'] ) && wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'suretriggers_tab_nonce' ) ) {
475 if ( array_key_exists( sanitize_key( $_REQUEST['tab'] ), $tabs ) ) {
476 $current_tab = sanitize_key( $_REQUEST['tab'] );
477 }
478 }
479 ?>
480 <nav class="suretriggers-nav-tab nav-tab-wrapper">
481 <?php
482 foreach ( $tabs as $name => $label ) {
483 $tab_url = add_query_arg(
484 [
485 'tab' => $name,
486 '_wpnonce' => wp_create_nonce( 'suretriggers_tab_nonce' ),
487 ],
488 admin_url( 'admin.php?page=suretriggers-status' )
489 );
490 echo '<a href="' . esc_url( $tab_url ) . '" class="nav-tab ';
491 if ( $current_tab == $name ) {
492 echo 'nav-tab-active';
493 }
494 echo '">' . esc_html( $label ) . '</a>';
495 }
496 ?>
497 </nav>
498 <?php
499 switch ( $current_tab ) {
500 case 'st_system_page':
501 include_once __DIR__ . '/Admin/Views/st-admin-system-page.php';
502 break;
503 case 'st_outgoing_requests':
504 include_once __DIR__ . '/Admin/Views/st-admin-outgoing-req-page.php';
505 break;
506 }
507 ?>
508 </div>
509 <?php
510 }
511
512 /**
513 * Include all files from the folder.
514 *
515 * @param string $folder folder path.
516 * @return void
517 */
518 public function include_all_files( $folder ) {
519 $dir = new DirectoryIterator( $folder );
520 foreach ( $dir as $file ) {
521 if ( ! $file->isDot() ) {
522 if ( $file->isDir() ) {
523 $this->include_all_files( $file->getPathname() );
524 } else {
525 require_once $file->getPathname();
526 }
527 }
528 }
529 }
530
531 /**
532 * Initialize core trigger and actions.
533 *
534 * @return void
535 */
536 public function initialize_core() {
537 /**
538 * Include only integrations root files
539 */
540
541 $this->include_all_files( SURE_TRIGGERS_DIR . 'src/Integrations/' );
542
543 $this->suretriggers_load_analytics_files();
544
545 IntegrationsController::load_event_files();
546
547 EventController::get_instance();
548 IntegrationsController::get_instance();
549 GlobalSearchController::get_instance();
550 RestController::get_instance();
551 OptionController::get_instance();
552 AutomationController::get_instance();
553 AuthController::get_instance();
554 RoutesController::get_instance();
555 SettingsController::get_instance();
556 WebhookRequestsController::get_instance();
557
558 // SureTriggers Custom Filter data.
559 add_filter( 'suretriggers_get_iframe_url', [ $this, 'suretriggers_iframe_data' ] );
560 add_filter( 'suretriggers_is_user_connected', [ $this, 'suretriggers_saas_connected_data' ] );
561
562 // Create Webhook Request Log table.
563 WebhookRequestsController::suretriggers_webhook_request_log_table();
564 // Schedule the cron jon to retry failed triggers.
565 WebhookRequestsController::suretriggers_setup_custom_cron();
566 }
567
568 /**
569 * Added option to reset plugin in case of testing.
570 *
571 * @return void
572 */
573 public function reset_plugin() {
574 $nonce = sanitize_text_field( wp_unslash( isset( $_GET['_wpnonce'] ) ? $_GET['_wpnonce'] : false ) );
575
576 if ( $nonce && wp_verify_nonce( $nonce, 'st-reset-action' ) ) {
577 $is_reset = sanitize_text_field( wp_unslash( isset( $_GET['st-reset'] ) ? $_GET['st-reset'] : false ) );
578 if ( $is_reset && current_user_can( 'manage_options' ) ) {
579 delete_option( 'suretrigger_options' );
580 wp_safe_redirect( admin_url( 'admin.php?page=suretriggers' ) );
581 exit();
582 }
583 }
584 }
585
586 /**
587 * Custom Filter data.
588 *
589 * @param string $site_url Optional. Site URL to include in the iframe data.
590 * @return string
591 */
592 public function suretriggers_iframe_data( $site_url = '' ) {
593 if ( ! current_user_can( 'manage_options' ) ) {
594 return apply_filters( 'suretriggers_get_iframe_url', [] );
595 }
596 $site_url = esc_url_raw( $site_url );
597 $site_content_data = [
598 'stSaasURL' => $site_url . 'wp-login',
599 'stCode' => SaasApiToken::get(),
600 'baseUrl' => str_replace( '/wp-json/', '', get_rest_url() ),
601 'resetUrl' => rtrim( base64_encode( wp_nonce_url( admin_url( 'admin.php?st-reset=true' ), 'st-reset-action' ) ), '=' ), // phpcs:ignore
602 ];
603 $params = [
604 'st-code' => $site_content_data['stCode'],
605 'base_url' => $site_content_data['baseUrl'],
606 'reset_url' => $site_content_data['resetUrl'],
607 'redirect_url' => $site_url . 'embed-login',
608 'is_embedded' => true,
609 ];
610
611 if ( filter_var( $site_url, FILTER_VALIDATE_URL ) ) {
612 $iframe_url = add_query_arg( $params, $site_content_data['stSaasURL'] );
613 } else {
614 $default_url = trailingslashit( SURE_TRIGGERS_SITE_URL ) . '?path=dashboard';
615 $iframe_url = add_query_arg( $params, $default_url );
616 }
617 return esc_url_raw( $iframe_url );
618 }
619
620
621 /**
622 * Custom Filter data to check if user is logged in iframe.
623 *
624 * @return bool
625 */
626 public function suretriggers_saas_connected_data() {
627 if ( ! current_user_can( 'manage_options' ) ) {
628 return apply_filters( 'suretriggers_is_user_connected', [] );
629 }
630 $token = SaasApiToken::get();
631
632 if ( '' === $token || null === $token || false === $token || 'connection-denied' === $token ) {
633 $logged_in = false;
634 } else {
635 $logged_in = true;
636 }
637 return $logged_in;
638 }
639
640 /**
641 * Load Analytics.
642 *
643 * @since 1.0.0
644 *
645 * @return void
646 */
647 public function suretriggers_load_analytics_files() {
648 if ( is_admin() ) {
649 require_once SURE_TRIGGERS_DIR . 'inc/lib/astra-notices/class-astra-notices.php';
650 }
651
652 if ( ! class_exists( 'BSF_Analytics_Loader' ) ) {
653 require_once SURE_TRIGGERS_DIR . 'inc/lib/bsf-analytics/class-bsf-analytics-loader.php';
654 }
655
656 if ( class_exists( 'BSF_Analytics_Loader' ) ) {
657 $st_bsf_analytics = BSF_Analytics_Loader::get_instance();
658 $st_bsf_analytics->set_entity(
659 [
660 'suretriggers' => [
661 'product_name' => 'SureTriggers',
662 'path' => SURE_TRIGGERS_DIR . 'inc/lib/bsf-analytics',
663 'author' => 'SureTriggers',
664 'time_to_display' => '+24 hours',
665 'deactivation_survey' => [
666 [
667 'id' => 'deactivation-survey-suretriggers',
668 'popup_logo' => SURE_TRIGGERS_URL . 'assets/images/STLogo.svg',
669 'plugin_slug' => 'suretriggers',
670 'plugin_version' => SURE_TRIGGERS_VER,
671 'popup_title' => __( 'Quick Feedback', 'suretriggers' ),
672 'support_url' => 'https://suretriggers.com/support/',
673 'popup_description' => __( 'If you have a moment, please share why you are deactivating SureTriggers:', 'suretriggers' ),
674 'show_on_screens' => [ 'plugins' ],
675 ],
676 ],
677 ],
678 ]
679 );
680 }
681 }
682 }
683