Newsletters Shortcodes

Below, you’ll find a detailed guide on how to add the Newsletters Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Newsletters Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Newsletters Plugin and the shortcodes it provides:

Plugin Icon
Newsletters

"Newsletters Lite is a user-friendly WordPress plugin that allows you to create, send, and track emails. It's perfect for blog updates, product announcements, or newsletters."

★★★★☆ (240) Active Installs: 3000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [newsletters-lite_management]
  • [newsletters-lite_subscribe]
  • [newsletters_lite_template]
  • [newsletters_lite_history]
  • [newsletters_meta]
  • [datestring]
  • [newsletters-lite-post]
  • [newsletters_posts_multiple]
  • [post_permalink]
  • [subscriberscount]
  • [newsletters_activate]
  • [newsletters_video]
  • [newsletters_bloginfo]
  • [newsletters_pluginurl]
  • [newsletters_subscribe_link]
  • [newsletters_authenticate]
  • [newsletters_sendas]
  • [newsletters_woocommerce_products]
  • [shortcode_posts]
  • [newsletters_if]

Newsletters [newsletters-lite_management] Shortcode

The ‘Newsletters-Lite’ plugin shortcode is used for managing various aspects of a mailing list. It allows for subscribing, unsubscribing, resubscribing, and deleting subscribers from the list. Additionally, it provides functionalities for paid subscriptions and handling user logins. It even tracks clicks for user activities.

Shortcode: [newsletters-lite_management]

Parameters

Here is a list of all possible newsletters-lite_management shortcode parameters and attributes:

  • method – Defines the action to be performed such as subscribing, unsubscribing, or managing subscriptions
  • subscriber_id – The unique identifier of the subscriber
  • list_id – The unique identifier of the mailing list
  • extend – Used to extend the subscription of a subscriber
  • email – The email address of the subscriber
  • mailinglists – The list of mailing lists to which the subscriber is subscribed
  • id – The unique identifier of the subscriber or user
  • user_id – The unique identifier of the user

Examples and Usage

Basic example – Displaying the management interface of the newsletter plugin

[newsletters_management]

Advanced examples

Displaying the management interface of the newsletter plugin with custom attributes. The shortcode accepts a variety of attributes that allow you to customize the output. Here’s an example:

[newsletters_management method="paidsubscription" subscriber_id="123" list_id="456" extend="true"]

In this example, the ‘method’ attribute is set to ‘paidsubscription’, which will display the paid subscription management interface. The ‘subscriber_id’ and ‘list_id’ attributes are used to specify the subscriber and the mailing list, and the ‘extend’ attribute is used to determine whether the subscription should be extended.

Here’s another example:

[newsletters_management method="unsubscribe" subscriber_id="123"]

In this example, the ‘method’ attribute is set to ‘unsubscribe’, which will display the unsubscribe interface for the subscriber specified by the ‘subscriber_id’ attribute.

PHP Function Code

In case you have difficulties debugging what causing issues with [newsletters-lite_management] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode($this -> pre . 'management', array($this, 'sc_management'));

Shortcode PHP function:

                    function sc_management($atts = array(), $content = null) {
			global $wpdb, $Db, $Mailinglist, $Subscriber, $SubscribersList, $Authnews, $Unsubscribe,
			$newsletters_errors, $Field, $Html;

			if (!defined('NEWSLETTERS_IS_MANAGEMENT')) {
				define('NEWSLETTERS_IS_MANAGEMENT', true);
			}

			$errors = array();

			$output = "";
			$defaults = array();
			extract(shortcode_atts($defaults, $atts));
			$emailfield = $Field -> email_field();

			ob_start();

			$method = sanitize_text_field(isset($_GET['method']) ? $_GET['method'] : "");
			$method = (!empty($method)) ? $method : false;

			switch ($method) {
				case 'paidsubscription'			:
					$subscriber_id = sanitize_text_field(wp_unslash($_REQUEST['subscriber_id']));
					$list_id = sanitize_text_field(wp_unslash($_REQUEST['list_id']));
					$extend = sanitize_text_field(wp_unslash($_REQUEST['extend']));

					if (!empty($subscriber_id)) {
						if (!empty($list_id)) {

							$subscriber = $Subscriber -> get($subscriber_id);
							$data = (array) $subscriber;
							$data['list_id'] = $list_id;
							$mailinglist = $Mailinglist -> get($list_id);
							$extend = (empty($extend)) ? false : true;

							$Field -> validate_optin($data, 'management');

							if (empty($Field -> errors)) {
								$this -> render('management' . DS . 'paidsubscription', array('subscriber' => $subscriber, 'mailinglist' => $mailinglist, 'extend' => $extend), true, 'default');
							} else {
								$url = $Html -> retainquery('updated=1&error=' . __('Some profile fields are required, please complete them.', 'wp-mailinglist') . '#profile', $this -> get_managementpost(true));
								$this -> redirect($url);
							}
						} else {
							$errors[] = __('No mailing list was specified', 'wp-mailinglist');
						}
					} else {
						$errors[] = __('No subscriber was specified', 'wp-mailinglist');
					}

					break;
				case 'paidsubscriptionsuccess'	:
					$message = __('Thank you for your payment! Please allow a moment for the subscription to be activated.', 'wp-mailinglist');
					$this -> redirect($this -> get_managementpost(true), "success", $message);
					break;
				case 'subscribe'			:

					$errors = false;
					$success = false;
					$id = (int) sanitize_text_field(wp_unslash($_GET['id']));

					if (!empty($id)) {
						if (!empty($_GET['mailinglists'])) {
							$Db -> model = $Subscriber -> model;
							if ($subscriber = $Db -> find(array('id' => $id))) {

								$subscriber -> mailinglists = explode(",", esc_html($_GET['mailinglists']));
								$subscriber -> active = "Y";

								if ($Subscriber -> optin($subscriber, false, false, false)) {
									$success = true;

									$Authnews -> set_emailcookie($subscriber -> email, "+30 days");
									if (empty($subscriber -> cookieauth)) {
										$subscriberauth = $Authnews -> gen_subscriberauth();
										$Db -> model = $Subscriber -> model;
										$Db -> save_field('cookieauth', $subscriberauth, array('id' => $subscriber -> id));
									} else {
										$subscriberauth = $subscriber -> cookieauth;
									}

									$Authnews -> set_cookie($subscriberauth, "+30 days", true);
								} else {
									$errors = $Subscriber -> errors;
								}
							} else {
								$errors[] = __('Subscriber cannot be read', 'wp-mailinglist');
							}
						} else {
							$errors[] = __('No list was specified', 'wp-mailinglist');
						}
					} else {
						$errors[] = __('No subscriber was specified', 'wp-mailinglist');
					}

					$this -> render('management' . DS . 'subscribe', array('subscriber' => $subscriber, 'errors' => $errors, 'success' => $success), true, 'default');
					break;
				case 'resubscribe'			:
					$errors = false;
					$success = false;

					if (!empty($_GET['email']) && (!empty($_GET['mailinglists']))) {

						$Db -> model = $Subscriber -> model;
						if (!$subscriber = $Db -> find(array('email' => sanitize_email(wp_unslash($_GET['email']))))) {
							$subscriber = array();
						}

						$subscriber = (array) $subscriber;

						$subscriber['email'] = sanitize_text_field(wp_unslash($_GET['email']));
						$subscriber['mailinglists'] = explode(",", sanitize_text_field(wp_unslash($_GET['mailinglists'])));
						$subscriber['active'] = "Y";

						if ($Subscriber -> optin($subscriber, false, false, false)) {
							$success = true;

							$Authnews -> set_emailcookie($subscriber -> email, "+30 days");
							if (empty($subscriber -> cookieauth)) {
								$subscriberauth = $Authnews -> gen_subscriberauth();
								$Db -> model = $Subscriber -> model;
								$Db -> save_field('cookieauth', $subscriberauth, array('id' => $subscriber -> id));
							} else {
								$subscriberauth = $subscriber -> cookieauth;
							}

							$Authnews -> set_cookie($subscriberauth, "+30 days", true);
						} else {
							$errors = $Subscriber -> errors;
						}
					} else {
						$errors[] = __('Some data is missing, please try again', 'wp-mailinglist');
					}

					$this -> render('resubscribe', array('subscriber' => $subscriber, 'errors' => $errors, 'success' => $success), true, 'default');
					break;
				case 'unsubscribe'			:
					global $wpdb, $Html, $Authnews, $Db, $Subscriber, $Mailinglist, $SubscribersList;

					$data = map_deep(wp_unslash($_REQUEST), 'sanitize_text_field');
					$dorender = true;
					$error = false;
					$success = false;
					$deleted = false;
					$userfile = "-success";

					$history_id = $data[$this -> pre . 'history_id'];
					$history = $this -> History() -> find(array('id' => $history_id));
					$subscriber_id = $data[$this -> pre . 'subscriber_id'];

					if (!empty($subscriber_id) || !empty($data['user_id'])) {
						if (($mailinglists = explode(",", $data[$this -> pre . 'mailinglist_id'])) !== false) {
							//do nothing, it's good...
							$includeonly = (empty($mailinglists)) ? $history -> mailinglists : $mailinglists;
							$mailinglists = $Subscriber -> mailinglists($subscriber_id, $includeonly, false, false);
						} else {
							$mailinglists = false;
						}

						if (!empty($data[$this -> pre . 'subscriber_id'])) {
							$subscriber_query = "SELECT * FROM " . $wpdb -> prefix . $Subscriber -> table . " WHERE id = '" . $data[$this -> pre . 'subscriber_id'] . "'";

							$subscriber = $wpdb -> get_row($subscriber_query);

							if (!empty($subscriber)) {
								if ($subscriber -> authkey == $_GET['authkey']) {
									if (empty($subscriber -> mandatory) || $subscriber -> mandatory == "N") {
										/* Management Auth */
										if (empty($data['cookieauth'])) {
											$Authnews -> set_emailcookie($subscriber -> email);
											$subscriberauth = $Authnews -> gen_subscriberauth();
											$Db -> model = $Subscriber -> model;
											$Db -> save_field('cookieauth', $subscriberauth, array('id' => $subscriber -> id));
											$Authnews -> set_cookie($subscriberauth);
										}

										$subscriber -> mailinglists = $mailinglists;

										if (empty($subscriber -> mailinglists)) {
											$errors[] = __('This email was not sent to any lists.', 'wp-mailinglist');
										}
									} else {
										$dorender = false;
										$errors[] = __('You are a mandatory subscriber and cannot unsubscribe', 'wp-mailinglist');
									}
								} else {
									$dorender = false;
									$errors[] = __('You are not authorised to use this link', 'wp-mailinglist');
								}
							} else {
								$errors[] = __('Your subscriber record cannot be read, please try again.', 'wp-mailinglist');
							}
						} elseif (!empty($data['user_id'])) {
							if ($user = $this -> userdata($data['user_id'])) {
								// all good
								$userfile = "-user";
							} else {
								$errors[] = __('User cannot be read', 'wp-mailinglist');
							}
						} else {
							$errors[] = __('No subscriber or user was specified', 'wp-mailinglist');
						}
					} else {
						$errors[] = __('No subscriber ID was specified, please try again.', 'wp-mailinglist');
					}

					$clicktrack = $this -> get_option('clicktrack');
					if (!empty($clicktrack) && $clicktrack == "Y") {
						$click_data = array(
							'referer'			=>	"unsubscribe",
							'history_id'		=>	(int) $_GET[$this -> pre . 'history_id'],
							'user_id'			=>	(int) $_GET[$this -> pre . 'user_id'],
							'subscriber_id'		=>	(int) $_GET[$this -> pre . 'subscriber_id'],
							'device'			=>	$this -> get_device()
						);

						$this -> Click() -> save($click_data, true);
					}

					if (!empty($data['confirm']) || $this -> get_option('unsubscribeconfirmation') == "N") {
						$unsubscribeemails = $this -> get_option('unsubscribeemails');
						$unsubscribelists = $data['unsubscribelists'];

						if (!empty($data[$this -> pre . 'subscriber_id'])) {
							if ($this -> get_option('unsubscribeconfirmation') == "N") {
								$data['unsubscribelists'] = $mailinglists;
							}

							if (!empty($data['unsubscribelists'])) {
								$this -> user_unsubscription_notification($subscriber, $mailinglists);

								$subscribedlists = $Subscriber -> mailinglists($subscriber -> id);	//all subscribed mailing lists

								foreach ($data['unsubscribelists'] as $unsubscribelist_id) {
									$Db -> model = $Mailinglist -> model;
									$mailinglist = $Db -> find(array('id' => $unsubscribelist_id));
									$subscriber -> mailinglist_id = $unsubscribelist_id;

									if (!empty($unsubscribeemails) && $unsubscribeemails == "multiple") {
										$this -> admin_unsubscription_notification($subscriber, $unsubscribelist_id);
									}

									if (!empty($subscriber -> id) && !empty($unsubscribelist_id)) {
										$subscribedlists = array_diff($subscribedlists, array($unsubscribelist_id));
										$SubscribersList -> delete_all(array('subscriber_id' => $subscriber -> id, 'list_id' => $unsubscribelist_id));
										$Db -> model = $this -> Autoresponderemail() -> model;
										$Db -> delete_all(array('subscriber_id' => $subscriber -> id, 'list_id' => $unsubscribelist_id));

										$Db -> model = $Unsubscribe -> model;
										$unsubscribe_data = array('email' => $subscriber -> email, 'mailinglist_id' => $unsubscribelist_id, 'history_id' => $data[$this -> pre . 'history_id'], 'comments' => $data[$this -> pre . 'comments']);
										$Db -> save($unsubscribe_data, true);
									}
								}

								if (!empty($unsubscribeemails) && $unsubscribeemails == "single") {
									$this -> admin_unsubscription_notification($subscriber, $unsubscribelists);
								}

								do_action('newsletters_subscriber_unsubscribe', $subscriber -> id, $data['unsubscribelists']);

								if ($this -> get_option('unsubscriberemoveallsubscriptions') == "Y") {
									foreach ($subscribedlists as $subscribedlist_id) {
										if (!empty($subscriber -> id) && !empty($subscribedlist_id)) {
											$SubscribersList -> delete_all(array('subscriber_id' => $subscriber -> id, 'list_id' => $subscribedlist_id));
										}
									}
								}

								//Should the subscriber be deleted?
								if ($this -> get_option('unsubscribedelete') == "Y") {
									if (empty($subscribedlists) || !is_array($subscribedlists) || count($subscribedlists) <= 0) {
										$Db -> model = $Subscriber -> model;
										$Db -> delete($subscriber -> id);
										$deleted = true;
									}
								}

                                //Should the WP User deleted on unsubscribe?
                                if ($this -> get_option('unsubscribewpuserdeletebyuser') == "Y") {
                                    $useridfrommail = get_user_by( 'email', $subscriber -> email );
                                    $wpuserid = $useridfrommail->ID;
                                    require_once(ABSPATH.'wp-admin/includes/user.php' );
                                    wp_delete_user($wpuserid);
                                }


								$success = true;
							} else {
								$errors[] = __('You did not select any list(s) to unsubscribe from.', 'wp-mailinglist');
								$success = false;
							}
						} elseif (!empty($data['user_id'])) {
							$Db -> model = $Unsubscribe -> model;
							$unsubscribe_data = array('user_id' => $user -> ID, 'email' => $user -> user_email, 'mailinglist_id' => false, 'history_id' => $data[$this -> pre . 'history_id'], 'comments' => $data[$this -> pre . 'comments']);
							$Db -> save($unsubscribe_data, true);
							$success = true;
							$errors = false;
						} else {
							$errors[] = __('No subscriber or user was specified', 'wp-mailinglist');
						}
					}
					
					// Is the unsubscribe successful?
					if (!empty($success)) {
						$unsubscribe_redirect = $this -> get_option('unsubscribe_redirect');
						if (!empty($unsubscribe_redirect)) {
							$unsubscribe_redirect_url = $this -> get_option('unsubscribe_redirect_url');
							if (!empty($unsubscribe_redirect_url)) {
								$this -> redirect($unsubscribe_redirect_url);
							}
						}
					}

					$this -> render('unsubscribe' . $userfile, array('subscriber' => $subscriber, 'history' => $history, 'dorender' => $dorender, 'user' => $user, 'data' => $data, 'errors' => $errors, 'success' => $success, 'deleted' => $deleted), true, 'default');
					break;
				case 'delete'				:
				
					global $Authnews, $Db, $Subscriber;
					
					$subscriber = $Authnews -> logged_in();					
					$Db -> model = $Subscriber -> model;
					$Db -> delete($subscriber -> id);
					$this -> delete_all_cache();
					
					$this -> render('management' . DS . 'delete', false, true, 'default');
					
					break;
				case 'logout'				:
					global $wpmljavascript;
					$subscriberemailauth = $Authnews -> read_emailcookie();
					$subscriberauth = $Authnews -> read_cookie();

					$managementauthtype = $this -> get_option('managementauthtype');
					switch ($managementauthtype) {
						case 1					:
							$Authnews -> delete_cookie($Authnews -> cookiename, $subscriberauth);
							$Authnews -> delete_cookie($Authnews -> emailcookiename, $subscriberemailauth);
							break;
						case 2					:
							$this -> end_session();
							break;
						case 3					:
						default 				:
							$Authnews -> delete_cookie($Authnews -> cookiename, $subscriberauth);
							$Authnews -> delete_cookie($Authnews -> emailcookiename, $subscriberemailauth);
							$this -> end_session();
							break;
					}

					echo html_entity_decode(str_replace("\'", "'", str_replace('\n', '', esc_js($wpmljavascript))));
					$this -> render('management' . DS . 'logout-auth', false, true, 'default');
					break;
				case 'loginauth'			:
					if (empty($_GET['email'])) {
					    // phpcs:ignore
						$subscriberemailauth = $_POST['email'] = $Authnews -> read_emailcookie();
					} else {
						$subscriberemailauth = sanitize_text_field($_GET['email']);
					}

					$subscriberauth = sanitize_text_field($_GET['subscriberauth']);

					if (!empty($subscriberemailauth)) {
						if (!empty($subscriberauth)) {
							$Db -> model = $Subscriber -> model;							
							if ($subscriber = $Db -> find(array('email' => $subscriberemailauth, 'cookieauth' => $subscriberauth))) {
								global $wpmljavascript;
								$Authnews -> set_cookie($subscriber -> cookieauth);
								$Authnews -> set_emailcookie($subscriberemailauth);
							} else {
								$errors[] = __('Authentication failed, please try again.', 'wp-mailinglist');
							}
						} else {
							$errors[] = __('No authentication string passed, please click the link again.', 'wp-mailinglist');
						}
					} else {
						$errors[] = __('No email saved, please try again.', 'wp-mailinglist');
					}

					if (empty($errors)) {
						$this -> render('management' . DS . 'login-auth', array('subscriberauth' => $subscriberauth, 'subscriberemailauth' => $subscriberemailauth), true, 'default');
					} else {
						$this -> render('management' . DS . 'login', array('errors' => $errors), true, 'default');
					}
					break;
				case 'login'				:
					$errors = array_merge($errors, $newsletters_errors);
					$this -> render('management' . DS . 'login', array('errors' => $errors), true, 'default');
					break;
				default						:
					if (!empty($_GET['subscriberauth'])) {
						$_COOKIE['subscriberauth'] = esc_html($_GET['subscriberauth']);
					}

					if ($subscriber = $Authnews -> logged_in()) {												
						if ($this -> get_option('subscriptions') == "Y") {
							$SubscribersList -> check_expirations(false, false, true, $subscriber -> id);
						}

						$subscriber = $Authnews -> logged_in();
						$this -> render('management' . DS . 'index', array('subscriber' => $subscriber), true, 'default');
					} else {
						$this -> render('management' . DS . 'login', false, true, 'default');
					}
					break;
			}

			global $wpmljavascript;
			if (!empty($wpmljavascript)) {
				echo wp_kses_post($wpmljavascript);
			}

			$output = ob_get_clean();
			global $Html;
			$output = $Html -> fragment_cache($output, 'this', 'sc_management', false);
			return $output;
		}
                    

Code file location:

newsletters-lite/newsletters-lite/includes/checkinit.php

Newsletters [newsletters-lite_subscribe] Shortcode

The Newsletters-Lite plugin shortcode is designed to manage subscription forms. It dynamically creates a unique form ID, handles form submission, and displays confirmation messages. The shortcode checks if the form attribute is empty. If it is, it generates a random number for the form ID, stores it in a transient, and creates a new widget instance. It also sets default values for the form fields and prepares the subscription URL. If the form attribute isn’t empty, the shortcode retrieves the form based on the provided ID. It then checks if the form submission was successful and displays the form’s confirmation message. In both cases, the output is either the subscription form or the confirmation message.

Shortcode: [newsletters-lite_subscribe]

Parameters

Here is a list of all possible newsletters-lite_subscribe shortcode parameters and attributes:

  • form – Specifies the ID of the form to display.
  • list – Defines the type of list to display, default is “select”.
  • id – Unique identifier of the contact form.
  • lists – If set to false, no lists will be displayed.
  • ajax – If set to true, the form will be submitted via AJAX.
  • button – Defines the text displayed on the submit button.
  • captcha – If set to true, a captcha will be included in the form.
  • acknowledgement – Specifies the message displayed after successful form submission.

Examples and Usage

Basic example – Display a subscription form with default settings

[newsletters-lite-subscribe /]

Advanced examples

Display a subscription form with a specific form ID

[newsletters-lite-subscribe form=2 /]

Display a subscription form with AJAX enabled and a custom button text

[newsletters-lite-subscribe ajax=true button="Subscribe Now!" /]

Display a subscription form with a specific list and custom acknowledgement message

[newsletters-lite-subscribe list="Newsletter" acknowledgement="Thank you for subscribing!" /]

Display a subscription form with captcha enabled

[newsletters-lite-subscribe captcha=true /]
Please note that the actual shortcode to be used will depend on the prefix set in your Newsletter Lite plugin settings. In these examples, we’ve used “newsletters-lite-subscribe” as the shortcode.

PHP Function Code

In case you have difficulties debugging what causing issues with [newsletters-lite_subscribe] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode($this -> pre . 'subscribe', array($Shortcode, 'subscribe'));

Shortcode PHP function:

                    function subscribe($atts = array(), $content = null)
		{
			global $Html, $Subscriber, $post;
            $post_id = isset($post -> ID) ? $post -> ID : 0;

            if (is_feed()) {
                return;
            }

			if (empty($atts['form'])) {
				if ($rand_transient = get_transient('newsletters_shortcode_subscribe_rand_' . $post_id)) {
					$rand = $rand_transient;
				} else {
					$rand = rand(999, 9999);
					set_transient('newsletters_shortcode_subscribe_rand_' . $post_id, $rand, HOUR_IN_SECONDS);
				}

				$number = 'embed' . $rand;
				$widget_id = 'newsletters-' . $number;
				$instance = $this -> widget_instance($number, $atts);

				$defaults = array(
					'list' 				=> 	"select",
					'id' 				=> 	false,
					'lists'				=>	false,
					'ajax'				=>	$instance['ajax'],
					'button'			=>	$instance['button'],
					'captcha'			=>	$instance['captcha'],
					'acknowledgement'	=>	$instance['acknowledgement'],
				);

				$r = shortcode_atts($defaults, $atts);
				extract($r);

				$action = ($this -> language_do() && !empty($instance['language'])) ? $this -> language_converturl(sanitize_text_field(wp_unslash($_SERVER['REQUEST_URI'])), $instance['language']) : sanitize_text_field(wp_unslash($_SERVER['REQUEST_URI']));
				$action = $Html -> retainquery($this -> pre . 'method=optin', $action) . '#' . $widget_id;

				$output = "";
				$output .= '<div id="' . $widget_id . '" class="newsletters ' . $this -> pre . ' widget_newsletters">';
				$output .= '<div id="' . $widget_id . '-wrapper">';

				if (!empty($_GET['success'])) {
					$output .= '<div class="newsletters-acknowledgement">' . wp_kses_post(wpautop($instance['acknowledgement'])) . '</div>';
				} else {
					$output .= $this -> render('widget', array('action' => $action, 'errors' => $Subscriber -> errors, 'instance' => $instance, 'widget_id' => $widget_id, 'number' => $number), false, 'default');
				}

				$output .= '</div>';
				$output .= '</div>';
			} elseif (!empty($atts['form'])) {
				if ($form = $this -> Subscribeform() -> find(array('id' => $atts['form']))) {
					global ${'newsletters_form' . $form -> id . '_success'};
					if (!empty(${'newsletters_form' . $form -> id . '_success'})) {
						if (!empty($form -> confirmationtype) && $form -> confirmationtype == "message") {
							if (!empty($form -> confirmation_message)) {
								if (!empty($form -> confirmation_message) && WPMAIL() -> language_do()) {
									$language_live =   WPMAIL() -> language_current();
									$form -> confirmation_message = WPMAIL() -> language_use($language_live, $form -> confirmation_message);
								}
								$output = '<div class="newsletters-acknowledgement">' . wpautop(esc_html($form -> confirmation_message)) . '</div>';
							}
						}
					} else {
						$output = $this -> render('subscribe', array('form' => $form, 'errors' => $Subscriber -> errors), false, 'default');	
					}
				}
			}

			return $output;
		}
                    

Code file location:

newsletters-lite/newsletters-lite/includes/checkinit.php

Newsletters [newsletters_lite_template] Shortcode

The Newsletters-Lite plugin shortcode is used to fetch and display a specific template’s content. It retrieves the template based on the provided ‘id’ attribute. . This shortcode queries the database for the template with the given ID, processes any nested shortcodes, and applies the ‘newsletters_snippet’ filter before output.

Shortcode: [newsletters_lite_template]

Parameters

Here is a list of all possible newsletters_lite_template shortcode parameters and attributes:

  • id – Specifies the unique identifier of the template.

Examples and Usage

Basic example – A straightforward usage of the shortcode to display a template by referencing its ID.

[newsletters-lite-template id=1 /]

Advanced examples – Below are some advanced usage of the shortcode.

Displaying a template by referencing its ID and wrapping it with additional content.


[newsletters-lite-template id=1]
Additional content here
[/newsletters-lite-template]

Using the shortcode to display multiple templates by referencing their IDs. This would be useful if you want to display different templates in a particular order on a page.


[newsletters-lite-template id=1 /]
[newsletters-lite-template id=2 /]
[newsletters-lite-template id=3 /]

PHP Function Code

In case you have difficulties debugging what causing issues with [newsletters_lite_template] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode($this -> pre . 'template', array($Shortcode, 'template'));

Shortcode PHP function:

                    function template($atts = array(), $content = null)
		{
			global $wpdb;

			$defaults = array('id' => false);
			extract(shortcode_atts($defaults, $atts));

			if (!empty($id)) {
				$templatequery = "SELECT * FROM " . $wpdb -> prefix . parent::Template() -> table . " WHERE id = '" . esc_sql($id) . "' LIMIT 1";

				$query_hash = md5($templatequery);
				if ($ob_template = $this -> get_cache($query_hash)) {
					$template = $ob_template;
				} else {
					$template = $wpdb -> get_row($templatequery);
					$this -> set_cache($query_hash, $template);
				}

				if (!empty($template)) {
					$output = wpautop(do_shortcode(__(wp_unslash($template -> content))));
				}

				$output = apply_filters('newsletters_snippet', $output, $template);
			}

			return $output;
		}
                    

Code file location:

newsletters-lite/newsletters-lite/includes/checkinit.php

Newsletters [newsletters_lite_history] Shortcode

The Newsletters-Lite plugin shortcode is used to display a history of newsletters. It retrieves and lists newsletters based on specified conditions. This shortcode fetches newsletters from specific lists or all lists if no ID is provided. It allows sorting by modification date in descending order. It also limits the number of newsletters displayed, if specified.

Shortcode: [newsletters_lite_history]

Parameters

Here is a list of all possible newsletters_lite_history shortcode parameters and attributes:

  • number – Specifies the maximum number of histories to display.
  • order – Controls the sorting direction of the histories, either ascending (ASC) or descending (DESC).
  • orderby – Determines the parameter by which the histories will be sorted. Default is by “modified” date.
  • list_id – Filters the histories by mailing list ids. If not specified, all lists are considered.
  • linksonly – If set to true, only the links to the histories will be displayed.
  • index – If set to true, includes the index number of each history in the output.

Examples and Usage

Basic example – Display the history of sent newsletters with default settings

[newsletters_lite_history /]

Advanced examples:

Display the history of sent newsletters, limiting the output to 5 items, ordered by the date they were modified in ascending order.

[newsletters_lite_history number=5 order="ASC" orderby="modified" /]

Display the history of sent newsletters from a specific list, by referencing the list ID, and only display the links to the newsletters.

[newsletters_lite_history list_id=3 linksonly=true /]

Display the history of sent newsletters from multiple lists, by referencing their IDs, and limit the output to 10 items.

[newsletters_lite_history list_id="2,3,4" number=10 /]

Note: Replace “newsletters_lite_history” with the actual shortcode name for the Newsletters Lite plugin history function.

PHP Function Code

In case you have difficulties debugging what causing issues with [newsletters_lite_history] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode($this -> pre . 'history', array($Shortcode, 'history'));

Shortcode PHP function:

                    function history($atts = array(), $content = null)
		{
			global $wpdb, $Db, $HistoriesList, $Html;

			$output = "";

			$defaults = array(
				'number' 		=> 	false, 
				'order' 		=> 	"DESC", 
				'orderby' 		=> 	"modified", 
				'list_id' 		=> 	false, 
				'linksonly'		=>	false,
				'index' 		=> 	true
			);
				
			$r = shortcode_atts($defaults, $atts);
			extract($r);

			$listscondition = "";
			$l = 1;

			if (!empty($list_id)) {
				if ($mailinglists = explode(",", $list_id)) {
					$listscondition = " (";

					foreach ($mailinglists as $mailinglist_id) {
						$listscondition .= "" . $wpdb -> prefix . $HistoriesList -> table . ".list_id = '" . esc_sql($mailinglist_id) . "'";

						if (count($mailinglists) > $l) {
							$listscondition .= " OR ";
						}

						$l++;
					}

					$listscondition .= ")";
				}
			} else {
				$listscondition = " 1 = 1";
			}

			$query = "SELECT DISTINCT " . $wpdb -> prefix . $HistoriesList -> table . ".history_id, " .
			$wpdb -> prefix . parent::History() -> table . ".id, " .
			$wpdb -> prefix . parent::History() -> table . ".message, " .
			$wpdb -> prefix . parent::History() -> table . ".modified, " .
			$wpdb -> prefix . $HistoriesList -> table . ".history_id, " . $wpdb -> prefix . parent::History() -> table . ".subject FROM `" . $wpdb -> prefix . $HistoriesList -> table . "` LEFT JOIN `" .
			$wpdb -> prefix . parent::History() -> table . "` ON " .
			$wpdb -> prefix . $HistoriesList -> table . ".history_id = " . $wpdb -> prefix . parent::History() -> table . ".id" .
			" WHERE" . $listscondition . " AND " . $wpdb -> prefix . parent::History() -> table . ".sent > '0' && " . $wpdb -> prefix . parent::History() -> table . ".senddate <= '" . $Html -> gen_date() . "'" .
			" ORDER BY " . $wpdb -> prefix . parent::History() -> table . "." . esc_sql($orderby) . " " . esc_sql($order) . "";
            if (!empty($number)) {
                $query .= " LIMIT " . esc_sql($number) . "";
            }

			$query_hash = md5($query);
			if ($ob_emails = $this -> get_cache($query_hash)) {
				$emails = $ob_emails;
			} else {
				$emails = $wpdb -> get_results($query);
				$this -> set_cache($query_hash, $emails);
			}

			if (!empty($emails)) {
				$output = $this -> render('history', array('emails' => $emails, 'history_index' => $index, 'linksonly' => $linksonly), false, 'default');
				$output = wp_unslash(do_shortcode($output));
				return $output;
			}

			return $output;
		}
                    

Code file location:

newsletters-lite/newsletters-lite/includes/checkinit.php

Newsletters [newsletters_meta] Shortcode

The Newsletters-lite plugin shortcode ‘meta’ retrieves and displays custom metadata from posts. It accepts ‘post_id’ and ‘key’ as parameters. If ‘post_id’ is not provided, it uses the current post. If ‘key’ is empty, it displays all metadata, otherwise, it shows the value of the specified ‘key’.

Shortcode: [newsletters_meta]

Parameters

Here is a list of all possible newsletters_meta shortcode parameters and attributes:

  • post_id – The identifier of the post to retrieve metadata from.
  • key – The specific metadata key to retrieve from the post.

Examples and Usage

Basic example – Displays the metadata of a post by using the post’s ID.

[newsletters_meta post_id=123 /]

Advanced examples

Displaying the metadata of a post by using the post’s ID and specifying a key. This will output only the metadata value associated with the specified key.

[newsletters_meta post_id=123 key="custom_key" /]

Using the shortcode without specifying a post ID. This will display the metadata of the current post being viewed. This is useful when placed in a loop or within a single post template.

[newsletters_meta /]

Using the shortcode without specifying a post ID or key. This will display all metadata of the current post being viewed, in a list format.

[newsletters_meta /]

Using the shortcode to display a specific metadata of the current post by specifying only the key. This will output the value of the specified metadata key of the current post being viewed.

[newsletters_meta key="custom_key" /]
Please note that the actual output may vary depending on the metadata associated with the specified post ID or key.

PHP Function Code

In case you have difficulties debugging what causing issues with [newsletters_meta] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode($this -> pre . 'meta', array($Shortcode, 'meta'));

Shortcode PHP function:

                    function meta($atts = array(), $content = null)
		{
			global $post, $shortcode_post;

			$thepost = (empty($atts['post_id'])) ? ((empty($shortcode_post)) ? $post : $shortcode_post) : get_post($atts['post_id']);
			$atts['post_id'] = $thepost -> ID;

			$defaults = array(
				'post_id' 			=>	false,
				'key'				=>	false,
			);

			$allatts = shortcode_atts($defaults, $atts);
			extract($allatts);

			if (!empty($post_id)) {
				global $post_ID;
				$oldpostid = $post_ID;
				$post_ID = $post_id;

				ob_start();
				if (empty($key)) {
					the_meta();
				} else {
					echo get_post_meta($thepost -> ID, $key, true);
				}

				$content = ob_get_clean();

				$post_ID = $oldpostid;
			}

			return apply_filters('newsletters_meta_shortcode', $content, $allatts, $thepost);
		}
                    

Code file location:

newsletters-lite/newsletters-lite/includes/checkinit.php

Newsletters [datestring] Shortcode

The Newsletters-lite plugin shortcode allows users to display the current date in their desired format. Shortcode Name: Newsletters-lite plugin shortcode This shortcode retrieves the date format set in your WordPress settings, converts it to a PHP date format, and then displays the current date in that format. It also supports localization, adjusting the date format based on your site’s locale settings.

Shortcode: [datestring]

Parameters

Here is a list of all possible datestring shortcode parameters and attributes:

  • format – defines the date format to be displayed
  • time – specifies the time to be converted into the chosen format

Examples and Usage

Basic example – Utilizes the shortcode to display the current date as per the WordPress date format setting.

[newsletters_lite_date]

Advanced examples

Display the date in a specific format. In this example, the date will be displayed in the format of day/month/year.

[newsletters_lite_date format="d/m/Y"]

Display a specific date. In this case, the shortcode will display the date of “2022-12-31” in the format specified in the WordPress date format setting.

[newsletters_lite_date time="2022-12-31"]

Display a specific date in a specific format. Here, the date “2022-12-31” is displayed in the format of day/month/year.

[newsletters_lite_date format="d/m/Y" time="2022-12-31"]

PHP Function Code

In case you have difficulties debugging what causing issues with [datestring] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode($this -> pre . 'date', array($Shortcode, 'datestring'));

Shortcode PHP function:

                    function datestring($atts = array(), $content = null)
		{
			global $Html;
			
			$defaults = array(
				//'format'		=>	"%d/%m/%Y",
				'format'		=>	get_option('date_format'),
				'time'			=>	date_i18n('r'),
			);

			extract(shortcode_atts($defaults, $atts));
			$locale = get_locale();
			setlocale(LC_ALL, apply_filters('newsletters_setlocale', $locale));
			$format = $Html -> strftime_format_to_date_format($format);

			//$output = utf8_encode(date_i18n($format, strtotime($time)));
			$output = (date_i18n($format, strtotime($time)));
			return $output;
		}
                    

Code file location:

newsletters-lite/newsletters-lite/includes/checkinit.php

Newsletters [newsletters-lite-post] Shortcode

The Newsletters-lite plugin shortcode is designed to display single posts. It pulls a post based on ID, with options to show the date and customize thumbnail appearance. This shortcode also supports multilingual content, allowing users to set a specific language for the post. It can display the full post or an excerpt, and provides a choice of target for the link. Shortcode: [newsletters-lite-post] The shortcode provides flexibility in design with options for thumbnail size, alignment, horizontal space, and class. Users can also choose to hide the thumbnail if desired. Shortcode: [newsletters-lite-post]

Shortcode: [newsletters-lite-post]

Parameters

Here is a list of all possible newsletters-lite-post shortcode parameters and attributes:

  • post_id – Identifier of the post to display.
  • showdate – Determines if the post’s date is shown (“Y”) or not.
  • language – Specifies the language of the post.
  • eftype – Defines whether to show full text (“full”) or excerpt (“excerpt”).
  • target – Sets link target to either same (“_self”) or new (“_blank”) window.
  • thumbnail_size – Specifies the size of the post’s thumbnail image.
  • thumbnail_align – Sets the alignment of the thumbnail image.
  • thumbnail_hspace – Determines the horizontal space around the thumbnail.
  • thumbnail_class – Assigns a CSS class to the thumbnail for styling.
  • hidethumbnail – Decides whether to hide the thumbnail (“Y”) or not (“N”).

Examples and Usage

Basic example – Display a single post with its default settings.

[newsletters-lite-post post_id=1 /]

Advanced examples

Display a single post with a specific language, thumbnail alignment, and thumbnail size.

[newsletters-lite-post post_id=1 language="en" thumbnail_align="right" thumbnail_size="medium" /]

Display a single post without a date and with a custom excerpt type.

[newsletters-lite-post post_id=1 showdate="N" eftype="full" /]

Display a single post without a thumbnail and open the post in a new tab.

[newsletters-lite-post post_id=1 hidethumbnail="Y" target="_blank" /]

Note: Replace the ‘post_id’ value with the ID of the post you want to display.

PHP Function Code

In case you have difficulties debugging what causing issues with [newsletters-lite-post] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode($this -> pre . 'post', array($Shortcode, 'posts_single'));

Shortcode PHP function:

                    function posts_single($atts = array(), $content = null)
		{
			global $post, $shortcode_posts, $shortcode_post_language, $shortcode_post_showdate;
			$atts['post_id'] = (empty($atts['post_id'])) ? $post -> ID : $atts['post_id'];

			$output = "";
			$defaults = array(
				'post_id'			=> 	false,
				'showdate'			=>	"Y",
				'language'			=>	false,
				'eftype'			=>	"excerpt",
				'target'			=>	"_self",
				'thumbnail_size'		=>	"thumbnail",
				'thumbnail_align'		=>	"left",
				'thumbnail_hspace'		=>	"15",
				'thumbnail_class'		=>	"newsletters-thumbnail",
				'hidethumbnail'			=> 'N'
			);

			$r = shortcode_atts($defaults, $atts);
			extract($r);

			global $wpml_eftype;
			$wpml_eftype = $eftype;

			global $shortcode_thumbnail;
			$shortcode_thumbnail = array(
				'size'				=>	$thumbnail_size,
				'align'				=>	$thumbnail_align,
				'hspace'			=>	$thumbnail_hspace,
				'class'				=>	$thumbnail_class,
			);

			$arguments = array(
				'post_id'			=>	$post_id,
				'showdate'			=>	$showdate,
				'language'			=>	$language,
				'hidethumbnail'		=>  $hidethumbnail

			);

			if (!empty($language)) {
				$this -> language_set($language);
			}

			foreach ($r as $rkey => $rval) {
				global ${'wpml_' . $rkey};
				${'wpml_' . $rkey} = $rval;
			}

			if (!empty($post_id)) {
				if ($post = get_post($post_id)) {					
					$shortcode_post_showdate = $showdate;

					if ($this -> language_do()) {
						$shortcode_post_language = $language;
						$post = $this -> language_use($language, $post, false);
						$shortcode_posts = array($post);
						$output = do_shortcode($this -> et_message('posts', false, $language, '' ,  $arguments['hidethumbnail']));
					} else {
						$shortcode_posts = array($post);
						$output = do_shortcode($this -> et_message('posts', '' , '' , '', $arguments['hidethumbnail']), false, '');
					}
				}
			}

			wp_reset_query();
			return $output;
		}
                    

Code file location:

newsletters-lite/newsletters-lite/includes/checkinit.php

Newsletters [newsletters_posts_multiple] Shortcode

The Newsletters-Lite plugin shortcode is designed to fetch and display multiple posts. It offers customization options like post type, number of posts, order, and more. This shortcode allows you to specify the post type, number of posts, category, and order. It also gives you control over the thumbnail size, alignment, and class. In case no category is specified, it defaults to ‘false’. Moreover, it supports language customization. If a specific language is set, it adjusts the posts according to that language. After fetching the posts, it resets the query to avoid conflicts.

Shortcode: [newsletters_posts_multiple]

Parameters

Here is a list of all possible newsletters_posts_multiple shortcode parameters and attributes:

  • numberposts – Sets the number of posts to display.
  • showdate – Determines whether to show the post date or not.
  • orderby – Defines the parameter to sort the posts by.
  • order – Sets the order of the posts (ascending or descending).
  • category – Filters posts by a specific category.
  • language – Filters posts by a specific language.
  • post_type – Defines the type of posts to display.
  • eftype – Sets the type of excerpt to display.
  • target – Determines how the post link is opened.
  • thumbnail_size – Sets the size of the post thumbnail.
  • thumbnail_align – Defines the alignment of the post thumbnail.
  • thumbnail_hspace – Sets the horizontal spacing for the post thumbnail.
  • thumbnail_class – Assigns a CSS class to the post thumbnail.
  • hidethumbnail – Determines whether to hide the post thumbnail or not.

Examples and Usage

Basic example – Display the latest 10 posts with a thumbnail and post date.

[newsletters-posts]

Advanced examples

Display the latest 5 posts from a specific category, ordered by title in ascending order, without a thumbnail, and opening in a new tab.

[newsletters-posts numberposts=5 category="news" orderby="title" order="ASC" hidethumbnail="Y" target="_blank"]

Display the latest 10 posts of a custom post type, with a medium-sized thumbnail aligned to the right, with 20px horizontal space, and a custom thumbnail class.

[newsletters-posts numberposts=10 post_type="custom_post_type" thumbnail_size="medium" thumbnail_align="right" thumbnail_hspace="20" thumbnail_class="custom-thumbnail-class"]

Display the latest 10 posts, without showing the post date, sorted by post date in descending order, and a specific language.

[newsletters-posts numberposts=10 showdate="N" orderby="post_date" order="DESC" language="en_US"]

PHP Function Code

In case you have difficulties debugging what causing issues with [newsletters_posts_multiple] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode($this -> pre . 'posts', array($Shortcode, 'posts_multiple'));

Shortcode PHP function:

                    function posts_multiple($atts = array(), $content = null)
		{
			global $shortcode_posts, $shortcode_post_language, $shortcode_post_showdate;
			$output = "";

			$defaults = array(
				'numberposts' 			=> 	10,
				'showdate'				=>	"Y",
				'orderby' 				=> 	"post_date",
				'order' 				=> 	"DESC",
				'category' 				=> 	null,
				'language'				=>	false,
				'post_type'				=>	"post",
				'eftype'				=>	"excerpt",
				'target'				=>	"_self",
				'thumbnail_size'		=>	"thumbnail",
				'thumbnail_align'		=>	"left",
				'thumbnail_hspace'		=>	"15",
				'thumbnail_class'		=>	"newsletters-thumbnail",
				'hidethumbnail'			=> 'N'

			);

			$arguments = shortcode_atts($defaults, $atts);
            if (empty($arguments['category'])) {
                $arguments['category'] = false;
            }

			if (!empty($arguments['post_type'])) {
				if (($new_post_types = @explode(",", $arguments['post_type'])) !== false) {
					$arguments['post_type'] = $new_post_types;
				}
			}

			$currentlanguage = $arguments['language'];
			$arguments['suppress_filters'] = 0;
			extract($arguments);

			if (!empty($currentlanguage)) {
				$this -> language_set($currentlanguage);
			}

			global $wpml_eftype, $wpml_target;
			$wpml_eftype = $eftype;
			$wpml_target = $target;

			global $shortcode_thumbnail;
			$shortcode_thumbnail = array(
				'size'				=>	$thumbnail_size,
				'align'				=>	$thumbnail_align,
				'hspace'			=>	$thumbnail_hspace,
				'class'				=>	$thumbnail_class,
			);
			
			$arguments = apply_filters('newsletters_shortcode_posts_multiple_arguments', $arguments);

			if ($posts = get_posts($arguments)) {
				$shortcode_post_showdate = $showdate;

				if ($this -> language_do()) {
					$shortcode_post_language = $currentlanguage;
					foreach ($posts as $pkey => $post) {
						$posts[$pkey] = $this -> language_use($currentlanguage, $post, false);
					}

					$shortcode_posts = $posts;
					$output = do_shortcode($this -> et_message('posts', false, $language, '' ,  $arguments['hidethumbnail']));
					//$output = do_shortcode('[newsletters_posts_loop_wrapper]');
				} else {
					$shortcode_posts = $posts;
					$output = do_shortcode($this -> et_message('posts', '' , '' , '', $arguments['hidethumbnail']), false, '');
					//$output = do_shortcode('[newsletters_posts_loop_wrapper]');
				}
			}

			wp_reset_query();
			return $output;
		}
                    

Code file location:

newsletters-lite/newsletters-lite/includes/checkinit.php

Newsletters [post_permalink] Shortcode

The Newsletters-Lite plugin shortcode ‘post_permalink’ retrieves the permalink of a specified post. It uses the post ID to fetch the permalink, and if no ID is provided, it defaults to the current post.

Shortcode: [post_permalink]

Parameters

Here is a list of all possible post_permalink shortcode parameters and attributes:

  • post_id – Specifies the unique identifier of the WordPress post

Examples and Usage

Basic example – A simple usage of the shortcode to fetch and display the permalink of the current post.

[newsletters-lite-post_permalink /]

Advanced examples

Using the shortcode to fetch and display the permalink of a specific post by providing the post ID as a parameter.

[newsletters-lite-post_permalink post_id=123 /]

Using the shortcode within a text to create a hyperlink to a specific post. The link text is provided as the content of the shortcode.

Check out our latest post: Latest Post

Note: In the above examples, replace ‘123’ with the actual ID of the post you want to link to.

PHP Function Code

In case you have difficulties debugging what causing issues with [post_permalink] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode($this -> pre . 'post_permalink', array($Shortcode, 'post_permalink'));

Shortcode PHP function:

                    function post_permalink($atts = array(), $content = null)
		{
			global $post;
			$output = "";
			$post_id = (empty($atts['post_id'])) ? $post -> ID : $atts['post_id'];

			if ($permalink = get_permalink($post_id)) {
				$output .= $permalink;
			}

			wp_reset_query();
			return $output;
		}
                    

Code file location:

newsletters-lite/newsletters-lite/includes/checkinit.php

Newsletters [subscriberscount] Shortcode

The Newsletters-Lite plugin shortcode ‘subscriberscount’ is designed to count the total number of subscribers. It fetches the count from the database and displays it on your website. The shortcode has an optional ‘list’ attribute which, if specified, counts the subscribers of a specific mailing list. If left empty, it counts all subscribers.

Shortcode: [subscriberscount]

Parameters

Here is a list of all possible subscriberscount shortcode parameters and attributes:

  • list – specifies the mailing list to count subscribers from

Examples and Usage

Basic Example – Displaying the total number of subscribers in a specific mailing list

[newsletters-lite-subscriberscount list=3 /]
In this example, we’re using the shortcode to display the total number of subscribers in the mailing list with the ID of 3. The ‘list’ parameter is used to specify the ID of the mailing list.

Advanced Examples

Displaying the total number of subscribers without specifying a mailing list

[newsletters-lite-subscriberscount /]
In this advanced example, we’re using the shortcode without any parameters. This will display the total number of subscribers across all mailing lists.

Displaying the total number of subscribers in multiple mailing lists

[newsletters-lite-subscriberscount list=3,5,7 /]
In this example, we’re using the shortcode to display the total number of subscribers in multiple mailing lists. The ‘list’ parameter is used to specify the IDs of the mailing lists, separated by commas.

PHP Function Code

In case you have difficulties debugging what causing issues with [subscriberscount] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode($this -> pre . 'subscriberscount', array($Shortcode, 'subscriberscount'));

Shortcode PHP function:

                    function subscriberscount($atts = array(), $content = null)
		{
			global $wpdb, $Subscriber, $SubscribersList, $Mailinglist;
			$subscriberscount = 0;

			$defaults = array(
				'list'				=>	false
			);

			extract(shortcode_atts($defaults, $atts));

			if (!empty($list)) {
				$query = "SELECT COUNT(`rel_id`) FROM " . $wpdb -> prefix . $SubscribersList -> table . " LEFT JOIN "
				. $wpdb -> prefix . $Mailinglist -> table . " ON " . $wpdb -> prefix . $SubscribersList -> table . ".list_id = "
				. $wpdb -> prefix . $Mailinglist -> table . ".id WHERE " . $wpdb -> prefix . $Mailinglist -> table . ".id = '" . esc_sql($list) . "'";
			} else {
				$query = "SELECT COUNT(`id`) FROM `" . $wpdb -> prefix . $Subscriber -> table . "`";
			}

			$query_hash = md5($query);
			if ($ob_count = $this -> get_cache($query_hash)) {
				$count = $ob_count;
			} else {
				$count = $wpdb -> get_var($query);
				$this -> set_cache($query_hash, $count);
			}

			if (!empty($count)) {
				$subscriberscount = $count;
			}

			return $subscriberscount;
		}
                    

Code file location:

newsletters-lite/newsletters-lite/includes/checkinit.php

Newsletters [newsletters_activate] Shortcode

The Newsletters-Lite plugin shortcode activates a new subscriber. It generates an activation link that’s sent to the user, and upon clicking, the subscriber is authenticated and added to the mailing list.

Shortcode: [newsletters_activate]

Parameters

Here is a list of all possible newsletters_activate shortcode parameters and attributes:

  • class – Assigns the CSS class to the activation link
  • style – Defines inline CSS styles for the activation link
  • urlonly – If set to true, only URL will be returned without the HTML anchor tag

Examples and Usage

Basic example – The following shortcode activates the newsletter plugin with the default settings. It uses the ID of the current subscriber and theme.

[newsletters-lite-activate /]

Advanced examples

The shortcode below activates the newsletter plugin with a specific style. The ‘style’ attribute allows you to customize the color of the activation link.

[newsletters-lite-activate style="color:red;" /]

In this example, the shortcode is used to display the activation link as a URL only, without any HTML or styling. This is useful if you want to include the link in a plain text email or document. The ‘urlonly’ attribute is set to ‘true’ to achieve this.

[newsletters-lite-activate urlonly=true /]

In the next example, the shortcode is used to activate the newsletter plugin with a custom class. The ‘class’ attribute is used to add a custom CSS class to the activation link. This allows you to style the link using your own CSS rules.

[newsletters-lite-activate class="my-custom-class" /]

Lastly, you can combine multiple attributes in the same shortcode. This example shows how to activate the newsletter plugin with a custom style, as a URL only, and with a custom class.

[newsletters-lite-activate style="color:blue;" urlonly=true class="my-custom-class" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [newsletters_activate] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode($this -> pre . 'activate', array($Shortcode, 'activate'));

Shortcode PHP function:

                    function activate($atts = array(), $content = null)
		{
			global $Html, $current_subscriber, $current_theme_id, $Subscriber;
			$output = '';

			$subscriber = $current_subscriber;
			$theme_id = $current_theme_id;

			if (!empty($theme_id)) {
				global $wpdb, $Theme;

				$acolorquery = "SELECT `acolor` FROM `" . $wpdb -> prefix . $Theme -> table . "` WHERE `id` = '" . esc_sql($theme_id) . "' LIMIT 1";

				$query_hash = md5($acolorquery);
				if ($ob_acolor = $this -> get_cache($query_hash)) {
					$acolor = $ob_acolor;
				} else {
					$acolor = $wpdb -> get_var($acolorquery);
					$this -> set_cache($query_hash, $acolor);
				}

				$style = "color:" . $acolor . ";";
			}

			$defaults = array(
				'class'				=>	"newsletters_link newsletters_activate",
                'style'				=>	isset($style) ? $style : '',
				'urlonly'			=>	false,
			);

			$r = shortcode_atts($defaults, $atts);
			extract($r);

			if (!empty($subscriber)) {				
				$linktext = apply_filters('newsletters_activation_link_text', esc_html($this -> get_option('activationlinktext')));
				$authkey = $this -> gen_auth($subscriber -> id, (!empty($subscriber -> mailinglist_id) ? $subscriber -> mailinglist_id : false));
				$mailinglist_id = (empty($subscriber -> mailinglists)) ? $subscriber -> mailinglist_id : @implode(",", $Subscriber -> mailinglists($subscriber -> id, false, false, false));

				$querystring = $this -> pre . 'method=activate&' . $this -> pre . 'subscriber_id=' . $subscriber -> id . '&' . $this -> pre . 'mailinglist_id=' . $mailinglist_id . '&authkey=' . $authkey;
				$url = $Html -> retainquery($querystring, $this -> get_managementpost(true));

				if (empty($subscriber -> format) || $subscriber -> format == "html" || !empty($urlonly)) {
					$activationlink = '<a class="newsletters_activate newsletters_link" href="' . $url . '" title="' . $linktext . '" style="' . $style . '">' . $linktext . '</a>';
				} else {
					$activationlink = $url;
				}

				$output = apply_filters('newsletters_activation_link', $activationlink, $url, $linktext, $style, $linktext);
			}

			return $output;
		}
                    

Code file location:

newsletters-lite/newsletters-lite/includes/checkinit.php

Newsletters [newsletters_video] Shortcode

The Newsletters Lite plugin shortcode is a function that embeds a video into your post. It accepts parameters like URL, width, and height. This shortcode checks if a URL is provided, then it uses the autoembed_callback function to embed the video.

Shortcode: [newsletters_video]

Parameters

Here is a list of all possible newsletters_video shortcode parameters and attributes:

  • url – The web address of the video to be embedded.
  • width – The display width of the embedded video.
  • height – The display height of the embedded video.

Examples and Usage

Basic example – A simple way to embed a video using the ‘newsletters_video’ shortcode. This example only requires the URL parameter, which is the link to the video you want to embed.

[newsletters_video url="https://www.youtube.com/watch?v=dQw4w9WgXcQ" /]

Advanced examples

Here, we are embedding a video with specified width and height parameters. By setting the width and height, you can alter the size of the video player to better fit your website’s layout. If these parameters are not provided, the video player will default to its standard size.

[newsletters_video url="https://www.youtube.com/watch?v=dQw4w9WgXcQ" width="500" height="300" /]

Another advanced usage could be to embed multiple videos with different sizes. Here, the first video will have a width of 500 and a height of 300, while the second video will have a width of 700 and a height of 400.

[newsletters_video url="https://www.youtube.com/watch?v=dQw4w9WgXcQ" width="500" height="300" /]
[newsletters_video url="https://www.youtube.com/watch?v=3tmd-ClpJxA" width="700" height="400" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [newsletters_video] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('newsletters_video', array($Shortcode, 'video'));

Shortcode PHP function:

                    function video($atts = array(), $content = null)
		{
			$output = "";

			$defaults = array(
				'url'			=>	false,
				'width'			=>	false,
				'height'		=>	false,
			);

			extract(shortcode_atts($defaults, $atts));

			if (!empty($url)) {
				$output = $this -> autoembed_callback($url, $width, $height);
			}

			return $output;
		}
                    

Code file location:

newsletters-lite/newsletters-lite/includes/checkinit.php

Newsletters [newsletters_bloginfo] Shortcode

The Newsletters-Lite Plugin shortcode is a powerful tool for retrieving and displaying specific blog information. This shortcode allows users to customize the ‘show’ and ‘filter’ parameters. The ‘show’ parameter specifies the type of blog information to display, such as the blog’s name. The ‘filter’ parameter lets users adjust the format of the displayed information. By default, it will display the blog’s name in raw format. If no value is specified, it will not return anything. The returned value is then unslashed for proper display.

Shortcode: [newsletters_bloginfo]

Parameters

Here is a list of all possible newsletters_bloginfo shortcode parameters and attributes:

  • show – Defines the specific blog information to display
  • filter – Determines how the blog information is processed before it’s displayed

Examples and Usage

Basic example – Display the blog name using the shortcode.

[newsletters_bloginfo show="name" /]

Advanced examples

Display the raw blog description using the shortcode. The raw filter will return the description without any HTML tags or formatting.

[newsletters_bloginfo show="description" filter="raw" /]

Display the blog language using the shortcode. This can be useful for multi-language websites to dynamically display the current language.

[newsletters_bloginfo show="language" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [newsletters_bloginfo] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('newsletters_bloginfo', array($Shortcode, 'bloginfo'));

Shortcode PHP function:

                    function bloginfo($atts = array(), $content = null)
		{
			$output = "";

			$defaults = array(
				'show'			=>	"name",
				'filter'		=>	"raw",
			);

			extract(shortcode_atts($defaults, $atts));

			if (!empty($show)) {
				if ($value = get_bloginfo($show, $filter)) {
					$output = __(wp_unslash($value));
				}
			}

			return $output;
		}
                    

Code file location:

newsletters-lite/newsletters-lite/includes/checkinit.php

Newsletters [newsletters_pluginurl] Shortcode

The Newsletters-Lite plugin shortcode ‘newsletters_pluginurl’ is designed to generate a URL. This shortcode starts the function ‘url’ which checks if a string starts with ‘url(‘. If true, it creates a string in the format ‘url([output])’. .

Shortcode: [newsletters_pluginurl]

Examples and Usage

Basic example – The shortcode “newsletters_pluginurl” is primarily used to return the URL of the Newsletters Lite plugin. It doesn’t require any parameters to function.

[newsletters_pluginurl /]

Advanced examples – Although the basic usage of this shortcode doesn’t require any parameters, it can be extended with custom PHP code to accept and process parameters. Here are a few examples:

Example 1: Adding a parameter to return a specific file URL within the plugin directory:

[newsletters_pluginurl file="readme.txt" /]

Example 2: Adding a parameter to return a specific asset URL within the plugin directory:

[newsletters_pluginurl asset="images/logo.png" /]

Please note, these advanced examples require additional PHP code to process the parameters and aren’t supported by the shortcode in its original form. You would need to modify the function “url” in the plugin’s PHP code to accept and process these parameters.

PHP Function Code

In case you have difficulties debugging what causing issues with [newsletters_pluginurl] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('newsletters_pluginurl', array($this, 'url'));

Shortcode PHP function:

                    function url(&$out)
    {
        if ($this->literal('url(', 4)) {
            $s = $this->count;

            if (
                ($this->string($out) || $this->spaceList($out)) &&
                $this->matchChar(')')
            ) {
                $out = [Type::T_STRING, '', ['url(', $out, ')']];

                return true;
            }

            $this->seek($s);

            if (
                $this->openString(')', $out) &&
                $this->matchChar(')')
            ) {
                $out = [Type::T_STRING, '', ['url(', $out, ')']];

                return true;
            }
        }

        return false;
    }
                    

Code file location:

newsletters-lite/newsletters-lite/includes/checkinit.php

Newsletters [newsletters_subscribe_link] Shortcode

The Newsletters-Lite plugin shortcode ‘newsletters_subscribe_link’ enables users to create a subscription link. It uses global subscriber data and list details to generate the URL.

Shortcode: [newsletters_subscribe_link]

Parameters

Here is a list of all possible newsletters_subscribe_link shortcode parameters and attributes:

  • list – refers to the specific newsletter list to be subscribed to
  • content – customizes the display text on the subscription link

Examples and Usage

Basic example – The shortcode ‘newsletters_subscribe_link’ enables the user to create a subscription link. In its simplest form, the shortcode can be used without any attributes or parameters.

[newsletters_subscribe_link]

Advanced examples

Adding a ‘list’ attribute to the shortcode allows you to specify a particular mailing list for the subscription. This can be useful if you have multiple mailing lists and want to direct subscribers to a specific one.

[newsletters_subscribe_link list="5"]

The ‘content’ attribute allows you to customize the text of the subscription link. By default, the text is ‘Subscribe’, but you can change it to anything you like. In the example below, the subscription link text is changed to ‘Join our mailing list’.

[newsletters_subscribe_link content="Join our mailing list"]

You can also combine multiple attributes in a single shortcode. In the following example, the shortcode creates a subscription link for mailing list 5 with the custom text ‘Join our mailing list’.

[newsletters_subscribe_link list="5" content="Join our mailing list"]

PHP Function Code

In case you have difficulties debugging what causing issues with [newsletters_subscribe_link] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('newsletters_subscribe_link', array($Shortcode, 'subscribe_link'));

Shortcode PHP function:

                    function subscribe_link($atts = array(), $content = null)
		{
			global $current_subscriber;
			$content = (empty($content)) ? __('Subscribe', 'wp-mailinglist') : $content;

			$output = "";

			$defaults = array(
				'list'			=>	false,
			);

			$r = shortcode_atts($defaults, $atts);
			extract($r);

			if (!empty($current_subscriber) && !empty($list)) {
				$url = $this -> gen_subscribe_url($current_subscriber, $list);
				$output = '<a href="' . $url . '" class="newsletters_subscribe newsletters_link">' . esc_attr(wp_unslash($content)) . '</a>';
			}

			return $output;
		}
                    

Code file location:

newsletters-lite/newsletters-lite/includes/checkinit.php

Newsletters [newsletters_authenticate] Shortcode

The Newsletters-Lite plugin shortcode ‘newsletters_authenticate’ allows users to verify their subscription. It generates an authentication link that, when clicked, confirms the subscriber’s identity. This shortcode uses global variables and the shortcode attributes to create a URL with a unique authentication parameter. If the subscriber is recognized, the ‘Authenticate now’ link is displayed.

Shortcode: [newsletters_authenticate]

Parameters

Here is a list of all possible newsletters_authenticate shortcode parameters and attributes:

  • class – Defines the CSS class of the authentication link.
  • style – Adds custom CSS styles to the authentication link.
  • content – Sets the text of the authentication link. If not provided, it defaults to “Authenticate now”.

Examples and Usage

Basic example – The shortcode is used to authenticate a subscriber. It checks if the subscriber object is not empty and generates an authentication link for the current subscriber. If no text is provided, it defaults to ‘Authenticate now’.

[newsletters_authenticate]

Advanced examples

Styling the authentication link with inline CSS. Here, the shortcode is used with an additional ‘style’ attribute to apply inline CSS to the authentication link.

[newsletters_authenticate style="color: red; font-size: 20px;"]

Changing the class of the authentication link. In this example, the ‘class’ attribute is used to change the CSS class of the authentication link to ‘custom_class’.

[newsletters_authenticate class="custom_class"]

Providing custom text for the authentication link. This example shows how to use the ‘content’ attribute to provide custom text for the authentication link. If the ‘content’ attribute is not provided, the text defaults to ‘Authenticate now’.

[newsletters_authenticate]Click here to authenticate[/newsletters_authenticate]

PHP Function Code

In case you have difficulties debugging what causing issues with [newsletters_authenticate] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('newsletters_authenticate', array($Shortcode, 'authenticate'));

Shortcode PHP function:

                    function authenticate($atts = array(), $content = null)
		{
			global $Html, $current_subscriber;

			$output = '';

			$defaults = array(
				'class'				=>	"newsletters_link newsletters_authenticate",
				'style'				=>	"",
			);

			$r = shortcode_atts($defaults, $atts);
			extract($r);

			if (!empty($current_subscriber)) {
				$subscriberauth = $this -> gen_auth($current_subscriber -> id);
				$url = $Html -> retainquery('method=loginauth&email=' . $current_subscriber -> email . '&subscriberauth=' . $subscriberauth, $this -> get_managementpost(true));
				$text = (!empty($content)) ? $content : $this -> get_option('authenticatelinktext');
                if (empty($text)) {
                    $text = __('Authenticate now', 'wp-mailinglist');
                }
                $link = '<a href="' . $url . '" class="' . esc_attr(wp_unslash($class)) . '" style="' . esc_attr(wp_unslash($style)) . '">' . esc_attr(wp_unslash(__($text))) . '</a>';

				$output = $link;
			}

			return $output;
		}
                    

Code file location:

newsletters-lite/newsletters-lite/includes/checkinit.php

Newsletters [newsletters_sendas] Shortcode

The Newsletters-Lite plugin shortcode ‘newsletters_sendas’ enables the customization of newsletter content. It allows users to specify post details, choose language, and set thumbnail properties. This shortcode extracts post details using the post ID. It also sets the language, date visibility, and excerpt type. The thumbnail properties can be adjusted for size, alignment, horizontal spacing, and class. The shortcode then checks the language and adjusts the content accordingly. If a post ID is specified, it fetches the post and includes it in the newsletter. The shortcode finally resets the query and returns the output.

Shortcode: [newsletters_sendas]

Parameters

Here is a list of all possible newsletters_sendas shortcode parameters and attributes:

  • post_id – Specifies the ID of the post to be displayed
  • showdate – Controls whether to show the date (“Y”) or not
  • language – Sets the language for the post
  • eftype – Chooses between “excerpt” or full post content
  • target – Sets the target for the post link, “_self” for same tab
  • thumbnail_size – Sets the size of the post’s thumbnail
  • thumbnail_align – Aligns the thumbnail to the “left”
  • thumbnail_hspace – Determines the horizontal space around the thumbnail
  • thumbnail_class – Applies a specific CSS class to the thumbnail

Examples and Usage

Basic example – Display a specific post with its thumbnail and date.

[newsletters_sendas post_id=1 showdate="Y" thumbnail_size="thumbnail" /]

Advanced examples

Display a specific post with custom thumbnail alignment, horizontal space and class. The thumbnail will be aligned to the right with a horizontal space of 20 and a custom class named “my-custom-thumbnail”.

[newsletters_sendas post_id=1 thumbnail_size="thumbnail" thumbnail_align="right" thumbnail_hspace="20" thumbnail_class="my-custom-thumbnail" /]

Display a specific post with a specific language. The post will be displayed in Spanish if available.

[newsletters_sendas post_id=1 language="es" /]

Display a specific post with a custom excerpt type and target. The excerpt type will be set to “full” and the target will be set to “_blank” which means the link will open in a new tab or window.

[newsletters_sendas post_id=1 eftype="full" target="_blank" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [newsletters_sendas] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('newsletters_sendas', array($Shortcode, 'posts_sendas'));

Shortcode PHP function:

                    function posts_sendas($atts = array(), $content = null)
		{
			global $post, $shortcode_posts, $shortcode_sendas, $shortcode_categories, $shortcode_post_language, $shortcode_post_showdate;
			$atts['post_id'] = (empty($atts['post_id'])) ? $post -> ID : $atts['post_id'];

			$shortcode_posts = false;
			$shortcode_sendas = false;
			$shortcode_categories = false;

			$output = "";
			$defaults = array(
				'post_id'			=> 	false,
				'showdate'			=>	"Y",
				'language'			=>	false,
				'eftype'			=>	"excerpt",
				'target'			=>	"_self",
				'thumbnail_size'		=>	"thumbnail",
				'thumbnail_align'		=>	"left",
				'thumbnail_hspace'		=>	"15",
				'thumbnail_class'		=>	"newsletters-thumbnail",
			);

			$r = shortcode_atts($defaults, $atts);
			extract($r);

			global $wpml_eftype;
			$wpml_eftype = $eftype;

			global $shortcode_thumbnail;
			$shortcode_thumbnail = array(
				'size'				=>	$thumbnail_size,
				'align'				=>	$thumbnail_align,
				'hspace'			=>	$thumbnail_hspace,
				'class'				=>	$thumbnail_class,
			);

			$arguments = array(
				'post_id'			=>	$post_id,
				'showdate'			=>	$showdate,
				'language'			=>	$language,
			);

			if (!empty($language)) {
				$this -> language_set($language);
			}

			foreach ($r as $rkey => $rval) {
				global ${'wpml_' . $rkey};
				${'wpml_' . $rkey} = $rval;
			}

			if (!empty($post_id)) {
				if ($post = get_post($post_id)) {
					$shortcode_post_showdate = $showdate;

					if ($this -> language_do()) {
						$shortcode_post_language = $language;
						$post = $this -> language_use($language, $post, false);
						$shortcode_sendas = array($post);
						$output = do_shortcode($this -> et_message('sendas', false, $language));
						//$output = do_shortcode('[newsletters_posts_loop_wrapper]');
					} else {
						$shortcode_sendas = array($post);
						$output = do_shortcode($this -> et_message('sendas'));
						//$output = do_shortcode('[newsletters_posts_loop_wrapper]');
					}
				}
			}

			wp_reset_query();
			return $output;
		}
                    

Code file location:

newsletters-lite/newsletters-lite/includes/checkinit.php

Newsletters [newsletters_woocommerce_products] Shortcode

The ‘newsletters_woocommerce_products’ shortcode from the Newsletters-Lite plugin displays WooCommerce products in a newsletter. It’s highly customizable, allowing control over elements like product image, title, price, and ‘Buy Now’ button. The shortcode fetches product data, formats it into a table, and styles it responsively for mobile screens. It also supports featured and best-selling products.

Shortcode: [newsletters_woocommerce_products]

Parameters

Here is a list of all possible newsletters_woocommerce_products shortcode parameters and attributes:

  • perrow – Sets the number of products displayed per row.
  • number – Sets the total number of products to be displayed.
  • featured – If set to 1, only featured products are displayed.
  • bestselling – If set to 1, only best selling products are displayed.
  • showimage – If set to 1, the product image is displayed.
  • imagesize – Sets the size of the product images to be displayed.
  • showtitle – If set to 1, the product title is displayed.
  • showprice – If set to 1, the product price is displayed.
  • showbutton – If set to 1, a purchase button is displayed.
  • buttontext – Sets the text to be displayed on the purchase button.
  • orderby – Sets the parameter to sort the products by.
  • order – Sets the order of the products to be ascending or descending.

Examples and Usage

Basic example – Displaying the latest 9 products in a 3-column layout.

[newsletters_woocommerce_products perrow=3 number=9 /]

Advanced examples

Displaying the latest 6 featured products in a 2-column layout, showing only the product image and title, and a custom button text.

[newsletters_woocommerce_products perrow=2 number=6 featured=1 showprice=0 showbutton=1 buttontext="View Product" /]

Displaying the top 5 best-selling products in a single row, showing the product image, title, and price, ordered by total sales.

[newsletters_woocommerce_products perrow=1 number=5 bestselling=1 orderby="total_sales" order="DESC" /]

Displaying 4 products in a 4-column layout, with a specific image size, and showing only the product image and custom button text.

[newsletters_woocommerce_products perrow=4 number=4 showtitle=0 showprice=0 showbutton=1 imagesize="medium" buttontext="Buy Now" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [newsletters_woocommerce_products] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('newsletters_woocommerce_products', array($Shortcode, 'woocommerce_products'));

Shortcode PHP function:

                    function woocommerce_products($atts = array())
		{
			global $woocommerce;
			
			$output = '';
			
			$defaults = array(
				'perrow'			=>	3,
				'number'			=>	9,
				'featured'			=>	0,
				'bestselling'		=>	0,
				// Image settings
				'showimage'			=>	1,
				'imagesize'			=>	'thumbnail',
				// Title settings
				'showtitle'			=>	1,
				// Price settings
				'showprice'			=>	1,
				// Button settings
				'showbutton'		=>	1,
				'buttontext'		=>	__('Buy Now', 'wp-mailinglist'),
				'orderby'			=>	'post_date',
				'order'				=>	"DESC",
			);
			
			extract(shortcode_atts($defaults, $atts, 'woocommerce_products'));
			
			if (strpos($imagesize, ',') !== false) {
				$sizes = explode(",", $imagesize);
				if (!empty($sizes) && is_array($sizes)) {
					$imagesize = $sizes;
				}
			}
			
			// Fetch products
			$params = array(
				'posts_per_page'		=>	$number,
				'post_type'				=>	'product',
				'orderby'				=>	$orderby,
				'order'					=>	$order,
			);
			
			if (!empty($featured) && $featured == 1) {
				$params['post__in'] = wc_get_featured_product_ids();
			}
			
			if (!empty($bestselling) && $bestselling == 1) {
				$params['meta_key'] = 'total_sales';
				$params['orderby'] = 'meta_value_num';
			}
			
			$wc_query = new WP_Query($params);
			
			$c = 0;
			$breaker = $perrow;
			
			if ($wc_query -> have_posts()) {
				$output .= '<div class="newsletters-wc-products">';
				$output .= '<table width="100%" border="0" cellspacing="0" cellpadding="0" style="table-layout:fixed;">
	            <tr>
	                <td>
	                    <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" class="mobilewrapper">
	                        <tr>
	                            <td>
	                                <table width="100%" border="0" cellspacing="0" cellpadding="0" class="mobilewrapper" align="center">';
				
				while ($wc_query -> have_posts()) {
	                $wc_query -> the_post();
	                $product_id = get_the_ID();
					$currency = get_woocommerce_currency_symbol();
					$product = wc_get_product($product_id);
					$price = $product -> get_price();
					$image = get_the_post_thumbnail_url($product_id, $imagesize, null);
					$title = __(get_the_title());
	                
	                if ($c == 0 || $c%$breaker == 0) {
						$output .= '<tr>';
					}
					
					$output .= '<th align="center" class="colsplit">';
					$output .= '<table class="contents">';
					$output .= '<tr>';
					$output .= '<td class="product">';
					
					if (!empty($showimage)) {
						$output .= '<a href="' . get_permalink($product_id) . '"><img class="email-image" src="' . $image . '" alt="' . esc_html($title) . '" /></a>';
					}
					
					if (!empty($showtitle)) {
						$output .= '<h4 class="product-title"><a href="' . get_permalink($product_id) . '">' . $title . '</a></h4>';
					}
					
					if (!empty($showprice)) {
						$output .= '<p class="price">' . $currency . $price . '</p>';
					}
					
					if (!empty($showbutton)) {
						$output .= '<div class="button"><a href="' . get_permalink($product_id) . '">' . esc_html($buttontext) . '</a></div>';
					}
					
					$output .= '</td>';
					$output .= '</tr>';
					$output .= '</table>';
					$output .= '</th>';
	                
	                $c++;
	                if ($c%$breaker == 0 || $c == count((empty($wc_query -> posts_count) ? array() : ($wc_query -> posts_count)))) {
		             	$output .= '</tr>'; 
		            }
                }
                
	                $output .= '</table>
			                            </td>
			                        </tr>
			                    </table>
			                </td>
			            </tr>
			        </table>';
                
                $output .= '<style type="text/css">
                .newsletters-wc-products table {
	            	width: 100%;   
	            }
	            
	            .newsletters-wc-products td, 
	            .newsletters-wc-products th {
		        	border: none;   
		        }
		        
		        .newsletters-wc-products .colsplit {
			        width: ' . round(100 / $perrow) . '%;
			    }
		        
		        .newsletters-wc-products td.product {
			    	padding: 0 4% 10% 4%;   
			    	text-align: center;
			    }
			    
			    .newsletters-wc-products .email-image {
				    width: 100%;
				    max-width: 100%;
				    height: auto;
					margin-bottom: 15px;   
				}
				
				.newsletters-wc-products .price {
					font-weight:bold;
					font-size:24px;
					color:#666;
					margin-bottom:15px;
					margin-top:15px;
				}
				
				.newsletters-wc-products .product-title {
					display: block;
					text-align: center;
				}
				
				.newsletters-wc-products .button {
					padding: 0;
					text-decoration:none;
					text-transform: uppercase;
					display:inline-block;
				}
                
                <style type="text/css" data-premailer="ignore">
				@media screen and (max-device-width: 600px), screen and (max-width: 600px) {
					.mobilewrapper{
						width: 100% !important; 
						height: auto !important;
					}
					
					.colsplit{
						width: 100% !important; 
						float: left !important; 
						display:block !important;
					}
					
					.newsletters-wc-products .product {
						padding: 0 0 10% 0 !important;	
					}	
				}
				</style>';

				wp_reset_postdata();
			} else {
				$output = __('No products are available', 'wp-mailinglist');
			}
			
			return $output;
		}
                    

Code file location:

newsletters-lite/newsletters-lite/includes/checkinit.php

Newsletters [shortcode_posts] Shortcode

The Newsletters-Lite Plugin shortcode is a powerful tool for managing and displaying posts. This shortcode allows you to fetch and display posts based on specific attributes, such as category or author. It also supports the display of post thumbnails and the creation of post loops. Additionally, it provides flexibility in terms of content display, offering options for full content, excerpt, or custom length. This shortcode is highly customizable, making it a versatile tool for content management in WordPress.

Shortcode: [shortcode_posts]

Parameters

Here is a list of all possible shortcode_posts shortcode parameters and attributes:

  • style – defines the style of the shortcode output
  • category_heading – displays the heading of the category
  • post_loop – loops through the posts in a category
  • post_id – displays the unique identifier of the post
  • post_author – shows the author of the post
  • post_anchor – creates a link to the post
  • post_title – displays the title of the post
  • post_link – provides a direct link to the post
  • post_date_wrapper – wraps the post date in a specific format
  • post_date – shows the date the post was published
  • post_thumbnail – displays the post’s thumbnail image
  • post_excerpt – presents a short summary of the post
  • post_content – displays the full content of the post

Examples and Usage

Basic example – Displaying post content by referencing post ID

[shortcode_posts post_id=1 /]

Advanced examples

Using the shortcode to display a post title and author of a specific post by referencing the post ID

[shortcode_posts post_id=1 tag='post_title'] [shortcode_posts post_id=1 tag='post_author']

Using the shortcode to display a post thumbnail of a specific size and align it to the right with a specific horizontal space

[shortcode_posts post_id=1 tag='post_thumbnail' size='medium' align='right' hspace='15']

Using the shortcode to display a post excerpt and the date of the post by referencing the post ID

[shortcode_posts post_id=1 tag='post_excerpt'] [shortcode_posts post_id=1 tag='post_date']

Using the shortcode to display a post content and a link to the post by referencing the post ID

[shortcode_posts post_id=1 tag='post_content'] [shortcode_posts post_id=1 tag='post_link']

PHP Function Code

In case you have difficulties debugging what causing issues with [shortcode_posts] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode($post_shortcode, array($Shortcode, 'shortcode_posts'));

Shortcode PHP function:

                    function shortcode_posts($atts = array(), $content = null, $tag = null)
		{
			global $wpml_eftype, $wpml_target, $Html, $shortcode_posts, $shortcode_categories, $shortcode_category, $shortcode_categories_done,
			$shortcode_post, $shortcode_sendas, $shortcode_post_row, $shortcode_post_language, $shortcode_post_showdate, $shortcode_thumbnail;

			$return = "";

			if (!empty($wpml_eftype) && $wpml_eftype == "full" && $tag == "post_excerpt") {
				$tag = "post_content";
			}

			$defaults = array(
				'style'					=>	"",
			);
			
			if (!empty($shortcode_post)) {
				
				// Visual Composer stuff
				if (class_exists('WPBMap')) {
                    if (method_exists('WPBMap', 'addAllMappedShortcodes')) {
						WPBMap::addAllMappedShortcodes();
					}
					
					// Run it through the_content filter	
					remove_filter('the_content', 'MeprRulesCtrl::rule_content', 999999);
					$shortcode_post -> post_content = apply_filters('the_content', $shortcode_post -> post_content);
				}
			}

			$arguments = shortcode_atts($defaults, $atts);
			extract($arguments);

			switch ($tag) {
				case 'category_heading'						:
				case 'newsletters_category_heading'			:
					$category_heading = "";

					if (!empty($shortcode_category)) {
						if (empty($shortcode_categories_done) || (!empty($shortcode_categories_done) && !in_array($shortcode_category -> cat_ID, $shortcode_categories_done))) {
							$category_heading = '<a href="' . get_category_link($shortcode_category -> cat_ID) . '">' . esc_html($shortcode_category -> name) . '</a>';
							$shortcode_categories_done[] = $shortcode_category -> cat_ID;
						}
					}

					return do_shortcode($category_heading);
					break;
				case 'post_loop'				:
				case 'newsletters_post_loop'	:
					if (!empty($shortcode_categories)) {
						$shortcode_post_row = 1;
						foreach ($shortcode_categories as $category) {
							$shortcode_category = $category['category'];
							$shortcode_posts = $category['posts'];

							foreach ($shortcode_posts as $post) {
								$shortcode_post = $post;
								$return .= do_shortcode($content);
								$shortcode_post_row++;
							}
						}
					} elseif (!empty($shortcode_posts)) {
						$shortcode_post_row = 1;
						foreach ($shortcode_posts as $post) {
							$shortcode_post = $post;
							$return .= do_shortcode($content);
							$shortcode_post_row++;
						}
					} elseif (!empty($shortcode_sendas)) {
						$shortcode_post_row = 1;
						foreach ($shortcode_sendas as $post) {
							$shortcode_post = $post;
							$return .= do_shortcode($content);
							$shortcode_post_row++;
						}
					}

					wp_reset_query();
					$shortcode_post = false;
					return $return;
					break;
				case 'post_id'					:
				case 'newsletters_post_id'		:
					if (!empty($shortcode_post)) {
						return $shortcode_post -> ID;
					}
					break;
				case 'post_author'				:
				case 'newsletters_post_author'	:
					global $post;
					$post = $shortcode_post;
					setup_postdata($post);
					$return = get_the_author();
					wp_reset_postdata();
					return do_shortcode($return);
					break;
				case 'post_anchor'				:
				case 'newsletters_post_anchor'	:
					if (!empty($shortcode_post)) {
						$linktitle = (empty($content)) ? esc_html($shortcode_post -> post_title) : esc_html($content);
						return do_shortcode('<a style="' . esc_attr(wp_unslash($style)) . '" title="' . esc_attr(wp_unslash($linktitle)) . '" href="' . $this -> direct_post_permalink($shortcode_post -> ID) . '">' . $linktitle . '</a>');
					}
					break;
				case 'post_title'				:
				case 'newsletters_post_title'	:
					if (!empty($shortcode_post)) {
						return do_shortcode(esc_html($shortcode_post -> post_title));
					}
					break;
				case 'post_link'				:
				case 'newsletters_post_link'	:
					if (!empty($shortcode_post)) {
						return do_shortcode($this -> direct_post_permalink(esc_html($shortcode_post -> ID)));
					}
					break;
				case 'post_date_wrapper'				:
				case 'newsletters_post_date_wrapper'	:
					if (empty($shortcode_post_showdate) || (!empty($shortcode_post_showdate) && $shortcode_post_showdate == "Y")) {
						return do_shortcode($content);
					} else {
						return "";
					}
					break;
				case 'post_date'				:
				case 'newsletters_post_date'	:
					if (!empty($shortcode_post)) {
						$format = get_option('date_format');
						return $Html -> gen_date($format, strtotime($shortcode_post -> post_date));
					}
					break;
				case 'post_thumbnail'			:
				case 'newsletters_post_thumbnail'	:
					if (empty($shortcode_post)) {
						// there is no $shortcode_post, this may be an independent [newsletters_post_thumbnail...] shortcode
						return $this -> post_thumbnail($atts, false);
					} else {
						if (!empty($atts) && is_array($atts)) {
							if (!empty($shortcode_thumbnail)) {
								$atts = wp_parse_args($atts, $shortcode_thumbnail);
							}
						} else {
							$atts = $shortcode_thumbnail;
						}
	
						$defaults = array(
							'size' 			=> 	"thumbnail",
							'align'			=>	"left",
							'hspace'		=>	"15",
							'class'			=>	"newsletters_thumbnail",
						);
	
						$defaults = apply_filters('newsletters_post_thumbnail_defaults', $defaults);
	
						$style = false;
						if (!empty($align) && !empty($hspace)) {
							switch ($align) {
								case 'left'					:
									$style = "margin-right:" . $hspace . "px;";
									break;
								case 'right'				:
									$style = "margin-left:" . $hspace . "px;";
									break;
							}
						}
	
						extract(shortcode_atts($defaults, $atts));
	
						if (strpos($size, ',') !== false) {
							$sizes = explode(",", $size);
							if (!empty($sizes) && is_array($sizes)) {
								$size = $sizes;
							}
						}						
	
						if (!empty($shortcode_post)) {
							if (function_exists('has_post_thumbnail') && has_post_thumbnail($shortcode_post -> ID)) {
								$return .= '<a target="' . $wpml_target . '" href="' . $this -> direct_post_permalink($shortcode_post -> ID) . '">';
								$attr = apply_filters('newsletters_post_thumbnail_attr', array('style' => $style, 'align' => $align, 'hspace' => $hspace, 'class' => $class), $shortcode_post -> ID);
								$return .= get_the_post_thumbnail($shortcode_post -> ID, $size, $attr);
								$return .= '</a>';
								return do_shortcode(apply_filters('newsletters_post_thumbnail_output', $return, $shortcode_post));
							} else {
								// added by Ted Eytan
								$return .= '<a target="' . $wpml_target . '" href="' . $this -> direct_post_permalink($shortcode_post -> ID) . '">';
								$attr = apply_filters('newsletters_post_thumbnail_attr', array('style' => $style, 'align' => $align, 'hspace' => $hspace, 'class' => $class), $shortcode_post -> ID);
								require_once($this -> plugin_base() . DS . 'vendors' . DS . 'gettheimage.php');								
								$return .= get_the_image(array('post_id' => $shortcode_post -> ID, 'scan' => true, 'size' => $size, 'echo' => false));
								$return .= '</a>';
								return do_shortcode(apply_filters('newsletters_post_thumbnail_output', $return, $shortcode_post));
							}
						}
					}
					break;
				case 'post_excerpt'				:
				case 'newsletters_post_excerpt'	:
				
					$postswpautop = $this -> get_option('postswpautop');
												
					if (empty($wpml_eftype) || (!empty($wpml_eftype) && $wpml_eftype != "full")) {
						$this -> add_filter('excerpt_length');
						$this -> add_filter('excerpt_more');
						$this -> add_filter('post_password_required', 'post_password_required', 10, 2);
						$this -> add_filter('the_content_more_link', 'excerpt_more');

						if (!empty($shortcode_post)) {
							global $post;
							$post = $shortcode_post;
							setup_postdata($post);
							
							if (preg_match('/<!--more(.*?)?-->/', $post -> post_content)) {
								if (!empty($postswpautop)) {
									$return .= do_shortcode(wpautop(__(get_the_content())));
								} else {
									$return .= do_shortcode(__(get_the_content()));
								}
							} else {
								if (!empty($postswpautop)) {
									$return .= do_shortcode(wpautop(__($this -> get_the_excerpt())));
								} else {
									$return .= do_shortcode(__($this -> get_the_excerpt()));
								}
							}
							
							wp_reset_postdata();
						}
					} else {						
						global $post;
						$post = $shortcode_post;
						setup_postdata($post);
						global $more;
						$more = true;
						
						if (!empty($postswpautop)) {
							$return = do_shortcode(wpautop(__(get_the_content())));
						} else {
							$return = do_shortcode(__(get_the_content()));
						}
							
						wp_reset_postdata();
					}

					return apply_filters('newsletters_post_excerpt', $return, $shortcode_post);
				case 'post_content'				:
				case 'newsletters_post_content'	:
				
					$postswpautop = $this -> get_option('postswpautop');
				
					if (empty($wpml_eftype) || (!empty($wpml_eftype) && $wpml_eftype != "excerpt")) {
						global $post;
						$post = $shortcode_post;
						setup_postdata($post);
						
						if (!empty($postswpautop)) {
							$return = wpautop(__(get_the_content()));
						} else {
							$return = __(get_the_content());	
						}
						
						wp_reset_postdata();
					} else {
						$this -> add_filter('excerpt_length');
						$this -> add_filter('excerpt_more');
						$this -> add_filter('post_password_required', 'post_password_required', 10, 2);
						$this -> add_filter('the_content_more_link', 'excerpt_more');

						if (!empty($shortcode_post)) {
							global $post;
							$post = $shortcode_post;
							setup_postdata($post);
							global $more;
							$more = true;
							
							if (preg_match('/<!--more(.*?)?-->/', $post -> post_content)) {
								if (!empty($postswpautop)) {
									$return .= do_shortcode(wpautop(__(get_the_content())));
								} else {
									$return .= do_shortcode(__(get_the_content()));
								}
							} else {
								if (!empty($postswpautop)) {
									$return .= do_shortcode(wpautop(__($this -> get_the_excerpt())));
								} else {
									$return .= do_shortcode(__($this -> get_the_excerpt()));
								}
							}
							
							wp_reset_postdata();
						}
					}

					return do_shortcode($return);
					break;
			}

			return do_shortcode(wp_unslash($content));
		}
                    

Code file location:

newsletters-lite/newsletters-lite/includes/checkinit.php

Newsletters [newsletters_if] Shortcode

The Newsletters Lite plugin shortcode ‘newsletters_if’ is a conditional shortcode that checks if specific content exists before rendering it. The shortcode takes in attributes and content, and checks if a newsletter with a specific ID and content area exists. If it does, the shortcode outputs the content, else it returns an empty string.

Shortcode: [newsletters_if]

Parameters

Here is a list of all possible newsletters_if shortcode parameters and attributes:

  • 0 – Determines the type of content to display, currently only supports ‘newsletters_content’
  • id – Corresponds to the specific number of the content area in the newsletter

Examples and Usage

Basic example – The basic usage of the shortcode ‘newsletters_if’ can be seen in the following example. This shortcode checks if there is content available for a specific newsletter history ID and a content area number.

[newsletters_if newsletters_content id=3 /]

Advanced examples

Example 1: In the following example, the shortcode ‘newsletters_if’ is used to check if there is content available for a specific newsletter history ID and a content area number. If content is found, it will be displayed; otherwise, nothing will be output.

[newsletters_if newsletters_content id=5 /]

Example 2: In this advanced example, the shortcode ‘newsletters_if’ is used to check if there is content available for a specific newsletter history ID and a content area number. The shortcode is nested inside a paragraph tag to ensure the output is formatted correctly.

<p>[newsletters_if newsletters_content id=7 /]</p>

Remember, the ‘id’ attribute in the shortcode corresponds to the number of the content area in the newsletter. Adjust this attribute as needed to display the correct content area in your newsletter.

PHP Function Code

In case you have difficulties debugging what causing issues with [newsletters_if] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('newsletters_if', array($Shortcode, 'newsletters_if'));

Shortcode PHP function:

                    function newsletters_if($atts = array(), $content = null)
		{
			global $newsletters_history_id, $Db;

			$output = "";

			$defaults = array(
				0				=>	false,
				'id'			=>	false,
			);

			extract(shortcode_atts($defaults, $atts));

			switch ($atts[0]) {
				case 'newsletters_content'					:
					if (!empty($newsletters_history_id) && !empty($atts['id'])) {
						if ($contentarea = $this -> Content() -> find(array('number' => $atts['id'], 'history_id' => $newsletters_history_id))) {
							$output = do_shortcode(wp_unslash(esc_html($content)));
						}
					}
					break;
			}

			return $output;
		}
                    

Code file location:

newsletters-lite/newsletters-lite/includes/checkinit.php

Conclusion

Now that you’ve learned how to embed the Newsletters Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *