Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Custom_Dashboard_Iframe {
- private $screen_id = 'dashboard';
- private $iframe_url = 'https://ovdemos.s3-tastewp.com/index.php/ov-dashboard/';
- public function __construct() {
- add_action('wp_dashboard_setup', [$this, 'remove_dashboard_widgets']);
- add_action('admin_notices', [$this, 'add_dashboard_iframe']);
- add_action('admin_head', [$this, 'custom_admin_styles']);
- add_action('admin_footer', [$this, 'custom_admin_scripts']);
- add_filter('show_admin_bar', [$this, 'disable_admin_bar_on_iframe_page']);
- }
- public function remove_dashboard_widgets() {
- global $wp_meta_boxes;
- $wp_meta_boxes[$this->screen_id]['normal']['core'] = [];
- $wp_meta_boxes[$this->screen_id]['side']['core'] = [];
- }
- public function add_dashboard_iframe() {
- $screen = get_current_screen();
- if ($screen->id !== $this->screen_id) return;
- echo '<div id="iframe-container" style="margin:0; padding:0; width:100%; height:calc(100vh - 32px); overflow:hidden;">';
- echo '<iframe id="mi-panel-iframe-completo" src="' . esc_url($this->iframe_url) . '" style="width:100%; height:100%; border:none;"></iframe>';
- echo '</div>';
- }
- public function custom_admin_styles() {
- $screen = get_current_screen();
- if ($screen->id !== $this->screen_id) return;
- ?>
- <style>
- .wrap h1, #welcome-panel, #dashboard-widgets-wrap { display: none !important; }
- #wpcontent { padding-left: 0 !important; }
- #wpbody-content { padding-bottom: 0 !important; }
- #iframe-container { overflow: hidden !important; }
- #mi-panel-iframe-completo { width: 100%; height: 100%; border: none; }
- @media screen and (max-width: 782px) {
- #iframe-container { height: calc(100vh - 46px); }
- }
- </style>
- <?php
- }
- public function custom_admin_scripts() {
- $screen = get_current_screen();
- if ($screen->id !== $this->screen_id) return;
- ?>
- <script>
- (function() {
- var iframe = document.getElementById('mi-panel-iframe-completo');
- var container = document.getElementById('iframe-container');
- var lastScrollTop = 0;
- var isScrolling = false;
- function handleIframeScroll(event) {
- if (isScrolling) return;
- isScrolling = true;
- var iframeDoc = event.target.documentElement;
- var newScrollTop = iframeDoc.scrollTop;
- if (newScrollTop !== lastScrollTop) {
- container.scrollTop = newScrollTop;
- lastScrollTop = newScrollTop;
- }
- setTimeout(function() {
- isScrolling = false;
- }, 50);
- }
- function updateIframeLinks() {
- var iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
- var links = iframeDocument.querySelectorAll('a');
- links.forEach(function(link) {
- link.setAttribute('target', '_parent');
- });
- }
- if (iframe) {
- iframe.addEventListener('load', function() {
- updateIframeLinks();
- var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
- iframeDoc.addEventListener('scroll', handleIframeScroll);
- });
- }
- })();
- </script>
- <?php
- }
- public function disable_admin_bar_on_iframe_page($show_admin_bar) {
- return is_page('ov-dashboard') ? false : $show_admin_bar;
- }
- }
- new Custom_Dashboard_Iframe();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement