Advanced

Developer Reference

Published · Last updated

Scalability Pro exposes a set of PHP constants and one add-on registration filter for developers who need to tune its behaviour beyond what the settings screens offer, or who are building an add-on that plugs into it. This article covers the configuration constants you can define in wp-config.php, how to set them, and how the spro_register_addons filter lets an external plugin load alongside it.

Every constant listed here is defined with a guard in the plugin’s defines.php, so defining it earlier (in wp-config.php) always wins. Anything not listed here is either internal or not consumed by the current code, so leave it alone.

Configuration constants

ConstantDefaultPurpose
SPRO_ATTRIBUTE_AJAX_LIMIT10Number of attribute terms fetched per request when the Ajax Attribute Editing feature is active. Keeps the product editor responsive on attributes with very large term sets. Set to 0 to disable the limiting behaviour entirely.
SPRO_KEEP_DEFER_TERM_COUNTS_OPTIONtrueKeeps the Defer Term Counting option and its supporting code active. When falsey, the deferred term-count machinery is not wired up.
SPRO_ALWAYS_DO_TERM_RECOUNTSarray('nav_menu', 'link_category', 'post_format', 'wp_theme', 'wp_template_part_area', 'elementor_library_type', 'elementor_library_category')Taxonomies that are always recounted even while Defer Term Counting is deferring counts for everything else. Redefine the array to add your own taxonomies.
SPRO_REMOVE_SORT_ORDER_POST_TYPESarray('product', array('product', 'product_variation'))Post types for which the natural (menu-order) sort clause is removed, avoiding an expensive sort on large archives. Only applies when the natural sort-order option is set and no explicit orderby is requested.
SPRO_SQL_CALC_ROWS_FINGERPRINTarray()Stack-trace fingerprints used to widen removal of SQL_CALC_FOUND_ROWS. By default only the main query is stripped; add substrings that appear in a query’s stack trace (for example a plugin folder or calling function) to strip it from those queries too.
SPRO_CACHE_PMXE_META_KEYSfalseEnables caching of the distinct meta-key list WP All Export builds when exporting a custom post type, which is otherwise a slow scan of postmeta.
SPRO_PREVENT_WPAI_DUP_CHECKfalseWhen true, short-circuits WP All Import’s in-file duplicate check, which scans the import file for duplicates and is wasteful on large imports.
SPRO_NAV_MENU_OPTIMISATIONSfalseEnables the nav-menu query optimisations in the archive options code.
SPRO_ALLOW_NAV_MENU_ITEMS_FILTERSfalseQuery filters are normally suppressed for nav_menu_item queries, so the standard optimisations do not reach them. Set true to force suppress_filters off for those queries so the optimisations apply.

Two of these are booleans that are on by default (SPRO_KEEP_DEFER_TERM_COUNTS_OPTION) and off by default (SPRO_CACHE_PMXE_META_KEYS, SPRO_PREVENT_WPAI_DUP_CHECK, both nav-menu constants); the rest are numbers or arrays. Where a constant relates to a feature that has its own settings screen, the constant tunes the underlying behaviour rather than turning the feature on. See Ajax Attribute Editing for SPRO_ATTRIBUTE_AJAX_LIMIT and Defer Term Counting for SPRO_KEEP_DEFER_TERM_COUNTS_OPTION and SPRO_ALWAYS_DO_TERM_RECOUNTS.

Archives constants

These belong to the bundled Archives listing table. Each is defined only when not already defined, so set them in wp-config.php like the others.

ConstantDefaultPurpose
SPRO_DISABLE_ARCHIVESnot definedSet to true and the Archives code does not load at all: no Archives tab, no wp ssa commands, no abilities and no query changes. The emergency switch for a site where wp-admin will not load.
SSTR_DEBUGfalseWhen true, Archives prints the SQL it rewrote as HTML comments in the page source. For diagnosis only.
SSTR_MAX_PROFILE_URLS20Most pages, sorted and filtered together, that Enable good settings profiles before planning the table.
SSTR_MAX_SORT_PROFILE_URLS10Of those, the most sorted pages; filtered pages fill the room that is left.
SSTR_DISCOVERY_MAX_META_KEYS3Most custom fields Enable good settings adds to the table in one run.
SSTR_DISCOVERY_MIN_MS50A custom field is only added when a page filtering or sorting on it took at least this many milliseconds for its main query, measured with Archives off.

The sstr_discover_profile_urls filter receives the list of sorted pages good settings is about to profile (each an array of url and label), so you can add or remove sorted pages before it measures them.

How to set a constant

Define the constant in wp-config.php, above the line that says to stop editing. Because defines.php only defines each constant if it is not already defined, your value takes precedence.

define('SPRO_ATTRIBUTE_AJAX_LIMIT', 25);

define('SPRO_ALWAYS_DO_TERM_RECOUNTS', array(
    'nav_menu',
    'link_category',
    'post_format',
    'product_cat',
));

define('SPRO_SQL_CALC_ROWS_FINGERPRINT', array(
    'my-plugin/includes/class-archive-query.php',
));

Array constants replace the default wholesale, so if you are adding to SPRO_ALWAYS_DO_TERM_RECOUNTS include the existing entries you still want alongside your additions.

Arrays replace, they do not merge

Redefining an array constant overwrites the default array entirely, it does not append to it. Copy the default entries you still want into your define() alongside your additions, or you will silently drop taxonomies (or fingerprints) the plugin was relying on.

Registering an add-on

Scalability Pro can host add-on plugins. An add-on registers through the spro_register_addons filter, which passes an array keyed by add-on slug. Each entry must declare a dir (the add-on’s base directory). On plugins_loaded at priority 10, Scalability Pro applies the filter and requires tabs/<slug>/functions.php from that directory, which is where the add-on bootstraps its classes, hooks and CLI commands.

The slug is the array key, and it is what forms the tabs/<slug>/ path, so the add-on’s files must live under a folder matching that key. Add the filter during your own plugin’s load, unconditionally:

add_filter('spro_register_addons', function ($addons) {
    $addons['my-addon'] = array(
        'plugin_file' => __FILE__,
        'dir'         => MY_ADDON_PLUGIN_DIR,
        'version'     => MY_ADDON_VERSION,
        'label'       => 'My Add-on',
    );
    return $addons;
});

The filter only runs when Scalability Pro is active, so an add-on registered this way stays dormant without it. Do not wrap the registration in defined('SPROPLUGIN_DIR') at file load: WordPress loads plugins alphabetically, so a plugin whose folder sorts before scalability-pro runs before that constant exists and never registers. If your add-on needs to know whether Scalability Pro is present for its own code, check defined('SPROPLUGIN_DIR') on plugins_loaded or later.

The loader uses require_once, so an add-on that also registers with another parent (Super Speedy Filters has an equivalent loader) will not redeclare its functions when both parents resolve to the same file.

Registering does not give an add-on a settings tab. The Scalability Pro settings page has a tab only for the bundled Archives module, which registers through this same filter under the archives slug. Pick a different slug for your own add-on, and do not ship a tabs/<slug>/tab.php: the tab row lists only Scalability Pro’s own tabs and Archives, so another add-on’s tab has no place in it.

Best practice

Add the spro_register_addons filter unconditionally during your own plugin’s load, with a slug other than archives, and keep everything the add-on does inside tabs/<slug>/functions.php. It then loads exactly when Scalability Pro is active, whatever order the plugins load in.

Notes

A few constants are internal and not intended for you to redefine, though they are handy to read. SPRO_VERSION holds the plugin version (read from the plugin header), SPRO_PLUGIN_NAME is the display name, and SPROPLUGIN_DIR is the plugin’s base directory, which is the value an add-on checks before registering.

SPRO_DB_VERSION (currently 6.13) tracks the schema version of Scalability Pro’s own tables and drives upgrade routines, so treat it as read-only. SPRO_ROW_CACHE_KEY is an internal cache-key prefix for the cached admin list tables and should not be redefined. If you are relying on the Remove Image Sizes Globally feature, note that it is driven by its own settings rather than a constant, so configure it from the settings screen rather than in wp-config.php.

WordPress Abilities API and MCP

On WordPress versions that provide the Abilities API, Scalability Pro registers 12 abilities in the spro namespace: get-settings, describe-settings, measure, set-settings, apply-setting, get-index-status, describe-recommended, apply-recommended, scan-options, get-options-plan, apply-options-plan and revert-options-plan. The read abilities inspect, measure and plan; safe writes use set-settings; confirmed changes use the dedicated apply/revert paths.

The capability split is spro_manage for inspection and safe settings, and spro_apply for confirmed changes. Administrators inherit both from manage_options. The shared Super Speedy bridge exposes permitted abilities through one site-wide connection; Scalability Pro registers no dedicated MCP server. Older WordPress versions simply skip the Abilities integration.

Archives registers 7 more abilities in the super-speedy-archives namespace: get-status, describe-config and get-config read; plan-from-analysis plans from a Performance Analysis run without writing; apply-from-analysis, start-build and delete-table need confirm: true. Reading and planning need the ssa_manage capability, and the three writes need ssa_execute; administrators have both. On the command line the same work is wp ssa build, status, enable, disable, configure and configure-from-analysis.

The measure ability accepts at most ten URLs on the site’s exact scheme, host and port, plus the named post-count, recent-posts and term-count database probes. It never accepts arbitrary SQL.

Further reading

the listing table, its wp ssa commands and its constants in context
the settings-screen equivalents of the behaviours these constants tune
where the plugin’s own options live and how they are stored

Comments