<?php
class NewsletterWidgetCustom extends WP_Widget {
function NewsletterWidgetCustom(){
parent::WP_Widget(false, $name = 'Newsletter Custom',
array('description' => 'Newsletter widget to add subscription forms on sidebars'),
array('width' => '350px'));
}
function widget($args, $instance) {
global $newsletter;
extract($args);
echo $before_widget;
$options = get_option('newsletter');
$options_profile = get_option('newsletter_profile');
$form = '<span class="text-new">new</span>';
if (!empty($instance['t1'])){
$form .= '<strong class="subhead">'.$instance['t1'].'</strong>';
}
if (!empty($instance['t2'])){
$form .= '<div class="heading-sidebar">'.
'<div class="heading-holder">'.
'<h4>'.str_replace(
array('[', ']'),
array('<span class="mark">', '</span>'),
$instance['t2']).
'</h4>'.
'</div>'.
'</div>';
}
if (!empty($instance['text'])){
$form .= wpautop(str_replace(
array('[', ']'),
array('<strong>', '</strong>'),
$instance['text'])
);
}
$form .= '<div class="newsletter newsletter-widget">'.
'<form action="'.$newsletter->options_main['url'].'" onsubmit="return newsletter_check(this)" '.
'method="post" class="report-form"><fieldset>'.
'<input type="hidden" name="na" value="s"/>'.
'<input type="hidden" name="nr" value="widget"/>';
if ($options_profile['name_status'] == 2){
$form .= '<div class="row">'.
'<label for="name">Name</label>'.
'<span class="text"><input type="text" id="name" name="nn" value="'.$options_profile['name'].'"/></span>'.
'</div>';
}
if ($options_profile['surname_status'] == 2){
$form .= '<div class="row">'.
'<label for="surname">Sname</label>'.
'<span class="text"><input type="text" id="surname" name="ns" value="'.$options_profile['surname'].'"/></span>'.
'</div>';
}
$form .= '<div class="row">'.
'<label for="email1">Email</label>'.
'<span class="text"><input type="text" id="email1" name="ne" value="'.$options_profile['email'].'"/></span>'.
'</div>';
if ($options_profile['sex_status'] == 2){
$form .= '<div class="row">'.
'<select name="nx" class="newsletter-sex">'.
'<option value="m">'.$options_profile['sex_male'].'</option>'.
'<option value="f">'.$options_profile['sex_female'].'</option>'.
'</select>'.
'</div>';
}
if ($options_profile['privacy_status'] == 1){
$form .= '<div class="row"><input type="checkbox" name="ny"/> '.$options_profile['privacy'].'</div>';
}
$form .= '<input type="submit" class="submit" value="'.$options_profile['subscribe'].'"/>';
if (!empty($instance['ts'])){
$form .= '<span class="info-text">'.$instance['ts'].'</span>';
}
$form .= '</fieldset></form></div>';
if (!empty($instance['t3'])){
$form .= '<strong class="subtext">'.$instance['t3'].'</strong>';
}
echo $form, $after_widget;
}
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['t1'] = strip_tags($new_instance['t1']);
$instance['t2'] = strip_tags($new_instance['t2']);
$instance['text'] = strip_tags($new_instance['text']);
$instance['ts'] = strip_tags($new_instance['ts']);
$instance['t3'] = strip_tags($new_instance['t3']);
return $instance;
}
function form($instance){
?><p><?php
?><label for="<?php echo $this->get_field_id('t1');?>"><?php
?>Title 1:<?php
?><input class="widefat" id="<?php echo $this->get_field_id('t1');?>" name="<?php
echo $this->get_field_name('t1');?>" type="text" value="<?php echo esc_attr($instance['t1']);?>"/><?php
?></label><?php
?></p><?php
?><p><?php
?><label for="<?php echo $this->get_field_id('t2');?>"><?php
?>Title 2:<?php
?><input class="widefat" id="<?php echo $this->get_field_id('t2');?>" name="<?php
echo $this->get_field_name('t2');?>" type="text" value="<?php echo esc_attr($instance['t2']);?>"/><?php
?></label><?php
?></p><?php
?><p><?php
?><label for="<?php echo $this->get_field_id('text');?>"><?php
?>Text:<?php
?><textarea class="widefat" rows="10" cols="20" id="<?php echo $this->get_field_id('text');?>" name="<?php
echo $this->get_field_name('text');?>"><?php echo esc_html($instance['text']);?></textarea><?php
?></label><?php
?></p><?php
?><p><?php
?><label for="<?php echo $this->get_field_id('ts');?>"><?php
?>Title Under "Submit":<?php
?><input class="widefat" id="<?php echo $this->get_field_id('ts');?>" name="<?php
echo $this->get_field_name('ts');?>" type="text" value="<?php echo esc_attr($instance['ts']);?>"/><?php
?></label><?php
?></p><?php
?><p><?php
?><label for="<?php echo $this->get_field_id('t3');?>"><?php
?>Title 3:<?php
?><input class="widefat" id="<?php echo $this->get_field_id('t3');?>" name="<?php
echo $this->get_field_name('t3');?>" type="text" value="<?php echo esc_attr($instance['t3']);?>"/><?php
?></label><?php
?></p><?php
}
}
add_action('widgets_init', create_function(EMPTY_STRING, 'return register_widget("NewsletterWidgetCustom");'));