| Server IP : 121.121.20.254 / Your IP : 216.73.216.202 Web Server : Microsoft-IIS/10.0 System : Windows NT WEB-SERVER 10.0 build 20348 (Windows Server 2022) AMD64 User : IUSR ( 0) PHP Version : 8.3.28 Disable Function : NONE MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/inetpub/wwwroot/KnowledgeBase/wp-content/plugins/url-shortify/lite/includes/ |
Upload File : |
<?php
namespace Kaizen_Coders\Url_Shortify;
class Shortcode {
/**
* Init Shortcode
*
* @since 1.7.0
*/
public function init() {
\add_shortcode( 'shorturl', array( $this, 'render' ) );
}
/**
* Render public facing URL Shortener
*
* @since 1.7.0
*/
public function render() {
global $post;
if ( $post instanceof \WP_Post ) {
$short_link = US()->db->links->get_by_cpt_id( $post->ID );
if ( empty( $short_link ) ) {
$link_data = array(
'cpt_id' => $post->ID,
'url' => get_permalink( $post->ID ),
'name' => addslashes( $post->post_title ),
'description' => addslashes( $post->post_excerpt )
);
$created = US()->db->links->create_link( $link_data );
if ( $created ) {
$short_link = US()->db->links->get_by_cpt_id( $post->ID );
}
}
$short_url = Helper::get_short_link( $short_link['slug'] );
return sprintf( '<a href="%s" target="__blank">%s</a>', $short_url, $short_url );
}
}
}