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

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

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