File "magzenpro-advertisement-20250501075235.php"
Full path: /var/www/html/cemeau/wp-content/themes/magzenpro/inc/widgets/magzenpro-advertisement-20250501075235.php
File size: 3.24 KB
MIME-type: text/x-php
Charset: utf-8
Download Open Edit Advanced Editor Back
<?php
/**
* MagZenPro Advertisement Widget
*/
class MagZenPro_Advertisement_Widget extends WP_Widget {
/**
* Register widget with WordPress.
*/
function __construct() {
parent::__construct(
'magzenpro-advertisement-widget', // Base ID
sprintf( esc_html__( '%s : Advertisement', 'magzenpro' ), wp_get_theme()->Name ), // Name
array( 'description' => __( 'Display Advertisement ', 'magzenpro' ), ) // Args
);
}
/**
* 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 ) {
echo $args['before_widget'];
$instance = wp_parse_args( $instance, array(
'src' => '',
'href'=> '',
'title' => '',
) );
$title = apply_filters( 'widget_title', $instance['title'] );
$args['before_title'] = '<h4 class="widget-title">';
$args['after_title'] = '</h4>';
if ( ! empty( $title ) ) {
echo $args['before_title'] .'<span class="mag-divider">'. $title .'</span>'. $args['after_title'];
} ?>
<div class="magzen-advertisement">
<div class="advertisement-content">
<a class="magzen-single-adds" href="<?php echo esc_url($instance['href']); ?>" target="_blank"><img src="<?php echo $instance['src'];?>"></a>
</div>
</div>
<?php echo $args['after_widget'];
}
/**
* Back-end widget form.
*
* @see WP_Widget::form()
*
* @param array $instance Previously saved values from database.
*/
public function form( $instance ) {
$instance = wp_parse_args( $instance, array(
'src' => '',
'href'=> '',
'title' => '',
) );
?>
<p>
<label for="<?php echo $this->get_field_id('title') ?>"><?php _e('Title', 'magzenpro') ?></label>
<input type="text" class="widefat" id="<?php echo $this->get_field_id('title') ?>" name="<?php echo $this->get_field_name('title') ?>" value="<?php echo esc_attr($instance['title']) ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('src') ?>"><?php _e('Advertisement Image URL', 'magzenpro') ?></label>
<input type="text" class="widefat" id="<?php echo $this->get_field_id('src') ?>" name="<?php echo $this->get_field_name('src') ?>" value="<?php echo esc_attr($instance['src']) ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('href') ?>"><?php _e('Advertisement Image Link', 'magzenpro') ?></label>
<input type="text" class="widefat" id="<?php echo $this->get_field_id('href') ?>" name="<?php echo $this->get_field_name('href') ?>" value="<?php echo esc_attr($instance['href']) ?>" />
</p>
<?php
}
/**
* Sanitize widget form values as they are saved.
*
* @see WP_Widget::update()
*
* @param array $new_instance Values just sent to be saved.
* @param array $old_instance Previously saved values from database.
*
* @return array Updated safe values to be saved.
*/
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['src'] = $new_instance['src'];
$instance['href'] = $new_instance['href'];
$instance['title'] = $new_instance['title'];
return $instance;
}
} // class Foo_Widget