Skip to content

Instantly share code, notes, and snippets.

@laxmariappan
Created July 14, 2022 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laxmariappan/0b71deb71c815718bc9ebf5523d599e1 to your computer and use it in GitHub Desktop.
Save laxmariappan/0b71deb71c815718bc9ebf5523d599e1 to your computer and use it in GitHub Desktop.
Send error response to REST endpoint
<?php
/**
* Send error response to REST endpoint.
*
* @return Error object
* @since 1.0
* @author Lax Mariappan <lax@webdevstudios.com>
*/
function get_email_notification() {
if ( isset( $_GET['id'] ) ) {
$id = sanitize_text_field(
wp_unslash( $_GET['id'] )
);
$error = get_post_meta( $id, 'email_notification', true );
if ( $error ) {
$data = json_decode( $error );
return new \WP_REST_Response(
array(
'code' => $data->code,
'message' => wp_unslash( $data->message ),
)
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment