Skip to content

Instantly share code, notes, and snippets.

@xnau
Created September 16, 2021 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xnau/0a01f468dfe6a94c00970dcfeb6fb920 to your computer and use it in GitHub Desktop.
Save xnau/0a01f468dfe6a94c00970dcfeb6fb920 to your computer and use it in GitHub Desktop.
Shows how to add a PArticipants Database record edit button to the single record template
<?php
/**
* @name pdb single template
* @version 1.0
*
* default template for displaying a single record with a record edit button
*
*/
if ( $this->participant_id > 0 ) :
$record = new PDb_Template( $this );
?>
<div class="wrap <?php echo $this->wrap_class ?>">
<?php while ( $this->have_groups() ) : $this->the_group(); ?>
<div class="section <?php $this->group->print_class() ?>" id="<?php echo Participants_Db::$prefix.$this->group->name ?>">
<?php $this->group->print_title( '<h2 class="pdb-group-title">', '</h2>' ) ?>
<?php $this->group->print_description() ?>
<?php while ( $this->have_fields() ) : $this->the_field();
// CSS class for empty fields
$empty_class = $this->get_empty_class( $this->field );
?>
<dl class="<?php echo Participants_Db::$prefix.$this->field->name.' '.$this->field->form_element.' '.$empty_class?>">
<dt class="<?php echo $this->field->name.' '.$empty_class?>"><?php $this->field->print_label() ?></dt>
<dd class="<?php echo $this->field->name.' '.$empty_class?>"><?php $this->field->print_value() ?></dd>
</dl>
<?php endwhile; // end of the fields loop ?>
</div>
<?php endwhile; // end of the groups loop ?>
<a href="<?php echo $record->get_edit_link() ?>"><button class="button button-secondary">Edit Record</button></a>
</div>
<?php else : // content to show if no record is found ?>
<?php $error_message = Participants_Db::plugin_setting( 'no_record_error_message', '' );
if ( ! empty( $error_message ) ) : ?>
<p class="alert alert-error"><?php echo $error_message ?></p>
<?php endif ?>
<?php endif ?>
@xnau
Copy link
Author

xnau commented Sep 16, 2021

Download and place in the Participants Database custom template location. On most systems, this will be:

wp-content/participants-database-templates/

Use this custom template with a shortcode like this:
[pdb_single template=edit-button]

@xnau
Copy link
Author

xnau commented Sep 16, 2021

If the button doesn't look right, you will need to edit the template so the HTML is similar to other buttons on your site. You may also need to use some custom CSS to get the appearance you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment