Skip to content

OG Database Cleaner: developer's guide

This page lists what OG Database Cleaner exposes to code: filters, actions, REST routes, MCP tools, options, cron hooks and constants. For everyday use, see the user guide.

Items marked Full exist only in the full (paid) version. Everything else is in both the full version and the Lite. Both editions share the ogdbc_ prefix, the ogdbc_options option and the og-database-cleaner/v1 REST namespace.

The plugin has no shortcodes, no blocks and no WP-CLI commands.

Warning

Every delete route and tool removes data permanently. Test on a copy of the site, and back up first.

Filters

ogdbc_allow_setup

Who may read data and change settings. Most REST routes check it.

Argument Type Default
$allowed bool current_user_can( 'manage_options' )
add_filter( 'ogdbc_allow_setup', function ( $allowed ) {
    return $allowed && current_user_can( 'administrator' );
} );

ogdbc_allow_usage

Who may run the heavier actions: reset settings, log the database size, refresh or clear the logs, build or remove indexes and generate test data.

Argument Type Default
$allowed bool current_user_can( 'administrator' )

Note

The REST routes are only registered when the current user is an administrator, whatever these filters return. Custom queries always need an administrator (or a network super admin) and cannot be widened by a filter.

ogdbc_table_to_plugin, ogdbc_post_type_to_plugin, ogdbc_option_to_plugin, ogdbc_cron_to_plugin, ogdbc_metadata_to_plugin

Build the "Used by" maps. They run once per request, the first time an owner is looked up. ogdbc_metadata_to_plugin is Full only.

Argument Type Description
$map array Item name (table name without the database prefix, post type, option name, cron hook or meta key) mapped to 'WP' or to a list of owners.

Each owner is an array:

Key Type Description
plugin string The name shown in Used By.
slugs string[] Plugin or theme folder names. * matches always. A trailing -pro on an active plugin's folder is ignored.
native bool Optional. Marks the main owner, shown when none of the owners is active.
custom bool Optional. Set for owners assigned by hand; returned as is.

Tell Database Cleaner about your own plugin's data, so it shows as Used while your plugin is active:

add_filter( 'ogdbc_table_to_plugin', function ( $map ) {
    $map['myplugin_log'] = array(
        array( 'plugin' => 'My Plugin', 'slugs' => array( 'my-plugin' ) ),
    );
    return $map;
} );

add_filter( 'ogdbc_option_to_plugin', function ( $map ) {
    $map['myplugin_settings'] = array(
        array( 'plugin' => 'My Plugin', 'slugs' => array( 'my-plugin' ) ),
    );
    return $map;
} );

ogdbc_check_support_for_{$kind}

Last chance to name an owner when the maps above found none. {$kind} is table, post_type, option, cron or metadata.

Argument Type Description
$status array ['status' => 'n/a' or 'warn', 'usedBy' => string]
$item_name string The item being checked.
$active_plugins string[] Active plugin folders and installed theme folders.

Return status as ok (used), warn (owner gone) or n/a (unknown).

add_filter( 'ogdbc_check_support_for_option', function ( $status, $name, $active ) {
    if ( 0 === strpos( $name, 'myplugin_' ) ) {
        $on = in_array( 'my-plugin', $active, true );
        return array( 'status' => $on ? 'ok' : 'warn', 'usedBy' => 'My Plugin' );
    }
    return $status;
}, 10, 3 );

ogdbc_check_table_info, ogdbc_check_post_type_info, ogdbc_check_option_info, ogdbc_check_cron_info, ogdbc_check_metadata_info

Called to get the owner and status of one item. The plugin hooks its own lookup at priority 10 and replaces the incoming name with an array ['status', 'usedBy', 'custom']. Hook later only to adjust that array.

Argument Type Description
$value string or array The item name before the plugin's lookup, the status array after it.

ogdbc_count_queries, ogdbc_delete_queries, ogdbc_get_queries

Registries of the WordPress Core clean-ups. Each is an array of item key to callable. Each built-in item adds itself.

Filter Callable signature
ogdbc_count_queries ( $age_threshold ) returns int
ogdbc_delete_queries ( $deep_deletions, $limit, $age_threshold ) returns the number deleted. The Lite passes ( $limit, $age_threshold ).
ogdbc_get_queries ( $offset, $limit, $age_threshold ) returns rows

ogdbc_generate_fake_data_queries (Full) does the same for the Dev Tools test data generator.

Built-in item keys:

Group Keys
Posts posts_revision, posts_auto_drafts, posts_deleted_posts
Post metadata posts_metadata_orphaned_post_meta, posts_metadata_orphaned_term_meta, posts_metadata_orphaned_term_relationship, posts_metadata_oembed_caches_in_post_meta, posts_metadata_unused_terms, posts_metadata_duplicated_term_meta, posts_metadata_duplicated_post_meta
Users users_orphaned_user_meta, users_duplicated_user_meta
Comments comments_spammed_comments, comments_deleted_comments, comments_unapproved_comments, comments_orphaned_comments_meta, comments_duplicated_comments_meta, comments_pingbacks
Transients options_expired_transients, options_all_transients

ogdbc_sweeper_run_next, ogdbc_sweeper_run_reset (Full)

Run the next Jellybean Sweeper step, or reset it. Without the Pro features installed they return the default.

Argument Type Default
$result array ['success' => false, 'data' => null, 'message' => 'Feature is not available.']

ogdbc_og_is_registered (Full)

Whether the licence is active.

Argument Type Description
$registered bool Default false.
$prefix string ogdbc

Actions

Action Arguments When it fires
ogdbc_support_db_loaded none Once per request, after the built-in owner data loads and before the *_to_plugin filters run. Add your map filters here at the latest.
ogdbc_cron_analytics none Cron, twice daily. Records the database size for Historical DB Sizes.
ogdbc_cron_tasks none Cron, hourly. Reserved; does no work at present.
ogdbc_cron_sweeper none Full. Cron, on the Jellybean Sweeper schedule, while the Sweeper is on.
ogdbc_pack_fetch none Full. Fetches the Pro features after the licence is saved or the plugin is updated.

Cron schedules

The full version adds ogdbc_5mn (5 minutes), ogdbc_10mn (10 minutes) and ogdbc_30mn (30 minutes) for the Sweeper.

REST routes

Namespace: og-database-cleaner/v1. Send the X-WP-Nonce header with a wp_rest nonce. Routes exist only for administrators.

Permission key: setup = ogdbc_allow_setup, usage = ogdbc_allow_usage, admin = administrator only.

Route Method Permission Edition What it does
/all_settings GET setup both All settings.
/update_options POST setup both Saves settings.
/reset_options POST usage both Back to defaults.
/db_sizes GET setup both Table sizes with owners.
/total_db_size GET setup both Total database size.
/list_post_types GET setup both Post types with counts and owners.
/posts, /posts_metadata, /users, /comments, /transients GET setup both Core items per group.
/entry_count GET setup both Count one item (item).
/entries GET setup both Sample rows for one item.
/delete_entries POST setup both Delete one batch of an item (item).
/options GET setup both Options list.
/option_value GET setup both One option's value.
/delete_options POST setup both Delete item or items.
/switch_autoloaded_option POST setup both item, autoload.
/cron_jobs GET setup both Cron jobs with owners.
/delete_crons POST setup both Unschedule item or items.
/optimize_tables POST setup both tables. The Lite accepts one table.
/repair_tables POST setup both tables. The Lite accepts one table.
/table POST setup both Rows of one table.
/delete_tables POST setup Full Drop tables.
/metadata, /metadata_value GET setup Full Browse post and user meta.
/delete_metadata POST setup Full Delete meta rows.
/custom_query_count POST admin Full Run a saved count query (item).
/custom_query_delete POST admin Full Run a saved delete query (item).
/auto_clean_items GET setup Full Items set to Auto.
/plugins GET setup Full Installed plugins, for assigning owners.
/run_sweeper, /run_sweeper_reset POST setup Full Run or reset the Sweeper.
/generate_fake_data POST usage Full Dev Tools test data.
/log_db_size POST usage both Record the size now.
/refresh_logs, /clear_logs POST usage both Read or empty the log.
/build_indexes, /remove_indexes POST usage both Add or drop the idx_postmeta_postid_metakey index on {prefix}postmeta.
// Count revisions from the browser console on the plugin screen.
fetch(ogdbc.api_url + '/entry_count?item=posts_revision', {
  headers: { 'X-WP-Nonce': ogdbc.rest_nonce }
}).then(r => r.json()).then(console.log);

MCP tools (Full)

The full version adds 20 tools to the MCP server of OG AI Core. Switch on Settings & Logs › MCP; OG AI Core's MCP module must be on too. Agent tools are for administrators only.

Every destructive tool needs confirm set to exactly PERMANENT. Items used by WordPress are always refused. Items owned by an installed plugin are refused unless Protected Items › Enable Deletion is on.

Tool Access Arguments
ogdbc_get_capabilities read none. Call it first: modules, protections, threshold, batch size, limits.
ogdbc_get_status read none. Size, recent history, table count, Sweeper state.
ogdbc_get_counts read items (string[], optional), include_post_types (bool, optional)
ogdbc_preview_entries read item (required), offset
ogdbc_delete_entries admin item, confirm (both required). One batch per call; repeat while finished is false.
ogdbc_list_tables read status (all, ok, warn, n/a), search, limit (1 to 100, default 50), skip
ogdbc_preview_table read table (required, with prefix), offset
ogdbc_delete_tables admin tables (string[], up to 100), confirm
ogdbc_optimize_tables write tables (string[], up to 100)
ogdbc_list_options read status, autoload (all, yes, no), search, limit (default 50), skip
ogdbc_get_option_value read option_name (required)
ogdbc_switch_autoloaded_option write option_name, autoload (yes or no), both required
ogdbc_delete_options admin option_names (string[], up to 100), confirm
ogdbc_list_crons read status, search
ogdbc_delete_crons admin crons (array of {name, args}, up to 100), confirm
ogdbc_list_metadata read table (required, with prefix), search, limit (default 25), skip
ogdbc_delete_metadata admin table, ids (int[], up to 100), confirm
ogdbc_list_custom_queries read none
ogdbc_run_custom_query_count read item (required)
ogdbc_run_custom_query_delete admin item, confirm. Only saved queries run; other SQL is refused.

Admin-post actions (Full)

Action What it does
ogdbc_licence_save Saves the licence key (licence_key). Nonce ogdbc_licence_save.
ogdbc_licence_remove Removes the licence from this site. Nonce ogdbc_licence_remove.
ogdbc_pack_retry Fetches the Pro features again. Nonce ogdbc_pack_retry.

Admin screens

Screen Slug
Database Cleaner (under OG Nexus) ogdbc_settings
Licence page (Full, linked from the Plugins row) ogdbc-licence
Add-ons list (Lite) ogdbc_addons

Options

Option Edition What it holds
ogdbc_options both All settings, in one array. Not autoloaded. Shared by both editions.
ogdbc_prefix_moved both 1 once older option names were moved to the ogdbc_ prefix.
ogdbc_license Full The licence record.
ogdbc_pack_error Full The last error while fetching the Pro features.
ogk_client_og_database_cleaner Full Licence client state.

Main keys in ogdbc_options:

Key Default Notes
mode easy easy or expert
aga_threshold 7 days 1 day, 7 days, 14 days, 1 month, 3 month, 6 month, 1 year
bulk_batch_size 100 Rows per delete batch
delay 100 Milliseconds between batches
hide_message false
options_limit, cron_jobs_limit, metadata_limit, list_post_types_limit 10 Rows per page
db_historical_sizes [] Size history
db_historical_sizes_limit 10
logs_path null Set on first log write
{item}_clean_style per item auto, manual or never (Lite: manual or never)
list_post_types_{type}_clean_style manual Core post types are never
deep_deletions false Full
enable_protected_deletion false Full
auto_refresh_core_count false Full
sweeper_enabled, sweeper_schedule, sweeper_stuck_reset, sweeper_tasks false, hourly, 10, state Full
module_posttypes, module_tables, module_options, module_metadata, module_cronjobs, module_customequeries true Full
module_devtools false Full
mcp_support false Full
custom_queries [] Full. Each entry has item (cq-…), query_count, query_delete, created_at. Administrators only.
post_type_usedby, option_usedby, table_usedby, cron_usedby, metadata_usedby [] Full. Owners assigned by hand.

When the Lite saves, it keeps the full version's keys untouched, so switching editions loses nothing.

Tables and files

Item Edition Notes
{prefix}ogdbc_fake_table Full Created only by Dev Tools test data. Dropped on uninstall.
idx_postmeta_postid_metakey on {prefix}postmeta both Only when you click Build Indexes.
wp-content/uploads/ogdbc_<random>.log both The log file. Must stay inside uploads with the ogdbc prefix and .log extension.
wp-content/og-pro/og-database-cleaner/ Full The Pro features, installed for a licensed site. Removed when the licence is removed or no longer valid.

Constants

Constant Value
OGDBC_VERSION Running version. If it is already defined, the second copy stands down with a notice.
OGDBC_PREFIX ogdbc
OGDBC_DOMAIN og-database-cleaner (Lite: og-database-cleaner-lite)
OGDBC_ENTRY Main plugin file path
OGDBC_PATH Plugin folder path
OGDBC_URL Plugin folder URL

JavaScript

The screen is a React app mounted on #ogdbc-admin-settings, script handle ogdbc. It reads the global ogdbc:

Key Description
api_url REST base, …/wp-json/og-database-cleaner/v1
rest_url Site REST root
rest_nonce wp_rest nonce
plugin_url, prefix, domain Plugin details
db_prefix The site's table prefix
is_pro, is_registered, has_mcp Full. Pro features installed, licence active, MCP available
core, core_count Core items and their counts per group
options All settings
metadata_tables Full. Post Meta and User Meta table names

No custom JavaScript events are fired.

Uninstall

uninstall.php deletes every option whose name starts with ogdbc_, unschedules ogdbc_cron_tasks, ogdbc_cron_analytics and (full version) ogdbc_cron_sweeper, and drops {prefix}ogdbc_fake_table (full version). It also deletes the ogdbc_*.log file in uploads. The ogk_client_og_database_cleaner option is not removed.