Skip to main content
  1. All Posts/

wp-plugin__gcal-sync

Tools Open Source Sync WordPress

Google Calendar Sync

Synchronise google calendar events with a selected post type.

1. Table of Contents

    1. Table of Contents
    1. About The Project
    <ul dir="auto">
      <li>
        2.1. <a rel="nofollow noopener" target="_blank" href="#BuiltWithDependencies">Built With / Dependencies</a>
      </li>
      <li>
        2.2. <a rel="nofollow noopener" target="_blank" href="#Installation">Installation</a>
      </li>
    </ul>
    
    1. Usage
    <ul dir="auto">
      <li>
        3.1. <a rel="nofollow noopener" target="_blank" href="#Authorise.">Authorise.</a>
      </li>
      <li>
        3.2. <a rel="nofollow noopener" target="_blank" href="#Calendar">Calendar</a>
      </li>
      <li>
        3.3. <a rel="nofollow noopener" target="_blank" href="#Posts">Posts</a>
      </li>
      <li>
        3.4. <a rel="nofollow noopener" target="_blank" href="#ExtraFields">Extra Fields</a>
      </li>
      <li>
        3.5. <a rel="nofollow noopener" target="_blank" href="#RegexReplace">Regex Replace</a>
      </li>
      <li>
        3.6. <a rel="nofollow noopener" target="_blank" href="#Scheduler">Scheduler</a>
      </li>
      <li>
        3.7. <a rel="nofollow noopener" target="_blank" href="#Trash">Trash</a>
      </li>
      <li>
        3.8. <a rel="nofollow noopener" target="_blank" href="#Update">Update</a>
      </li>
    </ul>
    
    1. Customising
    1. Contributing
    1. License
    1. Contact
    1. Changelog

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.
(back to top)

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.

(back to top)

2.2. Installation

These are the steps to get up and running with this plugin.

  1. Clone the repo into your wordpress plugin folder
git clone https://github.com/IORoot/wp-plugin__gcal-sync ./wp-content/plugins/gcal-sync
  1. Clone the oauth repo into your wordpress plugin folder
git clone https://github.com/IORoot/wp-plugin__oauth--gCAL ./wp-content/plugins/gcal-oauth
  1. Use Google API Console and create a new project. The project must include the “Google Calendar API”.
  2. Generate an “OAuth 2.0 Client ID”.

    1. Authorised JavaScript origins = https://londonparkour.com
    2. Authorised redirect URIs = https://londonparkour.com/wp-admin/admin-ajax.php
    <p>
      (replace for you own domains) </li> 
      
      <li>
        Download a credentials JSON file for the generated project.
      </li>
      <li>
        Place the <code>client_secret.json</code> file into the root of the <code>./wp-content/plugins/gcal-oauth</code> folder. Make sure it&#8217;s called <code>client_secret.json</code>.
      </li>
      <li>
        Run <code>composer install</code> in the <code>./wp-content/plugins/gcal-oauth</code> folder to install dependencies.
      </li>
      <li>
        Copy the same credentials JSON file into the <code>./wp-content/plugins/gcal-sync</code> folder and name it <code>credentials.json</code>.
      </li>
      <li>
        Run <code>composer install</code> in the <code>./wp-content/plugins/gcal-sync</code> folder to install dependencies.
      </li>
      <li>
        Activate the plugins.
      </li></ol> 
      
      <p>
        The <code>gcal-oauth</code> plugin is used to add a new ACF component that is a button to connect to the Google OAUTH servers.<br /> (<a rel="nofollow noopener" target="_blank" href="#top">back to top</a>)
      </p>
      
      <h2 dir="auto">
        <a rel="nofollow noopener" target="_blank" id="user-content-3-usage" class="anchor" aria-hidden="true" href="#3-usage"></a>3. <a rel="nofollow noopener" target="_blank" name="user-content-Usage"></a>Usage
      </h2>
      
      <p>
        Once the plugin is activated, you&#8217;ll have a new menu option at the top called &#8220;ANDYP&#8221; that contains the &#8220;gCAL Importer&#8221;. Click on that.
      </p>
      
      <h3 dir="auto">
        <a rel="nofollow noopener" target="_blank" id="user-content-31-authorise" class="anchor" aria-hidden="true" href="#31-authorise"></a>3.1. <a rel="nofollow noopener" target="_blank" name="user-content-Authorise."></a>Authorise.
      </h3>
      
      <p>
        Click on the &#8220;Log in&#8221; 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&#8217;s a private one and not something you put into production.<br /> Once the process has completed, the button will turn red and say <code>Logged In</code>. There will also be a &#8220;bin&#8221; button to log you out.
      </p>
      
      <h3 dir="auto">
        <a rel="nofollow noopener" target="_blank" id="user-content-32-calendar" class="anchor" aria-hidden="true" href="#32-calendar"></a>3.2. <a rel="nofollow noopener" target="_blank" name="user-content-Calendar"></a>Calendar
      </h3>
      
      <ol dir="auto">
        <li>
          Calendar ID. This will be the ID of the google calendar you wish to retrieve results from. The user&#8217;s default calendar ID is their email address. E.g. <code>andy@testme.com</code>
        </li>
        <li>
          Max Results. The number of results on each sync.
        </li>
        <li>
          Skip Private Events. By default, all events are pulled in. You can stop any &#8220;Private&#8221; ones (marked on google calendar under visibility) from being pulled in.
        </li>
      </ol>
      
      <h3 dir="auto">
        <a rel="nofollow noopener" target="_blank" id="user-content-33-posts" class="anchor" aria-hidden="true" href="#33-posts"></a>3.3. <a rel="nofollow noopener" target="_blank" name="user-content-Posts"></a>Posts
      </h3>
      
      <p>
        The <code>slug</code> 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.
      </p>
      
      <h3 dir="auto">
        <a rel="nofollow noopener" target="_blank" id="user-content-34-extra-fields" class="anchor" aria-hidden="true" href="#34-extra-fields"></a>3.4. <a rel="nofollow noopener" target="_blank" name="user-content-ExtraFields"></a>Extra Fields
      </h3>
      
      <p>
        When an event is pulled in you can automatically attach extra data into meta fields.<br /> Match the title of the event in google calendar and it will dynamically inject images and meta fields.<br /> The &#8220;Field Key&#8221; is the name of the meta field. The &#8220;Field Value&#8221; is the value.<br /> You can have as many Matches entries as you like.
      </p>
      
      <h3 dir="auto">
        <a rel="nofollow noopener" target="_blank" id="user-content-35-regex-replace" class="anchor" aria-hidden="true" href="#35-regex-replace"></a>3.5. <a rel="nofollow noopener" target="_blank" name="user-content-RegexReplace"></a>Regex Replace
      </h3>
      
      <p>
        You can also run the PHP <code>preg_replace()</code> function on the description field of the calendar event. This means you can restyle and markup the content however you wish.
      </p>
      
      <ol dir="auto">
        <li>
          Label. Purely for organisation and labelling.
        </li>
        <li>
          Regex Pattern. What to match.<br /> e.g.
        </li>
      </ol>
      
      <pre>/&lt;h1&gt;/</pre>
      
      <ol dir="auto">
        <li>
          Replacement<br /> e.g.
        </li>
      </ol>
      
      <pre>&lt;p class="text-xl md:text-3xl mb-10"&gt;</pre>
      
      <p>
        This would replace all <code>&lt;h1&gt;</code> tags with the <code>&lt;p class="text-xl md:text-3xl mb-10"&gt;</code> tag.
      </p>
      
      <h3 dir="auto">
        <a rel="nofollow noopener" target="_blank" id="user-content-36-scheduler" class="anchor" aria-hidden="true" href="#36-scheduler"></a>3.6. <a rel="nofollow noopener" target="_blank" name="user-content-Scheduler"></a>Scheduler
      </h3>
      
      <p>
        The GCal Sync has it&#8217;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.
      </p>
      
      <ol dir="auto">
        <li>
          Enabled. Enable / Disable current schedule.
        </li>
        <li>
          Schedule Label. Required field to reference the defined schedule.
        </li>
        <li>
          Schedule repeats. How often the sync should work.
        </li>
        <li>
          Schedule Start. Pick specific time/date to start the scheduler.
        </li>
      </ol>
      
      <h3 dir="auto">
        <a rel="nofollow noopener" target="_blank" id="user-content-37-trash" class="anchor" aria-hidden="true" href="#37-trash"></a>3.7. <a rel="nofollow noopener" target="_blank" name="user-content-Trash"></a>Trash
      </h3>
      
      <p>
        Once the event has passed, how long should the plugin wait (in seconds) until it puts the event into the trash.
      </p>
      
      <h3 dir="auto">
        <a rel="nofollow noopener" target="_blank" id="user-content-38-update" class="anchor" aria-hidden="true" href="#38-update"></a>3.8. <a rel="nofollow noopener" target="_blank" name="user-content-Update"></a>Update
      </h3>
      
      <p>
        Not the the &#8220;update&#8221; button will run the sync process as well as save any changes.
      </p>
      
      <h2 dir="auto">
        <a rel="nofollow noopener" target="_blank" id="user-content-4-customising" class="anchor" aria-hidden="true" href="#4-customising"></a>4. <a rel="nofollow noopener" target="_blank" name="user-content-Customising"></a>Customising
      </h2>
      
      <p>
        None.<br /> (<a rel="nofollow noopener" target="_blank" href="#top">back to top</a>)
      </p>
      
      <h2 dir="auto">
        <a rel="nofollow noopener" target="_blank" id="user-content-5-contributing" class="anchor" aria-hidden="true" href="#5-contributing"></a>5. <a rel="nofollow noopener" target="_blank" name="user-content-Contributing"></a>Contributing
      </h2>
      
      <p>
        Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are <strong>greatly appreciated</strong>.<br /> 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.<br /> Don&#8217;t forget to give the project a star! Thanks again!
      </p>
      
      <ol dir="auto">
        <li>
          Fork the Project
        </li>
        <li>
          Create your Feature Branch (<code>git checkout -b feature/AmazingFeature</code>)
        </li>
        <li>
          Commit your Changes (<code>git commit -m 'Add some AmazingFeature'</code>)
        </li>
        <li>
          Push to the Branch (<code>git push origin feature/AmazingFeature</code>)
        </li>
        <li>
          Open a Pull Request
        </li>
      </ol>
      
      <p>
        (<a rel="nofollow noopener" target="_blank" href="#top">back to top</a>)
      </p>
      
      <h2 dir="auto">
        <a rel="nofollow noopener" target="_blank" id="user-content-6-license" class="anchor" aria-hidden="true" href="#6-license"></a>6. <a rel="nofollow noopener" target="_blank" name="user-content-License"></a>License
      </h2>
      
      <p>
        Distributed under the MIT License.<br /> MIT License<br /> Copyright (c) 2022 Andy Pearson<br /> Permission is hereby granted, free of charge, to any person obtaining a copy<br /> of this software and associated documentation files (the &#8220;Software&#8221;), to deal<br /> in the Software without restriction, including without limitation the rights<br /> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell<br /> copies of the Software, and to permit persons to whom the Software is<br /> furnished to do so, subject to the following conditions:<br /> The above copyright notice and this permission notice shall be included in all<br /> copies or substantial portions of the Software.<br /> THE SOFTWARE IS PROVIDED &#8220;AS IS&#8221;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br /> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br /> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE<br /> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br /> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,<br /> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE<br /> SOFTWARE.<br /> (<a rel="nofollow noopener" target="_blank" href="#top">back to top</a>)
      </p>
      
      <h2 dir="auto">
        <a rel="nofollow noopener" target="_blank" id="user-content-7-contact" class="anchor" aria-hidden="true" href="#7-contact"></a>7. <a rel="nofollow noopener" target="_blank" name="user-content-Contact"></a>Contact
      </h2>
      
      <p>
        Author Link: https://github.com/IORoot<br /> (<a rel="nofollow noopener" target="_blank" href="#top">back to top</a>)
      </p>
      
      <h2 dir="auto">
        <a rel="nofollow noopener" target="_blank" id="user-content-8-changelog" class="anchor" aria-hidden="true" href="#8-changelog"></a>8. <a rel="nofollow noopener" target="_blank" name="user-content-Changelog"></a>Changelog
      </h2>
      
      <p>
        v1.0.0 &#8211; Initial.
      </p>