This manual describes a common issue with workflow automation when using authentication on your website. Whether using .htaccess to limit access or other forms of basic authentication, you might encounter issues with your automated workflows. This is because the internal requests made by the Automations (Flows) can’t authenticate to the server by default (As they are just simple HTTP requests).
But don’t worry, we have a solution. We’ve crafted a simple PHP snippet that allows you to authenticate internal requests using your Basic Auth credentials. Here’s how to do it:
The Solution: A PHP Snippet
This PHP function that hooks the WP Webhooks plugin’s HTTP request arguments for internal Flow actions while adding an Authorization header to the HTTP request, which includes your Basic Auth credentials.
add_filter( 'wpwhpro/flows/fire_flow/http_args', 'wpwh_custom_apply_basic_authentiaction', 10, 3 ); function wpwh_custom_apply_basic_authentiaction( $http_args, $endpoint_url, $webhook ) { $username = 'Your Username'; $password = 'The password'; if( ! empty( $username ) && ! empty( $password ) ){ $http_args['headers']['Authorization'] = 'Basic ' . base64_encode( $username . ':' . $password ); } return $http_args; }
How to Implement the Solution
- Backup Your Site
Before making any changes, it’s always a good idea to back up your website. This way, if anything goes wrong, you can easily revert to the previous state. - Access Your Site’s Files
Next, you need to access your site’s files. This can be done through your hosting provider’s cPanel or any FTP client. - Find Your Child Theme’s functions.php File
The code snippet needs to be added to your child theme’sfunctions.php
file. You can find this file in the directorywp-content/themes/your-theme-name/
. Please make sure it is the child theme and not the main theme as otherwise your changes will be overwritten with the next theme update. - Edit the Functions File
Open thefunctions.php
file in a text editor. Paste the code at the bottom of the file. - Replace the Credentials
ReplaceYour Username
andThe password
with your actual Basic Auth credentials. - Save and Upload the File
Once you’ve made the changes, save thefunctions.php
file and upload it back to your server. - Check Your Site
After you’ve uploaded the file, check your site to make sure everything is working as expected and give the Flow another try. This time, the actions will be able to communicate internal using the provided authentication credentials.
You can, of course, implement this snippet in a custom plugin as well.
That’s all you need to do. Happy automating!