| 1 |
<?php |
| 2 |
/** |
| 3 |
* Disco Plugin Uses Tracker |
| 4 |
* Uses Webappick Insights for tracking |
| 5 |
* @since 3.1.41 |
| 6 |
* @version 1.0.2 |
| 7 |
*/ |
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
die(); |
| 10 |
} |
| 11 |
|
| 12 |
if ( ! class_exists( 'DiscoWebAppickAPI' ) ) { |
| 13 |
/** |
| 14 |
* Class WooFeedWebAppickAPI |
| 15 |
*/ |
| 16 |
final class DiscoWebAppickAPI { |
| 17 |
|
| 18 |
/** |
| 19 |
* Singleton instance |
| 20 |
* @var WooFeedWebAppickAPI |
| 21 |
*/ |
| 22 |
protected static $instance; |
| 23 |
|
| 24 |
/** |
| 25 |
* @var Disco\AppServices\Client |
| 26 |
*/ |
| 27 |
protected $client = null; |
| 28 |
|
| 29 |
/** |
| 30 |
* @var Disco\AppServices\Insights |
| 31 |
*/ |
| 32 |
protected $insights = null; |
| 33 |
|
| 34 |
/** |
| 35 |
* Promotions Class Instance |
| 36 |
* @var Disco\AppServices\Promotions |
| 37 |
*/ |
| 38 |
public $promotion = null; |
| 39 |
|
| 40 |
/** |
| 41 |
* Plugin License Manager |
| 42 |
* @var Disco\AppServices\License |
| 43 |
*/ |
| 44 |
protected $license = null; |
| 45 |
|
| 46 |
/** |
| 47 |
* Plugin Updater |
| 48 |
* @var Disco\AppServices\Updater |
| 49 |
*/ |
| 50 |
protected $updater = null; |
| 51 |
|
| 52 |
/** |
| 53 |
* var $is_add_extra |
| 54 |
*/ |
| 55 |
protected $is_add_extra = true; |
| 56 |
|
| 57 |
/** |
| 58 |
* Initialize |
| 59 |
* @return WooFeedWebAppickAPI |
| 60 |
*/ |
| 61 |
public static function getInstance() { |
| 62 |
if ( is_null( self::$instance ) ) { |
| 63 |
self::$instance = new self(); |
| 64 |
} |
| 65 |
return self::$instance; |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Class constructor |
| 70 |
* |
| 71 |
* @return void |
| 72 |
* @since 1.0.0 |
| 73 |
* |
| 74 |
*/ |
| 75 |
private function __construct() { |
| 76 |
if ( ! class_exists( 'Disco\AppServices\Client' ) ) { |
| 77 |
/** @noinspection PhpIncludeInspection */ |
| 78 |
require_once DISCO_LIBS_PATH . 'WebAppick/AppServices/Client.php'; |
| 79 |
} |
| 80 |
|
| 81 |
if ( ! is_plugin_active('disco-pro/disco-pro.php') ) { |
| 82 |
$this->client = new Disco\Libs\WebAppick\AppServices\Client( '4e68acba-cbdc-476b-b4bf-eab176ac6a16', 'Disco', DISCO_PLUGIN_FILE ); |
| 83 |
} else { |
| 84 |
$this->client = new Disco\Libs\WebAppick\AppServices\Client( '4e68acba-cbdc-476b-b4bf-eab176ac6a16', 'Disco Pro', DISCO_PRO_PLUGIN_FILE ); |
| 85 |
} |
| 86 |
|
| 87 |
// Load Client |
| 88 |
// Load |
| 89 |
$this->insights = $this->client->insights(); // Plugin Insights |
| 90 |
$this->promotion = $this->client->promotions(); // Promo offers |
| 91 |
|
| 92 |
// Setup |
| 93 |
$this->promotion->set_source( 'https://api.bitbucket.org/2.0/snippets/woofeed/RLbyop/files/woo-feed-notice.json' ); |
| 94 |
|
| 95 |
// Initialize |
| 96 |
$this->insightInit(); |
| 97 |
$this->promotion->init(); |
| 98 |
|
| 99 |
// Housekeeping. |
| 100 |
// add_action( 'admin_menu', array( $this, 'premium_features' ), 999 ); |
| 101 |
// |
| 102 |
// //show admin notices when woocommerce is activated |
| 103 |
// if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) { |
| 104 |
// add_action( 'admin_notices', array( $this, 'disco_review_notice' ) ); |
| 105 |
// add_action( 'wp_ajax_disco_save_review_notice', array( $this, 'disco_save_review_notice' ) ); |
| 106 |
// add_action( 'wp_ajax_disco_hide_notice', array( $this, 'disco_hide_notice' ) ); |
| 107 |
// } |
| 108 |
|
| 109 |
} |
| 110 |
|
| 111 |
/** |
| 112 |
* Cloning is forbidden. |
| 113 |
* @since 1.0.2 |
| 114 |
*/ |
| 115 |
public function __clone() { |
| 116 |
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cloning is forbidden.', 'disco' ), '1.0.2' ); |
| 117 |
} |
| 118 |
|
| 119 |
/** |
| 120 |
* Initialize Insights |
| 121 |
* @return void |
| 122 |
*/ |
| 123 |
private function insightInit() { |
| 124 |
// global $wpdb; |
| 125 |
// $result = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->options WHERE option_name LIKE %s;", "wf_feed_%"), 'ARRAY_A' ); // phpcs:ignore |
| 126 |
// if ( ! is_array( $result ) ) { |
| 127 |
// $result = array(); |
| 128 |
// } |
| 129 |
$catCount = wp_count_terms( |
| 130 |
array( |
| 131 |
'taxonomy' => 'product_cat', |
| 132 |
'hide_empty' => false, |
| 133 |
'parent' => 0, |
| 134 |
) |
| 135 |
); |
| 136 |
if ( is_wp_error( $catCount ) ) { |
| 137 |
$catCount = 0; |
| 138 |
} |
| 139 |
/** |
| 140 |
* @TODO count products by type |
| 141 |
* @see wc_get_product_types(); |
| 142 |
*/ |
| 143 |
// update_option( 'disco_review_notice', $value ); |
| 144 |
// $notices = [ 'rp-wcdpd', 'wpml', 'rating', 'product_limit' ]; |
| 145 |
// |
| 146 |
$hidden_notices = array(); |
| 147 |
foreach ( array( 'rp-wcdpd', 'wpml', 'rating', 'product_limit' ) as $which ) { |
| 148 |
$hidden_notices[ $which ] = (int) get_option( sprintf( 'disco_%s_notice_hidden', $which ), 0 ); |
| 149 |
} |
| 150 |
|
| 151 |
$this->is_add_extra = apply_filters( 'disco_woocommerce_add_extra', true ); |
| 152 |
|
| 153 |
if( $this->is_add_extra ) { |
| 154 |
|
| 155 |
$tracker_extra = array( |
| 156 |
'products' => $this->insights->get_post_count('product'), |
| 157 |
'variations' => $this->insights->get_post_count('product_variation'), |
| 158 |
// 'batch_limit' => get_option('disco_per_batch'), |
| 159 |
// 'feed_configs' => wp_json_encode($result), |
| 160 |
'product_cat_num' => $catCount, |
| 161 |
'review_notice' => wp_json_encode(get_option('disco_review_notice', array())), |
| 162 |
'hidden_notices' => $hidden_notices, |
| 163 |
); |
| 164 |
$this->insights->add_extra($tracker_extra); |
| 165 |
} |
| 166 |
|
| 167 |
$projectSlug = $this->client->getSlug(); |
| 168 |
add_filter( $projectSlug . '_what_tracked', array( $this, 'data_we_collect' ), 10, 1 ); |
| 169 |
add_filter( |
| 170 |
"WebAppick_{$projectSlug}_Support_Ticket_Recipient_Email", |
| 171 |
function() { |
| 172 |
return 'sales@webappick.com'; |
| 173 |
}, |
| 174 |
10 |
| 175 |
); |
| 176 |
add_filter( "WebAppick_{$projectSlug}_Support_Ticket_Email_Template", array( $this, 'supportTicketTemplate' ), 10 ); |
| 177 |
add_filter( "WebAppick_{$projectSlug}_Support_Request_Ajax_Success_Response", array( $this, 'supportResponse' ), 10 ); |
| 178 |
add_filter( "WebAppick_{$projectSlug}_Support_Request_Ajax_Error_Response", array( $this, 'supportErrorResponse' ), 10 ); |
| 179 |
add_filter( |
| 180 |
"WebAppick_{$projectSlug}_Support_Page_URL", |
| 181 |
function() { |
| 182 |
return 'https://wordpress.org/support/plugin/disco/#new-topic-0'; |
| 183 |
}, |
| 184 |
10 |
| 185 |
); |
| 186 |
$this->insights->init(); |
| 187 |
} |
| 188 |
|
| 189 |
/** |
| 190 |
* Generate Support Ticket Email Template |
| 191 |
* @return string |
| 192 |
*/ |
| 193 |
public function supportTicketTemplate() { |
| 194 |
// dynamic variable format __INPUT_NAME__ |
| 195 |
/** @noinspection HtmlUnknownTarget */ |
| 196 |
$template = '<div style="margin: 10px auto;"><p>Website : <a href="__WEBSITE__">__WEBSITE__</a><br>Plugin : %s (v.%s)</p></div>'; |
| 197 |
$template = sprintf( $template, $this->client->getName(), $this->client->getProjectVersion() ); |
| 198 |
$template .= '<div style="margin: 10px auto;"><hr></div>'; |
| 199 |
$template .= '<div style="margin: 10px auto;"><h3>__SUBJECT__</h3></div>'; |
| 200 |
$template .= '<div style="margin: 10px auto;">__MESSAGE__</div>'; |
| 201 |
$template .= '<div style="margin: 10px auto;"><hr></div>'; |
| 202 |
$template .= sprintf( |
| 203 |
'<div style="margin: 50px auto 10px auto;"><p style="font-size: 12px;color: #009688">%s</p></div>', |
| 204 |
'Message Processed With WebAppick Service Library (v.' . $this->client->getClientVersion() . ')' |
| 205 |
); |
| 206 |
return $template; |
| 207 |
} |
| 208 |
|
| 209 |
/** |
| 210 |
* Generate Support Ticket Ajax Response |
| 211 |
* @return string |
| 212 |
*/ |
| 213 |
public function supportResponse() { |
| 214 |
$response = ''; |
| 215 |
$response .= sprintf( '<h3>%s</h3>', esc_html__( 'Thank you -- Support Ticket Submitted.', 'disco' ) ); |
| 216 |
$ticketSubmitted = esc_html__( 'Your ticket has been successfully submitted.', 'disco' ); |
| 217 |
$twenty4Hours = sprintf( '<strong>%s</strong>', esc_html__( '24 hours', 'disco' ) ); |
| 218 |
/* translators: %s: Approx. time to response after ticket submission. */ |
| 219 |
$notification = sprintf( esc_html__( 'You will receive an email notification from "support@webappick.com" in your inbox within %s.', 'disco' ), $twenty4Hours ); |
| 220 |
$followUp = esc_html__( 'Please Follow the email and Disco Support Team will get back with you shortly.', 'disco' ); |
| 221 |
$response .= sprintf( '<p>%s %s %s</p>', $ticketSubmitted, $notification, $followUp ); |
| 222 |
$docLink = sprintf( '<a class="disco-notice-primary-button" href="https://discoplugin.com/docs/" target="_blank"><span class="dashicons dashicons-media-document" aria-hidden="true"></span> %s</a>', esc_html__( 'Documentation', 'disco' ) ); |
| 223 |
$vidLink = sprintf( '<a class="disco-notice-primary-button" href="https://www.youtube.com/c/WebAppick" target="_blank"><span class="dashicons dashicons-video-alt3" aria-hidden="true"></span> %s</a>', esc_html__( 'Video Tutorials', 'disco' ) ); |
| 224 |
$response .= sprintf( '<p>%s %s</p>', $docLink, $vidLink ); |
| 225 |
$response .= '<br><br><br>'; |
| 226 |
$toc = sprintf( '<a class="disco-notice-link-text" href="https://discoplugin.com/terms-and-condition/" target="_blank">%s</a>', esc_html__( 'Terms & Conditions', 'disco' ) ); |
| 227 |
$pp = sprintf( '<a class="disco-notice-link-text" href="https://discoplugin.com/privacy-policy/" target="_blank">%s</a>', esc_html__( 'Privacy Policy', 'disco' ) ); |
| 228 |
/* translators: 1: Link to the Trams And Condition Page, 2: Link to the Privacy Policy Page */ |
| 229 |
$policy = sprintf( esc_html__( 'Please read our %1$s and %2$s', 'disco' ), $toc, $pp ); |
| 230 |
$response .= sprintf( '<p style="font-size: 12px;">%s</p>', $policy ); |
| 231 |
return $response; |
| 232 |
} |
| 233 |
|
| 234 |
/** |
| 235 |
* Set Error Response Message For Support Ticket Request |
| 236 |
* @return string |
| 237 |
*/ |
| 238 |
public function supportErrorResponse() { |
| 239 |
return sprintf( |
| 240 |
'<div class="mui-error"><p>%s</p><p>%s</p><br><br><p style="font-size: 12px;">%s</p></div>', |
| 241 |
esc_html__( 'Something Went Wrong. Please Try The Support Ticket Form On Our Website.', 'disco' ), |
| 242 |
sprintf( '<a class="button button-primary disco-btn-bg-gradient-blue" href="https://wordpress.org/support/plugin/disco/#new-topic-0" target="_blank">%s</a>', esc_html__( 'Get Support', 'disco' ) ), |
| 243 |
esc_html__( 'Support Ticket form will open in new tab in 5 seconds.', 'disco' ) |
| 244 |
); |
| 245 |
} |
| 246 |
|
| 247 |
/** |
| 248 |
* Set Data Collection description for the tracker |
| 249 |
* @param $data |
| 250 |
* |
| 251 |
* @return array |
| 252 |
*/ |
| 253 |
public function data_we_collect( $data ) { |
| 254 |
$data = array_merge( |
| 255 |
$data, |
| 256 |
array( |
| 257 |
esc_html__( 'Number of products in your site.', 'disco' ), |
| 258 |
esc_html__( 'Number of product categories in your site.', 'disco' ), |
| 259 |
// esc_html__( 'Feed Configuration.', 'disco' ), |
| 260 |
esc_html__( 'Site name, language and url.', 'disco' ), |
| 261 |
esc_html__( 'Number of active and inactive plugins.', 'disco' ), |
| 262 |
esc_html__( 'Your name and email address.', 'disco' ), |
| 263 |
) |
| 264 |
); |
| 265 |
return $data; |
| 266 |
} |
| 267 |
|
| 268 |
/** |
| 269 |
* Get Tracker Data Collection Description Array |
| 270 |
* @return array |
| 271 |
*/ |
| 272 |
public function get_data_collection_description() { |
| 273 |
return $this->insights->get_data_collection_description(); |
| 274 |
} |
| 275 |
|
| 276 |
/** |
| 277 |
* Update Tracker OptIn |
| 278 |
* |
| 279 |
* @param bool $override optional. ignore last send datetime settings if true. |
| 280 |
* @see Insights::send_tracking_data() |
| 281 |
* @return void |
| 282 |
*/ |
| 283 |
public function trackerOptIn( $override = false ) { |
| 284 |
$this->insights->optIn( $override ); |
| 285 |
} |
| 286 |
|
| 287 |
/** |
| 288 |
* Update Tracker OptOut |
| 289 |
* @return void |
| 290 |
*/ |
| 291 |
public function trackerOptOut() { |
| 292 |
$this->insights->optOut(); |
| 293 |
} |
| 294 |
|
| 295 |
/** |
| 296 |
* Check if tracking is enable |
| 297 |
* @return bool |
| 298 |
*/ |
| 299 |
public function is_tracking_allowed() { |
| 300 |
return $this->insights->is_tracking_allowed(); |
| 301 |
} |
| 302 |
|
| 303 |
// public function premium_features() { |
| 304 |
// add_submenu_page( 'webappick-manage-feeds', esc_html__( 'Premium', 'disco' ), '<span class="disco-premium">' . esc_html__( 'Premium', 'disco' ) . '</span>', 'manage_woocommerce', 'webappick-feed-pro-vs-free', array( $this, 'disco_pro_vs_free' ) ); |
| 305 |
// add_submenu_page( 'webappick-manage-feeds', esc_html__( 'Our Plugins', 'disco' ), '<span class="disco-our-plugin">' . esc_html__( 'Our Plugins', 'disco' ) . '</span>', 'manage_woocommerce', 'webappick-feed-our-plugins', array( $this, 'disco_our_plugins' ) ); |
| 306 |
// add_action( 'admin_head', array( $this, 'remove_admin_notices' ), 9999 ); |
| 307 |
// } |
| 308 |
|
| 309 |
/** |
| 310 |
* Render Premium Feature Comparison Page |
| 311 |
* @return void |
| 312 |
*/ |
| 313 |
// public function disco_pro_vs_free() { |
| 314 |
// /** @define "WOO_FEED_FREE_ADMIN_PATH''./../../admin/" */ // phpcs:ignore |
| 315 |
// require WOO_FEED_FREE_ADMIN_PATH . 'partials/disco-pro-vs-free.php'; |
| 316 |
// } |
| 317 |
|
| 318 |
/** |
| 319 |
* Render Our Plugins Page |
| 320 |
* @return void |
| 321 |
*/ |
| 322 |
// public function disco_our_plugins() { |
| 323 |
// /** @define "WOO_FEED_FREE_ADMIN_PATH''./../../admin/" */ // phpcs:ignore |
| 324 |
// require WOO_FEED_FREE_ADMIN_PATH . 'partials/disco-our-plugins.php'; |
| 325 |
// } |
| 326 |
|
| 327 |
/** |
| 328 |
* Remove Admin Notice in pro features page. |
| 329 |
* @global string $pagenow |
| 330 |
* @global string $plugin_page |
| 331 |
* @return void |
| 332 |
*/ |
| 333 |
public function remove_admin_notices() { |
| 334 |
global $pagenow, $plugin_page; |
| 335 |
if ( 'admin.php' == $pagenow && 'webappick-feed-pro-vs-free' == $plugin_page ) { |
| 336 |
remove_all_actions( 'admin_notices' ); |
| 337 |
} |
| 338 |
} |
| 339 |
|
| 340 |
/** |
| 341 |
* Show Review And Compatibility Notice For Pro Features |
| 342 |
* @global string $plugin_page |
| 343 |
* @return void |
| 344 |
*/ |
| 345 |
public function disco_review_notice() { |
| 346 |
global $plugin_page; |
| 347 |
$user_id = get_current_user_id(); |
| 348 |
$nonce = wp_create_nonce( 'disco_pro_notice_nonce' ); |
| 349 |
$pluginName = sprintf( '<b>%s</b>', esc_html__( 'Disco', 'disco' ) ); |
| 350 |
$proLink = sprintf( '<b><a href="https://discoplugin.com/" target="_blank">%s</a></b>', esc_html__( 'Premium', 'disco' ) ); |
| 351 |
$has_notice = false; |
| 352 |
|
| 353 |
//submit review notice form data |
| 354 |
$this->disco_save_review_notice(); |
| 355 |
|
| 356 |
//get review notice data |
| 357 |
$next_timestamp = get_option( 'disco_review_notice_next_show_time' ); |
| 358 |
$review_notice_dismissed = get_user_meta( $user_id, 'disco_review_notice_dismissed', true ); |
| 359 |
|
| 360 |
if ( ! empty( $next_timestamp ) ) { |
| 361 |
if ( ( time() > $next_timestamp ) ) { |
| 362 |
$show_notice = true; |
| 363 |
} else { |
| 364 |
$show_notice = false; |
| 365 |
} |
| 366 |
} else { |
| 367 |
if ( isset( $review_notice_dismissed ) && ! empty( $review_notice_dismissed ) ) { |
| 368 |
$show_notice = false; |
| 369 |
} else { |
| 370 |
$show_notice = true; |
| 371 |
} |
| 372 |
} |
| 373 |
|
| 374 |
// Review Notice. |
| 375 |
if ( $show_notice ) { |
| 376 |
$has_notice = true; |
| 377 |
?> |
| 378 |
<div class="disco-notice notice notice-info" style="line-height:1.5;" data-which="rating" data-nonce="<?php echo esc_attr( $nonce ); ?>"> |
| 379 |
<form method="post"> |
| 380 |
<p> |
| 381 |
<?php |
| 382 |
printf( |
| 383 |
/* translators: 1: plugin name,2: Slightly Smiling Face (Emoji), 3: line break 'br' tag */ |
| 384 |
esc_html__( '%3$s %2$s We have spent countless hours developing this free plugin for you, and we would really appreciate it if you dropped us a quick rating. Your opinion matters a lot to us.%4$s It helps us to get better. Thanks for using %1$s.', 'disco' ), |
| 385 |
$pluginName, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 386 |
'<span style="font-size: 16px;">🙂</span>', |
| 387 |
'<div class="disco-review-notice-logo"></div>', |
| 388 |
'<br>' |
| 389 |
); |
| 390 |
?> |
| 391 |
</p> |
| 392 |
<p> |
| 393 |
<button type="submit" name="disco_review_notice_btn_later" value="later" class="button button-secondary"><?php esc_html_e( 'Remind me later', 'disco' ); ?></button> |
| 394 |
<button type="submit" name="disco_review_notice_btn_never" value="never" class="button button-secondary"><?php esc_html_e( 'I would not', 'disco' ); ?></button> |
| 395 |
<button type="submit" name="disco_review_notice_btn_done" value="done" class="button button-secondary"><?php esc_html_e( 'I already did!', 'disco' ); ?></button> |
| 396 |
<button type="submit" name="disco_review_notice_btn_given" value="given" class="button button-primary disco-btn-bg-gradient-blue"><?php esc_html_e( 'Review Here', 'disco' ); ?></button> |
| 397 |
</p> |
| 398 |
|
| 399 |
<button type="submit" class="disco-review-btn-dismiss" name="disco_review_notice_submit"><span><?php esc_html_e( 'Dismiss', 'disco' ); ?></span></button> |
| 400 |
</form> |
| 401 |
</div> |
| 402 |
<?php |
| 403 |
} |
| 404 |
|
| 405 |
// Compatibility Notices. |
| 406 |
if ( class_exists( 'SitePress' ) && false === get_option( 'disco_wpml_notice_hidden' ) ) { |
| 407 |
$has_notice = true; |
| 408 |
?> |
| 409 |
<div class="disco-notice notice notice-success is-dismissible" data-which="wpml"> |
| 410 |
<p> |
| 411 |
<?php |
| 412 |
printf( |
| 413 |
/* translators: 1: This plugin name, 2: Pro version purchase link */ |
| 414 |
esc_html__( 'You are awesome for using %1$s. Using the %2$s version you can make multilingual feed for your WPML languages.', 'disco' ), |
| 415 |
$pluginName, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 416 |
$proLink // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 417 |
); |
| 418 |
?> |
| 419 |
</p> |
| 420 |
</div> |
| 421 |
<?php |
| 422 |
} |
| 423 |
if ( class_exists( 'RP_WCDPD', false ) && false === get_option( 'disco_rp-wcdpd_notice_hidden' ) ) { |
| 424 |
$has_notice = true; |
| 425 |
?> |
| 426 |
<div class="disco-notice notice notice-success is-dismissible" data-which="rp-wcdpd"> |
| 427 |
<p> |
| 428 |
<?php |
| 429 |
printf( |
| 430 |
/* translators: 1: This plugin Name, 2: Incompatible plugin name, 3: Pro version purchase link */ |
| 431 |
esc_html__( '%1$s isn\'t fully compatible with %2$s. Get the %3$s version for full support.', 'disco' ), |
| 432 |
$pluginName, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 433 |
'<b>' . esc_html__( 'WooCommerce Dynamic Pricing & Discounts', 'disco' ) . '</b>', |
| 434 |
$proLink // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 435 |
); |
| 436 |
?> |
| 437 |
</p> |
| 438 |
</div> |
| 439 |
<?php |
| 440 |
} |
| 441 |
if ( true === $has_notice ) { |
| 442 |
add_action( |
| 443 |
'admin_print_footer_scripts', |
| 444 |
function() use ( $nonce ) { |
| 445 |
?> |
| 446 |
<script> |
| 447 |
(function($){ |
| 448 |
"use strict"; |
| 449 |
$(document) |
| 450 |
.on('click', '.disco-notice a.button', function (e) { |
| 451 |
e.preventDefault(); |
| 452 |
// noinspection ES6ConvertVarToLetConst |
| 453 |
var self = $(this), notice = self.attr('data-response'); |
| 454 |
if ( 'given' === notice ) { |
| 455 |
window.open('https://wordpress.org/support/plugin/disco/reviews/?rate=5#new-post', '_blank'); |
| 456 |
} |
| 457 |
self.closest(".disco-notice").slideUp( 200, 'linear' ); |
| 458 |
wp.ajax.post( 'disco_save_review_notice', { _ajax_nonce: '<?php echo esc_attr( $nonce ); ?>', notice: notice } ); |
| 459 |
}) |
| 460 |
.on('click', '.disco-notice .notice-dismiss', function (e) { |
| 461 |
e.preventDefault(); |
| 462 |
// noinspection ES6ConvertVarToLetConst |
| 463 |
var self = $(this), feed_notice = self.closest('.disco-notice'), which = feed_notice.attr('data-which'); |
| 464 |
wp.ajax.post( 'disco_hide_notice', { _wpnonce: '<?php echo esc_attr( $nonce ); ?>', which: which } ); |
| 465 |
}); |
| 466 |
})(jQuery) |
| 467 |
</script> |
| 468 |
<?php |
| 469 |
}, |
| 470 |
99 |
| 471 |
); |
| 472 |
} |
| 473 |
} |
| 474 |
|
| 475 |
/** |
| 476 |
* Show Review request admin notice |
| 477 |
*/ |
| 478 |
public function disco_save_review_notice() { |
| 479 |
$user_id = get_current_user_id(); |
| 480 |
|
| 481 |
$disco_review_notice_submit = isset( $_POST['disco_review_notice_submit'] ) ? 1 : ''; |
| 482 |
$disco_review_notice_btn_given = sanitize_text_field( isset( $_POST['disco_review_notice_btn_given'] ) ? $_POST['disco_review_notice_btn_given'] : '' ); |
| 483 |
$disco_review_notice_btn_never = sanitize_text_field( isset( $_POST['disco_review_notice_btn_never'] ) ? $_POST['disco_review_notice_btn_never'] : '' ); |
| 484 |
$disco_review_notice_btn_done = sanitize_text_field( isset( $_POST['disco_review_notice_btn_done'] ) ? $_POST['disco_review_notice_btn_done'] : '' ); |
| 485 |
$disco_review_notice_btn_later = sanitize_text_field( isset( $_POST['disco_review_notice_btn_later'] ) ? $_POST['disco_review_notice_btn_later'] : '' ); |
| 486 |
|
| 487 |
//submit review notice dismissal |
| 488 |
if ( $disco_review_notice_submit ) { |
| 489 |
add_user_meta( $user_id, 'disco_review_notice_dismissed', true, true ); |
| 490 |
update_option( 'disco_review_notice_next_show_time', time() + ( DAY_IN_SECONDS * 30 ) ); |
| 491 |
} |
| 492 |
|
| 493 |
//submit review notice form data |
| 494 |
if ( $disco_review_notice_btn_given ) { |
| 495 |
wp_redirect( 'https://wordpress.org/support/plugin/disco/reviews/?rate=5#new-post' ); |
| 496 |
exit(); |
| 497 |
} elseif ( $disco_review_notice_btn_never || $disco_review_notice_btn_done ) { |
| 498 |
$notice = $disco_review_notice_btn_never ? $disco_review_notice_btn_never : $disco_review_notice_btn_done; |
| 499 |
add_user_meta( $user_id, 'disco_review_notice_dismissed', true, true ); |
| 500 |
delete_option( 'disco_review_notice_next_show_time' ); |
| 501 |
} elseif ( $disco_review_notice_btn_later ) { |
| 502 |
$notice = $disco_review_notice_btn_later; |
| 503 |
update_option( 'disco_review_notice_next_show_time', time() + ( DAY_IN_SECONDS * 30 ) ); |
| 504 |
} |
| 505 |
|
| 506 |
if ( ! empty( $notice ) ) { |
| 507 |
$value = array( |
| 508 |
'review_notice' => sanitize_text_field($notice), //phpcs:ignore |
| 509 |
'updated_at' => time(), |
| 510 |
); |
| 511 |
|
| 512 |
update_option( 'disco_review_notice', $value ); |
| 513 |
} |
| 514 |
|
| 515 |
} |
| 516 |
|
| 517 |
/** |
| 518 |
* Ajax Action For Hiding Compatibility Notices |
| 519 |
*/ |
| 520 |
public function disco_hide_notice() { |
| 521 |
check_ajax_referer( 'disco_pro_notice_nonce' ); |
| 522 |
$notices = array( 'rp-wcdpd', 'wpml', 'rating', 'product_limit' ); |
| 523 |
if ( isset( $_REQUEST['which'] ) && ! empty( $_REQUEST['which'] ) && in_array( $_REQUEST['which'], $notices ) ) { |
| 524 |
$which = sanitize_text_field( $_REQUEST['which'] ); //phpcs:ignore |
| 525 |
update_option( sprintf( 'disco_%s_notice_hidden', $which ), '1', false ); |
| 526 |
wp_send_json_success( esc_html__( 'Request Successful.', 'disco' ) ); |
| 527 |
wp_die(); |
| 528 |
} |
| 529 |
wp_send_json_error( esc_html__( 'Invalid Request.', 'disco' ) ); |
| 530 |
wp_die(); |
| 531 |
} |
| 532 |
} |
| 533 |
} |
| 534 |
// End of file class-disco-webappick-api.php |
| 535 |
|
| 536 |
|
| 537 |
|