| @@ -27,19 +27,14 @@ | ||
| 27 | 27 | const TYPE_EARLYACCESS = 'earlyaccess'; |
| 28 | 28 | |
| 29 | 29 | private static array $folders = []; |
| 30 | 30 | |
| 31 | - public static function enqueue( string $font_name, string $font_type = self::TYPE_DEFAULT, $force_enqueue_from_cdn = false ): bool { | |
| 31 | + public static function enqueue( string $font_name, string $font_type = self::TYPE_DEFAULT ): bool { | |
| 32 | 32 | if ( static::enqueue_style( $font_name ) ) { |
| 33 | 33 | return true; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - $is_local_gf_enabled = (bool) get_option( 'elementor_local_google_fonts', '0' ); | |
| 37 | - if ( ! $is_local_gf_enabled ) { | |
| 38 | - $force_enqueue_from_cdn = true; | |
| 39 | - } | |
| 40 | - | |
| 41 | - if ( $force_enqueue_from_cdn || ! static::fetch_font_data( $font_name, $font_type ) ) { | |
| 36 | + if ( ! static::fetch_font_data( $font_name, $font_type ) ) { | |
| 42 | 37 | static::enqueue_from_cdn( $font_name, $font_type ); |
| 43 | 38 | return false; |
| 44 | 39 | } |
| 45 | 40 | |
| @@ -47,8 +42,9 @@ | ||
| 47 | 42 | } |
| 48 | 43 | |
| 49 | 44 | private static function sanitize_font_name( string $font_name ): string { |
| 50 | 45 | return sanitize_key( $font_name ); |
| 46 | + | |
| 51 | 47 | } |
| 52 | 48 | |
| 53 | 49 | private static function enqueue_style( string $font_name ): bool { |
| 54 | 50 | $sanitize_font_name = static::sanitize_font_name( $font_name ); |
| @@ -213,24 +209,15 @@ | ||
| 213 | 209 | |
| 214 | 210 | $cleaned_url = set_url_scheme( $original_font_url, 'https' ); |
| 215 | 211 | $cleaned_url = strtok( $cleaned_url, '?#' ); |
| 216 | 212 | |
| 217 | - $font_ext = pathinfo( $cleaned_url, PATHINFO_EXTENSION ); | |
| 218 | - | |
| 219 | 213 | $tmp_font_file = download_url( $cleaned_url ); |
| 220 | 214 | if ( is_wp_error( $tmp_font_file ) ) { |
| 221 | 215 | return ''; |
| 222 | 216 | } |
| 223 | 217 | |
| 224 | - $unique_font_id = static::get_unique_font_id( $cleaned_url ); | |
| 218 | + $current_font_basename = $sanitize_font_name . '-' . strtolower( sanitize_file_name( basename( $cleaned_url ) ) ); | |
| 225 | 219 | |
| 226 | - $current_font_basename = sprintf( | |
| 227 | - '%s-%s.%s', | |
| 228 | - $sanitize_font_name, | |
| 229 | - strtolower( sanitize_file_name( $unique_font_id ) ), | |
| 230 | - $font_ext | |
| 231 | - ); | |
| 232 | - | |
| 233 | 220 | $dest_file = $fonts_folder['path'] . $current_font_basename; |
| 234 | 221 | $dest_file_url = $fonts_folder['url'] . $current_font_basename; |
| 235 | 222 | |
| 236 | 223 | // Use copy and unlink because rename breaks streams. |
| @@ -248,17 +235,14 @@ | ||
| 248 | 235 | |
| 249 | 236 | return $css_content; |
| 250 | 237 | } |
| 251 | 238 | |
| 252 | - private static function get_unique_font_id( $font_url ): string { | |
| 253 | - return substr( sha1( $font_url ), 0, 8 ); | |
| 254 | - } | |
| 255 | - | |
| 256 | 239 | private static function enqueue_from_cdn( string $font_name, string $font_type ): void { |
| 257 | 240 | $font_url = static::get_google_fonts_remote_url( $font_name, $font_type ); |
| 258 | 241 | |
| 259 | 242 | $sanitize_font_name = static::sanitize_font_name( $font_name ); |
| 260 | 243 | |
| 244 | + // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion | |
| 261 | 245 | wp_enqueue_style( |
| 262 | 246 | 'elementor-gf-' . $sanitize_font_name, |
| 263 | 247 | $font_url, |
| 264 | 248 | [], |