Merge pull request #1628 from mailpoet/mp-api-di

Introduce DI to plugin API [MAILPOET-1637]
This commit is contained in:
M. Shull
2018-11-15 07:55:11 -05:00
committed by GitHub
11 changed files with 210 additions and 107 deletions

View File

@@ -10,13 +10,14 @@ use MailPoet\WP\Posts as WPPosts;
if(!defined('ABSPATH')) exit;
class AutomatedLatestContent extends APIEndpoint {
/** @var \MailPoet\Newsletter\AutomatedLatestContent */
public $ALC;
public $permissions = array(
'global' => AccessControl::PERMISSION_MANAGE_EMAILS
);
function __construct() {
$this->ALC = new \MailPoet\Newsletter\AutomatedLatestContent();
function __construct(\MailPoet\Newsletter\AutomatedLatestContent $alc) {
$this->ALC = $alc;
}
function getPostTypes() {
@@ -74,14 +75,12 @@ class AutomatedLatestContent extends APIEndpoint {
}
function getBulkTransformedPosts($data = array()) {
$alc = new \MailPoet\Newsletter\AutomatedLatestContent();
$used_posts = array();
$rendered_posts = array();
foreach($data['blocks'] as $block) {
$posts = $alc->getPosts($block, $used_posts);
$rendered_posts[] = $alc->transformPosts($block, $posts);
$posts = $this->ALC->getPosts($block, $used_posts);
$rendered_posts[] = $this->ALC->transformPosts($block, $posts);
foreach($posts as $post) {
$used_posts[] = $post->ID;
@@ -90,4 +89,4 @@ class AutomatedLatestContent extends APIEndpoint {
return $this->successResponse($rendered_posts);
}
}
}