Plugin Directory

Changeset 2552518


Ignore:
Timestamp:
06/23/2021 08:34:27 AM (5 years ago)
Author:
msh134
Message:

Minor fixes

Location:
wp-upload-restriction/trunk
Files:
2 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • wp-upload-restriction/trunk/readme.txt

    r2533439 r2552518  
    33Tags: upload, media, developer tool
    44Tested up to: 5.7.2
    5 Stable tag: 2.2.2
     5Stable tag: 2.2.3
    66License: GPLv2 or later
    77
     
    3333
    3434== Changelog ==
    35 = 2.2.0 =
     35= 2.2.3 =
     36* Minor fixes.
     37
     38= 2.2.2 =
    3639* New feature: Added option for selecting file size unit (MB and KB).
    3740* Compatibility check.
  • wp-upload-restriction/trunk/wp-upload-restriction.php

    r2533439 r2552518  
    44  Plugin URI: https://wordpress.org/plugins/wp-upload-restriction/
    55  Description: This plugin allows you to control upload of files based on file types and sizes.
    6   Version: 2.2.2
     6  Version: 2.2.3
    77  Author: Sajjad Hossain
    88  Author URI: http://www.sajjadhossain.com
     
    8080        $user_roles = $user->roles;
    8181
     82        if(empty($user_roles)){
     83            return $mimes;
     84        }
     85
    8286        $selected_mimes = array();
    83         $has_setup = TRUE;
     87        $has_setup = false;
    8488       
    8589        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){
    8993                $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;
    9495            }
    9596        }
     
    126127        if($current_user->roles){
    127128            $upload_size = 0;
    128             $restrict = FALSE;
     129            $restrict = false;
    129130       
    130131            foreach($current_user->roles as $role){
    131132                if($this->isUploadSizeRestricted($role)){
    132                     $allowed_size = $this->getRoleMaxUploadSize($role, TRUE);               
     133                    $allowed_size = $this->getRoleMaxUploadSize($role, true);               
    133134                    $upload_size = max(array($upload_size, $allowed_size));
    134                     $restrict = TRUE;
     135                    $restrict = true;
    135136                }
    136137            }
     
    262263     */
    263264    public function getSelectedMimeTypes($role) {
    264         return get_option('wpur_selected_mimes_' . $role, FALSE);
     265        return get_option('wpur_selected_mimes_' . $role, false);
    265266    }
    266267   
     
    279280            $upload_size = $this->getRoleMaxUploadSize($role, false, $upload_size_unit);
    280281   
    281             $check_all = $selected_mimes === FALSE;
     282            $check_all = $selected_mimes === false;
    282283
    283284            ob_start();
     
    303304        }
    304305
    305         return FALSE;
     306        return false;
    306307    }
    307308
     
    342343     * @return int
    343344     */
    344     public function getRoleMaxUploadSize($role, $in_bytes = FALSE, $upload_size_unit = 'MB'){
     345    public function getRoleMaxUploadSize($role, $in_bytes = false, $upload_size_unit = 'MB'){
    345346        $upload_size_byte = get_option('wpur_max_upload_' . $role, 0);
    346347
     
    350351            }
    351352            else{
    352                 $upload_size = $upload_size_byte / ($upload_size_unit == 'MB' ? 1048576 : 1024);
     353                $upload_size = $upload_size_byte / $this->getMultiplier($upload_size_unit);
    353354                return round($upload_size, 0);
    354355            }
     
    373374     * @param string $role
    374375     * @param int $restrict_upload_size
    375      * @param int $size_in_mb
     376     * @param int $size
     377     * @param string $size_unit
    376378     */
    377379    private function setRolesMaxUploadSize($role, $restrict_upload_size, $size, $size_unit){
    378380        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);
    381382            update_option('wpur_max_upload_' . $role, $size_in_byte);
    382383            update_option('wpur_max_upload_unit_' . $role, $size_unit);
     
    511512
    512513    /**
     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    /**
    513531     * For updating database on version upgrade
    514532     */
     
    530548    private function updateDB1002(){
    531549        $roles = $this->getAllRoles();
    532         $selected_mimes = get_option('wpur_selected_mimes', FALSE);
     550        $selected_mimes = get_option('wpur_selected_mimes', false);
    533551        $all_mimes = $this->getWPSupportedMimeTypes();
    534552       
    535553        foreach($roles as $role => $details){
    536             if($role == 'administrator' || $selected_mimes === FALSE){       
     554            if($role == 'administrator' || $selected_mimes === false){       
    537555                update_option('wpur_selected_mimes_' . $role, $all_mimes);
    538556            }
Note: See TracChangeset for help on using the changeset viewer.