Skip to content

Commit

Permalink
#22 : refactor for negative form. Dynamically get the option page id.
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximeCulea committed Jul 31, 2018
1 parent 6c330a7 commit bf6a262
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions classes/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,28 @@ public function set_current_site_lang() {
* @param $reference
* @param $field_name
* @param $post_id
* @return string|void
*
* @author Jukra, Maxime CULEA
*
* @since 1.1.2
*
* @return string
*/
public function get_default_reference( $reference, $field_name, $post_id ) {
if ( ! $reference || $reference == '' ) {
remove_filter( 'acf/load_reference', [ $this, 'get_default_reference' ] );
$reference = acf_get_reference( $field_name, "options" );
add_filter( 'acf/load_reference', [ $this, 'get_default_reference' ], 10, 3 );
if ( ! empty( $reference ) ) {
return $reference;
}

/**
* 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 );

remove_filter( 'acf/load_reference', [ $this, 'get_default_reference' ] );
$reference = acf_get_reference( $field_name, $_post_id );
add_filter( 'acf/load_reference', [ $this, 'get_default_reference' ], 10, 3 );

return $reference;
}

Expand Down

0 comments on commit bf6a262

Please sign in to comment.