PluginProbe
WP Mail Log / dev
WP Mail Log vdev
1.1.6 trunk 0.1 0.2 0.3 0.4 0.5 1.0 1.0.1 1.0.2 1.1.1 1.1.2 1.1.3 1.1.5 dev
wp-mail-log / includes / bootstrap.php

bootstrap.php in WP Mail Log dev, at includes/bootstrap.php

626 lines 20.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // phpcs:disable WordPress.DateTime.RestrictedFunctions.date_date
3 // phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
4 // phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_error_log
5 // phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_print_r
6 namespace WML;
7
8 use WML\Classes\Admin_Notice;
9 use WML\Classes\Settings;
10
11 /**
12 * Main Functionality File
13 *
14 * This class is to add functionality of plugin.
15 *
16 */
17 class WP_MAIL_LOG {
18
19 /**
20 * Plugin Title
21 *
22 * @var $wm_title string
23 */
24 private $wml_title = 'WP Mail Log';
25 /**
26 * The instance
27 *
28 * @var $instance null|object
29 */
30 public static $instance;
31
32 public $helper;
33 /**
34 * Current Tab
35 *
36 * @var $current_tab string
37 */
38 private $current_tab = '';
39 /**
40 * Return the instance of class
41 *
42 * @since 0.3
43 * @return object $instance of class
44 * @access public
45 *
46 */
47 public static function get_instance() {
48 if ( ! isset( self::$instance ) ) {
49 self::$instance = new self();
50 }
51 return self::$instance;
52 }
53 /**
54 * The constructor of class. Automatically call when class object create
55 *
56 * @since 0.3
57 * @return void
58 * @access public
59 *
60 */
61 public function __construct() {
62 $this->register_autoloader();
63
64 // register_activation_hook( WML_BASE, [ $this, 'wml_activate' ] );
65 // register_deactivation_hook( WML_BASE, [ $this, 'wml_deactivate' ] );
66 // add_action( 'wpv/wml/delete_logs', [ $this, 'wml_delete_entry' ] );
67 // Register Rest API
68 add_action( 'rest_api_init', [ $this, 'init_rest_api' ] );
69
70 // Add Adimn Menu Setting Page
71 add_action( 'admin_menu', [ $this, 'admin_menu' ] );
72
73 // Add Setting Page Header
74 add_action( 'in_admin_header', [ $this, 'in_admin_header' ] );
75
76 // Create Table
77 add_action( 'plugins_loaded', [ 'WML\Classes\DbTable', 'wml_plugin_activated' ] );
78
79 // Caputure Mail Register Filter
80 add_filter( 'wp_mail', [ 'WML\Classes\Capture_Mail', 'log_email' ] );
81
82 // for admin scripts & styles
83 add_action( 'admin_enqueue_scripts', [ $this, 'wml_admin_enqueue_scripts' ] );
84
85 add_action( 'admin_notices', [ $this, 'add_review_notice' ] );
86
87 add_filter( 'admin_footer_text', [ $this, 'admin_footer_text' ] );
88
89 add_action( 'admin_init', [ $this, 'wpv_mail_review' ], 10 );
90
91 // Add Script type module
92 add_filter('script_loader_tag', [ $this, 'add_type_attribute' ] , 10, 3);
93 }
94
95
96
97 /**
98 * Add admin menu
99 *
100 * @since 0.3
101 * @return void
102 * @access public
103 *
104 */
105 public function admin_menu() {
106 add_menu_page(
107 __( 'WP Mail Log', 'wpv-wml' ),
108 __( 'WP Mail Log', 'wpv-wml' ),
109 'manage_options',
110 'wp-mail-log',
111 [ $this, 'create_wp_mail_page' ],
112 // 'dashicons-chart-line',
113 'dashicons-email-alt',
114 25
115 );
116 add_submenu_page( 'wp-mail-log', __( 'WP Mail Logs', 'wpv-wml' ), __( 'Emails Logs', 'wpv-wml' ), 'manage_options', 'wp-mail-log', [ $this, 'create_wp_mail_page' ], 1 );
117 // add_submenu_page( 'wp-mail-log', 'WP Mail Log Settings', 'Settings', 'manage_options', 'wpv-wpml-settings', [ $this, 'wpml_settings' ], 5 );
118 }
119 /**
120 * Create Setting page
121 *
122 * @since 0.3
123 * @return void
124 * @access public
125 *
126 */
127 public function wpml_settings() {
128 if ( isset( $_GET['wml_nonce'] ) && ! wp_verify_nonce( $_GET['wml_nonce'], 'wp_rest' ) ) {
129 die( 'Sorry, your nonce did not verify!' );
130 }
131
132 if ( isset( $_GET['tab'] ) ) {
133 $this->current_tab = sanitize_text_field( wp_unslash( $_GET['tab'] ) );
134 }
135
136 $setting_pages = [
137 'general' => __( 'General', 'wpv-wml' ),
138 ];
139 ?>
140
141 <div class="wml-settings-wrapper">
142
143 <div class="wml-data-wrapper">
144 <div class="wml-settings-content-wrapper">
145 <nav class="wml-nav-tab-wrapper">
146 <?php
147 foreach ( $setting_pages as $key => $label ) {
148 ?>
149 <a class="wml-nav-tab <?php echo ( ( '' === $this->current_tab && 'general' === $key ) || $key === $this->current_tab ) ? 'wml-tab-active' : ''; ?>" href="admin.php?page=wpv-wpml-settings&tab=<?php echo esc_html( $key . add_query_arg( 'wml_nonce', wp_create_nonce( 'wp_rest' ) ) ); ?>"><?php echo esc_html( $label ); ?></a>
150 <?php
151 }
152 ?>
153 </nav>
154
155 <div class="wml-settings-tab-content-wrapper">
156
157 <?php
158 if ( '' === $this->current_tab || 'general' === $this->current_tab ) {
159 ?>
160 <div id="wml-settings"></div>
161 <?php
162 }
163 ?>
164
165 </div>
166
167 </div>
168 </div>
169
170 </div>
171 <?php
172 }
173
174 public function add_review_notice() {
175 if ( is_admin() ) {
176 $remind_later = get_transient( 'wml_remind_later' );
177
178 $wml_review = get_option( 'wml_review' );
179
180 if ( $wml_review === 'done' || $remind_later ) {
181 return;
182 }
183
184 global $wpdb;
185 $rowcount = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}wml_entries" );
186
187 if ( $rowcount > 10 ) {
188 $this->wml_review_box();
189 }
190 }
191 }
192
193 public function sidebar() {
194 echo '<div>Sidebar Content</div>';
195 }
196
197 /**
198 * Create Header
199 *
200 * Create header for our plugin pages
201 *
202 * @since 0.3
203 * @return void
204 * @access public
205 *
206 */
207 public function in_admin_header() {
208 $nav_links = $this->get_nav_links();
209 $current_screen = get_current_screen();
210 if ( ! isset( $nav_links[ $current_screen->id ] ) ) {
211 return;
212 }
213 ?>
214 <div class="wml-topbar">
215 <div class="wml-branding">
216 <div class="wml-logo">
217 <svg viewBox="0 0 831 775" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
218 <!-- Generator: Sketch 57.1 (83088) - https://sketch.com -->
219 <title>WP Mail Log</title>
220 <desc>Email Log for WordPress</desc>
221 <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
222 <g id="El-logo-blue" fill-rule="nonzero">
223 <path d="M227.7,160.1 C227.7,155.8 229,151.8 231.3,148.5 C232.4,146.8 233.8,145.3 235.3,144.1 C238.9,141.1 243.5,139.3 248.5,139.3 L582.7,139.3 C587,139.3 591,140.6 594.3,142.9 C596.5,144.4 598.4,146.3 599.9,148.5 C602.1,151.8 603.5,155.8 603.5,160.1 L603.5,394.9 L830.8,257.3 L446.5,10.2 C427.4,-2.1 402.9,-2.1 383.8,10.2 L0.3,257.2 L227.6,394.8 L227.6,160.1 L227.7,160.1 Z" id="Path" fill="#154DAE"></path>
224 <path d="M599.9,148.5 C598.4,146.3 596.5,144.4 594.3,142.9 C591,140.7 587,139.3 582.7,139.3 L248.5,139.3 C243.5,139.3 238.9,141.1 235.3,144.1 C233.8,145.4 232.4,146.9 231.3,148.5 C229.1,151.8 227.7,155.8 227.7,160.1 L227.7,394.8 L283.2,428.4 L329.1,456.2 L382.3,488.4 C402.8,500.8 428.4,500.8 448.8,488.4 L503.7,455.7 L549.5,427.5 L603.4,394.9 L603.4,160.1 C603.5,155.8 602.2,151.8 599.9,148.5 Z M368.5,182.9 L462.7,182.9 C469.5,182.9 475,188.4 475,195.2 C475,202 469.5,207.5 462.7,207.5 L368.5,207.5 C361.7,207.5 356.2,202 356.2,195.2 C356.2,188.4 361.7,182.9 368.5,182.9 Z M495.6,384.8 L335.6,384.8 C328.8,384.8 323.3,379.3 323.3,372.5 C323.3,365.7 328.8,360.2 335.6,360.2 L495.6,360.2 C502.4,360.2 507.9,365.7 507.9,372.5 C507.9,379.3 502.4,384.8 495.6,384.8 Z M342.1,313.4 C342.1,306.6 347.6,301.1 354.4,301.1 L476.6,301.1 C483.4,301.1 488.9,306.6 488.9,313.4 C488.9,320.2 483.4,325.7 476.6,325.7 L354.5,325.7 C347.7,325.7 342.1,320.2 342.1,313.4 Z M515.5,266.6 L315.7,266.6 C308.9,266.6 303.4,261.1 303.4,254.3 C303.4,247.5 308.9,242 315.7,242 L515.5,242 C522.3,242 527.8,247.5 527.8,254.3 C527.8,261.1 522.3,266.6 515.5,266.6 Z" id="Shape" fill="#F2F2F2"></path>
225 <polygon id="Path" fill="#154DAE" points="101.1 694.3 329.1 456.2 283.2 428.4"></polygon>
226 <polygon id="Path" fill="#154DAE" points="732.3 694.3 549.6 427.5 503.8 455.7"></polygon>
227 <path d="M830.8,736.5 L830.8,257.2 L830.8,257.2 L603.5,394.8 L549.6,427.4 L732.4,694.2 L503.8,455.7 L448.9,488.4 C428.4,500.8 402.8,500.8 382.4,488.4 L329.2,456.2 L101.1,694.3 L283.2,428.4 L227.7,394.8 L0.4,257.2 L0.4,707.7 L0.4,736.5 C0.4,757.8 17.7,775 38.9,775 L792.3,775 C813.6,775 830.8,757.8 830.8,736.5 Z" id="Path" fill="#1B5ED7"></path>
228 <path d="M368.5,207.6 L462.7,207.6 C469.5,207.6 475,202.1 475,195.3 C475,188.5 469.5,183 462.7,183 L368.5,183 C361.7,183 356.2,188.5 356.2,195.3 C356.2,202.1 361.7,207.6 368.5,207.6 Z" id="Path" fill="#154DAE"></path>
229 <path d="M515.5,242 L315.7,242 C308.9,242 303.4,247.5 303.4,254.3 C303.4,261.1 308.9,266.6 315.7,266.6 L515.5,266.6 C522.3,266.6 527.8,261.1 527.8,254.3 C527.8,247.5 522.3,242 515.5,242 Z" id="Path" fill="#154DAE"></path>
230 <path d="M476.7,325.7 C483.5,325.7 489,320.2 489,313.4 C489,306.6 483.5,301.1 476.7,301.1 L354.5,301.1 C347.7,301.1 342.2,306.6 342.2,313.4 C342.2,320.2 347.7,325.7 354.5,325.7 L476.7,325.7 Z" id="Path" fill="#154DAE"></path>
231 <path d="M495.6,360.1 L335.6,360.1 C328.8,360.1 323.3,365.6 323.3,372.4 C323.3,379.2 328.8,384.7 335.6,384.7 L495.6,384.7 C502.4,384.7 507.9,379.2 507.9,372.4 C507.9,365.6 502.4,360.1 495.6,360.1 Z" id="Path" fill="#154DAE"></path>
232 </g>
233 </g>
234 </svg>
235 </div>
236
237 <h2>
238 <?php
239 echo esc_html( $this->wml_title );
240 ?>
241 </h2>
242 <span class="wml-version"><?php echo 'v ' . esc_html( WML_VERSION ); ?></span>
243 </div>
244 </div>
245
246 <?php
247 }
248 /**
249 * Navigation link of Our Plugin
250 *
251 * @since 0.3
252 * @return bool
253 * @access public
254 *
255 */
256 public function get_nav_links() {
257 $nav = [
258 'toplevel_page_wp-mail-log' => [
259 'label' => __( 'Email Logs', 'wpv-wml' ),
260 'link' => admin_url( 'admin.php?page=wp-mail-log' ),
261 'top_nav' => true,
262 ],
263 'wp-mail-log_page_wpv-wpml-settings' => [
264 'label' => __( 'Settings', 'wpv-wml' ),
265 'link' => admin_url( 'admin.php?page=wpv-wml-settings' ),
266 'top_nav' => true,
267 ],
268 ];
269
270 $nav = apply_filters( 'wml/nav_links', $nav );
271
272 return $nav;
273 }
274
275 /**
276 * Create Mail Log Page
277 *
278 * Create page to view logs, render content using react js.
279 *
280 * @since 0.3
281 * @return void
282 * @access public
283 *
284 */
285
286 public function create_wp_mail_page() {
287 ?>
288 <div class="wml-content-section">
289 <div id="wml-content"></div>
290 </div>
291 <?php
292 }
293
294 /**
295 * Add Admin Scripts
296 *
297 * Function fire on `admin_enqueue_scripts` hook
298 *
299 * @since 0.3
300 * @return void
301 * @access public
302 *
303 */
304
305 public function wml_admin_enqueue_scripts() {
306 $settings = Settings::instance();
307 $settings = $settings->get();
308 $screen = get_current_screen();
309 wp_enqueue_style( 'wml-admin-style', WML_URL . 'assets/css/admin.css', [], WML_VERSION );
310 if ( $screen->id !== 'toplevel_page_wp-mail-log' ) {
311 return;
312 }
313 wp_enqueue_style( 'log-style', WML_URL . 'build/css/index.css', [], WML_VERSION );
314 wp_enqueue_script( 'log-js', WML_URL . 'build/js/index.js', [], WML_VERSION, true );
315
316 wp_localize_script(
317 'log-js',
318 'WmlGlobalVar',
319 [
320 'site_url' => site_url(),
321 'ajax_url' => admin_url( 'admin-ajax.php' ),
322 'admin_url' => admin_url(),
323 'rest_url' => get_rest_url(),
324 'nonce' => wp_create_nonce( 'wp_rest' ),
325 'ajax_nonce' => wp_create_nonce( 'wml_ajax_nonce' ),
326 'locale' => get_locale(),
327 'date-formate' => get_option( 'date_format' ),
328 'temp_date' => date( get_option( 'date_format' ) ),
329 'settings' => $settings,
330 'upload_dir' => wp_upload_dir()['baseurl'],
331 ]
332 );
333 }
334
335 function add_type_attribute($tag, $handle, $src){
336 // if not your script, do nothing and return original $tag
337 if ( 'log-js' !== $handle ) {
338 return $tag;
339 }
340 // change the script tag by adding type="module" and return it.
341 $tag = '<script type="module" src="' . esc_url( $src ) . '"></script>';
342 return $tag;
343 }
344
345
346
347 /**
348 * Add Api endopints
349 *
350 * Function fire on `rest_api_init` hook
351 *
352 * @since 0.3
353 * @return void
354 * @access public
355 *
356 */
357 public function init_rest_api() {
358 $controllers = [
359 new \WML\Classes\Api(),
360 ];
361 foreach ( $controllers as $controller ) {
362 $controller->register_routes();
363 }
364 }
365 /**
366 * Register Autoloader
367 *
368 * Register function as `__autoload()` implementation.
369 *
370 * @since 0.3
371 * @return void
372 * @access public
373 *
374 */
375 private function register_autoloader() {
376 spl_autoload_register( [ __CLASS__, 'autoload' ] );
377 }
378 /**
379 * Run Autoloader
380 *
381 * Autoloader will add classes
382 *
383 * @param string $class Class name.
384 * @since 0.3
385 * @return void
386 * @access public
387 *
388 */
389 public function autoload( $class ) {
390
391 if ( 0 !== strpos( $class, __NAMESPACE__ ) ) {
392 return;
393 }
394
395 if ( ! class_exists( $class ) ) {
396
397 $filename = strtolower(
398 preg_replace(
399 [ '/^' . __NAMESPACE__ . '\\\/', '/([a-z])([A-Z])/', '/_/', '/\\\/' ],
400 [ '', '$1-$2', '-', DIRECTORY_SEPARATOR ],
401 $class
402 )
403 );
404
405 $filename = WML_PATH . $filename . '.php';
406
407 if ( is_readable( $filename ) ) {
408 include $filename;
409 }
410 }
411 }
412 /**
413 * Add Mail Review Notice
414 *
415 * @since 0.3
416 * @return void
417 * @access public
418 *
419 */
420 public function wpv_mail_review() {
421 if ( isset( $_GET['wml_remind_later'] ) || isset( $_GET['wml_review_done'] ) ) {
422 if ( ! empty( $_GET['wml_nonce'] ) && wp_verify_nonce( $_GET['wml_nonce'], 'wml_rest' ) ) {
423
424 $user = \wp_get_current_user();
425 $roles = (array) $user->roles;
426 if ( $roles[0] !== 'administrator' ) {
427 return;
428 }
429
430 if ( isset( $_GET['wml_remind_later'] ) ) {
431 $this->wml_remind_later();
432 } elseif (
433 isset( $_GET['wml_review_done'] ) ) {
434 $this->wml_review_done();
435 }
436 }
437 }
438 }
439 /**
440 * Set Notice to Remind Later
441 *
442 * @since 0.3
443 * @return void
444 * @access public
445 *
446 */
447 public function wml_remind_later() {
448 set_transient( 'wml_remind_later', 'show again', WEEK_IN_SECONDS );
449 }
450 /**
451 * Set Review Notice to Done
452 *
453 * @since 0.3
454 * @return void
455 * @access public
456 *
457 */
458 public function wml_review_done() {
459 update_option( 'wml_review', 'done', false );
460 }
461
462 /**
463 * Review Notice HTML
464 *
465 * @since 0.3
466 * @return void
467 * @access public
468 *
469 */
470
471 public function wml_review_box() {
472 ?>
473 <div class="wml-review notice notice-success is-dismissible">
474 <div class="wml-logo">
475 <svg viewBox="0 0 831 775" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
476 <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
477 <g id="El-logo-blue" fill-rule="nonzero">
478 <path d="M227.7,160.1 C227.7,155.8 229,151.8 231.3,148.5 C232.4,146.8 233.8,145.3 235.3,144.1 C238.9,141.1 243.5,139.3 248.5,139.3 L582.7,139.3 C587,139.3 591,140.6 594.3,142.9 C596.5,144.4 598.4,146.3 599.9,148.5 C602.1,151.8 603.5,155.8 603.5,160.1 L603.5,394.9 L830.8,257.3 L446.5,10.2 C427.4,-2.1 402.9,-2.1 383.8,10.2 L0.3,257.2 L227.6,394.8 L227.6,160.1 L227.7,160.1 Z" id="Path" fill="#154DAE"></path>
479 <path d="M599.9,148.5 C598.4,146.3 596.5,144.4 594.3,142.9 C591,140.7 587,139.3 582.7,139.3 L248.5,139.3 C243.5,139.3 238.9,141.1 235.3,144.1 C233.8,145.4 232.4,146.9 231.3,148.5 C229.1,151.8 227.7,155.8 227.7,160.1 L227.7,394.8 L283.2,428.4 L329.1,456.2 L382.3,488.4 C402.8,500.8 428.4,500.8 448.8,488.4 L503.7,455.7 L549.5,427.5 L603.4,394.9 L603.4,160.1 C603.5,155.8 602.2,151.8 599.9,148.5 Z M368.5,182.9 L462.7,182.9 C469.5,182.9 475,188.4 475,195.2 C475,202 469.5,207.5 462.7,207.5 L368.5,207.5 C361.7,207.5 356.2,202 356.2,195.2 C356.2,188.4 361.7,182.9 368.5,182.9 Z M495.6,384.8 L335.6,384.8 C328.8,384.8 323.3,379.3 323.3,372.5 C323.3,365.7 328.8,360.2 335.6,360.2 L495.6,360.2 C502.4,360.2 507.9,365.7 507.9,372.5 C507.9,379.3 502.4,384.8 495.6,384.8 Z M342.1,313.4 C342.1,306.6 347.6,301.1 354.4,301.1 L476.6,301.1 C483.4,301.1 488.9,306.6 488.9,313.4 C488.9,320.2 483.4,325.7 476.6,325.7 L354.5,325.7 C347.7,325.7 342.1,320.2 342.1,313.4 Z M515.5,266.6 L315.7,266.6 C308.9,266.6 303.4,261.1 303.4,254.3 C303.4,247.5 308.9,242 315.7,242 L515.5,242 C522.3,242 527.8,247.5 527.8,254.3 C527.8,261.1 522.3,266.6 515.5,266.6 Z" id="Shape" fill="#F2F2F2"></path>
480 <polygon id="Path" fill="#154DAE" points="101.1 694.3 329.1 456.2 283.2 428.4"></polygon>
481 <polygon id="Path" fill="#154DAE" points="732.3 694.3 549.6 427.5 503.8 455.7"></polygon>
482 <path d="M830.8,736.5 L830.8,257.2 L830.8,257.2 L603.5,394.8 L549.6,427.4 L732.4,694.2 L503.8,455.7 L448.9,488.4 C428.4,500.8 402.8,500.8 382.4,488.4 L329.2,456.2 L101.1,694.3 L283.2,428.4 L227.7,394.8 L0.4,257.2 L0.4,707.7 L0.4,736.5 C0.4,757.8 17.7,775 38.9,775 L792.3,775 C813.6,775 830.8,757.8 830.8,736.5 Z" id="Path" fill="#1B5ED7"></path>
483 <path d="M368.5,207.6 L462.7,207.6 C469.5,207.6 475,202.1 475,195.3 C475,188.5 469.5,183 462.7,183 L368.5,183 C361.7,183 356.2,188.5 356.2,195.3 C356.2,202.1 361.7,207.6 368.5,207.6 Z" id="Path" fill="#154DAE"></path>
484 <path d="M515.5,242 L315.7,242 C308.9,242 303.4,247.5 303.4,254.3 C303.4,261.1 308.9,266.6 315.7,266.6 L515.5,266.6 C522.3,266.6 527.8,261.1 527.8,254.3 C527.8,247.5 522.3,242 515.5,242 Z" id="Path" fill="#154DAE"></path>
485 <path d="M476.7,325.7 C483.5,325.7 489,320.2 489,313.4 C489,306.6 483.5,301.1 476.7,301.1 L354.5,301.1 C347.7,301.1 342.2,306.6 342.2,313.4 C342.2,320.2 347.7,325.7 354.5,325.7 L476.7,325.7 Z" id="Path" fill="#154DAE"></path>
486 <path d="M495.6,360.1 L335.6,360.1 C328.8,360.1 323.3,365.6 323.3,372.4 C323.3,379.2 328.8,384.7 335.6,384.7 L495.6,384.7 C502.4,384.7 507.9,379.2 507.9,372.4 C507.9,365.6 502.4,360.1 495.6,360.1 Z" id="Path" fill="#154DAE"></path>
487 </g>
488 </g>
489 </svg>
490 </div>
491 <div class="wml-review-content">
492 <p class="wml-review-desc"><?php echo 'WP Mail Log has already captured 10+ mail log. That’s awesome! Could you please do a BIG favor and give it a 5-star rating on WordPress? <br/> Just to help us spread the word and boost our motivation. <br/><b>~ Anand Upadhyay</b>'; ?></p>
493 <span class="wml-notic-link-wrapper">
494 <a class="wml-notice-link" target="_blank" href="https://wordpress.org/support/plugin/wp-mail-log/reviews/#new-post" class="button button-primary"><span class="dashicons dashicons-heart"></span><?php esc_html_e( 'Ok, you deserve it!', 'wpv-wml' ); ?></a>
495 <a class="wml-notice-link" href="
496 <?php
497 echo esc_html(
498 add_query_arg(
499 [
500 'wml_remind_later' => 'later',
501 'wml_nonce' => wp_create_nonce( 'wml_rest' ),
502 ]
503 )
504 )
505 ?>
506 "><span class="dashicons dashicons-schedule"></span><?php esc_html_e( 'May Be Later', 'wpv-wml' ); ?></a>
507 <a class="wml-notice-link" href="
508 <?php
509 echo esc_html(
510 add_query_arg(
511 [
512 'wml_review_done' => 'done',
513 'wml_nonce' => wp_create_nonce( 'wml_rest' ),
514 ]
515 )
516 );
517 ?>
518 "><span class="dashicons dashicons-smiley"></span><?php esc_html_e( 'Already Done', 'wpv-wml' ); ?></a>
519 </span>
520 </div>
521 </div>
522 <?php
523 }
524 /**
525 * Fire on Plugin Activation Hook
526 *
527 * Write the function which will fire on plugin Activate.
528 *
529 * @since 0.3
530 * @return void
531 * @access public
532 *
533 */
534 public function wml_activate() {
535 // wp_schedule_event( time(), 'daily', 'wpv/wml/delete_logs' );
536 }
537 /**
538 * Delete Logs Automatically
539 *
540 * This function fire on wp_schedule_event.
541 *
542 * @since 0.3
543 * @return void
544 * @access public
545 *
546 */
547 public function wml_delete_entry() {
548 global $wpdb;
549
550 $settings = get_option( 'wpv_wml_settings' );
551 $isDelete = $settings['deleteLogs'];
552 $days = $settings['deleteDays'];
553
554 if ( ! $isDelete ) {
555 return;
556 }
557
558 $date = date( 'Y-m-d', strtotime( '-' . $days . ' days' ) );
559
560 $table_name = $wpdb->prefix . 'wml_entries';
561
562 $query = $wpdb->prepare( "DELETE FROM {$table_name} WHERE DATE_FORMAT(captured_gmt,GET_FORMAT(DATE,'JIS')) <= %s", $date );
563
564 $dl1 = $wpdb->query( $query );
565
566 if ( $dl1 === 0 ) {
567 if ( defined( 'WP_DEBUG' ) && WP_DEBUG === true ) {
568 error_log( print_r( 'No rows deleted...!!!', true ) );
569 }
570 } else {
571 if ( defined( 'WP_DEBUG' ) && WP_DEBUG === true ) {
572 error_log( print_r( 'Row Deleted...!!!', true ) );
573 }
574 }
575 }
576
577 /**
578 * Fire on Plugin Deactivation hook
579 *
580 * Write the function which will fire on plugin deactivate.
581 *
582 * @since 0.3
583 * @return void
584 * @access public
585 *
586 */
587
588 public function wml_deactivate() {
589 wp_clear_scheduled_hook( 'wpv/wml/delete_logs' );
590 }
591
592
593 /**
594 * Update Admin Footer Text
595 *
596 * @since 0.3
597 * @param string $footer_text Footer Text
598 * @return string updated $footer_text
599 * @access public
600 *
601 */
602
603 public function admin_footer_text( $footer_text ) {
604 $screen = get_current_screen();
605 // Todo:: Show on plugin screens
606 $wml_screens = [
607 'toplevel_page_wp-mail-log',
608 'wp-mail-log_page_wpv-wpml-settings',
609 ];
610
611 if ( in_array( $screen->id, $wml_screens, true ) ) {
612 $footer_text = sprintf(
613 /* translators: 1: WP Mail Log, 2: Link to plugin review */
614 __( 'Enjoyed %1$s? Please leave us a %2$s rating. We really appreciate your support!', 'wpv-wml' ),
615 '<strong>' . __( 'WP Mail Log', 'wpv-wml' ) . '</strong>',
616 '<a href="https://wordpress.org/support/plugin/wp-mail-log/reviews/#new-post" target="_blank">&#9733;&#9733;&#9733;&#9733;&#9733;</a>'
617 );
618 }
619
620 return $footer_text;
621 }
622
623 }
624
625 WP_MAIL_LOG::get_instance();
626