Jump to content

Modifying Wordpress Plugin to add images next to petition signatures


Recommended Posts

Weird request, but I'm currently using the "SpeakUp! Email Petitions" plugin on Wordpress (here) and would like to have an image automatically show up next to each individual signature in the signature list. How would I go about this?

Ideally, I wanted to have it where if you mouse over the image, you see the signature, but I think this might be a bit complex (though definitely preferred if possible). 

I'm new to coding, so any help would be MUCH appreciated. :) Thank you!

 

The following is the code from the class.signaturelist.php file (not sure if this is the file I should edit?):

<?php

/**
 * Class for displaying signatures via [signaturelist] shortcode
 */
class dk_speakup_Signaturelist
{

	/**
	 * generates HTML table of signatures for a single petition
	 *
	 * @param int $id the ID petition for which we are displaying signatures
	 * @param int $start the first signature to be retrieved
	 * @param int $limit number of signatures to be retrieved
	 * @param string $context either 'shortcode' or 'ajax' to distinguish between calls from the initia page load (shortcode) and calls from pagination buttons (ajax)
	 * @param string $dateformat PHP date format provided by shortcode attribute - also relayed in ajax requests
	 * @param string $nextbuttontext provided by shortcode attribute
	 * @param string $prevtbuttontext provided by shortcode attribute
	 *
	 * @return string HTML table containing signatures (or just the table rows if context is ajax)
	 */
	public static function table( $id, $start, $limit, $context = 'shortcode', $dateformat = 'M d, Y', $nextbuttontext = '>', $prevbuttontext = '<' ) {

		include_once( 'class.signature.php' );
		$the_signatures = new dk_speakup_Signature();
		$options = get_option( 'dk_speakup_options' );

		// get list of columns to display - as defined in settings
		$columns = unserialize( $options['signaturelist_columns'] );

		// get the signatures
		$signatures = $the_signatures->all( $id, $start, $limit, 'signaturelist' );

		$total = $the_signatures->count( $id, 'signaturelist' );
		$current_signature_number = $total - $start;
		$signatures_list = '';

		// only show signature lists if there are signatures
		if ( $total > 0 ) {
			// determine which columns to display
			$display_city     = ( in_array( 'sig_city', $columns ) ) ? 1 : 0;
			$display_state    = ( in_array( 'sig_state', $columns ) ) ? 1 : 0;
			$display_postcode = ( in_array( 'sig_postcode', $columns ) ) ? 1 : 0;
			$display_country  = ( in_array( 'sig_country', $columns ) ) ? 1 : 0;
			$display_custom   = ( in_array( 'sig_custom', $columns ) ) ? 1 : 0;
			$display_date     = ( in_array( 'sig_date', $columns ) ) ? 1 : 0;

			if ( $context !== 'ajax' ) { // only include on initial page load (not when paging)
				$signatures_list = '
					<!-- signaturelist -->
					<table class="dk-speakup-signaturelist dk-speakup-signaturelist-' . $id . '">
						<caption>' . $options['signaturelist_header'] . '</caption>';
			}

			$row_count = 0;
			foreach ( $signatures as $signature ) {
				if ( $row_count % 2 ) {
					$signatures_list .= '<tr class="dk-speakup-even">';
				}
				else {
					$signatures_list .= '<tr class="dk-speakup-odd">';
				}
				$signatures_list .= '<td class="dk-speakup-signaturelist-count">' . number_format( $current_signature_number, 0, '.', ',' ) . '</td>';
				$signatures_list .= '<td class="dk-speakup-signaturelist-name">' . stripslashes( $signature->first_name . ' ' . $signature->last_name ) . '</td>';

				// if we display both city and state, combine them into one column
				$city  = ( $display_city )  ? $signature->city : '';
				$state = ( $display_state ) ? $signature->state : '';
				if ( $display_city && $display_state ) {
					// should we separate with a comma?
					$delimiter = ( $city !='' && $state != '' ) ? ', ' : '';
					$signatures_list .= '<td class="dk-speakup-signaturelist-city">' . stripslashes( $city . $delimiter . $state ) . '</td>';
				}
				// else keep city or state values in their own column
				else {
					if ( $display_city ) $signatures_list  .= '<td class="dk-speakup-signaturelist-city">' . stripslashes( $city ) . '</td>';
					if ( $display_state ) $signatures_list .= '<td class="dk-speakup-signaturelist-state">' . stripslashes( $state ) . '</td>';
				}

				if ( $display_postcode ) $signatures_list .= '<td class="dk-speakup-signaturelist-postcode">' . stripslashes( $signature->postcode ) . '</td>';
				if ( $display_country ) $signatures_list  .= '<td class="dk-speakup-signaturelist-country">' . stripslashes( $signature->country ) . '</td>';
				if ( $display_custom ) $signatures_list   .= '<td class="dk-speakup-signaturelist-custom">' . stripslashes( $signature->custom_field ) . '</td>';
				if ( $display_date ) $signatures_list     .= '<td class="dk-speakup-signaturelist-date">' . date_i18n( $dateformat, strtotime( $signature->date ) ) . '</td>';
				$signatures_list .= '</tr>';
 
				$current_signature_number --;
				$row_count ++;
			}

			if ( $context !== 'ajax' ) { // only include on initial page load

				if ( $limit != 0 && $start + $limit < $total  ) {
					$colspan = ( count( $columns ) + 2 );
					$signatures_list .= '
					<tr class="dk-speakup-signaturelist-pagelinks">
						<td colspan="' . $colspan . '">
							<a class="dk-speakup-signaturelist-prev dk-speakup-signaturelist-disabled" rel="' . $id .  ',' . $total . ',' . $limit . ',' . $total . ',0">' . $prevbuttontext . '</a>
							<a class="dk-speakup-signaturelist-next" rel="' . $id .  ',' . ( $start + $limit ) . ',' . $limit . ',' . $total . ',1">' . $nextbuttontext . '</a>
						</td>
					</tr>
					';
				}
				$signatures_list .= '</table>';
			}

		}

		return $signatures_list;
	}

}

?>

Find the line in the function that has this:

 

				if ( $display_date ) $signatures_list     .= '<td class="dk-speakup-signaturelist-date">' . date_i18n( $dateformat, strtotime( $signature->date ) ) . '</td>';
At that point, if you add a new ... you'll inject it at the end of the existing row of content.

 

 

 $signatures_list     .= '<td><img src="some/image/path?"></td>';
What is the idea here? Well this code builds up a variable ($signatures_list) that is ultimately displayed a single html table row. In php, '.' concatenates, so the code here simply keeps concatenating extra values onto the end of the string until it is fully formed. That is basic idea of the pattern of

 

$signatures_list .=  'something new to add to the end';

What the image would be, where it's stored, and what you meant with your rollover comment are all mysteries you didn't adequately explain for anyone to offer you any more help.

Thank you so much!!! I have another question if you could help me out -- would it be possible to stack the First Name, Last Name, Custom, & Date fields on top of the image I have in the first column? So it would appear as so:

 

(background image)

First Name, Last Name

Custom

Date

 

instead of having them in a row? Thanks again!

<?php

/**
 * Class for displaying signatures via [signaturelist] shortcode
 */
class dk_speakup_Signaturelist
{

	/**
	 * generates HTML table of signatures for a single petition
	 *
	 * @param int $id the ID petition for which we are displaying signatures
	 * @param int $start the first signature to be retrieved
	 * @param int $limit number of signatures to be retrieved
	 * @param string $context either 'shortcode' or 'ajax' to distinguish between calls from the initia page load (shortcode) and calls from pagination buttons (ajax)
	 * @param string $dateformat PHP date format provided by shortcode attribute - also relayed in ajax requests
	 * @param string $nextbuttontext provided by shortcode attribute
	 * @param string $prevtbuttontext provided by shortcode attribute
	 *
	 * @return string HTML table containing signatures (or just the table rows if context is ajax)
	 */
	public static function table( $id, $start, $limit, $context = 'shortcode', $dateformat = 'M d, Y', $nextbuttontext = '>', $prevbuttontext = '<' ) {

		include_once( 'class.signature.php' );
		$the_signatures = new dk_speakup_Signature();
		$options = get_option( 'dk_speakup_options' );

		// get list of columns to display - as defined in settings
		$columns = unserialize( $options['signaturelist_columns'] );

		// get the signatures
		$signatures = $the_signatures->all( $id, $start, $limit, 'signaturelist' );

		$total = $the_signatures->count( $id, 'signaturelist' );
		$current_signature_number = $total - $start;
		$signatures_list = '';

		// only show signature lists if there are signatures
		if ( $total > 0 ) {
			// determine which columns to display
			$display_city     = ( in_array( 'sig_city', $columns ) ) ? 1 : 0;
			$display_state    = ( in_array( 'sig_state', $columns ) ) ? 1 : 0;
			$display_postcode = ( in_array( 'sig_postcode', $columns ) ) ? 1 : 0;
			$display_country  = ( in_array( 'sig_country', $columns ) ) ? 1 : 0;
			$display_custom   = ( in_array( 'sig_custom', $columns ) ) ? 1 : 0;
			$display_date     = ( in_array( 'sig_date', $columns ) ) ? 1 : 0;

			if ( $context !== 'ajax' ) { // only include on initial page load (not when paging)
				$signatures_list = '
					<!-- signaturelist -->
					<table class="dk-speakup-signaturelist dk-speakup-signaturelist-' . $id . '">
						<caption>' . $options['signaturelist_header'] . '</caption>';
			}

			$row_count = 0;
			foreach ( $signatures as $signature ) {
				if ( $row_count % 2 ) {
					$signatures_list .= '<tr class="dk-speakup-even">';
				}
				else {
					$signatures_list .= '<tr class="dk-speakup-odd">';
				}
$signatures_list     .= '<td><div style="width: 175px; height: 175px; background: url(wp-content/uploads/Rose2.png) no-repeat center center;"></td>';

$signatures_list .= '<td class="dk-speakup-signaturelist-name">' . stripslashes( $signature->first_name . ' ' . $signature->last_name ) . '</td>';
				
				// if we display both city and state, combine them into one column
				$city  = ( $display_city )  ? $signature->city : '';
				$state = ( $display_state ) ? $signature->state : '';
				if ( $display_city && $display_state ) {
					// should we separate with a comma?
					$delimiter = ( $city !='' && $state != '' ) ? ', ' : '';
					$signatures_list .= '<td class="dk-speakup-signaturelist-city">' . stripslashes( $city . $delimiter . $state ) . '</td>';
				}
				// else keep city or state values in their own column
				else {
					if ( $display_city ) $signatures_list  .= '<td class="dk-speakup-signaturelist-city">' . stripslashes( $city ) . '</td>';
					if ( $display_state ) $signatures_list .= '<td class="dk-speakup-signaturelist-state">' . stripslashes( $state ) . '</td>';
				}

				if ( $display_postcode ) $signatures_list .= '<td class="dk-speakup-signaturelist-postcode">' . stripslashes( $signature->postcode ) . '</td>';
				if ( $display_country ) $signatures_list  .= '<td class="dk-speakup-signaturelist-country">' . stripslashes( $signature->country ) . '</td>';
				if ( $display_custom ) $signatures_list   .= '<td class="dk-speakup-signaturelist-custom">' . stripslashes( $signature->custom_field ) . '</td>';
				if ( $display_date ) $signatures_list     .= '<td class="dk-speakup-signaturelist-date">' . date_i18n( $dateformat, strtotime( $signature->date ) ) . '</td>';
 	
				$signatures_list .= '</tr>';
 
				$current_signature_number --;
				$row_count ++;
			}

			if ( $context !== 'ajax' ) { // only include on initial page load

				if ( $limit != 0 && $start + $limit < $total  ) {
					$colspan = ( count( $columns ) + 2 );
					$signatures_list .= '
					<tr class="dk-speakup-signaturelist-pagelinks">
						<td colspan="' . $colspan . '">
							<a class="dk-speakup-signaturelist-prev dk-speakup-signaturelist-disabled" rel="' . $id .  ',' . $total . ',' . $limit . ',' . $total . ',0">' . $prevbuttontext . '</a>
							<a class="dk-speakup-signaturelist-next" rel="' . $id .  ',' . ( $start + $limit ) . ',' . $limit . ',' . $total . ',1">' . $nextbuttontext . '</a>
						</td>
					</tr>
					';
				}
				$signatures_list .= '</table>';
			}

		}

		return $signatures_list;
	}

}

?>
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.