zZzzZ.
home2
/
zrzvbdry
/
airuzu.com
/
wp-content
/
themes
/
savings-pro-main
/
inc
/
widgets
New Folder
Editing: exclusive-offer.php
Save
Cancel
<?php /** * Add Exclusive offer widget. */ class WPCoupon_Exclusive_Offer_Widget extends WP_Widget { /** * Register widget with WordPress. */ function __construct() { parent::__construct( 'exclusive_offer', // Base ID esc_html__( 'Savings Pro Exclusive Offer', 'savings-pro' ), // Name array( 'description' => esc_html__( 'Display exclusive offers With Link', 'savings-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' => '', 'url' => '', 'widget_title_color' => '', 'item_title_color' => '', ) ); $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', 'savings-pro' ); ?></a> </div> <div class="element-settings"> <div class="element"> <label><?php esc_attr_e( 'Title', 'savings-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"> </div> <div class="element"> <label><?php esc_attr_e( 'URL', 'savings-pro' ); ?></label> <input type="text" name="<?php echo $this->get_field_name( 'fake' ); ?>" value="<?php echo esc_attr( $value['url'] ); ?>" data-name="url" class="widefat"> </div> </div> <div class="actions"> <a href="#" class="remove"><?php esc_attr_e( 'Remove', 'savings-pro' ); ?></a>|<a href="#" class="close"><?php esc_attr_e( 'Close', 'savings-pro' ); ?></a> </div> </div> </div> <?php } public function form( $instance ) { $instance = wp_parse_args( $instance, array( 'title' => '', 'items' => array(), 'widget_title_color' => '', 'item_title_color' => '', ) ); $id = uniqid('widget-ui-'); $name = $this->get_field_name( 'items' ); $title = ! empty( $instance['title'] ) ? $instance['title'] : esc_html__( 'Featured Discounts and Promo Codes', 'savings-pro' ); $widget_title_color = ! empty( $instance['widget_title_color'] ) ? $instance['widget_title_color'] : esc_html__( '#07525d', 'savings-pro' ); $item_title_color = ! empty( $instance['item_title_color'] ) ? $instance['item_title_color'] : esc_html__( '#07525d', 'savings-pro' ); ?> <p> <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:', 'savings-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 ); ?>"> </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', 'savings-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 --> <p> <label style="float:left;width:120px;" for="<?php echo $this->get_field_id( 'widget_title_color' ); ?>"><?php esc_html_e( 'Widget Title Color:', 'savings-pro' ); ?></label> <input class="widefat widget_title_color" id="<?php echo $this->get_field_id( 'widget_title_color' ); ?>" name="<?php echo $this->get_field_name( 'widget_title_color' ); ?>" type="color" value="<?php echo esc_attr( $widget_title_color ); ?>" style="padding: 0px 2px;height: 25px;width: 38px;position: relative;top: 4px;left: 4px;"> </p> <p> <label style="float:left;width:120px;" for="<?php echo $this->get_field_id( 'item_title_color' ); ?>"><?php esc_html_e( 'Item Font Color:', 'savings-pro' ); ?></label> <input class="widefat item_title_color" id="<?php echo $this->get_field_id( 'item_title_color' ); ?>" name="<?php echo $this->get_field_name( 'item_title_color' ); ?>" type="color" value="<?php echo esc_attr( $item_title_color ); ?>" style="padding: 0px 2px;height: 25px;width: 38px;position: relative;top: 4px;left: 4px;"> </p> <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"> <h3 class="saletitle font-semibold font-serif" <?php echo isset($instance['widget_title_color'])? 'style="color:'.esc_attr( $instance['widget_title_color'] ).'"': ""; ?>> <?php if ( ! empty( $instance['title'] ) ) { echo apply_filters( 'widget_title', $instance['title'] ); } ?> </h3> </div> <div class="best-sale-items"> <?php foreach( $instance['items'] as $i => $item ) { $item = wp_parse_args( $item, array( 'image_url' => '', 'image_id' => '', 'title' => '', 'url' => '', ) ); $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"> <a href="<?php if( ! empty( $item['url'] ) ) echo $item['url']; ?>" target="_blank" rel="noopener"> <div class="banner-img"> <img src="<?php echo esc_url( $image_url ) ?>" alt="<?php echo esc_attr( $image_alt ) ?>"> </div> <div class="bls-title" <?php echo isset($instance['item_title_color'])? 'style="color:'.esc_attr( $instance['item_title_color'] ).'"': ""; ?>> <?php if( !empty( $item['url'] ) ) echo esc_attr( $item['title'] ); ?> </div> </a> </div> <?php } ?> </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' );