2014-09-08 02:23:45 +02:00
< ? php
/**
2014-10-23 18:16:47 +02:00
* Payment Methods widget
2014-09-08 02:23:45 +02:00
*
2015-04-24 20:13:22 +02:00
* @package vendocrat
* @subpackage Payment Methods
2014-09-08 02:23:45 +02:00
*
2015-04-24 20:13:22 +02:00
* @since 2014-09-08
* @version 2015-04-24
2014-09-08 02:23:45 +02:00
*
2015-04-24 20:13:22 +02:00
* @author Poellmann Alexander Manfred (@AMPoellmann)
* @copyright Copyright 2015 vendocrat. All Rights Reserved.
* @link https://vendocr.at/
2014-09-08 02:23:45 +02:00
*/
if ( ! defined ( 'ABSPATH' ) ) exit ; // Exit if accessed directly
2014-10-23 18:16:47 +02:00
class vendocrat_Widget_WC_Payment_Methods extends WP_Widget {
2014-09-08 02:23:45 +02:00
public $slug ;
public $name ;
public $desc ;
public $title ;
/**
* Construct Widget
*
* @since 2014-09-08
* @version 2014-09-08
**************************************************/
function __construct () {
2014-09-22 01:02:13 +02:00
$this -> slug = 'vendocrat_payment_methods' ;
2014-10-23 18:16:47 +02:00
$this -> name = __ ( 'Payment Methods' , 'woocommerce-payment-methods' );
$this -> desc = __ ( 'Easily display your accepted payment methods' , 'woocommerce-payment-methods' );
$this -> title = __ ( 'Accepted Payment Methods' , 'woocommerce-payment-methods' );
2014-09-08 02:23:45 +02:00
parent :: __construct (
$this -> slug ,
'vendocrat: ' . $this -> name ,
array (
'description' => $this -> desc ,
)
);
}
/**
* Front-end display of widget
*
* @param array $args Widget arguments.
* @param array $instance Saved values from database.
* @return void
*
* @since 2014-09-08
2014-09-15 03:19:28 +02:00
* @version 2014-09-15
2014-09-08 02:23:45 +02:00
**************************************************/
public function widget ( $args , $instance ) {
$title = apply_filters ( 'widget_title' , $instance [ 'title' ] );
2014-09-22 01:02:13 +02:00
$methods = $instance [ 'methods' ];
2014-09-15 03:19:28 +02:00
$style = $instance [ 'style' ];
$tooltip = ( $instance [ 'tooltip' ] != 'true' ) ? false : true ;
$placement = $instance [ 'placement' ];
$xclass = $instance [ 'xclass' ];
2014-09-08 02:23:45 +02:00
extract ( $args );
echo $before_widget ;
if ( $title ) {
echo $before_title . $title . $after_title ;
}
2014-10-23 18:16:47 +02:00
global $vendocrat_wc_payment_methods ;
2014-09-08 02:23:45 +02:00
$atts = array (
2014-09-22 01:02:13 +02:00
'methods' => $methods ,
'style' => $style ,
'tooltip' => $tooltip ,
'placement' => $placement ,
'xclass' => $xclass ,
2014-09-08 02:23:45 +02:00
);
2014-10-23 18:16:47 +02:00
echo $vendocrat_wc_payment_methods -> get_payment_methods ( $atts );
2014-09-08 02:23:45 +02:00
echo $after_widget ;
}
/**
* Back-end widget form
*
* @param array $instance Previously saved values from database.
*
* @since 2014-09-08
2014-09-15 03:19:28 +02:00
* @version 2014-09-15
2014-09-08 02:23:45 +02:00
**************************************************/
public function form ( $instance ) {
$defaults = array (
2014-09-22 01:02:13 +02:00
'title' => $this -> title ,
'methods' => '' ,
'style' => 'default' ,
'tooltip' => 'false' ,
'placement' => 'bottom' ,
'xclass' => '' ,
2014-09-08 02:23:45 +02:00
);
$instance = wp_parse_args ( ( array ) $instance , $defaults );
?>
<p>
2014-10-23 18:16:47 +02:00
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title', 'woocommerce-payment-methods' ); ?>:</label>
2014-09-08 02:23:45 +02:00
<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( $instance['title'] ); ?>" />
</p>
<p>
2014-10-23 18:16:47 +02:00
<label for="<?php echo $this->get_field_id( 'style' ); ?>"><?php _e( 'Style', 'woocommerce-payment-methods' ); ?>:</label>
2014-09-08 02:23:45 +02:00
<select name="<?php echo $this->get_field_name( 'style' ); ?>" class="widefat" id="<?php echo $this->get_field_id( 'style' ); ?>">
2014-10-23 18:16:47 +02:00
<option value="default"<?php selected( $instance['style'], 'default' ); ?>><?php _e( 'Default', 'woocommerce-payment-methods' ); ?></option>
<option value="inverse"<?php selected( $instance['style'], 'inverse' ); ?>><?php _e( 'Inverse', 'woocommerce-payment-methods' ); ?></option>
<option value="o"<?php selected( $instance['style'], 'o' ); ?>><?php _e( 'Outline', 'woocommerce-payment-methods' ); ?></option>
2014-09-08 02:23:45 +02:00
</select>
</p>
<p>
2014-10-23 18:16:47 +02:00
<label for="<?php echo $this->get_field_id( 'tooltip' ); ?>"><?php _e( 'Add Tooltip markup?', 'woocommerce-payment-methods' ); ?></label>
2014-09-08 02:23:45 +02:00
<select name="<?php echo $this->get_field_name( 'tooltip' ); ?>" class="widefat" id="<?php echo $this->get_field_id( 'tooltip' ); ?>">
2014-10-23 18:16:47 +02:00
<option value="false"<?php selected( $instance['tooltip'], 'false' ); ?>><?php _e( 'No', 'woocommerce-payment-methods' ); ?></option>
<option value="true"<?php selected( $instance['tooltip'], 'true' ); ?>><?php _e( 'Yes', 'woocommerce-payment-methods' ); ?></option>
2014-09-08 02:23:45 +02:00
</select>
</p>
2014-09-15 03:19:28 +02:00
<p>
2014-10-23 18:16:47 +02:00
<label for="<?php echo $this->get_field_id( 'placement' ); ?>"><?php _e( 'Placement', 'woocommerce-payment-methods' ); ?>:</label>
2014-09-15 03:19:28 +02:00
<select name="<?php echo $this->get_field_name( 'placement' ); ?>" class="widefat" id="<?php echo $this->get_field_id( 'placement' ); ?>">
2014-10-23 18:16:47 +02:00
<option value="top"<?php selected( $instance['placement'], 'top' ); ?>><?php _e( 'Top', 'woocommerce-payment-methods' ); ?></option>
<option value="right"<?php selected( $instance['placement'], 'right' ); ?>><?php _e( 'Right', 'woocommerce-payment-methods' ); ?></option>
<option value="bottom"<?php selected( $instance['placement'], 'bottom' ); ?>><?php _e( 'Bottom', 'woocommerce-payment-methods' ); ?></option>
<option value="left"<?php selected( $instance['placement'], 'left' ); ?>><?php _e( 'Left', 'woocommerce-payment-methods' ); ?></option>
2014-09-15 03:19:28 +02:00
</select>
</p>
2014-09-08 02:23:45 +02:00
<p>
2014-10-23 18:16:47 +02:00
<label for="<?php echo $this->get_field_id('xclass'); ?>"><?php _e( 'Extra classes', 'woocommerce-payment-methods' ); ?>:</label>
2014-09-08 02:23:45 +02:00
<input class="widefat" id="<?php echo $this->get_field_id('xclass'); ?>" name="<?php echo $this->get_field_name('xclass'); ?>" type="text" value="<?php echo esc_attr( $instance['xclass'] ); ?>" />
</p>
2015-04-24 20:13:22 +02:00
<p>
<label for="<?php echo $this->get_field_id('methods'); ?>"><?php _e( 'Payment Methods', 'woocommerce-payment-methods' ); ?>:</label>
<input class="widefat" id="<?php echo $this->get_field_id('methods'); ?>" name="<?php echo $this->get_field_name('methods'); ?>" type="text" value="<?php echo esc_attr( $instance['methods'] ); ?>" />
<i><?php echo '<strong>'. __( 'Optional', 'woocommerce-payment-methods' ) . ':</strong> ' . sprintf( __( 'Specify payment methods to be shown manually by entering their slugs comma separated (eg. "paypal,visa,mastercard" for PayPal, Visa and MasterCard). See %s for available payment methods an their slugs! If left blank the widget will try to automatically fetch available payment methods from WooCommerce.', 'woocommerce-payment-methods' ), '<a href="http://paymentfont.io" target="_blank">PaymentFont.io</a>' ); ?></i>
</p>
2014-09-08 02:23:45 +02:00
<?php
}
/**
* Sanitize widget form values as they are saved
*
* @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 = $old_instance;
2014-09-15 03:19:28 +02:00
$instance['title'] = strip_tags( $new_instance['title'] );
2014-09-22 01:02:13 +02:00
$instance['methods'] = esc_attr( $new_instance['methods'] );
2014-09-15 03:19:28 +02:00
$instance['style'] = esc_attr( $new_instance['style'] );
$instance['tooltip'] = esc_attr( $new_instance['tooltip'] );
$instance['placement'] = esc_attr( $new_instance['placement'] );
$instance['xclass'] = esc_attr( $new_instance['xclass'] );
2014-09-08 02:23:45 +02:00
return $instance;
}
} // END Class
/*
2014-09-22 01:28:22 +02:00
* E fatto!
2014-09-08 02:23:45 +02:00
*/