Social Icons', 'chromatic' ); $settings['widget_options'] = array( 'description' => __('Display Social Icons', 'chromatic'), // 'classname' => 'hoot-social-icons-widget', // CSS class applied to frontend widget container via 'before_widget' arg ); $settings['control_options'] = array(); $settings['form_options'] = array( //'name' => can be empty or false to hide the name array( 'name' => __( 'Title (optional)', 'chromatic' ), 'id' => 'title', 'type' => 'text', ), array( 'name' => __( 'Icon Size', 'chromatic' ), 'id' => 'size', 'type' => 'select', 'std' => 'small', 'options' => array( 'small' => __( 'Small', 'chromatic' ), 'medium' => __( 'Medium', 'chromatic' ), 'large' => __( 'Large', 'chromatic' ), 'huge' => __( 'Huge', 'chromatic' ), ), ), array( 'name' => __( 'Social Icons', 'chromatic' ), 'id' => 'icons', 'type' => 'group', 'options' => array( 'item_name' => __( 'Icon', 'chromatic' ), ), 'fields' => array( array( 'name' => __( 'Social Icon', 'chromatic' ), 'id' => 'icon', 'type' => 'select', 'options' => hoot_enum_social_profiles(), ), array( 'name' => __( 'URL (enter username for Skype, email address for Email)', 'chromatic' ), 'id' => 'url', 'type' => 'text', 'sanitize' => 'social_icons_sanitize_url', ), ), ), array( 'name' => __( 'Widget CSS', 'chromatic' ), 'id' => 'customcss', 'type' => 'collapse', 'fields' => array( array( 'name' => __( 'Custom CSS Class', 'chromatic' ), 'desc' => __( 'Give this widget a custom css classname', 'chromatic' ), 'id' => 'class', 'type' => 'text', ), array( 'name' => __( 'Margin Top', 'chromatic' ), 'desc' => __( '(in pixels) Leave empty to load default margins', 'chromatic' ), 'id' => 'mt', 'type' => 'text', 'settings' => array( 'size' => 3 ), 'sanitize' => 'integer', ), array( 'name' => __( 'Margin Bottom', 'chromatic' ), 'desc' => __( '(in pixels) Leave empty to load default margins', 'chromatic' ), 'id' => 'mb', 'type' => 'text', 'settings' => array( 'size' => 3 ), 'sanitize' => 'integer', ), array( 'name' => __( 'Widget ID', 'chromatic' ), 'id' => 'widgetid', 'type' => '' . __( 'Save this widget to view its ID', 'chromatic' ) . '', ), ), ), ); $settings = apply_filters( 'hoot_social_icons_widget_settings', $settings ); parent::__construct( $settings['id'], $settings['name'], $settings['widget_options'], $settings['control_options'], $settings['form_options'] ); } /** * Echo the widget content */ function display_widget( $instance, $before_title = '', $title='', $after_title = '' ) { extract( $instance, EXTR_SKIP ); include( hoot_locate_widget( 'social-icons' ) ); // Loads the widget/social-icons or template-parts/widget-social-icons.php template. } } /** * Register Widget */ function hoot_social_icons_widget_register(){ register_widget('Hoot_Social_Icons_Widget'); } add_action('widgets_init', 'hoot_social_icons_widget_register'); /** * Custom Sanitization Function */ function hoot_social_icons_sanitize_url( $value, $name, $instance ){ if ( $name == 'social_icons_sanitize_url' ) { if ( !empty( $instance['icon'] ) && $instance['icon'] == 'fa-skype' ) $new = sanitize_user( $value, true ); elseif ( !empty( $instance['icon'] ) && $instance['icon'] == 'fa-envelope' ) $new = is_email( $value ); else $new = esc_url_raw( $value ); return $new; } return $value; } add_filter('widget_admin_sanitize_field', 'hoot_social_icons_sanitize_url', 10, 3);