Add admin notices when using WordPress filters
-
I’m calling my plugin’s function via a filter (wp_handle_upload_prefilter), so I can’t just directly write a notice as output, correct? At least, when I tried doing that, it interrupted WordPress and would not continue processing the upload.
I’m currently trying to nest a function within the main function, which actually works slightly better, but still doesn’t seem to allow WordPress to continue processing the upload either (it just uploads it, then gets stuck on “Crunching”). So how can I write a notice or error to the user?
Here’s some relevant code I’m working on.
function aou_upload_file($file) { $file_no_ext = preg_replace('/\\.[^.\\s]{3,4}$/', '', $file['name']); // Determine if the file can be uploaded if (strpos($file['type'],'video') !== false) { $mediatype = 'movies'; } elseif (strpos($file['type'],'audio') !== false) { $mediatype = 'audio'; } else { function aou_not_supported_notice(){ echo '<div class="error"><p>File type not supported.</p></div>'; } add_action('add_attachment', 'aou_not_supported_notice'); return $file; } } add_filter('wp_handle_upload_prefilter','aou_upload_file');
Viewing 10 replies - 1 through 10 (of 10 total)
Viewing 10 replies - 1 through 10 (of 10 total)
The topic ‘Add admin notices when using WordPress filters’ is closed to new replies.