Skip to content

Instantly share code, notes, and snippets.

@raylinanthony
Last active October 18, 2020 17:44
Show Gist options
  • Save raylinanthony/eff3805d7c9d2dc93d1e to your computer and use it in GitHub Desktop.
Save raylinanthony/eff3805d7c9d2dc93d1e to your computer and use it in GitHub Desktop.
Polylang Global Register String
<?php
/**
* @desc Small script that reads all the files in a matter of wordoress Plugin ... Polylang used to record each string in the Wordpress Admin ... (Appearance -> Languages)
* script include polylang_global_register_string()
* @author Raylin Aquino raylinaquino@gmail.com
* @date 08-16-2015 (m-d-y)
* @note: It requires installation of Polylang Plugin
*/
if (!function_exists("polylang_global_register_string")) {
function polylang_global_register_string()
{
$files = scandir(get_template_directory());
if (count($files) == 0)
return; //Stop Script
$exts = array(
".php",
".phtml"
);
$files = array_filter($files, function($d) use ($exts)
{
foreach ($exts as $dd)
return strpos($d, $dd);
});
if (count($files) == 0)
return; //Stop Script
/*** Reading each file ***/
foreach ($files as $file) {
$data_file = file_get_contents(get_template_directory() . "/$file");
preg_match_all('/(pll_e|pll__)\(["|\'](.*?)["|\']\)/', $data_file, $matches, PREG_SET_ORDER);
foreach ($matches as $data) {
pll_register_string("$file", $data[2]);
}
}
}
/*** End Function ***/
add_action('init', 'polylang_global_register_string');
}
?>
@raylinanthony
Copy link
Author

polylang-global-string-register

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment