Google Calendar Sync
Synchronise google calendar events with a selected post type.
This project was built as a way to generate event posts based on the contents of a google calendar. Used on LondonParkour.com/classes to generate the daily classes.
The sister plugin https://github.com/IORoot/wp-plugin__oauth--gCAL is required to login to your google calendar.
This must be installed to work. You also need ACFPro to work also.
This project was built with the following frameworks, technologies and software.
These are the steps to get up and running with this plugin.
- Clone the repo into your wordpress plugin folder
git clone https://github.com/IORoot/wp-plugin__gcal-sync ./wp-content/plugins/gcal-sync
- Clone the oauth repo into your wordpress plugin folder
git clone https://github.com/IORoot/wp-plugin__oauth--gCAL ./wp-content/plugins/gcal-oauth
Use Google API Console and create a new project. The project must include the "Google Calendar API".
Generate an "OAuth 2.0 Client ID".
- Authorised redirect URIs = https://londonparkour.com/wp-admin/admin-ajax.php
(replace for you own domains)
Download a credentials JSON file for the generated project.
client_secret.jsonfile into the root of the
./wp-content/plugins/gcal-oauthfolder. Make sure it's called
composer installin the
./wp-content/plugins/gcal-oauthfolder to install dependencies.
Copy the same credentials JSON file into the
./wp-content/plugins/gcal-syncfolder and name it
composer installin the
./wp-content/plugins/gcal-syncfolder to install dependencies.
Activate the plugins.
gcal-oauth plugin is used to add a new ACF component that is a button to connect to the Google OAUTH servers.
Once the plugin is activated, you'll have a new menu option at the top called "ANDYP" that contains the "gCAL Importer". Click on that.
Click on the "Log in" button. This will navigate you through the google OAuth process to allow your Google API Project access to the user that has the google calendar. You may get a warning that the project is unsafe, this is because it's a private one and not something you put into production.
Once the process has completed, the button will turn red and say
Logged In. There will also be a "bin" button to log you out.
Calendar ID. This will be the ID of the google calendar you wish to retrieve results from. The user's default calendar ID is their email address. E.g.
Max Results. The number of results on each sync.
Skip Private Events. By default, all events are pulled in. You can stop any "Private" ones (marked on google calendar under visibility) from being pulled in.
slug of the target Post type (or custom post type). This is where all the posts will be generated once the sync is run. There will be one post per calendar event.
When an event is pulled in you can automatically attach extra data into meta fields.
Match the title of the event in google calendar and it will dynamically inject images and meta fields.
The "Field Key" is the name of the meta field. The "Field Value" is the value.
You can have as many Matches entries as you like.
You can also run the PHP
preg_replace() function on the description field of the calendar event. This means you can restyle and markup the content however you wish.
Label. Purely for organisation and labelling.
Regex Pattern. What to match. e.g.
- Replacement e.g.
<p class="text-xl md:text-3xl mb-10">
This would replace all
<h1> tags with the
<p class="text-xl md:text-3xl mb-10"> tag.
The GCal Sync has it's own scheduler that means you can automatically run a sync whenever you wish. It will rescan the google calendar and pull in any new events.
Enabled. Enable / Disable current schedule.
Schedule Label. Required field to reference the defined schedule.
Schedule repeats. How often the sync should work.
Schedule Start. Pick specific time/date to start the scheduler.
Once the event has passed, how long should the plugin wait (in seconds) until it puts the event into the trash.
Not the the "update" button will run the sync process as well as save any changes.
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue. Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature)
- Commit your Changes (
git commit -m 'Add some AmazingFeature')
- Push to the Branch (
git push origin feature/AmazingFeature)
- Open a Pull Request
Distributed under the MIT License.
Copyright (c) 2022 Andy Pearson
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Author Link: https://github.com/IORoot
v1.0.0 - Initial.