Plugin Directory

Changeset 3394862


Ignore:
Timestamp:
11/13/2025 09:21:31 AM (4 months ago)
Author:
chrmrtns
Message:

Version 1.1.8: Add CSS regeneration feature to prevent fonts.css overwrite on plugin updates

  • NEW: Manual CSS regeneration button in Settings page
  • NEW: Automatic CSS regeneration after plugin updates
  • IMPROVEMENT: fonts.css automatically regenerates when plugin is updated
Location:
safefonts/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • safefonts/trunk/assets/js/admin.js

    r3390097 r3394862  
    1212            this.initBulkActions();
    1313            this.initTabs();
     14            this.initCssRegeneration();
    1415        },
    1516
     
    173174                $('.safefonts-tab-content').hide();
    174175                $(target).show();
     176            });
     177        },
     178
     179        initCssRegeneration: function() {
     180            $('#safefonts-regenerate-css').on('click', function(e) {
     181                e.preventDefault();
     182                SafeFontsAdmin.handleCssRegeneration($(this));
     183            });
     184        },
     185
     186        handleCssRegeneration: function($button) {
     187            const nonce = $button.data('nonce');
     188            const $result = $('#safefonts-regenerate-css-result');
     189
     190            // Disable button and show loading state
     191            $button.prop('disabled', true);
     192            $button.text(safefontsAjax.strings.regenerating);
     193            $result.empty();
     194
     195            $.ajax({
     196                url: safefontsAjax.ajaxurl,
     197                type: 'POST',
     198                data: {
     199                    action: 'regenerate_safefonts_css',
     200                    nonce: nonce
     201                },
     202                success: function(response) {
     203                    $button.prop('disabled', false);
     204                    $button.text('Regenerate CSS');
     205
     206                    if (response.success) {
     207                        $result.html('<div class="notice notice-success inline"><p>' + response.data + '</p></div>');
     208
     209                        // Clear success message after 5 seconds
     210                        setTimeout(function() {
     211                            $result.fadeOut(300, function() {
     212                                $(this).empty().show();
     213                            });
     214                        }, 5000);
     215                    } else {
     216                        $result.html('<div class="notice notice-error inline"><p>' + safefontsAjax.strings.regenerate_error + ': ' + response.data + '</p></div>');
     217                    }
     218                },
     219                error: function() {
     220                    $button.prop('disabled', false);
     221                    $button.text('Regenerate CSS');
     222                    $result.html('<div class="notice notice-error inline"><p>' + safefontsAjax.strings.regenerate_error + '</p></div>');
     223                }
    175224            });
    176225        },
  • safefonts/trunk/includes/Admin/AdminInterface.php

    r3393584 r3394862  
    154154                'delete_error' => __('Failed to delete font', 'safefonts'),
    155155                'font_family_required' => __('Font family name is required', 'safefonts'),
     156                'regenerating' => __('Regenerating CSS...', 'safefonts'),
     157                'regenerate_success' => __('CSS regenerated successfully!', 'safefonts'),
     158                'regenerate_error' => __('Failed to regenerate CSS', 'safefonts'),
    156159            )
    157160        ));
     
    592595                        </td>
    593596                    </tr>
     597
     598                    <tr>
     599                        <th scope="row">
     600                            <?php esc_html_e('Font CSS', 'safefonts'); ?>
     601                        </th>
     602                        <td>
     603                            <button type="button"
     604                                    id="safefonts-regenerate-css"
     605                                    class="button"
     606                                    data-nonce="<?php echo esc_attr(wp_create_nonce('regenerate_safefonts_css')); ?>">
     607                                <?php esc_html_e('Regenerate CSS', 'safefonts'); ?>
     608                            </button>
     609                            <p class="description">
     610                                <?php esc_html_e('Manually regenerate the fonts.css file. This is useful if fonts aren\'t displaying correctly after an update.', 'safefonts'); ?>
     611                            </p>
     612                            <div id="safefonts-regenerate-css-result" style="margin-top: 10px;"></div>
     613                        </td>
     614                    </tr>
    594615                </table>
    595616
  • safefonts/trunk/includes/Core.php

    r3394834 r3394862  
    106106            add_action('init', array($this, 'register_font_collection'));
    107107        }
     108
     109        // AJAX handler for CSS regeneration
     110        add_action('wp_ajax_regenerate_safefonts_css', array($this, 'handle_regenerate_css_ajax'));
     111
     112        // Auto-regenerate CSS after plugin updates
     113        add_action('upgrader_process_complete', array($this, 'regenerate_css_after_update'), 10, 2);
    108114
    109115        // Register activation/deactivation hooks
     
    420426        // Default to sans-serif
    421427        return 'sans-serif';
     428    }
     429
     430    /**
     431     * AJAX handler for CSS regeneration
     432     *
     433     * @return void
     434     */
     435    public function handle_regenerate_css_ajax() {
     436        // Verify nonce
     437        check_ajax_referer('regenerate_safefonts_css', 'nonce');
     438
     439        // Check user permissions
     440        if (!current_user_can('manage_options')) {
     441            wp_send_json_error(__('Insufficient permissions', 'safefonts'));
     442        }
     443
     444        // Regenerate CSS
     445        $result = $this->generate_fonts_css();
     446
     447        if ($result) {
     448            wp_send_json_success(__('Font CSS successfully regenerated!', 'safefonts'));
     449        } else {
     450            wp_send_json_error(__('Failed to regenerate CSS file. Please check file permissions.', 'safefonts'));
     451        }
     452    }
     453
     454    /**
     455     * Regenerate CSS after plugin update
     456     *
     457     * @param \WP_Upgrader $upgrader Upgrader instance
     458     * @param array        $options  Update options
     459     * @return void
     460     */
     461    public function regenerate_css_after_update($upgrader, $options) {
     462        // Check if this is a plugin update
     463        if ($options['type'] !== 'plugin' || $options['action'] !== 'update') {
     464            return;
     465        }
     466
     467        // Check if SafeFonts was updated
     468        if (isset($options['plugins'])) {
     469            foreach ($options['plugins'] as $plugin) {
     470                if ($plugin === plugin_basename(CHRMRTNS_SAFEFONTS_PLUGIN_FILE)) {
     471                    // Regenerate CSS silently
     472                    $this->generate_fonts_css();
     473                    break;
     474                }
     475            }
     476        }
    422477    }
    423478
  • safefonts/trunk/readme.txt

    r3394846 r3394862  
    44Requires at least: 6.2
    55Tested up to: 6.8
    6 Stable tag: 1.1.7
     6Stable tag: 1.1.8
    77Requires PHP: 7.4
    88License: GPLv2 or later
     
    209209
    210210== Changelog ==
     211
     212= 1.1.8 =
     213* NEW: Manual CSS regeneration button in Settings page for refreshing fonts.css when needed
     214* NEW: Automatic CSS regeneration after plugin updates to prevent font display issues
     215* IMPROVEMENT: fonts.css automatically regenerates when plugin is updated via WordPress auto-update or manual update
    211216
    212217= 1.1.7 =
  • safefonts/trunk/safefonts.php

    r3394834 r3394862  
    44 * Plugin URI: https://safefonts.com
    55 * Description: Secure font management for WordPress with Gutenberg integration and local hosting for GDPR compliance.
    6  * Version: 1.1.7
     6 * Version: 1.1.8
    77 * Requires at least: 6.2
    88 * Requires PHP: 7.4
     
    2121
    2222// Define plugin constants
    23 define('CHRMRTNS_SAFEFONTS_VERSION', '1.1.7');
     23define('CHRMRTNS_SAFEFONTS_VERSION', '1.1.8');
    2424define('CHRMRTNS_SAFEFONTS_PLUGIN_FILE', __FILE__);
    2525define('CHRMRTNS_SAFEFONTS_PLUGIN_DIR', plugin_dir_path(__FILE__));
Note: See TracChangeset for help on using the changeset viewer.