Plugin Directory

Changeset 2961908


Ignore:
Timestamp:
09/02/2023 09:00:33 AM (3 years ago)
Author:
easywpstuff
Message:

update

Location:
use-bunnyfont-host-google-fonts
Files:
73 added
3 edited

Legend:

Unmodified
Added
Removed
  • use-bunnyfont-host-google-fonts/trunk/bunnyfont.php

    r2931777 r2961908  
    55 * Plugin URI: https://wordpress.org/plugins/use-bunnyfont-host-google-fonts/
    66 * Description: Disable and remove google fonts or simply replace all Google Fonts with BunnyFonts (GDPR friendly)
    7  * Version: 1.4.2
     7 * Version: 1.5
    88 * Author: easywpstuff
    99 * Author URI: https://easywpstuff.com/
     
    5454
    5555require BFH_PATH . "/inc/options.php";
    56 
     56require BFH_PATH . "/vendor/autoload.php";
    5757/**
    5858 * Begins execution of the plugin.
     
    6262function bfh_run_bunnyfont( $html ) {
    6363    $html = str_replace('fonts.googleapis.com', 'fonts.bunny.net', $html);
    64     $html = str_replace('fonts.gstatic.com" crossorigin', 'fonts.bunny.net" crossorigin', $html);
    65     $html = str_replace("fonts.gstatic.com' crossorigin", "fonts.bunny.net' crossorigin", $html);
     64    $html = preg_replace_callback('/<link[^>]+>/', function($match) {
     65    // Check if the <link> tag contains crossorigin, fonts.gstatic, and prefetch or preconnect
     66    if (strpos($match[0], 'crossorigin') !== false
     67        && strpos($match[0], 'fonts.gstatic') !== false
     68        && (strpos($match[0], 'prefetch') !== false || strpos($match[0], 'preconnect') !== false)
     69    ) {
     70        // Replace fonts.gstatic.com with fonts.bunny.net
     71        $match[0] = str_replace('fonts.gstatic.com', 'fonts.bunny.net', $match[0]);
     72    }
     73    return $match[0];
     74}, $html);
    6675    return $html;
    6776}
     
    8897function bfh_remove_google_add_bunny($output) {
    8998   
    90     $output = str_replace('fonts.googleapis.com', 'fonts.bunny.net', $output);
    91     $output = str_replace('fonts.gstatic.com" crossorigin', 'fonts.bunny.net" crossorigin', $output);
    92     $output = str_replace("fonts.gstatic.com' crossorigin", "fonts.bunny.net' crossorigin", $output);
    93    
    94     // Remove Google fonts
    95     $output = preg_replace('/<link\s+[^>]*?href=["\']?(?<url>(?:https?:)?\/\/fonts\.googleapis\.com\/[^"\'>]+)["\']?[^>]*?>/', '', $output);
    96    
    97     $output = preg_replace('/@font-face\s*\{[^\}]*?src:\s*url\([\'"]?(?<url>(?:https?:)?\/\/fonts\.gstatic\.com\/[^\'"]+)[\'"]?\).*?\}/s', '', $output);
    98    
    99     $output = preg_replace('/@import\s+url\([\'"]?(?<url>(?:https?:)?\/\/fonts\.googleapis\.com\/[^\'"]+)[\'"]?\);/', '', $output);
    100    
    101     $output = preg_replace('/<script[^>]*>([^<]*WebFontConfig[^<]*googleapis\.com[^<]*)<\/script>/', '', $output);
     99    $output = bfh_run_bunnyfont( $output );
     100    $output = bfh_remove_google_fonts( $output );
    102101   
    103102    return $output;
     
    115114
    116115// run bunnyfont function
     116
     117function bfh_choose_ob_start_callback() {
     118  $options = get_option('bunnyfonts_options');
     119
     120  // Define the default callback
     121  $callback = null;
     122
     123  // Check if the replace font option is enabled
     124  if (isset($options['replace_google_fonts']) && $options['replace_google_fonts'] && !isset($options['block_google_fonts'])) {
     125    $callback = 'bfh_run_bunnyfont';
     126      add_filter( 'wordpress_prepare_output', 'bfh_run_bunnyfont', 11 );
     127      add_filter('groovy_menu_final_output', 'bfh_run_bunnyfont', 11);
     128  }
     129
     130  // Check if remove font option is enabled
     131  if (isset($options['block_google_fonts']) && $options['block_google_fonts'] && !isset($options['replace_google_fonts'])) {
     132    $callback = 'bfh_remove_google_fonts';
     133      add_filter( 'wordpress_prepare_output', 'bfh_remove_google_fonts', 11 );
     134      add_filter('groovy_menu_final_output', 'bfh_remove_google_fonts', 11);
     135  }
     136
     137  // Check if both options are enabled
     138  if (isset($options['block_google_fonts']) && $options['block_google_fonts'] && isset($options['replace_google_fonts']) && $options['replace_google_fonts']) {
     139    $callback = 'bfh_remove_google_add_bunny';
     140      add_filter( 'wordpress_prepare_output', 'bfh_remove_google_add_bunny', 11 );
     141      add_filter('groovy_menu_final_output', 'bfh_remove_google_add_bunny', 11);
     142  }
     143
     144  if ($callback !== null) {
     145    ob_start($callback);
     146  }
     147}
     148
    117149function run_bunnyfont_template_redirect() {
    118   $options = get_option('bunnyfonts_options');
    119     // check if the replace font option is enabled
    120    if (isset($options['replace_google_fonts']) && $options['replace_google_fonts'] && !isset($options['block_google_fonts'])) {
    121     ob_start('bfh_run_bunnyfont');
    122   }
    123     // check if remove font option is enabled
    124   if (isset($options['block_google_fonts']) && $options['block_google_fonts'] && !isset($options['replace_google_fonts'])) {
    125     ob_start('bfh_remove_google_fonts');
    126   }
    127     // check if both option is enabled
    128     if (isset($options['block_google_fonts']) && $options['block_google_fonts'] && isset($options['replace_google_fonts']) && $options['replace_google_fonts']) {
    129     ob_start('bfh_remove_google_add_bunny');
    130   }
    131 }
    132 add_action('template_redirect', 'run_bunnyfont_template_redirect', 9);
     150  // Call the function to choose the ob_start callback
     151  bfh_choose_ob_start_callback();
     152}
     153
     154add_action('template_redirect', 'run_bunnyfont_template_redirect', -1000);
     155
    133156
    134157
     
    158181}
    159182add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'bunnyadd_settings_link' );
     183
     184
     185/**
     186 * Initialize the plugin tracker
     187 *
     188 * @return void
     189 */
     190function appsero_init_tracker_use_bunnyfont_host_google_fonts() {
     191
     192    if ( ! class_exists( 'Appsero\Client' ) ) {
     193      require_once __DIR__ . '/appsero/src/Client.php';
     194    }
     195
     196    $client = new Appsero\Client( '84913d70-971f-41dc-b310-6aed8fcfc989', 'Replace or Remove Google fonts', __FILE__ );
     197
     198    // Active insights
     199    $client->insights()->init();
     200
     201}
     202
     203appsero_init_tracker_use_bunnyfont_host_google_fonts();
  • use-bunnyfont-host-google-fonts/trunk/inc/options.php

    r2860127 r2961908  
    3737      submit_button('Save Changes');
    3838      ?>
    39     </form>
     39    </form><script>jQuery(document).ready(function(e){var o=e("#replace_google_fonts"),t=e('td label[for="block_google_fonts"]'),n="This option will remove the remaining Google Fonts that are not compatible with the Bunnyfonts replacement.",l="This option will remove all the Google fonts from HTML.";o.prop("checked")?t.text(n):t.text(l),o.change(function(){o.prop("checked")?t.text(n):t.text(l)})});</script>
    4040  </div><div class="easy"><p>
    4141   
  • use-bunnyfont-host-google-fonts/trunk/readme.txt

    r2931777 r2961908  
    44Tags: remove google fonts, disable google fonts, GDPR, google fonts, speed
    55Requires at least: 5.0
    6 Tested up to: 6.2.2
     6Tested up to: 6.3
    77Requires PHP: 5.6
    8 Stable tag: 1.4.2
     8Stable tag: 1.5
    99License: GNU General Public License v2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    5555
    5656== Changelog ==
     57= 1.5 =
     58* Added Support for Smart Slider and Groovy Menu.
     59* Fixed Minor Issues.
    5760= 1.4 =
    5861* Improved font removal
     
    6669= 1.0 =
    6770* Initial release.
     71
     72
     73## Privacy Policy
     74This plugin uses [Appsero](https://appsero.com) SDK to collect some telemetry data upon user's confirmation. This helps us to troubleshoot problems faster & make product improvements.
     75
     76Appsero SDK **does not gather any data by default.** The SDK only starts gathering basic telemetry data **when a user allows it via the admin notice**. We collect the data to ensure a great user experience for all our users.
     77
     78Integrating Appsero SDK **DOES NOT IMMEDIATELY** start gathering data, **without confirmation from users in any case.**
     79
     80Learn more about how [Appsero collects and uses this data](https://appsero.com/privacy-policy/).
Note: See TracChangeset for help on using the changeset viewer.