{"id":18924445,"url":"https://github.com/outlandishideas/calendar-event-sync","last_synced_at":"2025-04-15T12:32:34.983Z","repository":{"id":57034114,"uuid":"271024324","full_name":"outlandishideas/calendar-event-sync","owner":"outlandishideas","description":"WordPress plugin that saves Google Calendar events to your WordPress database as posts","archived":false,"fork":false,"pushed_at":"2022-01-10T19:09:23.000Z","size":32,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-06T06:55:27.745Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/outlandishideas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-06-09T14:24:17.000Z","updated_at":"2024-06-12T16:50:46.000Z","dependencies_parsed_at":"2022-08-23T20:50:34.127Z","dependency_job_id":null,"html_url":"https://github.com/outlandishideas/calendar-event-sync","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/outlandishideas%2Fcalendar-event-sync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/outlandishideas%2Fcalendar-event-sync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/outlandishideas%2Fcalendar-event-sync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/outlandishideas%2Fcalendar-event-sync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/outlandishideas","download_url":"https://codeload.github.com/outlandishideas/calendar-event-sync/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249072469,"owners_count":21208191,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T11:06:49.841Z","updated_at":"2025-04-15T12:32:34.749Z","avatar_url":"https://github.com/outlandishideas.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Calendar Event Sync\nAn Outlandish Plugin\n\n[![Build Status](https://travis-ci.com/outlandishideas/calendar-event-sync.svg?branch=master)](https://travis-ci.com/outlandishideas/calendar-event-sync)\n\nThis plugin adds a WP-CLI command to authenticate with a Google Calendar\nand sync events from it to your WordPress instance; storing them as posts\nwith a `post_type` of `event`.\n\nIt uses WordPress actions to allow you to hook into this process and add\nany additional metadata to each event that you would like.\n\n\n## Installation\n\nTo install this plugin you will need to use composer to install it from \npackagist using the following command\n\n    composer require outlandish/calendar-event-sync\n    \nYou can now enable this plugin in your WordPress Admin. \n\n## Basic Usage\n\n### Setting the Google Cloud project\n\nTo begin using this plugin to sync Google Calendar Events, you will\nneed to create a Google Cloud project with access to the Google Calendar \nAPI. You can create one from this page:\n\nhttps://developers.google.com/calendar/quickstart/php\n\nYou will need to create this project with the Google account you intend to sync\nthe calendar items with, as a Google Cloud project that hasn't gone through a review\nprocess and been made public can only access resources for the account that it\nwas created with. \n\nAfter creating the Cloud Platform project download the client configuration details,\nand keep them for later. \n\n### Setting up the WordPress project\n\nYou'll want to add some new constants to your `wp-config.php` file (or if you are\nusing `roots/bedrock` to your `config/application.php` file). The constants that you\nmust set are\n\n    GOOGLE_CALENDAR_CLIENT_ID\n    GOOGLE_CALENDAR_PROJECT_ID\n    GOOGLE_CALENDAR_CLIENT_SECRET\n    GOOGLE_CALENDAR_ID\n    \nThe `GOOGLE_CALENDAR_CLIENT_ID`, `GOOGLE_CALENDAR_PROJECT_ID` and `GOOGLE_CALENDAR_CLIENT_SECRET` \nare all provided to you in the `credentials.json` file that you downloaded when you \ncreated the Google Cloud Project in the previous step. The `GOOGLE_CALENDAR_ID` will \nbe the email address of the Google Account that you created the Google Cloud project \nwith (or if your project has been reviewed and published can be any email address). \nYou will need to have access to the Google Account that owns this Calendar when \nauthenticating to allow the plugin to download events from the calendar.\n\n### Authenticating on the command line\n\nTo authenticate the plugin to access the calendar of your Google Account, run the following\ncommand using wp-cli\n\n    wp events auth\n    \nThis will output a url that you should open in a browser. It will ask you to log in with a\nGoogle Account, and then ask you to provide the project with access to your calendar. \n\nOnce you have gone through this process, you will be presented with an Authentication Code, \nwhich you copy and then run the following command\n\n    wp events auth \u003cauth-code\u003e\n    \nPassing the Authentication Code as the argument to the previous command will start the process\nof fetching an Access Token from Google and then storing that Access Token in the WordPress\ndatabase. \n\nYou should now be able to run the command to fetch events from the calendar and store them\nto your WordPress instance as posts. \n\n    wp events sync\n    \nOnce the command has finished it will report a successful import and tell you in the command\nline output how many events were fetched and how many were stored. \n\nIf you run the same command again, you will see that while 300 events were fetched, no events\nshould have been stored. This is because before storing an event, it will check if one \nalready exists with the Google Calendar Event Id.\n\n### Viewing your events\n\nThis plugin doesn't register the an Events custom post type with WordPress, so if you would\nlike to view the posts that were created by the plugin you will need to do that for your\nWordPress project separately. However, as long as you create a custom post type with the \n`post_type` of `event` you will be able to see all the data that was saved. \n\nBy default the only data about the Google Calendar Event that the plugin will save\nis the Summary of the event (which it saves as the title of the post), and the ID\nof the event (which it saves both as post metadata and as the slug of the post). Of \ncourse, this isn't very useful, so you will want to do a little more, which you \ncan find out more about in Advanced Usage below\n\n## Advanced Usage\n\nBy default the Google Calendar Event only stores the bare minimum it needs to save the \nevent as a WordPress post. It does this, as it does not want to assume anything about\nthe way that you want to store your event data. \n\n### Adding more metadata \n\nYou can add additional metadata from the Google Calendar event to the WordPress post, \nby adding a new function to your theme and calling it during the `outlandish/calendar-sync/adding-event`\naction that is defined in the plugin\n\nFor example the following code could be placed in your `functions.php` and would \nstore the description, start time and end time of the event as metadata on the \npost.\n\n    use Outlandish\\CalendarEventSync\\CalendarEventSyncPlugin;\n    use Outlandish\\CalendarEventSync\\Models\\ExternalEvent;\n    \n    add_action(CalendarEventSyncPlugin::STORE_EVENT_ACTION, function (ExternalEvent $event) {\n        if ($event-\u003esavedToWordPress()) {\n            add_post_meta($event-\u003egetPostId(), 'event_description', $event-\u003egetDescription());\n            add_post_meta($event-\u003egetPostId(), 'event_start', $event-\u003egetStartTime()-\u003egetTimestamp());\n            add_post_meta($event-\u003egetPostId(), 'event_end', $event-\u003egetEndTime()-\u003egetTimestamp());\n        }\n    }, 20);\n\nOr if you are using ACF and have defined some custom fields of your own\n\n    use Outlandish\\CalendarEventSync\\CalendarEventSyncPlugin;\n    use Outlandish\\CalendarEventSync\\Models\\ExternalEvent;\n    \n    add_action(CalendarEventSyncPlugin::STORE_EVENT_ACTION, function (ExternalEvent $event) {\n        if ($event-\u003esavedToWordPress()) {\n            update_field('event_description', $event-\u003egetDescription(), $event-\u003egetPostId());\n            update_field('event_start', $event-\u003egetStartTime()-\u003egetTimestamp(), $event-\u003egetPostId());\n            update_field('event_end', $event-\u003egetEndTime()-\u003egetTimestamp(), $event-\u003egetPostId());\n        }\n    }, 20);\n\nThe timing for when your action is run (in our example this is set to `20`), is very important.\nThe saving of the WordPress post is run at `10`, so if you set your action hook to run at \n`10` or less, you will be acting on the ExternalEvent before it has been turned into a \nWordPress post and won't be able to save any metadata about the event.\n\n\n### Replacing the default behaviour\n\nYou might not like the way that the Google Calendar Event is stored, and you can use\nthe `remove_action` method to remove the default behaviour and replace it with your own.\n\nBy default the WordPress post is created at time `10`, and then later updated to be published\nat time `50`. \n\nTo stop Events from being published by default you can use the following code snippet\n\n    remove_action(\n        CalendarEventSyncPlugin::STORE_EVENT_ACTION, \n        [CalendarEventSyncPlugin::class, 'publishEvent'], \n        50\n    );\n    \nNote that when doing this, you need to specify the same timing (the third argument\nto the function) as was specified when the action you are removing was added. This will \nnow stop events from being published after they are created. You could then replace this\nbehaviour with some other logic about what events get automatically published and which \nones don't.\n\nTo stop Events from being saved altogether, so that you can save them with a different\npost_type (for example), you will want to run the following snippet\n\n    remove_action(\n        CalendarEventSyncPlugin::STORE_EVENT_ACTION, \n        [CalendarEventSyncPlugin::class, 'defaultStoreStrategy'], \n        10\n    );\n    \nYou can then define your own storage strategy like so\n\n    use Outlandish\\CalendarEventSync\\CalendarEventSyncPlugin;\n    use Outlandish\\CalendarEventSync\\Models\\ExternalEvent;\n    \n    add_action(CalendarEventSyncPlugin::STORE_EVENT_ACTION, function (ExternalEvent $event) {\n        \n        if ($event-\u003egetSummary() === 'Only store this event') { //only store the event if this is true\n                \n            $id = wp_insert_post([\n                'post_title' =\u003e $event-\u003egetSummary(),\n                'post_type' =\u003e 'calendar_event', // a custom post_type here\n                'post_status' =\u003e 'draft',\n                'post_name' =\u003e $event-\u003egetId()\n            ]);\n            \n            add_post_meta($id, 'event_description', $event-\u003egetDescription());\n            add_post_meta($id, 'event_start', $event-\u003egetStartTime()-\u003egetTimestamp());\n            add_post_meta($id, 'event_end', $event-\u003egetEndTime()-\u003egetTimestamp());\n    \n            //always do this code\n            add_post_meta($id, CalendarEventSyncPlugin::EXTERNAL_EVENT_ID_KEY, $event-\u003egetId());\n            $event-\u003esetPostId($id);\n        }\n        \n    }, 10);\n\n## Testing\n\nTests have been written with the use of `humanmade/plugin-tester` docker image in mind. \n\nTo run the project's tests run `composer install` to install the plugin's dependencies, \nand then run \n\n    docker run --rm -v \"$PWD:/code\" humanmade/plugin-tester --testsuite=Unit\n    \nThis will run all tests defined in the Unit testsuite and output the results.\n\n\u003e This plugin expects pconv to be installed when running the tests for code\n\u003e coverage results. If you do not have this installed on your local version of \n\u003e php, you can run `composer install --ignore-platform-reqs` to install required\n\u003e packages without needing for pcov to be installed.\n\n### Test Coverage\n\nWhen you run the tests you will also produce an HTML report that will appear in \n`reports/coverage` which will provide you with information about the code that\nis covered by the tests.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foutlandishideas%2Fcalendar-event-sync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foutlandishideas%2Fcalendar-event-sync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foutlandishideas%2Fcalendar-event-sync/lists"}