| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; |
| 4 |
} |
| 5 |
|
| 6 |
if ( ! class_exists( 'VillaTheme_Support' ) ) { |
| 7 |
/** |
| 8 |
* Class VillaTheme_Support |
| 9 |
* 1.1.21 |
| 10 |
*/ |
| 11 |
class VillaTheme_Support { |
| 12 |
protected $plugin_base_name; |
| 13 |
protected $ads_data = null; |
| 14 |
protected $version = '1.1.21'; |
| 15 |
protected $data = []; |
| 16 |
|
| 17 |
public function __construct( $data ) { |
| 18 |
$data = is_array( $data ) ? $data : []; |
| 19 |
$this->data = []; |
| 20 |
$this->data['support'] = $data['support'] ?? ''; |
| 21 |
$this->data['docs'] = $data['docs'] ?? ''; |
| 22 |
$this->data['review'] = $data['review'] ?? ''; |
| 23 |
$this->data['css_url'] = $data['css'] ?? ''; |
| 24 |
$this->data['images_url'] = $data['image'] ?? ''; |
| 25 |
$this->data['slug'] = $data['slug'] ?? ''; |
| 26 |
$this->data['deactivate_id'] = $data['deactivate_id'] ?? ''; |
| 27 |
$this->data['menu_slug'] = $data['menu_slug'] ?? ''; |
| 28 |
$this->data['version'] = $data['version'] ?? '1.0.0'; |
| 29 |
$this->data['pro_url'] = $data['pro_url'] ?? ''; |
| 30 |
$this->data['survey_url'] = $data['survey_url'] ?? ''; |
| 31 |
$this->plugin_base_name = "{$this->data['slug']}/{$this->data['slug']}.php"; |
| 32 |
add_action( 'villatheme_support_' . $this->data['slug'], array( $this, 'villatheme_support' ) ); |
| 33 |
add_action( 'admin_enqueue_scripts', array( $this, 'scripts' ) ); |
| 34 |
add_action( 'admin_notices', array( $this, 'review_notice' ) ); |
| 35 |
add_action( 'admin_init', array( $this, 'hide_review_notice' ) ); |
| 36 |
add_action( 'admin_menu', array( $this, 'admin_menu' ), 9999 ); |
| 37 |
add_filter( 'plugin_action_links_' . $this->plugin_base_name, array( $this, 'link_to_pro' ) ); |
| 38 |
add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 ); |
| 39 |
/*Admin ads notices*/ |
| 40 |
add_action( 'admin_init', array( $this, 'admin_init' ), 1 ); |
| 41 |
/*Add toolbar*/ |
| 42 |
add_action( 'admin_bar_menu', array( $this, 'add_toolbar' ), 100 ); |
| 43 |
} |
| 44 |
|
| 45 |
public function admin_init() { |
| 46 |
if ( wp_doing_ajax() ) { |
| 47 |
return; |
| 48 |
} |
| 49 |
$this->hide_notices(); |
| 50 |
$villatheme_call = get_transient( 'villatheme_call' ); |
| 51 |
if ( ! function_exists( 'is_plugin_active' ) ) { |
| 52 |
include_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 53 |
} |
| 54 |
if ( ! $villatheme_call || ! is_plugin_active( "{$villatheme_call}/{$villatheme_call}.php" ) ) { |
| 55 |
/*Make sure ads and dashboard widget show only once when multiple VillaTheme plugins are installed*/ |
| 56 |
set_transient( 'villatheme_call', $this->data['slug'], DAY_IN_SECONDS ); |
| 57 |
} |
| 58 |
// if ( get_transient( 'villatheme_call' ) == $this->data['slug'] ) { |
| 59 |
add_action( 'admin_notices', array( $this, 'form_ads' ) ); |
| 60 |
// } |
| 61 |
} |
| 62 |
|
| 63 |
/**Add link to Documentation, Support and Reviews |
| 64 |
* |
| 65 |
* @param $links |
| 66 |
* @param $file |
| 67 |
* |
| 68 |
* @return array |
| 69 |
*/ |
| 70 |
public function plugin_row_meta( $links, $file ) { |
| 71 |
if ( $this->plugin_base_name === $file ) { |
| 72 |
$row_meta = array( |
| 73 |
'support' => '<a href="' . esc_url( $this->data['support'] ) . '" target="_blank" title="' . esc_attr( 'VillaTheme Support' ) . '">' . esc_html( 'Support' ) . '</a>', |
| 74 |
'review' => '<a href="' . esc_url( $this->data['review'] ) . '" target="_blank" title="' . esc_attr( 'Rate this plugin' ) . '">' . esc_html( 'Reviews' ) . '</a>', |
| 75 |
); |
| 76 |
if ( ! empty( $this->data['docs'] ) ) { |
| 77 |
$row_meta['docs'] = '<a href="' . esc_url( $this->data['docs'] ) . '" target="_blank" title="' . esc_attr( 'Plugin Documentation' ) . '">' . esc_html( 'Docs' ) . '</a>'; |
| 78 |
} |
| 79 |
|
| 80 |
return array_merge( (array) $links, $row_meta ); |
| 81 |
} |
| 82 |
|
| 83 |
return (array) $links; |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* @param $links |
| 88 |
* |
| 89 |
* @return mixed |
| 90 |
*/ |
| 91 |
public function link_to_pro( $links ) { |
| 92 |
if ( ! empty( $this->data['pro_url'] ) ) { |
| 93 |
$links = is_array( $links ) ? $links : []; |
| 94 |
$link = '<a class="villatheme-button-upgrade" href="' . esc_url( $this->data['pro_url'] ) . '" target="_blank" title="' . esc_attr( 'Upgrade plugin to premium version' ) . '">' . esc_html( 'Upgrade' ) . '</a>'; |
| 95 |
array_unshift( $links, $link ); |
| 96 |
} |
| 97 |
|
| 98 |
return $links; |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* Get latest VillaTheme plugins and ads |
| 103 |
* Available information is appended to changelog of some plugins, which is available with plugins_api() |
| 104 |
* |
| 105 |
* @param $is_ads |
| 106 |
* |
| 107 |
* @return array |
| 108 |
*/ |
| 109 |
public function remote_get( $is_ads = false ) { |
| 110 |
$return = array( |
| 111 |
'status' => 'error', |
| 112 |
'data' => '', |
| 113 |
); |
| 114 |
foreach ( |
| 115 |
array( |
| 116 |
'woo-multi-currency', |
| 117 |
'email-template-customizer-for-woo', |
| 118 |
) as $slug |
| 119 |
) { |
| 120 |
$api = $this->plugin_information( array( |
| 121 |
'slug' => $slug, |
| 122 |
'locale' => 'en_US', |
| 123 |
) ); |
| 124 |
if ( ! is_wp_error( $api ) ) { |
| 125 |
if ( isset( $api->sections, $api->sections['changelog'] ) ) { |
| 126 |
$changelog = $api->sections['changelog']; |
| 127 |
if ( $changelog ) { |
| 128 |
if ( $is_ads ) { |
| 129 |
preg_match( '/VillaThemeCampaign:{(.*)}/', $changelog, $match ); |
| 130 |
} else { |
| 131 |
preg_match( '/VillaThemePlugins:\[(.*)]/sm', $changelog, $match ); |
| 132 |
} |
| 133 |
if ( $match ) { |
| 134 |
$json = html_entity_decode( str_replace( array( |
| 135 |
'„', |
| 136 |
'”', |
| 137 |
'“', |
| 138 |
'″', |
| 139 |
'„', |
| 140 |
), '"', $match[1] ) ); |
| 141 |
if ( $is_ads ) { |
| 142 |
$json = '{' . $json . '}'; |
| 143 |
} else { |
| 144 |
$json = '[' . $json . ']'; |
| 145 |
} |
| 146 |
$return['data'] = $json; |
| 147 |
$return['status'] = 'success'; |
| 148 |
break; |
| 149 |
} |
| 150 |
} |
| 151 |
} |
| 152 |
} |
| 153 |
} |
| 154 |
|
| 155 |
return $return; |
| 156 |
} |
| 157 |
|
| 158 |
public function plugin_information( $args = array() ) { |
| 159 |
global $wp_version; |
| 160 |
$wp_version1 = $wp_version; |
| 161 |
if ( ! $wp_version ) { |
| 162 |
$wp_version1 = '5.0'; |
| 163 |
} |
| 164 |
if ( is_array( $args ) ) { |
| 165 |
$args = (object) $args; |
| 166 |
} |
| 167 |
if ( ! is_object( $args ) ) { |
| 168 |
$args = (object) []; |
| 169 |
} |
| 170 |
if ( ! isset( $args->locale ) ) { |
| 171 |
$args->locale = get_user_locale(); |
| 172 |
} |
| 173 |
|
| 174 |
if ( ! isset( $args->wp_version ) ) { |
| 175 |
$args->wp_version = substr( $wp_version1, 0, 3 ); // x.y |
| 176 |
} |
| 177 |
$url = 'https://api.wordpress.org/plugins/info/1.2/'; |
| 178 |
$url = add_query_arg( |
| 179 |
array( |
| 180 |
'action' => 'plugin_information', |
| 181 |
'request' => $args, |
| 182 |
), |
| 183 |
$url |
| 184 |
); |
| 185 |
$http_url = $url; |
| 186 |
$ssl = wp_http_supports( array( 'ssl' ) ); |
| 187 |
if ( $ssl ) { |
| 188 |
$url = set_url_scheme( $url, 'https' ); |
| 189 |
} |
| 190 |
$http_args = array( |
| 191 |
'timeout' => 15, |
| 192 |
'user-agent' => 'WordPress/' . $wp_version1 . '; ' . home_url( '/' ), |
| 193 |
); |
| 194 |
$request = wp_remote_get( $url, $http_args ); |
| 195 |
if ( $ssl && is_wp_error( $request ) ) { |
| 196 |
$request = wp_remote_get( $http_url, $http_args ); |
| 197 |
} |
| 198 |
if ( is_wp_error( $request ) ) { |
| 199 |
$res = new WP_Error( |
| 200 |
'plugins_api_failed', |
| 201 |
esc_html( 'Error' ), |
| 202 |
$request->get_error_message() |
| 203 |
); |
| 204 |
} else { |
| 205 |
$res = json_decode( wp_remote_retrieve_body( $request ), true ); |
| 206 |
if ( is_array( $res ) ) { |
| 207 |
// Object casting is required in order to match the info/1.0 format. |
| 208 |
$res = (object) $res; |
| 209 |
} elseif ( null === $res ) { |
| 210 |
$res = new WP_Error( |
| 211 |
'plugins_api_failed', |
| 212 |
esc_html( 'Error' ), |
| 213 |
wp_remote_retrieve_body( $request ) |
| 214 |
); |
| 215 |
} |
| 216 |
|
| 217 |
if ( isset( $res->error ) ) { |
| 218 |
$res = new WP_Error( 'plugins_api_failed', $res->error ); |
| 219 |
} |
| 220 |
} |
| 221 |
|
| 222 |
return $res; |
| 223 |
} |
| 224 |
|
| 225 |
/** |
| 226 |
* Add Extensions page |
| 227 |
*/ |
| 228 |
public function admin_menu() { |
| 229 |
if ( $this->data['menu_slug'] ) { |
| 230 |
add_submenu_page( |
| 231 |
$this->data['menu_slug'], |
| 232 |
esc_html( 'Extensions' ), |
| 233 |
esc_html( 'Extensions' ), |
| 234 |
'manage_options', |
| 235 |
'villatheme-' . $this->data['slug'] . '-extensions', |
| 236 |
array( $this, 'page_callback' ) |
| 237 |
); |
| 238 |
|
| 239 |
if ( $this->data['pro_url'] ) { |
| 240 |
add_submenu_page( |
| 241 |
$this->data['menu_slug'], |
| 242 |
esc_html( 'Try Premium Version' ), |
| 243 |
esc_html( 'Try Premium Version' ), |
| 244 |
'manage_options', |
| 245 |
$this->data['pro_url'] |
| 246 |
); |
| 247 |
} |
| 248 |
} |
| 249 |
} |
| 250 |
|
| 251 |
/** |
| 252 |
* Extensions page |
| 253 |
*/ |
| 254 |
public function page_callback() { ?> |
| 255 |
<div class="villatheme-extension-page"> |
| 256 |
<div class="villatheme-extension-top"> |
| 257 |
<h2><?php echo esc_html( 'THE BEST PLUGINS FOR WOOCOMMERCE' ) ?></h2> |
| 258 |
<p><?php echo esc_html( 'Our plugins are constantly updated and thanks to your feedback. We add new features on a daily basis. Try our live demo and start increasing the conversions on your ecommerce right away.' ) ?></p> |
| 259 |
</div> |
| 260 |
<div class="villatheme-extension-content"> |
| 261 |
<?php |
| 262 |
$ads = $this->get_data(); |
| 263 |
if ( is_array( $ads ) && !empty( $ads ) ) { |
| 264 |
foreach ( $ads as $ad ) { |
| 265 |
if ( empty( $ad ) ) { |
| 266 |
continue; |
| 267 |
} |
| 268 |
?> |
| 269 |
<div class="villatheme-col-3"> |
| 270 |
<?php |
| 271 |
if ( $ad->image ) { ?> |
| 272 |
<div class="villatheme-item-image"> |
| 273 |
<img src="<?php echo esc_url( $ad->image ) // phpcs:ignore PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage ?>"> |
| 274 |
</div> |
| 275 |
<?php |
| 276 |
} |
| 277 |
if ( $ad->title ) { |
| 278 |
?> |
| 279 |
<div class="villatheme-item-title"> |
| 280 |
<?php if ( $ad->link ) { ?> |
| 281 |
<a target="_blank" |
| 282 |
href="<?php echo esc_url( $ad->link ) ?>"> |
| 283 |
<?php } ?> |
| 284 |
<?php echo esc_html( $ad->title ) ?> |
| 285 |
<?php if ( $ad->link ) { ?> |
| 286 |
</a> |
| 287 |
<?php |
| 288 |
} |
| 289 |
?> |
| 290 |
</div> |
| 291 |
<?php |
| 292 |
} |
| 293 |
?> |
| 294 |
<div class="villatheme-item-controls"> |
| 295 |
<div class="villatheme-item-controls-inner"> |
| 296 |
<?php |
| 297 |
if ( $ad->link ) { |
| 298 |
?> |
| 299 |
<a class="villatheme-item-controls-inner-button active" target="_blank" |
| 300 |
href="<?php echo esc_url( $ad->link ) ?>"><?php echo esc_html( 'Download' ) ?></a> |
| 301 |
<?php |
| 302 |
} |
| 303 |
if ( $ad->demo_url ) { |
| 304 |
?> |
| 305 |
<a class="villatheme-item-controls-inner-button" target="_blank" |
| 306 |
href="<?php echo esc_url( $ad->demo_url ) ?>"><?php echo esc_html( 'Demo' ) ?></a> |
| 307 |
<?php |
| 308 |
} |
| 309 |
if ( $ad->free_url ) { |
| 310 |
?> |
| 311 |
<a class="villatheme-item-controls-inner-button" target="_blank" |
| 312 |
href="<?php echo esc_url( $ad->free_url ) ?>"><?php echo esc_html( 'Free download' ) ?></a> |
| 313 |
<?php |
| 314 |
} |
| 315 |
?> |
| 316 |
</div> |
| 317 |
</div> |
| 318 |
</div> |
| 319 |
<?php |
| 320 |
} |
| 321 |
} |
| 322 |
?> |
| 323 |
</div> |
| 324 |
</div> |
| 325 |
<?php |
| 326 |
} |
| 327 |
|
| 328 |
/** |
| 329 |
* Hide notices |
| 330 |
*/ |
| 331 |
public function hide_review_notice() { |
| 332 |
if (wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
| 333 |
return; |
| 334 |
} |
| 335 |
$_villatheme_nonce = !empty( $_GET['_villatheme_nonce'] ) ? sanitize_text_field( wp_unslash( $_GET['_villatheme_nonce'] ) ) : ''; |
| 336 |
|
| 337 |
if ( empty( $_villatheme_nonce ) ) { |
| 338 |
return; |
| 339 |
} |
| 340 |
|
| 341 |
if ( wp_verify_nonce( $_villatheme_nonce, 'villatheme_' . $this->data['slug'] . '_dismiss_notices' ) ) { |
| 342 |
update_option( 'villatheme_' . $this->data['slug'] . '_dismiss_notices', 1 ); |
| 343 |
} |
| 344 |
if ( wp_verify_nonce( $_villatheme_nonce, 'villatheme_' . $this->data['slug'] . '_hide_notices' ) ) { |
| 345 |
set_transient( 'villatheme_' . $this->data['slug'] . $this->data['version'] . '_hide_notices', 1, 2592000 ); |
| 346 |
} |
| 347 |
if ( wp_verify_nonce( $_villatheme_nonce, 'villatheme_' . $this->data['slug'] . '_wp_reviewed' ) ) { |
| 348 |
set_transient( 'villatheme_' . $this->data['slug'] . $this->data['version'] . '_hide_notices', 1, 2592000 ); |
| 349 |
update_option( 'villatheme_' . $this->data['slug'] . '_wp_reviewed', 1 ); |
| 350 |
wp_safe_redirect( esc_url_raw( $this->data['review'] ) ); |
| 351 |
exit(); |
| 352 |
} |
| 353 |
} |
| 354 |
|
| 355 |
/** |
| 356 |
* Show review WordPress |
| 357 |
*/ |
| 358 |
public function review_notice() { |
| 359 |
if ( get_option( 'villatheme_' . $this->data['slug'] . '_dismiss_notices', 0 ) ) { |
| 360 |
return; |
| 361 |
} |
| 362 |
if ( get_transient( 'villatheme_' . $this->data['slug'] . $this->data['version'] . '_hide_notices' ) ) { |
| 363 |
return; |
| 364 |
} |
| 365 |
$name = $this->get_plugin_name(); |
| 366 |
$check_review = get_option( 'villatheme_' . $this->data['slug'] . '_wp_reviewed', 0 ); |
| 367 |
$check_start = get_option( 'villatheme_' . $this->data['slug'] . '_start_use', 0 ); |
| 368 |
if ( ! $check_start ) { |
| 369 |
update_option( 'villatheme_' . $this->data['slug'] . '_start_use', 1 ); |
| 370 |
set_transient( 'villatheme_' . $this->data['slug'] . $this->data['version'] . '_hide_notices', 1, 259200 ); |
| 371 |
|
| 372 |
return; |
| 373 |
} |
| 374 |
if ( $check_review && ! $this->data['pro_url'] ) { |
| 375 |
return; |
| 376 |
} |
| 377 |
?> |
| 378 |
|
| 379 |
<div class="villatheme-dashboard updated" style="border-left: 4px solid #ffba00"> |
| 380 |
<div class="villatheme-content"> |
| 381 |
<form action="" method="get"> |
| 382 |
<?php if ( ! $check_review ) { ?> |
| 383 |
<p><?php echo esc_html( 'Hi there! You\'ve been using ' ) . '<strong>' . esc_html( $name ) . '</strong>' . esc_html( ' on your site for a few days - I hope it\'s been helpful. If you\'re enjoying my plugin, would you mind rating it 5-stars to help spread the word?' ) ?></p> |
| 384 |
<?php } else { ?> |
| 385 |
<p><?php echo esc_html( 'Hi there! You\'ve been using ' ) . '<strong>' . esc_html( $name ) . '</strong>' . esc_html( ' on your site for a few days - I hope it\'s been helpful. Would you want get more features?' ) ?></p> |
| 386 |
<?php } ?> |
| 387 |
<p> |
| 388 |
<a href="<?php echo esc_url( wp_nonce_url( add_query_arg( array() ), 'villatheme_' . $this->data['slug'] . '_hide_notices', '_villatheme_nonce' ) ); ?>" |
| 389 |
class="button"><?php echo esc_html( 'Thanks, later' ) ?></a> |
| 390 |
<?php if ( ! $check_review ) { ?> |
| 391 |
<button class="button button-primary"><?php echo esc_html( 'Rate Now' ) ?></button> |
| 392 |
<?php wp_nonce_field( 'villatheme_' . $this->data['slug'] . '_wp_reviewed', '_villatheme_nonce' ) ?> |
| 393 |
<?php } ?> |
| 394 |
<?php if ( $this->data['pro_url'] ) { ?> |
| 395 |
<a target="_blank" href="<?php echo esc_url( $this->data['pro_url'] ); ?>" |
| 396 |
class="button button-primary"><?php echo esc_html( 'Try Premium Version' ) ?></a> |
| 397 |
<?php } ?> |
| 398 |
<a target="_self" |
| 399 |
href="<?php echo esc_url( wp_nonce_url( add_query_arg( array() ), 'villatheme_' . $this->data['slug'] . '_dismiss_notices', '_villatheme_nonce' ) ); ?>" |
| 400 |
class="button notice-dismiss vi-button-dismiss"><?php echo esc_html( 'Dismiss' ) ?></a> |
| 401 |
</p> |
| 402 |
</form> |
| 403 |
</div> |
| 404 |
</div> |
| 405 |
<?php |
| 406 |
} |
| 407 |
|
| 408 |
|
| 409 |
public function widget() { |
| 410 |
if ( ! is_array( $this->ads_data ) ) { |
| 411 |
return; |
| 412 |
} |
| 413 |
?> |
| 414 |
<div class="villatheme-dashboard"> |
| 415 |
<div class="villatheme-content"> |
| 416 |
<?php |
| 417 |
if ( ! empty( $this->ads_data['heading'] ) ) { ?> |
| 418 |
<h3><?php echo esc_html( $this->ads_data['heading'] ) ?></h3> |
| 419 |
<?php |
| 420 |
} |
| 421 |
if ( ! empty( $this->ads_data['description'] ) ) { ?> |
| 422 |
<p><?php echo esc_html( $this->ads_data['description'] ) ?></p> |
| 423 |
<?php |
| 424 |
} |
| 425 |
?> |
| 426 |
<p> |
| 427 |
<?php |
| 428 |
if ( ! empty( $this->ads_data['link'] ) ) { |
| 429 |
?> |
| 430 |
<a target="_blank" href="<?php echo esc_url( $this->ads_data['link'] ); ?>" |
| 431 |
class="button button-primary"><?php echo esc_html( 'Get Your Gift' ) ?></a> |
| 432 |
<?php |
| 433 |
} |
| 434 |
?> |
| 435 |
</p> |
| 436 |
</div> |
| 437 |
</div> |
| 438 |
<?php |
| 439 |
} |
| 440 |
|
| 441 |
/** |
| 442 |
* Hide notices |
| 443 |
*/ |
| 444 |
public function hide_notices() { |
| 445 |
$raw_nonce = $_GET['_villatheme_nonce'] ?? ''; |
| 446 |
$_villatheme_nonce = sanitize_text_field( wp_unslash( is_string( $raw_nonce ) ? $raw_nonce : '' ) ); |
| 447 |
if ( $_villatheme_nonce === '' ) { |
| 448 |
return; |
| 449 |
} |
| 450 |
|
| 451 |
if ( wp_verify_nonce( $_villatheme_nonce, 'villatheme_hide_toolbar' ) ) { |
| 452 |
update_option( 'villatheme_hide_admin_toolbar', time() ); |
| 453 |
wp_safe_redirect( ( esc_url_raw( remove_query_arg( array( '_villatheme_nonce' ) ) ) ) ); |
| 454 |
exit(); |
| 455 |
} |
| 456 |
if ( wp_verify_nonce( $_villatheme_nonce, 'villatheme_show_toolbar' ) ) { |
| 457 |
delete_option( 'villatheme_hide_admin_toolbar' ); |
| 458 |
wp_safe_redirect( ( esc_url_raw( remove_query_arg( array( '_villatheme_nonce' ) ) ) ) ); |
| 459 |
exit(); |
| 460 |
} |
| 461 |
|
| 462 |
if ( wp_verify_nonce( $_villatheme_nonce, 'hide_notices' ) ) { |
| 463 |
$hide_notice = isset( $_GET['villatheme-hide-notice'] ) ? sanitize_text_field( wp_unslash( $_GET['villatheme-hide-notice'] ) ) : ''; |
| 464 |
$ads_id = isset( $_GET['ads_id'] ) ? sanitize_text_field( wp_unslash( $_GET['ads_id'] ) ) : ''; |
| 465 |
global $current_user; |
| 466 |
$user_id = ( $current_user && ! empty( $current_user->ID ) ) ? $current_user->ID : 0; |
| 467 |
if ( $hide_notice == 1 ) { |
| 468 |
if ( $ads_id ) { |
| 469 |
update_option( 'villatheme_hide_notices_' . $ads_id, time() + DAY_IN_SECONDS ); |
| 470 |
} else { |
| 471 |
set_transient( 'villatheme_hide_notices_' . $user_id, 1, DAY_IN_SECONDS ); |
| 472 |
} |
| 473 |
} else { |
| 474 |
if ( $ads_id ) { |
| 475 |
update_option( 'villatheme_hide_notices_' . $ads_id, $ads_id ); |
| 476 |
} else { |
| 477 |
set_transient( 'villatheme_hide_notices_' . $user_id, 1, DAY_IN_SECONDS * 30 ); |
| 478 |
} |
| 479 |
} |
| 480 |
} |
| 481 |
} |
| 482 |
|
| 483 |
/** |
| 484 |
* Show Notices |
| 485 |
*/ |
| 486 |
public function form_ads() { |
| 487 |
global $current_screen; |
| 488 |
if ( ! is_object( $current_screen ) ) { |
| 489 |
return; |
| 490 |
} |
| 491 |
$page = $current_screen->parent_base ?? $current_screen->parent_file ?? ''; |
| 492 |
if ( ! in_array( $page, [ 'plugins', $this->data['menu_slug'] ], true ) || ( 'plugins' === $page && get_transient( 'villatheme_call' ) !== $this->data['slug'] ) ) { |
| 493 |
return; |
| 494 |
} |
| 495 |
$this->get_ads_data(); |
| 496 |
if ( $this->ads_data === false ) { |
| 497 |
return; |
| 498 |
} |
| 499 |
ob_start(); ?> |
| 500 |
<div class="villatheme-dashboard updated"> |
| 501 |
<div class="villatheme-content"> |
| 502 |
<?php |
| 503 |
if ( ! empty( $this->ads_data['heading'] ) ) { ?> |
| 504 |
<h3><?php echo esc_html( $this->ads_data['heading'] ) ?></h3> |
| 505 |
<?php |
| 506 |
} |
| 507 |
if ( ! empty( $this->ads_data['description'] ) ) { ?> |
| 508 |
<p><?php echo esc_html( $this->ads_data['description'] ) ?></p> |
| 509 |
<?php |
| 510 |
} |
| 511 |
?> |
| 512 |
<p> |
| 513 |
<a target="_self" |
| 514 |
href="<?php echo esc_url( wp_nonce_url( add_query_arg( array( |
| 515 |
'villatheme-hide-notice' => '2', |
| 516 |
'ads_id' => $this->ads_data['id'], |
| 517 |
) ), 'hide_notices', '_villatheme_nonce' ) ); ?>" |
| 518 |
class="button notice-dismiss vi-button-dismiss"><?php echo esc_html( 'Dismiss' ) ?></a> |
| 519 |
<a href="<?php echo esc_url( wp_nonce_url( add_query_arg( array( |
| 520 |
'villatheme-hide-notice' => '1', |
| 521 |
'ads_id' => $this->ads_data['id'], |
| 522 |
) ), 'hide_notices', '_villatheme_nonce' ) ); ?>" |
| 523 |
class="button"><?php echo esc_html( 'Thanks, later.' ) ?></a> |
| 524 |
<?php |
| 525 |
if ( ! empty( $this->ads_data['link'] ) ) { ?> |
| 526 |
<a target="_blank" href="<?php echo esc_url( $this->ads_data['link'] ); ?>" |
| 527 |
class="button button-primary"><?php echo esc_html( 'Get Your Gift' ) ?></a> |
| 528 |
<?php |
| 529 |
} |
| 530 |
?> |
| 531 |
</p> |
| 532 |
</div> |
| 533 |
</div> |
| 534 |
<?php |
| 535 |
echo wp_kses_post( apply_filters( 'villatheme_form_ads_data', ob_get_clean() ) ); |
| 536 |
} |
| 537 |
|
| 538 |
public function get_ads_data() { |
| 539 |
global $current_user; |
| 540 |
if ( $this->ads_data !== null ) { |
| 541 |
return; |
| 542 |
} |
| 543 |
$this->ads_data = false; |
| 544 |
$user_id = ( is_object( $current_user ) && ! empty( $current_user->ID ) ) ? $current_user->ID : 0; |
| 545 |
if ( get_transient( 'villatheme_hide_notices_' . $user_id ) ) { |
| 546 |
return; |
| 547 |
} |
| 548 |
$data = get_transient( 'villatheme_notices' ); |
| 549 |
$called = get_transient( 'villatheme_called' ); |
| 550 |
if ( ! $data && ! $called ) { |
| 551 |
$request_data = $this->remote_get( true ); |
| 552 |
if ( isset( $request_data['status'] ) && $request_data['status'] === 'success' ) { |
| 553 |
$data = json_decode( $request_data['data'], true ); |
| 554 |
} |
| 555 |
set_transient( 'villatheme_notices', $data, DAY_IN_SECONDS ); |
| 556 |
} |
| 557 |
|
| 558 |
if ( ! $called ) { |
| 559 |
set_transient( 'villatheme_called', 1, DAY_IN_SECONDS ); |
| 560 |
} |
| 561 |
|
| 562 |
if ( ! is_array( $data ) ) { |
| 563 |
return; |
| 564 |
} |
| 565 |
$data = wp_parse_args( $data, array( |
| 566 |
'heading' => '', |
| 567 |
'description' => '', |
| 568 |
'link' => '', |
| 569 |
'id' => '', |
| 570 |
) ); |
| 571 |
if ( ! $data['heading'] && ! $data['description'] ) { |
| 572 |
return; |
| 573 |
} |
| 574 |
$getdate = getdate(); |
| 575 |
$current_time = $getdate[0]; |
| 576 |
if ( isset( $data['start'] ) && strtotime( $data['start'] ) > $current_time ) { |
| 577 |
return; |
| 578 |
} |
| 579 |
if ( isset( $data['end'] ) && strtotime( $data['end'] ) < $current_time ) { |
| 580 |
return; |
| 581 |
} |
| 582 |
// if ( isset( $data['loop'] ) && $data['loop'] ) { |
| 583 |
// if ( ! in_array( $getdate['wday'], explode( ',', $data['loop'] ) ) ) { |
| 584 |
// return; |
| 585 |
// } |
| 586 |
// } |
| 587 |
if ( $data['id'] ) { |
| 588 |
$hide = get_option( 'villatheme_hide_notices_' . $data['id'] ); |
| 589 |
if ( $hide === $data['id'] || time() < intval( $hide ) ) { |
| 590 |
return; |
| 591 |
} |
| 592 |
} |
| 593 |
$this->ads_data = $data; |
| 594 |
} |
| 595 |
|
| 596 |
/** |
| 597 |
* Init script |
| 598 |
*/ |
| 599 |
public function scripts() { |
| 600 |
if ( ! wp_style_is( 'villatheme-support' ) ) { |
| 601 |
wp_enqueue_style( 'villatheme-support', $this->data['css_url'] . 'villatheme-support.min.css', [], $this->version ); |
| 602 |
wp_register_script( 'villatheme-support', false, [ 'jquery' ], $this->version, false ); |
| 603 |
wp_enqueue_script( 'villatheme-support' ); |
| 604 |
wp_add_inline_script( 'villatheme-support', "(function ($) { |
| 605 |
$(function () { |
| 606 |
$(document).on('click','#wp-admin-bar-villatheme_hide_toolbar',function(e){ |
| 607 |
if (!confirm('VillaTheme toolbar helps you access all VillaTheme items quickly, do you want to hide it anyway?')){ |
| 608 |
e.preventDefault(); |
| 609 |
e.stopPropagation(); |
| 610 |
return false; |
| 611 |
} |
| 612 |
}); |
| 613 |
}); |
| 614 |
}(jQuery));" ); |
| 615 |
} |
| 616 |
global $pagenow; |
| 617 |
if ( $this->data['survey_url'] && ( 'plugins.php' === $pagenow ) ) { |
| 618 |
$support_basic = ! wp_style_is( 'villatheme-support-basic' ); |
| 619 |
if ( $support_basic ) { |
| 620 |
wp_register_style( 'villatheme-support-basic', false, [], $this->version ); |
| 621 |
wp_enqueue_style( 'villatheme-support-basic' ); |
| 622 |
wp_add_inline_style( 'villatheme-support-basic', '.villatheme-deactivate-modal{position: fixed;z-index: 99999;top: 0;right: 0;bottom: 0;left: 0;background: rgba(0, 0, 0, 0.5);display: none}.villatheme-deactivate-modal.modal-active{display: block}.villatheme-deactivate-modal-wrap{width: 50%;position: relative;margin: 10% auto;background: #fff}.villatheme-deactivate-modal-header{border-bottom: 1px solid #eee;padding: 8px 20px}.villatheme-deactivate-modal-header h3{line-height: 150%;margin: 0}.villatheme-deactivate-modal-body{padding: 5px 20px 20px 20px}.villatheme-deactivate-modal-body .input-text,.villatheme-deactivate-modal-body textarea{width: 75%}.villatheme-deactivate-modal-body .reason-input{margin-top: 5px;margin-left: 20px}.villatheme-deactivate-modal-footer{border-top: 1px solid #eee;padding: 12px 20px;text-align: right}' ); |
| 623 |
wp_add_inline_script( 'villatheme-support', "var ViDeactivate = {deactivateLink: '', surveyUrl: ''}; |
| 624 |
(function ($) { |
| 625 |
$(function () { |
| 626 |
let modal = $('#villatheme-deactivate-survey-modal'); |
| 627 |
ViDeactivate.modal = modal; |
| 628 |
|
| 629 |
modal.on('click', 'button.villatheme-model-cancel', function (e) { |
| 630 |
e.preventDefault(); |
| 631 |
modal.removeClass('modal-active'); |
| 632 |
}); |
| 633 |
|
| 634 |
modal.on('click', 'input[type=\"radio\"]', function () { |
| 635 |
$('button.villatheme-deactivate-submit').removeClass('disabled'); |
| 636 |
var parent = $(this).parents('li:first'); |
| 637 |
modal.find('.reason-input').remove(); |
| 638 |
var inputType = parent.data('type'), |
| 639 |
inputPlaceholder = parent.data('placeholder'), |
| 640 |
reasonInputHtml = '<div class=\"reason-input\">' + (('text' === inputType) ? '<input type=\"text\" class=\"input-text\" size=\"40\" />' : '<textarea rows=\"5\" cols=\"45\"></textarea>') + '</div>'; |
| 641 |
|
| 642 |
if (inputType !== '') { |
| 643 |
parent.append($(reasonInputHtml)); |
| 644 |
parent.find('input, textarea').attr('placeholder', inputPlaceholder).focus(); |
| 645 |
} |
| 646 |
}); |
| 647 |
|
| 648 |
modal.on('click', 'button.villatheme-deactivate-submit', function (e) { |
| 649 |
e.preventDefault(); |
| 650 |
let button = $(this); |
| 651 |
|
| 652 |
if (button.hasClass('disabled')) return; |
| 653 |
|
| 654 |
let radio = $('input[type=\"radio\"]:checked', modal); |
| 655 |
let selected_reason = radio.parents('li:first'), |
| 656 |
input = selected_reason.find('textarea, input[type=\"text\"]'); |
| 657 |
let reason_id = (0 === radio.length) ? '' : radio.val(); |
| 658 |
let reason_info = (0 !== input.length) ? input.val().trim() : ''; |
| 659 |
let date = new Date(Date.now()).toLocaleString().split(',')[0]; |
| 660 |
|
| 661 |
if ((reason_id === 'other' && !reason_info) || !reason_id) { |
| 662 |
window.location.href = ViDeactivate.deactivateLink; |
| 663 |
return; |
| 664 |
} |
| 665 |
|
| 666 |
$.ajax({ |
| 667 |
url: ViDeactivate.surveyUrl+'?date='+date+'&'+reason_id+'=1&reason_info='+reason_info, |
| 668 |
type: 'GET', |
| 669 |
beforeSend: function () { |
| 670 |
button.addClass('disabled'); |
| 671 |
button.text('Processing...'); |
| 672 |
}, |
| 673 |
complete: function () { |
| 674 |
window.location.href = ViDeactivate.deactivateLink; |
| 675 |
} |
| 676 |
}); |
| 677 |
|
| 678 |
}); |
| 679 |
}); |
| 680 |
}(jQuery));" ); |
| 681 |
} |
| 682 |
wp_add_inline_script( 'villatheme-support', "(function ($) { |
| 683 |
$(function () { |
| 684 |
$(document).on('click', '#the-list a#deactivate-" . esc_html( $this->data['deactivate_id'] ?: $this->data['slug'] ) . "', function (e) { |
| 685 |
e.preventDefault(); |
| 686 |
ViDeactivate.modal.addClass('modal-active'); |
| 687 |
ViDeactivate.deactivateLink = $(this).attr('href'); |
| 688 |
ViDeactivate.surveyUrl = '" . esc_html( $this->data['survey_url'] ) . "'; |
| 689 |
ViDeactivate.modal.find('a.dont-bother-me').attr('href', ViDeactivate.deactivateLink).css('float', 'left'); |
| 690 |
}); |
| 691 |
}); |
| 692 |
}(jQuery));" ); |
| 693 |
add_action( 'admin_footer', array( $this, 'deactivate_scripts' ) ); |
| 694 |
} |
| 695 |
} |
| 696 |
|
| 697 |
/** |
| 698 |
* |
| 699 |
*/ |
| 700 |
public function villatheme_support() { |
| 701 |
?> |
| 702 |
<div id="villatheme-support" class="vi-ui form segment"> |
| 703 |
|
| 704 |
<div class="villatheme-support-head"> |
| 705 |
<span class="villatheme-support-title"><?php echo esc_html( 'MAYBE YOU LIKE' ) ?></span> |
| 706 |
<div class="villatheme-support-action"> |
| 707 |
<a class="vi-ui button labeled inverted icon min document" target="_blank" |
| 708 |
href="<?php echo esc_attr( esc_url( $this->data['docs'] ) ) ?>"> |
| 709 |
<i class="file alternate icon"></i> |
| 710 |
<?php echo esc_html( 'Documentation' ) ?> |
| 711 |
</a> |
| 712 |
<a class="vi-ui button inverted labeled review icon mini" target="_blank" |
| 713 |
href="<?php echo esc_attr( esc_url( $this->data['review'] ) ) ?>"> |
| 714 |
<i class="star icon"></i> |
| 715 |
<?php echo esc_html( 'Review' ) ?> |
| 716 |
</a> |
| 717 |
<a class="vi-ui button labeled icon request-support green min" target="_blank" |
| 718 |
href="<?php echo esc_attr( esc_url( $this->data['support'] ) ) ?>"> |
| 719 |
<i class="users icon"></i> |
| 720 |
<?php echo esc_html( 'Request Support' ) ?> |
| 721 |
</a> |
| 722 |
<?php |
| 723 |
if ( get_option( 'villatheme_hide_admin_toolbar' ) ) { |
| 724 |
?> |
| 725 |
<a class="vi-ui button labeled icon blue inverted admin-toolbar mini" target="_self" |
| 726 |
title="<?php echo esc_attr( 'VillaTheme toolbar helps you access all VillaTheme items quickly' ) ?>" |
| 727 |
href="<?php echo esc_url( add_query_arg( array( '_villatheme_nonce' => wp_create_nonce( 'villatheme_show_toolbar' ) ) ) ) ?>"> |
| 728 |
<i class="eye icon"></i> |
| 729 |
<?php echo esc_html( 'Show Toolbar' ) ?> |
| 730 |
</a> |
| 731 |
<?php |
| 732 |
} |
| 733 |
?> |
| 734 |
</div> |
| 735 |
</div> |
| 736 |
<div class="villatheme-items"> |
| 737 |
<?php |
| 738 |
$items = $this->get_data( $this->data['slug'] ); |
| 739 |
if ( is_array( $items ) && !empty( $items ) ) { |
| 740 |
shuffle( $items ); |
| 741 |
$items = array_slice( $items, 0, 12 ); |
| 742 |
foreach ( $items as $k => $item ) { |
| 743 |
?> |
| 744 |
<div class="villatheme-item"> |
| 745 |
<a target="_blank" href="<?php echo esc_url( $item->link ) ?>"> |
| 746 |
<img src="<?php echo esc_url( $item->image ) // phpcs:ignore PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage ?>"/> |
| 747 |
</a> |
| 748 |
</div> |
| 749 |
<?php |
| 750 |
} |
| 751 |
} |
| 752 |
?> |
| 753 |
</div> |
| 754 |
</div> |
| 755 |
<?php |
| 756 |
} |
| 757 |
|
| 758 |
/** |
| 759 |
* @param bool $slug |
| 760 |
* |
| 761 |
* @return array |
| 762 |
*/ |
| 763 |
protected function get_data( $slug = false ) { |
| 764 |
$feeds = get_transient( 'villatheme_ads' ); |
| 765 |
$ads = null; |
| 766 |
|
| 767 |
if ( ! $feeds ) { |
| 768 |
try { |
| 769 |
$request_data = $this->remote_get( false ); |
| 770 |
if ( isset( $request_data['status'] ) && $request_data['status'] === 'success' ) { |
| 771 |
$ads = $request_data['data']; |
| 772 |
} |
| 773 |
set_transient( 'villatheme_ads', $ads, DAY_IN_SECONDS ); |
| 774 |
} catch ( Exception $e ) { |
| 775 |
} |
| 776 |
} else { |
| 777 |
$ads = $feeds; |
| 778 |
} |
| 779 |
|
| 780 |
$results = []; |
| 781 |
|
| 782 |
if ( is_string( $ads ) && $ads !== '' ) { |
| 783 |
$ads = json_decode( $ads ); |
| 784 |
if ( is_array( $ads ) ) { |
| 785 |
$ads = array_filter( $ads ); |
| 786 |
foreach ( $ads as $ad ) { |
| 787 |
if ( ! is_object( $ad ) ) { |
| 788 |
continue; |
| 789 |
} |
| 790 |
if ( $slug ) { |
| 791 |
if ( ( $ad->slug ?? '' ) == $slug ) { |
| 792 |
continue; |
| 793 |
} |
| 794 |
} |
| 795 |
if ( empty( $ad->link ) || empty( $ad->image ) ) { |
| 796 |
continue; |
| 797 |
} |
| 798 |
$item = new stdClass(); |
| 799 |
$item->title = $ad->title ?? ''; |
| 800 |
$item->link = $ad->link ?? ''; |
| 801 |
$item->thumb = $ad->thumb ?? ''; |
| 802 |
$item->image = $ad->image ?? ''; |
| 803 |
$item->desc = $ad->description ?? ''; |
| 804 |
$item->free_url = $ad->free_url ?? ''; |
| 805 |
$item->demo_url = $ad->demo_url ?? ''; |
| 806 |
$results[] = $item; |
| 807 |
} |
| 808 |
} |
| 809 |
} |
| 810 |
|
| 811 |
return $results; |
| 812 |
} |
| 813 |
|
| 814 |
/** |
| 815 |
* Add toolbar in WordPress Dashboard |
| 816 |
*/ |
| 817 |
public function add_toolbar() { |
| 818 |
/** |
| 819 |
* @var $wp_admin_bar WP_Admin_Bar |
| 820 |
*/ |
| 821 |
global $wp_admin_bar; |
| 822 |
if ( get_option( 'villatheme_hide_admin_toolbar' ) ) { |
| 823 |
return; |
| 824 |
} |
| 825 |
if ( ! is_object( $wp_admin_bar ) ) { |
| 826 |
return; |
| 827 |
} |
| 828 |
if ( ! $wp_admin_bar->get_node( 'villatheme' ) ) { |
| 829 |
$wp_admin_bar->add_node( array( |
| 830 |
'id' => 'villatheme', |
| 831 |
'title' => '<span class="ab-icon dashicons-star-filled villatheme-rotating"></span>' . 'VillaTheme', |
| 832 |
'href' => '', |
| 833 |
'meta' => array( |
| 834 |
'class' => 'villatheme-toolbar' |
| 835 |
), |
| 836 |
) ); |
| 837 |
add_action( 'admin_bar_menu', array( $this, 'hide_toolbar_button' ), 200 ); |
| 838 |
} |
| 839 |
if ( $this->data['menu_slug'] ) { |
| 840 |
$wp_admin_bar->add_node( array( |
| 841 |
'id' => $this->data['slug'], |
| 842 |
'title' => $this->get_plugin_name(), |
| 843 |
'parent' => 'villatheme', |
| 844 |
'href' => strpos( $this->data['menu_slug'], '.php' ) === false ? admin_url( 'admin.php?page=' . $this->data['menu_slug'] ) : admin_url( $this->data['menu_slug'] ), |
| 845 |
) ); |
| 846 |
} |
| 847 |
} |
| 848 |
|
| 849 |
public function hide_toolbar_button() { |
| 850 |
global $wp_admin_bar; |
| 851 |
/** |
| 852 |
* @var $wp_admin_bar WP_Admin_Bar |
| 853 |
*/ |
| 854 |
if ( ! is_object( $wp_admin_bar ) ) { |
| 855 |
return; |
| 856 |
} |
| 857 |
$wp_admin_bar->add_node( array( |
| 858 |
'id' => 'villatheme_hide_toolbar', |
| 859 |
'title' => '<span class="dashicons dashicons-dismiss"></span><span class="villatheme-hide-toolbar-button-title">Hide VillaTheme toolbar</span>', |
| 860 |
'parent' => 'villatheme', |
| 861 |
'href' => add_query_arg( array( '_villatheme_nonce' => wp_create_nonce( 'villatheme_hide_toolbar' ) ) ), |
| 862 |
) ); |
| 863 |
} |
| 864 |
|
| 865 |
private function get_plugin_name() { |
| 866 |
$plugins = get_plugins(); |
| 867 |
|
| 868 |
return isset( $plugins[ $this->plugin_base_name ]['Title'] ) ? $plugins[ $this->plugin_base_name ]['Title'] : ucwords( str_replace( '-', ' ', $this->data['slug'] ) ); |
| 869 |
} |
| 870 |
|
| 871 |
private function get_uninstall_reasons() { |
| 872 |
$reasons = array( |
| 873 |
array( |
| 874 |
'id' => 'could_not_understand', |
| 875 |
'text' => 'I couldn\'t understand how to make it work', |
| 876 |
'type' => 'textarea', |
| 877 |
'placeholder' => 'Would you like us to assist you?' |
| 878 |
), |
| 879 |
array( |
| 880 |
'id' => 'found_better_plugin', |
| 881 |
'text' => 'I found a better plugin', |
| 882 |
'type' => 'text', |
| 883 |
'placeholder' => 'Which plugin?' |
| 884 |
), |
| 885 |
array( |
| 886 |
'id' => 'not_have_that_feature', |
| 887 |
'text' => 'The plugin is great, but I need specific feature that you don\'t support', |
| 888 |
'type' => 'textarea', |
| 889 |
'placeholder' => 'Could you tell us more about that feature?' |
| 890 |
), |
| 891 |
array( |
| 892 |
'id' => 'is_not_working', |
| 893 |
'text' => 'The plugin is not working', |
| 894 |
'type' => 'textarea', |
| 895 |
'placeholder' => 'Could you tell us a bit more whats not working?' |
| 896 |
), |
| 897 |
array( |
| 898 |
'id' => 'looking_for_other', |
| 899 |
'text' => 'It\'s not what I was looking for', |
| 900 |
'type' => 'textarea', |
| 901 |
'placeholder' => 'Could you tell us a bit more?' |
| 902 |
), |
| 903 |
array( |
| 904 |
'id' => 'did_not_work_as_expected', |
| 905 |
'text' => 'The plugin didn\'t work as expected', |
| 906 |
'type' => 'textarea', |
| 907 |
'placeholder' => 'What did you expect?' |
| 908 |
), |
| 909 |
array( |
| 910 |
'id' => 'other', |
| 911 |
'text' => 'Other', |
| 912 |
'type' => 'textarea', |
| 913 |
'placeholder' => 'Could you tell us a bit more?' |
| 914 |
), |
| 915 |
); |
| 916 |
|
| 917 |
return $reasons; |
| 918 |
} |
| 919 |
|
| 920 |
public function deactivate_scripts() { |
| 921 |
global $pagenow; |
| 922 |
if ( 'plugins.php' != $pagenow ) { |
| 923 |
return; |
| 924 |
} |
| 925 |
|
| 926 |
static $modal = false; |
| 927 |
|
| 928 |
if ( ! $modal ) { |
| 929 |
$reasons = $this->get_uninstall_reasons(); |
| 930 |
?> |
| 931 |
<div class="villatheme-deactivate-modal" id="villatheme-deactivate-survey-modal"> |
| 932 |
<div class="villatheme-deactivate-modal-wrap"> |
| 933 |
<div class="villatheme-deactivate-modal-header"> |
| 934 |
<h3><?php echo esc_html( 'If you have a moment, please let us know why you are deactivating:' ); ?></h3> |
| 935 |
</div> |
| 936 |
<div class="villatheme-deactivate-modal-body"> |
| 937 |
<ul class="reasons"> |
| 938 |
<?php foreach ( $reasons as $reason ) { ?> |
| 939 |
<li data-type="<?php echo esc_attr( $reason['type'] ); ?>" data-placeholder="<?php echo esc_attr( $reason['placeholder'] ); ?>"> |
| 940 |
<label> |
| 941 |
<input type="radio" name="selected-reason" value="<?php echo esc_attr( $reason['id'] ); ?>"> |
| 942 |
<?php echo esc_html( $reason['text'] ); ?> |
| 943 |
</label> |
| 944 |
</li> |
| 945 |
<?php } ?> |
| 946 |
</ul> |
| 947 |
</div> |
| 948 |
<div class="villatheme-deactivate-modal-footer"> |
| 949 |
<a href="#" class="dont-bother-me"><?php echo esc_html( 'I rather wouldn\'t say' ); ?></a> |
| 950 |
<button class="button-primary villatheme-deactivate-submit disabled"><?php echo esc_html( 'Submit & Deactivate' ); ?></button> |
| 951 |
<button class="button-secondary villatheme-model-cancel"><?php echo esc_html( 'Cancel' ); ?></button> |
| 952 |
</div> |
| 953 |
</div> |
| 954 |
</div> |
| 955 |
<?php |
| 956 |
$modal = true; |
| 957 |
} |
| 958 |
} |
| 959 |
} |
| 960 |
} |
| 961 |
|
| 962 |
if ( ! class_exists( 'VillaTheme_Require_Environment' ) ) { |
| 963 |
class VillaTheme_Require_Environment { |
| 964 |
|
| 965 |
protected $args; |
| 966 |
protected $plugin_name; |
| 967 |
protected $notices = []; |
| 968 |
|
| 969 |
public function __construct( $args ) { |
| 970 |
if ( ! did_action( 'plugins_loaded' ) ) { |
| 971 |
_doing_it_wrong( 'VillaTheme_Require_Environment', wp_kses_post( 'VillaTheme_Require_Environment should not be run before the <code>plugins_loaded</code> hook.' ), '1.1.9' ); |
| 972 |
} |
| 973 |
|
| 974 |
$args = apply_filters( 'villatheme_check_requires', wp_parse_args( $args, [ |
| 975 |
'plugin_name' => '', |
| 976 |
'php_version' => '', |
| 977 |
'wp_version' => '', |
| 978 |
'wc_version' => '', |
| 979 |
'require_plugins' => [], |
| 980 |
] ) ); |
| 981 |
|
| 982 |
$this->plugin_name = $args['plugin_name']; |
| 983 |
|
| 984 |
$this->check( $args ); |
| 985 |
|
| 986 |
add_action( 'admin_notices', [ $this, 'notice' ] ); |
| 987 |
} |
| 988 |
|
| 989 |
protected function check( $args ) { |
| 990 |
if ( ! empty( $args['php_version'] ) && version_compare( PHP_VERSION, $args['php_version'], '<' ) ) { |
| 991 |
$this->notices[] = sprintf( "PHP version at least %s.", esc_html( $args['php_version'] ) ); |
| 992 |
} |
| 993 |
|
| 994 |
if ( ! empty( $args['wp_version'] ) && version_compare( get_bloginfo( 'version' ), $args['wp_version'], '<' ) ) { |
| 995 |
$this->notices[] = sprintf( "WordPress version at least %s.", esc_html( $args['wp_version'] ) ); |
| 996 |
} |
| 997 |
if ( ! empty( $args['require_plugins'] ) ) { |
| 998 |
foreach ( $args['require_plugins'] as $plugin ) { |
| 999 |
if ( ! is_array( $plugin ) || empty( $plugin ) || empty( $plugin['defined_version'] ) ) { |
| 1000 |
continue; |
| 1001 |
} |
| 1002 |
$plugin_name = $plugin['name'] ?? ''; |
| 1003 |
$plugin_slug = $plugin['slug'] ?? ''; |
| 1004 |
$plugin_version = $plugin['version'] ?? $plugin['required_version'] ?? ''; |
| 1005 |
if ( ! $plugin_version && $plugin_slug === 'woocommerce' ) { |
| 1006 |
$plugin_version = $args['wc_version'] ?? ''; |
| 1007 |
} |
| 1008 |
$plugin['version'] = $plugin_version; |
| 1009 |
if ( ! defined( $plugin['defined_version'] ) ) { |
| 1010 |
$msg = sprintf( '%s is <a href="%s" target="_blank">installed and activated.</a>', esc_html( $plugin_name ), network_admin_url( "plugin-install.php?s={$plugin_slug}&tab=search&type=term" ) ); |
| 1011 |
$this->notices[] = $msg; |
| 1012 |
} elseif ( $plugin_version && ! version_compare( constant( $plugin['defined_version'] ), $plugin_version, '>=' ) ) { |
| 1013 |
$this->notices[] = sprintf( "%s version at least %s.", esc_html( $plugin_name ), esc_html( $plugin_version ) ); |
| 1014 |
} |
| 1015 |
} |
| 1016 |
} |
| 1017 |
} |
| 1018 |
|
| 1019 |
public function notice() { |
| 1020 |
$screen = get_current_screen(); |
| 1021 |
|
| 1022 |
if ( ! current_user_can( 'manage_options' ) || ! is_object( $screen ) || 'update' === $screen->id ) { |
| 1023 |
return; |
| 1024 |
} |
| 1025 |
|
| 1026 |
if ( ! empty( $this->notices ) ) { |
| 1027 |
?> |
| 1028 |
<div class="error"> |
| 1029 |
<?php |
| 1030 |
if ( count( $this->notices ) > 1 ) { |
| 1031 |
printf( "<p>%s requires:</p>", esc_html( $this->plugin_name ) ); |
| 1032 |
?> |
| 1033 |
<ol> |
| 1034 |
<?php |
| 1035 |
foreach ( $this->notices as $notice ) { |
| 1036 |
printf( "<li>%s</li>", wp_kses_post( $notice ) ); |
| 1037 |
} |
| 1038 |
?> |
| 1039 |
</ol> |
| 1040 |
<?php |
| 1041 |
} else { |
| 1042 |
printf( "<p>%s requires %s</p>", esc_html( $this->plugin_name ), wp_kses_post( current( $this->notices ) ) ); |
| 1043 |
} |
| 1044 |
?> |
| 1045 |
</div> |
| 1046 |
<?php |
| 1047 |
} |
| 1048 |
} |
| 1049 |
|
| 1050 |
public function has_error() { |
| 1051 |
return ! empty( $this->notices ); |
| 1052 |
} |
| 1053 |
} |
| 1054 |
} |