Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -656,40 +650,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()
{
if ( is_admin() ) {
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.
*
Expand Down Expand Up @@ -727,6 +687,7 @@ protected function getRawPostTitle($post_id)
return '';
}

// Search the cache.
$primed_title = $this->getPrimedRawPostTitle($post_id);
if ( $primed_title !== '' ) {
return $primed_title;
Expand All @@ -746,6 +707,7 @@ protected function getRawPostTitle($post_id)
}

if ( strpos($title, 'apbct-email-encoder') === false ) {
// Set the cache.
self::$raw_titles_cache[$post_id] = $title;
}

Expand Down Expand Up @@ -841,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;
Expand Down Expand Up @@ -965,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;
Comment thread
Glomberg marked this conversation as resolved.
if ( $raw_title === '' || strpos($raw_title, '[apbct_skip_encoding]') === false ) {
return $title;
}
Expand All @@ -987,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;
Expand Down Expand Up @@ -1016,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;
}
Expand Down Expand Up @@ -1052,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,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);
add_action('init', array($this->shortcode_to_exclude, 'primeRawTitleCache'), 1);
add_filter('render_block', array($this->shortcode_to_exclude, 'restoreEncodedBlockTitlesFilter'), 1000, 3);
Comment thread
Glomberg marked this conversation as resolved.
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);
Expand Down
Loading