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 '

'; echo __('Widgets have been deprecated in the EmailOctopus plugin. Please delete this widget and add forms to widget areas via shortcodes.', 'emailoctopus'); 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 .= '
'; if ($form_id !== 0) { // Preload some variables. $form_data = Deprecated::get_form_data($form_id); if (!$form_data) { return; } $settings = []; $settings['appearance'] = Deprecated::get_form_meta($form_id, 'appearance'); $settings['classname'] = Deprecated::get_form_meta($form_id, 'form_class'); // Get class names and allow them to be filterable switch ($settings['appearance']) { case 'custom': $settings['main_class_names'][] = 'emailoctopus-custom-colors'; break; case 'light': $settings['main_class_names'][] = 'emailoctopus-theme-light'; break; case 'dark': $settings['main_class_names'][] = 'emailoctopus-theme-dark'; break; } if (!empty($settings['classname'])) { $classname = explode(' ', $settings['classname']); foreach ($classname as $class) { $settings['main_class_names'][] = $class; } } ob_start(); $form = new Form($form_id); $form->render_form(); $widget_output .= ob_get_clean(); } $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']), ]; } }