| 1 |
<?php |
| 2 |
/** |
| 3 |
* Builder Plugin Compatibility Code |
| 4 |
* |
| 5 |
* @package Themify_Builder |
| 6 |
* @subpackage Themify_Builder/classes |
| 7 |
*/ |
| 8 |
|
| 9 |
class Themify_Builder_Plugin_Compat_RankMath { |
| 10 |
|
| 11 |
static function init() { |
| 12 |
if(is_admin()){ |
| 13 |
add_filter( 'rank_math/video/content', [ __CLASS__, 'scan_builder_content' ], 10, 2 ); |
| 14 |
add_filter( 'rank_math/links/content', [ __CLASS__, 'scan_builder_content' ], 10, 2 ); |
| 15 |
add_filter( 'rank_math/metabox/values', [ __CLASS__, 'has_toc_filter' ] ); |
| 16 |
} |
| 17 |
add_filter( 'rank_math/sitemap/content_before_parse_html_images', array( __CLASS__, 'sitemap' ), 10, 2 ); |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* Themify Builder has built-in Table of Content support, let RankMath know |
| 22 |
*/ |
| 23 |
public static function has_toc_filter(array $values ):array { |
| 24 |
$values['assessor']['hasTOCPlugin'] = true; |
| 25 |
|
| 26 |
return $values; |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Fix the image counter in Rank Math site map. |
| 31 |
* |
| 32 |
* Append a plain text version of Builder output, before Rank Math |
| 33 |
* searches for images in the post content. |
| 34 |
*/ |
| 35 |
public static function sitemap(string $content,int $post_id ):string { |
| 36 |
$builder_data = ThemifyBuilder_Data_Manager::get_data( $post_id ); |
| 37 |
$plain_text = ThemifyBuilder_Data_Manager::_get_all_builder_text_content( $builder_data ); |
| 38 |
$plain_text = do_shortcode( $plain_text ); // render shortcodes that might be in the Themify_Builder_Component_Module::get_plain_text() |
| 39 |
|
| 40 |
return $content . $plain_text; |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Enable RankMath to scan Builder's contents |
| 45 |
*/ |
| 46 |
public static function scan_builder_content(string $content, int $object_id ):string { |
| 47 |
return $content . ' ' . Themify_Builder::render( $object_id ); |
| 48 |
} |
| 49 |
} |