Skip to content

Commit

Permalink
Pro Mime Types 2.1.0 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
sybrew committed Apr 3, 2024
1 parent ef1b719 commit b2b7837
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 36 deletions.
51 changes: 25 additions & 26 deletions inc/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function _register_or_migrate_settings() {
\wp_cache_flush();
\wp_cache_delete( 'alloptions', 'options' );

$supported_extensions = [];
$old_supported_regex = [];

// We used to separate storage based on site mode, rather than plugin activation mode.
if ( \is_multisite() ) {
Expand All @@ -171,7 +171,7 @@ function _register_or_migrate_settings() {
foreach ( $old_results as $row ) {
switch ( $row->meta_value ) { // Either 2 or 1; disallowed and allowed.
case 1: // Allowed.
$supported_extensions[] = str_replace( 'pmt_mime_type_', '', $row->meta_key );
$old_supported_regex[] = str_replace( 'pmt_mime_type_', '', $row->meta_key );
// Ignore all other settings.
}
}
Expand All @@ -188,27 +188,14 @@ function _register_or_migrate_settings() {
foreach ( $old_results as $row ) {
switch ( $row->option_value ) { // Either 2 or 1; disallowed and allowed.
case 1: // Allowed.
$supported_extensions[] = str_replace( 'pmt_mime_type_', '', $row->option_name );
$old_supported_regex[] = str_replace( 'pmt_mime_type_', '', $row->option_name );
// Ignore all other settings.
}
}
}
}

if ( ! $old_results ) {
// Register.
$supported_types = [];

// Extract to reduce array access opcodes in loop.
$safe = MIME_DANGER_LEVEL['safe'];

// SUPPORTED_MIME_TYPES: extension_regex, mime, danger, comment, type
foreach ( SUPPORTED_MIME_TYPES as $option => [ , , $danger ] )
if ( $safe === $danger )
$supported_types[] = $option;

$supported_types = implode( ',', $supported_types );
} else {
if ( $old_results ) {
// Migrate from < 2.0
foreach (
[
Expand All @@ -218,21 +205,33 @@ function _register_or_migrate_settings() {
]
as $old => $new
) {
if ( \in_array( $old, $supported_extensions, true ) ) {
if ( \in_array( $old, $old_supported_regex, true ) ) {
// It'd be faster if we'd collect the "$old", and then perform an array_diff... oh well.
$supported_extensions = array_diff( $supported_extensions, [ $old ] );
$supported_extensions[] = $new;
$old_supported_regex = array_diff( $old_supported_regex, [ $old ] );
$old_supported_regex[] = $new;
}
}

// SWF and FLV are long gone. Let's stop recognizing it.
$supported_extensions = array_diff( $supported_extensions, [ 'swf', 'flv' ] );
// SWF and FLV are long gone. Let's stop recognizing them.
$old_supported_regex = array_diff( $old_supported_regex, [ 'swf', 'flv' ] );

// Convert extensions to 2.1+
$supported_types = _update_extension_regexes_to_mime_type_options( $supported_extensions );
$supported_types = _update_extension_regexes_to_mime_type_options( $old_supported_regex );
} else {
// Register new installation.
$supported_types = [];

// Extract to reduce array access opcodes in loop.
$safe = MIME_DANGER_LEVEL['safe'];

// SUPPORTED_MIME_TYPES: extension_regex, mime, danger, comment, type
foreach ( SUPPORTED_MIME_TYPES as $option => [ , , $danger ] )
if ( $safe === $danger )
$supported_types[] = $option;

$supported_types = implode( ',', $supported_types );
}

// Migrate;
$success = is_network_mode()
? \update_site_option( ALLOWED_MIME_TYPES_OPTIONS_NAME, $supported_types )
: \update_option( ALLOWED_MIME_TYPES_OPTIONS_NAME, $supported_types );
Expand All @@ -242,7 +241,7 @@ function _register_or_migrate_settings() {
return false;

// Delete old options, if any.
if ( ! empty( $old_results ) ) {
if ( $old_results ) {
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->sitemeta} WHERE meta_key LIKE %s",
Expand Down Expand Up @@ -341,7 +340,7 @@ function _update_extension_regexes_to_mime_type_options( $extension_regexes ) {

$supported_types = [];

// This extracts SUPPORTED_MIME_TYPES to becomes [ 'avif' => 'avif|avifs', 'bpm' => 'bmp', ... ]
// This extracts SUPPORTED_MIME_TYPES to become [ 'avif' => 'avif|avifs', 'bpm' => 'bmp', ... ]
$options = array_combine(
array_keys( SUPPORTED_MIME_TYPES ),
array_column( SUPPORTED_MIME_TYPES, 0 ),
Expand Down
2 changes: 1 addition & 1 deletion promimetypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Plugin Name: Pro Mime Types - Manage file media types
* Plugin URI: https://wordpress.org/plugins/pro-mime-types/
* Description: Enable or block MIME types and file extensions for media / file / attachment uploads through a nifty (network) admin menu.
* Version: 2.1.0-dev-4
* Version: 2.1.0
* Author: Sybre Waaijer
* Author URI: https://cyberwire.nl/
* License: GPLv3
Expand Down
18 changes: 9 additions & 9 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: Cybr
Donate link: https://github.com/sponsors/sybrew
Tags: attachment, image, mime types, upload, multisite
Requires at least: 5.3
Tested up to: 6.2
Tested up to: 6.5
Requires PHP: 7.4.0
Stable tag: 2.1.0
License: GPLv3
Expand Down Expand Up @@ -63,16 +63,16 @@ If you find an issue, please open a [support topic](https://wordpress.org/suppor

= 2.1.0 =

* Upgrade: The stored settings will now convert from regex-based to key-based. This allows adding new types and adjusting existing regexes via the filter much more reliably.
* Upgrade: The stored settings will now convert from regex-based to key-based. This allows new types to be added and existing regexes to be adjusted much more reliably via the filter.
* This changes the return value of function `Pro_Mime_Types\get_allowed_mime_types_settings()`. Since the value is useable in the same manner as before, we didn't change or deprecate the function name.
* Added: AVIF is now supported (`image/avif`, extensions `avif` or `avifs`). You require WP 6.5 or later to prevent corruption of the upload.
* Added: AVIF is now supported (`image/avif`, extensions `avif` or `avifs`). The site requires WP 6.5 or later to make the upload editable -- however, WP 6.5 has various bugs with this.
* Added: The settings link has been added to Pro Mime Types's listing on the plugin activation page.
* In network mode, only the network administrator will see this and it will be accessible from any subsite.
* Added: Pro Mime Types now registers the current "database version" in option `pro_mime_types_db_version`, separately for networks and single-site activations (depending on how it's activated). This makes upgrading the options possible over time.
* Changed: constant `Pro_Mime_Types\SUPPORTED_MIME_TYPES` is now an associative array (with index keys), instead of a sequential one.
* Filter `pmt_supported_mime_types` is directly affected by this change, but using sequential values is still possible, though they may not be stored properly.
* Fixed: .exe is now assigned the MIME type PHP recognizes, instead of what Windows does.
* Fixed: When setting the plugin to single-site mode, from network-mode, the plugin's network options are no longer cleared.
* Only the network administrator will see this in network mode, conveniently accessible from any subsite.
* Added: Pro Mime Types now registers the current "database version" in option `pro_mime_types_db_version`, separately for networks and single-site activations (depending on how it's activated). This option allows for upgrading the settings over time.
* Changed: constant `Pro_Mime_Types\SUPPORTED_MIME_TYPES` is now an associative array (with index keys) instead of a sequential one.
* This change directly affects filter `pmt_supported_mime_types`, but sequential values can still be used, though they may not be stored properly.
* Fixed: .exe is now assigned the MIME type PHP recognizes instead of the one Windows does.
* Fixed: When setting the plugin to single-site mode from network mode, the plugin's network options are no longer cleared.

= 2.0.1 =

Expand Down

0 comments on commit b2b7837

Please sign in to comment.