Since we have demonstrated our connection to GSheets APIv4 from our web server, we can now move onto accessing it from a WordPress instance, in order to utilize it for filling in contents for Gravity Forms later.
- Install the Code Snippets plugin – it is free. This plugin brings us many advantages:
- No need to edit the functions.php file directly.
- We can activate and disable a code snippet at any point or run it as a one-off, at the back-end only or everywhere.
- Provides a powerful text editor that can highlight invalid syntax.
- Enable DEBUG mode in your WordPress instance. This will allow you to see any errors later on if you try to launch a code snippet and it fails for any reason. This can be switched off easily later when you move into production. In the root folder of your website and edit the wp-config.php.
# Modify to the correct root folder of your WordPress instance
nano /var/www/my_web/wp-config.php
# Paste the following line anywhere in the body of the code:
define( 'WP_DEBUG', true )
# Then save and exit - CTRL+ X (or Command + X) followed by pressing 'Y'.
- Move the contents from ‘/tmp/composer’ (as per previous step) into ‘/usr/share/php’ as this folder is accessible to the Code Snippet plugin + change permission to the owner of the web service.
sudo mkdir -p /usr/share/php/
sudo mv /tmp/composer /usr/share/php/
# Change owner to your web service
sudo chown -R www-data:www-data /usr/share/php
- Add the folder /usr/share/php as an allowed path in the open_basedir directive within the php.ini configuration file. Otherwise when your website tries to access a path on your server outside of its root folder, it will not be able to. The syntax is a path followed by : to indicate the next record.
locate php.ini
nano /etc/php/php.ini
# Add to the existing if there are already some records.
open_basedir = /tmp/:/usr/share/php/
# Save an exit the nano editor (CTRL + K / Command + K and confirm Y + enter)
# Reload your web server. Examples include:
sudo /etc/init.d/apache2 reload
sudo /etc/init.d/nginx reload
Note: In case you run your website on a Plesk server, then do not edit the php.ini directly as the change will be overwritten. Instead, add the path in the Plesk’s web service as shown below:
Source:
- WordPress official documentation for enabling WP Debug mode
- PHP.ini documentation
- MediaTemple’s Plesk configuration
- StackOverflow’s discussion post