Categories: Web

How to Create a Google Calendar Plugin for WordPress

Regardless of niche, adding a calendar plugin to your WordPress site is a great way to improve user engagement and retention. Creating such a plugin doesn’t take much effort because there are lots of cloud-based calendaring packages available today. Google Calendar is the most popular of them all, and it offers a free to use API.

In this tutorial, I’ll show you how to use the Google Calendar API to quickly create a WordPress calendar plugin that can display events from any publicly accessible Google calendar.

Prerequisites

To be able to make the most of this tutorial, you’ll need:

  • PHP 7.0.32 or higher
  • WordPress 4.4.2 or higher
  • Composer 1.8.0 or higher
  • a Google account

1. Creating a Google Project

You can use the Google Calendar API only after you’ve created an appropriately configured project on the Google Cloud Platform console. So log in to the console and, in the dashboard, press the Create button.

Dashboard of the Google Cloud Platform console

In the form that’s shown next, give a name to your project, change its ID if you want to, and press the Create button.

Project creation form

Once the project is ready, open the API library, select the Google Calendar API card, and press the Enable button to activate the API.

Calendar API home

2. Creating a Service Account

Unlike most other Google APIs, the Google Calendar API doesn’t allow you to authenticate your requests using an API key. Instead, it expects an OAuth 2.0 authorization token.

To be able to generate such a token from the server you’re running WordPress on, you’ll need a Google service account. So go to the Credentials section, press the Create Credentials button, and select the Service account key option.

Credentials creation page

In the next screen, choose the New service account option and type in a name for the service account. In the Role field, select the Role Viewer option. This will give the service account read-only access to all your Google calendars.

Service account creation form

Once you press the Create button, you’ll receive a JSON file containing a private key and a client ID. Save the file because you’ll need it later.

3. Creating a WordPress Plugin

To start creating the WordPress plugin, create a new directory called my-gcal-plugin inside the wp-content/plugins/ directory of your WordPress installation. You are free to use any other name for the directory. However, if you plan to share the plugin in the future, make sure that the name is unique in order to avoid conflicts with other plugins.

Inside the directory, create a PHP file named my-gcal-plugin.php and open it using a text editor.

For WordPress to recognize your plugin, this file needs to have a valid header comment. At the very least, the comment must specify the name of your plugin. However, I suggest including a short description and a version number too. So add the following code inside the file:

Share
Tags: web

Recent Posts

6 Questions to Ask Yourself Before Accepting a Web Design Project
  • Web

6 Questions to Ask Yourself Before Accepting a Web Design Project

Especially when you are at the beginning of your career as a web designer, you may be tempted to accept… Read More

21st August 2019 1:50 am
When Fast Food Logos Get Mashed Up
  • Web

When Fast Food Logos Get Mashed Up

As our lives become more hectic, so does our eating. We aren’t necessarily eating more, but eating faster. The way… Read More

19th August 2019 4:00 pm
How to Clean Malware from a Hacked Website
  • Web

How to Clean Malware from a Hacked Website

Just the hint of a hacked site is enough to send jitters down the spine of every webmaster. In an… Read More

14th August 2019 4:00 pm
How to Build an Engaging (And Functional) Event Website
  • Web

How to Build an Engaging (And Functional) Event Website

Hosting an event, a birthday or even planning for your own wedding or retirement party? No matter what it is,… Read More

9th August 2019 7:15 pm
5 Best Magento Extensions That Can Boost On-page SEO
  • Web

5 Best Magento Extensions That Can Boost On-page SEO

Doing business online and ignoring SEO is parallel to opening a shop in far-flung areas where nobody bothers to visit.… Read More

5th August 2019 4:00 pm
The Best Websites Designs of 2019 So Far
  • Web

The Best Websites Designs of 2019 So Far

As bloggers and website owners, we’ve all had our share of fickle website visitors. You know the kind. They are… Read More

1st August 2019 1:00 pm