mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-06-05 15:09:37 +09:00
- fixed licenses validation;
- fixed no-UM custom roles update;
This commit is contained in:
@@ -109,7 +109,7 @@ th.column-email.column-primary {
|
||||
width: 30.5%;
|
||||
max-width: 350px;
|
||||
padding: 14px;
|
||||
min-height: 220px;
|
||||
min-height: 240px;
|
||||
position: relative;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
@@ -1704,7 +1704,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) {
|
||||
return;
|
||||
|
||||
foreach ( $_POST['um_options'] as $key => $value ) {
|
||||
$this->previous_licenses[$key] = UM()->options()->get( $key );
|
||||
$this->previous_licenses[ $key ] = UM()->options()->get( $key );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1713,25 +1713,27 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) {
|
||||
*
|
||||
*/
|
||||
function licenses_save() {
|
||||
if ( empty( $_POST['um_options'] ) || empty( $_POST['licenses_settings'] ) )
|
||||
if ( empty( $_POST['um_options'] ) || empty( $_POST['licenses_settings'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $_POST['um_options'] as $key => $value ) {
|
||||
$edd_action = '';
|
||||
$license_key = '';
|
||||
if ( empty( $this->previous_licenses[$key] ) && ! empty( $value ) || ( ! empty( $this->previous_licenses[$key] ) && ! empty( $value ) && $this->previous_licenses[$key] != $value ) ) {
|
||||
if ( empty( $this->previous_licenses[ $key ] ) && ! empty( $value ) || ( ! empty( $this->previous_licenses[ $key ] ) && ! empty( $value ) && $this->previous_licenses[ $key ] != $value ) ) {
|
||||
$edd_action = 'activate_license';
|
||||
$license_key = $value;
|
||||
} elseif ( ! empty( $this->previous_licenses[$key] ) && empty( $value ) ) {
|
||||
} elseif ( ! empty( $this->previous_licenses[ $key ] ) && empty( $value ) ) {
|
||||
$edd_action = 'deactivate_license';
|
||||
$license_key = $this->previous_licenses[$key];
|
||||
} elseif ( ! empty( $this->previous_licenses[$key] ) && ! empty( $value ) ) {
|
||||
$license_key = $this->previous_licenses[ $key ];
|
||||
} elseif ( ! empty( $this->previous_licenses[ $key ] ) && ! empty( $value ) ) {
|
||||
$edd_action = 'check_license';
|
||||
$license_key = $value;
|
||||
}
|
||||
|
||||
if ( empty( $edd_action ) )
|
||||
if ( empty( $edd_action ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$item_name = false;
|
||||
$version = false;
|
||||
@@ -1762,15 +1764,17 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) {
|
||||
)
|
||||
);
|
||||
|
||||
if ( ! is_wp_error( $request ) )
|
||||
if ( ! is_wp_error( $request ) ) {
|
||||
$request = json_decode( wp_remote_retrieve_body( $request ) );
|
||||
}
|
||||
|
||||
$request = ( $request ) ? maybe_unserialize( $request ) : false;
|
||||
|
||||
if ( $edd_action == 'activate_license' || $edd_action == 'check_license' )
|
||||
if ( $edd_action == 'activate_license' || $edd_action == 'check_license' ) {
|
||||
update_option( "{$key}_edd_answer", $request );
|
||||
else
|
||||
} else {
|
||||
delete_option( "{$key}_edd_answer" );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1884,13 +1888,13 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) {
|
||||
<tbody>
|
||||
<?php foreach ( $section_fields as $field_data ) {
|
||||
$option_value = UM()->options()->get( $field_data['id'] );
|
||||
$value = isset( $option_value ) && ! empty( $option_value ) ? $option_value : ( isset( $field_data['default'] ) ? $field_data['default'] : '' );
|
||||
$value = isset( $option_value ) && ! empty( $option_value ) ? $option_value : ( isset( $field_data['default'] ) ? $field_data['default'] : '' );
|
||||
|
||||
$license = get_option( "{$field_data['id']}_edd_answer" );
|
||||
|
||||
if ( is_object( $license ) && ! empty( $value ) ) {
|
||||
// activate_license 'invalid' on anything other than valid, so if there was an error capture it
|
||||
if ( false === $license->success ) {
|
||||
if ( empty( $license->success ) ) {
|
||||
|
||||
if ( ! empty( $license->error ) ) {
|
||||
switch ( $license->error ) {
|
||||
@@ -1935,16 +1939,16 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) {
|
||||
case 'invalid' :
|
||||
case 'site_inactive' :
|
||||
|
||||
$class = 'error';
|
||||
$messages[] = sprintf(
|
||||
__( 'Your %s is not active for this URL. Please <a href="%s" target="_blank">visit your account page</a> to manage your license key URLs.', 'ultimate-member' ),
|
||||
$field_data['item_name'],
|
||||
'https://ultimatemember.com/account?utm_campaign=admin&utm_source=licenses&utm_medium=invalid'
|
||||
);
|
||||
$class = 'error';
|
||||
$messages[] = sprintf(
|
||||
__( 'Your %s is not active for this URL. Please <a href="%s" target="_blank">visit your account page</a> to manage your license key URLs.', 'ultimate-member' ),
|
||||
$field_data['item_name'],
|
||||
'https://ultimatemember.com/account?utm_campaign=admin&utm_source=licenses&utm_medium=invalid'
|
||||
);
|
||||
|
||||
$license_status = 'license-' . $class . '-notice';
|
||||
$license_status = 'license-' . $class . '-notice';
|
||||
|
||||
break;
|
||||
break;
|
||||
|
||||
case 'item_name_mismatch' :
|
||||
|
||||
@@ -1975,7 +1979,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) {
|
||||
default :
|
||||
|
||||
$class = 'error';
|
||||
$error = ! empty( $license->error ) ? $license->error : __( 'unknown_error', 'ultimate-member' );
|
||||
$error = ! empty( $license->error ) ? $license->error : __( 'unknown_error', 'ultimate-member' );
|
||||
$messages[] = sprintf( __( 'There was an error with this license key: %s. Please <a href="%s">contact our support team</a>.', 'ultimate-member' ), $error, 'https://ultimatemember.com/support' );
|
||||
|
||||
$license_status = 'license-' . $class . '-notice';
|
||||
@@ -1983,12 +1987,24 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) {
|
||||
}
|
||||
} else {
|
||||
$class = 'error';
|
||||
$error = ! empty( $license->error ) ? $license->error : __( 'unknown_error', 'ultimate-member' );
|
||||
$error = ! empty( $license->error ) ? $license->error : __( 'unknown_error', 'ultimate-member' );
|
||||
$messages[] = sprintf( __( 'There was an error with this license key: %s. Please <a href="%s">contact our support team</a>.', 'ultimate-member' ), $error, 'https://ultimatemember.com/support' );
|
||||
|
||||
$license_status = 'license-' . $class . '-notice';
|
||||
}
|
||||
|
||||
} elseif ( ! empty( $license->errors ) ) {
|
||||
|
||||
$errors = array_keys( $license->errors );
|
||||
$errors_data = array_values( $license->errors );
|
||||
|
||||
$class = 'error';
|
||||
$error = ! empty( $errors[0] ) ? $errors[0] : __( 'unknown_error', 'ultimate-member' );
|
||||
$errors_data = ! empty( $errors_data[0][0] ) ? ', ' . $errors_data[0][0] : '';
|
||||
$messages[] = sprintf( __( 'There was an error with this license key: %s%s. Please <a href="%s">contact our support team</a>.', 'ultimate-member' ), $error, $errors_data, 'https://ultimatemember.com/support' );
|
||||
|
||||
$license_status = 'license-' . $class . '-notice';
|
||||
|
||||
} else {
|
||||
|
||||
switch( $license->license ) {
|
||||
@@ -2033,16 +2049,16 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) {
|
||||
case 'invalid' :
|
||||
case 'site_inactive' :
|
||||
|
||||
$class = 'error';
|
||||
$messages[] = sprintf(
|
||||
__( 'Your %s is not active for this URL. Please <a href="%s" target="_blank">visit your account page</a> to manage your license key URLs.', 'ultimate-member' ),
|
||||
$field_data['item_name'],
|
||||
'https://ultimatemember.com/account?utm_campaign=admin&utm_source=licenses&utm_medium=invalid'
|
||||
);
|
||||
$class = 'error';
|
||||
$messages[] = sprintf(
|
||||
__( 'Your %s is not active for this URL. Please <a href="%s" target="_blank">visit your account page</a> to manage your license key URLs.', 'ultimate-member' ),
|
||||
$field_data['item_name'],
|
||||
'https://ultimatemember.com/account?utm_campaign=admin&utm_source=licenses&utm_medium=invalid'
|
||||
);
|
||||
|
||||
$license_status = 'license-' . $class . '-notice';
|
||||
$license_status = 'license-' . $class . '-notice';
|
||||
|
||||
break;
|
||||
break;
|
||||
|
||||
case 'item_name_mismatch' :
|
||||
|
||||
@@ -2073,39 +2089,39 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) {
|
||||
case 'valid' :
|
||||
default:
|
||||
|
||||
$class = 'valid';
|
||||
$class = 'valid';
|
||||
|
||||
$now = current_time( 'timestamp' );
|
||||
$expiration = strtotime( $license->expires, current_time( 'timestamp' ) );
|
||||
$now = current_time( 'timestamp' );
|
||||
$expiration = strtotime( $license->expires, $now );
|
||||
|
||||
if( 'lifetime' === $license->expires ) {
|
||||
if( 'lifetime' === $license->expires ) {
|
||||
|
||||
$messages[] = __( 'License key never expires.', 'ultimate-member' );
|
||||
$messages[] = __( 'License key never expires.', 'ultimate-member' );
|
||||
|
||||
$license_status = 'license-lifetime-notice';
|
||||
$license_status = 'license-lifetime-notice';
|
||||
|
||||
} elseif( $expiration > $now && $expiration - $now < ( DAY_IN_SECONDS * 30 ) ) {
|
||||
} elseif( $expiration > $now && $expiration - $now < ( DAY_IN_SECONDS * 30 ) ) {
|
||||
|
||||
$messages[] = sprintf(
|
||||
__( 'Your license key expires soon! It expires on %s. <a href="%s" target="_blank">Renew your license key</a>.', 'ultimate-member' ),
|
||||
date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) ),
|
||||
'https://ultimatemember.com/checkout/?edd_license_key=' . $value . '&utm_campaign=admin&utm_source=licenses&utm_medium=renew'
|
||||
);
|
||||
$messages[] = sprintf(
|
||||
__( 'Your license key expires soon! It expires on %s. <a href="%s" target="_blank">Renew your license key</a>.', 'ultimate-member' ),
|
||||
date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) ),
|
||||
'https://ultimatemember.com/checkout/?edd_license_key=' . $value . '&utm_campaign=admin&utm_source=licenses&utm_medium=renew'
|
||||
);
|
||||
|
||||
$license_status = 'license-expires-soon-notice';
|
||||
$license_status = 'license-expires-soon-notice';
|
||||
|
||||
} else {
|
||||
} else {
|
||||
|
||||
$messages[] = sprintf(
|
||||
__( 'Your license key expires on %s.', 'ultimate-member' ),
|
||||
date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) )
|
||||
);
|
||||
$messages[] = sprintf(
|
||||
__( 'Your license key expires on %s.', 'ultimate-member' ),
|
||||
date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) )
|
||||
);
|
||||
|
||||
$license_status = 'license-expiration-date-notice';
|
||||
$license_status = 'license-expiration-date-notice';
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
@@ -2121,9 +2137,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) {
|
||||
|
||||
$license_status = null;
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
} ?>
|
||||
|
||||
<tr class="um-settings-line">
|
||||
<th><label for="um_options_<?php echo $field_data['id'] ?>"><?php echo $field_data['label'] ?></label></th>
|
||||
|
||||
@@ -429,11 +429,11 @@ if ( $role_keys ) {
|
||||
$role_meta = get_option( "um_role_{$role_key}_meta" );
|
||||
if ( $role_meta ) {
|
||||
|
||||
$roles['um_' . $role_key] = array(
|
||||
$roles[ 'um_' . $role_key ] = array(
|
||||
'key' => $role_key,
|
||||
'users' => ! empty( $users_count['avail_roles']['um_' . $role_key] ) ? $users_count['avail_roles']['um_' . $role_key] : 0
|
||||
'users' => ! empty( $users_count['avail_roles'][ 'um_' . $role_key ] ) ? $users_count['avail_roles'][ 'um_' . $role_key ] : 0
|
||||
);
|
||||
$roles['um_' . $role_key] = array_merge( $roles['um_' . $role_key], $role_meta );
|
||||
$roles[ 'um_' . $role_key ] = array_merge( $roles[ 'um_' . $role_key ], $role_meta );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -441,18 +441,20 @@ if ( $role_keys ) {
|
||||
global $wp_roles;
|
||||
|
||||
foreach ( $wp_roles->roles as $roleID => $role_data ) {
|
||||
if ( in_array( $roleID, array_keys( $roles ) ) )
|
||||
if ( in_array( $roleID, array_keys( $roles ) ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$roles[$roleID] = array(
|
||||
$roles[ $roleID ] = array(
|
||||
'key' => $roleID,
|
||||
'users' => ! empty( $users_count['avail_roles'][$roleID] ) ? $users_count['avail_roles'][$roleID] : 0,
|
||||
'name' => $role_data['name']
|
||||
'users' => ! empty( $users_count['avail_roles'][ $roleID ] ) ? $users_count['avail_roles'][ $roleID ] : 0,
|
||||
'name' => $role_data['name']
|
||||
);
|
||||
|
||||
$role_meta = get_option( "um_role_{$roleID}_meta" );
|
||||
if ( $role_meta )
|
||||
$roles[$roleID] = array_merge( $roles[$roleID], $role_meta );
|
||||
if ( $role_meta ) {
|
||||
$roles[ $roleID ] = array_merge( $roles[ $roleID ], $role_meta );
|
||||
}
|
||||
}
|
||||
|
||||
switch( strtolower( $order ) ) {
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
|
||||
function um_upgrade_roles2054() {
|
||||
UM()->admin()->check_ajax_nonce();
|
||||
|
||||
um_maybe_unset_time_limit();
|
||||
|
||||
include 'roles.php';
|
||||
|
||||
update_option( 'um_last_version_upgrade', '2.0.54' );
|
||||
|
||||
wp_send_json_success( array( 'message' => __( 'Roles was upgraded successfully', 'ultimate-member' ) ) );
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
return array(
|
||||
'roles2054' => 'roles2054',
|
||||
);
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
<?php if ( ! defined( 'ABSPATH' ) ) exit; ?>
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
jQuery( document ).ready( function() {
|
||||
//upgrade styles
|
||||
um_add_upgrade_log( '<?php echo esc_js( __( 'Upgrade user roles...', 'ultimate-member' ) ) ?>' );
|
||||
|
||||
jQuery.ajax({
|
||||
url: wp.ajax.settings.url,
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: 'um_roles2054',
|
||||
nonce: um_admin_scripts.nonce
|
||||
},
|
||||
success: function( response ) {
|
||||
if ( typeof response.data != 'undefined' ) {
|
||||
um_add_upgrade_log( response.data.message );
|
||||
//switch to the next package
|
||||
um_run_upgrade();
|
||||
} else {
|
||||
um_wrong_ajax();
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
um_something_wrong();
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
<?php if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
$role_keys = get_option( 'um_roles', array() );
|
||||
$role_keys = array_map( function( $item ) {
|
||||
return 'um_' . $item;
|
||||
}, $role_keys );
|
||||
|
||||
global $wp_roles;
|
||||
foreach ( $wp_roles->roles as $roleID => $role_data ) {
|
||||
if ( in_array( $roleID, $role_keys ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$role_meta = get_option( "um_role_{$roleID}_meta", array() );
|
||||
if ( ! empty( $role_meta ) ) {
|
||||
if ( $role_meta['name'] === null ) {
|
||||
unset( $role_meta['name'] );
|
||||
update_option( "um_role_{$roleID}_meta", $role_meta );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -98,9 +98,11 @@ if ( ! empty( $_POST['role'] ) ) {
|
||||
$id = $_GET['id'];
|
||||
|
||||
$pre_role_meta = get_option( "um_role_{$id}_meta", array() );
|
||||
$data['name'] = $pre_role_meta['name'];
|
||||
if ( isset( $pre_role_meta['name'] ) ) {
|
||||
$data['name'] = $pre_role_meta['name'];
|
||||
}
|
||||
|
||||
$redirect = add_query_arg( array( 'page' => 'um_roles', 'tab'=>'edit', 'id'=>$id, 'msg'=>'u' ), admin_url( 'admin.php' ) );
|
||||
$redirect = add_query_arg( array( 'page' => 'um_roles', 'tab' => 'edit', 'id' => $id, 'msg'=> 'u' ), admin_url( 'admin.php' ) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user