mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-16 05:03:33 +09:00
Fix sync role widget in manage roles
This commit is contained in:
@@ -1,3 +1,30 @@
|
||||
jQuery(document).ready(function() {
|
||||
|
||||
});
|
||||
|
||||
function getParameterByName(name, url) {
|
||||
if (!url) url = window.location.href;
|
||||
name = name.replace(/[\[\]]/g, "\\$&");
|
||||
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
|
||||
results = regex.exec(url);
|
||||
if (!results) return null;
|
||||
if (!results[2]) return '';
|
||||
return decodeURIComponent(results[2].replace(/\+/g, " "));
|
||||
}
|
||||
|
||||
jQuery("#_um_synced_role").on("change",function(){
|
||||
$sync_button = jQuery("#_um_button_sync_update_button");
|
||||
var url = $sync_button.attr("href");
|
||||
|
||||
if ( ! getParameterByName('wp_role', url) ) {
|
||||
console.log("wp_role is not set");
|
||||
}
|
||||
|
||||
var um_role = getParameterByName('um_role', url);
|
||||
var wp_role = jQuery(this).val();
|
||||
$sync_button.attr("href", window.location.href+'&um_adm_action=mass_role_sync&um_role='+um_role+'&wp_role='+wp_role );
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -163,24 +163,25 @@
|
||||
add_action('um_admin_do_action__mass_role_sync', 'um_admin_do_action__mass_role_sync');
|
||||
function um_admin_do_action__mass_role_sync( $action ){
|
||||
global $ultimatemember;
|
||||
if ( !is_admin() || !current_user_can( 'edit_user' ) ) die();
|
||||
if ( !is_admin() || !current_user_can( 'edit_user' ) ) wp_die('You don\'t have permissions to access this page.');
|
||||
|
||||
if ( !isset($_REQUEST['post']) || !is_numeric( $_REQUEST['post'] ) ) die();
|
||||
if ( !isset($_REQUEST['post']) || !is_numeric( $_REQUEST['post'] ) ) wp_die('You\'re not allowed to do this.');
|
||||
|
||||
$post_id = (int) $_REQUEST['post'];
|
||||
|
||||
$post = get_post( $post_id );
|
||||
$slug = $post->post_name;
|
||||
|
||||
|
||||
if ( $slug != $_REQUEST['um_role'] )
|
||||
die();
|
||||
|
||||
if ( get_post_meta( $post_id, '_um_synced_role', true ) != $_REQUEST['wp_role'] )
|
||||
die();
|
||||
wp_die('Invalid community role.');
|
||||
|
||||
$um_synced_role = get_post_meta( $post_id, '_um_synced_role', true );
|
||||
|
||||
if ( $slug == 'admin' ) {
|
||||
$_REQUEST['wp_role'] = 'administrator';
|
||||
update_post_meta( $post_id, '_um_synced_role', 'administrator' );
|
||||
}else{
|
||||
update_post_meta( $post_id, '_um_synced_role', $_REQUEST['wp_role'] );
|
||||
}
|
||||
|
||||
$wp_role = ( $_REQUEST['wp_role'] ) ? $_REQUEST['wp_role'] : 'subscriber';
|
||||
|
||||
@@ -25,7 +25,7 @@ $url = add_query_arg('wp_role', $saved_r, $url);
|
||||
</span>
|
||||
</p><div class="um-admin-clear"></div>
|
||||
|
||||
<p><a href="<?php echo $url; ?>" class="button"><?php _e('Sync / update all existing users','ultimatemember'); ?></a></p>
|
||||
<p><a href="<?php echo $url; ?>" id="_um_button_sync_update_button" class="button"><?php _e('Sync / update all existing users','ultimatemember'); ?></a></p>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user