Widget development – Drop down options won’t save

Danny, this is pretty much lifted straight from a plug-in I’ve made: <?php function form($instance){ $instance = wp_parse_args( (array) $instance, $this->w_arg ); ?> <p> <select id=”<?php echo $this->get_field_id(‘order’); ?>” name=”<?php echo $this->get_field_name(‘order’); ?>” type=”text”> <option value=”asc” <?php selected($instance[‘order’], ‘asc’); ?>>ASC </option> <option value=”desc” <?php selected($instance[‘order’], ‘desc’);?>>DESC </option> </select> </p> <?php } ?> Without seeing the … Read more

Prevent widgets removal

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. In this example, only one user is able to add/delete widgets. function wpse_53398_script_printer(){ // used to display the … Read more

Show post tags in a widget

Tags can be shown outside the Post loop using the global functions. Step 1 : Get a PHP Code Widget (this solved many problems) Step 2 : Place the Code <?php the_tags(); ?> in widget and Save. Check Tags Documentation to tweak display order. All done just rock and roll.

How to hook into unregistering a widget instance?

Yes, this can be done. Ultimately, adding and removing a widget to/from a sidebar means updating an option in the database with a call like this: update_option( ‘sidebars_widgets’, array( … ) ) If you look at the code of update_option you see that there is a filter called just before the actual update. So if … Read more

Get Widget Instance inside Widget

You can get widget options using following code $current_widget_options = $this->get_settings(); This will return array like array(instance number => settings). Instance number refers to the $number of widget. Example: If your widget instance number is 2 then your required options will be at $current_widget_options[2] Alternative: As get_settings() is deprecated, you can use get_option. Check following … Read more

How Do I Add Custom CSS To Only Certain Widgets

Hi John: I think this is what you are looking for (I’d explain the code be I think it’s self-explanatory; let me know if not): <?php add_filter(‘dynamic_sidebar_params’,’my_dynamic_sidebar_params’); function my_dynamic_sidebar_params($params) { $sidebar_id = $params[0][‘id’]; $sidebar_widgets = wp_get_sidebars_widgets(); $last_widget_id = end($sidebar_widgets[$sidebar_id]); if ($last_widget_id==$params[0][‘widget_id’]) $params[0][‘before_widget’] = str_replace(‘ class=”‘,’ class=”last_widget ‘,$params[0][‘before_widget’]); return $params; }

How to hide or remove unwanted widgets on Multisite installation?

Add this to your functions.php file: function jpb_unregister_widgets(){ unregister_widget(‘WP_Widget_Pages’); unregister_widget(‘WP_Widget_Calendar’); unregister_widget(‘WP_Widget_Archives’); unregister_widget(‘WP_Widget_Links’); unregister_widget(‘WP_Widget_Meta’); unregister_widget(‘WP_Widget_Search’); unregister_widget(‘WP_Widget_Text’); unregister_widget(‘WP_Widget_Categories’); unregister_widget(‘WP_Widget_Recent_Posts’); unregister_widget(‘WP_Widget_Recent_Comments’); unregister_widget(‘WP_Widget_RSS’); unregister_widget(‘WP_Widget_Tag_Cloud’); unregister_widget(‘WP_Nav_Menu_Widget’); } add_action( ‘widgets_init’, ‘jpb_unregister_widgets’ ); This will get rid of all default widgets. If you want to keep a certain widget, remove that line from the function above.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)