-
Notifications
You must be signed in to change notification settings - Fork 215
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: enrimk <[email protected]>
There was a problem hiding this 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?
7.3 e 7.4 |
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; | ||
} | ||
} |
There was a problem hiding this comment.
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.
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'])) |
There was a problem hiding this comment.
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?
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