Below, you’ll find a detailed guide on how to add the WP Telegram Widget and Join Link 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 WP Telegram Widget and Join Link Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the WP Telegram Widget and Join Link Plugin and the shortcodes it provides:
"WP Telegram Widget and Join Link is a versatile WordPress plugin that seamlessly integrates a Telegram widget into your site. The plugin offers an easy way for visitors to join your Telegram community directly from your webpage."
- [wptelegram-ajax-widget]
WP Telegram Widget and Join Link [wptelegram-ajax-widget] Shortcode
The wptelegram-ajax-widget shortcode is a powerful tool in the wptelegram plugin. It fetches and displays content from a specified Telegram channel on your WordPress website. The shortcode works by sending a request to the Telegram channel, sanitizing the received URL, and validating it. If the URL is valid, it retrieves the content, processes it, and outputs it on your site. For non-English channels, it ensures proper encoding for Cyrillic characters. It also customizes the widget output and replaces Telegram links with the specified username.
Shortcode: [wptelegram-ajax-widget]
Examples and Usage
Basic example – The following shortcode will render the Ajax widget for the specified Telegram username.
[wptelegram-ajax-widget username="your_telegram_username" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [wptelegram-ajax-widget]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'wptelegram-ajax-widget', [ AjaxWidgetShortcode::class, 'render' ] );
Shortcode PHP function:
function render( $username ) {
$json = false;
// phpcs:disable WordPress.Security.NonceVerification.Recommended
if ( isset( $_GET['url'] ) ) {
$url = sanitize_text_field( wp_unslash( $_GET['url'] ) );
if ( ! preg_match( '/\Ahttps:\/\/t\.me\/s\/' . $username . '.*/i', $url ) ) {
exit;
}
$json = Utils::send_request_to_t_dot_me_cached(
$url,
[
'method' => 'POST',
'headers' => [
'X-Requested-With' => 'XMLHttpRequest',
],
]
);
if ( empty( $json ) ) {
exit;
}
$output = json_decode( $json );
$json = true;
} else {
$url = self::get_channel_cors_url( $username );
$output = Utils::send_request_to_t_dot_me_cached( $url );
if ( empty( $output ) ) {
exit;
}
if ( extension_loaded( 'mbstring' ) ) {
// fix the issue with Cyrillic characters.
$output = mb_convert_encoding( $output, 'UTF-8', mb_detect_encoding( $output ) );
$output = mb_convert_encoding( $output, 'HTML-ENTITIES', 'UTF-8' );
}
$output = self::customize_widget_output( $output );
}
$output = self::replace_tg_links( $output, $username );
if ( $json ) {
$output = json_encode( $output ); // phpcs:ignore WordPress.WP.AlternativeFunctions
}
// phpcs:ignore WordPress.Security.EscapeOutput
echo $output;
exit;
}
Code file location:
wptelegram-widget/wptelegram-widget/includes/Main.php
Conclusion
Now that you’ve learned how to embed the WP Telegram Widget and Join Link 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