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; }
- @media screen and (min-width: 1156px) {
- body, html { overflow: auto !important; }
- #mi-panel-iframe-completo {
- overflow: hidden !important;
- -ms-overflow-style: none !important;
- scrollbar-width: none !important;
- }
- #mi-panel-iframe-completo::-webkit-scrollbar { display: none !important; }
- }
- @media screen and (max-width: 1155px) {
- body, html { overflow: hidden !important; }
- #mi-panel-iframe-completo { overflow: auto !important; }
- }
- @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');
- function adjustIframe() {
- if (!iframe || !container) return;
- iframe.style.height = container.clientHeight + 'px';
- var isWideScreen = window.innerWidth > 1155;
- iframe.style.overflow = isWideScreen ? 'hidden' : 'auto';
- iframe.scrolling = isWideScreen ? 'no' : 'yes';
- document.body.style.overflow = isWideScreen ? 'auto' : 'hidden';
- }
- function updateIframeLinks() {
- var iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
- var links = iframeDocument.querySelectorAll('a');
- links.forEach(function(link) {
- link.setAttribute('target', '_parent');
- });
- }
- if (iframe) {
- window.addEventListener('load', function() {
- adjustIframe();
- updateIframeLinks();
- });
- window.addEventListener('resize', adjustIframe);
- iframe.addEventListener('load', function() {
- updateIframeLinks();
- });
- setInterval(adjustIframe, 500);
- }
- })();
- </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