bws_check_pro_license

The Google Sitemap by BestWebSoft bws check pro license function.

Description

bws_check_pro_license( (string) $plugin_basename, (bool) $trial_plugin = false ); 

Parameters (2)

0. $plugin_basename (string)
The plugin basename.
1. $trial_plugin — Optional. (bool) => false
The trial plugin.

Usage

  1. if ( !function_exists( 'bws_check_pro_license' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-sitemap-by-bestwebsoft/bws_menu/bws_functions.php'; 
  3.  
  4. // The plugin basename. 
  5. $plugin_basename = ''; 
  6.  
  7. // The trial plugin. 
  8. $trial_plugin = false; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bws_check_pro_license($plugin_basename, $trial_plugin); 
  12.  

Defined (1)

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

/bws_menu/bws_functions.php  
  1. function bws_check_pro_license( $plugin_basename, $trial_plugin = false ) { 
  2. global $wp_version, $bstwbsftwppdtplgns_options; 
  3. $result = array(); 
  4.  
  5. if ( isset( $_POST['bws_license_submit'] ) && check_admin_referer( $plugin_basename, 'bws_license_nonce_name' ) ) { 
  6. $license_key = isset( $_POST['bws_license_key'] ) ? stripslashes( esc_html( trim( $_POST['bws_license_key'] ) ) ) : ''; 
  7.  
  8. if ( '' != $license_key ) { 
  9. if ( ! function_exists( 'get_plugins' ) ) 
  10. require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); 
  11. $plugins_all = get_plugins(); 
  12. $current = get_site_transient( 'update_plugins' ); 
  13.  
  14. if ( is_array( $plugins_all ) && !empty( $plugins_all ) && isset( $current ) && is_array( $current->response ) ) { 
  15. $to_send = array(); 
  16. $to_send["plugins"][ $plugin_basename ] = $plugins_all[ $plugin_basename ]; 
  17. $to_send["plugins"][ $plugin_basename ]["bws_license_key"] = $license_key; 
  18. $to_send["plugins"][ $plugin_basename ]["bws_illegal_client"] = true; 
  19. $options = array( 
  20. 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3),  
  21. 'body' => array( 'plugins' => serialize( $to_send ) ),  
  22. 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) 
  23. ); 
  24. $raw_response = wp_remote_post( 'http://bestwebsoft.com/wp-content/plugins/paid-products/plugins/update-check/1.0/', $options ); 
  25. if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) { 
  26. $result[error] = __( 'Something went wrong. Please try again later. If theerrorappears again, please contact us', 'bestwebsoft' ) . ' <a href=http://support.bestwebsoft.com>BestWebSoft</a>. ' . __( 'We are sorry for inconvenience.', 'bestwebsoft' ); 
  27. } else { 
  28. $response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) ); 
  29. if ( is_array( $response ) && !empty( $response ) ) { 
  30. foreach ( $response as $key => $value ) { 
  31. if ( "wrong_license_key" == $value->package ) { 
  32. $result[error] = __( 'Wrong license key.', 'bestwebsoft' );  
  33. } else if ( "wrong_domain" == $value->package ) { 
  34. $result[error] = __( 'This license key is bind to another site.', 'bestwebsoft' ); 
  35. } else if ( "time_out" == $value->package ) { 
  36. $result['message'] = __( 'This license key is valid, but Your license has expired. If you want to update our plugin in future, you should extend the license.', 'bestwebsoft' ); 
  37. } elseif ( "you_are_banned" == $value->package ) { 
  38. $result[error] = __( "Unfortunately, you have exceeded the number of available tries.", 'bestwebsoft' ); 
  39. } elseif ( "duplicate_domen_for_trial" == $value->package ) { 
  40. $result[error] = __( "Unfortunately, the Pro Trial licence was already installed to this domain. The Pro Trial license can be installed only once.", 'bestwebsoft' ); 
  41. if ( empty( $result['message'] ) && empty( $result[error] ) ) { 
  42. if ( isset( $value->trial ) ) 
  43. $result['message'] = __( 'The Pro Trial license key is valid.', 'bestwebsoft' ); 
  44. else 
  45. $result['message'] = __( 'The license key is valid.', 'bestwebsoft' ); 
  46.  
  47. if ( isset( $value->time_out ) && $value->time_out != '' ) 
  48. $result['message'] .= ' ' . __( 'Your license will expire on', 'bestwebsoft' ) . ' ' . $value->time_out . '.'; 
  49.  
  50. if ( isset( $value->trial ) && $trial_plugin != false ) 
  51. $result['message'] .= ' ' . sprintf( __( 'In order to continue using the plugin it is necessary to buy a %s license.', 'bestwebsoft' ), '<a href="http://bestwebsoft.com/products/' . $trial_plugin['link_slug'] . '/?k=' . $trial_plugin['link_key'] . '&pn=' . $trial_plugin['link_pn'] . '&v=' . $trial_plugin['plugin_info']['Version'] . '&wp_v=' . $wp_version . '" target="_blank" title="' . $trial_plugin['plugin_info']['Name'] . '">Pro</a>' ); 
  52.  
  53. if ( isset( $value->trial ) ) { 
  54. $bstwbsftwppdtplgns_options['trial'][ $plugin_basename ] = 1; 
  55. } else { 
  56. unset( $bstwbsftwppdtplgns_options['trial'][ $plugin_basename ] ); 
  57. if ( empty( $result[error] ) ) { 
  58. if ( $bstwbsftwppdtplgns_options[ $plugin_basename ] != $license_key ) { 
  59. $bstwbsftwppdtplgns_options[ $plugin_basename ] = $license_key; 
  60. $bstwbsftwppdtplgns_options['time_out'][ $plugin_basename ] = $value->time_out; 
  61. if ( is_multisite() ) 
  62. update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); 
  63. else 
  64. update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); 
  65. $file = @fopen( dirname( dirname( __FILE__ ) ) . "/license_key.txt" , "w+" ); 
  66. if ( $file ) { 
  67. @fwrite( $file, $license_key ); 
  68. @fclose( $file ); 
  69. } else { 
  70. $result[error] = __( 'Something went wrong. Please try again later. If theerrorappears again, please contact us', 'bestwebsoft' ) . ' <a href=http://support.bestwebsoft.com>BestWebSoft</a>. ' . __( 'We are sorry for inconvenience.', 'bestwebsoft' ); 
  71. } else { 
  72. $result[error] = __( 'Please, enter your license key', 'bestwebsoft' ); 
  73. return $result;