'', 'supermag_ad_image' => '', 'supermag_ad_link' => '', 'supermag_ad_new_window' => 1, 'supermag_ad_img_alt' => '' ); function __construct() { parent::__construct( /*Base ID of your widget*/ 'supermag_ad', /*Widget name will appear in UI*/ __('AT Advertisement', 'supermag'), /*Widget description*/ array( 'description' => __( 'Add advertisement with different options.', 'supermag' ), ) ); } /*Widget Backend*/ public function form( $instance ) { /*merging arrays*/ $instance = wp_parse_args( (array) $instance, $this->defaults); $supermag_ad_title = esc_attr( $instance['supermag_ad_title'] ); $supermag_ad_image = esc_url( $instance['supermag_ad_image'] ); $supermag_ad_link = esc_url( $instance['supermag_ad_link'] ); $supermag_ad_new_window = esc_attr( $instance['supermag_ad_new_window'] ); $supermag_ad_img_alt = esc_attr( $instance['supermag_ad_img_alt'] ); ?>

> <?php _e( 'Image preview', 'supermag' ); ?>

/>


defaults); $supermag_ad_title = apply_filters( 'widget_title', $instance['supermag_ad_title'], $instance, $this->id_base ); $supermag_ad_image = esc_url( $instance['supermag_ad_image'] ); $supermag_ad_link = esc_url( $instance['supermag_ad_link'] ); $supermag_ad_new_window = esc_attr( $instance['supermag_ad_new_window'] ); $supermag_ad_img_alt = esc_attr( $instance['supermag_ad_img_alt'] ); echo $args['before_widget']; if ( !empty($supermag_ad_title) ) { echo $args['before_title'] . $supermag_ad_title . $args['after_title']; } $ad_content_image = ''; if ( ! empty( $supermag_ad_image ) ) { /*creating add*/ $img_html = ''.$supermag_ad_img_alt . ''; $link_open = ''; $link_close = ''; if ( ! empty( $supermag_ad_link ) ) { $target_text = ( 1 == $supermag_ad_new_window ) ? ' target="_blank" ' : ''; $link_open = ''; $link_close = ''; } $ad_content_image = $link_open . $img_html . $link_close; } if ( !empty( $ad_content_image ) ) { echo '
'; echo $ad_content_image; echo '
'; } echo $args['after_widget']; } } endif; if ( ! function_exists( 'supermag_ad_widget' ) ) : /** * Function to Register and load the widget * * @since 1.0 * * @param null * @return void * */ function supermag_ad_widget() { register_widget( 'supermag_ad_widget' ); } endif; add_action( 'widgets_init', 'supermag_ad_widget' );