get_widget_slug(), __('EmailOctopus Form', 'emailoctopus'), [ 'classname' => $this->get_widget_slug() . '-class', 'description' => __( 'A widget to display your EmailOctopus forms.', 'emailoctopus' ), ] ); } /** * Returns the widget slug. * * @return string Widget slug. */ public function get_widget_slug() { return $this->widget_slug; } public function form($instance) { echo '
'; return 'noform'; } /** * Outputs the content of the widget. * * @param array $args The array of form elements. * @param array $instance The current instance of the widget. */ public function widget($args, $instance) { // Check if there is a cached output. $cache = wp_cache_get($this->get_widget_slug(), 'emailoctopus_widget'); if (!is_array($cache)) { $cache = []; } $widget_id = $this->id; if (isset($cache[$widget_id])) { return print $cache[$widget_id]; } $form_id = !empty($instance['form_id']) ? $instance['form_id'] : 0; $widget_output = isset($args['before_widget']) ? $args['before_widget'] : ''; $widget_output .= ''; $widget_output .= isset($args['after_widget']) ? $args['after_widget'] : ''; $cache[$widget_id] = $widget_output; wp_cache_set($this->get_widget_slug(), $cache, 'emailoctopus_widget'); echo $widget_output; } /** * Flushes the widget's cache. */ public function flush_widget_cache() { wp_cache_delete($this->get_widget_slug(), 'emailoctopus_widget'); } /** * Processes the widget's options to be saved. * * @param array $new_instance The new instance of values to be generated via the update. * @param array $old_instance The previous instance of values before the update. */ public function update($new_instance, $old_instance) { return [ 'form_id' => sanitize_text_field($new_instance['emailoctopus-form-select']), ]; } }