PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 3.6.0
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v3.6.0
3.6.0 3.5.3 3.5.2 3.5.1 3.5.0 3.4.8 3.4.7 3.4.6 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5.1 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.10 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.6.1 1.6.7 1.7.0 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.2 1.7.2.1 1.7.2.2 1.7.3 1.7.4 1.7.5 1.7.5.1 1.7.5.2 1.7.6 1.7.7 1.7.7.1 1.7.7.2 1.7.8 1.7.9 1.8.0 1.8.0.1 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.0.1 1.9.1 1.9.2 1.9.3 1.9.4 1.9.4.1 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.0.1 2.0.1 2.0.2 2.0.3 2.0.3.1 2.0.4 2.0.4.1 2.0.5 2.0.6 2.0.7 2.0.8 2.0.8.1 2.0.9 3.0.0 3.0.0.1 3.0.1 3.0.2 3.0.3 3.0.3.1 3.0.4 3.0.4.1 3.0.4.2 3.0.5 3.0.5.1 3.0.5.2 3.0.6 3.0.6.1 3.0.7.1 3.0.8 3.0.8.1 3.0.9 3.0.9.1 3.0.9.2 3.0.9.3 3.0.9.4 3.0.9.5 3.1.0 3.1.1 3.1.2 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.3.0 3.4.0 3.4.1 3.4.2 3.4.2.1 3.4.3 3.4.4 3.4.5 trunk 1.0 1.0.1 1.0.2 1.0.3
everest-forms / vendor / themegrill / themegrill-sdk / src / Modules / Logger.php
everest-forms / vendor / themegrill / themegrill-sdk / src / Modules Last commit date
Announcements.php 6 months ago Licenser.php 1 month ago Logger.php 6 months ago Notification.php 6 months ago Rollback.php 6 months ago ScriptLoader.php 6 months ago UninstallFeedback.php 6 months ago Updater.php 1 month ago
Logger.php
179 lines
1 <?php
2 /**
3 * The logger model class for ThemeGrill SDK
4 *
5 * @package ThemeGrillSDK
6 * @subpackage Modules
7 * @copyright Copyright (c) 2025, ThemeGrill
8 * @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
9 * @since 1.0.0
10 */
11
12 namespace ThemeGrillSDK\Modules;
13
14 use ThemeGrillSDK\Common\AbstractModule;
15 use ThemeGrillSDK\Loader;
16 use ThemeGrillSDK\Product;
17
18 // Exit if accessed directly.
19 if ( ! defined( 'ABSPATH' ) ) {
20 exit;
21 }
22
23 /**
24 * Logger module for ThemeGrill SDK.
25 */
26 class Logger extends AbstractModule {
27 /**
28 * Endpoint where to collect logs.
29 */
30 const TRACKING_ENDPOINT = 'https://api.themegrill.com/tracking/log';
31
32 /**
33 * Check if we should load the module for this product.
34 *
35 * @param Product $product Product to load the module for.
36 *
37 * @return bool Should we load ?
38 */
39 public function can_load( $product ) {
40 return apply_filters( $product->get_slug() . '_sdk_enable_logger', true );
41 }
42
43 /**
44 * Load module logic.
45 *
46 * @param Product $product Product to load.
47 *
48 * @return Logger Module object.
49 */
50 public function load( $product ) {
51 $this->product = $product;
52 add_action( 'wp_loaded', array( $this, 'setup_actions' ) );
53 add_action( 'admin_init', array( $this, 'setup_notification' ) );
54 return $this;
55 }
56
57 /**
58 * Setup notification on admin.
59 */
60 public function setup_notification() {
61 if ( $this->is_logger_active() ) {
62 return;
63 }
64 add_filter( 'themegrill_sdk_registered_notifications', [ $this, 'add_notification' ] );
65 }
66
67 /**
68 * Setup tracking actions.
69 */
70 public function setup_actions() {
71 if ( ! $this->is_logger_active() ) {
72 return;
73 }
74 $action_key = $this->product->get_key() . '_log_activity';
75 if ( ! wp_next_scheduled( $action_key ) ) {
76 wp_schedule_single_event( time() + ( wp_rand( 1, 24 ) * 3600 ), $action_key );
77 }
78 add_action( $action_key, array( $this, 'send_log' ) );
79 }
80
81 /**
82 * Check if the logger is active.
83 *
84 * @return bool Is logger active?
85 */
86 private function is_logger_active() {
87 $default = 'no';
88
89 if ( ! $this->product->is_wordpress_available() ) {
90 $default = 'yes';
91 } else {
92 $all_products = Loader::get_products();
93 foreach ( $all_products as $product ) {
94 if ( $product->requires_license() ) {
95 $default = 'yes';
96 break;
97 }
98 }
99 }
100
101 return ( get_option( $this->product->get_key() . '_logger_flag', $default ) === 'yes' );
102 }
103 /**
104 * Add notification to queue.
105 *
106 * @param array $all_notifications Previous notification.
107 *
108 * @return array All notifications.
109 */
110 public function add_notification( $all_notifications ) {
111
112 $message = apply_filters( $this->product->get_key() . '_logger_heading', Loader::$labels['logger']['notice'] );
113
114 $message = str_replace(
115 array( '{product}' ),
116 $this->product->get_friendly_name(),
117 $message
118 );
119 $button_submit = apply_filters( $this->product->get_key() . '_logger_button_submit', Loader::$labels['logger']['cta_y'] );
120 $button_cancel = apply_filters( $this->product->get_key() . '_logger_button_cancel', Loader::$labels['logger']['cta_n'] );
121
122 $all_notifications[] = [
123 'id' => $this->product->get_key() . '_logger_flag',
124 'message' => $message,
125 'ctas' => [
126 'confirm' => [
127 'link' => '#',
128 'text' => $button_submit,
129 ],
130 'cancel' => [
131 'link' => '#',
132 'text' => $button_cancel,
133 ],
134 ],
135 ];
136
137 return $all_notifications;
138 }
139
140 /**
141 * Send the statistics to the api endpoint.
142 */
143 public function send_log() {
144 $environment = array();
145 $theme = wp_get_theme();
146 $environment['theme'] = array();
147 $environment['theme']['name'] = $theme->get( 'Name' );
148 $environment['theme']['author'] = $theme->get( 'Author' );
149 $environment['theme']['parent'] = $theme->parent() !== false ? $theme->parent()->get( 'Name' ) : $theme->get( 'Name' );
150 $environment['plugins'] = get_option( 'active_plugins' );
151 global $wp_version;
152 wp_remote_post(
153 self::TRACKING_ENDPOINT,
154 array(
155 'method' => 'POST',
156 'timeout' => 3,
157 'redirection' => 5,
158 'body' => wp_json_encode(
159 array(
160 'site' => get_site_url(),
161 'slug' => $this->product->get_slug(),
162 'version' => $this->product->get_version(),
163 'wp_version' => $wp_version,
164 'install_time' => $this->product->get_install_time(),
165 'locale' => get_locale(),
166 'data' => apply_filters( $this->product->get_key() . '_logger_data', array() ),
167 'environment' => $environment,
168 'license' => apply_filters( $this->product->get_key() . '_license_status', '' ),
169 )
170 ),
171 'headers' => array(
172 'Content-Type' => 'application/json',
173 'User-Agent' => 'ThemeGrillSDK',
174 ),
175 )
176 );
177 }
178 }
179