exists it will be merged on top of our custom strings. * @param string $domain * @param string $mopath * @return void */ public function on_load_textdomain( $domain, $mopath ){ $key = ''; // domains may be split into multiple files $name = pathinfo( $mopath, PATHINFO_FILENAME ); if( $lpos = strrpos( $name, '-') ){ $slug = substr( $name, 0, $lpos ); if( $slug !== $domain ){ $key = $slug; } } // avoid recursion when we've already handled this domain/slug if( isset($this->lock[$domain][$key]) ){ return; } // if context is set, then a theme or plugin initialized the loading process properly if( is_array($this->context) ){ list( $subdir, $_domain, $locale ) = $this->context; $this->context = null; if( $_domain !== $domain ){ return; } $mopath = $this->base.$subdir.$domain.'-'.$locale.'.mo'; } // else load_textdomain must have been called directly, including to load core domain else { $mopath = $this->resolve($mopath); if( '' === $mopath ){ return; } } // Load our custom translations avoiding recursion back into this hook $this->lock[$domain][$key] = true; load_textdomain( $domain, $mopath ); } /* * `load_script_translation_file` filter callback * Alternative method to merging in `pre_load_script_translations` * @param string|false candidate JSON file (false on final attempt) * @param string * @return string */ public function filter_load_script_translation_file( $path = '', $handle = '' ){ // currently handle-based JSONs for author-provided translations will never map. if( is_string($path) && preg_match('/^-[a-f0-9]{32}\\.json$/',substr($path,-38) ) ){ $custom = $this->resolve($path); if( $custom && is_readable($custom) ){ // Defer until either JSON is resolved or final attempt passes an empty path. $this->json[$handle] = $custom; } } // If we return an unreadable file, load_script_translations will not fire. // However, we need to allow WordPress to try all files. Last attempt will have empty path else if( false === $path && array_key_exists($handle,$this->json) ){ $path = $this->json[$handle]; unset( $this->json[$handle] ); } return $path; } /** * `load_script_translations` filter callback. * Merges custom translations on top of installed ones, as late as possible. * @param string $json contents of JSON file that WordPress has read * @param string $path path relating to given JSON (not used here) * @param string $handle script handle for registered merge * @return string final JSON translations * @noinspection PhpUnusedParameterInspection */ public function filter_load_script_translations( $json = '', $path = '', $handle = '' ){ if( array_key_exists($handle,$this->json) ){ $path = $this->json[$handle]; unset( $this->json[$handle] ); $json = self::mergeJson( $json, file_get_contents($path) ); } return $json; } /** * Merge two JSON translation files such that custom strings override * @param string $json Original/fallback JSON * @param string $custom Custom JSON (must exclude empty keys) * @return string Merged JSON */ private static function mergeJson( $json, $custom ){ $fallbackJed = json_decode($json,true); $overrideJed = json_decode($custom,true); if( self::jedValid($fallbackJed) && self::jedValid($overrideJed) ){ // Original key is probably "messages" instead of domain, but this could change at any time. // Although custom file should have domain key, there's no guarantee JSON wasn't overwritten or key changed. $overrideMessages = current($overrideJed['locale_data']); $fallbackMessages = current($fallbackJed['locale_data']); // We could merge headers, but custom file should be correct // $overrideMessages[''] += $fallbackMessages['']; // Continuing to use "messages" here as per WordPress. Good backward compatibility is likely. // Note that our custom JED is sparse (exported with empty keys absent). This is essential for + operator. $overrideJed['locale_data'] = [ 'messages' => $overrideMessages + $fallbackMessages, ]; // Note that envelope will be the custom one. No functional difference but demonstrates that merge worked. $overrideJed['merged'] = true; $json = json_encode($overrideJed); } // Handle situations where one or neither JSON strings are valid else if( self::jedValid($overrideJed) ){ $json = $custom; } else if( ! self::jedValid($fallbackJed) ){ $json = ''; } return $json; } /** * Test if unserialized JSON is a valid JED structure * @param array $jed * @return bool */ private static function jedValid( $jed ){ return is_array($jed) && array_key_exists('locale_data',$jed) && is_array($jed['locale_data']) && $jed['locale_data']; } /* * Alternative merging method using `script_loader_tag` filter callback. * We could load two JSONs via two calls to wp.i18n.setLocaleData BUT WordPress closure makes it difficult/unreliable. * @param string candidate JSON file * @param string * @param string * @return string * public function filter_script_loader_tag( $tag = '', $handle = '', $src = '' ){ if( array_key_exists($handle,$this->json) ){ $json = file_get_contents($this->json[$handle] ); unset($this->json[$handle]); // splice custom translations between original ones and the script they're attached to. list( $foo, $bar ) = explode('',$tag,2); $tag = $foo."\n console.log({$json});".$bar; } return $tag; }*/ }
Fatal error: Uncaught Error: Class "MailPoet\WPCOM\DotcomHelperFunctions" not found in /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php:1215 Stack trace: #0 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(1205): MailPoetGenerated\FreeCachedContainer->getReporterService() #1 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(830): MailPoetGenerated\FreeCachedContainer->getAnalytics2Service() #2 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(4818): MailPoetGenerated\FreeCachedContainer->getServicesService() #3 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(2248): MailPoetGenerated\FreeCachedContainer->getDotcomLicenseProvisionerService() #4 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(2276): MailPoetGenerated\FreeCachedContainer->getHooks2Service() #5 /htdocs/wp-content/plugins/mailpoet/vendor-prefixed/symfony/dependency-injection/Container.php(122): MailPoetGenerated\FreeCachedContainer->getInitializerService() #6 /htdocs/wp-content/plugins/mailpoet/vendor-prefixed/symfony/dependency-injection/Container.php(110): MailPoetVendor\Symfony\Component\DependencyInjection\Container->make('MailPoet\\Config...', 1) #7 /htdocs/wp-content/plugins/mailpoet/lib/DI/ContainerWrapper.php(39): MailPoetVendor\Symfony\Component\DependencyInjection\Container->get('MailPoet\\Config...') #8 /htdocs/wp-content/plugins/mailpoet/mailpoet_initializer.php(89): MailPoet\DI\ContainerWrapper->get('MailPoet\\Config...') #9 /htdocs/wp-content/plugins/mailpoet/mailpoet.php(206): require_once('/htdocs/wp-cont...') #10 /htdocs/wp-settings.php(462): include_once('/htdocs/wp-cont...') #11 /htdocs/wp-config.php(96): require_once('/htdocs/wp-sett...') #12 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...') #13 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...') #14 /htdocs/index.php(17): require('/htdocs/wp-blog...') #15 {main} thrown in /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php on line 1215