GithubHelp home page GithubHelp logo

rapaccinim / cf7-hook-4-amazon-sqs Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 61 KB

A simple PHP hook for getting data from Contact Form 7 (CF7) and send it to Amazon Simple Queue Service (SQS)

License: MIT License

PHP 100.00%

cf7-hook-4-amazon-sqs's Introduction

CF7 Hook 4 Amazon SQS cover

CF7 hook for sending data to Amazon SQS

A simple PHP hook for getting data from Contact Form 7 (CF7) and send it to Amazon Simple Queue Service (SQS)

Description

Amazon SQS is a queue service where you can send messages to. In this use case, we want to get the data entered by users on a CF7 form - a popular WordPress plugin - and send that data to the SQS. The code in this repo is basically a WordPress custom plugin that has to be uploaded in a dedicated folder like /wp-content/plugins/cf7-amazon-sqs.

Requirements

In order to use this code you need:

Installation

  • Create a dedicated plugin folder (e.g. cf7-amazon-sqs) containing the PHP source file inside /wp-content/plugins/ folder
  • Install the Amazon SDK as a dependency using Composer inside the plugin folder: composer require aws/aws-sdk-php
  • Activate the plugin through the your-site/wp-admin/plugins.php page

Configurations

  • The function add_custom_field is optional and can be used to assign a unique ID to the form submission.
  • In function cf7_amazon_sqs there's a check about the form title. The hook will send data to the Amazon SQS only if the title contains a TitleCustomString (change this string with your desired value).
  • In function cf7_amazon_sqs you can customize the posted data you are getting from CF7. Remember that the fields name (e.g. surname) have to be same in the CF7 dashboard.
  • In function cf7_amazon_sqs there's the $client variable that holds all the client details:
    • Change the region parameter with your curernt Amazon SQS region.
    • Consider a better authentication with environment variables than the hardcoded (but faster for development) solution you can see in credentials parameter.
  • In function cf7_amazon_sqs there's the $params variable that holds useful parameters like:
    • MessageAttributes - you can choose to use this parameter to send data to the Amazon SQS.
    • MessageBody - you can choose to use this parameter in addition (or as an alternative) to MessageAttributes to send data do the Amazon SQS.
    • QueueUrl - is the parameter that holds your Amazon SQS url (change it by replacing the example value yourAmazonSQSURL at the beginning of the cf7_amazon_sqs function).

Troubleshooting

  • To check if you are having some errors, activate WordPress debug mode and log in /wp-config.php adding the following lines of code:
     define('WP_DEBUG', true);
     define('WP_DEBUG_LOG', true);
    
    These 2 commands will write a debug.log inside the /wp-content folder anytime WordPress will face same warnings/errors.
  • Common issues that you could encounter:
    • Problem: you have freshly installed the SimpleXML extension for PHP, but you still get an error about missing extension in WordPress. Solution: try to restart the server (e.g. sudo systemctl restart apache2).
    • Problem: Composer is not globally installed. Solution: follow these commands if you are using Ubuntu 20.04 as server or refer to Composer's official documentation.
    • Problem: after installing Amazon SDK dependencies for PHP, WordPress cannot access the /vendor subfolder or related files, so permissions are messed up. Solution: go inside the plugin folder and change the permissions using chown with your WordPress instance couple user:group (generally it's www-data:www-data or apache:apache) running the command sudo chown -R yourWPInstanceUser:yourWPInstanceUserGroup *.
    • Problem: conflicts with other plugins' Composer dependencies. Solution: try to update/disable other plugins. Generally they use older versions of dependencies.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.