Dear Mohit, I hope I can help.
First, you must not touch the "check permissions" part of the function; the code checks if the user has permissions to edit either post or page. Note that the custom posts you refer to are checking permissions for 'edit_page' which is incorrect since they are posts.
This could be also a nonce problem, since you didn't change 'taxonomy_noncename' by another noncename of your own.
Also, I didn't tried the function if you include several custom posts in it. I suppose that you tested it before with one custom post only?
In order to avoid misunderstandings, here is the sequence of functions I used for a custom post named 'anecdote' with a custom taxonomy named 'anecdote-media':
/////////////// MEDIA CUSTOM TAXONOMY /////////////////////
/**
* First, create a form section for WP User Frontend
* with the fields relative to the custom taxonomy
* in a function 'wpufe_anecdote_media'
*/
/**
* Add media dropdown to the add anecdote area
*
* @uses wpuf_add_post_form_description action hook
*
* @param string $post_type the post type of the post add screen
* @param object|null $post the post object
*/
function wpufe_anecdote_media( $post_type, $post = null) {
?>
<label for="anecdote-media">
Media <span class="required">*</span>
</label>
<?php
// Add security nonce check
wp_nonce_field( __FILE__, 'nonce-anecdote-media' );
// Get all media taxonomy terms
$medias = get_terms('anecdote-media', 'hide_empty=0'); //$medias = wp_get_object_terms( $post->ID, 'anecdote-media', array('fields' => 'ids') );
?>
<li>
<?php
// You can also use the included dropdown generator function of wordpress, but I'd prefer to code the select myself in order to avoid possible problems
//wp_dropdown_categories('taxonomy=anecdote-media&hide_empty=0&orderby=name&name=post_media&show_option_none=Select media&selected='.$medias[0]);
?>
<select name='post_media' id='post_media' class="requiredField">
<option value='' <?php if (!count($medias)) echo "selected='selected'";?>>Select a media</option>
<?php
foreach ($medias as $media) {
$selected = (has_term($media->slug, 'anecdote-media', $post->ID)) ? ' selected="selected" ' : '';
echo "<option value='" . $media->name . "' " . $selected . ">" . $media->name . "</option>\n";
}
?>
</select>
</li>
<?php
}
/**
* The following action adds a form section
* below the description field of WP User Frontend
*/
add_action( 'wpuf_add_post_form_after_description', 'wpufe_anecdote_media', 10, 2 );
/**
* Validate existence of the media after anecdote creation/edit
* If the select is empty, it returns an error message
*
* @uses 'wpuf_add_post_validation' filter
*
* @param array $errors errors array
* @return array errors array
*/
function wpufe_media_validation( $errors ) {
if( $_POST['post_media'] == '' ) {
$errors[] = 'Please select a media for your anecdote';
}
return $errors;
}
add_filter( 'wpuf_add_post_validation', 'wpufe_media_validation' );
add_filter( 'wpuf_edit_post_validation', 'wpufe_media_validation' );
/**
* Input the media data after submitting
*/
if (function_exists('wpufe_anecdote_media')) {
add_action('save_post', 'save_media_data');
}
/**
* Save the media taxonomy data
*/
function save_media_data($post_id) {
// verify this came from our screen and with proper authorization.
if ( !wp_verify_nonce( $_POST['nonce-anecdote-media'], __FILE__ )) {
return $post_id;
}
// verify if this is an auto save routine. If it is our form has not been submitted, so we dont want to do anything
// maybe you'll find this unnecessary since there is no possible autosave in the frontend
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
return $post_id;
// Check permissions
if ( 'anecdote' == $_POST['post_type'] ) {
if ( !current_user_can( 'edit_page', $post_id ) )
return $post_id;
} else {
if ( !current_user_can( 'edit_post', $post_id ) )
return $post_id;
}
// OK, we're authenticated: we need to find and save the data
$post = get_post($post_id);
if ($post->post_type == 'anecdote') {
$media = $_POST['post_media'];
wp_set_object_terms( $post_id, $media, 'anecdote-media' );
}
}
I recommend also that you check your sequence of functions with the tutorial 'WordPress Custom Taxonomy Input Panels by ShibaShake' linked in an above post.
Finally, I encountered (as for others, as you probably noticed in the plugin forum) a permission issue depending on if you use WPUFE with a contributor/author/editor level or with an administrator level.