| @@ -3,10 +3,10 @@ | ||
| 3 | 3 | if ( !class_exists( 'MeowKit_MWCODE_Admin' ) ) { |
| 4 | 4 | |
| 5 | 5 | class MeowKit_MWCODE_Admin { |
| 6 | 6 | public static $loaded = false; |
| 7 | - public static $version = '5.0'; | |
| 8 | - public static $admin_version = '5.0'; | |
| 7 | + public static $version = '4.0'; | |
| 8 | + public static $admin_version = '4.0'; | |
| 9 | 9 | public static $network_license_modal_added = false; |
| 10 | 10 | public static $network_license_plugins = []; |
| 11 | 11 | |
| 12 | 12 | /** |
| @@ -157,13 +157,8 @@ | ||
| 157 | 157 | if ( $page === 'meowapps-main-menu' ) { |
| 158 | 158 | add_filter( 'admin_footer_text', [ $this, 'admin_footer_text' ], 100000, 1 ); |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - // Promote AI Engine on the WordPress 7 Connectors page when AI Engine | |
| 162 | - // itself isn't installed. When AI Engine is active, its own banner | |
| 163 | - // takes over — so this path only runs on "bare" Meow Apps installs. | |
| 164 | - add_action( 'admin_enqueue_scripts', [ $this, 'maybe_render_wpai_promo' ] ); | |
| 165 | - | |
| 166 | 161 | MeowKit_MWCODE_Admin::$loaded = true; |
| 167 | 162 | } |
| 168 | 163 | |
| 169 | 164 | // PER-INSTANCE SETUP: Run for each plugin that uses this library |
| @@ -272,11 +267,9 @@ | ||
| 272 | 267 | <button type="button" id="meowapps-license-submit" class="button button-primary">Validate & Register</button> |
| 273 | 268 | </div> |
| 274 | 269 | </div> |
| 275 | 270 | </div> |
| 276 | - <?php | |
| 277 | - ob_start(); | |
| 278 | - ?> | |
| 271 | + <script> | |
| 279 | 272 | (function() { |
| 280 | 273 | var modal = document.getElementById('meowapps-network-license-modal'); |
| 281 | 274 | var input = document.getElementById('meowapps-license-key-input'); |
| 282 | 275 | var message = document.getElementById('meowapps-license-message'); |
| @@ -386,10 +379,10 @@ | ||
| 386 | 379 | submitBtn.textContent = 'Validate & Register'; |
| 387 | 380 | }); |
| 388 | 381 | }); |
| 389 | 382 | })(); |
| 383 | + </script> | |
| 390 | 384 | <?php |
| 391 | - wp_print_inline_script_tag( ob_get_clean() ); | |
| 392 | 385 | } |
| 393 | 386 | |
| 394 | 387 | public function request_verify_ssl() { |
| 395 | 388 | return get_option( 'force_sslverify', false ); |
| @@ -407,12 +400,9 @@ | ||
| 407 | 400 | return $file; |
| 408 | 401 | } |
| 409 | 402 | |
| 410 | 403 | public function admin_notices_licensed_free() { |
| 411 | - // Verify the nonce before removing the license from a POST request (CSRF protection). | |
| 412 | - if ( isset( $_POST[$this->prefix . '_reset_sub'] ) | |
| 413 | - && isset( $_POST[ $this->prefix . '_reset_sub_nonce' ] ) | |
| 414 | - && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST[ $this->prefix . '_reset_sub_nonce' ] ) ), $this->prefix . '_reset_sub' ) ) { | |
| 404 | + if ( isset( $_POST[$this->prefix . '_reset_sub'] ) ) { | |
| 415 | 405 | delete_option( $this->prefix . '_pro_serial' ); |
| 416 | 406 | delete_option( $this->prefix . '_license' ); |
| 417 | 407 | return; |
| 418 | 408 | } |
| @@ -422,9 +412,9 @@ | ||
| 422 | 412 | $this->nice_name_from_file( $this->mainfile ) |
| 423 | 413 | ); |
| 424 | 414 | $html .= '<p> |
| 425 | 415 | <form method="post" action=""> |
| 426 | - <input type="hidden" name="' . $this->prefix . '_reset_sub" value="true"><input type="hidden" name="' . $this->prefix . '_reset_sub_nonce" value="' . esc_attr( wp_create_nonce( $this->prefix . '_reset_sub' ) ) . '"> | |
| 416 | + <input type="hidden" name="' . $this->prefix . '_reset_sub" value="true"> | |
| 427 | 417 | <input type="submit" name="submit" id="submit" class="button" value="' |
| 428 | 418 | . __( 'Remove the license', $this->domain ) . '"> |
| 429 | 419 | </form> |
| 430 | 420 | </p>'; |
| @@ -434,23 +424,19 @@ | ||
| 434 | 424 | |
| 435 | 425 | public function admin_menu_start() { |
| 436 | 426 | // Hide the admin if user doesn't like Meow much |
| 437 | 427 | if ( get_option( 'meowapps_hide_meowapps', false ) ) { |
| 438 | - register_setting( 'general', 'meowapps_hide_meowapps', [ 'type' => 'boolean', 'sanitize_callback' => 'rest_sanitize_boolean' ] ); | |
| 428 | + register_setting( 'general', 'meowapps_hide_meowapps' ); | |
| 439 | 429 | add_settings_field( 'meowapps_hide_ads', 'Meow Apps Menu', [ $this, 'meowapps_hide_dashboard_callback' ], 'general' ); |
| 440 | 430 | return; |
| 441 | 431 | } |
| 442 | 432 | |
| 443 | - // Create standard menu if it does not already exist. | |
| 444 | - // The cat logo is injected as an <img> inside the menu title (rather than passed as | |
| 445 | - // the $icon_url argument) so the original SVG fills are preserved — passing it via | |
| 446 | - // $icon_url makes WordPress add the .svg class and the admin color scheme strips | |
| 447 | - // the colors to a single fill. | |
| 433 | + // Create standard menu if it does not already exist | |
| 448 | 434 | global $submenu; |
| 449 | 435 | if ( !isset( $submenu[ 'meowapps-main-menu' ] ) ) { |
| 450 | 436 | add_menu_page( |
| 451 | 437 | 'Meow Apps', |
| 452 | - '<img alt="Meow Apps" class="meowapps-menu-icon" src="' . MeowKit_MWCODE_Admin::$logo . '" />Meow Apps', | |
| 438 | + '<img alt="Meow Apps" style="width: 21px; margin-left: -28px; position: absolute; margin-top: 2px;" src="' . MeowKit_MWCODE_Admin::$logo . '" />Meow Apps', | |
| 453 | 439 | 'manage_options', |
| 454 | 440 | 'meowapps-main-menu', |
| 455 | 441 | [ $this, 'admin_meow_apps' ], |
| 456 | 442 | '', |
| @@ -465,46 +451,15 @@ | ||
| 465 | 451 | [ $this, 'admin_meow_apps' ] |
| 466 | 452 | ); |
| 467 | 453 | } |
| 468 | 454 | |
| 469 | - // Position the cat icon so it sits in the standard icon column in both the | |
| 470 | - // expanded and the collapsed (folded) sidebar. | |
| 471 | - // | |
| 472 | - // The image lives inside the .wp-menu-name title (where the original code | |
| 473 | - // put it) so the <img> renders with its native SVG fills. When the sidebar | |
| 474 | - // is collapsed, WP hides .wp-menu-name (and everything inside it), so a | |
| 475 | - // small JS snippet below clones the same <img> into the .wp-menu-image | |
| 476 | - // slot — which WP keeps visible in both states. We use a real <img> | |
| 477 | - // (not a background-image) on purpose: at small sizes WP's admin renders | |
| 478 | - // background-image SVGs noticeably lighter than the equivalent <img>, | |
| 479 | - // and we want the colored cat in both states. | |
| 480 | - // | |
| 481 | - // The !important rules also override an older "display: none" style that | |
| 482 | - // previous-generation Meow Apps common copies inject for .wp-menu-image; | |
| 483 | - // if any of them load first, ours still wins. | |
| 484 | - // Enqueue the menu-icon CSS/JS through the assets API instead of echoing inline tags. | |
| 485 | - add_action( 'admin_enqueue_scripts', function () { | |
| 486 | - $css = ' | |
| 487 | - #toplevel_page_meowapps-main-menu .meowapps-menu-icon { width: 20px; height: auto; position: absolute; margin-left: -28px; margin-top: 3px; } | |
| 488 | - #toplevel_page_meowapps-main-menu .wp-menu-image { display: block !important; position: relative; } | |
| 489 | - #toplevel_page_meowapps-main-menu .wp-menu-image::before { display: none !important; } | |
| 490 | - #toplevel_page_meowapps-main-menu .wp-menu-image .meowapps-menu-icon-folded { display: none; position: absolute; top: 50%; left: 50%; transform: translate(-50%, calc(-50% - 3px)); width: 20px; height: auto; } | |
| 491 | - body.folded #toplevel_page_meowapps-main-menu .wp-menu-image .meowapps-menu-icon-folded { display: block; } | |
| 492 | - body.folded #toplevel_page_meowapps-main-menu .meowapps-menu-icon { display: none; } | |
| 493 | - @media only screen and (max-width: 960px) { | |
| 494 | - body.auto-fold #toplevel_page_meowapps-main-menu .wp-menu-image .meowapps-menu-icon-folded { display: block; } | |
| 495 | - body.auto-fold #toplevel_page_meowapps-main-menu .meowapps-menu-icon { display: none; } | |
| 496 | - }'; | |
| 497 | - wp_add_inline_style( 'admin-menu', $css ); | |
| 498 | - | |
| 499 | - // Clone the in-title cat icon into the .wp-menu-image slot (CSS shows it only when folded). | |
| 500 | - $js = 'document.addEventListener("DOMContentLoaded", function () {' | |
| 501 | - . 'var li = document.getElementById("toplevel_page_meowapps-main-menu"); if ( !li ) { return; }' | |
| 502 | - . 'var src = li.querySelector(".meowapps-menu-icon"); var slot = li.querySelector(".wp-menu-image");' | |
| 503 | - . 'if ( !src || !slot || slot.querySelector(".meowapps-menu-icon-folded") ) { return; }' | |
| 504 | - . 'var clone = src.cloneNode(); clone.className = "meowapps-menu-icon-folded"; clone.removeAttribute("style"); slot.appendChild(clone);' | |
| 505 | - . '});'; | |
| 506 | - wp_add_inline_script( 'common', $js ); | |
| 455 | + // Add CSS to hide the default icon | |
| 456 | + add_action( 'admin_head', function () { | |
| 457 | + echo '<style> | |
| 458 | + #toplevel_page_meowapps-main-menu .wp-menu-image { | |
| 459 | + display: none; | |
| 460 | + } | |
| 461 | + </style>'; | |
| 507 | 462 | } ); |
| 508 | 463 | } |
| 509 | 464 | |
| 510 | 465 | public function meowapps_hide_dashboard_callback() { |
| @@ -548,202 +503,7 @@ | ||
| 548 | 503 | __( 'Thanks for using <a href="https://meowapps.com">Meow Apps</a>! This is the Meow Admin %1$s <br /><i>Loaded from %2$s </i>', $this->domain ), |
| 549 | 504 | MeowKit_MWCODE_Admin::$version, |
| 550 | 505 | __FILE__ |
| 551 | 506 | ); |
| 552 | - } | |
| 553 | - | |
| 554 | - /** | |
| 555 | - * Renders a promo banner on WordPress 7's Connectors page when AI Engine | |
| 556 | - * isn't installed. Kept self-contained so the common library stays simple: | |
| 557 | - * no new file, no REST endpoint, dismissal persists in localStorage. | |
| 558 | - */ | |
| 559 | - public function maybe_render_wpai_promo() { | |
| 560 | - // WordPress 7+ only. | |
| 561 | - if ( ! class_exists( 'WP_Connector_Registry' ) ) { | |
| 562 | - return; | |
| 563 | - } | |
| 564 | - // If AI Engine is installed, its own Connectors banner takes over. | |
| 565 | - if ( class_exists( 'Meow_MWAI_Core' ) ) { | |
| 566 | - return; | |
| 567 | - } | |
| 568 | - // Another Meow Apps plugin's common copy may have rendered already. | |
| 569 | - if ( defined( 'MEOWAPPS_WPAI_PROMO_RENDERED' ) ) { | |
| 570 | - return; | |
| 571 | - } | |
| 572 | - // Gate on the Connectors screen. The hook suffix differs between the | |
| 573 | - // direct file (`options-connectors.php`) and the menu-page variant. | |
| 574 | - $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; | |
| 575 | - $id = $screen ? $screen->id : ( isset( $GLOBALS['hook_suffix'] ) ? $GLOBALS['hook_suffix'] : '' ); | |
| 576 | - $targets = array( 'options-connectors', 'options-connectors.php', 'settings_page_options-connectors-wp-admin' ); | |
| 577 | - if ( ! in_array( $id, $targets, true ) ) { | |
| 578 | - return; | |
| 579 | - } | |
| 580 | - define( 'MEOWAPPS_WPAI_PROMO_RENDERED', true ); | |
| 581 | - | |
| 582 | - // Install button → WordPress's own plugin-install search page, pre- | |
| 583 | - // filtered for AI Engine. One click from there to install. This is the | |
| 584 | - // most reliable path: no custom nonces, native progress UI, native | |
| 585 | - // filesystem credential prompt if needed. | |
| 586 | - $can_install = current_user_can( 'install_plugins' ); | |
| 587 | - $install_url = $can_install | |
| 588 | - ? self_admin_url( 'plugin-install.php?tab=search&type=term&s=AI+Engine' ) | |
| 589 | - : 'https://wordpress.org/plugins/ai-engine/'; | |
| 590 | - $wporg_url = 'https://wordpress.org/plugins/ai-engine/'; | |
| 591 | - $learn_url = 'https://meowapps.com/wordpress-7-ai-engine-gateway/'; | |
| 592 | - | |
| 593 | - // Title is split so "AI Engine" can carry an anchor to wp.org. Keeping | |
| 594 | - // the pieces as data (not one HTML string) avoids escaping surprises and | |
| 595 | - // keeps the translation unit stable. | |
| 596 | - $payload = array( | |
| 597 | - 'titleBefore' => __( 'Highly recommended: Let ', 'meowapps' ), | |
| 598 | - 'titleLink' => __( 'AI Engine', 'meowapps' ), | |
| 599 | - 'titleAfter' => __( ' handle your connections.', 'meowapps' ), | |
| 600 | - 'sub' => __( 'One plugin for every provider. Keep your AI setup clean and consistent: monitor your API costs in one place, log every single request, and avoid the mess of juggling separate plugins for each AI model.', 'meowapps' ), | |
| 601 | - 'install' => __( 'Install AI Engine', 'meowapps' ), | |
| 602 | - 'learn' => __( 'Learn more', 'meowapps' ), | |
| 603 | - 'dismiss' => __( 'Dismiss', 'meowapps' ), | |
| 604 | - 'installUrl' => $install_url, | |
| 605 | - 'wporgUrl' => $wporg_url, | |
| 606 | - 'learnUrl' => $learn_url, | |
| 607 | - ); | |
| 608 | - wp_register_style( 'meowapps-common-inline', false ); | |
| 609 | - wp_enqueue_style( 'meowapps-common-inline' ); | |
| 610 | - ob_start(); | |
| 611 | - ?> | |
| 612 | - .meowapps-wpai-promo { | |
| 613 | - margin: 0 0 16px; padding: 14px 18px; | |
| 614 | - display: flex; align-items: flex-start; gap: 14px; | |
| 615 | - background: #f0f4ff; border: 1px solid #d6deff; border-radius: 4px; | |
| 616 | - font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; | |
| 617 | - font-size: 13px; line-height: 1.45; color: #1e1e1e; | |
| 618 | - } | |
| 619 | - .meowapps-wpai-promo-icon { | |
| 620 | - width: 32px; height: 32px; border-radius: 50%; | |
| 621 | - background: #2f5fff; color: #fff; | |
| 622 | - display: flex; align-items: center; justify-content: center; | |
| 623 | - flex-shrink: 0; | |
| 624 | - margin-top: 1px; | |
| 625 | - } | |
| 626 | - .meowapps-wpai-promo-icon svg { width: 18px; height: 18px; display: block; } | |
| 627 | - .meowapps-wpai-promo-body { | |
| 628 | - flex: 1; min-width: 0; | |
| 629 | - display: flex; flex-direction: column; gap: 10px; | |
| 630 | - } | |
| 631 | - .meowapps-wpai-promo-text strong { font-weight: 700; display: block; margin-bottom: 3px; } | |
| 632 | - .meowapps-wpai-promo-text span { color: #50575e; } | |
| 633 | - .meowapps-wpai-promo-titlelink { | |
| 634 | - color: #2f5fff; text-decoration: none; border-bottom: 1px dashed #2f5fff; | |
| 635 | - } | |
| 636 | - .meowapps-wpai-promo-titlelink:hover { color: #2448cc; border-bottom-color: #2448cc; } | |
| 637 | - .meowapps-wpai-promo-actions { | |
| 638 | - display: flex; gap: 8px; flex-wrap: wrap; align-items: center; | |
| 639 | - } | |
| 640 | - .meowapps-wpai-promo-btn { | |
| 641 | - appearance: none; border: 1px solid transparent; border-radius: 4px; | |
| 642 | - padding: 7px 16px; font: inherit; font-size: 12.5px; font-weight: 600; | |
| 643 | - cursor: pointer; text-decoration: none; | |
| 644 | - transition: background 0.12s ease, border-color 0.12s ease; | |
| 645 | - } | |
| 646 | - .meowapps-wpai-promo-btn-primary { background: #2f5fff; color: #fff; } | |
| 647 | - .meowapps-wpai-promo-btn-primary:hover { background: #2448cc; color: #fff; } | |
| 648 | - .meowapps-wpai-promo-btn-secondary { background: #7c3aed; color: #fff; } | |
| 649 | - .meowapps-wpai-promo-btn-secondary:hover { background: #6527c9; color: #fff; } | |
| 650 | - .meowapps-wpai-promo-btn-dismiss { | |
| 651 | - margin-left: auto; | |
| 652 | - background: transparent; color: #6b7280; | |
| 653 | - font-weight: 500; padding: 7px 10px; | |
| 654 | - } | |
| 655 | - .meowapps-wpai-promo-btn-dismiss:hover { color: #1e1e1e; background: rgba(0,0,0,0.04); } | |
| 656 | - <?php | |
| 657 | - wp_add_inline_style( 'meowapps-common-inline', ob_get_clean() ); | |
| 658 | - | |
| 659 | - wp_register_script( 'meowapps-common-inline', false, array(), false, true ); | |
| 660 | - wp_enqueue_script( 'meowapps-common-inline' ); | |
| 661 | - ob_start(); | |
| 662 | - ?> | |
| 663 | - (function () { | |
| 664 | - var D = <?php echo wp_json_encode( $payload ); ?>; | |
| 665 | - try { if (localStorage.getItem('meowapps-wpai-promo-dismissed') === '1') return; } catch (e) {} | |
| 666 | - | |
| 667 | - function build() { | |
| 668 | - var host = document.createElement('div'); | |
| 669 | - host.className = 'meowapps-wpai-promo'; | |
| 670 | - host.setAttribute('role', 'status'); | |
| 671 | - var iconSvg = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 5v14M5 12h14"/></svg>'; | |
| 672 | - host.innerHTML = [ | |
| 673 | - '<span class="meowapps-wpai-promo-icon">', iconSvg, '</span>', | |
| 674 | - '<div class="meowapps-wpai-promo-body">', | |
| 675 | - '<div class="meowapps-wpai-promo-text">', | |
| 676 | - '<strong></strong> <span class="meowapps-wpai-promo-sub"></span>', | |
| 677 | - '</div>', | |
| 678 | - '<div class="meowapps-wpai-promo-actions"></div>', | |
| 679 | - '</div>' | |
| 680 | - ].join(''); | |
| 681 | - // Title carries an anchor on "AI Engine" → wp.org plugin page. | |
| 682 | - var strong = host.querySelector('strong'); | |
| 683 | - strong.appendChild(document.createTextNode(D.titleBefore)); | |
| 684 | - var tLink = document.createElement('a'); | |
| 685 | - tLink.href = D.wporgUrl; | |
| 686 | - tLink.target = '_blank'; | |
| 687 | - tLink.rel = 'noopener noreferrer'; | |
| 688 | - tLink.className = 'meowapps-wpai-promo-titlelink'; | |
| 689 | - tLink.textContent = D.titleLink; | |
| 690 | - strong.appendChild(tLink); | |
| 691 | - strong.appendChild(document.createTextNode(D.titleAfter)); | |
| 692 | - host.querySelector('.meowapps-wpai-promo-sub').textContent = D.sub; | |
| 693 | - var actions = host.querySelector('.meowapps-wpai-promo-actions'); | |
| 694 | - | |
| 695 | - function link(label, cls, href, newTab) { | |
| 696 | - var a = document.createElement('a'); | |
| 697 | - a.className = 'meowapps-wpai-promo-btn ' + cls; | |
| 698 | - a.textContent = label; | |
| 699 | - a.href = href; | |
| 700 | - if (newTab) { a.target = '_blank'; a.rel = 'noopener noreferrer'; } | |
| 701 | - actions.appendChild(a); | |
| 702 | - return a; | |
| 703 | - } | |
| 704 | - | |
| 705 | - // Install → WordPress's plugin-install search page, pre-filtered. | |
| 706 | - // User lands on a familiar screen with AI Engine as the top hit and | |
| 707 | - // can install with the native WordPress UX. | |
| 708 | - link(D.install, 'meowapps-wpai-promo-btn-primary', D.installUrl, false); | |
| 709 | - link(D.learn, 'meowapps-wpai-promo-btn-secondary', D.learnUrl, true); | |
| 710 | - | |
| 711 | - var d = document.createElement('button'); | |
| 712 | - d.type = 'button'; | |
| 713 | - d.className = 'meowapps-wpai-promo-btn meowapps-wpai-promo-btn-dismiss'; | |
| 714 | - d.textContent = D.dismiss; | |
| 715 | - d.addEventListener('click', function () { | |
| 716 | - try { localStorage.setItem('meowapps-wpai-promo-dismissed', '1'); } catch (e) {} | |
| 717 | - if (host.parentNode) host.parentNode.removeChild(host); | |
| 718 | - }); | |
| 719 | - actions.appendChild(d); | |
| 720 | - return host; | |
| 721 | - } | |
| 722 | - | |
| 723 | - function ensure() { | |
| 724 | - if (document.querySelector('.meowapps-wpai-promo')) return; | |
| 725 | - var page = document.querySelector('.connectors-page'); | |
| 726 | - if (page) { page.insertBefore(build(), page.firstChild); return; } | |
| 727 | - var header = document.querySelector('.boot-layout__stage header'); | |
| 728 | - if (header && header.parentNode) { | |
| 729 | - header.parentNode.insertBefore(build(), header.nextSibling); | |
| 730 | - } | |
| 731 | - } | |
| 732 | - | |
| 733 | - var tries = 0; | |
| 734 | - var iv = setInterval(function () { | |
| 735 | - ensure(); | |
| 736 | - if (document.querySelector('.meowapps-wpai-promo') || ++tries > 40) clearInterval(iv); | |
| 737 | - }, 120); | |
| 738 | - | |
| 739 | - var app = document.getElementById('options-connectors-wp-admin-app') | |
| 740 | - || document.getElementById('options-connectors-app'); | |
| 741 | - if (app && 'MutationObserver' in window) { | |
| 742 | - new MutationObserver(ensure).observe(app, { childList: true, subtree: true }); | |
| 743 | - } | |
| 744 | - })(); | |
| 745 | - <?php | |
| 746 | - wp_add_inline_script( 'meowapps-common-inline', ob_get_clean() ); | |
| 747 | 507 | } |
| 748 | 508 | } |
| 749 | 509 | } |