class-wpseo-shortlinker.php 1.17 KB
Newer Older
imac's avatar
imac committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
<?php
/**
 * @package WPSEO
 */

/**
 * Helps with creating shortlinks in the plugin
 */
class  WPSEO_Shortlinker {

	/**
	 * @var string
	 */
	protected $version;

	/**
	 * @param string $version The version to put in the utm_content tag.
	 */
	public function __construct( $version ) {
		$this->version = $version;
	}

	/**
	 * Builds a URL to use in the plugin as shortlink.
	 *
	 * @param string $url The URL to build upon.
	 *
	 * @return string The final URL.
	 */
	public function build_shortlink( $url ) {
		return $url . '?utm_content=' . $this->version;
	}

	/**
	 * Returns a version of the URL with a utm_content with the current version.
	 *
	 * @param string $url The URL to build upon.
	 *
	 * @return string The final URL.
	 */
	public static function get( $url ) {
		$version = WPSEO_VERSION;

		$version = apply_filters( 'wpseo_shortlink_version', $version );

		$shortlinker = new WPSEO_Shortlinker( $version );

		return $shortlinker->build_shortlink( $url );
	}

	/**
	 * Echoes a version of the URL with a utm_content with the current version.
	 *
	 * @param string $url The URL to build upon.
	 */
	public static function show( $url ) {
		echo esc_url( self::get( $url ) );
	}
}