403 )
);
}
if ( ! defined( 'WPBRIGADE_SDK__DEV_MODE' ) || true !== WPBRIGADE_SDK__DEV_MODE ) {
wp_die(
esc_html__( 'Debug mode is not enabled.', 'wp-headers-and-footers' ),
'',
array( 'response' => 403 )
);
}
/**
* Enqueue CSS file for admin debugging.
*/
function wpb_debug_enqueue_styles() {
wp_enqueue_style(
'custom-debug-style',
plugins_url( 'admin/css/debug.css', __FILE__ ),
array(),
defined( 'WP_WPBRIGADE_SDK_VERSION' ) ? WP_WPBRIGADE_SDK_VERSION : '1.0.0'
);
}
add_action( 'wp_enqueue_scripts', 'wpb_debug_enqueue_styles' );
/**
* Verify POST request: method, capability, and nonce for a given action.
*
* @param string $action Nonce action (e.g. 'wpb_debug_clear_cache').
* @return bool True if valid POST with valid nonce and capability.
*/
function wpb_debug_verify_request( $action ) {
if ( ! isset( $_SERVER['REQUEST_METHOD'] ) || 'POST' !== $_SERVER['REQUEST_METHOD'] ) {
return false;
}
if ( ! current_user_can( 'manage_options' ) ) {
return false;
}
if ( ! isset( $_POST['_wpnonce'] ) ) {
return false;
}
return (bool) wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), $action );
}
/**
* Mask a sensitive string (show last N chars, rest as bullets).
*
* @param string $value Raw value.
* @param int $visible Number of trailing characters to show.
* @return string Masked value.
*/
function wpb_debug_mask( $value, $visible = 4 ) {
if ( '' === (string) $value ) {
return '—';
}
$value = (string) $value;
$len = strlen( $value );
if ( $len <= $visible ) {
return str_repeat( '•', $len );
}
return str_repeat( '•', $len - $visible ) . substr( $value, - $visible );
}
/**
* Mask email for display (e.g. a***@***.com).
*
* @param string $email Email address.
* @return string Masked email.
*/
function wpb_debug_mask_email( $email ) {
if ( '' === (string) $email || ! is_email( $email ) ) {
return '—';
}
$parts = explode( '@', $email, 2 );
if ( 2 !== count( $parts ) ) {
return wpb_debug_mask( $email, 0 );
}
$local = $parts[0];
$domain = $parts[1];
$local_display = strlen( $local ) > 2 ? substr( $local, 0, 1 ) . str_repeat( '•', strlen( $local ) - 1 ) : '••';
$domain_display = strlen( $domain ) > 4 ? '•••' . substr( $domain, -4 ) : '••••';
return $local_display . '@' . $domain_display;
}
/**
* Shorten path for display (show last two segments to avoid exposing full server path).
*
* @param string $path Full path.
* @return string Shortened path.
*/
function wpb_debug_mask_path( $path ) {
if ( '' === (string) $path ) {
return '—';
}
$path = str_replace( array( '\\', '/' ), '/', (string) $path );
$parts = array_filter( explode( '/', $path ) );
$tail = array_slice( $parts, -2 );
return ( count( $parts ) > 2 ? '…/' : '' ) . implode( '/', $tail );
}
$slug = get_option( 'wpb_sdk_module_slug' );
$wpb_sdk_module_id = get_option( 'wpb_sdk_module_id' );
$all_plugins = array();
$wpb = WPBRIGADE_Logger::instance( $wpb_sdk_module_id, $slug, true );
$data = $wpb->get_logs_data( $slug );
$plugin_path = isset( $data['product_info']['path'] ) ? $data['product_info']['path'] : '';
$installed_plugin_slugs = array_keys( get_plugins() );
$active_plugins = get_option( 'active_plugins', array() );
$sdk_path = WPBRIGADE_SDK_DIR;
$this_sdk_path = strstr( $sdk_path, $slug );
if ( false !== $this_sdk_path ) {
$this_sdk_path = '\\' . ltrim( $this_sdk_path, '\\' );
}
// Clear API cache.
if ( isset( $_POST['wpb_clear_api_cache'] ) && 'true' === $_POST['wpb_clear_api_cache'] && wpb_debug_verify_request( 'wpb_debug_clear_cache' ) ) {
update_option( 'wpb_api_cache', null );
}
// Clear updates data.
if ( isset( $_POST['wpb_action'] ) && 'clear_updates_data' === $_POST['wpb_action'] && wpb_debug_verify_request( 'wpb_debug_clear_updates' ) ) {
set_site_transient( 'update_plugins', null );
set_site_transient( 'update_themes', null );
}
// Background sync.
if ( isset( $_POST['background_sync'] ) && 'true' === $_POST['background_sync'] && wpb_debug_verify_request( 'wpb_debug_background_sync' ) ) {
$response = wp_remote_post(
WPBRIGADE_SDK_API_ENDPOINT,
array(
'method' => 'POST',
'body' => $data,
'timeout' => 5,
'headers' => array(),
)
);
if ( is_wp_error( $response ) ) {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- Debug view only.
error_log( 'Error sending data: ' . $response->get_error_message() );
} else {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- Debug view only.
error_log( 'Log sent successfully' . wp_json_encode( $data ) );
}
}
/** Option name prefix allowed for Set DB Option (strict whitelist by prefix). */
define( 'WPB_DEBUG_OPTION_PREFIX', 'wpb_' );
/**
* Set an option value only if it is in the allowed prefix scope.
*
* @param string $option_name Option name (must start with WPB_DEBUG_OPTION_PREFIX).
* @param mixed $option_value Option value.
* @return bool True on success, false if not allowed.
*/
function wpb_debug_set_option( $option_name, $option_value ) {
if ( ! current_user_can( 'manage_options' ) ) {
return false;
}
$option_name = sanitize_text_field( $option_name );
if ( '' === $option_name || 0 !== strpos( $option_name, WPB_DEBUG_OPTION_PREFIX ) ) {
return false;
}
update_option( $option_name, $option_value );
return true;
}
$wpb_debug_set_option_success = false;
$wpb_debug_set_option_submitted = false;
if ( isset( $_POST['set_option_name'], $_POST['option_value'] ) && wpb_debug_verify_request( 'wpb_debug_set_option' ) ) {
$wpb_debug_set_option_submitted = true;
$option_name = sanitize_text_field( wp_unslash( $_POST['set_option_name'] ) );
$option_value = isset( $_POST['option_value'] ) ? sanitize_text_field( wp_unslash( $_POST['option_value'] ) ) : '';
$wpb_debug_set_option_success = wpb_debug_set_option( $option_name, $option_value );
}
/**
* Get an option value from the database.
*
* @param string $option_name Option name.
* @return mixed Option value.
*/
function wpb_debug_get_option_value( $option_name ) {
return get_option( sanitize_text_field( $option_name ) );
}
$option_value = '';
$result_visible = false;
if ( isset( $_POST['load_option_name'] ) && wpb_debug_verify_request( 'wpb_debug_load_option' ) ) {
$option_name = sanitize_text_field( wp_unslash( $_POST['load_option_name'] ) );
$option_value = wpb_debug_get_option_value( $option_name );
$result_visible = true;
}
$wpb_debug_msg_success = __( 'Successfully set the option.', 'wp-headers-and-footers' );
$wpb_debug_msg_error = __( 'Option not set. Name must start with wpb_.', 'wp-headers-and-footers' );
?>
WPB Debug - SDK v.
| Key |
Value |
| WP_WPB__REMOTE_ADDR |
|
| WP_WPB__DIR |
|
| wp_using_ext_object_cache() |
false |
SDK Versions
| Version |
SDK Path |
Module Path |
Is Active |
|
|
|
Active |
Plugins
| ID |
Slug |
Version |
Title |
API |
Telemetry State |
Module Path |
Public Key |
Actions |
|
|
|
|
|
|
|
|
|
Plugins/Sites
| ID |
Slug |
User ID |
License ID |
Plan |
Public Key |
Secret Key |
| 3538 |
|
|
|
|
|
|
Users
| ID |
Name |
Email |
Verified |
Public Key |
Secret Key |
| 3538 |
|
|
|
|
|