Created
July 14, 2016 15:48
-
-
Save nusserstudios/c7dc6963229abd738621e6c8a9344b1b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Profile Builder Edit Profile Link in single-userlisting visible only for users with the edit_users permission | |
* Usage: [pb-edit-profile-link link="http://www.example.com/edit-profile" title="User Profile"] | |
*/ | |
add_shortcode('pb-edit-profile-link', 'func_pb_edit_profile_link'); | |
function func_pb_edit_profile_link( $atts ){ | |
if ( !isset( $atts['link'] ) || !isset( $atts['title'])){ | |
return ''; | |
} | |
//get_userid_from userlisting | |
$permalink = $_SERVER['REQUEST_URI']; | |
$pos = strrpos($permalink, '/'); | |
$substr = substr($permalink, 0, $pos ); | |
$pos = strrpos($substr, '/'); | |
$user_id = substr($substr, $pos + 1 ); | |
if ( current_user_can( 'edit_users' ) ){ | |
$output = '<label>Make changes to: </label><span><a href="' . $atts['link'] . '?edit_user='. $user_id . '">' . $atts['title'] . '</a></span>'; | |
return $output; | |
} | |
else { | |
return ''; | |
} | |
} | |
/* | |
* Delete user from front-end edit-profile only displayed for admins. | |
* Usage shortcode: [wppbc_link_delete_user] | |
*/ | |
add_action('init','wppbc_delete_user'); | |
function wppbc_delete_user() { | |
if(isset($_REQUEST['actiond']) && $_REQUEST['actiond']=='wppbc_delete_this_user') { | |
include("./wp-admin/includes/user.php" ); | |
//check admin permissions. | |
if (current_user_can('edit_users')) { | |
$user_id = intval($_REQUEST['edit_user']); | |
echo'<script> window.location = window.location.pathname; </script>'; | |
wp_delete_user($user_id); | |
} | |
} | |
} | |
add_shortcode('wppbc_link_delete_user', 'wppbc_link_delete_user_func'); | |
function wppbc_link_delete_user_func(){ | |
if ( is_user_logged_in() ) { | |
$user = new WP_User( get_current_user_id() ); | |
if ( !empty( $user->roles ) && is_array( $user->roles ) ) { | |
foreach ( $user->roles as $role ){ | |
if ( $role == 'administrator' && isset($_REQUEST['edit_user']) && current_user_can('edit_users') ){ | |
return '<a href=' . get_permalink() . '?edit_user=' . $_REQUEST['edit_user'] . '&actiond=wppbc_delete_this_user>Delete user</a>'; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment