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

disable translation on specific option pages #26

Closed
oguilleux opened this issue Oct 15, 2018 · 13 comments
Closed

disable translation on specific option pages #26

oguilleux opened this issue Oct 15, 2018 · 13 comments
Assignees

Comments

@oguilleux
Copy link

Hi Maxime,

Awesome plugin ! I'd like to disable the translation functionnality on certain options page. Is it possible with the work you've done ? With a filter perhaps ? I haven't seen anything that could allow me to do so.

Thanks for your feedback,

Olivier

@MaximeCulea
Copy link
Contributor

Hi @oguilleux, thx for you feedback! :)

I think you can play around this filter : https://github.com/BeAPI/acf-options-for-polylang#for-developpers

Anyway, if not, don't hesitate to add one (PR) or ask me, I'll be glad.
Have a good day.

@MaximeCulea MaximeCulea self-assigned this Oct 15, 2018
@oguilleux
Copy link
Author

oguilleux commented Oct 15, 2018

I'm trying to use that exactly but I can't get it to work with my function.

function dont_translate_option_page(){
	$screen = get_current_screen();
	if ($screen->id === "my-option-page") {
		add_filter('bea.aofp.get_default', false);
	}
}
add_action('current_screen','dont_translate_option_page');

@MaximeCulea
Copy link
Contributor

@oguilleux Is this solved for you? It sounds not ;)

@oguilleux
Copy link
Author

No I didn't manage to solve that question :(

@MaximeCulea
Copy link
Contributor

What is your need ? You have several option pages and want to disable on one of them ?
I'll will write a better example in documentation.

@MaximeCulea MaximeCulea reopened this Oct 17, 2018
@oguilleux
Copy link
Author

Yes I wanted to disable one of them because I have data that is website related and not language related.

@MaximeCulea
Copy link
Contributor

MaximeCulea commented Nov 6, 2018

@oguilleux There is a way to filter this, but I need your PR 😉

You can add it here in the code.
Can I also ask you to follow the following syntax, I would appreciate.

In this method, you can introduce a filter on returned "option page ids", then in your project code if you filter the "option page id" by deleting it, you could finally "disable" the feature for the one you need 🤗

@oguilleux
Copy link
Author

oguilleux commented Nov 8, 2018

I would be glad to contribute.

I added the following filter where you asked me

if(has_filter('bea.aofp.exclude_option_pages')) {
  $options_pages = apply_filters('bea.aofp.exclude_option_pages', $options_pages);
}

and in my functions.php I tried debugging with this

function exclude_main_options($options_pages) {

  var_dump($options_pages);

  return $options_pages;

}
add_filter( 'bea.aofp.exclude_option_pages', 'exclude_main_options' );

but nothing shows up

@mingyeungs
Copy link

Hi Maxime, thanks for creating this great plugin!

I found this thread while trying to do the exact same thing (i.e. to have an option page that should NOT be translated), but aren't sure how this can be done.

I read this link https://github.com/BeAPI/acf-options-for-polylang#for-just-one-acf-options-page, but adding add_filter( 'bea.aofp.get_default', '__return_false' ); to my theme functions.php do the opposite of what I want - it simply ignore the options set under "all language", whereas what I want to do is to ignore the options set under the individual languages.

Is this support by the plugin? Thanks for your reply!
Ming

@indrek-k
Copy link

indrek-k commented Aug 4, 2020

+1

Would really love to be able to disable language switching for a specific options page, ideally even hide the language selector.

@hattricks
Copy link

I managed to get this working with this code. Added some css to hide the admin bar language selector and the text in the postbox.

/**
 * Disable ACF Polylang translations
 */
add_action('current_screen','dont_translate_option_page'); 
function dont_translate_option_page() {
	$disable_option_pages = array(
		'options_screen_id',
	);
	
	$screen = get_current_screen();

	if (in_array($screen->id, $disable_option_pages)) {
		add_filter( 'acf/validate_post_id', 'skip_acf_polylang_options', 10, 2 );
		add_action('admin_head', function () {
			echo '<style type="text/css">#wp-admin-bar-languages, .postbox .misc-pub-section { display:none; }</style>';
		}, 10);

	}
}


/**
 * Helper function to disable Polylang
 */
function skip_acf_polylang_options( $future_post_id, $original_post_id ) {
	return $original_post_id;
}

@Abdelmonem-BEN-NACEUR
Copy link

Abdelmonem-BEN-NACEUR commented Jan 29, 2021

I managed to get this working with this code. Added some css to hide the admin bar language selector and the text in the postbox.

/**
 * Disable ACF Polylang translations
 */
add_action('current_screen','dont_translate_option_page'); 
function dont_translate_option_page() {
	$disable_option_pages = array(
		'options_screen_id',
	);
	
	$screen = get_current_screen();

	if (in_array($screen->id, $disable_option_pages)) {
		add_filter( 'acf/validate_post_id', 'skip_acf_polylang_options', 10, 2 );
		add_action('admin_head', function () {
			echo '<style type="text/css">#wp-admin-bar-languages, .postbox .misc-pub-section { display:none; }</style>';
		}, 10);

	}
}


/**
 * Helper function to disable Polylang
 */
function skip_acf_polylang_options( $future_post_id, $original_post_id ) {
	return $original_post_id;
}

To hide the admin bar language selector you can use a filter : 'pll_admin_languages_filter'.

Here is a snippet i'm using for my case :

add_filter( 'pll_admin_languages_filter', function ( $adminBarLanguages ) {
    global $pagenow;
    if ( $pagenow === 'admin.php' && isset( $_GET['page'] ) && $_GET['page'] === 'acf-options' ) {
        unset( $adminBarLanguages[0] );
    }

    return $adminBarLanguages;
} );

@turpoint turpoint mentioned this issue Jun 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants