Add support for [site:title] and [site:homepage_link]
These will add support for these two shortcodes in the Shortcode engine MAILPOET-4599
This commit is contained in:
committed by
Aschepikov
parent
80f22c5b50
commit
f92ee90e9b
@@ -10,6 +10,7 @@ use MailPoet\Newsletter\NewslettersRepository;
|
||||
use MailPoet\Newsletter\Shortcodes\Categories\Date;
|
||||
use MailPoet\Newsletter\Shortcodes\Categories\Link;
|
||||
use MailPoet\Newsletter\Shortcodes\Categories\Newsletter;
|
||||
use MailPoet\Newsletter\Shortcodes\Categories\Site;
|
||||
use MailPoet\Newsletter\Shortcodes\Categories\Subscriber as SubscriberCategory;
|
||||
use MailPoet\Newsletter\Shortcodes\Shortcodes as NewsletterShortcodes;
|
||||
use MailPoet\Newsletter\Url as NewsletterUrl;
|
||||
@@ -49,6 +50,9 @@ class Shortcodes {
|
||||
/** @var SubscriberCategory */
|
||||
private $subscriberCategory;
|
||||
|
||||
/** @var Site */
|
||||
private $siteCategory;
|
||||
|
||||
public function __construct(
|
||||
Pages $subscriptionPages,
|
||||
WPFunctions $wp,
|
||||
@@ -59,7 +63,8 @@ class Shortcodes {
|
||||
Date $dateCategory,
|
||||
Link $linkCategory,
|
||||
Newsletter $newsletterCategory,
|
||||
SubscriberCategory $subscriberCategory
|
||||
SubscriberCategory $subscriberCategory,
|
||||
Site $siteCategory
|
||||
) {
|
||||
$this->subscriptionPages = $subscriptionPages;
|
||||
$this->wp = $wp;
|
||||
@@ -71,6 +76,7 @@ class Shortcodes {
|
||||
$this->linkCategory = $linkCategory;
|
||||
$this->newsletterCategory = $newsletterCategory;
|
||||
$this->subscriberCategory = $subscriberCategory;
|
||||
$this->siteCategory = $siteCategory;
|
||||
}
|
||||
|
||||
public function init() {
|
||||
@@ -216,6 +222,7 @@ class Shortcodes {
|
||||
$this->linkCategory,
|
||||
$this->newsletterCategory,
|
||||
$this->subscriberCategory,
|
||||
$this->siteCategory,
|
||||
$this->wp
|
||||
);
|
||||
|
||||
|
@@ -456,6 +456,7 @@ class ContainerConfigurator implements IContainerConfigurator {
|
||||
$container->autowire(\MailPoet\Newsletter\Shortcodes\Categories\Link::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Newsletter\Shortcodes\Categories\Newsletter::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Newsletter\Shortcodes\Categories\Subscriber::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Newsletter\Shortcodes\Categories\Site::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Newsletter\Statistics\NewsletterStatisticsRepository::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Newsletter\Scheduler\AutomaticEmailScheduler::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Newsletter\Scheduler\AutomationEmailScheduler::class)->setPublic(true);
|
||||
|
32
mailpoet/lib/Newsletter/Shortcodes/Categories/Site.php
Normal file
32
mailpoet/lib/Newsletter/Shortcodes/Categories/Site.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace MailPoet\Newsletter\Shortcodes\Categories;
|
||||
|
||||
use MailPoet\Entities\NewsletterEntity;
|
||||
use MailPoet\Entities\SendingQueueEntity;
|
||||
use MailPoet\Entities\SubscriberEntity;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class Site implements CategoryInterface {
|
||||
public function process(
|
||||
array $shortcodeDetails,
|
||||
NewsletterEntity $newsletter = null,
|
||||
SubscriberEntity $subscriber = null,
|
||||
SendingQueueEntity $queue = null,
|
||||
string $content = '',
|
||||
bool $wpUserPreview = false
|
||||
): ?string {
|
||||
$wp = new WPFunctions();
|
||||
|
||||
switch ($shortcodeDetails['action']) {
|
||||
case 'title':
|
||||
return $wp->getBloginfo('name');
|
||||
|
||||
case 'homepage_link':
|
||||
return $wp->getBloginfo('url');
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -9,6 +9,7 @@ use MailPoet\Newsletter\Shortcodes\Categories\CategoryInterface;
|
||||
use MailPoet\Newsletter\Shortcodes\Categories\Date;
|
||||
use MailPoet\Newsletter\Shortcodes\Categories\Link;
|
||||
use MailPoet\Newsletter\Shortcodes\Categories\Newsletter;
|
||||
use MailPoet\Newsletter\Shortcodes\Categories\Site;
|
||||
use MailPoet\Newsletter\Shortcodes\Categories\Subscriber;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
@@ -37,6 +38,9 @@ class Shortcodes {
|
||||
/** @var Subscriber */
|
||||
private $subscriberCategory;
|
||||
|
||||
/** @var Site */
|
||||
private $siteCategory;
|
||||
|
||||
/** @var WPFunctions */
|
||||
private $wp;
|
||||
|
||||
@@ -45,12 +49,14 @@ class Shortcodes {
|
||||
Link $linkCategory,
|
||||
Newsletter $newsletterCategory,
|
||||
Subscriber $subscriberCategory,
|
||||
Site $siteCategory,
|
||||
WPFunctions $wp
|
||||
) {
|
||||
$this->dateCategory = $dateCategory;
|
||||
$this->linkCategory = $linkCategory;
|
||||
$this->newsletterCategory = $newsletterCategory;
|
||||
$this->subscriberCategory = $subscriberCategory;
|
||||
$this->siteCategory = $siteCategory;
|
||||
$this->wp = $wp;
|
||||
}
|
||||
|
||||
@@ -210,6 +216,8 @@ class Shortcodes {
|
||||
return $this->newsletterCategory;
|
||||
} elseif ($category === 'subscriber') {
|
||||
return $this->subscriberCategory;
|
||||
} elseif ($category === 'site') {
|
||||
return $this->siteCategory;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@@ -111,6 +111,16 @@ class ShortcodesHelper {
|
||||
),
|
||||
],
|
||||
],
|
||||
__('Site', 'mailpoet') => [
|
||||
[
|
||||
'text' => __('Site title', 'mailpoet'),
|
||||
'shortcode' => '[site:title]',
|
||||
],
|
||||
[
|
||||
'text' => __('Homepage link', 'mailpoet'),
|
||||
'shortcode' => '[site:homepage_link]',
|
||||
],
|
||||
],
|
||||
];
|
||||
$customFields = $this->getCustomFields();
|
||||
if (count($customFields) > 0) {
|
||||
|
Reference in New Issue
Block a user