Moved hook like in master v3

This commit is contained in:
Mike Jolley 2019-06-26 15:28:56 +01:00
parent 4ba989a07e
commit 1d0bd12a46
1 changed files with 18 additions and 18 deletions

View File

@ -196,13 +196,6 @@ abstract class WC_REST_CRUD_Controller extends WC_REST_Posts_Controller {
try {
$this->update_additional_fields_for_object( $object, $request );
} catch ( WC_Data_Exception $e ) {
$object->delete();
return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() );
} catch ( WC_REST_Exception $e ) {
$object->delete();
return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
}
/**
* Fires after a single object is created or updated via the REST API.
@ -212,6 +205,13 @@ abstract class WC_REST_CRUD_Controller extends WC_REST_Posts_Controller {
* @param boolean $creating True when creating object, false when updating.
*/
do_action( "woocommerce_rest_insert_{$this->post_type}_object", $object, $request, true );
} catch ( WC_Data_Exception $e ) {
$object->delete();
return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() );
} catch ( WC_REST_Exception $e ) {
$object->delete();
return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
}
$request->set_param( 'context', 'edit' );
$response = $this->prepare_object_for_response( $object, $request );
@ -243,11 +243,6 @@ abstract class WC_REST_CRUD_Controller extends WC_REST_Posts_Controller {
try {
$this->update_additional_fields_for_object( $object, $request );
} catch ( WC_Data_Exception $e ) {
return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() );
} catch ( WC_REST_Exception $e ) {
return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
}
/**
* Fires after a single object is created or updated via the REST API.
@ -257,6 +252,11 @@ abstract class WC_REST_CRUD_Controller extends WC_REST_Posts_Controller {
* @param boolean $creating True when creating object, false when updating.
*/
do_action( "woocommerce_rest_insert_{$this->post_type}_object", $object, $request, false );
} catch ( WC_Data_Exception $e ) {
return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() );
} catch ( WC_REST_Exception $e ) {
return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
}
$request->set_param( 'context', 'edit' );
$response = $this->prepare_object_for_response( $object, $request );