🐞 fix: Add array position helper function for custom excerpt
This commit is contained in:
@@ -164,6 +164,31 @@ function escEmbeds() {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the numeric position of the first occurrence of a needle in a haystack array.
|
||||
*
|
||||
* @param string $haystack The string to search in.
|
||||
* @param mixed $needles The array of strings to search for.
|
||||
* @param int $offset (Optional) The position to start the search from.
|
||||
* @return int|false The numeric position of the first occurrence of a needle in the haystack array.
|
||||
*/
|
||||
function strposArray( $haystack, $needles, $offset = 0 ) {
|
||||
if ( is_array( $needles ) ) {
|
||||
$positions = array();
|
||||
|
||||
foreach ( $needles as $str ) {
|
||||
$pos = strpos( $haystack, $str, $offset );
|
||||
|
||||
if ( $pos !== false ) {
|
||||
$positions[] = $pos; }
|
||||
}
|
||||
|
||||
return count( $positions ) ? min( $positions ) : false;
|
||||
} else {
|
||||
return strpos( $haystack, $needles, $offset );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a custom excerpt for the given text.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user