Yoast_Product

Class Yoast_Product.

Defined (1)

The class is defined in the following location(s).

/vendor/yoast/license-manager/class-product.php  
  1. class Yoast_Product { 
  2.  
  3. /** 
  4. * @var string The URL of the shop running the EDD API. 
  5. */ 
  6. protected $api_url; 
  7.  
  8. /** 
  9. * @var string The item name in the EDD shop. 
  10. */ 
  11. protected $item_name; 
  12.  
  13. /** 
  14. * @var string The theme slug or plugin file 
  15. */ 
  16. protected $slug; 
  17.  
  18. /** 
  19. * @var string The version number of the item 
  20. */ 
  21. protected $version; 
  22.  
  23. /** 
  24. * @var string The absolute url on which users can purchase a license 
  25. */ 
  26. protected $item_url; 
  27.  
  28. /** 
  29. * @var string Absolute admin URL on which users can enter their license key. 
  30. */ 
  31. protected $license_page_url; 
  32.  
  33. /** 
  34. * @var string The text domain used for translating strings 
  35. */ 
  36. protected $text_domain; 
  37.  
  38. /** 
  39. * @var string The item author 
  40. */ 
  41. protected $author; 
  42.  
  43. /** 
  44. * @var string Relative file path to the plugin. 
  45. */ 
  46. protected $file; 
  47.  
  48. /** @var int Product ID in backend system for quick lookup */ 
  49. protected $product_id; 
  50.  
  51. /** @var string URL referring to the extension page */ 
  52. protected $extension_url; 
  53.  
  54. /** 
  55. * Yoast_Product constructor. 
  56. * @param string $api_url The URL of the shop running the EDD API. 
  57. * @param string $item_name The item name in the EDD shop. 
  58. * @param string $slug The slug of the plugin, for shiny updates this needs to be a valid HTML id. 
  59. * @param string $version The version number of the item. 
  60. * @param string $item_url The absolute url on which users can purchase a license. 
  61. * @param string $license_page_url Absolute admin URL on which users can enter their license key. 
  62. * @param string $text_domain The text domain used for translating strings. 
  63. * @param string $author The item author. 
  64. * @param string $file The relative file path to the plugin. 
  65. * @param int $product_id The ID of the product in the backend system. 
  66. */ 
  67. public function __construct( $api_url, $item_name, $slug, $version, $item_url = '', $license_page_url = '#', $text_domain = 'yoast', $author = 'Yoast', $file = '', $product_id = 0 ) { 
  68. $this->set_api_url( $api_url ); 
  69. $this->set_item_name( $item_name ); 
  70. $this->set_slug( $slug ); 
  71. $this->set_version( $version ); 
  72. $this->set_item_url( $item_url ); 
  73. $this->set_license_page_url( $license_page_url ); 
  74. $this->set_text_domain( $text_domain ); 
  75. $this->set_author( $author ); 
  76. $this->set_file( $file ); 
  77. $this->set_product_id( $product_id ); 
  78.  
  79. /** 
  80. * @param string $api_url 
  81. */ 
  82. public function set_api_url( $api_url ) { 
  83. $this->api_url = $api_url; 
  84.  
  85. /** 
  86. * @return string 
  87. */ 
  88. public function get_api_url() { 
  89. return $this->api_url; 
  90.  
  91. /** 
  92. * @param string $author 
  93. */ 
  94. public function set_author( $author ) { 
  95. $this->author = $author; 
  96.  
  97. /** 
  98. * @return string 
  99. */ 
  100. public function get_author() { 
  101. return $this->author; 
  102.  
  103. /** 
  104. * @param string $item_name 
  105. */ 
  106. public function set_item_name( $item_name ) { 
  107. $this->item_name = $item_name; 
  108.  
  109. /** 
  110. * @return string 
  111. */ 
  112. public function get_item_name() { 
  113. return $this->item_name; 
  114.  
  115. /** 
  116. * @param string $item_url 
  117. */ 
  118. public function set_item_url( $item_url ) { 
  119. if ( empty( $item_url ) ) { 
  120. $item_url = $this->api_url; 
  121.  
  122. $this->item_url = $item_url; 
  123.  
  124. /** 
  125. * @return string 
  126. */ 
  127. public function get_item_url() { 
  128. return $this->item_url; 
  129.  
  130. /** 
  131. * @param string $license_page_url 
  132. */ 
  133. public function set_license_page_url( $license_page_url ) { 
  134.  
  135. if ( is_admin() && is_multisite() ) { 
  136.  
  137. if ( ! function_exists( 'is_plugin_active_for_network' ) ) { 
  138. require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); 
  139.  
  140. if ( is_plugin_active_for_network( $this->get_slug() ) ) { 
  141. $this->license_page_url = network_admin_url( $license_page_url ); 
  142.  
  143. return; 
  144.  
  145. $this->license_page_url = admin_url( $license_page_url ); 
  146.  
  147. /** 
  148. * @return string 
  149. */ 
  150. public function get_license_page_url() { 
  151. return $this->license_page_url; 
  152.  
  153. /** 
  154. * @param string $slug 
  155. */ 
  156. public function set_slug( $slug ) { 
  157. $this->slug = $slug; 
  158.  
  159. /** 
  160. * @return string 
  161. */ 
  162. public function get_slug() { 
  163. return $this->slug; 
  164.  
  165. /** 
  166. * Returns the dirname of the slug and limits it to 15 chars 
  167. * @return string 
  168. */ 
  169. public function get_transient_prefix() { 
  170. return substr( md5( $this->file ), 0, 15 ); 
  171.  
  172. /** 
  173. * @param string $text_domain 
  174. */ 
  175. public function set_text_domain( $text_domain ) { 
  176. $this->text_domain = $text_domain; 
  177.  
  178. /** 
  179. * @return string 
  180. */ 
  181. public function get_text_domain() { 
  182. return $this->text_domain; 
  183.  
  184. /** 
  185. * @param string $version 
  186. */ 
  187. public function set_version( $version ) { 
  188. $this->version = $version; 
  189.  
  190. /** 
  191. * @return string 
  192. */ 
  193. public function get_version() { 
  194. return $this->version; 
  195.  
  196. /** 
  197. * Returns the file path relative to the plugins folder 
  198. * @return string 
  199. */ 
  200. public function get_file() { 
  201. /** 
  202. * Fall back to the slug for BC reasons. 
  203. * We used to pass the file to the slug field, but this isn't supported with the shiny updates in WordPress. 
  204. * WordPress uses the slug in the HTML as an ID and a slash isn't a valid 
  205. */ 
  206. return empty( $this->file ) ? $this->slug : $this->file; 
  207.  
  208. /** 
  209. * Sets the file path relative to the plugins folder 
  210. * @param string $file Relative file path to the plugin. 
  211. */ 
  212. public function set_file( $file ) { 
  213. $this->file = $file; 
  214.  
  215. /** 
  216. * Return the Product ID 
  217. * @return int 
  218. */ 
  219. public function get_product_id() { 
  220. return $this->product_id; 
  221.  
  222. /** 
  223. * Set the product ID 
  224. * @param int $product_id Product ID to set. 
  225. */ 
  226. public function set_product_id( $product_id ) { 
  227. $this->product_id = (int) $product_id; 
  228.  
  229. /** 
  230. * Gets a Google Analytics Campaign url for this product 
  231. * @param string $link_identifier 
  232. * @return string The full URL 
  233. */ 
  234. public function get_tracking_url( $link_identifier = '' ) { 
  235. return $this->add_campaign_attributes( $this->get_item_url(), $link_identifier ); 
  236.  
  237. /** 
  238. * Returns the extension url if set, otherwise it will be the tracking url. 
  239. * @param string $link_identifier 
  240. * @return string 
  241. */ 
  242. public function get_extension_url( $link_identifier = '' ) { 
  243. if ( $this->extension_url ) { 
  244. return $this->add_campaign_attributes( $this->extension_url, $link_identifier ); 
  245.  
  246. return $this->get_tracking_url( $link_identifier ); 
  247.  
  248. /** 
  249. * Sets the extension url. 
  250. * @param string $extension_url 
  251. */ 
  252. public function set_extension_url( $extension_url ) { 
  253. $this->extension_url = $extension_url; 
  254.  
  255. private function add_campaign_attributes( $url, $link_identifier ) { 
  256. $tracking_vars = array( 
  257. 'utm_campaign' => $this->get_item_name() . ' licensing',  
  258. 'utm_medium' => 'link',  
  259. 'utm_source' => $this->get_item_name(),  
  260. 'utm_content' => $link_identifier 
  261. ); 
  262.  
  263. // URL encode tracking vars. 
  264. $tracking_vars = urlencode_deep( $tracking_vars ); 
  265. $query_string = build_query( $tracking_vars ); 
  266.  
  267. return $url . '#' . $query_string; 
  268.