Skip to content

Instantly share code, notes, and snippets.

@Braunson
Created July 21, 2025 15:46
Show Gist options
  • Save Braunson/c1a74de54fe123fa091bf6a9ba843a1a to your computer and use it in GitHub Desktop.
Save Braunson/c1a74de54fe123fa091bf6a9ba843a1a to your computer and use it in GitHub Desktop.
WP Bakery Visual Composer fresh copy downloader. Download a fresh zip from of an authorized licensed version of the plugin. In my case the local plugin was modified by previous devs with no docs so I need to get a fresh unmodified version from the author to compare against the modified local version.
<?php
/**
* WPBakery Visual Composer Fresh Copy Downloader
* Uses the plugin's own update mechanism to download a clean copy
* Place this in your WordPress root directory and run via browser
*/
// Require WordPress
require_once('wp-config.php');
require_once('wp-load.php');
// Check if WPBakery is active
if (!defined('WPB_VC_VERSION')) {
die('WPBakery Visual Composer is not active or installed.');
}
echo "<h2>WPBakery Fresh Copy Downloader</h2>";
// Get current version and license
$current_version = WPB_VC_VERSION;
$license_key = get_option('wpb_js_composer_purchase_code');
if (!$license_key) {
die('No license key found. Please activate your license first.');
}
echo "Current Version: {$current_version}<br>";
echo "License Key: " . substr($license_key, 0, 10) . "..." . substr($license_key, -10) . "<br><br>";
// Include WPBakery's updater class
$updater_file = WP_PLUGIN_DIR . '/js_composer/include/classes/updaters/class-vc-updater.php';
if (file_exists($updater_file)) {
require_once($updater_file);
}
// Try to access the update API directly
function download_wpbakery_fresh_copy($license_key, $version) {
$api_url = 'https://wpbakery.com/updater/';
// Prepare request data (mimicking the plugin's update check)
$request_data = array(
'action' => 'get_version',
'version' => $version,
'purchase_code' => $license_key,
'site_url' => home_url(),
'item_name' => 'WPBakery Visual Composer'
);
// Make the API request
$response = wp_remote_post($api_url, array(
'timeout' => 30,
'body' => $request_data,
'user-agent' => 'WordPress/' . get_bloginfo('version') . '; ' . home_url()
));
if (is_wp_error($response)) {
return array('error' => 'API request failed: ' . $response->get_error_message());
}
$body = wp_remote_retrieve_body($response);
$data = json_decode($body, true);
return $data;
}
// Try to get download URL using the update mechanism
function get_wpbakery_download_url($license_key) {
// Check if there's an update available (even if same version)
$update_data = get_site_transient('update_plugins');
// Force check for updates
delete_site_transient('update_plugins');
wp_update_plugins();
// Look for WPBakery in the update data
$plugin_file = 'js_composer/js_composer.php';
// Try the direct API approach
$api_response = download_wpbakery_fresh_copy($license_key, WPB_VC_VERSION);
return $api_response;
}
// Alternative: Use WordPress's plugin download mechanism
function download_via_wp_updater($license_key) {
// Include WordPress updater
if (!function_exists('download_url')) {
require_once(ABSPATH . 'wp-admin/includes/file.php');
}
// Try to trigger the plugin's own download mechanism
$plugin_slug = 'js_composer/js_composer.php';
// Check if the plugin has update data
$plugins = get_plugins();
if (!isset($plugins[$plugin_slug])) {
return array('error' => 'Plugin not found in installed plugins list');
}
// Try to access the plugin's updater directly
$updater_class = 'Vc_Updater';
if (class_exists($updater_class)) {
$updater = new $updater_class();
// Try to get download URL
$download_url = $updater->getRemoteVersion();
return array('download_url' => $download_url);
}
return array('error' => 'Updater class not found');
}
// Main execution
echo "<h3>Attempting to get fresh download...</h3>";
// Method 1: Direct API
echo "<strong>Method 1: Direct API Access</strong><br>";
$api_result = download_wpbakery_fresh_copy($license_key, $current_version);
if (isset($api_result['error'])) {
echo "❌ " . $api_result['error'] . "<br><br>";
} else {
echo "✅ API Response received<br>";
echo "<pre>" . print_r($api_result, true) . "</pre>";
// If we got a download URL, try to download
if (isset($api_result['download_url'])) {
echo "<strong>Downloading fresh copy...</strong><br>";
$download_url = $api_result['download_url'];
$temp_file = download_url($download_url);
if (!is_wp_error($temp_file)) {
// Move to a permanent location
$upload_dir = wp_upload_dir();
$target_file = $upload_dir['path'] . '/wpbakery-fresh-' . $current_version . '.zip';
if (copy($temp_file, $target_file)) {
echo "✅ Fresh copy downloaded: <a href='" . $upload_dir['url'] . '/wpbakery-fresh-' . $current_version . '.zip' . "'>Download Here</a><br>";
unlink($temp_file); // Clean up temp file
} else {
echo "❌ Failed to save downloaded file<br>";
}
} else {
echo "❌ Download failed: " . $temp_file->get_error_message() . "<br>";
}
}
}
// Method 2: WordPress Updater
echo "<br><strong>Method 2: WordPress Update System</strong><br>";
$wp_result = download_via_wp_updater($license_key);
if (isset($wp_result['error'])) {
echo "❌ " . $wp_result['error'] . "<br>";
} else {
echo "✅ WordPress updater accessed<br>";
echo "<pre>" . print_r($wp_result, true) . "</pre>";
}
// Method 3: Manual instructions with exact API endpoints
echo "<br><hr><h3>Manual Download Method</h3>";
echo "<p>If automated methods fail, use these exact API calls:</p>";
$manual_curl = "curl -X POST 'https://wpbakery.com/updater/' \\
-H 'User-Agent: WordPress/" . get_bloginfo('version') . "; " . home_url() . "' \\
-d 'action=get_version' \\
-d 'version={$current_version}' \\
-d 'purchase_code={$license_key}' \\
-d 'site_url=" . home_url() . "' \\
-d 'item_name=WPBakery Visual Composer'";
echo "<pre style='background: #f0f0f0; padding: 10px; overflow-x: auto;'>{$manual_curl}</pre>";
// Method 4: Check for cached update data
echo "<br><strong>Method 3: Check Cached Update Data</strong><br>";
$update_plugins = get_site_transient('update_plugins');
if ($update_plugins && isset($update_plugins->response['js_composer/js_composer.php'])) {
$vc_update_data = $update_plugins->response['js_composer/js_composer.php'];
echo "✅ Found update data:<br>";
echo "<pre>" . print_r($vc_update_data, true) . "</pre>";
if (isset($vc_update_data->package)) {
echo "<strong>Package URL found:</strong> " . $vc_update_data->package . "<br>";
echo "<a href='{$vc_update_data->package}' target='_blank'>Try Direct Download</a><br>";
}
} else {
echo "❌ No update data found in transients<br>";
}
echo "<hr>";
echo "<h3>Next Steps:</h3>";
echo "<ol>";
echo "<li>If any download succeeded, extract the zip and compare with your current installation</li>";
echo "<li>Use <code>diff -r</code> or a GUI tool to compare directories</li>";
echo "<li>If all methods failed, the plugin might use a different API endpoint - check the plugin's updater class files</li>";
echo "</ol>";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment