{"id":8137662,"date":"2016-09-05T07:16:28","date_gmt":"2016-09-05T07:16:28","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/function-call-by-reference\/"},"modified":"2016-09-05T07:16:28","modified_gmt":"2016-09-05T07:16:28","slug":"function-call-by-reference","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/function-call-by-reference\/","title":{"rendered":"Function Call by Reference"},"content":{"rendered":"<p>Hi everybody,<\/p>\n<p>I am using the following code in a plugin in order to change some specific translated strings for a plugin and for my theme. (I could change the translations itself into the .po .mo files, but I would have to do it after each update of the plugin or of the theme. Including this code in a separate plugin avoids these updates.)<\/p>\n<pre><code>register_activation_hook( __FILE__, &#039;Corrections_install&#039; );\nfunction Corrections_install() {\n\tglobal $wp_version;\n\tif (version_compare($wp_version, &#039;4.1&#039;, &#039;&lt;&#039; )) wp_die( &#039;This plugin requires WordPress version 4.1 or higher.&#039; );\n};\n \n\/*\n * Filter the translation string before it is displayed.\n *\n * @param $translation The current translation\n * @param $text        The text to translate\n * @param $domain      The domain for the translation\n * @return string      The translated \/ filtered text.\n *\/\n function filter_gettext($translation, $text, $domain) {\n\t$translations = &amp;get_translations_for_domain($domain);\n\n\t\/* Menus de langues et de pages sur les appareils mobiles *\/\n\n\tif ($domain == &#039;catch-box&#039;) {\n\n\t\t\/* Menu de gauche (les langues) *\/\n\n\t\tif (($text == &#039;Menu&#039;) &amp;&amp; (function_exists(&#039;pll_current_language&#039;))) {\n\t\t\tswitch (pll_current_language()) {\n\t\t\t\tcase &#039;en&#039;: return $translations-&gt;translate(&#039;Languages&#039;);\n\t\t\t\tcase &#039;fr&#039;: return $translations-&gt;translate(&#039;Langues&#039;);\n\t\t\t\tcase &#039;ar&#039;: return $translations-&gt;translate(&#039;\u0627\u0644\u0644\u063a\u0627\u062a&#039;);\n\t\t\t};\n\t\t};\n\n\t\t\/* Menu de droite (les pages) *\/\n\n\t\tif ($text == &#039;Secondary Menu&#039;) return $translations-&gt;translate(&#039;&amp;nbsp;&#039;);\n\t};\n\n\t\/* Typos dans les messages du widget calendrier *\/\n\n\tif (($domain == &#039;google-calendar-events&#039;) &amp;&amp; ($text == &#039;Nothing from %1$s to %2$s.&#039;)) {\n\t\tswitch ($translation) {\n\t\t\tcase &#039;Rien de %1$s \u00e0 %2$s.&#039;: return $translations-&gt;translate(&#039;Rien du %1$s au %2$s.&#039;);\n\t\t\tcase &#039;\u0644\u0627 \u0634\u064a\u0626 \u0645\u0646 %1$s \u0625\u0644\u0649 %2$s.&#039;: return $translations-&gt;translate(&#039;\u0644\u0627 \u0634\u064a\u0621 \u0645\u0646 %1$s \u0625\u0644\u0649 %2$s.&#039;);\n\t\t};\n\t};\n\treturn $translation;\n};\nadd_filter(&#039;gettext&#039;, &#039;filter_gettext&#039;, 10, 3);<\/code><\/pre>\n<p>It works perfectly, but I am using <strong>$translations = &amp;get_translations_for_domain($domain);<\/strong>, which seems not to be strongly recommanded.<\/p>\n<p>What do you think? Should I change my code? And how?<\/p>\n<p>Thanks!<\/p>\n<p>R\u00e9mi<\/p>\n","protected":false},"template":"","class_list":["post-8137662","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/8137662","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/8137662\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=8137662"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}