Add: Suport author to marker

This commit is contained in:
Luca 2023-01-09 17:48:09 +01:00
parent ba9eebe2fa
commit ad8d0b610c

View File

@ -385,6 +385,8 @@ if (!class_exists('Soundmap')){
add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts')); add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
add_action('init', array($this,'add_feed')); add_action('init', array($this,'add_feed'));
add_action('init', array($this,'add_author_support_to_posts'));
//AJAX ACTIONS //AJAX ACTIONS
add_action('wp_ajax_soundmap_JSON_load_markers',array($this, 'JSON_load_markers')); add_action('wp_ajax_soundmap_JSON_load_markers',array($this, 'JSON_load_markers'));
add_action('wp_ajax_nopriv_soundmap_JSON_load_markers',array($this, 'JSON_load_markers')); add_action('wp_ajax_nopriv_soundmap_JSON_load_markers',array($this, 'JSON_load_markers'));
@ -439,6 +441,8 @@ if (!class_exists('Soundmap')){
}); });
function soundmap_save_term_translation($request) { function soundmap_save_term_translation($request) {
$taxonomy=$request->get_param('taxonomy'); $taxonomy=$request->get_param('taxonomy');
@ -452,23 +456,39 @@ if (!class_exists('Soundmap')){
$termB = $termA."-es"; $termB = $termA."-es";
$termC = $termA."-en"; $termC = $termA."-en";
if ( term_exists($termA) && term_exists($termB) && term_exists($termC) ) : $translation = [];
if (term_exists($termA)) :
pll_set_term_language(term_exists($termA), 'eu'); pll_set_term_language(term_exists($termA), 'eu');
pll_set_term_language(term_exists($termB), 'es'); $translation['eu']=term_exists($termA);
pll_set_term_language(term_exists($termC), 'en'); endif;
$translation = array( if (term_exists($termB)) :
'eu' => term_exists($termA), pll_set_term_language(term_exists($termB), 'es');
'es' => term_exists($termB), $translation['es']=term_exists($termB);
'en' => term_exists($termC) endif;
);
if (term_exists($termC)) :
pll_set_term_language(term_exists($termC), 'en');
$translation['en']=term_exists($termC);
endif;
pll_save_term_translations($translation); pll_save_term_translations($translation);
$response = true; $response = true;
endif; // if ( term_exists($termA) && term_exists($termB) && term_exists($termC) ) :
//
// $translation = array(
// 'eu' => term_exists($termA),
// 'es' => term_exists($termB),
// 'en' => term_exists($termC)
// );
//
//
// $response = true;
//
// endif;
endif; endif;
@ -483,11 +503,10 @@ if (!class_exists('Soundmap')){
function soundmap_save_post_translation($request) { function soundmap_save_post_translation($request) {
// http://docker:8089/wp-json/soundmap/translate/post?postA=43688&langA=es&postB=12707&langB=eu // http://docker:8089/wp-json/soundmap/translate/post?postA=43688&langA=es&postB=12707&langB=eu
// http://docker:8089/wp-json/soundmap/translate/post?postA=jentilarrian-txalaparta&langA=eu
$postA=$request->get_param('postA'); // slug $postA=$request->get_param('postA'); // slug
$langA=$request->get_param('langA'); // locale $langA=$request->get_param('langA'); // locale
//$postB=$request->get_param('postB');
//$langB=$request->get_param('langB');
$response = false; $response = false;
@ -498,20 +517,22 @@ if (!class_exists('Soundmap')){
$pC = get_page_by_path( $postA."-en", OBJECT, 'marker' ); $pC = get_page_by_path( $postA."-en", OBJECT, 'marker' );
//return new WP_REST_Response(get_page_by_path( "lesaka-ekaitz-elektromagnetikoa-es", OBJECT, 'marker' )); //return new WP_REST_Response(get_page_by_path( "lesaka-ekaitz-elektromagnetikoa-es", OBJECT, 'marker' ));
$translation = [];
if ( $pA && $pB && $pC ) : if ( $pA ) :
pll_set_post_language($pA->ID, 'eu'); pll_set_post_language($pA->ID, 'eu');
pll_set_post_language($pB->ID, 'es'); $translation['eu']=$pA->ID;
pll_set_post_language($pC->ID, 'en'); endif;
$translation = array( if ( $pB ) :
'eu' => $pA->ID, pll_set_post_language($pB->ID, 'es');
'es' => $pB->ID, $translation['es']=$pB->ID;
'en' => $pC->ID endif;
);
if ( $pC ) :
pll_set_post_language($pC->ID, 'en');
$translation['en']=$pC->ID;
endif;
pll_save_post_translations($translation); pll_save_post_translations($translation);
@ -519,8 +540,6 @@ if (!class_exists('Soundmap')){
endif; endif;
endif;
return new WP_REST_Response($response); return new WP_REST_Response($response);
} }
@ -553,6 +572,9 @@ if (!class_exists('Soundmap')){
} }
function add_author_support_to_posts() {
add_post_type_support( 'marker', 'author' );
}
function add_feed(){ function add_feed(){
global $wp_rewrite; global $wp_rewrite;