-
Notifications
You must be signed in to change notification settings - Fork 19
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
Add a language filter for ACF options pages #42
base: master
Are you sure you want to change the base?
Add a language filter for ACF options pages #42
Conversation
…ve unused function arguments, ensure consistent function prefixing
…unused/unreachable code, add some return type declarations
…t, update resolver to change language
// If WPML is installed | ||
if ($sitepress) { | ||
// Switch the current locale WPML | ||
$sitepress->switch_lang($lang); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldnt we switch the locale back to what it was before after this resolver? Otherwise this will cause resolvers further down in the call chain to behave different, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is something that seems to be happening, yes. I'm using it to my advantage by following it up with a query that has no language filter, but it would be better to reset the language to the default. Or maybe even better, save what it was before and set that back.
global $wpgraphqlwpml_prev_language; | ||
global $wpgraphqlwpml_url_filter_off; | ||
|
||
$field_name = $resolver->getInfo()->fieldName; | ||
if ($field_name === 'menus') { | ||
global $icl_adjust_id_url_filter_off; | ||
$icl_adjust_id_url_filter_off = true; | ||
$args = $resolver->getArgs(); | ||
$args = $resolver->get_args(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The getArgs
method was deprecated by WP GraphQL. I'm not sure if the new option was already available in older versions of the plugin, so it might be something that should be reverted to ensure compatibility with older versions of WPGQL.
I just found out that a GQL debug message is generated with my current code:
I removed the code that first deregisters the fields because everything seemed to work without it, but I think re-adding that code would get rid of this debug message. |
The main addition of this PR is the addition of a
wpmlLanguage
argument on ACF options page fields, which controls the language of the query output. By default, ACF options pages only output the default site language on WPGraphQL. This argument allows the user to supply a language code (e.g. "en", or "nl"), very similar to PR #32.I added a gitignore file to ensure no unnecessary files are added to the repository.
I also took some time to consistently reformat the plugin's code, add
use
statements to replace FQCNs, remove unused function arguments, replace deprecated function calls, and remove some duplicate and unused code. The exact changes can be found in the first few commits.The (WIP) commit is an intermediate commit where I failed to get it fully working, you can essentially ignore that, as I moved the code into a separate file in the last commit, while also solving the problem and getting it to function correctly.