PluginProbe ʕ •ᴥ•ʔ
Hostinger Reach – AI-Powered Email Marketing for WordPress / 1.7.0
Hostinger Reach – AI-Powered Email Marketing for WordPress v1.7.0
1.7.2 1.7.1 1.7.0 1.6.0 1.5.9 1.5.8 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 1.5.2 1.5.1 1.5.0 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 trunk 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 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.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6
hostinger-reach / vendor / woocommerce / action-scheduler / classes / ActionScheduler_WPCommentCleaner.php
hostinger-reach / vendor / woocommerce / action-scheduler / classes Last commit date
WP_CLI 10 months ago abstracts 10 months ago actions 10 months ago data-stores 10 months ago migration 10 months ago schedules 10 months ago schema 10 months ago ActionScheduler_ActionClaim.php 10 months ago ActionScheduler_ActionFactory.php 10 months ago ActionScheduler_AdminView.php 10 months ago ActionScheduler_AsyncRequest_QueueRunner.php 10 months ago ActionScheduler_Compatibility.php 10 months ago ActionScheduler_DataController.php 10 months ago ActionScheduler_DateTime.php 10 months ago ActionScheduler_Exception.php 10 months ago ActionScheduler_FatalErrorMonitor.php 10 months ago ActionScheduler_InvalidActionException.php 10 months ago ActionScheduler_ListTable.php 10 months ago ActionScheduler_LogEntry.php 10 months ago ActionScheduler_NullLogEntry.php 10 months ago ActionScheduler_OptionLock.php 10 months ago ActionScheduler_QueueCleaner.php 10 months ago ActionScheduler_QueueRunner.php 10 months ago ActionScheduler_RecurringActionScheduler.php 10 months ago ActionScheduler_SystemInformation.php 10 months ago ActionScheduler_Versions.php 10 months ago ActionScheduler_WPCommentCleaner.php 10 months ago ActionScheduler_wcSystemStatus.php 10 months ago
ActionScheduler_WPCommentCleaner.php
134 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 $has_logs = 'no';
70
71 $args = array(
72 'type' => ActionScheduler_wpCommentLogger::TYPE,
73 'number' => 1,
74 'fields' => 'ids',
75 );
76
77 if ( (bool) get_comments( $args ) ) {
78 $has_logs = 'yes';
79
80 if ( ! as_next_scheduled_action( self::$cleanup_hook ) ) {
81 as_schedule_single_action( gmdate( 'U' ) + ( 6 * MONTH_IN_SECONDS ), self::$cleanup_hook );
82 }
83 }
84
85 update_option( self::$has_logs_option_key, $has_logs, true );
86 }
87
88 /**
89 * Delete all action comments from the WP Comments table.
90 */
91 public static function delete_all_action_comments() {
92 global $wpdb;
93
94 $wpdb->delete(
95 $wpdb->comments,
96 array(
97 'comment_type' => ActionScheduler_wpCommentLogger::TYPE,
98 'comment_agent' => ActionScheduler_wpCommentLogger::AGENT,
99 )
100 );
101
102 update_option( self::$has_logs_option_key, 'no', true );
103 }
104
105 /**
106 * Registers admin notices about the orphaned action logs.
107 */
108 public static function register_admin_notice() {
109 add_action( 'admin_notices', array( __CLASS__, 'print_admin_notice' ) );
110 }
111
112 /**
113 * Prints details about the orphaned action logs and includes information on where to learn more.
114 */
115 public static function print_admin_notice() {
116 $next_cleanup_message = '';
117 $next_scheduled_cleanup_hook = as_next_scheduled_action( self::$cleanup_hook );
118
119 if ( $next_scheduled_cleanup_hook ) {
120 /* translators: %s: date interval */
121 $next_cleanup_message = sprintf( __( 'This data will be deleted in %s.', 'action-scheduler' ), human_time_diff( gmdate( 'U' ), $next_scheduled_cleanup_hook ) );
122 }
123
124 $notice = sprintf(
125 /* translators: 1: next cleanup message 2: github issue URL */
126 __( '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' ),
127 $next_cleanup_message,
128 'https://github.com/woocommerce/action-scheduler/issues/368'
129 );
130
131 echo '<div class="notice notice-warning"><p>' . wp_kses_post( $notice ) . '</p></div>';
132 }
133 }
134