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

E_WARNING: Undefined array key 1 #689

Open
jhard opened this issue Feb 13, 2024 · 0 comments
Open

E_WARNING: Undefined array key 1 #689

jhard opened this issue Feb 13, 2024 · 0 comments

Comments

@jhard
Copy link

jhard commented Feb 13, 2024

E_WARNING in /var/www/public/wp-content/plugins/tablepress/libraries/freemius/includes/class-freemius.php:14598 Undefined array key 1

If an ajax request is being made and the endpoint URL is not inside wp-admin, freemius triggers a warning because it's trying to access a non-existant array key.

The bug is in the static function get_current_page():

if ( is_network_admin() ) {
        preg_match( '#/wp-admin/network/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches );
} else if ( is_user_admin() ) {
        preg_match( '#/wp-admin/user/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches );
} else {
        preg_match( '#/wp-admin/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches );
}
$pagenow = $self_matches[1];

preg_match will only fill self_matches if it actually matches something.

The solution is to check return values or using something like the null-coalescing operator, e.g. by turning the offending line into $pagenow = $self_matches[1] ?? "";.

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

No branches or pull requests

1 participant