PHP code example of cdoebler / doppelganger

1. Go to this page and download the library: Download cdoebler/doppelganger library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cdoebler / doppelganger example snippets


// Disable the plugin completely
define('DOPPELGANGER_ENABLED', false);

// Restrict to development environments (comma-separated)
define('DOPPELGANGER_ALLOWED_ENVIRONMENTS', 'local,development');

// Or allow specific environments including staging
define('DOPPELGANGER_ALLOWED_ENVIRONMENTS', 'local,development,staging');

// Allow all environments (default)
define('DOPPELGANGER_ALLOWED_ENVIRONMENTS', '*');

// Enable dev mode - BYPASSES ALL SECURITY CHECKS
define('DOPPELGANGER_DEV_MODE', true);

add_filter('doppelganger_allowed_environments', function(array $environments): array {
    // Only allow in local and development
    return ['local', 'development'];
});

// Or allow multiple environments
add_filter('doppelganger_allowed_environments', function(array $environments): array {
    return ['local', 'development', 'staging'];
});

add_filter('doppelganger_can_switch', function(bool $canSwitch, int $currentUserId): bool {
    // Example: Allow users with manage_options capability instead
    return user_can($currentUserId, 'manage_options');

    // Or allow specific user IDs
    // return in_array($currentUserId, [1, 5, 10], true);

    // Or allow all users and even guests (helpful for debugging)
    // return true;
}, 10, 2);

add_filter('doppelganger_config', function(array $config): array {
    // You can modify the default config or return a completely new one
    $config['position'] = 'bottom-left'; // 'bottom-right', 'bottom-left', 'top-right', 'top-left'
    $config['param_name'] = '_my_custom_switch_param'; // Custom URL parameter name

    return $config;
});

// Disable the plugin via database
update_option('doppelganger_enabled', false);

// Re-enable it
update_option('doppelganger_enabled', true);