<?php
/*-----------------------------------------------*/
/*  EXTHEM.ES
/*  PREMIUM WORDRESS THEMES
/*
/*  STOP DON'T TRY EDIT
/*  IF YOU DON'T KNOW PHP 
/*
/*  As Errors In Your Themes
/*  Are Not The Responsibility
/*  Of The DEVELOPERS
/*  @EXTHEM.ES
/*  
/*  Follow Social Media Exthem.es
/*  Youtube : https://www.youtube.com/channel/UCpcZNXk6ySLtwRSBN6fVyLA
/*  Facebook : https://www.facebook.com/groups/exthem.es
/*  Twitter : https://x.com/bangreyblog
/*  Instagram : https://www.instagram.com/exthem.es/
/*  Telegram : https://t.me/exthemes_helps
/*  TikTok : https://www.tiktok.com/@exthemes
/* 	More Premium Themes Visit Now On https://exthem.es/
/*-----------------------------------------------*/
if ( ! defined( 'ABSPATH' ) ) exit; 
// Silence is golden.

if ( !empty($gets_data['GP_ID']) ) { 
	update_post_meta( $post_id, 'wp_GP_ID', $gets_data['GP_ID'] ); 
}

if ( !empty($gets_data['title_GP']) ) { 
	update_post_meta( $post_id, 'wp_title_GP', $gets_data['title_GP'] );
}

if ( !empty($gets_data['images_GP']) ) { 
	update_post_meta( $post_id, 'wp_images_GP', $gets_data['images_GP'] );
}

if ( !empty($gets_data['backgrounds_GP']) ) { 
	update_post_meta( $post_id, 'wp_backgrounds_GP', $gets_data['backgrounds_GP'] );
}

if ( !empty($gets_data['poster_GP']) ) {
	update_post_meta( $post_id, 'wp_poster_GP', $gets_data['poster_GP'] ); 
} else {
	update_post_meta( $post_id, 'wp_poster_GP', $gets_data['poster_sc'] );
}

if ( !empty($gets_data['youtube_GP']) ) { 
	update_post_meta( $post_id, 'wp_youtube_GP', $gets_data['youtube_GP'] );
}

if ( !empty($gets_data['paid_GP2']) ) { 
	wp_set_object_terms( $post_id, $gets_data['paid_GP2'], 'category', false );
} 

if ( !empty($gets_data['whatnews_GP']) ) { 
	update_post_meta( $post_id, 'wp_whatnews_GP', $gets_data['whatnews_GP'] );
}

if ( !empty($gets_data['installs_GP']) ) { 
	update_post_meta( $post_id, 'wp_installs_GP', $gets_data['installs_GP'] );
}

if ( !empty($gets_data['updates_GP']) ) { 
	update_post_meta( $post_id, 'wp_updates_GP', $gets_data['updates_GP'] );
}

if ( !empty($gets_data['numbervoters']) ) { 
	update_post_meta( $post_id, 'wp_ratings_GP', $gets_data['numbervoters'] );
}

if ( !empty($gets_data['numberrates']) ) { 
	update_post_meta( $post_id, 'wp_rated_GP', $gets_data['numberrates'] );
}

if ( !empty($gets_data['desck_GP']) ) { 
	update_post_meta( $post_id, 'wp_desck_GP', $gets_data['desck_GP'] );
} else {
	update_post_meta( $post_id, 'wp_desck_GP', $gets_data['summary_sc'] );
}

if ( !empty($gets_data['articlebody_GP']) ) { 
	update_post_meta( $post_id, 'wp_articlebody_GP', $gets_data['articlebody_GP'] );
}

if ( !empty($gets_data['developers_GP']) ) { 
	update_post_meta( $post_id, 'wp_developers_GP', str_replace(array('.', ',' ), ' ', $gets_data['developers_GP']) );
	wp_set_post_terms( $post_id, str_replace(array('.', ',' ), ' ', $gets_data['developers_GP']), 'developer' );
	wp_set_object_terms( $post_id, str_replace(array('.', ',' ), ' ', $gets_data['developers_GP']), 'developer', true ); 
}

//if ( !empty($gets_data['version_GP']) ) { 
//	update_post_meta( $post_id, 'wp_version_GP', $gets_data['version_GP'] );
//} else { 
//	update_post_meta( $post_id, 'wp_version_GP', $gets_data['version_sc'] ); 
//}

if ( !empty($gets_data['version_GP'] )) { 
	update_post_meta( $post_id, 'wp_version_GP', $gets_data['version_GP'] );
}

//if ( $gets_data['appversion'] ) { 
//	update_post_meta( $post_id, 'wp_version_GP', $gets_data['appversion'] );
//}

//	update_post_meta( $post_id, 'wp_version_GP', $gets_data['version_sc'] ); 

if ( !empty($gets_data['sizes_GP']) ) {
	update_post_meta( $post_id, 'wp_sizes_GP', $gets_data['sizes_GP'] );
	update_post_meta( $post_id, 'wp_sizes', $gets_data['sizes_GP'] );
}

if ( !empty($gets_data['requires_GP']) ) { 
	update_post_meta( $post_id, 'wp_requires_GP', $gets_data['requires_GP'] );
}

if ( !empty($gets_data['GP_ID']) ) { 
	update_post_meta( $post_id, 'wp_playstore_link', 'https://play.google.com/store/apps/details?id='.$gets_data['GP_ID'] ); 
}

if ( !empty($gets_data['tag']) ) { 
	wp_set_object_terms( $post_id, $gets_data['tag'], 'post_tag', true ); 
}
 
if ( !empty($gets_data['genres_GP']) ) { 
	//update_post_meta( $post_id, 'wp_genres_GP', $gets_data['genres_GP'] ); 
	//wp_set_object_terms( $post_id, $gets_data['genres_GP'], 'category', false );
} else {
	//update_post_meta( $post_id, 'wp_genres_GP', $gets_data['genre_sc'] ); 
	//wp_set_object_terms( $post_id, $gets_data['genre_sc'], 'category', false );
}

if ( !empty($gets_data['SubCategory']) ) { 
//	update_post_meta( $post_id, 'wp_genres_GP', $gets_data['genres_GP'] ); 
	//wp_set_object_terms( $post_id, $gets_data['SubCategory'], 'category', false );
} else {
//	update_post_meta( $post_id, 'wp_genres_GP', $gets_data['genre_sc'] ); 
	//wp_set_object_terms( $post_id, $gets_data['genre_sc'], 'category', false );
}


$parent_cat_name 	= $gets_data['p_category'];
$child_cat_name 	= $gets_data['genres_GP'];
$parent_cat_slug 	= $parent_cat_name;
$child_cat_slug 	= $child_cat_name;


$parent_category = get_term_by("slug", $parent_cat_slug, "category");

if ($parent_category) {
    $categories['parent_id'] = $parent_category->term_id;  
} else {
    $parent_id = wp_insert_term($parent_cat_name, "category", ['slug' => $parent_cat_slug]);
    if (!is_wp_error($parent_id)) {
	$categories['parent_id'] = $parent_id["term_id"];
    }
}
wp_set_object_terms( $post_id, array( $categories['parent_id'] ), 'category', true );

$child_category = get_term_by("slug", $child_cat_slug, "category");

if ($child_category) {
    $categories['child_id'] = $child_category->term_id;
} else {
    $child_id = wp_insert_term($child_cat_name, "category", ["parent" => $categories['parent_id'], "slug" => $child_cat_slug]);

    if (!is_wp_error($child_id)) {
	$categories['child_id'] = $child_id["term_id"];
    }
}
wp_set_object_terms( $post_id, array( $categories['child_id'] ), 'category', false );
