From 45d8b1d6c184d3f0c1cde33398e7f646b2d9ecaf Mon Sep 17 00:00:00 2001 From: Glomberg Date: Mon, 28 Sep 2026 15:26:19 +0300 Subject: [PATCH 1/5] Fix. Contacts encoder. Shortcodes processing fixed. --- .../ContactsEncoder/Shortcodes/ExcludedEncodeContentSC.php | 4 +++- .../ContactsEncoder/Shortcodes/ShortCodesService.php | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/Cleantalk/ApbctWP/ContactsEncoder/Shortcodes/ExcludedEncodeContentSC.php b/lib/Cleantalk/ApbctWP/ContactsEncoder/Shortcodes/ExcludedEncodeContentSC.php index 511ebd99a..339510da7 100644 --- a/lib/Cleantalk/ApbctWP/ContactsEncoder/Shortcodes/ExcludedEncodeContentSC.php +++ b/lib/Cleantalk/ApbctWP/ContactsEncoder/Shortcodes/ExcludedEncodeContentSC.php @@ -664,7 +664,9 @@ protected function stripProtectedContactsFromPlainText($text, array $contacts) */ public function primeRawTitleCache() { - if ( is_admin() ) { + global $apbct; + + if ( is_admin() || empty($apbct->settings['data__email_decoder']) ) { return; } diff --git a/lib/Cleantalk/ApbctWP/ContactsEncoder/Shortcodes/ShortCodesService.php b/lib/Cleantalk/ApbctWP/ContactsEncoder/Shortcodes/ShortCodesService.php index 7dbdd82c5..2d0efee55 100644 --- a/lib/Cleantalk/ApbctWP/ContactsEncoder/Shortcodes/ShortCodesService.php +++ b/lib/Cleantalk/ApbctWP/ContactsEncoder/Shortcodes/ShortCodesService.php @@ -49,12 +49,16 @@ private function registerRenderBlockNestingHooks() */ public function registerTitleFilters() { + global $apbct; + add_filter('the_title', array($this->shortcode_to_exclude, 'filterTheTitle'), 1000, 2); add_filter('single_post_title', array($this->shortcode_to_exclude, 'filterSinglePostTitle'), 20, 2); add_filter('document_title_parts', array($this->shortcode_to_exclude, 'filterDocumentTitleParts'), 20); add_filter('nav_menu_item_title', array($this->shortcode_to_exclude, 'filterNavMenuItemTitle'), 20, 2); add_filter('wp_insert_post_data', array($this->shortcode_to_exclude, 'filterPostDataForSlug'), 10, 2); - add_action('init', array($this->shortcode_to_exclude, 'primeRawTitleCache'), 1); + if ( ! empty($apbct->settings['data__email_decoder']) ) { + add_action('init', array($this->shortcode_to_exclude, 'primeRawTitleCache'), 1); + } add_filter('render_block', array($this->shortcode_to_exclude, 'restoreEncodedBlockTitlesFilter'), 1000, 3); add_filter('render_block_core/page-list', array($this->shortcode_to_exclude, 'restoreEncodedBlockTitlesFilter'), 1000, 3); add_filter('render_block_core/navigation', array($this->shortcode_to_exclude, 'restoreEncodedBlockTitlesFilter'), 1000, 3); From 7679a3b86f44f3e52ec5bf59b4e6a07acbc15e99 Mon Sep 17 00:00:00 2001 From: Glomberg Date: Tue, 29 Sep 2026 11:56:40 +0300 Subject: [PATCH 2/5] Fix. Contacts encoder. Shortcodes for exclusions optimized. --- .../Shortcodes/ExcludedEncodeContentSC.php | 38 +------------------ .../Shortcodes/ShortCodesService.php | 3 -- 2 files changed, 2 insertions(+), 39 deletions(-) diff --git a/lib/Cleantalk/ApbctWP/ContactsEncoder/Shortcodes/ExcludedEncodeContentSC.php b/lib/Cleantalk/ApbctWP/ContactsEncoder/Shortcodes/ExcludedEncodeContentSC.php index 339510da7..72e5ee0a8 100644 --- a/lib/Cleantalk/ApbctWP/ContactsEncoder/Shortcodes/ExcludedEncodeContentSC.php +++ b/lib/Cleantalk/ApbctWP/ContactsEncoder/Shortcodes/ExcludedEncodeContentSC.php @@ -656,42 +656,6 @@ protected function stripProtectedContactsFromPlainText($text, array $contacts) return $text; } - /** - * Cache titles with skip-encoding shortcodes before frontend encoding mutates post objects. - * - * @return void - * @psalm-suppress PossiblyUnusedMethod - */ - public function primeRawTitleCache() - { - global $apbct; - - if ( is_admin() || empty($apbct->settings['data__email_decoder']) ) { - return; - } - - global $wpdb; - - $rows = $wpdb->get_results( - "SELECT ID, post_title FROM {$wpdb->posts} WHERE post_status = 'publish' AND post_title LIKE '%[apbct_skip_encoding]%'", - OBJECT_K - ); - - if ( ! is_array($rows) ) { - return; - } - - foreach ( $rows as $post_id => $row ) { - if ( - isset($row->post_title) - && is_string($row->post_title) - && strpos($row->post_title, 'apbct-email-encoder') === false - ) { - self::$raw_titles_cache[(int)$post_id] = $row->post_title; - } - } - } - /** * Return raw title from init-time prime cache when this post is known to use skip-encoding. * @@ -729,6 +693,7 @@ protected function getRawPostTitle($post_id) return ''; } + // Search in cached $primed_title = $this->getPrimedRawPostTitle($post_id); if ( $primed_title !== '' ) { return $primed_title; @@ -748,6 +713,7 @@ protected function getRawPostTitle($post_id) } if ( strpos($title, 'apbct-email-encoder') === false ) { + // Set cache self::$raw_titles_cache[$post_id] = $title; } diff --git a/lib/Cleantalk/ApbctWP/ContactsEncoder/Shortcodes/ShortCodesService.php b/lib/Cleantalk/ApbctWP/ContactsEncoder/Shortcodes/ShortCodesService.php index 2d0efee55..ac637c7aa 100644 --- a/lib/Cleantalk/ApbctWP/ContactsEncoder/Shortcodes/ShortCodesService.php +++ b/lib/Cleantalk/ApbctWP/ContactsEncoder/Shortcodes/ShortCodesService.php @@ -56,9 +56,6 @@ public function registerTitleFilters() add_filter('document_title_parts', array($this->shortcode_to_exclude, 'filterDocumentTitleParts'), 20); add_filter('nav_menu_item_title', array($this->shortcode_to_exclude, 'filterNavMenuItemTitle'), 20, 2); add_filter('wp_insert_post_data', array($this->shortcode_to_exclude, 'filterPostDataForSlug'), 10, 2); - if ( ! empty($apbct->settings['data__email_decoder']) ) { - add_action('init', array($this->shortcode_to_exclude, 'primeRawTitleCache'), 1); - } add_filter('render_block', array($this->shortcode_to_exclude, 'restoreEncodedBlockTitlesFilter'), 1000, 3); add_filter('render_block_core/page-list', array($this->shortcode_to_exclude, 'restoreEncodedBlockTitlesFilter'), 1000, 3); add_filter('render_block_core/navigation', array($this->shortcode_to_exclude, 'restoreEncodedBlockTitlesFilter'), 1000, 3); From 5d74051d9026dd2c061e71e206c789e9fc630fc3 Mon Sep 17 00:00:00 2001 From: Glomberg Date: Tue, 29 Sep 2026 12:01:24 +0300 Subject: [PATCH 3/5] Dev. Code. Unused variable removed. --- .../ApbctWP/ContactsEncoder/Shortcodes/ShortCodesService.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/Cleantalk/ApbctWP/ContactsEncoder/Shortcodes/ShortCodesService.php b/lib/Cleantalk/ApbctWP/ContactsEncoder/Shortcodes/ShortCodesService.php index ac637c7aa..b60bd5b7d 100644 --- a/lib/Cleantalk/ApbctWP/ContactsEncoder/Shortcodes/ShortCodesService.php +++ b/lib/Cleantalk/ApbctWP/ContactsEncoder/Shortcodes/ShortCodesService.php @@ -49,8 +49,6 @@ private function registerRenderBlockNestingHooks() */ public function registerTitleFilters() { - global $apbct; - add_filter('the_title', array($this->shortcode_to_exclude, 'filterTheTitle'), 1000, 2); add_filter('single_post_title', array($this->shortcode_to_exclude, 'filterSinglePostTitle'), 20, 2); add_filter('document_title_parts', array($this->shortcode_to_exclude, 'filterDocumentTitleParts'), 20); From e557de69888d641f8e303b81affc7a989bdc555f Mon Sep 17 00:00:00 2001 From: Glomberg Date: Tue, 29 Sep 2026 12:26:55 +0300 Subject: [PATCH 4/5] Fix. Contact encoder. Shortcode for skip encoding fixed. --- .../Shortcodes/ExcludedEncodeContentSC.php | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/lib/Cleantalk/ApbctWP/ContactsEncoder/Shortcodes/ExcludedEncodeContentSC.php b/lib/Cleantalk/ApbctWP/ContactsEncoder/Shortcodes/ExcludedEncodeContentSC.php index 72e5ee0a8..8eadcda79 100644 --- a/lib/Cleantalk/ApbctWP/ContactsEncoder/Shortcodes/ExcludedEncodeContentSC.php +++ b/lib/Cleantalk/ApbctWP/ContactsEncoder/Shortcodes/ExcludedEncodeContentSC.php @@ -395,10 +395,7 @@ function ($matches) { return $matches[0]; } - $title = $this->getPrimedRawPostTitle($post_id); - if ( $title === '' ) { - $title = $this->getRawPostTitle($post_id); - } + $title = $this->getRawPostTitle($post_id); if ( ! is_string($title) || $title === '' || strpos($title, '[apbct_skip_encoding]') === false ) { return $matches[0]; @@ -485,15 +482,12 @@ protected function restorePostTitleInHtml($content, $_parsed_block = array(), $b if ( strpos($content, '[apbct_skip_encoding]') === false && strpos($content, 'apbct-email-encoder') === false - && $this->getPrimedRawPostTitle($post_id) === '' + && $this->getRawPostTitle($post_id) === '' ) { return $content; } - $title = $this->getPrimedRawPostTitle($post_id); - if ( $title === '' ) { - $title = $this->getRawPostTitle($post_id); - } + $title = $this->getRawPostTitle($post_id); if ( $title === '' || strpos($title, '[apbct_skip_encoding]') === false ) { return $content; @@ -809,15 +803,12 @@ protected function restoreDocumentTitleInHtml($content) strpos($content, '[apbct_skip_encoding]') === false && strpos($content, 'apbct-email-encoder') === false && strpos($content, '%%APBCT_SHORT_CODE_SKIP') === false - && $this->getPrimedRawPostTitle($post_id) === '' + && $this->getRawPostTitle($post_id) === '' ) { return $content; } - $raw_title = $this->getPrimedRawPostTitle($post_id); - if ( $raw_title === '' ) { - $raw_title = $this->getRawPostTitle($post_id); - } + $raw_title = $this->getRawPostTitle($post_id); if ( $raw_title === '' || strpos($raw_title, '[apbct_skip_encoding]') === false ) { return $content; @@ -933,7 +924,7 @@ public function filterTheTitle($title, $post_id = 0) return $title; } - $raw_title = $this->getPrimedRawPostTitle($post_id); + $raw_title = $post_id ? $this->getRawPostTitle($post_id) : $title; if ( $raw_title === '' || strpos($raw_title, '[apbct_skip_encoding]') === false ) { return $title; } @@ -955,7 +946,11 @@ public function filterTheTitle($title, $post_id = 0) public function filterSinglePostTitle($title, $_post) { $post_id = is_object($_post) && isset($_post->ID) ? (int)$_post->ID : 0; - $raw_title = $post_id ? $this->getPrimedRawPostTitle($post_id) : $title; + if ( ! $post_id && is_singular() ) { + $post_id = (int)get_queried_object_id(); + } + + $raw_title = $post_id ? $this->getRawPostTitle($post_id) : $title; if ( $raw_title === '' || strpos($raw_title, '[apbct_skip_encoding]') === false ) { return $title; @@ -984,7 +979,7 @@ public function filterDocumentTitleParts($parts) $title = $parts['title']; if ( $post_id ) { - $raw_title = $this->getPrimedRawPostTitle($post_id); + $raw_title = $this->getRawPostTitle($post_id); if ( $raw_title !== '' && strpos($raw_title, '[apbct_skip_encoding]') !== false ) { $title = $raw_title; } @@ -1020,7 +1015,7 @@ public function filterNavMenuItemTitle($title, $menu_item) } if ( $post_id ) { - $raw_title = $this->getPrimedRawPostTitle($post_id); + $raw_title = $this->getRawPostTitle($post_id); if ( $raw_title !== '' && strpos($raw_title, '[apbct_skip_encoding]') !== false ) { if ( $this->isBufferMode() ) { return $this->prepareTitleForBufferMode($raw_title); From 4b4909b15169d9f93386d016bfe3e22d4943f68e Mon Sep 17 00:00:00 2001 From: Glomberg Date: Tue, 29 Sep 2026 12:27:51 +0300 Subject: [PATCH 5/5] Dev. Code. Comments typo fixed. --- .../ContactsEncoder/Shortcodes/ExcludedEncodeContentSC.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Cleantalk/ApbctWP/ContactsEncoder/Shortcodes/ExcludedEncodeContentSC.php b/lib/Cleantalk/ApbctWP/ContactsEncoder/Shortcodes/ExcludedEncodeContentSC.php index 8eadcda79..f09b12e7b 100644 --- a/lib/Cleantalk/ApbctWP/ContactsEncoder/Shortcodes/ExcludedEncodeContentSC.php +++ b/lib/Cleantalk/ApbctWP/ContactsEncoder/Shortcodes/ExcludedEncodeContentSC.php @@ -687,7 +687,7 @@ protected function getRawPostTitle($post_id) return ''; } - // Search in cached + // Search the cache. $primed_title = $this->getPrimedRawPostTitle($post_id); if ( $primed_title !== '' ) { return $primed_title; @@ -707,7 +707,7 @@ protected function getRawPostTitle($post_id) } if ( strpos($title, 'apbct-email-encoder') === false ) { - // Set cache + // Set the cache. self::$raw_titles_cache[$post_id] = $title; }