page title ] * * @since 1.0.2 * @author Maxime CULEA * * @return array */ function get_option_page_ids() { $rule = [ 'param' => 'options_page', 'operator' => '==', 'value' => 'acf-options', 'id' => 'rule_0', 'group' => 'group_0', ]; $rule = acf_get_valid_location_rule( $rule ); $options_pages = acf_get_location_rule_values( $rule ); return empty( $options_pages ) ? [] : array_keys( $options_pages ); } /** * Check if the given post id is from an options page or not * * @param string $post_id * * @since 1.0.2 * @author Maxime CULEA * * @return bool */ function is_option_page( $post_id ) { if ( false !== strpos( $post_id, 'options' ) ) { return true; } $options_pages = $this->get_option_page_ids(); if ( ! empty( $options_pages ) && in_array( $post_id, $options_pages ) ) { return true; } return false; } /** * Manage to change the post_id with the current lang to save option against * * @param string $future_post_id * @param string $original_post_id * * @since 1.0.2 * @author Maxime CULEA * * @return string */ function set_options_id_lang( $future_post_id, $original_post_id ) { // Only on custom post id option page $options_pages = $this->get_option_page_ids(); if ( empty( $options_pages ) || ! in_array( $original_post_id, $options_pages ) ) { return $future_post_id; } $dl = acf_get_setting( 'default_language' ); $cl = acf_get_setting( 'current_language' ); if ( $cl && $cl !== $dl ) { $future_post_id .= '_' . $cl; } return $future_post_id; } } /** * Load at plugins loaded to ensure ACF and Polylang are used * * @since 1.0.2 * @author Maxime CULEA */ add_action( 'plugins_loaded', function () { if ( ! function_exists( 'get_field' ) || ! function_exists( 'pll_current_language' ) ) { return; } new BEA_ACF_For_Polylang(); } );