| 1 |
<?php |
| 2 |
|
| 3 |
namespace YayMail\Integrations; |
| 4 |
|
| 5 |
use YayMail\PostTypes\TemplatePostType; |
| 6 |
use YayMail\Utils\SingletonTrait; |
| 7 |
|
| 8 |
/** |
| 9 |
* RankMath |
| 10 |
* * @method static RankMath get_instance() |
| 11 |
*/ |
| 12 |
class RankMath { |
| 13 |
use SingletonTrait; |
| 14 |
|
| 15 |
protected function __construct() { |
| 16 |
|
| 17 |
if ( ! class_exists( 'RankMath' ) ) { |
| 18 |
return; |
| 19 |
} |
| 20 |
|
| 21 |
add_filter( |
| 22 |
'rank_math/sitemap/exclude_post_type', |
| 23 |
function( $check, $post_type ) { |
| 24 |
if ( $post_type === TemplatePostType::POST_TYPE ) { |
| 25 |
return true; |
| 26 |
} |
| 27 |
return $check; |
| 28 |
}, |
| 29 |
10, |
| 30 |
2 |
| 31 |
); |
| 32 |
|
| 33 |
// Trick to delete all the duplicate value in the previous version of the plugin |
| 34 |
add_action( 'init', [ $this, 'init' ], PHP_INT_MAX ); |
| 35 |
} |
| 36 |
|
| 37 |
public function init() { |
| 38 |
$titles_settings = get_option( 'rank-math-options-titles', [] ); |
| 39 |
if ( empty( $titles_settings ) ) { |
| 40 |
return; |
| 41 |
} |
| 42 |
|
| 43 |
$title_meta_key = 'pt_' . TemplatePostType::POST_TYPE . '_robots'; |
| 44 |
|
| 45 |
if ( empty( $titles_settings[ $title_meta_key ] ) ) { |
| 46 |
$titles_settings[ $title_meta_key ] = []; |
| 47 |
} |
| 48 |
|
| 49 |
$titles_settings[ $title_meta_key ] = array_unique( $titles_settings[ $title_meta_key ] ); |
| 50 |
|
| 51 |
update_option( 'rank-math-options-titles', $titles_settings ); |
| 52 |
} |
| 53 |
} |
| 54 |
|