Changeset 2552518
- Timestamp:
- 06/23/2021 08:34:27 AM (5 years ago)
- Location:
- wp-upload-restriction/trunk
- Files:
-
- 2 deleted
- 2 edited
-
readme.txt (modified) (2 diffs)
-
screenshot-1.png (deleted)
-
screenshot-2.png (deleted)
-
wp-upload-restriction.php (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-upload-restriction/trunk/readme.txt
r2533439 r2552518 3 3 Tags: upload, media, developer tool 4 4 Tested up to: 5.7.2 5 Stable tag: 2.2. 25 Stable tag: 2.2.3 6 6 License: GPLv2 or later 7 7 … … 33 33 34 34 == Changelog == 35 = 2.2.0 = 35 = 2.2.3 = 36 * Minor fixes. 37 38 = 2.2.2 = 36 39 * New feature: Added option for selecting file size unit (MB and KB). 37 40 * Compatibility check. -
wp-upload-restriction/trunk/wp-upload-restriction.php
r2533439 r2552518 4 4 Plugin URI: https://wordpress.org/plugins/wp-upload-restriction/ 5 5 Description: This plugin allows you to control upload of files based on file types and sizes. 6 Version: 2.2. 26 Version: 2.2.3 7 7 Author: Sajjad Hossain 8 8 Author URI: http://www.sajjadhossain.com … … 80 80 $user_roles = $user->roles; 81 81 82 if(empty($user_roles)){ 83 return $mimes; 84 } 85 82 86 $selected_mimes = array(); 83 $has_setup = TRUE;87 $has_setup = false; 84 88 85 89 foreach ($user_roles as $role){ 86 $roles_selected_mimes = get_option('wpur_selected_mimes_' . $role, FALSE);87 88 if($roles_selected_mimes !== FALSE){90 $roles_selected_mimes = get_option('wpur_selected_mimes_' . $role, false); 91 92 if($roles_selected_mimes !== false){ 89 93 $selected_mimes = array_merge($selected_mimes, $roles_selected_mimes); 90 $has_setup = TRUE; 91 } 92 elseif(!$$has_setup){ 93 $has_setup = FALSE; 94 $has_setup = true; 94 95 } 95 96 } … … 126 127 if($current_user->roles){ 127 128 $upload_size = 0; 128 $restrict = FALSE;129 $restrict = false; 129 130 130 131 foreach($current_user->roles as $role){ 131 132 if($this->isUploadSizeRestricted($role)){ 132 $allowed_size = $this->getRoleMaxUploadSize($role, TRUE);133 $allowed_size = $this->getRoleMaxUploadSize($role, true); 133 134 $upload_size = max(array($upload_size, $allowed_size)); 134 $restrict = TRUE;135 $restrict = true; 135 136 } 136 137 } … … 262 263 */ 263 264 public function getSelectedMimeTypes($role) { 264 return get_option('wpur_selected_mimes_' . $role, FALSE);265 return get_option('wpur_selected_mimes_' . $role, false); 265 266 } 266 267 … … 279 280 $upload_size = $this->getRoleMaxUploadSize($role, false, $upload_size_unit); 280 281 281 $check_all = $selected_mimes === FALSE;282 $check_all = $selected_mimes === false; 282 283 283 284 ob_start(); … … 303 304 } 304 305 305 return FALSE;306 return false; 306 307 } 307 308 … … 342 343 * @return int 343 344 */ 344 public function getRoleMaxUploadSize($role, $in_bytes = FALSE, $upload_size_unit = 'MB'){345 public function getRoleMaxUploadSize($role, $in_bytes = false, $upload_size_unit = 'MB'){ 345 346 $upload_size_byte = get_option('wpur_max_upload_' . $role, 0); 346 347 … … 350 351 } 351 352 else{ 352 $upload_size = $upload_size_byte / ($upload_size_unit == 'MB' ? 1048576 : 1024);353 $upload_size = $upload_size_byte / $this->getMultiplier($upload_size_unit); 353 354 return round($upload_size, 0); 354 355 } … … 373 374 * @param string $role 374 375 * @param int $restrict_upload_size 375 * @param int $size_in_mb 376 * @param int $size 377 * @param string $size_unit 376 378 */ 377 379 private function setRolesMaxUploadSize($role, $restrict_upload_size, $size, $size_unit){ 378 380 if($role){ 379 $multiplier = $size_unit == 'MB' ? 1048576 : 1024; 380 $size_in_byte = ($size ? $size : 0) * $multiplier; 381 $size_in_byte = ($size ? $size : 0) * $this->getMultiplier($size_unit); 381 382 update_option('wpur_max_upload_' . $role, $size_in_byte); 382 383 update_option('wpur_max_upload_unit_' . $role, $size_unit); … … 511 512 512 513 /** 514 * Returns multiplier for converting the limit to byte. 515 * 516 * @param string $size_unit 517 * @return int 518 */ 519 private function getMultiplier($size_unit){ 520 switch($size_unit){ 521 case 'MB': 522 return 1048576; 523 case 'KB': 524 return 1024; 525 default: 526 return 1; 527 } 528 } 529 530 /** 513 531 * For updating database on version upgrade 514 532 */ … … 530 548 private function updateDB1002(){ 531 549 $roles = $this->getAllRoles(); 532 $selected_mimes = get_option('wpur_selected_mimes', FALSE);550 $selected_mimes = get_option('wpur_selected_mimes', false); 533 551 $all_mimes = $this->getWPSupportedMimeTypes(); 534 552 535 553 foreach($roles as $role => $details){ 536 if($role == 'administrator' || $selected_mimes === FALSE){554 if($role == 'administrator' || $selected_mimes === false){ 537 555 update_option('wpur_selected_mimes_' . $role, $all_mimes); 538 556 }
Note: See TracChangeset
for help on using the changeset viewer.