Create New Item
×
Item Type
File
Folder
Item Name
×
Search file in folder and subfolders...
File Manager
/
wp-content
/
themes
/
magzenpro
/
inc
/
widgets
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
<?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