bws_go_pro_tab_check

The Google Sitemap by BestWebSoft bws go pro tab check function.

Description

bws_go_pro_tab_check( (string) $plugin_basename, (constant) $plugin_options_name = false, (bool) $is_network_option = false ); 

Parameters (3)

0. $plugin_basename (string)
The plugin basename.
1. $plugin_options_name — Optional. (constant) => false
The plugin options name.
2. $is_network_option — Optional. (bool) => false
The is network option.

Usage

  1. if ( !function_exists( 'bws_go_pro_tab_check' ) ) { 
  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 plugin options name. 
  8. $plugin_options_name = false; 
  9.  
  10. // The is network option. 
  11. $is_network_option = false; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = bws_go_pro_tab_check($plugin_basename, $plugin_options_name, $is_network_option); 
  15.  

Defined (1)

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

/bws_menu/bws_functions.php  
  1. function bws_go_pro_tab_check( $plugin_basename, $plugin_options_name = false, $is_network_option = false ) { 
  2. global $wp_version, $bstwbsftwppdtplgns_options; 
  3. $result = array(); 
  4.  
  5. $bws_license_key = ( isset( $_POST['bws_license_key'] ) ) ? stripslashes( esc_html( trim( $_POST['bws_license_key'] ) ) ) : ""; 
  6.  
  7. if ( ! empty( $plugin_options_name ) && isset( $_POST['bws_hide_premium_options_submit'] ) && check_admin_referer( $plugin_basename, 'bws_license_nonce_name' ) ) { 
  8.  
  9. $plugin_options = ( $is_network_option ) ? get_site_option( $plugin_options_name ) : get_option( $plugin_options_name ); 
  10.  
  11. if ( !empty( $plugin_options['hide_premium_options'] ) ) { 
  12.  
  13. $key = array_search( get_current_user_id(), $plugin_options['hide_premium_options'] ); 
  14. if ( false !== $key ) { 
  15. unset( $plugin_options['hide_premium_options'][ $key ] ); 
  16.  
  17. if ( $is_network_option ) 
  18. update_site_option( $plugin_options_name, $plugin_options ); 
  19. else 
  20. update_option( $plugin_options_name, $plugin_options ); 
  21.  
  22. $result['message'] = __( 'Check premium options on the plugin settings page!', 'bestwebsoft' ); 
  23.  
  24. if ( isset( $_POST['bws_license_submit'] ) && check_admin_referer( $plugin_basename, 'bws_license_nonce_name' ) ) { 
  25. if ( '' != $bws_license_key ) {  
  26. if ( strlen( $bws_license_key ) != 18 ) { 
  27. $result[error] = __( "Wrong license key", 'bestwebsoft' ); 
  28. } else { 
  29. $bws_license_plugin = stripslashes( esc_html( $_POST['bws_license_plugin'] ) ); 
  30. if ( isset( $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] ) && $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['time'] > ( time() - (24 * 60 * 60) ) ) { 
  31. $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] = $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] + 1; 
  32. } else { 
  33. $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] = 1; 
  34. $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['time'] = time(); 
  35.  
  36. /** download Pro */ 
  37. if ( ! function_exists( 'get_plugins' ) ) 
  38. require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); 
  39.  
  40. $all_plugins = get_plugins(); 
  41.  
  42. if ( ! array_key_exists( $bws_license_plugin, $all_plugins ) ) { 
  43. $current = get_site_transient( 'update_plugins' ); 
  44. if ( is_array( $all_plugins ) && !empty( $all_plugins ) && isset( $current ) && is_array( $current->response ) ) { 
  45. $to_send = array(); 
  46. $to_send["plugins"][ $bws_license_plugin ] = array(); 
  47. $to_send["plugins"][ $bws_license_plugin ]["bws_license_key"] = $bws_license_key; 
  48. $to_send["plugins"][ $bws_license_plugin ]["bws_illegal_client"] = true; 
  49. $options = array( 
  50. 'timeout' => ( ( defined( 'DOING_CRON' ) && DOING_CRON ) ? 30 : 3 ),  
  51. 'body' => array( 'plugins' => serialize( $to_send ) ),  
  52. 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) ); 
  53. $raw_response = wp_remote_post( 'http://bestwebsoft.com/wp-content/plugins/paid-products/plugins/update-check/1.0/', $options ); 
  54.  
  55. if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) { 
  56. $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' ); 
  57. } else { 
  58. $response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) ); 
  59. if ( is_array( $response ) && !empty( $response ) ) { 
  60. foreach ( $response as $key => $value ) { 
  61. if ( "wrong_license_key" == $value->package ) { 
  62. $result[error] = __( "Wrong license key", 'bestwebsoft' );  
  63. } elseif ( "wrong_domain" == $value->package ) { 
  64. $result[error] = __( "This license key is bind to another site", 'bestwebsoft' ); 
  65. } elseif ( "you_are_banned" == $value->package ) { 
  66. $result[error] = __( "Unfortunately, you have exceeded the number of available tries per day. Please, upload the plugin manually.", 'bestwebsoft' ); 
  67. } elseif ( "time_out" == $value->package ) { 
  68. $result[error] = __( "Unfortunately, Your license has expired. To continue getting top-priority support and plugin updates you should extend it in your", 'bestwebsoft' ) . ' <a href="http://bestwebsoft.com/wp-admin/admin.php?page=client-area">Client area</a>'; 
  69. } elseif ( "duplicate_domen_for_trial" == $value->package ) { 
  70. $result[error] = __( "Unfortunately, the Pro licence was already installed to this domain. The Pro Trial license can be installed only once.", 'bestwebsoft' ); 
  71. if ( empty( $result[error] ) ) { 
  72. $bstwbsftwppdtplgns_options[ $bws_license_plugin ] = $bws_license_key; 
  73.  
  74. $url = 'http://bestwebsoft.com/wp-content/plugins/paid-products/plugins/downloads/?bws_first_download=' . $bws_license_plugin . '&bws_license_key=' . $bws_license_key . '&download_from=5'; 
  75. $uploadDir = wp_upload_dir(); 
  76. $zip_name = explode( '/', $bws_license_plugin ); 
  77.  
  78. if ( !function_exists( 'curl_init' ) ) {  
  79. $received_content = file_get_contents( $url ); 
  80. } else { 
  81. $ch = curl_init(); 
  82. curl_setopt( $ch, CURLOPT_URL, $url ); 
  83. curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); 
  84. $received_content = curl_exec( $ch ); 
  85. curl_close( $ch ); 
  86.  
  87. if ( ! $received_content ) { 
  88. $result[error] = __( "Failed to download the zip archive. Please, upload the plugin manually", 'bestwebsoft' ); 
  89. } else { 
  90. if ( is_writable( $uploadDir["path"] ) ) { 
  91. $file_put_contents = $uploadDir["path"] . "/" . $zip_name[0] . ".zip"; 
  92. if ( file_put_contents( $file_put_contents, $received_content ) ) { 
  93. @chmod( $file_put_contents, octdec( 755 ) ); 
  94. if ( class_exists( 'ZipArchive' ) ) { 
  95. $zip = new ZipArchive(); 
  96. if ( $zip->open( $file_put_contents ) === TRUE ) { 
  97. $zip->extractTo( WP_PLUGIN_DIR ); 
  98. $zip->close(); 
  99. } else { 
  100. $result[error] = __( "Failed to open the zip archive. Please, upload the plugin manually", 'bestwebsoft' ); 
  101. } elseif ( class_exists( 'Phar' ) ) { 
  102. $phar = new PharData( $file_put_contents ); 
  103. $phar->extractTo( WP_PLUGIN_DIR ); 
  104. } else { 
  105. $result[error] = __( "Your server does not support either ZipArchive or Phar. Please, upload the plugin manually", 'bestwebsoft' ); 
  106. @unlink( $file_put_contents ); 
  107. } else { 
  108. $result[error] = __( "Failed to download the zip archive. Please, upload the plugin manually", 'bestwebsoft' ); 
  109. } else { 
  110. $result[error] = __( "UploadDir is not writable. Please, upload the plugin manually", 'bestwebsoft' ); 
  111.  
  112. /** activate Pro */ 
  113. if ( file_exists( WP_PLUGIN_DIR . '/' . $zip_name[0] ) ) { 
  114. if ( is_multisite() && is_plugin_active_for_network( plugin_basename( __FILE__ ) ) ) { 
  115. /** if multisite and free plugin is network activated */ 
  116. $active_plugins = get_site_option( 'active_sitewide_plugins' ); 
  117. $active_plugins[ $bws_license_plugin ] = time(); 
  118. update_site_option( 'active_sitewide_plugins', $active_plugins ); 
  119. } else { 
  120. /** activate on a single blog */ 
  121. $active_plugins = get_option( 'active_plugins' ); 
  122. array_push( $active_plugins, $bws_license_plugin ); 
  123. update_option( 'active_plugins', $active_plugins ); 
  124. $result['pro_plugin_is_activated'] = true; 
  125. } elseif ( empty( $result[error] ) ) { 
  126. $result[error] = __( "Failed to download the zip archive. Please, upload the plugin manually", 'bestwebsoft' ); 
  127. } else { 
  128. $result[error] = __( "Something went wrong. Try again later or upload the plugin manually. We are sorry for inconvenience.", 'bestwebsoft' );  
  129. } else { 
  130. $bstwbsftwppdtplgns_options[ $bws_license_plugin ] = $bws_license_key; 
  131. /** activate Pro */ 
  132. if ( ! is_plugin_active( $bws_license_plugin ) ) { 
  133. if ( is_multisite() && is_plugin_active_for_network( plugin_basename( __FILE__ ) ) ) { 
  134. /** if multisite and free plugin is network activated */ 
  135. $network_wide = true; 
  136. } else { 
  137. /** activate on a single blog */ 
  138. $network_wide = false; 
  139. activate_plugin( $bws_license_plugin, NULL, $network_wide ); 
  140. $result['pro_plugin_is_activated'] = true; 
  141. if ( is_multisite() ) 
  142. update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); 
  143. else 
  144. update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); 
  145.  
  146. if ( ! empty( $result['pro_plugin_is_activated'] ) ) 
  147. delete_transient( 'bws_plugins_update' ); 
  148. } else { 
  149. $result[error] = __( "Please, enter Your license key", 'bestwebsoft' ); 
  150. return $result;