Changeset 3797653
- Timestamp:
- 11/12/2026 07:05:06 AM (4 days ago)
- Location:
- kipdesk
- Files:
-
- 4 added
- 3 edited
-
tags/1.1.0 (added)
-
tags/1.1.0/kipdesk.php (added)
-
tags/1.1.0/readme.txt (added)
-
tags/1.1.0/uninstall.php (added)
-
trunk/kipdesk.php (modified) (14 diffs)
-
trunk/readme.txt (modified) (5 diffs)
-
trunk/uninstall.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
kipdesk/trunk/kipdesk.php
r3795922 r3797653 3 3 * Plugin Name: KipDesk 4 4 * Description: Adds your KipDesk assistant to your site: it answers customers 24/7 from facts you approve and emails you every lead. Connect in one click. 5 * Version: 1. 0.05 * Version: 1.1.0 6 6 * Requires at least: 6.3 7 7 * Requires PHP: 7.4 … … 19 19 } 20 20 21 define( 'KIPDESK_VERSION', '1. 0.0' );21 define( 'KIPDESK_VERSION', '1.1.0' ); 22 22 23 23 /* … … 43 43 return add_query_arg( $args, admin_url( 'admin.php?page=kipdesk' ) ); 44 44 } 45 46 /** The line of code the plugin adds, for adding it by hand on sites where the plugin's way is blocked. */ 47 function kipdesk_snippet( $key ) { 48 return '<script src="' . kipdesk_app_url() . '/w.js" data-key="' . $key . '" defer></script>'; // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript -- shown as text in a box for the owner to copy; never printed as a tag (the plugin enqueues the script itself). 49 } 50 51 /* 52 * After connecting, disconnecting or changing where the chat shows, saved copies of pages (page 53 * caches) would keep showing the old version. Clears the caches of common caching plugins and 54 * hosts, when they're installed. Nothing happens for the ones that aren't. 55 */ 56 function kipdesk_purge_caches() { 57 delete_transient( 'kipdesk_check' ); 58 if ( function_exists( 'rocket_clean_domain' ) ) { 59 rocket_clean_domain(); // WP Rocket. 60 } 61 if ( function_exists( 'w3tc_flush_all' ) ) { 62 w3tc_flush_all(); // W3 Total Cache. 63 } 64 if ( function_exists( 'wp_cache_clear_cache' ) ) { 65 wp_cache_clear_cache(); // WP Super Cache. 66 } 67 if ( function_exists( 'sg_cachepress_purge_cache' ) ) { 68 sg_cachepress_purge_cache(); // SiteGround. 69 } 70 if ( function_exists( 'wpfc_clear_all_cache' ) ) { 71 wpfc_clear_all_cache( true ); // WP Fastest Cache. 72 } 73 if ( class_exists( 'autoptimizeCache' ) && method_exists( 'autoptimizeCache', 'clearall' ) ) { 74 autoptimizeCache::clearall(); // Autoptimize. 75 } 76 if ( class_exists( 'WpeCommon' ) ) { 77 if ( method_exists( 'WpeCommon', 'purge_memcached' ) ) { 78 WpeCommon::purge_memcached(); // WP Engine. 79 } 80 if ( method_exists( 'WpeCommon', 'purge_varnish_cache' ) ) { 81 WpeCommon::purge_varnish_cache(); 82 } 83 } 84 do_action( 'litespeed_purge_all' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- LiteSpeed Cache (also Hostinger): that plugin's own cache hook. 85 do_action( 'breeze_clear_all_cache' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Breeze (Cloudways): that plugin's own cache hook. 86 do_action( 'wphb_clear_page_cache' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Hummingbird: that plugin's own cache hook. 87 do_action( 'rt_nginx_helper_purge_all' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Nginx Helper: that plugin's own cache hook. 88 } 89 90 register_deactivation_hook( __FILE__, 'kipdesk_purge_caches' ); 45 91 46 92 /* ---------- Admin: menu, links, notice ---------- */ … … 137 183 update_option( 'kipdesk_name', substr( $name, 0, 120 ) ); 138 184 update_option( 'kipdesk_enabled', 1 ); 185 kipdesk_purge_caches(); 139 186 wp_safe_redirect( kipdesk_settings_url( array( 'kipdesk_done' => 'connected' ) ) ); 140 187 exit; … … 160 207 update_option( 'kipdesk_name', '' ); 161 208 update_option( 'kipdesk_enabled', 1 ); 209 kipdesk_purge_caches(); 162 210 wp_safe_redirect( kipdesk_settings_url( array( 'kipdesk_done' => 'connected' ) ) ); 163 211 exit; … … 180 228 } 181 229 update_option( 'kipdesk_hide', implode( "\n", $paths ) ); 230 kipdesk_purge_caches(); 182 231 wp_safe_redirect( kipdesk_settings_url( array( 'kipdesk_done' => 'saved' ) ) ); 183 232 exit; … … 192 241 delete_option( 'kipdesk_key' ); 193 242 delete_option( 'kipdesk_name' ); 243 kipdesk_purge_caches(); 194 244 wp_safe_redirect( kipdesk_settings_url( array( 'kipdesk_done' => 'disconnected' ) ) ); 195 245 exit; 246 } 247 248 /* "Check again" on the settings page. */ 249 add_action( 'admin_post_kipdesk_check', 'kipdesk_check_again' ); 250 function kipdesk_check_again() { 251 if ( ! current_user_can( 'manage_options' ) ) { 252 wp_die( esc_html__( 'You are not allowed to do that.', 'kipdesk' ) ); 253 } 254 check_admin_referer( 'kipdesk_check' ); 255 delete_transient( 'kipdesk_check' ); 256 wp_safe_redirect( kipdesk_settings_url() ); 257 exit; 258 } 259 260 /* 261 * Is the chat really on the site? Asks KipDesk whether the key's plan is active, then loads the 262 * home page the way a visitor would and looks for the chat code. If it's missing, loads it again 263 * with a one-off address, which skips most page caches: found then means an old saved copy is 264 * being shown. Remembered for 10 minutes. 265 */ 266 function kipdesk_check() { 267 $key = (string) get_option( 'kipdesk_key' ); 268 $cached = get_transient( 'kipdesk_check' ); 269 if ( is_array( $cached ) && isset( $cached['key'], $cached['status'] ) && $cached['key'] === $key ) { 270 return $cached['status']; 271 } 272 $status = kipdesk_run_check( $key ); 273 set_transient( 'kipdesk_check', array( 'key' => $key, 'status' => $status ), 10 * MINUTE_IN_SECONDS ); 274 return $status; 275 } 276 277 function kipdesk_run_check( $key ) { 278 $res = wp_remote_get( kipdesk_app_url() . '/api/widget/' . rawurlencode( $key ), array( 'timeout' => 5 ) ); 279 if ( ! is_wp_error( $res ) ) { 280 $code = (int) wp_remote_retrieve_response_code( $res ); 281 $body = json_decode( (string) wp_remote_retrieve_body( $res ), true ); 282 if ( 404 === $code ) { 283 return 'unknown_key'; 284 } 285 if ( 200 === $code && is_array( $body ) && empty( $body['active'] ) ) { 286 return 'inactive'; 287 } 288 } 289 if ( ! get_option( 'kipdesk_enabled', 1 ) ) { 290 return 'off'; 291 } 292 if ( ! kipdesk_shows_on( '/' ) ) { 293 return 'hidden_home'; 294 } 295 $home = home_url( '/' ); 296 $found = kipdesk_page_has( $home, $key ); 297 if ( true === $found ) { 298 return 'ok'; 299 } 300 $fresh = kipdesk_page_has( add_query_arg( 'kipdesk_check', wp_generate_password( 10, false, false ), $home ), $key ); 301 if ( true === $fresh ) { 302 return 'cached'; 303 } 304 return ( null === $found || null === $fresh ) ? 'no_check' : 'missing'; 305 } 306 307 /** True if the page has the chat code, false if not, null if it couldn't be loaded. */ 308 function kipdesk_page_has( $url, $key ) { 309 $res = wp_remote_get( 310 $url, 311 array( 312 'timeout' => 6, 313 'redirection' => 3, 314 'sslverify' => apply_filters( 'https_local_ssl_verify', false ), // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WordPress core's own filter for requests to this site. 315 ) 316 ); 317 if ( is_wp_error( $res ) ) { 318 return null; 319 } 320 $code = (int) wp_remote_retrieve_response_code( $res ); 321 if ( $code < 200 || $code >= 300 ) { 322 return null; 323 } 324 return false !== strpos( (string) wp_remote_retrieve_body( $res ), $key ); 196 325 } 197 326 … … 247 376 <div class="card kipdesk-card"> 248 377 <h2><?php esc_html_e( 'Add your AI assistant to this site', 'kipdesk' ); ?></h2> 249 <p><?php esc_html_e( 'KipDesk answers your customers 24/7 from facts you approve, says when it doesn\'t know, and emails you every lead. Connect this site to your KipDesk account, or start a 7-day free trial (no card needed).', 'kipdesk' ); ?></p> 378 <p><?php esc_html_e( 'KipDesk answers your customers 24/7 from facts you approve, says when it doesn\'t know, and emails you every lead.', 'kipdesk' ); ?></p> 379 <ol class="kipdesk-steps"> 380 <li><?php esc_html_e( 'Click Connect to KipDesk below. It opens kipdesk.com.', 'kipdesk' ); ?></li> 381 <li><?php esc_html_e( 'Sign in, or start your 7-day free trial (no card needed).', 'kipdesk' ); ?></li> 382 <li><?php esc_html_e( 'Choose the website to connect and click Connect.', 'kipdesk' ); ?></li> 383 <li><?php esc_html_e( 'You\'re brought back here, and the chat button appears in the corner of your site.', 'kipdesk' ); ?></li> 384 </ol> 250 385 <form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>"> 251 386 <input type="hidden" name="action" value="kipdesk_connect" /> … … 253 388 <?php submit_button( __( 'Connect to KipDesk', 'kipdesk' ), 'primary large', 'submit', false ); ?> 254 389 </form> 255 <p class="description"><?php esc_html_e( 'Opens kipdesk.com, where you sign in or start your trial, then brings you back here.', 'kipdesk' ); ?></p>256 390 </div> 257 391 258 392 <details class="kipdesk-manual"> 259 <summary><?php esc_html_e( 'Or paste your key', 'kipdesk' ); ?></summary> 393 <summary><?php esc_html_e( 'Connect didn\'t work? Paste your code instead', 'kipdesk' ); ?></summary> 394 <ol class="kipdesk-steps"> 395 <li> 396 <?php 397 echo wp_kses( 398 sprintf( 399 /* translators: %s: link to the KipDesk dashboard */ 400 esc_html__( 'Open %s and go to Add to your website.', 'kipdesk' ), 401 '<a href="' . esc_url( $app . '/dashboard/install' ) . '" target="_blank" rel="noopener noreferrer">' . esc_html__( 'your KipDesk dashboard', 'kipdesk' ) . '</a>' 402 ), 403 array( 404 'a' => array( 405 'href' => true, 406 'target' => true, 407 'rel' => true, 408 ), 409 ) 410 ); 411 ?> 412 </li> 413 <li><?php esc_html_e( 'Under Your website code, click Copy.', 'kipdesk' ); ?></li> 414 <li><?php esc_html_e( 'Paste it below and click Save. Check that this site\'s address is listed under Where it can appear on that page.', 'kipdesk' ); ?></li> 415 </ol> 260 416 <form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>"> 261 417 <input type="hidden" name="action" value="kipdesk_save_key" /> 262 418 <?php wp_nonce_field( 'kipdesk_save_key' ); ?> 263 419 <p> 264 <label for="kipdesk_key"><?php esc_html_e( 'Your key or line of code, from KipDesk → Add to your website', 'kipdesk' ); ?></label><br />420 <label for="kipdesk_key"><?php esc_html_e( 'Your line of code (or just the key, starting with wk_)', 'kipdesk' ); ?></label><br /> 265 421 <input type="text" id="kipdesk_key" name="kipdesk_key" class="regular-text code" placeholder="wk_..." autocomplete="off" /> 266 422 </p> 267 <?php submit_button( __( 'Save key', 'kipdesk' ), 'secondary', 'submit', false ); ?>423 <?php submit_button( __( 'Save', 'kipdesk' ), 'secondary', 'submit', false ); ?> 268 424 </form> 269 425 </details> … … 283 439 <p class="description"><?php esc_html_e( 'Key:', 'kipdesk' ); ?> <code><?php echo esc_html( $key ); ?></code></p> 284 440 </div> 441 442 <?php 443 $check = kipdesk_check(); 444 $results = array( 445 'ok' => array( 'success', __( 'The chat is on your site. Open your site and look for the chat button in the corner. (Still not seeing it? Try a private window.)', 'kipdesk' ) ), 446 'cached' => array( 'warning', __( 'Your site is still showing an old saved copy of its pages (a cache), so visitors don\'t see the chat yet. Clear the cache in your caching plugin or your hosting control panel, then click Check again.', 'kipdesk' ) ), 447 'missing' => array( 'error', __( 'The chat code isn\'t reaching your pages. Something on your site (often the theme, a page builder or a speed plugin) is removing it. Add the code to your site\'s header yourself: see the steps below.', 'kipdesk' ) ), 448 'inactive' => array( 'error', __( 'Your KipDesk plan isn\'t active (for example, the free trial has ended), so the chat is hidden. Open your KipDesk dashboard to choose a plan.', 'kipdesk' ) ), 449 'unknown_key' => array( 'error', __( 'KipDesk doesn\'t recognise this key. Disconnect at the bottom of this page, then connect again.', 'kipdesk' ) ), 450 'off' => array( 'info', __( 'The chat is switched off. Tick Show the chat button on my site below to turn it on.', 'kipdesk' ) ), 451 'hidden_home' => array( 'info', __( 'The chat is hidden on your home page, so it couldn\'t be checked. Open a page where it should show.', 'kipdesk' ) ), 452 'no_check' => array( 'info', __( 'Your site couldn\'t be checked from here (some hosts block this). Open your site in a private window and look for the chat button in the corner. Not there? Add the code to your header yourself: see the steps below.', 'kipdesk' ) ), 453 ); 454 $result = isset( $results[ $check ] ) ? $results[ $check ] : $results['no_check']; 455 ?> 456 <div class="notice notice-<?php echo esc_attr( $result[0] ); ?> inline kipdesk-check"> 457 <p> 458 <strong><?php esc_html_e( 'Is the chat on your site?', 'kipdesk' ); ?></strong> 459 <?php echo esc_html( $result[1] ); ?> 460 </p> 461 <form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>"> 462 <input type="hidden" name="action" value="kipdesk_check" /> 463 <?php wp_nonce_field( 'kipdesk_check' ); ?> 464 <?php submit_button( __( 'Check again', 'kipdesk' ), 'secondary small', 'submit', false ); ?> 465 </form> 466 </div> 467 468 <details class="kipdesk-manual" <?php echo in_array( $check, array( 'missing', 'no_check' ), true ) ? 'open' : ''; ?>> 469 <summary><?php esc_html_e( 'Chat not showing? Add the code to your header yourself', 'kipdesk' ); ?></summary> 470 <ol class="kipdesk-steps"> 471 <li> 472 <?php esc_html_e( 'Copy this line of code:', 'kipdesk' ); ?><br /> 473 <textarea class="large-text code kipdesk-code" rows="2" readonly onclick="this.select()"><?php echo esc_textarea( kipdesk_snippet( $key ) ); ?></textarea> 474 </li> 475 <li><?php esc_html_e( 'Paste it into your site\'s header. Many themes have a setting for this (look for Custom code, Header scripts or Code injection). If yours doesn\'t, install a free header and footer code plugin such as WPCode and paste it in its Header box.', 'kipdesk' ); ?></li> 476 <li><?php esc_html_e( 'Save, clear your cache if you use a caching plugin, and open your site. You can keep this plugin installed: the chat won\'t show twice.', 'kipdesk' ); ?></li> 477 </ol> 478 </details> 285 479 286 480 <h2><?php esc_html_e( 'Where the chat shows', 'kipdesk' ); ?></h2> … … 322 516 wp_register_style( 'kipdesk-admin', false, array(), KIPDESK_VERSION ); 323 517 wp_enqueue_style( 'kipdesk-admin' ); 324 wp_add_inline_style( 'kipdesk-admin', '.kipdesk-card{max-width:640px;padding:8px 20px 16px}.kipdesk-card h2{margin-top:12px}.kipdesk-manual{margin-top:20px;max-width:640px}.kipdesk-manual summary{cursor:pointer;color:#2271b1}.kipdesk- disconnect{margin-top:24px}.kipdesk-disconnect .button-link-delete{margin-right:8px}' );518 wp_add_inline_style( 'kipdesk-admin', '.kipdesk-card{max-width:640px;padding:8px 20px 16px}.kipdesk-card h2{margin-top:12px}.kipdesk-manual{margin-top:20px;max-width:640px}.kipdesk-manual summary{cursor:pointer;color:#2271b1}.kipdesk-steps{margin-left:1.4em}.kipdesk-steps li{margin-bottom:6px}.kipdesk-check{max-width:640px;margin:20px 0 0;padding:4px 12px 10px}.kipdesk-code{margin-top:6px;font-size:12px}.kipdesk-disconnect{margin-top:24px}.kipdesk-disconnect .button-link-delete{margin-right:8px}' ); 325 519 } 326 520 … … 332 526 return false; 333 527 } 528 $uri = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '/'; 529 return kipdesk_shows_on( $uri ); 530 } 531 532 /** Whether the chat shows on this page address, going by the "Hide on these pages" list. */ 533 function kipdesk_shows_on( $uri ) { 334 534 $hide = trim( (string) get_option( 'kipdesk_hide', '' ) ); 335 535 if ( '' === $hide ) { 336 536 return true; 337 537 } 338 $uri = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '/';339 538 $path = kipdesk_clean_path( $uri ); 340 539 $path = '' === $path ? '/' : $path; … … 356 555 return; 357 556 } 358 // The KipDesk widget loader: small, loads after the page, and only fetches the chat window when opened. 359 wp_enqueue_script( 'kipdesk-widget', kipdesk_app_url() . '/w.js', array(), null, array( 'strategy' => 'defer', 'in_footer' => true ) ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion -- the service serves its current loader. 360 } 361 362 /* The loader reads the key from its own script tag. */ 557 // The KipDesk widget loader: small, loads after the page, and only fetches the chat window when 558 // opened. In the head (deferred, so it doesn't hold the page up): some themes and page builders 559 // leave out the footer hook. 560 wp_enqueue_script( 'kipdesk-widget', kipdesk_app_url() . '/w.js', array(), null, array( 'strategy' => 'defer', 'in_footer' => false ) ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion -- the service serves its current loader. 561 } 562 563 /* 564 * The loader reads the key from its own script tag. The other attributes ask speed plugins to 565 * leave it as it is (it's already deferred): Cloudflare Rocket Loader, LiteSpeed and WP Rocket. 566 */ 363 567 add_filter( 'script_loader_tag', 'kipdesk_script_tag', 10, 2 ); 364 568 function kipdesk_script_tag( $tag, $handle ) { … … 366 570 return $tag; 367 571 } 368 return str_replace( ' src=', ' data-key="' . esc_attr( get_option( 'kipdesk_key' ) ) . '" src=', $tag ); 369 } 572 return str_replace( ' src=', ' data-key="' . esc_attr( get_option( 'kipdesk_key' ) ) . '" data-cfasync="false" data-no-optimize="1" data-no-defer="1" nowprocket src=', $tag ); 573 } 574 575 /* Speed plugins that delay scripts until the visitor scrolls or taps: leave the chat out of it. */ 576 add_filter( 'rocket_delay_js_exclusions', 'kipdesk_delay_exclusions' ); 577 add_filter( 'perfmatters_delay_js_exclusions', 'kipdesk_delay_exclusions' ); 578 function kipdesk_delay_exclusions( $exclusions ) { 579 $exclusions = is_array( $exclusions ) ? $exclusions : array(); 580 $exclusions[] = 'kipdesk.com/w.js'; 581 return $exclusions; 582 } -
kipdesk/trunk/readme.txt
r3795922 r3797653 5 5 Tested up to: 7.1 6 6 Requires PHP: 7.4 7 Stable tag: 1. 0.07 Stable tag: 1.1.0 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 32 32 2. Go to **KipDesk** in your WordPress menu and click **Connect to KipDesk**. 33 33 3. Sign in, or start a 7-day free trial (no card needed). KipDesk reads your website and shows you what it learned. 34 4. You're sent back to WordPress, connected. The chat button appears on your site. 34 4. You're sent back to WordPress, connected. The chat button appears on your site, and the KipDesk page in WordPress checks that it's really showing. 35 36 If Connect doesn't work on your site, the KipDesk page shows you how to paste your code instead. 35 37 36 38 You manage everything else (what your assistant knows, how it looks, leads and chats) in your KipDesk dashboard. … … 56 58 2. Open **KipDesk** in the menu and click **Connect to KipDesk**. 57 59 58 Prefer not to connect this way? In KipDesk, open **Add to your website**, copy your key (it starts with `wk_`), and paste it under **Or paste your key**.60 Connect didn't work? In KipDesk, open **Add to your website**, copy the line under **Your website code**, and paste it under **Connect didn't work? Paste your code instead**. 59 61 60 62 == Frequently Asked Questions == … … 78 80 = Does it work with page builders and caching plugins? = 79 81 80 Yes. The plugin adds the script through WordPress itself, so it works with Elementor, the block editor, classic themes and caching plugins. If a caching plugin combines or delays scripts, exclude `kipdesk.com/w.js`. 82 Yes. The plugin adds the script through WordPress itself, so it works with Elementor, the block editor and classic themes. It asks speed plugins (WP Rocket, LiteSpeed, Perfmatters, Cloudflare Rocket Loader) not to delay it, and clears common page caches when you connect or change settings. 83 84 = I connected, but the chat doesn't show = 85 86 Open **KipDesk** in your WordPress menu. It checks your site and tells you what's wrong: an old cached copy of your pages (clear your cache), a plan that isn't active, or something on your site removing the code. In that last case, it shows you the line of code to paste into your site's header yourself. 81 87 82 88 = What happens if I disconnect or delete the plugin? = … … 93 99 == Changelog == 94 100 101 = 1.1.0 = 102 * Checks that the chat is really on your site, and says what to do if it isn't. 103 * Shows the line of code to add to your header by hand, for sites where the plugin's way is blocked. 104 * Clears common page caches when you connect, disconnect or change settings. 105 * Asks speed plugins (WP Rocket, LiteSpeed, Perfmatters, Cloudflare Rocket Loader) not to delay the chat. 106 * Adds the chat script in the page head, for themes and page builders without a footer. 107 * Clearer connect steps. 108 95 109 = 1.0.0 = 96 110 * First release: connect in one click, or paste your key; show the chat on every page; hide it on chosen pages. -
kipdesk/trunk/uninstall.php
r3795922 r3797653 13 13 delete_option( $kipdesk_option ); 14 14 } 15 delete_transient( 'kipdesk_check' );
Note:
See TracChangeset
for help on using the changeset viewer.