Hei,
primero, verifica si el resultado es un objeto WP_Error
o no:
$id = wp_insert_post(...);
if (is_wp_error($id)) {
$errors = $id->get_error_messages();
foreach ($errors as $error) {
echo $error; //this is just an example and generally not a good idea, you should implement means of processing the errors further down the track and using WP's error/message hooks to display them
}
}
Esta es la forma habitual.
Pero el objeto WP_Error se puede instanciar sin que se produzca ningún error, solo para actuar como un almacén de error general, por si acaso. Si desea hacerlo, puede verificar si hay algún error utilizando get_error_code()
:
function my_func() {
$errors = new WP_Error();
... //we do some stuff
if (....) $errors->add('1', 'My custom error'); //under some condition we store an error
.... //we do some more stuff
if (...) $errors->add('5', 'My other custom error'); //under some condition we store another error
.... //and we do more stuff
if ($errors->get_error_code()) return $errors; //the following code is vital, so before continuing we need to check if there's been errors...if so, return the error object
.... // do vital stuff
return $my_func_result; // return the real result
}
Si lo haces, entonces puedes verificar el proceso de error devuelto, como en el ejemplo anterior wp_insert_post()
.
La Clase está documentada en el Codex .
Y también hay un pequeño artículo aquí .