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

suppress deprecated warning on php 8.2.0 because $post_id is null on 404 pages #87

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions classes/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@ class Helpers {
* @author Maxime CULEA
*/
public static function original_option_id( $post_id ) {
// $post_id may be an object
// Default value for $post_id
$processed_post_id = 0;

// If $post_id is an object, determine its type
if ( is_object( $post_id ) ) {
if ( isset( $post_id->post_type, $post_id->ID ) ) { // post
$post_id = $post_id->ID;
} elseif ( isset( $post_id->roles, $post_id->ID ) ) { // user
$post_id = 'user_' . $post_id->ID;
} elseif ( isset( $post_id->taxonomy, $post_id->term_id ) ) { // term
$post_id = 'term_' . $post_id->term_id;
} elseif ( isset( $post_id->comment_ID ) ) { // comment
$post_id = 'comment_' . $post_id->comment_ID;
} else { // default
$post_id = 0;
if ( isset( $post_id->post_type, $post_id->ID ) ) {
$processed_post_id = $post_id->ID;
} elseif ( isset( $post_id->roles, $post_id->ID ) ) {
$processed_post_id = 'user_' . $post_id->ID;
} elseif ( isset( $post_id->taxonomy, $post_id->term_id ) ) {
$processed_post_id = 'term_' . $post_id->term_id;
} elseif ( isset( $post_id->comment_ID ) ) {
$processed_post_id = 'comment_' . $post_id->comment_ID;
}
}

// allow for option == options
if ( 'option' === $post_id ) {
$post_id = 'options';
}
// Replace 'option' with 'options'
$processed_post_id = ( 'option' === $processed_post_id ) ? 'options' : $processed_post_id;

return str_replace( sprintf( '_%s', pll_current_language( 'locale' ) ), '', $post_id );
// Remove the locale suffix from $processed_post_id
return str_replace( sprintf( '_%s', pll_current_language( 'locale' ) ), '', $processed_post_id );
}


Expand Down
2 changes: 1 addition & 1 deletion classes/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function get_default_reference( $reference, $field_name, $post_id ) {
* Dynamically get the options page ID
* @see : https://regex101.com/r/58uhKg/2/
*/
$_post_id = preg_replace( '/(_[a-z]{2}_[A-Z]{2})/', '', $post_id );
$_post_id = $post_id ? preg_replace( '/(_[a-z]{2}_[A-Z]{2})/', '', $post_id ) : 0;

remove_filter( 'acf/load_reference', [ $this, 'get_default_reference' ] );
$reference = acf_get_reference( $field_name, $_post_id );
Expand Down