Skip to content

Conversation

Copy link

Copilot AI commented Dec 9, 2025

The get_keymaps() function throws "Undefined offset: 1" notices on single-site installations when processing cache keys. After applying array_slice() to remove key prefixes, the code accesses $parts[1] without validation.

Changes

  • Add empty array check after offset slicing to skip malformed keys
  • Add isset($parts[1]) guard before accessing second element in multisite branch
// Remove key salts
if ( $offset > 0 ) {
    $parts = array_slice( $parts, $offset );
}

// Skip if not enough parts after offset
if ( empty( $parts ) ) {
    continue;
}

// Multisite means first part is numeric
if ( is_numeric( $parts[ 0 ] ) ) {
    // Skip if missing group part
    if ( ! isset( $parts[ 1 ] ) ) {
        continue;
    }
    $blog_id = (int) $parts[ 0 ];
    $group   = $parts[ 1 ];
    $global  = false;

This prevents notices while preserving existing behavior for well-formed cache keys.

Original prompt

This section details on the original issue you should resolve

<issue_title>Strange keys, undefined index</issue_title>
<issue_description>Trying the plugin out, keep getting some odd behavior. The plugin was installed via composer (5.0.0), copied drop-ins, activated the plugin. At first, it didn't show any results on the admin page, although a number of SQL queries dropped, indicating the object cache is working. Installed php-memcache extension (by default, Laravel's Homestead box includes only php-memcached), now there are some keys, but they don't look real:

screen shot 2017-08-11 at 12 08 25

The value of all keys is the same and equals -1.

Also, I'm getting this notice dumped multiple times to debug.log:

[11-Aug-2017 09:01:59 UTC] PHP Notice:  Undefined offset: 1 in /home/vagrant/Code/ihorvorotnov/app/plugins/wp-spider-cache/wp-spider-cache.php on line 787
[11-Aug-2017 09:01:59 UTC] PHP Stack trace:
[11-Aug-2017 09:01:59 UTC] PHP   1. {main}() /home/vagrant/Code/ihorvorotnov/core/wp-admin/admin-ajax.php:0
[11-Aug-2017 09:01:59 UTC] PHP   2. do_action() /home/vagrant/Code/ihorvorotnov/core/wp-admin/admin-ajax.php:91
[11-Aug-2017 09:01:59 UTC] PHP   3. WP_Hook->do_action() /home/vagrant/Code/ihorvorotnov/core/wp-includes/plugin.php:453
[11-Aug-2017 09:01:59 UTC] PHP   4. WP_Hook->apply_filters() /home/vagrant/Code/ihorvorotnov/core/wp-includes/class-wp-hook.php:323
[11-Aug-2017 09:01:59 UTC] PHP   5. WP_Spider_Cache_UI->ajax_get_instance() /home/vagrant/Code/ihorvorotnov/core/wp-includes/class-wp-hook.php:298
[11-Aug-2017 09:01:59 UTC] PHP   6. WP_Spider_Cache_UI->do_rows() /home/vagrant/Code/ihorvorotnov/app/plugins/wp-spider-cache/wp-spider-cache.php:370
[11-Aug-2017 09:01:59 UTC] PHP   7. WP_Spider_Cache_UI->get_keymaps() /home/vagrant/Code/ihorvorotnov/app/plugins/wp-spider-cache/wp-spider-cache.php:1047

Line 787 is a multisite related check. The site is not multisite though.

My environment:

  • latest Laravel's Homestead,
  • PHP 7.1.8 (fpm, with Nginx),
  • php-memcache 3.0.9,
  • php-memcached 3.0.3,
  • Memcached 1.4.25,
  • Latest WP (4.8.1)

Some other plugins are installed - mostly dev related (Query Monitor, Laps etc). Deactivating them doesn't fix the problem.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI assigned Copilot and JJJ Dec 9, 2025
Copilot AI changed the title [WIP] Fix undefined index notice in wp-spider-cache plugin Fix undefined array offset in get_keymaps() after offset slicing Dec 9, 2025
Copilot AI requested a review from JJJ December 9, 2025 03:28
@JJJ JJJ requested a review from Copilot December 9, 2025 03:43
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes "Undefined offset: 1" notices that occur in the get_keymaps() function on single-site WordPress installations when processing cache keys. After applying array_slice() to remove key prefixes, the code attempted to access array elements without proper validation.

Key Changes

  • Added empty($parts) check after offset slicing to skip malformed keys that result in empty arrays
  • Added isset($parts[1]) guard before accessing the second array element in the multisite code path

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Strange keys, undefined index

2 participants