zZzzZ.
home2
/
zrzvbdry
/
couponetive.com
/
wp-content
/
themes
/
retail-pro-main
/
inc
/
widgets
New Folder
Editing: exclusive-offer.php
Save
Cancel
<?php /** * Add Slider widget. */ class WPCoupon_Exclusive_Offer_Widget extends WP_Widget { /** * Register widget with WordPress. */ function __construct() { parent::__construct( 'exclusive_offer', // Base ID esc_html__( 'RetailPro Front Page Exclusive Offer', 'retail-pro' ), // Name array( 'description' => esc_html__( 'Display exclusive offers With Link', 'retail-pro' ), 'classname' => 'best-live-sale-section' ), // Args array( 'width' => 530 ) ); } public function item( $name, $value = array(), $closed = true ){ $value = wp_parse_args( $value, array( 'image_url' => '', 'image_id' => '', 'title' => '', 'sub-title' => '', 'link_action' => '', 'store-id' => '', // 'url' => '', ) ); $class = $closed ? 'closed': ''; $image_url = ''; if ( $value['image_id'] > 0 ) { $image_attributes = wp_get_attachment_image_src( $value['image_id'] ); // returns an array if ( $image_attributes ) { $image_url = $image_attributes[0]; } } ?> <div data-name="<?php echo esc_attr( $name ); ?>" class="item <?php echo esc_attr( $class );?>"> <div class="handle"> <span class="item-index"></span> <span class="ellipsis live-item-title"></span> <a href="#" class="toggle"></a> </div> <div class="item-settings"> <div class="image-upload-wrapper element-thumbnail"> <div class="image-upload thumb-preview"> <?php if ( $image_url != '' ){ ?> <img src="<?php echo esc_attr( $image_url ); ?>" alt=""> <?php } ?> <input type="hidden" name="<?php echo $this->get_field_name( 'fake' ); ?>" value="<?php echo esc_attr( $image_url != '' ? $image_url : $value['image_url'] ); ?>" class="image_url" data-name="image_url"> <input type="hidden" name="<?php echo $this->get_field_name( 'fake' ); ?>" value="<?php echo esc_attr( $value['image_id'] ); ?>" class="image_id" data-name="image_id" > </div> <a class="remove-thumbnail" href="#"><?php esc_attr_e( 'Remove', 'retail-pro' ); ?></a> </div> <div class="element-settings"> <div class="element"> <label><?php esc_attr_e( 'Title', 'retail-pro' ); ?></label> <input type="text" name="<?php echo $this->get_field_name( 'fake' ); ?>" value="<?php echo esc_attr( $value['title'] ); ?>" data-name="title" class="live-title widefat" placeholder="Please enter a title"> </div> <div class="element"> <label><?php esc_attr_e( 'Sub Title', 'retail-pro' ); ?></label> <input type="text" name="<?php echo $this->get_field_name( 'fake' ); ?>" value="<?php echo esc_attr( $value['sub-title'] ); ?>" data-name="sub-title" class="live-sub-title widefat" placeholder="Please enter a sub-title"> </div> <div class="element"> <label for="<?php echo $this->get_field_id('link_action'); ?>">Link Action Select:</label> <input type="text" name="<?php echo $this->get_field_name( 'fake' ); ?>" value="<?php echo esc_attr( $value['link_action'] ); ?>" data-name="link_action" list="link_action_list" id="link_action" class="link_action widefat" placeholder="Please select link action type" required> <datalist id="link_action_list"> <option value="Same Tab"> <option value="New Tab"> </datalist> </div> <div class="element"> <label><?php esc_attr_e( 'Select Store', 'retail-pro' ); ?></label> <?php $categories = get_categories('taxonomy=coupon_store&post_type=coupon'); ?> <input type="text" name="<?php echo $this->get_field_name( 'fake' ); ?>" value="<?php echo esc_attr( $value['store-id'] ); ?>" data-name="store-id" list="brow" id="shop_id" class="live-store-name widefat" placeholder="Please select a store" required> <datalist id="brow"> <?php foreach ($categories as $category) : ?> <option value="<?php echo $category->term_id; ?>"><?php echo $category->name; ?></option> <?php endforeach; ?> </datalist> </div> </div> <div class="actions"> <a href="#" class="remove"><?php esc_attr_e( 'Remove', 'retail-pro' ); ?></a> | <a href="#" class="close"><?php esc_attr_e( 'Close', 'retail-pro' ); ?></a> </div> </div> </div> <?php } public function form( $instance ) { $instance = wp_parse_args( $instance, array( 'title' => '', 'items' => array() ) ); $id = uniqid('widget-ui-'); $name = $this->get_field_name( 'items' ); $title = ! empty( $instance['title'] ) ? $instance['title'] : esc_html__( 'Best Online Live Sale', 'retail-pro' ); ?> <p> <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:', 'retail-pro' ); ?></label> <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" placeholder="Please input your widget title"> </p> <div class="st-widget-ui-items" id="<?php echo esc_attr( $id ); ?>"> <div class="ui-items"> <?php foreach( $instance['items'] as $item ) { $this->item( $name, $item ); } ?> </div><!-- /.ui-items --> <a href="#" class="button-secondary new-item"><?php esc_html_e( 'Add item', 'retail-pro' ); ?></a> <script type="text/template" class="widget-ui-template" id="<?php echo esc_attr( $id ); ?>_template"> <?php $this->item( $name, array(), false ); ?> </script> </div><!-- /.st-widget-ui-items --> <script type="text/javascript"> jQuery( document).ready( function( $ ){ // $( "#sortable" ).sortable(); new ST_Widgets( "<?php echo esc_js( $id ) ?>" ); } ); </script> <?php } /** * 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 ) { $instance = wp_parse_args( $instance, array( 'title' => '', 'items' => array() ) ); echo $args['before_widget']; ?> <div class="livesale-title"> <h1 class="saletitle font-semibold font-serif"> <?php if ( ! empty( $instance['title'] ) ) { echo apply_filters( 'widget_title', $instance['title'] ); } ?> </h1> </div> <div class="best-sale-item-wrap"> <div class="best-sale-items"> <?php foreach( $instance['items'] as $i => $item ) { $item = wp_parse_args( $item, array( 'image_url' => '', 'image_id' => '', 'title' => '', 'sub-title' => '', 'link_action' => '', 'store-id' => '', ) ); $image_url = ''; $image_alt = ''; if ( $item['image_id'] > 0 ) { $image_attributes = wp_get_attachment_image_src( $item['image_id'], 'full' ); // returns an array $image_alt = get_post_meta( $item['image_id'], '_wp_attachment_image_alt', true); if ( $image_attributes ) { $image_url = $image_attributes[0]; } } if ( ! $image_url ) { $image_url = $item['image_url']; } if ( ! $image_url ) { continue; } ?> <div class="sale-item"> <?php $store_id = $item['store-id'] ;?> <?php $link_action = $item['link_action']; if($link_action == 'Same Tab'){ ?> <a href="<?php echo wpcoupon_store($store_id)->get_url();?>" rel="noopener"> <div class="banner-img" style="background-image:url('<?php echo esc_url( $image_url ) ?>');"> <?php // echo esc_attr( $image_alt ) ?> </div> <div class="sale-item-info"> <div class="shop-img"> <?php echo wpcoupon_store($store_id)->get_thumbnail(); ?> </div> <div class="sell-item-txt"> <div class="bls-title"> <?php if( !empty( $item['title'] ) ) echo esc_attr( $item['title'] ); ?> </div> <div class="bls-sub-title"> <?php if( !empty( $item['sub-title'] ) ) echo esc_attr( $item['sub-title'] ); ?> </div> </div> </div> </a> <?php }elseif($link_action == 'New Tab'){ ?> <a href="<?php echo wpcoupon_store($store_id)->get_url();?>" target="_blank" rel="noopener"> <div class="banner-img" style="background-image:url('<?php echo esc_url( $image_url ) ?>');"> <?php // echo esc_attr( $image_alt ) ?> </div> <div class="sale-item-info"> <div class="shop-img"> <?php echo wpcoupon_store($store_id)->get_thumbnail(); ?> </div> <div class="sell-item-txt"> <div class="bls-title"> <?php if( !empty( $item['title'] ) ) echo esc_attr( $item['title'] ); ?> </div> <div class="bls-sub-title"> <?php if( !empty( $item['sub-title'] ) ) echo esc_attr( $item['sub-title'] ); ?> </div> </div> </div> </a> <?php }else{ ?> <a href="<?php echo wpcoupon_store($store_id)->get_url();?>" rel="noopener"> <div class="banner-img" style="background-image:url('<?php echo esc_url( $image_url ) ?>');"> <?php // echo esc_attr( $image_alt ) ?> </div> <div class="sale-item-info"> <div class="shop-img"> <?php echo wpcoupon_store($store_id)->get_thumbnail(); ?> </div> <div class="sell-item-txt"> <div class="bls-title"> <?php if( !empty( $item['title'] ) ) echo esc_attr( $item['title'] ); ?> </div> <div class="bls-sub-title"> <?php if( !empty( $item['sub-title'] ) ) echo esc_attr( $item['sub-title'] ); ?> </div> </div> </div> </a> <?php } ?> </div> <?php } ?> </div> </div><!-- END .best-sell-items --> <?php echo $args['after_widget']; } /** * 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(); //$new_instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : ''; return $new_instance; } } // class Popular_Store // register Foo_Widget widget function wpcoupon_register_exclusive_offer_widget() { register_widget( 'WPCoupon_Exclusive_Offer_Widget' ); } add_action( 'widgets_init', 'wpcoupon_register_exclusive_offer_widget' );