...

PluginRx Control Center

The PluginRx Control Center plugin has hooks and methods for developers to extend it. Hooks are labeled Host when they run on the site that runs the Control Center, Agent when they run on a managed site, and Host and Agent when they can run on either. All classes use the PluginRx\ControlCenter namespace.

Add your code in a plugin or mu-plugin so it loads on every request, not only in the admin. Agents answer the Control Center through the REST API, and code placed in is_admin() checks will not run there. The examples use closures for brevity.

prxctrl_integrations

TYPE ⇢ Filter

RUNS ON ⇢ Host and Agent

Registers an integration: the data and actions of another plugin, defined once for both sides. Each request becomes a widget on the Control Center dashboard and an item in the agent’s Permissions list. Each action becomes a button on the dashboard and an item in the same list. Load your code on the Control Center and on every agent, since both read the same definition.

  • $integrations (array): Integration definitions keyed by slug.

Things to know:

  • Add this in a normal plugin or mu-plugin so it loads on every request, not only in the admin. Agents read their integrations during REST requests from the Control Center.
  • Integration keys: label, plugin (plugin basename; requests share “N/A” while it is inactive on the agent, leave empty for no plugin), requests and actions.
  • Request keys: label, description, callback (runs on the agent and returns a number, string or bool), link (optional, relative to the agent’s admin URL), format (optional: number, filesize or text), warn (optional, runs on the Control Center, receives $value and $site, return true to flag it) and widget (optional, false to skip the widget).
  • Action keys: label, description, waiting (button text while running), callback (runs on the agent and returns [ 'success' => bool, 'message' => string ]) and available (optional, runs on the Control Center, receives $site and returns a bool).
  • Prefix request and action keys with your slug so they never clash with another plugin’s. New widgets from other plugins start in Disabled Widgets in the Widget Manager.

Example Usage

PHP
/**  * Share the number of WooCommerce orders on hold, warn when there are too many, and add a button  * that clears expired transients on the agent.  *  * @param array $integrations → Integration definitions keyed by slug.  *  * @return array → The modified integrations.  */ add_filter( 'prxctrl_integrations', function( $integrations ) {     $integrations[ 'my_shop' ] = [         'label'    => __( 'My Shop', 'my-plugin' ),         // Requests share "N/A" while this plugin is inactive on the agent         'plugin'   => 'woocommerce/woocommerce.php',         'requests' => [             'my_shop_on_hold' => [                 'label'       => __( 'Orders On Hold', 'my-plugin' ),                 'description' => __( 'Share the number of orders on hold.', 'my-plugin' ),                 // Runs on the agent                 'callback'    => function() {                     return function_exists( 'wc_orders_count' ) ? (int) wc_orders_count( 'on-hold' ) : 0;                 },                 // Relative to the agent's admin URL                 'link'        => 'admin.php?page=wc-orders&status=wc-on-hold',                 'format'      => 'number',                 // Runs on the Control Center. Return true to show "Needs attention."                 'warn'        => function( $value, $site ) {                     return (int) $value > 10;                 },             ],         ],         'actions'  => [             'my_shop_clear_transients' => [                 'label'       => __( 'Clear Shop Transients', 'my-plugin' ),                 'description' => __( 'Allow deleting expired WooCommerce transients.', 'my-plugin' ),                 'waiting'     => __( 'Clearing transients...', 'my-plugin' ),                 // Runs on the agent                 'callback'    => function() {                     if ( ! function_exists( 'wc_delete_expired_transients' ) ) {                         return [ 'success' => false, 'message' => __( 'WooCommerce is not active.', 'my-plugin' ) ];                     }                     $deleted = (int) wc_delete_expired_transients();                     return [ 'success' => true, 'message' => sprintf( __( 'Deleted %d expired transients.', 'my-plugin' ), $deleted ) ];                 },             ],         ],     ];     return $integrations; } );
PHP
/**  * Integrations do not need a plugin. Share the size of the PHP error log in the site root and let  * the Control Center empty it, but only while it has something in it.  *  * @param array $integrations → Integration definitions keyed by slug.  *  * @return array → The modified integrations.  */ add_filter( 'prxctrl_integrations', function( $integrations ) {     $integrations[ 'error_log' ] = [         'label'    => __( 'PHP Error Log', 'my-plugin' ),         // Empty means no plugin is required, so the request is always shared         'plugin'   => '',         'requests' => [             'error_log_size' => [                 'label'       => __( 'Error Log Size', 'my-plugin' ),                 'description' => __( 'Share the size of the error_log file in the site root.', 'my-plugin' ),                 'callback'    => function() {                     $path = ABSPATH . 'error_log';                     return file_exists( $path ) ? (int) filesize( $path ) : 0;                 },                 // Formats the bytes as KB, MB, etc.                 'format'      => 'filesize',                 // Warn when the log passes 5 MB                 'warn'        => function( $value, $site ) {                     return (int) $value > 5 * MB_IN_BYTES;                 },             ],         ],         'actions'  => [             'error_log_clear' => [                 'label'       => __( 'Clear Error Log', 'my-plugin' ),                 'description' => __( 'Allow emptying the error_log file in the site root.', 'my-plugin' ),                 'waiting'     => __( 'Clearing log...', 'my-plugin' ),                 'callback'    => function() {                     $cleared = false !== file_put_contents( ABSPATH . 'error_log', '' );                     return [ 'success' => $cleared, 'message' => $cleared ? __( 'Error log cleared.', 'my-plugin' ) : __( 'The log could not be cleared.', 'my-plugin' ) ];                 },                 // Runs on the Control Center. Only enable the button when the last check found a log                 'available'   => function( $site ) {                     $size = \PluginRx\ControlCenter\Registry::value( $site, 'error_log_size' );                     return is_numeric( $size ) && $size > 0;                 },             ],         ],     ];     return $integrations; } );

prxctrl_requests

TYPE ⇢ Filter

RUNS ON ⇢ Host and Agent

Changes the list of everything an agent can share. Use it to remove a request so it can never be shared or shown, or to change what a request returns. Every request has label, description, default (checked on fresh installs), callback and group (core or integration).

  • $requests (array): Requests keyed by permission key.

Things to know:

  • The core keys are wordpress_version, core_update, php_version, plugins, themes, wp_debug, is_multisite, blog_id, admin_path, admin_email, admin_users, server_ip and abspath. Integration requests use the keys you registered.

Example Usage

PHP
/**  * Change what an agent can share.  *  * @param array $requests → Requests keyed by permission key.  *  * @return array → The modified requests.  */ add_filter( 'prxctrl_requests', function( $requests ) {     // Make sure these can never be shared from this site, even if someone checks them     unset( $requests[ 'server_ip' ], $requests[ 'abspath' ] );      // Share a technical contact instead of the site admin email, falling back to the admin email     if ( isset( $requests[ 'admin_email' ] ) ) {         $requests[ 'admin_email' ][ 'callback' ] = function() {             return sanitize_email( (string) get_option( 'my_tech_contact', get_option( 'admin_email' ) ) );         };     }      return $requests; } );

prxctrl_actions

TYPE ⇢ Filter

RUNS ON ⇢ Host and Agent

Changes the list of actions a Control Center can run. Each action has label, description, waiting, callback, available and group. The built-in actions are update_wordpress, update_themes and update_plugins.

  • $actions (array): Actions keyed by permission key.

Things to know:

  • Removing an action removes its button, its permission and its REST handler, so the agent cannot run it even if it was allowed before.

Example Usage

PHP
/**  * Adjust the built-in actions.  *  * @param array $actions → Actions keyed by permission key.  *  * @return array → The modified actions.  */ add_filter( 'prxctrl_actions', function( $actions ) {     // Never allow WordPress core updates from a Control Center on this site     unset( $actions[ 'update_wordpress' ] );      // Rename a button     if ( isset( $actions[ 'update_plugins' ] ) ) {         $actions[ 'update_plugins' ][ 'label' ] = __( 'Update All Plugins', 'my-plugin' );         $actions[ 'update_plugins' ][ 'waiting' ] = __( 'Updating, this can take a minute...', 'my-plugin' );     }      // Only enable the theme button when the active theme has an update     if ( isset( $actions[ 'update_themes' ] ) ) {         $actions[ 'update_themes' ][ 'available' ] = function( $site ) {             foreach ( (array) $site->themes as $theme ) {                 if ( ! empty( $theme->is_active ) && ! empty( $theme->update_available ) ) {                     return true;                 }             }             return false;         };     }      return $actions; } );

prxctrl_default_permissions

TYPE ⇢ Filter

RUNS ON ⇢ Agent

Changes which permissions are checked on a site that has never saved its Agent settings. New installs start with version and update information only. Sites that already saved their permissions are not changed.

  • $defaults (array): Permission keys that start checked.

Example Usage

PHP
/**  * Start new agents with a few more permissions checked.  *  * @param array $defaults → Permission keys that start checked.  *  * @return array → The modified keys.  */ add_filter( 'prxctrl_default_permissions', function( $defaults ) {     // Also share the admin email and the update buttons     $defaults[] = 'admin_email';     $defaults[] = 'update_plugins';     $defaults[] = 'update_themes';      return array_values( array_unique( $defaults ) ); } );
PHP
/**  * Or start with nothing shared until an administrator chooses.  */ add_filter( 'prxctrl_default_permissions', '__return_empty_array' );

prxctrl_widgets

TYPE ⇢ Filter

RUNS ON ⇢ Host and Agent

Changes the dashboard widgets. Each widget has label, type, request, builtin and wide. Integration widgets also have integration, link, format and warn.

  • $widgets (array): Widgets keyed by widget key.

Things to know:

  • A widget with builtin set to true is added to the dashboard automatically. Without it, a new widget starts in Disabled Widgets in the Widget Manager.

Example Usage

PHP
/**  * Customize the widgets.  *  * @param array $widgets → Widgets keyed by widget key.  *  * @return array → The modified widgets.  */ add_filter( 'prxctrl_widgets', function( $widgets ) {     // Rename a widget     if ( isset( $widgets[ 'admin_users' ] ) ) {         $widgets[ 'admin_users' ][ 'label' ] = __( 'Administrators', 'my-plugin' );     }      // Enable one of your own widgets for everyone without visiting the Widget Manager     if ( isset( $widgets[ 'my_shop_on_hold' ] ) ) {         $widgets[ 'my_shop_on_hold' ][ 'builtin' ] = true;     }      // Take up the full width of the card     if ( isset( $widgets[ 'abspath' ] ) ) {         $widgets[ 'abspath' ][ 'wide' ] = true;     }      return $widgets; } );

prxctrl_widget_state

TYPE ⇢ Filter

RUNS ON ⇢ Host and Agent

Changes what a single widget shows for a site: its value, link, warning and note. It does not run for widgets that are not shared or for sites that have not been checked yet.

  • $state (array): The widget state: key, label, type, wide, value, link, warning, note, unshared and ignored.
  • $site (object): The site, including plugins, themes, admin_users and integrations.
  • $widget (array): The widget definition from the registry.

Things to know:

  • A non-empty warning highlights the widget and counts toward the site’s warnings. Users can still ignore it per site.

Example Usage

PHP
/**  * Add your own warnings and notes to widgets.  *  * @param array  $state  → The widget state.  * @param object $site   → The site being displayed.  * @param array  $widget → The widget definition.  *  * @return array → The modified state.  */ add_filter( 'prxctrl_widget_state', function( $state, $site, $widget ) {     // Warn when a site has an unreasonable number of plugins     if ( 'plugins' === $widget[ 'type' ] && (int) $state[ 'count' ] > 40 ) {         $state[ 'warning' ] = __( 'This site has more than 40 plugins.', 'my-plugin' );     }      // Add a reminder under the WordPress version for sites that are held back on purpose     if ( 'wp_version' === $widget[ 'type' ] && false !== strpos( (string) $site->notes, 'LTS' ) ) {         $state[ 'note' ] = __( 'Pinned on purpose.', 'my-plugin' );         $state[ 'warning' ] = '';     }      return $state; }, 10, 3 );

TYPE ⇢ Filter

RUNS ON ⇢ Host and Agent

Changes the quick links shown for a site. The array is keyed by label. The first link is always Login Page, followed by the link fields saved for the site.

  • $links (array): Label => URL.
  • $site (object): The site.

Example Usage

PHP
/**  * Add, change or remove quick links.  *  * @param array  $links → Label => URL.  * @param object $site  → The site.  *  * @return array → The modified links.  */ add_filter( 'prxctrl_site_links', function( $links, $site ) {     $host = wp_parse_url( (string) $site->site_url, PHP_URL_HOST );      // Link to an external dashboard built from the site's domain     $links[ 'Uptime' ] = 'https://uptime.example.com/monitors?search=' . rawurlencode( (string) $host );      // Link to the site's search console property     $links[ 'Search Console' ] = 'https://search.google.com/search-console?resource_id=' . rawurlencode( 'sc-domain:' . $host );      // Hide the login link for sites that use single sign-on     if ( false !== strpos( (string) $site->notes, 'SSO' ) ) {         unset( $links[ 'Login Page' ] );     }      return $links; }, 10, 2 );

prxctrl_site_card_after

TYPE ⇢ Action

RUNS ON ⇢ Host and Agent

Runs inside each site card after the plugin, theme and admin tables. Use it to print your own section. It does not run in the Widget Manager preview.

  • $site (object): The site.
  • $context (string): host on the Control Center dashboard or agent on an agent’s own dashboard.

Things to know:

  • Escape everything you print.

Example Usage

PHP
/**  * Show a custom section on each Control Center card.  *  * @param object $site    → The site.  * @param string $context → "host" or "agent".  */ add_action( 'prxctrl_site_card_after', function( $site, $context ) {     if ( 'host' !== $context ) {         return;     }      // Your own data, saved per site ID     $renewal = get_option( 'my_renewal_' . (int) $site->id );      if ( ! $renewal ) {         return;     }      echo '<p class="prxctrl-muted">' . esc_html( sprintf( __( 'Hosting renews on %s.', 'my-plugin' ), $renewal ) ) . '</p>'; }, 10, 2 );

prxctrl_dashboard_sites

TYPE ⇢ Filter

RUNS ON ⇢ Host

Changes the list of sites the Control Center dashboard displays. The Sites page is not affected.

  • $sites (array): Site objects, including plugins, themes, admin users and integration values.

Example Usage

PHP
/**  * Limit the dashboard to the sites assigned to the current user.  *  * @param array $sites → Site objects.  *  * @return array → The filtered sites.  */ add_filter( 'prxctrl_dashboard_sites', function( $sites ) {     // Administrators see everything     if ( current_user_can( 'manage_options' ) ) {         return $sites;     }      // A comma-separated list of site IDs saved in user meta     $assigned = array_map( 'absint', explode( ',', (string) get_user_meta( get_current_user_id(), 'my_assigned_sites', true ) ) );      return array_values( array_filter( $sites, function( $site ) use ( $assigned ) {         return in_array( (int) $site->id, $assigned, true );     } ) ); } );

prxctrl_site_data

TYPE ⇢ Filter

RUNS ON ⇢ Host

Changes the data an agent returned after a check, before it is saved. Use it to correct or hide values, or to read data your own agent code added.

  • $result (array): The agent’s response, such as wordpress_version, plugins, themes, admin_users, integrations and _meta.
  • $site (object): The site that was checked.

Things to know:

  • Each plugin and theme is an array with name, version, author, slug, active and update_available (the new version, or null).

Example Usage

PHP
/**  * Adjust what a check returns before it is saved.  *  * @param array  $result → The agent's response.  * @param object $site   → The site that was checked.  *  * @return array → The modified response.  */ add_filter( 'prxctrl_site_data', function( $result, $site ) {     // A premium plugin always reports an update that cannot be installed without a license     if ( ! empty( $result[ 'plugins' ] ) && is_array( $result[ 'plugins' ] ) ) {         foreach ( $result[ 'plugins' ] as $index => $plugin ) {             if ( 'my-premium/my-premium.php' === ( $plugin[ 'plugin_file' ] ?? '' ) ) {                 $result[ 'plugins' ][ $index ][ 'update_available' ] = null;             }         }     }      // Do not store the server IP for sites behind a proxy     if ( false !== strpos( (string) $site->site_url, 'proxied.example.com' ) ) {         unset( $result[ 'server_ip' ] );     }      return $result; }, 10, 2 );

prxctrl_site_checked

TYPE ⇢ Action

RUNS ON ⇢ Host

Runs after a site was checked successfully and its data was saved. It does not run when the check fails.

  • $site_id (int): The site ID.
  • $data (array): The data the agent returned.

Example Usage

PHP
/**  * Send an alert when a checked site has WP_DEBUG on or a WordPress update waiting.  *  * @param int   $site_id → The site ID.  * @param array $data    → The data the agent returned.  */ add_action( 'prxctrl_site_checked', function( $site_id, $data ) {     $site = \PluginRx\ControlCenter\Database::get_site( $site_id );     $problems = [];      if ( ! empty( $data[ 'wp_debug' ] ) ) {         $problems[] = __( 'WP_DEBUG is enabled.', 'my-plugin' );     }      if ( ! empty( $data[ 'core_update' ] ) ) {         $problems[] = sprintf( __( 'WordPress %s is available.', 'my-plugin' ), $data[ 'core_update' ] );     }      if ( ! $site || empty( $problems ) ) {         return;     }      wp_mail( get_option( 'admin_email' ), sprintf( __( 'Attention: %s', 'my-plugin' ), $site->site_name ), implode( "\n", $problems ) ); }, 10, 2 );
PHP
/**  * Forward the response time of every check to an external monitoring service.  */ add_action( 'prxctrl_site_checked', function( $site_id ) {     $site = \PluginRx\ControlCenter\Database::get_site( $site_id );      if ( ! $site ) {         return;     }      wp_remote_post( 'https://metrics.example.com/api/response-time', [         'timeout'  => 5,         'blocking' => false,         'body'     => [             'site' => $site->site_url,             'ms'   => (int) $site->response_ms,         ],     ] ); } );

prxctrl_action_performed

TYPE ⇢ Action

RUNS ON ⇢ Host

Runs after an action button finished on a site, whether it succeeded or not. It runs on the Control Center after the result is logged.

  • $site_id (int): The site ID.
  • $type (string): The action key, such as update_plugins.
  • $result (array): success (bool) and message (string).

Example Usage

PHP
/**  * Post updates and failures to a chat webhook.  *  * @param int    $site_id → The site ID.  * @param string $type    → The action key.  * @param array  $result  → The result with "success" and "message".  */ add_action( 'prxctrl_action_performed', function( $site_id, $type, $result ) {     $site = \PluginRx\ControlCenter\Database::get_site( $site_id );     $name = $site ? $site->site_name : '#' . $site_id;      // Only report updates, and any failure     $is_update = 0 === strpos( $type, 'update_' );      if ( ! $is_update && ! empty( $result[ 'success' ] ) ) {         return;     }      wp_remote_post( 'https://hooks.example.com/services/XXXX', [         'timeout'  => 5,         'blocking' => false,         'headers'  => [ 'Content-Type' => 'application/json' ],         'body'     => wp_json_encode( [             'text' => sprintf( '%s: %s (%s) - %s', $name, $type, ! empty( $result[ 'success' ] ) ? 'ok' : 'failed', wp_strip_all_tags( (string) ( $result[ 'message' ] ?? '' ) ) ),         ] ),     ] ); }, 10, 3 );

prxctrl_site_added

TYPE ⇢ Action

RUNS ON ⇢ Host

Runs after a site is added to the Control Center, including sites added by setup or by the network option “Also add new subsites automatically.”

  • $site_id (int): The new site ID.
  • $data (array): The columns that were saved, such as site_url, site_name and group_id.

Things to know:

  • Database::update_site() does not run this hook, so it is safe to call from here.

Example Usage

PHP
/**  * Give every new site a starting note and a billing link.  *  * @param int   $site_id → The new site ID.  * @param array $data    → The columns that were saved.  */ add_action( 'prxctrl_site_added', function( $site_id, $data ) {     \PluginRx\ControlCenter\Database::update_site( $site_id, [         'notes' => sprintf( __( 'Added %s. Hosting and DNS not yet reviewed.', 'my-plugin' ), wp_date( 'F j, Y' ) ),         // Link fields are saved by slug. This one must exist under Link Fields in the Host settings         'links' => [ 'billing' => 'https://billing.example.com/search?q=' . rawurlencode( (string) wp_parse_url( (string) $data[ 'site_url' ], PHP_URL_HOST ) ) ],     ] ); }, 10, 2 );

prxctrl_site_deleted

TYPE ⇢ Action

RUNS ON ⇢ Host

Runs after a site and its saved data were removed. The site’s logs are kept.

  • $site_id (int): The removed site ID.

Example Usage

PHP
/**  * Clean up data your own code saved for the site.  *  * @param int $site_id → The removed site ID.  */ add_action( 'prxctrl_site_deleted', function( $site_id ) {     delete_option( 'my_renewal_' . $site_id );     delete_transient( 'my_report_' . $site_id ); } );
PHP
/**  * Or leave a record for your team.  */ add_action( 'prxctrl_site_deleted', function( $site_id ) {     error_log( sprintf( 'PluginRx Control Center: site #%d was removed by user #%d.', $site_id, get_current_user_id() ) ); } );

prxctrl_action_window

TYPE ⇢ Filter

RUNS ON ⇢ Host

Changes how long after a successful check the action buttons stay available. After this time the button asks you to check the site again, so actions run on up-to-date information. The default is one hour.

  • $seconds (int): The window in seconds.
  • $site (object): The site.

Example Usage

PHP
/**  * Change how long actions stay available after a check.  *  * @param int    $seconds → The window in seconds.  * @param object $site    → The site.  *  * @return int → The modified window.  */ add_filter( 'prxctrl_action_window', function( $seconds, $site ) {     // Production sites must be checked again within 10 minutes     if ( false === strpos( (string) $site->site_url, 'staging' ) ) {         return 10 * MINUTE_IN_SECONDS;     }      // Staging sites can wait a day     return DAY_IN_SECONDS; }, 10, 2 );

prxctrl_screenshot_url

TYPE ⇢ Filter

RUNS ON ⇢ Host

Changes the screenshot address of a site. The default is the WordPress.com mShots service. Return an empty string to show no screenshot for the site.

  • $url (string): The screenshot URL.
  • $site (object): The site.

Example Usage

PHP
/**  * Use another screenshot service, and skip staging sites.  *  * @param string $url  → The screenshot URL.  * @param object $site → The site.  *  * @return string → The modified URL.  */ add_filter( 'prxctrl_screenshot_url', function( $url, $site ) {     if ( false !== strpos( (string) $site->site_url, 'staging' ) ) {         return '';     }      return add_query_arg( [         'url'    => rawurlencode( (string) $site->site_url ),         'width'  => 400,         'height' => 300,     ], 'https://screenshots.example.com/capture' ); }, 10, 2 );

prxctrl_request_body

TYPE ⇢ Filter

RUNS ON ⇢ Host

Changes the JSON body sent to an agent with each data request. By default it contains layout, the list of enabled widgets. The body is signed, so the agent can trust anything you add.

  • $body (array): The request body.

Things to know:

  • The agent receives the body through the REST request. See the example for reading it with rest_request_before_callbacks.

Example Usage

PHP
/**  * Control Center: tell agents which environment is asking.  *  * @param array $body → The request body.  *  * @return array → The modified body.  */ add_filter( 'prxctrl_request_body', function( $body ) {     $body[ 'environment' ] = wp_get_environment_type();      return $body; } );  /**  * Agent: read it on the way in.  *  * @param mixed            $response → The response so far.  * @param array            $handler  → The route handler.  * @param \WP_REST_Request $request  → The request.  *  * @return mixed → The unchanged response.  */ add_filter( 'rest_request_before_callbacks', function( $response, $handler, $request ) {     if ( 0 === strpos( $request->get_route(), '/prx-agent/v2/request' ) ) {         $params = (array) $request->get_json_params();         update_option( 'my_control_center_environment', sanitize_key( (string) ( $params[ 'environment' ] ?? '' ) ), false );     }      return $response; }, 10, 3 );

prxctrl_remote_args

TYPE ⇢ Filter

RUNS ON ⇢ Host

Changes the arguments used for every request to an agent. They are passed to wp_remote_post() and include timeout, redirection, headers and body.

  • $args (array): The request arguments.

Things to know:

  • Do not change body or the X-PRX-* headers. They are signed, and the agent rejects a request that no longer matches its signature.

Example Usage

PHP
/**  * Adjust requests sent to agents.  *  * @param array $args → The wp_remote_post() arguments.  *  * @return array → The modified arguments.  */ add_filter( 'prxctrl_remote_args', function( $args ) {     // Identify the Control Center in your server logs     $args[ 'user-agent' ] = 'PluginRx Control Center; ' . home_url();      // Allow self-signed certificates while developing locally     if ( 'local' === wp_get_environment_type() ) {         $args[ 'sslverify' ] = false;     }      // Updates on large sites can take a while     $args[ 'timeout' ] = max( (int) $args[ 'timeout' ], 60 );      return $args; } );

prxctrl_agent_response

TYPE ⇢ Filter

RUNS ON ⇢ Agent

Changes the data an agent returns to a Control Center. Add your own keys here, then read them on the Control Center with prxctrl_site_data or prxctrl_site_checked.

  • $data (array): The response, including _meta.
  • $allowed (array|null): The permission keys allowed on this site, or null for a network subsite read from the network admin.

Example Usage

PHP
/**  * Agent: include the active theme's parent and the object cache status in every response.  *  * @param array      $data    → The response.  * @param array|null $allowed → Allowed permission keys.  *  * @return array → The modified response.  */ add_filter( 'prxctrl_agent_response', function( $data, $allowed ) {     // Respect the permissions. Only share this when themes may be shared     if ( null === $allowed || in_array( 'themes', $allowed, true ) ) {         $theme = wp_get_theme();         $data[ 'my_parent_theme' ] = $theme->parent() ? $theme->parent()->get( 'Name' ) : '';     }      $data[ 'my_object_cache' ] = wp_using_ext_object_cache();      return $data; }, 10, 2 );  /**  * Control Center: save what the agent added so you can use it elsewhere.  */ add_action( 'prxctrl_site_checked', function( $site_id, $data ) {     if ( isset( $data[ 'my_object_cache' ] ) ) {         update_option( 'my_object_cache_' . $site_id, (bool) $data[ 'my_object_cache' ], false );     } }, 10, 2 );

prxctrl_agent_action

TYPE ⇢ Action

RUNS ON ⇢ Agent

Runs on an agent after one of its actions ran, whether the action succeeded or not. It does not run for unknown or forbidden actions.

  • $type (string): The action key.
  • $result (array): success (bool) and message (string).

Example Usage

PHP
/**  * Flush caches and tell the site owner after plugins or themes were updated remotely.  *  * @param string $type   → The action key.  * @param array  $result → The result.  */ add_action( 'prxctrl_agent_action', function( $type, $result ) {     if ( empty( $result[ 'success' ] ) || ! in_array( $type, [ 'update_plugins', 'update_themes', 'update_wordpress' ], true ) ) {         return;     }      wp_cache_flush();      wp_mail( get_option( 'admin_email' ), __( 'Your site was updated', 'my-plugin' ), wp_strip_all_tags( (string) $result[ 'message' ] ) ); }, 10, 2 );

prxctrl_remote_login

TYPE ⇢ Action

RUNS ON ⇢ Agent

Runs on an agent when a single-use login link was used and the visitor is logged in, just before they are redirected to the admin area.

  • $user_id (int): The ID of the account that was logged in.

Example Usage

PHP
/**  * Let the site owner know whenever someone used Remote Login.  *  * @param int $user_id → The account that was logged in.  */ add_action( 'prxctrl_remote_login', function( $user_id ) {     $user = get_userdata( $user_id );      if ( ! $user ) {         return;     }      wp_mail(         get_option( 'admin_email' ),         __( 'Remote login used', 'my-plugin' ),         sprintf( __( '%1$s was logged in remotely from %2$s.', 'my-plugin' ), $user->user_login, \PluginRx\ControlCenter\Helpers::ip() )     ); } );

prxctrl_remote_login_fire_wp_login

TYPE ⇢ Filter

RUNS ON ⇢ Agent

Remote login sets the login cookie directly and does not run the core wp_login action. Return true to run it, so security and activity log plugins record the login.

  • $fire (bool): Whether to run wp_login. The default is false.
  • $user (WP_User): The account being logged in.

Example Usage

PHP
/**  * Run wp_login for remote logins so the activity log records them.  */ add_filter( 'prxctrl_remote_login_fire_wp_login', '__return_true' );
PHP
/**  * Or only for some accounts.  *  * @param bool    $fire → Whether to run wp_login.  * @param WP_User $user → The account being logged in.  *  * @return bool → The modified value.  */ add_filter( 'prxctrl_remote_login_fire_wp_login', function( $fire, $user ) {     return user_can( $user, 'manage_options' ); }, 10, 2 );

prxctrl_setup_complete

TYPE ⇢ Action

RUNS ON ⇢ Host and Agent

Runs once when the Setup page is completed and a site role is saved.

  • $mode (string): host, agent or both.
  • $network (bool): true when a network-activated install finished setup.

Example Usage

PHP
/**  * Give a new Control Center useful link fields, and a new agent a heads up.  *  * @param string $mode    → host, agent or both.  * @param bool   $network → Whether this was a network setup.  */ add_action( 'prxctrl_setup_complete', function( $mode, $network ) {     $has_host = in_array( $mode, [ 'host', 'both' ], true );      if ( $has_host && empty( \PluginRx\ControlCenter\Options::get( 'link_fields' ) ) ) {         \PluginRx\ControlCenter\Options::update( 'link_fields', [             [ 'label' => 'Hosting', 'slug' => 'hosting' ],             [ 'label' => 'Repository', 'slug' => 'repo' ],             [ 'label' => 'Analytics', 'slug' => 'analytics' ],         ] );     }      if ( ! $has_host ) {         wp_mail( '[email protected]', __( 'New agent ready', 'my-plugin' ), home_url() );     } }, 10, 2 );

prxctrl_log_details

TYPE ⇢ Filter

RUNS ON ⇢ Host and Agent

Changes the text of a log entry before it is saved. The result is sanitized as plain text afterwards.

  • $details (string): The log details.
  • $site_id (int): The site ID, or 0 for this site.
  • $action (string): The action key, such as check_site.
  • $success (bool): Whether it succeeded.

Example Usage

PHP
/**  * Mask email addresses in logs.  *  * @param string $details → The log details.  * @param int    $site_id → The site ID.  * @param string $action  → The action key.  * @param bool   $success → Whether it succeeded.  *  * @return string → The modified details.  */ add_filter( 'prxctrl_log_details', function( $details, $site_id, $action, $success ) {     $details = preg_replace( '/[A-Z0-9._%+-]+@([A-Z0-9.-]+\.[A-Z]{2,})/i', '***@$1', $details );      // Label every failure with the environment to make shared logs easier to read     if ( ! $success ) {         $details = '[' . wp_get_environment_type() . '] ' . $details;     }      return $details; }, 10, 4 );

prxctrl_log_added

TYPE ⇢ Action

RUNS ON ⇢ Host and Agent

Runs after a log entry was saved.

  • $log_id (int): The log ID.
  • $data (array): The saved columns: user_id, site_id, action, context, status (success or error), details, ip_address, created_at and, for agent events, requester.

Things to know:

  • Do not call Database::log() from this hook, or it will log forever.

Example Usage

PHP
/**  * Email when someone fails to authenticate against an agent, and copy every error to the PHP log.  *  * @param int   $log_id → The log ID.  * @param array $data   → The saved log columns.  */ add_action( 'prxctrl_log_added', function( $log_id, $data ) {     if ( 'error' !== $data[ 'status' ] ) {         return;     }      error_log( sprintf( 'Control Center %s: %s', $data[ 'action' ], $data[ 'details' ] ) );      if ( 'auth_failed' === $data[ 'action' ] ) {         wp_mail( get_option( 'admin_email' ), __( 'Failed Control Center connection', 'my-plugin' ), sprintf( "%s\nIP: %s", $data[ 'details' ], $data[ 'ip_address' ] ) );     } }, 10, 2 );

prxctrl_option_definitions

TYPE ⇢ Filter

RUNS ON ⇢ Host and Agent

Changes the plugin’s setting definitions. Use it to change defaults across all your sites, or to register your own setting so you can read and save it with Options::get() and Options::update(). Values are saved as prxctrl_ plus the key.

  • $definitions (array): Definitions keyed by setting key.

Things to know:

  • Each definition has scope (global, host or agent), type and default.
  • Types are bool, int (also needs min and max), choice (also needs choices), text, timezone, roles, hosts, api_key, permissions, login_user, link_fields and layout. Anything else is saved as plain text.
  • A setting you add has no field on the Settings page. Save it with your own form or code.
  • Add the filter in a plugin or mu-plugin file that loads before the plugin first reads its settings, not later on init or admin_init. Definitions are cached for the request.

Example Usage

PHP
/**  * Change defaults and add a setting.  *  * @param array $definitions → Definitions keyed by setting key.  *  * @return array → The modified definitions.  */ add_filter( 'prxctrl_option_definitions', function( $definitions ) {     // Change defaults for every site that has not saved its own value     $definitions[ 'timeout' ][ 'default' ] = 45;     $definitions[ 'log_retention' ][ 'default' ] = 30;     $definitions[ 'screenshots' ][ 'default' ] = 0;      // Add your own setting     $definitions[ 'alert_email' ] = [         'scope'   => 'host',         'type'    => 'text',         'default' => get_option( 'admin_email' ),     ];      return $definitions; } );  // Read it anywhere, in a class or in a function $alert_email = \PluginRx\ControlCenter\Options::get( 'alert_email' );

prxctrl_settings_saved

TYPE ⇢ Action

RUNS ON ⇢ Host and Agent

Runs after the Host, Agent or Site Role settings were saved with the Save button.

  • $page (string): host, agent or role.
  • $settings (array): The submitted values keyed by setting key.

Things to know:

  • The values are already saved and sanitized when this runs. Read them with Options::get() rather than trusting $settings.

Example Usage

PHP
/**  * Warn the site owner when an agent starts sharing admin accounts or allows remote login.  *  * @param string $page     → host, agent or role.  * @param array  $settings → The submitted values.  */ add_action( 'prxctrl_settings_saved', function( $page, $settings ) {     if ( 'agent' !== $page ) {         return;     }      $allowed = (array) \PluginRx\ControlCenter\Options::get( 'agent_permissions' );     $risky = array_intersect( [ 'admin_users', 'remote_login' ], $allowed );      if ( empty( $risky ) ) {         return;     }      wp_mail( get_option( 'admin_email' ), __( 'Control Center permissions changed', 'my-plugin' ), sprintf( __( 'Now allowed: %s', 'my-plugin' ), implode( ', ', $risky ) ) ); }, 10, 2 );

prxctrl_settings_tabs

TYPE ⇢ Filter

RUNS ON ⇢ Host and Agent

Changes the tabs on the Settings page. Add a tab here and print its content with prxctrl_settings_tab_{tab}.

  • $tabs (array): Tab slug => label.

Example Usage

PHP
/**  * Add a tab to the Settings page.  *  * @param array $tabs → Tab slug => label.  *  * @return array → The modified tabs.  */ add_filter( 'prxctrl_settings_tabs', function( $tabs ) {     $tabs[ 'notifications' ] = __( 'Notifications', 'my-plugin' );      return $tabs; } );

prxctrl_settings_tab_{tab}

TYPE ⇢ Action

RUNS ON ⇢ Host and Agent

Prints the content of a custom Settings tab added with prxctrl_settings_tabs. Replace {tab} with the tab slug, such as prxctrl_settings_tab_notifications.

Things to know:

  • The Save button in the header only saves the Host, Agent and Site Role tabs, so give your tab its own form. The SettingsUi class has helpers for matching panels: open_box( $title ) and close_box().

Example Usage

PHP
/**  * Print the Notifications tab and save it with admin-post.php.  */ add_action( 'prxctrl_settings_tab_notifications', function() {     echo '<div class="wrap prxctrl-wrap prxctrl-settings"><div class="prxctrl-settings-grid">';     \PluginRx\ControlCenter\SettingsUi::open_box( __( 'Notifications', 'my-plugin' ) );     ?>     <form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">         <input type="hidden" name="action" value="my_save_notifications">         <?php wp_nonce_field( 'my_save_notifications' ); ?>         <p>             <label for="my-alert-email"><?php esc_html_e( 'Send alerts to', 'my-plugin' ); ?></label><br>             <input type="email" id="my-alert-email" name="alert_email" value="<?php echo esc_attr( (string) get_option( 'my_alert_email', get_option( 'admin_email' ) ) ); ?>">         </p>         <button type="submit" class="prxctrl-button"><?php esc_html_e( 'Save Notifications', 'my-plugin' ); ?></button>     </form>     <?php     \PluginRx\ControlCenter\SettingsUi::close_box();     echo '</div></div>'; } );  add_action( 'admin_post_my_save_notifications', function() {     check_admin_referer( 'my_save_notifications' );      if ( ! \PluginRx\ControlCenter\Access::can_manage() ) {         wp_die( esc_html__( 'You do not have permission to do this.', 'my-plugin' ), 403 );     }      update_option( 'my_alert_email', sanitize_email( wp_unslash( $_POST[ 'alert_email' ] ?? '' ) ) );      wp_safe_redirect( \PluginRx\ControlCenter\Helpers::page_url( 'settings', [ 'tab' => 'notifications' ] ) );     exit; } );

prxctrl_pages

TYPE ⇢ Filter

RUNS ON ⇢ Host and Agent

Changes the pages in the Control Center menu. Each page is [ title, callback, manage ]. Set manage to true to limit the page to users who can change settings. A page opens at admin.php?page=prxctrl-{slug}; use Helpers::page_url( $slug ) to link to it.

  • $pages (array): Page slug => [ title, callback, manage ].

Example Usage

PHP
/**  * Add a Reports page, and hide Logs from everyone but managers.  *  * @param array $pages → Page slug => [ title, callback, manage ].  *  * @return array → The modified pages.  */ add_filter( 'prxctrl_pages', function( $pages ) {     $pages[ 'reports' ] = [         __( 'Reports', 'my-plugin' ),         function() {             echo '<div class="wrap prxctrl-wrap">';             echo '<h2>' . esc_html__( 'Monthly Reports', 'my-plugin' ) . '</h2>';              foreach ( \PluginRx\ControlCenter\Database::get_sites() as $site ) {                 echo '<p>' . esc_html( $site->site_name ) . '</p>';             }              echo '</div>';         },         false,     ];      if ( isset( $pages[ 'logs' ] ) ) {         $pages[ 'logs' ][ 2 ] = true;     }      return $pages; } );

prxctrl_menu_name

TYPE ⇢ Filter

RUNS ON ⇢ Host and Agent

Changes the name of the menu item in the admin menu. The default is “Control Center.”

  • $name (string): The menu name.

Example Usage

PHP
/**  * White label the menu name.  *  * @param string $name → The menu name.  *  * @return string → The modified name.  */ add_filter( 'prxctrl_menu_name', function( $name ) {     return __( 'Client Sites', 'my-plugin' ); } );

prxctrl_page_name

TYPE ⇢ Filter

RUNS ON ⇢ Host and Agent

Changes the title shown in the header of the plugin’s pages. The default is the plugin name.

  • $name (string): The page name.

Example Usage

PHP
/**  * Change the title in the page header.  *  * @param string $name → The page name.  *  * @return string → The modified name.  */ add_filter( 'prxctrl_page_name', function( $name ) {     return __( 'Acme Site Manager', 'my-plugin' ); } );

TYPE ⇢ Filter

RUNS ON ⇢ Host and Agent

Changes the logo shown in the header of the plugin’s pages.

  • $url (string): The logo URL.

Example Usage

PHP
/**  * Use your own logo, from the active theme or from the media library.  *  * @param string $url → The logo URL.  *  * @return string → The modified URL.  */ add_filter( 'prxctrl_logo', function( $url ) {     return get_stylesheet_directory_uri() . '/images/control-center-logo.png'; } );

prxctrl_theme_colors

TYPE ⇢ Filter

RUNS ON ⇢ Host and Agent

Changes the colors used on the plugin’s pages. Colors are hex values. Invalid values fall back to the defaults.

  • $colors (array): Color overrides keyed by name. Available keys: header-bg, header-font, header-tab, header-tab-link, accent, button, button-font and button-hover.

Things to know:

  • If Admin Help Docs is active, its colors are applied to this filter at priority 5, so a filter at the default priority 10 overrides them.

Example Usage

PHP
/**  * Match the plugin's pages to your brand.  *  * @param array $colors → Color overrides keyed by name.  *  * @return array → The modified colors.  */ add_filter( 'prxctrl_theme_colors', function( $colors ) {     $colors[ 'header-bg' ]    = '#14213D';     $colors[ 'accent' ]       = '#FCA311';     $colors[ 'button' ]       = '#FCA311';     $colors[ 'button-font' ]  = '#14213D';     $colors[ 'button-hover' ] = '#E08E0B';      return $colors; } );

prxctrl_header_right

TYPE ⇢ Action

RUNS ON ⇢ Host and Agent

Prints content on the right side of the header on every page of the plugin.

  • $current (string): The page slug, such as dashboard, sites, logs or settings.

Things to know:

  • Escape everything you print.

Example Usage

PHP
/**  * Add a support link to the header.  *  * @param string $current → The current page slug.  */ add_action( 'prxctrl_header_right', function( $current ) {     echo '<a href="' . esc_url( 'https://support.example.com' ) . '" target="_blank" rel="noopener noreferrer">' . esc_html__( 'Support', 'my-plugin' ) . '</a>'; } );

prxctrl_subheader_left

TYPE ⇢ Action

RUNS ON ⇢ Host and Agent

Prints content next to the page title in the sub header, where buttons such as Check All, Clear All and Save live.

  • $current (string): The page slug.

Things to know:

  • Escape everything you print.

Example Usage

PHP
/**  * Add an Export button next to the Logs title.  *  * @param string $current → The current page slug.  */ add_action( 'prxctrl_subheader_left', function( $current ) {     if ( 'logs' !== $current ) {         return;     }      echo '<a class="prxctrl-button prxctrl-button-secondary" href="' . esc_url( admin_url( 'admin-post.php?action=my_export_logs' ) ) . '">' . esc_html__( 'Export CSV', 'my-plugin' ) . '</a>'; } );

prxctrl_subheader_right

TYPE ⇢ Action

RUNS ON ⇢ Host and Agent

Prints content on the right side of the sub header, where the search box and help links live.

  • $current (string): The page slug.

Things to know:

  • Escape everything you print.

Example Usage

PHP
/**  * Show the current environment on the dashboard.  *  * @param string $current → The current page slug.  */ add_action( 'prxctrl_subheader_right', function( $current ) {     if ( 'dashboard' !== $current ) {         return;     }      echo '<span class="prxctrl-muted">' . esc_html( strtoupper( wp_get_environment_type() ) ) . '</span>'; } );

prxctrl_can_access

TYPE ⇢ Filter

RUNS ON ⇢ Host and Agent

Changes who can open the Dashboard, Sites and Logs pages. Administrators and the roles chosen under Additional Roles With Access are allowed by default. On the network admin, only super admins are.

  • $allowed (bool): Whether the user is allowed.
  • $user (WP_User): The current user.

Things to know:

  • Settings and everything that changes data are controlled by prxctrl_can_manage.

Example Usage

PHP
/**  * Let a capability or a specific account in.  *  * @param bool    $allowed → Whether the user is allowed.  * @param WP_User $user    → The current user.  *  * @return bool → The modified value.  */ add_filter( 'prxctrl_can_access', function( $allowed, $user ) {     // Anyone who can edit others' posts can view the dashboard     if ( user_can( $user, 'edit_others_posts' ) ) {         return true;     }      // A contractor with a specific email     return $allowed || '[email protected]' === $user->user_email; }, 10, 2 );

prxctrl_can_manage

TYPE ⇢ Filter

RUNS ON ⇢ Host and Agent

Changes who can change settings, clear logs and use the plugin’s management tools. Users with manage_options (or manage_network_options on the network admin) are allowed by default.

  • $allowed (bool): Whether the user is allowed.
  • $user (WP_User): The current user.

Example Usage

PHP
/**  * Only specific accounts may change Control Center settings, even if other users are administrators.  *  * @param bool    $allowed → Whether the user is allowed.  * @param WP_User $user    → The current user.  *  * @return bool → The modified value.  */ add_filter( 'prxctrl_can_manage', function( $allowed, $user ) {     $managers = [ '[email protected]', '[email protected]' ];      return $allowed && in_array( $user->user_email, $managers, true ); }, 10, 2 );

prxctrl_test_mode

TYPE ⇢ Filter

RUNS ON ⇢ Host and Agent

Turns test mode on or off. In test mode, scripts and styles are versioned with the current time so changes show up right away. It follows the test mode setting in Developer Debug Tools by default.

  • $test_mode (mixed): The Developer Debug Tools test mode option.

Example Usage

PHP
/**  * Use test mode on development and local environments only.  *  * @param mixed $test_mode → The test mode value.  *  * @return bool → Whether test mode is on.  */ add_filter( 'prxctrl_test_mode', function( $test_mode ) {     return in_array( wp_get_environment_type(), [ 'local', 'development' ], true ); } );

Options::get( $key )

TYPE ⇢ Static method

AVAILABLE ⇢ Everywhere

Gets a plugin setting, or its default when it has not been saved. Returns null for a key that does not exist. When the Control Center runs in the network admin, host and global settings are stored network-wide.

  • $key (string): The setting key without the prxctrl_ prefix.

Returns: mixed The saved value, the default, or null if the key does not exist.

Things to know:

  • Common keys: sorting, jump_menu, screenshots, concurrency, timeout, log_retention, wp_warning, php_warning, ssl_warning_days, admin_inactive_days, link_fields, agent_remote_access, agent_domains, agent_permissions and agent_require_signed.

Example Usage

PHP
use PluginRx\ControlCenter\Options;  // How long the Control Center waits for a site $timeout = (int) Options::get( 'timeout' );  // The domains allowed to connect to this agent $domains = (array) Options::get( 'agent_domains' );  // Whether this agent shares its plugin list $shares_plugins = in_array( 'plugins', (array) Options::get( 'agent_permissions' ), true );

Options::update( $key, $value )

TYPE ⇢ Static method

AVAILABLE ⇢ Everywhere

Sanitizes a value for its setting type and saves it. Keys that do not exist are ignored.

  • $key (string): The setting key without the prefix.
  • $value (mixed): The new value. It is sanitized for the setting type.

Returns: void

Things to know:

  • agent_api_key must be 64 lowercase hexadecimal characters, or it is saved as empty.

Example Usage

PHP
use PluginRx\ControlCenter\Options;  // Turn on remote access for this agent and allow one Control Center Options::update( 'agent_remote_access', 1 ); Options::update( 'agent_domains', 'controlcenter.example.com' );  // Share only version information Options::update( 'agent_permissions', [ 'wordpress_version', 'core_update', 'php_version', 'plugins', 'themes' ] );  // Warn when WordPress is one minor version behind. Choices: exact, minor, previous, major, off Options::update( 'wp_warning', 'previous' );

Options::delete( $key )

TYPE ⇢ Static method

AVAILABLE ⇢ Everywhere

Deletes a saved setting so it falls back to its default.

  • $key (string): The setting key without the prefix.

Returns: void

Example Usage

PHP
use PluginRx\ControlCenter\Options;  // Go back to the default timeout Options::delete( 'timeout' );

Mode::get(), Mode::has_host(), Mode::has_agent()

TYPE ⇢ Static method

AVAILABLE ⇢ Everywhere

Reads the site role. Mode::get() returns host, agent, both, or an empty string until setup is complete. has_host() is true for Host and Both. has_agent() is true for Agent and Both.

Returns: string|bool The role string for get(), a bool for the others.

Things to know:

  • Mode::HOST, Mode::AGENT and Mode::BOTH are available as constants.

Example Usage

PHP
use PluginRx\ControlCenter\Mode;  // Only do this on a site that runs the Control Center if ( Mode::has_host() ) {     add_action( 'admin_notices', function() {         echo '<div class="notice notice-info"><p>' . esc_html__( 'You are on the Control Center.', 'my-plugin' ) . '</p></div>';     } ); }  // Only share extra data from sites that act as agents if ( Mode::has_agent() ) {     add_filter( 'prxctrl_agent_response', function( $data ) {         $data[ 'my_extra' ] = 'value';          return $data;     } ); }

Access::can_access() and Access::can_manage()

TYPE ⇢ Static method

AVAILABLE ⇢ Everywhere

can_access() checks whether the current user may open the Dashboard, Sites and Logs pages. can_manage() checks whether they may change settings and clear logs. Both run their filters, prxctrl_can_access and prxctrl_can_manage.

Returns: bool

Example Usage

PHP
use PluginRx\ControlCenter\Access;  // Show a link to the dashboard only to people who can open it add_action( 'admin_bar_menu', function( $bar ) {     if ( ! Access::can_access() ) {         return;     }      $bar->add_node( [         'id'    => 'my-control-center',         'title' => __( 'Control Center', 'my-plugin' ),         'href'  => \PluginRx\ControlCenter\Helpers::page_url( 'dashboard' ),     ] ); }, 100 );

Database::get_sites( $details = false )

TYPE ⇢ Static method

AVAILABLE ⇢ Everywhere

Gets every site the Control Center manages, in the order set by the Sorting setting. Each site is an object.

  • $details (bool): When true, also attach plugins, themes, admin_users and integrations. Default false.

Returns: array Site objects.

Things to know:

  • Common properties: id, site_url, site_name, group_id, status (ok, error or empty if never checked), last_checked, last_error, wordpress_version, core_update, php_version, wp_debug, admin_email, http_status, response_ms, ssl_expires, permissions (array, or null if unknown), links (array keyed by link field slug) and notes.
  • Each plugin and theme has slug (the plugin file for plugins), name, author, version, is_active (1 or 0) and update_available (1 or 0). Plugins also have is_required. Each admin user has user_id, user_login, display_name, user_email, role and user_registered.
  • Use it on a site that runs the Control Center (Host or Both).

Example Usage

PHP
use PluginRx\ControlCenter\Database;  // Names of sites that failed their last check $failing = [];  foreach ( Database::get_sites() as $site ) {     if ( 'error' === $site->status ) {         $failing[] = $site->site_name . ' (' . $site->last_error . ')';     } }  // Plugins that need an update on each site. Pass true to include plugin details $needs_updates = [];  foreach ( Database::get_sites( true ) as $site ) {     foreach ( (array) $site->plugins as $plugin ) {         if ( ! empty( $plugin->update_available ) ) {             $needs_updates[ $site->site_name ][] = $plugin->name . ' ' . $plugin->version;         }     } }

Database::get_site( $site_id, $details = false )

TYPE ⇢ Static method

AVAILABLE ⇢ Everywhere

Gets one site by ID. Returns null when it does not exist.

  • $site_id (int): The site ID.
  • $details (bool): Also attach plugins, themes, admin users and integration values. Default false.

Returns: object|null

Example Usage

PHP
use PluginRx\ControlCenter\Database;  $site = Database::get_site( 12, true );  if ( $site ) {     // The value another plugin's integration shared, or "N/A" while that plugin is inactive     $broken_links = \PluginRx\ControlCenter\Registry::value( $site, 'broken_link_notifier_count' );      echo esc_html( sprintf( '%s has %s broken links.', $site->site_name, $broken_links ) ); }

Database::get_site_by_url( $site_url )

TYPE ⇢ Static method

AVAILABLE ⇢ Everywhere

Gets a site by its exact saved URL. Normalize the URL first so a trailing slash, a missing scheme or upper case letters do not cause a miss.

  • $site_url (string): The saved site URL.

Returns: object|null

Example Usage

PHP
use PluginRx\ControlCenter\Database; use PluginRx\ControlCenter\Helpers;  // Normalize first: lowercase scheme and host, no trailing slash, https:// added if missing $site = Database::get_site_by_url( Helpers::normalize_url( 'Client-Site.com/' ) );  if ( $site ) {     echo esc_html( $site->site_name ); }

Database::insert_site( $data )

TYPE ⇢ Static method

AVAILABLE ⇢ Everywhere

Adds a site to the Control Center and runs prxctrl_site_added. Returns the new site ID, or 0 when the URL is missing, already exists, or the insert failed.

  • $data (array): Columns to save. site_url is required. Others include site_name, api_key, group_id, notes and login_url.

Returns: int The site ID, or 0.

Things to know:

  • Nothing is sanitized or validated for you. Normalize the URL with Helpers::normalize_url(), and use a 64-character lowercase hexadecimal API key that no other site uses.
  • Check the site afterward with the Check Site button, or the new site will show as “Not checked.”

Example Usage

PHP
use PluginRx\ControlCenter\Database; use PluginRx\ControlCenter\Helpers;  // Add a client site when a project is created in your own system $site_url = Helpers::normalize_url( 'https://client-site.com' );  if ( $site_url && ! Database::get_site_by_url( $site_url ) ) {     $site_id = Database::insert_site( [         'site_url'   => $site_url,         'site_name'  => sanitize_text_field( 'Client Site' ),         // Paste the key generated on the agent (Settings > Agent > API Key)         'api_key'    => strtolower( preg_replace( '/[^a-f0-9]/i', '', 'PASTE_64_CHARACTER_KEY_HERE' ) ),         'notes'      => 'Added automatically from the project tracker.',     ] ); }

Database::update_site( $site_id, $data )

TYPE ⇢ Static method

AVAILABLE ⇢ Everywhere

Updates columns on a site. Only the site table’s columns are written; array values are saved as JSON. Returns true unless the query failed.

  • $site_id (int): The site ID.
  • $data (array): Columns to change.

Returns: bool

Things to know:

  • Nothing is sanitized for you.

Example Usage

PHP
use PluginRx\ControlCenter\Database;  $site = Database::get_site_by_url( 'https://client-site.com' );  if ( $site ) {     Database::update_site( $site->id, [         'site_name' => 'Client Site (Retainer)',         'notes'     => $site->notes . "\nMoved to the retainer plan.",         // Link fields are saved by slug         'links'     => array_merge( $site->links, [ 'hosting' => 'https://host.example.com/accounts/1234' ] ),     ] ); }

Database::delete_site( $site_id )

TYPE ⇢ Static method

AVAILABLE ⇢ Everywhere

Removes a site and its saved plugins, themes, admin users and integration values, then runs prxctrl_site_deleted. Its log entries are kept.

  • $site_id (int): The site ID.

Returns: bool

Example Usage

PHP
use PluginRx\ControlCenter\Database;  // Remove a site when the client's contract ends $site = Database::get_site_by_url( 'https://former-client.com' );  if ( $site ) {     Database::delete_site( $site->id ); }

Database::log( $site_id, $action, $success, $context = ”, $details = ”, $requester = ” )

TYPE ⇢ Static method

AVAILABLE ⇢ Everywhere

Adds an entry to the Logs page. The current user and IP address are saved automatically.

  • $site_id (int): The site ID, or 0 for this site.
  • $action (string): A key for what happened. It is shown as a readable label.
  • $success (bool): true for a success, false for an error.
  • $context (string): Where it came from. Optional.
  • $details (string): A message. Optional, and run through prxctrl_log_details.
  • $requester (string): Who asked, for agent events. Optional.

Returns: int The log ID, or 0 if it could not be saved.

Things to know:

  • Do not call this from prxctrl_log_added.

Example Usage

PHP
use PluginRx\ControlCenter\Database;  // Record a nightly import in the Control Center logs add_action( 'my_nightly_import', function() {     $site = Database::get_site_by_url( 'https://client-site.com' );     $count = my_run_import();      Database::log( $site ? $site->id : 0, 'nightly_import', $count > 0, 'my_plugin', sprintf( 'Imported %d records.', $count ) ); } );

Dashboard::check_site( $site )

TYPE ⇢ Static method

AVAILABLE ⇢ Admin only

Checks a site the same way the Check Site button does: it requests the agent’s data, measures the response time and SSL certificate, saves the result, and runs prxctrl_site_data and prxctrl_site_checked.

  • $site (object): A site object from Database::get_site().

Returns: array [ ‘success’ => bool, ‘message’ => string ]

Things to know:

  • This class is only loaded in the admin area, which includes admin-ajax.php and admin-post.php. It is not available to WP-Cron or front-end requests.

Example Usage

PHP
use PluginRx\ControlCenter\Database; use PluginRx\ControlCenter\Dashboard;  // Re-check a site from your own admin-post handler, for example from a "Refresh" button add_action( 'admin_post_my_refresh_site', function() {     check_admin_referer( 'my_refresh_site' );      if ( ! \PluginRx\ControlCenter\Access::can_access() ) {         wp_die( esc_html__( 'You do not have permission to do this.', 'my-plugin' ), 403 );     }      $site = Database::get_site( absint( $_POST[ 'site_id' ] ?? 0 ) );      if ( $site ) {         $result = Dashboard::check_site( $site );          if ( ! $result[ 'success' ] ) {             wp_die( esc_html( $result[ 'message' ] ) );         }     }      wp_safe_redirect( \PluginRx\ControlCenter\Helpers::page_url( 'dashboard' ) );     exit; } );

Registry::value( $site, $key ) and Registry::has_value( $value )

TYPE ⇢ Static method

AVAILABLE ⇢ Everywhere

value() gets the last saved value of an integration request for a site. It returns null if it was never shared, or "N/A" (Registry::NOT_ACTIVE) if the plugin is not active on the agent. has_value() is true for anything that is not empty, zero, false or “N/A.”

  • $site (object): A site from Database::get_site( $id, true ).
  • $key (string): The integration request key.
  • $value (mixed): A value to test.

Returns: mixed|bool

Example Usage

PHP
use PluginRx\ControlCenter\Database; use PluginRx\ControlCenter\Registry;  // List sites that have broken links, from Broken Link Notifier $report = [];  foreach ( Database::get_sites( true ) as $site ) {     $count = Registry::value( $site, 'broken_link_notifier_count' );      if ( Registry::has_value( $count ) ) {         $report[] = sprintf( '%s: %s', $site->site_name, $count );     } }

Registry::integrations(), requests(), actions(), widgets() and permissions()

TYPE ⇢ Static method

AVAILABLE ⇢ Everywhere

Get the final lists after every filter has run, such as prxctrl_integrations, prxctrl_requests and prxctrl_actions. Results are cached for the request. Call Registry::flush() after changing something that affects them.

Returns: array

Example Usage

PHP
use PluginRx\ControlCenter\Registry;  // Everything this site could be asked to share or do, with labels foreach ( Registry::permissions() as $key => $permission ) {     printf( "%s | %s | %s\n", $key, $permission[ 'label' ], $permission[ 'kind' ] ); }  // Check that your integration registered if ( ! isset( Registry::integrations()[ 'my_shop' ] ) ) {     error_log( 'The My Shop integration did not register.' ); }

TYPE ⇢ Static method

AVAILABLE ⇢ Everywhere

Creates a single-use login link for the account chosen under Log In As in the Agent settings. The link expires after 60 seconds. This is the same method the Control Center’s Remote Login button calls.

Returns: array|WP_Error [ ‘url’ => string, ‘expires’ => int ]

Things to know:

  • Returns a WP_Error with the code login_user_missing if no administrator is selected. Making a link does not check Allow Remote Login or the caller, so check both yourself before handing it out.

Example Usage

PHP
use PluginRx\ControlCenter\Login; use PluginRx\ControlCenter\Options;  // A support button that logs the current support agent into this site for 60 seconds add_action( 'admin_post_my_support_login', function() {     check_admin_referer( 'my_support_login' );      if ( ! current_user_can( 'manage_options' ) || ! in_array( 'remote_login', (array) Options::get( 'agent_permissions' ), true ) ) {         wp_die( esc_html__( 'You do not have permission to do this.', 'my-plugin' ), 403 );     }      $link = Login::create_link();      if ( is_wp_error( $link ) ) {         wp_die( esc_html( $link->get_error_message() ) );     }      wp_safe_redirect( $link[ 'url' ] );     exit; } );

Helpers::page_url( $page, $args = [] )

TYPE ⇢ Static method

AVAILABLE ⇢ Everywhere

Builds the URL of one of the plugin’s pages, in the network admin when the Control Center lives there.

  • $page (string): The page slug: dashboard, sites, logs, settings or one you added with prxctrl_pages.
  • $args (array): Extra query arguments. Optional.

Returns: string

Things to know:

  • Logs accepts the filters site, log_action, context and status. Settings accepts tab.

Example Usage

PHP
use PluginRx\ControlCenter\Helpers;  // Link straight to the failed checks of one site $url = Helpers::page_url( 'logs', [ 'site' => 12, 'status' => 'error', 'log_action' => 'check_site' ] );  echo '<a href="' . esc_url( $url ) . '">' . esc_html__( 'View failed checks', 'my-plugin' ) . '</a>';  // Link to the Agent settings $agent_settings = Helpers::page_url( 'settings', [ 'tab' => 'agent' ] );

Helpers::normalize_url( $url ), Helpers::host( $value ) and Helpers::format_date( $date )

TYPE ⇢ Static method

AVAILABLE ⇢ Everywhere

normalize_url() turns a URL into the form the plugin saves (http or https only, lowercase, no trailing slash, query or fragment) and returns an empty string if it is invalid. host() returns just the lowercase host without the scheme, port, path or www.. format_date() formats a MySQL date or Unix timestamp using the plugin’s Date Format and Timezone settings.

  • $url (string): A URL.
  • $value (string): A URL or host.
  • $date (string|int): A MySQL datetime in site time, or a Unix timestamp.

Returns: string

Example Usage

PHP
use PluginRx\ControlCenter\Helpers;  // "https://client-site.com" $url = Helpers::normalize_url( 'HTTPS://Client-Site.com/?utm=1' );  // "client-site.com", good for comparing two URLs $same_site = Helpers::host( 'https://www.client-site.com/about' ) === Helpers::host( $url );  // Shown the way the Logs and Dashboard pages show it echo esc_html( Helpers::format_date( '2026-11-05 14:30:00' ) );

Sign In

Register

Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.

Seraphinite AcceleratorOptimized by Seraphinite Accelerator
Turns on site high speed to be attractive for people and search engines.