diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index 64c9b06bd..a124d084a 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -52,6 +52,36 @@ case 'delete-cat' : die('1'); else die('0'); break; +case 'delete-link-cat' : + check_ajax_referer( "delete-link-category_$id" ); + if ( !current_user_can( 'manage_categories' ) ) + die('-1'); + + $cat_name = get_term_field('name', $id, 'link_category'); + + // Don't delete the default cats. + if ( $id == get_option('default_link_category') ) { + $x = new WP_AJAX_Response( array( + 'what' => 'link-cat', + 'id' => $id, + 'data' => new WP_Error( 'default-link-cat', sprintf(__("Can’t delete the %s category: this is the default one"), $cat_name) ) + ) ); + $x->send(); + } + + $r = wp_delete_term($id, 'link_category'); + if ( !$r ) + die('0'); + if ( is_wp_error($r) ) { + $x = new WP_AJAX_Response( array( + 'what' => 'link-cat', + 'id' => $id, + 'data' => $r + ) ); + $x->send(); + } + die('1'); + break; case 'delete-link' : check_ajax_referer( "delete-bookmark_$id" ); if ( !current_user_can( 'manage_links' ) ) @@ -181,6 +211,32 @@ case 'add-cat' : // From Manage->Categories ) ); $x->send(); break; +case 'add-link-cat' : // From Blogroll -> Categories + check_ajax_referer( 'add-link-category' ); + if ( !current_user_can( 'manage_categories' ) ) + die('-1'); + + $r = wp_insert_term($_POST['name'], 'link_category', $_POST ); + if ( is_wp_error( $r ) ) { + $x = new WP_AJAX_Response( array( + 'what' => 'link-cat', + 'id' => $r + ) ); + $x->send(); + } + + extract($r, EXTR_SKIP); + + if ( !$link_cat = link_cat_row( $term_id ) ) + die('0'); + + $x = new WP_Ajax_Response( array( + 'what' => 'link-cat', + 'id' => $term_id, + 'data' => $link_cat + ) ); + $x->send(); + break; case 'add-comment' : check_ajax_referer( $action ); if ( !current_user_can( 'edit_post', $id ) ) diff --git a/wp-admin/edit-link-categories.php b/wp-admin/edit-link-categories.php index 3e05f5a88..a036fa6aa 100644 --- a/wp-admin/edit-link-categories.php +++ b/wp-admin/edit-link-categories.php @@ -4,7 +4,7 @@ require_once('admin.php'); $title = __('Categories'); $parent_file = 'link-manager.php'; -//wp_enqueue_script( 'admin-categories' ); TODO: Fix AJAX +wp_enqueue_script( 'admin-categories' ); require_once ('admin-header.php'); $messages[1] = __('Category added.'); @@ -13,35 +13,8 @@ $messages[3] = __('Category updated.'); $messages[4] = __('Category not added.'); $messages[5] = __('Category not updated.'); -function link_cat_row($category) { - global $class; +if (isset($_GET['message'])) : ?> - if ( current_user_can( 'manage_categories' ) ) { - $edit = "".__( 'Edit' ).""; - $default_cat_id = (int) get_option( 'default_link_category' ); - - if ( $category->term_id != $default_cat_id ) - $edit .= "term_id ) . "' onclick=\"return deleteSomething( 'cat', $category->term_id, '" . js_escape(sprintf( __("You are about to delete the category '%s'.\nAll links that were only assigned to this category will be assigned to the '%s' category.\n'OK' to delete, 'Cancel' to stop." ), $category->name, get_term_field( 'name', $default_cat_id, 'link_category' ))) . "' );\" class='delete'>".__( 'Delete' ).""; - else - $edit .= "".__( "Default" ); - } else { - $edit = ''; - } - - $class = ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || " class='alternate'" == $class ) ? '' : " class='alternate'"; - - $category->count = number_format_i18n( $category->count ); - $count = ( $category->count > 0 ) ? "$category->count" : $category->count; - return " - $category->term_id - " . ( $name_override ? $name_override : $pad . ' ' . $category->name ) . " - $category->description - $count - $edit\n\t\n"; -} -?> - -

@@ -61,7 +34,7 @@ function link_cat_row($category) { - + '; + $form = '
'; $action = 'addcat'; $nonce_action = 'add-link-category'; do_action('add_link_category_form_pre', $category); diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index bb2c6446e..23eff600c 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -34,6 +34,8 @@ function cat_rows( $parent = 0, $level = 0, $categories = 0 ) { function _cat_row( $category, $level, $name_override = false ) { global $class; + $category = get_category( $category ); + $pad = str_repeat( '— ', $level ); if ( current_user_can( 'manage_categories' ) ) { $edit = "".__( 'Edit' ).""; @@ -47,7 +49,7 @@ function _cat_row( $category, $level, $name_override = false ) { } else $edit = ''; - $class = ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || " class='alternate'" == $class ) ? '' : " class='alternate'"; + $class = " class='alternate'" == $class ? '' : " class='alternate'"; $category->count = number_format_i18n( $category->count ); $posts_count = ( $category->count > 0 ) ? "$category->count" : $category->count; @@ -61,6 +63,41 @@ function _cat_row( $category, $level, $name_override = false ) { return apply_filters('cat_row', $output); } +function link_cat_row( $category ) { + global $class; + + if ( !$category = get_term( $category, 'link_category' ) ) + return false; + if ( is_wp_error( $category ) ) + return $category; + + if ( current_user_can( 'manage_categories' ) ) { + $edit = "".__( 'Edit' ).""; + $default_cat_id = (int) get_option( 'default_link_category' ); + + $delete_url = wp_nonce_url( "link-category.php?action=delete&cat_ID=$category->term_id", "delete-link-category_$category->term_id" ); + if ( $category->term_id != $default_cat_id ) + $edit .= "" . __( 'Delete' ) . ""; + else + $edit .= "" . __( "Default" ); + } else { + $edit = ''; + } + + $class = " class='alternate'" == $class ? '' : " class='alternate'"; + + $category->count = number_format_i18n( $category->count ); + $count = ( $category->count > 0 ) ? "$category->count" : $category->count; + $output = " + $category->term_id + " . ( $name_override ? $name_override : $pad . ' ' . $category->name ) . " + $category->description + $count + $edit\n\t\n"; + + return apply_filters( 'link_cat_row', $output ); +} + function checked( $checked, $current) { if ( $checked == $current) echo ' checked="checked"'; diff --git a/wp-admin/js/categories.js b/wp-admin/js/categories.js index 23a67c53d..a32733802 100644 --- a/wp-admin/js/categories.js +++ b/wp-admin/js/categories.js @@ -1,5 +1,7 @@ jQuery(function($) { - var options = document.forms['addcat'].category_parent.options; + var options = false + if ( document.forms['addcat'].category_parent ) + options = document.forms['addcat'].category_parent.options; var addAfter = function( r, settings ) { var name = $("" + $('name', r).text() + "").html(); @@ -14,5 +16,8 @@ jQuery(function($) { options[o] = null; } - var a = $('#the-list').wpList( { addAfter: addAfter, delAfter: delAfter } ); + if ( options ) + $('#the-list').wpList( { addAfter: addAfter, delAfter: delAfter } ); + else + $('#the-list').wpList(); }); diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 2e1365ceb..c93e60703 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -115,7 +115,7 @@ class WP_Scripts { 'add' => attribute_escape(__('Add')), 'how' => __('Separate multiple categories with commas.') ) ); - $this->add( 'admin-categories', '/wp-admin/js/categories.js', array('wp-lists'), '20070823' ); + $this->add( 'admin-categories', '/wp-admin/js/categories.js', array('wp-lists'), '20071031' ); $this->add( 'admin-custom-fields', '/wp-admin/js/custom-fields.js', array('wp-lists'), '20070823' ); $this->add( 'admin-comments', '/wp-admin/js/edit-comments.js', array('wp-lists'), '20070822' ); $this->add( 'admin-posts', '/wp-admin/js/edit-posts.js', array('wp-lists'), '20071023' ); diff --git a/wp-settings.php b/wp-settings.php index 4d54777da..e4c3a1f21 100644 --- a/wp-settings.php +++ b/wp-settings.php @@ -118,34 +118,14 @@ if ( !defined('PLUGINDIR') ) require (ABSPATH . WPINC . '/compat.php'); require (ABSPATH . WPINC . '/functions.php'); +require (ABSPATH . WPINC . '/classes.php'); require_wp_db(); -// $table_prefix is deprecated as of 2.1 -$wpdb->prefix = $table_prefix; +$prefix = $wpdb->set_prefix($table_prefix); -if ( preg_match('|[^a-z0-9_]|i', $wpdb->prefix) && !file_exists(ABSPATH . 'wp-content/db.php') ) +if ( is_wp_error($prefix) ) wp_die("ERROR: $table_prefix in wp-config.php can only contain numbers, letters, and underscores."); -// Table names -$wpdb->posts = $wpdb->prefix . 'posts'; -$wpdb->users = $wpdb->prefix . 'users'; -$wpdb->categories = $wpdb->prefix . 'categories'; -$wpdb->post2cat = $wpdb->prefix . 'post2cat'; -$wpdb->comments = $wpdb->prefix . 'comments'; -$wpdb->link2cat = $wpdb->prefix . 'link2cat'; -$wpdb->links = $wpdb->prefix . 'links'; -$wpdb->options = $wpdb->prefix . 'options'; -$wpdb->postmeta = $wpdb->prefix . 'postmeta'; -$wpdb->usermeta = $wpdb->prefix . 'usermeta'; -$wpdb->terms = $wpdb->prefix . 'terms'; -$wpdb->term_taxonomy = $wpdb->prefix . 'term_taxonomy'; -$wpdb->term_relationships = $wpdb->prefix . 'term_relationships'; - -if ( defined('CUSTOM_USER_TABLE') ) - $wpdb->users = CUSTOM_USER_TABLE; -if ( defined('CUSTOM_USER_META_TABLE') ) - $wpdb->usermeta = CUSTOM_USER_META_TABLE; - if ( file_exists(ABSPATH . 'wp-content/object-cache.php') ) require_once (ABSPATH . 'wp-content/object-cache.php'); else @@ -153,7 +133,6 @@ else wp_cache_init(); -require (ABSPATH . WPINC . '/classes.php'); require (ABSPATH . WPINC . '/plugin.php'); require (ABSPATH . WPINC . '/default-filters.php'); include_once(ABSPATH . WPINC . '/streams.php');