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

Language switcher not available on ACF Option Page #1386

Open
fintinc opened this issue Nov 1, 2023 · 3 comments
Open

Language switcher not available on ACF Option Page #1386

fintinc opened this issue Nov 1, 2023 · 3 comments
Labels
maybe bug Potential bug, to be investigated module: ACF Integration with ACF need info The submitter must provide more info

Comments

@fintinc
Copy link

fintinc commented Nov 1, 2023

Since the ACF extra qTranslate fields are deprecated the ACF Option Page would need language switch buttons to see other languages than the standard language:

image

I fixed it quickly by adding a ACF Message field with the language switch buttons html code:
image

image
@fintinc fintinc added the maybe bug Potential bug, to be investigated label Nov 1, 2023
@herrvigg herrvigg added the module: ACF Integration with ACF label Nov 5, 2023
@herrvigg
Copy link
Collaborator

herrvigg commented Nov 5, 2023

I don't manage to reproduce and I don't understand what you mean with "ACF Message field", what is that?
Please give a very concise example to reproduce, by explaining very precisely which fields you select and how you create the option page.

@herrvigg herrvigg added the need info The submitter must provide more info label Nov 5, 2023
@fintinc
Copy link
Author

fintinc commented Nov 6, 2023

Hello and thanks for looking into this.
I try to explain more precisely:

  1. I created an Option Page in PHP like this:
    if( function_exists('acf_add_options_page') ) { acf_add_options_page(array( 'page_title' => 'Beiträge Einstellungen', 'menu_title' => 'Beiträge Einstellungen', 'menu_slug' => 'posts-settings', )); }
  2. I set up a ACF "repeater field" to appear on this Option Page. The repeater field has simple text fields and an URL field.
  3. Now on this Option Page it is not possible to switch the text fields to other languages to see and use them. Only the main language is visible even if I switch to another language using the main switch in the black admin bar on top of the browser window.
  4. By inspecting the code, I see that the input fields of the other languages are there but they are always hidden.
  5. So I thought this page would just need language switch buttons like there are when editing posts or pages .
  6. I went to a normal WordPress Page and copied the code of the qtranslate language switch buttons.
  7. On the Option Page I added a new ACF field with the the type of "Message". This field allows to add a message or html code to be visible in the UI of the backend.
  8. I just use this field to paste the code of the language switch buttons I copied from the normal WP page to be rendered as buttons on the Option Page.
  9. Now I can use these buttons to switch the text fields to other languages.

I guess the solution would be, if you could integrate the language switch buttons on the option page.
In earlier versions (link 3.13.x) there was also no language switch buttons on the ACF Option Page, but the visibility of the different language fields changed according to the main language of the backend. e.g. if I changed to french using the main language switcher in the wp admin bar, the french input fields would be visible. This is not the case anymore in version 3.15.x.

@lloydud
Copy link

lloydud commented Nov 30, 2023

Hello there,

Id thought id share my solution, just put the code in your theme functions.php.

Find your acf field id replacing field_60d9a9a5def77 in the below code. Then find the options page name in the url /wp-admin/admin.php?page=your_options_page_name and update the conditional:

add_action( 'admin_head', 'enable_qt_language_switcher_for_acf');
function enable_qt_language_switcher_for_acf(){
    if (isset($_GET['page']) && 'your_options_page_name' == $_GET['page']) { ?>
        <script>
            acf.getField('field_60d9a9a5def77').addAction('ready', function(){
                qTranslateConfig.js.get_qtx().setupLanguageSwitch();
            });
        </script>
   <?php }
}

Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maybe bug Potential bug, to be investigated module: ACF Integration with ACF need info The submitter must provide more info
Projects
None yet
Development

No branches or pull requests

3 participants