'host_link', 'desc' => __( 'Download Google Fonts from <link> and host them locally.', 'easyfonts' ) ] );
add_settings_field( 'host_import', __( 'Process @import inline style', 'easyfonts' ), [ $this, 'checkbox_field' ], 'easyfonts', 'easyfonts_main', [ 'label_for' => 'host_import', 'desc' => __( 'Process @import rules from inline <style> tags.', 'easyfonts' ) ] );
add_settings_field( 'process_fontface', __( 'Process @font-face statement', 'easyfonts' ), [ $this, 'checkbox_field' ], 'easyfonts', 'easyfonts_main', [ 'label_for' => 'process_fontface', 'desc' => __( 'Process @font-face from inline <style> tags.', 'easyfonts' ) ] );
add_settings_field( 'remove_hints', __( 'Remove Resource Hints', 'easyfonts' ), [ $this, 'checkbox_field' ], 'easyfonts', 'easyfonts_main', [ 'label_for' => 'remove_hints', 'desc' => __( 'Remove resource hints like preconnect, prefetch.', 'easyfonts' ) ] );
add_settings_field( 'remove_scripts', __( 'Remove webfont.js fonts', 'easyfonts' ), [ $this, 'checkbox_field' ], 'easyfonts', 'easyfonts_main', [ 'label_for' => 'remove_scripts', 'desc' => __( 'Remove Google Fonts loading from webfont.js inline scripts.', 'easyfonts' ) ] );
add_settings_field( 'combine_fonts', __( 'Combine Font Stylesheets', 'easyfonts' ), [ $this, 'checkbox_field' ], 'easyfonts', 'easyfonts_main', [ 'label_for' => 'combine_fonts', 'desc' => __( 'Merge all locally hosted font CSS files into a single file and remove duplicates.', 'easyfonts' ) ] );
add_settings_field( 'font_display', __( 'Font Display', 'easyfonts' ), [ $this, 'select_field' ], 'easyfonts', 'easyfonts_main', [ 'label_for' => 'font_display', 'desc' => __( 'Set font-display on all @font-face declarations for better loading control.', 'easyfonts' ) ] );
}
public function checkbox_field( $args ) {
$options = get_option( 'easyfonts_options', [] );
$id = $args['label_for'];
$checked = ! empty( $options[ $id ] ) ? 'checked' : '';
echo '
' . wp_kses_post( $args['desc'] ) . '
'; } } public function select_field( $args ) { $options = get_option( 'easyfonts_options', [] ); $id = $args['label_for']; $current = ! empty( $options[ $id ] ) ? $options[ $id ] : 'none'; $choices = [ 'none' => __( 'Disabled', 'easyfonts' ), 'auto' => 'auto', 'block' => 'block', 'swap' => 'swap', 'fallback' => 'fallback', 'optional' => 'optional', ]; echo ''; if ( ! empty( $args['desc'] ) ) { echo '' . wp_kses_post( $args['desc'] ) . '
'; } } public function options_page_html() { if ( ! current_user_can( 'manage_options' ) ) { return; } $this->handle_actions(); $options = get_option( 'easyfonts_options', [] ); ?>Support Us with 5⭐ Rating', 'easyfonts' ), 'https://wordpress.org/support/plugin/easyfonts/reviews/#new-post' ); ?>
list_styles(); } ?>Your hosting plays a key role in website speed and user experience. Analyze your server’s performance now, and explore better solutions if needed.
' . esc_html__( 'Fonts styles are not found. Preload the font first or visit the homepage.', 'easyfonts' ) . '
'; return; } $dir = new DirectoryIterator( EASYFONTS_UPLOAD_DIR ); foreach ( $dir as $file ) { if ( ! $file->isFile() || $file->getExtension() !== 'css' ) { continue; } $fname = $file->getFilename(); // When combine is enabled, only show combined file if ( $combine_enabled && strpos( $fname, '_combined.css' ) === false ) { continue; } // When combine is disabled, skip combined files if ( ! $combine_enabled && strpos( $fname, '_combined.css' ) !== false ) { continue; } $css_files[] = $fname; } if ( empty( $css_files ) ) { echo '' . esc_html__( 'Fonts styles are not found. Preload the font first or visit the homepage.', 'easyfonts' ) . '
'; return; } foreach ( $css_files as $file_name ) { if ( strpos( $file_name, '..' ) !== false ) { continue; } $file_path = EASYFONTS_UPLOAD_DIR . '/' . $file_name; if ( ! is_readable( $file_path ) ) { continue; } $file_content = file_get_contents( $file_path ); $font_family = []; $variant_italic = []; $variant_normal = []; preg_match_all( '/@font-face\s*{[^}]+}/', $file_content, $matches ); if ( empty( $matches[0] ) ) { continue; } foreach ( $matches[0] as $font_face ) { if ( preg_match( '/font-family:\s*[\'"]?([^;\'"]+)[\'"]?;/', $font_face, $family_match ) ) { $font_family[] = trim( $family_match[1] ); } if ( preg_match( '/font-style:\s*([^;]+);/', $font_face, $style_match ) ) { $style = trim( $style_match[1] ); if ( preg_match( '/font-weight:\s*([^;]+);/', $font_face, $weight_match ) ) { $weight = trim( $weight_match[1] ); if ( $style === 'italic' ) { $variant_italic[] = $weight; } elseif ( $style === 'normal' ) { $variant_normal[] = $weight; } } } } $font_family = array_unique( $font_family ); $variant_italic = array_unique( $variant_italic ); $variant_normal = array_unique( $variant_normal ); $style_data[] = [ 'file_url' => esc_url( EASYFONTS_UPLOAD_URL . '/' . $file_name ), 'font_families' => esc_html( implode( ', ', $font_family ) ), 'variant' => esc_html( 'italic: ' . implode( ', ', $variant_italic ) . ' | normal: ' . implode( ', ', $variant_normal ) ), ]; } if ( empty( $style_data ) ) { return; } echo '| ' . esc_html__( 'Hosted Fonts CSS URL', 'easyfonts' ) . ' | ' . esc_html__( 'Font Families', 'easyfonts' ) . ' | ' . esc_html__( 'Variants', 'easyfonts' ) . ' |
|---|---|---|
| ' . $style['file_url'] . ' | ' . $style['font_families'] . ' | ' . $style['variant'] . ' |
⏳Fetching Performance Data…... Please wait.
'); $.when( $.get(mobileApiUrl), $.get(desktopApiUrl) ).done(function(mobileResponse, desktopResponse) { var mobileScore = Math.round(mobileResponse[0].lighthouseResult.categories.performance.score * 100); var desktopScore = Math.round(desktopResponse[0].lighthouseResult.categories.performance.score * 100); var mobileSpeed = (mobileResponse[0].lighthouseResult.audits['speed-index'].numericValue / 1000).toFixed(2); var desktopSpeed = (desktopResponse[0].lighthouseResult.audits['speed-index'].numericValue / 1000).toFixed(2); var resultHtml = '⚠️ Error fetching speed test results.
'); }); }); }); JS; wp_add_inline_script( 'jquery', $script ); } } new EasyFonts_Options();