Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined index: ip_address in […]classes/class-log.php on line 204 #1010

Closed
kasparsd opened this issue Jun 21, 2019 · 7 comments · Fixed by #1034
Closed

Undefined index: ip_address in […]classes/class-log.php on line 204 #1010

kasparsd opened this issue Jun 21, 2019 · 7 comments · Fixed by #1034
Labels

Comments

@kasparsd
Copy link
Contributor

See https://wordpress.org/support/topic/notice-undefined-index-ip_address-in-classes-class-log-php-on-line-204/

When adding a new user in WordPress (Multisite), I get the following Notice:

Notice: Undefined index: ip_address in wp-content/plugins/stream/classes/class-log.php on line 204

I have several excludes defined that follow the rule of excluding a role like “Subscriber” while leaving all other fields empty which defaults to “Any …”.

I tried saving the excludes again, or adding other rules with the same scheme, but still, $multisite_options['exclude_rules'] does not include an index ip_address.

@kasparsd kasparsd added the bug label Jul 1, 2019
@tyrann0us
Copy link

@kasparsd, are there any updates on this issue? Thanks!

@kasparsd
Copy link
Contributor Author

@tyrann0us I haven't been able to replicate the issue, yet.

@tyrann0us
Copy link

The bug can be reproduced by following these steps:

  1. Create multisite
  2. Activate plugin network-wide
  3. Go to Stream's network settings
  4. Add exclude rule but keep IP address dropdown empty
  5. Save settings
  6. Edit any user in backend
  7. Save user

The bug is caused because empty select fields aren't submitted, which is the case in Stream's settings page. Thus, the wp_stream_network site meta doesn't contain (empty) ip_address keys (as it does for other columns, e.g. action):

[…]
'exclude_rules' => 
  array (
    'exclude_row' => 
    array (
      0 => '',
    ),
    'author_or_role' => 
    array (
      0 => 'administrator',
    ),
    'connector' => 
    array (
      0 => '',
    ),
    'context' => 
    array (
      0 => '',
    ),
    'action' => 
    array (
      0 => '',
    ),
    // 'ip_address' array missing.
  ),
[…]

But in Log::log(), the ip_address index is accessed without check for existence. A solution would be to always save the ip_address key in wp_stream_network.

BTW, I don't know if the but applies to the single sites too; have not tested it.

@kasparsd
Copy link
Contributor Author

This is great, thank you so much for the detailed steps.

@tyrann0us
Copy link

Note that the plugin does not correctly save multiple lines of exclude rules if some of them contain empty IP adresses. I think this is related to missing empty ip_address keys.

@kasparsd
Copy link
Contributor Author

@tyrann0us Could you please test the #1034 changeset by checking out the fix/ip-address branch?

@tyrann0us
Copy link

LGTM. The warning cannot be reproduced. Thanks!

However, the issue of incorrectly stored exclude rules if some of them have not set IP addresses (see my comment above) is still not resolved and therefore probably not associated with this bug.
I have created a new issue for this: #1035.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants