Yoast_Product

Class Yoast_Product.

Defined (1)

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

/vendor/yoast/license-manager-2/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. /** 
  52. * Yoast_Product constructor. 
  53. * @param string $api_url The URL of the shop running the EDD API. 
  54. * @param string $item_name The item name in the EDD shop. 
  55. * @param string $slug The slug of the plugin, for shiny updates this needs to be a valid HTML id. 
  56. * @param string $version The version number of the item. 
  57. * @param string $item_url The absolute url on which users can purchase a license. 
  58. * @param string $license_page_url Absolute admin URL on which users can enter their license key. 
  59. * @param string $text_domain The text domain used for translating strings. 
  60. * @param string $author The item author. 
  61. * @param string $file The relative file path to the plugin. 
  62. * @param int $product_id The ID of the product in the backend system. 
  63. */ 
  64. public function __construct( $api_url, $item_name, $slug, $version, $item_url = '', $license_page_url = '#', $text_domain = 'yoast', $author = 'Yoast', $file = '', $product_id = 0 ) { 
  65. $this->set_api_url( $api_url ); 
  66. $this->set_item_name( $item_name ); 
  67. $this->set_slug( $slug ); 
  68. $this->set_version( $version ); 
  69. $this->set_item_url( $item_url ); 
  70. $this->set_license_page_url( $license_page_url ); 
  71. $this->set_text_domain( $text_domain ); 
  72. $this->set_author( $author ); 
  73. $this->set_file( $file ); 
  74. $this->set_product_id( $product_id ); 
  75.  
  76. /** 
  77. * @param string $api_url 
  78. */ 
  79. public function set_api_url( $api_url ) { 
  80. $this->api_url = $api_url; 
  81.  
  82. /** 
  83. * @return string 
  84. */ 
  85. public function get_api_url() { 
  86. return $this->api_url; 
  87.  
  88. /** 
  89. * @param string $author 
  90. */ 
  91. public function set_author( $author ) { 
  92. $this->author = $author; 
  93.  
  94. /** 
  95. * @return string 
  96. */ 
  97. public function get_author() { 
  98. return $this->author; 
  99.  
  100. /** 
  101. * @param string $item_name 
  102. */ 
  103. public function set_item_name( $item_name ) { 
  104. $this->item_name = $item_name; 
  105.  
  106. /** 
  107. * @return string 
  108. */ 
  109. public function get_item_name() { 
  110. return $this->item_name; 
  111.  
  112. /** 
  113. * @param string $item_url 
  114. */ 
  115. public function set_item_url( $item_url ) { 
  116. if ( empty( $item_url ) ) { 
  117. $item_url = $this->api_url; 
  118.  
  119. $this->item_url = $item_url; 
  120.  
  121. /** 
  122. * @return string 
  123. */ 
  124. public function get_item_url() { 
  125. return $this->item_url; 
  126.  
  127. /** 
  128. * @param string $license_page_url 
  129. */ 
  130. public function set_license_page_url( $license_page_url ) { 
  131.  
  132. if ( is_admin() && is_multisite() ) { 
  133.  
  134. if ( ! function_exists( 'is_plugin_active_for_network' ) ) { 
  135. require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); 
  136.  
  137. if ( is_plugin_active_for_network( $this->get_slug() ) ) { 
  138. $this->license_page_url = network_admin_url( $license_page_url ); 
  139.  
  140. return; 
  141.  
  142. $this->license_page_url = admin_url( $license_page_url ); 
  143.  
  144. /** 
  145. * @return string 
  146. */ 
  147. public function get_license_page_url() { 
  148. return $this->license_page_url; 
  149.  
  150. /** 
  151. * @param string $slug 
  152. */ 
  153. public function set_slug( $slug ) { 
  154. $this->slug = $slug; 
  155.  
  156. /** 
  157. * @return string 
  158. */ 
  159. public function get_slug() { 
  160. return $this->slug; 
  161.  
  162. /** 
  163. * Returns the dirname of the slug and limits it to 15 chars 
  164. * @return string 
  165. */ 
  166. public function get_transient_prefix() { 
  167. return substr( md5( $this->file ), 0, 15 ); 
  168.  
  169. /** 
  170. * @param string $text_domain 
  171. */ 
  172. public function set_text_domain( $text_domain ) { 
  173. $this->text_domain = $text_domain; 
  174.  
  175. /** 
  176. * @return string 
  177. */ 
  178. public function get_text_domain() { 
  179. return $this->text_domain; 
  180.  
  181. /** 
  182. * @param string $version 
  183. */ 
  184. public function set_version( $version ) { 
  185. $this->version = $version; 
  186.  
  187. /** 
  188. * @return string 
  189. */ 
  190. public function get_version() { 
  191. return $this->version; 
  192.  
  193. /** 
  194. * Returns the file path relative to the plugins folder 
  195. * @return string 
  196. */ 
  197. public function get_file() { 
  198. /** 
  199. * Fall back to the slug for BC reasons. 
  200. * We used to pass the file to the slug field, but this isn't supported with the shiny updates in WordPress. 
  201. * WordPress uses the slug in the HTML as an ID and a slash isn't a valid 
  202. */ 
  203. return empty( $this->file ) ? $this->slug : $this->file; 
  204.  
  205. /** 
  206. * Sets the file path relative to the plugins folder 
  207. * @param string $file Relative file path to the plugin. 
  208. */ 
  209. public function set_file( $file ) { 
  210. $this->file = $file; 
  211.  
  212. /** 
  213. * Return the Product ID 
  214. * @return int 
  215. */ 
  216. public function get_product_id() { 
  217. return $this->product_id; 
  218.  
  219. /** 
  220. * Set the product ID 
  221. * @param int $product_id Product ID to set. 
  222. */ 
  223. public function set_product_id( $product_id ) { 
  224. $this->product_id = (int) $product_id; 
  225.  
  226. /** 
  227. * Gets a Google Analytics Campaign url for this product 
  228. * @param string $link_identifier 
  229. * @return string The full URL 
  230. */ 
  231. public function get_tracking_url( $link_identifier = '' ) { 
  232.  
  233. $tracking_vars = array( 
  234. 'utm_campaign' => $this->get_item_name() . ' licensing',  
  235. 'utm_medium' => 'link',  
  236. 'utm_source' => $this->get_item_name(),  
  237. 'utm_content' => $link_identifier 
  238. ); 
  239.  
  240. // URL encode tracking vars. 
  241. $tracking_vars = urlencode_deep( $tracking_vars ); 
  242. $query_string = build_query( $tracking_vars ); 
  243.  
  244. return $this->get_item_url() . '#' . $query_string;