--- a/wp/wp-includes/class-wp-widget-factory.php Tue Dec 15 15:52:01 2020 +0100
+++ b/wp/wp-includes/class-wp-widget-factory.php Wed Sep 21 18:19:35 2022 +0200
@@ -102,4 +102,39 @@
$this->widgets[ $key ]->_register();
}
}
+
+ /**
+ * Returns the registered WP_Widget object for the given widget type.
+ *
+ * @since 5.8.0
+ *
+ * @param string $id_base Widget type ID.
+ * @return WP_Widget|null
+ */
+ public function get_widget_object( $id_base ) {
+ $key = $this->get_widget_key( $id_base );
+ if ( '' === $key ) {
+ return null;
+ }
+
+ return $this->widgets[ $key ];
+ }
+
+ /**
+ * Returns the registered key for the given widget type.
+ *
+ * @since 5.8.0
+ *
+ * @param string $id_base Widget type ID.
+ * @return string
+ */
+ public function get_widget_key( $id_base ) {
+ foreach ( $this->widgets as $key => $widget_object ) {
+ if ( $widget_object->id_base === $id_base ) {
+ return $key;
+ }
+ }
+
+ return '';
+ }
}