What is the quickest way to make a widget?

The Widgets API is the quickest way to make a widget that’s reusable. Example use: class My_Widget extends WP_Widget { /** * PHP4 constructor */ function My_Widget() { My_Widget::__construct(); } /** * PHP5 constructor */ function __construct() { // actual widget processes } /** * Echo the settings update form * * @param array $instance … Read more

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