I am trying to utilize WP_Error for my plugin, but nothing happens. Is this too late for WP_Error? Too early? Or am I doing something else wrong?
function cpt_pre_post_publish(){
return new WP_Error('error', __('Error!' ));
}
add_action('pre_get_posts', 'cpt_pre_post_publish');
Actions don’t typically
return
data, so I doubt you will get this working the way you are trying to. Something like…… should set a variable that you could access in a template file with…
It is really not clear exactly what you are trying to do though.
Please see the example on the Codex, which indicates that you can return the WP_Error from a function, later use the function
is_wp_error()
(essentially the same as checkinginstanceof WP_Error
), and display the error message.s_ha_dum is right that actions shouldn’t really return — there’s nothing to catch the information being returned.