Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amministrazione trasparente - Uncaught Error: Object of class WP_Error could not be converted to stringFornire un riepilogo generale del problema #485

Open
2 tasks done
emanueless opened this issue Oct 16, 2023 · 2 comments
Labels
bug Something isn't working wontfix This will not be worked on

Comments

@emanueless
Copy link

Prerequisiti

Descrivi il problema

La pagina dell' Amministrazione trasparente non si apre perché nella creazione dei link delle categorie e sottocategorie riceve anche dei dati di tipo WP_Error invece di classiche stringhe.

I file affetti da questo problema sono i seguenti:
/page-templates/amministrazione-trasparente.php
Fatal error
: Uncaught Error: Object of class WP_Error could not be converted to string in /var/www/vhosts/SCUOLA.edu.it/httpdocs/wp-content/themes/design-scuole-wordpress-theme-main/page-templates/amministrazione-trasparente.php:62

/template-parts/search/filters-amministrazione.php
Fatal error: Uncaught Error: Object of class WP_Error could not be converted to string in /var/www/vhosts/SCUOLA.edu.it/httpdocs/wp-content/themes/design-scuole-wordpress-theme-main/template-parts/search/filters-amministrazione.php:43

Per risolvere il problema ho proceduto alle seguenti modifiche:

/page-templates/amministrazione-trasparente.php LINEA 62 sostituita con:
// FIX Uncaught Error: Object of class WP_Error could not be converted to string $testString = get_term_link( get_term_by('name', $value, 'amministrazione-trasparente'), 'amministrazione-trasparente' ); if (gettype($testString)=="string") { $atreturn .= '<a href="' .$testString.'" title="' . $value . '">' . $value . '</a>'; $atreturn .= '</li>'; }

/template-parts/search/filters-amministrazione.php LINEA 43 sostituita con:
// FIX Uncaught Error: Object of class WP_Error could not be converted to string $testString = get_term_link( get_term_by('name', $value, 'amministrazione-trasparente'), 'amministrazione-trasparente' ); if (gettype($testString)=="string") { $atreturn_body .= ' <label class="mb-0" for="check-'.$term->slug.'"><a href="' . $testString . '">'.$term->name.'</a></label>'; $atreturn_body .= '</div>'; $atreturn_body .= '</li>'; }
`

Includi link o screenshot

errore_amm_trasparente

Su quale sisitema operativo stai riscontrando il problema?

Windows

Su quale browser stai riscontrando il problema?

Qualsiasi

Che versione del tema stai utilizzando?

2.5.1

@emanueless emanueless added the bug Something isn't working label Oct 16, 2023
@Prancingkiller
Copy link
Contributor

Prancingkiller commented Nov 6, 2023

Credo che il problema stia nell'utilizzo della funzione dsi_amministrazione_trasparente_array() definita nel file:
"design-scuole-wordpress-theme-main\inc\vocabolario.php"

perchè restituisce un array predefinito che contiene tutte le categorie dell'amministrazione trasparente (senza prenderle dal db, è lo stesso array utilizzato per popolare la sezione amministrazione trasparente al momento dell'installazione del tema), sulle quali poi i files:
/page-templates/amministrazione-trasparente.php
/template-parts/search/filters-amministrazione.php
invocano la funzione get_terms() per ricavarne i dettagli, se però ho modificato le categorie dell'amministrazione trasparente dal backend, la funzione get_terms() restituirà degli errori perchè non trova i terms nel db, li cerca a partire dall'array di dsi_amministrazione_trasparente_array(), ma nel db non li trova,
bisognerebbe scrivere una funzione che invece di restituire l'array dei terms predefiniti, li prende direttamente dal db, in modo tale che se ho fatto delle modifiche all'albero delle categorie dell'amministrazione trasparente funziona comunque tutto, ho aggiunto questa funzione al file del vocabolario:

function testA(){
$myterms = get_terms( array( 'taxonomy' => 'amministrazione-trasparente', 'parent' => 0 ) );
$data = [];
foreach($myterms as $term){
$inner = [];
$inner[]=$term->name;
$sub=[];
foreach(get_terms( array( 'taxonomy' => 'amministrazione-trasparente', 'parent' => $term->term_id ))as $subT){
$sub[] = $subT->name;
}
$inner[]=$sub;
$data[] = $inner;
}
return $data;
}

e ho chiamato questa funzione invece di dsi_amministrazione_trasparente_array() nei files:
/page-templates/amministrazione-trasparente.php
/template-parts/search/filters-amministrazione.php

mi sembra funzioni correttamente, l'unica differenza è che nella pagina saranno visualizzate le categorie di documenti che contengono almeno un documento, questo perchè get_terms() restituisce solo i terms che hanno un valore di count superiore a 0.

Copy link

stale bot commented Jul 24, 2024

Questo problema è stato automaticamente contrassegnato come non aggiornato perché non ha avuto attività recentemente. Sarà chiuso se non si verificano ulteriori attività. Considerate inoltre l'aggiornamento alle ultime versioni del tema. Grazie.

@stale stale bot added the wontfix This will not be worked on label Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants