Recent

Helpers class

Helpers

Admin Columns Class.

Namespace: WebberZone\Better_Search\Util
Since: 3.3.0
Source: includes/util/class-helpers.php line 21

Methods

__construct()

Constructor class.

Since: 3.3.0
Line: 28

public function __construct(  );

get_bsearch_table() static

Function to delete all rows in the posts table.

Since: 3.3.0
Line: 38

static public function get_bsearch_table( $daily = ... );
TypeNameDescription
bool$dailyDaily flag.

clean_terms() static

Clean search string from XSS exploits.

Since: 3.3.0
Line: 56

static public function clean_terms( $val ): string;
TypeNameDescription
string$valPotentially unclean string.

Returns: string — Cleaned string if successful or empty string on use of banned word

rand_censor() static

Generates a random string.

Since: 3.3.0
Line: 149

static public function rand_censor( $chars, $len ): string;
TypeNameDescription
string$charsChars that can be used.
int$lenLength of the output string.

Returns: string — Random string

censor_string() static

Apply censorship to $message, replacing $badwords with $censor_char.

Since: 3.3.0
Line: 171

static public function censor_string( $message, $badwords, $censor_char = ..., $whole_words = ... ): array;
TypeNameDescription
string$messageString to be censored.
array$badwordsArray of badwords.
string$censor_charString which replaces bad words. If it’s more than 1-char long, a random string will be generated from these chars. Default: ’*’.
bool$whole_wordsFilter whole worlds only.

Returns: array — Array containing the original string at orig and the censored string at clean.

html2rgb() static

Convert Hexadecimal colour code to RGB.

Since: 3.3.0
Line: 241

static public function html2rgb( $color ): array|bool;
TypeNameDescription
string$colorHexadecimal colour.

Returns: array|bool — Array containing RGB colour code or false if error.

rgb2html() static

Function to convert RGB color code to Hexadecimal.

Since: 1.3.4
Line: 282

static public function rgb2html( $r, $g = ..., $b = ..., $padhash = ... ): string;
TypeNameDescription
int|string|array$rRed colour or array of RGB values.
int|string$g(default: -1) Green colour.
int|string$b(default: -1) Blue colour.
bool$padhashPad # when returning.

Returns: string — HEX color code

get_from_date() static

Retrieve the from date for the query

Since: 3.3.0
Line: 316

static public function get_from_date( $time = ..., $daily_range = ... ): string;
TypeNameDescription
string$timeA date/time string.
int$daily_rangeDaily range.

Returns: string — From date

number_format_i18n() static

Convert float number to format based on the locale if number_format_count is true.

Since: 3.3.0
Line: 346

static public function number_format_i18n( $number, $decimals = ... ): string;
TypeNameDescription
float$numberThe number to convert based on locale.
int$decimalsOptional. Precision of the number of decimal places. Default 0.

Returns: string — Converted number in string format.

str_putcsv() static

Convert a string to CSV.

Since: 3.3.0
Line: 377

static public function str_putcsv( $input_array, $delimiter = ..., $enclosure = ..., $terminator = ... ): string;
TypeNameDescription
array$input_arrayInput string.
string$delimiterDelimiter.
string$enclosureEnclosure.
string$terminatorTerminating string.

Returns: string — CSV string.

Get the link to Better Search homepage.

Since: 3.3.0
Line: 430

static public function get_credit_link(  ): string;

Returns: string — HTML markup.

highlight() static

Highlights search terms in HTML content without affecting tags or attributes.

Since: 3.3.0
Line: 454

static public function highlight( $content, $terms ): string;
TypeNameDescription
string$contentThe HTML content to process.
string|array$termsSingle term, phrase, or array of terms/phrases to highlight.

Returns: string — The content with highlighted search terms.

score2percent() static

Function to convert the mySQL score to percentage.

Since: 3.3.0
Line: 592

static public function score2percent( $score, $topscore ): string;
TypeNameDescription
float$scoreScore for the search result.
float$topscoreScore for the most relevant search result.

Returns: string — Score converted to percentage

extract_locations() static

Find the locations of each of the words within the text.

Since: 3.3.0
Line: 622

static public function extract_locations( $words, $fulltext ): array;
TypeNameDescription
array|string$wordsArray of words whose location needs to be extracted, or a single word.
string$fulltextText to search the words in.

Returns: array

extract_start_position() static

Extract the start position of the relevant portion to display.

This is done by looping over each match and finding the smallest distance between two found strings. The idea being that the closer the terms are the better match the snippet would be. When checking for matches we only change the location if there is a better match. The only exception is where we have only two matches in which case we just take the first as will be equally distant.

Since: 3.3.0
Line: 670

static public function extract_start_position( $locations, $padding_before ): int;
TypeNameDescription
array$locationsArray of locations.
int$padding_beforeNumber of characters to include before the first match.

Returns: int — Starting position of the relevant extract.

extract_relevant_excerpt() static

Extract the relevant excerpt for a set of words.

Since: 3.3.0
Line: 709

static public function extract_relevant_excerpt( $words, $fulltext, $excerpt_more = ..., $excerpt_length = ..., $padding_before = ... ): string;
TypeNameDescription
array|string$wordsArray of words used to determine the relevant excerpt, or a single word.
string$fulltextFull text to search for the extract.
string$excerpt_moreWhat to append if $text needs to be trimmed. Default ’…’.
int$excerpt_lengthExcerpt length in characters.
int$padding_beforeNumber of characters to include before the first match.

Returns: string — Excerpt containing the relevant portion of of the text.

strip_stopwords() static

Strip stopwords from text.

Since: 4.2.0
Line: 750

static public function strip_stopwords( $subject = ..., $search = ..., $replace = ... ): string;
TypeNameDescription
string|array$subjectThe string or an array with strings to search and replace.
string|array$searchOptional. The pattern to search for. It can be either a string or an array with strings.
string|array$replaceOptional. The string to replace with. Default empty string.

Returns: string — Processed text with stopwords removed.

parse_wp_query_arguments() static

Parse WP_Query variables to parse comma separated list of IDs and convert them to arrays as needed by WP_Query.

Since: 4.0.0
Line: 780

static public function parse_wp_query_arguments( $query_vars ): array;
TypeNameDescription
array$query_varsDefined query variables.

Returns: array — Complete query variables with undefined ones filled in empty.

sanitize_args() static

Sanitize args.

Since: 4.1.1
Line: 817

static public function sanitize_args( $args ): array;
TypeNameDescription
array$argsArray of arguments.

Returns: array — Sanitized array of arguments.

get_primary_term() static

Get the primary term for a given post.

Since: 4.2.0
Line: 849

static public function get_primary_term( $post, $term = ..., $return_all = ..., $return_first = ... ): array;
TypeNameDescription
int|\WP_Post$postPost ID or WP_Post object.
string$termTerm name.
bool$return_allWhether to return all terms.
bool$return_firstWhether to return the first term.

Returns: array — Primary term object at primary and array of term

get_database_compatibility_message() static

Get a message about MySQL/MariaDB compatibility issues.

Since: 4.2.0
Line: 928

static public function get_database_compatibility_message(  ): string;

Returns: string — Message about compatibility or empty string if compatible.