Skip to content

Coding best practices

Thomas Steur edited this page Jul 7, 2021 · 1 revision

Performance

For performance we should avoid setting or fetching data from the DB (eg options) when bootstrapping the plugin classes.

For example instead of:

if (count(get_users() < 1000){
  add_action('foo', function () {
       // logic
  });
}

we get the users only in the action when it's needed as in 99.9% of the requests the action won't be triggered and therefore we load the data for no reason:

add_action('foo', function () {
    if (count(get_users() < 1000){
       // logic
    }
});