Separate AJAX cat adder into post and link flavors. see #4189
git-svn-id: http://svn.automattic.com/wordpress/trunk@5637 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
9828d17066
commit
4214428322
|
@ -125,6 +125,28 @@ case 'add-category' : // On the Fly
|
||||||
}
|
}
|
||||||
$x->send();
|
$x->send();
|
||||||
break;
|
break;
|
||||||
|
case 'add-link-category' : // On the Fly
|
||||||
|
if ( !current_user_can( 'manage_categories' ) )
|
||||||
|
die('-1');
|
||||||
|
$names = explode(',', $_POST['newcat']);
|
||||||
|
$x = new WP_Ajax_Response();
|
||||||
|
foreach ( $names as $cat_name ) {
|
||||||
|
$cat_name = trim($cat_name);
|
||||||
|
if ( !$slug = sanitize_title($cat_name) )
|
||||||
|
die('0');
|
||||||
|
if ( !$cat_id = category_exists( $cat_name ) ) {
|
||||||
|
$cat_id = wp_insert_term( $cat_name, 'link_category' );
|
||||||
|
$cat_id = $cat_id['term_id'];
|
||||||
|
}
|
||||||
|
$cat_name = wp_specialchars(stripslashes($cat_name));
|
||||||
|
$x->add( array(
|
||||||
|
'what' => 'link-category',
|
||||||
|
'id' => $cat_id,
|
||||||
|
'data' => "<li id='link-category-$cat_id'><label for='in-link-category-$cat_id' class='selectit'><input value='$cat_id' type='checkbox' checked='checked' name='link_category[]' id='in-link-category-$cat_id'/> $cat_name</label></li>"
|
||||||
|
) );
|
||||||
|
}
|
||||||
|
$x->send();
|
||||||
|
break;
|
||||||
case 'add-cat' : // From Manage->Categories
|
case 'add-cat' : // From Manage->Categories
|
||||||
if ( !current_user_can( 'manage_categories' ) )
|
if ( !current_user_can( 'manage_categories' ) )
|
||||||
die('-1');
|
die('-1');
|
||||||
|
|
|
@ -43,7 +43,7 @@ function xfn_check($class, $value = '', $type = 'check') {
|
||||||
<h3 class="dbx-handle"><?php _e('Categories') ?></h3>
|
<h3 class="dbx-handle"><?php _e('Categories') ?></h3>
|
||||||
<div class="dbx-content">
|
<div class="dbx-content">
|
||||||
<p id="jaxcat"></p>
|
<p id="jaxcat"></p>
|
||||||
<ul id="categorychecklist"><?php dropdown_link_categories(get_option('default_link_category')); ?></ul>
|
<ul id="linkcategorychecklist"><?php dropdown_link_categories(get_option('default_link_category')); ?></ul>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@ function edit_link( $link_id = '' ) {
|
||||||
$_POST['link_name'] = wp_specialchars( $_POST['link_name'] );
|
$_POST['link_name'] = wp_specialchars( $_POST['link_name'] );
|
||||||
$_POST['link_image'] = wp_specialchars( $_POST['link_image'] );
|
$_POST['link_image'] = wp_specialchars( $_POST['link_image'] );
|
||||||
$_POST['link_rss'] = clean_url($_POST['link_rss']);
|
$_POST['link_rss'] = clean_url($_POST['link_rss']);
|
||||||
$_POST['link_category'] = $_POST['post_category'];
|
|
||||||
|
|
||||||
if ( !empty( $link_id ) ) {
|
if ( !empty( $link_id ) ) {
|
||||||
$_POST['link_id'] = $link_id;
|
$_POST['link_id'] = $link_id;
|
||||||
|
|
|
@ -5,7 +5,10 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
function category_exists($cat_name) {
|
function category_exists($cat_name) {
|
||||||
return is_term($cat_name, 'category');
|
$id = is_term($cat_name, 'category');
|
||||||
|
if ( is_array($id) )
|
||||||
|
$id = $id['term_id'];
|
||||||
|
return $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_category_to_edit( $id ) {
|
function get_category_to_edit( $id ) {
|
||||||
|
|
|
@ -157,7 +157,7 @@ function dropdown_link_categories( $default = 0 ) {
|
||||||
$cat_id = $category->term_id;
|
$cat_id = $category->term_id;
|
||||||
$name = wp_specialchars( apply_filters('the_category', $category->name));
|
$name = wp_specialchars( apply_filters('the_category', $category->name));
|
||||||
$checked = in_array( $cat_id, $checked_categories );
|
$checked = in_array( $cat_id, $checked_categories );
|
||||||
echo '<li id="category-', $cat_id, '"><label for="in-category-', $cat_id, '" class="selectit"><input value="', $cat_id, '" type="checkbox" name="post_category[]" id="in-category-', $cat_id, '"', ($checked ? ' checked="checked"' : "" ), '/> ', $name, "</label></li>";
|
echo '<li id="link-category-', $cat_id, '"><label for="in-link-category-', $cat_id, '" class="selectit"><input value="', $cat_id, '" type="checkbox" name="link_category[]" id="in-link-category-', $cat_id, '"', ($checked ? ' checked="checked"' : "" ), '/> ', $name, "</label></li>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
addLoadEvent(function(){linkcatList=new listMan('linkcategorychecklist');linkcatList.ajaxRespEl='jaxcat';linkcatList.topAdder=1;linkcatList.alt=0;linkcatList.showLink=0;});
|
||||||
|
addLoadEvent(newLinkCatAddIn);
|
||||||
|
function newLinkCatAddIn() {
|
||||||
|
var jaxcat = $('jaxcat');
|
||||||
|
if ( !jaxcat )
|
||||||
|
return false;
|
||||||
|
Element.update(jaxcat,'<span id="ajaxcat"><input type="text" name="newcat" id="newcat" size="16" autocomplete="off"/><input type="button" name="Button" id="catadd" value="' + linkcatL10n.add + '"/><input type="hidden"/><span id="howto">' + linkcatL10n.how + '</span></span>');
|
||||||
|
$('newcat').onkeypress = function(e) { return killSubmit("linkcatList.ajaxAdder('link-category','jaxcat');", e); };
|
||||||
|
$('catadd').onclick = function() { linkcatList.ajaxAdder('link-category', 'jaxcat'); };
|
||||||
|
}
|
|
@ -13,7 +13,7 @@ wp_reset_vars(array('action', 'cat_id', 'linkurl', 'name', 'image',
|
||||||
|
|
||||||
wp_enqueue_script( array('xfn', 'dbx-admin-key?pagenow=link.php') );
|
wp_enqueue_script( array('xfn', 'dbx-admin-key?pagenow=link.php') );
|
||||||
if ( current_user_can( 'manage_categories' ) )
|
if ( current_user_can( 'manage_categories' ) )
|
||||||
wp_enqueue_script( 'ajaxcat' );
|
wp_enqueue_script( 'ajaxlinkcat' );
|
||||||
require('admin-header.php');
|
require('admin-header.php');
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,7 @@ switch ($action) {
|
||||||
case 'edit' :
|
case 'edit' :
|
||||||
wp_enqueue_script( array('xfn', 'dbx-admin-key?pagenow=link.php') );
|
wp_enqueue_script( array('xfn', 'dbx-admin-key?pagenow=link.php') );
|
||||||
if ( current_user_can( 'manage_categories' ) )
|
if ( current_user_can( 'manage_categories' ) )
|
||||||
wp_enqueue_script( 'ajaxcat' );
|
wp_enqueue_script( 'ajaxlinkcat' );
|
||||||
$parent_file = 'link-manager.php';
|
$parent_file = 'link-manager.php';
|
||||||
$submenu_file = 'link-manager.php';
|
$submenu_file = 'link-manager.php';
|
||||||
$title = __('Edit Link');
|
$title = __('Edit Link');
|
||||||
|
|
|
@ -109,6 +109,11 @@ class WP_Scripts {
|
||||||
'add' => attribute_escape(__('Add')),
|
'add' => attribute_escape(__('Add')),
|
||||||
'how' => __('Separate multiple categories with commas.')
|
'how' => __('Separate multiple categories with commas.')
|
||||||
) );
|
) );
|
||||||
|
$this->add( 'ajaxlinkcat', '/wp-admin/js/link-cat.js', array('listman'), '200700601' );
|
||||||
|
$this->localize( 'ajaxlinkcat', 'linkcatL10n', array(
|
||||||
|
'add' => attribute_escape(__('Add')),
|
||||||
|
'how' => __('Separate multiple categories with commas.')
|
||||||
|
) );
|
||||||
$this->add( 'admin-categories', '/wp-admin/js/categories.js', array('listman'), '3684' );
|
$this->add( 'admin-categories', '/wp-admin/js/categories.js', array('listman'), '3684' );
|
||||||
$this->add( 'admin-custom-fields', '/wp-admin/js/custom-fields.js', array('listman'), '3733' );
|
$this->add( 'admin-custom-fields', '/wp-admin/js/custom-fields.js', array('listman'), '3733' );
|
||||||
$this->add( 'admin-comments', '/wp-admin/js/edit-comments.js', array('listman'), '20070327' );
|
$this->add( 'admin-comments', '/wp-admin/js/edit-comments.js', array('listman'), '20070327' );
|
||||||
|
|
Loading…
Reference in New Issue