Plugin Directory

Changeset 3826997


Ignore:
Timestamp:
11/26/2026 12:58:08 PM (less than one hour ago)
Author:
wpcoretools
Message:

Release version 1.1.1: finds more media in use (ACF/SCF Icon Picker, Meta Box media and plupload_image, JetEngine galleries, Elementor default styles, SiteOrigin blocks in widget areas, Brizy fonts), originals of images edited in the WordPress 7.2 editor are marked Review, quarantined media hidden from the block editor lists, results of earlier scans need a new scan before quarantine; requires WordPress 6.4

Location:
tidy-media/trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • tidy-media/trunk/assets/js/admin.js

    r3744142 r3826997  
    26302630                        this.collapseSetup();
    26312631                        $('#tidymedia-needs-rescan').remove();
     2632                        tidyMedia.resultsStale = false;
    26322633
    26332634                        this.showThemeFilesNotice(state);
    … …  
    32173218
    32183219                /**
     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                /**
    32193236                 * Quarantine selected files.
    32203237                 */
    32213238                quarantineSelected: function(e) {
    32223239                        e.preventDefault();
     3240
     3241                        if (this.refuseStaleResults()) {
     3242                                return;
     3243                        }
    32233244
    32243245                        var $checked = $('.tidymedia-file-checkbox:checked');
    … …  
    33553376                        e.preventDefault();
    33563377
     3378                        if (this.refuseStaleResults()) {
     3379                                return;
     3380                        }
     3381
    33573382                        var self = this;
    33583383                        var isReview = this.currentRisk === 'review';
    … …  
    34433468                        e.preventDefault();
    34443469
     3470                        if (this.refuseStaleResults()) {
     3471                                return;
     3472                        }
     3473
    34453474                        var $button = $(e.currentTarget);
    34463475                        var $item = $button.closest('.tidymedia-file-item');
    … …  
    35093538                deleteEntry: function(e) {
    35103539                        e.preventDefault();
     3540
     3541                        if (this.refuseStaleResults()) {
     3542                                return;
     3543                        }
    35113544
    35123545                        var $button = $(e.currentTarget);
    … …  
    55575590                                code_id: tidyMedia.strings.classCodeId || 'Used in code',
    55585591                                soft_refs: tidyMedia.strings.classSoftRefs || 'Only in revisions or trash',
     5592                                edit_root: tidyMedia.strings.classEditRoot || 'Original of an edited image',
    55595593                                'protected': tidyMedia.strings.classProtected || 'Protected ID'
    55605594                        };
  • tidy-media/trunk/includes/class-tidy-media-admin.php

    r3744142 r3826997  
    112112                                'batchSizeMin'     => Tidy_Media_Scanner::BATCH_SIZE_MIN,
    113113                                'scanIsIncomplete' => $scan_is_incomplete,
     114                                'resultsStale'     => $scanner->has_stale_results(),
    114115                                'scannerUrl'       => admin_url( 'upload.php?page=tidy-media&tab=scanner' ),
    115116                                'quarantineUrl'    => admin_url( 'upload.php?page=tidy-media&tab=quarantine' ),
    116117                                'probesPerClick'   => Tidy_Media_Http_Checks::PROBES_PER_CLICK,
    117118                                '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' ),
    118121                                        'scanning'             => __( 'Scanning...', 'tidy-media' ),
    119122                                        'scanComplete'         => __( 'Scan complete!', 'tidy-media' ),
    … …  
    386389                                        'classCodeId'          => __( 'Used in code', 'tidy-media' ),
    387390                                        'classSoftRefs'        => __( 'Only in revisions or trash', 'tidy-media' ),
     391                                        'classEditRoot'        => __( 'Original of an edited image', 'tidy-media' ),
    388392                                        'classProtected'       => __( 'Protected ID', 'tidy-media' ),
    389393                                        // Where is this used?
    … …  
    911915                        </div>
    912916
    913                         <?php if ( get_option( 'tidy_media_needs_rescan' ) ) : ?>
     917                        <?php if ( tidy_media()->scanner->has_stale_results() ) : ?>
    914918                        <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>
    916924                        </div>
    917925                        <?php endif; ?>
  • tidy-media/trunk/includes/class-tidy-media-ajax.php

    r3744142 r3826997  
    629629                        $reply['fs_skipped_notice']  = $scanner->has_completed_scan() ? $scanner->get_fs_skipped_notice() : '';
    630630                        $reply['needs_rescan']       = (bool) get_option( 'tidy_media_needs_rescan' ) && ! $scanner->has_completed_scan();
     631                        $reply['results_stale']      = $scanner->has_stale_results();
    631632
    632633                        // A stale scan is offered as paused so it can be resumed.
    … …  
    15381539         * Sends a 409 scan_incomplete reply when no scan has completed since the
    15391540         * 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).
    15411543         *
    15421544         * @since 1.1.0
    … …  
    15481550                if ( '' === $scan_id || ! tidy_media()->scanner->has_completed_scan() ) {
    15491551                        $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 );
    15501557                        return '';
    15511558                }
  • tidy-media/trunk/includes/class-tidy-media-custom-fields-support.php

    r3744142 r3826997  
    104104                'time_picker',
    105105                'color_picker',
    106                 'icon_picker',
    107106                'message',
    108107                'accordion',
    … …  
    140139                'video',
    141140                'background',
     141                // Older type names Meta Box still accepts in code.
     142                'media',
     143                'plupload_image',
    142144        );
    143145
    … …  
    11831185
    11841186                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;
    12001191                        }
    12011192                } elseif ( is_numeric( $unserialized ) && (int) $unserialized > 0 ) {
  • tidy-media/trunk/includes/class-tidy-media-page-builder-support.php

    r3744142 r3826997  
    4040                'wpbakery'       => 1,
    4141                'bricks'         => 2,
    42                 'siteorigin'     => 3,
    43                 'brizy'          => 2,
     42                'siteorigin'     => 4,
     43                'brizy'          => 3,
    4444        );
    4545
    … …  
    239239
    240240                        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.
    243245                                $kind = 'elementor_settings';
    244246                                $rows = $wpdb->get_results(
    … …  
    246248                                                "SELECT pm.meta_id AS id, pm.meta_value AS value FROM {$wpdb->postmeta} pm
    247249                                        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')
    249251                                        AND pm.meta_value != ''
    250252                                        AND p.post_type <> 'revision'
    … …  
    500502                                }
    501503
     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
    502534                                return array( $used_media, null, $page );
    503535
    … …  
    540572                                }
    541573
    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;
    543598
    544599                        default:
    … …  
    667722         * @param string $kind       Builder key (see SUB_STEPS), or the kind of row
    668723         *                           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).
    670726         * @param string $value      Meta value or post content.
    671727         * @param array  $used_media Current used media array.
    … …  
    692748                        case 'brizy':
    693749                                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;
    694755                }
    695756
  • tidy-media/trunk/includes/class-tidy-media-scanner.php

    r3744142 r3826997  
    287287         * Version of the scan state layout. A saved scan with an older version
    288288         * 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.
    289292         *
    290293         * @var int
    291294         */
    292         const STATE_VERSION = 3;
     295        const STATE_VERSION = 4;
    293296
    294297        /**
    … …  
    448451                'code_id'          => 'review',
    449452                'soft_refs'        => 'review',
     453                'edit_root'        => 'review',
    450454                'protected'        => 'keep',
    451455        );
    … …  
    16461650                }
    16471651
     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
    16481658                // The files they own: shared with another item, or linked from content.
    16491659                $owned_checks = $this->check_owned_files( $unused_ids );
    … …  
    17031713
    17041714                        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 );
    17061716                                $item_bytes = (int) $row['total_size'] > 0 ? (int) $row['total_size'] : (int) $row['file_size'];
    17071717
    … …  
    59565966                                /* translators: %s: where the media item was found, e.g. 'a revision of "About us" (#12)' */
    59575967                                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 );
    59585971                        case 'protected':
    59595972                                return __( 'In your Protected media IDs list (Settings). Never offered.', 'tidy-media' );
    … …  
    60206033                        'code_id'          => __( 'Used in code', 'tidy-media' ),
    60216034                        'soft_refs'        => __( 'Only in revisions or trash', 'tidy-media' ),
     6035                        'edit_root'        => __( 'Original of an edited image', 'tidy-media' ),
    60226036                        'protected'        => __( 'Protected ID', 'tidy-media' ),
    60236037                );
    … …  
    68846898         *
    68856899         * 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.
    68876902         *
    68886903         * @since 1.1.0
    … …  
    68916906         * @param array  $owned_checks Result of check_owned_files().
    68926907         * @param array  $evidence     Result of Tidy_Media_Evidence::get().
     6908         * @param array  $edit_copies  Result of get_used_edit_copies().
    68936909         * @return array Row without scan_id.
    68946910         */
    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() ) {
    68966912                $id  = (int) $attachment->ID;
    68976913                $row = $this->classify_attachment_files( $attachment, $file_users, $owned_checks );
    … …  
    69046920                }
    69056921
    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 ] ) ) {
    69076931                        return $row;
    69086932                }
    … …  
    69236947
    69246948                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;
    69257002        }
    69267003
    … …  
    73657442        public function has_completed_scan() {
    73667443                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' );
    73677459        }
    73687460
  • tidy-media/trunk/readme.txt

    r3744142 r3826997  
    22Contributors: wpcoretools
    33Tags: media library, unused images, cleanup, storage, optimization
    4 Requires at least: 6.0
    5 Tested up to: 7.1
     4Requires at least: 6.4
     5Tested up to: 7.2
    66Requires PHP: 7.4
    7 Stable tag: 1.1.0
     7Stable tag: 1.1.1
    88License: GPL-2.0-or-later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    130130
    131131== 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.
    132144
    133145= 1.1.0 - 2026-10-13 =
    … …  
    274286== Upgrade Notice ==
    275287
     288= 1.1.1 =
     289Finds 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
    276291= 1.1.0 =
    277292Adds 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  
    44 * Plugin URI: https://wpcoretools.com/plugins/tidy-media
    55 * 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.0
     6 * Version: 1.1.1
    77 * Author: WP Core Tools
    88 * Author URI: https://wpcoretools.com
    … …  
    1111 * Text Domain: tidy-media
    1212 * Domain Path: /languages
    13  * Requires at least: 6.0
    14  * Tested up to: 7.1
     13 * Requires at least: 6.4
    1514 * Requires PHP: 7.4
    1615 *
    17  * WC requires at least: 5.0
    18  * WC tested up to: 11.0
     16 * WC requires at least: 8.5
     17 * WC tested up to: 11.3
    1918 *
    2019 * @package Tidy_Media
    … …  
    2726
    2827// Plugin constants.
    29 define( 'TIDY_MEDIA_VERSION', '1.1.0' );
     28define( 'TIDY_MEDIA_VERSION', '1.1.1' );
    3029define( 'TIDY_MEDIA_PLUGIN_FILE', __FILE__ );
    3130define( 'TIDY_MEDIA_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
    … …  
    8180         */
    8281        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';
    8395
    8496        /**
    … …  
    324336                $this->maybe_create_tables();
    325337
     338                // Results of a scan made by an older release are not acted on.
     339                $this->maybe_flag_old_results();
     340
    326341                // Initialize components.
    327342                $this->init_components();
    328343
    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.
    330346                add_action( 'pre_get_posts', array( $this, 'hide_quarantined_from_library' ) );
    331347                add_filter( 'ajax_query_attachments_args', array( $this, 'hide_quarantined_from_ajax' ) );
     348                add_filter( 'rest_attachment_query', array( $this, 'hide_quarantined_from_ajax' ) );
    332349
    333350                // Site Health checks.
    334351                add_filter( 'site_status_tests', array( $this, 'add_site_health_tests' ) );
    335352                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                 }
    341353
    342354                /**
    … …  
    528540                        }
    529541                }
     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 );
    530572        }
    531573
    … …  
    12121254
    12131255        /**
    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).
    12151258         *
    12161259         * @since 1.1.0
    … …  
    12191262         */
    12201263        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'] ) ) {
    12221270                        $query['meta_query'] = array();
    12231271                }
  • tidy-media/trunk/uninstall.php

    r3744142 r3826997  
    123123                'tidy_media_last_scan_id',
    124124                'tidy_media_needs_rescan',
     125                'tidy_media_version',
    125126                'tidy_media_quarantine_dir',
    126127                'tidy_media_bytes_deleted',
Note: See TracChangeset for help on using the changeset viewer.