芝麻web文件管理V1.00
编辑当前文件:/var/www/cognitio.in/wp-content/plugins/the-events-calendar/src/Tribe/Event_Cleaner_Scheduler.php
trash_new_date = $move_to_trash; $this->del_new_date = $permanently_delete; } /** * Receives the new user-defined value for $key_trash_events option * and defines it as the trash_new_date variable. * * @param mixed $trash_new_value - the value for the $key_trash_events option * * @since 4.6.13 */ public function set_trash_new_date( $trash_new_value ) { $this->trash_new_date = $trash_new_value; } /** * Receives the new user-defined value for $key_delete_events option * and defines it as the del_new_date variable. * * @param mixed $del_new_value - the value for the $key_delete_events option * * @since 4.6.13 */ public function set_delete_new_date( $del_new_value ) { $this->del_new_date = $del_new_value; } /** * Schedules the hooks to delete and move old events to trash * These hooks will be executed daily. * * @since 4.6.13 */ public function add_hooks() { if ( ! wp_next_scheduled( self::$trash_cron_hook ) && $this->trash_new_date != null ) { wp_schedule_event( time(), 'daily', self::$trash_cron_hook ); } if ( ! wp_next_scheduled( self::$del_cron_hook ) && $this->del_new_date != null ) { wp_schedule_event( time(), 'daily', self::$del_cron_hook ); } if ( null != $this->trash_new_date ) { add_action( self::$trash_cron_hook, [ $this, 'move_old_events_to_trash' ], 10, 0 ); } if ( null != $this->del_new_date ) { add_action( self::$del_cron_hook, [ $this, 'permanently_delete_old_events' ], 10, 0 ); } add_action( 'tribe_events_blog_deactivate', [ $this, 'trash_clear_scheduled_task' ] ); add_action( 'tribe_events_blog_deactivate', [ $this, 'delete_clear_scheduled_task' ] ); } /** * Removes the hooks * * @since 4.6.13 */ public function remove_hooks() { remove_action( self::$trash_cron_hook, [ $this, 'move_old_events_to_trash' ] ); remove_action( self::$del_cron_hook, [ $this, 'permanently_delete_old_events' ] ); } /** * Un-schedules all previously-scheduled cron jobs for tribe_trash_event_cron * * @since 4.6.13 */ public function trash_clear_scheduled_task() { wp_clear_scheduled_hook( self::$trash_cron_hook ); } /** * Un-schedules all previously-scheduled cron jobs for tribe_del_event_cron * * @since 4.6.13 */ public function delete_clear_scheduled_task() { wp_clear_scheduled_hook( self::$del_cron_hook ); } /** * Selects events to be moved to trash or permanently deleted. * * @since 4.6.13 * * @param int $month - The value chosen by user to purge all events older than x months * * @return array $post_ids - an array of event Post_IDs with the Event End Date older than $month */ public function select_events_to_purge( $month ) { /** @var wpdb $wpdb */ global $wpdb; $event_post_type = Tribe__Events__Main::POSTTYPE; $posts_with_parents_sql = " SELECT DISTINCT post_parent FROM {$wpdb->posts} WHERE post_type= '$event_post_type' AND post_parent <> 0 "; $sql = " SELECT post_id FROM {$wpdb->posts} AS t1 INNER JOIN {$wpdb->postmeta} AS t2 ON t1.ID = t2.post_id WHERE t1.post_type = %s AND t2.meta_key = '_EventEndDate' AND t2.meta_value <= DATE_SUB( CURDATE(), INTERVAL %d MONTH ) AND t2.meta_value != 0 AND t2.meta_value != '' AND t2.meta_value IS NOT NULL AND t1.post_parent = 0 AND t1.ID NOT IN ( $posts_with_parents_sql ) "; /** * Filter - Allows users to manipulate the cleanup query * * @param string $sql - The query statement * * @since 4.6.13 */ $sql = apply_filters( 'tribe_events_delete_old_events_sql', $sql ); $args = [ 'post_type' => $event_post_type, 'date' => $month, ]; /** * Filter - Allows users to modify the query's placeholders * * @param array $args - The array of variables * * @since 4.6.13 */ $args = apply_filters( 'tribe_events_delete_old_events_sql_args', $args ); /** * Returns an array of Post IDs (events) that ended before a specific date */ $post_ids = $wpdb->get_col( $wpdb->prepare( $sql, $args ) ); return $post_ids; } /** * Moves to trash events that ended before a date specified by user * * @since 4.6.13 * @since TBD Added a return value. * * @return mixed */ public function move_old_events_to_trash() { $month = $this->trash_new_date; $post_ids = $this->select_events_to_purge( $month ); if ( empty( $post_ids ) ) { return; } foreach ( $post_ids as $post_id ) { wp_trash_post( $post_id ); } } /** * Permanently deletes events that ended before a date specified by user * * @since 4.6.13 * * @return mixed - The post object (if it was deleted successfully) or false (failure) */ public function permanently_delete_old_events() { $month = $this->del_new_date; $post_ids = $this->select_events_to_purge( $month ); if ( empty( $post_ids ) ) { return; } foreach ( $post_ids as $post_id ) { wp_delete_post( $post_id, true ); } } }