2

I'm working on a multisite WP installation and I need to import content from other Wordpress sites (.wxr files). When I use the Import WordPress plugin I got the following:

enter image description here

The maximum allowed upload size is only 1MB, while I set 100MB in my php.ini. A call to phpinfo() tells that the .ini values should apply:

enter image description here

What is wrong there? I read through most of the search results for upload_max_filesize on this site, but none works.

Note: This only happens with Wordpress. I have Symfony2 sites and I can upload files with 100MB size and more - so yes, it's the right php.ini settings and the Apache server properly applies them.

Writing MU Wordpress Plugin

After @kaiser suggestion I've created a /wp-content/mu-plugins/uploadSizeLimit.php file and wrote this on it:

/** Plugin Name: (WPSE) #177620 Alter Upload Size Limit */
add_filter(
    'upload_size_limit',
    function ( $limit = 0, $u_bytes = 0, $p_bytes = 0 ) {
        return 
               current_user_can( 'manage_options' ) 
               ? 1024 * 1024 * 10 // Divert by 1024 to get the value in kB
               : $limit;
    }
);

How do I use this to achieve what I need?

  • 2
    Reynier, sidenote for your next questions: When you tried some stuff, you maybe want to show what exactly you tried so people like me who answer your question do not duplicate what you have already tried. Please keep that in mind. Thanks. – kaiser Feb 10 '15 at 8:25
1

There's a filter named 'upload_size_limit' where you should be able to change the value. Just add a small mu-plugin for that job:

<?php
/** Plugin Name: (WPSE) #177620 Alter Upload Size Limit */
add_filter( 'upload_size_limit', function( $limit = 0, $u_bytes = 0, $p_bytes = 0 )
{
    return (
        in_array( get_current_screen()->base, array( /* Add Screen "base"s here */ )
        and current_user_can( 'manage_options' )
    )
        ? 1024 * 1024 * 10 // Divert by 1024 to get the value in kB
        : $limit;
} );

As you can see, I also check for a get_current_screen()s property named base. You could check for different properties as well, but make sure to narrow the screens where removing/altering the default limit applies to the screens where you really need it.

  • Hi @kaiser, thanks for your answer, just one doubt, what you mean with this Add Screen "base"s here? What about if I just want to apply to the whole wp-admin side? – ReynierPM Feb 10 '15 at 13:14
  • If to the whole, then omit it. Still I'd suggest to narrow it down. – kaiser Feb 10 '15 at 15:39
  • I've created a uploadSizeLimit.php file under /wp-content/mu-plugins/ and write the filter on it, but, how do I use this? Is this the right way to go? See the edit I made to the main post – ReynierPM Feb 10 '15 at 20:13
  • Ehm... Please take a look at the if/else (in the case of my plugin in the answer, it's a "ternary operator" instead). When you copy/paste stuff, then you will always shoot yourself in your foot. Try to read my plugin bit by bit, statement by statement and line by line to find your mistake. Hint: you are comparing if the current screen objects base property is the in an array - while current_user_can() just returns a boolean true/false. – kaiser Feb 10 '15 at 20:22
  • Also: You have now added the plugin header comment twice. I suggest that you make a step back, breath 10 times deep and then really review what you have written :) – kaiser Feb 10 '15 at 20:23
5

Thanks @kaiser but not need to go through your solution I found a easy one and I'll share here for newbie likes me.

If you're working on a WP Network site then the steps are:

  1. At the top, hover over My Sites and then click Network Admin.
  2. At the left, hover over Settings and then click Network Settings.
  3. Scroll to the bottom of the page and change the Max upload file size to whatever you would like in KB.
  4. Click Save Changes.

By setting that value to 500000 I got 500M as max_file_size upload. Credits is for user here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.