Skip to content

Instantly share code, notes, and snippets.

@xnau
Last active December 29, 2017 19:26
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/3c191ec34923ff10c832aaf285a2b68b to your computer and use it in GitHub Desktop.
Save xnau/3c191ec34923ff10c832aaf285a2b68b to your computer and use it in GitHub Desktop.
Describes how to set a custom datatype for a Participants Database field form element
<?php
/**
* @wordpress-plugin
* Plugin Name: Set Decimal Datatype
* Description: set a custom datatype for a Participants Database decimal form element
*/
add_filter( 'pdb-form_element_datatype', 'xnau_set_decimal_type', 10, 2 );
/**
* sets the datatype for decimal fields
*
* @param string $datatype the default datatype
* @param string $form_element the form element type
* @return string the datatype to use for this form element
*/
function xnau_set_decimal_type( $datatype, $form_element )
{
if ( $form_element === 'decimal' ) {
$datatype = 'decimal(14,8)'; // change this to the decimal configuration you need
}
return $datatype;
}
@xnau
Copy link
Author

xnau commented Dec 29, 2017

After you install and activate this plugin, you must save some change to your decimal field definition (on the Manage Database Fields page) so that the database is updated as well. If you create a new decimal field, it will get it's decimal format from this plugin.

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