Skip to content

Commit

Permalink
Merge pull request #19 from itthinx/pre-2.12.0
Browse files Browse the repository at this point in the history
Pre 2.12.0
  • Loading branch information
itthinx committed Aug 25, 2015
2 parents a70b8fd + c475f47 commit 385f328
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 84 deletions.
4 changes: 2 additions & 2 deletions affiliates.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
* Plugin Name: Affiliates
* Plugin URI: http://www.itthinx.com/plugins/affiliates
* Description: The Affiliates plugin provides the right tools to maintain a partner referral program.
* Version: 2.11.0
* Version: 2.12.0
* Author: itthinx
* Author URI: http://www.itthinx.com
* Donate-Link: http://www.itthinx.com
* License: GPLv3
*/
if ( !defined( 'AFFILIATES_CORE_VERSION' ) ) {
define( 'AFFILIATES_CORE_VERSION', '2.11.0' );
define( 'AFFILIATES_CORE_VERSION', '2.12.0' );
define( 'AFFILIATES_PLUGIN_NAME', 'affiliates' );
define( 'AFFILIATES_FILE', __FILE__ );
define( 'AFFILIATES_PLUGIN_BASENAME', plugin_basename( AFFILIATES_FILE ) );
Expand Down
2 changes: 1 addition & 1 deletion lib/core/class-affiliates-registration-widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Affiliates_Registration_Widget extends WP_Widget {
* Creates an affiliate registration widget.
*/
function __construct() {
parent::WP_Widget( false, $name = 'Affiliates Registration' );
parent::__construct( false, $name = 'Affiliates Registration' );
}

/**
Expand Down
14 changes: 12 additions & 2 deletions lib/core/class-affiliates-registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,13 @@ public static function register_affiliate( $userdata ) {
*/
public static function update_affiliate_user( $user_id, $userdata ) {

global $wpdb;
global $wpdb, $affiliates_update_affiliate_user;

if ( !isset( $affiliates_update_affiliate_user ) ) {
$affiliates_update_affiliate_user = true;
} else {
return;
}

$errors = new WP_Error();

Expand Down Expand Up @@ -553,8 +559,12 @@ public static function update_affiliate_user( $user_id, $userdata ) {
'user_email' => esc_sql( $userdata['user_email'] ),
);
if ( !empty( $userdata['password'] ) ) {
$_userdata['user_pass'] = esc_sql( $userdata['password'] );
// Don't pass the new password through wp_update_user as we risk
// sending headers again when wp_update_user() clears the cookies while
// the new password is set. Instead, we set the new password here and
// only update the other user data below.
$new_password = true;
wp_set_password( $userdata['password'], $user_id );
}
if ( isset( $userdata['user_url'] ) ) {
$_userdata['user_url'] = esc_sql( $userdata['user_url'] );
Expand Down
11 changes: 6 additions & 5 deletions lib/core/class-affiliates-shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ public static function affiliates_fields( $atts, $content = null ) {
if ( $field['enabled'] ) {
$value = isset( $_POST[$name] ) ? $_POST[$name] : '';
$value = Affiliates_Utility::filter( $value );
if ( $field['required'] && empty( $value ) ) {
if ( $field['required'] && empty( $value ) && !( is_user_logged_in() && isset( $field['type'] ) && $field['type'] == 'password' ) ) {
$error = true;
$output .= '<div class="error">';
$output .= __( '<strong>ERROR</strong>', AFFILIATES_PLUGIN_DOMAIN );
Expand Down Expand Up @@ -816,26 +816,27 @@ public static function affiliates_fields( $atts, $content = null ) {
$output .= sprintf(
'<input type="%s" class="%s" name="%s" value="%s" %s %s />',
esc_attr( $type ),
'regular-text ' . esc_attr( $name ) . ( $field['required'] ? ' required ' : '' ),
'regular-text ' . esc_attr( $name ) . ( $type != 'password' && $field['required'] ? ' required ' : '' ),
esc_attr( $name ),
esc_attr( stripslashes( $value ) ),
$field['required'] ? ' required="required" ' : '',
( $type != 'password' && $field['required'] ) ? ' required="required" ' : '',
$extra
);
$output .= '</label>';
$output .= '</div>';

if ( $type == 'password' ) {
// the second passwort field is also not required
$output .= '<div class="field">';
$output .= '<label>';
$output .= sprintf( __( 'Repeat %s', AFFILIATES_PLUGIN_DOMAIN ), esc_html( stripslashes( $field['label'] ) ) ); // @todo i18n
$output .= sprintf(
'<input type="%s" class="%s" name="%s" value="%s" %s %s />',
esc_attr( $type ),
'regular-text ' . esc_attr( $name ) . ( $field['required'] ? ' required ' : '' ),
'regular-text ' . esc_attr( $name ),
esc_attr( $name . '2' ),
esc_attr( $value ),
$field['required'] ? ' required="required" ' : '',
'',
$extra
);
$output .= '</label>';
Expand Down
95 changes: 25 additions & 70 deletions lib/core/wp-init.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,12 @@ function affiliates_wp_enqueue_scripts() {
add_action( 'wpmu_new_blog', 'affiliates_wpmu_new_blog', 10, 2 );
add_action( 'delete_blog', 'affiliates_delete_blog', 10, 2 );

//global $affiliates_version, $affiliates_admin_messages;

add_action( 'init', 'affiliates_version_check' );
function affiliates_version_check() {
global $affiliates_version, $affiliates_admin_messages;
$previous_version = get_option( 'affiliates_plugin_version', null );
$affiliates_version = AFFILIATES_CORE_VERSION;
if ( strcmp( $previous_version, $affiliates_version ) < 0 ) {
if ( version_compare( $previous_version, $affiliates_version ) < 0 ) {
if ( affiliates_update( $previous_version ) ) {
update_option( 'affiliates_plugin_version', $affiliates_version );
} else {
Expand Down Expand Up @@ -253,7 +251,7 @@ function affiliates_get_blogs() {
}

/**
* Create tables and prepare data.
* Create tables and prepare data.
*/
function affiliates_setup() {
global $wpdb, $wp_roles;
Expand Down Expand Up @@ -406,6 +404,7 @@ function affiliates_setup() {
}
}

affiliates_update();
affiliates_update_rewrite_rules();
}

Expand Down Expand Up @@ -462,90 +461,46 @@ function _affiliates_assure_capabilities() {
}

/**
* D'oh :/
* Yes, update hooks are awesome ...
* Update from a previous version or repair on activation (within 2.x).
*
* This is called from affiliates_setup() on plugin activation and affiliates_version_check()
* when a previous version is detected.
*
* @param string $previous_version
* @return boolean
*/
function affiliates_update( $previous_version ) {
global $wpdb, $affiliates_admin_messages;
$result = true;
$queries = array();
switch ( $previous_version ) {
case '1.1.0' :
case '1.1.1' :
// add new fields and index to referrals
$referrals_table = _affiliates_get_tablename( 'referrals' );
$type_row = $wpdb->get_row( "SHOW COLUMNS FROM " . $referrals_table . " LIKE 'type'" );
if ( empty( $type_row ) ) {
$queries[] = "ALTER TABLE " . $referrals_table . "
ADD COLUMN type varchar(10) NULL,
ADD INDEX aff_referrals_tda (type, datetime, affiliate_id)
;";
}
break;
function affiliates_update( $previous_version = null ) {

default : // 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4
if ( !empty( $previous_version ) ) {
$affiliates_users_table = _affiliates_get_tablename( 'affiliates_users' );
if ( $wpdb->get_var( "SHOW TABLES LIKE '" . $affiliates_users_table . "'" ) != $affiliates_users_table ) {
$queries[] = "CREATE TABLE " . $affiliates_users_table . " (
affiliate_id bigint(20) unsigned NOT NULL,
user_id bigint(20) unsigned NOT NULL,
PRIMARY KEY (affiliate_id, user_id)
);";
}
global $wpdb;

// add new fields and index to referrals
$referrals_table = _affiliates_get_tablename( 'referrals' );
$amount_row = $wpdb->get_row( "SHOW COLUMNS FROM " . $referrals_table . " LIKE 'amount'" );
if ( empty( $amount_row ) ) {
$queries[] = "ALTER TABLE " . $referrals_table . "
ADD COLUMN amount decimal(18,2) default NULL,
ADD COLUMN currency_id char(3) default NULL,
ADD COLUMN status varchar(10) NOT NULL DEFAULT '" . AFFILIATES_REFERRAL_STATUS_ACCEPTED . "',
ADD COLUMN type varchar(10) NULL,
ADD INDEX aff_referrals_da (datetime, affiliate_id),
ADD INDEX aff_referrals_sda (status, datetime, affiliate_id),
ADD INDEX aff_referrals_tda (type, datetime, affiliate_id)
;";
$queries[] = "UPDATE " . $referrals_table . " SET status = '" . AFFILIATES_REFERRAL_STATUS_ACCEPTED . "' WHERE status IS NULL;";
}
}
break;
} // switch
// add new PK & fields if it's not a new installation
if ( !empty( $previous_version ) && strcmp( $previous_version, "1.2.0" ) < 0 ) {
$referrals_table = _affiliates_get_tablename( 'referrals' );
$queries[] = "ALTER TABLE " . $referrals_table . "
ADD COLUMN referral_id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
ADD COLUMN reference VARCHAR(100) DEFAULT NULL,
DROP PRIMARY KEY,
ADD PRIMARY KEY (referral_id),
ADD INDEX aff_referrals_ref (reference(20));";
}
if ( !empty( $previous_version ) && strcmp( $previous_version, "2.8.0" ) < 0 ) {
$hits_table = _affiliates_get_tablename( 'hits' );
$result = true;
$queries = array();

$hits_table = _affiliates_get_tablename( 'hits' );
$column = $wpdb->get_row( "SHOW COLUMNS FROM $hits_table LIKE 'campaign_id'" );
if ( empty( $column ) ) {
$queries[] = "ALTER TABLE " . $hits_table . "
ADD COLUMN campaign_id BIGINT(20) UNSIGNED DEFAULT NULL,
ADD INDEX aff_hits_acm (affiliate_id, campaign_id);";
}

$referrals_table = _affiliates_get_tablename( 'referrals' );
$referrals_table = _affiliates_get_tablename( 'referrals' );
$column = $wpdb->get_row( "SHOW COLUMNS FROM $referrals_table LIKE 'campaign_id'" );
if ( empty( $column ) ) {
$queries[] = "ALTER TABLE " . $referrals_table . "
ADD COLUMN campaign_id BIGINT(20) UNSIGNED DEFAULT NULL,
ADD INDEX aff_referrals_ac (affiliate_id, campaign_id),
ADD INDEX aff_referrals_c (campaign_id);";
}
// dbDelta won't handle ALTER ...
// if ( !empty( $queries ) ) {
// require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
// dbDelta( $queries );
// }

foreach ( $queries as $query ) {
// don't use dbDelta, it doesn't handle ALTER
if ( $wpdb->query( $query ) === false ) {
// fail but still try to go on
$result = false;
}
}
if ( !empty( $previous_version ) && strcmp( $previous_version, "2.1.5" ) < 0 ) {
if ( !empty( $previous_version ) && version_compare( $previous_version, '2.1.5' ) < 0 ) {
affiliates_update_rewrite_rules();
}
return $result;
Expand Down
14 changes: 10 additions & 4 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Contributors: itthinx
Donate link: http://www.itthinx.com/plugins/affiliates
Tags: ads, AddToAny, AddThis, advertising, affiliate, affiliate marketing, affiliate plugin, affiliate tool, affiliates, contact form, contact form 7, downloads, e-commerce, Ecwid, Events Manager, Jigoshop, lead, link, marketing, money, partner, Pay per Click, PayPal, PPC, referral, referral links, referrer, sales, shopping cart, TheCartPress, track, transaction, WooCommerce, WP e-Commerce
Requires at least: 4.0.0
Tested up to: 4.2.3
Stable tag: 2.11.0
Tested up to: 4.3
Stable tag: 2.12.0
License: GPLv3

The Affiliates system provides powerful tools to maintain an Affiliate Marketing Program.
Expand Down Expand Up @@ -340,6 +340,12 @@ See [Affiliates Screenshots](http://www.itthinx.com/plugins/affiliates/affiliate

== Changelog ==

= 2.12.0 =
* Fixed ompatibility with WordPress 4.3 (widget constructor).
* Fixed potential issues when upgrading from earlier versions.
* Fixed a PHP Warning related to password changes through the affiliate fields.
* Added a guard against multiple invocations of the affiliate user update procedure in the same request.

= 2.11.0 =
* Added a cookie timeout filter.
* Removed menu title translation to circumvent effects of core bug 18857.
Expand Down Expand Up @@ -654,5 +660,5 @@ See [Affiliates Screenshots](http://www.itthinx.com/plugins/affiliates/affiliate

== Upgrade Notice ==

= 2.11.0 =
This release improves the API by adding a cookie timeout filter and circumvents issues with translated screens related to a core bug.
= 2.12.0 =
This release includes compatibility fixes for WordPress 4.3 and solves potential issues when upgrading from earlier versions.

0 comments on commit 385f328

Please sign in to comment.