Skip to content

Commit

Permalink
Added an email subcribe widget
Browse files Browse the repository at this point in the history
  • Loading branch information
mutendebrian committed Mar 8, 2019
1 parent d9c5e1c commit 51daa8c
Show file tree
Hide file tree
Showing 8 changed files with 358 additions and 27 deletions.
4 changes: 2 additions & 2 deletions admin/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
height: 1px;
overflow: hidden;
background-color: #e0e0e0;
margin-bottom: 5px;
margin-top: 5px;
margin-bottom: 20px;
margin-top: 20px;
}


Expand Down
23 changes: 19 additions & 4 deletions admin/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ public function __construct() {
*/
private function includes() {

// Include admin files
//require_once $this->plugin_path . 'admin/functions.php';
// Include the widget class
require_once $this->admin_path . 'widget.php';

/**
* Runs right after including admin files.
Expand All @@ -124,6 +124,9 @@ private function init_hooks() {
*/
do_action('noptin_before_admin_init_hooks', $this);

//Register our new widget
add_action( 'widgets_init', array($this, 'register_widget'));

//Admin scripts
add_action('admin_enqueue_scripts', array($this, 'enqeue_scripts'));

Expand All @@ -141,6 +144,17 @@ private function init_hooks() {
do_action('noptin_after_admin_init_hooks', $this);
}

/**
* Registers a widget area
*
* @access public
* @since 1.0.2
* @return self::$instance
*/
public function register_widget() {
register_widget( 'Noptin_Widget' );
}

/**
* Register admin scripts
*
Expand Down Expand Up @@ -213,8 +227,9 @@ public function render_main_page() {
*/
do_action('noptin_before_admin_main_page', $this);

$logo_url = $this->admin_url . 'logo.png';
$screenshot_url = $this->admin_url . 'screenshot1.png';
$logo_url = $this->admin_url . 'logo.png';
$screenshot_url = $this->admin_url . 'screenshot1.png';
$screenshot2_url = $this->admin_url . 'screenshot2.png';
include $this->admin_path . 'welcome.php';

/**
Expand Down
Binary file added admin/screenshot2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 8 additions & 11 deletions admin/welcome.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<div class="wrap noptin-container noptin-shadow" style="padding: 2em; background: #fff">
<div class="wrap noptin-container noptin-shadow" style="padding: 2em; background: #f4fcfc;">
<div class="noptin-row">
<div class="noptin-col-2">
<img src="<?php echo $logo_url;?>" style="width: 100px;max-width: 100%;"/>
</div>
<div class="noptin-col-10">
<h1 class="noptin-color">Noptin</h1>
<p class="noptin-big">Easily add email subscription forms into your posts, pages and custom post types.</p>
<p class="noptin-big">Easily add email subscription forms into your posts, sidebars and other widget areas.</p>
</div>
</div>
<div class="noptin-divider"></div>
Expand All @@ -24,15 +24,12 @@
<li>Click on any text to edit it.</li>
<li>Customize the colors using the options on the left.</li>
</ol>
</div>
</div>
<div class="noptin-col noptin-col-12">
<h2 class="noptin-big">Content upgrades and Link magnets.</h2>
<p class="noptin-big">Here is how you can boost conversions by 529% in 45-Minutes.</p>
<ol>
<li>Step #1: Use Google Analytics to Identify Blog Posts that Bring In the Most Traffic.</li>
<li>Step #2: <a href="https://optinmonster.com/9-lead-magnets-to-increase-subscribers/">Create a Resource</a> that Would Make Each Blog Post Even Better.</li>
<li>Step #3: Add a new opt in form to the posts and provide a link to the associated resource in the redirect field.</li>
</ol>
</div>
<div class="noptin-divider"></div>
<h2 class="noptin-big">Widgets</h2>
<p class="noptin-big">Click on <strong>Appearance->Widget</strong> then select <strong>Noptin Subscription Widget</strong> to add an email subscription form to your sidebar.</p>
<img src="<?php echo $screenshot2_url;?>" style="max-width: 100%;"/>
</div>
</div>
</div>
298 changes: 298 additions & 0 deletions admin/widget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,298 @@
<?php
/**
* Adds a newsletter optin widget
*
* Simple WordPress optin form
*
* @since 1.0.0
*
*/

// Exit if accessed directly
if (!defined('ABSPATH')) {
die;
}

/**
* Widget class
*
* @since 1.0.0
*/

class Noptin_Widget extends WP_Widget {

//Colors
public $colors = array(
'transparent' => 'Transparent',
'#e51c23' => 'Red',
'#e91e63' => 'Pink',
'#9c27b0' => 'Purple',
'#673ab7' => 'Deep Purple',
'#3f51b5' => 'Indigo',
'#2196F3' => 'Blue',
'#03a9f4' => 'Light Blue',
'#00bcd4' => 'Cyan',
'#009688' => 'Teal',
'#4CAF50' => 'Green',
'#8bc34a' => 'Light Green',
'#cddc39' => 'Lime',
'#ffeb3b' => 'Yellow',
'#ffc107' => 'Amber',
'#ff9800' => 'Orange',
'#ff5722' => 'Deep Orange',
'#795548' => 'Brown',
'#607d8b' => 'Blue Grey',
'#313131' => 'Black',
'#fff' => 'White',
'#aaa' => 'Grey',
);

// class constructor
public function __construct() {
$widget_ops = array(
'classname' => 'noptin_widget',
'description' => 'Add a newsletter optin box to any sidebar or widget area.',
);
parent::__construct( 'noptin_widget', 'Noptin Email Subscription', $widget_ops );
}

// output the widget content on the front-end
public function widget($args, $instance) {
echo $args['before_widget'];

//Title
$title = '';
if ( ! empty( $instance['title'] ) ) {
$_title = apply_filters( 'widget_title', $instance['title'] );
$title = $args['before_title'] . $_title . $args['after_title'];
}

//Description
$desc = '';
if ( ! empty( $instance['desc'] ) ) {
$desc = '<p class="noptin-widget-desc">' . $instance['desc'] . '</p>';
}

//Redirect
$redirect = '';
if ( ! empty( $instance['redirect'] ) ) {
$_redirect = esc_url($instance['redirect']);
$redirect = '<input class="noptin_form_redirect" name="noptin-redirect" type="hidden" value="' . $_redirect . '"/>';
}

//Submit button
$submit = empty( $instance['submit'] ) ? esc_attr('Submit') : esc_attr($instance['submit']);

//Colors
$bg_color = sanitize_hex_color( $instance['bg_color'] );
$color = sanitize_hex_color( $instance['color'] );
$h2_col = sanitize_hex_color( $instance['h2_col'] );
$btn_col = sanitize_hex_color( $instance['btn_col'] );

?>
<style>

.noptin-email-optin-widget {
padding: 2.4em;
padding-top: 80px;
color: <?php echo $color;?> !important;
background-color: <?php echo $bg_color;?> !important;
min-height: 400px;
}

.noptin-email-optin-widget .widget-title{
color: <?php echo $h2_col;?> !important;
font-size: 1.3em;
}

.noptin-email-optin-widget .noptin-widget-email-input{
background-color: rgba(255, 255, 255, 0.3) !important;;
border: none !important;
}

.noptin-email-optin-widget .noptin_feedback_success{
border:1px solid rgba(6, 147, 227, 0.8);
display:none;
padding:10px;
margin-top:10px;
}

.noptin-email-optin-widget .noptin_feedback_error{
border:1px solid rgba(227, 6, 37, 0.8);
display:none;
padding:10px;
margin-top:10px;
}

.noptin-email-optin-widget .noptin-widget-submit-input{
margin-top: 5px;
display: block;
width: 100%;
background-color: <?php echo $btn_col;?> !important;
}
</style>
<div class="noptin-email-optin-widget">
<form>
<?php echo $title . $desc . $redirect;?>
<input class="noptin-widget-email-input noptin_form_input_email" type="email" placeholder="Email Address" required >
<input class="noptin-widget-submit-input" value="<?php echo $submit;?>" type="submit">
<div class="noptin_feedback_success"></div>
<div class="noptin_feedback_error"></div>
</form>
</div>

<?php echo $args['after_widget'];
}

//Displays color select boxes
public function noptin_color_select($color) {
foreach ( $this->colors as $hex => $name ) {

$hex = esc_attr( $hex );
$name = esc_html($name);
echo "<option value='$hex' ";

//Check if the current field is being shown
selected( $color, $hex );

echo ">$name</option>";
}
}

// output the option form field in admin Widgets screen
public function form($instance) {
$title = ! empty( $instance['title'] ) ? $instance['title'] : esc_html__( 'FREE NEWSLETTER', 'noptin' );
$desc = ! empty( $instance['desc'] ) ? $instance['desc'] : esc_html__( 'Subscribe to our newsletter today and be the first to know when we publish a new blog post.', 'noptin' );
$submit = ! empty( $instance['submit'] ) ? $instance['submit'] : esc_html__( 'SUBSCRIBE NOW', 'noptin' );
$bg_color = ! empty( $instance['bg_color'] ) ? $instance['bg_color'] : '#2196F3';
$color = ! empty( $instance['color'] ) ? $instance['color'] : '#fff';
$h2_col = ! empty( $instance['h2_col'] ) ? $instance['h2_col'] : '#fff';
$btn_col = ! empty( $instance['btn_col'] ) ? $instance['btn_col'] : '#e51c23';
$redirect = ! empty( $instance['redirect'] ) ? $instance['redirect'] : '';

?>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>">
<?php esc_attr_e( 'Title:', 'noptin' ); ?>
</label>

<input
class="widefat"
id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"
name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>"
type="text"
value="<?php echo esc_attr( $title ); ?>">
</p>

<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'desc' ) ); ?>">
<?php esc_attr_e( 'Description:', 'noptin' ); ?>
</label>

<input
class="widefat"
id="<?php echo esc_attr( $this->get_field_id( 'desc' ) ); ?>"
name="<?php echo esc_attr( $this->get_field_name( 'desc' ) ); ?>"
type="text"
value="<?php echo esc_attr( $desc ); ?>">
</p>

<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'redirect' ) ); ?>">
<?php esc_attr_e( 'Redirect:', 'noptin' ); ?>
</label>

<input
class="widefat"
id="<?php echo esc_attr( $this->get_field_id( 'redirect' ) ); ?>"
name="<?php echo esc_attr( $this->get_field_name( 'redirect' ) ); ?>"
type="text"
placeholder="Optional. Where should we redirect a user after they sign up?"
value="<?php echo esc_attr( $redirect ); ?>">
</p>

<p>

<label for="<?php echo esc_attr( $this->get_field_id( 'bg_color' ) ); ?>">
<?php esc_attr_e( 'Background Color:', 'noptin' ); ?>
</label>

<select
name="<?php echo esc_attr( $this->get_field_name( 'bg_color' ) ); ?>"
class="widefat"
id="<?php echo esc_attr( $this->get_field_id( 'bg_color' ) ); ?>"
>
<?php $this->noptin_color_select($bg_color );?>
</select>
</p>


<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'h2_col' ) ); ?>">
<?php esc_attr_e( 'Title Color:', 'noptin' ); ?>
</label>

<select
name="<?php echo esc_attr( $this->get_field_name( 'h2_col' ) ); ?>"
class="widefat"
id="<?php echo esc_attr( $this->get_field_id( 'h2_col' ) ); ?>"
>
<?php $this->noptin_color_select($h2_col );?>
</select>
</p>

<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'color' ) ); ?>">
<?php esc_attr_e( 'Text Color:', 'noptin' ); ?>
</label>
<select
name="<?php echo esc_attr( $this->get_field_name( 'color' ) ); ?>"
class="widefat"
id="<?php echo esc_attr( $this->get_field_id( 'color' ) ); ?>"
>
<?php $this->noptin_color_select($color );?>
</select>
</p>

<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'btn_col' ) ); ?>">
<?php esc_attr_e( 'Button Color:', 'noptin' ); ?>
</label>
<select
name="<?php echo esc_attr( $this->get_field_name( 'btn_col' ) ); ?>"
class="widefat"
id="<?php echo esc_attr( $this->get_field_id( 'btn_col' ) ); ?>"
>
<?php $this->noptin_color_select($btn_col );?>
</select>
</p>

<label for="<?php echo esc_attr( $this->get_field_id( 'submit' ) ); ?>">
<?php esc_attr_e( 'Submit Button Text:', 'noptin' ); ?>
</label>
<input
class="widefat"
id="<?php echo esc_attr( $this->get_field_id( 'submit' ) ); ?>"
name="<?php echo esc_attr( $this->get_field_name( 'submit' ) ); ?>"
type="text"
value="<?php echo esc_attr( $submit ); ?>">
</p>
<?php
}

// save options
public function update($new_instance, $old_instance) {
return array(
'title' => ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '',
'submit' => ( ! empty( $new_instance['submit'] ) ) ? strip_tags( $new_instance['submit'] ) : '',
'desc' => ( ! empty( $new_instance['desc'] ) ) ? strip_tags( $new_instance['desc'] ) : '',
'bg_color' => ( ! empty( $new_instance['bg_color'] ) ) ? $new_instance['bg_color'] : 'transparent',
'color' => ( ! empty( $new_instance['color'] ) ) ? $new_instance['color'] : '#313131',
'h2_col' => ( ! empty( $new_instance['h2_col'] ) ) ? $new_instance['h2_col'] : '#313131',
'btn_col' => ( ! empty( $new_instance['btn_col'] ) ) ? $new_instance['btn_col'] : '#ffc107',
'redirect' => ( ! empty( $new_instance['redirect'] ) ) ? esc_url( $new_instance['redirect'] ) : '',

);

}
}
Loading

0 comments on commit 51daa8c

Please sign in to comment.