diff --git a/admin/assets/js/um-admin-users.js b/admin/assets/js/um-admin-users.js index 8f3f03bd..c9dcb5e6 100644 --- a/admin/assets/js/um-admin-users.js +++ b/admin/assets/js/um-admin-users.js @@ -1,3 +1,30 @@ jQuery(document).ready(function() { - -}); \ No newline at end of file + + 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 ); + + }); + + + +}); + diff --git a/admin/core/um-admin-actions.php b/admin/core/um-admin-actions.php index c628d2f3..2871be41 100644 --- a/admin/core/um-admin-actions.php +++ b/admin/core/um-admin-actions.php @@ -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'; diff --git a/admin/templates/role/sync.php b/admin/templates/role/sync.php index e026cb07..2b4bbba3 100644 --- a/admin/templates/role/sync.php +++ b/admin/templates/role/sync.php @@ -25,7 +25,7 @@ $url = add_query_arg('wp_role', $saved_r, $url);
- +