post_type === 'post') {
// Keywords meta box
add_meta_box(
'igny8_keywords',
__('IGNY8 Keywords', 'igny8-bridge'),
array($this, 'render_keywords_meta_box'),
'post',
'side',
'high'
);
// SEO meta box
add_meta_box(
'igny8_seo',
__('IGNY8 SEO', 'igny8-bridge'),
array($this, 'render_seo_meta_box'),
'post',
'normal',
'high'
);
// Sync data meta box (read-only info)
add_meta_box(
'igny8_sync_data',
__('IGNY8 Sync Data', 'igny8-bridge'),
array($this, 'render_sync_data_meta_box'),
'post',
'side',
'default'
);
}
}
/**
* Render Keywords meta box
*/
public function render_keywords_meta_box($post) {
wp_nonce_field('igny8_keywords_nonce', 'igny8_keywords_nonce');
$primary_keyword = get_post_meta($post->ID, '_igny8_primary_keyword', true);
$secondary_keywords = get_post_meta($post->ID, '_igny8_secondary_keywords', true);
// Convert comma-separated string to array for display
$secondary_keywords_array = !empty($secondary_keywords) ? explode(',', $secondary_keywords) : array();
?>
ID, '_igny8_meta_title', true);
$meta_description = get_post_meta($post->ID, '_igny8_meta_description', true);
?>
ID, '_igny8_content_id', true);
$task_id = get_post_meta($post->ID, '_igny8_task_id', true);
$last_sync = get_post_meta($post->ID, '_igny8_last_sync', true);
$cluster_id = get_post_meta($post->ID, '_igny8_cluster_id', true);
$sector_id = get_post_meta($post->ID, '_igny8_sector_id', true);
?>
post_type !== 'post') {
return;
}
// Check user permissions
if (!current_user_can('edit_post', $post_id)) {
return;
}
// Save keywords
if (isset($_POST['igny8_keywords_nonce']) && wp_verify_nonce($_POST['igny8_keywords_nonce'], 'igny8_keywords_nonce')) {
// Save primary keyword
if (isset($_POST['igny8_primary_keyword'])) {
$primary_keyword = sanitize_text_field($_POST['igny8_primary_keyword']);
update_post_meta($post_id, '_igny8_primary_keyword', $primary_keyword);
}
// Save secondary keywords
if (isset($_POST['igny8_secondary_keywords'])) {
$secondary_keywords_raw = sanitize_textarea_field($_POST['igny8_secondary_keywords']);
// Convert newlines to commas for storage
$secondary_keywords_array = array_filter(array_map('trim', explode("\n", $secondary_keywords_raw)));
$secondary_keywords = implode(',', $secondary_keywords_array);
update_post_meta($post_id, '_igny8_secondary_keywords', $secondary_keywords);
}
}
// Save SEO fields
if (isset($_POST['igny8_seo_nonce']) && wp_verify_nonce($_POST['igny8_seo_nonce'], 'igny8_seo_nonce')) {
// Save meta title
if (isset($_POST['igny8_meta_title'])) {
$meta_title = sanitize_text_field($_POST['igny8_meta_title']);
update_post_meta($post_id, '_igny8_meta_title', $meta_title);
// Also update for SEO plugins
$this->sync_seo_title($post_id, $meta_title);
}
// Save meta description
if (isset($_POST['igny8_meta_description'])) {
$meta_description = sanitize_textarea_field($_POST['igny8_meta_description']);
update_post_meta($post_id, '_igny8_meta_description', $meta_description);
// Also update for SEO plugins
$this->sync_seo_description($post_id, $meta_description);
}
}
}
/**
* Sync SEO title to popular SEO plugins
*/
private function sync_seo_title($post_id, $title) {
if (empty($title)) {
return;
}
// Yoast SEO
update_post_meta($post_id, '_yoast_wpseo_title', $title);
// Rank Math
update_post_meta($post_id, 'rank_math_title', $title);
// All in One SEO
update_post_meta($post_id, '_aioseo_title', $title);
}
/**
* Sync SEO description to popular SEO plugins
*/
private function sync_seo_description($post_id, $description) {
if (empty($description)) {
return;
}
// Yoast SEO
update_post_meta($post_id, '_yoast_wpseo_metadesc', $description);
// Rank Math
update_post_meta($post_id, 'rank_math_description', $description);
// All in One SEO
update_post_meta($post_id, '_aioseo_description', $description);
}
}
// Initialize
new IGNY8_Post_Meta_Boxes();