<?php/*PluginName:YoastUpdaterAPIDescription:RESTAPIを使用してYoastSEOのメタデータを更新するプラグイン。Version:1.0Author:ここに名前を記載*/classYoastSEOControllerextendsWP_REST_Controller{publicfunctionregister_routes(){register_rest_route('wp/v2/','/yoast-meta/',array('methods'=>'POST','callback'=>[$this,'update_yoast_meta'],'permission_callback'=>function(){returncurrent_user_can('edit_posts');//投稿編集権限を確認},));}publicfunctionupdate_yoast_meta($request){$post_id=$request->get_param('postID');$meta_desc=$request->get_param('metaDesc');$focus_keyphrase=$request->get_param('focusKeyphrase');$seo_title=$request->get_param('seoTitle');if(!$post_id||!get_post($post_id)){returnnewWP_Error('invalid_post','Invalid or missing post ID',['status'=>400]);}$updated=[];if($meta_desc){update_post_meta($post_id,'_yoast_wpseo_metadesc',sanitize_text_field($meta_desc));$updated['meta_description']=$meta_desc;}if($focus_keyphrase){update_post_meta($post_id,'_yoast_wpseo_focuskw',sanitize_text_field($focus_keyphrase));$updated['focus_keyphrase']=$focus_keyphrase;}if($seo_title){update_post_meta($post_id,'_yoast_wpseo_title',sanitize_text_field($seo_title));$updated['seo_title']=$seo_title;}returnrest_ensure_response(['success'=>true,'updated_fields'=>$updated,]);}}functionregister_yoast_seo_controller(){$controller=newYoastSEOController();$controller->register_routes();}add_action('rest_api_init','register_yoast_seo_controller');