Switching themes without losing widgets?

Storing widgets is complex topic. Basically it is such a multi-level-array-mess on the inside that very few people try to make sense of it (and even fewer succeed). 🙂 As far as I understand it myself while we can manipulate cute sidebar names on the surface, deep inside it is getting deconstructed to numerical IDs. … Read more

Modifying the default search widget

You can hook into the ‘get_search_form’ action hook ( check out the “last option” part of the link below ). Set the priority high enough to override anything created in a theme. A plugin could look like ( from the link below ): function my_search_form( $form ) { $form = ‘<form role=”search” method=”get” id=”searchform” class=”searchform” … Read more

How to add a specific widget to only 1 page?

It depends on where you want to show the widget. Let’s start with the widget area (sidebar) registration: add_action( ‘wp_loaded’, ‘wpse_76959_register_widget_area’ ); function wpse_76959_register_widget_area() { register_sidebar( array ( ‘name’ => __( ‘Widgets on page Sample Page’, ‘theme_textdomain’ ), ‘description’ => __( ‘Will be used on a page with a slug “sample-page” only.’, ‘theme_textdomain’ ), ‘id’ … Read more

Get a list of all Widgets registered in WordPress admin widgets-area

Widgets are stored in a public variable $widgets in the class WP_Widget_Factory. You can access this class per global variable $wp_widget_factory. To get all registered widgets, list the keys: add_action( ‘wp_footer’, function() { if ( empty ( $GLOBALS[‘wp_widget_factory’] ) ) return; $widgets = array_keys( $GLOBALS[‘wp_widget_factory’]->widgets ); print ‘<pre>$widgets=” . esc_html( var_export( $widgets, TRUE ) ) … Read more

Retrieve each widget separately from a sidebar

I am taking the core of the question to be: “… I’m not able to retrieve the widget class name” You will need to check the global variable $wp_registered_widgets to fill in the missing information. This proof-of-concept code should give you the idea. The code assumes a sidebar named sidebar-1. You will have to adjust … Read more

How to use is_active_widget?

You should make the check inside the widget class, unless you don’t have a choice. The example in the codex is pretty much what you’re looking for: class cbs_map_widget extends WP_Widget{ function cbs_map_widget(){ $this->WP_Widget(‘cbsmaps’, __(‘Widget Name’), array(‘classname’ => ‘cbsmaps’, ‘description’ => __(‘whatever’))); … add_action(‘wp_enqueue_scripts’, array(&$this, ‘js’)); } function js(){ if ( is_active_widget(false, false, $this->id_base, true) … Read more

Extend WordPress 3.8 Site Activity Dashboard Widget to include more comments

Seems like there is no filter for this (yet), but you can unregister the default activity widget and register (within your functions, or even better within your plugin as recommended by Dave Warfel) a similar activity widget with your custom settings: // unregister the default activity widget add_action(‘wp_dashboard_setup’, ‘remove_dashboard_widgets’ ); function remove_dashboard_widgets() { global $wp_meta_boxes; … Read more

dynamically add scripts to WP_Widget widget() method

I’m plucking this code out of my Total Widget Control plugin, so it might throw an error or two. I dunno, just let me know if it does. This is basically the widget code that I use for everything that I build. if (!function_exists(“register_multiwidget”)): /** * Register a widget * * @param $widget */ function … Read more

Simple rich text editor in Text widget?

I’ve never found one that was reliable and/or not a huge resource/memory drain. 🙁 I ended up using the very handy “Page in Widget” plugin instead – it has the advantage of all the functionality of a regular editable page and your widget content won’t accidentally get wiped, which has happened to me far too … Read more

How to edit widgets in WordPress

The WordPress Widgets API is how various widgets are created and sidebars registered. When creating a new widget there are variables that can be added to any widget. Those get their value from the register_sidebars arguments. args (string/array) (optional) Builds Sidebar based off of ‘name’ and ‘id’ values. Default: None name – Sidebar name. id … Read more