trim( (string) Settings::value( 'path_prefix', '' ), '/' ), '{file}' => ltrim( (string) ( $vars['file'] ?? $filename ), '/' ), '{Y}' => gmdate( 'Y', $time ), '{m}' => gmdate( 'm', $time ), '{uuid}' => $vars['uuid'] ?? str_replace( '-', '', wp_generate_uuid4() ), '{filename}' => $filename, '{context}' => str_replace( '.', '-', (string) ( $vars['context'] ?? '' ) ), '{id}' => (string) ( $vars['id'] ?? '' ), ]; $key = strtr( $template, $replacements ); $key = preg_replace( '#/+#', '/', $key ); /** * Filters an object key before it is stored. * * @param string $key The key. * @param array $vars Template variables (context, id, filename, file). */ return ltrim( (string) apply_filters( 'gemoffload/object_key', $key, $vars ), '/' ); } /** * The path of a file relative to the uploads base directory, or '' when it * lives outside uploads. */ public static function relative_to_uploads( string $path ): string { $uploads = wp_get_upload_dir(); $base = trailingslashit( wp_normalize_path( $uploads['basedir'] ) ); $path = wp_normalize_path( $path ); return 0 === strpos( $path, $base ) ? substr( $path, strlen( $base ) ) : ''; } }