Advertisement
oscarviedma

Código funcionalidad PHP OV Dashboard - OV DIVI - Corregido

Aug 19th, 2024
488
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.82 KB | None | 0 0
  1. class Custom_Dashboard_Iframe {
  2.     private $screen_id = 'dashboard';
  3.     private $iframe_url = 'https://ovdemos.s3-tastewp.com/index.php/ov-dashboard/';
  4.  
  5.     public function __construct() {
  6.         add_action('wp_dashboard_setup', [$this, 'remove_dashboard_widgets']);
  7.         add_action('admin_notices', [$this, 'add_dashboard_iframe']);
  8.         add_action('admin_head', [$this, 'custom_admin_styles']);
  9.         add_action('admin_footer', [$this, 'custom_admin_scripts']);
  10.         add_filter('show_admin_bar', [$this, 'disable_admin_bar_on_iframe_page']);
  11.     }
  12.  
  13.     public function remove_dashboard_widgets() {
  14.         global $wp_meta_boxes;
  15.         $wp_meta_boxes[$this->screen_id]['normal']['core'] = [];
  16.         $wp_meta_boxes[$this->screen_id]['side']['core'] = [];
  17.     }
  18.  
  19.     public function add_dashboard_iframe() {
  20.         $screen = get_current_screen();
  21.         if ($screen->id !== $this->screen_id) return;
  22.         echo '<div id="iframe-container" style="margin:0; padding:0; width:100%; height:calc(100vh - 32px); overflow:hidden;">';
  23.         echo '<iframe id="mi-panel-iframe-completo" src="' . esc_url($this->iframe_url) . '" style="width:100%; height:100%; border:none;"></iframe>';
  24.         echo '</div>';
  25.     }
  26.  
  27.     public function custom_admin_styles() {
  28.         $screen = get_current_screen();
  29.         if ($screen->id !== $this->screen_id) return;
  30.         ?>
  31.         <style>
  32.             .wrap h1, #welcome-panel, #dashboard-widgets-wrap { display: none !important; }
  33.             #wpcontent { padding-left: 0 !important; }
  34.             #wpbody-content { padding-bottom: 0 !important; }
  35.             #iframe-container { overflow: hidden !important; }
  36.             #mi-panel-iframe-completo { width: 100%; height: 100%; border: none; }
  37.             @media screen and (max-width: 782px) {
  38.                 #iframe-container { height: calc(100vh - 46px); }
  39.             }
  40.         </style>
  41.         <?php
  42.     }
  43.  
  44.     public function custom_admin_scripts() {
  45.         $screen = get_current_screen();
  46.         if ($screen->id !== $this->screen_id) return;
  47.         ?>
  48.         <script>
  49.         (function() {
  50.             var iframe = document.getElementById('mi-panel-iframe-completo');
  51.             var container = document.getElementById('iframe-container');
  52.             var lastScrollTop = 0;
  53.             var isScrolling = false;
  54.  
  55.             function handleIframeScroll(event) {
  56.                 if (isScrolling) return;
  57.                 isScrolling = true;
  58.                 var iframeDoc = event.target.documentElement;
  59.                 var newScrollTop = iframeDoc.scrollTop;
  60.                
  61.                 if (newScrollTop !== lastScrollTop) {
  62.                     container.scrollTop = newScrollTop;
  63.                     lastScrollTop = newScrollTop;
  64.                 }
  65.                
  66.                 setTimeout(function() {
  67.                     isScrolling = false;
  68.                 }, 50);
  69.             }
  70.  
  71.             function updateIframeLinks() {
  72.                 var iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
  73.                 var links = iframeDocument.querySelectorAll('a');
  74.                 links.forEach(function(link) {
  75.                     link.setAttribute('target', '_parent');
  76.                 });
  77.             }
  78.  
  79.             if (iframe) {
  80.                 iframe.addEventListener('load', function() {
  81.                     updateIframeLinks();
  82.                     var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
  83.                     iframeDoc.addEventListener('scroll', handleIframeScroll);
  84.                 });
  85.             }
  86.         })();
  87.         </script>
  88.         <?php
  89.     }
  90.  
  91.     public function disable_admin_bar_on_iframe_page($show_admin_bar) {
  92.         return is_page('ov-dashboard') ? false : $show_admin_bar;
  93.     }
  94. }
  95.  
  96. new Custom_Dashboard_Iframe();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement