PluginProbe ʕ •ᴥ•ʔ
reCaptcha by BestWebSoft / 1.74
reCaptcha by BestWebSoft v1.74
1.79 1.80 1.82 1.83 1.84 1.85 1.86 1.87 trunk 1.01 1.02 1.03 1.04 1.05 1.06 1.07 1.08 1.09 1.10 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.18 1.19 1.20 1.21 1.22 1.23 1.24 1.25 1.26 1.27 1.28 1.29 1.30 1.31 1.32 1.33 1.34 1.35 1.36 1.37 1.38 1.39 1.40 1.41 1.42 1.43 1.44 1.45 1.46 1.47 1.48 1.49 1.50 1.51 1.52 1.53 1.54 1.55 1.56 1.57 1.58 1.59 1.60 1.61 1.62 1.63 1.64 1.65 1.66 1.67 1.68 1.70 1.71 1.72 1.73 1.74 1.75 1.78
google-captcha / bws_menu / bws_functions.php
google-captcha / bws_menu Last commit date
css 2 years ago fonts 2 years ago icons 2 years ago images 2 years ago js 2 years ago languages 2 years ago bws_functions.php 2 years ago bws_include.php 2 years ago bws_menu.php 2 years ago class-bws-settings.php 2 years ago deactivation-form.php 2 years ago deprecated.php 2 years ago product_list.php 2 years ago
bws_functions.php
1386 lines
1 <?php
2 /**
3 * @package BWS Menu
4 * @version 2.4.3
5 * Main functions
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) exit;
9
10 /**
11 * General functions for BestWebSoft plugins
12 */
13 require dirname( __FILE__ ) . '/deprecated.php';
14 require_once dirname( __FILE__ ) . '/deactivation-form.php';
15
16
17 if ( ! function_exists( 'bws_get_mofile' ) ) {
18 /**
19 * Function to add 'bestwebsoft' slug for BWS_Menu MO file if BWS_Menu loaded from theme.
20 *
21 * @since 1.9.7
22 */
23 function bws_get_mofile( $mofile, $domain ) {
24 if ( 'bestwebsoft' === $domain ) {
25 $locale = get_locale();
26 return str_replace( $locale, "bestwebsoft-{$locale}", $mofile );
27 }
28
29 return $mofile;
30 }
31 }
32
33 /**
34 * Internationalization, first(!)
35 *
36 * @since 1.9.7
37 */
38 if ( isset( $bws_menu_source ) && 'themes' === $bws_menu_source ) {
39 add_filter( 'load_textdomain_mofile', 'bws_get_mofile', 10, 2 );
40 load_theme_textdomain( 'bestwebsoft', get_stylesheet_directory() . '/inc/bws_menu/languages' );
41 remove_filter( 'load_textdomain_mofile', 'bws_get_mofile' );
42 } else {
43 load_plugin_textdomain( 'bestwebsoft', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
44 }
45
46 /**
47 * Function to getting url to current BWS_Menu.
48 *
49 * @since 1.9.7
50 */
51 if ( ! function_exists( 'bws_menu_url' ) ) {
52 if ( ! isset( $bws_menu_source ) || 'plugins' === $bws_menu_source ) {
53 function bws_menu_url( $path = '' ) {
54 return plugins_url( $path, __FILE__ );
55 }
56 } else {
57 function bws_menu_url( $path = '' ) {
58 $bws_menu_current_dir = str_replace( '\\', '/', dirname( __FILE__ ) );
59 $bws_menu_abspath = str_replace( '\\', '/', ABSPATH );
60 $bws_menu_current_url = site_url( str_replace( $bws_menu_abspath, '', $bws_menu_current_dir ) );
61
62 return sprintf( '%s/%s', $bws_menu_current_url, $path );
63 }
64 }
65 }
66
67 /**
68 * Function check if plugin is compatible with current WP version
69 *
70 * @return void
71 */
72 if ( ! function_exists( 'bws_wp_min_version_check' ) ) {
73 function bws_wp_min_version_check( $plugin_basename, $plugin_info, $require_wp, $min_wp = false ) {
74 global $wp_version, $bws_versions_notice_array;
75 if ( false === $min_wp ) {
76 $min_wp = $require_wp;
77 }
78 if ( version_compare( $wp_version, $min_wp, '<' ) ) {
79 include_once ABSPATH . 'wp-admin/includes/plugin.php';
80 if ( is_plugin_active( $plugin_basename ) ) {
81 deactivate_plugins( $plugin_basename );
82 $admin_url = ( function_exists( 'get_admin_url' ) ) ? get_admin_url( null, 'plugins.php' ) : esc_url( '/wp-admin/plugins.php' );
83 wp_die(
84 sprintf(
85 "<strong>%s</strong> %s <strong>WordPress %s</strong> %s <br /><br />%s <a href='%s'>%s</a>.",
86 esc_html( $plugin_info['Name'] ),
87 esc_html__( 'requires', 'bestwebsoft' ),
88 esc_html( $require_wp ),
89 esc_html__( 'or higher, that is why it has been deactivated! Please upgrade WordPress and try again.', 'bestwebsoft' ),
90 esc_html__( 'Back to the WordPress', 'bestwebsoft' ),
91 esc_url( $admin_url ),
92 esc_html__( 'Plugins page', 'bestwebsoft' )
93 )
94 );
95 }
96 } elseif ( version_compare( $wp_version, $require_wp, '<' ) ) {
97 $bws_versions_notice_array[] = array(
98 'name' => $plugin_info['Name'],
99 'version' => $require_wp,
100 );
101 }
102 }
103 }
104
105 /**
106 * Function display review block
107 *
108 * @echo string
109 */
110 if ( ! function_exists( 'bws_plugin_reviews_block' ) ) {
111 function bws_plugin_reviews_block( $plugin_name, $plugin_slug ) { ?>
112 <div class="bws-plugin-reviews">
113 <div class="bws-plugin-reviews-rate">
114 <?php esc_html_e( 'Like the plugin?', 'bestwebsoft' ); ?>
115 <a href="https://wordpress.org/support/view/plugin-reviews/<?php echo esc_attr( $plugin_slug ); ?>?filter=5" target="_blank" title="<?php printf( esc_html__( '%s reviews', 'bestwebsoft' ), esc_html( sanitize_text_field( $plugin_name ) ) ); ?>">
116 <?php esc_html_e( 'Rate it', 'bestwebsoft' ); ?>
117 <span class="dashicons dashicons-star-filled"></span>
118 <span class="dashicons dashicons-star-filled"></span>
119 <span class="dashicons dashicons-star-filled"></span>
120 <span class="dashicons dashicons-star-filled"></span>
121 <span class="dashicons dashicons-star-filled"></span>
122 </a>
123 </div>
124 <div class="bws-plugin-reviews-support">
125 <?php esc_html_e( 'Need help?', 'bestwebsoft' ); ?>
126 <a href="https://support.bestwebsoft.com"><?php esc_html_e( 'Visit Help Center', 'bestwebsoft' ); ?></a>
127 </div>
128 <div class="bws-plugin-reviews-donate">
129 <?php esc_html_e( 'Want to support the plugin?', 'bestwebsoft' ); ?>
130 <a href="https://bestwebsoft.com/donate/"><?php esc_html_e( 'Donate', 'bestwebsoft' ); ?></a>
131 </div>
132 </div>
133 <?php
134 }
135 }
136
137 /**
138 * Function display license notification
139 *
140 * @echo string
141 */
142 if ( ! function_exists( 'bws_plugin_update_row' ) ) {
143 function bws_plugin_update_row( $plugin_key, $link_slug = false, $free_plugin_name = false ) {
144 global $bstwbsftwppdtplgns_options, $wp_version;
145 $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
146 if ( isset( $bstwbsftwppdtplgns_options['wrong_license_key'][ $plugin_key ] ) ) {
147 $explode_plugin_key = explode( '/', $plugin_key );
148 $class = ( $wp_version >= 4.6 ) ? 'active' : '';
149 $style = ( $wp_version < 4.6 ) ? ' style="background-color: #FFEBE8;border-color: #CC0000;"' : '';
150 $div_class = ( $wp_version >= 4.6 ) ? ' notice inline notice-warning notice-alt' : '';
151 echo '<tr class="bws-plugin-update-tr plugin-update-tr ' . esc_attr( $class ) . '" id="' . esc_attr( $explode_plugin_key[0] ) . '-update" data-slug="' . esc_attr( $explode_plugin_key[0] ) . '" data-plugin="' . esc_attr( $plugin_key ) . '">
152 <td colspan="' . esc_attr( $wp_list_table->get_column_count() ) . '" class="plugin-update colspanchange">
153 <div class="update-message' . esc_attr( $div_class ) . '"' . wp_kses_post( $style ) . '>';
154 if ( $wp_version >= 4.6 ) {
155 echo '<p>';
156 }
157 echo '<strong>' . esc_html__( 'WARNING: Illegal use notification', 'bestwebsoft' ) . '.</strong> ' . esc_html__( 'You can use one license of the Pro plugin for one domain only. Please check and edit your license or domain if necessary using your 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="https://support.bestwebsoft.com/hc/en-us/articles/204240089">' . esc_html__( 'Learn More', 'bestwebsoft' ) . '</a>';
158 if ( $wp_version >= 4.6 ) {
159 echo '</p>';
160 }
161 echo '</div>
162 </td>
163 </tr>';
164 } elseif ( isset( $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] ) && strtotime( $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] ) < strtotime( gmdate( 'm/d/Y' ) ) ) {
165 $explode_plugin_key = explode( '/', $plugin_key );
166 $class = ( $wp_version >= 4.6 ) ? 'active' : '';
167 $style = ( $wp_version < 4.6 ) ? ' style="color: #8C0000;"' : '';
168 $div_class = ( $wp_version >= 4.6 ) ? ' notice inline notice-warning notice-alt' : '';
169 echo '<tr class="bws-plugin-update-tr plugin-update-tr ' . esc_attr( $class ) . '" id="' . esc_attr( $explode_plugin_key[0] ) . '-update" data-slug="' . esc_attr( $explode_plugin_key[0] ) . '" data-plugin="' . esc_attr( $plugin_key ) . '">
170 <td colspan="' . esc_attr( $wp_list_table->get_column_count() ) . '" class="plugin-update colspanchange">
171 <div class="update-message' . esc_attr( $div_class ) . '"' . wp_kses_post( $style ) . '>';
172 if ( $wp_version >= 4.6 ) {
173 echo '<p>';
174 }
175 if ( isset( $bstwbsftwppdtplgns_options['trial'][ $plugin_key ] ) && false !== $link_slug ) {
176 echo esc_html__( 'Notice: Your Pro Trial license has expired. To continue using the plugin, you should buy a Pro license', 'bestwebsoft' ) . ' - <a href="https://bestwebsoft.com/products/wordpress/plugins/' . esc_attr( $link_slug ) . '/">https://bestwebsoft.com/products/wordpress/plugins/' . esc_attr( $link_slug ) . '/</a>';
177 } else {
178 echo esc_html__( 'Your license has expired. To continue getting top-priority support and plugin updates, you should extend it.', 'bestwebsoft' ) . ' <a target="_new" href="https://support.bestwebsoft.com/entries/53487136">' . esc_html__( 'Learn more', 'bestwebsoft' ) . '</a>';
179 }
180 if ( $wp_version >= 4.6 ) {
181 echo '</p>';
182 }
183 echo '</div>
184 </td>
185 </tr>';
186 } elseif ( isset( $bstwbsftwppdtplgns_options['trial'][ $plugin_key ] ) ) {
187 $explode_plugin_key = explode( '/', $plugin_key );
188 $class = ( $wp_version >= 4.6 ) ? 'active' : '';
189 $style = ( $wp_version < 4.6 ) ? ' style="color: #8C0000;"' : '';
190 $div_class = ( $wp_version >= 4.6 ) ? ' notice inline notice-warning notice-alt' : '';
191 echo '<tr class="bws-plugin-update-tr plugin-update-tr ' . esc_attr( $class ) . '" id="' . esc_attr( $explode_plugin_key[0] ) . '-update" data-slug="' . esc_attr( $explode_plugin_key[0] ) . '" data-plugin="' . esc_attr( $plugin_key ) . '">
192 <td colspan="' . esc_attr( $wp_list_table->get_column_count() ) . '" class="plugin-update colspanchange">
193 <div class="update-message' . esc_attr( $div_class ) . '"' . wp_kses_post( $style ) . '>';
194 if ( $wp_version >= 4.6 ) {
195 echo '<p>';
196 }
197 if ( false !== $free_plugin_name ) {
198 printf( esc_html__( 'Notice: You are using the Pro Trial license of %s plugin.', 'bestwebsoft' ), esc_html( $free_plugin_name ) );
199 } else {
200 esc_html_e( 'Notice: You are using the Pro Trial license of plugin.', 'bestwebsoft' );
201 }
202 if ( isset( $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] ) ) {
203 echo ' ' . esc_html__( 'The Pro Trial license will expire on', 'bestwebsoft' ) . ' ' . esc_html( $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] ) . '.';
204 }
205 if ( $wp_version >= 4.6 ) {
206 echo '</p>';
207 }
208 echo '</div>
209 </td>
210 </tr>';
211 }
212 }
213 }
214
215 /**
216 * Function display admin notices
217 *
218 * @echo string
219 */
220 if ( ! function_exists( 'bws_admin_notices' ) ) {
221 function bws_admin_notices() {
222 global $bws_versions_notice_array, $bws_plugin_banner_to_settings, $bstwbsftwppdtplgns_options, $bws_plugin_banner_go_pro, $bstwbsftwppdtplgns_banner_array, $bws_plugin_banner_timeout;
223
224 /* bws_plugin_banner_go_pro */
225 if ( ! empty( $bws_plugin_banner_go_pro ) ) {
226 /* get $bws_plugins */
227 require dirname( __FILE__ ) . '/product_list.php';
228
229 foreach ( $bstwbsftwppdtplgns_banner_array as $value ) {
230 if ( isset( $bws_plugin_banner_go_pro[ $value[0] ] ) && ! isset( $_COOKIE[ $value[0] ] ) ) {
231
232 if ( isset( $bws_plugins[ $value[1] ]['pro_version'] ) && is_plugin_active( $bws_plugins[ $value[1] ]['pro_version'] ) ) {
233 continue;
234 }
235
236 $single_banner_value = $bws_plugin_banner_go_pro[ $value[0] ];
237 ?>
238 <div class="updated" style="padding: 0; margin: 0; border: none; background: none;">
239 <div class="<?php echo esc_attr( $single_banner_value['prefix'] ); ?>_message bws_banner_on_plugin_page bws_go_pro_banner" style="display: none;">
240 <button class="<?php echo esc_attr( $single_banner_value['prefix'] ); ?>_close_icon close_icon notice-dismiss bws_hide_settings_notice" title="<?php esc_html_e( 'Close notice', 'bestwebsoft' ); ?>"></button>
241 <div class="icon">
242 <img title="" src="<?php echo esc_attr( $single_banner_value['banner_url'] ); ?>" alt="" />
243 </div>
244 <div class="text">
245 <?php esc_html_e( 'It’s time to upgrade your', 'bestwebsoft' ); ?> <strong><?php echo esc_html( $single_banner_value['plugin_info']['Name'] ); ?> plugin</strong> <?php esc_html_e( 'to', 'bestwebsoft' ); ?> <strong>Pro</strong> <?php esc_html_e( 'version!', 'bestwebsoft' ); ?><br />
246 <span><?php esc_html_e( 'Extend standard plugin functionality with new great options.', 'bestwebsoft' ); ?></span>
247 </div>
248 <div class="button_div">
249 <a class="button" target="_blank" href="<?php echo esc_url( $single_banner_value['bws_link'] ); ?>"><?php esc_html_e( 'Learn More', 'bestwebsoft' ); ?></a>
250 </div>
251 </div>
252 </div>
253 <?php
254 break;
255 }
256 }
257 }
258
259 /* $bws_plugin_banner_timeout */
260 if ( ! empty( $bws_plugin_banner_timeout ) ) {
261 foreach ( $bws_plugin_banner_timeout as $banner_value ) {
262 ?>
263 <div class="updated" style="padding: 0; margin: 0; border: none; background: none;">
264 <div class="<?php echo esc_attr( $banner_value['prefix'] ); ?>_message_timeout bws_banner_on_plugin_page bws_banner_timeout" style="display:none;">
265 <button class="<?php echo esc_attr( $banner_value['prefix'] ); ?>_close_icon close_icon notice-dismiss bws_hide_settings_notice" title="<?php esc_html_e( 'Close notice', 'bestwebsoft' ); ?>"></button>
266 <div class="icon">
267 <img title="" src="<?php echo esc_url( $banner_value['banner_url'] ); ?>" alt="" />
268 </div>
269 <div class="text"><?php printf( esc_html__( "Your license key for %1\$s expires on %2\$s and you won't be granted TOP-PRIORITY SUPPORT or UPDATES.", 'bestwebsoft' ), '<strong>' . esc_html( $banner_value['plugin_name'] ) . '</strong>', esc_html( $bstwbsftwppdtplgns_options['time_out'][ $banner_value['plugin_key'] ] ) ); ?> <a target="_new" href="https://support.bestwebsoft.com/entries/53487136"><?php esc_html_e( 'Learn more', 'bestwebsoft' ); ?></a></div>
270 </div>
271 </div>
272 <?php
273 }
274 }
275
276 /* versions notice */
277 if ( ! empty( $bws_versions_notice_array ) ) {
278 foreach ( $bws_versions_notice_array as $key => $value ) {
279 ?>
280 <div class="update-nag">
281 <?php
282 printf(
283 '<strong>%s</strong> %s <strong>WordPress %s</strong> %s',
284 esc_html( $value['name'] ),
285 esc_html__( 'requires', 'bestwebsoft' ),
286 esc_html( $value['version'] ),
287 esc_html__( 'or higher! We do not guarantee that our plugin will work correctly. Please upgrade to WordPress latest version.', 'bestwebsoft' )
288 );
289 ?>
290 </div>
291 <?php
292 }
293 }
294
295 /* banner_to_settings notice */
296 if ( ! empty( $bws_plugin_banner_to_settings ) ) {
297 if ( 1 === count( $bws_plugin_banner_to_settings ) ) {
298 ?>
299 <div class="updated" style="padding: 0; margin: 0; border: none; background: none;">
300 <div class="bws_banner_on_plugin_page bws_banner_to_settings">
301 <div class="icon">
302 <img title="" src="<?php echo esc_url( $bws_plugin_banner_to_settings[0]['banner_url'] ); ?>" alt="" />
303 </div>
304 <div class="text">
305 <strong><?php printf( esc_html__( 'Thank you for installing %s plugin!', 'bestwebsoft' ), esc_html( $bws_plugin_banner_to_settings[0]['plugin_info']['Name'] ) ); ?></strong>
306 <br />
307 <?php esc_html_e( "Let's get started", 'bestwebsoft' ); ?>:
308 <a href="<?php echo esc_url( self_admin_url( $bws_plugin_banner_to_settings[0]['settings_url'] ) ); ?>"><?php esc_html_e( 'Settings', 'bestwebsoft' ); ?></a>
309 <?php if ( false !== $bws_plugin_banner_to_settings[0]['post_type_url'] ) { ?>
310 <?php esc_html_e( 'or', 'bestwebsoft' ); ?>
311 <a href="<?php echo esc_url( self_admin_url( $bws_plugin_banner_to_settings[0]['post_type_url'] ) ); ?>"><?php esc_html_e( 'Add New', 'bestwebsoft' ); ?></a>
312 <?php } ?>
313 </div>
314 <form action="" method="post">
315 <button class="notice-dismiss bws_hide_settings_notice" title="<?php esc_html_e( 'Close notice', 'bestwebsoft' ); ?>"></button>
316 <input type="hidden" name="bws_hide_settings_notice_<?php echo esc_html( $bws_plugin_banner_to_settings[0]['plugin_options_name'] ); ?>" value="hide" />
317 <?php wp_nonce_field( plugin_basename( __FILE__ ), 'bws_settings_nonce_name' ); ?>
318 </form>
319 </div>
320 </div>
321 <?php } else { ?>
322 <div class="updated" style="padding: 0; margin: 0; border: none; background: none;">
323 <div class="bws_banner_on_plugin_page bws_banner_to_settings_joint">
324 <form action="" method="post">
325 <button class="notice-dismiss bws_hide_settings_notice" title="<?php esc_html_e( 'Close notice', 'bestwebsoft' ); ?>"></button>
326 <div class="bws-text">
327 <div class="icon">
328 <span class="dashicons dashicons-admin-plugins"></span>
329 </div>
330 <strong><?php esc_html_e( 'Thank you for installing plugins by BestWebSoft!', 'bestwebsoft' ); ?></strong>
331 <div class="hide-if-no-js bws-more-links">
332 <a href="#" class="bws-more"><?php esc_html_e( 'More Details', 'bestwebsoft' ); ?></a>
333 <a href="#" class="bws-less hidden"><?php esc_html_e( 'Less Details', 'bestwebsoft' ); ?></a>
334 </div>
335 <?php wp_nonce_field( plugin_basename( __FILE__ ), 'bws_settings_nonce_name' ); ?>
336 <div class="clear"></div>
337 </div>
338 <div class="bws-details hide-if-js">
339 <?php foreach ( $bws_plugin_banner_to_settings as $value ) { ?>
340 <div>
341 <strong><?php echo esc_html( str_replace( ' by BestWebSoft', '', $value['plugin_info']['Name'] ) ); ?></strong>&ensp;<a href="<?php echo esc_url( self_admin_url( $value['settings_url'] ) ); ?>"><?php esc_html_e( 'Settings', 'bestwebsoft' ); ?></a>
342 <?php if ( false !== $value['post_type_url'] ) { ?>
343 &ensp;|&ensp;<a target="_blank" href="<?php echo esc_url( self_admin_url( $value['post_type_url'] ) ); ?>"><?php esc_html_e( 'Add New', 'bestwebsoft' ); ?></a>
344 <?php } ?>
345 <input type="hidden" name="bws_hide_settings_notice_<?php echo esc_html( $value['plugin_options_name'] ); ?>" value="hide" />
346 </div>
347 <?php } ?>
348 </div>
349 </div>
350 </form>
351 </div>
352 <?php
353 }
354 }
355
356 /**
357 * Show notices about deprecated_function
358 *
359 * @since 1.9.8
360 */
361 if ( ! empty( $bstwbsftwppdtplgns_options['deprecated_function'] ) ) {
362 ?>
363 <div class="update-nag">
364 <strong><?php esc_html_e( 'Deprecated function(-s) is used on the site here:', 'bestwebsoft' ); ?></strong>
365 <?php
366 $i = 1;
367 foreach ( $bstwbsftwppdtplgns_options['deprecated_function'] as $function_name => $attr ) {
368 if ( 1 !== $i ) {
369 echo ' ,';
370 }
371 if ( ! empty( $attr['product-name'] ) ) {
372 echo esc_html( $attr['product-name'] );
373 } elseif ( ! empty( $attr['file'] ) ) {
374 echo esc_url( $attr['file'] );
375 }
376 unset( $bstwbsftwppdtplgns_options['deprecated_function'][ $function_name ] );
377 $i++;
378 }
379 ?>
380 .
381 <br/>
382 <?php esc_html_e( 'This function(-s) will be removed over time. Please update the product(-s).', 'bestwebsoft' ); ?>
383 </div>
384 <?php
385 if ( is_multisite() ) {
386 update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
387 } else {
388 update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
389 }
390 }
391 }
392 }
393
394 /**
395 * Function display banner
396 *
397 * @return array
398 */
399 if ( ! function_exists( 'bws_plugin_banner_go_pro' ) ) {
400 function bws_plugin_banner_go_pro( $plugin_options, $plugin_info, $this_banner_prefix, $bws_link_slug, $link_key, $link_pn, $banner_url_or_slug ) {
401 global $bws_plugin_banner_go_pro, $wp_version, $bstwbsftwppdtplgns_banner_array;
402
403 if ( ! isset( $plugin_options['first_install'] ) || strtotime( '-1 week' ) < $plugin_options['first_install'] ) {
404 return;
405 }
406
407 $bws_link = esc_url( 'https://bestwebsoft.com/products/wordpress/plugins/' . $bws_link_slug . '/?k=' . $link_key . '&pn=' . $link_pn . '&v=' . $plugin_info['Version'] . '&wp_v=' . $wp_version );
408
409 if ( false === strrpos( $banner_url_or_slug, '/' ) ) {
410 $banner_url_or_slug = '//ps.w.org/' . $banner_url_or_slug . '/assets/icon-256x256.png';
411 }
412
413 $bws_plugin_banner_go_pro[ $this_banner_prefix . '_hide_banner_on_plugin_page' ] = array(
414 'plugin_info' => $plugin_info,
415 'prefix' => $this_banner_prefix,
416 'bws_link' => $bws_link,
417 'banner_url' => $banner_url_or_slug,
418 );
419
420 if ( empty( $bstwbsftwppdtplgns_banner_array ) ) {
421 if ( ! function_exists( 'bws_get_banner_array' ) ) {
422 require_once dirname( __FILE__ ) . '/bws_menu.php';
423 }
424 bws_get_banner_array();
425 }
426 }
427 }
428
429 /**
430 * Function update banner params
431 *
432 * @return global array
433 */
434 if ( ! function_exists( 'bws_add_plugin_banner_timeout' ) ) {
435 function bws_add_plugin_banner_timeout( $plugin_key, $plugin_prefix, $plugin_name, $banner_url_or_slug ) {
436 global $bws_plugin_banner_timeout;
437
438 if ( isset( $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] ) && ( strtotime( $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] ) < strtotime( gmdate( 'm/d/Y' ) . '+1 month' ) ) && ( strtotime( $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] ) > strtotime( gmdate( 'm/d/Y' ) ) ) ) {
439
440 if ( false === strrpos( $banner_url_or_slug, '/' ) ) {
441 $banner_url_or_slug = '//ps.w.org/' . $banner_url_or_slug . '/assets/icon-256x256.png';
442 }
443
444 $bws_plugin_banner_timeout[] = array(
445 'plugin_key' => $plugin_key,
446 'prefix' => $plugin_prefix,
447 'plugin_name' => $plugin_name,
448 'banner_url' => $banner_url_or_slug,
449 );
450 }
451 }
452 }
453
454 /**
455 * Function settings for banner
456 *
457 * @return global array
458 */
459 if ( ! function_exists( 'bws_plugin_banner_to_settings' ) ) {
460 function bws_plugin_banner_to_settings( $plugin_info, $plugin_options_name, $banner_url_or_slug, $settings_url, $post_type_url = false ) {
461 global $bws_plugin_banner_to_settings;
462
463 $is_network_admin = is_network_admin();
464
465 $plugin_options = $is_network_admin ? get_site_option( $plugin_options_name ) : get_option( $plugin_options_name );
466
467 if ( isset( $plugin_options['display_settings_notice'] ) && 0 === $plugin_options['display_settings_notice'] ) {
468 return;
469 }
470
471 if ( isset( $_POST[ 'bws_hide_settings_notice_' . $plugin_options_name ] ) && check_admin_referer( plugin_basename( __FILE__ ), 'bws_settings_nonce_name' ) ) {
472 $plugin_options['display_settings_notice'] = 0;
473 if ( $is_network_admin ) {
474 update_site_option( $plugin_options_name, $plugin_options );
475 } else {
476 update_option( $plugin_options_name, $plugin_options );
477 }
478 return;
479 }
480
481 if ( false === strrpos( $banner_url_or_slug, '/' ) ) {
482 $banner_url_or_slug = '//ps.w.org/' . $banner_url_or_slug . '/assets/icon-256x256.png';
483 }
484
485 $bws_plugin_banner_to_settings[] = array(
486 'plugin_info' => $plugin_info,
487 'plugin_options_name' => $plugin_options_name,
488 'banner_url' => $banner_url_or_slug,
489 'settings_url' => $settings_url,
490 'post_type_url' => $post_type_url,
491 );
492 }
493 }
494
495 /**
496 * Function display for feature banner
497 *
498 * @echo string
499 */
500 if ( ! function_exists( 'bws_plugin_suggest_feature_banner' ) ) {
501 function bws_plugin_suggest_feature_banner( $plugin_info, $plugin_options_name, $banner_url_or_slug ) {
502 $is_network_admin = is_network_admin();
503
504 $plugin_options = $is_network_admin ? get_site_option( $plugin_options_name ) : get_option( $plugin_options_name );
505
506 if ( isset( $plugin_options['display_suggest_feature_banner'] ) && 0 === $plugin_options['display_suggest_feature_banner'] ) {
507 return;
508 }
509
510 if ( ! isset( $plugin_options['first_install'] ) ) {
511 $plugin_options['first_install'] = strtotime( 'now' );
512 $update_option = $return = true;
513 } elseif ( strtotime( '-2 week' ) < $plugin_options['first_install'] ) {
514 $return = true;
515 }
516
517 if ( ! isset( $plugin_options['go_settings_counter'] ) ) {
518 $plugin_options['go_settings_counter'] = 1;
519 $update_option = $return = true;
520 } elseif ( 20 > $plugin_options['go_settings_counter'] ) {
521 $plugin_options['go_settings_counter'] = $plugin_options['go_settings_counter'] + 1;
522 $update_option = $return = true;
523 }
524
525 if ( isset( $update_option ) ) {
526 if ( $is_network_admin ) {
527 update_site_option( $plugin_options_name, $plugin_options );
528 } else {
529 update_option( $plugin_options_name, $plugin_options );
530 }
531 }
532
533 if ( isset( $return ) ) {
534 return;
535 }
536
537 if ( isset( $_POST[ 'bws_hide_suggest_feature_banner_' . $plugin_options_name ] ) && check_admin_referer( $plugin_info['Name'], 'bws_settings_nonce_name' ) ) {
538 $plugin_options['display_suggest_feature_banner'] = 0;
539 if ( $is_network_admin ) {
540 update_site_option( $plugin_options_name, $plugin_options );
541 } else {
542 update_option( $plugin_options_name, $plugin_options );
543 }
544 return;
545 }
546
547 if ( false === strrpos( $banner_url_or_slug, '/' ) ) {
548 $banner_url_or_slug = '//ps.w.org/' . $banner_url_or_slug . '/assets/icon-256x256.png';
549 }
550 ?>
551 <div class="updated" style="padding: 0; margin: 0; border: none; background: none;">
552 <div class="bws_banner_on_plugin_page bws_suggest_feature_banner">
553 <div class="icon">
554 <img title="" src="<?php echo esc_url( $banner_url_or_slug ); ?>" alt="" />
555 </div>
556 <div class="text">
557 <strong><?php printf( esc_html__( 'Thank you for choosing %s plugin!', 'bestwebsoft' ), esc_html( $plugin_info['Name'] ) ); ?></strong><br />
558 <?php esc_html_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' ); ?>
559 <a target="_blank" href="https://support.bestwebsoft.com/hc/en-us/requests/new"><?php esc_html_e( 'Suggest a Feature', 'bestwebsoft' ); ?></a>
560 </div>
561 <form action="" method="post">
562 <button class="notice-dismiss bws_hide_settings_notice" title="<?php esc_html_e( 'Close notice', 'bestwebsoft' ); ?>"></button>
563 <input type="hidden" name="bws_hide_suggest_feature_banner_<?php echo esc_html( $plugin_options_name ); ?>" value="hide" />
564 <?php wp_nonce_field( $plugin_info['Name'], 'bws_settings_nonce_name' ); ?>
565 </form>
566 </div>
567 </div>
568 <?php
569 }
570 }
571
572 /**
573 * Function display affiliate postbox
574 *
575 * @echo string
576 */
577 if ( ! function_exists( 'bws_affiliate_postbox' ) ) {
578 function bws_affiliate_postbox() {
579
580 $dismissed = get_user_meta( get_current_user_id(), '_bws_affiliate_postbox_dismissed', true );
581
582 if ( ! empty( $dismissed ) && strtotime( '-3 month' ) < $dismissed ) {
583 return;
584 }
585
586 if ( isset( $_POST['bws_hide_affiliate_banner'] ) && check_admin_referer( 'bws_affiliate_postbox', 'bws_settings_nonce_name' ) ) {
587 update_user_meta( get_current_user_id(), '_bws_affiliate_postbox_dismissed', strtotime( 'now' ) );
588 return;
589 }
590
591 $bws_link = esc_url( 'https://bestwebsoft.com/affiliate/?utm_source=plugin&utm_medium=settings&utm_campaign=affiliate_program' );
592 ?>
593 <div id="bws-affiliate-postbox" class="postbox">
594 <form action="" method="post">
595 <button class="notice-dismiss bws_hide_settings_notice" title="<?php esc_html_e( 'Close notice', 'bestwebsoft' ); ?>"></button>
596 <input type="hidden" name="bws_hide_affiliate_banner" value="hide" />
597 <?php wp_nonce_field( 'bws_affiliate_postbox', 'bws_settings_nonce_name' ); ?>
598 </form>
599 <p>BESTWEBSOFT</p>
600 <h3><?php esc_html_e( 'Affiliate Program', 'bestwebsoft' ); ?></h3>
601 <div class="bws-affiliate-get"><?php printf( esc_html__( 'Get %s', 'bestwebsoft' ), '20%' ); ?></div>
602 <div><?php esc_html_e( 'from each BestWebSoft plugin and theme sale you refer', 'bestwebsoft' ); ?></div>
603 <div class="bws-row">
604 <div class="bws-cell">
605 <img src="<?php echo esc_url( bws_menu_url( 'images/join-icon.svg' ) ); ?>" alt="" />
606 <div><?php esc_html_e( 'Join affiliate program', 'bestwebsoft' ); ?></div>
607 </div>
608 <div class="bws-cell">
609 <img src="<?php echo esc_url( bws_menu_url( 'images/promote-icon.svg' ) ); ?>" alt="" />
610 <div><?php esc_html_e( 'Promote and sell products', 'bestwebsoft' ); ?></div>
611 </div>
612 <div class="bws-cell">
613 <img src="<?php echo esc_url( bws_menu_url( 'images/earn-icon.svg' ) ); ?>" alt="" />
614 <div><?php esc_html_e( 'Get commission!', 'bestwebsoft' ); ?></div>
615 </div>
616 </div>
617 <div class="clear"></div>
618 <p>
619 <a class="button" href="<?php echo esc_url( $bws_link ); ?>" target="_blank"><?php esc_html_e( 'Start Now', 'bestwebsoft' ); ?></a>
620 </p>
621 </div>
622 <?php
623 }
624 }
625
626 /**
627 * Function display settings notice
628 *
629 * @echo string
630 */
631 if ( ! function_exists( 'bws_show_settings_notice' ) ) {
632 function bws_show_settings_notice() {
633 ?>
634 <div id="bws_save_settings_notice" class="updated fade below-h2" style="display:none;">
635 <p>
636 <strong><?php esc_html_e( 'Notice', 'bestwebsoft' ); ?></strong>: <?php esc_html_e( "The plugin's settings have been changed.", 'bestwebsoft' ); ?>
637 <a class="bws_save_anchor" href="#bws-submit-button"><?php esc_html_e( 'Save Changes', 'bestwebsoft' ); ?></a>
638 </p>
639 </div>
640 <?php
641 }
642 }
643
644 /**
645 * Function for hide premium options
646 *
647 * @echo string
648 */
649 if ( ! function_exists( 'bws_hide_premium_options' ) ) {
650 function bws_hide_premium_options( $options ) {
651 if ( ! isset( $options['hide_premium_options'] ) || ! is_array( $options['hide_premium_options'] ) ) {
652 $options['hide_premium_options'] = array();
653 }
654
655 $options['hide_premium_options'][] = get_current_user_id();
656
657 return array(
658 'message' => esc_html__( 'You can always look at premium options by checking the "Pro Options" in the "Misc" tab.', 'bestwebsoft' ),
659 'options' => $options,
660 );
661 }
662 }
663
664 /**
665 * Function for check checkbox for hide premium options
666 *
667 * @return bool
668 */
669 if ( ! function_exists( 'bws_hide_premium_options_check' ) ) {
670 function bws_hide_premium_options_check( $options ) {
671 if ( ! empty( $options['hide_premium_options'] ) && in_array( get_current_user_id(), $options['hide_premium_options'] ) ) {
672 return true;
673 } else {
674 return false;
675 }
676 }
677 }
678
679 /**
680 * Function init fir dashboard
681 */
682 if ( ! function_exists( 'bws_plugins_admin_init' ) ) {
683 function bws_plugins_admin_init() {
684 $page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
685 if ( isset( $_GET['bws_activate_plugin'] ) && check_admin_referer( 'bws_activate_plugin' . sanitize_text_field( wp_unslash( $_GET['bws_activate_plugin'] ) ) ) ) {
686
687 $plugin = isset( $_GET['bws_activate_plugin'] ) ? sanitize_text_field( wp_unslash( $_GET['bws_activate_plugin'] ) ) : '';
688 $result = activate_plugin( $plugin, '', is_network_admin() );
689 if ( is_wp_error( $result ) ) {
690 if ( 'unexpected_output' === $result->get_error_code() ) {
691 $redirect = self_admin_url( 'admin.php?page=bws_panel&error=true&charsout=' . strlen( $result->get_error_data() ) . '&plugin=' . $plugin );
692 wp_safe_redirect( add_query_arg( '_error_nonce', wp_create_nonce( 'plugin-activation-error_' . $plugin ), $redirect ) );
693 exit();
694 } else {
695 wp_die( esc_html( $result ) );
696 }
697 }
698
699 if ( ! is_network_admin() ) {
700 $recent = (array) get_option( 'recently_activated' );
701 unset( $recent[ $plugin ] );
702 update_option( 'recently_activated', $recent );
703 } else {
704 $recent = (array) get_site_option( 'recently_activated' );
705 unset( $recent[ $plugin ] );
706 update_site_option( 'recently_activated', $recent );
707 }
708 /**
709 * @deprecated 1.9.8 (15.12.2016)
710 */
711 $is_main_page = in_array( $page, array( 'bws_panel', 'bws_themes', 'bws_system_status' ) );
712 $tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : '';
713
714 if ( $is_main_page ) {
715 $current_page = 'admin.php?page=' . $page;
716 } else {
717 $current_page = isset( $_GET['tab'] ) ? 'admin.php?page=' . $page . '&tab=' . $tab : 'admin.php?page=' . $page;
718 }
719 /*end deprecated */
720
721 wp_safe_redirect( self_admin_url( esc_url( $current_page . '&activate=true' ) ) );
722 exit();
723 }
724
725 if ( 'bws_panel' === $page || strpos( $page, '-bws-panel' ) ) {
726 if ( ! session_id() ) {
727 @session_start();
728 }
729 }
730
731 bws_add_editor_buttons();
732 }
733 }
734
735 /**
736 * Function add scripts ans syles for dashboard
737 */
738 if ( ! function_exists( 'bws_admin_enqueue_scripts' ) ) {
739 function bws_admin_enqueue_scripts() {
740 global $wp_scripts,
741 $hook_suffix,
742 $post_type,
743 $bws_plugin_banner_go_pro, $bws_plugin_banner_timeout, $bstwbsftwppdtplgns_banner_array,
744 $bws_shortcode_list,
745 $wp_filesystem;
746
747 $page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
748
749 wp_enqueue_style( 'bws-admin-css', bws_menu_url( 'css/general_style.css' ), array(), '2.4.2' );
750 wp_enqueue_script( 'bws-admin-scripts', bws_menu_url( 'js/general_script.js' ), array( 'jquery', 'jquery-ui-tooltip' ) );
751
752 $plugin_dir = explode( '/', plugin_basename( __FILE__ ) )[0];
753 $plugin_file = array_keys( get_plugins( "/$plugin_dir" ) )[0];
754
755 $include_jquery_ui = false;
756 if ( ! empty( $bws_plugins ) ) {
757 $admin_page_free = $pagenow . '?page=' . str_replace( '-pro', '', $page );
758
759 foreach( $bws_plugins as $bws_plugin ) {
760 if ( $admin_page_free === $bws_plugin['settings'] ) {
761 $include_jquery_ui = true;
762 break;
763 }
764 }
765 }
766
767 if ( in_array( $page, array( 'bws_panel', 'bws_themes', 'bws_system_status', $plugin_file ) ) || $include_jquery_ui || strpos( $page, '-bws-panel' ) ) {
768 $jquery_ui_version = isset( $wp_scripts->registered['jquery-ui-core']->ver ) ? $wp_scripts->registered['jquery-ui-core']->ver : '1.12.1';
769 WP_Filesystem();
770 if ( ! $wp_filesystem->exists( dirname( __FILE__ ) . '/css/jquery-ui-styles/' . $jquery_ui_version . '/' ) ) {
771 $jquery_ui_version = '1.12.1';
772 }
773 wp_enqueue_style( 'jquery-ui-style', bws_menu_url( 'css/jquery-ui-styles/' . $jquery_ui_version . '/jquery-ui.css', array(), $jquery_ui_version ) );
774 wp_enqueue_style( 'bws_menu_style', bws_menu_url( 'css/style.css' ), array(), '2.4.2' );
775 wp_enqueue_script( 'bws_menu_script', bws_menu_url( 'js/bws_menu.js' ), array(), '2.4.2', true );
776 wp_enqueue_script( 'theme-install' );
777 add_thickbox();
778 wp_enqueue_script( 'plugin-install' );
779 }
780
781 if ( 'plugins.php' === $hook_suffix ) {
782 if ( ! empty( $bws_plugin_banner_go_pro ) || ! empty( $bws_plugin_banner_timeout ) ) {
783 wp_enqueue_script( 'bws_menu_cookie', bws_menu_url( 'js/c_o_o_k_i_e.js' ) );
784
785 if ( ! empty( $bws_plugin_banner_go_pro ) ) {
786
787 foreach ( $bstwbsftwppdtplgns_banner_array as $value ) {
788 if ( isset( $bws_plugin_banner_go_pro[ $value[0] ] ) && ! isset( $_COOKIE[ $value[0] ] ) ) {
789 $prefix = $bws_plugin_banner_go_pro[ $value[0] ]['prefix'];
790
791 $script = "(function($) {
792 $(document).ready( function() {
793 var hide_message = $.cookie( '" . $prefix . "_hide_banner_on_plugin_page' );
794 if ( hide_message === 'true' ) {
795 $( '." . $prefix . "_message' ).css( 'display', 'none' );
796 } else {
797 $( '." . $prefix . "_message' ).css( 'display', 'block' );
798 };
799 $( '." . $prefix . "_close_icon' ).click( function() {
800 $( '." . $prefix . "_message' ).css( 'display', 'none' );
801 $.cookie( '" . $prefix . "_hide_banner_on_plugin_page', 'true', { expires: 32, secure: true } );
802 });
803 });
804 })(jQuery);";
805
806 wp_register_script( $prefix . '_hide_banner_on_plugin_page', '' );
807 wp_enqueue_script( $prefix . '_hide_banner_on_plugin_page' );
808 wp_add_inline_script( $prefix . '_hide_banner_on_plugin_page', sprintf( $script ) );
809 break;
810 }
811 }
812 }
813
814 if ( ! empty( $bws_plugin_banner_timeout ) ) {
815 $script = '(function($) {
816 $(document).ready( function() {';
817
818 foreach ( $bws_plugin_banner_timeout as $banner_value ) {
819 $script .= "var hide_message = $.cookie( '" . $banner_value['prefix'] . "_timeout_hide_banner_on_plugin_page' );
820 if ( hide_message === 'true' ) {
821 $( '." . $banner_value['prefix'] . "_message_timeout' ).css( 'display', 'none' );
822 } else {
823 $( '." . $banner_value['prefix'] . "_message_timeout' ).css( 'display', 'block' );
824 }
825 $( '." . $banner_value['prefix'] . "_close_icon' ).click( function() {
826 $( '." . $banner_value['prefix'] . "_message_timeout' ).css( 'display', 'none' );
827 $.cookie( '" . $banner_value['prefix'] . "_timeout_hide_banner_on_plugin_page', 'true', { expires: 30, secure: true } );
828 });";
829 }
830
831 $script .= '});
832 })(jQuery);';
833
834 wp_register_script( 'plugin_banner_timeout_hide', '' );
835 wp_enqueue_script( 'plugin_banner_timeout_hide' );
836 wp_add_inline_script( 'plugin_banner_timeout_hide', sprintf( $script ) );
837 }
838 }
839
840 if ( ! defined( 'DOING_AJAX' ) ) {
841 wp_enqueue_style( 'bws-modal-css', bws_menu_url( 'css/modal.css' ) );
842
843 bws_add_deactivation_feedback_dialog_box();
844 }
845 }
846
847 if ( 'multilanguage-languages.php' === $page ) {
848 wp_enqueue_style( 'bws-modal-css', bws_menu_url( 'css/modal.css' ) );
849 }
850
851 if ( ! empty( $bws_shortcode_list ) ) {
852 /* TinyMCE Shortcode Plugin */
853 $script = "var bws_shortcode_button = {
854 'label': '" . esc_attr__( 'Add BWS Shortcode', 'bestwebsoft' ) . "',
855 'title': '" . esc_attr__( 'Add BWS Plugins Shortcode', 'bestwebsoft' ) . "',
856 'function_name': [";
857 foreach ( $bws_shortcode_list as $value ) {
858 if ( isset( $value['js_function'] ) ) {
859 $script .= "'" . $value['js_function'] . "',";
860 }
861 }
862 $script .= ']
863 };';
864 wp_register_script( 'bws_shortcode_button', '' );
865 wp_enqueue_script( 'bws_shortcode_button' );
866 wp_add_inline_script( 'bws_shortcode_button', sprintf( $script ) );
867
868 /* TinyMCE Shortcode Plugin */
869 if ( isset( $post_type ) && in_array( $post_type, array( 'post', 'page' ) ) ) {
870 $tooltip_args = array(
871 'tooltip_id' => 'bws_shortcode_button_tooltip',
872 'css_selector' => '.mce-bws_shortcode_button',
873 'actions' => array(
874 'click' => false,
875 'onload' => true,
876 ),
877 'content' => '<h3>' . esc_html__( 'Add shortcode', 'bestwebsoft' ) . '</h3><p>' . esc_html__( "Add BestWebSoft plugins' shortcodes using this button.", 'bestwebsoft' ) . '</p>',
878 'position' => array(
879 'edge' => 'right',
880 ),
881 'set_timeout' => 2000,
882 );
883 bws_add_tooltip_in_admin( $tooltip_args );
884 }
885 }
886 }
887 }
888
889 /**
890 * add styles and scripts for Bws_Settings_Tabs
891 *
892 * @since 1.9.8
893 */
894 if ( ! function_exists( 'bws_enqueue_settings_scripts' ) ) {
895 function bws_enqueue_settings_scripts() {
896 wp_enqueue_script( 'jquery-ui-resizable' );
897 wp_enqueue_script( 'jquery-ui-tabs' );
898 wp_enqueue_style( 'bws-modal-css', bws_menu_url( 'css/modal.css' ), array(), '2.4.2' );
899 }
900 }
901
902 /**
903 * Function add syles into admin head
904 *
905 * @since 1.9.8
906 */
907 if ( ! function_exists( 'bws_plugins_admin_head' ) ) {
908 function bws_plugins_admin_head() {
909 $page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
910
911 if ( 'bws_panel' === $page ) {
912 ?>
913 <noscript>
914 <style type="text/css">
915 .bws_product_button {
916 display: inline-block;
917 }
918 </style>
919 </noscript>
920 <?php
921 }
922 }
923 }
924
925 /**
926 * Function add syles into admin footer
927 *
928 * @since 1.9.8
929 */
930 if ( ! function_exists( 'bws_plugins_admin_footer' ) ) {
931 function bws_plugins_admin_footer() {
932 $screen = get_current_screen();
933 if ( 'edit' === $screen->parent_base ) {
934 bws_shortcode_media_button_popup();
935 }
936 }
937 }
938
939 /**
940 * Function add style and scripts for older version
941 *
942 * @since 1.9.8
943 */
944 if ( ! function_exists( 'bws_plugins_include_codemirror' ) ) {
945 function bws_plugins_include_codemirror() {
946 global $wp_version;
947 if ( version_compare( $wp_version, '4.9.0', '>=' ) ) {
948 wp_enqueue_style( 'wp-codemirror' );
949 wp_enqueue_script( 'wp-codemirror' );
950 }
951 }
952 }
953
954 /**
955 * Tooltip block
956 */
957 if ( ! function_exists( 'bws_add_tooltip_in_admin' ) ) {
958 function bws_add_tooltip_in_admin( $tooltip_args = array() ) {
959 new BWS_Admin_Tooltip( $tooltip_args );
960 }
961 }
962
963 /**
964 * Class for Tooltip
965 *
966 * @since 1.9.8
967 */
968 if ( ! class_exists( 'BWS_Admin_Tooltip' ) ) {
969 class BWS_Admin_Tooltip {
970 private $tooltip_args;
971
972 public function __construct( $tooltip_args ) {
973 global $bstwbsftwppdtplgns_tooltip_script_add;
974
975 /* Default arguments */
976 $tooltip_args_default = array(
977 'tooltip_id' => false,
978 'css_selector' => false,
979 'actions' => array(
980 'click' => true,
981 'onload' => false,
982 ),
983 'buttons' => array(
984 'close' => array(
985 'type' => 'dismiss',
986 'text' => esc_html__( 'Close', 'bestwebsoft' ),
987 ),
988 ),
989 'position' => array(
990 'edge' => 'top',
991 'align' => 'center',
992 'pos-left' => 0,
993 'pos-top' => 0,
994 'zindex' => 10000,
995 ),
996 'set_timeout' => 0,
997 );
998 $tooltip_args = array_merge( $tooltip_args_default, $tooltip_args );
999 /* Check that our merged array has default values */
1000 foreach ( $tooltip_args_default as $arg_key => $arg_value ) {
1001 if ( is_array( $arg_value ) ) {
1002 foreach ( $arg_value as $key => $value ) {
1003 if ( ! isset( $tooltip_args[ $arg_key ][ $key ] ) ) {
1004 $tooltip_args[ $arg_key ][ $key ] = $tooltip_args_default[ $arg_key ][ $key ];
1005 }
1006 }
1007 }
1008 }
1009 /* Check if tooltip is dismissed */
1010 if ( true === $tooltip_args['actions']['onload'] ) {
1011 if ( in_array( $tooltip_args['tooltip_id'], array_filter( explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ) ) ) ) {
1012 $tooltip_args['actions']['onload'] = false;
1013 }
1014 }
1015 /* Check entered data */
1016 if ( false === $tooltip_args['tooltip_id'] || false === $tooltip_args['css_selector'] || ( false === $tooltip_args['actions']['click'] && false === $tooltip_args['actions']['onload'] ) ) {
1017 /* if not enough data to output a tooltip or both actions (click, onload) are false */
1018 return;
1019 } else {
1020 /* check position */
1021 if ( ! in_array( $tooltip_args['position']['edge'], array( 'left', 'right', 'top', 'bottom' ) ) ) {
1022 $tooltip_args['position']['edge'] = 'top';
1023 }
1024 if ( ! in_array( $tooltip_args['position']['align'], array( 'top', 'bottom', 'left', 'right', 'center' ) ) ) {
1025 $tooltip_args['position']['align'] = 'center';
1026 }
1027 }
1028 /* fix position */
1029 switch ( $tooltip_args['position']['edge'] ) {
1030 case 'left':
1031 case 'right':
1032 switch ( $tooltip_args['position']['align'] ) {
1033 case 'top':
1034 case 'bottom':
1035 $tooltip_args['position']['align'] = 'center';
1036 break;
1037 }
1038 break;
1039 case 'top':
1040 case 'bottom':
1041 if ( 'left' === $tooltip_args['position']['align'] ) {
1042 $tooltip_args['position']['pos-left'] -= 65;
1043 }
1044 break;
1045 }
1046 $this->tooltip_args = $tooltip_args;
1047 /* add styles and scripts */
1048 wp_enqueue_style( 'wp-pointer' );
1049 wp_enqueue_script( 'wp-pointer' );
1050 /* add script that displays our tooltip */
1051 if ( ! isset( $bstwbsftwppdtplgns_tooltip_script_add ) ) {
1052 wp_enqueue_script( 'bws-tooltip-script', bws_menu_url( 'js/bws_tooltip.js' ), array(), '2.4.2' );
1053 $bstwbsftwppdtplgns_tooltip_script_add = true;
1054 }
1055 $tooltip_args = $this->tooltip_args;
1056
1057 $script = '(function($) {
1058 $(document).ready( function() {
1059 $.bwsTooltip( ' . wp_json_encode( $tooltip_args ) . ' );
1060 })
1061 })(jQuery);';
1062 wp_register_script( 'bws-tooltip-script-single-' . $this->tooltip_args['tooltip_id'], '' );
1063 wp_enqueue_script( 'bws-tooltip-script-single-' . $this->tooltip_args['tooltip_id'] );
1064 wp_add_inline_script( 'bws-tooltip-script-single-' . $this->tooltip_args['tooltip_id'], sprintf( $script ) );
1065 }
1066 }
1067 }
1068
1069 /**
1070 * Function display confirm
1071 *
1072 * @since 1.9.8
1073 */
1074 if ( ! function_exists( 'bws_form_restore_default_confirm' ) ) {
1075 function bws_form_restore_default_confirm( $plugin_basename ) {
1076 ?>
1077 <div>
1078 <p><?php esc_html_e( 'Are you sure you want to restore default settings?', 'bestwebsoft' ); ?></p>
1079 <form method="post" action="">
1080 <p>
1081 <button class="button button-primary" name="bws_restore_confirm"><?php esc_html_e( 'Yes, restore all settings', 'bestwebsoft' ); ?></button>
1082 <button class="button" name="bws_restore_deny"><?php esc_html_e( 'No, go back to the settings page', 'bestwebsoft' ); ?></button>
1083 <?php wp_nonce_field( $plugin_basename, 'bws_settings_nonce_name' ); ?>
1084 </p>
1085 </form>
1086 </div>
1087 <?php
1088 }
1089 }
1090
1091 /**
1092 * Function for shortcode
1093 *
1094 * @since 1.9.8
1095 */
1096 if ( ! function_exists( 'bws_add_editor_buttons' ) ) {
1097 function bws_add_editor_buttons() {
1098 global $bws_shortcode_list;
1099 if ( ! empty( $bws_shortcode_list ) && current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) ) {
1100 add_filter( 'mce_external_plugins', 'bws_add_buttons' );
1101 add_filter( 'mce_buttons', 'bws_register_buttons' );
1102 }
1103 }
1104 }
1105
1106 /**
1107 * Function add button for editor
1108 *
1109 * @since 1.9.8
1110 */
1111 if ( ! function_exists( 'bws_add_buttons' ) ) {
1112 function bws_add_buttons( $plugin_array ) {
1113 $plugin_array['add_bws_shortcode'] = bws_menu_url( 'js/shortcode-button.js' );
1114 return $plugin_array;
1115 }
1116 }
1117
1118 /**
1119 * Function register button for editor
1120 *
1121 * @since 1.9.8
1122 */
1123 if ( ! function_exists( 'bws_register_buttons' ) ) {
1124 function bws_register_buttons( $buttons ) {
1125 array_push( $buttons, 'add_bws_shortcode' ); /* dropcap', 'recentposts */
1126 return $buttons;
1127 }
1128 }
1129
1130 /**
1131 * Function Generate inline content for the popup window when the "bws shortcode" button is clicked
1132 *
1133 * @since 1.9.8
1134 */
1135 if ( ! function_exists( 'bws_shortcode_media_button_popup' ) ) {
1136 function bws_shortcode_media_button_popup() {
1137 global $bws_shortcode_list;
1138
1139 if ( ! empty( $bws_shortcode_list ) ) {
1140 ?>
1141 <div id="bws_shortcode_popup" style="display:none;">
1142 <div id="bws_shortcode_popup_block">
1143 <div id="bws_shortcode_select_plugin">
1144 <h4><?php esc_html_e( 'Plugin', 'bestwebsoft' ); ?></h4>
1145 <select name="bws_shortcode_select" id="bws_shortcode_select">
1146 <?php foreach ( $bws_shortcode_list as $key => $value ) { ?>
1147 <option value="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $value['name'] ); ?></option>
1148 <?php } ?>
1149 </select>
1150 </div>
1151 <div class="clear"></div>
1152 <div id="bws_shortcode_content">
1153 <h4><?php esc_html_e( 'Shortcode settings', 'bestwebsoft' ); ?></h4>
1154 <?php echo wp_kses_post( apply_filters( 'bws_shortcode_button_content', '' ) ); ?>
1155 </div>
1156 <div class="clear"></div>
1157 <div id="bws_shortcode_content_bottom">
1158 <p><?php esc_html_e( 'The shortcode will be inserted', 'bestwebsoft' ); ?></p>
1159 <div id="bws_shortcode_block"><div id="bws_shortcode_display"></div></div>
1160 </div>
1161 </div>
1162 </div>
1163 <?php
1164 }
1165 }
1166 }
1167
1168 /**
1169 * Output shortcode in a special block
1170 *
1171 * @since 1.9.8
1172 */
1173 if ( ! function_exists( 'bws_shortcode_output' ) ) {
1174 function bws_shortcode_output( $shortcode ) {
1175 ?>
1176 <span class="bws_shortcode_output"><input type="text" onfocus="this.select();" readonly="readonly" value="<?php echo esc_attr( $shortcode ); ?>" class="large-text bws_no_bind_notice"></span>
1177 <?php
1178 }
1179 }
1180
1181 /**
1182 * Output tooltip
1183 *
1184 * @since 1.9.8
1185 * @param string $content - HTML content for the tooltip
1186 * @param string $class - Can be standart "bws-hide-for-mobile" (tooltip will be hidden in 782px) and "bws-auto-width" (need for img) or some custom class.
1187 */
1188 if ( ! function_exists( 'bws_add_help_box' ) ) {
1189 function bws_add_help_box( $content, $class = '' ) {
1190 return '<span class="bws_help_box dashicons dashicons-editor-help ' . $class . ' hide-if-no-js">
1191 <span class="bws_hidden_help_text">' . $content . '</span>
1192 </span>';
1193 }
1194 }
1195
1196 /**
1197 * Function add help tab
1198 *
1199 * @since 1.9.8
1200 */
1201 if ( ! function_exists( 'bws_help_tab' ) ) {
1202 function bws_help_tab( $screen, $args ) {
1203 $url = ( ! empty( $args['section'] ) ) ? 'https://support.bestwebsoft.com/hc/en-us/sections/' . $args['section'] : 'https://support.bestwebsoft.com/';
1204
1205 $content = '<p><a href="' . esc_url( $url ) . '" target="_blank">' . __( 'Visit Help Center', 'bestwebsoft' ) . '</a></p>';
1206
1207 $screen->add_help_tab(
1208 array(
1209 'id' => $args['id'] . '_help_tab',
1210 'title' => esc_html__( 'FAQ', 'bestwebsoft' ),
1211 'content' => wp_kses_post( $content ),
1212 )
1213 );
1214
1215 $screen->set_help_sidebar(
1216 '<p><strong>' . esc_html__( 'For more information:', 'bestwebsoft' ) . '</strong></p>' .
1217 '<p><a href="https://bestwebsoft.com/documentation/" target="_blank">' . esc_html__( 'Documentation', 'bestwebsoft' ) . '</a></p>' .
1218 '<p><a href="https://www.youtube.com/user/bestwebsoft/playlists?flow=grid&sort=da&view=1" target="_blank">' . esc_html__( 'Video Instructions', 'bestwebsoft' ) . '</a></p>' .
1219 '<p><a href="https://support.bestwebsoft.com/hc/en-us/requests/new" target="_blank">' . esc_html__( 'Submit a Request', 'bestwebsoft' ) . '</a></p>'
1220 );
1221 }
1222 }
1223
1224 /**
1225 * Function add css and js
1226 *
1227 * @since 1.9.8
1228 */
1229 if ( ! function_exists( 'bws_enqueue_custom_code_css_js' ) ) {
1230 function bws_enqueue_custom_code_css_js() {
1231 global $bstwbsftwppdtplgns_options;
1232
1233 if ( ! isset( $bstwbsftwppdtplgns_options ) ) {
1234 $bstwbsftwppdtplgns_options = ( function_exists( 'is_multisite' ) && is_multisite() ) ? get_site_option( 'bstwbsftwppdtplgns_options' ) : get_option( 'bstwbsftwppdtplgns_options' );
1235 }
1236
1237 if ( ! empty( $bstwbsftwppdtplgns_options['custom_code'] ) ) {
1238 $is_multisite = is_multisite();
1239 if ( $is_multisite ) {
1240 $blog_id = get_current_blog_id();
1241 }
1242
1243 if ( ! $is_multisite && ! empty( $bstwbsftwppdtplgns_options['custom_code']['bws-custom-code.css'] ) ) {
1244 wp_enqueue_style( 'bws-custom-style', $bstwbsftwppdtplgns_options['custom_code']['bws-custom-code.css'], array(), '2.4.2' );
1245 } elseif ( $is_multisite && ! empty( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ]['bws-custom-code.css'] ) ) {
1246 wp_enqueue_style( 'bws-custom-style', $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ]['bws-custom-code.css'], array(), '2.4.2' );
1247 }
1248
1249 if ( ! $is_multisite && ! empty( $bstwbsftwppdtplgns_options['custom_code']['bws-custom-code.js'] ) ) {
1250 wp_enqueue_script( 'bws-custom-style', $bstwbsftwppdtplgns_options['custom_code']['bws-custom-code.js'], array(), '2.4.2' );
1251 } elseif ( $is_multisite && ! empty( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ]['bws-custom-code.js'] ) ) {
1252 wp_enqueue_script( 'bws-custom-style', $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ]['bws-custom-code.js'], array(), '2.4.2' );
1253 }
1254 }
1255 }
1256 }
1257
1258 /**
1259 * Function add custom php code
1260 *
1261 * @since 1.9.8
1262 */
1263 if ( ! function_exists( 'bws_enqueue_custom_code_php' ) ) {
1264 function bws_enqueue_custom_code_php() {
1265 if ( is_admin() ) {
1266 return;
1267 }
1268
1269 global $bstwbsftwppdtplgns_options;
1270
1271 if ( ! isset( $bstwbsftwppdtplgns_options ) ) {
1272 $bstwbsftwppdtplgns_options = ( function_exists( 'is_multisite' ) && is_multisite() ) ? get_site_option( 'bstwbsftwppdtplgns_options' ) : get_option( 'bstwbsftwppdtplgns_options' );
1273 }
1274
1275 if ( ! empty( $bstwbsftwppdtplgns_options['custom_code'] ) ) {
1276
1277 $is_multisite = is_multisite();
1278 if ( $is_multisite ) {
1279 $blog_id = get_current_blog_id();
1280 }
1281
1282 if ( ! $is_multisite && ! empty( $bstwbsftwppdtplgns_options['custom_code']['bws-custom-code.php'] ) ) {
1283 if ( file_exists( $bstwbsftwppdtplgns_options['custom_code']['bws-custom-code.php'] ) ) {
1284 if ( ! defined( 'BWS_GLOBAL' ) ) {
1285 define( 'BWS_GLOBAL', true );
1286 }
1287 require_once $bstwbsftwppdtplgns_options['custom_code']['bws-custom-code.php'];
1288 } else {
1289 unset( $bstwbsftwppdtplgns_options['custom_code']['bws-custom-code.php'] );
1290 if ( $is_multisite ) {
1291 update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
1292 } else {
1293 update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
1294 }
1295 }
1296 } elseif ( $is_multisite && ! empty( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ]['bws-custom-code.php'] ) ) {
1297 if ( file_exists( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ]['bws-custom-code.php'] ) ) {
1298 if ( ! defined( 'BWS_GLOBAL' ) ) {
1299 define( 'BWS_GLOBAL', true );
1300 }
1301 require_once $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ]['bws-custom-code.php'];
1302 } else {
1303 unset( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ]['bws-custom-code.php'] );
1304 if ( $is_multisite ) {
1305 update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
1306 } else {
1307 update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
1308 }
1309 }
1310 }
1311 }
1312 }
1313 }
1314
1315 /**
1316 * Function delete plugin
1317 *
1318 * @since 1.9.8
1319 */
1320 if ( ! function_exists( 'bws_delete_plugin' ) ) {
1321 function bws_delete_plugin( $basename ) {
1322 global $bstwbsftwppdtplgns_options;
1323
1324 $is_multisite = is_multisite();
1325 if ( $is_multisite ) {
1326 $blog_id = get_current_blog_id();
1327 }
1328
1329 if ( ! isset( $bstwbsftwppdtplgns_options ) ) {
1330 $bstwbsftwppdtplgns_options = ( $is_multisite ) ? get_site_option( 'bstwbsftwppdtplgns_options' ) : get_option( 'bstwbsftwppdtplgns_options' );
1331 }
1332
1333 /* remove bws_menu versions */
1334 unset( $bstwbsftwppdtplgns_options['bws_menu']['version'][ $basename ] );
1335 /* remove track usage data */
1336 if ( isset( $bstwbsftwppdtplgns_options['bws_menu']['track_usage']['products'][ $basename ] ) ) {
1337 unset( $bstwbsftwppdtplgns_options['bws_menu']['track_usage']['products'][ $basename ] );
1338 }
1339 /* if empty ['bws_menu']['version'] - there is no other bws plugins - delete all */
1340 if ( empty( $bstwbsftwppdtplgns_options['bws_menu']['version'] ) ) {
1341 /* remove options */
1342 if ( $is_multisite ) {
1343 delete_site_option( 'bstwbsftwppdtplgns_options' );
1344 } else {
1345 delete_option( 'bstwbsftwppdtplgns_options' );
1346 }
1347
1348 /* remove custom_code */
1349 if ( $is_multisite ) {
1350 global $wpdb;
1351 $old_blog = $wpdb->blogid;
1352 /* Get all blog ids */
1353 $blogids = $wpdb->get_col( "SELECT `blog_id` FROM $wpdb->blogs" );
1354 foreach ( $blogids as $blog_id ) {
1355 switch_to_blog( $blog_id );
1356 $upload_dir = wp_upload_dir();
1357 $folder = $upload_dir['basedir'] . '/bws-custom-code';
1358 if ( file_exists( $folder ) && is_dir( $folder ) ) {
1359 array_map( 'unlink', glob( "$folder/*" ) );
1360 rmdir( $folder );
1361 }
1362 }
1363 switch_to_blog( $old_blog );
1364 } else {
1365 $upload_dir = wp_upload_dir();
1366 $folder = $upload_dir['basedir'] . '/bws-custom-code';
1367 if ( file_exists( $folder ) && is_dir( $folder ) ) {
1368 array_map( 'unlink', glob( "$folder/*" ) );
1369 rmdir( $folder );
1370 }
1371 }
1372 }
1373 }
1374 }
1375
1376 add_action( 'admin_init', 'bws_plugins_admin_init' );
1377 add_action( 'admin_enqueue_scripts', 'bws_admin_enqueue_scripts' );
1378 add_action( 'admin_head', 'bws_plugins_admin_head' );
1379 add_action( 'admin_footer', 'bws_plugins_admin_footer' );
1380
1381 add_action( 'admin_notices', 'bws_admin_notices', 30 );
1382
1383 add_action( 'wp_enqueue_scripts', 'bws_enqueue_custom_code_css_js', 20 );
1384
1385 bws_enqueue_custom_code_php();
1386