Skip to content

Instantly share code, notes, and snippets.

@jstroem
Created May 30, 2013 21:50
Show Gist options
  • Save jstroem/5681552 to your computer and use it in GitHub Desktop.
Save jstroem/5681552 to your computer and use it in GitHub Desktop.
Widget info from widget ID (wordpress)
function getWidgetInfo($widgetId){
if (preg_match('/^(.+)-(\d+)$/', $widgetId, $matches)){
global $wp_widget_factory;
list($widgetId, $baseid, $instanceid) = $matches;
$widget_obj = null;
foreach($wp_widget_factory->widgets as $widget){
if ($widget->id_base == $baseid){
$widget_obj = $widget;
break;
}
}
if ($widget_obj != null){
$info = $widget_obj->get_settings();
if (isset($info[$instanceid])){
return $info[$instanceid];
} else {
return null;
}
} else {
return null;
}
} else {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment