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 = ... );
| Type | Name | Description |
|---|---|---|
bool | $daily | Daily flag. |
clean_terms() static
Clean search string from XSS exploits.
Since: 3.3.0
Line: 56
static public function clean_terms( $val ): string;
| Type | Name | Description |
|---|---|---|
string | $val | Potentially 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;
| Type | Name | Description |
|---|---|---|
string | $chars | Chars that can be used. |
int | $len | Length 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;
| Type | Name | Description |
|---|---|---|
string | $message | String to be censored. |
array | $badwords | Array of badwords. |
string | $censor_char | String which replaces bad words. If it’s more than 1-char long, a random string will be generated from these chars. Default: ’*’. |
bool | $whole_words | Filter 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;
| Type | Name | Description |
|---|---|---|
string | $color | Hexadecimal 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;
| Type | Name | Description |
|---|---|---|
int|string|array | $r | Red colour or array of RGB values. |
int|string | $g | (default: -1) Green colour. |
int|string | $b | (default: -1) Blue colour. |
bool | $padhash | Pad # 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;
| Type | Name | Description |
|---|---|---|
string | $time | A date/time string. |
int | $daily_range | Daily 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;
| Type | Name | Description |
|---|---|---|
float | $number | The number to convert based on locale. |
int | $decimals | Optional. 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;
| Type | Name | Description |
|---|---|---|
array | $input_array | Input string. |
string | $delimiter | Delimiter. |
string | $enclosure | Enclosure. |
string | $terminator | Terminating string. |
Returns: string — CSV string.
get_credit_link() static
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;
| Type | Name | Description |
|---|---|---|
string | $content | The HTML content to process. |
string|array | $terms | Single 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;
| Type | Name | Description |
|---|---|---|
float | $score | Score for the search result. |
float | $topscore | Score 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;
| Type | Name | Description |
|---|---|---|
array|string | $words | Array of words whose location needs to be extracted, or a single word. |
string | $fulltext | Text 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;
| Type | Name | Description |
|---|---|---|
array | $locations | Array of locations. |
int | $padding_before | Number 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;
| Type | Name | Description |
|---|---|---|
array|string | $words | Array of words used to determine the relevant excerpt, or a single word. |
string | $fulltext | Full text to search for the extract. |
string | $excerpt_more | What to append if $text needs to be trimmed. Default ’…’. |
int | $excerpt_length | Excerpt length in characters. |
int | $padding_before | Number 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;
| Type | Name | Description |
|---|---|---|
string|array | $subject | The string or an array with strings to search and replace. |
string|array | $search | Optional. The pattern to search for. It can be either a string or an array with strings. |
string|array | $replace | Optional. 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;
| Type | Name | Description |
|---|---|---|
array | $query_vars | Defined 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;
| Type | Name | Description |
|---|---|---|
array | $args | Array 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;
| Type | Name | Description |
|---|---|---|
int|\WP_Post | $post | Post ID or WP_Post object. |
string | $term | Term name. |
bool | $return_all | Whether to return all terms. |
bool | $return_first | Whether 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.