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

Replace multiple hooks with a static check #46

Open
schlessera opened this issue Feb 8, 2018 · 0 comments
Open

Replace multiple hooks with a static check #46

schlessera opened this issue Feb 8, 2018 · 0 comments

Comments

@schlessera
Copy link
Contributor

Issue #40 correctly suggested to get rid of the global variable (globals are always bad and should be avoided at all cost).

However, the proposed solution in turns a single check into three function calls that are processed through major parts of the WordPress system (and, ironically, rely on multiple globals as well).

I better fix would have been to turn the global variable into a method-scoped static variable. Serves the same purpose, has no impact outside of the method and does not produce unneeded overhead.

So, something simple like this would have been preferable:

function whip_wp_check_versions( $requirements ) {
    // ...
    static $is_registered = false;
    if ( ! $is_registered ) {
        // Register!
        $is_registered = true;
    }
}

On subsequent calls, the first line is skipped at compile-time already, and the second immediately fails, skipping a duplicate registration.
No globals involved (even indirectly through $wp_filters).

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

No branches or pull requests

2 participants