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

fix: allow to use this theme an old php version #737

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

VinsMach
Copy link
Contributor

Descrizione

le modifiche fatte consentono di far funzionare il tema anche su versioni antecedenti alla 8.
Modificate alcune funzioni
Aggiunta una funziona prima che sia deprecata l'originale

inc/actions.php Outdated Show resolved Hide resolved
inc/breadcrumb.php Show resolved Hide resolved
@zetareticoli zetareticoli self-requested a review December 17, 2024 14:24
Copy link
Member

@zetareticoli zetareticoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cosa intendi con versioni antecedenti alla 8, PHP?

@VinsMach
Copy link
Contributor Author

7.3 e 7.4

Comment on lines +1238 to 1257
if(!function_exists("get_page_by_title_new")){
function get_page_by_title_new( $page_title, $output = OBJECT, $post_type = 'page' ) {
$query = new WP_Query([
'post_type' => 'page',
'title' => $page_title,
'post_status' => 'publish', // Opzionale: solo pagine pubblicate
'posts_per_page' => 1, // Opzionale: limitare a un risultato
]);

$page = null;

if ($query->have_posts()) {
$query->the_post();
$page = get_post(); // Recupera l'oggetto del post corrente
wp_reset_postdata(); // Resetta i dati del loop di WordPress
}

return $page;
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggerirei una formulazione un po' più compatta.

Suggested change
if(!function_exists("get_page_by_title_new")){
function get_page_by_title_new( $page_title, $output = OBJECT, $post_type = 'page' ) {
$query = new WP_Query([
'post_type' => 'page',
'title' => $page_title,
'post_status' => 'publish', // Opzionale: solo pagine pubblicate
'posts_per_page' => 1, // Opzionale: limitare a un risultato
]);
$page = null;
if ($query->have_posts()) {
$query->the_post();
$page = get_post(); // Recupera l'oggetto del post corrente
wp_reset_postdata(); // Resetta i dati del loop di WordPress
}
return $page;
}
}
if (!function_exists("dsi_get_page_by_title")) {
function dsi_get_page_by_title( $page_title ) {
return (new WP_Query([
'post_type' => 'page',
'title' => $page_title,
'post_status' => 'publish',
'posts_per_page' => 1,
]))->post;
}
}

@@ -1112,7 +1112,7 @@ protected function get_post_types_by_slug( $slug ) {

foreach ( $post_types as $type ) {

if ( $slug === $type->has_archive || ( true === $type->has_archive && $slug === $type->rewrite['slug'] ) )
if ( $slug === $type->has_archive || ( true === $type->has_archive && is_array($type->rewrite) && isset($type->rewrite['slug']) && $slug === $type->rewrite['slug']))
Copy link

@enrimk enrimk Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non è un'eventualità piuttosto remota?
Cioè, mi pare che rewrite['slug'] qui possa risultare non definito solo nel caso di un post_type con has_archive === true e rewrite === false contemporaneamente (con archivio, ma senza permalink). È così? È un caso che si verifica nell'app?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants