PluginProbe
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin / 1.8.8
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin v1.8.8
trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.1 All 71 releases
pdf-print / bws_menu / bws_functions.php

bws_functions.php in PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin 1.8.8, at bws_menu/bws_functions.php

1,339 lines 61.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * General functions for BestWebSoft plugins
4 */
5
6 /**
7 * Function add BWS Plugins page - for old plugin version
8 * @deprecated 1.7.9
9 */
10 if ( ! function_exists ( 'bws_add_general_menu' ) ) {
11 function bws_add_general_menu() {
12 bws_general_menu();
13 }
14 }
15
16 /**
17 * Function add BWS Plugins page
18 * @return void
19 */
20 if ( ! function_exists ( 'bws_general_menu' ) ) {
21 function bws_general_menu() {
22 global $menu, $bws_general_menu_exist;
23
24 if ( ! $bws_general_menu_exist ) {
25 /* we check also menu exist in global array as in old plugins $bws_general_menu_exist variable not exist */
26 foreach ( $menu as $value_menu ) {
27 if ( 'bws_plugins' == $value_menu[2] ) {
28 $bws_general_menu_exist = true;
29 return;
30 }
31 }
32
33 add_menu_page( 'BWS Plugins', 'BWS Plugins', 'manage_options', 'bws_plugins', 'bws_add_menu_render', plugins_url( 'images/px.png', __FILE__ ), 1001 );
34 $bws_general_menu_exist = true;
35 }
36 }
37 }
38
39 /**
40 * Function check if plugin is compatible with current WP version - for old plugin version
41 * @deprecated 1.7.4
42 */
43 if ( ! function_exists ( 'bws_wp_version_check' ) ) {
44 function bws_wp_version_check( $plugin_basename, $plugin_info, $require_wp ) {
45 bws_wp_min_version_check( $plugin_basename, $plugin_info, '3.8' , $require_wp );
46 }
47 }
48
49 /**
50 * Function check if plugin is compatible with current WP version
51 * @return void
52 */
53 if ( ! function_exists ( 'bws_wp_min_version_check' ) ) {
54 function bws_wp_min_version_check( $plugin_basename, $plugin_info, $require_wp, $min_wp = false ) {
55 global $wp_version, $bws_versions_notice_array;
56 if ( false == $min_wp )
57 $min_wp = $require_wp;
58 if ( version_compare( $wp_version, $min_wp, "<" ) ) {
59 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
60 if ( is_plugin_active( $plugin_basename ) ) {
61 deactivate_plugins( $plugin_basename );
62 $admin_url = ( function_exists( 'get_admin_url' ) ) ? get_admin_url( null, 'plugins.php' ) : esc_url( '/wp-admin/plugins.php' );
63 wp_die(
64 sprintf(
65 "<strong>%s</strong> %s <strong>WordPress %s</strong> %s <br /><br />%s <a href='%s'>%s</a>.",
66 $plugin_info['Name'],
67 __( 'requires', 'bestwebsoft' ),
68 $require_wp,
69 __( 'or higher, that is why it has been deactivated! Please upgrade WordPress and try again.', 'bestwebsoft' ),
70 __( 'Back to the WordPress', 'bestwebsoft' ),
71 $admin_url,
72 __( 'Plugins page', 'bestwebsoft' )
73 )
74 );
75 }
76 } elseif ( version_compare( $wp_version, $require_wp, "<" ) ) {
77 $bws_versions_notice_array[] = array( 'name' => $plugin_info['Name'], 'version' => $require_wp );
78 }
79 }
80 }
81
82 if ( ! function_exists( 'bws_versions_notice' ) ) {
83 function bws_versions_notice() {
84 global $bws_versions_notice_array;
85 if ( ! empty( $bws_versions_notice_array ) ) {
86 foreach ( $bws_versions_notice_array as $key => $value ) { ?>
87 <div class="update-nag"><?php
88 echo sprintf(
89 "<strong>%s</strong> %s <strong>WordPress %s</strong> %s",
90 $value['name'],
91 __( 'requires', 'bestwebsoft' ),
92 $value['version'],
93 __( 'or higher! We do not guarantee that our plugin will work correctly. Please upgrade to WordPress latest version.', 'bestwebsoft' )
94 );
95 ?></div>
96 <?php }
97 }
98 }
99 }
100
101 if ( ! function_exists( 'bws_plugin_banner' ) ) {
102 function bws_plugin_banner( $plugin_info, $this_banner_prefix, $link_slug, $link_key, $link_pn, $banner_url_or_slug ) {
103 global $wp_version, $bstwbsftwppdtplgns_cookie_add, $bstwbsftwppdtplgns_banner_array;
104
105 if ( empty( $bstwbsftwppdtplgns_banner_array ) ) {
106 if ( ! function_exists( 'bws_get_banner_array' ) )
107 require_once( dirname( __FILE__ ) . '/bws_menu.php' );
108 bws_get_banner_array();
109 }
110
111 if ( false == strrpos( $banner_url_or_slug, '/' ) ) {
112 $banner_url_or_slug = '//ps.w.org/' . $banner_url_or_slug . '/assets/icon-128x128.png';
113 }
114
115 if ( ! function_exists( 'is_plugin_active' ) )
116 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
117
118 $all_plugins = get_plugins();
119
120 $this_banner = $this_banner_prefix . '_hide_banner_on_plugin_page';
121 foreach ( $bstwbsftwppdtplgns_banner_array as $key => $value ) {
122 if ( $this_banner == $value[0] ) {
123 if ( ! isset( $bstwbsftwppdtplgns_cookie_add ) ) {
124 echo '<script type="text/javascript" src="' . plugins_url( 'js/c_o_o_k_i_e.js', __FILE__ ) . '"></script>';
125 $bstwbsftwppdtplgns_cookie_add = true;
126 } ?>
127 <script type="text/javascript">
128 (function($) {
129 $(document).ready( function() {
130 var hide_message = $.cookie( '<?php echo $this_banner_prefix; ?>_hide_banner_on_plugin_page' );
131 if ( hide_message == "true" ) {
132 $( ".<?php echo $this_banner_prefix; ?>_message" ).css( "display", "none" );
133 } else {
134 $( ".<?php echo $this_banner_prefix; ?>_message" ).css( "display", "block" );
135 };
136 $( ".<?php echo $this_banner_prefix; ?>_close_icon" ).click( function() {
137 $( ".<?php echo $this_banner_prefix; ?>_message" ).css( "display", "none" );
138 $.cookie( "<?php echo $this_banner_prefix; ?>_hide_banner_on_plugin_page", "true", { expires: 32 } );
139 });
140 });
141 })(jQuery);
142 </script>
143 <div class="updated" style="padding: 0; margin: 0; border: none; background: none;">
144 <div class="<?php echo $this_banner_prefix; ?>_message bws_banner_on_plugin_page bws_go_pro_banner" style="display: none;">
145 <button class="<?php echo $this_banner_prefix; ?>_close_icon close_icon notice-dismiss bws_hide_settings_notice" title="<?php _e( 'Close notice', 'bestwebsoft' ); ?>"></button>
146 <div class="icon">
147 <img title="" src="<?php echo esc_attr( $banner_url_or_slug ); ?>" alt="" />
148 </div>
149 <div class="text"><?php
150 _e( 'It’s time to upgrade your', 'bestwebsoft' ); ?> <strong><?php echo $plugin_info['Name']; ?> plugin</strong> <?php _e( 'to', 'bestwebsoft' ); ?> <strong>Pro</strong> <?php _e( 'version!', 'bestwebsoft' ); ?><br />
151 <span><?php _e( 'Extend standard plugin functionality with new great options.', 'bestwebsoft' ); ?></span>
152 </div>
153 <div class="button_div">
154 <a class="button" target="_blank" href="http://bestwebsoft.com/products/<?php echo $link_slug; ?>/?k=<?php echo $link_key; ?>&amp;pn=<?php echo $link_pn; ?>&amp;v=<?php echo $plugin_info["Version"]; ?>&amp;wp_v=<?php echo $wp_version; ?>"><?php _e( 'Learn More', 'bestwebsoft' ); ?></a>
155 </div>
156 </div>
157 </div>
158 <?php break;
159 }
160 if ( isset( $all_plugins[ $value[1] ] ) && $all_plugins[ $value[1] ]["Version"] >= $value[2] && is_plugin_active( $value[1] ) && ! isset( $_COOKIE[ $value[0] ] ) ) {
161 break;
162 }
163 }
164 }
165 }
166
167 if ( ! function_exists( 'bws_plugin_reviews_block' ) ) {
168 function bws_plugin_reviews_block( $plugin_name, $plugin_slug ) { ?>
169 <div class="bws-plugin-reviews">
170 <div class="bws-plugin-reviews-rate">
171 <?php _e( 'If you enjoy our plugin, please give it 5 stars on WordPress', 'bestwebsoft' ); ?>:
172 <a href="http://wordpress.org/support/view/plugin-reviews/<?php echo $plugin_slug; ?>?filter=5" target="_blank" title="<?php echo $plugin_name; ?> reviews"><?php _e( 'Rate the plugin', 'bestwebsoft' ); ?></a>
173 </div>
174 <div class="bws-plugin-reviews-support">
175 <?php _e( 'If there is something wrong about it, please contact us', 'bestwebsoft' ); ?>:
176 <a href="http://support.bestwebsoft.com">http://support.bestwebsoft.com</a>
177 </div>
178 </div>
179 <?php }
180 }
181
182 if ( ! function_exists( 'bws_go_pro_tab_check' ) ) {
183 function bws_go_pro_tab_check( $plugin_basename, $plugin_options_name = false, $is_network_option = false ) {
184 global $wp_version, $bstwbsftwppdtplgns_options, $current_user;
185 $result = array();
186
187 $bws_license_key = ( isset( $_POST['bws_license_key'] ) ) ? stripslashes( esc_html( trim( $_POST['bws_license_key'] ) ) ) : "";
188
189 if ( ! empty( $plugin_options_name ) && isset( $_POST['bws_hide_premium_options_submit'] ) && check_admin_referer( $plugin_basename, 'bws_license_nonce_name' ) ) {
190 if ( ! $current_user )
191 get_currentuserinfo();
192
193 $plugin_options = ( $is_network_option ) ? get_site_option( $plugin_options_name ) : get_option( $plugin_options_name );
194
195 if ( !empty( $plugin_options['hide_premium_options'] ) ) {
196
197 $key = array_search( $current_user->ID, $plugin_options['hide_premium_options'] );
198 if ( false !== $key ) {
199 unset( $plugin_options['hide_premium_options'][ $key ] );
200 }
201
202 if ( $is_network_option )
203 update_site_option( $plugin_options_name, $plugin_options );
204 else
205 update_option( $plugin_options_name, $plugin_options );
206
207 $result['message'] = __( 'Check premium options on the plugin settings page!', 'bestwebsoft' );
208 }
209 }
210
211 if ( isset( $_POST['bws_license_submit'] ) && check_admin_referer( $plugin_basename, 'bws_license_nonce_name' ) ) {
212 if ( '' != $bws_license_key ) {
213 if ( strlen( $bws_license_key ) != 18 ) {
214 $result['error'] = __( "Wrong license key", 'bestwebsoft' );
215 } else {
216 $bws_license_plugin = stripslashes( esc_html( $_POST['bws_license_plugin'] ) );
217 if ( isset( $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] ) && $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['time'] > ( time() - (24 * 60 * 60) ) ) {
218 $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] = $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] + 1;
219 } else {
220 $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] = 1;
221 $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['time'] = time();
222 }
223
224 /* download Pro */
225 if ( ! function_exists( 'get_plugins' ) )
226 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
227
228 $all_plugins = get_plugins();
229
230 if ( ! array_key_exists( $bws_license_plugin, $all_plugins ) ) {
231 $current = get_site_transient( 'update_plugins' );
232 if ( is_array( $all_plugins ) && !empty( $all_plugins ) && isset( $current ) && is_array( $current->response ) ) {
233 $to_send = array();
234 $to_send["plugins"][ $bws_license_plugin ] = array();
235 $to_send["plugins"][ $bws_license_plugin ]["bws_license_key"] = $bws_license_key;
236 $to_send["plugins"][ $bws_license_plugin ]["bws_illegal_client"] = true;
237 $options = array(
238 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3 ),
239 'body' => array( 'plugins' => serialize( $to_send ) ),
240 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) );
241 $raw_response = wp_remote_post( 'http://bestwebsoft.com/wp-content/plugins/paid-products/plugins/update-check/1.0/', $options );
242
243 if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) {
244 $result['error'] = __( "Something went wrong. Please try again later. If the error appears again, please contact us", 'bestwebsoft' ) . ' <a href="http://support.bestwebsoft.com">BestWebSoft</a>. ' . __( "We are sorry for inconvenience.", 'bestwebsoft' );
245 } else {
246 $response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) );
247 if ( is_array( $response ) && !empty( $response ) ) {
248 foreach ( $response as $key => $value ) {
249 if ( "wrong_license_key" == $value->package ) {
250 $result['error'] = __( "Wrong license key", 'bestwebsoft' );
251 } elseif ( "wrong_domain" == $value->package ) {
252 $result['error'] = __( "This license key is bind to another site", 'bestwebsoft' );
253 } elseif ( "you_are_banned" == $value->package ) {
254 $result['error'] = __( "Unfortunately, you have exceeded the number of available tries per day. Please, upload the plugin manually.", 'bestwebsoft' );
255 } elseif ( "time_out" == $value->package ) {
256 $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=bws_plugins_client_area">Client area</a>';
257 } elseif ( "duplicate_domen_for_trial" == $value->package ) {
258 $result['error'] = __( "Unfortunately, the Pro licence was already installed to this domain. The Pro Trial license can be installed only once.", 'bestwebsoft' );
259 }
260 }
261 if ( empty( $result['error'] ) ) {
262 $bstwbsftwppdtplgns_options[ $bws_license_plugin ] = $bws_license_key;
263
264 $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';
265 $uploadDir = wp_upload_dir();
266 $zip_name = explode( '/', $bws_license_plugin );
267
268 if ( !function_exists( 'curl_init' ) ) {
269 $received_content = file_get_contents( $url );
270 } else {
271 $ch = curl_init();
272 curl_setopt( $ch, CURLOPT_URL, $url );
273 curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
274 $received_content = curl_exec( $ch );
275 curl_close( $ch );
276 }
277
278 if ( ! $received_content ) {
279 $result['error'] = __( "Failed to download the zip archive. Please, upload the plugin manually", 'bestwebsoft' );
280 } else {
281 if ( is_writable( $uploadDir["path"] ) ) {
282 $file_put_contents = $uploadDir["path"] . "/" . $zip_name[0] . ".zip";
283 if ( file_put_contents( $file_put_contents, $received_content ) ) {
284 @chmod( $file_put_contents, octdec( 755 ) );
285 if ( class_exists( 'ZipArchive' ) ) {
286 $zip = new ZipArchive();
287 if ( $zip->open( $file_put_contents ) === TRUE ) {
288 $zip->extractTo( WP_PLUGIN_DIR );
289 $zip->close();
290 } else {
291 $result['error'] = __( "Failed to open the zip archive. Please, upload the plugin manually", 'bestwebsoft' );
292 }
293 } elseif ( class_exists( 'Phar' ) ) {
294 $phar = new PharData( $file_put_contents );
295 $phar->extractTo( WP_PLUGIN_DIR );
296 } else {
297 $result['error'] = __( "Your server does not support either ZipArchive or Phar. Please, upload the plugin manually", 'bestwebsoft' );
298 }
299 @unlink( $file_put_contents );
300 } else {
301 $result['error'] = __( "Failed to download the zip archive. Please, upload the plugin manually", 'bestwebsoft' );
302 }
303 } else {
304 $result['error'] = __( "UploadDir is not writable. Please, upload the plugin manually", 'bestwebsoft' );
305 }
306 }
307
308 /* activate Pro */
309 if ( file_exists( WP_PLUGIN_DIR . '/' . $zip_name[0] ) ) {
310 if ( is_multisite() && is_plugin_active_for_network( plugin_basename( __FILE__ ) ) ) {
311 /* if multisite and free plugin is network activated */
312 $active_plugins = get_site_option( 'active_sitewide_plugins' );
313 $active_plugins[ $bws_license_plugin ] = time();
314 update_site_option( 'active_sitewide_plugins', $active_plugins );
315 } else {
316 /* activate on a single blog */
317 $active_plugins = get_option( 'active_plugins' );
318 array_push( $active_plugins, $bws_license_plugin );
319 update_option( 'active_plugins', $active_plugins );
320 }
321 $result['pro_plugin_is_activated'] = true;
322 } elseif ( empty( $result['error'] ) ) {
323 $result['error'] = __( "Failed to download the zip archive. Please, upload the plugin manually", 'bestwebsoft' );
324 }
325 }
326 } else {
327 $result['error'] = __( "Something went wrong. Try again later or upload the plugin manually. We are sorry for inconvenience.", 'bestwebsoft' );
328 }
329 }
330 }
331 } else {
332 $bstwbsftwppdtplgns_options[ $bws_license_plugin ] = $bws_license_key;
333 /* activate Pro */
334 if ( ! is_plugin_active( $bws_license_plugin ) ) {
335 if ( is_multisite() && is_plugin_active_for_network( plugin_basename( __FILE__ ) ) ) {
336 /* if multisite and free plugin is network activated */
337 $network_wide = true;
338 } else {
339 /* activate on a single blog */
340 $network_wide = false;
341 }
342 activate_plugin( $bws_license_plugin, NULL, $network_wide );
343 $result['pro_plugin_is_activated'] = true;
344 }
345 }
346 if ( is_multisite() )
347 update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
348 else
349 update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
350 }
351 } else {
352 $result['error'] = __( "Please, enter Your license key", 'bestwebsoft' );
353 }
354 }
355 return $result;
356 }
357 }
358
359 /**
360 * Function display GO PRO tab - for old plugin version
361 * @deprecated 1.7.6
362 */
363 if ( ! function_exists( 'bws_go_pro_tab' ) ) {
364 function bws_go_pro_tab( $plugin_info, $plugin_basename, $page, $pro_page, $bws_license_plugin, $link_slug, $link_key, $link_pn, $pro_plugin_is_activated = false, $trial_days_number = false ) {
365 bws_go_pro_tab_show( false, $plugin_info, $plugin_basename, $page, $pro_page, $bws_license_plugin, $link_slug, $link_key, $link_pn, $pro_plugin_is_activated, $trial_days_number );
366 }
367 }
368
369 /**
370 * Function display GO PRO tab
371 */
372 if ( ! function_exists( 'bws_go_pro_tab_show' ) ) {
373 function bws_go_pro_tab_show( $bws_hide_premium_options_check, $plugin_info, $plugin_basename, $page, $pro_page, $bws_license_plugin, $link_slug, $link_key, $link_pn, $pro_plugin_is_activated = false, $trial_days_number = false ) {
374 global $wp_version, $bstwbsftwppdtplgns_options;
375 $bws_license_key = ( isset( $_POST['bws_license_key'] ) ) ? stripslashes( esc_html( trim( $_POST['bws_license_key'] ) ) ) : "";
376 if ( $pro_plugin_is_activated ) { ?>
377 <script type="text/javascript">
378 window.setTimeout( function() {
379 window.location.href = 'admin.php?page=<?php echo $pro_page; ?>';
380 }, 5000 );
381 </script>
382 <p><?php _e( "Congratulations! The Pro version of the plugin is successfully download and activated.", 'bestwebsoft' ); ?></p>
383 <p>
384 <?php _e( "Please, go to", 'bestwebsoft' ); ?> <a href="admin.php?page=<?php echo $pro_page; ?>"><?php _e( 'the setting page', 'bestwebsoft' ); ?></a>
385 (<?php _e( "You will be redirected automatically in 5 seconds.", 'bestwebsoft' ); ?>)
386 </p>
387 <?php } else {
388 if ( $bws_hide_premium_options_check ) { ?>
389 <form method="post" action="">
390 <p>
391 <input type="hidden" name="bws_hide_premium_options_submit" value="submit" />
392 <input type="submit" class="button" value="<?php _e( 'Show Pro features', 'bestwebsoft' ); ?>" />
393 <?php wp_nonce_field( $plugin_basename, 'bws_license_nonce_name' ); ?>
394 </p>
395 </form>
396 <?php } ?>
397 <form method="post" action="">
398 <p>
399 <?php _e( 'You can download and activate', 'bestwebsoft' ); ?>
400 <a href="http://bestwebsoft.com/products/<?php echo $link_slug; ?>/?k=<?php echo $link_key; ?>&amp;pn=<?php echo $link_pn; ?>&amp;v=<?php echo $plugin_info["Version"]; ?>&amp;wp_v=<?php echo $wp_version; ?>" target="_blank" title="<?php echo $plugin_info["Name"]; ?> Pro">Pro</a>
401 <?php _e( 'version of this plugin by entering Your license key.', 'bestwebsoft' ); ?><br />
402 <span class="bws_info">
403 <?php _e( 'You can find your license key on your personal page Client area, by clicking on the link', 'bestwebsoft' ); ?>
404 <a href="http://bestwebsoft.com/wp-login.php">http://bestwebsoft.com/wp-login.php</a>
405 <?php _e( '(your username is the email you specify when purchasing the product).', 'bestwebsoft' ); ?>
406 </span>
407 </p>
408 <?php if ( $trial_days_number !== false )
409 $trial_days_number = __( 'or', 'bestwebsoft' ) . ' <a href="http://bestwebsoft.com/products/' . $link_slug . '/trial/" target="_blank">' . sprintf( __( 'Start Your Free %s-Day Trial Now', 'bestwebsoft' ), $trial_days_number ) . '</a>';
410 if ( isset( $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] ) &&
411 '5' < $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] &&
412 $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['time'] > ( time() - ( 24 * 60 * 60 ) ) ) { ?>
413 <p>
414 <input disabled="disabled" type="text" name="bws_license_key" value="<?php echo $bws_license_key; ?>" />
415 <input disabled="disabled" type="submit" class="button-primary" value="<?php _e( 'Activate', 'bestwebsoft' ); ?>" />
416 <?php if ( $trial_days_number !== false ) echo $trial_days_number; ?>
417 </p>
418 <p><?php _e( "Unfortunately, you have exceeded the number of available tries per day. Please, upload the plugin manually.", 'bestwebsoft' ); ?></p>
419 <?php } else { ?>
420 <p>
421 <input type="text" maxlength="100" name="bws_license_key" value="<?php echo $bws_license_key; ?>" />
422 <input type="hidden" name="bws_license_plugin" value="<?php echo $bws_license_plugin; ?>" />
423 <input type="hidden" name="bws_license_submit" value="submit" />
424 <input type="submit" class="button-primary" value="<?php _e( 'Activate', 'bestwebsoft' ); ?>" />
425 <?php if ( $trial_days_number !== false ) echo $trial_days_number;
426 wp_nonce_field( $plugin_basename, 'bws_license_nonce_name' ); ?>
427 </p>
428 <?php } ?>
429 </form>
430 <?php }
431 }
432 }
433
434 if ( ! function_exists( 'bws_go_pro_from_trial_tab' ) ) {
435 function bws_go_pro_from_trial_tab( $plugin_info, $plugin_basename, $page, $link_slug, $link_key, $link_pn, $trial_license_is_set = true ) {
436 global $wp_version, $bstwbsftwppdtplgns_options;
437 $bws_license_key = ( isset( $_POST['bws_license_key'] ) ) ? stripslashes( esc_html( trim( $_POST['bws_license_key'] ) ) ) : "";
438 if ( $trial_license_is_set ) { ?>
439 <form method="post" action="">
440 <p>
441 <?php echo sprintf( __( 'In order to continue using the plugin it is necessary to buy a %s license.', 'bestwebsoft' ), '<a href="http://bestwebsoft.com/products/' . $link_slug . '/?k=' . $link_key . '&amp;pn=' . $link_pn . '&amp;v=' . $plugin_info["Version"] . '&amp;wp_v=' . $wp_version .'" target="_blank" title="' . $plugin_info["Name"] . '">Pro</a>' ) . ' ';
442 _e( 'After that you can activate it by entering your license key.', 'bestwebsoft' ); ?><br />
443 <span class="bws_info">
444 <?php _e( 'You can find your license key on your personal page Client area, by clicking on the link', 'bestwebsoft' ); ?>
445 <a href="http://bestwebsoft.com/wp-login.php">http://bestwebsoft.com/wp-login.php</a>
446 <?php _e( '(your username is the email you specify when purchasing the product).', 'bestwebsoft' ); ?>
447 </span>
448 </p>
449 <?php if ( isset( $bstwbsftwppdtplgns_options['go_pro'][ $plugin_basename ]['count'] ) &&
450 '5' < $bstwbsftwppdtplgns_options['go_pro'][ $plugin_basename ]['count'] &&
451 $bstwbsftwppdtplgns_options['go_pro'][ $plugin_basename ]['time'] > ( time() - ( 24 * 60 * 60 ) ) ) { ?>
452 <p>
453 <input disabled="disabled" type="text" name="bws_license_key" value="" />
454 <input disabled="disabled" type="submit" class="button-primary" value="<?php _e( 'Activate', 'bestwebsoft' ); ?>" />
455 </p>
456 <p><?php _e( "Unfortunately, you have exceeded the number of available tries per day.", 'bestwebsoft' ); ?></p>
457 <?php } else { ?>
458 <p>
459 <input type="text" maxlength="100" name="bws_license_key" value="" />
460 <input type="hidden" name="bws_license_plugin" value="<?php echo $plugin_basename; ?>" />
461 <input type="hidden" name="bws_license_submit" value="submit" />
462 <input type="submit" class="button-primary" value="<?php _e( 'Activate', 'bestwebsoft' ); ?>" />
463 <?php wp_nonce_field( $plugin_basename, 'bws_license_nonce_name' ); ?>
464 </p>
465 <?php } ?>
466 </form>
467 <?php } else { ?>
468 <script type="text/javascript">
469 window.setTimeout( function() {
470 window.location.href = 'admin.php?page=<?php echo $page; ?>';
471 }, 5000 );
472 </script>
473 <p><?php _e( "Congratulations! The Pro license of the plugin is successfully activated.", 'bestwebsoft' ); ?></p>
474 <p>
475 <?php _e( "Please, go to", 'bestwebsoft' ); ?> <a href="admin.php?page=<?php echo $page; ?>"><?php _e( 'the setting page', 'bestwebsoft' ); ?></a>
476 (<?php _e( "You will be redirected automatically in 5 seconds.", 'bestwebsoft' ); ?>)
477 </p>
478 <?php }
479 }
480 }
481
482 if ( ! function_exists( 'bws_check_pro_license' ) ) {
483 function bws_check_pro_license( $plugin_basename, $trial_plugin = false ) {
484 global $wp_version, $bstwbsftwppdtplgns_options;
485 $result = array();
486
487 if ( isset( $_POST['bws_license_submit'] ) && check_admin_referer( $plugin_basename, 'bws_license_nonce_name' ) ) {
488 $license_key = isset( $_POST['bws_license_key'] ) ? stripslashes( esc_html( trim( $_POST['bws_license_key'] ) ) ) : '';
489
490 if ( '' != $license_key ) {
491 if ( ! function_exists( 'get_plugins' ) )
492 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
493 $plugins_all = get_plugins();
494 $current = get_site_transient( 'update_plugins' );
495
496 if ( is_array( $plugins_all ) && !empty( $plugins_all ) && isset( $current ) && is_array( $current->response ) ) {
497 $to_send = array();
498 $to_send["plugins"][ $plugin_basename ] = $plugins_all[ $plugin_basename ];
499 $to_send["plugins"][ $plugin_basename ]["bws_license_key"] = $license_key;
500 $to_send["plugins"][ $plugin_basename ]["bws_illegal_client"] = true;
501 $options = array(
502 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3),
503 'body' => array( 'plugins' => serialize( $to_send ) ),
504 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
505 );
506 $raw_response = wp_remote_post( 'http://bestwebsoft.com/wp-content/plugins/paid-products/plugins/update-check/1.0/', $options );
507 if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) {
508 $result['error'] = __( 'Something went wrong. Please try again later. If the error appears again, please contact us', 'bestwebsoft' ) . ' <a href=http://support.bestwebsoft.com>BestWebSoft</a>. ' . __( 'We are sorry for inconvenience.', 'bestwebsoft' );
509 } else {
510 $response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) );
511 if ( is_array( $response ) && !empty( $response ) ) {
512 foreach ( $response as $key => $value ) {
513 if ( "wrong_license_key" == $value->package ) {
514 $result['error'] = __( 'Wrong license key.', 'bestwebsoft' );
515 } else if ( "wrong_domain" == $value->package ) {
516 $result['error'] = __( 'This license key is bind to another site.', 'bestwebsoft' );
517 } else if ( "time_out" == $value->package ) {
518 $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' );
519 } elseif ( "you_are_banned" == $value->package ) {
520 $result['error'] = __( "Unfortunately, you have exceeded the number of available tries.", 'bestwebsoft' );
521 } elseif ( "duplicate_domen_for_trial" == $value->package ) {
522 $result['error'] = __( "Unfortunately, the Pro Trial licence was already installed to this domain. The Pro Trial license can be installed only once.", 'bestwebsoft' );
523 }
524 if ( empty( $result['message'] ) && empty( $result['error'] ) ) {
525 if ( isset( $value->trial ) )
526 $result['message'] = __( 'The Pro Trial license key is valid.', 'bestwebsoft' );
527 else
528 $result['message'] = __( 'The license key is valid.', 'bestwebsoft' );
529
530 if ( isset( $value->time_out ) && $value->time_out != '' )
531 $result['message'] .= ' ' . __( 'Your license will expire on', 'bestwebsoft' ) . ' ' . $value->time_out . '.';
532
533 if ( isset( $value->trial ) && $trial_plugin != false )
534 $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>' );
535
536 if ( isset( $value->trial ) ) {
537 $bstwbsftwppdtplgns_options['trial'][ $plugin_basename ] = 1;
538 } else {
539 unset( $bstwbsftwppdtplgns_options['trial'][ $plugin_basename ] );
540 }
541 }
542 if ( empty( $result['error'] ) ) {
543 if ( $bstwbsftwppdtplgns_options[ $plugin_basename ] != $license_key ) {
544 $bstwbsftwppdtplgns_options[ $plugin_basename ] = $license_key;
545 $bstwbsftwppdtplgns_options['time_out'][ $plugin_basename ] = $value->time_out;
546 if ( is_multisite() )
547 update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
548 else
549 update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
550 $file = @fopen( dirname( dirname( __FILE__ ) ) . "/license_key.txt" , "w+" );
551 if ( $file ) {
552 @fwrite( $file, $license_key );
553 @fclose( $file );
554 }
555 }
556 }
557 }
558 } else {
559 $result['error'] = __( 'Something went wrong. Please try again later. If the error appears again, please contact us', 'bestwebsoft' ) . ' <a href=http://support.bestwebsoft.com>BestWebSoft</a>. ' . __( 'We are sorry for inconvenience.', 'bestwebsoft' );
560 }
561 }
562 }
563 } else {
564 $result['error'] = __( 'Please, enter your license key', 'bestwebsoft' );
565 }
566 }
567 return $result;
568 }
569 }
570
571 if ( ! function_exists ( 'bws_check_pro_license_form' ) ) {
572 function bws_check_pro_license_form( $plugin_basename ) {
573 global $bstwbsftwppdtplgns_options;
574 $license_key = ( isset( $bstwbsftwppdtplgns_options[ $plugin_basename ] ) ) ? $bstwbsftwppdtplgns_options[ $plugin_basename ] : ''; ?>
575 <div class="clear"></div>
576 <form method="post" action="">
577 <p><?php echo _e( 'If needed you can check if the license key is correct or reenter it in the field below. You can find your license key on your personal page - Client area - on our website', 'bestwebsoft' ) . ' <a href="http://bestwebsoft.com/wp-login.php">http://bestwebsoft.com/wp-login.php</a> ' . __( '(your username is the email you specify when purchasing the product). If necessary, please submit "Lost your password?" request.', 'bestwebsoft' ); ?></p>
578 <p>
579 <input type="text" maxlength="100" name="bws_license_key" value="<?php echo $license_key; ?>" />
580 <input type="hidden" name="bws_license_submit" value="submit" />
581 <input type="submit" class="button-primary" value="<?php _e( 'Check license key', 'bestwebsoft' ) ?>" />
582 <?php wp_nonce_field( $plugin_basename, 'bws_license_nonce_name' ); ?>
583 </p>
584 </form>
585 <?php }
586 }
587
588 if ( ! function_exists ( 'bws_plugin_update_row' ) ) {
589 function bws_plugin_update_row( $plugin_key, $link_slug = false, $free_plugin_name = false ) {
590 global $bstwbsftwppdtplgns_options;
591 $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
592 if ( isset( $bstwbsftwppdtplgns_options['wrong_license_key'][ $plugin_key ] ) ) {
593 echo '<tr class="plugin-update-tr">
594 <td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange">
595 <div class="update-message" style="background-color: #FFEBE8; border-color: #CC0000;"><strong>' . __( 'WARNING: Illegal use notification', 'bestwebsoft' ) . '.</strong> ' . __( 'You can use one license of the Pro plugin for one domain only. Please check and edit your license or domain if necessary using you personal Client Area. We strongly recommend you to solve the problem within 24 hours, otherwise the Pro plugin will be deactivated.', 'bestwebsoft' ) . ' <a target="_blank" href="http://support.bestwebsoft.com/hc/en-us/articles/204240089">' . __( 'Learn More', 'bestwebsoft' ) . '</a></div>
596 </td>
597 </tr>';
598 } elseif ( isset( $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] ) && strtotime( $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] ) < strtotime( date("m/d/Y") ) ) {
599 echo '<tr class="plugin-update-tr">
600 <td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange">
601 <div class="update-message" style="color: #8C0000;">';
602 if ( isset( $bstwbsftwppdtplgns_options['trial'][ $plugin_key ] ) && $link_slug != false ) {
603 echo __( 'Notice: Your Pro Trial license has expired. To continue using the plugin you should buy a Pro license', 'bestwebsoft' ) . ' - <a href="http://bestwebsoft.com/products/' . $link_slug .'/">http://bestwebsoft.com/products/' . $link_slug . '/</a>';
604 } else {
605 echo __( 'Your license has expired. To continue getting top-priority support and plugin updates you should extend it.', 'bestwebsoft' ) . ' <a target="_new" href="http://support.bestwebsoft.com/entries/53487136">' . __( "Learn more", 'bestwebsoft' ) . '</a>';
606 }
607 echo '</div>
608 </td>
609 </tr>';
610 } elseif ( isset( $bstwbsftwppdtplgns_options['trial'][ $plugin_key ] ) ) {
611 echo '<tr class="plugin-update-tr">
612 <td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange">
613 <div class="update-message" style="color: #8C0000;">';
614 if ( $free_plugin_name != false ) {
615 echo sprintf( __( 'Notice: You are using the Pro Trial license of %s plugin.', 'bestwebsoft' ), $free_plugin_name );
616 } else {
617 _e( 'Notice: You are using the Pro Trial license of plugin.', 'bestwebsoft' );
618 }
619 if ( isset( $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] ) )
620 echo ' ' . __( "The Pro Trial license will expire on", 'bestwebsoft' ) . ' ' . $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] . '.';
621 echo '</div>
622 </td>
623 </tr>';
624 }
625 }
626 }
627
628 if ( ! function_exists ( 'bws_plugin_banner_timeout' ) ) {
629 function bws_plugin_banner_timeout( $plugin_key, $plugin_prefix, $plugin_name, $banner_url = false ) {
630 global $bstwbsftwppdtplgns_options, $bstwbsftwppdtplgns_cookie_add;
631 if ( isset( $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] ) && ( strtotime( $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] ) < strtotime( date("m/d/Y") . '+1 month' ) ) && ( strtotime( $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] ) > strtotime( date("m/d/Y") ) ) ) {
632 if ( ! isset( $bstwbsftwppdtplgns_cookie_add ) ) {
633 echo '<script type="text/javascript" src="' . plugins_url( 'js/c_o_o_k_i_e.js', __FILE__ ) . '"></script>';
634 $bstwbsftwppdtplgns_cookie_add = true;
635 } ?>
636 <script type="text/javascript">
637 (function($) {
638 $(document).ready( function() {
639 var hide_message = $.cookie( "<?php echo $plugin_prefix; ?>_timeout_hide_banner_on_plugin_page" );
640 if ( hide_message == "true" ) {
641 $( ".<?php echo $plugin_prefix; ?>_message" ).css( "display", "none" );
642 } else {
643 $( ".<?php echo $plugin_prefix; ?>_message" ).css( "display", "block" );
644 }
645 $( ".<?php echo $plugin_prefix; ?>_close_icon" ).click( function() {
646 $( ".<?php echo $plugin_prefix; ?>_message" ).css( "display", "none" );
647 $.cookie( "<?php echo $plugin_prefix; ?>_timeout_hide_banner_on_plugin_page", "true", { expires: 30 } );
648 });
649 });
650 })(jQuery);
651 </script>
652 <div class="updated" style="padding: 0; margin: 0; border: none; background: none;">
653 <div class="<?php echo $plugin_prefix; ?>_message bws_banner_on_plugin_page bws_banner_timeout" style="display:none;">
654 <button class="<?php echo $plugin_prefix; ?>_close_icon close_icon notice-dismiss bws_hide_settings_notice" title="<?php _e( 'Close notice', 'bestwebsoft' ); ?>"></button>
655 <div class="icon">
656 <img title="" src="<?php echo $banner_url; ?>" alt="" />
657 </div>
658 <div class="text"><?php _e( "You license for", 'bestwebsoft' ); ?> <strong><?php echo $plugin_name; ?></strong> <?php echo __( "expires on", 'bestwebsoft' ) . ' ' . $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] . ' ' . __( "and you won't be granted TOP-PRIORITY SUPPORT or UPDATES.", 'bestwebsoft' ); ?> <a target="_new" href="http://support.bestwebsoft.com/entries/53487136"><?php _e( "Learn more", 'bestwebsoft' ); ?></a></div>
659 </div>
660 </div>
661 <?php }
662 }
663 }
664
665 if ( ! function_exists( 'bws_plugin_banner_to_settings' ) ) {
666 function bws_plugin_banner_to_settings( $plugin_info, $plugin_options_name, $banner_url_or_slug, $settings_url, $post_type_url = false, $post_type_name = false ) {
667 global $wp_version;
668
669 $plugin_options = get_option( $plugin_options_name );
670
671 if ( isset( $plugin_options['display_settings_notice'] ) && 0 == $plugin_options['display_settings_notice'] )
672 return;
673
674 if ( isset( $_POST['bws_hide_settings_notice_' . $plugin_options_name ] ) && check_admin_referer( $plugin_info['Name'], 'bws_settings_nonce_name' ) ) {
675 $plugin_options['display_settings_notice'] = 0;
676 update_option( $plugin_options_name, $plugin_options );
677 return;
678 }
679
680 if ( false == strrpos( $banner_url_or_slug, '/' ) ) {
681 $banner_url_or_slug = '//ps.w.org/' . $banner_url_or_slug . '/assets/icon-128x128.png';
682 } ?>
683 <div class="updated" style="padding: 0; margin: 0; border: none; background: none;">
684 <div class="bws_banner_on_plugin_page bws_banner_to_settings">
685 <div class="icon">
686 <img title="" src="<?php echo esc_attr( $banner_url_or_slug ); ?>" alt="" />
687 </div>
688 <div class="text">
689 <strong><?php _e( 'Thank you for installing', 'bestwebsoft' ); ?> <?php echo $plugin_info['Name']; ?> plugin!</strong><br />
690 <?php _e( "Let's get started", 'bestwebsoft' ); ?>:
691 <a target="_blank" href="<?php echo $settings_url; ?>"><?php _e( 'Configure Settings', 'bestwebsoft' ); ?></a>
692 <?php if ( false != $post_type_url && false != $post_type_name ) { ?>
693 <?php _e( 'or', 'bestwebsoft' ); ?>
694 <a target="_blank" href="<?php echo $post_type_url; ?>"><?php _e( 'Add New', 'bestwebsoft' ); ?> <?php echo $post_type_name; ?></a>
695 <?php } ?>
696 </div>
697 <form action="" method="post">
698 <button class="notice-dismiss bws_hide_settings_notice" title="<?php _e( 'Close notice', 'bestwebsoft' ); ?>"></button>
699 <input type="hidden" name="bws_hide_settings_notice_<?php echo $plugin_options_name; ?>" value="hide" />
700 <?php wp_nonce_field( $plugin_info['Name'], 'bws_settings_nonce_name' ); ?>
701 </form>
702 </div>
703 </div>
704 <?php }
705 }
706
707 if ( ! function_exists( 'bws_plugin_suggest_feature_banner' ) ) {
708 function bws_plugin_suggest_feature_banner( $plugin_info, $plugin_options_name, $banner_url_or_slug ) {
709 global $wp_version;
710
711 $plugin_options = get_option( $plugin_options_name );
712
713 if ( isset( $plugin_options['display_suggest_feature_banner'] ) && 0 == $plugin_options['display_suggest_feature_banner'] )
714 return;
715
716 if ( ! isset( $plugin_options['first_install'] ) ) {
717 $plugin_options['first_install'] = strtotime( "now" );
718 update_option( $plugin_options_name, $plugin_options );
719 $return = true;
720 } elseif ( strtotime( '-2 week' ) < $plugin_options['first_install'] ) {
721 $return = true;
722 }
723
724 if ( ! isset( $plugin_options['go_settings_counter'] ) ) {
725 $plugin_options['go_settings_counter'] = 1;
726 update_option( $plugin_options_name, $plugin_options );
727 $return = true;
728 } elseif ( 20 > $plugin_options['go_settings_counter'] ) {
729 $plugin_options['go_settings_counter'] = $plugin_options['go_settings_counter'] + 1;
730 update_option( $plugin_options_name, $plugin_options );
731 $return = true;
732 }
733
734 if ( isset( $return ) )
735 return;
736
737 if ( isset( $_POST['bws_hide_suggest_feature_banner_' . $plugin_options_name ] ) && check_admin_referer( $plugin_info['Name'], 'bws_settings_nonce_name' ) ) {
738 $plugin_options['display_suggest_feature_banner'] = 0;
739 update_option( $plugin_options_name, $plugin_options );
740 return;
741 }
742
743 if ( false == strrpos( $banner_url_or_slug, '/' ) ) {
744 $banner_url_or_slug = '//ps.w.org/' . $banner_url_or_slug . '/assets/icon-128x128.png';
745 } ?>
746 <div class="updated" style="padding: 0; margin: 0; border: none; background: none;">
747 <div class="bws_banner_on_plugin_page bws_suggest_feature_banner">
748 <div class="icon">
749 <img title="" src="<?php echo esc_attr( $banner_url_or_slug ); ?>" alt="" />
750 </div>
751 <div class="text">
752 <strong><?php _e( 'Thank you for choosing', 'bestwebsoft' ); ?> <?php echo $plugin_info['Name']; ?> plugin!</strong><br />
753 <?php _e( "If you have a feature, suggestion or idea you'd like to see in the plugin, we'd love to hear about it!", 'bestwebsoft' ); ?>
754 <a target="_blank" href="http://support.bestwebsoft.com/hc/en-us/requests/new"><?php _e( 'Suggest a Feature', 'bestwebsoft' ); ?></a>
755 </div>
756 <form action="" method="post">
757 <button class="notice-dismiss bws_hide_settings_notice" title="<?php _e( 'Close notice', 'bestwebsoft' ); ?>"></button>
758 <input type="hidden" name="bws_hide_suggest_feature_banner_<?php echo $plugin_options_name; ?>" value="hide" />
759 <?php wp_nonce_field( $plugin_info['Name'], 'bws_settings_nonce_name' ); ?>
760 </form>
761 </div>
762 </div>
763 <?php }
764 }
765
766 if ( ! function_exists( 'bws_show_settings_notice' ) ) {
767 function bws_show_settings_notice() { ?>
768 <div id="bws_save_settings_notice" class="updated fade below-h2" style="display:none;">
769 <p>
770 <strong><?php _e( 'Notice', 'bestwebsoft' ); ?></strong>: <?php _e( "The plugin's settings have been changed.", 'bestwebsoft' ); ?>
771 <a class="bws_save_anchor" href="#bws-submit-button"><?php _e( 'Save Changes', 'bestwebsoft' ); ?></a>
772 </p>
773 </div>
774 <?php }
775 }
776
777 if ( ! function_exists( 'bws_hide_premium_options' ) ) {
778 function bws_hide_premium_options( $options ) {
779 global $current_user;
780 if ( ! $current_user )
781 get_currentuserinfo();
782 if ( ! isset( $options['hide_premium_options'] ) || ! is_array( $options['hide_premium_options'] ) )
783 $options['hide_premium_options'] = array();
784
785 $options['hide_premium_options'][] = $current_user->ID;
786
787 return array(
788 'message' => __( 'You can always look at premium options by clicking on the "Show Pro features" in the "Go PRO" tab', 'bestwebsoft' ),
789 'options' => $options );
790 }
791 }
792
793 if ( ! function_exists( 'bws_hide_premium_options_check' ) ) {
794 function bws_hide_premium_options_check( $options ) {
795 global $current_user;
796 if ( ! $current_user )
797 get_currentuserinfo();
798
799 if ( ! empty( $options['hide_premium_options'] ) && in_array( $current_user->ID, $options['hide_premium_options'] ) )
800 return true;
801 else
802 return false;
803 }
804 }
805
806 if ( ! function_exists ( 'bws_plugins_admin_init' ) ) {
807 function bws_plugins_admin_init() {
808 /* Internationalization, first(!) */
809 load_plugin_textdomain( 'bestwebsoft', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
810
811 bws_add_editor_buttons();
812 }
813 }
814
815 if ( ! function_exists ( 'bws_admin_enqueue_scripts' ) ) {
816 function bws_admin_enqueue_scripts() {
817 global $wp_version;
818 wp_enqueue_style( 'bws-admin-css', plugins_url( 'css/general_style.css', __FILE__ ) );
819 wp_enqueue_script( 'bws-admin-scripts', plugins_url( 'js/general_script.js', __FILE__ ), array( 'jquery' ) );
820
821 if ( isset( $_GET['page'] ) && $_GET['page'] == "bws_plugins" ) {
822 wp_enqueue_style( 'bws_menu_style', plugins_url( 'css/style.css', __FILE__ ) );
823 wp_enqueue_script( 'bws_menu_script', plugins_url( 'js/bws_menu.js' , __FILE__ ) );
824 wp_enqueue_script( 'theme-install' );
825 }
826 }
827 }
828
829 if ( ! function_exists ( 'bws_plugins_admin_head' ) ) {
830 function bws_plugins_admin_head() {
831 global $bws_shortcode_list, $wp_version, $post_type;
832 if ( isset( $_GET['page'] ) && $_GET['page'] == "bws_plugins" ) { ?>
833 <noscript>
834 <style type="text/css">
835 .bws_product_button {
836 display: inline-block;
837 }
838 </style>
839 </noscript>
840 <?php }
841 if ( 4.2 > $wp_version ) {
842 $plugin_dir_array = explode( '/', plugin_basename( __FILE__ ) );
843 $plugin_dir = $plugin_dir_array[0]; ?>
844 <style type="text/css">
845 .bws_hide_settings_notice,
846 .bws_hide_premium_options {
847 width: 11px;
848 height: 11px;
849 border: none;
850 background: url("<?php echo plugins_url( $plugin_dir . '/bws_menu/images/close_banner.png' ); ?>") no-repeat center center;
851 box-shadow: none;
852 float: right;
853 margin: 8px;
854 }
855 .bws_hide_settings_notice:hover,
856 .bws_hide_premium_options:hover {
857 cursor: pointer;
858 }
859 .bws_hide_premium_options {
860 position: relative;
861 }
862 </style>
863 <?php }
864 if ( ! empty( $bws_shortcode_list ) ) { ?>
865 <!-- TinyMCE Shortcode Plugin -->
866 <script type='text/javascript'>
867 var bws_shortcode_button = {
868 'title': '<?php esc_attr_e( "Add BWS Plugins Shortcode", "bestwebsoft" ); ?>',
869 'function_name': [
870 <?php foreach ( $bws_shortcode_list as $key => $value ) {
871 if ( isset( $value['js_function'] ) )
872 echo "'" . $value['js_function'] . "',";
873 } ?>
874 ],
875 'icon_url': '<?php echo plugins_url( "images/shortcode-icon.png" , __FILE__ ); ?>',
876 'wp_version' : '<?php echo $wp_version; ?>'
877 };
878 </script>
879 <!-- TinyMCE Shortcode Plugin -->
880 <?php if ( isset( $post_type ) && in_array( $post_type, array( 'post', 'page' ) ) ) {
881 $tooltip_args = array(
882 'tooltip_id' => 'bws_shortcode_button_tooltip',
883 'css_selector' => '.mce-bws_shortcode_button',
884 'actions' => array(
885 'click' => false,
886 'onload' => true
887 ),
888 'content' => '<h3>' . __( 'Add shortcode', 'bestwebsoft' ) . '</h3><p>' . __( "Add BestWebSoft plugins' shortcodes using this button.", 'bestwebsoft' ) . '</p>',
889 'position' => array(
890 'edge' => 'right'
891 ),
892 'set_timeout' => 2000
893 );
894 if ( $wp_version < '3.9' )
895 $tooltip_args['css_selector'] = '.mce_add_bws_shortcode';
896 bws_add_tooltip_in_admin( $tooltip_args );
897 }
898 }
899 }
900 }
901
902 if ( ! function_exists ( 'bws_plugins_include_codemirror' ) ) {
903 function bws_plugins_include_codemirror() {
904 wp_enqueue_style( 'codemirror.css', plugins_url( 'css/codemirror.css', __FILE__ ) );
905 wp_enqueue_script( 'codemirror.js', plugins_url( 'js/codemirror.js', __FILE__ ), array( 'jquery' ) );
906 }
907 }
908
909 /**
910 * Tooltip block
911 */
912 if ( ! function_exists( 'bws_add_tooltip_in_admin' ) ) {
913 function bws_add_tooltip_in_admin( $tooltip_args = array() ) {
914 new BWS_admin_tooltip( $tooltip_args );
915 }
916 }
917
918 if ( ! class_exists( 'BWS_admin_tooltip' ) ) {
919 class BWS_admin_tooltip {
920 private $tooltip_args;
921
922 public function __construct( $tooltip_args ) {
923 global $wp_version;
924 if ( 3.3 > $wp_version )
925 return;
926 /* Default arguments */
927 $tooltip_args_default = array(
928 'tooltip_id' => false,
929 'css_selector' => false,
930 'actions' => array(
931 'click' => true,
932 'onload' => false,
933 ),
934 'buttons' => array(
935 'close' => array(
936 'type' => 'dismiss',
937 'text' => __( 'Close', 'bestwebsoft' ),
938 ),
939 ),
940 'position' => array(
941 'edge' => 'top',
942 'align' => 'center',
943 'pos-left' => 0,
944 'pos-top' => 0,
945 'zindex' => 10000
946 ),
947 'set_timeout' => 0
948 );
949 $tooltip_args = array_merge( $tooltip_args_default, $tooltip_args );
950 /* Check that our merged array has default values */
951 foreach ( $tooltip_args_default as $arg_key => $arg_value ) {
952 if ( is_array( $arg_value ) ) {
953 foreach ( $arg_value as $key => $value) {
954 if ( ! isset( $tooltip_args[ $arg_key ][ $key ] ) ) {
955 $tooltip_args[ $arg_key ][ $key ] = $tooltip_args_default[ $arg_key ][ $key ];
956 }
957 }
958 }
959 }
960 /* Check if tooltip is dismissed */
961 if ( true === $tooltip_args['actions']['onload'] ) {
962 if ( in_array( $tooltip_args['tooltip_id'], array_filter( explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ) ) ) ) {
963 $tooltip_args['actions']['onload'] = false;
964 }
965 }
966 /* Check entered data */
967 if ( false === $tooltip_args['tooltip_id'] || false === $tooltip_args['css_selector'] || ( false === $tooltip_args['actions']['click'] && false === $tooltip_args['actions']['onload'] ) ) {
968 /* if not enough data to output a tooltip or both actions (click, onload) are false */
969 return;
970 } else {
971 /* check position */
972 if ( ! in_array( $tooltip_args['position']['edge'], array( 'left', 'right', 'top', 'bottom' ) ) ) {
973 $tooltip_args['position']['edge'] = 'top';
974 }
975 if ( ! in_array( $tooltip_args['position']['align'], array( 'top', 'bottom', 'left', 'right', 'center', ) ) ) {
976 $tooltip_args['position']['align'] = 'center';
977 }
978 }
979 /* fix position */
980 switch ( $tooltip_args['position']['edge'] ) {
981 case 'left':
982 case 'right':
983 switch ( $tooltip_args['position']['align'] ) {
984 case 'top':
985 case 'bottom':
986 $tooltip_args['position']['align'] = 'center';
987 break;
988 }
989 break;
990 case 'top':
991 case 'bottom':
992 if ( $tooltip_args['position']['align'] == 'left' ) {
993 $tooltip_args['position']['pos-left'] -= 65;
994 }
995 break;
996 }
997 $this->tooltip_args = $tooltip_args;
998 /* add styles and scripts */
999 wp_enqueue_style( 'wp-pointer' );
1000 wp_enqueue_script( 'wp-pointer' );
1001 /* add script that displays our tooltip */
1002 add_action( 'admin_print_footer_scripts', array( $this, 'add_scripts' ) );
1003 }
1004
1005 /**
1006 * Display tooltip
1007 */
1008 public function add_scripts() {
1009 global $bstwbsftwppdtplgns_tooltip_script_add;
1010 if ( ! isset( $bstwbsftwppdtplgns_tooltip_script_add ) ) {
1011 echo '<script type="text/javascript" src="' . plugins_url( 'js/bws_tooltip.js', __FILE__ ) . '"></script>';
1012 $bstwbsftwppdtplgns_tooltip_script_add = true;
1013 }
1014 $tooltip_args = $this->tooltip_args; ?>
1015 <script type="text/javascript">
1016 (function($) {
1017 $(document).ready( function() {
1018 $.bwsTooltip( <?php echo json_encode( $tooltip_args ); ?> );
1019 })
1020 })(jQuery);
1021 </script>
1022 <?php }
1023 }
1024 }
1025
1026 if ( ! function_exists ( 'bws_form_restore_default_settings' ) ) {
1027 function bws_form_restore_default_settings( $plugin_basename, $change_permission_attr = '' ) { ?>
1028 <form method="post" action="">
1029 <p><?php _e( 'Restore all plugin settings to defaults', 'bestwebsoft' ); ?></p>
1030 <p>
1031 <input <?php echo $change_permission_attr; ?> type="submit" class="button" value="<?php _e( 'Restore settings', 'bestwebsoft' ); ?>" />
1032 </p>
1033 <input type="hidden" name="bws_restore_default" value="submit" />
1034 <?php wp_nonce_field( $plugin_basename, 'bws_settings_nonce_name' ); ?>
1035 </form>
1036 <?php }
1037 }
1038
1039 if ( ! function_exists ( 'bws_form_restore_default_confirm' ) ) {
1040 function bws_form_restore_default_confirm( $plugin_basename ) { ?>
1041 <div>
1042 <p><?php _e( 'Are you sure you want to restore all settings by default?', 'bestwebsoft' ) ?></p>
1043 <form method="post" action="">
1044 <p>
1045 <button class="button" name="bws_restore_confirm"><?php _e( 'Yes, restore all settings', 'bestwebsoft' ) ?></button>
1046 <button class="button" name="bws_restore_deny"><?php _e( 'No, go back to the settings page', 'bestwebsoft' ) ?></button>
1047 <?php wp_nonce_field( $plugin_basename, 'bws_settings_nonce_name' ); ?>
1048 </p>
1049 </form>
1050 </div>
1051 <?php }
1052 }
1053
1054 /* shortcode */
1055 if ( ! function_exists( 'bws_add_editor_buttons' ) ) {
1056 function bws_add_editor_buttons() {
1057 global $bws_shortcode_list, $wp_version;
1058 if ( $wp_version < '3.3' )
1059 return;
1060 if ( ! empty( $bws_shortcode_list ) && current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) ) {
1061 add_filter( 'mce_external_plugins', 'bws_add_buttons' );
1062 add_filter( 'mce_buttons', 'bws_register_buttons' );
1063 }
1064 }
1065 }
1066
1067 if ( ! function_exists( 'bws_add_buttons' ) ){
1068 function bws_add_buttons( $plugin_array ) {
1069 $plugin_array['add_bws_shortcode'] = plugins_url( 'js/shortcode-button.js', __FILE__ );
1070 return $plugin_array;
1071 }
1072 }
1073
1074 if ( ! function_exists( 'bws_register_buttons' ) ) {
1075 function bws_register_buttons( $buttons ) {
1076 array_push( $buttons, 'add_bws_shortcode' ); /* dropcap', 'recentposts */
1077 return $buttons;
1078 }
1079 }
1080
1081 /* Generate inline content for the popup window when the "bws shortcode" button is clicked */
1082 if ( ! function_exists( 'bws_shortcode_media_button_popup' ) ) {
1083 function bws_shortcode_media_button_popup() {
1084 global $bws_shortcode_list, $wp_version;
1085 if ( $wp_version < '3.3' )
1086 return;
1087
1088 if ( ! empty( $bws_shortcode_list ) ) { ?>
1089 <div id="bws_shortcode_popup" style="display:none;">
1090 <div id="bws_shortcode_popup_block">
1091 <div id="bws_shortcode_select_plugin">
1092 <h4><?php _e( 'Plugin', 'bestwebsoft' ); ?></h4>
1093 <select name="bws_shortcode_select" id="bws_shortcode_select">
1094 <?php foreach ( $bws_shortcode_list as $key => $value ) { ?>
1095 <option value="<?php echo $key; ?>"><?php echo $value['name']; ?></option>
1096 <?php } ?>
1097 </select>
1098 </div>
1099 <div class="clear"></div>
1100 <div id="bws_shortcode_content">
1101 <h4><?php _e( 'Shortcode settings', 'bestwebsoft' ); ?></h4>
1102 <?php echo apply_filters( 'bws_shortcode_button_content', '' ); ?>
1103 </div>
1104 <div class="clear"></div>
1105 <div id="bws_shortcode_content_bottom">
1106 <p><?php _e( 'The shortcode will be inserted', 'bestwebsoft' ); ?></p>
1107 <div id="bws_shortcode_block"><div id="bws_shortcode_display"></div></div>
1108 </div>
1109 <?php if ( $wp_version < '3.9' ) { ?>
1110 <p>
1111 <button class="button-primary primary bws_shortcode_insert"><?php _e( 'Insert', 'bestwebsoft' ); ?></button>
1112 </p>
1113 <?php } ?>
1114 </div>
1115 </div>
1116 <?php }
1117 if ( $wp_version < '3.9' ) { ?>
1118 <script type="text/javascript">
1119 (function($){
1120 $( '.bws_shortcode_insert' ).on( 'click',function() {
1121 var shortcode = $( '#TB_ajaxContent #bws_shortcode_display' ).text();
1122 if ( '' != shortcode ) {
1123 /* insert shortcode to tinymce */
1124 if ( !tinyMCE.activeEditor || tinyMCE.activeEditor.isHidden() ) {
1125 $( 'textarea#content' ).val( shortcode );
1126 } else {
1127 tinyMCE.execCommand( 'mceInsertContent', false, shortcode );
1128 }
1129 }
1130 /* close the thickbox after adding shortcode to editor */
1131 self.parent.tb_remove();
1132 });
1133 })(jQuery);
1134 </script>
1135 <?php }
1136 }
1137 }
1138
1139 /* add help tab */
1140 if ( ! function_exists( 'bws_help_tab' ) ) {
1141 function bws_help_tab( $screen, $args ) {
1142 $content = '<p><a href="http://support.bestwebsoft.com/hc/en-us/sections/' . $args['section'] . '" target="_blank">' . __( 'Visit Help Center', 'bestwebsoft' ) . '</a></p>';
1143
1144 $screen->add_help_tab(
1145 array(
1146 'id' => $args['id'] . '_help_tab',
1147 'title' => __( 'FAQ', 'bestwebsoft' ),
1148 'content' => $content
1149 )
1150 );
1151
1152 $screen->set_help_sidebar(
1153 '<p><strong>' . __( 'For more information:', 'bestwebsoft' ) . '</strong></p>' .
1154 '<p><a href="https://drive.google.com/folderview?id=0B5l8lO-CaKt9VGh0a09vUjNFNjA&usp=sharing#list" target="_blank">' . __( 'Documentation', 'bestwebsoft' ) . '</a></p>' .
1155 '<p><a href="http://www.youtube.com/user/bestwebsoft/playlists?flow=grid&sort=da&view=1" target="_blank">' . __( 'Video Instructions', 'bestwebsoft' ) . '</a></p>' .
1156 '<p><a href="http://support.bestwebsoft.com/hc/en-us/requests/new" target="_blank">' . __( 'Submit a Request', 'bestwebsoft' ) . '</a></p>'
1157 );
1158 }
1159 }
1160
1161 /**
1162 * Function display 'Custom code' tab
1163 */
1164 if ( ! function_exists( 'bws_custom_code_tab' ) ) {
1165 function bws_custom_code_tab() {
1166 if ( ! current_user_can( 'edit_plugins' ) )
1167 wp_die( __( 'You do not have sufficient permissions to edit plugins for this site.', 'bestwebsoft' ) );
1168
1169 global $bstwbsftwppdtplgns_options;
1170
1171 $message = $content = '';
1172 $is_active = false;
1173
1174 $upload_dir = wp_upload_dir();
1175 $folder = $upload_dir['basedir'] . '/bws-custom-code';
1176 if ( ! $upload_dir["error"] ) {
1177 if ( ! is_dir( $folder ) )
1178 wp_mkdir_p( $folder, 0755 );
1179 }
1180
1181 $file = 'bws-custom-code.css';
1182 $real_file = $folder . '/' . $file;
1183 $is_multisite = is_multisite();
1184 if ( $is_multisite )
1185 $blog_id = get_current_blog_id();
1186
1187 if ( isset( $_REQUEST['bws_update_custom_code'] ) && check_admin_referer( 'bws_update_' . $file ) ) {
1188
1189 $newcontent = wp_unslash( $_POST['bws_newcontent_css'] );
1190
1191
1192 if ( ! empty( $newcontent ) && isset( $_REQUEST['bws_custom_css_active'] ) ) {
1193 if ( $is_multisite )
1194 $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $file ] = $upload_dir['baseurl'] . '/bws-custom-code/' . $file;
1195 else
1196 $bstwbsftwppdtplgns_options['custom_code'][ $file ] = $upload_dir['baseurl'] . '/bws-custom-code/' . $file;
1197 } else {
1198 if ( $is_multisite ) {
1199 if ( isset( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $file ] ) )
1200 unset( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $file ] );
1201 } else {
1202 if ( isset( $bstwbsftwppdtplgns_options['custom_code'][ $file ] ) )
1203 unset( $bstwbsftwppdtplgns_options['custom_code'][ $file ] );
1204 }
1205 }
1206
1207 if ( $f = fopen( $real_file, 'w+' ) ) {
1208 fwrite( $f, $newcontent );
1209 fclose( $f );
1210 $message = __( 'File edited successfully.', 'bestwebsoft' );
1211 } else {
1212 $error = __( 'Not enough permissions to create or update the file', 'bestwebsoft' ) . ' ' . $real_file . '. <a href="https://codex.wordpress.org/Changing_File_Permissions">' . __( 'Learn more', 'bestwebsoft' ) . '</a>';
1213 }
1214
1215 if ( $is_multisite )
1216 update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
1217 else
1218 update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
1219 }
1220
1221 if ( file_exists( $real_file ) ) {
1222 update_recently_edited( $real_file );
1223 $content = file_get_contents( $real_file );
1224 $content = esc_textarea( $content );
1225 if ( ( $is_multisite && isset( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $file ] ) ) ||
1226 ( ! $is_multisite && isset( $bstwbsftwppdtplgns_options['custom_code'][ $file ] ) ) ) {
1227 $is_active = true;
1228 }
1229 }
1230
1231 if ( ! empty( $message ) ) { ?>
1232 <div id="message" class="below-h2 updated notice is-dismissible"><p><?php echo $message; ?></p></div>
1233 <?php } ?>
1234 <p><?php _e( 'These styles will be added to the header on all pages of your site.', 'bestwebsoft' ); ?></p>
1235 <p><big>
1236 <?php if ( ! file_exists( $real_file ) || ( is_writeable( $real_file ) ) ) {
1237 echo __( 'Editing', 'bestwebsoft' ) . ' <strong>' . $file . '</strong>';
1238 } else {
1239 echo __( 'Browsing', 'bestwebsoft' ) . ' <strong>' . $file . '</strong>';
1240 } ?>
1241 </big></p>
1242 <form action="" method="post">
1243 <?php wp_nonce_field( 'bws_update_' . $file ); ?>
1244 <p><label><input type="checkbox" name="bws_custom_css_active" value="1" <?php if ( $is_active ) echo "checked"; ?> /> <?php _e( 'Activate', 'bestwebsoft' ); ?></label></p>
1245 <textarea cols="70" rows="25" name="bws_newcontent_css" id="bws_newcontent_css"><?php echo $content; ?></textarea>
1246 <p class="description">
1247 <a href="https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_started" target="_blank"><?php _e( 'Learn more about CSS', 'bestwebsoft' ); ?></a>
1248 </p>
1249 <?php if ( ! file_exists( $real_file ) || is_writeable( $real_file ) ) { ?>
1250 <p class="submit">
1251 <input type="hidden" name="bws_update_custom_code" value="submit" />
1252 <?php submit_button( __( 'Save Changes', 'bestwebsoft' ), 'primary', 'submit', false ); ?>
1253 </p>
1254 <?php } else { ?>
1255 <p><em><?php printf( __( 'You need to make this file writable before you can save your changes. See %s the Codex %s for more information.', 'bestwebsoft' ),
1256 '<a href="https://codex.wordpress.org/Changing_File_Permissions">',
1257 '</a>' ); ?></em></p>
1258 <?php } ?>
1259 </form>
1260 <?php }
1261 }
1262
1263 if ( ! function_exists( 'bws_enqueue_custom_code' ) ) {
1264 function bws_enqueue_custom_code() {
1265 global $bstwbsftwppdtplgns_options;
1266
1267 if ( ! isset( $bstwbsftwppdtplgns_options ) )
1268 $bstwbsftwppdtplgns_options = ( function_exists( 'is_multisite' ) && is_multisite() ) ? get_site_option( 'bstwbsftwppdtplgns_options' ) : get_option( 'bstwbsftwppdtplgns_options' );
1269
1270 if ( ! empty( $bstwbsftwppdtplgns_options['custom_code'] ) ) {
1271 $is_multisite = is_multisite();
1272 if ( $is_multisite )
1273 $blog_id = get_current_blog_id();
1274
1275 if ( ! $is_multisite && ! empty( $bstwbsftwppdtplgns_options['custom_code']['bws-custom-code.css'] ) )
1276 wp_enqueue_style( 'bws-custom-style', $bstwbsftwppdtplgns_options['custom_code']['bws-custom-code.css'] );
1277 elseif ( $is_multisite && ! empty( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ]['bws-custom-code.css'] ) )
1278 wp_enqueue_style( 'bws-custom-style', $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ]['bws-custom-code.css'] );
1279 }
1280 }
1281 }
1282
1283 if ( ! function_exists( 'bws_delete_plugin' ) ) {
1284 function bws_delete_plugin( $basename ) {
1285 global $bstwbsftwppdtplgns_options;
1286
1287 $is_multisite = is_multisite();
1288 if ( $is_multisite )
1289 $blog_id = get_current_blog_id();
1290
1291 if ( ! isset( $bstwbsftwppdtplgns_options ) )
1292 $bstwbsftwppdtplgns_options = ( $is_multisite ) ? get_site_option( 'bstwbsftwppdtplgns_options' ) : get_option( 'bstwbsftwppdtplgns_options' );
1293
1294 /* remove bws_menu versions */
1295 unset( $bstwbsftwppdtplgns_options['bws_menu']['version'][ $basename ] );
1296 /* if empty ['bws_menu']['version'] - there is no other bws plugins - delete all */
1297 if ( empty( $bstwbsftwppdtplgns_options['bws_menu']['version'] ) ) {
1298 /* remove options */
1299 if ( $is_multisite )
1300 delete_site_option( 'bstwbsftwppdtplgns_options' );
1301 else
1302 delete_option( 'bstwbsftwppdtplgns_options' );
1303
1304 /* remove custom_code */
1305 if ( $is_multisite ) {
1306 global $wpdb;
1307 $old_blog = $wpdb->blogid;
1308 /* Get all blog ids */
1309 $blogids = $wpdb->get_col( "SELECT `blog_id` FROM $wpdb->blogs" );
1310 foreach ( $blogids as $blog_id ) {
1311 switch_to_blog( $blog_id );
1312 $upload_dir = wp_upload_dir();
1313 $folder = $upload_dir['basedir'] . '/bws-custom-code';
1314 if ( file_exists( $folder ) && is_dir( $folder ) ) {
1315 array_map( 'unlink', glob( "$folder/*" ) );
1316 rmdir( $folder );
1317 }
1318 }
1319 switch_to_blog( $old_blog );
1320 } else {
1321 $upload_dir = wp_upload_dir();
1322 $folder = $upload_dir['basedir'] . '/bws-custom-code';
1323 if ( file_exists( $folder ) && is_dir( $folder ) ) {
1324 array_map( 'unlink', glob( "$folder/*" ) );
1325 rmdir( $folder );
1326 }
1327 }
1328 }
1329 }
1330 }
1331
1332 add_action( 'admin_init', 'bws_plugins_admin_init' );
1333 add_action( 'admin_enqueue_scripts', 'bws_admin_enqueue_scripts' );
1334 add_action( 'admin_head', 'bws_plugins_admin_head' );
1335 add_action( 'admin_footer','bws_shortcode_media_button_popup' );
1336
1337 add_action( 'admin_notices', 'bws_versions_notice' );
1338
1339 add_action( 'wp_enqueue_scripts', 'bws_enqueue_custom_code', 20 );