Below, you’ll find a detailed guide on how to add the Telsender Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Telsender Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Telsender Plugin and the shortcodes it provides:
"TelSender is a versatile WordPress plugin that seamlessly integrates Contact Form 7, Events, WPForms, and WooCommerce with your Telegram bot for efficient and effective communication."
- [TS_PAGE]
Telsender [TS_PAGE] Shortcode
The Telsender plugin shortcode ‘TS_PAGE’ triggers when a page is viewed. It sends a Telegram message containing details like IP, user agent, referrer, and title of the viewed page.
Shortcode: [TS_PAGE]
Examples and Usage
Basic example – The shortcode ‘TS_PAGE’ can be used to view a specific page. In this case, there are no parameters to pass so it’s straightforward to use.
[TS_PAGE /]
Advanced examples
Although the given shortcode doesn’t inherently support parameters, you can customize the shortcode function to accept parameters. Let’s say we want to pass an IP address and a user agent as parameters. Here’s how you might do that:
function viewPage($attr)
{
// ...
$variable['{REMOTE_ADDR}'] = $attr['ip'];
$variable['{USER_AGENT}'] = $attr['user_agent'];
//...
}
add_shortcode('TS_PAGE', array($this, 'viewPage'));
Then you can use the shortcode like this:
[TS_PAGE ip="192.168.1.1" user_agent="Mozilla/5.0" /]
Please note that this is just an example. You need to handle the security issues related to passing such sensitive data as shortcode parameters.
PHP Function Code
In case you have difficulties debugging what causing issues with [TS_PAGE]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('TS_PAGE', array($this, 'viewPage'));
Shortcode PHP function:
function viewPage($attr)
{
global $post;
$server = $this->getServer();
if ($this->token) $this->telsener->telegram->Token = $this->token;
$url = str_replace('/', '_', $server['REQUEST_URI']);
if (isset($_SESSION[$url])) return false; // reset one send
$variable = [];
$variable['{REMOTE_ADDR}'] = (isset($server['REMOTE_ADDR'])) ? $server['REMOTE_ADDR'] : 'None';
$variable['{USER_AGENT}'] = (isset($server['HTTP_USER_AGENT'])) ? $server['HTTP_USER_AGENT'] : 'None';
$variable['{REFERER}'] = (isset($server['HTTP_REFERER'])) ? $server['HTTP_REFERER'] : 'None';
$variable['{TITLE}'] = get_the_title($post->ID);
$message = <<<'TAG'
🆙 View page: <b>{TITLE}</b>
Ip: <b>{REMOTE_ADDR}</b>
User agent: <b>{USER_AGENT}</b>
Referer: <b>{REFERER}</b>
#View_page
TAG;
$variable = apply_filters('tsevent_view_page', $variable);
$message = str_replace(array_keys($variable), array_values($variable), $message);
$this->telsener->telegram->isSendPechenki = false; // fix
$this->telsener->telegram->SendMesage($message);
$_SESSION[$url] = 1;
}
Code file location:
telsender/telsender/clasess/TelsenderEvent.php
Conclusion
Now that you’ve learned how to embed the Telsender Plugin shortcode, 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.
Leave a Reply