Embedpress_Elementor_Integration.php
831 lines
| 1 | <?php |
| 2 | |
| 3 | namespace EmbedPress\Elementor; |
| 4 | |
| 5 | |
| 6 | (defined('ABSPATH')) or die("No direct script access allowed."); |
| 7 | |
| 8 | use EmbedPress\Compatibility; |
| 9 | use EmbedPress\Elementor\Widgets\Embedpress_Calendar; |
| 10 | use EmbedPress\Elementor\Widgets\Embedpress_Document; |
| 11 | use EmbedPress\Elementor\Widgets\Embedpress_Elementor; |
| 12 | use EmbedPress\Elementor\Widgets\Embedpress_Pdf; |
| 13 | use EmbedPress\Includes\Classes\Helper; |
| 14 | |
| 15 | class Embedpress_Elementor_Integration |
| 16 | { |
| 17 | |
| 18 | /** |
| 19 | * @since 2.4.2 |
| 20 | */ |
| 21 | public function init() |
| 22 | { |
| 23 | $elements = (array) get_option(EMBEDPRESS_PLG_NAME . ":elements", []); |
| 24 | $e_blocks = isset($elements['elementor']) ? (array) $elements['elementor'] : []; |
| 25 | if (!empty($e_blocks['embedpress']) || !empty($e_blocks['embedpress-document']) || !empty($e_blocks['embedpress-pdf'])) { |
| 26 | add_action('elementor/frontend/after_enqueue_styles', [$this, 'embedpress_enqueue_style']); |
| 27 | add_action('elementor/editor/before_enqueue_styles', array($this, 'editor_enqueue_style')); |
| 28 | add_action('elementor/editor/before_enqueue_scripts', array($this, 'editor_enqueue_scripts')); |
| 29 | add_action('elementor/elements/categories_registered', array($this, 'register_widget_categories')); |
| 30 | add_action('elementor/widgets/widgets_registered', array($this, 'register_widget')); |
| 31 | add_action('elementor/widgets/register', array($this, 'register_widget')); |
| 32 | add_filter('oembed_providers', [$this, 'addOEmbedProviders']); |
| 33 | |
| 34 | if (Helper::get_options_value('turn_off_rating_help') || !is_plugin_active('embedpress-pro/embedpress-pro.php')) { |
| 35 | add_action('elementor/editor/after_enqueue_scripts', [$this, 'elementor_upsale']); |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Add elementor category |
| 42 | * |
| 43 | * @since 2.4.3 |
| 44 | */ |
| 45 | public function register_widget_categories($elements_manager) |
| 46 | { |
| 47 | $elements_manager->add_category( |
| 48 | 'embedpress', |
| 49 | [ |
| 50 | 'title' => __('EmbedPress', 'embedpress'), |
| 51 | 'icon' => 'font', |
| 52 | ], |
| 53 | 1 |
| 54 | ); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Load elementor widget |
| 59 | * |
| 60 | * @param $widgets_manager |
| 61 | * @throws \Exception |
| 62 | * @since 2.4.2 |
| 63 | */ |
| 64 | public function register_widget($widgets_manager) |
| 65 | { |
| 66 | if ( |
| 67 | did_action('elementor/widgets/widgets_registered') && |
| 68 | did_action('elementor/widgets/register') // doing action |
| 69 | ) { |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | $elements = (array) get_option(EMBEDPRESS_PLG_NAME . ":elements", []); |
| 74 | $e_blocks = isset($elements['elementor']) ? (array) $elements['elementor'] : []; |
| 75 | |
| 76 | if (method_exists($widgets_manager, 'register')) { |
| 77 | if (!empty($e_blocks['embedpress'])) { |
| 78 | $widgets_manager->register(new Embedpress_Elementor); |
| 79 | } |
| 80 | if (!empty($e_blocks['embedpress-document'])) { |
| 81 | $widgets_manager->register(new Embedpress_Document); |
| 82 | } |
| 83 | |
| 84 | if (!empty($e_blocks['embedpress-pdf'])) { |
| 85 | $widgets_manager->register(new Embedpress_Pdf); |
| 86 | } |
| 87 | if (!empty($e_blocks['embedpress-calendar'])) { |
| 88 | $widgets_manager->register(new Embedpress_Calendar); |
| 89 | } |
| 90 | } else { |
| 91 | if (!empty($e_blocks['embedpress'])) { |
| 92 | $widgets_manager->register_widget_type(new Embedpress_Elementor); |
| 93 | } |
| 94 | if (!empty($e_blocks['embedpress-document'])) { |
| 95 | $widgets_manager->register_widget_type(new Embedpress_Document); |
| 96 | } |
| 97 | |
| 98 | if (!empty($e_blocks['embedpress-pdf'])) { |
| 99 | $widgets_manager->register_widget_type(new Embedpress_Pdf); |
| 100 | } |
| 101 | if (!empty($e_blocks['embedpress-calendar'])) { |
| 102 | $widgets_manager->register_widget_type(new Embedpress_Calendar); |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Enqueue elementor assets |
| 109 | * @since 2.4.3 |
| 110 | */ |
| 111 | public function embedpress_enqueue_style() |
| 112 | { |
| 113 | wp_register_style( |
| 114 | 'embedpress-elementor-css', |
| 115 | EMBEDPRESS_URL_ASSETS . 'css/embedpress-elementor.css', |
| 116 | false, |
| 117 | EMBEDPRESS_VERSION |
| 118 | ); |
| 119 | } |
| 120 | |
| 121 | public function editor_enqueue_style() |
| 122 | { |
| 123 | wp_enqueue_style( |
| 124 | 'embedpress-el-icon', |
| 125 | EMBEDPRESS_URL_ASSETS . 'css/el-icon.css', |
| 126 | false, |
| 127 | EMBEDPRESS_VERSION |
| 128 | ); |
| 129 | } |
| 130 | |
| 131 | public function editor_enqueue_scripts() |
| 132 | { } |
| 133 | |
| 134 | public function addOEmbedProviders($providers) |
| 135 | { |
| 136 | if (Compatibility::isWordPress5() && !Compatibility::isClassicalEditorActive()) { |
| 137 | unset($providers['#https?://(.+\.)?wistia\.com/medias/.+#i'], $providers['#https?://(.+\.)?fast\.wistia\.com/embed/medias/.+#i\.jsonp']); |
| 138 | } |
| 139 | |
| 140 | return $providers; |
| 141 | } |
| 142 | |
| 143 | public function elementor_upsale() |
| 144 | { |
| 145 | ?> |
| 146 | <style> |
| 147 | :root { |
| 148 | /* Light Mode Variables */ |
| 149 | --background-color: #FDFAFF; |
| 150 | --text-color: #0C0D0E; |
| 151 | --secondary-text-color: #5f6c7f; |
| 152 | --description-text-color: #5f6c7f; |
| 153 | --border-color: #ECEFF5; |
| 154 | --button-bg: #5b4e96; |
| 155 | --button-text: #ffffff; |
| 156 | --upgrade-bg: linear-gradient(181.32deg, #fffbf8 1.12%, #ffffff 98.95%); |
| 157 | --star-color: #b1b8c2; |
| 158 | --placeholder-text-color: #5f6c7f; |
| 159 | --submit-button-color: #5b4e96; |
| 160 | --form-control-backgound: #fff; |
| 161 | --upgrade-box-title-color: #1d2939; |
| 162 | } |
| 163 | |
| 164 | @media (prefers-color-scheme: light) { |
| 165 | :root { |
| 166 | /* Light Mode Variables */ |
| 167 | --background-color: #FDFAFF; |
| 168 | --text-color: #0C0D0E; |
| 169 | --secondary-text-color: #5f6c7f; |
| 170 | --description-text-color: #5f6c7f; |
| 171 | --border-color: #ECEFF5; |
| 172 | --button-bg: #5b4e96; |
| 173 | --button-text: #ffffff; |
| 174 | --upgrade-bg: linear-gradient(181.32deg, #fffbf8 1.12%, #ffffff 98.95%); |
| 175 | --star-color: #b1b8c2; |
| 176 | --placeholder-text-color: #5f6c7f; |
| 177 | --submit-button-color: #5b4e96; |
| 178 | --form-control-backgound: #fff; |
| 179 | --upgrade-box-title-color: #1d2939; |
| 180 | |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | @media (prefers-color-scheme: dark) { |
| 185 | :root { |
| 186 | /* Dark Mode Variables */ |
| 187 | --background-color: #1A1C1F; |
| 188 | --text-color: #ffffff; |
| 189 | --secondary-text-color: #CBCBD0; |
| 190 | --description-text-color: #fff; |
| 191 | --border-color: #272A2F; |
| 192 | --button-bg: #4b3293; |
| 193 | --button-text: #ffffff; |
| 194 | --upgrade-bg: linear-gradient(181.32deg, #1F2023 1.12%, #18191B 98.95%); |
| 195 | --star-color: #676D76; |
| 196 | --placeholder-text-color: #CBCBD0; |
| 197 | --submit-button-color: #fff; |
| 198 | --form-control-backgound: #1F2124; |
| 199 | --upgrade-box-title-color: #fff; |
| 200 | |
| 201 | |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | .elementor-panel .plugin-rating { |
| 206 | border-top: 2px solid #e6e8ea; |
| 207 | } |
| 208 | |
| 209 | /* Applying Variables */ |
| 210 | .elementor-panel .rating-chat-content { |
| 211 | background-color: var(--background-color); |
| 212 | border: 0.6px solid var(--border-color); |
| 213 | color: var(--text-color); |
| 214 | } |
| 215 | |
| 216 | .elementor-panel .plugin-rating h4 { |
| 217 | color: var(--text-color); |
| 218 | } |
| 219 | |
| 220 | .elementor-panel .plugin-rating .chat-button { |
| 221 | background-color: var(--button-bg); |
| 222 | color: var(--button-text); |
| 223 | } |
| 224 | |
| 225 | .elementor-panel .plugin-rating .upgrade-box { |
| 226 | background: var(--upgrade-bg); |
| 227 | border: 0.6px solid var(--border-color); |
| 228 | } |
| 229 | |
| 230 | .elementor-panel p.thank-you-message { |
| 231 | color: var(--secondary-text-color); |
| 232 | } |
| 233 | |
| 234 | .elementor-panel .plugin-rating .stars .star { |
| 235 | color: var(--star-color); |
| 236 | } |
| 237 | |
| 238 | |
| 239 | .elementor-panel .plugin-rating { |
| 240 | font-family: system-ui; |
| 241 | padding: 15px; |
| 242 | padding-top: 0; |
| 243 | } |
| 244 | |
| 245 | .elementor-panel .rating-chat-content { |
| 246 | border-radius: 4px; |
| 247 | border-width: 0.6px; |
| 248 | gap: 12px; |
| 249 | padding: 15px; |
| 250 | position: relative; |
| 251 | display: flex; |
| 252 | flex-direction: column; |
| 253 | overflow: hidden; |
| 254 | margin-top: 15px; |
| 255 | } |
| 256 | |
| 257 | .rating-chat-content::after { |
| 258 | content: ""; |
| 259 | position: absolute; |
| 260 | top: -65px; |
| 261 | right: -65px; |
| 262 | width: 120px; |
| 263 | height: 120px; |
| 264 | background: radial-gradient(circle, rgb(121 62 255 / 14%) 20%, transparent 70%); |
| 265 | border-radius: 50%; |
| 266 | } |
| 267 | |
| 268 | |
| 269 | /* .rating-chat-content::after{ |
| 270 | content: ''; |
| 271 | background: linear-gradient(175.54deg, rgba(81, 241, 255, 0.117) 19.13%, rgba(71, 58, 217, 0.132319) 22.57%, rgba(127, 22, 255, 0.2085) 39.66%, rgba(17, 1, 35, 0.3) 60.19%); |
| 272 | transform: rotate(60deg); |
| 273 | top: 0; |
| 274 | right: 0; |
| 275 | z-index: 1212; |
| 276 | width: 118.63550843535211px; |
| 277 | height: 208.14842708207777px; |
| 278 | position: absolute; |
| 279 | transform: rotate(60deg); |
| 280 | backdrop-filter: blur(20px); |
| 281 | } */ |
| 282 | |
| 283 | |
| 284 | .elementor-panel .plugin-rating h4 { |
| 285 | font-size: 15px; |
| 286 | font-weight: 500; |
| 287 | } |
| 288 | |
| 289 | .elementor-panel .plugin-rating .stars { |
| 290 | display: flex; |
| 291 | gap: 5px; |
| 292 | margin-bottom: 10px; |
| 293 | color: #FFFFFF; |
| 294 | } |
| 295 | |
| 296 | .elementor-panel .plugin-rating .stars .star { |
| 297 | cursor: pointer; |
| 298 | width: 20px; |
| 299 | height: 20px; |
| 300 | } |
| 301 | |
| 302 | .elementor-panel .plugin-rating .thank-you-msg-container { |
| 303 | padding: 15px; |
| 304 | border-radius: 8px; |
| 305 | text-align: left; |
| 306 | background: linear-gradient(181.32deg, #f5f3ff 1.12%, #ffffff 98.95%); |
| 307 | border: 0.6px solid #f4efec; |
| 308 | position: relative; |
| 309 | } |
| 310 | |
| 311 | .elementor-panel .plugin-rating .thank-you-msg-container span.close-icon { |
| 312 | position: absolute; |
| 313 | top: 8px; |
| 314 | right: 8px; |
| 315 | } |
| 316 | |
| 317 | .elementor-panel .plugin-rating .thank-you-msg-container span.close-icon svg { |
| 318 | height: 12px; |
| 319 | width: 12px; |
| 320 | cursor: pointer; |
| 321 | } |
| 322 | |
| 323 | /* .elementor-panel .plugin-rating .thankyou-msg-container span.close-icon { |
| 324 | position: absolute; |
| 325 | top: 8px; |
| 326 | right: 8px; |
| 327 | } */ |
| 328 | |
| 329 | .elementor-panel .plugin-rating .thank-you-msg-container p.thank-you-message { |
| 330 | font-weight: 400; |
| 331 | color: #232c39; |
| 332 | margin-bottom: 8px; |
| 333 | font-size: 12px; |
| 334 | } |
| 335 | |
| 336 | .elementor-panel .plugin-rating .thank-you-msg-container span.undo-review { |
| 337 | color: #5b4e96; |
| 338 | font-weight: 400; |
| 339 | text-decoration: none; |
| 340 | cursor: pointer !important; |
| 341 | } |
| 342 | |
| 343 | .elementor-panel .plugin-rating .chat-button { |
| 344 | color: white; |
| 345 | border: none; |
| 346 | padding: 10px 20px; |
| 347 | border-radius: 5px; |
| 348 | cursor: pointer; |
| 349 | font-size: 14px; |
| 350 | display: flex; |
| 351 | align-items: center; |
| 352 | justify-content: center; |
| 353 | gap: 5px; |
| 354 | font-weight: 400; |
| 355 | width: 100%; |
| 356 | } |
| 357 | |
| 358 | .elementor-panel .plugin-rating .chat-button svg { |
| 359 | width: 18px; |
| 360 | height: 18px; |
| 361 | } |
| 362 | |
| 363 | .elementor-panel .plugin-rating .chat-button:hover { |
| 364 | background-color: #4b3293; |
| 365 | } |
| 366 | |
| 367 | .elementor-panel .plugin-rating .upgrade-box { |
| 368 | padding: 15px; |
| 369 | margin-top: 15px; |
| 370 | border-radius: 8px; |
| 371 | text-align: left; |
| 372 | } |
| 373 | |
| 374 | .elementor-panel .plugin-rating .upgrade-box h5 { |
| 375 | font-size: 14px; |
| 376 | margin-top: 0; |
| 377 | margin-bottom: 10px; |
| 378 | color: #1d2939; |
| 379 | color: #fff; |
| 380 | color: var(--upgrade-box-title-color); |
| 381 | font-weight: 600; |
| 382 | } |
| 383 | |
| 384 | .elementor-panel .plugin-rating .upgrade-box p { |
| 385 | font-size: 12px; |
| 386 | color: var(--secondary-text-color); |
| 387 | margin-bottom: 12px; |
| 388 | font-weight: 400; |
| 389 | line-height: 1.6; |
| 390 | } |
| 391 | |
| 392 | .elementor-panel .plugin-rating .upgrade-box .upgrade-link { |
| 393 | color: #ec6e00; |
| 394 | font-weight: 400; |
| 395 | text-decoration: none; |
| 396 | } |
| 397 | |
| 398 | .elementor-panel .plugin-rating .upgrade-box .upgrade-link:hover { |
| 399 | text-decoration: underline; |
| 400 | } |
| 401 | |
| 402 | |
| 403 | |
| 404 | .elementor-panel .thankyou-msg-container, |
| 405 | .elementor-panel .feedback-submit-container { |
| 406 | border-radius: 8px; |
| 407 | text-align: left; |
| 408 | position: relative; |
| 409 | margin-bottom: 10px; |
| 410 | } |
| 411 | |
| 412 | .elementor-panel .thankyou-msg-container textarea.form-control, |
| 413 | .elementor-panel .feedback-submit-container textarea.form-control { |
| 414 | width: 100%; |
| 415 | background: var(--form-control-backgound); |
| 416 | outline: 1px solid var(--border-color); |
| 417 | margin-bottom: 10px; |
| 418 | border: none; |
| 419 | font-weight: 400; |
| 420 | font-size: 14px; |
| 421 | line-height: 1.6; |
| 422 | font-family: system-ui; |
| 423 | padding: 8px 8px; |
| 424 | } |
| 425 | |
| 426 | .elementor-panel .thankyou-msg-container textarea.form-control::placeholder, |
| 427 | .elementor-panel .feedback-submit-container textarea.form-control::placeholder { |
| 428 | font-weight: 400; |
| 429 | font-size: 14px; |
| 430 | line-height: 1.6; |
| 431 | color: var(--placeholder-text-color); |
| 432 | font-family: system-ui; |
| 433 | } |
| 434 | |
| 435 | .elementor-panel .thankyou-msg-container textarea:focus, |
| 436 | .elementor-panel .feedback-submit-container textarea:focus { |
| 437 | outline-color: #5b4e96; |
| 438 | box-shadow: none !important; |
| 439 | outline: 1px solid #5b4e96; |
| 440 | } |
| 441 | |
| 442 | .elementor-panel .submit-button, |
| 443 | .elementor-panel .rating-button { |
| 444 | border-radius: 4px; |
| 445 | border-width: 1px; |
| 446 | width: 100%; |
| 447 | border: 1px solid #5b4e96; |
| 448 | color: var(--submit-button-color); |
| 449 | background: transparent; |
| 450 | cursor: pointer; |
| 451 | display: flex; |
| 452 | align-items: center; |
| 453 | justify-content: center; |
| 454 | padding: 12px 8px; |
| 455 | |
| 456 | } |
| 457 | |
| 458 | .elementor-panel .submit-button svg, |
| 459 | .elementor-panel .rating-button svg { |
| 460 | height: 18px; |
| 461 | width: 18px; |
| 462 | } |
| 463 | |
| 464 | .elementor-panel .help-message { |
| 465 | font-weight: 500; |
| 466 | font-size: 15px; |
| 467 | line-height: 1.6; |
| 468 | letter-spacing: 0%; |
| 469 | margin-bottom: 10px; |
| 470 | margin-top: 0 color: var(--text-color) |
| 471 | } |
| 472 | |
| 473 | .elementor-panel p.form-description { |
| 474 | font-size: 14px; |
| 475 | margin-bottom: 12px; |
| 476 | font-family: system-ui; |
| 477 | color: var(--description-text-color); |
| 478 | line-height: 1.4; |
| 479 | } |
| 480 | |
| 481 | .elementor-panel span.close-icon { |
| 482 | position: absolute; |
| 483 | top: 8px; |
| 484 | right: 8px; |
| 485 | } |
| 486 | |
| 487 | .elementor-panel span.close-icon svg { |
| 488 | height: 12px; |
| 489 | width: 12px; |
| 490 | cursor: pointer; |
| 491 | } |
| 492 | |
| 493 | .elementor-panel span.undo-review { |
| 494 | color: #5b4e96; |
| 495 | font-weight: 400; |
| 496 | text-decoration: none; |
| 497 | cursor: pointer; |
| 498 | } |
| 499 | |
| 500 | .elementor-panel p.thank-you-message { |
| 501 | font-weight: 400; |
| 502 | color: var(--secondary-text-color); |
| 503 | font-size: 14px; |
| 504 | line-height: 1.6; |
| 505 | } |
| 506 | |
| 507 | .elementor-panel .chat-button { |
| 508 | background-color: #5b4e96; |
| 509 | color: white; |
| 510 | border: none; |
| 511 | padding: 10px 20px; |
| 512 | border-radius: 5px; |
| 513 | cursor: pointer; |
| 514 | font-size: 12px; |
| 515 | display: flex; |
| 516 | align-items: center; |
| 517 | justify-content: center; |
| 518 | gap: 5px; |
| 519 | font-weight: 500; |
| 520 | width: 100%; |
| 521 | } |
| 522 | |
| 523 | .elementor-panel .chat-button { |
| 524 | background-color: transparent; |
| 525 | border: 1px solid #5B4E96; |
| 526 | color: #fff; |
| 527 | } |
| 528 | |
| 529 | .elementor-panel .rating-button { |
| 530 | background-color: transparent; |
| 531 | border: 1px solid #5B4E96; |
| 532 | color: var(--submit-button-color); |
| 533 | margin-top: 20px; |
| 534 | } |
| 535 | |
| 536 | .elementor-panel .chat-button svg { |
| 537 | width: 18px; |
| 538 | height: 18px; |
| 539 | } |
| 540 | |
| 541 | .elementor-panel .chat-button:hover { |
| 542 | background-color: #4b3293; |
| 543 | } |
| 544 | </style> |
| 545 | |
| 546 | <script> |
| 547 | document.addEventListener("DOMContentLoaded", function() { |
| 548 | if (typeof jQuery === 'undefined') { |
| 549 | console.error("❌ jQuery is not loaded!"); |
| 550 | return; |
| 551 | } |
| 552 | |
| 553 | jQuery(document).ready(function($) { |
| 554 | console.log("� |
| 555 | jQuery is loaded and ready!"); |
| 556 | |
| 557 | let message = ""; // Store the thank-you message state |
| 558 | let rating = 0; // Store rating state |
| 559 | let showThank = localStorage.getItem("feedbackSubmitted") ? 1 : 0; // Store rating state |
| 560 | let targetNode = null; // Store reference to the Elementor controls section |
| 561 | |
| 562 | const currentUser = <?php echo json_encode(wp_get_current_user()->data); ?>; |
| 563 | const isProActive = <?php echo json_encode(is_plugin_active('embedpress-pro/embedpress-pro.php')); ?>; |
| 564 | const isEmbedpressFeedbackSubmited = <?php echo json_encode(get_option('embedpress_feedback_submited')); ?>; |
| 565 | |
| 566 | const turnOffRattingHelp = <?php echo json_encode(Helper::get_options_value('turn_off_rating_help')); ?>; |
| 567 | |
| 568 | function handleRating(selectedRating) { |
| 569 | |
| 570 | rating = selectedRating; |
| 571 | |
| 572 | $(".star").each(function() { |
| 573 | const starValue = $(this).data("rating"); |
| 574 | $(this).attr("fill", starValue <= rating ? "#FFD700" : "#B1B8C2"); // Gold for selected, Grey for unselected |
| 575 | }); |
| 576 | |
| 577 | if (rating == 5) { |
| 578 | sendFiveStarRating(); |
| 579 | } |
| 580 | |
| 581 | // Delay message update by 2 seconds |
| 582 | setTimeout(() => { |
| 583 | if (rating < 5) { |
| 584 | message = "Please describe your issue in details."; |
| 585 | } else { |
| 586 | message = `Thanks for rating ${rating} stars!`; |
| 587 | } |
| 588 | renderUpsellSection(); |
| 589 | }, 500); |
| 590 | |
| 591 | } |
| 592 | |
| 593 | function setMessage(value) { |
| 594 | message = value; |
| 595 | renderUpsellSection(); |
| 596 | } |
| 597 | |
| 598 | function handleSubmit(event) { |
| 599 | event.preventDefault(); |
| 600 | |
| 601 | const submitButton = event.target.querySelector('.submit-button'); |
| 602 | submitButton.disabled = true; // Disable the button |
| 603 | submitButton.textContent = 'Sending...'; // Update button text |
| 604 | |
| 605 | const formData = new FormData(event.target); |
| 606 | const data = { |
| 607 | name: currentUser.display_name, |
| 608 | email: currentUser.user_email, |
| 609 | rating: rating, |
| 610 | message: formData.get('message') |
| 611 | }; |
| 612 | |
| 613 | fetch('/wp-json/embedpress/v1/send-feedback', { // Updated API endpoint |
| 614 | method: 'POST', |
| 615 | headers: { |
| 616 | 'Content-Type': 'application/json' |
| 617 | }, |
| 618 | body: JSON.stringify(data) |
| 619 | }) |
| 620 | .then(response => response.json()) |
| 621 | .then(data => { |
| 622 | |
| 623 | submitButton.disabled = false; // Re-enable the button |
| 624 | submitButton.textContent = 'Send'; // Reset button text |
| 625 | showThank = 1; |
| 626 | |
| 627 | localStorage.setItem("feedbackSubmitted", "true"); |
| 628 | renderUpsellSection(); |
| 629 | |
| 630 | setTimeout(() => { |
| 631 | $(".thankyou-msg-container").fadeOut(500, function() { |
| 632 | $(this).remove(); |
| 633 | }); |
| 634 | }, 3000); // Disappear after 3 seconds |
| 635 | |
| 636 | }) |
| 637 | .catch(error => { |
| 638 | console.error('Error:', error); |
| 639 | alert('Failed to send email.'); |
| 640 | }); |
| 641 | }; |
| 642 | |
| 643 | function sendFiveStarRating() { |
| 644 | const data = { |
| 645 | name: currentUser.display_name, |
| 646 | email: currentUser.user_email, |
| 647 | rating: '5', |
| 648 | message: '' |
| 649 | }; |
| 650 | |
| 651 | fetch('/wp-json/embedpress/v1/send-feedback', { // Updated API endpoint |
| 652 | method: 'POST', |
| 653 | headers: { |
| 654 | 'Content-Type': 'application/json' |
| 655 | }, |
| 656 | body: JSON.stringify(data) |
| 657 | }) |
| 658 | .then(response => response.json()) |
| 659 | .then(data => { |
| 660 | console.log('Success:', data); |
| 661 | localStorage.setItem("feedbackSubmitted", "true"); |
| 662 | renderUpsellSection(); |
| 663 | |
| 664 | }) |
| 665 | .catch(error => { |
| 666 | console.error('Error:', error); |
| 667 | alert('Failed to send email.'); |
| 668 | }); |
| 669 | } |
| 670 | |
| 671 | function renderUpsellSection() { |
| 672 | if (!targetNode) return; |
| 673 | |
| 674 | $(".plugin-rating").remove(); // Remove previous upsell section |
| 675 | |
| 676 | |
| 677 | const thnkMsgHeading = rating < 5 ? 'We appreciate it!' : 'We’re glad that you liked us! 😍'; |
| 678 | const thnkMsgDsc = rating < 5 ? 'A heartfelt gratitude for managing the time to share your thoughts with us' : 'If you don’t mind, could you take 30 seconds to review us on WordPress? Your feedback will help us improve and grow. Thank you in advance! 🙏'; |
| 679 | |
| 680 | let upsellHtml = ` |
| 681 | <div class="plugin-rating"> |
| 682 | ${turnOffRattingHelp ? ` |
| 683 | <div class="rating-chat-content"> |
| 684 | ${!isEmbedpressFeedbackSubmited ? ` |
| 685 | ${((rating && rating == 5) || showThank) ? ` |
| 686 | <div class="thankyou-msg-container"> |
| 687 | |
| 688 | <h5 class="help-message">${thnkMsgHeading}</h5> |
| 689 | <p class="thank-you-message">${thnkMsgDsc}</p> |
| 690 | |
| 691 | ${rating == 5 ? ` |
| 692 | <button class="rating-button"> |
| 693 | Rate the Plugin |
| 694 | <svg width="10" height="10" viewBox="0 0 10 10" fill="none" xmlns="http://www.w3.org/2000/svg"> |
| 695 | <path d="M3.75 2.083 6.25 5l-2.5 2.917" stroke="#5B4E96" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round" /> |
| 696 | </svg> |
| 697 | </button> |
| 698 | ` : ''} |
| 699 | </div> |
| 700 | ` : rating && rating < 5 ? ` |
| 701 | <div class="feedback-submit-container"> |
| 702 | <h5 class="help-message">Help us make it better!</h5> |
| 703 | <p class="form-description">Please share what went wrong with The EmbedPress so that we can improve further*</p> |
| 704 | <form id="feedback-form"> |
| 705 | <div class="form-group"> |
| 706 | <textarea name="message" placeholder="Describe your issue in details" type="text" rows="4" class="form-control" required></textarea> |
| 707 | </div> |
| 708 | <div class="form-group"> |
| 709 | <button class="submit-button" type="submit">Send</button> |
| 710 | </div> |
| 711 | </form> |
| 712 | </div> |
| 713 | ` : ` |
| 714 | <h4>Rate EmbedPress</h4> |
| 715 | <div class="stars"> |
| 716 | ${[1, 2, 3, 4, 5].map(i => ` |
| 717 | <svg class="star" data-rating="${i}" width="20" height="18.667" viewBox="0 0 20 18.667" fill="none" xmlns="http://www.w3.org/2000/svg" |
| 718 | style={{ cursor: "pointer", transition: "fill 0.2s ease-in-out" }}> |
| 719 | <g clip-path="url(#a)"> |
| 720 | <path d="m7.3 5.709-4.963.72-.087.017a.777.777 0 0 0-.343 1.309l3.595 3.499-.848 4.943-.009.087a.777.777 0 0 0 1.139.733l4.437-2.333 4.428 2.333.077.036a.777.777 0 0 0 1.053-.855l-.849-4.944 3.596-3.5.061-.067a.777.777 0 0 0-.493-1.259l-4.961-.72-2.218-4.495a.777.777 0 0 0-1.396 0z"/> |
| 721 | </g> |
| 722 | <defs><clipPath id="a"><path fill="#fff" d="M.888 0h18.667v18.667H.888z"/></clipPath></defs> |
| 723 | </svg> |
| 724 | `).join('')} |
| 725 | </div> |
| 726 | `} |
| 727 | ` : ''} |
| 728 | |
| 729 | <p style="font-weight: 500">Need help? We're here</p> |
| 730 | <a href="https://embedpress.com/?support=chat" target="_blank" class="chat-button"> |
| 731 | <svg width="13" height="12" viewBox="0 0 13 12" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#a)" fill="#fff"><path d="M7.93.727H1.555C.97.727.5 1.198.5 1.782V6c0 .584.471 1.055 1.055 1.055h.351V8.11c0 .254.263.438.52.31.008-.008.022-.008.029-.015 1.934-1.297 1.5-1.008 1.933-1.294a.35.35 0 0 1 .19-.056H7.93c.583 0 1.054-.47 1.054-1.055V1.782c0-.584-.47-1.055-1.054-1.055M5.117 4.946h-2.86c-.463 0-.465-.703 0-.703h2.86c.464 0 .466.703 0 .703m2.11-1.406h-4.97c-.463 0-.465-.704 0-.704h4.97c.463 0 .465.704 0 .704" /><path d="M11.445 3.54H9.687V6c0 .97-.787 1.758-1.757 1.758H4.684l-.668.443v.612c0 .584.47 1.055 1.054 1.055h3.457l2.018 1.35c.276.153.549-.033.549-.296V9.868h.351c.584 0 1.055-.471 1.055-1.055V4.594c0-.583-.471-1.054-1.055-1.054" /></g><defs><clipPath id="a"><path fill="#fff" d="M.5 0h12v12H.5z" /></clipPath></defs></svg> |
| 732 | Let’s Chat |
| 733 | </a> |
| 734 | </div>` : ''} |
| 735 | |
| 736 | ${!isProActive ? ` |
| 737 | <div class="upgrade-box"> |
| 738 | <h5>Want to explore more?</h5> |
| 739 | <p>Dive in and discover all the premium features</p> |
| 740 | <a href="https://embedpress.com/#pricing" target="_blank" class="upgrade-link">Upgrade to PRO</a> |
| 741 | </div>` : ''} |
| 742 | </div> |
| 743 | `; |
| 744 | |
| 745 | $(upsellHtml).insertAfter(targetNode); |
| 746 | |
| 747 | |
| 748 | |
| 749 | let currentRating = 0; // Store the selected rating |
| 750 | $(".star").attr("fill", "#FFD700"); |
| 751 | |
| 752 | $(".star").on("mouseenter", function() { |
| 753 | let hoverRating = $(this).data("rating"); |
| 754 | |
| 755 | console.log(hoverRating); |
| 756 | |
| 757 | $(".star").each(function() { |
| 758 | $(this).attr("fill", $(this).data("rating") <= hoverRating ? "#FFD700" : "#B1B8C2"); |
| 759 | }); |
| 760 | }); |
| 761 | |
| 762 | $(".star").on("mouseleave", function() { |
| 763 | $(".star").each(function() { |
| 764 | $(this).attr("fill", $(this).data("rating") <= currentRating ? "#FFD700" : "#B1B8C2"); |
| 765 | }); |
| 766 | }); |
| 767 | |
| 768 | $(".star").on("click", function() { |
| 769 | currentRating = $(this).data("rating"); |
| 770 | |
| 771 | $(".star").each(function() { |
| 772 | $(this).attr("fill", $(this).data("rating") <= currentRating ? "#FFD700" : "#B1B8C2"); |
| 773 | }); |
| 774 | |
| 775 | handleRating(currentRating); |
| 776 | }); |
| 777 | |
| 778 | |
| 779 | |
| 780 | $(".rating-button").on("click", function() { |
| 781 | window.open('https://wordpress.org/support/plugin/embedpress/reviews/#new-post') |
| 782 | }); |
| 783 | |
| 784 | $("#feedback-form").on("submit", handleSubmit); |
| 785 | } |
| 786 | |
| 787 | function addUpsellSection(node) { |
| 788 | if (!node) return; |
| 789 | |
| 790 | targetNode = node; // Store reference to the correct node |
| 791 | if (!$(".plugin-rating").length) { |
| 792 | console.log("� |
| 793 | Elementor Panel Found! Adding Upsell Section..."); |
| 794 | renderUpsellSection(); |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | // MutationObserver to detect Elementor panel changes |
| 799 | const observer = new MutationObserver((mutations) => { |
| 800 | mutations.forEach((mutation) => { |
| 801 | mutation.addedNodes.forEach((node) => { |
| 802 | if ($(node).hasClass("elementor-controls-stack")) { |
| 803 | const elementorControls = node.querySelector("#elementor-controls:has(.elementor-control-embedpress_elementor_content_settings, .elementor-control-embedpress_pdf_content_settings, .elementor-control-embedpress_document_content_settings, .elementor-control-embedpress_calendar_content_settings)"); |
| 804 | |
| 805 | if (elementorControls) { |
| 806 | addUpsellSection(elementorControls); |
| 807 | } |
| 808 | } |
| 809 | }); |
| 810 | }); |
| 811 | }); |
| 812 | |
| 813 | // Start observing Elementor panel for changes |
| 814 | const elementorPanel = document.querySelector(".elementor-panel"); |
| 815 | if (elementorPanel) { |
| 816 | observer.observe(elementorPanel, { |
| 817 | childList: true, |
| 818 | subtree: true, |
| 819 | }); |
| 820 | console.log("🔍 Observer started on Elementor Panel"); |
| 821 | } else { |
| 822 | console.log("❌ Elementor panel not found, observer not started."); |
| 823 | } |
| 824 | }); |
| 825 | }); |
| 826 | </script> |
| 827 | |
| 828 | <?php |
| 829 | } |
| 830 | } |
| 831 |