Skip to content

Instantly share code, notes, and snippets.

@cyberhobo
Created May 15, 2015 22:48
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save cyberhobo/09d13085ac4534465fc8 to your computer and use it in GitHub Desktop.
Save cyberhobo/09d13085ac4534465fc8 to your computer and use it in GitHub Desktop.
Get a WordPress registered widget instance settings.
<?php
function get_widget_instance( $widget_id ) {
global $wp_registered_widgets;
if ( empty( $wp_registered_widgets[$widget_id]['callback'] ) )
return array();
/** @var WP_Widget $widget */
$widget = $wp_registered_widgets[$widget_id]['callback'][0];
$settings = $widget->get_settings();
return ! empty( $settings[$widget->number] ) ? $settings[$widget->number] : array();
}
@sb-lc
Copy link

sb-lc commented Sep 23, 2015

this just return the widget defaults not the values of the widget instance, is this correct?

@drinkmaker
Copy link

this just returns the widget defaults not the values of the widget instance, is this correct?

No, returns the current widget settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment