wp/wp-includes/class-wp-widget-factory.php
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 21 48c4eec2b7e6
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
   100 			}
   100 			}
   101 
   101 
   102 			$this->widgets[ $key ]->_register();
   102 			$this->widgets[ $key ]->_register();
   103 		}
   103 		}
   104 	}
   104 	}
       
   105 
       
   106 	/**
       
   107 	 * Returns the registered WP_Widget object for the given widget type.
       
   108 	 *
       
   109 	 * @since 5.8.0
       
   110 	 *
       
   111 	 * @param string $id_base Widget type ID.
       
   112 	 * @return WP_Widget|null
       
   113 	 */
       
   114 	public function get_widget_object( $id_base ) {
       
   115 		$key = $this->get_widget_key( $id_base );
       
   116 		if ( '' === $key ) {
       
   117 			return null;
       
   118 		}
       
   119 
       
   120 		return $this->widgets[ $key ];
       
   121 	}
       
   122 
       
   123 	/**
       
   124 	 * Returns the registered key for the given widget type.
       
   125 	 *
       
   126 	 * @since 5.8.0
       
   127 	 *
       
   128 	 * @param string $id_base Widget type ID.
       
   129 	 * @return string
       
   130 	 */
       
   131 	public function get_widget_key( $id_base ) {
       
   132 		foreach ( $this->widgets as $key => $widget_object ) {
       
   133 			if ( $widget_object->id_base === $id_base ) {
       
   134 				return $key;
       
   135 			}
       
   136 		}
       
   137 
       
   138 		return '';
       
   139 	}
   105 }
   140 }