get_path() ); $config = [ 'name' => blocksy_id_to_title( $prefix ), 'description' => __( 'Default widget description', 'blocksy' ), ]; $options = null; if ($this->get_config()) { $config = array_merge( $config, $this->get_config() ); } $this->prefix = $prefix; parent::__construct( false, blocksy_akg( 'name', $config, __( 'Default widget name', 'blocksy' ) ), [ 'description' => blocksy_akg( 'description', $config, __( 'Display online support infomation', 'blocksy' ) ), 'classname' => $prefix . '-widget', ] ); } public function widget( $args, $instance ) { $file_path = $this->get_path() . '/view.php'; if ( ! file_exists( $file_path ) ) { echo '
Default widget view. Please create a view.php file.
'; return; } $instance = blocksy_akg( blocksy_post_name(), $instance, [] ); if ( ! $instance ) { $instance = []; } // @codingStandardsIgnoreLine echo blocksy_render_view( $file_path, array_merge( [ 'atts' => $instance ], $args ) ); } public function read_options() { $options = null; if ( file_exists( $this->get_path() . '/options.php' ) ) { $options = blocksy_akg( 'options', blocksy_get_variables_from_file( $this->get_path() . '/options.php', [ 'options' => [] ] ) ); } if ( $options ) { $this->options = $options; } else { $this->options = [ 'title' => [ 'type' => 'text', 'label' => __( 'Widget Title', 'blocksy' ), 'field_attr' => [ 'id' => 'widget-title' ], ], ]; } } /** * Save widget values, if available. * * @param array $new_instance new widget values. * @param array $old_instance old widget values. */ public function update( $new_instance, $old_instance ) { $new_instance[ $this->prefix ][ blocksy_post_name() ] = json_decode( $new_instance[ $this->prefix ][ blocksy_post_name() ], true ); return $new_instance[ $this->prefix ]; } public function form( $values ) { $this->read_options(); echo blocksy_output_options_panel( [ 'options' => $this->options, 'values' => blocksy_akg( blocksy_post_name(), $values ), 'id_prefix' => 'ct-widget-options-' . $this->get_field_id( $this->prefix ), 'name_prefix' => $this->get_field_name( $this->prefix ), 'attr' => [ 'data-disable-reverse-button' => '' ] ] ); return $values; } }