diff --git a/wordpress-dev/bin/setup-zoho-credentials.php b/wordpress-dev/bin/setup-zoho-credentials.php new file mode 100644 index 00000000..40549185 --- /dev/null +++ b/wordpress-dev/bin/setup-zoho-credentials.php @@ -0,0 +1,125 @@ + 'ZohoCRM.settings.all,ZohoCRM.modules.all,ZohoCRM.users.all,ZohoCRM.org.all', + 'client_id' => $client_id, + 'response_type' => 'code', + 'access_type' => 'offline', + 'redirect_uri' => $redirect_uri, + 'prompt' => 'consent' +]); + +echo "\nStep 2: Authorization\n"; +echo "-------------------\n"; +echo "Open this URL in your browser:\n\n"; +echo "$auth_url\n\n"; +echo "After authorization, you'll be redirected to:\n"; +echo "$redirect_uri?code=YOUR_AUTH_CODE\n\n"; + +echo "Enter the authorization code from the URL: "; +$auth_code = trim(fgets(STDIN)); + +if (empty($auth_code)) { + die("Error: Authorization code is required.\n"); +} + +// Exchange code for tokens +echo "\nStep 3: Exchanging code for tokens...\n"; +echo "-----------------------------------\n"; + +$token_url = 'https://accounts.zoho.com/oauth/v2/token'; +$token_params = [ + 'grant_type' => 'authorization_code', + 'client_id' => $client_id, + 'client_secret' => $client_secret, + 'redirect_uri' => $redirect_uri, + 'code' => $auth_code +]; + +// Use cURL to make the request +$ch = curl_init($token_url); +curl_setopt($ch, CURLOPT_POST, true); +curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($token_params)); +curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); +curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); + +$response = curl_exec($ch); +$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); +curl_close($ch); + +if ($http_code !== 200) { + echo "Error: Failed to get tokens (HTTP $http_code)\n"; + echo "Response: " . $response . "\n"; + exit(1); +} + +$token_data = json_decode($response, true); + +if (!isset($token_data['access_token']) || !isset($token_data['refresh_token'])) { + echo "Error: Invalid token response\n"; + echo "Response: " . $response . "\n"; + exit(1); +} + +// Success! Display the values +echo "✓ Tokens received successfully!\n\n"; +echo "Here are your Zoho CRM credentials:\n"; +echo "--------------------------------\n"; +echo "Client ID: $client_id\n"; +echo "Client Secret: $client_secret\n"; +echo "Refresh Token: " . $token_data['refresh_token'] . "\n\n"; + +// Generate wp-config.php code +echo "Add these lines to your wp-config.php file:\n"; +echo "----------------------------------------\n"; +echo "define('ZOHO_CLIENT_ID', '$client_id');\n"; +echo "define('ZOHO_CLIENT_SECRET', '$client_secret');\n"; +echo "define('ZOHO_REFRESH_TOKEN', '" . $token_data['refresh_token'] . "');\n"; +echo "define('ZOHO_DIAGNOSTICS_ENABLED', true);\n\n"; + +// Generate environment variables setup +echo "Or set these environment variables in your .env file:\n"; +echo "-----------------------------------------------\n"; +echo "ZOHO_CLIENT_ID=$client_id\n"; +echo "ZOHO_CLIENT_SECRET=$client_secret\n"; +echo "ZOHO_REFRESH_TOKEN=" . $token_data['refresh_token'] . "\n\n"; + +echo "To verify your setup, run the diagnostics script:\n"; +echo "--------------------------------------------\n"; +echo "$staging_url/wp-content/plugins/hvac-community-events/includes/zoho/diagnostics.php?run_diagnostics=true\n\n"; + +echo "=== Setup Complete! ===\n"; \ No newline at end of file diff --git a/wordpress-dev/wordpress/wp-content/plugins/hvac-community-events/includes/zoho/check-permissions.php b/wordpress-dev/wordpress/wp-content/plugins/hvac-community-events/includes/zoho/check-permissions.php new file mode 100644 index 00000000..1302a48d --- /dev/null +++ b/wordpress-dev/wordpress/wp-content/plugins/hvac-community-events/includes/zoho/check-permissions.php @@ -0,0 +1,144 @@ +user_login . "\n"; + echo "Can manage options: " . (current_user_can('manage_options') ? 'Yes' : 'No') . "\n"; + } else { + echo "Could not check user capabilities\n"; + } +} + +echo "\n=== Check Completed ===\n"; +echo "If you see any 'Failed' or 'No' responses, they may indicate issues with your Zoho CRM integration.\n"; +echo "See the diagnostic log for more details about the connection test failures."; \ No newline at end of file