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