's2_form_widget',
'description' => esc_html__( 'Sidebar Widget for Subscribe2', 'subscribe2' ),
'customize_selective_refresh' => true,
);
$control_ops = array(
'width' => 250,
'height' => 300,
);
parent::__construct( 's2_form_widget', esc_html__( 'Subscribe2 Widget', 'subscribe2' ), $widget_ops, $control_ops );
}
/**
* Displays the Widget
*/
public function widget( $args, $instance ) {
$title = empty( $instance['title'] ) ? __( 'Subscribe2', 'subscribe2' ) : $instance['title'];
$div = empty( $instance['div'] ) ? 'search' : $instance['div'];
$widgetprecontent = empty( $instance['widgetprecontent'] ) ? '' : $instance['widgetprecontent'];
$widgetpostcontent = empty( $instance['widgetpostcontent'] ) ? '' : $instance['widgetpostcontent'];
$textbox_size = empty( $instance['size'] ) ? 20 : $instance['size'];
$hidebutton = empty( $instance['hidebutton'] ) ? 'none' : $instance['hidebutton'];
$postto = empty( $instance['postto'] ) ? '' : $instance['postto'];
$js = empty( $instance['js'] ) ? '' : $instance['js'];
$noantispam = empty( $instance['noantispam'] ) ? '' : $instance['noantispam'];
$nowrap = empty( $instance['nowrap'] ) ? '' : $instance['nowrap'];
$hide = '';
if ( 'subscribe' === $hidebutton || 'unsubscribe' === $hidebutton ) {
$hide = ' hide="' . $hidebutton . '"';
} elseif ( 'link' === $hidebutton ) {
$hide = ' link="' . __( '(Un)Subscribe to Posts', 'subscribe2' ) . '"';
}
$postid = '';
if ( ! empty( $postto ) ) {
$postid = ' id="' . $postto . '"';
}
$size = ' size="' . $textbox_size . '"';
$nojs = '';
if ( $js ) {
$nojs = ' nojs="true"';
}
if ( $noantispam ) {
$noantispam = ' noantispam="true"';
}
if ( $nowrap ) {
$nowrap = ' wrap="false"';
}
$shortcode = '[subscribe2' . $hide . $postid . $size . $nojs . $noantispam . $nowrap . ' widget="true"]';
echo wp_kses_post( $args['before_widget'] );
if ( ! empty( $title ) ) {
echo wp_kses_post( $args['before_title'] ) . esc_attr( $title ) . wp_kses_post( $args['after_title'] );
}
echo '
';
if ( ! empty( $widgetprecontent ) ) {
echo wp_kses_post( $widgetprecontent );
}
echo do_shortcode( $shortcode );
if ( ! empty( $widgetpostcontent ) ) {
echo wp_kses_post( $widgetpostcontent );
}
echo '
';
echo wp_kses_post( $args['after_widget'] );
}
/**
* Saves the widgets settings.
*/
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = wp_strip_all_tags( stripslashes( $new_instance['title'] ) );
$instance['div'] = wp_strip_all_tags( stripslashes( $new_instance['div'] ) );
$instance['widgetprecontent'] = stripslashes( $new_instance['widgetprecontent'] );
$instance['widgetpostcontent'] = stripslashes( $new_instance['widgetpostcontent'] );
$instance['size'] = intval( stripslashes( $new_instance['size'] ) );
$instance['hidebutton'] = wp_strip_all_tags( stripslashes( $new_instance['hidebutton'] ) );
$instance['postto'] = stripslashes( $new_instance['postto'] );
$instance['js'] = stripslashes( $new_instance['js'] );
$instance['noantispam'] = stripslashes( $new_instance['noantispam'] );
$instance['nowrap'] = stripslashes( $new_instance['nowrap'] );
return $instance;
}
/**
* Creates the edit form for the widget.
*/
public function form( $instance ) {
// set some defaults, getting any old options first
$options = get_option( 'widget_subscribe2widget' );
if ( false === $options ) {
$defaults = array(
'title' => 'Subscribe2',
'div' => 'search',
'widgetprecontent' => '',
'widgetpostcontent' => '',
'size' => 20,
'hidebutton' => 'none',
'postto' => '',
'js' => '',
'noantispam' => '',
'nowrap' => '',
);
} else {
$defaults = array(
'title' => $options['title'],
'div' => $options['div'],
'widgetprecontent' => $options['widgetprecontent'],
'widgetpostcontent' => $options['widgetpostcontent'],
'size' => $options['size'],
'hidebutton' => $options['hidebutton'],
'postto' => $options['postto'],
'js' => $options['js'],
'noantispam' => $options['noantispam'],
'nowrap' => $options['nowrap'],
);
delete_option( 'widget_subscribe2widget' );
}
// code to obtain old settings too
$instance = wp_parse_args( (array) $instance, $defaults );
$title = htmlspecialchars( $instance['title'], ENT_QUOTES );
$div = htmlspecialchars( $instance['div'], ENT_QUOTES );
$widgetprecontent = htmlspecialchars( $instance['widgetprecontent'], ENT_QUOTES );
$widgetpostcontent = htmlspecialchars( $instance['widgetpostcontent'], ENT_QUOTES );
$size = htmlspecialchars( $instance['size'], ENT_QUOTES );
$hidebutton = htmlspecialchars( $instance['hidebutton'], ENT_QUOTES );
$postto = htmlspecialchars( $instance['postto'], ENT_QUOTES );
$js = htmlspecialchars( $instance['js'], ENT_QUOTES );
$noantispam = htmlspecialchars( $instance['noantispam'], ENT_QUOTES );
$nowrap = htmlspecialchars( $instance['nowrap'], ENT_QUOTES );
global $wpdb, $mysubscribe2;
$sql = "SELECT ID, post_title FROM $wpdb->posts WHERE post_type='page' AND post_status='publish'";
echo '' . "\r\n";
echo '
' . "\r\n";
echo '
' . "\r\n";
echo '
' . "\r\n";
echo '
' . "\r\n";
echo '
' . "\r\n";
echo '
' . esc_html__( 'Display options', 'subscribe2' ) . ':
' . "\r\n";
echo '' . "\r\n";
echo '
' . "\r\n";
echo '
' . "\r\n";
if ( '1' === $mysubscribe2->subscribe2_options['ajax'] ) {
echo '
' . "\r\n";
}
echo '
' . "\r\n";
echo '
' . "\r\n";
echo '
' . "\r\n";
echo '
' . "\r\n";
echo '
' . "\r\n";
echo '
' . "\r\n";
}
} // End S2_Form_widget class