Support » Plugin: User Tags » Onclick tag set this tag as user preferences

  • Sorry, my last doubts. I want to do something similar to Most Popular tag list. Onclick the tag set this tag as user preference.


    (a) href=”#” onclick=SetAsUserPreferences”>Tag 1 (/a)
    (a) href=”#” onclick=SetAsUserPreferences”>Tag 2 (/a)

    What can I do?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Umesh Kumar


    @diegooli, you can look at the code in here:

    This might help you, unless I didn’t got it right what you are asking.

    instead of Most Popular tag list, I want to display all wordpress tags, and when the user click in one, the tag goes to preferences, and so the user can save it.

    Sorry my english.

    Plugin Author Umesh Kumar



    To display a list of tags

    //Get all the taxonomies
    $user_taxonomies = get_object_taxonomies( 'user', 'object' );
    //Get user Id
    $user_id = get_current_user_id();
    if(!empty( $user_taxonomies) {?>
    <form name="user-tags" action="" method="post">
    	<ul class="form-table user-profile-taxonomy user-taxonomy-wrapper"><?php
    		foreach ( $user_taxonomies as $key => $taxonomy ) {
    			// Check the current user can assign terms for this taxonomy
    			if ( ! current_user_can( $taxonomy->cap->assign_terms ) ) {
    			$choose_from_text = apply_filters( 'ut_tag_cloud_heading', $taxonomy->labels->choose_from_most_used, $taxonomy );
    			// Get all the terms in this taxonomy
    			$terms     = wp_get_object_terms( $user_id, $taxonomy->name );
    			$num       = 0;
    			$html      = '';
    			$user_tags = '';
    			if ( ! empty( $terms ) ) {
    				foreach ( $terms as $term ) {
    					$user_tags[] = $term->name;
    					$term_url    = site_url() . '/' . $taxonomy->rewrite['slug'] . '/' . $term->slug;
    					$html .= "<div class='tag-hldr'>";
    					$html .= '<span><a id="user_tag-' . $taxonomy->name . '-' . $num . '" class="ntdelbutton">x</a></span> <a href="' . $term_url . '" class="term-link">' . $term->name . '</a>';
    					$html .= "</div>";
    					$num ++;
    				$user_tags = implode( ',', $user_tags );
    			} ?>
    			<label for="new-tag-user_tag_<?php echo $taxonomy->name; ?>"><?php _e( "{$taxonomy->labels->singular_name}" ) ?></label>
    			<div class="taxonomy-wrapper">
    				<input type="text" id="new-tag-user_tag_<?php echo $taxonomy->name; ?>" name="newtag[user_tag]" class="newtag form-input-tip float-left hide-on-blur" size="16" autocomplete="off" value="">
    				<input type="button" class="button tagadd float-left" value="Add">
    				<p class="howto"><?php _e( 'Separate tags with commas', WP_UT_TRANSLATION_DOMAIN ); ?></p>
    				<div class="tagchecklist"><?php echo $html; ?></div>
    				<input type="hidden" name="user-tags[<?php echo $taxonomy->name; ?>]" id="user-tags-<?php echo $taxonomy->name; ?>" value="<?php echo $user_tags; ?>"/>
    			<!--Display Tag cloud for most used terms-->
    			<p class="hide-if-no-js tagcloud-container">
    				<a href="#titlediv" class="tagcloud-link user-taxonomy" id="link-<?php echo $taxonomy->name; ?>"><?php echo $choose_from_text; ?></a>
    		} ?>
    	<?php wp_nonce_field( 'save-user-tags', 'user-tags-nonce' ); ?>
    	<input type="submit" name="update-user-tags" class="button tagadd float-left" value="Update">

    Process the form
    //Should be automatically saved, as I hook on wp_loaded in plugin code

    I hope that works for you, or you can modify the above code to make it work using Ajax.


Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Onclick tag set this tag as user preferences’ is closed to new replies.