Skip to content

Instantly share code, notes, and snippets.

@jonathanbossenger
Last active September 30, 2025 09:12
Show Gist options
  • Select an option

  • Save jonathanbossenger/4a61b00758631e73c27909f1d135ff42 to your computer and use it in GitHub Desktop.

Select an option

Save jonathanbossenger/4a61b00758631e73c27909f1d135ff42 to your computer and use it in GitHub Desktop.
// Register a custom ability to get the WordPress debug status.
add_action( 'abilities_api_init', 'my_plugin_register_debug_status_ability' );
/**
* Registers the 'my-plugin/debug-status' ability.
*
* @return void
*/
function my_plugin_register_debug_status_ability() {
wp_register_ability(
'my-plugin/debug-status',
array(
'label' => __( 'Get the WordPress debug status', 'my-plugin' ),
'description' => __( 'Retrieves the status of the WordPress Debugging Constants.', 'my-plugin' ),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'debug' => array(
'type' => 'boolean',
'description' => 'Status of WP_DEBUG constant',
),
'debug_display' => array(
'type' => 'boolean',
'description' => 'Status of WP_DEBUG_DISPLAY constant',
),
'debug_log' => array(
'type' => 'boolean',
'description' => 'Status of WP_DEBUG_LOG constant',
),
),
),
'execute_callback' => 'my_plugin_register_debug_status_execute_callback',
'permission_callback' => 'my_plugin_register_debug_status_permission_callback',
)
);
}
/**
* Executes the ability to get the WordPress debug status.
*
* @return array An array containing the status of WP_DEBUG, WP_DEBUG_DISPLAY, and WP_DEBUG_LOG constants.
*/
function my_plugin_register_debug_status_execute_callback() {
$debug = defined( 'WP_DEBUG' ) && WP_DEBUG;
$debug_display = defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG_DISPLAY;
$debug_log = defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG;
return array(
'debug' => $debug,
'debug_display' => $debug_display,
'debug_log' => $debug_log,
);
}
/**
* Permission callback to check if the current user can manage options.
*
* @return bool True if the user can manage options, false otherwise.
*/
function my_plugin_register_debug_status_permission_callback() {
return current_user_can( 'manage_options' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment