isFile() && 'php' === strtolower( $file_info->getExtension() ) ) { $file_path = $file_info->getPathname(); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents $file_content = file_get_contents( $file_path ); if ( empty( $file_content ) ) { continue; } if ( preg_match_all( $pattern, $file_content, $matches ) ) { foreach ( $matches[1] as $raw_string ) { if ( '' !== $raw_string ) { // Strip execution slashes to obtain the clean textual string representation $clean_string = stripcslashes( $raw_string ); $discovered_strings[ $clean_string ] = true; } } } } } } catch ( Exception $e ) { return false; } // --- CONSTRUCT GETTEXT POT HEADERS --- $pot_content = "# Copyright (C) " . gmdate( 'Y' ) . " AF Themes\n"; $pot_content .= "# This file is distributed under the same license as the {$component} package.\n"; $pot_content .= "msgid \"\"\n"; $pot_content .= "msgstr \"\"\n"; $pot_content .= "\"Project-Id-Version: {$component} Templates\\n\"\n"; $pot_content .= "\"Report-Msgid-Bugs-To: https://wordpress.org/support/\\n\"\n"; $pot_content .= "\"POT-Creation-Date: " . gmdate( 'Y-m-d H:i:sO' ) . "\\n\"\n"; $pot_content .= "\"MIME-Version: 1.0\\n\"\n"; $pot_content .= "\"Content-Type: text/plain; charset=UTF-8\\n\"\n"; $pot_content .= "\"Content-Transfer-Encoding: 8bit\\n\"\n"; $pot_content .= "\"X-Generator: AF Translate Run Time Engine\\n\"\n\n"; // --- POPULATE DATA MAP ENTRIES --- if ( ! empty( $discovered_strings ) ) { foreach ( array_keys( $discovered_strings ) as $raw_string ) { // Format safely for Gettext standards by escaping double quotes and backslashes $escaped_string = addcslashes( $raw_string, "\"\\" ); $pot_content .= "msgid \"{$escaped_string}\"\n"; $pot_content .= "msgstr \"\"\n\n"; } } return false !== file_put_contents( $destination_path, $pot_content ); } }