<?php namespace MailPoet\API\JSON\v1; if (!defined('ABSPATH')) exit; use MailPoet\API\JSON\Endpoint as APIEndpoint; use MailPoet\Config\AccessControl; use MailPoet\WP\Functions as WPFunctions; use MailPoet\WP\Posts as WPPosts; class AutomatedLatestContent extends APIEndpoint { /** @var \MailPoet\Newsletter\AutomatedLatestContent */ public $ALC; private $wp; public $permissions = [ 'global' => AccessControl::PERMISSION_MANAGE_EMAILS, ]; public function __construct( \MailPoet\Newsletter\AutomatedLatestContent $alc, WPFunctions $wp ) { $this->ALC = $alc; $this->wp = $wp; } public function getPostTypes() { $postTypes = array_map(function($postType) { return [ 'name' => $postType->name, 'label' => $postType->label, ]; }, WPPosts::getTypes([], 'objects')); return $this->successResponse( array_filter($postTypes) ); } public function getTaxonomies($data = []) { $postType = (isset($data['postType'])) ? $data['postType'] : 'post'; $allTaxonomies = WPFunctions::get()->getObjectTaxonomies($postType, 'objects'); $taxonomiesWithLabel = array_filter($allTaxonomies, function($taxonomy) { return $taxonomy->label; }); return $this->successResponse($taxonomiesWithLabel); } public function getTerms($data = []) { $taxonomies = (isset($data['taxonomies'])) ? $data['taxonomies'] : []; $search = (isset($data['search'])) ? $data['search'] : ''; $limit = (isset($data['limit'])) ? (int)$data['limit'] : 100; $page = (isset($data['page'])) ? (int)$data['page'] : 1; $args = [ 'taxonomy' => $taxonomies, 'hide_empty' => false, 'search' => $search, 'number' => $limit, 'offset' => $limit * ($page - 1), 'orderby' => 'name', 'order' => 'ASC', ]; $args = $this->wp->applyFilters('mailpoet_search_terms_args', $args); $terms = WPPosts::getTerms($args); return $this->successResponse(array_values($terms)); } public function getPosts($data = []) { return $this->successResponse( $this->ALC->getPosts($data) ); } public function getTransformedPosts($data = []) { $posts = $this->ALC->getPosts($data); return $this->successResponse( $this->ALC->transformPosts($data, $posts) ); } public function getBulkTransformedPosts($data = []) { $usedPosts = []; $renderedPosts = []; foreach ($data['blocks'] as $block) { $posts = $this->ALC->getPosts($block, $usedPosts); $renderedPosts[] = $this->ALC->transformPosts($block, $posts); foreach ($posts as $post) { $usedPosts[] = $post->ID; } } return $this->successResponse($renderedPosts); } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
Analytics.php | File | 574 B | 0644 |
|
AutomatedLatestContent.php | File | 2.67 KB | 0644 |
|
AutomaticEmails.php | File | 2.67 KB | 0644 |
|
CustomFields.php | File | 2.74 KB | 0644 |
|
DynamicSegments.php | File | 10.45 KB | 0644 |
|
FeatureFlags.php | File | 1.32 KB | 0644 |
|
Forms.php | File | 10.67 KB | 0644 |
|
ImportExport.php | File | 5.13 KB | 0644 |
|
MP2Migrator.php | File | 1.53 KB | 0644 |
|
Mailer.php | File | 2.61 KB | 0644 |
|
NewsletterLinks.php | File | 940 B | 0644 |
|
NewsletterTemplates.php | File | 3.14 KB | 0644 |
|
Newsletters.php | File | 14.76 KB | 0644 |
|
Premium.php | File | 2.16 KB | 0644 |
|
Segments.php | File | 11.08 KB | 0644 |
|
SendingQueue.php | File | 5.45 KB | 0644 |
|
SendingTaskSubscribers.php | File | 3.51 KB | 0644 |
|
Services.php | File | 8.72 KB | 0644 |
|
Settings.php | File | 9.66 KB | 0644 |
|
Setup.php | File | 920 B | 0644 |
|
SubscriberStats.php | File | 2.22 KB | 0644 |
|
Subscribers.php | File | 10.02 KB | 0644 |
|
UserFlags.php | File | 994 B | 0644 |
|
WoocommerceSettings.php | File | 776 B | 0644 |
|
index.php | File | 0 B | 0644 |
|