Add base route for sending preview email
MAILPOET-6092
This commit is contained in:
committed by
Rostislav Wolný
parent
27d8093f86
commit
87676ccdb6
@ -146,21 +146,16 @@ export function* requestSendingNewsletterPreview(
|
|||||||
} as Partial< State[ 'preview' ] >,
|
} as Partial< State[ 'preview' ] >,
|
||||||
} as const;
|
} as const;
|
||||||
try {
|
try {
|
||||||
const url = window.MailPoetEmailEditor.json_api_root;
|
const postId = select( storeName ).getEmailPostId();
|
||||||
const token = window.MailPoetEmailEditor.api_token;
|
|
||||||
const method = 'POST';
|
|
||||||
const body = new FormData();
|
|
||||||
body.append( 'token', token );
|
|
||||||
body.append( 'action', 'mailpoet' );
|
|
||||||
body.append( 'api_version', window.MailPoetEmailEditor.api_version );
|
|
||||||
body.append( 'endpoint', 'newsletters' );
|
|
||||||
body.append( 'method', 'sendPreview' );
|
|
||||||
body.append( 'data[subscriber]', email );
|
|
||||||
body.append( 'data[id]', newsletterId.toString() );
|
|
||||||
yield apiFetch( {
|
yield apiFetch( {
|
||||||
url,
|
path: '/mailpoet-email-editor/v1/send_preview_email',
|
||||||
method,
|
method: 'POST',
|
||||||
body,
|
data: {
|
||||||
|
newsletterId,
|
||||||
|
email,
|
||||||
|
postId,
|
||||||
|
},
|
||||||
} );
|
} );
|
||||||
|
|
||||||
yield {
|
yield {
|
||||||
|
@ -10,6 +10,8 @@ namespace MailPoet\EmailEditor\Engine;
|
|||||||
|
|
||||||
use MailPoet\EmailEditor\Validator\Builder;
|
use MailPoet\EmailEditor\Validator\Builder;
|
||||||
use WP_Post;
|
use WP_Post;
|
||||||
|
use WP_REST_Request;
|
||||||
|
use WP_REST_Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for email API controller.
|
* Class for email API controller.
|
||||||
@ -35,6 +37,11 @@ class Email_Api_Controller {
|
|||||||
// Here comes code saving of Email specific data that will be passed on 'email_data' attribute.
|
// Here comes code saving of Email specific data that will be passed on 'email_data' attribute.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function send_preview_email_data( WP_REST_Request $request ): WP_REST_Response {
|
||||||
|
$data = $request->get_params();
|
||||||
|
return new WP_REST_Response(['success' => true, 'data' => $data], 200);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the schema for email data.
|
* Returns the schema for email data.
|
||||||
*
|
*
|
||||||
|
@ -94,6 +94,7 @@ class Email_Editor {
|
|||||||
$this->extend_email_post_api();
|
$this->extend_email_post_api();
|
||||||
$this->settings_controller->init();
|
$this->settings_controller->init();
|
||||||
}
|
}
|
||||||
|
add_action( 'rest_api_init', [ $this, 'register_email_editor_api_routes' ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -198,6 +199,16 @@ class Email_Editor {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function register_email_editor_api_routes() {
|
||||||
|
register_rest_route('mailpoet-email-editor/v1', '/send_preview_email', [
|
||||||
|
'methods' => 'POST',
|
||||||
|
'callback' => array( $this->email_api_controller, 'send_preview_email_data' ),
|
||||||
|
'permission_callback' => function() {
|
||||||
|
return current_user_can('edit_posts');
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the schema for email theme data.
|
* Returns the schema for email theme data.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user