Data Type API

The Data Types API is used by WordPoints to provide a common interface for interacting with values of various types.

The existing Data Types include:

  • text — A string of text (like the content of a post).
  • integer — An integer number value (like the ID of a post).
  • decimal_number — Floats, numbers composed entirely of integers and an optional decimal (like the price of a product). (Added in 2.3.0)

The following Data Types are reserved, but not yet implemented:

Adding a new data type is fairly simple, all you have to do is extend the WordPoints_Data_Type class, and define the validate_value() method to check if a value is of that data type. The class for the integer data type looks like this:

As you can see, all that the validate_value() method needs to do is see if a passed in value is the correct type, and if it isn’t to return a WP_Error object containing an error message. The error message should contain a placeholder, which will be filled in with the form field name by the code that is validating the value.