From dfdf12a62ab0968000dcdd196a78bfe6543e5d02 Mon Sep 17 00:00:00 2001 From: Keith Solomon Date: Fri, 9 Jan 2026 08:41:36 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20Add=20array=20position=20?= =?UTF-8?q?helper=20function=20for=20custom=20excerpt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/helpers.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/helpers.php b/lib/helpers.php index a1a5f75..be9223f 100644 --- a/lib/helpers.php +++ b/lib/helpers.php @@ -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. *