Admin_Ajax implements Registerable

Handles all ajax requests from the admin panel for the plugin.

Interfaces, Classes and Traits

Registerable

Table of Contents

create_group()  : void
Create a group in the database.
delete_filter()  : void
Delete a filter from the database.
delete_group()  : void
Delete a group from the database.
duplicate_group()  : void
Duplicate a filter group.
get_filters()  : void
Get filters from the database ready for display in the list table.
get_group()  : void
Get details about a given group.
get_groups()  : void
Get filter group from the database.
get_terms_taxonomies()  : void
Get the list of taxonomies and attributes available for products.
register()  : void
Hook into WP
save_filter()  : void
Create or save an existing filter.
save_group()  : void
Save or create a group in the database.
save_priority()  : void
Save the priority of groups.
send_error()  : void
Send a json error back to the react app.
validate_custom_fields_settings()  : array<string|int, mixed>
Validate settings of custom fields.
all_keys_are_matching()  : bool
Check if the group filters have changed.
create_or_update_filter()  : Filter
Create or update a filter.
did_group_name_change()  : bool
Determine if the group name has changed.
filters_are_identical()  : bool
Check if the group filters are identical.
fix_filter_ids()  : void
Navigate through the filters and fix the "filter_id" property inside the options array but only if "filter_id" exists.
fix_parent_filter_ids()  : void
Navigate through the filters and fix the "parent_filter" column but only if the "parent_filter" is different than 0.
get_filter_data_source()  : string
Format the data source of an attribute filter.
has_attributes_filter()  : bool
Check if the array of filters has an attribute filter.
has_unique_sources()  : bool|WP_Error
Determine if the collection of filters has filters that are sharing the same data source or in the case of attributes, determine if there's any conflict.
maybe_adjust_filter_by()  : string
Adjust the filter_by option based on the filter mode.
maybe_attach_children()  : Collection
When creating a group detect whether or not child filters should be attached too.
maybe_attach_taxonomy_setting()  : Collection
Attach a "taxonomy" setting if the filter_by option starts with "tax_".
parse_group_filters_to_verification_array()  : array<string|int, mixed>
Parse the group filters to an array that can be used for verification.
validate_filter_settings()  : void
Validate various settings about a given filter.
were_there_any_group_changes()  : bool
Check if there were any changes to the group.

Methods

create_group()

Create a group in the database.

public create_group() : void

Used by the modal form on the add/Edit filter page.

Return values
void

delete_filter()

Delete a filter from the database.

public delete_filter() : void
Return values
void

delete_group()

Delete a group from the database.

public delete_group() : void
Return values
void

duplicate_group()

Duplicate a filter group.

public duplicate_group() : void
Return values
void

get_filters()

Get filters from the database ready for display in the list table.

public get_filters() : void

Load groups too.

Return values
void

get_group()

Get details about a given group.

public get_group() : void
Return values
void

get_groups()

Get filter group from the database.

public get_groups() : void
Return values
void

get_terms_taxonomies()

Get the list of taxonomies and attributes available for products.

public get_terms_taxonomies() : void
Return values
void

register()

Hook into WP

public register() : void
Return values
void

save_filter()

Create or save an existing filter.

public save_filter() : void
Return values
void

save_group()

Save or create a group in the database.

public save_group() : void
Return values
void

save_priority()

Save the priority of groups.

public save_priority() : void
Return values
void

send_error()

Send a json error back to the react app.

public send_error(string $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
$message : string
$context : array<string|int, mixed> = []

Any additional context to pass to the error message.

Return values
void

validate_custom_fields_settings()

Validate settings of custom fields.

public validate_custom_fields_settings(array<string|int, mixed> $filters) : array<string|int, mixed>
Parameters
$filters : array<string|int, mixed>
Return values
array<string|int, mixed>

all_keys_are_matching()

Check if the group filters have changed.

private all_keys_are_matching(array<string|int, mixed> $current_filters, array<string|int, mixed> $new_filters) : bool

Compare the values of the current filters with the new ones and return true if they have changed.

Parameters
$current_filters : array<string|int, mixed>
$new_filters : array<string|int, mixed>
Return values
bool

create_or_update_filter()

Create or update a filter.

private create_or_update_filter(array<string|int, mixed> $filter, string|int $group_id, int $priority) : Filter
Parameters
$filter : array<string|int, mixed>
$group_id : string|int
$priority : int
Return values
Filter

did_group_name_change()

Determine if the group name has changed.

private did_group_name_change(int $group_id, string $new_name) : bool
Parameters
$group_id : int
$new_name : string
Return values
bool

filters_are_identical()

Check if the group filters are identical.

private filters_are_identical(array<string|int, mixed> $current_filters, array<string|int, mixed> $new_filters) : bool

Compare the values of the current filters with the new ones and return true if they are identical.

Parameters
$current_filters : array<string|int, mixed>
$new_filters : array<string|int, mixed>
Return values
bool

fix_filter_ids()

Navigate through the filters and fix the "filter_id" property inside the options array but only if "filter_id" exists.

private fix_filter_ids(Group $group) : void

The new filter_id is the one of the newly created filter.

This is needed because when duplicating a group, the filters are duplicated too but the filter_id is not updated.

Parameters
$group : Group
Return values
void

fix_parent_filter_ids()

Navigate through the filters and fix the "parent_filter" column but only if the "parent_filter" is different than 0.

private fix_parent_filter_ids(Group $group) : void

To retrieve the new parent_filter we need to query the database and get the new filter_id of the filter in the group that has the option "attributes_mode" set to "all".

Parameters
$group : Group
Return values
void

get_filter_data_source()

Format the data source of an attribute filter.

private get_filter_data_source(Filter $filter) : string

Used internally to check for dupes.

Parameters
$filter : Filter
Return values
string

has_attributes_filter()

Check if the array of filters has an attribute filter.

private has_attributes_filter(array<string|int, mixed> $filters) : bool

The structure of the array is parsed via the parse_group_filters_to_verification_array() method.

We check if the "filter_by" key is "attributes" and if a "attributes_mode" option is set to "all".

Parameters
$filters : array<string|int, mixed>
Return values
bool

has_unique_sources()

Determine if the collection of filters has filters that are sharing the same data source or in the case of attributes, determine if there's any conflict.

private has_unique_sources(Collection $filters) : bool|WP_Error
Parameters
$filters : Collection
Return values
bool|WP_Error

maybe_adjust_filter_by()

Adjust the filter_by option based on the filter mode.

private maybe_adjust_filter_by(Collection $options, string $filter_by) : string
Parameters
$options : Collection

The filter options.

$filter_by : string

The filter_by option.

Return values
string

The filter_by option.

maybe_attach_children()

When creating a group detect whether or not child filters should be attached too.

private maybe_attach_children(Collection $filters) : Collection

How it works: Detects the "all" attribute type of filter and queries the child filters once found, push each child filter right after the parent attribute place into the array so that when the parent attribute is moved around the children follow the same exact position and respect the priority.

Parameters
$filters : Collection
Return values
Collection

maybe_attach_taxonomy_setting()

Attach a "taxonomy" setting if the filter_by option starts with "tax_".

private maybe_attach_taxonomy_setting(Collection $options) : Collection
Parameters
$options : Collection

The filter options.

Return values
Collection

The filter options.

parse_group_filters_to_verification_array()

Parse the group filters to an array that can be used for verification.

private parse_group_filters_to_verification_array(array<string|int, mixed> $filters) : array<string|int, mixed>

The verification array is used to check if the group filters have changed.

Parameters
$filters : array<string|int, mixed>
Return values
array<string|int, mixed>

validate_filter_settings()

Validate various settings about a given filter.

private validate_filter_settings(array<string|int, mixed> &$filter, int $index) : void
Parameters
$filter : array<string|int, mixed>
$index : int
Return values
void

were_there_any_group_changes()

Check if there were any changes to the group.

private were_there_any_group_changes(int $group_id, string $new_name, array<string|int, mixed> $new_filters) : bool
Parameters
$group_id : int
$new_name : string
$new_filters : array<string|int, mixed>
Return values
bool

Search results