Last active
October 18, 2020 17:44
-
-
Save raylinanthony/eff3805d7c9d2dc93d1e to your computer and use it in GitHub Desktop.
Polylang Global Register String
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 [email protected] | |
* @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'); | |
} | |
?> |
Author
raylinanthony
commented
Aug 16, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment