Skip to content
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