Performance: Reading and writing settings
MEDIUM IMPACT
This concept affects page load speed and interaction responsiveness by how settings are accessed and saved in WordPress.
<?php // Read once and cache in variable $setting = get_option('my_plugin_setting'); // Use $setting multiple times without extra calls // Write once after all changes update_option('my_plugin_setting', $final_value); ?>
<?php // Reading settings multiple times in a single request $setting1 = get_option('my_plugin_setting'); // ... some code ... $setting2 = get_option('my_plugin_setting'); // Writing settings multiple times update_option('my_plugin_setting', $new_value); update_option('my_plugin_setting', $new_value2); ?>
| Pattern | Database Queries | Writes | Blocking Time | Verdict |
|---|---|---|---|---|
| Multiple get_option/update_option calls | Multiple queries | Multiple writes | Blocks rendering 50-100ms | [X] Bad |
| Single get_option and one update_option | Single query | Single write | Minimal blocking | [OK] Good |