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