Skip to main content

The solution I can think of is removing the panels Available and Inactive Widgets so there's simply nowhere to drag (and delete) the widgets used in the sidebar. And you

You can inject something else to fill the gap.

Important: the HTML; closing line cannot have any white-spaceswhitespace characters before or after

PS: this Heredoc sintaxsyntax <<<HTML code HTML; is preventing the code to display the PHP properly formatedformatted here in WPSE. But the code is tested and working.

The solution I can think of is removing the panels Available and Inactive Widgets so there's simply nowhere to drag (and delete) the widgets used in the sidebar. And you can inject something else to fill the gap.

Important: the HTML; closing line cannot have any white-spaces before or after

PS: this Heredoc sintax <<<HTML code HTML; is preventing the code to display the PHP properly formated here in WPSE. But the code is tested and working.

The solution I can think of is removing the panels Available and Inactive Widgets so there's simply nowhere to drag (and delete) the widgets used in the sidebar.

You can inject something else to fill the gap.

Important: the HTML; closing line cannot have any whitespace characters before or after

PS: this Heredoc syntax <<<HTML code HTML; is preventing the code to display the PHP properly formatted here in WPSE. But the code is tested and working.

Code correction
Source Link
brasofilo
  • 22.1k
  • 8
  • 69
  • 264
function wpse_53398_script_printer(){
    // used to display the front end site
    $site = get_site_url();
    
    // here you can filter who can add/delete widgets
    global $current_user;  
    if ( 'kursus' !=== $current_user->data->user_login ) 
    {
            echo <<<HTML
            <!-- CSS to hide the widgets descriptions = real estate gains -->
            <style type="text/css">#widget-list .widget-description {display:none;}</style>
            <script type="text/javascript">
            jQuery(document).ready( function($) {
                // swaps the placement of the panels Available Widgets and Incactive Widgets
                $('#available-widgets').appendTo('#widgets-left');
            });     
            </script>
HTML;
    }
    else
    {
            echo <<<HTML
            <!-- CSS to prevent the div from briefly appearing before the jQuery can act -->
            <style type="text/css">#widgets-left {display:none;}</style>
            <script type="text/javascript">
            // reload the contents of the iframe
            function Reload () {
                var f = document.getElementById('the-front-end');
                f.src = f.src;
            }
            jQuery(document).ready( function($) {
                // inject other content to fill the void
                $('<div style="width:70%;"><input type="button" value="Reload front page" onclick="Reload();" style="float:right"><br /><iframe id="the-front-end" src="{$site}" frameborder="0" width="100%" height="700"></div>').insertBefore('#widgets-left');

                // removes the whole left side of the widgets page
                $('#widgets-left').remove();

            });     
            </script>
HTML;
    }
}
add_action('admin_footer-widgets.php', 'wpse_53398_script_printer');
function wpse_53398_script_printer(){
    // used to display the front end site
    $site = get_site_url();
    
    // here you can filter who can add/delete widgets
    global $current_user;  
    if ( 'kursus' != $current_user->data->user_login ) 
    {
            echo <<<HTML
            <!-- CSS to hide the widgets descriptions = real estate gains -->
            <style type="text/css">#widget-list .widget-description {display:none;}</style>
            <script type="text/javascript">
            jQuery(document).ready( function($) {
                // swaps the placement of the panels Available Widgets and Incactive Widgets
                $('#available-widgets').appendTo('#widgets-left');
            });     
            </script>
HTML;
    }
    else
    {
            echo <<<HTML
            <!-- CSS to prevent the div from briefly appearing before the jQuery can act -->
            <style type="text/css">#widgets-left {display:none;}</style>
            <script type="text/javascript">
            // reload the contents of the iframe
            function Reload () {
                var f = document.getElementById('the-front-end');
                f.src = f.src;
            }
            jQuery(document).ready( function($) {
                // inject other content to fill the void
                $('<div style="width:70%;"><input type="button" value="Reload front page" onclick="Reload();" style="float:right"><br /><iframe id="the-front-end" src="{$site}" frameborder="0" width="100%" height="700"></div>').insertBefore('#widgets-left');

                // removes the whole left side of the widgets page
                $('#widgets-left').remove();

            });     
            </script>
HTML;
    }
}
add_action('admin_footer-widgets.php', 'wpse_53398_script_printer');
function wpse_53398_script_printer(){
    // used to display the front end site
    $site = get_site_url();
    
    // here you can filter who can add/delete widgets
    global $current_user;  
    if ( 'kursus' == $current_user->data->user_login ) 
    {
            echo <<<HTML
            <!-- CSS to hide the widgets descriptions = real estate gains -->
            <style type="text/css">#widget-list .widget-description {display:none;}</style>
            <script type="text/javascript">
            jQuery(document).ready( function($) {
                // swaps the placement of the panels Available Widgets and Incactive Widgets
                $('#available-widgets').appendTo('#widgets-left');
            });     
            </script>
HTML;
    }
    else
    {
            echo <<<HTML
            <!-- CSS to prevent the div from briefly appearing before the jQuery can act -->
            <style type="text/css">#widgets-left {display:none;}</style>
            <script type="text/javascript">
            // reload the contents of the iframe
            function Reload () {
                var f = document.getElementById('the-front-end');
                f.src = f.src;
            }
            jQuery(document).ready( function($) {
                // inject other content to fill the void
                $('<div style="width:70%;"><input type="button" value="Reload front page" onclick="Reload();" style="float:right"><br /><iframe id="the-front-end" src="{$site}" frameborder="0" width="100%" height="700"></div>').insertBefore('#widgets-left');

                // removes the whole left side of the widgets page
                $('#widgets-left').remove();

            });     
            </script>
HTML;
    }
}
add_action('admin_footer-widgets.php', 'wpse_53398_script_printer');
Changes in code. Iframe example.
Source Link
brasofilo
  • 22.1k
  • 8
  • 69
  • 264

In mythis example, only one user is able to add/delete widgets.

Don't know why, but setting display:none was not working via CSS to hide the widgets descriptions, so was done in jQuery.

function wpse_53398_script_printer(){
    // used to display the front end site
    $site = get_site_url();
    
    // here you can filter who can add/delete widgets
    global $current_user;  
    if ( 'kursus' != $current_user->data->user_login ) 
    {
            echo <<<HTML
            <!-- CSS to hide the widgets descriptions = real estate gains -->
            <style type="text/css">#widget-list .widget-description {display:none;}</style>
            <script type="text/javascript">
            jQuery(document).ready( function($) {
                // swaps the placement of the panels Available Widgets and Incactive Widgets
                $('#available-widgets').appendTo('#widgets-left');
            });     
            </script>
HTML;
    }
    else
    {
            echo <<<HTML
            <!-- CSS to prevent the div from briefly appearing beforbefore the jQuery can act -->
            <style type="text/css">#widgets-left {display:none;}</style>
            <script type="text/javascript">
            // reload the contents of the iframe
            function Reload () {
                var f = document.getElementById('the-front-end');
                f.src = f.src;
            }
            jQuery(document).ready( function($) {
                // inject other content to fill the void
                $('<div style="width:70%;"><img70%;"><input src="httptype="button" value="Reload front page" onclick="Reload();" style="float://cdn.sstatic.net/wordpress/imgright"><br /logo.png?v=123"><><iframe id="the-front-end" src="{$site}" frameborder="0" width="100%" height="700"></div>').insertBefore('#widgets-left');

                // removes the whole left side of the widgets page
                $('#widgets-left').remove();

            });     
            </script>
HTML;
    }
}
add_action('admin_footer-widgets.php', 'wpse_53398_script_printer');

In my example, only one user is able to add/delete widgets.

Don't know why, but setting display:none was not working via CSS to hide the widgets descriptions, so was done in jQuery.

function wpse_53398_script_printer(){
    // here you can filter who can add/delete widgets
    global $current_user;  
    if ( 'kursus' != $current_user->data->user_login ) 
    {
            echo <<<HTML
            <!-- CSS to hide the widgets descriptions = real estate gains -->
            <style type="text/css">#widget-list .widget-description {display:none;}</style>
            <script type="text/javascript">
            jQuery(document).ready( function($) {
                // swaps the placement of the panels Available Widgets and Incactive Widgets
                $('#available-widgets').appendTo('#widgets-left');
            });     
            </script>
HTML;
    }
    else
    {
            echo <<<HTML
            <!-- CSS to prevent the div from briefly appearing befor the jQuery can act -->
            <style type="text/css">#widgets-left {display:none;}</style>
            <script type="text/javascript">
            jQuery(document).ready( function($) {
                // inject other content to fill the void
                $('<div style="width:70%;"><img src="http://cdn.sstatic.net/wordpress/img/logo.png?v=123"></div>').insertBefore('#widgets-left');

                // removes the whole left side of the widgets page
                $('#widgets-left').remove();

            });     
            </script>
HTML;
    }
}
add_action('admin_footer-widgets.php', 'wpse_53398_script_printer');

In this example, only one user is able to add/delete widgets.

function wpse_53398_script_printer(){
    // used to display the front end site
    $site = get_site_url();
    
    // here you can filter who can add/delete widgets
    global $current_user;  
    if ( 'kursus' != $current_user->data->user_login ) 
    {
            echo <<<HTML
            <!-- CSS to hide the widgets descriptions = real estate gains -->
            <style type="text/css">#widget-list .widget-description {display:none;}</style>
            <script type="text/javascript">
            jQuery(document).ready( function($) {
                // swaps the placement of the panels Available Widgets and Incactive Widgets
                $('#available-widgets').appendTo('#widgets-left');
            });     
            </script>
HTML;
    }
    else
    {
            echo <<<HTML
            <!-- CSS to prevent the div from briefly appearing before the jQuery can act -->
            <style type="text/css">#widgets-left {display:none;}</style>
            <script type="text/javascript">
            // reload the contents of the iframe
            function Reload () {
                var f = document.getElementById('the-front-end');
                f.src = f.src;
            }
            jQuery(document).ready( function($) {
                // inject other content to fill the void
                $('<div style="width:70%;"><input type="button" value="Reload front page" onclick="Reload();" style="float:right"><br /><iframe id="the-front-end" src="{$site}" frameborder="0" width="100%" height="700"></div>').insertBefore('#widgets-left');

                // removes the whole left side of the widgets page
                $('#widgets-left').remove();

            });     
            </script>
HTML;
    }
}
add_action('admin_footer-widgets.php', 'wpse_53398_script_printer');
Source Link
brasofilo
  • 22.1k
  • 8
  • 69
  • 264
Loading