Restrict access to specific widget field based on user role

I ended up adding the class ‘ab-ads’ to all my widget areas. if ( !is_super_admin() ) { add_action(‘admin_print_styles-widgets.php’, function() { echo ‘<style type=”text/css”>div.sidebar-widgets-ab-ads { display:none; }</style>’; }); } That way I just hide them for everyone that isn’t administrators.

Why does my widget break other widgets?

I can already see a problem. It is your use of switch_to_blog(). You are potentially doing multiple switch_to_blog() calls; calling restore_current_blog() once at the end of the loop is meaningless. Please review the codex with examples – http://codex.wordpress.org/Function_Reference/switch_to_blog A quick fix is putting restore_current_blog() within the foreach loop. What happens if you do not use … Read more

How i can widget ID get after drag for wordpress with jquery?

My jquery function working perfectly in sidebar :). Jquery Enable after Dragging widget in sidebar . jQuery( document ).ajaxComplete( function( event, XMLHttpRequest, ajaxOptions ) { var request = {}, pairs = ajaxOptions.data.split(‘&’), i, split, widget; for( i in pairs ) { split = pairs[i].split( ‘=’ ); request[decodeURIComponent( split[0] )] = decodeURIComponent( split[1] ); } if( … Read more

Registering a stylesheet inside my WordPress widget

Please check this reference is_active_widget, check the example for an exact solution. That code will go within the __construct() method right after parent::__construct() is called. wp_enqueue_style works if it is called before wp_head is called. and widget() method are called definitely after wp_head is loaded as it just display the HTML template. So here is … Read more

Apply code for all else first block

I believe that what you want to do would better be done with CSS rules in your stylesheet rather than with an embedded style tag that you dynamically manipulate with PHP. Remove style=”visibility: hidden;” from your register_sidebar argument and use something like the following instead (Proof of Concept): <html> <head> <style> .aclass { visibility:hidden } … Read more

Widget dropdown always displays first option

I got an answer on WordPress Support forms, http://wordpress.org/support/topic/widget-dropdown-always-displays-first-option?replies=6 Replaced function form with, function form( $instance ) { // Check values $category = isset( $instance[‘category’] ) ? (int) $instance[‘category’] : ”; $terms = get_terms( ‘app_category’, ‘parent=0&hide_empty=0’ ); if ( !empty( $terms ) && !is_wp_error( $terms ) ) { ?> And changed, name=”<?php echo $this->get_field_name( ‘Category’ … Read more

Display attachment, post and page in recent comments widget

It does seem that you are already using a custom function that you found from this site. You should credit the original author of that code. The widget_comments_args filter was introduced in WordPress3.4. This filter is poorly documented. This filter uses get_comments(), so you can also use the same parameters. Here is the filter in … Read more