@@ -122,27 +122,57 @@ private function byPluginSetting($apbct)
122122 /**
123123 * Skip encoder run on hooks.
124124 *
125- * 1. Applies filter "apbct_hook_skip_email_encoder_on_url_list" to get modified list of URI chunks that needs to skip.
125+ * Applies filter "apbct_skip_email_encoder_on_uri_chunk_list" to get list of URI patterns to skip.
126+ * Each pattern can be:
127+ * - A simple string (e.g., 'details') - matched as substring
128+ * - A regex pattern (e.g., '^/$' for homepage) - matched as regex if contains special chars
129+ *
126130 * @return bool
127131 */
128132 private function byUrlOnHooks ()
129133 {
130- $ skip_encode = false ;
131- $ url_chunk_list = array ();
134+ $ url_patterns = apply_filters ('apbct_skip_email_encoder_on_uri_chunk_list ' , array ());
132135
133- // Apply filter "apbct_hook_skip_email_encoder_on_url_list" to get the URI chunk list.
134- $ url_chunk_list = apply_filters ('apbct_skip_email_encoder_on_uri_chunk_list ' , $ url_chunk_list );
136+ if (empty ($ url_patterns ) || !is_array ($ url_patterns )) {
137+ return false ;
138+ }
135139
136- if ( !empty ($ url_chunk_list ) && is_array ($ url_chunk_list ) ) {
137- foreach ($ url_chunk_list as $ chunk ) {
138- if (is_string ($ chunk ) && strpos (TT ::toString (Server::get ('REQUEST_URI ' )), $ chunk ) !== false ) {
139- $ skip_encode = true ;
140- break ;
141- }
140+ $ request_uri = TT ::toString (Server::get ('REQUEST_URI ' ));
141+
142+ foreach ($ url_patterns as $ pattern ) {
143+ if (is_string ($ pattern ) && $ this ->isUriMatchPattern ($ pattern , $ request_uri )) {
144+ return true ;
142145 }
143146 }
144147
145- return $ skip_encode ;
148+ return false ;
149+ }
150+
151+ /**
152+ * Check if URI matches the given pattern.
153+ *
154+ * @param string $pattern - simple string, special keyword or regex pattern
155+ * @param string $uri - REQUEST_URI to check
156+ * @return bool
157+ */
158+ private function isUriMatchPattern ($ pattern , $ uri )
159+ {
160+ // Special keyword for homepage
161+ if ($ pattern === '__HOME__ ' ) {
162+ return $ uri === '/ ' || $ uri === '' ;
163+ }
164+
165+ // Check if pattern contains regex special characters
166+ $ is_regex = (bool ) preg_match ('/[\^$.|?*+()\[\]{}]/ ' , $ pattern );
167+
168+ if (!$ is_regex ) {
169+ // Simple substring match (faster)
170+ return strpos ($ uri , $ pattern ) !== false ;
171+ }
172+
173+ // Regex match: escape delimiter
174+ $ safe_pattern = str_replace ('/ ' , '\/ ' , $ pattern );
175+ return (bool ) @preg_match ('/ ' . $ safe_pattern . '/u ' , $ uri );
146176 }
147177
148178 /**
0 commit comments