PHP Class WPAS_Custom_Fields

Author: ThemeAvenue ([email protected])
Show file Open project: awesome-support/awesome-support Class Usage Examples

Public Properties

Property Type Description
$remove_mb List of metaboxes to remove.

Public Methods

Method Description
__construct ( )
add_custom_column ( array $columns ) : array Add possible custom columns to tickets list.
add_field ( string $name = '', array $args = [] ) : boolean Add a new custom field to the ticket.
check_required_fields ( $go, array $data = [] ) : mixed Checks required custom fields.
custom_column_orderby ( object $query ) : void Reorder custom columns based on custom values.
custom_columns_content ( string $column, integer $post_id ) : void Manage custom columns content
custom_columns_sortable ( array $columns ) : array Make custom columns sortable
custom_taxonomy_filter ( ) : void Add filters for custom taxonomies
custom_taxonomy_filter_convert_id_term ( object $query ) : void Convert taxonomy term ID into term slug.
enqueue_select2_assets ( ) : void Register and enqueue the select2 assets
frontend_submission ( integer $ticket_id ) : void Trigger the custom fields save function upon front-end submission of a new ticket.
get_custom_fields ( ) : array Return the list of fields
have_custom_fields ( boolean $core = false ) : boolean Check if custom fields are registered.
is_field_missing ( array $data = [] ) : boolean | WP_Error Makes sure no required custom field is missing from the data passed.
move_status_first ( array $columns ) : array Reorder the admin columns.
register_taxonomies ( ) : void Register all custom taxonomies.
remove_field ( string $id ) : void Remove a custom field.
remove_taxonomy_metabox ( ) : void Remove taxonomies metaboxes.
save_core_field ( integer $post_id, array $field, mixed $value ) : void Save the core fields.
save_custom_fields ( integer $post_id, array $data = [], boolean $allow_log = true ) : array Save all custom fields given in $data to the database.
status_filter ( ) : void Add status dropdown in the filters bar.
status_filter_by_status ( object $query ) : void Filter tickets by status.
submission_form_fields ( ) : void Display the custom fields on submission form.

Method Details

__construct() public method

public __construct ( )

add_custom_column() public method

Add possible custom columns to tickets list.
Since: 3.0.0
public add_custom_column ( array $columns ) : array
$columns array List of default columns
return array Updated list of columns

add_field() public method

Add a new custom field to the ticket.
Since: 3.0.0
public add_field ( string $name = '', array $args = [] ) : boolean
$name string Option name
$args array Field arguments
return boolean Whether or not the field was added

check_required_fields() public method

This function is hooked on the filter wpas_before_submit_new_ticket_checks through the parent class. It checks all required custom fields and if they were correctly filled. If one or more required field(s) is/are missing then the submission process is stopped and an error message is returned.
Since: 3.0.0
public check_required_fields ( $go, array $data = [] ) : mixed
$data array Array of data containing the custom fields to check for required attribute
return mixed True if no error or a WP_Error otherwise

custom_column_orderby() public method

Reorder custom columns based on custom values.
Since: 3.0.0
public custom_column_orderby ( object $query ) : void
$query object Main query
return void

custom_columns_content() public method

Manage custom columns content
Since: 3.0.0
public custom_columns_content ( string $column, integer $post_id ) : void
$column string The name of the column to display
$post_id integer ID of the post being processed
return void

custom_columns_sortable() public method

Make custom columns sortable
Since: 3.0.0
public custom_columns_sortable ( array $columns ) : array
$columns array Already sortable columns
return array New sortable columns

custom_taxonomy_filter() public method

Add filters for custom taxonomies
Since: 2.0.0
public custom_taxonomy_filter ( ) : void
return void

custom_taxonomy_filter_convert_id_term() public method

When filtering, WordPress uses the term ID by default in the query but that doesn't work. We need to convert it to the taxonomy term slug.
public custom_taxonomy_filter_convert_id_term ( object $query ) : void
$query object WordPress current main query
return void

enqueue_select2_assets() public method

This method will be called if the select2 parameter is passed with a custom field (could be a select or a taxonomy field).
Since: 3.3
public enqueue_select2_assets ( ) : void
return void

frontend_submission() public method

Trigger the custom fields save function upon front-end submission of a new ticket.
Since: 3.2.0
public frontend_submission ( integer $ticket_id ) : void
$ticket_id integer ID of the ticket that's just been added
return void

get_custom_fields() public method

Return the list of fields
Since: 3.0.0
public get_custom_fields ( ) : array
return array List of custom fields

have_custom_fields() public method

If there are registered custom fields, the method returns true. Core fields are not considered registered custom fields by default but that can be overridden with the $core parameter.
Since: 3.0.0
public have_custom_fields ( boolean $core = false ) : boolean
$core boolean True if core fields should be counted as registered custom fields.
return boolean True if custom fields are present, false otherwise

is_field_missing() public method

Makes sure no required custom field is missing from the data passed.
Since: 3.2.0
public is_field_missing ( array $data = [] ) : boolean | WP_Error
$data array Array of data to check
return boolean | WP_Error False if no field is missing, WP_Error with the list of missing fields otherwise

move_status_first() public method

Reorder the admin columns.
Since: 3.0.0
public move_status_first ( array $columns ) : array
$columns array List of admin columns
return array Re-ordered list

register_taxonomies() public method

Register all custom taxonomies.
Since: 3.0.0
public register_taxonomies ( ) : void
return void

remove_field() public method

Remove a custom field.
Since: 3.0.0
public remove_field ( string $id ) : void
$id string ID of the field to remove
return void

remove_taxonomy_metabox() public method

In some cases taxonomies are used as select. Hence, we don't need the standard taxonomy metabox.
Since: 3.0.0
public remove_taxonomy_metabox ( ) : void
return void

save_core_field() public method

Core fields are processed differently and won't use the same saving function as the standard custom fields of the same type.
Since: 3.2.0
public save_core_field ( integer $post_id, array $field, mixed $value ) : void
$post_id integer ID of the post being saved
$field array Field array
$value mixed Field new value
return void

save_custom_fields() public method

Save all custom fields given in $data to the database.
Since: 3.2.0
public save_custom_fields ( integer $post_id, array $data = [], boolean $allow_log = true ) : array
$post_id integer ID of the post being saved
$data array Array of data that might contain custom fields values.
$allow_log boolean Whether or not to allow logging actions. If this is set to false and the custom field is set to true, $log has higher priority. I tis used to prevent logging on ticket creation.
return array Array of custom field / value saved to the database

status_filter() public method

Add status dropdown in the filters bar.
Since: 2.0.0
public status_filter ( ) : void
return void

status_filter_by_status() public method

When filtering, WordPress uses the ID by default in the query but that doesn't work. We need to convert it to the taxonomy term.
Since: 3.0.0
public status_filter_by_status ( object $query ) : void
$query object WordPress current main query
return void

submission_form_fields() public method

Display the custom fields on submission form.
Since: 3.2.0
public submission_form_fields ( ) : void
return void

Property Details

$remove_mb public property

List of metaboxes to remove.
public $remove_mb