- Centralizes a list of all shortcodes
- Returns all shortcodes with custom fields
This commit is contained in:
@@ -1,67 +1,67 @@
|
||||
<?php
|
||||
namespace MailPoet\Newsletter\Shortcodes\Categories;
|
||||
|
||||
use MailPoet\Models\Subscriber;
|
||||
|
||||
require_once(ABSPATH . 'wp-includes/pluggable.php');
|
||||
|
||||
class User {
|
||||
/*
|
||||
{
|
||||
text: '<%= __('First Name') %>',
|
||||
shortcode: 'user:firstname | default:reader',
|
||||
},
|
||||
{
|
||||
text: '<%= __('Last Name') %>',
|
||||
shortcode: 'user:lastname | default:reader',
|
||||
},
|
||||
{
|
||||
text: '<%= __('Email Address') %>',
|
||||
shortcode: 'user:email',
|
||||
},
|
||||
{
|
||||
text: '<%= __('Wordpress user display name') %>',
|
||||
shortcode: 'user:displayname | default:member',
|
||||
},
|
||||
{
|
||||
text: '<%= __('Total of subscribers') %>',
|
||||
shortcode: 'user:count',
|
||||
}
|
||||
*/
|
||||
static function process(
|
||||
$action,
|
||||
$default_value,
|
||||
$newsletter = false,
|
||||
$subscriber
|
||||
) {
|
||||
switch($action) {
|
||||
case 'firstname':
|
||||
return ($subscriber) ? $subscriber['first_name'] : $default_value;
|
||||
break;
|
||||
|
||||
case 'lastname':
|
||||
return ($subscriber) ? $subscriber['last_name'] : $default_value;
|
||||
break;
|
||||
|
||||
case 'email':
|
||||
return ($subscriber) ? $subscriber['email'] : false;
|
||||
break;
|
||||
|
||||
case 'displayname':
|
||||
if($subscriber && $subscriber['wp_user_id']) {
|
||||
$wp_user = get_userdata($subscriber['wp_user_id']);
|
||||
return $wp_user->user_login;
|
||||
}
|
||||
return $default_value;
|
||||
break;
|
||||
|
||||
case 'count':
|
||||
return Subscriber::filter('subscribed')->count();
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
namespace MailPoet\Newsletter\Shortcodes\Categories;
|
||||
|
||||
use MailPoet\Models\Subscriber;
|
||||
|
||||
require_once(ABSPATH . 'wp-includes/pluggable.php');
|
||||
|
||||
class User {
|
||||
/*
|
||||
{
|
||||
text: '<%= __('First Name') %>',
|
||||
shortcode: 'user:firstname | default:reader',
|
||||
},
|
||||
{
|
||||
text: '<%= __('Last Name') %>',
|
||||
shortcode: 'user:lastname | default:reader',
|
||||
},
|
||||
{
|
||||
text: '<%= __('Email Address') %>',
|
||||
shortcode: 'user:email',
|
||||
},
|
||||
{
|
||||
text: '<%= __('Wordpress user display name') %>',
|
||||
shortcode: 'user:displayname | default:member',
|
||||
},
|
||||
{
|
||||
text: '<%= __('Total of subscribers') %>',
|
||||
shortcode: 'user:count',
|
||||
}
|
||||
*/
|
||||
static function process(
|
||||
$action,
|
||||
$default_value,
|
||||
$newsletter = false,
|
||||
$subscriber
|
||||
) {
|
||||
switch($action) {
|
||||
case 'firstname':
|
||||
return ($subscriber) ? $subscriber['first_name'] : $default_value;
|
||||
break;
|
||||
|
||||
case 'lastname':
|
||||
return ($subscriber) ? $subscriber['last_name'] : $default_value;
|
||||
break;
|
||||
|
||||
case 'email':
|
||||
return ($subscriber) ? $subscriber['email'] : false;
|
||||
break;
|
||||
|
||||
case 'displayname':
|
||||
if($subscriber && $subscriber['wp_user_id']) {
|
||||
$wp_user = get_userdata($subscriber['wp_user_id']);
|
||||
return $wp_user->user_login;
|
||||
}
|
||||
return $default_value;
|
||||
break;
|
||||
|
||||
case 'count':
|
||||
return Subscriber::filter('subscribed')->count();
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
113
lib/Newsletter/Shortcodes/ShortcodesHelper.php
Normal file
113
lib/Newsletter/Shortcodes/ShortcodesHelper.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
namespace MailPoet\Newsletter\Shortcodes;
|
||||
|
||||
use MailPoet\Models\CustomField;
|
||||
|
||||
class ShortcodesHelper {
|
||||
|
||||
static function getShortcodes() {
|
||||
$shortcodes = array(
|
||||
__('Subscriber') => array(
|
||||
array(
|
||||
'text' => __('First Name'),
|
||||
'shortcode' => 'subscriber:firstname | default:reader',
|
||||
),
|
||||
array(
|
||||
'text' => __('Last Name'),
|
||||
'shortcode' => 'subscriber:lastname | default:reader',
|
||||
),
|
||||
array(
|
||||
'text' => __('Email Address'),
|
||||
'shortcode' => 'subscriber:email',
|
||||
),
|
||||
array(
|
||||
'text' => __('Wordpress user display name'),
|
||||
'shortcode' => 'subscriber:displayname | default:member',
|
||||
),
|
||||
array(
|
||||
'text' => __('Total of subscribers'),
|
||||
'shortcode' => 'subscriber:count',
|
||||
)
|
||||
),
|
||||
__('Newsletter') => array(
|
||||
array(
|
||||
'text' => __('Newsletter Subject'),
|
||||
'shortcode' => 'newsletter:subject',
|
||||
)
|
||||
),
|
||||
__('Post Notifications') => array(
|
||||
array(
|
||||
'text' => __('Total number of posts or pages'),
|
||||
'shortcode' => 'newsletter:total',
|
||||
),
|
||||
array(
|
||||
'text' => __('Latest post title'),
|
||||
'shortcode' => 'newsletter:post_title',
|
||||
),
|
||||
array(
|
||||
'text' => __('Issue number'),
|
||||
'shortcode' => 'newsletter:number',
|
||||
)
|
||||
),
|
||||
__('Date') => array(
|
||||
array(
|
||||
'text' => __('Current day of the month number'),
|
||||
'shortcode' => 'date:d',
|
||||
),
|
||||
array(
|
||||
'text' => __('Current day of the month in ordinal, ie. 2nd, 3rd, etc.'),
|
||||
'shortcode' => 'date:dordinal',
|
||||
),
|
||||
array(
|
||||
'text' => __('Full name of current day'),
|
||||
'shortcode' => 'date:dtext',
|
||||
),
|
||||
array(
|
||||
'text' => __('Current month number'),
|
||||
'shortcode' => 'date:m',
|
||||
),
|
||||
array(
|
||||
'text' => __('Full name of current month'),
|
||||
'shortcode' => 'date:mtext',
|
||||
),
|
||||
array(
|
||||
'text' => __('Year'),
|
||||
'shortcode' => 'date:y',
|
||||
)
|
||||
),
|
||||
__('Links') => array(
|
||||
array(
|
||||
'text' => __('Unsubscribe link'),
|
||||
'shortcode' => 'link:subscription_unsubscribe',
|
||||
),
|
||||
array(
|
||||
'text' => __('Edit subscription page link'),
|
||||
'shortcode' => 'link:subscription_manage',
|
||||
),
|
||||
array(
|
||||
'text' => __('View in browser link'),
|
||||
'shortcode' => 'link:newsletter_view_in_browser',
|
||||
)
|
||||
)
|
||||
);
|
||||
$custom_fields = self::getCustomFields();
|
||||
if($custom_fields) {
|
||||
$shortcodes[__('Subscriber')] = array_merge(
|
||||
$shortcodes[__('Subscriber')],
|
||||
$custom_fields
|
||||
);
|
||||
}
|
||||
return $shortcodes;
|
||||
}
|
||||
|
||||
static function getCustomFields() {
|
||||
$custom_fields = CustomField::findMany();
|
||||
if(!$custom_fields) return false;
|
||||
return array_map(function ($custom_field) {
|
||||
return array(
|
||||
'text' => $custom_field->name,
|
||||
'shortcode' => 'subscriber:cf_' . $custom_field->id
|
||||
);
|
||||
}, $custom_fields);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user