Changeset 3826997
- Timestamp:
- 11/26/2026 12:58:08 PM (less than one hour ago)
- Location:
- tidy-media/trunk
- Files:
-
- 9 edited
-
assets/js/admin.js (modified) (6 diffs)
-
includes/class-tidy-media-admin.php (modified) (3 diffs)
-
includes/class-tidy-media-ajax.php (modified) (3 diffs)
-
includes/class-tidy-media-custom-fields-support.php (modified) (3 diffs)
-
includes/class-tidy-media-page-builder-support.php (modified) (7 diffs)
-
includes/class-tidy-media-scanner.php (modified) (11 diffs)
-
readme.txt (modified) (3 diffs)
-
tidy-media.php (modified) (8 diffs)
-
uninstall.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
tidy-media/trunk/assets/js/admin.js
r3744142 r3826997 2630 2630 this.collapseSetup(); 2631 2631 $('#tidymedia-needs-rescan').remove(); 2632 tidyMedia.resultsStale = false; 2632 2633 2633 2634 this.showThemeFilesNotice(state); … … 3217 3218 3218 3219 /** 3220 * Results of a scan made before the plugin was updated are not acted 3221 * on (the server refuses them with rescan_required): say so before any 3222 * dialog. A scan that completes on this page clears the flag. 3223 */ 3224 refuseStaleResults: function() { 3225 if (!tidyMedia.resultsStale) { 3226 return false; 3227 } 3228 this.showAlert( 3229 tidyMedia.strings.rescanRequiredTitle || 'Run a new scan first', 3230 tidyMedia.strings.rescanRequired || 'These results come from a scan made before Tidy Media was updated. Run a new scan before moving or deleting files.' 3231 ); 3232 return true; 3233 }, 3234 3235 /** 3219 3236 * Quarantine selected files. 3220 3237 */ 3221 3238 quarantineSelected: function(e) { 3222 3239 e.preventDefault(); 3240 3241 if (this.refuseStaleResults()) { 3242 return; 3243 } 3223 3244 3224 3245 var $checked = $('.tidymedia-file-checkbox:checked'); … … 3355 3376 e.preventDefault(); 3356 3377 3378 if (this.refuseStaleResults()) { 3379 return; 3380 } 3381 3357 3382 var self = this; 3358 3383 var isReview = this.currentRisk === 'review'; … … 3443 3468 e.preventDefault(); 3444 3469 3470 if (this.refuseStaleResults()) { 3471 return; 3472 } 3473 3445 3474 var $button = $(e.currentTarget); 3446 3475 var $item = $button.closest('.tidymedia-file-item'); … … 3509 3538 deleteEntry: function(e) { 3510 3539 e.preventDefault(); 3540 3541 if (this.refuseStaleResults()) { 3542 return; 3543 } 3511 3544 3512 3545 var $button = $(e.currentTarget); … … 5557 5590 code_id: tidyMedia.strings.classCodeId || 'Used in code', 5558 5591 soft_refs: tidyMedia.strings.classSoftRefs || 'Only in revisions or trash', 5592 edit_root: tidyMedia.strings.classEditRoot || 'Original of an edited image', 5559 5593 'protected': tidyMedia.strings.classProtected || 'Protected ID' 5560 5594 }; -
tidy-media/trunk/includes/class-tidy-media-admin.php
r3744142 r3826997 112 112 'batchSizeMin' => Tidy_Media_Scanner::BATCH_SIZE_MIN, 113 113 'scanIsIncomplete' => $scan_is_incomplete, 114 'resultsStale' => $scanner->has_stale_results(), 114 115 'scannerUrl' => admin_url( 'upload.php?page=tidy-media&tab=scanner' ), 115 116 'quarantineUrl' => admin_url( 'upload.php?page=tidy-media&tab=quarantine' ), 116 117 'probesPerClick' => Tidy_Media_Http_Checks::PROBES_PER_CLICK, 117 118 'strings' => array( 119 'rescanRequiredTitle' => __( 'Run a new scan first', 'tidy-media' ), 120 'rescanRequired' => __( 'These results come from a scan made before Tidy Media was updated, and the update looks for media in more places. Run a new scan before moving or deleting files.', 'tidy-media' ), 118 121 'scanning' => __( 'Scanning...', 'tidy-media' ), 119 122 'scanComplete' => __( 'Scan complete!', 'tidy-media' ), … … 386 389 'classCodeId' => __( 'Used in code', 'tidy-media' ), 387 390 'classSoftRefs' => __( 'Only in revisions or trash', 'tidy-media' ), 391 'classEditRoot' => __( 'Original of an edited image', 'tidy-media' ), 388 392 'classProtected' => __( 'Protected ID', 'tidy-media' ), 389 393 // Where is this used? … … 911 915 </div> 912 916 913 <?php if ( get_option( 'tidy_media_needs_rescan') ) : ?>917 <?php if ( tidy_media()->scanner->has_stale_results() ) : ?> 914 918 <div id="tidymedia-needs-rescan" class="notice notice-warning inline tidymedia-needs-rescan"> 915 <p><?php esc_html_e( 'Tidy Media was updated. Run a new scan to rebuild the results with the new safety classes.', 'tidy-media' ); ?></p> 919 <p><?php esc_html_e( 'Tidy Media was updated and now looks for media in more places. The results below come from a scan made before the update and may list files that are in use, so they cannot be moved to quarantine. Run a new scan before removing any files.', 'tidy-media' ); ?></p> 920 </div> 921 <?php elseif ( get_option( 'tidy_media_needs_rescan' ) ) : ?> 922 <div id="tidymedia-needs-rescan" class="notice notice-warning inline tidymedia-needs-rescan"> 923 <p><?php esc_html_e( 'Tidy Media was updated and now looks for media in more places. Run a new scan before removing any files.', 'tidy-media' ); ?></p> 916 924 </div> 917 925 <?php endif; ?> -
tidy-media/trunk/includes/class-tidy-media-ajax.php
r3744142 r3826997 629 629 $reply['fs_skipped_notice'] = $scanner->has_completed_scan() ? $scanner->get_fs_skipped_notice() : ''; 630 630 $reply['needs_rescan'] = (bool) get_option( 'tidy_media_needs_rescan' ) && ! $scanner->has_completed_scan(); 631 $reply['results_stale'] = $scanner->has_stale_results(); 631 632 632 633 // A stale scan is offered as paused so it can be resumed. … … 1538 1539 * Sends a 409 scan_incomplete reply when no scan has completed since the 1539 1540 * results were last cleared (a scan is running, was cancelled, or the 1540 * plugin was just updated). 1541 * plugin was just updated), and a 409 rescan_required reply when the 1542 * results were made by an older release that read fewer places (1.1.1). 1541 1543 * 1542 1544 * @since 1.1.0 … … 1548 1550 if ( '' === $scan_id || ! tidy_media()->scanner->has_completed_scan() ) { 1549 1551 $this->send_action_error( 'scan_incomplete', __( 'Run a scan to completion before quarantining.', 'tidy-media' ), 409 ); 1552 return ''; 1553 } 1554 1555 if ( tidy_media()->scanner->has_stale_results() ) { 1556 $this->send_action_error( 'rescan_required', __( 'These results come from a scan made before Tidy Media was updated, and the update looks for media in more places. Run a new scan before moving or deleting files.', 'tidy-media' ), 409 ); 1550 1557 return ''; 1551 1558 } -
tidy-media/trunk/includes/class-tidy-media-custom-fields-support.php
r3744142 r3826997 104 104 'time_picker', 105 105 'color_picker', 106 'icon_picker',107 106 'message', 108 107 'accordion', … … 140 139 'video', 141 140 'background', 141 // Older type names Meta Box still accepts in code. 142 'media', 143 'plupload_image', 142 144 ); 143 145 … … 1183 1185 1184 1186 if ( 'gallery' === $field_type ) { 1185 // Gallery: comma-separated IDs or serialized array. 1186 if ( is_array( $unserialized ) ) { 1187 foreach ( $unserialized as $id ) { 1188 if ( is_numeric( $id ) && (int) $id > 0 ) { 1189 $used_media[ (int) $id ] = true; 1190 } 1191 } 1192 } elseif ( is_string( $value ) && strpos( $value, ',' ) !== false ) { 1193 $ids = explode( ',', $value ); 1194 foreach ( $ids as $id ) { 1195 $id = (int) trim( $id ); 1196 if ( $id > 0 ) { 1197 $used_media[ $id ] = true; 1198 } 1199 } 1187 // Gallery: one ID, comma-separated IDs, a list of IDs, or a list 1188 // of array( 'id' => ID, 'url' => URL ) items. 1189 foreach ( Tidy_Media_Id_Keys::extract_ids( $unserialized, 'all' ) as $id ) { 1190 $used_media[ (int) $id ] = true; 1200 1191 } 1201 1192 } elseif ( is_numeric( $unserialized ) && (int) $unserialized > 0 ) { -
tidy-media/trunk/includes/class-tidy-media-page-builder-support.php
r3744142 r3826997 40 40 'wpbakery' => 1, 41 41 'bricks' => 2, 42 'siteorigin' => 3,43 'brizy' => 2,42 'siteorigin' => 4, 43 'brizy' => 3, 44 44 ); 45 45 … … 239 239 240 240 case 'elementor:2': 241 // Page and Site Settings, and the global classes of Elementor 4 242 // (e_global_class posts and the kit), JSON or serialized. 241 // Page and Site Settings, the global classes of Elementor 4 242 // (e_global_class posts and the kit), the Default Styles of 243 // Elementor 4.3 (e_default_style posts) and the element defaults 244 // saved with "Save as default" (kit), JSON or serialized. 243 245 $kind = 'elementor_settings'; 244 246 $rows = $wpdb->get_results( … … 246 248 "SELECT pm.meta_id AS id, pm.meta_value AS value FROM {$wpdb->postmeta} pm 247 249 INNER JOIN {$wpdb->posts} p ON pm.post_id = p.ID 248 WHERE pm.meta_key IN ('_elementor_page_settings', '_elementor_global_class_data', '_elementor_global_class_data_preview', '_elementor_global_classes', '_elementor_global_classes_preview' )250 WHERE pm.meta_key IN ('_elementor_page_settings', '_elementor_global_class_data', '_elementor_global_class_data_preview', '_elementor_global_classes', '_elementor_global_classes_preview', '_elementor_default_style_data', '_elementor_elements_default_values') 249 251 AND pm.meta_value != '' 250 252 AND p.post_type <> 'revision' … … 500 502 } 501 503 504 $cursor['sub'] = 3; 505 $cursor['after'] = 0; 506 return array( $used_media, $cursor, $page ); 507 508 case 'siteorigin:3': 509 // Widgets Bundle blocks and Layout Blocks placed in block widget 510 // areas (Appearance > Widgets, Customizer): the option 511 // widget_block, one entry per widget with its markup in 512 // 'content'. Saved there, a block keeps its media as IDs in 513 // widgetData or panelsData only. 514 $block_widgets = get_option( 'widget_block', array() ); 515 if ( is_array( $block_widgets ) ) { 516 foreach ( $block_widgets as $block_widget ) { 517 if ( ! is_array( $block_widget ) || ! isset( $block_widget['content'] ) || ! is_string( $block_widget['content'] ) ) { 518 continue; 519 } 520 if ( false === strpos( $block_widget['content'], 'wp:sowb/' ) && false === strpos( $block_widget['content'], 'wp:siteorigin-panels/' ) ) { 521 continue; 522 } 523 524 $used_media = $this->extract_siteorigin_content_media( $block_widget['content'], $used_media ); 525 } 526 } 527 528 $lookup_error = Tidy_Media_Content_Parser::take_query_error(); 529 if ( '' !== $lookup_error ) { 530 $page['error'] = $lookup_error; 531 return array( $used_media, $cursor, $page ); 532 } 533 502 534 return array( $used_media, null, $page ); 503 535 … … 540 572 } 541 573 542 return array( $used_media, null, $page ); 574 $cursor['sub'] = 2; 575 $cursor['after'] = 0; 576 return array( $used_media, $cursor, $page ); 577 578 case 'brizy:2': 579 // Uploaded fonts: each font is a brizy-font post and its files 580 // are media items attached to it (post_parent). Nothing stores 581 // their ID or URL; Brizy finds them by their parent. 582 $kind = 'brizy_font'; 583 $rows = $wpdb->get_results( 584 $wpdb->prepare( 585 "SELECT a.ID AS id, a.ID AS value FROM {$wpdb->posts} a 586 INNER JOIN {$wpdb->posts} f ON a.post_parent = f.ID 587 WHERE a.post_type = 'attachment' 588 AND f.post_type = 'brizy-font' 589 AND f.post_status NOT IN ('trash', 'auto-draft') 590 AND a.ID > %d 591 ORDER BY a.ID ASC 592 LIMIT %d", 593 $after, 594 $limit 595 ) 596 ); 597 break; 543 598 544 599 default: … … 667 722 * @param string $kind Builder key (see SUB_STEPS), or the kind of row 668 723 * a builder's query reads ('elementor_settings', 669 * 'divi5', 'siteorigin_data', 'siteorigin_content'). 724 * 'divi5', 'siteorigin_data', 'siteorigin_content', 725 * 'brizy_font': the value is a media item ID). 670 726 * @param string $value Meta value or post content. 671 727 * @param array $used_media Current used media array. … … 692 748 case 'brizy': 693 749 return $this->extract_brizy_media( $value, $used_media ); 750 case 'brizy_font': 751 if ( (int) $value > 0 ) { 752 $used_media[ (int) $value ] = true; 753 } 754 return $used_media; 694 755 } 695 756 -
tidy-media/trunk/includes/class-tidy-media-scanner.php
r3744142 r3826997 287 287 * Version of the scan state layout. A saved scan with an older version 288 288 * was started by an older plugin version and cannot give complete results. 289 * 4 (1.1.1): steps that a scan started by 1.1.0 may already have passed 290 * read more places (siteorigin:3, brizy:2, Elementor and custom field 291 * keys), so such a scan is not resumed. 289 292 * 290 293 * @var int 291 294 */ 292 const STATE_VERSION = 3;295 const STATE_VERSION = 4; 293 296 294 297 /** … … 448 451 'code_id' => 'review', 449 452 'soft_refs' => 'review', 453 'edit_root' => 'review', 450 454 'protected' => 'keep', 451 455 ); … … 1646 1650 } 1647 1651 1652 // Originals of edited images whose edited copy is in use. 1653 $edit_copies = $this->get_used_edit_copies( $unused_ids ); 1654 if ( null === $edit_copies ) { 1655 return $this->finish_batch( $this->db_failure( $state, 'db_query_failed', $this->query_error ), $batch_start ); 1656 } 1657 1648 1658 // The files they own: shared with another item, or linked from content. 1649 1659 $owned_checks = $this->check_owned_files( $unused_ids ); … … 1703 1713 1704 1714 if ( ! $this->is_media_used( $attachment->ID ) ) { 1705 $row = $this->classify_attachment( $attachment, $file_users, $owned_checks, $evidence );1715 $row = $this->classify_attachment( $attachment, $file_users, $owned_checks, $evidence, $edit_copies ); 1706 1716 $item_bytes = (int) $row['total_size'] > 0 ? (int) $row['total_size'] : (int) $row['file_size']; 1707 1717 … … 5956 5966 /* translators: %s: where the media item was found, e.g. 'a revision of "About us" (#12)' */ 5957 5967 return sprintf( __( 'Only found in %s. Revisions, the trash and unsaved drafts are not shown on the site, but restoring that content would show a missing file.', 'tidy-media' ), $value ); 5968 case 'edit_root': 5969 /* translators: %d: media item ID */ 5970 return sprintf( __( 'Original of the edited image #%d, which is in use. The image editor needs this file for "Restore original image".', 'tidy-media' ), (int) $value ); 5958 5971 case 'protected': 5959 5972 return __( 'In your Protected media IDs list (Settings). Never offered.', 'tidy-media' ); … … 6020 6033 'code_id' => __( 'Used in code', 'tidy-media' ), 6021 6034 'soft_refs' => __( 'Only in revisions or trash', 'tidy-media' ), 6035 'edit_root' => __( 'Original of an edited image', 'tidy-media' ), 6022 6036 'protected' => __( 'Protected ID', 'tidy-media' ), 6023 6037 ); … … 6884 6898 * 6885 6899 * A Protected media ID is kept whatever else is found. An unused item 6886 * whose ID is in code, or that only old content references, is Review. 6900 * whose ID is in code, that only old content references, or whose edited 6901 * copy is in use, is Review. 6887 6902 * 6888 6903 * @since 1.1.0 … … 6891 6906 * @param array $owned_checks Result of check_owned_files(). 6892 6907 * @param array $evidence Result of Tidy_Media_Evidence::get(). 6908 * @param array $edit_copies Result of get_used_edit_copies(). 6893 6909 * @return array Row without scan_id. 6894 6910 */ 6895 private function classify_attachment( $attachment, $file_users, $owned_checks, $evidence = array() ) {6911 private function classify_attachment( $attachment, $file_users, $owned_checks, $evidence = array(), $edit_copies = array() ) { 6896 6912 $id = (int) $attachment->ID; 6897 6913 $row = $this->classify_attachment_files( $attachment, $file_users, $owned_checks ); … … 6904 6920 } 6905 6921 6906 if ( 'unused' !== $row['file_class'] || empty( $evidence[ $id ] ) ) { 6922 if ( 'unused' !== $row['file_class'] ) { 6923 return $row; 6924 } 6925 6926 if ( isset( $edit_copies[ $id ] ) ) { 6927 return array_merge( $row, self::class_fields( 'edit_root', $edit_copies[ $id ], '', $edit_copies[ $id ] ) ); 6928 } 6929 6930 if ( empty( $evidence[ $id ] ) ) { 6907 6931 return $row; 6908 6932 } … … 6923 6947 6924 6948 return $row; 6949 } 6950 6951 /** 6952 * Get the edited copies in use of media items (WordPress 7.2 and later). 6953 * 6954 * An image edited in the block editor is saved as a new media item that 6955 * names its original in '_wp_attachment_edit_root_id' (every later edit 6956 * names the same original). The editor's "Restore original image" loads 6957 * the original's file, so an original whose copy is in use is Review. 6958 * 6959 * @since 1.1.1 6960 * @param array $attachment_ids Media item IDs. 6961 * @return array|null Original ID => ID of its first edited copy in use, or 6962 * null when the query failed (query_error says why). 6963 */ 6964 private function get_used_edit_copies( $attachment_ids ) { 6965 global $wpdb; 6966 6967 if ( empty( $attachment_ids ) ) { 6968 return array(); 6969 } 6970 6971 $values = array(); 6972 foreach ( $attachment_ids as $id ) { 6973 $values[] = (string) absint( $id ); 6974 } 6975 6976 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare -- Dynamic IN() list built with array_fill placeholders. 6977 $rows = $wpdb->get_results( 6978 $wpdb->prepare( 6979 "SELECT post_id, meta_value FROM {$wpdb->postmeta} 6980 WHERE meta_key = '_wp_attachment_edit_root_id' 6981 AND meta_value IN (" . implode( ',', array_fill( 0, count( $values ), '%s' ) ) . ') 6982 ORDER BY post_id ASC', 6983 $values 6984 ) 6985 ); 6986 6987 if ( '' !== $wpdb->last_error ) { 6988 $this->query_error = $wpdb->last_error; 6989 return null; 6990 } 6991 6992 $copies = array(); 6993 foreach ( (array) $rows as $row ) { 6994 $root = (int) $row->meta_value; 6995 $copy = (int) $row->post_id; 6996 if ( $copy !== $root && ! isset( $copies[ $root ] ) && $this->is_media_used( $copy ) ) { 6997 $copies[ $root ] = $copy; 6998 } 6999 } 7000 7001 return $copies; 6925 7002 } 6926 7003 … … 7365 7442 public function has_completed_scan() { 7366 7443 return (bool) get_option( 'tidy_media_scan_completed' ); 7444 } 7445 7446 /** 7447 * Whether the completed scan's results were made by an older release. 7448 * 7449 * Set on the first load after an update (Tidy_Media::maybe_flag_old_results()) 7450 * and cleared when a scan completes. Such results stay readable but are 7451 * not acted on: the older release read fewer places, so a Safe row may be 7452 * in use. 7453 * 7454 * @since 1.1.1 7455 * @return bool 7456 */ 7457 public function has_stale_results() { 7458 return $this->has_completed_scan() && (bool) get_option( 'tidy_media_needs_rescan' ); 7367 7459 } 7368 7460 -
tidy-media/trunk/readme.txt
r3744142 r3826997 2 2 Contributors: wpcoretools 3 3 Tags: media library, unused images, cleanup, storage, optimization 4 Requires at least: 6. 05 Tested up to: 7. 14 Requires at least: 6.4 5 Tested up to: 7.2 6 6 Requires PHP: 7.4 7 Stable tag: 1.1. 07 Stable tag: 1.1.1 8 8 License: GPL-2.0-or-later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 130 130 131 131 == Changelog == 132 133 = 1.1.1 - 2026-11-26 = 134 * Fixed: Media chosen in an ACF or Secure Custom Fields Icon Picker field is found. 135 * Fixed: SiteOrigin Widgets Bundle blocks and Layout Blocks in block widget areas (sidebars, footers) are found. 136 * Fixed: Brizy custom font files are found. 137 * Fixed: Images in Elementor Default Styles and in element defaults saved with "Save as default" are found. 138 * Fixed: Meta Box fields of the types "media" and "plupload_image" are found. 139 * Fixed: JetEngine gallery fields that hold one image, or images saved as ID and URL, are found. 140 * New: The original of an image edited in the WordPress 7.2 image editor is marked Review while the edited copy is in use, so "Restore original image" keeps working. 141 * Fixed: Quarantined media no longer shows in the block editor's media lists. 142 * Changed: After this update, results of a scan made with an earlier version stay visible but cannot be moved to quarantine until a new scan, and a scan left unfinished by the earlier version cannot be resumed (start a new one). 143 * Enhancement: Tested with the WordPress 7.2 release candidate and WooCommerce 11.3. Requires WordPress 6.4 or later, and WooCommerce 8.5 or later when WooCommerce is used. 132 144 133 145 = 1.1.0 - 2026-10-13 = … … 274 286 == Upgrade Notice == 275 287 288 = 1.1.1 = 289 Finds more media in use (ACF Icon Picker, SiteOrigin blocks in widget areas, Brizy fonts, Elementor Default Styles). Results of an earlier scan cannot be moved to quarantine until you run a new scan. 290 276 291 = 1.1.0 = 277 292 Adds safety classes, finds more media in use, and adds automatic batch size and quarantine history. Earlier results are cleared; run a new scan after updating. -
tidy-media/trunk/tidy-media.php
r3744142 r3826997 4 4 * Plugin URI: https://wpcoretools.com/plugins/tidy-media 5 5 * Description: Find and safely remove unused media files from your WordPress Media Library. Includes quarantine system, page builder support, and WooCommerce compatibility. 6 * Version: 1.1. 06 * Version: 1.1.1 7 7 * Author: WP Core Tools 8 8 * Author URI: https://wpcoretools.com … … 11 11 * Text Domain: tidy-media 12 12 * Domain Path: /languages 13 * Requires at least: 6.0 14 * Tested up to: 7.1 13 * Requires at least: 6.4 15 14 * Requires PHP: 7.4 16 15 * 17 * WC requires at least: 5.018 * WC tested up to: 11. 016 * WC requires at least: 8.5 17 * WC tested up to: 11.3 19 18 * 20 19 * @package Tidy_Media … … 27 26 28 27 // Plugin constants. 29 define( 'TIDY_MEDIA_VERSION', '1.1. 0' );28 define( 'TIDY_MEDIA_VERSION', '1.1.1' ); 30 29 define( 'TIDY_MEDIA_PLUGIN_FILE', __FILE__ ); 31 30 define( 'TIDY_MEDIA_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); … … 81 80 */ 82 81 const DB_VERSION = '1.4.1'; 82 83 /** 84 * Oldest plugin version whose scan results are still valid. 85 * 86 * Raise it to the new version when a release reads places an older one 87 * did not: results of a scan made before it may list files that are in 88 * use, so they are no longer acted on until a new scan 89 * (maybe_flag_old_results()). 90 * 91 * @since 1.1.1 92 * @var string 93 */ 94 const RESULTS_VERSION = '1.1.1'; 83 95 84 96 /** … … 324 336 $this->maybe_create_tables(); 325 337 338 // Results of a scan made by an older release are not acted on. 339 $this->maybe_flag_old_results(); 340 326 341 // Initialize components. 327 342 $this->init_components(); 328 343 329 // Hide quarantined attachments from the Media Library and AJAX queries. 344 // Hide quarantined attachments from the Media Library, AJAX queries and 345 // REST media lists (block editor inserter); a single item stays reachable. 330 346 add_action( 'pre_get_posts', array( $this, 'hide_quarantined_from_library' ) ); 331 347 add_filter( 'ajax_query_attachments_args', array( $this, 'hide_quarantined_from_ajax' ) ); 348 add_filter( 'rest_attachment_query', array( $this, 'hide_quarantined_from_ajax' ) ); 332 349 333 350 // Site Health checks. 334 351 add_filter( 'site_status_tests', array( $this, 'add_site_health_tests' ) ); 335 352 add_action( 'wp_ajax_health-check-tidy-media-quarantine-reachable', array( $this, 'ajax_site_health_quarantine' ) ); 336 337 // The "run a new scan" notice after an upgrade ends with the first completed scan.338 if ( get_option( 'tidy_media_needs_rescan' ) && get_option( 'tidy_media_scan_completed' ) ) {339 delete_option( 'tidy_media_needs_rescan' );340 }341 353 342 354 /** … … 528 540 } 529 541 } 542 } 543 544 /** 545 * On the first load after an update, mark the results of an older scan. 546 * 547 * A scan made by a release before RESULTS_VERSION did not read every 548 * place this one reads, so its Safe rows may be in use. The results stay 549 * readable, but tidy_media_needs_rescan is set: the Scanner tab asks for 550 * a new scan and the quarantine actions refuse those rows 551 * (Tidy_Media_Scanner::has_stale_results()) until a scan completes, which 552 * deletes the option. A scan left unfinished by the older release cannot 553 * be resumed (Tidy_Media_Scanner::STATE_VERSION), so it gets the notice 554 * too. Releases before 1.1.1 stored no plugin version. 555 * 556 * @since 1.1.1 557 */ 558 private function maybe_flag_old_results() { 559 $stored = (string) get_option( 'tidy_media_version', '' ); 560 561 if ( TIDY_MEDIA_VERSION === $stored ) { 562 return; 563 } 564 565 if ( '' === $stored || version_compare( $stored, self::RESULTS_VERSION, '<' ) ) { 566 if ( get_option( 'tidy_media_scan_completed' ) || false !== get_option( 'tidy_media_scan_state', false ) ) { 567 update_option( 'tidy_media_needs_rescan', self::RESULTS_VERSION ); 568 } 569 } 570 571 update_option( 'tidy_media_version', TIDY_MEDIA_VERSION ); 530 572 } 531 573 … … 1212 1254 1213 1255 /** 1214 * Hide quarantined attachments from AJAX media queries (media modal grid). 1256 * Hide quarantined attachments from AJAX media queries (media modal grid) 1257 * and, since 1.1.1, from REST media collections (rest_attachment_query). 1215 1258 * 1216 1259 * @since 1.1.0 … … 1219 1262 */ 1220 1263 public function hide_quarantined_from_ajax( $query ) { 1221 if ( ! isset( $query['meta_query'] ) ) { 1264 if ( ! is_array( $query ) ) { 1265 return $query; 1266 } 1267 1268 // Another plugin may have left a non-array meta_query (as in hide_quarantined_from_library()). 1269 if ( ! isset( $query['meta_query'] ) || ! is_array( $query['meta_query'] ) ) { 1222 1270 $query['meta_query'] = array(); 1223 1271 } -
tidy-media/trunk/uninstall.php
r3744142 r3826997 123 123 'tidy_media_last_scan_id', 124 124 'tidy_media_needs_rescan', 125 'tidy_media_version', 125 126 'tidy_media_quarantine_dir', 126 127 'tidy_media_bytes_deleted',
Note:
See TracChangeset
for help on using the changeset viewer.