Automattic\WooCommerce\EmailEditor\Engine
Email_Editor::register_email_editor_api_routes
Registers the API route endpoint for the email editor
Method of the class: Email_Editor{}
Hooks from the method
Returns
void. Nothing (null).
Usage
$Email_Editor = new Email_Editor(); $Email_Editor->register_email_editor_api_routes();
Email_Editor::register_email_editor_api_routes() Email Editor::register email editor api routes code WC 11.2.2
public function register_email_editor_api_routes() {
register_rest_route(
'woocommerce-email-editor/v1',
'/send_preview_email',
array(
'methods' => 'POST',
'callback' => array( $this->email_api_controller, 'send_preview_email_data' ),
'permission_callback' => function ( WP_REST_Request $request ) {
if ( ! current_user_can( 'edit_posts' ) ) {
return false;
}
$post_id = $request->get_param( 'postId' );
if ( is_numeric( $post_id ) && (int) $post_id > 0 ) {
return self::is_email_post_type( get_post_type( (int) $post_id ) ) && current_user_can( 'edit_post', (int) $post_id );
}
/**
* Filters whether a preview email may be sent for a request without a backing post.
*
* Defaults to false: postless requests are rejected unless an integration
* that handles them (via the `woocommerce_email_editor_send_preview_email`
* filter) explicitly authorizes the request.
*
* @param bool $allowed Whether the postless request is authorized. Default false.
* @param \WP_REST_Request $request The send-preview REST request.
*
* @since 2.16.0
*/
return (bool) apply_filters( 'woocommerce_email_editor_send_preview_email_without_post_permission', false, $request );
},
)
);
register_rest_route(
'woocommerce-email-editor/v1',
'/get_personalization_tags',
array(
'methods' => 'GET',
'callback' => array( $this->email_api_controller, 'get_personalization_tags' ),
'permission_callback' => function () {
return current_user_can( 'edit_posts' );
},
)
);
register_rest_route(
'woocommerce-email-editor/v1',
'/personalization_tags',
array(
'methods' => 'GET',
'callback' => array( $this->email_api_controller, 'get_personalization_tags_collection' ),
'permission_callback' => function () {
return current_user_can( 'edit_posts' );
},
'args' => array(
'post_id' => array(
'description' => __( 'The post ID for context-aware tag filtering.', 'woocommerce' ),
'type' => 'integer',
'required' => false,
'sanitize_callback' => 'absint',
),
),
)
);
}