Skip to content

Commit

Permalink
use some match-statements
Browse files Browse the repository at this point in the history
  • Loading branch information
liedekef committed Jan 27, 2025
1 parent 79c29dd commit 20e4e09
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 90 deletions.
37 changes: 10 additions & 27 deletions eme-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2890,33 +2890,16 @@ function eme_sanitize_upload_filename( $fName, $field_id, $extra_id = '' ) {
}

function eme_upload_file_err( $code ) {
switch ( $code ) {
case UPLOAD_ERR_INI_SIZE:
$message = __( 'The uploaded file exceeds the upload_max_filesize directive in php.ini', 'events-made-easy' );
break;
case UPLOAD_ERR_FORM_SIZE:
$message = __( 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form', 'events-made-easy' );
break;
case UPLOAD_ERR_PARTIAL:
$message = __( 'The uploaded file was only partially uploaded', 'events-made-easy' );
break;
case UPLOAD_ERR_NO_FILE:
$message = __( 'No file was uploaded', 'events-made-easy' );
break;
case UPLOAD_ERR_NO_TMP_DIR:
$message = __( 'Missing a temporary folder', 'events-made-easy' );
break;
case UPLOAD_ERR_CANT_WRITE:
$message = __( 'Failed to write file to disk', 'events-made-easy' );
break;
case UPLOAD_ERR_EXTENSION:
$message = __( 'File upload stopped by extension', 'events-made-easy' );
break;

default:
$message = __( 'Unknown upload error', 'events-made-easy' );
break;
}
$message = match( $code ) {
UPLOAD_ERR_INI_SIZE => __( 'The uploaded file exceeds the upload_max_filesize directive in php.ini', 'events-made-easy' ),
UPLOAD_ERR_FORM_SIZE => __( 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form', 'events-made-easy' ),
UPLOAD_ERR_PARTIAL => __( 'The uploaded file was only partially uploaded', 'events-made-easy' ),
UPLOAD_ERR_NO_FILE => __( 'No file was uploaded', 'events-made-easy' ),
UPLOAD_ERR_NO_TMP_DIR => __( 'Missing a temporary folder', 'events-made-easy' ),
UPLOAD_ERR_CANT_WRITE => __( 'Failed to write file to disk', 'events-made-easy' ),
UPLOAD_ERR_EXTENSION => __( 'File upload stopped by extension', 'events-made-easy' ),
default => __( 'Unknown upload error', 'events-made-easy' ),
};
return $message;
}

Expand Down
20 changes: 10 additions & 10 deletions eme-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,16 @@ function _eme_install() {
function eme_uninstall( $networkwide ) {
if ( function_exists( 'is_multisite' ) && is_multisite() ) {
// check if it is a network activation - if so, run the activation function for each blog id
if ( $networkwide ) {
// Get all blog ids
$blog_ids = get_sites( [ 'fields' => 'ids' ] );
foreach ( $blog_ids as $site_id ) {
switch_to_blog( $site_id );
_eme_uninstall();
restore_current_blog();
}
return;
}
if ( $networkwide ) {
// Get all blog ids
$blog_ids = get_sites( [ 'fields' => 'ids' ] );
foreach ( $blog_ids as $site_id ) {
switch_to_blog( $site_id );
_eme_uninstall();
restore_current_blog();
}
return;
}
}
// executed if no network activation
_eme_uninstall();
Expand Down
Loading

0 comments on commit 20e4e09

Please sign in to comment.