I'm beginning with creating plugins and I don't quite understand the process of displaying error messages. e.g. I use the php readfile function to download a file from a hidden location. If something goes wrong e.g. the file isn't found, how do you display a message at that moment.
I know you need to use add_action for 'admin_notices' but I can't quite figure out where you are supposed to put the add_action calls.
As far as I can tell, you have to create a function my_download_file which tries the download and echo's a <div class="error">
. Then 'somewhere' you need to call add_action('admin_notices', 'my_download file');
.
This, from reading the Action Reference, then gets called when admin_notices are being printed out. But does it always get called, or does it only get called when do_action gets called?
functions.php
file. In a plugin, that could essentially go anywhere as long as it's included in your main plugin file.add_action
, and then in the function that is called in that action, do your conditional logic.