Skip to content

Commit

Permalink
Fixes PHP error while loading non-existent options on multi sites ins…
Browse files Browse the repository at this point in the history
…tances - see #8
  • Loading branch information
Pierre-Lannoy committed Nov 23, 2023
1 parent 31b4c6d commit 5f2992c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ All notable changes to **APCu Manager** are documented in this *changelog*.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and **APCu Manager** adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.7.2] - 2023-11-23

### Fixed
- In some edge-cases, multi sites instances may experience a PHP error while loading non-existent options (thanks to [Szabó József](https://github.com/er2es)).

## [3.7.1] - 2023-11-22

### Changed
Expand Down
17 changes: 16 additions & 1 deletion includes/api/object-class.php
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,21 @@ private function delete_non_persistent( $key ) {
return false;
}

/**
* Retrieves the current network ID.
*
* @since 3.7.2
*
* @return int The ID of the current network.
*/
private function get_current_network_id() {
global $current_site;
if ( is_multisite() && isset( $current_site ) && $current_site instanceof WP_Network && isset( $current_site->id ) ) {
return absint( $current_site->id );
}
return 1;
}

/**
* Retrieves the cache contents, if it exists.
*
Expand All @@ -958,7 +973,7 @@ public function get( $key, $group = 'default', $force = false, &$success = null,
if ( ! $is_option ) {
// Prevent non-existent options or site-options from triggering any queries if in notoptions!
if ( 'options' === $group || 'site-options' === $group ) {
$notoptions = $this->get( 'site-options' === $group ? get_current_network_id() . ':notoptions' : 'notoptions', $group, false, $success, true );
$notoptions = $this->get( 'site-options' === $group ? $this->get_current_network_id() . ':notoptions' : 'notoptions', $group, false, $success, true );
if ( is_array( $notoptions ) && isset( $notoptions[ $key ] ) ) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion init.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
define( 'APCM_PRODUCT_SHORTNAME', 'APCu' );
define( 'APCM_PRODUCT_ABBREVIATION', 'apcm' );
define( 'APCM_SLUG', 'apcu-manager' );
define( 'APCM_VERSION', '3.7.1' );
define( 'APCM_VERSION', '3.7.2-dev1' );
define( 'APCM_CODENAME', '"-"' );

define( 'APCM_CDN_AVAILABLE', true );
Expand Down

0 comments on commit 5f2992c

Please sign in to comment.