PluginProbe ʕ •ᴥ•ʔ
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin / 2.1.1
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin v2.1.1
4.9.0 0.9.6 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.6.0 1.6.2 1.7.0 1.7.1 1.8.0 1.8.1 1.9.0 2.0.0 2.0.1 2.1.1 2.2.1 2.3.1 2.4.0 2.5.0 2.5.1 2.6.0 2.7.0 2.8.0 2.9.0 3.0.1 3.0.2 3.0.3 3.1.0 3.10.0 3.11.0 3.11.1 3.2.0 3.2.1 3.3.0 3.4.0 3.5.0 3.5.1 3.5.2 3.6.1 3.7.0 3.8.0 3.8.2 3.9.0 4.0.1 4.1.0 4.1.1 4.2.0 4.3.0 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.8.0 trunk 0.10.0 0.10.1 0.11.1 0.11.2 0.3.1 0.3.2 0.4 0.4.1 0.4.2 0.5.0 0.5.1 0.5.2 0.6 0.7 0.8 0.8.2 0.8.3 0.8.4 0.8.5 0.8.6 0.8.7 0.9.0 0.9.1 0.9.2 0.9.3 0.9.4 0.9.5
wp-mail-smtp / vendor / woocommerce / action-scheduler / classes / ActionScheduler_WPCommentCleaner.php
wp-mail-smtp / vendor / woocommerce / action-scheduler / classes Last commit date
WP_CLI 6 years ago abstracts 6 years ago actions 6 years ago data-stores 6 years ago migration 6 years ago schedules 6 years ago schema 6 years ago ActionScheduler_ActionClaim.php 6 years ago ActionScheduler_ActionFactory.php 6 years ago ActionScheduler_AdminView.php 6 years ago ActionScheduler_AsyncRequest_QueueRunner.php 6 years ago ActionScheduler_Compatibility.php 6 years ago ActionScheduler_DataController.php 6 years ago ActionScheduler_DateTime.php 6 years ago ActionScheduler_Exception.php 6 years ago ActionScheduler_FatalErrorMonitor.php 6 years ago ActionScheduler_InvalidActionException.php 6 years ago ActionScheduler_ListTable.php 6 years ago ActionScheduler_LogEntry.php 6 years ago ActionScheduler_NullLogEntry.php 6 years ago ActionScheduler_OptionLock.php 6 years ago ActionScheduler_QueueCleaner.php 6 years ago ActionScheduler_QueueRunner.php 6 years ago ActionScheduler_Versions.php 6 years ago ActionScheduler_WPCommentCleaner.php 6 years ago ActionScheduler_wcSystemStatus.php 6 years ago
ActionScheduler_WPCommentCleaner.php
116 lines
1 <?php
2
3 /**
4 * Class ActionScheduler_WPCommentCleaner
5 *
6 * @since 3.0.0
7 */
8 class ActionScheduler_WPCommentCleaner {
9
10 /**
11 * Post migration hook used to cleanup the WP comment table.
12 *
13 * @var string
14 */
15 protected static $cleanup_hook = 'action_scheduler/cleanup_wp_comment_logs';
16
17 /**
18 * An instance of the ActionScheduler_wpCommentLogger class to interact with the comments table.
19 *
20 * This instance should only be used as an interface. It should not be initialized.
21 *
22 * @var ActionScheduler_wpCommentLogger
23 */
24 protected static $wp_comment_logger = null;
25
26 /**
27 * The key used to store the cached value of whether there are logs in the WP comment table.
28 *
29 * @var string
30 */
31 protected static $has_logs_option_key = 'as_has_wp_comment_logs';
32
33 /**
34 * Initialize the class and attach callbacks.
35 */
36 public static function init() {
37 if ( empty( self::$wp_comment_logger ) ) {
38 self::$wp_comment_logger = new ActionScheduler_wpCommentLogger();
39 }
40
41 add_action( self::$cleanup_hook, array( __CLASS__, 'delete_all_action_comments' ) );
42
43 // While there are orphaned logs left in the comments table, we need to attach the callbacks which filter comment counts.
44 add_action( 'pre_get_comments', array( self::$wp_comment_logger, 'filter_comment_queries' ), 10, 1 );
45 add_action( 'wp_count_comments', array( self::$wp_comment_logger, 'filter_comment_count' ), 20, 2 ); // run after WC_Comments::wp_count_comments() to make sure we exclude order notes and action logs
46 add_action( 'comment_feed_where', array( self::$wp_comment_logger, 'filter_comment_feed' ), 10, 2 );
47
48 // Action Scheduler may be displayed as a Tools screen or WooCommerce > Status administration screen
49 add_action( 'load-tools_page_action-scheduler', array( __CLASS__, 'register_admin_notice' ) );
50 add_action( 'load-woocommerce_page_wc-status', array( __CLASS__, 'register_admin_notice' ) );
51 }
52
53 /**
54 * Determines if there are log entries in the wp comments table.
55 *
56 * Uses the flag set on migration completion set by @see self::maybe_schedule_cleanup().
57 *
58 * @return boolean Whether there are scheduled action comments in the comments table.
59 */
60 public static function has_logs() {
61 return 'yes' === get_option( self::$has_logs_option_key );
62 }
63
64 /**
65 * Schedules the WP Post comment table cleanup to run in 6 months if it's not already scheduled.
66 * Attached to the migration complete hook 'action_scheduler/migration_complete'.
67 */
68 public static function maybe_schedule_cleanup() {
69 if ( (bool) get_comments( array( 'type' => ActionScheduler_wpCommentLogger::TYPE, 'number' => 1, 'fields' => 'ids' ) ) ) {
70 update_option( self::$has_logs_option_key, 'yes' );
71
72 if ( ! as_next_scheduled_action( self::$cleanup_hook ) ) {
73 as_schedule_single_action( gmdate( 'U' ) + ( 6 * MONTH_IN_SECONDS ), self::$cleanup_hook );
74 }
75 }
76 }
77
78 /**
79 * Delete all action comments from the WP Comments table.
80 */
81 public static function delete_all_action_comments() {
82 global $wpdb;
83 $wpdb->delete( $wpdb->comments, array( 'comment_type' => ActionScheduler_wpCommentLogger::TYPE, 'comment_agent' => ActionScheduler_wpCommentLogger::AGENT ) );
84 delete_option( self::$has_logs_option_key );
85 }
86
87 /**
88 * Registers admin notices about the orphaned action logs.
89 */
90 public static function register_admin_notice() {
91 add_action( 'admin_notices', array( __CLASS__, 'print_admin_notice' ) );
92 }
93
94 /**
95 * Prints details about the orphaned action logs and includes information on where to learn more.
96 */
97 public static function print_admin_notice() {
98 $next_cleanup_message = '';
99 $next_scheduled_cleanup_hook = as_next_scheduled_action( self::$cleanup_hook );
100
101 if ( $next_scheduled_cleanup_hook ) {
102 /* translators: %s: date interval */
103 $next_cleanup_message = sprintf( __( 'This data will be deleted in %s.', 'action-scheduler' ), human_time_diff( gmdate( 'U' ), $next_scheduled_cleanup_hook ) );
104 }
105
106 $notice = sprintf(
107 /* translators: 1: next cleanup message 2: github issue URL */
108 __( 'Action Scheduler has migrated data to custom tables; however, orphaned log entries exist in the WordPress Comments table. %1$s <a href="%2$s">Learn more &raquo;</a>', 'action-scheduler' ),
109 $next_cleanup_message,
110 'https://github.com/woocommerce/action-scheduler/issues/368'
111 );
112
113 echo '<div class="notice notice-warning"><p>' . wp_kses_post( $notice ) . '</p></div>';
114 }
115 }
116