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. public function __construct( $api_url, $item_name, $slug, $version, $item_url = '', $license_page_url = '#', $text_domain = 'yoast', $author = 'Yoast' ) { 
  44. $this->api_url = $api_url; 
  45. $this->item_name = $item_name; 
  46. $this->slug = $slug; 
  47. $this->version = $version; 
  48. $this->item_url = $item_url; 
  49. $this->license_page_url = admin_url( $license_page_url ); 
  50. $this->text_domain = $text_domain; 
  51. $this->author = $author; 
  52.  
  53. // Fix possible empty item url 
  54. if ( $this->item_url === '' ) { 
  55. $this->item_url = $this->api_url; 
  56.  
  57. if( is_admin() && is_multisite() ) { 
  58.  
  59. if ( ! function_exists( 'is_plugin_active_for_network' ) ) { 
  60. require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); 
  61.  
  62. if( is_plugin_active_for_network( $slug ) ) { 
  63. $this->license_page_url = network_admin_url( $license_page_url ); 
  64.  
  65.  
  66. /** 
  67. * @param string $api_url 
  68. */ 
  69. public function set_api_url( $api_url ) { 
  70. $this->api_url = $api_url; 
  71.  
  72. /** 
  73. * @return string 
  74. */ 
  75. public function get_api_url() { 
  76. return $this->api_url; 
  77.  
  78. /** 
  79. * @param string $author 
  80. */ 
  81. public function set_author( $author ) { 
  82. $this->author = $author; 
  83.  
  84. /** 
  85. * @return string 
  86. */ 
  87. public function get_author() { 
  88. return $this->author; 
  89.  
  90. /** 
  91. * @param string $item_name 
  92. */ 
  93. public function set_item_name( $item_name ) { 
  94. $this->item_name = $item_name; 
  95.  
  96. /** 
  97. * @return string 
  98. */ 
  99. public function get_item_name() { 
  100. return $this->item_name; 
  101.  
  102. /** 
  103. * @param string $item_url 
  104. */ 
  105. public function set_item_url( $item_url ) { 
  106. $this->item_url = $item_url; 
  107.  
  108. /** 
  109. * @return string 
  110. */ 
  111. public function get_item_url() { 
  112. return $this->item_url; 
  113.  
  114. /** 
  115. * @param string $license_page_url 
  116. */ 
  117. public function set_license_page_url( $license_page_url ) { 
  118. $this->license_page_url = admin_page( $license_page_url ); 
  119.  
  120. /** 
  121. * @return string 
  122. */ 
  123. public function get_license_page_url() { 
  124. return $this->license_page_url; 
  125.  
  126. /** 
  127. * @param string $slug 
  128. */ 
  129. public function set_slug( $slug ) { 
  130. $this->slug = $slug; 
  131.  
  132. /** 
  133. * @return string 
  134. */ 
  135. public function get_slug() { 
  136. return $this->slug; 
  137.  
  138. /** 
  139. * Returns the dirname of the slug and limits it to 15 chars 
  140. * @return string 
  141. */ 
  142. public function get_transient_prefix() { 
  143. return substr( dirname( $this->slug ), 0, 15 ); 
  144.  
  145. /** 
  146. * @param string $text_domain 
  147. */ 
  148. public function set_text_domain( $text_domain ) { 
  149. $this->text_domain = $text_domain; 
  150.  
  151. /** 
  152. * @return string 
  153. */ 
  154. public function get_text_domain() { 
  155. return $this->text_domain; 
  156.  
  157. /** 
  158. * @param string $version 
  159. */ 
  160. public function set_version( $version ) { 
  161. $this->version = $version; 
  162.  
  163. /** 
  164. * @return string 
  165. */ 
  166. public function get_version() { 
  167. return $this->version; 
  168.  
  169. /** 
  170. * Gets a Google Analytics Campaign url for this product 
  171. * @param string $link_identifier 
  172. * @return string The full URL 
  173. */ 
  174. public function get_tracking_url( $link_identifier = '' ) { 
  175.  
  176. $tracking_vars = array( 
  177. 'utm_campaign' => $this->get_item_name() . ' licensing',  
  178. 'utm_medium' => 'link',  
  179. 'utm_source' => $this->get_item_name(),  
  180. 'utm_content' => $link_identifier 
  181. ); 
  182.  
  183. // url encode tracking vars 
  184. $tracking_vars = urlencode_deep( $tracking_vars ); 
  185.  
  186. $query_string = build_query( $tracking_vars ); 
  187.  
  188.  
  189. return $this->get_item_url() . '#' . $query_string; 
  190.