🐞 fix: Add array position helper function for custom excerpt

This commit is contained in:
Keith Solomon
2026-01-09 08:41:36 -06:00
parent 2ae983108c
commit dfdf12a62a

View File

@@ -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.
*