HEX
Server: Apache/2.4.65 (Debian)
System: Linux 88f31f35b0b8 6.1.0-38-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.147-1 (2025-08-02) x86_64
User: www-data (33)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: /var/www/html/wp-content/plugins/advanced-ads-tracking/includes/class-shortcodes.php
<?php
/**
 * The class hold shortcodes for tracking.
 *
 * @package AdvancedAds\Tracking
 * @author  Advanced Ads <info@wpadvancedads.com>
 * @since   2.6.0
 */

namespace AdvancedAds\Tracking;

use AdvancedAds\Constants;
use AdvancedAds\Framework\Interfaces\Integration_Interface;

defined( 'ABSPATH' ) || exit;

/**
 * Class Shortcodes
 */
class Shortcodes implements Integration_Interface {
	/**
	 * Hook into WordPress.
	 *
	 * @return void
	 */
	public function hooks(): void {
		add_shortcode( 'the_ad_impressions', [ $this, 'ad_impressions' ] );
		add_shortcode( 'the_ad_clicks', [ $this, 'ad_clicks' ] );
	}

	/**
	 * Display impressions of an ad in the frontend
	 *
	 * @param array $atts shortcode attributes.
	 *
	 * @return string
	 */
	public function ad_impressions( $atts ): string {
		$atts = shortcode_atts( [ 'id' => 0 ], $atts, 'the_ad_impressions' );
		$id   = absint( $atts['id'] );
		if ( ! $id ) {
			return '';
		}

		if ( $id < 1 || Constants::POST_TYPE_AD !== get_post_type( $id ) ) {
			return '';
		}

		return Database::get_ad_total_impressions( $id );
	}

	/**
	 * Display clicks of an ad in the frontend
	 *
	 * @param array $atts shortcode attributes.
	 *
	 * @return string
	 */
	public function ad_clicks( array $atts ): string {
		$atts = shortcode_atts( [ 'id' => 0 ], $atts, 'the_ad_clicks' );
		$id   = absint( $atts['id'] );
		if ( ! $id ) {
			return '';
		}

		if ( $id < 1 || Constants::POST_TYPE_AD !== get_post_type( $id ) ) {
			return '';
		}

		return Database::get_ad_total_clicks( $id );
	}
}