| 1 |
<?php |
| 2 |
/** |
| 3 |
* @file wp-content/plugins/wordpress-plugin/includes/widget.php |
| 4 |
* Mailgun-wordpress-plugin - Sending mail from Wordpress using Mailgun |
| 5 |
* Copyright (C) 2016 Mailgun, et al. |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation; either version 2 of the License, or |
| 10 |
* (at your option) any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License along |
| 18 |
* with this program; if not, write to the Free Software Foundation, Inc., |
| 19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 |
* |
| 21 |
* @package Mailgun |
| 22 |
*/ |
| 23 |
class List_Widget extends \WP_Widget { |
| 24 |
|
| 25 |
/** |
| 26 |
* Register widget with WordPress. |
| 27 |
*/ |
| 28 |
public function __construct() { |
| 29 |
parent::__construct( |
| 30 |
// Base ID of your widget |
| 31 |
'list_widget', |
| 32 |
// Widget name will appear in UI |
| 33 |
__('Mailgun List Widget', 'wpb_widget_domain'), |
| 34 |
// Widget description |
| 35 |
array( 'description' => __('Mailgun list widget', 'wpb_widget_domain') ) |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* @param mixed $args |
| 41 |
* @param mixed $instance |
| 42 |
* @return void |
| 43 |
* @throws JsonException |
| 44 |
*/ |
| 45 |
public function widget( $args, $instance ) { |
| 46 |
$mailgun = Mailgun::getInstance(); |
| 47 |
|
| 48 |
if ( ! isset($instance['list_address']) || ! $instance['list_address']) { |
| 49 |
return; |
| 50 |
} |
| 51 |
// vars |
| 52 |
$list_address = apply_filters('list_address', $instance['list_address']); |
| 53 |
|
| 54 |
if (isset($instance['collect_name'])) { |
| 55 |
$args['collect_name'] = true; |
| 56 |
} |
| 57 |
|
| 58 |
if (isset($instance['list_title'])) { |
| 59 |
$args['list_title'] = $instance['list_title']; |
| 60 |
} |
| 61 |
|
| 62 |
if (isset($instance['list_description'])) { |
| 63 |
$args['list_description'] = $instance['list_description']; |
| 64 |
} |
| 65 |
|
| 66 |
$mailgun->list_form($list_address, $args); |
| 67 |
} |
| 68 |
|
| 69 |
// Widget Backend |
| 70 |
|
| 71 |
/** |
| 72 |
* @param mixed $instance |
| 73 |
* @return string|void |
| 74 |
*/ |
| 75 |
public function form( $instance ) { |
| 76 |
if (isset($instance['list_address'])) { |
| 77 |
$list_address = $instance['list_address']; |
| 78 |
} else { |
| 79 |
$list_address = __('New list_address', 'wpb_widget_domain'); |
| 80 |
} |
| 81 |
|
| 82 |
if (isset($instance['collect_name']) && $instance['collect_name'] === 'on') { |
| 83 |
$collect_name = 'checked'; |
| 84 |
} else { |
| 85 |
$collect_name = ''; |
| 86 |
} |
| 87 |
|
| 88 |
$list_title = $instance['list_title'] ?? null; |
| 89 |
$list_description = $instance['list_description'] ?? null; |
| 90 |
|
| 91 |
// Widget admin form |
| 92 |
?> |
| 93 |
<div class="mailgun-list-widget-back"> |
| 94 |
<p> |
| 95 |
<label for="<?php echo esc_attr($this->get_field_id('list_title')); ?>"><?php _e('Title (optional):'); ?></label> |
| 96 |
<input class="widefat" id="<?php echo esc_attr($this->get_field_id('list_title')); ?>" name="<?php echo esc_attr($this->get_field_name('list_title')); ?>" type="text" value="<?php echo esc_attr($list_title); ?>" /> |
| 97 |
</p> |
| 98 |
<p> |
| 99 |
<label for="<?php echo $this->get_field_id('list_description'); ?>"><?php _e('Description (optional):'); ?></label> |
| 100 |
<input class="widefat" id="<?php echo esc_attr($this->get_field_id('list_description')); ?>" name="<?php echo esc_attr($this->get_field_name('list_description')); ?>" type="text" value="<?php echo esc_attr($list_description); ?>" /> |
| 101 |
</p> |
| 102 |
<p> |
| 103 |
<label for="<?php echo $this->get_field_id('list_address'); ?>"><?php _e('List addresses (required):'); ?></label> |
| 104 |
<input class="widefat" id="<?php echo esc_attr($this->get_field_id('list_address')); ?>" name="<?php echo esc_attr($this->get_field_name('list_address')); ?>" type="text" value="<?php echo esc_attr($list_address); ?>" /> |
| 105 |
</p> |
| 106 |
<p> |
| 107 |
<label for="<?php echo $this->get_field_id('collect_name'); ?>"><?php _e('Collect name:'); ?></label> |
| 108 |
<input class="widefat" id="<?php echo esc_attr($this->get_field_id('collect_name')); ?>" name="<?php echo esc_attr($this->get_field_name('collect_name')); ?>" type="checkbox" <?php echo esc_attr($collect_name); ?> /> |
| 109 |
</p> |
| 110 |
</div> |
| 111 |
<?php |
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* @param mixed $new_instance |
| 116 |
* @param mixed $old_instance |
| 117 |
* @return array |
| 118 |
*/ |
| 119 |
public function update( $new_instance, $old_instance ) { |
| 120 |
return $new_instance; |
| 121 |
} |
| 122 |
} |
| 123 |
|