summaryrefslogtreecommitdiffstats
path: root/wp-inst/wp-admin/admin-functions.php
diff options
context:
space:
mode:
Diffstat (limited to 'wp-inst/wp-admin/admin-functions.php')
-rw-r--r--wp-inst/wp-admin/admin-functions.php44
1 files changed, 25 insertions, 19 deletions
diff --git a/wp-inst/wp-admin/admin-functions.php b/wp-inst/wp-admin/admin-functions.php
index cb3fcff..e6d0521 100644
--- a/wp-inst/wp-admin/admin-functions.php
+++ b/wp-inst/wp-admin/admin-functions.php
@@ -301,26 +301,33 @@ function wp_delete_category($cat_ID) {
return 1;
}
-function wp_delete_user($id) {
+function wp_delete_user($id, $reassign = 'novalue') {
global $wpdb;
$id = (int) $id;
-
- $post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_author = $id");
-
- if ($post_ids) {
- $post_ids = implode(',', $post_ids);
-
- // Delete comments, *backs
- $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_post_ID IN ($post_ids)");
- // Clean cats
- $wpdb->query("DELETE FROM $wpdb->post2cat WHERE post_id IN ($post_ids)");
- // Clean post_meta
- $wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id IN ($post_ids)");
+
+ if($reassign == 'novalue') {
+ $post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_author = $id");
+
+ if ($post_ids) {
+ $post_ids = implode(',', $post_ids);
+
+ // Delete comments, *backs
+ $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_post_ID IN ($post_ids)");
+ // Clean cats
+ $wpdb->query("DELETE FROM $wpdb->post2cat WHERE post_id IN ($post_ids)");
+ // Clean post_meta
+ $wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id IN ($post_ids)");
+ // Delete posts
+ $wpdb->query("DELETE FROM $wpdb->posts WHERE post_author = $id");
+ }
+
// Clean links
$wpdb->query("DELETE FROM $wpdb->links WHERE link_owner = $id");
- // Delete posts
- $wpdb->query("DELETE FROM $wpdb->posts WHERE post_author = $id");
+ } else {
+ $reassign = (int)$reassign;
+ $wpdb->query("UPDATE $wpdb->posts SET post_author = {$reassign} WHERE post_author = {$id}");
+ $wpdb->query("UPDATE $wpdb->links SET link_owner = {$reassign} WHERE link_owner = {$id}");
}
// FINALLY, delete user
@@ -996,14 +1003,13 @@ function user_can_access_admin_page() {
global $pagenow;
global $menu;
global $submenu;
- global $user_level;
$parent = get_admin_page_parent();
foreach ($menu as $menu_array) {
//echo "parent array: " . $menu_array[2];
if ($menu_array[2] == $parent) {
- if ($user_level < $menu_array[1]) {
+ if ( !current_user_can($menu_array[1]) ) {
return false;
} else {
break;
@@ -1014,7 +1020,7 @@ function user_can_access_admin_page() {
if (isset($submenu[$parent])) {
foreach ($submenu[$parent] as $submenu_array) {
if ($submenu_array[2] == $pagenow) {
- if ($user_level < $submenu_array[1]) {
+ if ( !current_user_can($submenu_array[1]) ) {
return false;
} else {
return true;
@@ -1395,4 +1401,4 @@ function documentation_link( $for ) {
return;
}
-?> \ No newline at end of file
+?>