'business_owner_static_counter', 'description' => __( 'Display contents as static counter.', 'business-owner' ) ); parent::__construct( 'business_static_counter', __( 'Business Owner: Static Counter', 'business-owner' ), $widget_ops ); } /** * Helper function that holds widget fields * Array is used in update and form functions */ private function widget_fields() { $fields = array( 'section_title' => array( 'owner_widgets_name' => 'section_title', 'owner_widgets_title' => __( 'Section Title', 'business-owner' ), 'owner_widgets_field_type' => 'text' ), 'section_bg_image' => array( 'owner_widgets_name' => 'section_bg_image', 'owner_widgets_title' => __( 'Section Background Image', 'business-owner' ), 'owner_widgets_field_type' => 'upload', ), ); return $fields; } /** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget( $args, $instance ) { extract( $args ); if( empty( $instance ) ) { return ; } $owner_section_title = empty( $instance['section_title'] ) ? '' : $instance['section_title']; $owner_section_bg_image = empty( $instance['section_bg_image'] ) ? '' : $instance['section_bg_image']; $get_static_static_counters_json = get_theme_mod( 'static_counters', '' ); if( !empty( $owner_section_menu_id ) ) { $owner_section_menu_id = 'id='.esc_attr( $owner_section_menu_id ); } if( !empty( $owner_section_title ) || !empty( $owner_section_info ) ) { $sec_title_class = 'has-title'; } else { $sec_title_class = 'no-title'; } echo $before_widget; ?>
counter_number ); ?>

counter_title ); ?>

widget_fields(); // Loop through fields foreach ( $widget_fields as $widget_field ) { extract( $widget_field ); // Use helper function to get updated field values $instance[$owner_widgets_name] = owner_widgets_updated_field_value( $widget_field, $new_instance[$owner_widgets_name] ); } return $instance; } /** * Back-end widget form. * * @see WP_Widget::form() * * @param array $instance Previously saved values from database. * * @uses owner_widgets_show_widget_field() defined in owner-widget-fields.php */ public function form( $instance ) { $widget_fields = $this->widget_fields(); // Loop through fields foreach ( $widget_fields as $widget_field ) { // Make array elements available as variables extract( $widget_field ); $owner_widgets_field_value = !empty( $instance[$owner_widgets_name] ) ? wp_kses_post( $instance[$owner_widgets_name] ) : ''; owner_widgets_show_widget_field( $this, $widget_field, $owner_widgets_field_value ); } } }