First cut of link category management. Rough and ugly.
git-svn-id: http://svn.automattic.com/wordpress/trunk@5654 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
1390f9deee
commit
539b2e48f0
|
@ -134,7 +134,7 @@ case 'add-link-category' : // On the Fly
|
|||
$cat_name = trim($cat_name);
|
||||
if ( !$slug = sanitize_title($cat_name) )
|
||||
die('0');
|
||||
if ( !$cat_id = category_exists( $cat_name ) ) {
|
||||
if ( !$cat_id = is_term( $cat_name, 'link_category' ) ) {
|
||||
$cat_id = wp_insert_term( $cat_name, 'link_category' );
|
||||
$cat_id = $cat_id['term_id'];
|
||||
}
|
||||
|
|
|
@ -36,9 +36,6 @@ case 'delete':
|
|||
if ( $cat_ID == get_option('default_category') )
|
||||
wp_die(sprintf(__("Can’t delete the <strong>%s</strong> category: this is the default one"), $cat_name));
|
||||
|
||||
if ( $cat_ID == get_option('default_link_category') )
|
||||
wp_die(sprintf(__("Can’t delete the <strong>%s</strong> category: this is the default one for links"), $cat_name));
|
||||
|
||||
wp_delete_category($cat_ID);
|
||||
|
||||
wp_redirect('categories.php?message=2');
|
||||
|
@ -113,7 +110,7 @@ cat_rows();
|
|||
|
||||
<?php if ( current_user_can('manage_categories') ) : ?>
|
||||
<div class="wrap">
|
||||
<p><?php printf(__('<strong>Note:</strong><br />Deleting a category does not delete the posts and links in that category. Instead, posts that were only assigned to the deleted category are set to the category <strong>%s</strong> and links that were only assigned to the deleted category are set to <strong>%s</strong>.'), apply_filters('the_category', get_catname(get_option('default_category'))), apply_filters('the_category', get_catname(get_option('default_link_category')))) ?></p>
|
||||
<p><?php printf(__('<strong>Note:</strong><br />Deleting a category does not delete the posts in that category. Instead, posts that were only assigned to the deleted category are set to the category <strong>%s</strong>.'), apply_filters('the_category', get_catname(get_option('default_category')))) ?></p>
|
||||
</div>
|
||||
|
||||
<?php include('edit-category-form.php'); ?>
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
require_once('admin.php');
|
||||
|
||||
$title = __('Categories');
|
||||
$parent_file = 'link-manager.php';
|
||||
|
||||
//wp_enqueue_script( 'admin-categories' ); TODO: Fix AJAX
|
||||
require_once ('admin-header.php');
|
||||
|
||||
$messages[1] = __('Category added.');
|
||||
$messages[2] = __('Category deleted.');
|
||||
$messages[3] = __('Category updated.');
|
||||
$messages[4] = __('Category not added.');
|
||||
$messages[5] = __('Category not updated.');
|
||||
|
||||
function link_cat_row($category) {
|
||||
global $class;
|
||||
|
||||
if ( current_user_can( 'manage_categories' ) ) {
|
||||
$edit = "<a href='link-category.php?action=edit&cat_ID=$category->term_id' class='edit'>".__( 'Edit' )."</a></td>";
|
||||
$default_cat_id = (int) get_option( 'default_link_category' );
|
||||
|
||||
if ( $category->term_id != $default_cat_id )
|
||||
$edit .= "<td><a href='" . wp_nonce_url( "link-category.php?action=delete&cat_ID=$category->term_id", 'delete-link-category_' . $category->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' )."</a>";
|
||||
else
|
||||
$edit .= "<td style='text-align:center'>".__( "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 ) ? "<a href='link-manager.php?cat_id=$category->term_id'>$category->count</a>" : $category->count;
|
||||
return "<tr id='cat-$category->term_id'$class>
|
||||
<th scope='row' style='text-align: center'>$category->term_id</th>
|
||||
<td>" . ( $name_override ? $name_override : $pad . ' ' . $category->name ) . "</td>
|
||||
<td>$category->description</td>
|
||||
<td align='center'>$count</td>
|
||||
<td>$edit</td>\n\t</tr>\n";
|
||||
}
|
||||
?>
|
||||
|
||||
<?php if (isset($_GET['message'])) : ?>
|
||||
<div id="message" class="updated fade"><p><?php echo $messages[$_GET['message']]; ?></p></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="wrap">
|
||||
<?php if ( current_user_can('manage_categories') ) : ?>
|
||||
<h2><?php printf(__('Categories (<a href="%s">add new</a>)'), '#addcat') ?> </h2>
|
||||
<?php else : ?>
|
||||
<h2><?php _e('Categories') ?> </h2>
|
||||
<?php endif; ?>
|
||||
<table class="widefat">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col" style="text-align: center"><?php _e('ID') ?></th>
|
||||
<th scope="col"><?php _e('Name') ?></th>
|
||||
<th scope="col"><?php _e('Description') ?></th>
|
||||
<th scope="col" width="90" style="text-align: center"><?php _e('Links') ?></th>
|
||||
<th colspan="2" style="text-align: center"><?php _e('Action') ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="the-list">
|
||||
<?php
|
||||
$categories = get_terms( 'link_category', 'hide_empty=0' );
|
||||
if ( $categories ) {
|
||||
$output = '';
|
||||
foreach ( $categories as $category ) {
|
||||
$category = sanitize_term($category, 'link_category', 'display');
|
||||
$output .= link_cat_row($category);
|
||||
}
|
||||
$output = apply_filters('cat_rows', $output);
|
||||
echo $output;
|
||||
unset($category);
|
||||
}
|
||||
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
|
||||
<?php if ( current_user_can('manage_categories') ) : ?>
|
||||
<div class="wrap">
|
||||
<p><?php printf(__('<strong>Note:</strong><br />Deleting a category does not delete the links in that category. Instead, links that were only assigned to the deleted category are set to the category <strong>%s</strong>.'), get_term_field('name', get_option('default_link_category'), 'link_category')) ?></p>
|
||||
</div>
|
||||
|
||||
<?php include('edit-link-category-form.php'); ?>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<?php include('admin-footer.php'); ?>
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
if ( ! empty($cat_ID) ) {
|
||||
$heading = __('Edit Category');
|
||||
$submit_text = __('Edit Category »');
|
||||
$form = '<form name="editcat" id="editcat" method="post" action="link-category.php">';
|
||||
$action = 'editedcat';
|
||||
$nonce_action = 'update-link-category_' . $cat_ID;
|
||||
do_action('edit_link_category_form_pre', $category);
|
||||
} else {
|
||||
$heading = __('Add Category');
|
||||
$submit_text = __('Add Category »');
|
||||
$form = '<form name="addcat" id="addcat" method="post" action="link-category.php">';
|
||||
$action = 'addcat';
|
||||
$nonce_action = 'add-link-category';
|
||||
do_action('add_link_category_form_pre', $category);
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="wrap">
|
||||
<h2><?php echo $heading ?></h2>
|
||||
<div id="ajax-response"></div>
|
||||
<?php echo $form ?>
|
||||
<input type="hidden" name="action" value="<?php echo $action ?>" />
|
||||
<input type="hidden" name="cat_ID" value="<?php echo $category->term_id ?>" />
|
||||
<?php wp_nonce_field($nonce_action); ?>
|
||||
<table class="editform" width="100%" cellspacing="2" cellpadding="5">
|
||||
<tr>
|
||||
<th width="33%" scope="row" valign="top"><label for="name"><?php _e('Category name:') ?></label></th>
|
||||
<td width="67%"><input name="name" id="name" type="text" value="<?php echo $category->name; ?>" size="40" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row" valign="top"><label for="slug"><?php _e('Category slug:') ?></label></th>
|
||||
<td><input name="slug" id="slug" type="text" value="<?php echo $category->slug; ?>" size="40" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row" valign="top"><label for="parent"><?php _e('Category parent:') ?></label></th>
|
||||
<td>
|
||||
<?php wp_dropdown_categories('hide_empty=0&name=parent&orderby=name&selected=' . $category->parent . '&hierarchical=1&show_option_none=' . __('None')); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row" valign="top"><label for="description"><?php _e('Description: (optional)') ?></label></th>
|
||||
<td><textarea name="description" id="description" rows="5" cols="50" style="width: 97%;"><?php echo $category->description; ?></textarea></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p class="submit"><input type="submit" name="submit" value="<?php echo $submit_text ?>" /></p>
|
||||
<?php do_action('edit_link_category_form', $category); ?>
|
||||
</form>
|
||||
</div>
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
require_once('admin.php');
|
||||
|
||||
wp_reset_vars(array('action', 'cat'));
|
||||
|
||||
switch($action) {
|
||||
|
||||
case 'addcat':
|
||||
|
||||
check_admin_referer('add-link-category');
|
||||
|
||||
if ( !current_user_can('manage_categories') )
|
||||
wp_die(__('Cheatin’ uh?'));
|
||||
|
||||
if ( wp_insert_term($_POST['name'], 'link_category', $_POST ) ) {
|
||||
wp_redirect('edit-link-categories.php?message=1#addcat');
|
||||
} else {
|
||||
wp_redirect('edit-link-categories.php?message=4#addcat');
|
||||
}
|
||||
exit;
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
$cat_ID = (int) $_GET['cat_ID'];
|
||||
check_admin_referer('delete-link-category_' . $cat_ID);
|
||||
|
||||
if ( !current_user_can('manage_categories') )
|
||||
wp_die(__('Cheatin’ uh?'));
|
||||
|
||||
$cat_name = get_term_field('name', $cat_ID, 'link_category');
|
||||
|
||||
// Don't delete the default cats.
|
||||
if ( $cat_ID == get_option('default_link_category') )
|
||||
wp_die(sprintf(__("Can’t delete the <strong>%s</strong> category: this is the default one"), $cat_name));
|
||||
|
||||
wp_delete_term($cat_ID, 'link_category');
|
||||
|
||||
wp_redirect('edit-link-categories.php?message=2');
|
||||
exit;
|
||||
|
||||
break;
|
||||
|
||||
case 'edit':
|
||||
$title = __('Categories');
|
||||
$parent_file = 'link-manager.php';
|
||||
$submenu_file = 'edit-link-categories.php';
|
||||
require_once ('admin-header.php');
|
||||
$cat_ID = (int) $_GET['cat_ID'];
|
||||
$category = get_term_to_edit($cat_ID, 'link_category');
|
||||
include('edit-link-category-form.php');
|
||||
include('admin-footer.php');
|
||||
exit;
|
||||
break;
|
||||
|
||||
case 'editedcat':
|
||||
$cat_ID = (int) $_POST['cat_ID'];
|
||||
check_admin_referer('update-link-category_' . $cat_ID);
|
||||
|
||||
if ( !current_user_can('manage_categories') )
|
||||
wp_die(__('Cheatin’ uh?'));
|
||||
|
||||
if ( wp_update_term($cat_ID, 'link_category', $_POST) )
|
||||
wp_redirect('edit-link-categories.php?message=3');
|
||||
else
|
||||
wp_redirect('edit-link-categories.php?message=5');
|
||||
|
||||
exit;
|
||||
break;
|
||||
}
|
||||
|
||||
?>
|
|
@ -46,6 +46,7 @@ $submenu['edit.php'][40] = array(__('Export'), 'import', 'export.php');
|
|||
$submenu['link-manager.php'][5] = array(__('Manage Blogroll'), 'manage_links', 'link-manager.php');
|
||||
$submenu['link-manager.php'][10] = array(__('Add Link'), 'manage_links', 'link-add.php');
|
||||
$submenu['link-manager.php'][20] = array(__('Import Links'), 'manage_links', 'link-import.php');
|
||||
$submenu['link-manager.php'][30] = array(__('Categories'), 'manage_links', 'edit-link-categories.php');
|
||||
|
||||
if ( current_user_can('edit_users') ) {
|
||||
$_wp_real_parent_file['profile.php'] = 'users.php'; // Back-compat for plugins adding submenus to profile.php.
|
||||
|
|
Loading…
Reference in New Issue