v2.0.0: add includes/Tools/SeoTools.php
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace AskTamMCP\Tools;
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
class SeoTools {
|
||||
public static function getSeoMeta(array $args): array {
|
||||
$id = (int)$args['post_id'];
|
||||
$data = ['post_id'=>$id];
|
||||
// Yoast
|
||||
if (defined('WPSEO_VERSION')) {
|
||||
$data['yoast'] = ['title'=>get_post_meta($id,'_yoast_wpseo_title',true),'description'=>get_post_meta($id,'_yoast_wpseo_metadesc',true),'focus_keyword'=>get_post_meta($id,'_yoast_wpseo_focuskw',true),'robots'=>get_post_meta($id,'_yoast_wpseo_meta-robots-noindex',true)];
|
||||
}
|
||||
// RankMath
|
||||
if (defined('RANK_MATH_VERSION')) {
|
||||
$data['rankmath'] = ['title'=>get_post_meta($id,'rank_math_title',true),'description'=>get_post_meta($id,'rank_math_description',true),'focus_keyword'=>get_post_meta($id,'rank_math_focus_keyword',true),'robots'=>get_post_meta($id,'rank_math_robots',true)];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
public static function updateSeoMeta(array $args): array {
|
||||
$id = (int)$args['post_id'];
|
||||
if (defined('WPSEO_VERSION')) {
|
||||
if (isset($args['title'])) update_post_meta($id,'_yoast_wpseo_title',$args['title']);
|
||||
if (isset($args['description'])) update_post_meta($id,'_yoast_wpseo_metadesc',$args['description']);
|
||||
if (isset($args['focus_keyword'])) update_post_meta($id,'_yoast_wpseo_focuskw',$args['focus_keyword']);
|
||||
}
|
||||
if (defined('RANK_MATH_VERSION')) {
|
||||
if (isset($args['title'])) update_post_meta($id,'rank_math_title',$args['title']);
|
||||
if (isset($args['description'])) update_post_meta($id,'rank_math_description',$args['description']);
|
||||
if (isset($args['focus_keyword'])) update_post_meta($id,'rank_math_focus_keyword',$args['focus_keyword']);
|
||||
}
|
||||
return ['post_id'=>$id,'updated'=>true];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user