Suggestion for Parameters API Docs: Performance Best Practices for Dynamic Data

Hi theme.co team!

I’ve dived deeper into the Cornerstone Parameters API recently to create dynamic select controls (e.g., populating a dropdown with Taxonomy Terms via get_terms ).

While this works functionally, it creates a potential performance bottleneck for dynamic data if i use this in a 'init' hook for example. If we run a heavy DB query (like get_terms or WP_Query ) inside the init hook to populate the options array, this query runs on every single page load (Frontend, Backend, AJAX), even when Cornerstone is not active.

My Findings: I discovered that a much more performant approach is to “lazy load” the cornerstone_before_boot_app hook.

By moving the logic into this filter, the database queries are only executed when the Cornerstone Builder actually loads , saving resources on the frontend and standard WP Admin pages.

Do you see any possible issues with using this hook?

If not I would suggest adding this info to the “Parameters API” documentation.

Thanks in advance

Hey @Regnalf,

cornerstone_before_boot_app is not in our doc because it’s meant to be used internally in Cornerstone. You can use it but we cannot support any issues that will arise from the use of it.

We have not used the hook outside of it’s intended function so we can’t have no idea about its pros and cons. If you do find it useful, you’re free to share your findings here and we appreciate it.

Thank you.

Okay, then I’ll ask the question the other way around. Is there a hook I can use that only fires when Cornerstone is loaded, which would be suitable for the parameter API with get terms?

Because your filter cs_parameters_managed is running allways in WordPress backend, and outside cornerstone before the init hook where i register my taxonomies!

You can use cornerstone_before_boot_app and be just fine if it’s already working fine. We don’t have many docs on integrating with the App UI, but certain things are possible. We do need to run those managed parameters everywhere because you can set the default value via initial.

1 Like

Thanks, @charlie, for the confirmation.

You are most welcome, @Regnalf

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.