Skip to content

Commit

Permalink
1.2.2 release changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mutendebrian committed Jan 20, 2020
1 parent bbb7c85 commit e85475d
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 24 deletions.
2 changes: 1 addition & 1 deletion includes/admin/welcome.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="noptin-welcome">
<div class="noptin-main-header">
<h1>Noptin v1.2.0</h1>
<h1>Noptin v1.2.2</h1>
<a href="https://github.com/hizzle-co/noptin/issues/new/choose" target="_blank"><?php _e( 'Report a bug or request a feature', 'newsletter-optin-box' ); ?></a>
</div>

Expand Down
2 changes: 1 addition & 1 deletion includes/assets/js/dist/subscribers.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion includes/assets/js/src/subscribers.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
})

},
worker: true,
worker: false,
header: true
});

Expand Down
84 changes: 66 additions & 18 deletions includes/class-noptin-ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,42 +183,61 @@ public function import_subscribers() {
$table = get_noptin_subscribers_table_name();
$imported = 0;
$mappings = array(
'First Name' => 'first_name',
'Second Name' => 'second_name',
'Last Name' => 'second_name',
'Email Address' => 'email',
'Active' => 'active',
'Email Confirmed' => 'confirmed',
'Subscribed On' => 'date_created',
'Confirm Key' => 'confirm_key',
'Meta' => 'meta',
'first name' => 'first_name',
'second name' => 'second_name',
'last name' => 'second_name',
'email address' => 'email',
'email' => 'email',
'active' => 'active',
'list status' => 'active',
'email confirmed' => 'confirmed',
'global status' => 'confirmed',
'subscribed on' => 'date_created',
'confirm key' => 'confirm_key',
'meta' => 'meta',
);

foreach( $subscribers as $subscriber ) {

// Prepare subscriber fields.
foreach( $mappings as $key => $value ) {
foreach( $subscriber as $key => $value ) {
$lowercase = strtolower( $key );

if( isset( $subscriber[ $key ] ) ) {
$subscriber[$value] = $subscriber[ $key ];
if( isset( $mappings[ $lowercase ] ) ) {
$subscriber[ $mappings[ $lowercase ] ] = $value;
unset( $subscriber[ $key ] );
}

}

// Ensure that there is a unique email address.
if( empty( $subscriber[ 'email' ] ) || ! is_email( $subscriber['email'] ) || noptin_email_exists( $subscriber['email'] ) ) {
continue;
}

// Sanitize email status
if( empty( $subscriber['confirmed'] ) || 'false' == $subscriber['confirmed'] || 'unconfirmed' == $subscriber['confirmed'] ) {
$subscriber['confirmed'] = 0;
} else {
$subscriber['confirmed'] = 1;
}

// Sanitize subscriber status
if( empty( $subscriber['active'] ) || 'true' == $subscriber['active'] || 'subscribed' == $subscriber['active'] ) {
$subscriber['active'] = 0;
} else {
$subscriber['active'] = 1;
}

// Save the main subscriber fields.
$database_fields = array(
'email' => $subscriber['email'],
'first_name' => empty( $subscriber['first_name'] ) ? '' : $subscriber['first_name'],
'second_name' => empty( $subscriber['second_name'] ) ? '' : $subscriber['second_name'],
'confirm_key' => empty( $subscriber['confirm_key'] ) ? md5( $subscriber['email'] ) . wp_generate_password( 4, false ) : $subscriber['confirm_key'],
'date_created' => empty( $subscriber['date_created'] ) ? date( 'Y-m-d' ) : $subscriber['date_created'],
'confirmed' => empty( $subscriber['confirmed'] ) ? 0 : (int) $subscriber['confirmed'],
'active' => empty( $subscriber['active'] ) ? 1 : (int) $subscriber['active'],
'confirmed' => $subscriber['confirmed'],
'active' => $subscriber['active'],
);

if ( ! $wpdb->insert( $table, $database_fields, '%s' ) ) {
Expand All @@ -230,6 +249,8 @@ public function import_subscribers() {
$meta = array();
if( !empty( $subscriber['meta'] ) ) {

$subscriber['meta'] = maybe_unserialize( $subscriber['meta'] );

// Arrays
if( is_array( $subscriber['meta'] ) ) {
$meta = array( $subscriber['meta'] );
Expand All @@ -248,9 +269,31 @@ public function import_subscribers() {
$meta = array();
}

$meta += array_diff_key( $subscriber, $database_fields );
$extra_meta = array_diff_key( $subscriber, $database_fields );
foreach ( $extra_meta as $field => $value ) {

if( is_null( $value ) ) {
continue;
}

if( ! isset( $meta[$field] ) ) {
$meta[$field] = array();
}

$meta[$field][] = $value;

}

foreach ( $meta as $field => $value ) {
update_noptin_subscriber_meta( $id, $field, $value );

if( ! is_array( $value ) ) {
$value = array( $value );
}

foreach( $value as $val ) {
update_noptin_subscriber_meta( $id, $field, $val );
}

}

$imported += 1;
Expand Down Expand Up @@ -583,7 +626,7 @@ public function download_subscribers() {

$output = fopen( 'php://output', 'w' ) or die( 'Unsupported server' );
$table = get_noptin_subscribers_table_name();
$results = $wpdb->get_results( "SELECT `first_name`, `second_name`, `email`, `active`, `confirmed`, `date_created` FROM $table", ARRAY_N );
$results = $wpdb->get_results( "SELECT `id`, `first_name`, `second_name`, `email`, `active`, `confirmed`, `date_created`, `confirm_key` FROM $table", ARRAY_N );

header( 'Content-Type:application/csv' );
header( 'Content-Disposition:attachment;filename=subscribers.csv' );
Expand All @@ -598,9 +641,14 @@ public function download_subscribers() {
__( 'Active', 'newsletter-optin-box' ),
__( 'Email Confirmed', 'newsletter-optin-box' ),
__( 'Subscribed On', 'newsletter-optin-box' ),
__( 'Confirm Key', 'newsletter-optin-box' ),
__( 'Meta', 'newsletter-optin-box' ),
)
);

foreach ( $results as $result ) {
$result[] = wp_json_encode( get_noptin_subscriber_meta( $result[0] ) );
unset( $result[0] );
fputcsv( $output, $result );
}
fclose( $output );
Expand Down
4 changes: 2 additions & 2 deletions noptin.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Description: Easily add a newsletter optin box onto post content, widget or popup
* Author: Picocodes
* Author URI: https://github.com/picocodes
* Version: 1.2.1
* Version: 1.2.2
* Text Domain: noptin
* License: GPL3+
* License URI: http://www.gnu.org/licenses/gpl-3.0.txt
Expand Down Expand Up @@ -40,7 +40,7 @@ class Noptin {
* @var Plugin version
* @since 1.0.0
*/
public $version = '1.2.1';
public $version = '1.2.2';

/**
* @var Plugin db version
Expand Down
7 changes: 6 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: newsletter, email newsletter form, email opt-in, email popup, newsletter w
Requires at least: 4.9
Tested up to: 5.3
Requires PHP: 5.3
Version: 1.2.1
Version: 1.2.2
Stable tag: trunk
License: GPLv3
License URI: https://www.gnu.org/licenses/gpl-3.0.html
Expand Down Expand Up @@ -94,6 +94,11 @@ Yeah. Your newsletter subscription forms will take your theme's default styling.

== Changelog ==

= 1.2.2 - 2020-01-20 =
- Ability to preview email campaigns - ADDED
- Ability to import email subscribers - ADDED
- Template loader - ADDED

= 1.2.1 - 2020-01-06 =
- Do not inject shortcode forms on post previews - CHANGED
- check if class DOMDocument exists before emogrifying - ADDED
Expand Down

0 comments on commit e85475d

Please sign in to comment.