Bachelor Tech
  • Home
  • Tutorials
  • Portfolio
  • About Jan
  • Contact Jan

Use GSheets APIv4 in WordPress using the Code Snippets plugin

by Jan Bachelor March 16, 2021

Last Updated on March 16, 2021 by Jan Bachelor

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.

  1. 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.
Install the Code Snippets plugin in WordPress
  1. 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'.
  1. 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
  1. 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:

In case you use Plesk, add the path into the open_basedir directive there

Source:

  • WordPress official documentation for enabling WP Debug mode
  • PHP.ini documentation
  • MediaTemple’s Plesk configuration
  • StackOverflow’s discussion post
Utilize Composer to talk to Google Sheets API
Example 1a: Purchase orders - load a list of clients into a Gravity Forms dropdown from a GSheet
Back to: Dynamically Populate Gravity Forms from Google Sheets (GSheets APIv4) > Part 1 - Get GSheets API working with your WordPress instance

Leave a Comment Cancel Reply

Save my name, email, and website in this browser for the next time I comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 comment 0 FacebookWhatsappEmail

Dynamically Populate Gravity Forms from Google Sheets (GSheets APIv4)

  • Previous
  • Next
Collapse
Expand
  • Part 1 - Get GSheets API working with your WordPress instance

  • Create a Google Service Account + Key
  • Install Composer + Google API Client (Linux)
  • Utilize Composer to talk to Google Sheets API
  • Use GSheets APIv4 in WordPress using the Code Snippets plugin
  • Part 2 - Examples for loading GSheets into Gravity Forms

  • Example 1a: Purchase orders - load a list of clients into a Gravity Forms dropdown from a GSheet
  • Example 1b: Purchase orders - load a list of projects from a GSheet based on the previously selected clients into a Gravity Forms dropdown

Search for articles

Other Tips

  • How to mount an NFS share (such as from FreeNAS) from an Android box
  • How to download a Windows 10 ISO on a Windows device – easy work-around

Other Tutorials

  • Build Your Own Router - Proxmox, OPNSense, OpenVPN server and a VPN client all in one!
    12 Steps
  • Dynamically Populate Gravity Forms from Google Sheets (GSheets APIv4)
    6 Steps

Recent Comments

  • Jan Bachelor on Use Integromat to get computer IDs from user email in JamF ProHi Robert, the static groups were created in the p…
  • Robert Petitto on Use Integromat to get computer IDs from user email in JamF ProCan you share how you'd use Make (integromat) to a…
  • Martin on Part 1 – What do we want to do + Required technology (bank feed)This tutorial deserves more credit, I've not seen…
  • Jan Bachelor on WAN / LAN Set Up (Before OPNSense Installation)Hi Ed, I have not tested it with PCI passthrough y…
  • Ed on OPNSense VM Set UpIn step 4 firewall you turned off firewall, should…

Tags

chrome iso windows

Categories

  • Android
  • FreeNAS
  • Linux
  • Windows

Recent Posts

  • How to mount an NFS share (such as from FreeNAS) from an Android box

  • How to download a Windows 10 ISO on a Windows device – easy work-around

Facebook Twitter Instagram Pinterest Linkedin Youtube

@2019 - All Right Reserved. Designed and Developed by PenciDesign

Bachelor Tech
  • Home
  • Tutorials
  • Portfolio
  • About Jan
  • Contact Jan