Google Calendar Sync
Synchronise google calendar events with a selected post type.
1. Table of Contents
- 2.1. Built With / Dependencies
- 2.2. Installation
- 3.1. Authorise.
- 3.2. Calendar
- 3.3. Posts
- 3.4. Extra Fields
- 3.5. Regex Replace
- 3.6. Scheduler
- 3.7. Trash
- 3.8. Update
2. About The Project
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.
2.1. Built With / Dependencies
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.
2.2. Installation
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 JavaScript origins = https://londonparkour.com
- 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.
Place the
client_secret.json
file into the root of the./wp-content/plugins/gcal-oauth
folder. Make sure it's calledclient_secret.json
.Run
composer install
in the./wp-content/plugins/gcal-oauth
folder to install dependencies.Copy the same credentials JSON file into the
./wp-content/plugins/gcal-sync
folder and name itcredentials.json
.Run
composer install
in the./wp-content/plugins/gcal-sync
folder to install dependencies.Activate the plugins.
The gcal-oauth
plugin is used to add a new ACF component that is a button to connect to the Google OAUTH servers.
3. Usage
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.
3.1. Authorise.
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.
3.2. Calendar
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.
andy@testme.com
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.
3.3. Posts
The 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.
3.4. Extra Fields
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.
3.5. Regex Replace
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.
/<h1>/
- 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.
3.6. Scheduler
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.
3.7. Trash
Once the event has passed, how long should the plugin wait (in seconds) until it puts the event into the trash.
3.8. Update
Not the the "update" button will run the sync process as well as save any changes.
4. Customising
None.
5. Contributing
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
6. License
Distributed under the MIT License.
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.
7. Contact
Author Link: https://github.com/IORoot
8. Changelog
v1.0.0 - Initial.