MPFT

Extends WOOF_Wrap

Methods

The base class for all MasterPress field types, which establishes the necessary methods for implementing a field type user interface, and a base API for each field type used in theme development.

List of Methods

Magic Methods

Property Methods

  • addslashes()String

    Apply’s PHPs addslashes function to the field value.

  • balance_tags()String

    Applies WordPress’ balance_tags function to the field value, to correctly balance HTML tags.

  • equals( String $value )Boolean

    Check if the value in this field equals the supplied value.

  • esc_attr()String

    Applies WordPress’ esc_attr function to the field value, for formatting strings to be safely used inside HTML tag attributes.

  • esc_html()String

    Applies WordPress’ esc_html function to the field value, for escaping HTML blocks. .

  • esc_js()String

    Applies WordPress’ esc_js function to the field value, to safely escape the value of the string for use in javascript string variables.

  • esc_sql()String

    Applies WordPress’ esc_sql function to safely and securely escape the field of the value for use in SQL statements.

  • esc_sql_like()String

    Applies WordPress’ like_escape function to the value of the field, to allow safe use in SQL like statements.

  • esc_url( Array $protocols )String

    Applies WordPress’ esc_url function to the field value, to sanitize URLs.

  • esc_url_raw( Array $allowed_protocols )String

    Applies WordPress’ esc_url_raw function to the field value, which is the same as esc_url but does not replace HTML entities in the string.

  • float( Float $fallback = 0.00 )Float

    Returns the value of the field cast to a float if it is numeric, or the value of the $fallback argument otherwise (which defaults to 0.00).

  • html()String

    A default implementation of the html method for field types, which simply forwards the call to MPFT::val.

  • int( Integer $fallback = 0 )Integer

    Returns the value of the field cast to an integer if it is numeric, or the value of the $fallback argument otherwise (which defaults to 0).

  • is()Mixed

    A default implementation of the is method for field types, which simply returns the value of the field.

  • is_email()Boolean

    Checks if the field value is a valid email address, via WordPress’ is_email function.

  • is_numeric()Boolean

    Checks if the value of the field is numeric, via PHP’s is_numeric function.

  • kses( Array $allowed_html = null, Array $allowed_protocols = null )String

    Applies WordPress wp_kses function to the value of the field to safely sanitize its content.

  • md5()String

    Applies PHP’s md5 function to the value of the field.

  • nl2( String $tag = p, Boolean $line_breaks = false, Boolean $xml = true )String

    Applies the WOOF::nl2 method to the value of the field. .

  • nl2br( Boolean $is_xhtml = true )String

    Applies PHP’s nl2br function to the field value.

  • nl2p( String $string, Boolean $line_breaks = false, Boolean $xml = true )String

    Applies the WOOF::nl2p function to the field value.

  • raw()Mixed

    Retrieves the raw value of the field (after decoding the value in the database, as some values are encoded to json).

  • s( Array / String $args = array() )String

    A shorthand synonym for the MPFT::sanitize function.

  • sanitize( Array / String $args = array() )String

    Calls the sanitize_title_with_dashes WordPress function on the field value, with some optional post-processing.

  • sanitize_email()String

    Calls WordPress’ sanitize_email function on the field value.

  • shorthash( Integer $length = 12 )String

    Generates a short hash (via truncated md5) of the field value, configurable via a length parameter. .

  • str()String

    Applies the MPFT::__toString on the field to return the string representation of the field.

  • stripslashes()String

    Calls PHP’s stripslashes function on the field value. .

  • t( String $tmpl, $default = null )String

    Outputs the value of this field in a supplied template with a placeholder for where the field value should be, but only if the value is not empty.

  • truncate( Integer $length = 160, String $etc = … )String

    An alternative syntax to MPFT::truncate_custom with explicit arguments, which also always truncates at the end.

  • truncate_custom( Array / String $args )String

    Calls the WOOF::truncate method on the field value, which chops the value to the specified length, with various options to control where and if the truncation takes place.

  • truncate_middle( Integer $length = 160, String $etc = … )String

    An alternative syntax to MPFT::truncate_custom with explicit arguments, which always truncates in the middle.

  • val()Mixed

    A shorthand to return the field’s value.

  • value()Mixed

    Returns the value of the field, which is very useful in expressions involving the field, or for placing the value in a variable.

  • wrap( String $tag, Mixed $default = null )String

    Wraps the string value of the field in the specified tag if the field has a value, but falls back to the default value otherwise. This method can be helpful to allow you to output a field value in a single line of code without needing to check for its presence first, especially when using a null default paramater, which will not even output.

Manipulation

  • value_for_set( Mixed $value )Mixed

    A default implementation that field types use when being assigned a value, to parse that value into the correct format for data storage assigned value when assigning values to fields directly, which allows field types to offer a very developer-friendly interface for assignment.Note that this default implementation simply returns the value as it was assigned, which is appropriate for most simple fields.The Related Term field type, for example, overrides this method to allow terms to be set via arrays or CSV string of term slugs, term names, or term IDs.

Theming

Internal Use

  • __toString()String

    A default implementation of PHP’s magic method __toString to allow the MEOW_Field to auto-convert itself to a string when echoed.

  • call( String $name, Array $arguments = array() )Mixed

    Forwards a call for a type delegate object onto the object returned by get_delegate in this class.

  • change()

    A default implementation for a change method for all field types, designed to be called when any field updates are made.

  • col()String

    A default implementation to return content for this field that is appropriate for the display of the field in a column in Post and Term management screens in WordPress.

  • forward()WOOF_Silent

    A default implementation of the forward method which simply returns a WOOF_Silent object to indicate that the field type does not support call forwarding to another delegate object. When implemented by specific field types, this method enables the ability to directly forward method calls from the MEOW_Field object to another object that the field type is delegating to – for example, the Related Post field type delegates to a WOOF_Post object representing the first post selected in the field UI.This method is intended for internal use, and should not be called directly.

  • value_for_set( Mixed $value )Mixed

    A default implementation that field types use when being assigned a value, to parse that value into the correct format for data storage assigned value when assigning values to fields directly, which allows field types to offer a very developer-friendly interface for assignment.Note that this default implementation simply returns the value as it was assigned, which is appropriate for most simple fields.The Related Term field type, for example, overrides this method to allow terms to be set via arrays or CSV string of term slugs, term names, or term IDs.

  • __toString()String

    A default implementation of PHP’s magic method __toString to allow the MEOW_Field to auto-convert itself to a string when echoed.

  • addslashes()String

    Apply’s PHPs addslashes function to the field value.

  • balance_tags()String

    Applies WordPress’ balance_tags function to the field value, to correctly balance HTML tags.

  • call( String $name, Array $arguments = array() )Mixed

    Forwards a call for a type delegate object onto the object returned by get_delegate in this class.

  • change()

    A default implementation for a change method for all field types, designed to be called when any field updates are made.

  • col()String

    A default implementation to return content for this field that is appropriate for the display of the field in a column in Post and Term management screens in WordPress.

  • equals( String $value )Boolean

    Check if the value in this field equals the supplied value.

  • esc_attr()String

    Applies WordPress’ esc_attr function to the field value, for formatting strings to be safely used inside HTML tag attributes.

  • esc_html()String

    Applies WordPress’ esc_html function to the field value, for escaping HTML blocks. .

  • esc_js()String

    Applies WordPress’ esc_js function to the field value, to safely escape the value of the string for use in javascript string variables.

  • esc_sql()String

    Applies WordPress’ esc_sql function to safely and securely escape the field of the value for use in SQL statements.

  • esc_sql_like()String

    Applies WordPress’ like_escape function to the value of the field, to allow safe use in SQL like statements.

  • esc_url( Array $protocols )String

    Applies WordPress’ esc_url function to the field value, to sanitize URLs.

  • esc_url_raw( Array $allowed_protocols )String

    Applies WordPress’ esc_url_raw function to the field value, which is the same as esc_url but does not replace HTML entities in the string.

  • float( Float $fallback = 0.00 )Float

    Returns the value of the field cast to a float if it is numeric, or the value of the $fallback argument otherwise (which defaults to 0.00).

  • forward()WOOF_Silent

    A default implementation of the forward method which simply returns a WOOF_Silent object to indicate that the field type does not support call forwarding to another delegate object. When implemented by specific field types, this method enables the ability to directly forward method calls from the MEOW_Field object to another object that the field type is delegating to – for example, the Related Post field type delegates to a WOOF_Post object representing the first post selected in the field UI.This method is intended for internal use, and should not be called directly.

  • html()String

    A default implementation of the html method for field types, which simply forwards the call to MPFT::val.

  • int( Integer $fallback = 0 )Integer

    Returns the value of the field cast to an integer if it is numeric, or the value of the $fallback argument otherwise (which defaults to 0).

  • is()Mixed

    A default implementation of the is method for field types, which simply returns the value of the field.

  • is_email()Boolean

    Checks if the field value is a valid email address, via WordPress’ is_email function.

  • is_numeric()Boolean

    Checks if the value of the field is numeric, via PHP’s is_numeric function.

  • kses( Array $allowed_html = null, Array $allowed_protocols = null )String

    Applies WordPress wp_kses function to the value of the field to safely sanitize its content.

  • md5()String

    Applies PHP’s md5 function to the value of the field.

  • nl2( String $tag = p, Boolean $line_breaks = false, Boolean $xml = true )String

    Applies the WOOF::nl2 method to the value of the field. .

  • nl2br( Boolean $is_xhtml = true )String

    Applies PHP’s nl2br function to the field value.

  • nl2p( String $string, Boolean $line_breaks = false, Boolean $xml = true )String

    Applies the WOOF::nl2p function to the field value.

  • raw()Mixed

    Retrieves the raw value of the field (after decoding the value in the database, as some values are encoded to json).

  • s( Array / String $args = array() )String

    A shorthand synonym for the MPFT::sanitize function.

  • sanitize( Array / String $args = array() )String

    Calls the sanitize_title_with_dashes WordPress function on the field value, with some optional post-processing.

  • sanitize_email()String

    Calls WordPress’ sanitize_email function on the field value.

  • shorthash( Integer $length = 12 )String

    Generates a short hash (via truncated md5) of the field value, configurable via a length parameter. .

  • str()String

    Applies the MPFT::__toString on the field to return the string representation of the field.

  • stripslashes()String

    Calls PHP’s stripslashes function on the field value. .

  • t( String $tmpl, $default = null )String

    Outputs the value of this field in a supplied template with a placeholder for where the field value should be, but only if the value is not empty.

  • truncate( Integer $length = 160, String $etc = … )String

    An alternative syntax to MPFT::truncate_custom with explicit arguments, which also always truncates at the end.

  • truncate_custom( Array / String $args )String

    Calls the WOOF::truncate method on the field value, which chops the value to the specified length, with various options to control where and if the truncation takes place.

  • truncate_middle( Integer $length = 160, String $etc = … )String

    An alternative syntax to MPFT::truncate_custom with explicit arguments, which always truncates in the middle.

  • val()Mixed

    A shorthand to return the field’s value.

  • value()Mixed

    Returns the value of the field, which is very useful in expressions involving the field, or for placing the value in a variable.

  • value_for_set( Mixed $value )Mixed

    A default implementation that field types use when being assigned a value, to parse that value into the correct format for data storage assigned value when assigning values to fields directly, which allows field types to offer a very developer-friendly interface for assignment.Note that this default implementation simply returns the value as it was assigned, which is appropriate for most simple fields.The Related Term field type, for example, overrides this method to allow terms to be set via arrays or CSV string of term slugs, term names, or term IDs.

  • wrap( String $tag, Mixed $default = null )String

    Wraps the string value of the field in the specified tag if the field has a value, but falls back to the default value otherwise. This method can be helpful to allow you to output a field value in a single line of code without needing to check for its presence first, especially when using a null default paramater, which will not even output.

Base Class Methods

View method list from the base class WOOF_Wrap.

Latest From the Blog

MasterPress 1.3.10 is now available

9th November 2023

MasterPress 1.3.10 is a feature and bugfix release. Workaround for fatal error introduced by changes to WordPress’ wpdb class in WordPress 6.4. Added actions to MPC files upload_field & WF image save_image functions.

Plugin Requirements

MasterPress requires a minimum of WordPress version 4.9, MySQL 5.6, and PHP version 5.6.20.

We also recommend that PHP is configured to use a memory limit of 64MB per request (128MB may be required for sites with higher complexity).

This plug-in is not compatible with the WordPress.com hosted service.

Three AM