| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Insights SDK File |
| 5 |
* SDK Version 1.0.0 |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
if ( ! class_exists( 'Insights_SDK' ) ) { |
| 13 |
|
| 14 |
/** |
| 15 |
* Insights SDK Class |
| 16 |
*/ |
| 17 |
class Insights_SDK { |
| 18 |
|
| 19 |
public $version = '1.3.0'; |
| 20 |
|
| 21 |
public $dci_name; |
| 22 |
public $dci_allow_name; |
| 23 |
public $dci_date_name; |
| 24 |
public $dci_count_name; |
| 25 |
public $nonce; |
| 26 |
public $params; |
| 27 |
public $text_domain; |
| 28 |
|
| 29 |
/** |
| 30 |
* Insights SDK Version |
| 31 |
* param array $params |
| 32 |
* @return void |
| 33 |
*/ |
| 34 |
public function __construct( $params ) { |
| 35 |
$this->params = $params; |
| 36 |
$this->text_domain = $params['text_domain']; |
| 37 |
|
| 38 |
add_action( 'wp_ajax_dci_sdk_insights', array( $this, 'dci_sdk_insights' ) ); |
| 39 |
add_action( 'wp_ajax_dci_sdk_dismiss_notice', array( $this, 'dci_sdk_dismiss_notice' ) ); |
| 40 |
add_action( 'wp_ajax_dci_sdk_insights_deactivate_feedback', array( $this, 'insights_deactivate_feedback' ) ); |
| 41 |
|
| 42 |
$security_key = md5( $params['plugin_name'] ); |
| 43 |
$this->dci_name = 'dci_' . str_replace( '-', '_', sanitize_title( $params['plugin_name'] ) . '_' . $security_key ); |
| 44 |
$this->dci_allow_name = 'dci_allow_status_' . $this->dci_name; |
| 45 |
$this->dci_date_name = 'dci_status_date_' . $this->dci_name; |
| 46 |
$dci_count_name = 'dci_attempt_count_' . $this->dci_name; |
| 47 |
$dci_status_db = get_option( $this->dci_allow_name, false ); |
| 48 |
|
| 49 |
$this->nonce = wp_create_nonce( $this->dci_allow_name ); |
| 50 |
|
| 51 |
/** |
| 52 |
* Deactivate Feedback |
| 53 |
* Visible only in plugins.php |
| 54 |
*/ |
| 55 |
$this->deactivation_feedback( $params ); |
| 56 |
|
| 57 |
/** |
| 58 |
* Modal Trigger if not init |
| 59 |
* Show Notice Modal |
| 60 |
*/ |
| 61 |
if ( ! $dci_status_db ) { |
| 62 |
$this->notice_modal( $params ); |
| 63 |
return; |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* If Disallow |
| 68 |
*/ |
| 69 |
if ( 'disallow' == $dci_status_db ) { |
| 70 |
return; |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Skip & Date Not Expired |
| 75 |
* Show Notice Modal |
| 76 |
*/ |
| 77 |
if ( 'skip' == $dci_status_db && true == $this->check_date() ) { |
| 78 |
$this->notice_modal( $params ); |
| 79 |
return; |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* Allowed & Date not Expired |
| 84 |
* No need send data to server |
| 85 |
* Else Send Data to Server |
| 86 |
*/ |
| 87 |
if ( ! $this->check_date() ) { |
| 88 |
return; |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Count attempt every time |
| 93 |
*/ |
| 94 |
$dci_attempt = get_option( $dci_count_name, 0 ); |
| 95 |
|
| 96 |
if ( ! $dci_attempt ) { |
| 97 |
update_option( $dci_count_name, 1 ); |
| 98 |
} |
| 99 |
update_option( $dci_count_name, $dci_attempt + 1 ); |
| 100 |
|
| 101 |
/** |
| 102 |
* Next schedule date for attempt |
| 103 |
*/ |
| 104 |
update_option( $this->dci_date_name, gmdate( 'Y-m-d', strtotime( "+1 month" ) ) ); |
| 105 |
|
| 106 |
/** |
| 107 |
* Prepare data |
| 108 |
*/ |
| 109 |
$this->data_prepare( $params ); |
| 110 |
} |
| 111 |
|
| 112 |
/** |
| 113 |
* Insights Deactivate Feedback |
| 114 |
*/ |
| 115 |
public function insights_deactivate_feedback() { |
| 116 |
$api_endpoint = isset( $_POST['api_endpoint'] ) ? sanitize_text_field( $_POST['api_endpoint'] ) : ''; |
| 117 |
$public_key = isset( $_POST['public_key'] ) ? sanitize_text_field( $_POST['public_key'] ) : ''; |
| 118 |
$product_id = isset( $_POST['product_id'] ) ? sanitize_text_field( $_POST['product_id'] ) : ''; |
| 119 |
$feedback = isset( $_POST['feedback'] ) ? sanitize_text_field( $_POST['feedback'] ) : ''; |
| 120 |
$nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( $_POST['nonce'] ) : ''; |
| 121 |
|
| 122 |
if ( ! wp_verify_nonce( $nonce, 'dci_sdk' ) ) { |
| 123 |
wp_send_json( array( |
| 124 |
'status' => 'error', |
| 125 |
'title' => 'Error', |
| 126 |
'message' => 'Nonce verification failed', |
| 127 |
) ); |
| 128 |
wp_die(); |
| 129 |
} |
| 130 |
|
| 131 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 132 |
wp_send_json( array( |
| 133 |
'status' => 'error', |
| 134 |
'title' => 'Error', |
| 135 |
'message' => 'Denied, you don\'t have right permission', |
| 136 |
) ); |
| 137 |
wp_die(); |
| 138 |
} |
| 139 |
|
| 140 |
$feedback = json_decode( stripslashes( $feedback ), true ); |
| 141 |
|
| 142 |
$data = array( |
| 143 |
'api_endpoint' => $api_endpoint, |
| 144 |
'public_key' => $public_key, |
| 145 |
'product_id' => $product_id, |
| 146 |
'feedback' => $feedback, |
| 147 |
); |
| 148 |
|
| 149 |
$this->data_prepare( $data ); |
| 150 |
|
| 151 |
wp_send_json( array( |
| 152 |
'status' => 'success', |
| 153 |
'title' => 'Success', |
| 154 |
'message' => 'Success.', |
| 155 |
) ); |
| 156 |
wp_die(); |
| 157 |
} |
| 158 |
|
| 159 |
/** |
| 160 |
* Notice Modal |
| 161 |
* |
| 162 |
* @return void |
| 163 |
*/ |
| 164 |
public function notice_modal( $params ) { |
| 165 |
|
| 166 |
$dci_data = array(); |
| 167 |
$dci_data['name'] = $this->dci_name; |
| 168 |
$dci_data['date_name'] = $this->dci_date_name; |
| 169 |
$dci_data['allow_name'] = $this->dci_allow_name; |
| 170 |
$dci_data['nonce'] = wp_create_nonce( 'dci_sdk' ); |
| 171 |
$dci_data['slug'] = $params['slug']; |
| 172 |
$dci_data['text_domain'] = $this->text_domain; |
| 173 |
|
| 174 |
add_action( 'admin_enqueue_scripts', array( $this, 'dci_enqueue_scripts' ) ); |
| 175 |
|
| 176 |
/** |
| 177 |
* If not current page |
| 178 |
* Show Notice Modal & Return |
| 179 |
*/ |
| 180 |
if ( $params['current_page'] !== $params['menu_slug'] ) { |
| 181 |
if ( ! get_transient( 'dismissed_notice_' . $this->dci_name ) ) { |
| 182 |
add_action( 'admin_notices', array( $this, 'display_global_notice' ) ); |
| 183 |
} |
| 184 |
return; |
| 185 |
} |
| 186 |
|
| 187 |
add_action( 'admin_notices', array( $this, 'display_global_notice' ) ); |
| 188 |
|
| 189 |
|
| 190 |
if ( isset( $params['popup_notice'] ) && true === $params['popup_notice'] ) { |
| 191 |
|
| 192 |
include_once dirname( __FILE__ ) . '/notice.php'; |
| 193 |
|
| 194 |
add_action( |
| 195 |
'in_admin_header', |
| 196 |
function () use ($dci_data) { |
| 197 |
if ( function_exists( 'dci_popup_notice' ) ) { |
| 198 |
dci_popup_notice( $dci_data ); |
| 199 |
} |
| 200 |
}, |
| 201 |
99999 |
| 202 |
); |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
/** |
| 207 |
* Deactivate Feedback |
| 208 |
* |
| 209 |
* @return void |
| 210 |
*/ |
| 211 |
public function deactivation_feedback( $params ) { |
| 212 |
$dci_data = array(); |
| 213 |
$dci_data['nonce'] = wp_create_nonce( 'dci_sdk' ); |
| 214 |
$dci_data['slug'] = $params['slug']; |
| 215 |
$dci_data['text_domain'] = $this->text_domain; |
| 216 |
$dci_data['api_endpoint'] = $params['api_endpoint']; |
| 217 |
$dci_data['public_key'] = $params['public_key']; |
| 218 |
$dci_data['product_id'] = $params['product_id']; |
| 219 |
|
| 220 |
add_action( 'admin_enqueue_scripts', array( $this, 'dci_enqueue_scripts' ) ); |
| 221 |
|
| 222 |
if ( isset( $params['deactivate_feedback'] ) && true === $params['deactivate_feedback'] ) { |
| 223 |
|
| 224 |
include_once dirname( __FILE__ ) . '/deactivate-feedback.php'; |
| 225 |
|
| 226 |
$current_screen = get_admin_page_parent(); |
| 227 |
|
| 228 |
if ( isset( $current_screen ) && ! empty( $current_screen ) && 'plugins.php' === $current_screen ) { |
| 229 |
add_action( |
| 230 |
'in_admin_header', |
| 231 |
function () use ($dci_data) { |
| 232 |
if ( function_exists( 'dci_deactivate_feedback' ) ) { |
| 233 |
dci_deactivate_feedback( $dci_data ); |
| 234 |
} |
| 235 |
}, |
| 236 |
99999 |
| 237 |
); |
| 238 |
} |
| 239 |
} |
| 240 |
} |
| 241 |
|
| 242 |
/** |
| 243 |
* If date is expired immidiate action |
| 244 |
* |
| 245 |
* @return boolean |
| 246 |
*/ |
| 247 |
public function check_date() { |
| 248 |
$current_date = strtotime( gmdate( 'Y-m-d' ) ); |
| 249 |
$dci_status_date = strtotime( get_option( $this->dci_date_name, false ) ); |
| 250 |
|
| 251 |
if ( ! $dci_status_date ) { |
| 252 |
return true; |
| 253 |
} |
| 254 |
|
| 255 |
if ( $dci_status_date && $current_date >= $dci_status_date ) { |
| 256 |
return true; |
| 257 |
} |
| 258 |
return false; |
| 259 |
} |
| 260 |
|
| 261 |
/** |
| 262 |
* Modal Trigger |
| 263 |
* |
| 264 |
* Not used |
| 265 |
* @return boolean |
| 266 |
*/ |
| 267 |
public function modal_trigger() { |
| 268 |
|
| 269 |
if ( ! wp_verify_nonce( $this->dci_allow_name, $this->nonce ) ) { |
| 270 |
echo 'Nonce Verification Failed'; |
| 271 |
return false; |
| 272 |
} |
| 273 |
|
| 274 |
$sanitized_status = sanitize_text_field( $_GET['dci_allow_status'] ); |
| 275 |
|
| 276 |
if ( $sanitized_status == 'skip' ) { |
| 277 |
update_option( $this->dci_allow_name, 'skip' ); |
| 278 |
/** |
| 279 |
* Next schedule date for attempt |
| 280 |
*/ |
| 281 |
update_option( $this->dci_date_name, gmdate( 'Y-m-d', strtotime( "+1 month" ) ) ); |
| 282 |
return false; |
| 283 |
} elseif ( $sanitized_status == 'yes' ) { |
| 284 |
update_option( $this->dci_allow_name, 'yes' ); |
| 285 |
return true; |
| 286 |
} |
| 287 |
|
| 288 |
return false; |
| 289 |
} |
| 290 |
|
| 291 |
/** |
| 292 |
* Reset Options Settings |
| 293 |
* @return void |
| 294 |
*/ |
| 295 |
public function reset_settings() { |
| 296 |
delete_option( $this->dci_allow_name ); |
| 297 |
delete_option( $this->dci_date_name ); |
| 298 |
} |
| 299 |
|
| 300 |
/** |
| 301 |
* Data prepare for send server |
| 302 |
* |
| 303 |
* @param array $server_url |
| 304 |
* @return void |
| 305 |
*/ |
| 306 |
public function data_prepare( $params ) { |
| 307 |
$server_url = isset( $params['api_endpoint'] ) ? $params['api_endpoint'] : false; |
| 308 |
$public_key = isset( $params['public_key'] ) ? $params['public_key'] : false; |
| 309 |
$custom_data = isset( $params['custom_data'] ) ? $params['custom_data'] : false; |
| 310 |
$product_id = isset( $params['product_id'] ) ? $params['product_id'] : false; |
| 311 |
|
| 312 |
if ( ! $server_url || ! $public_key ) { |
| 313 |
return; |
| 314 |
} |
| 315 |
|
| 316 |
/** |
| 317 |
* ================================== |
| 318 |
* |
| 319 |
* Start Own Custom Important Data |
| 320 |
* |
| 321 |
* ================================== |
| 322 |
*/ |
| 323 |
|
| 324 |
// $custom_data = array( |
| 325 |
// 'active_modules' => array(), |
| 326 |
// 'third_party' => array(), |
| 327 |
// 'extend' => array(), |
| 328 |
// 'other_settings' => array(), |
| 329 |
// ); |
| 330 |
|
| 331 |
// $custom_data = wp_json_encode($custom_data, true); |
| 332 |
|
| 333 |
/** |
| 334 |
* ================================== |
| 335 |
* |
| 336 |
* End Own Custom Important Data |
| 337 |
* |
| 338 |
* ================================== |
| 339 |
*/ |
| 340 |
|
| 341 |
$data = array(); |
| 342 |
$data['public_key'] = $public_key; |
| 343 |
$data['product_id'] = $product_id; |
| 344 |
$data['custom_data'] = $custom_data; |
| 345 |
|
| 346 |
if ( isset( $params['feedback'] ) && ! empty( $params['feedback'] ) ) { |
| 347 |
$data['feedback'] = $params['feedback']; |
| 348 |
} |
| 349 |
|
| 350 |
$non_sensitive_data = $this->dci_non_sensitve_data(); |
| 351 |
$data = array_merge( $data, $non_sensitive_data ); |
| 352 |
|
| 353 |
$this->dci_send_data_to_server( $server_url, $data ); |
| 354 |
} |
| 355 |
|
| 356 |
/** |
| 357 |
* Get the list of active and inactive plugins |
| 358 |
* |
| 359 |
* @return array |
| 360 |
*/ |
| 361 |
private function get_all_plugins() { |
| 362 |
// Ensure get_plugins function is loaded |
| 363 |
if ( ! function_exists( 'get_plugins' ) ) { |
| 364 |
include ABSPATH . '/wp-admin/includes/plugin.php'; |
| 365 |
} |
| 366 |
|
| 367 |
$plugins = get_plugins(); |
| 368 |
$active_plugins_keys = get_option( 'active_plugins', [] ); |
| 369 |
$active_plugins = []; |
| 370 |
|
| 371 |
foreach ( $plugins as $k => $v ) { |
| 372 |
// Take care of formatting the data how we want it. |
| 373 |
$formatted = []; |
| 374 |
$formatted['name'] = wp_strip_all_tags( $v['Name'] ); |
| 375 |
|
| 376 |
if ( isset( $v['Version'] ) ) { |
| 377 |
$formatted['version'] = wp_strip_all_tags( $v['Version'] ); |
| 378 |
} |
| 379 |
|
| 380 |
if ( isset( $v['Author'] ) ) { |
| 381 |
$formatted['author'] = wp_strip_all_tags( $v['Author'] ); |
| 382 |
} |
| 383 |
|
| 384 |
if ( isset( $v['Network'] ) ) { |
| 385 |
$formatted['network'] = wp_strip_all_tags( $v['Network'] ); |
| 386 |
} |
| 387 |
|
| 388 |
if ( isset( $v['PluginURI'] ) ) { |
| 389 |
$formatted['plugin_uri'] = wp_strip_all_tags( $v['PluginURI'] ); |
| 390 |
} |
| 391 |
|
| 392 |
if ( in_array( $k, $active_plugins_keys, true ) ) { |
| 393 |
// Remove active plugins from list so we can show active and inactive separately |
| 394 |
unset( $plugins[ $k ] ); |
| 395 |
$active_plugins[ $k ] = $formatted; |
| 396 |
} else { |
| 397 |
$plugins[ $k ] = $formatted; |
| 398 |
} |
| 399 |
} |
| 400 |
|
| 401 |
$plugins_data = []; |
| 402 |
foreach ( $active_plugins as $slug => $_plugin ) { |
| 403 |
$slug = strstr( $slug, '/', true ); |
| 404 |
|
| 405 |
if ( ! $slug ) { |
| 406 |
continue; |
| 407 |
} |
| 408 |
|
| 409 |
$plugins_data[ $slug ] = [ |
| 410 |
'name' => isset( $_plugin['name'] ) ? $_plugin['name'] : '', |
| 411 |
'version' => isset( $_plugin['version'] ) ? $_plugin['version'] : '', |
| 412 |
]; |
| 413 |
} |
| 414 |
|
| 415 |
return [ |
| 416 |
'active_plugins' => $active_plugins, |
| 417 |
'inactive_plugins' => $plugins, |
| 418 |
'plugins_data' => $plugins_data, |
| 419 |
]; |
| 420 |
} |
| 421 |
|
| 422 |
/** |
| 423 |
* Non sensitive data |
| 424 |
* |
| 425 |
* @return array |
| 426 |
*/ |
| 427 |
public function dci_non_sensitve_data() { |
| 428 |
$current_user = wp_get_current_user(); |
| 429 |
$all_plugins = $this->get_all_plugins(); |
| 430 |
|
| 431 |
$users = get_users( |
| 432 |
[ |
| 433 |
'role' => 'administrator', |
| 434 |
'orderby' => 'ID', |
| 435 |
'order' => 'ASC', |
| 436 |
'number' => 1, |
| 437 |
'paged' => 1, |
| 438 |
] |
| 439 |
); |
| 440 |
|
| 441 |
$admin_user = ( is_array( $users ) && ! empty( $users ) ) ? $users[0] : false; |
| 442 |
$first_name = $current_user->first_name; |
| 443 |
$last_name = $current_user->last_name; |
| 444 |
|
| 445 |
if ( empty( $first_name ) && empty( $last_name ) ) { |
| 446 |
$first_name = $current_user->display_name; |
| 447 |
$last_name = null; |
| 448 |
} |
| 449 |
|
| 450 |
if ( $admin_user ) { |
| 451 |
$first_name = $admin_user->first_name ? $admin_user->first_name : $admin_user->display_name; |
| 452 |
$last_name = $admin_user->last_name; |
| 453 |
} |
| 454 |
|
| 455 |
$theme = wp_get_theme( get_stylesheet() ); |
| 456 |
|
| 457 |
$data = array( |
| 458 |
'first_name' => $first_name, |
| 459 |
'last_name' => $last_name, |
| 460 |
'email' => get_option( 'admin_email' ), |
| 461 |
'user_role' => $current_user->roles[0], |
| 462 |
'website_url' => $current_user->user_url, |
| 463 |
'website_data' => array( |
| 464 |
'sdk_version' => $this->version, |
| 465 |
'website_name' => get_bloginfo( 'name' ), |
| 466 |
'wp_version' => get_bloginfo( 'version' ), |
| 467 |
'php_version' => phpversion(), |
| 468 |
'locale' => get_locale(), |
| 469 |
'wp_multisite' => is_multisite() ? 'Yes' : 'No', |
| 470 |
'wp_memory_limit' => defined( WP_MEMORY_LIMIT ) ? WP_MEMORY_LIMIT : false, |
| 471 |
'memory_limit' => ini_get( 'memory_limit' ), |
| 472 |
|
| 473 |
'inactive_plugins' => $all_plugins['inactive_plugins'], |
| 474 |
'active_plugins' => $all_plugins['active_plugins'], |
| 475 |
'active_plugins_count' => count( $all_plugins['active_plugins'] ), |
| 476 |
'inactive_plugins_count' => count( $all_plugins['inactive_plugins'] ), |
| 477 |
|
| 478 |
'theme_name' => $theme->get( 'Name' ), |
| 479 |
'theme_version' => $theme->get( 'Version' ), |
| 480 |
'theme_uri' => $theme->get( 'ThemeURI' ), |
| 481 |
'theme_author' => $theme->get( 'Author' ), |
| 482 |
), |
| 483 |
); |
| 484 |
|
| 485 |
return $data; |
| 486 |
} |
| 487 |
|
| 488 |
/** |
| 489 |
* Send data to server |
| 490 |
* |
| 491 |
* @param [string] $server_url |
| 492 |
* @param [array] $data |
| 493 |
* @return void |
| 494 |
*/ |
| 495 |
public function dci_send_data_to_server( $server_url, $data = null ) { |
| 496 |
|
| 497 |
$args = array( |
| 498 |
'method' => 'POST', |
| 499 |
'timeout' => 60, |
| 500 |
'headers' => array( |
| 501 |
'Content-Type' => 'application/json', |
| 502 |
'X-API-KEY' => $data['public_key'], |
| 503 |
), |
| 504 |
'body' => wp_json_encode( $data ), |
| 505 |
); |
| 506 |
|
| 507 |
// error_log( print_r( $args, true ) ); |
| 508 |
|
| 509 |
$response = wp_remote_request( $server_url, $args ); |
| 510 |
|
| 511 |
if ( is_wp_error( $response ) ) { |
| 512 |
// echo 'Error: ' . $response->get_error_message(); |
| 513 |
$this->reset_settings(); |
| 514 |
} else { |
| 515 |
$response_data = wp_remote_retrieve_body( $response ); |
| 516 |
$response_data = json_decode( $response_data, true ); |
| 517 |
// print_r( $response_data ); |
| 518 |
if ( isset( $response_data['data']['status'] ) && 401 == $response_data['data']['status'] ) { |
| 519 |
update_option( $this->dci_date_name, gmdate( 'Y-m-d', strtotime( "+3 days" ) ) ); |
| 520 |
} |
| 521 |
} |
| 522 |
} |
| 523 |
|
| 524 |
/** |
| 525 |
* Ajax callback |
| 526 |
*/ |
| 527 |
public function dci_sdk_insights() { |
| 528 |
$sanitized_status = isset( $_POST['button_val'] ) ? sanitize_text_field( $_POST['button_val'] ) : ''; |
| 529 |
$nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( $_POST['nonce'] ) : ''; |
| 530 |
$allow_name = isset( $_POST['allow_name'] ) ? sanitize_text_field( $_POST['allow_name'] ) : ''; |
| 531 |
$date_name = isset( $_POST['date_name'] ) ? sanitize_text_field( $_POST['date_name'] ) : ''; |
| 532 |
|
| 533 |
if ( ! wp_verify_nonce( $nonce, 'dci_sdk' ) ) { |
| 534 |
wp_send_json( array( |
| 535 |
'status' => 'error', |
| 536 |
'title' => 'Error', |
| 537 |
'message' => 'Nonce verification failed', |
| 538 |
) ); |
| 539 |
wp_die(); |
| 540 |
} |
| 541 |
|
| 542 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 543 |
wp_send_json( array( |
| 544 |
'status' => 'error', |
| 545 |
'title' => 'Error', |
| 546 |
'message' => 'Denied, you don\'t have right permission', |
| 547 |
) ); |
| 548 |
wp_die(); |
| 549 |
} |
| 550 |
|
| 551 |
if ( 'disallow' == $sanitized_status ) { |
| 552 |
update_option( $allow_name, 'disallow' ); |
| 553 |
} |
| 554 |
|
| 555 |
if ( $sanitized_status == 'skip' ) { |
| 556 |
update_option( $allow_name, 'skip' ); |
| 557 |
/** |
| 558 |
* Next schedule date for attempt |
| 559 |
*/ |
| 560 |
update_option( $date_name, gmdate( 'Y-m-d', strtotime( "+1 month" ) ) ); |
| 561 |
} elseif ( $sanitized_status == 'yes' ) { |
| 562 |
update_option( $allow_name, 'yes' ); |
| 563 |
} |
| 564 |
|
| 565 |
wp_send_json( array( |
| 566 |
'status' => 'success', |
| 567 |
'title' => 'Success', |
| 568 |
'message' => 'Success.', |
| 569 |
) ); |
| 570 |
wp_die(); |
| 571 |
} |
| 572 |
|
| 573 |
/** |
| 574 |
* Enqueue scripts and styles. |
| 575 |
* |
| 576 |
* @since 1.0.0 |
| 577 |
*/ |
| 578 |
public function dci_enqueue_scripts() { |
| 579 |
wp_enqueue_style( 'dci-sdk', plugins_url( 'assets/css/dci.css', __FILE__ ), array(), $this->version, 'all' ); |
| 580 |
wp_enqueue_script( 'dci-sdk', plugins_url( 'assets/js/dci.js', __FILE__ ), array( 'jquery' ), $this->version, true ); |
| 581 |
} |
| 582 |
|
| 583 |
/** |
| 584 |
* Display Global Notice |
| 585 |
* |
| 586 |
* @return void |
| 587 |
*/ |
| 588 |
public function display_global_notice() { |
| 589 |
$menu_slug = isset( $this->params['menu_slug'] ) ? $this->params['menu_slug'] : 'javascript:void(0);'; |
| 590 |
|
| 591 |
$admin_url = add_query_arg( array( |
| 592 |
'page' => $menu_slug, |
| 593 |
), admin_url( 'admin.php' ) ); |
| 594 |
|
| 595 |
$plugin_title = isset( $this->params['plugin_title'] ) ? $this->params['plugin_title'] : ''; |
| 596 |
$plugin_msg = isset( $this->params['plugin_msg'] ) ? $this->params['plugin_msg'] : ''; |
| 597 |
$plugin_icon = isset( $this->params['plugin_icon'] ) ? $this->params['plugin_icon'] : ''; |
| 598 |
|
| 599 |
?> |
| 600 |
<div |
| 601 |
class="dci-global-notice dci-notice-data notice notice-success is-dismissible <?php echo esc_attr( substr( $this->dci_name, 0, -33 ) ); ?>"> |
| 602 |
<div class="dci-global-header bdt-dci-notice-global-header"> |
| 603 |
<?php if ( ! empty( $plugin_icon ) ) : ?> |
| 604 |
<div class="bdt-dci-notice-logo"> |
| 605 |
<img src="<?php echo esc_url( $plugin_icon ); ?>" alt="icon"> |
| 606 |
</div> |
| 607 |
<?php endif; ?> |
| 608 |
<div class="bdt-dci-notice-content"> |
| 609 |
<h3> |
| 610 |
<?php printf( wp_kses_post( $plugin_title ) ); ?> |
| 611 |
</h3> |
| 612 |
<?php printf( wp_kses_post( $plugin_msg ) ); ?> |
| 613 |
<p> |
| 614 |
<a href="<?php echo esc_url( $admin_url ); ?>">Learn More</a>? |
| 615 |
</p> |
| 616 |
<input type="hidden" name="dci_name" value="<?php echo esc_html( $this->dci_name ); ?>"> |
| 617 |
<input type="hidden" name="dci_date_name" value="<?php echo esc_html( $this->dci_date_name ); ?>"> |
| 618 |
<input type="hidden" name="dci_allow_name" value="<?php echo esc_html( $this->dci_allow_name ); ?>"> |
| 619 |
<input type="hidden" name="nonce" value="<?php echo esc_html( wp_create_nonce( 'dci_sdk' ) ); ?>"> |
| 620 |
|
| 621 |
<div class="bdt-dci-notice-button-wrap"> |
| 622 |
<button name="dci_allow_status" value="yes" class="dci-button-allow"> |
| 623 |
Yes, I'd Love To Contribute |
| 624 |
</button> |
| 625 |
<button name="dci_allow_status" value="skip" class="dci-button-skip"> |
| 626 |
Skip For Now |
| 627 |
</button> |
| 628 |
<button name="dci_allow_status" value="disallow" class="dci-button-disallow dci-button-danger"> |
| 629 |
No Thanks |
| 630 |
</button> |
| 631 |
</div> |
| 632 |
</div> |
| 633 |
</div> |
| 634 |
|
| 635 |
</div> |
| 636 |
|
| 637 |
<?php |
| 638 |
} |
| 639 |
public function __display_global_notice() { |
| 640 |
$menu_slug = isset( $this->params['menu_slug'] ) ? $this->params['menu_slug'] : 'javascript:void(0);'; |
| 641 |
|
| 642 |
$admin_url = add_query_arg( array( |
| 643 |
'page' => $menu_slug, |
| 644 |
), admin_url( 'admin.php' ) ); |
| 645 |
|
| 646 |
$plugin_title = isset( $this->params['plugin_title'] ) ? $this->params['plugin_title'] : ''; |
| 647 |
$plugin_msg = isset( $this->params['plugin_msg'] ) ? $this->params['plugin_msg'] : ''; |
| 648 |
$plugin_icon = isset( $this->params['plugin_icon'] ) ? $this->params['plugin_icon'] : ''; |
| 649 |
|
| 650 |
?> |
| 651 |
<div class="dci-global-notice dci-notice-data notice notice-success is-dismissible"> |
| 652 |
<div class="dci-global-header"> |
| 653 |
<?php if ( ! empty( $plugin_icon ) ) : ?> |
| 654 |
<div> |
| 655 |
<img src="<?php echo esc_url( $plugin_icon ); ?>" alt="icon"> |
| 656 |
</div> |
| 657 |
<?php endif; ?> |
| 658 |
<h3> |
| 659 |
<?php printf( $plugin_title ); ?> |
| 660 |
</h3> |
| 661 |
</div> |
| 662 |
<?php printf( $plugin_msg ); ?> |
| 663 |
<p> |
| 664 |
What we <a href="<?php echo esc_url( $admin_url ); ?>">collect</a>? |
| 665 |
</p> |
| 666 |
<input type="hidden" name="dci_name" value="<?php echo esc_html( $this->dci_name ); ?>"> |
| 667 |
<input type="hidden" name="dci_date_name" value="<?php echo esc_html( $this->dci_date_name ); ?>"> |
| 668 |
<input type="hidden" name="dci_allow_name" value="<?php echo esc_html( $this->dci_allow_name ); ?>"> |
| 669 |
<input type="hidden" name="nonce" value="<?php echo esc_html( wp_create_nonce( 'dci_sdk' ) ); ?>"> |
| 670 |
<p> |
| 671 |
<button name="dci_allow_status" value="yes" class="button button-primary dci-button-allow"> |
| 672 |
Allow |
| 673 |
</button> |
| 674 |
<button name="dci_allow_status" value="skip" class="button dci-button-skip button-secondary"> |
| 675 |
I'll Skip For Now |
| 676 |
</button> |
| 677 |
<button name="dci_allow_status" value="disallow" class="button dci-button-disallow dci-button-danger"> |
| 678 |
Don't Allow |
| 679 |
</button> |
| 680 |
</p> |
| 681 |
</div> |
| 682 |
<?php |
| 683 |
} |
| 684 |
|
| 685 |
/** |
| 686 |
* Dismiss Notice |
| 687 |
* |
| 688 |
* @return void |
| 689 |
*/ |
| 690 |
public function dci_sdk_dismiss_notice() { |
| 691 |
$nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( $_POST['nonce'] ) : ''; |
| 692 |
$dci_name = isset( $_POST['dci_name'] ) ? sanitize_text_field( $_POST['dci_name'] ) : ''; |
| 693 |
|
| 694 |
if ( ! wp_verify_nonce( $nonce, 'dci_sdk' ) ) { |
| 695 |
wp_send_json( array( |
| 696 |
'status' => 'error', |
| 697 |
'title' => 'Error', |
| 698 |
'message' => 'Nonce verification failed', |
| 699 |
) ); |
| 700 |
wp_die(); |
| 701 |
} |
| 702 |
|
| 703 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 704 |
wp_send_json( array( |
| 705 |
'status' => 'error', |
| 706 |
'title' => 'Error', |
| 707 |
'message' => 'Denied, you don\'t have right permission', |
| 708 |
) ); |
| 709 |
wp_die(); |
| 710 |
} |
| 711 |
|
| 712 |
set_transient( 'dismissed_notice_' . $dci_name, true, 30 * DAY_IN_SECONDS ); |
| 713 |
|
| 714 |
wp_send_json( array( |
| 715 |
'status' => 'success', |
| 716 |
'title' => 'Success', |
| 717 |
'message' => 'Success.', |
| 718 |
) ); |
| 719 |
wp_die(); |
| 720 |
} |
| 721 |
} |
| 722 |
} |
| 723 |
|
| 724 |
/** |
| 725 |
* Main Insights Function |
| 726 |
*/ |
| 727 |
if ( ! function_exists( 'dci_sdk_insights' ) ) { |
| 728 |
function dci_sdk_insights( $params ) { |
| 729 |
if ( class_exists( 'Insights_SDK' ) ) { |
| 730 |
new Insights_SDK( $params ); |
| 731 |
} |
| 732 |
} |
| 733 |
} |
| 734 |
|