defaults = array(
'title' => '',
);
$this->form_fields = array(
'title' => array(
"title" => __( 'Title:', 'brands-for-woocommerce' ),
'type' => 'text',
'class' => 'width100',
),
);
$this->shortcode_args = array();
parent::__construct( $widget_name, $widget_title, $args );
}
protected function set_cache_key( $instance ) {
if ( !empty( $instance['cache_key'] ) ) return $instance;
$instance['cache_key'] = $this->id . brfr_language_prefix();
return $instance;
}
protected function replace_shortcode_keys( $instance ) {
foreach ( $this->shortcode_args as $old => $new ) {
if ( !isset( $instance[ $new ] ) && isset( $instance[ $old ] ) ) {
$instance[ $new ] = $instance[ $old ];
}
}
return $instance;
}
protected function get_size( $side, $atts ) {
if ( empty( $atts[$side] ) ) return $atts;
$size = $atts[$side];
if ( is_numeric( $size ) ) {
if ( empty( $atts["{$side}_units"] ) ) {
$atts["{$side}_units"] = 'px';
}
} else {
$size_numeric = intval( $size );
$atts["{$side}_units"] = str_replace( $size_numeric, '', $size );
$atts[$side] = $size_numeric;
}
return $atts;
}
// $args = array( 'attributes' => [ options for
';
}
private function form_field_autocomplete( $name, $instance, $args = array() ) {
$field_id = $this->get_field_id( $name );
$field_name = $this->get_field_name( $name );
$field_value = esc_attr( $instance[$name] );
$title = empty( $args['title'] ) ? '' : "";
$class = empty( $args['class'] ) ? '' : $args['class'];
$id = empty( $args['id'] ) ? '' : "id='{$args['id']}'";
$input_class = empty( $args['input_class'] ) ? '' : $args['input_class'];
$placeholder = empty( $args['placeholder'] ) ? '' : "placeholder='{$args['placeholder']}'";
// $selected_brands = empty( $instance[$name] ) ? array() : array_map( function($v) {
// $term = get_term_by( 'term_id', $v, BeRocket_product_brand::$taxonomy_name ); return $term->term_id; },
// unserialize( $instance[$name] ) );
return
"
$title
";
}
private function form_field_fieldset( $name, $instance, $args = array() ) {
if ( empty( $args['items'] ) ) return;
$title = empty( $args['title'] ) ? '' : $args['title'];
$this->render_form_fields(
"", $args['items'], $instance );
}
private function render_form_fields( $before, $after, $fields_array, $instance ) {
echo $before;
foreach ( $fields_array as $name => $fields ) {
$function = "form_field_{$fields['type']}";
// $options = empty( $fields['attributes'] ) ? array() : $fields['attributes'];
echo $this->$function( $name, $instance, $fields );
}
echo $after;
}
public function form($instance) {
$instance = $this->replace_shortcode_keys( $instance );
$instance = wp_parse_args( (array)$instance, $this->defaults );
$this->render_form_fields( "", "
", $this->form_fields, $instance );
}
public function update( $new_instance, $old_instance ) {
// $instance = $old_instance;
foreach ( array_keys( $this->defaults ) as $name ) {
$instance[$name] = empty( $new_instance[$name] ) ? '' : strip_tags( $new_instance[$name] );
}
return $instance;
}
public function widget( $args, $instance ) {
if ( empty( $args['template'] ) ) return;
ob_start();
$BeRocket_product_brand = BeRocket_product_brand::getInstance();
$BeRocket_product_brand->br_get_template_part( $args['template'] );
$content = ob_get_clean();
if( $content ) {
echo $args['before_widget'];
if ( !empty( $instance['title'] ) ) echo $args['before_title'], $instance['title'], $args['after_title'];
echo $content;
echo $args['after_widget'];
}
}
}