Skip to main content
MainWP Dashboard 6.4 adds mainwp_get_sql_where_allow_access_sites. Call this filter from Dashboard-side PHP code to retrieve the existing site-access SQL conditions for a custom site query.

Retrieve the Conditions

Run the code after MainWP has initialized its hooks:
The third argument is the table alias used for the MainWP sites table in your query. Use a fixed alias defined by your code, such as wp. The returned conditions use MainWP’s existing site-access query logic and exclude staging sites. The result depends on the current execution context.

Preserve Permission Checks

Use this helper to reuse query conditions, not as a standalone authorization check. Your code must still check the current user’s operation permissions, site access, and any applicable ownership restrictions. Cron, WP-CLI, and REST execution contexts can use different access handling from an interactive Dashboard request. Continue using prepared queries for values supplied by users. Do not accept a table alias or SQL fragment from request data.