prefix = $prefix; $this->id = 'mwpal_search_widget_' . $this->prefix; $this->title = $title; } /** * Set data loading callback. * * @param callable $ldr - A callback that will receive this widget as first parameter and is supposed to populate this widget. * @param mixed $usr - Some data to be passed to callback as 2nd parameter. */ public function set_data_loader( $ldr, $usr = null ) { $this->data_loader_func = $ldr; $this->data_loader_data = $usr; } /** * Called when widget needs to be populated. * * @param bool $force_load - Force (re)loading data. */ public function load_data( $force_load = false ) { // Avoid loading data multiple times. if ( ( ! $this->data_loaded || $force_load ) && $this->data_loader_func ) { call_user_func( $this->data_loader_func, $this, $this->data_loader_data ); $this->data_loaded = true; } } /** * Renders widget HTML. */ public function render() { $this->load_data(); echo ''; $this->render_label(); $this->render_error(); echo ''; echo ''; $this->render_field(); echo ''; } /** * Renders widget label (left). */ protected function render_label() { ?> title ); ?>