Skip to content

Commit

Permalink
Merge pull request #22 from jukra/master
Browse files Browse the repository at this point in the history
Fix error with repeater fields default values
  • Loading branch information
MaximeCulea authored Jul 31, 2018
2 parents 89ff786 + 58ed325 commit 7b14c10
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion classes/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ protected function init() {
// Get default Polylang's option page value
add_filter( 'acf/load_value', [ $this, 'get_default_value' ], 10, 3 );

// Help loading right field for repeaters
add_filter( 'acf/load_reference', [ $this, 'get_default_reference' ], 10, 3 );

// Plugin's own translations
add_action( 'init', [ $this, 'init_translations' ] );
}

Expand All @@ -30,6 +34,23 @@ public function set_current_site_lang() {
return pll_current_language( 'locale' );
}

/**
* Load the correct reference for field key in have_rows loops
*
* @param $reference
* @param $field_name
* @param $post_id
* @return string|void
*/
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 );
}
return $reference;
}

/**
* Load default value (all languages) in front if none found for an acf option
*
Expand Down Expand Up @@ -192,4 +213,4 @@ public function init_translations() {
// Load translations
load_plugin_textdomain( 'bea-acf-options-for-polylang', false, BEA_ACF_OPTIONS_FOR_POLYLANG_PLUGIN_DIRNAME . '/languages' );
}
}
}

0 comments on commit 7b14c10

Please sign in to comment.