• Resolved TWD

    (@twd)


    “No items matched your search”

    That’s what I get (and only that) when I try to upload a file into the Media Library.
    The upload window opens fine, but the files on my desktop appear invisible.

    I have created a custom plugin for WordPress MultiSite WAAS which is designed to:
    a) check if the current user is a “premium” plan customer
    b) if they are NOT then restrict the MIME types they can upload to just static images

    BUT it seems like every MIME type has been removed.

    Is this a quirk of MultiSite?
    It seems to work as intended on a stand alone WP site.

    function restrict_mime($mimes) {
        
      if ( function_exists('is_plugin_active_for_network') ){
          
        if ( is_plugin_active_for_network( 'wp-ultimo/wp-ultimo.php' ) ) {
            
          if ( !is_super_admin() ) {   
              
              //get user id
              $user_id = get_current_user_id();
               
              //define the Premium Pro plan ID
              $plan_id = 52;
               
              // restrict MIME types if the current user doesnt have Premium Pro plan
              if ( !wu_has_plan( $user_id, $plan_id ) ) {
                   $mimes = array( 
                      'jpg|jpeg' => 'image/jpeg', 
                      'gif' => 'image/gif',
                      'png' => 'image/png'
                                  );
                   return $mimes;
              }
                  
          }
        }
      }
    }
    add_filter('upload_mimes','restrict_mime');
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Apparently a network quirk. I tried your code, but had to comment out the wp-ultimo is active check and the wu_has_plan() call since I don’t have those. I still had trouble uploading, so they apparently are not an influence. I found that by commenting out the is_plugin_active_for_network existence check that I could then upload the allowed image types. No idea why that’s an issue though.

    Could you simply check if a function in the plugin is defined or not?

    Thread Starter TWD

    (@twd)

    Solved.
    The problem apparently, is that the return $mimes was in the wrong place.
    It needs to be at the very bottom of the function, outside the conditional statements.

    Otherwise, when testing either as a Super Admin or in any situation where the conditional statements return false, no $mimes are handed back by the plugin.

    Here is the working code.

    function restrict_mime($mimes) {
        
      if ( function_exists('is_plugin_active_for_network') ){
          
        if ( is_plugin_active_for_network( 'wp-ultimo/wp-ultimo.php' ) ) {
            
          if ( !is_super_admin() ) {   
              
              //get user id
              $user_id = get_current_user_id();
               
              //define the Premium Pro plan ID
              $plan_id = 52;
               
              // restrict MIME types if the current user doesnt have Premium Pro plan
              if ( !wu_has_plan( $user_id, $plan_id ) ) {
                   $mimes = array( 
                      'jpg|jpeg' => 'image/jpeg', 
                      'gif' => 'image/gif',
                      'png' => 'image/png',
                      'pdf' => 'application/pdf',
                      'txt' => 'text/plain',
                      'csv' => 'text/csv',
                      'doc' => 'application/msword',
                      'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
                      'ppt' => 'application/vnd.ms-powerpoint',
                      'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
                      'xls' => 'application/vnd.ms-excel',
                      'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'   
                                  );
              }
                  
          }
        }
      }
      return $mimes;    
    }
    add_filter('upload_mimes','restrict_mime');
    • This reply was modified 3 years, 9 months ago by TWD.
    Moderator bcworkz

    (@bcworkz)

    Hah! Of course. I can’t tell you how many times I’ve made the same mistake. Probably why I failed to see such a blunder even though the symptom was staring me in the face. I’m glad you solved it.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘MultiSite code snippet. Can’t upload ANY media.’ is closed to new replies.