• Hey Spencer,

    Just finishing a first go at a plugin for your Quality Control theme that adds some user assignment capabilities – even shoots off an email when a new user is assigned.

    This theme is pretty much blowing me away right now. Great work!

    There are two settings in the plugin to play with – one that allows you to pick a user level for who can be assigned a ticket. You can also choose a user level for access to the site. Anyone below that level will simply get the login screen. I know I wanted this so I could make it a private dev site.

    It would be nice to ad these as options in the back end. Maybe one day…

    I will try to add the code below here until I get it working a little better and can upload it to the repository, lets see if this works…

    [Large code excerpt removed by moderator. Per forum rules, please use the pastebin for all large code excerpts. It works better anyway.]

Viewing 15 replies - 1 through 15 (of 16 total)
  • Marty,

    Would your plugin allow you to make it so users could only view and respond to there own tickets? (While allowing the “admin” to view and respond to all tickets.)

    Also, Awesome theme Spencer!

    Thread Starter MartyThornley

    (@martythornley)

    No, interesting idea though.

    I have ended up making somewhat of a mess of it unfortunately. I had to hack the theme itself a little (sorry Spencer… really just for the sake of speed.)

    So I now have a combo of child theme + Plugin + a couple minor hacks to the original theme. Not the prettiest code around but I can assign users, choose a certain level of user that can be included as collaborators, and email any of them at any time as tickets are submitted. Also added a choice of priority – works similar to the states or status included in the theme, with colors and all. Also made it so the blog is totally private unless signed in as a user of the proper level. A couple people seemed to have problems with the way that worked but works for me.

    Happy to share for anyone interested. Email me and I’ll send you zip of the latest.

    I’m working on the following:

    Allowing tickets to be assigned to a single user (the owner) and then being able to manually add other people that are “assigned” the ticket. Then there will be an option where you can make it so only owners/people assigned and admins can view the ticket.

    Also, I’m tweaking the ticket form, so Marty some of your hacks might mess up. Not sure when it will be released.

    Thread Starter MartyThornley

    (@martythornley)

    Cool. No worries on that – I know I hacked a beta version ??

    I have a system working ok for now, but looking forward to see what you add to the next one.

    Nice. The other thing that would be nice if for non administrators to be able to see the my-profile menu to change passwords.

    Marty I’d like to check out what you did if you don’t mind sending it to me.

    I should be able to upload version 0.1.5 later tonight. Just working out some of the permission logic. It’s going to be kind of clunky the first release.

    You’ll be able to assign multiple users to a ticket, then select in the options how to “protect” those tickets. Tickets that are assigned to specific users can be inaccessible, read-only, or read/writable.

    Thread Starter MartyThornley

    (@martythornley)

    Ben, I’d be happy to. Just need an email addy…

    Hi Marty, may I please have a copy of the Zip file. My addy is [email protected]. Thanks in advance.

    Kyle, Version 0.1.5 now supports user assignment. Check it out. If it’s not up to your needs, have a look at Marty’s ??

    uturano

    (@uturano)

    Hi Everybody,

    some of you managed to solve the problem of e-mail notification when a new ticket is opened ? or when a ticket has been changed? How? Can we please let me know how is possible to do that?

    Thanks

    Spencer Finnell

    (@spencerfinnell)

    The next version will support both of those. Hopefully it will be released soon.

    uturano

    (@uturano)

    Hi,

    I apologize if I continue to bother you but there is a problem that only you can help me to solve it. I can not understand what are the variables on the page updates.php. I was able to notify via email when a ticket has been opened and the variables in this way …. but I take the file updates do not know how to take the variables and how they are called. I wish I could store in a variable of the comments made or update the ticket and send this email. How can I do this? Please help me to understand … THANK YOU

    THIS IS THE PAGE CODE ( updates.php):

    <?php
    if ( !function_exists( 'quality_comment' ) ) :
    /**
     * The comments, or "updates" for each ticket.
     *
     * @since Quality Control 0.1
     */
    function quality_comment( $comment, $args, $depth )
    {
    	$GLOBALS[ 'comment' ] = $comment;
    	$updates = get_comment_meta( get_comment_ID(), 'ticket_updates', true );
    	$i = 0;
    ?>
    	<li <?php comment_class( 'ticket' . ( $i % 2 ? '' : ' alt' ) ); ?> id="comment-<?php comment_ID(); ?>"> 
    
    		<div class="ticket-gravatar">
    			<a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>"><?php echo get_avatar( $comment, 29 ); ?></a>
    		</div> 
    
    		<div class="ticket-info"> 
    
    			<p class="ticket-author">
    				<strong><?php comment_author_link(); ?></strong><br />
    				<small><?php printf( __( 'about <em title="%s">%s</em> ago', 'quality' ), esc_attr( get_the_date() . __( ' at ', 'quality' ) . get_the_time() ), esc_attr( human_time_diff( get_comment_time( 'U' ), current_time( 'timestamp' ) ) ) ); ?></small>
    			</p>
    
    			<div class="reply">
    
    				<?php if( get_comment_text() != '&nbsp;' ) : comment_text(); endif; ?>
    
    				<?php if( $updates ) : ?>
    
    					<ol class="update-list<?php if( get_comment_text() == '&nbsp;' ) :?> single<?php endif; ?>">
    						<li><strong class="title"><?php _e( 'Updates Made:', 'quality' ); ?></strong>
    							<ul>
    								<?php foreach( $updates as $update ) : ?>
    									<li><?php echo $update; ?></li>
    								<?php endforeach; ?>
    							</ul>
    						</li>
    					</ol>
    
    				<?php endif; ?>
    
    			</div>
    
    		</div>
    <?php
    	$i++;
    }
    endif;
    
    /** Tell WordPress to run quality_save_comment() when the 'comment_post' hook is run. */
    add_action( 'comment_post', 'quality_save_comment', 1 );
    
    /**
     * Create the update history in the form of comment meta.
     *
     * How this works: This function compares the previous ticket
     * attributes, and see if the updates made via the comment form
     * are different. If they are, then it adds a bit of text as
     * comment meta. Tags and Categories are done directly in this function,
     * while status, milestones, and attachments are done through a hook, so they
     * can be removed.
     *
     * @since Quality Control 0.1
     * @uses wp_set_object_terms
     * @uses get_term
     * @uses get_the_category
     * @uses add_comment_meta
     */
    function quality_save_comment( $comment_id )
    {
    	global $post, $updates;
    
    	//$comment_meta = $_POST[ "quality_comment_meta" ];
    
    	$category = get_the_category( $post->ID );
    	$ticket_category = get_term( esc_attr( $_POST[ 'ticket_category' ] ), 'category' );
    	$tags = get_the_tags( $post->ID );
    
    	if( $tags )
    	{
    		$ticket_tags = "";
    
    		foreach( $tags as $tag )
    			$ticket_tags .= $tag->name . ', ';
    
    		$ticket_tags = substr( $ticket_tags, 0, -2 );
    	}
    
    	$updates = array();
    
    	do_action( 'quality_update_ticket_comment', $post, $_POST );
    
    	/** Has the category changed? */
    	if( $ticket_category->term_id != $category[0]->cat_ID )
    	{
    		$updates[] = apply_filters( 'quality_comment_category_updated', sprintf( __( '<strong>category</strong> changed from <em>%s</em> to <em>%s</em>', 'quality' ), $category[0]->cat_name, $ticket_category->name ) );
    
    		$status = wp_set_object_terms( $post->ID, intval( $ticket_category->term_id ), 'category', false );
    	}
    
    	/** Have the tags changed? */
    	if( esc_attr( $_POST[ 'ticket_tags' ] ) != $ticket_tags )
    	{
    		$updates[] = apply_filters( 'quality_comment_tags_updated', sprintf( __( '<strong>tags</strong> updated from <em>%s</em> to <em>%s</em>', 'quality' ), $ticket_tags, esc_attr( $_POST[ 'ticket_tags' ] ) ) );
    
    		$tags = wp_set_post_tags( $post->ID, explode( ', ', esc_attr( $_POST[ 'ticket_tags' ] ) ), false );
    	}
    
    	$updates = apply_filters( 'quality_comment_update_meta', $updates );
    
    	/** Add the array of updates as comment meta. */
    	if( !empty( $updates ) )
    		add_comment_meta( $comment_id, 'ticket_updates', $updates, true );
    
    	do_action( 'quality_comment_update_made', $comment_id );
    }
    
    /** Tell WordPress to run quality_update_ticket_status() when the 'quality_update_ticket_comment' hook is run. */
    add_action( 'quality_update_ticket_comment', 'quality_update_ticket_status', 10, 2 );
    
    /**
     * When a comment has been created, check to see if they are updating the status.
     * If they are, actually update the status, but then also provide a string which
     * says what is updated.
     *
     * @since Quality Control 0.1.2
     * @uses wp_set_object_terms
     * @uses get_term
     */
    function quality_update_ticket_status( $post, $comment_meta )
    {
    	global $updates;
    
    	$ticket_status = get_term( esc_attr( $comment_meta[ 'ticket_status' ] ), 'ticket_status' );
    
    	if( $ticket_status->term_id != quality_ticket_status( $post->ID, 'term_id', 'ticket_status' ) )
    	{
    		$updates[] = apply_filters( 'quality_comment_state_updated', sprintf( __( '<strong>state</strong> changed from <em>%s</em> to <em>%s</em>', 'quality' ), quality_ticket_status( $post->ID, 'name', 'ticket_status' ), $ticket_status->name ) );
    
    		$status = wp_set_object_terms( $post->ID, intval( $ticket_status->term_id ), 'ticket_status', false );
    
    		return $updates;
    	}
    }
    
    /** Tell WordPress to run quality_update_ticket_milestone() when the 'quality_update_ticket_comment' hook is run. */
    add_action( 'quality_update_ticket_comment', 'quality_update_ticket_milestone', 10, 2 );
    
    /**
     * When a comment has been created, check to see if they are updating the milestone.
     * If they are, actually update the milestone, but then also provide a string which
     * says what is updated.
     *
     * @since Quality Control 0.1.2
     * @uses wp_set_object_terms
     * @uses get_term
     */
    function quality_update_ticket_milestone( $post, $comment_meta )
    {
    	global $updates;
    
    	$ticket_milestone = get_term( esc_attr( $comment_meta[ 'ticket_milestone' ] ), 'ticket_milestone' );
    
    	if( $ticket_milestone->term_id != quality_ticket_status( $post->ID, 'term_id', 'ticket_milestone' ) )
    	{
    		$updates[] = apply_filters( 'quality_comment_milestone_updated', sprintf( __( '<strong>milestone</strong> changed from <em>%s</em> to <em>%s</em>', 'quality' ), quality_ticket_status( $post->ID, 'name', 'ticket_milestone' ), $ticket_milestone->name ) );
    
    		$milestone = wp_set_object_terms( $post->ID, intval( $ticket_milestone->term_id ), 'ticket_milestone', false );
    
    		return $updates;
    	}
    }
    
    /** Tell WordPress to run quality_update_ticket_owners() when the 'quality_update_ticket_comment' hook is run. */
    add_action( 'quality_update_ticket_comment', 'quality_update_ticket_owners', 10, 2 );
    
    /**
     * When a comment has been created, check to see if the assigned
     * users have been changed. If so, see if you can find the difference.
     *
     * @since Quality Control 0.1.2
     * @uses wp_set_object_terms
     * @uses get_term
     */
    function quality_update_ticket_owners( $post, $comment_meta )
    {
    	global $updates;
    
    	$ticket_owners = $comment_meta[ 'ticket_assign' ];
    
    	if( $ticket_owners != quality_get_ticket_assigned_to() )
    	{
    		$updates[] = apply_filters( 'quality_comment_owners_updated', sprintf( __( '<strong>owner(s)</strong> changed from <em>%s</em> to <em>%s</em>', 'quality' ), quality_get_ticket_assigned_to(), $ticket_owners ) );
    
    		$ticket_owners = explode( ",", $ticket_owners );
    		$owners = array();
    
    		delete_post_meta( $post->ID, '_assigned_to' );
    
    		foreach( $ticket_owners as $owner )
    		{
    			$owner = get_userdatabylogin( $owner );
    			//$owners[] = $owner->ID;
    			add_post_meta( $post->ID, '_assigned_to', $owner->ID );
    		}
    
    		//$owners = update_post_meta( $post->ID, '_assigned_to', $owners );
    
    		return $updates;
    	}
    }
    
    /** Tell WordPress to run quality_update_ticket_attachment() when the 'quality_update_ticket_comment' hook is run. */
    add_action( 'quality_update_ticket_comment', 'quality_update_ticket_attachment', 10, 2 );
    
    /**
     * When a comment has been created, check to see if they are trying
     * to attach a file. Adding the ID of the attachment to comment meta,
     * just as something to have in the future.
     *
     * @since Quality Control 0.1.2
     * @uses media_handle_upload
     * @uses add_comment_meta
     */
    function quality_update_ticket_attachment( $post, $comment_meta )
    {
    	global $updates;
    
    	if( !empty( $_FILES[ 'ticket_attachment' ][ 'size' ] ) )
    	{
    		require_once( ABSPATH . "wp-admin" . '/includes/admin.php' );
    
    		$attachment = media_handle_upload( 'ticket_attachment', $post->ID );
    
    		$updates[] = apply_filters( 'quality_comment_attachment_added', sprintf( __( 'File Attached: <a href="%s">%s</a>', 'quality' ), get_permalink( $attachment ), get_the_title( $attachment ) ) );
    
    		add_comment_meta( $comment_id, 'file_attachment', $attachment, true );
    	}
    }
    
    /** Tell WordPress to run quality_restrict_comment_editing() when the 'map_meta_cap' filter is called. */
    add_filter( 'map_meta_cap', 'quality_restrict_comment_editing', 10, 3 );
    
    /**
     * Restrict post author to only editing their comments.
     *
     * via https://scribu.net/wordpress/prevent-blog-authors-from-editing-comments.html
     *
     * @since Quality Control 0.1
     * @uses add_options_page
     */
    function quality_restrict_comment_editing( $caps, $cap, $user_id )
    {
    	global $pagenow, $comment;
    
    	if( 'edit_post' == $cap && is_admin() && 'comment.php' == $pagenow )
    	{
    		if ( $comment->user_id != $user_id )
    			$caps[] = 'moderate_comments';
    	}
    
    	return $caps;
    }
    
    /** Tell WordPress to run quality_blank_comment() when the 'pre_comment_on_post' action is called. */
    add_action( 'pre_comment_on_post', 'quality_blank_comments' );
    
    /**
     * If the comment field is blank, insert an invisible &nbsp;
     * This only works once. If you do it twice in the same ticket,
     * it will trigger the duplicate comment error. still looking for a work-around.
     *
     * via https://www.johnpbloch.com/
     *
     * @since Quality Control 0.1.3
     */
    function quality_blank_comments()
    {
    	$comment_content = ( isset( $_POST[ 'comment' ] ) ) ? trim( $_POST['comment'] ) : null;
    
    	if( empty( $comment_content ) )
    		$_POST[ 'comment' ] = '&nbsp;';
    }
    Spencer Finnell

    (@spencerfinnell)

    Please update to version 0.2, as this is supported.

    uturano

    (@uturano)

    Hi Spencer,

    thanks for your answer and for your very good work. I’m trying to install the version 0.2 but there is a thing that i dont’ understand. You say “In functions.php of your child theme add:”…….but what is the child theme? Where have I exactly insert that part of php code? In whitch function.php file?

    Thanks
    Umberto

    Spencer Finnell

    (@spencerfinnell)

    Check out Child Themes in the Codex.

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Plugin adds User Assignment to Quality Control Theme’ is closed to new replies.