Changes in trunk/wp-admin/admin-db.php [4364:3350]
- File:
-
- 1 edited
-
trunk/wp-admin/admin-db.php (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/admin-db.php
r4364 r3350 4 4 global $wpdb; 5 5 $user_id = (int) $user_id; 6 $query = "SELECT ID, post_title FROM $wpdb->posts WHERE post_ type = 'post' AND post_status = 'draft' AND post_author = $user_id ORDER BY ID DESC";6 $query = "SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'draft' AND post_author = $user_id ORDER BY ID DESC"; 7 7 $query = apply_filters('get_users_drafts', $query); 8 8 return $wpdb->get_results( $query ); … … 15 15 16 16 $editable = get_editable_user_ids( $user_id ); 17 17 18 18 if( !$editable ) { 19 19 $other_drafts = ''; 20 20 } else { 21 21 $editable = join(',', $editable); 22 $other_drafts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_ type = 'post' AND post_status = 'draft' AND post_author IN ($editable) AND post_author != '$user_id' ");22 $other_drafts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'draft' AND post_author IN ($editable) AND post_author != '$user_id' "); 23 23 } 24 24 … … 35 35 } else { 36 36 $editable = join(',', $editable); 37 $authors = $wpdb->get_results( "SELECT * FROM $wpdb->users WHERE ID IN ($editable) ORDER BY display_name" );37 $authors = $wpdb->get_results( "SELECT * FROM $wpdb->users WHERE ID IN ($editable)" ); 38 38 } 39 39 … … 43 43 function get_editable_user_ids( $user_id, $exclude_zeros = true ) { 44 44 global $wpdb; 45 45 46 46 $user = new WP_User( $user_id ); 47 47 48 48 if ( ! $user->has_cap('edit_others_posts') ) { 49 49 if ( $user->has_cap('edit_posts') || $exclude_zeros == false ) … … 58 58 if ( $exclude_zeros ) 59 59 $query .= " AND meta_value != '0'"; 60 60 61 61 return $wpdb->get_col( $query ); 62 62 } … … 84 84 85 85 extract($catarr); 86 87 if( trim( $cat_name ) == '' )88 return 0;89 86 90 87 $cat_ID = (int) $cat_ID; … … 96 93 $update = false; 97 94 98 $cat_name = apply_filters('pre_category_name',$cat_name);99 95 $cat_name = wp_specialchars($cat_name); 96 100 97 if (empty ($category_nicename)) 101 98 $category_nicename = sanitize_title($cat_name); 102 99 else 103 100 $category_nicename = sanitize_title($category_nicename); 104 $category_nicename = apply_filters('pre_category_nicename', $category_nicename);105 101 106 102 if (empty ($category_description)) 107 103 $category_description = ''; 108 $category_description = apply_filters('pre_category_description', $category_description); 109 110 $category_parent = (int) $category_parent; 111 if ( empty($category_parent) || !get_category( $category_parent ) || $category_parent == $cat_ID ) 104 105 if (empty ($category_parent)) 112 106 $category_parent = 0; 113 107 114 if ( isset($posts_private) )115 $posts_private = (int) $posts_private;116 else117 $posts_private = 0;118 119 if ( isset($links_private) )120 $links_private = (int) $links_private;121 else122 $links_private = 0;123 124 108 if (!$update) { 125 $wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_description, category_parent , links_private, posts_private) VALUES ('0', '$cat_name', '$category_nicename', '$category_description', '$category_parent', '$links_private', '$posts_private')");109 $wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_description, category_parent) VALUES ('0', '$cat_name', '$category_nicename', '$category_description', '$category_parent')"); 126 110 $cat_ID = $wpdb->insert_id; 127 111 } else { 128 $wpdb->query ("UPDATE $wpdb->categories SET cat_name = '$cat_name', category_nicename = '$category_nicename', category_description = '$category_description', category_parent = '$category_parent' , links_private = '$links_private', posts_private = '$posts_private'WHERE cat_ID = '$cat_ID'");129 } 130 112 $wpdb->query ("UPDATE $wpdb->categories SET cat_name = '$cat_name', category_nicename = '$category_nicename', category_description = '$category_description', category_parent = '$category_parent' WHERE cat_ID = '$cat_ID'"); 113 } 114 131 115 if ( $category_nicename == '' ) { 132 116 $category_nicename = sanitize_title($cat_name, $cat_ID ); … … 170 154 171 155 // Don't delete the default cat. 172 if ( $cat_ID == get_option('default_category'))156 if (1 == $cat_ID) 173 157 return 0; 174 158 175 if ( $cat_ID == get_option('default_link_category') )176 return 0;177 178 159 $category = get_category($cat_ID); 179 160 … … 181 162 182 163 // Delete the category. 183 if ( !$wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'") ) 184 return 0; 164 $wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'"); 185 165 186 166 // Update children to point to new parent. 187 167 $wpdb->query("UPDATE $wpdb->categories SET category_parent = '$parent' WHERE category_parent = '$cat_ID'"); 188 168 189 // Only set posts and links to the default category if they're not in another category already. 190 $default_cat = get_option('default_category'); 191 $posts = $wpdb->get_col("SELECT post_id FROM $wpdb->post2cat WHERE category_id='$cat_ID'"); 192 if ( is_array($posts) ) foreach ($posts as $post_id) { 193 $cats = wp_get_post_categories($post_id); 194 if ( 1 == count($cats) ) 195 $cats = array($default_cat); 196 else 197 $cats = array_diff($cats, array($cat_ID)); 198 wp_set_post_categories($post_id, $cats); 199 } 200 201 $default_link_cat = get_option('default_link_category'); 202 $links = $wpdb->get_col("SELECT link_id FROM $wpdb->link2cat WHERE category_id='$cat_ID'"); 203 if ( is_array($links) ) foreach ($links as $link_id) { 204 $cats = wp_get_link_cats($link_id); 205 if ( 1 == count($cats) ) 206 $cats = array($default_link_cat); 207 else 208 $cats = array_diff($cats, array($cat_ID)); 209 wp_set_link_cats($link_id, $cats); 210 } 211 169 // TODO: Only set categories to general if they're not in another category already 170 $wpdb->query("UPDATE $wpdb->post2cat SET category_id='1' WHERE category_id='$cat_ID'"); 171 212 172 wp_cache_delete($cat_ID, 'category'); 213 173 wp_cache_delete('all_category_ids', 'category'); … … 234 194 235 195 if ($post_id) 236 wp_set_post_cat egories($post_id, $cat_ids);196 wp_set_post_cats('', $post_id, $cat_ids); 237 197 238 198 return $cat_ids; … … 270 230 271 231 // FINALLY, delete user 272 do_action('delete_user', $id);273 274 232 $wpdb->query("DELETE FROM $wpdb->users WHERE ID = $id"); 275 233 $wpdb->query("DELETE FROM $wpdb->usermeta WHERE user_id = '$id'"); … … 278 236 wp_cache_delete($user->user_login, 'userlogins'); 279 237 238 do_action('delete_user', $id); 239 280 240 return true; 281 241 } 282 242 283 function wp_revoke_user($id) { 284 $id = (int) $id; 285 286 $user = new WP_User($id); 287 $user->remove_all_caps(); 243 function get_link($link_id, $output = OBJECT) { 244 global $wpdb; 245 246 $link = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE link_id = '$link_id'"); 247 248 if ( $output == OBJECT ) { 249 return $link; 250 } elseif ( $output == ARRAY_A ) { 251 return get_object_vars($link); 252 } elseif ( $output == ARRAY_N ) { 253 return array_values(get_object_vars($link)); 254 } else { 255 return $link; 256 } 288 257 } 289 258 290 259 function wp_insert_link($linkdata) { 291 260 global $wpdb, $current_user; 292 261 293 262 extract($linkdata); 294 263 295 264 $update = false; 296 297 265 if ( !empty($link_id) ) 298 266 $update = true; 299 267 300 if( trim( $link_name ) == '' )301 return 0;302 $link_name = apply_filters('pre_link_name', $link_name);303 304 if( trim( $link_url ) == '' )305 return 0;306 $link_url = apply_filters('pre_link_url', $link_url);307 308 268 if ( empty($link_rating) ) 309 $link_rating = 0; 310 else 311 $link_rating = (int) $link_rating; 312 313 if ( empty($link_image) ) 314 $link_image = ''; 315 $link_image = apply_filters('pre_link_image', $link_image); 269 $link_rating = 0; 316 270 317 271 if ( empty($link_target) ) 318 $link_target = ''; 319 $link_target = apply_filters('pre_link_target', $link_target); 272 $link_target = ''; 320 273 321 274 if ( empty($link_visible) ) 322 275 $link_visible = 'Y'; 323 $link_visibile = preg_replace('/[^YNyn]/', '', $link_visible); 324 276 325 277 if ( empty($link_owner) ) 326 278 $link_owner = $current_user->id; 327 else328 $link_owner = (int) $link_owner;329 279 330 280 if ( empty($link_notes) ) 331 281 $link_notes = ''; 332 $link_notes = apply_filters('pre_link_notes', $link_notes);333 334 if ( empty($link_description) )335 $link_description = '';336 $link_description = apply_filters('pre_link_description', $link_description);337 338 if ( empty($link_rss) )339 $link_rss = '';340 $link_rss = apply_filters('pre_link_rss', $link_rss);341 342 if ( empty($link_rel) )343 $link_rel = '';344 $link_rel = apply_filters('pre_link_rel', $link_rel);345 346 // Make sure we set a valid category347 if (0 == count($link_category) || !is_array($link_category)) {348 $link_category = array(get_option('default_link_category'));349 }350 282 351 283 if ( $update ) { 352 284 $wpdb->query("UPDATE $wpdb->links SET link_url='$link_url', 353 285 link_name='$link_name', link_image='$link_image', 354 link_target='$link_target', 286 link_target='$link_target', link_category='$link_category', 355 287 link_visible='$link_visible', link_description='$link_description', 356 288 link_rating='$link_rating', link_rel='$link_rel', … … 358 290 WHERE link_id='$link_id'"); 359 291 } else { 360 $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_image, link_target, link_ description, link_visible, link_owner, link_rating, link_rel, link_notes, link_rss) VALUES('$link_url','$link_name', '$link_image', '$link_target', '$link_description', '$link_visible', '$link_owner', '$link_rating', '$link_rel', '$link_notes', '$link_rss')");292 $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_image, link_target, link_category, link_description, link_visible, link_owner, link_rating, link_rel, link_notes, link_rss) VALUES('$link_url','$link_name', '$link_image', '$link_target', '$link_category', '$link_description', '$link_visible', '$link_owner', '$link_rating', '$link_rel', '$link_notes', '$link_rss')"); 361 293 $link_id = $wpdb->insert_id; 362 294 } 363 364 wp_set_link_cats($link_id, $link_category); 365 295 366 296 if ( $update ) 367 297 do_action('edit_link', $link_id); … … 376 306 377 307 $link_id = (int) $linkdata['link_id']; 378 308 379 309 $link = get_link($link_id, ARRAY_A); 380 310 381 311 // Escape data pulled from DB. 382 312 $link = add_magic_quotes($link); 383 384 // Passed link category list overwrites existing category list if not empty. 385 if ( isset($linkdata['link_category']) && is_array($linkdata['link_category']) 386 && 0 != count($linkdata['link_category']) ) 387 $link_cats = $linkdata['link_category']; 388 else 389 $link_cats = $link['link_category']; 390 313 391 314 // Merge old and new fields with new fields overwriting old ones. 392 315 $linkdata = array_merge($link, $linkdata); 393 $linkdata['link_category'] = $link_cats;394 316 395 317 return wp_insert_link($linkdata); … … 400 322 401 323 do_action('delete_link', $link_id); 402 403 $categories = wp_get_link_cats($link_id); 404 if( is_array( $categories ) ) { 405 foreach ( $categories as $category ) { 406 $wpdb->query("UPDATE $wpdb->categories SET link_count = link_count - 1 WHERE cat_ID = '$category'"); 407 wp_cache_delete($category, 'category'); 408 } 409 } 410 411 $wpdb->query("DELETE FROM $wpdb->link2cat WHERE link_id = '$link_id'"); 412 return $wpdb->query("DELETE FROM $wpdb->links WHERE link_id = '$link_id'"); 413 } 414 415 function wp_get_link_cats($link_ID = 0) { 416 global $wpdb; 417 418 $sql = "SELECT category_id 419 FROM $wpdb->link2cat 420 WHERE link_id = $link_ID 421 ORDER BY category_id"; 422 423 $result = $wpdb->get_col($sql); 424 425 if ( !$result ) 426 $result = array(); 427 428 return array_unique($result); 429 } 430 431 function wp_set_link_cats($link_ID = 0, $link_categories = array()) { 432 global $wpdb; 433 // If $link_categories isn't already an array, make it one: 434 if (!is_array($link_categories) || 0 == count($link_categories)) 435 $link_categories = array(get_option('default_link_category')); 436 437 $link_categories = array_unique($link_categories); 438 439 // First the old categories 440 $old_categories = $wpdb->get_col(" 441 SELECT category_id 442 FROM $wpdb->link2cat 443 WHERE link_id = $link_ID"); 444 445 if (!$old_categories) { 446 $old_categories = array(); 447 } else { 448 $old_categories = array_unique($old_categories); 449 } 450 451 // Delete any? 452 $delete_cats = array_diff($old_categories,$link_categories); 453 454 if ($delete_cats) { 455 foreach ($delete_cats as $del) { 456 $wpdb->query(" 457 DELETE FROM $wpdb->link2cat 458 WHERE category_id = $del 459 AND link_id = $link_ID 460 "); 461 } 462 } 463 464 // Add any? 465 $add_cats = array_diff($link_categories, $old_categories); 466 467 if ($add_cats) { 468 foreach ($add_cats as $new_cat) { 469 $wpdb->query(" 470 INSERT INTO $wpdb->link2cat (link_id, category_id) 471 VALUES ($link_ID, $new_cat)"); 472 } 473 } 474 475 // Update category counts. 476 $all_affected_cats = array_unique(array_merge($link_categories, $old_categories)); 477 foreach ( $all_affected_cats as $cat_id ) { 478 $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->link2cat, $wpdb->links WHERE $wpdb->links.link_id = $wpdb->link2cat.link_id AND category_id = '$cat_id'"); 479 $wpdb->query("UPDATE $wpdb->categories SET link_count = '$count' WHERE cat_ID = '$cat_id'"); 480 wp_cache_delete($cat_id, 'category'); 481 } 482 } // wp_set_link_cats() 324 return $wpdb->query("DELETE FROM $wpdb->links WHERE link_id = '$link_id'"); 325 } 483 326 484 327 function post_exists($title, $content = '', $post_date = '') {
Note: See TracChangeset
for help on using the changeset viewer.