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

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
Go back to course overview: 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 FacebookWhatsappEmail

Course Steps

    1. Create a Google Service Account + Key
    2. Install Composer + Google API Client (Linux)
    3. Utilize Composer to talk to Google Sheets API
    4. Use GSheets APIv4 in WordPress using the Code Snippets plugin
    4 lessons
    1. Example 1a: Purchase orders - load a list of clients into a Gravity Forms dropdown from a GSheet
    2. Example 1b: Purchase orders - load a list of projects from a GSheet based on the previously selected clients into a Gravity Forms dropdown
    2 lessons
Previous Next

Recent Comments

  • Jan Bachelor on Dynamic DNS Set Up with DuckDNS on OPNSenseHi Jake, that's awesome, congratulations on getting…
  • Jake on Dynamic DNS Set Up with DuckDNS on OPNSensefollowed guide above to the T and all is working. i…
  • Fastbrain on Dynamic DNS Set Up with DuckDNS on OPNSenseThanks for the guide. For some reason, after follow…

Other courses

Install iRedMail Mail Server As Proxmox VM With...

October 31, 2024

Remote Bucket Storage for Proxmox VM Backups

August 16, 2024

Concur Alternative: Import Employees’ Credit Card Expenses to...

January 19, 2024

Create an automated Gravity workflow that will allow...

January 19, 2024

Dynamically Populate Gravity Forms from Google Sheets (GSheets...

March 16, 2021
Bachelor Tech
  • Home
  • Tutorials
  • Portfolio
  • About Jan
  • Contact Jan

Recent Posts

  • How to join two Proxmox nodes into a cluster (PVE 8.x)

  • How to Rename a Proxmox Node

  • How to mount an NFS share on an Android box

Facebook Twitter Instagram Pinterest Linkedin Youtube

All Rights Reserved. The theme was customized from Soledad, see PenciDesign