Tahák k tvorbě webů

WordPress

Úpravy související s pluginem Polylang

Vlastní překladové řetězce

<?php
	$gog_pll_strings = array(
		'wc_payment_ba_title' => 'wc_payment_ba_title',
		'wc_payment_ba_description' => 'wc_payment_ba_description',
		'wc_payment_ba_instruction' => 'wc_payment_ba_instruction',
		'wc_payment_ba_payment' => 'wc_payment_ba_payment'
	);

	function gog_register_pll_strings() {
		global $gog_pll_strings ;
		if (function_exists('pll_register_string')) {
			foreach ($gog_pll_strings as $key => $string) {
				pll_register_string($key, $string);
			}
		}
	}
	add_action('after_setup_theme', 'gog_register_pll_strings');

Shortcode - zobrazení překladového řetězce

Příklad použití: [pll wc_payment_ba_title]

<?php
	function gog_pll_string($atts) {
		global $gog_pll_strings;
		foreach ($atts as $a) {
			if (array_key_exists($a, $gog_pll_strings )) {
				return do_shortcode(pll__($gog_pll_strings [$a]));
			}
		}
	}
	add_shortcode('pll', 'gog_pll_string');

Shortcode - zobrazení pouze v určitém jazyce

Umožňuje mi zobrazit určitý obsah jen pro některé jazyky. Např:

  • [polylang lang=cz]Text česky[/polylang]
  • [polylang lang=en]English text[/polylang] 
<?php
	function gog_pll_shortcode($atts, $content = null) {
		extract(shortcode_atts(array('lang' => ''), $atts ));
		if (empty($content) || empty($lang)) {
			return '';
		}
		return ($lang == pll_current_language()) ? do_shortcode($content) : '';
	}
	add_shortcode('polylang', 'gog_pll_shortcode');
?>

Plugin WPForms

Takto přeložím validační zprávy WPForms:

<?php
	function gog_wpforms_translate() {
		if (function_exists('pll_current_language') && 'pll_current_language() == 'cs') {
			?>
			<script type="text/javascript">
	        jQuery(document).ready(function() {
	            jQuery.extend(jQuery.validator.messages, {
	                required: "Toto pole je povinné.",
	                url: "Zadejte prosím platnou URL adresu.",
	                email: "Zadejte prosím platný e-mail."

	            });
	        });
			</script>
			<?php
		}
	}
	add_action('wpforms_wp_footer_end', 'gog_wpforms_translate', 20);
?>

Plugin ContentBlocks

Tento kód nastaví viditelnost bloků na public a díky tomu můžu vytvářet jazykové verze jednotlivých bloků.

<?php
	function content_block_public($args, $post_type) {
		if ($post_type == 'content_block') {
			$args['public'] = true;
		}
		return $args;
	}
	add_filter('register_post_type_args', 'content_block_public', 20, 2);
?>