YIT_Licence

YIT Licence Panel.

Defined (1)

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

/plugin-fw/licence/lib/yit-licence.php  
  1. abstract class YIT_Licence { 
  2.  
  3. /** 
  4. * @var mixed array The registered products info 
  5. * @since 1.0 
  6. */ 
  7. protected $_products = array(); 
  8.  
  9. /** 
  10. * @var array The settings require to add the submenu page "Activation" 
  11. * @since 1.0 
  12. */ 
  13. protected $_settings = array(); 
  14.  
  15. /** 
  16. * @var string Option name 
  17. * @since 1.0 
  18. */ 
  19. protected $_licence_option = 'yit_products_licence_activation'; 
  20.  
  21. /** 
  22. * @var string The yithemes api uri 
  23. * @since 1.0 
  24. */ 
  25. protected $_api_uri = 'https://yithemes.com'; 
  26.  
  27. /** 
  28. * @var string The yithemes api uri query args 
  29. * @since 1.0 
  30. */ 
  31. protected $_api_uri_query_args = '?wc-api=software-api&request=%request%'; 
  32.  
  33.  
  34. /** 
  35. * @var string check for show extra info 
  36. * @since 1.0 
  37. */ 
  38. public $show_extra_info = false; 
  39.  
  40. /** 
  41. * @var string check for show extra info 
  42. * @since 1.0 
  43. */ 
  44. public $show_renew_button = true; 
  45.  
  46. /** 
  47. * Constructor 
  48. * @since 1.0 
  49. * @author Andrea Grillo <andrea.grillo@yithemes.com> 
  50. */ 
  51. public function __construct() { 
  52. $is_debug_enabled = defined( 'YIT_LICENCE_DEBUG' ) && YIT_LICENCE_DEBUG; 
  53. if ( $is_debug_enabled ) { 
  54. $this->_api_uri = defined( 'YIT_LICENCE_DEBUG_LOCALHOST' ) ? YIT_LICENCE_DEBUG_LOCALHOST : 'http://dev.yithemes.com'; 
  55. add_filter( 'block_local_requests', '__return_false' ); 
  56.  
  57. /** Style adn Script */ 
  58. add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); 
  59. if( $is_debug_enabled ) { 
  60. //show extra info and renew button in debug mode 
  61. $this->show_extra_info = $this->show_renew_button = true; 
  62.  
  63. else { 
  64. $this->show_extra_info = defined( 'YIT_SHOW_EXTRA_LICENCE_INFO' ) && YIT_SHOW_EXTRA_LICENCE_INFO; 
  65. $this->show_renew_button = ! ( defined( 'YIT_HIDE_LICENCE_RENEW_BUTTON' ) && YIT_HIDE_LICENCE_RENEW_BUTTON ); 
  66.  
  67. /** Update Licence Information */ 
  68. //@TODO: Removed for performance 
  69. // add_action( 'core_upgrade_preamble', array( $this, 'check_all' ) ); 
  70. // add_action( 'wp_maybe_auto_update', array( $this, 'check_all' ) ); 
  71.  
  72.  
  73. /** 
  74. * Premium products registration 
  75. * @param $init string | The products identifier 
  76. * @param $secret_key string | The secret key 
  77. * @param $product_id string | The product id 
  78. * @return void 
  79. * @since 1.0 
  80. * @author Andrea Grillo <andrea.grillo@yithemes.com> 
  81. */ 
  82. abstract public function register( $init, $secret_key, $product_id ); 
  83.  
  84. /** 
  85. * Get protected array products 
  86. * @return mixed array 
  87. * @since 1.0 
  88. * @author Andrea Grillo <andrea.grillo@yithemes.com> 
  89. */ 
  90. public function get_products() { 
  91. return $this->_products; 
  92.  
  93. /** 
  94. * Get The home url without protocol 
  95. * @return string | The home url 
  96. * @since 1.0 
  97. * @author Andrea Grillo <andrea.grillo@yithemes.com> 
  98. */ 
  99. public function get_home_url() { 
  100. $home_url = home_url(); 
  101. $schemes = apply_filters( 'yit_licence_url_schemes', array( 'https://', 'http://' ) ); 
  102.  
  103. foreach( $schemes as $scheme ) { 
  104. $home_url = str_replace( $scheme, '', $home_url ); 
  105.  
  106. return apply_filters('yit_licence_get_home_url', $home_url ); 
  107.  
  108. /** 
  109. * Check if the request is ajax 
  110. * @return bool true if the request is ajax, false otherwise 
  111. * @since 1.0 
  112. * @author Andrea Grillo <andrea.grillo@yithemes.com> 
  113. */ 
  114. public function is_ajax() { 
  115. return defined( 'DOING_AJAX' ) && DOING_AJAX ? true : false; 
  116.  
  117. /** 
  118. * Admin Enqueue Scripts 
  119. * @return void 
  120. * @since 1.0 
  121. * @author Andrea Grillo <andrea.grillo@yithemes.com> 
  122. */ 
  123. public function admin_enqueue_scripts() { 
  124.  
  125. /** 
  126. * Support to YIT Framework < 2.0 
  127. */ 
  128. $filename = function_exists( 'yit_load_js_file' ) ? yit_load_js_file( 'yit-licence.js' ) : 'yit-licence.js'; 
  129. $script_path = defined( 'YIT_CORE_PLUGIN_URL' ) ? YIT_CORE_PLUGIN_URL : get_template_directory_uri() . '/core/plugin-fw'; 
  130. $style_path = defined( 'YIT_CORE_PLUGIN_URL' ) ? YIT_CORE_PLUGIN_URL : get_template_directory_uri() . '/core/plugin-fw'; 
  131.  
  132. wp_enqueue_script( 'yit-licence', $script_path . '/licence/assets/js/' . $filename, array( 'jquery' ), '1.0.0', true ); 
  133. wp_enqueue_style( 'yit-theme-licence', $style_path . '/licence/assets/css/yit-licence.css' ); 
  134.  
  135. /** Localize Scripts */ 
  136. wp_localize_script( 'yit-licence', 'licence_message', array( 
  137. 'error' => sprintf( _x( '%s field cannot be empty', '%s = field name', 'yith-plugin-fw' ), '%field%' ), // sprintf must be used to avoid errors with '%field%' string in translation in .po file 
  138. 'errors' => sprintf( __( '%s and %s fields cannot be empty', 'yith-plugin-fw' ), '%field_1%', '%field_2%' ),  
  139. 'server' => __( 'Unable to contact the remote server, please try again later. Thanks!', 'yith-plugin-fw' ),  
  140. 'email' => __( 'Email', 'yith-plugin-fw' ),  
  141. 'license_key' => __( 'License Key', 'yith-plugin-fw' ),  
  142. 'are_you_sure' => __( 'Are you sure you want to deactivate the license for current site?', 'yith-plugin-fw' ) 
  143. ); 
  144.  
  145. wp_localize_script( 'yit-licence', 'script_info', array( 
  146. 'is_debug' => defined( 'YIT_LICENCE_DEBUG' ) && YIT_LICENCE_DEBUG 
  147. ); 
  148.  
  149. /** 
  150. * Activate Plugins 
  151. * Send a request to API server to activate plugins 
  152. * @return void 
  153. * @use wp_send_json 
  154. * @since 1.0 
  155. * @author Andrea Grillo <andrea.grillo@yithemes.com> 
  156. */ 
  157. public function activate() { 
  158. $product_init = $_REQUEST['product_init']; 
  159. $product = $this->get_product( $product_init ); 
  160.  
  161. $args = array( 
  162. 'email' => urlencode( sanitize_email( $_REQUEST['email'] ) ),  
  163. 'licence_key' => sanitize_text_field( $_REQUEST['licence_key'] ),  
  164. 'product_id' => sanitize_text_field( $product['product_id'] ),  
  165. 'secret_key' => sanitize_text_field( $product['secret_key'] ),  
  166. 'instance' => $this->get_home_url() 
  167. ); 
  168.  
  169. $api_uri = esc_url_raw( add_query_arg( $args, $this->get_api_uri( 'activation' ) ) ); 
  170. $response = wp_remote_get( $api_uri, array( 'timeout' => 30 ) ); 
  171.  
  172. if ( is_wp_error( $response ) ) { 
  173. $body = false; 
  174. else { 
  175. $body = json_decode( $response['body'] ); 
  176. $body = is_object( $body ) ? get_object_vars( $body ) : false; 
  177.  
  178. if ( $body && is_array( $body ) && isset( $body['activated'] ) && $body['activated'] ) { 
  179.  
  180. $option[$product['product_id']] = array( 
  181. 'email' => urldecode( $args['email'] ),  
  182. 'licence_key' => $args['licence_key'],  
  183. 'licence_expires' => $body['licence_expires'],  
  184. 'message' => $body['message'],  
  185. 'activated' => true,  
  186. 'activation_limit' => $body['activation_limit'],  
  187. 'activation_remaining' => $body['activation_remaining'],  
  188. 'is_membership' => isset( $body['is_membership'] ) ? $body['is_membership'] : false,  
  189. ); 
  190.  
  191. /** === Check for other plugins activation === */ 
  192. $options = $this->get_licence(); 
  193. $options[$product['product_id']] = $option[$product['product_id']]; 
  194.  
  195. update_option( $this->_licence_option, $options ); 
  196.  
  197. /** === Update Plugin Licence Information === */ 
  198. YIT_Upgrade()->force_regenerate_update_transient(); 
  199.  
  200. /** === Licence Activation Template === */ 
  201. $body['template'] = $this->show_activation_panel( $this->get_response_code_message( 200 ) ); 
  202.  
  203. wp_send_json( $body ); 
  204.  
  205. /** 
  206. * Deactivate Plugins 
  207. * Send a request to API server to activate plugins 
  208. * @return void 
  209. * @use wp_send_json 
  210. * @since 1.0 
  211. * @author Andrea Grillo <andrea.grillo@yithemes.com> 
  212. */ 
  213. public function deactivate() { 
  214. $product_init = $_REQUEST['product_init']; 
  215. $product = $this->get_product( $product_init ); 
  216.  
  217. $args = array( 
  218. 'email' => urlencode( sanitize_email( $_REQUEST['email'] ) ),  
  219. 'licence_key' => sanitize_text_field( $_REQUEST['licence_key'] ),  
  220. 'product_id' => sanitize_text_field( $product['product_id'] ),  
  221. 'secret_key' => sanitize_text_field( $product['secret_key'] ),  
  222. 'instance' => $this->get_home_url() 
  223. ); 
  224.  
  225. $api_uri = esc_url_raw( add_query_arg( $args, $this->get_api_uri( 'deactivation' ) ) ); 
  226. $response = wp_remote_get( $api_uri, array( 'timeout' => 30 ) ); 
  227.  
  228. if ( is_wp_error( $response ) ) { 
  229. $body = false; 
  230. else { 
  231. $body = json_decode( $response['body'] ); 
  232. $body = is_object( $body ) ? get_object_vars( $body ) : false; 
  233.  
  234. if ( $body && is_array( $body ) && isset( $body['activated'] ) && ! $body['activated'] && ! isset( $body['error'] ) ) { 
  235.  
  236. $option[$product['product_id']] = array( 
  237. 'activated' => false,  
  238. 'email' => urldecode( $args['email'] ),  
  239. 'licence_key' => $args['licence_key'],  
  240. 'licence_expires' => $body['licence_expires'],  
  241. 'message' => $body['message'],  
  242. 'activation_limit' => $body['activation_limit'],  
  243. 'activation_remaining' => $body['activation_remaining'],  
  244. 'is_membership' => isset( $body['is_membership'] ) ? $body['is_membership'] : false,  
  245. ); 
  246.  
  247. /** === Check for other plugins activation === */ 
  248. $options = $this->get_licence(); 
  249. $options[$product['product_id']] = $option[$product['product_id']]; 
  250.  
  251. update_option( $this->_licence_option, $options ); 
  252.  
  253. /** === Update Plugin Licence Information === */ 
  254. YIT_Upgrade()->force_regenerate_update_transient(); 
  255.  
  256. /** === Licence Activation Template === */ 
  257. $body['template'] = $this->show_activation_panel( $this->get_response_code_message( 'deactivated', array( 'instance' => $body['instance'] ) ) ); 
  258.  
  259. else { 
  260. $body['error'] = $this->get_response_code_message( $body['code'] ); 
  261.  
  262. wp_send_json( $body ); 
  263.  
  264. /** 
  265. * Check Plugins Licence 
  266. * Send a request to API server to check if plugins is activated 
  267. * @param string|The plugin init slug $plugin_init 
  268. * @return bool | true if activated, false otherwise 
  269. * @since 1.0 
  270. * @author Andrea Grillo <andrea.grillo@yithemes.com> 
  271. */ 
  272. public function check( $product_init, $regenerate_transient = true ) { 
  273.  
  274. $status = false; 
  275. $body = false; 
  276. $product = $this->get_product( $product_init ); 
  277. $licence = $this->get_licence(); 
  278. $product_id = $product['product_id']; 
  279.  
  280. if( ! isset( $licence[ $product_id ] ) ) { 
  281. return false; 
  282.  
  283. $args = array( 
  284. 'email' => urlencode( $licence[$product_id]['email'] ),  
  285. 'licence_key' => $licence[$product_id]['licence_key'],  
  286. 'product_id' => $product_id,  
  287. 'secret_key' => $product['secret_key'],  
  288. 'instance' => $this->get_home_url() 
  289. ); 
  290.  
  291. $api_uri = esc_url_raw( add_query_arg( $args, $this->get_api_uri( 'check' ) ) ); 
  292. $response = wp_remote_get( $api_uri, array( 'timeout' => 30 ) ); 
  293.  
  294. if ( ! is_wp_error( $response ) ) { 
  295. $body = json_decode( $response['body'] ); 
  296. $body = is_object( $body ) ? get_object_vars( $body ) : false; 
  297.  
  298. if ( $body && is_array( $body ) && isset( $body['success'] ) ) { 
  299. if ( $body['success'] ) { 
  300.  
  301. /** 
  302. * Code 200 -> Licence key is valid 
  303. */ 
  304. $licence[ $product_id ]['status_code'] = '200'; 
  305. $licence[ $product_id ]['activated'] = $body['activated']; 
  306. $licence[ $product_id ]['licence_expires'] = $body['licence_expires']; 
  307. $licence[ $product_id ]['activation_remaining'] = $body['activation_remaining']; 
  308. $licence[ $product_id ]['activation_limit'] = $body['activation_limit']; 
  309. $licence[ $product_id ]['is_membership'] = isset( $body['is_membership'] ) ? $body['is_membership'] : false; 
  310. $status = (bool) $body['activated']; 
  311. elseif ( isset( $body['code'] ) ) { 
  312.  
  313. switch ( $body['code'] ) { 
  314.  
  315. /** 
  316. * Error Code List: 
  317. * 100 -> Invalid Request 
  318. * 101 -> Invalid licence key 
  319. * 102 -> Software has been deactivate 
  320. * 103 -> Exceeded maximum number of activations 
  321. * 104 -> Invalid instance ID 
  322. * 105 -> Invalid security key 
  323. * 106 -> Licence key has expired 
  324. * 107 -> Licence key has be banned 
  325. * Only code 101, 106 and 107 have effect on DB during activation 
  326. * All error code have effect on DB during deactivation 
  327. */ 
  328.  
  329. case '101': 
  330. case '102': 
  331. unset( $licence[ $product_id ] ); 
  332. break; 
  333.  
  334. case '106': 
  335. $licence[ $product_id ]['activated'] = false; 
  336. $licence[ $product_id ]['message'] = $body['error']; 
  337. $licence[ $product_id ]['status_code'] = $body['code']; 
  338. $licence[ $product_id ]['licence_expires'] = $body['licence_expires']; 
  339. //$licence[ $product_id ]['is_membership'] = isset( $body['is_membership'] ) ? $body['is_membership'] : false; 
  340. break; 
  341.  
  342. case '107': 
  343. $licence[ $product_id ]['activated'] = false; 
  344. $licence[ $product_id ]['message'] = $body['error']; 
  345. $licence[ $product_id ]['status_code'] = $body['code']; 
  346. //$licence[ $product_id ]['is_membership'] = isset( $body['is_membership'] ) ? $body['is_membership'] : false; 
  347. break; 
  348.  
  349. /** === Update Plugin Licence Information === */ 
  350. update_option( $this->_licence_option, $licence ); 
  351.  
  352. /** === Update Plugin Licence Information === */ 
  353. if( $regenerate_transient ) { 
  354. YIT_Upgrade()->force_regenerate_update_transient(); 
  355. return $status; 
  356.  
  357. /** 
  358. * Check for licence update 
  359. * @return void 
  360. * @since 2.5 
  361. * @use YIT_Theme_Licence->check() 
  362. * @author Andrea Grillo <andrea.grillo@yithemes.com> 
  363. */ 
  364. public function check_all() { 
  365. foreach ( $this->_products as $init => $info ) { 
  366. $this->check( $init ); 
  367.  
  368. /** 
  369. * Update Plugins Information 
  370. * Send a request to API server to check activate plugins and update the informations 
  371. * @return void 
  372. * @use YIT_Theme_Licence->check() 
  373. * @since 1.0 
  374. * @author Andrea Grillo <andrea.grillo@yithemes.com> 
  375. */ 
  376. public function update_licence_information() { 
  377. /** Check licence information for alla products */ 
  378. $this->check_all(); 
  379.  
  380. /** === Regenerate Update Plugins Transient === */ 
  381. YIT_Upgrade()->force_regenerate_update_transient(); 
  382.  
  383. do_action( 'yit_licence_after_check' ); 
  384.  
  385. if( $this->is_ajax() ) { 
  386. $response['template'] = $this->show_activation_panel(); 
  387. wp_send_json( $response ); 
  388.  
  389. /** 
  390. * Include activation page template 
  391. * @return mixed void | string the contents of the output buffer and end output buffering. 
  392. * @since 1.0 
  393. * @author Andrea Grillo <andrea.grillo@yithemes.com> 
  394. */ 
  395. public function show_activation_panel( $notice = '' ) { 
  396.  
  397. $path = defined( 'YIT_CORE_PLUGIN_PATH' ) ? YIT_CORE_PLUGIN_PATH : get_template_directory() . '/core/plugin-fw/'; 
  398.  
  399. if ( $this->is_ajax() ) { 
  400. ob_start(); 
  401. require_once( $path . '/licence/templates/panel/activation/activation-panel.php' ); 
  402. return ob_get_clean(); 
  403. else { 
  404. require_once( $path . '/licence/templates/panel/activation/activation-panel.php' ); 
  405.  
  406. /** 
  407. * Get activated products 
  408. * @return array 
  409. * @since 1.0 
  410. * @author Andrea Grillo <andrea.grillo@yithemes.com> 
  411. */ 
  412. public function get_activated_products() { 
  413. $activated_products = array(); 
  414. $licence = $this->get_licence(); 
  415.  
  416. if ( is_array( $licence ) ) { 
  417. foreach ( $this->_products as $init => $info ) { 
  418. if ( in_array( $info['product_id'], array_keys( $licence ) ) && isset( $licence[$info['product_id']]['activated'] ) && $licence[$info['product_id']]['activated'] ) { 
  419. $product[$init] = $this->_products[$init]; 
  420. $product[$init]['licence'] = $licence[$info['product_id']]; 
  421. $activated_products[$init] = $product[$init]; 
  422.  
  423. return $activated_products; 
  424.  
  425. /** 
  426. * Get to active products 
  427. * @return array 
  428. * @since 1.0 
  429. * @author Andrea Grillo <andrea.grillo@yithemes.com> 
  430. */ 
  431. public function get_to_active_products() { 
  432. return array_diff_key( $this->get_products(), $this->get_activated_products() ); 
  433.  
  434. /** 
  435. * Get no active products 
  436. * @return array 
  437. * @since 1.0 
  438. * @author Andrea Grillo <andrea.grillo@yithemes.com> 
  439. */ 
  440. public function get_no_active_licence_key() { 
  441. $unactive_products = $this->get_to_active_products(); 
  442. $licence = $this->get_licence(); 
  443. $licence_key = array(); 
  444.  
  445. /** 
  446. * Remove banned licence key 
  447. */ 
  448. foreach ( $unactive_products as $init => $info ) { 
  449. $product_id = $unactive_products[$init]['product_id']; 
  450. if ( isset( $licence[$product_id]['activated'] ) && ! $licence[$product_id]['activated'] && isset( $licence[$product_id]['status_code'] ) ) { 
  451. $status_code = $licence[$product_id]['status_code']; 
  452.  
  453. switch ( $status_code ) { 
  454. case '106': 
  455. $licence_key[$status_code][$init] = $unactive_products[$init]; 
  456. $licence_key[$status_code][$init]['licence'] = $licence[$product_id]; 
  457. break; 
  458.  
  459. case '107': 
  460. $licence_key[$status_code][$init] = $unactive_products[$init]; 
  461. $licence_key[$status_code][$init]['licence'] = $licence[$product_id]; 
  462. break; 
  463. return $licence_key; 
  464.  
  465. /** 
  466. * Get a specific product information 
  467. * @param $product_init | product init file 
  468. * @return mixed array 
  469. * @since 1.0 
  470. * @author Andrea Grillo <andrea.grillo@yithemes.com> 
  471. */ 
  472. public function get_product( $init ) { 
  473. return isset( $this->_products[$init] ) ? $this->_products[$init] : false; 
  474.  
  475. /** 
  476. * Get product product id information 
  477. * @param $product_init | product init file 
  478. * @return mixed array 
  479. * @since 1.0 
  480. * @author Andrea Grillo <andrea.grillo@yithemes.com> 
  481. */ 
  482. public function get_product_id( $init ) { 
  483. return isset( $this->_products[$init]['product_id'] ) ? $this->_products[$init]['product_id'] : false; 
  484.  
  485. /** 
  486. * Get Renewing uri 
  487. * @param $licence_key The licence key to renew 
  488. * @return mixed The renewing uri if licence_key exists, false otherwise 
  489. * @since 1.0 
  490. * @author Andrea Grillo <andrea.grillo@yithemes.com> 
  491. */ 
  492. public function get_renewing_uri( $licence_key ) { 
  493. return ! empty( $licence_key ) ? str_replace( 'www.', '', $this->_api_uri ) . '?renewing_key=' . $licence_key : false; 
  494.  
  495. /** 
  496. * Get protected yithemes api uri 
  497. * @param $request 
  498. * @return mixed array 
  499. * @since 1.0 
  500. * @author Andrea Grillo <andrea.grillo@yithemes.com> 
  501. */ 
  502. public function get_api_uri( $request ) { 
  503. return str_replace( '%request%', $request, $this->_api_uri . $this->_api_uri_query_args ); 
  504.  
  505. /** 
  506. * Get the activation page url 
  507. * @return String | Activation page url 
  508. * @since 1.0 
  509. * @author Andrea Grillo <andrea.grillo@yithemes.com> 
  510. */ 
  511. public function get_licence_activation_page_url() { 
  512. return esc_url( add_query_arg( array( 'page' => $this->_settings['page'] ), admin_url( 'admin.php' ) ) ); 
  513.  
  514.  
  515. /** 
  516. * Get the licence information 
  517. * @return array | licence array 
  518. * @since 1.0 
  519. * @author Andrea Grillo <andrea.grillo@yithemes.com> 
  520. */ 
  521. public function get_licence() { 
  522. return get_option( $this->_licence_option ); 
  523.  
  524. /** 
  525. * Get the licence information 
  526. * @param $code string The error code 
  527. * @return string | Error code message 
  528. * @since 1.0 
  529. * @author Andrea Grillo <andrea.grillo@yithemes.com> 
  530. */ 
  531. public function get_response_code_message( $code, $args = array() ) { 
  532. extract( $args ); 
  533.  
  534. $messages = array( 
  535. '100' => __( 'Invalid Request', 'yith-plugin-fw' ),  
  536. '101' => __( 'Invalid license key', 'yith-plugin-fw' ),  
  537. '102' => __( 'Software has been deactivated', 'yith-plugin-fw' ),  
  538. '103' => __( 'Maximum number of activations exceeded', 'yith-plugin-fw' ),  
  539. '104' => __( 'Invalid instance ID', 'yith-plugin-fw' ),  
  540. '105' => __( 'Invalid security key', 'yith-plugin-fw' ),  
  541. '106' => __( 'License key has expired', 'yith-plugin-fw' ),  
  542. '107' => __( 'License key has been banned', 'yith-plugin-fw' ),  
  543. '108' => __( 'Current product is not included in your YITH Club Subscription key', 'yith-plugin-fw' ),  
  544. '200' => sprintf( '<strong>%s</strong>! %s', __( 'Great', 'yith-plugin-fw' ), __( 'License successfully activated', 'yith-plugin-fw' ) ),  
  545. 'deactivated' => sprintf( '%s <strong>%s</strong>', __( 'License key deactivated for website', 'woocommerce-software-add-on' ), isset( $instance ) ? $instance : '' ) 
  546. ); 
  547.  
  548. return isset( $messages[$code] ) ? $messages[$code] : false; 
  549.  
  550. /** 
  551. * Get the product name to display 
  552. * @param $product_name 
  553. * @return string the product name 
  554. * @since 2.2 
  555. * @author Andrea Grillo <andrea.grillo@yithemes.com> 
  556. */ 
  557. public function display_product_name( $product_name ) { 
  558. return str_replace( array( 'for WooCommerce', 'YITH', 'WooCommerce', 'Premium', 'Theme', 'WordPress' ), '', $product_name ); 
  559.  
  560. public function get_number_of_membership_products() { 
  561. $activated_products = $this->get_activated_products(); 
  562. $num_members_products_activate = 0; 
  563. foreach( $activated_products as $activated_product ) { 
  564. if( isset( $activated_product['licence']['is_membership'] ) && $activated_product['licence']['is_membership'] ) { 
  565. $num_members_products_activate++; 
  566. return $num_members_products_activate; 
  567.