'bp_advertisement_widget',
'description' => esc_html__( 'Widget for displaying ads', 'blue-planet' ),
);
parent::__construct( 'bp-advertisement', esc_html__( 'Blue Planet Advertisement', 'blue-planet' ), $opts );
}
/**
* Echo the widget content.
*
* @since 1.0.0
*
* @param array $args Display arguments including before_title, after_title,
* before_widget, and after_widget.
* @param array $instance The settings for the particular instance of the widget.
*/
function widget( $args, $instance ) {
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
$adcode = ! empty( $instance['adcode'] ) ? $instance['adcode'] : '';
$image = ! empty( $instance['image'] ) ? $instance['image'] : '';
$href = ! empty( $instance['href'] ) ? $instance['href'] : '';
$target = ! empty( $instance['target'] ) ? 'true' : 'false';
$alt = ! empty( $instance['alt'] ) ? $instance['alt'] : '';
echo $args['before_widget'];
if ( $title ) {
echo $args['before_title'] . $title . $args['after_title'];
}
if ( ! empty( $adcode ) ) {
echo $adcode;
} else {
echo '';
}
echo $args['after_widget'];
}
/**
* Update widget instance.
*
* @since 1.0.0
*
* @param array $new_instance New settings for this instance as input by the user via
* {@see WP_Widget::form()}.
* @param array $old_instance Old settings for this instance.
* @return array Settings to save or bool false to cancel saving.
*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = sanitize_text_field( $new_instance['title'] );
$instance['adcode'] = wp_kses_stripslashes( $new_instance['adcode'] );
$instance['image'] = esc_url( $new_instance['image'] );
$instance['href'] = esc_url( $new_instance['href'] );
$instance['target'] = ! empty( $new_instance['target'] ) ? 1 : 0;
$instance['alt'] = sanitize_text_field( $new_instance['alt'] );
return $instance;
}
/**
* Output the settings update form.
*
* @since 1.0.0
*
* @param array $instance Current settings.
*/
function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array(
'title' => '',
'adcode' => '',
'image' => '',
'href' => '',
'target' => 0,
'alt' => '',
)
);
$title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
$adcode = isset( $instance['adcode'] ) ? esc_textarea( $instance['adcode'] ) : '';
$image = isset( $instance['image'] ) ? esc_url( $instance['image'] ) : '';
$href = isset( $instance['href'] ) ? esc_url( $instance['href'] ) : '';
$target = isset( $instance['target'] ) ? esc_attr( $instance['target'] ) : '';
$alt = isset( $instance['alt'] ) ? esc_attr( $instance['alt'] ) : '';
?>
/>