Skip to content

Commit

Permalink
Merge pull request #15 from soderlind/fix/include
Browse files Browse the repository at this point in the history
Catch errors in the cache handler.
  • Loading branch information
soderlind authored Jun 12, 2024
2 parents 6bc60dc + 07ee814 commit 58f61cd
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Changelog

### 2.3.1

- Catch errors in the cache handler. If the cache file is corrupt, update the file and return the .mo file.

### 2.3.0

- If running WordPress 6.5, give a notice that the plugin is not needed.
Expand Down
18 changes: 11 additions & 7 deletions a-faster-load-textdomain.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Plugin Name: A faster load_textdomain
* Version: 2.3.0
* Version: 2.3.1
* Description: Cache the .mo file as an PHP array, and load the array instead of the .mo file.
* Author: Per Soderlind
* Author URI: https://soderlind.no
Expand Down Expand Up @@ -76,7 +76,7 @@ function a_faster_load_textdomain( $loaded, $domain, $mofile, $locale = null ) {
}

// Prepare the data to be cached.
$data = [
$data = [
'mtime' => $mtime, // The last modification time of the MO file.
'file' => $mofile, // The path to the MO file.
'entries' => $mo->entries, // The entries from the MO file.
Expand Down Expand Up @@ -111,13 +111,17 @@ function a_faster_load_textdomain( $loaded, $domain, $mofile, $locale = null ) {
\add_filter( 'override_load_textdomain', __NAMESPACE__ . '\a_faster_load_textdomain', 0, 3 );
}
if ( version_compare( $GLOBALS['wp_version'], '6.5', '>=' ) ) {
//admin messages
\add_action( 'admin_notices', function () {
?>
// admin messages
\add_action(
'admin_notices',
function () {
?>
<div class="notice notice-error">
<p><?php _e( '<strong>A faster load_textdomain</strong> is not needed in WordPress 6.5 and later, please deactivate the plugin.', 'a-faster-load-textdomain' ); ?></p>
<p><?php _e( 'The functionality is now <a href="https://make.wordpress.org/core/2024/02/27/i18n-improvements-6-5-performant-translations/">built into WordPress core</a>.', 'a-faster-load-textdomain' ); ?></p>
<p><?php _e( 'If you need to generate translation in the new <code>.l10n.php</code> format, use the <a href="https://wordpress.org/plugins/performant-translations/">Performant Translations</a> plugin', 'a-faster-load-textdomain' ); ?></p>
</div><?php
} );
</div>
<?php
}
);
}
14 changes: 9 additions & 5 deletions includes/class-afld-cachehandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,16 @@ public function get_cache_data( $file ) {
$cache_file = sprintf( '%s/%s-%s.php', $this->cache_path, $this->cache_file_prefix, md5( $file ) );

// If cache file exists, include it and return the data.
if ( file_exists( $cache_file ) ) {
include $cache_file;
return isset( $val ) ? $val : false;
} else {
return false;
try {
if ( file_exists( $cache_file ) ) {
include $cache_file;
} else {
$val = false;
}
} catch ( Error $e ) { // If there's an error, return false.
$val = false;
}
return isset( $val ) ? $val : false;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "a-faster-load-textdomain",
"version": "2.3.0",
"version": "2.3.1",
"description": "A faster load_textdomain",
"author": "Per Søderlind <[email protected]>",
"license": "GPL-2.0-or-later",
Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: l10n, load_textdomain, cache, performance
Requires at least: 5.9
Requires PHP: 7.4
Tested up to: 6.4
Stable tag: 2.3.0
Stable tag: 2.3.1
Donate link: https://paypal.me/PerSoderlind
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -60,6 +60,10 @@ It's also possible to install the plugin via Composer:

== Changelog ==

= 2.3.1 =

* Catch errors in the cache handler. If the cache file is corrupt, update the file and return the .mo file.

= 2.3.0 =

* If running WordPress 6.5, give a notice that the plugin is not needed.
Expand Down

0 comments on commit 58f61cd

Please sign in to comment.