PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.5.1
JetFormBuilder — Dynamic Blocks Form Builder v3.6.5.1
3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / vendor / woocommerce / action-scheduler / classes / ActionScheduler_WPCommentCleaner.php
jetformbuilder / vendor / woocommerce / action-scheduler / classes Last commit date
WP_CLI 2 months ago abstracts 2 months ago actions 1 year ago data-stores 2 months ago migration 1 year ago schedules 1 year ago schema 2 months ago ActionScheduler_ActionClaim.php 1 year ago ActionScheduler_ActionFactory.php 1 year ago ActionScheduler_AdminView.php 1 year ago ActionScheduler_AsyncRequest_QueueRunner.php 1 year ago ActionScheduler_Compatibility.php 1 year ago ActionScheduler_DataController.php 2 months ago ActionScheduler_DateTime.php 1 year ago ActionScheduler_Exception.php 2 years ago ActionScheduler_FatalErrorMonitor.php 1 year ago ActionScheduler_InvalidActionException.php 1 year ago ActionScheduler_ListTable.php 1 year ago ActionScheduler_LogEntry.php 1 year ago ActionScheduler_NullLogEntry.php 1 year ago ActionScheduler_OptionLock.php 1 year ago ActionScheduler_QueueCleaner.php 1 year ago ActionScheduler_QueueRunner.php 1 year ago ActionScheduler_RecurringActionScheduler.php 2 months ago ActionScheduler_SystemInformation.php 1 year ago ActionScheduler_Versions.php 1 year ago ActionScheduler_WPCommentCleaner.php 1 year ago ActionScheduler_wcSystemStatus.php 2 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