MultiSite code snippet. Can’t upload ANY media.

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?

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/',
                  'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
                  'xls' => 'application/',
                  'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'   
  return $mimes;    
  • This reply was modified 2 days, 21 hours ago by TWD.

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.

Source link