How do I increase the upload size only when editing special pages?
I have the following code to increase the upload size only when editing certain, special pages:
function my_edit_page_form( $post ) {
if( my_is_special_page( $post ) ) {
add_filter( 'upload_size_limit', 'my_upload_size_limit' );
}
}
add_action( 'edit_page_form', 'my_edit_page_form' );
function my_upload_size_limit( $size ) {
return 1024 * 18000;
}
On one of those pages, I have a Gallery shortcode. When I click on the Edit button, the "Maximum upload" message looks correct, but the upload is denied:
When viewing the source, I see that max_file_size
set is to 8388608b, the default for the site. This value comes from wp_plupload_default_settings
. This means this function must be called before the edit_page_form
hook.
So, if I cannot use edit_page_form
, what can I use instead that will be called before wp_plupload_default_settings
in order to check the post? Or, alternatively, should I be checking the post from within upload_size_limit
? If yes to the latter, then how do I do that?
-- UPDATE --
Here is my final code:
function my_upload_size_limit( $size ) {
global $post;
if ( $post $post-filter == 'edit' $post-post_type == 'page'
my_is_special_page( $post ) ) {
$size = 1024 * 18000;
}
return $size;
}
add_filter( 'upload_size_limit', 'my_upload_size_limit' );