[wp-hackers] Prevent display of dynamic sidebar in widgets.php

Andy Charrington andycharrington at gmail.com
Sun May 15 20:51:06 UTC 2011


Ok ive done it. thought i would let you all know the solution i came up
with.

Added a conditional statement to 'admin_menu' action which unregisters the
dynamic sidebar i didnt want to display.

However the problem then is that when ever a widget is added, edited or
removed the ajax that takes care of that resaves all the sidebars and their
consequent widgets. Which means the sidebar that i dont want to display
loses all its settings. which is bad! so... I added a call to the sidebar i
want to hide wrapped in a hidden div. Here is the relevant code-

function add_hidden_sidebar_for_ajax(){
if($_SERVER['PHP_SELF'] == '/wp-admin/widgets.php'){
require_once(ABSPATH . 'wp-admin/includes/widgets.php');
echo "<div id=\"thisOneHere\" style=\"display:none;\">";
wp_list_widget_controls('the-id-of-the-sidebar-i-want-to-hide');
echo "</div>";
unregister_sidebar( 'the-id-of-the-sidebar-i-want-to-hide' );
}
}

add_action( 'admin_menu', 'add_hidden_sidebar_for_ajax' );

My plugin then reregisters the sidebar.

Sorted.

Just thought you may be interested in the solution.

Andy

On Sun, May 15, 2011 at 7:44 PM, Andy Charrington-Wilden <
andycharrington at gmail.com> wrote:

> Actually Justin I wonder if unregistering the sidebar would remove the
> widgets. Here's the code for that function-
>
>  576  function unregister_sidebar <http://xref.yoast.com/trunk/_functions/unregister_sidebar.html>( $name <http://xref.yoast.com/trunk/_variables/name.html> ) { 577      global $wp_registered_sidebars <http://xref.yoast.com/trunk/_variables/wp_registered_sidebars.html>; 578   579      if ( isset( $wp_registered_sidebars <http://xref.yoast.com/trunk/_variables/wp_registered_sidebars.html>[$name <http://xref.yoast.com/trunk/_variables/name.html>] ) ) 580          unset <http://xref.yoast.com/trunk/_functions/unset.html>( $wp_registered_sidebars <http://xref.yoast.com/trunk/_variables/wp_registered_sidebars.html>[$name <http://xref.yoast.com/trunk/_variables/name.html>] ); 581  }
>
> Which to me looks like to simply removes it from the array. Which in theory
> means we could put it back in the array at the appropriate time and it
> should pick up it's widget relationships. But there's only one way to find
> out! I'll try it now.
>
> Sent from my iPhone
>
> On 16 May 2011, at 19:02, Justin Tadlock <justin at justintadlock.com> wrote:
>
> You could use something like this:
>
> add_action( 'load-widgets.php', 'my_unregister_sidebars' );
>
> function my_unregister_sidebars() {
>    unregister_sidebar( 'your-sidebar-id' );
> }
>
> I'm thinking that will remove all the widgets from the sidebar too, so it
> might not produce the desired functionality.
>
> On 5/14/2011 4:24 PM, Andy Charrington-Wilden wrote:
>
> Hi all
>
>
> I am trying to find a way to exclude a dynamic sidebar from the default
> widgets page (widgets.php) in wp-admin. I know it sounds crazy but I am
> using dynamic sidebars as part of a plugin and as such don't want the user
> to be able to assign widgets to the sidebars my plugin creates.
>
>
> Does that makes sense? I hope so!
>
>
> I haven't found any hooks I can use, so am wondering if the only option is
> to use CSS to hide the sidebar in widgets.php. Not the ideal solution to be
> honest so was hoping someone here had some bright ideas!
>
>
> Thanks a lot
>
>
> Andy
>
>
> Sent from my iPhone
>
>
> On 11 Apr 2011, at 22:40, Brian Layman<wp-hackers at thecodecave.com>  wrote:
>
>
> On 4/11/2011 2:58 PM, Andy Charrington wrote:
>
> I am trying to set up a test environment for a multisite install and
> figured
>
> that the most realistic tests would be when done with actual data from from
>
> the target site. So...
>
> Would somebody mind explaining and/or pointing me in the right direction??
>
> Leaving port 3306 wide open is generally a bad idea.  You'll eventually be
> hacked or have a slow mysql server due to all the servers out there
> continuously trying passwords.
>
>
> What you are trying to do will work. IF you really want to do this test,
> figure out your hostgator IP address and then contact wired tree and then
> can setup a iptables rule to open 3306 for only that server on your vps.
>  Additionally you'll need to make sure that you are able to make the out
> bound connection from the hostgator side.  It is likely blocked by default.
>  If you have ssh access on your host gator account, I would use mysql from
> the command line to make sure that part is working before trying to diagnose
> more wide ranging issues.
>
>
> Beyond that you'll need to post to the support forums for help with a
> better definition of what you mean by an infinite loop...
>
>
> Hope that helped.
>
> --
>
>
> Brian Layman
>
>
> _______________________________________________
>
> wp-hackers mailing list
>
> wp-hackers at lists.automattic.com
>
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
> _______________________________________________
>
> wp-hackers mailing list
>
> wp-hackers at lists.automattic.com
>
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
>
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
>


-- 
Jealous Designs
Website:  <http://jealousdesigns.co.uk/>jealousdesigns.co.uk
Portfolio:  <http://jealousdesigns.co.uk/portfolio>
jealousdesigns.co.uk/portfolio
Phone: 07903030008
Twitter: _a_n_d_y
Skype: andycharrington



Web design | Web development | WordPress | Flash | Posters, business cards
and flyers | Bespoke online tools | PHP | MySQL | (X)HTML | CSS | Javascript
| ActionScript


More information about the wp-hackers mailing list