PluginProbe ʕ •ᴥ•ʔ
OttoKit: All-in-One Automation Platform / 1.1.1
OttoKit: All-in-One Automation Platform v1.1.1
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 11 months ago Integrations 11 months ago Models 11 months ago Support 1 year ago Traits 3 years ago Loader.php 11 months ago
Loader.php
754 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\WebhookRequestsController;
26 use SureTriggers\Controllers\SettingsController;
27 use SureTriggers\Traits\SingletonLoader;
28 use SureTriggers\Models\SaasApiToken;
29 use function add_menu_page;
30 use function add_submenu_page;
31
32 /**
33 * Loader
34 *
35 * @category Loader
36 * @package SureTriggers
37 * @author BSF <username@example.com>
38 * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3
39 * @link https://www.brainstormforce.com/
40 * @since 1.0.0
41 */
42 class Loader {
43
44
45
46 use SingletonLoader;
47
48 /**
49 * Constructor
50 *
51 * @since 1.0.0
52 */
53 public function __construct() {
54 register_activation_hook( SURE_TRIGGERS_FILE, [ $this, 'st_activate' ] );
55
56 $this->define_constants();
57 add_action( 'plugins_loaded', [ $this, 'initialize_core' ] );
58 // Admin Menu.
59 add_action( 'admin_menu', [ $this, 'admin_menu' ] );
60 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
61 add_action( 'admin_init', [ $this, 'reset_plugin' ] );
62
63 add_filter( 'plugin_action_links_' . plugin_basename( SURE_TRIGGERS_FILE ), [ $this, 'add_settings_link' ] );
64 add_action( 'admin_init', [ $this, 'redirect_after_activation' ] );
65
66 add_action( 'admin_notices', [ $this, 'display_notice' ] );
67
68 add_action( 'all_admin_notices', [ $this, 'suretriggers_show_api_connection_error' ] );
69
70 add_action( 'wp_dashboard_setup', [ $this, 'add_dashboard_widgets' ] );
71
72 // Remove Webhook Requests retry cron and requests table.
73 register_uninstall_hook(
74 SURE_TRIGGERS_FILE,
75 [ WebhookRequestsController::class, 'suretriggers_remove_table_retry_cron' ]
76 );
77 }
78
79 /**
80 * Adding dashboard widget.
81 *
82 * @return void
83 */
84 public function add_dashboard_widgets() {
85 if ( isset( OptionController::$options['secret_key'] ) ) {
86 return;
87 }
88
89 wp_add_dashboard_widget(
90 'suretriggers_dashboard_widget',
91 'Please Connect OttoKit (Formerly SureTriggers)',
92 [ $this, 'dashboard_widget_display' ],
93 null,
94 null,
95 'side',
96 'high'
97 );
98 }
99
100 /**
101 * Dashboard widget callback.
102 *
103 * @return void
104 */
105 public function dashboard_widget_display() { ?>
106 <div>
107 <p> <?php esc_html_e( 'Please connect to or create your OttoKit (Formerly SureTriggers) account.', 'suretriggers' ); ?></p>
108 <p> <?php esc_html_e( 'This will enable you to connect your various plugins, and apps together and automate repetitive tasks.', 'suretriggers' ); ?> </p>
109 <a href="<?php echo esc_url( admin_url( 'admin.php?page=suretriggers' ) ); ?>" class="button button-primary"> <?php esc_html_e( 'Get Started', 'suretriggers' ); ?> </a>
110 </div>
111 <?php
112 }
113
114 /**
115 * Display notice.
116 *
117 * @return void
118 */
119 public function display_notice() {
120 global $pagenow;
121 if ( isset( OptionController::$options['secret_key'] ) ) {
122 return;
123 }
124 if ( 'index.php' != $pagenow ) {
125 return;
126 }
127 ?>
128 <div class="notice notice-success" style="padding-bottom: 15px;">
129 <p>
130 <strong>
131 <?php esc_html_e( 'Connect your plugins and apps together with OttoKit (Formerly SureTriggers)', 'suretriggers' ); ?>
132 <span style="transform: rotate(-90deg); font-size: 15px;" class="dashicons dashicons-admin-plugins"></span>
133 </strong>
134 </p>
135 <p> <?php esc_html_e( 'Please connect to or create your OttoKit (Formerly SureTriggers) account. This will enable you to connect your various plugins and apps together and automate repetitive tasks.', 'suretriggers' ); ?> </p>
136
137 <a href="<?php echo esc_url( admin_url( 'admin.php?page=suretriggers' ) ); ?>" class="button button-primary"> <?php esc_html_e( 'Get Started With OttoKit (Formerly SureTriggers)', 'suretriggers' ); ?> </a>
138 <a href="https://ottokit.com/" class="button button-secondary"> <?php esc_html_e( 'Learn More', 'suretriggers' ); ?> </a>
139 </div>
140 <?php
141 }
142
143 /**
144 * Show Connection Error Admin Notice.
145 *
146 * @return void
147 */
148 public function suretriggers_show_api_connection_error() {
149 global $pagenow;
150 $is_authorized = true;
151 if ( ! current_user_can( 'manage_options' ) ) {
152 $is_authorized = self::suretriggers_user_permission_check();
153 }
154 if ( 'index.php' != $pagenow || ! isset( OptionController::$options['secret_key'] ) || ! $is_authorized ) {
155 return;
156 }
157 $notice = get_option( 'suretriggers_verify_connection' );
158 // If empty option value for connection status, then verify the connection.
159 if ( empty( $notice ) || 'suretriggers_connection_successful' != $notice ) {
160 $connection_status = RestController::suretriggers_verify_wp_connection();
161 $connection_status_code = wp_remote_retrieve_response_code( $connection_status );
162 if ( is_wp_error( $connection_status ) ) {
163 update_option( 'suretriggers_verify_connection', 'suretriggers_connection_wp_error' );
164 } else {
165 if ( 200 !== $connection_status_code ) {
166 update_option( 'suretriggers_verify_connection', 'suretriggers_connection_error' );
167 } else {
168 update_option( 'suretriggers_verify_connection', 'suretriggers_connection_successful' );
169 }
170 }
171 }
172 $notice = get_option( 'suretriggers_verify_connection' );
173 if ( 'suretriggers_connection_successful' != $notice ) {
174 // If connection status is not successful, then show the notice.
175 ?>
176 <div class="notice notice-error is-dismissible">
177 <p>
178 <strong>
179 <?php esc_html_e( 'OttoKit Connection Issue', 'suretriggers' ); ?>
180 <span style="transform: rotate(-180deg); font-size: 20px;" class="dashicons dashicons-warning"></span>
181 </strong>
182 </p>
183 <p>
184 <?php esc_html_e( 'There is an issue with the established connection between WordPress and OttoKit. Please visit the OttoKit dashboard to verify and re-establish the connection if necessary.', 'suretriggers' ); ?>
185 </p>
186 <p>
187 <a href="<?php echo esc_url( admin_url( 'admin.php?page=suretriggers' ) ); ?>" class="button button-secondary"> <?php esc_html_e( 'Go To OttoKit', 'suretriggers' ); ?> </a>
188 </p>
189 </div>
190 <?php
191 }
192 }
193
194 /**
195 * Redirect user after plugin activation.
196 *
197 * @return void
198 */
199 public function redirect_after_activation() {
200 $is_redirect = get_transient( 'st-redirect-after-activation' );
201 if ( $is_redirect ) {
202 delete_transient( 'st-redirect-after-activation' );
203 $url = get_admin_url() . 'admin.php?page=suretriggers';
204 wp_safe_redirect( $url );
205 die;
206 }
207 }
208
209 /**
210 * Adding setting link.
211 *
212 * @param array $links links.
213 * @return array
214 */
215 public function add_settings_link( array $links ) {
216 $url = get_admin_url() . 'admin.php?page=suretriggers';
217 $setting_option = get_option( 'suretrigger_options' );
218 if ( isset( $setting_option ) && ! empty( $setting_option ) ) {
219 $settings_link = '<a href="' . $url . '">' . __( 'Dashboard', 'suretriggers' ) . '</a>';
220 } else {
221 $settings_link = '<a href="' . $url . '">' . __( 'Connect', 'suretriggers' ) . '</a>';
222 }
223 $links[] = $settings_link;
224 return $links;
225 }
226
227 /**
228 * Define constants
229 *
230 * @return void
231 * @since 1.0.0
232 */
233 public function define_constants() {
234 $sass_url = 'https://app.ottokit.com';
235 $api_url = 'https://api.ottokit.com';
236 $webhook_url = 'https://webhook.ottokit.com';
237
238 define( 'SURE_TRIGGERS_BASE', plugin_basename( SURE_TRIGGERS_FILE ) );
239 define( 'SURE_TRIGGERS_DIR', plugin_dir_path( SURE_TRIGGERS_FILE ) );
240 define( 'SURE_TRIGGERS_URL', plugins_url( '/', SURE_TRIGGERS_FILE ) );
241 define( 'SURE_TRIGGERS_VER', '1.1.1' );
242 define( 'SURE_TRIGGERS_DB_VER', '1.1.1' );
243 define( 'SURE_TRIGGERS_REST_NAMESPACE', 'sure-triggers/v1' );
244 define( 'SURE_TRIGGERS_SASS_URL', $sass_url . '/wp-json/wp-plugs/v1/' );
245 define( 'SURE_TRIGGERS_SITE_URL', $sass_url );
246 define( 'SURE_TRIGGERS_API_SERVER_URL', $api_url );
247 define( 'SURE_TRIGGERS_WEBHOOK_SERVER_URL', $webhook_url );
248
249 define( 'SURE_TRIGGERS_PAGE', 'OttoKit' );
250 define( 'SURE_TRIGGERS_AS_GROUP', 'OttoKit' );
251
252 define( 'SURE_TRIGGERS_ACTION_ERROR_MESSAGE', 'An unexpected error occurred. Something went wrong with the action.' );
253 }
254
255 /**
256 * Flush permalink rules while plugin activation.
257 *
258 * @return void
259 */
260 public function st_activate() {
261 flush_rewrite_rules(); //phpcs:ignore
262
263 set_transient( 'st-redirect-after-activation', true, 120 );
264 }
265
266 /**
267 * SureTriggers Access for Users and User Roles.
268 *
269 * @return bool
270 */
271 private function suretriggers_user_permission_check() {
272 $current_user = wp_get_current_user();
273 $current_user_id = $current_user->ID;
274 $current_user_roles = $current_user->roles;
275
276 // Get enabled users and roles with proper default values.
277 $enabled_users = get_option( 'suretriggers_enabled_users', [] );
278 $enabled_user_roles = get_option( 'suretriggers_enabled_user_roles', [] );
279
280 $enabled_users = is_array( $enabled_users ) ? $enabled_users : [];
281 $enabled_user_roles = is_array( $enabled_user_roles ) ? $enabled_user_roles : [];
282
283 $is_authorized = in_array( $current_user_id, (array) $enabled_users ) || array_intersect( $current_user_roles, (array) $enabled_user_roles );
284
285 return $is_authorized;
286 }
287
288 /**
289 * Add main menu
290 *
291 * @since x.x.x
292 *
293 * @return void
294 */
295 public function admin_menu() {
296 $page_title = apply_filters( 'st_menu_page_title', esc_html__( 'OttoKit', 'suretriggers' ) );
297 $logo = file_get_contents( plugin_dir_path( SURE_TRIGGERS_FILE ) . 'assets/images/OttoKitLogo.svg' );
298
299 $is_authorized = true;
300 if ( ! current_user_can( 'manage_options' ) ) {
301 $is_authorized = self::suretriggers_user_permission_check();
302 }
303
304 if ( $is_authorized ) {
305 add_menu_page(
306 $page_title,
307 $page_title,
308 'read',
309 'suretriggers',
310 [ $this, 'menu_callback' ],
311 $logo ? 'data:image/svg+xml;base64,' . base64_encode( $logo ) : '',
312 30.6002
313 );
314
315 add_submenu_page(
316 'suretriggers',
317 'OttoKit Status',
318 'Status',
319 'read',
320 'suretriggers-status',
321 [ $this, 'suretriggers_status_menu_callback' ]
322 );
323 }
324
325 if ( isset( OptionController::$options['secret_key'] ) ) {
326 add_options_page(
327 __( 'OttoKit Settings', 'suretriggers' ),
328 __( 'OttoKit Settings', 'suretriggers' ),
329 'manage_options',
330 'ottokit-settings',
331 [ $this, 'suretriggers_render_interface_callback' ]
332 );
333 }
334 }
335
336 /**
337 * Enqueue the admin scripts
338 *
339 * @param string $hook hook.
340 * @since x.x.x
341 *
342 * @return void
343 */
344 public function enqueue_scripts( $hook = '' ) {
345 if ( ! in_array( $hook, [ 'toplevel_page_suretriggers', 'ottokit_page_suretriggers-status', 'settings_page_ottokit-settings' ], true ) ) {
346 return;
347 }
348
349 remove_all_actions( 'admin_notices' );
350
351 $file = SURE_TRIGGERS_DIR . 'app/build/main.asset.php';
352 if ( ! file_exists( $file ) ) {
353 return;
354 }
355
356 $asset = require_once $file;
357
358 if ( ! isset( $asset ) ) {
359 return;
360 }
361
362 wp_register_script(
363 'sure-trigger-admin',
364 SURE_TRIGGERS_URL . 'app/build/main.js',
365 array_merge( $asset['dependencies'], [ 'regenerator-runtime' ] ),
366 $asset['version'],
367 true
368 );
369
370 wp_localize_script(
371 'sure-trigger-admin',
372 'sureTriggerData',
373 $this->get_localized_array()
374 );
375 wp_enqueue_script( 'sure-trigger-admin' );
376 wp_enqueue_style( 'sure-trigger-components', SURE_TRIGGERS_URL . 'app/build/style-main.css', [], SURE_TRIGGERS_VER );
377 wp_enqueue_style( 'st-trigger-style', SURE_TRIGGERS_URL . 'assets/admin-css/st-admin-css.css', [], SURE_TRIGGERS_VER );
378 wp_enqueue_style( 'sure-trigger-css', SURE_TRIGGERS_URL . 'app/build/main.css', [], SURE_TRIGGERS_VER );
379 }
380
381 /**
382 * Get localized array for sure triggers.
383 *
384 * @return array
385 */
386 private function get_localized_array() {
387 $settings_nonce = wp_create_nonce( 'suretriggers_settings_nonce_action' );
388 $current_user = wp_get_current_user();
389 global $wp_roles;
390 $is_authorized = true;
391 if ( ! current_user_can( 'manage_options' ) ) {
392 $is_authorized = self::suretriggers_user_permission_check();
393 }
394
395 $source_type = get_option( 'suretriggers_source' );
396
397 // Get enabled users and roles with proper default values.
398 $enabled_users = get_option( 'suretriggers_enabled_users', [] );
399 $enabled_user_roles = get_option( 'suretriggers_enabled_user_roles', [] );
400
401 $enabled_users = is_array( $enabled_users ) ? $enabled_users : [];
402 $enabled_user_roles = is_array( $enabled_user_roles ) ? $enabled_user_roles : [];
403
404 $data = [
405 'siteContent' => [
406 'siteUrl' => str_replace( '/wp-json/', '', get_rest_url() ),
407 'redirectUrl' => get_site_url() . '/wp-admin/themes.php?page=suretriggers',
408 'connectNonce' => wp_create_nonce( 'sure-trigger-connect' ),
409 'connectUrl' => SURE_TRIGGERS_SITE_URL . '/connect-st/connect',
410 'siteTitle' => get_bloginfo( 'name' ),
411 'resetUrl' => base64_encode( wp_nonce_url( admin_url( 'admin.php?st-reset=true' ), 'st-reset-action' ) ),
412 'sourceType' => $source_type,
413 ],
414 'user' => [
415 'name' => $current_user->display_name,
416 'email' => $current_user->user_email,
417 ],
418 'stSaasURL' => trailingslashit( SURE_TRIGGERS_SITE_URL ),
419 'stPluginURL' => plugin_dir_url( SURE_TRIGGERS_FILE ),
420 'integrations' => IntegrationsController::get_activated_integrations(),
421 'enabledIntegrations' => OptionController::get_option( 'enabled_integrations' ),
422 'verification_status' => false,
423 'projects' => [],
424 'apiSlug' => SURE_TRIGGERS_REST_NAMESPACE,
425 'reConnectSorryMsg' => (bool) OptionController::get_option( 'st_connect_notice_deprecated' ),
426 'usersRoles' => array_diff_key( $wp_roles->get_names(), [ 'administrator' => '' ] ),
427 'usersList' => get_users(
428 [
429 'fields' => [
430 'ID',
431 'display_name',
432 ],
433 'role__not_in' => [
434 'administrator',
435 ],
436 ]
437 ),
438 'enabledUsers' => $enabled_users,
439 'enabledUserRoles' => $enabled_user_roles,
440 ];
441
442 if ( $is_authorized ) {
443 $data['siteContent']['accessKey'] = SaasApiToken::get();
444 $data['siteContent']['connected_email'] = OptionController::get_option( 'connected_email_key' );
445 }
446
447 $data['settingsNonce'] = esc_js( $settings_nonce );
448 $data['ajaxurl'] = esc_url( admin_url( 'admin-ajax.php' ) );
449
450 return apply_filters( 'sure_trigger_control_localize_vars', $data );
451 }
452
453 /**
454 * Render OttoKit Interface callback.
455 *
456 * @return void
457 */
458 public function suretriggers_render_interface_callback() {
459 ?>
460 <div id="ottokit-settings-page" class="ottokit-settings"></div>
461 <?php
462 }
463
464 /**
465 * Menu callback.
466 *
467 * @since x.x.x
468 *
469 * @return void
470 */
471 public function menu_callback() {
472 // Check permalink structure first.
473 $permalink_structure = get_option( 'permalink_structure' );
474 $is_plain_permalink = empty( $permalink_structure );
475
476 // If permalink structure is "Plain" and we're trying to connect or already connected, show a prominent warning.
477 if ( $is_plain_permalink ) {
478 ?>
479 <div class="st-permalink-warning-wrapper">
480 <div class="st-permalink-warning-card">
481 <div class="st-permalink-warning-icon">
482 <span class="st-permalink-warning-icon-text">!</span>
483 </div>
484 <div class="st-permalink-warning-content">
485 <p class="st-permalink-warning-title">
486 <?php esc_html_e( '“Plain” Permalink Structure Detected', 'suretriggers' ); ?>
487 </p>
488 <p class="st-permalink-warning-message">
489 <?php esc_html_e( 'Your site is currently using the “Plain” permalink structure, which is not supported by OttoKit. Please visit', 'suretriggers' ); ?>
490 <a href="<?php echo esc_url( admin_url( 'options-permalink.php' ) ); ?>" target="_blank" class="st-permalink-warning-link">
491 <?php esc_html_e( 'Permalinks Settings', 'suretriggers' ); ?>
492 </a>
493 <?php esc_html_e( 'on your WordPress Dashboard and choose any structure other than “Plain”.', 'suretriggers' ); ?>
494 </p>
495 </div>
496 </div>
497 </div>
498 <?php
499 }
500
501 // Verify Token.
502 $response = RestController::verify_user_token();
503 $response_body = wp_remote_retrieve_body( $response );
504 $response_code = wp_remote_retrieve_response_code( $response );
505 if ( ! empty( $response_body ) ) {
506 $response_body = json_decode( $response_body, true );
507 }
508 if ( 200 === $response_code || 401 === $response_code ) {
509 if ( is_array( $response_body ) && isset( $response_body['is_iframe_enabled'] ) && 'NO' === $response_body['is_iframe_enabled'] ) {
510 ?>
511 <div class="suretriggers-nobase">
512 <div>
513 <div>
514 <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>
515 <h2 class="suretriggers-info-title">
516 OttoKit is connected.
517 </h2>
518 <p class="suretriggers-info-content">
519 Your WordPress site is successfully connected to the OttoKit SaaS platform. However, the OttoKit interface display is currently disabled. Click below to enable it.
520 </p>
521 <a class="suretriggers-info-link" href="<?php echo esc_url( SURE_TRIGGERS_SITE_URL . '/apps/WordPress' ); ?>" target="_blank">
522 Access Connection Page
523 </a>
524 </div>
525 </div>
526 </div>
527 <?php
528 } else {
529 ?>
530 <div id="sure-triggger-entry" class="st-base"></div>
531 <?php
532 }
533 } elseif ( isset( $response ) && is_wp_error( $response ) || 200 !== $response_code ) {
534 ?>
535 <div class="suretriggers-nobase">
536 <div>
537 <div>
538 <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>
539 <h2 class="suretriggers-info-title">
540 OttoKit Not Connected.
541 </h2>
542 <p class="suretriggers-info-content">
543 It looks like your WordPress site’s connection with OttoKit has been affected because the URL used for communication has changed. The current link for your site is different from the one OttoKit was originally connected to.
544 </p>
545 <a class="suretriggers-info-link" href="<?php echo esc_url( SURE_TRIGGERS_SITE_URL ); ?>" target="_blank">
546 Access Dashboard
547 </a>
548 <a class="suretriggers-info-link" href="<?php echo esc_url( wp_nonce_url( admin_url( 'admin.php?st-reset=true' ), 'st-reset-action' ) ); ?>">
549 Disconnect OttoKit
550 </a>
551 </div>
552 </div>
553 </div>
554 <?php
555 }
556 }
557
558 /**
559 * Status Menu callback.
560 *
561 * @since x.x.x
562 *
563 * @return void
564 */
565 public function suretriggers_status_menu_callback() {
566 if ( ! isset( OptionController::$options['secret_key'] ) ) {
567 ?>
568 <div class="suretriggers-nobase">
569 <div>
570 <div>
571 <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>
572 <h2 class="suretriggers-info-title">
573 <?php esc_html_e( 'OttoKit Not Connected.', 'suretriggers' ); ?>
574 </h2>
575 <p class="suretriggers-info-content">
576 <?php esc_html_e( 'Please connect your OttoKit (Formerly SureTriggers) account to access registered events and outgoing requests.', 'suretriggers' ); ?>
577 </p>
578 <a href="<?php echo esc_url( admin_url( 'admin.php?page=suretriggers' ) ); ?>" class="suretriggers-info-link"> <?php esc_html_e( 'Connect With OttoKit (Formerly SureTriggers)', 'suretriggers' ); ?> </a>
579 </div>
580 </div>
581 </div>
582 <?php
583 return;
584 }
585 ?>
586 <div class="wrap">
587 <?php
588 $tabs = [
589 'st_system_page' => 'Status',
590 'st_outgoing_requests' => 'Outgoing Requests',
591 ];
592 $current_tab = 'st_system_page';
593 if ( isset( $_REQUEST['tab'], $_REQUEST['_wpnonce'] ) && wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'suretriggers_tab_nonce' ) ) {
594 if ( array_key_exists( sanitize_key( $_REQUEST['tab'] ), $tabs ) ) {
595 $current_tab = sanitize_key( $_REQUEST['tab'] );
596 }
597 }
598 ?>
599 <nav class="suretriggers-nav-tab nav-tab-wrapper">
600 <?php
601 foreach ( $tabs as $name => $label ) {
602 $tab_url = add_query_arg(
603 [
604 'tab' => $name,
605 '_wpnonce' => wp_create_nonce( 'suretriggers_tab_nonce' ),
606 ],
607 admin_url( 'admin.php?page=suretriggers-status' )
608 );
609 echo '<a href="' . esc_url( $tab_url ) . '" class="nav-tab ';
610 if ( $current_tab == $name ) {
611 echo 'nav-tab-active';
612 }
613 echo '">' . esc_html( $label ) . '</a>';
614 }
615 ?>
616 </nav>
617 <?php
618 switch ( $current_tab ) {
619 case 'st_system_page':
620 include_once __DIR__ . '/Admin/Views/st-admin-system-page.php';
621 break;
622 case 'st_outgoing_requests':
623 include_once __DIR__ . '/Admin/Views/st-admin-outgoing-req-page.php';
624 break;
625 }
626 ?>
627 </div>
628 <?php
629 }
630
631 /**
632 * Include all files from the folder.
633 *
634 * @param string $folder folder path.
635 * @return void
636 */
637 public function include_all_files( $folder ) {
638 $dir = new DirectoryIterator( $folder );
639 foreach ( $dir as $file ) {
640 if ( ! $file->isDot() ) {
641 if ( $file->isDir() ) {
642 $this->include_all_files( $file->getPathname() );
643 } else {
644 require_once $file->getPathname();
645 }
646 }
647 }
648 }
649
650 /**
651 * Initialize core trigger and actions.
652 *
653 * @return void
654 */
655 public function initialize_core() {
656
657 IntegrationsController::load_event_files();
658
659 EventController::get_instance();
660 IntegrationsController::get_instance();
661 GlobalSearchController::get_instance();
662 RestController::get_instance();
663 OptionController::get_instance();
664 AutomationController::get_instance();
665 AuthController::get_instance();
666 RoutesController::get_instance();
667 WebhookRequestsController::get_instance();
668 SettingsController::get_instance();
669
670 // SureTriggers Custom Filter data.
671 add_filter( 'suretriggers_get_iframe_url', [ $this, 'suretriggers_iframe_data' ] );
672 add_filter( 'suretriggers_is_user_connected', [ $this, 'suretriggers_saas_connected_data' ] );
673
674 // Create Webhook Request Log table.
675 WebhookRequestsController::suretriggers_webhook_request_log_table();
676 // Schedule the cron jon to retry failed triggers.
677 WebhookRequestsController::suretriggers_setup_custom_cron();
678
679 $this->include_all_files( SURE_TRIGGERS_DIR . 'src/Integrations/' );
680 }
681
682 /**
683 * Added option to reset plugin in case of testing.
684 *
685 * @return void
686 */
687 public function reset_plugin() {
688 $nonce = sanitize_text_field( wp_unslash( isset( $_GET['_wpnonce'] ) ? $_GET['_wpnonce'] : false ) );
689
690 if ( $nonce && wp_verify_nonce( $nonce, 'st-reset-action' ) ) {
691 $is_reset = sanitize_text_field( wp_unslash( isset( $_GET['st-reset'] ) ? $_GET['st-reset'] : false ) );
692 if ( $is_reset && current_user_can( 'manage_options' ) ) {
693 delete_option( 'suretrigger_options' );
694 wp_safe_redirect( admin_url( 'admin.php?page=suretriggers' ) );
695 exit();
696 }
697 }
698 }
699
700 /**
701 * Custom Filter data.
702 *
703 * @param string $site_url Optional. Site URL to include in the iframe data.
704 * @return string
705 */
706 public function suretriggers_iframe_data( $site_url = '' ) {
707 $site_url = esc_url_raw( $site_url );
708 if ( ! current_user_can( 'manage_options' ) ) {
709 return $site_url;
710 }
711 $site_content_data = [
712 'stSaasURL' => $site_url . 'wp-login',
713 'stCode' => SaasApiToken::get(),
714 'baseUrl' => str_replace( '/wp-json/', '', get_rest_url() ),
715 'resetUrl' => rtrim( base64_encode( wp_nonce_url( admin_url( 'admin.php?st-reset=true' ), 'st-reset-action' ) ), '=' ), // phpcs:ignore
716 ];
717 $params = [
718 'st-code' => $site_content_data['stCode'],
719 'base_url' => $site_content_data['baseUrl'],
720 'reset_url' => $site_content_data['resetUrl'],
721 'redirect_url' => $site_url . 'embed-login',
722 'is_embedded' => true,
723 ];
724
725 if ( filter_var( $site_url, FILTER_VALIDATE_URL ) ) {
726 $iframe_url = add_query_arg( $params, $site_content_data['stSaasURL'] );
727 } else {
728 $default_url = trailingslashit( SURE_TRIGGERS_SITE_URL ) . '?path=dashboard';
729 $iframe_url = add_query_arg( $params, $default_url );
730 }
731 return esc_url_raw( $iframe_url );
732 }
733
734
735 /**
736 * Custom Filter data to check if user is logged in iframe.
737 *
738 * @return bool
739 */
740 public function suretriggers_saas_connected_data() {
741 if ( ! current_user_can( 'manage_options' ) ) {
742 return false;
743 }
744 $token = SaasApiToken::get();
745
746 if ( '' === $token || null === $token || false === $token || 'connection-denied' === $token ) {
747 $logged_in = false;
748 } else {
749 $logged_in = true;
750 }
751 return $logged_in;
752 }
753 }
754