mirror of
https://github.com/10h30/WooCommerce-Payment-Methods.git
synced 2026-06-05 15:07:59 +09:00
a4e13eead1
Fixed an error in widget class, added placement option to tooltips, updated language files.
159 lines
5.9 KiB
PHP
159 lines
5.9 KiB
PHP
<?php
|
|
/**
|
|
* vendocrat Payment Methods widget
|
|
*
|
|
* @package vendocrat
|
|
* @subpackage Payment Methods/Classes
|
|
*
|
|
* @since 2014-09-08
|
|
* @version 2014-09-15
|
|
*
|
|
* @author Poellmann Alexander Manfred <alex@vendocr.at>
|
|
* @copyright Copyright 2014 vendocrat. All Rights Reserved.
|
|
* @link http://vendocr.at/
|
|
*/
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|
|
|
class vendocrat_Widget_Payment_Methods extends WP_Widget {
|
|
|
|
public $slug;
|
|
public $name;
|
|
public $desc;
|
|
public $title;
|
|
|
|
/**
|
|
* Construct Widget
|
|
*
|
|
* @since 2014-09-08
|
|
* @version 2014-09-08
|
|
**************************************************/
|
|
function __construct() {
|
|
$this->slug = 'vendocrat_widget_payment_methods';
|
|
$this->name = __( 'Payment Methods', 'vendocrat-payment-methods' );
|
|
$this->desc = __( 'Easily display your accepted payment methods', 'vendocrat-payment-methods' );
|
|
$this->title = __( 'Accepted Payment Methods', 'vendocrat-payment-methods' );
|
|
|
|
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
|
|
* @version 2014-09-15
|
|
**************************************************/
|
|
public function widget( $args, $instance ) {
|
|
$title = apply_filters( 'widget_title', $instance['title'] );
|
|
|
|
$style = $instance['style'];
|
|
$tooltip = ($instance['tooltip'] != 'true') ? false : true;
|
|
$placement = $instance['placement'];
|
|
$xclass = $instance['xclass'];
|
|
|
|
extract($args);
|
|
|
|
echo $before_widget;
|
|
|
|
if ( $title ) {
|
|
echo $before_title . $title . $after_title;
|
|
}
|
|
|
|
global $vendocrat_woo_payment_methods;
|
|
|
|
$atts = array(
|
|
'style' => $style,
|
|
'tooltip' => $tooltip,
|
|
'xclass' => $xclass,
|
|
);
|
|
echo $vendocrat_woo_payment_methods->get_payment_methods( $atts );
|
|
|
|
echo $after_widget;
|
|
}
|
|
|
|
/**
|
|
* Back-end widget form
|
|
*
|
|
* @param array $instance Previously saved values from database.
|
|
*
|
|
* @since 2014-09-08
|
|
* @version 2014-09-15
|
|
**************************************************/
|
|
public function form( $instance ) {
|
|
$defaults = array(
|
|
'title' => $this->title,
|
|
'style' => 'default',
|
|
'tooltip' => 'false',
|
|
'xclass' => '',
|
|
);
|
|
$instance = wp_parse_args( (array) $instance, $defaults );
|
|
?>
|
|
<p>
|
|
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title', 'vendocrat-payment-methods' ); ?>:</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( $instance['title'] ); ?>" />
|
|
</p>
|
|
<p>
|
|
<label for="<?php echo $this->get_field_id( 'style' ); ?>"><?php _e( 'Style', 'vendocrat-payment-methods' ); ?>:</label>
|
|
<select name="<?php echo $this->get_field_name( 'style' ); ?>" class="widefat" id="<?php echo $this->get_field_id( 'style' ); ?>">
|
|
<option value="default"<?php selected( $instance['style'], 'default' ); ?>><?php _e( 'Default', 'vendocrat-payment-methods' ); ?></option>
|
|
<option value="inverse"<?php selected( $instance['style'], 'inverse' ); ?>><?php _e( 'Inverse', 'vendocrat-payment-methods' ); ?></option>
|
|
<option value="o"<?php selected( $instance['style'], 'o' ); ?>><?php _e( 'Outline', 'vendocrat-payment-methods' ); ?></option>
|
|
</select>
|
|
</p>
|
|
<p>
|
|
<label for="<?php echo $this->get_field_id( 'tooltip' ); ?>"><?php _e( 'Add Tooltip markup?', 'vendocrat-payment-methods' ); ?></label>
|
|
<select name="<?php echo $this->get_field_name( 'tooltip' ); ?>" class="widefat" id="<?php echo $this->get_field_id( 'tooltip' ); ?>">
|
|
<option value="false"<?php selected( $instance['tooltip'], 'false' ); ?>><?php _e( 'No', 'vendocrat-payment-methods' ); ?></option>
|
|
<option value="true"<?php selected( $instance['tooltip'], 'true' ); ?>><?php _e( 'Yes', 'vendocrat-payment-methods' ); ?></option>
|
|
</select>
|
|
</p>
|
|
<p>
|
|
<label for="<?php echo $this->get_field_id( 'placement' ); ?>"><?php _e( 'Placement', 'vendocrat-payment-methods' ); ?>:</label>
|
|
<select name="<?php echo $this->get_field_name( 'placement' ); ?>" class="widefat" id="<?php echo $this->get_field_id( 'placement' ); ?>">
|
|
<option value="top"<?php selected( $instance['placement'], 'top' ); ?>><?php _e( 'Top', 'vendocrat-payment-methods' ); ?></option>
|
|
<option value="right"<?php selected( $instance['placement'], 'right' ); ?>><?php _e( 'Right', 'vendocrat-payment-methods' ); ?></option>
|
|
<option value="bottom"<?php selected( $instance['placement'], 'bottom' ); ?>><?php _e( 'Bottom', 'vendocrat-payment-methods' ); ?></option>
|
|
<option value="left"<?php selected( $instance['placement'], 'left' ); ?>><?php _e( 'Left', 'vendocrat-payment-methods' ); ?></option>
|
|
</select>
|
|
</p>
|
|
<p>
|
|
<label for="<?php echo $this->get_field_id('xclass'); ?>"><?php _e( 'Extra classes', 'vendocrat-payment-methods' ); ?>:</label>
|
|
<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>
|
|
<?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;
|
|
|
|
$instance['title'] = strip_tags( $new_instance['title'] );
|
|
$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'] );
|
|
|
|
return $instance;
|
|
}
|
|
|
|
} // END Class
|
|
|
|
/*
|
|
* NO MORE LOVE TO GIVE
|
|
*/
|