Last active
December 29, 2017 19:26
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.