debug_backtrace = $debug_backtrace; $this->file = $file; $this->theme_dir = $this->file->fix_dir_separator( get_theme_root() ); } public function find_id( $mo_file ) { return $this->find_theme_directory( $mo_file ); } private function find_theme_directory( $mo_file ) { if ( false !== strpos( $mo_file, $this->theme_dir ) ) { return $this->extract_theme_directory( $mo_file ); } return $this->find_theme_directory_in_backtrace(); } private function find_theme_directory_in_backtrace() { $file = $this->find_file_in_backtrace(); if ( ! $file ) { return null; } return $this->extract_theme_directory( $file ); } private function find_file_in_backtrace() { $stack = $this->debug_backtrace->get_backtrace(); foreach ( $stack as $call ) { if ( isset( $call['function'] ) && 'load_theme_textdomain' === $call['function'] ) { return $call['file']; } } return null; } /** * @param $file_path * * @return mixed */ private function extract_theme_directory( $file_path ) { $file_path = $this->file->fix_dir_separator( $file_path ); $dir = ltrim( str_replace( $this->theme_dir, '', $file_path ), DIRECTORY_SEPARATOR ); $dir = explode( DIRECTORY_SEPARATOR, $dir ); return trim( $dir[0], DIRECTORY_SEPARATOR ); } }