[
  {
    "path": ".dockerignore",
    "content": ".env\n.github_changelog_generator\n.travis.yml\ncodeception.yml\n"
  },
  {
    "path": ".env.dist",
    "content": "DB_NAME=wordpress\nDB_HOST=app_db\nDB_USER=wordpress\nDB_PASSWORD=wordpress\nWP_TABLE_PREFIX=wp_\nWP_URL=http://localhost\nWP_DOMAIN=localhost\nADMIN_EMAIL=admin@example.com\nADMIN_USERNAME=admin\nADMIN_PASSWORD=password\nADMIN_PATH=/wp-admin\n\nTEST_DB_NAME=wpgatsby_tests\nTEST_DB_HOST=127.0.0.1\nTEST_DB_USER=wordpress\nTEST_DB_PASSWORD=wordpress\nTEST_WP_TABLE_PREFIX=wp_\n\nSKIP_DB_CREATE=false\nTEST_WP_ROOT_FOLDER=/tmp/wordpress\nTEST_ADMIN_EMAIL=admin@wp.test\n\nTESTS_DIR=tests\nTESTS_OUTPUT=tests/_output\nTESTS_DATA=tests/_data\nTESTS_SUPPORT=tests/_support\nTESTS_ENVS=tests/_envs\n\nWPGRAPHQL_VERSION=v1.1.5\nSKIP_TESTS_CLEANUP=1\nSUITES=wpunit\n"
  },
  {
    "path": ".github/workflows/main.yml",
    "content": "name: Deploy to WordPress.org\non:\n  push:\n    tags:\n    - \"*\"\njobs:\n  tag:\n    name: New tag\n    runs-on: ubuntu-latest\n    steps:\n    - uses: actions/checkout@master\n    - name: WordPress Plugin Deploy\n      uses: 10up/action-wordpress-plugin-deploy@master\n      env:\n        SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}\n        SVN_USERNAME: ${{ secrets.SVN_USERNAME }}\n        SLUG: wp-gatsby"
  },
  {
    "path": ".github/workflows/tests.yml",
    "content": "name: Automated-Testing\n\non:\n  push:\n    branches:\n      - master\n  pull_request:\n    types: [opened, synchronize]\n\njobs:\n  continuous_integration:\n    runs-on: ubuntu-latest\n    strategy:\n      matrix:\n        php: [\"7.3\", \"7.4\"]\n        wordpress: [\"5.6\", \"5.5.3\", \"5.4.2\"]\n        include:\n          - php: \"7.4\"\n            wordpress: \"5.6\"\n          - php: \"7.4\"\n            wordpress: \"5.5.3\"\n          - php: \"7.4\"\n            wordpress: \"5.4.2\"\n          - php: \"7.3\"\n            wordpress: \"5.6\"\n          - php: \"7.3\"\n            wordpress: \"5.5.3\"\n          - php: \"7.3\"\n            wordpress: \"5.4.2\"\n      fail-fast: false\n    name: WordPress ${{ matrix.wordpress }} on PHP ${{ matrix.php }}\n    steps:\n      - name: Checkout\n        uses: actions/checkout@v2\n\n      - name: Install PHP\n        if: matrix.coverage == 1\n        uses: shivammathur/setup-php@v2\n        with:\n          php-version: ${{ matrix.php }}\n          extensions: json, mbstring\n\n      - name: Get Composer Cache Directory\n        id: composercache\n        run: echo \"::set-output name=dir::$(composer config cache-files-dir)\"\n\n      - name: Cache dependencies\n        uses: actions/cache@v2\n        with:\n          path: ${{ steps.composercache.outputs.dir }}\n          key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}\n          restore-keys: ${{ runner.os }}-composer-\n\n      - name: Install dependencies\n        run: composer install --no-dev\n\n      - name: Build \"testing\" Docker Image\n        env:\n          PHP_VERSION: ${{ matrix.php }}\n          WP_VERSION: ${{ matrix.wordpress }}\n          USE_XDEBUG: ${{ matrix.use_xdebug }}\n        run: composer build-test\n\n      - name: Run Tests w/ Docker.\n        env:\n          COVERAGE: ${{ matrix.coverage }}\n          DEBUG: ${{ matrix.debug }}\n          SKIP_TESTS_CLEANUP: ${{ matrix.coverage }}\n          LOWEST: ${{ matrix.lowest }}\n        run: composer run-test\n"
  },
  {
    "path": ".gitignore",
    "content": ".DS_Store\nnode_modules\nphpcs.xml\nphpunit.xml\nThumbs.db\nwp-cli.local.yml\nnode_modules/\n*.sql\n*.tar.gz\n*.zip\n.env\n.env.*\n!.env.dist\n.idea\n.vscode\n.github_changelog_generator\n!vendor/\nvendor/*\n!vendor/autoload.php\n!vendor/composer\n!vendor/firebase\n!vendor/ircmaxell\nvendor/composer/installed.json\nvendor/composer/*/\n!vendor/composer/semver/*\n!tests\ntests/*.suite.yml\nbuild/\ncoverage/*\nschema.graphql\nphpunit.xml\ndocker-output\ncomposer.lock\nc3.php\n.log/\nphp-coveralls.phar\ncodeception.yml\n"
  },
  {
    "path": ".prettierrc.js",
    "content": "module.exports = {\n\tarrowParens: \"avoid\",\n\tsemi: false,\n}\n"
  },
  {
    "path": "CHANGELOG.md",
    "content": "# Change Log\n\n## 2.3.3\n\nFixes an issue where publicly_queryable post types that were not public weren't being tracked in action monitor even though those post types were available in Gatsby. Thanks @nickcernis! (via PR #217)\n\n## 2.3.2\n\nPreviously Author and Contributor roles couldn't properly use Gatsby Cloud Preview. This release introduces new custom role capabilities which allow all authenticated users that can use WP preview to use Gatsby Preview.\n\n## 2.3.1\n\nFixes bug in last version where not having the right ACF version installed would throw an error about `Call to undefined function \"acf_get_options_pages\"`\n\n## 2.3.0\n\nAdded action monitor tracking for ACF options pages via PR #206. Thanks @henrikwirth!\n\n## 2.2.1\n\nBumped the \"tested to\" version to latest WP version.\n\n## 2.2.0\n\nAdded support for Gatsby Cloud Preview's new feature \"eager redirects\" which reduces the amount of time spent watching the preview loading screen by redirecting to the preview frontend as soon as possible and then letting the user wait for the preview to finish building there.\n\n## 2.1.1\n\nChanging away from the default UTC+0 timezone in WP could cause problems with local development and syncing changed data from WP. This release fixes that via PR #204.\n\n## 2.1.0\n\nUpdated how the `gatsby_action_monitors` filter works. Previously this filter didn't properly expose the ActionMonitor class making it impossible or very difficult to add your own action monitors. Thanks @justlevine! via PR #203.\n\n## 2.0.2\n\nWPGraphQL made a breaking change in a minor release v1.6.7 which caused delta updates to stop working. Fixed via https://github.com/gatsbyjs/wp-gatsby/pull/201. Breaking change notice here https://github.com/wp-graphql/wp-graphql/blob/develop/readme.txt#L80-L109\n\n## 2.0.1\n\n- gatsby-source-wordpress v5.14.2 and v6.1.0 both support WPGatsby v2.0.0+. This release re-published v2 as the latest WPGatsby version.\n\n## 1.1.4\n\n- Rolling out a release to overwrite v2.0.0. gatsby-source-wordpress didn't yet have a new release allowing WPGatsby v2.0.0+ support.\n\n## 2.0.0\n\nWe finalized support for Gatsby Cloud Content Sync Previews in this release. Content Sync is a Gatsby Cloud preview loader. Previously preview loading was handled within this plugin but we removed support for that legacy preview loader as the support burden for keeping the old and new preview logic around would be too much. Gatsby Cloud Content Sync is far more reliable than WPGatsby's preview loader as it has more context on the Gatsby build process.\n\nFor Content Sync to work you will need to upgrade to the latest version of `gatsby-source-wordpress` and either the latest `3.0.0` or `4.0.0` version of Gatsby core.\n\nIn addition this release comes with some bug fixes:\n\n- Fixed double instantiation of ActionMonitor classes which caused double webhooks and potentially double saving of data in some cases.\n- Makes preview routing more reliable by simplifying our logic and adding a `gatsby_preview=true` param to all preview links. For some users every second preview would fail to correctly route to the preview template. This is now fixed.\n\n## 1.1.3\n\n- The uri field was being overwritten during GraphQL requests, resulting in post uri's that included the content sync URL.\n- Some logic attempting to choose the correct manifest ID instead of regenerating it was causing manifest id's to be outdated during previews.\n\n## 1.1.2\n\n- Fixed redirection to Gatsby Cloud Content Sync preview loader in Gutenberg\n\n## 1.1.0\n\n- Added support for the new Gatsby Cloud Content Sync API. This new API moves the WPGatsby Preview loader logic to the Gatsby Cloud side as Cloud has more context on the Gatsby process making it more reliable than the existing WPGatsby preview loader with fewer restrictions and caveats.\n\n## 1.0.12\n\nPreview webhooks added the remote url as a property on the webhook body. When publishing updates we also send a preview webhook to update the preview Gatsby site. These two webhook bodies previously differed in that the latter didn't include a remoteUrl property. As of gatsby-source-wordpress@5.10.0 this causes problems because the source plugin assumes this property always exists. Related to https://github.com/gatsbyjs/gatsby/issues/32732. Fixed in https://github.com/gatsbyjs/wp-gatsby/pull/184\n\n## 1.0.11\n\n- Fixed a warning state for Preview to let users know when the preview Gatsby site set in the preview webhook setting is pointing at a Gatsby site which isn't sourcing data from the current WP site. Preview requires a 1:1 connection between WP and Gatsby where settings point at a Gatsby site that sources data from the WP instance previews are originating from.\n\n## 1.0.10\n\n- Fixed preview loader logic for subdirectory WP installs so that we request the GraphQL endpoint from the right URL.\n\n## 1.0.9\n\n- Fixed a bug where draft posts weren't previewable.\n\n## 1.0.8\n\n- Our internal preview logic had a bug where a request was being made with double forward slashes in the url in some cases. This broke incremental builds previews but worked on regular `gatsby develop` previews. This is fixed in this release.\n\n## 1.0.7\n\n- Before using WPGraphQL::debug() we weren't making sure that the debug method exists on that class. This could throw errors for older versions of WPGraphQL - we now check that the method exists before using it.\n\n- Documents using multiple webhooks support in Build and Preview webhook input field labels.\n\n- Fixes trailing comma in MediaActionMonitor log array.\n\n## 1.0.6\n\n- Bump stable version tag\n\n## 1.0.5\n\n- Fixed our build/publish process which was failing due to using the develop branch of WPGraphQL in tests.\n\n## 1.0.4\n\n- In some cases the homepage was not previewable in Gatsby Preview - this is now fixed.\n\n## 1.0.3\n\n- Fixed `wp_save_image_file` and `wp_save_image_editor_file` callback argument count.\n\n## 1.0.2\n\n- An erroneous change in our composer autoload broke our first stable release 😅 bit of a rocky start but lets try this again 🤝 😁 You can bet we'll be adding a test for this 😂\n\n## 1.0.1\n\n- Fixed a broken link in the readme.\n\n## 1.0.0\n\nThis plugin has come a long way over the past few months! This release introduces no changes outside of a few pages of docs. We're choosing this point to call this plugin stable as the plugin is well tested via our test suites and members of the community using it in the wild. Thanks everyone for your help and support in getting this plugin to this point!\n\n## 0.9.2\n\n### Bug Fixes\n\n- The preview template loader was fixed for cases where the global $post is not set, which previously lead to PHP errors.\n\n## 0.9.1\n\n- Removed a new internal taxonomy from the GraphQL schema which was unintentionally added in the last release.\n\n## 0.9.0\n\n### Breaking Changes\n\n- This release massively increases the performance of Gatsby Previews when more than one person is previewing or editing content at the same time. Previously when multiple users previewed simultaneously, only one of those users would see their preview or it would take a very long time for the others to see their previews. Now many users can preview concurrently. This was tested with a headless chrome puppeteer script. We found that 10 users making 100 previews over the course of a few minutes now have a 100% success rate. Previously 3 users making 30 previews would have a less than 30% success rate. This is a breaking change because `gatsby-source-wordpress-experimental` has some changes which are required to make this work.\n- Previously, saving a Media item would call the build and preview webhooks. This wasn't desireable because if you upload an image to your post, that will start a build to just source that media item, then when you press publish or preview you'd have to wait for the image build to complete before being able to see your build. Now a webhook is not sent out when images are uploaded/edited and other content updates which do send a webhook will catch these image changes and apply them alongside the other changes.\n\n## 0.8.0\n\n### Breaking Changes\n\nThis is a breaking change release as a lot of internals for the Action Monitor class have been modified and moved around. For most users nothing will change but for those who are using our internal plugin functions/classes in their own custom code, things might break.\n\n- Refactors Action Monitor to have separate classes for tracking activity for Acf, Media, Menus, Posts, Post Types, Settings, Taxonomies, Terms, and Users.\n\n### Fixes and improvements\n\n- TESTS! Lots of tests for the Action Monitors.\n- JWT Secret is now set once when WPGatsby is first loaded, instead of every time the settings page is visited.\n\n### Issues closed by this release\n\n- [#70](https://github.com/gatsbyjs/wp-gatsby/issues/70): When field groups are saved using ACF Field Group GUI, a \"Diff Schema\" action is triggered\n- [#58](https://github.com/gatsbyjs/wp-gatsby/issues/58): A \"Refetch All\" action is available and is used when Permalinks are changed\n- [#57](https://github.com/gatsbyjs/wp-gatsby/issues/57): Term meta is now properly tracked when changed\n- [#56](https://github.com/gatsbyjs/wp-gatsby/issues/56): Custom post types (all post types that are public and show_in_graphql) are now tracked when they are moved from publish to trash and vis-versa\n- [#41](https://github.com/gatsbyjs/wp-gatsby/issues/41): Codeception tests are now in place\n- [#38](https://github.com/gatsbyjs/wp-gatsby/issues/38): Many core WordPress options have been added to an allow-list and trigger a general NON_NODE_ROOT_FIELDS action. A few specific actions trigger specific actions for specific nodes. For example, changing the home_page triggers an update for the new page and the old page being changed as the URI is now different.\n- [#26](https://github.com/gatsbyjs/wp-gatsby/issues/26): Posts that transition from future->publish now trigger an action (ensuring WordPress cron is triggered for WordPress sites using Gatsby front-ends might need more thought still though. . .)\n- [#17](https://github.com/gatsbyjs/wp-gatsby/issues/17): Meta is now tracked for Posts, Terms and Users (comments are not currently tracked at the moment)\n- [#15](https://github.com/gatsbyjs/wp-gatsby/issues/15): Saving permalinks triggers a REFETCH_ALL Action\n- [#7](https://github.com/gatsbyjs/wp-gatsby/issues/7): Gatsby JWT Secret is now generated once and saved immediately and not generated again\n- [#6](https://github.com/gatsbyjs/wp-gatsby/issues/6): Gatsby now tracks only post_types (and taxonomies) that are set to be both public and show_in_graphql and there are filters to override as needed.\n\n## 0.7.3\n\n- Small internal changes to Previews to facilitate e2e tests.\n\n## 0.7.2\n\n- Version 0.7.0 introduced a change which resulted in Previews for some WP instances being overwritten by published posts on each preview.\n\n## 0.7.1\n\n- The last version added some internal taxonomies to the GraphQL schema unintentionally. This release removes them.\n\n## 0.7.0\n\n### Breaking Changes\n\n- Previously we were storing a brand new post internally for every content-related action that happened in your site. As of this release we only make a single action post for each post you take actions against and update it each time instead of creating a new one.\n\n## 0.6.8\n\n- The `NO_PAGE_CREATED_FOR_PREVIEWED_NODE` preview status was no longer making it through to the preview template because we were checking if the preview had deployed before checking if a page had been created in Gatsby for the preview. this release fixes that.\n- The preview-template.php check for wether or not the preview frontend is online could occasionally come back with a false negative. It is now more resilient and will recheck for 10 seconds before showing an error.\n- The above check used to throw harmless CORS errors in the console, this check is now done server-side so that CORS isn't an issue.\n\n## 0.6.7\n\n- Gatsby Preview process errors were not coming through for new post drafts. They do now :)\n- I was checking if the Gatsby webhook hit by WPGatsby returned any errors and displaying an error in the preview client if it did. It turns out this is problematic because the webhook can return errors in WPGatsby and yet Gatsby can still have successfully received it. So the logic is now more optimistic and tries to load the preview regardless of wether or not we received an error when posting to the webhook.\n\n## 0.6.6\n\n- Fixed a timing issue between Previews and WPGatsby. WPGatsby now reads the page-data.json of the page being previewed in order to determine wether or not it's been deployed.\n- Added publish webhooks for Preview so that polling is not needed in Gatsby Preview on the source plugin side.\n\n## 0.6.5\n\n- Improved garbage collection of old action monitor posts. Garbage collection previously took over 20 seconds to clean up 6,204 action_monitor actions, after this change it takes approximately 1/10 of a second.\n\n## 0.6.4\n\n- Extended WPGatsby JWT expiry to 1 hour. It was previously 30 seconds which can be problematic for slower servers and Gatsby setups.\n\n## 0.6.3\n\n- graphql_single_name's that start with a capital letter were causing issues because WPGatsby was not making the first character lowercase but WPGraphQL does do this when adding the field to schema.\n\n## 0.6.2\n\n- More PHP 7.1 syntax fixes. We will soon have CI tests which will prevent these issues.\n\n## 0.6.1\n\n- Fixed an unexpected token syntax error.\n\n## 0.6.0\n\n- This release adds a major re-work to the Gatsby Preview experience! It adds remote Gatsby state management and error handling in WordPress so that WP and Gatsby don't get out of sync during the Preview process.\n\n## 0.5.4\n\n- Force enable WPGraphQL Introspection when WPGatsby is enabled. [WPGraphQL v0.14.0](https://github.com/wp-graphql/wp-graphql/releases/tag/v0.14.0) has Introspection disabled by default with an option to enable it, and Gatsby requires it to be enabled, so WPGatsby force-enables it.\n\n## 0.5.3\n\n- Meta delta syncing was using the same code for posts and users. In many cases this was causing errors when updating usermeta. This code is now scoped to posts only and we will add usermeta delta syncing separately.\n- Our composer setup was previously double autoloading\n\n## 0.5.2\n\n- Added a backwards compatibility fix for a regression introduced in v0.4.18 where WPGraphQL::debug() was called. This method is only available in later versions of WPGraphQL, but this plugin currently supports earlier versions\n\n## 0.5.1\n\n- Fixed a typo in the new footer locations 🤦‍♂️ gatbsy should be gatsby\n\n## 0.5.0\n\n### Bug Fixes\n\n- Added support for delta syncing menu locations. This appeared as a bug where updating your menu locations didn't update in Gatsby, but this was actually a missing feature.\n\n## 0.4.18\n\n### Bug Fixes\n\n- The action_monitor post type was registered incorrectly so that it was showing in the rest api, in search, and other places it didn't need to be. This release fixes that. Thanks @jasonbahl!\n\n## 0.4.17\n\n### New Features\n\n- Added `WPGatsby.arePrettyPermalinksEnabled` to the schema in order to add more helpful error messages to the Gatsby build process.\n- Added a filter `gatsby_trigger_dispatch_args` to filter the arguments passed to `wp_safe_remote_post` when triggering webhooks.\n\n## 0.4.16\n\n### Bug Fixes\n\nIt turns out the new feature in the last release could potentially cause many more issues than it presently solves, so it has been disabled as a bug fix. This will be re-enabled within the next couple weeks as we do more testing and thinking on how best to approach sending WP options events to Gatsby.\n\n## 0.4.15\n\n### New Features\n\n- Non-node root fields (options and settings) are now recorded as an action so Gatsby can inc build when the site title changes for example.\n\n## 0.4.14\n\n### Bug Fixes\n\n- Making a post into a draft was not previously saving an action monitor post which means posts that became drafts would never be deleted.\n\n## 0.4.13\n\n### Bug Fixes\n\n- the ContentType.archivePath field was returning an empty string instead of `/` for a homepage archive.\n\n## 0.4.12\n\n### New Features\n\n- Added temporary `ContentType.archivePath` and `Taxonomy.archivePath` fields to the schema until WPGraphQL supports these fields.\n\n## 0.4.11\n\n### Bug Fixes\n\n- get_home_url() was being used where get_site_url() should've been used, causing the gql endpoint to not be referenced correctly in some situations. For example when using Bedrock.\n\n## 0.4.10\n\n### Bug Fixes\n\n- The Preview fix in the last release introduced a new bug where saving a draft at any time would send a webhook to the Preview instance.\n\n## 0.4.9\n\n### Bug Fixes\n\n- Preview wasn't working properly for new posts that hadn't yet been published or for drafts.\n\n## 0.4.8\n\nPushing release to WordPress.org\n\n## 0.4.7\n\n### New Features\n\n- Added a link to the GatsbyJS settings page on how to configure this plugin.\n\n### Bug Fixes\n\n- Activating this plugin before WPGraphQL was causing PHP errors.\n\n## 0.4.6\n\nAdd Wapuu Icons for display in the WordPress.org repo\n\n## 0.4.5\n\nRe-publish with proper package name\n\n## 0.4.4\n\nTesting Github Actions\n\n## 0.4.3\n\nNew release to trigger publishing to WordPress.org!\n\n## 0.4.2\n\n### Bug Fixes\n\n- Previously when a post transitioned from published to draft, it wouldn't be deleted in Gatsby\n\n## 0.4.1\n\nVersion bump to add /vendor directory to Git so that Github releases work as WP plugins without running `composer install`. In the future there will be a better release process, but for now this works.\n\n## 0.4.0\n\n### Breaking Changes\n\n- WPGraphQL was using nav_menu for it's menu relay id's instead of term. WPGQL 0.9.1 changes this from nav_menu to term. This is a breaking change because cache invalidation wont work properly if the id is incorrect. So we move to v0.4.0 so gatsby-source-wordpress-experimental can set 0.4.0 as it's min version and cache invalidation will keep working.\n\n## 0.3.0\n\n### Breaking Changes\n\n- Updated Relay ids to be compatible with WPGraphQL 0.9.0. See https://github.com/wp-graphql/wp-graphql/releases/tag/v0.9.0 for more info.\n- Bumped min PHP and WP versions\n\n## 0.2.6\n\n### Bug fixes\n\nFixed an issue where we were trying to access post object properties when we didn't yet have the post.\n\n## 0.2.5\n\n### Bug Fixes\n\nEarlier versions of WPGatsby were recording up to 4 duplicate content saves per content change in WordPress. This release stops that from happening. WPGatsby does garbage collection, so any duplicate actions will be automatically removed from your DB.\n"
  },
  {
    "path": "README.md",
    "content": "<div align=\"center\" style=\"margin-bottom: 20px;\">\n<img src=\"https://raw.githubusercontent.com/gatsbyjs/gatsby/master/packages/gatsby-source-wordpress/docs/assets/gatsby-wapuus.png\" alt=\"Wapuu hugging a ball with the Gatsby logo on it\" />\n</div>\n\n<p align=\"center\">\n  <a href=\"https://github.com/gatsbyjs/wp-gatsby/blob/master/license.txt\">\n    <img src=\"https://img.shields.io/badge/license-GPLv3-blue.svg\" alt=\"Gatsby and gatsby-source-wordpress are released under the MIT license.\" />\n  </a>\n  <a href=\"https://twitter.com/intent/follow?screen_name=gatsbyjs\">\n    <img src=\"https://img.shields.io/twitter/follow/gatsbyjs.svg?label=Follow%20@gatsbyjs\" alt=\"Follow @gatsbyjs\" />\n  </a>\n</p>\n\n# WPGatsby\n\nWPGatsby is a free open-source WordPress plugin that optimizes your WordPress site to work as a data source for [Gatsby](https://www.gatsbyjs.com/docs/how-to/sourcing-data/sourcing-from-wordpress).\n\nThis plugin must be used in combination with the npm package [`gatsby-source-wordpress@>=4.0.0`](https://www.npmjs.com/package/gatsby-source-wordpress).\n\n## Install and Activation\n\nWPGatsby is available on the WordPress.org repository and can be installed from your WordPress dashboard, or by using any other plugin installation method you prefer, such as installing with Composer from wpackagist.org.\n\n## Plugin Overview\n\nThis plugin has 2 primary responsibilities:\n\n- [Monitor Activity in WordPress to keep Gatsby in sync with WP](https://github.com/gatsbyjs/wp-gatsby/blob/master/docs/action-monitor.md)\n- [Configure WordPress Previews to work with Gatsby](https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-wordpress/docs/tutorials/configuring-wp-gatsby.md#setting-up-preview)\n\nAdditionally, WPGatsby has a settings page to connect your WordPress site with your Gatsby site:\n\n- [WPGatsby Settings](https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-wordpress/docs/tutorials/configuring-wp-gatsby.md)\n"
  },
  {
    "path": "access-functions.php",
    "content": "<?php\n"
  },
  {
    "path": "bin/install-test-env.sh",
    "content": "#!/usr/bin/env bash\n\nsource .env\n\nprint_usage_instruction() {\n\techo \"Ensure that .env file exist in project root directory exists.\"\n\techo \"And run the following 'composer install-wp-tests' in the project root directory\"\n\texit 1\n}\n\nif [[ -z \"$TEST_DB_NAME\" ]]; then\n\techo \"TEST_DB_NAME not found\"\n\tprint_usage_instruction\nelse\n\tDB_NAME=$TEST_DB_NAME\nfi\nif [[ -z \"$TEST_DB_USER\" ]]; then\n\techo \"TEST_DB_USER not found\"\n\tprint_usage_instruction\nelse\n\tDB_USER=$TEST_DB_USER\nfi\n\nDB_HOST=${TEST_DB_HOST-localhost}\nDB_PASS=${TEST_DB_PASSWORD-\"\"}\nWP_VERSION=${WP_VERSION-latest}\nTMPDIR=${TMPDIR-/tmp}\nTMPDIR=$(echo $TMPDIR | sed -e \"s/\\/$//\")\nWP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib}\nWP_CORE_DIR=${TEST_WP_ROOT_FOLDER-$TMPDIR/wordpress/}\nPLUGIN_DIR=$(pwd)\nDB_SERVE_NAME=${DB_SERVE_NAME-wpgatsby_serve}\nSKIP_DB_CREATE=${SKIP_DB_CREATE-false}\n\ndownload() {\n    if [ `which curl` ]; then\n        curl -s \"$1\" > \"$2\";\n    elif [ `which wget` ]; then\n        wget -nv -O \"$2\" \"$1\"\n    fi\n}\n\nif [[ $WP_VERSION =~ ^[0-9]+\\.[0-9]+\\-(beta|RC)[0-9]+$ ]]; then\n\tWP_BRANCH=${WP_VERSION%\\-*}\n\tWP_TESTS_TAG=\"branches/$WP_BRANCH\"\n\nelif [[ $WP_VERSION =~ ^[0-9]+\\.[0-9]+$ ]]; then\n\tWP_TESTS_TAG=\"branches/$WP_VERSION\"\nelif [[ $WP_VERSION =~ [0-9]+\\.[0-9]+\\.[0-9]+ ]]; then\n\tif [[ $WP_VERSION =~ [0-9]+\\.[0-9]+\\.[0] ]]; then\n\t\t# version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x\n\t\tWP_TESTS_TAG=\"tags/${WP_VERSION%??}\"\n\telse\n\t\tWP_TESTS_TAG=\"tags/$WP_VERSION\"\n\tfi\nelif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then\n\tWP_TESTS_TAG=\"trunk\"\nelse\n\t# http serves a single offer, whereas https serves multiple. we only want one\n\tdownload http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json\n\tgrep '[0-9]+\\.[0-9]+(\\.[0-9]+)?' /tmp/wp-latest.json\n\tLATEST_VERSION=$(grep -o '\"version\":\"[^\"]*' /tmp/wp-latest.json | sed 's/\"version\":\"//')\n\tif [[ -z \"$LATEST_VERSION\" ]]; then\n\t\techo \"Latest WordPress version could not be found\"\n\t\texit 1\n\tfi\n\tWP_TESTS_TAG=\"tags/$LATEST_VERSION\"\nfi\nset -ex\n\ninstall_wp() {\n\n\tif [ -d $WP_CORE_DIR ]; then\n\t\treturn;\n\tfi\n\n\tmkdir -p $WP_CORE_DIR\n\n\tif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then\n\t\tmkdir -p $TMPDIR/wordpress-nightly\n\t\tdownload https://wordpress.org/nightly-builds/wordpress-latest.zip  $TMPDIR/wordpress-nightly/wordpress-nightly.zip\n\t\tunzip -q $TMPDIR/wordpress-nightly/wordpress-nightly.zip -d $TMPDIR/wordpress-nightly/\n\t\tmv $TMPDIR/wordpress-nightly/wordpress/* $WP_CORE_DIR\n\telse\n\t\tif [ $WP_VERSION == 'latest' ]; then\n\t\t\tlocal ARCHIVE_NAME='latest'\n\t\telif [[ $WP_VERSION =~ [0-9]+\\.[0-9]+ ]]; then\n\t\t\t# https serves multiple offers, whereas http serves single.\n\t\t\tdownload https://api.wordpress.org/core/version-check/1.7/ $TMPDIR/wp-latest.json\n\t\t\tif [[ $WP_VERSION =~ [0-9]+\\.[0-9]+\\.[0] ]]; then\n\t\t\t\t# version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x\n\t\t\t\tLATEST_VERSION=${WP_VERSION%??}\n\t\t\telse\n\t\t\t\t# otherwise, scan the releases and get the most up to date minor version of the major release\n\t\t\t\tlocal VERSION_ESCAPED=`echo $WP_VERSION | sed 's/\\./\\\\\\\\./g'`\n\t\t\t\tLATEST_VERSION=$(grep -o '\"version\":\"'$VERSION_ESCAPED'[^\"]*' $TMPDIR/wp-latest.json | sed 's/\"version\":\"//' | head -1)\n\t\t\tfi\n\t\t\tif [[ -z \"$LATEST_VERSION\" ]]; then\n\t\t\t\tlocal ARCHIVE_NAME=\"wordpress-$WP_VERSION\"\n\t\t\telse\n\t\t\t\tlocal ARCHIVE_NAME=\"wordpress-$LATEST_VERSION\"\n\t\t\tfi\n\t\telse\n\t\t\tlocal ARCHIVE_NAME=\"wordpress-$WP_VERSION\"\n\t\tfi\n\t\tdownload https://wordpress.org/${ARCHIVE_NAME}.tar.gz  $TMPDIR/wordpress.tar.gz\n\t\ttar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR\n\tfi\n\n\tdownload https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php\n}\n\ninstall_db() {\n\n\tif [ ${SKIP_DB_CREATE} = \"true\" ]; then\n\t\treturn 0\n\tfi\n\n\t# parse DB_HOST for port or socket references\n\tlocal PARTS=(${DB_HOST//\\:/ })\n\tlocal DB_HOSTNAME=${PARTS[0]};\n\tlocal DB_SOCK_OR_PORT=${PARTS[1]};\n\tlocal EXTRA=\"\"\n\n\tif ! [ -z $DB_HOSTNAME ] ; then\n\t\tif [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\\{1,\\}$') ]; then\n\t\t\tEXTRA=\" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp\"\n\t\telif ! [ -z $DB_SOCK_OR_PORT ] ; then\n\t\t\tEXTRA=\" --socket=$DB_SOCK_OR_PORT\"\n\t\telif ! [ -z $DB_HOSTNAME ] ; then\n\t\t\tEXTRA=\" --host=$DB_HOSTNAME --protocol=tcp\"\n\t\tfi\n\tfi\n\n\t# create database\n\tRESULT=`mysql -u $DB_USER --password=\"$DB_PASS\" --skip-column-names -e \"SHOW DATABASES LIKE '$DB_NAME'\"$EXTRA`\n\tif [ \"$RESULT\" != $DB_NAME ]; then\n\t\t\tmysqladmin create $DB_NAME --user=\"$DB_USER\" --password=\"$DB_PASS\"$EXTRA\n\tfi\n}\n\nconfigure_wordpress() {\n    cd $WP_CORE_DIR\n    wp config create --dbname=\"$DB_NAME\" --dbuser=\"$DB_USER\" --dbpass=\"$DB_PASS\" --dbhost=\"$DB_HOST\" --skip-check --force=true\n    wp core install --url=wp.test --title=\"WPGatsby Tests\" --admin_user=admin --admin_password=password --admin_email=admin@wp.test\n    wp rewrite structure '/%year%/%monthnum%/%postname%/'\n}\n\nsetup_wpgraphql() {\n\tif [ ! -d $WP_CORE_DIR/wp-content/plugins/wp-graphql ]; then\n\t\techo \"Cloning WPGraphQL\"\n\t\twp plugin install https://github.com/wp-graphql/wp-graphql/releases/download/${WPGRAPHQL_VERSION}/wp-graphql.zip\n\tfi\n\techo \"Activating WPGraphQL\"\n\twp plugin activate wp-graphql\n\n}\n\nsetup_plugin() {\n\t# Add this repo as a plugin to the repo\n\tif [ ! -d $WP_CORE_DIR/wp-content/plugins/wp-gatsby ]; then\n\t\tln -s $PLUGIN_DIR $WP_CORE_DIR/wp-content/plugins/wp-gatsby\n\t\tcd $WP_CORE_DIR/wp-content/plugins\n\t\tpwd\n\t\tls\n\tfi\n\n\tcd $WP_CORE_DIR\n\n    wp plugin list\n\n\t# activate the plugin\n\twp plugin activate wp-gatsby\n\n\t# Flush the permalinks\n\twp rewrite flush\n\n\t# Export the db for codeception to use\n\twp db export $PLUGIN_DIR/tests/_data/dump.sql\n}\n\ninstall_wp\ninstall_db\nconfigure_wordpress\nsetup_wpgraphql\nsetup_plugin\n"
  },
  {
    "path": "bin/run-docker.sh",
    "content": "#!/usr/bin/env bash\n\nset -eu\n\n##\n# Use this script through Composer scripts in the package.json.\n# To quickly build and run the docker-compose scripts for an app or automated testing\n# run the command below after run `composer install --no-dev` with the respectively\n# flag for what you need.\n##\nprint_usage_instructions() {\n\techo \"Usage: composer build-and-run -- [-a|-t]\";\n\techo \"       -a  Spin up a WordPress installation.\";\n\techo \"       -t  Run the automated tests.\";\n\texit 1\n}\n\nif [ -z \"$1\" ]; then\n\tprint_usage_instructions\nfi\n\nenv_file=\".env.dist\";\n\nsubcommand=$1; shift\ncase \"$subcommand\" in\n    \"build\" )\n        while getopts \":at\" opt; do\n            case ${opt} in\n                a )\n                docker build -f docker/app.Dockerfile \\\n                    -t wpgatsby-app:latest \\\n                    --build-arg WP_VERSION=${WP_VERSION-5.4} \\\n                    --build-arg PHP_VERSION=${PHP_VERSION-7.4} \\\n                    .\n                    ;;\n                t )\n                docker build -f docker/app.Dockerfile \\\n                    -t wpgatsby-app:latest \\\n                    --build-arg WP_VERSION=${WP_VERSION-5.4} \\\n                    --build-arg PHP_VERSION=${PHP_VERSION-7.4} \\\n                    .\n\n                docker build -f docker/testing.Dockerfile \\\n                    -t wpgatsby-testing:latest \\\n                    --build-arg USE_XDEBUG=${USE_XDEBUG-} \\\n                    .\n                    ;;\n                \\? ) print_usage_instructions;;\n                * ) print_usage_instructions;;\n            esac\n        done\n        shift $((OPTIND -1))\n        ;;\n    \"run\" )\n        while getopts \"e:at\" opt; do\n            case ${opt} in\n\t\t\t\te )\n\t\t\t\tenv_file=${OPTARG};\n\t\t\t\tif [ ! -f $env_file ]; then\n\t\t\t\t\techo \"No file found at $env_file\"\n\t\t\t\tfi\n\t\t\t\t;;\n                a ) docker-compose up --scale testing=0;;\n                t )\n\t\t\t\tsource ${env_file}\n                docker-compose run --rm \\\n                    -e SUITES=${SUITES-wpunit} \\\n                    -e COVERAGE=${COVERAGE-} \\\n                    -e DEBUG=${DEBUG-} \\\n                    -e SKIP_TESTS_CLEANUP=${SKIP_TESTS_CLEANUP-} \\\n\t\t\t\t\t-e LOWEST=${LOWEST-} \\\n                    testing --scale app=0\n                    ;;\n                \\? ) print_usage_instructions;;\n                * ) print_usage_instructions;;\n            esac\n        done\n        shift $((OPTIND -1))\n        ;;\n\n    \\? ) print_usage_instructions;;\n    * ) print_usage_instructions;;\nesac\n"
  },
  {
    "path": "codeception.dist.yml",
    "content": "paths:\n  tests: '%TESTS_DIR%'\n  output: '%TESTS_OUTPUT%'\n  data: '%TESTS_DATA%'\n  support: '%TESTS_SUPPORT%'\n  envs: '%TESTS_ENVS%'\nparams:\n  - env\n  - .env.dist\nactor_suffix: Tester\nsettings:\n  colors: true\n  memory_limit: 1024M\ncoverage:\n  enabled: true\n  remote: false\n  c3_url: '%WP_URL%/wp-content/plugins/wp-gatsby/wp-gatsby.php'\n  include:\n    - includes/*\n  exclude:\n    - wp-gatsby.php\n    - vendor/*\n  show_only_summary: false\nextensions:\n  enabled:\n    - Codeception\\Extension\\RunFailed\n  commands:\n    - Codeception\\Command\\GenerateWPUnit\n    - Codeception\\Command\\GenerateWPRestApi\n    - Codeception\\Command\\GenerateWPRestController\n    - Codeception\\Command\\GenerateWPRestPostTypeController\n    - Codeception\\Command\\GenerateWPAjax\n    - Codeception\\Command\\GenerateWPCanonical\n    - Codeception\\Command\\GenerateWPXMLRPC\nmodules:\n  config:\n    WPDb:\n      dsn: 'mysql:host=%DB_HOST%;dbname=%DB_NAME%'\n      user: '%DB_USER%'\n      password: '%DB_PASSWORD%'\n      populator: 'mysql -u $user -p$password -h $host $dbname < $dump'\n      dump: 'tests/_data/dump.sql'\n      populate: false\n      cleanup: true\n      waitlock: 0\n      url: '%WP_URL%'\n      urlReplacement: true\n      tablePrefix: '%WP_TABLE_PREFIX%'\n    WPBrowser:\n      url: '%WP_URL%'\n      wpRootFolder: '%WP_ROOT_FOLDER%'\n      adminUsername: '%ADMIN_USERNAME%'\n      adminPassword: '%ADMIN_PASSWORD%'\n      adminPath: '/wp-admin'\n      cookies: false\n    REST:\n      depends: WPBrowser\n      url: '%WP_URL%'\n    WPFilesystem:\n      wpRootFolder: '%WP_ROOT_FOLDER%'\n      plugins: '/wp-content/plugins'\n      mu-plugins: '/wp-content/mu-plugins'\n      themes: '/wp-content/themes'\n      uploads: '/wp-content/uploads'\n    WPLoader:\n      wpRootFolder: '%WP_ROOT_FOLDER%'\n      dbName: '%DB_NAME%'\n      dbHost: '%DB_HOST%'\n      dbUser: '%DB_USER%'\n      dbPassword: '%DB_PASSWORD%'\n      tablePrefix: '%WP_TABLE_PREFIX%'\n      domain: '%WP_DOMAIN%'\n      adminEmail: '%ADMIN_EMAIL%'\n      title: 'Test'\n      plugins:\n        - wp-graphql/wp-graphql.php\n        - wp-gatsby/wp-gatsby.php\n      activatePlugins:\n        - wp-graphql/wp-graphql.php\n        - wp-gatsby/wp-gatsby.php\n      configFile: 'tests/_data/config.php'\n"
  },
  {
    "path": "composer.json",
    "content": "{\n  \"name\": \"gatsbyjs/wp-gatsby\",\n  \"description\": \"Optimize your WordPress site as a source for Gatsby site(s)\",\n  \"type\": \"wordpress-plugin\",\n  \"license\": \"GPL-3.0-or-later\",\n  \"authors\": [\n    {\n      \"name\": \"GatsbyJS\"\n    },\n    {\n      \"name\": \"Jason Bahl\"\n    },\n    {\n      \"name\": \"Tyler Barnes\"\n    }\n  ],\n  \"autoload\": {\n    \"psr-4\": {\n      \"WPGatsby\\\\\": \"src/\"\n    }\n  },\n  \"autoload-dev\": {\n    \"files\": [\n      \"tests/_data/config.php\"\n    ]\n  },\n  \"config\": {\n    \"optimize-autoloader\": true,\n    \"process-timeout\": 0\n  },\n  \"require\": {\n    \"php\": \"^7.3||^8.0\",\n    \"firebase/php-jwt\": \"^5.2\",\n    \"ircmaxell/random-lib\": \"^1.2\",\n    \"composer/semver\": \"^1.5\"\n  },\n  \"require-dev\": {\n    \"lucatume/wp-browser\": \"^2.4\",\n    \"codeception/module-asserts\": \"^1.0\",\n    \"codeception/module-phpbrowser\": \"^1.0\",\n    \"codeception/module-webdriver\": \"^1.0\",\n    \"codeception/module-db\": \"^1.0\",\n    \"codeception/module-filesystem\": \"^1.0\",\n    \"codeception/module-cli\": \"^1.0\",\n    \"codeception/util-universalframework\": \"^1.0\",\n    \"dealerdirect/phpcodesniffer-composer-installer\": \"^0.7.1\",\n    \"wp-coding-standards/wpcs\": \"2.1.1\",\n    \"phpcompatibility/phpcompatibility-wp\": \"2.1.0\",\n    \"squizlabs/php_codesniffer\": \"3.5.4\",\n    \"codeception/module-rest\": \"^1.2\",\n    \"wp-graphql/wp-graphql-testcase\": \"^1.0\",\n    \"phpunit/phpunit\": \"9.4.1\"\n  },\n  \"scripts\": {\n    \"install-test-env\": \"bash bin/install-test-env.sh\",\n    \"docker-build\": \"bash bin/run-docker.sh build\",\n    \"docker-run\": \"bash bin/run-docker.sh run\",\n    \"docker-destroy\": \"docker-compose down\",\n    \"build-and-run\": [\n      \"@docker-build\",\n      \"@docker-run\"\n    ],\n    \"build-app\": \"@docker-build -a\",\n    \"build-test\": \"@docker-build -t\",\n    \"run-app\": \"@docker-run -a\",\n    \"run-test\": \"@docker-run -t\",\n    \"lint\": \"vendor/bin/phpcs\",\n    \"phpcs-i\": [\n      \"php ./vendor/bin/phpcs -i\"\n    ],\n    \"check-cs\": [\n      \"php ./vendor/bin/phpcs src\"\n    ],\n    \"fix-cs\": [\n      \"php ./vendor/bin/phpcbf src\"\n    ]\n  },\n  \"support\": {\n    \"issues\": \"https://github.com/gatsbyjs/wp-gatsby/issues\",\n    \"source\": \"https://github.com/gatsbyjs/wp-gatsby\"\n  }\n}\n"
  },
  {
    "path": "docker/app.Dockerfile",
    "content": "###############################################################################\n# Pre-configured WordPress Installation w/ WPGraphQL, WPGatsby #\n# For testing only, use in production not recommended. #\n###############################################################################\nARG WP_VERSION\nARG PHP_VERSION\n\nFROM wordpress:${WP_VERSION}-php${PHP_VERSION}-apache\n\nENV WP_VERSION=${WP_VERSION}\nENV PHP_VERSION=${PHP_VERSION}\n\nLABEL author=jasonbahl\nLABEL author_uri=https://github.com/jasonbahl\n\nSHELL [ \"/bin/bash\", \"-c\" ]\n\n# Install system packages\nRUN apt-get update && \\\n    apt-get -y install \\\n    # CircleCI depedencies\n    git \\\n    ssh \\\n    tar \\\n    gzip \\\n    wget \\\n    mariadb-client\n\n# Install Dockerize\nENV DOCKERIZE_VERSION v0.6.1\nRUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \\\n    && tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \\\n    && rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz\n\n# Install WP-CLI\nRUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar \\\n    && chmod +x wp-cli.phar \\\n    && mv wp-cli.phar /usr/local/bin/wp\n\n# Set project environmental variables\nENV WP_ROOT_FOLDER=\"/var/www/html\"\nENV WORDPRESS_DB_HOST=${DB_HOST}\nENV WORDPRESS_DB_USER=${DB_USER}\nENV WORDPRESS_DB_PASSWORD=${DB_PASSWORD}\nENV WORDPRESS_DB_NAME=${DB_NAME}\nENV PLUGINS_DIR=\"${WP_ROOT_FOLDER}/wp-content/plugins\"\nENV PROJECT_DIR=\"${PLUGINS_DIR}/wp-gatsby\"\n\n# Remove exec statement from base entrypoint script.\nRUN sed -i '$d' /usr/local/bin/docker-entrypoint.sh\n\n# Set up Apache\nRUN echo 'ServerName localhost' >> /etc/apache2/apache2.conf\n\n# Set up entrypoint\nWORKDIR    /var/www/html\nCOPY       docker/app.entrypoint.sh /usr/local/bin/app-entrypoint.sh\nRUN        chmod 755 /usr/local/bin/app-entrypoint.sh\nENTRYPOINT [\"app-entrypoint.sh\"]\nCMD [\"apache2-foreground\"]\n"
  },
  {
    "path": "docker/app.entrypoint.sh",
    "content": "#!/bin/bash\n\n# Run WordPress docker entrypoint.\n. docker-entrypoint.sh 'apache2'\n\nset +u\n\n# Ensure mysql is loaded\ndockerize -wait tcp://${DB_HOST}:${DB_HOST_PORT:-3306} -timeout 1m\n\n# Config WordPress\nif [ ! -f \"${WP_ROOT_FOLDER}/wp-config.php\" ]; then\n    wp config create \\\n        --path=\"${WP_ROOT_FOLDER}\" \\\n        --dbname=\"${DB_NAME}\" \\\n        --dbuser=\"${DB_USER}\" \\\n        --dbpass=\"${DB_PASSWORD}\" \\\n        --dbhost=\"${DB_HOST}\" \\\n        --dbprefix=\"${WP_TABLE_PREFIX}\" \\\n        --skip-check \\\n        --quiet \\\n        --allow-root\nfi\n\n# Install WP if not yet installed\nif ! $( wp core is-installed --allow-root ); then\n\twp core install \\\n\t\t--path=\"${WP_ROOT_FOLDER}\" \\\n\t\t--url=\"${WP_URL}\" \\\n\t\t--title='Test' \\\n\t\t--admin_user=\"${ADMIN_USERNAME}\" \\\n\t\t--admin_password=\"${ADMIN_PASSWORD}\" \\\n\t\t--admin_email=\"${ADMIN_EMAIL}\" \\\n\t\t--allow-root\nfi\n\n# Install and activate WPGraphQL\nif [ ! -f \"${PLUGINS_DIR}/wp-graphql/wp-graphql.php\" ]; then\n    wp plugin install \\\n        https://github.com/wp-graphql/wp-graphql/archive/${WPGRAPHQL_VERSION}.zip \\\n        --activate --allow-root\nelse\n    wp plugin activate wp-graphql --allow-root\nfi\n\n# Install and activate WPGatsby\nwp plugin activate wp-gatsby --allow-root\n\n# Set pretty permalinks.\nwp rewrite structure '/%year%/%monthnum%/%postname%/' --allow-root\n\nwp db export \"${PROJECT_DIR}/tests/_data/dump.sql\" --allow-root\n\nexec \"$@\"\n"
  },
  {
    "path": "docker/testing.Dockerfile",
    "content": "############################################################################\n# Container for running Codeception tests on a WooGraphQL Docker instance. #\n############################################################################\n\n# Using the 'DESIRED_' prefix to avoid confusion with environment variables of the same name.\nFROM wpgatsby-app:latest\n\nLABEL author=jasonbahl\nLABEL author_uri=https://github.com/jasonbahl\n\nSHELL [ \"/bin/bash\", \"-c\" ]\n\n# Redeclare ARGs and set as environmental variables for reuse.\nARG USE_XDEBUG\nENV USING_XDEBUG=${USE_XDEBUG}\n\n# Install php extensions\nRUN docker-php-ext-install pdo_mysql\n\n# Install composer\nENV COMPOSER_ALLOW_SUPERUSER=1\n\nRUN curl -sS https://getcomposer.org/installer | php -- \\\n    --filename=composer \\\n    --install-dir=/usr/local/bin\n\n# Add composer global binaries to PATH\nENV PATH \"$PATH:~/.composer/vendor/bin\"\n\n# Configure php\nRUN echo \"date.timezone = UTC\" >> /usr/local/etc/php/php.ini\n\n# Remove exec statement from base entrypoint script.\nRUN sed -i '$d' /usr/local/bin/app-entrypoint.sh\n\n# Set up entrypoint\nWORKDIR    /var/www/html/wp-content/plugins/wp-gatsby\nCOPY       docker/testing.entrypoint.sh /usr/local/bin/testing-entrypoint.sh\nRUN        chmod 755 /usr/local/bin/testing-entrypoint.sh\nENTRYPOINT [\"testing-entrypoint.sh\"]\n"
  },
  {
    "path": "docker/testing.entrypoint.sh",
    "content": "#!/bin/bash\n\n# Processes parameters and runs Codeception.\nrun_tests() {\n    echo \"Running Tests\"\n    if [[ -n \"$COVERAGE\" ]]; then\n        local coverage=\"--coverage --coverage-xml\"\n    fi\n    if [[ -n \"$DEBUG\" ]]; then\n        local debug=\"--debug\"\n    fi\n\n    local suites=${1:-\" ;\"}\n    IFS=';' read -ra target_suites <<< \"$suites\"\n    for suite in \"${target_suites[@]}\"; do\n        vendor/bin/codecept run -c codeception.dist.yml ${suite} ${coverage:-} ${debug:-} --no-exit\n    done\n}\n\n# Exits with a status of 0 (true) if provided version number is higher than proceeding numbers.\nversion_gt() {\n    test \"$(printf '%s\\n' \"$@\" | sort -V | head -n 1)\" != \"$1\";\n}\n\nwrite_htaccess() {\n    echo \"<IfModule mod_rewrite.c>\nRewriteEngine On\nRewriteBase /\nSetEnvIf Authorization \\\"(.*)\\\" HTTP_AUTHORIZATION=\\$1\nRewriteRule ^index\\.php$ - [L]\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteRule . /index.php [L]\n</IfModule>\" >> ${WP_ROOT_FOLDER}/.htaccess\n}\n\n# Move to WordPress root folder\nworkdir=\"$PWD\"\necho \"Moving to WordPress root directory.\"\ncd ${WP_ROOT_FOLDER}\n\n# Run app entrypoint script.\n. app-entrypoint.sh\n\nwrite_htaccess\n\n# Return to PWD.\necho \"Moving back to project working directory.\"\ncd ${workdir}\n\n# Ensure Apache is running\nservice apache2 start\n\n# Ensure everything is loaded\ndockerize \\\n    -wait tcp://${DB_HOST}:${DB_HOST_PORT:-3306} \\\n    -wait ${WP_URL} \\\n    -timeout 1m\n\n# Download c3 for testing.\nif [ ! -f \"$PROJECT_DIR/c3.php\" ]; then\n    echo \"Downloading Codeception's c3.php\"\n    curl -L 'https://raw.github.com/Codeception/c3/2.0/c3.php' > \"$PROJECT_DIR/c3.php\"\nfi\n\nif [[ -n \"$LOWEST\" ]]; then\n    PREFER_LOWEST=\"--prefer-source\"\nfi\n\n# Install dependencies\nCOMPOSER_MEMORY_LIMIT=-1 composer update --prefer-source ${PREFER_LOWEST}\nCOMPOSER_MEMORY_LIMIT=-1 composer install --prefer-source --no-interaction\n\n# Install pcov/clobber if PHP7.1+\nif version_gt $PHP_VERSION 7.0 && [[ -n \"$COVERAGE\" ]] && [[ -z \"$USING_XDEBUG\" ]]; then\n    echo \"Installing pcov/clobber\"\n    COMPOSER_MEMORY_LIMIT=-1 composer require --dev pcov/clobber\n    vendor/bin/pcov clobber\nelif [[ -n \"$COVERAGE\" ]]; then\n    echo \"Using XDebug for codecoverage\"\nfi\n\n# Set output permission\necho \"Setting Codeception output directory permissions\"\nchmod 777 ${TESTS_OUTPUT}\n\n# Run tests\nrun_tests ${SUITES}\n\n# Remove c3.php\nif [ -f \"$PROJECT_DIR/c3.php\" ] && [ \"$SKIP_TESTS_CLEANUP\" != \"1\" ]; then\n    echo \"Removing Codeception's c3.php\"\n    rm -rf \"$PROJECT_DIR/c3.php\"\nfi\n\n# Clean coverage.xml and clean up PCOV configurations.\nif [ -f \"${TESTS_OUTPUT}/coverage.xml\" ] && [[ -n \"$COVERAGE\" ]]; then\n    echo 'Cleaning coverage.xml for deployment'.\n    pattern=\"$PROJECT_DIR/\"\n    sed -i \"s~$pattern~~g\" \"$TESTS_OUTPUT\"/coverage.xml\n\n    # Remove pcov/clobber\n    if version_gt $PHP_VERSION 7.0 && [[ -z \"$SKIP_TESTS_CLEANUP\" ]] && [[ -z \"$USING_XDEBUG\" ]]; then\n        echo 'Removing pcov/clobber.'\n        vendor/bin/pcov unclobber\n        COMPOSER_MEMORY_LIMIT=-1 composer remove --dev pcov/clobber\n    fi\n\nfi\n\nif [[ -z \"$SKIP_TESTS_CLEANUP\" ]]; then\n    echo 'Changing composer configuration in container.'\n    composer config --global discard-changes true\n\n    echo 'Removing devDependencies.'\n    composer install --no-dev -n\n\n    echo 'Removing composer.lock'\n    rm composer.lock\nfi\n\n# Set public test result files permissions.\nif [ -n \"$(ls \"$TESTS_OUTPUT\")\" ]; then\n    echo 'Setting result files permissions'.\n    chmod 777 -R \"$TESTS_OUTPUT\"/*\nfi\n\n\n# Check results and exit accordingly.\nif [ -f \"${TESTS_OUTPUT}/failed\" ]; then\n    echo \"Uh oh, some went wrong.\"\n    exit 1\nelse\n    echo \"Woohoo! It's working!\"\n    exit 0\nfi\n"
  },
  {
    "path": "docker-compose.yml",
    "content": "version: '3.3'\n\nservices:\n  app:\n    depends_on:\n      - app_db\n    image: wpgatsby-app:latest\n    volumes:\n      - '.:/var/www/html/wp-content/plugins/wp-gatsby'\n      - './.log/app:/var/log/apache2'\n    environment:\n      WP_URL: 'http://localhost:8091'\n      WP_DOMAIN: 'localhost:8091'\n      DB_HOST: app_db\n      DB_NAME: wordpress\n      DB_USER: wordpress\n      DB_PASSWORD: wordpress\n      WP_DOMAIN: localhost\n      ADMIN_EMAIL: admin@example.com\n      ADMIN_USERNAME: admin\n      ADMIN_PASSWORD: password\n      INCLUDE_WPGRAPHIQL: 1\n      IMPORT_WC_PRODUCTS: 1\n      STRIPE_GATEWAY: 1\n    ports:\n      - '8091:80'\n    networks:\n      local:\n\n  app_db:\n    image: mysql:5.7\n    environment:\n      MYSQL_ROOT_PASSWORD: root\n      MYSQL_DATABASE:      wordpress\n      MYSQL_USER:          wordpress\n      MYSQL_PASSWORD:      wordpress\n    ports:\n      - '3306'\n    networks:\n      testing:\n      local:\n\n  testing:\n    depends_on:\n      - app_db\n    image: wpgatsby-testing:latest\n    volumes:\n      - '.:/var/www/html/wp-content/plugins/wp-gatsby'\n      - './.log/testing:/var/log/apache2'\n      - './codeception.dist.yml:/var/www/html/wp-content/plugins/wp-gatsby/codeception.yml'\n    env_file: .env.dist\n    environment:\n      XDEBUG_CONFIG: remote_host=host.docker.internal remote_port=9000 remote_enable=1\n      DB_HOST: app_db\n      WP_URL: 'http://localhost'\n      WP_DOMAIN: 'localhost'\n      STRIPE_GATEWAY: 1\n    networks:\n      testing:\n\nnetworks:\n  local:\n  testing:\n"
  },
  {
    "path": "docs/action-monitor.md",
    "content": "# Activity Monitor\n\nWPGatsby monitors activity that occurs in your WordPress site and notifies your Gatsby site\nof the changes, allowing your Gatsby site to stay in sync with your WordPress site.\n\nThis document covers how WPGatsby tracks activity, what activity is tracked and how to customize the\nactivity tracking.\n\n## How does WPGatsby track activity?\n\nWPGatsby listens for CRUD (create, read, update and delete) actions that occur in WordPress, such as\npublishing or deleting a post, updating menus, and more.\n\nWPGatsby uses common WordPress actions to capture the objects that are changing, and stores records\nof the actions in a custom post type named \"action_monitor\".\n\nWhenever tracked activity is detected and an \"action_monitor\" action is created, a webhook is sent\nto the Gatsby site that is configured in the [GatsbyJS settings page](./settings.md), allowing Gatsby to rebuild\npages that are affected by the changed data.\n\n## What activity does WPGatsby track?\n\nWPGatsby tracks when public data is changed in WordPress. Private data, such as draft posts, or users\nwith no published content, is not tracked (except for during previews but that data is private and deleted as soon as the preview completes).\n\nBelow you can read more details about all the data that WPGatsby tracks.\n\nAdditionally, you can check out [the tests](https://github.com/gatsbyjs/wp-gatsby/blob/master/tests/wpunit/ActionMonitorTest.php)\nto see all the data that is tracked and the expected outcomes of different actions in WordPress.\n\n### Advanced Custom Fields\n\nWhenever ACF Field Groups are updated or deleted (using the ACF User Interface), WPGatsby logs an\naction monitor action to notify Gatsby that the WPGraphQL Schema _may_ have changed.\n\n#### Activity Tracked for ACF\n\n-   Update Field Group\n-   Delete Field Group\n\n### Media\n\nWhenever Media Items are uploaded, edited or deleted in the WordPress Media Library, WPGatsby logs\nan action monitor action to notify Gatsby of the change.\n\n#### Activity Tracked for Media\n\n-   Add Attachment\n-   Edit Attachment\n-   Delete Attachment\n-   Save Image Editor File\n-   Save Image File\n\n### Menus\n\nBy default, Menus are considered private entities in WordPress. Once they are assinged to a Menu\nLocation, they become public. WPGatsby tracks activity related to public Menus and Menu Items.\n\nMenus that are not assigned to Nav Menu Locations are not tracked, other than when they transition\nfrom being not assigned a location to assigned a location, or the inverse.\n\n#### Activity Tracked for Menus\n\n-   Update Nav Menu Locations\n-   Update Nav Menu\n-   Delete Nav Menu\n-   Update Nav Menu Item\n-   Add Nav Menu Item\n\n### Posts (of any public post type, set to show in GraphQL)\n\nPosts (and Pages and Custom Post Types) are typically pretty central to any WordPress site, and it's\nimportant for Gatsby to know when they change.\n\nWPGatsby tracks when posts are published (made public), and when published posts are edited or\ndeleted. Non-published posts are not tracked by WPGatsby. So changes can be made to draft posts, for\nexample and WPGatsby won't track that activity.\n\n#### Activity Tracked for Posts\n\n-   Post Updated\n-   Transition Post Status\n-   Deleted Post\n-   Post Meta Added\n-   Post Meta Updated\n-   Post Meta Deleted\n\n### Post Types (registered post types, not content of a post type)\n\nWPGatsby caches the list of registered post types, and whenever it detects changes to the Post Type\nregistry, it logs an \"action_monitor\" action and notifies Gatsby of the change.\n\nThis allows Gatsby to update it's GraphQL Schema to reflect the changes in WPGraphQL.\n\n#### Activity Tracked for Post Types\n\n-   Post Type registry changes\n\n### Settings\n\nThe way WordPress stores settings is a bit of a blackbox. Many different things are stored in the\noptions table, so tracking changes to _all_ settings could be problematic. For example, tracking all\nchanges to all settings would cause WPGatsby to track transients. A transient changing would cause\nGatsby to fetch data from WordPress again, which could trigger further transient changes, and thus\ncould lead to an infinite loop.\n\nSo, instead of tracking updates to _all_ settings, WPGatsby only tracks specific settings that have\nbeen configured to be \"allowed\" to be tracked.\n\nWPGatsby provides an initial list of settings to track, and this list can be filtered (using the\n`gatsby_action_monitor_should_track_option` filter) to disallow tracked settings, or allow tracking\nof additional settings.\n\n#### Activity Tracked for Settings\n\n-   Updated settings (based on filterable allow-list of settings to track)\n\n### Taxonomies (registered taxonomies, not terms of a taxonomy)\n\nWPGatsby caches the list of registered taxonomies, and whenever it detects changes to the Taxonomy\nregistry, it logs an \"action_monitor\" action and notifies Gatsby of the change.\n\nThis allows Gatsby to update it's GraphQL Schema to reflect the changes in WPGraphQL.\n\n#### Activity Tracked for Taxonomies\n\n-   Custom Taxonomy registry changes\n\n### Terms (of any public taxonomy, set to show in GraphQL)\n\nTerms are tracked when they are created, updated or deleted.\n\n#### Activity Tracked for Terms\n\n-   Term Created\n-   Term Updated\n-   Term Deleted\n-   Term Meta Added\n-   Term Meta Updated\n-   Term Meta Deleted\n\n### Users (must be a published author of public content)\n\nIn WordPress, users are considered private by default. But once a user publishes content of a public\npost type, that user becomes a public entity, as it then has an author archive page, REST API\nendpoint, etc. WPGatsby tracks activity of these public users. Users with no published content are\nnot tracked.\n\n#### Activity Tracked for Users\n\n-   Profile Update\n-   Delete User\n-   Update User Meta\n-   Add User Meta\n-   Delete User Meta\n-   Publish Post by author\n\n## How to customize WPGatsby Activity Monitoring\n\nYou may find that you want to ignore certain actions from being tracked, or more likely you may want\nto track additional actions that are not tracked by default.\n\nBelow you can learn more about both of these cases:\n\n### Skip tracking of an action\n\nIf you'd like to prevent an action from being logged, you can use the `gatsby_pre_log_action_monitor_action` filter.\n\nThis filter will get passed the array of data to be logged.\n\nIf the filter returns `false`, the action will not be logged. If it returns anything else, the action\nwill proceed to be logged.\n\nExample:\n\nThe example below would ignore logging actions for Post with ID `15`.\n\n```php\nadd_filter( 'gatsby_pre_log_action_monitor_action', function( $null, $log_data ) {\n\n    if ( 'Post' === $log_data['graphql_single_name'] && 15 === $log_data['node_id'] ) {\n        return false;\n    }\n    return $null;\n\n}, 10, 2 );\n```\n\n### Tracking a custom action\n\nIf you have a plugin that stores data in non-traditional ways, such as in a Custom Database Table,\nyou may need to track custom actions to tell Gatsby that something has changed.\n\nYou can do this by extending the `Monitor` class, and registering it with the `gatsby_action_monitors` filter. \n\n**Note**: All of the fields passed to the `log_action` method below are required.\n\n```php\n/**\n * Class - MyCustomActionMonitor\n */\nclass MyCustomActionMonitor extends \\WPGatsby\\ActionMonitor\\Monitors\\Monitor {\n\n\t/**\n\t * Initialize the custom tracker.\n\t */\n\tpublic function init() {\n\t\t// Hook into the custom action you want to log.\n\t\tadd_action( 'my_custom_action', [ $this, 'custom_action_callback' ] );\n\t}\n\n\t/**\n\t * Callback for custom action.\n\t */\n\tpublic function custom_action_callback( $your_custom_object ) {\n\n\t\t/**\n\t\t * Log an action to Action Monitor. \n\t\t * \n\t\t * This will create an entry in the `action_monitor` post type\n\t\t * and will notify Gatsby Source WordPress about the activity.\n\t\t */\n\t\t$this->monitor->log_action( [\n\t\t\t'action_type' => 'CREATE',\n\t\t\t'title' => $your_custom_object->title,\n\t\t\t'graphql_single_name' => 'MyCustomType',\n\t\t\t'graphql_plural_name' => 'MyCustomTypes',\n\t\t\t'status' => 'publish',\n\t\t\t'relay_id' => base64_encode( 'MyCustomType:' . $your_custom_object->ID ),\n\t\t\t'node_id' => $your_custom_object->ID,\n\t\t] );\n\t}\n}\n\nadd_filter( 'gatsby_action_monitors', function( array $monitors, \\WPGatsby\\ActionMonitor\\ActionMonitor $action_monitor) {\n\t$monitors['MyCustomActionMonitor'] = new MyCustomActionMonitor( $action_monitor );\n\n\treturn $monitors;\n}, 10, 2 );\n```\n"
  },
  {
    "path": "docs/running-tests.md",
    "content": "# Running Tests\n\nThis document provides information on running tests locally.\n\nThere are 2 options: \n\n- [Running tests with your own local environment](#local-tests) (faster, more room for environmental inconsistencies)\n- [Running tests with Docker](#docker-tests) (slower, more consistent)\n\n<span id=\"local-tests\"></span>\n## Running Tests with your own local environment\n\nBelow are instructions for running tests with your own local environment. Running tests this way is more flexible and faster than running tests with Docker. But, there's a chance your local environment (PHP versions, MySQL versions, etc) could change (as you work on other projects, for example), and that could cause problems with the test suite. \n\nIf you follow the instructions below, you should be able to run tests locally with your own local environment. \n\n### Prerequisties\nYou must have the following available locally: \n- **PHP**\n- **MySQL** (or equivalent such as MariaDB)\n- **[Composer](https://getcomposer.org/doc/00-intro.md)** \n- **[WP-CLI](https://wp-cli.org/)** installed as well as terminal/shell/command-line access.\n\n\n### Codeception & the wp-browser module\n**WPGraphQL** and **WPGatsby** both use the **[Codeception](https://codeception.com/)** testing framework alongside the **[wp-browser](https://wpbrowser.wptestkit.dev/)** module created by [Luca Tumedei](https://www.theaveragedev.com/) for running the automated test suite. We'll be using Codeception scaffolding to generate all the tedious test code, but this will not be an in-depth guide on either of these libraries. It's not required to process with this tutorial, but it's highly recommended that after finishing this tutorial you take a look at the documentation for both.\n- **[Codeception](https://codeception.com/docs/01-Introduction)**\n- **[wp-browser](https://wpbrowser.wptestkit.dev/)**\n\n1. Start by cloning **[WPGatsby](https://github.com/wp-gatsby/wp-gatsby)**.\n2. Open your terminal.\n3. Copy the `.env.dist` to `.env` by execute the following in your terminal in the **WPGatsby** root directory.\n```\ncp .env.dist .env\n```\n4. Open the .env and update the highlighted environmental variables to match your machine setup.\n![.env example](img/testing-env-example.png)\n5. Last thing to do is run the WordPress testing environment install script in the terminal.\n```\ncomposer install-test-env\n```\n\nThis will create and configure a WordPress installation in a temporary directory for the purpose of testing.\n\n### Setting up Codeception\nNow that we have setup our testing environment, let's run the tests. To do this we will need to install the **Codeception** and the rest of our **devDependencies**\n\n1. First run `composer install` in the terminal.\n2. Next copy the `codeception.dist.yml` to `codeception.yml`\n```\ncp codeception.dist.yml codeception.yml\n```\n3. Open `codeception.yml` and make the following changes.\n![codeception.yml params config](img/codeception-yml-changes.png)\n![codeception.yml WPLoader config](img/codeception-wploader-config.png)\n\nNow you are ready to run the tests.\n\n### Running the tests\nNow your're ready to rum the tests. There is a small issue you may have with our testing environment. The WordPress installation we created doesn't support **end-to-end (*e2e*)** testing, however this won't be a problem. **WPGraphQL** is an API and most of the time you can get away with just ensuring that your query works, and **WPGraphQL** provides a few functions that will allow us to do just that.\n\nLet's get started by running all the unit tests. Back in your terminal run the following:\n```\nvendor/bin/codecept run wpunit\n```\nIf everything is how it should be you should get all passing tests.\n![WPUnit test results](img/test-results.png)\n\nYou can also run individual test suites by specifying the path: \n\n```\nvendor/bin/codecept run tests/wpunit/ActionMonitorTest.php\n```\n\nOr even run a single test by specifying the specific test:\n\n```\nvendor/bin/codecept run tests/wpunit/ActionMonitorTest.php:testActionMonitorQueryIsValid\n```\n\n<span id=\"docker-tests\"></span>\n## Running Tests with Docker\n\nThe automated tests that run in the Github workflows use Docker. This ensures the environment is always what we expect. No risk of inconsistencies with PHP versions, MySQL versions, etc. \n\nThe trade off (at least as of right now) is that you must run the entire test suite instead of having the ability to run individual tests. And you must wait for the Docker environment to boot up. Overall, this is slower and less flexible than running tests with your own local environment, but it's more consistent. \n\nTo run tests with Docker, run the following commands:\n\n- `composer install`: This will install the composer dependencies needed for testing\n- `composer build-test`: This will build a Docker environment. This can take some time, especially the first time you run it.\n- `composer run-test`: This will run the tests in the Docker environment.\n"
  },
  {
    "path": "lib/wp-settings-api.php",
    "content": "<?php\n\n/**\n * weDevs Settings API wrapper class\n *\n * @version 1.3 (27-Sep-2016)\n *\n * @author  Tareq Hasan <tareq@weDevs.com>\n * @link    https://tareq.co Tareq Hasan\n * @link    https://github.com/tareq1988/wordpress-settings-api-class\n * @example example/oop-example.php How to use the class\n */\nif ( ! class_exists( 'WPGraphQL_Settings_API' ) ) :\n\tclass WPGraphQL_Settings_API {\n\n\t\t/**\n\t\t * settings sections array\n\t\t *\n\t\t * @var array\n\t\t */\n\t\tprotected $settings_sections = array();\n\n\t\t/**\n\t\t * Settings fields array\n\t\t *\n\t\t * @var array\n\t\t */\n\t\tprotected $settings_fields = array();\n\n\t\tpublic function __construct() {\n\t\t\tadd_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );\n\t\t}\n\n\t\t/**\n\t\t * Enqueue scripts and styles\n\t\t */\n\t\tfunction admin_enqueue_scripts() {\n\t\t\twp_enqueue_style( 'wp-color-picker' );\n\n\t\t\twp_enqueue_media();\n\t\t\twp_enqueue_script( 'wp-color-picker' );\n\t\t\twp_enqueue_script( 'jquery' );\n\t\t}\n\n\t\t/**\n\t\t * Set settings sections\n\t\t *\n\t\t * @param array $sections setting sections array\n\t\t */\n\t\tfunction set_sections( $sections ) {\n\t\t\t$this->settings_sections = $sections;\n\n\t\t\treturn $this;\n\t\t}\n\n\t\t/**\n\t\t * Add a single section\n\t\t *\n\t\t * @param array $section\n\t\t */\n\t\tfunction add_section( $section ) {\n\t\t\t$this->settings_sections[] = $section;\n\n\t\t\treturn $this;\n\t\t}\n\n\t\t/**\n\t\t * Set settings fields\n\t\t *\n\t\t * @param array $fields settings fields array\n\t\t */\n\t\tfunction set_fields( $fields ) {\n\t\t\t$this->settings_fields = $fields;\n\n\t\t\treturn $this;\n\t\t}\n\n\t\tfunction add_field( $section, $field ) {\n\t\t\t$defaults = array(\n\t\t\t\t'name'  => '',\n\t\t\t\t'label' => '',\n\t\t\t\t'desc'  => '',\n\t\t\t\t'type'  => 'text'\n\t\t\t);\n\n\t\t\t$arg                                 = wp_parse_args( $field, $defaults );\n\t\t\t$this->settings_fields[ $section ][] = $arg;\n\n\t\t\treturn $this;\n\t\t}\n\n\t\t/**\n\t\t * Initialize and registers the settings sections and fileds to WordPress\n\t\t *\n\t\t * Usually this should be called at `admin_init` hook.\n\t\t *\n\t\t * This function gets the initiated settings sections and fields. Then\n\t\t * registers them to WordPress and ready for use.\n\t\t */\n\t\tfunction admin_init() {\n\t\t\t//register settings sections\n\t\t\tforeach ( $this->settings_sections as $section ) {\n\t\t\t\tif ( false == get_option( $section['id'] ) ) {\n\t\t\t\t\tadd_option( $section['id'] );\n\t\t\t\t}\n\n\t\t\t\tif ( isset( $section['desc'] ) && ! empty( $section['desc'] ) ) {\n\t\t\t\t\t$section['desc'] = '<div class=\"inside\">' . $section['desc'] . '</div>';\n\t\t\t\t\t$callback        = function() use ( $section ) {\n\t\t\t\t\t\techo str_replace( '\"', '\\\"', $section['desc'] );\n\t\t\t\t\t};\n\t\t\t\t} else if ( isset( $section['callback'] ) ) {\n\t\t\t\t\t$callback = $section['callback'];\n\t\t\t\t} else {\n\t\t\t\t\t$callback = null;\n\t\t\t\t}\n\n\t\t\t\tadd_settings_section( $section['id'], $section['title'], $callback, $section['id'] );\n\t\t\t}\n\n\t\t\t//register settings fields\n\t\t\tforeach ( $this->settings_fields as $section => $field ) {\n\t\t\t\tforeach ( $field as $option ) {\n\n\t\t\t\t\t$name     = $option['name'];\n\t\t\t\t\t$type     = isset( $option['type'] ) ? $option['type'] : 'text';\n\t\t\t\t\t$label    = isset( $option['label'] ) ? $option['label'] : '';\n\t\t\t\t\t$callback = isset( $option['callback'] ) ? $option['callback'] : array(\n\t\t\t\t\t\t$this,\n\t\t\t\t\t\t'callback_' . $type\n\t\t\t\t\t);\n\n\t\t\t\t\t$args = array(\n\t\t\t\t\t\t'id'                => $name,\n\t\t\t\t\t\t'class'             => isset( $option['class'] ) ? $option['class'] : $name,\n\t\t\t\t\t\t'label_for'         => \"{$section}[{$name}]\",\n\t\t\t\t\t\t'desc'              => isset( $option['desc'] ) ? $option['desc'] : '',\n\t\t\t\t\t\t'name'              => $label,\n\t\t\t\t\t\t'section'           => $section,\n\t\t\t\t\t\t'size'              => isset( $option['size'] ) ? $option['size'] : null,\n\t\t\t\t\t\t'options'           => isset( $option['options'] ) ? $option['options'] : '',\n\t\t\t\t\t\t'std'               => isset( $option['default'] ) ? $option['default'] : '',\n\t\t\t\t\t\t'sanitize_callback' => isset( $option['sanitize_callback'] ) ? $option['sanitize_callback'] : '',\n\t\t\t\t\t\t'type'              => $type,\n\t\t\t\t\t\t'placeholder'       => isset( $option['placeholder'] ) ? $option['placeholder'] : '',\n\t\t\t\t\t\t'min'               => isset( $option['min'] ) ? $option['min'] : '',\n\t\t\t\t\t\t'max'               => isset( $option['max'] ) ? $option['max'] : '',\n\t\t\t\t\t\t'step'              => isset( $option['step'] ) ? $option['step'] : '',\n\t\t\t\t\t);\n\n\t\t\t\t\tadd_settings_field( \"{$section}[{$name}]\", $label, $callback, $section, $section, $args );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// creates our settings in the options table\n\t\t\tforeach ( $this->settings_sections as $section ) {\n\t\t\t\tregister_setting( $section['id'], $section['id'], array(\n\t\t\t\t\t$this,\n\t\t\t\t\t'sanitize_options'\n\t\t\t\t) );\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Get field description for display\n\t\t *\n\t\t * @param array $args settings field args\n\t\t */\n\t\tpublic function get_field_description( $args ) {\n\t\t\tif ( ! empty( $args['desc'] ) ) {\n\t\t\t\t$desc = sprintf( '<p class=\"description\">%s</p>', $args['desc'] );\n\t\t\t} else {\n\t\t\t\t$desc = '';\n\t\t\t}\n\n\t\t\treturn $desc;\n\t\t}\n\n\t\t/**\n\t\t * Displays a text field for a settings field\n\t\t *\n\t\t * @param array $args settings field args\n\t\t */\n\t\tfunction callback_text( $args ) {\n\n\t\t\t$value       = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );\n\t\t\t$size        = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';\n\t\t\t$type        = isset( $args['type'] ) ? $args['type'] : 'text';\n\t\t\t$placeholder = empty( $args['placeholder'] ) ? '' : ' placeholder=\"' . $args['placeholder'] . '\"';\n\n\t\t\t$html = sprintf( '<input type=\"%1$s\" class=\"%2$s-text\" id=\"%3$s[%4$s]\" name=\"%3$s[%4$s]\" value=\"%5$s\"%6$s/>', $type, $size, $args['section'], $args['id'], $value, $placeholder );\n\t\t\t$html .= $this->get_field_description( $args );\n\n\t\t\techo $html;\n\t\t}\n\n\t\t/**\n\t\t * Displays a url field for a settings field\n\t\t *\n\t\t * @param array $args settings field args\n\t\t */\n\t\tfunction callback_url( $args ) {\n\t\t\t$this->callback_text( $args );\n\t\t}\n\n\t\t/**\n\t\t * Displays a number field for a settings field\n\t\t *\n\t\t * @param array $args settings field args\n\t\t */\n\t\tfunction callback_number( $args ) {\n\t\t\t$value       = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );\n\t\t\t$size        = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';\n\t\t\t$type        = isset( $args['type'] ) ? $args['type'] : 'number';\n\t\t\t$placeholder = empty( $args['placeholder'] ) ? '' : ' placeholder=\"' . $args['placeholder'] . '\"';\n\t\t\t$min         = ( $args['min'] == '' ) ? '' : ' min=\"' . $args['min'] . '\"';\n\t\t\t$max         = ( $args['max'] == '' ) ? '' : ' max=\"' . $args['max'] . '\"';\n\t\t\t$step        = ( $args['step'] == '' ) ? '' : ' step=\"' . $args['step'] . '\"';\n\n\t\t\t$html = sprintf( '<input type=\"%1$s\" class=\"%2$s-number\" id=\"%3$s[%4$s]\" name=\"%3$s[%4$s]\" value=\"%5$s\"%6$s%7$s%8$s%9$s/>', $type, $size, $args['section'], $args['id'], $value, $placeholder, $min, $max, $step );\n\t\t\t$html .= $this->get_field_description( $args );\n\n\t\t\techo $html;\n\t\t}\n\n\t\t/**\n\t\t * Displays a checkbox for a settings field\n\t\t *\n\t\t * @param array $args settings field args\n\t\t */\n\t\tfunction callback_checkbox( $args ) {\n\n\t\t\t$value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );\n\n\t\t\t$html = '<fieldset>';\n\t\t\t$html .= sprintf( '<label for=\"wpuf-%1$s[%2$s]\">', $args['section'], $args['id'] );\n\t\t\t$html .= sprintf( '<input type=\"hidden\" name=\"%1$s[%2$s]\" value=\"off\" />', $args['section'], $args['id'] );\n\t\t\t$html .= sprintf( '<input type=\"checkbox\" class=\"checkbox\" id=\"wpuf-%1$s[%2$s]\" name=\"%1$s[%2$s]\" value=\"on\" %3$s />', $args['section'], $args['id'], checked( $value, 'on', false ) );\n\t\t\t$html .= sprintf( '%1$s</label>', $args['desc'] );\n\t\t\t$html .= '</fieldset>';\n\n\t\t\techo $html;\n\t\t}\n\n\t\t/**\n\t\t * Displays a multicheckbox for a settings field\n\t\t *\n\t\t * @param array $args settings field args\n\t\t */\n\t\tfunction callback_multicheck( $args ) {\n\n\t\t\t$value = $this->get_option( $args['id'], $args['section'], $args['std'] );\n\t\t\t$html  = '<fieldset>';\n\t\t\t$html  .= sprintf( '<input type=\"hidden\" name=\"%1$s[%2$s]\" value=\"\" />', $args['section'], $args['id'] );\n\t\t\tforeach ( $args['options'] as $key => $label ) {\n\t\t\t\t$checked = isset( $value[ $key ] ) ? $value[ $key ] : '0';\n\t\t\t\t$html    .= sprintf( '<label for=\"wpuf-%1$s[%2$s][%3$s]\">', $args['section'], $args['id'], $key );\n\t\t\t\t$html    .= sprintf( '<input type=\"checkbox\" class=\"checkbox\" id=\"wpuf-%1$s[%2$s][%3$s]\" name=\"%1$s[%2$s][%3$s]\" value=\"%3$s\" %4$s />', $args['section'], $args['id'], $key, checked( $checked, $key, false ) );\n\t\t\t\t$html    .= sprintf( '%1$s</label><br>', $label );\n\t\t\t}\n\n\t\t\t$html .= $this->get_field_description( $args );\n\t\t\t$html .= '</fieldset>';\n\n\t\t\techo $html;\n\t\t}\n\n\t\t/**\n\t\t * Displays a radio button for a settings field\n\t\t *\n\t\t * @param array $args settings field args\n\t\t */\n\t\tfunction callback_radio( $args ) {\n\n\t\t\t$value = $this->get_option( $args['id'], $args['section'], $args['std'] );\n\t\t\t$html  = '<fieldset>';\n\n\t\t\tforeach ( $args['options'] as $key => $label ) {\n\t\t\t\t$html .= sprintf( '<label for=\"wpuf-%1$s[%2$s][%3$s]\">', $args['section'], $args['id'], $key );\n\t\t\t\t$html .= sprintf( '<input type=\"radio\" class=\"radio\" id=\"wpuf-%1$s[%2$s][%3$s]\" name=\"%1$s[%2$s]\" value=\"%3$s\" %4$s />', $args['section'], $args['id'], $key, checked( $value, $key, false ) );\n\t\t\t\t$html .= sprintf( '%1$s</label><br>', $label );\n\t\t\t}\n\n\t\t\t$html .= $this->get_field_description( $args );\n\t\t\t$html .= '</fieldset>';\n\n\t\t\techo $html;\n\t\t}\n\n\t\t/**\n\t\t * Displays a selectbox for a settings field\n\t\t *\n\t\t * @param array $args settings field args\n\t\t */\n\t\tfunction callback_select( $args ) {\n\n\t\t\t$value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );\n\t\t\t$size  = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';\n\t\t\t$html  = sprintf( '<select class=\"%1$s\" name=\"%2$s[%3$s]\" id=\"%2$s[%3$s]\">', $size, $args['section'], $args['id'] );\n\n\t\t\tforeach ( $args['options'] as $key => $label ) {\n\t\t\t\t$html .= sprintf( '<option value=\"%s\"%s>%s</option>', $key, selected( $value, $key, false ), $label );\n\t\t\t}\n\n\t\t\t$html .= sprintf( '</select>' );\n\t\t\t$html .= $this->get_field_description( $args );\n\n\t\t\techo $html;\n\t\t}\n\n\t\t/**\n\t\t * Displays a textarea for a settings field\n\t\t *\n\t\t * @param array $args settings field args\n\t\t */\n\t\tfunction callback_textarea( $args ) {\n\n\t\t\t$value       = esc_textarea( $this->get_option( $args['id'], $args['section'], $args['std'] ) );\n\t\t\t$size        = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';\n\t\t\t$placeholder = empty( $args['placeholder'] ) ? '' : ' placeholder=\"' . $args['placeholder'] . '\"';\n\n\t\t\t$html = sprintf( '<textarea rows=\"5\" cols=\"55\" class=\"%1$s-text\" id=\"%2$s[%3$s]\" name=\"%2$s[%3$s]\"%4$s>%5$s</textarea>', $size, $args['section'], $args['id'], $placeholder, $value );\n\t\t\t$html .= $this->get_field_description( $args );\n\n\t\t\techo $html;\n\t\t}\n\n\t\t/**\n\t\t * Displays the html for a settings field\n\t\t *\n\t\t * @param  array $args settings field args\n\t\t *\n\t\t * @return string\n\t\t */\n\t\tfunction callback_html( $args ) {\n\t\t\techo $this->get_field_description( $args );\n\t\t}\n\n\t\t/**\n\t\t * Displays a rich text textarea for a settings field\n\t\t *\n\t\t * @param array $args settings field args\n\t\t */\n\t\tfunction callback_wysiwyg( $args ) {\n\n\t\t\t$value = $this->get_option( $args['id'], $args['section'], $args['std'] );\n\t\t\t$size  = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : '500px';\n\n\t\t\techo '<div style=\"max-width: ' . $size . ';\">';\n\n\t\t\t$editor_settings = array(\n\t\t\t\t'teeny'         => true,\n\t\t\t\t'textarea_name' => $args['section'] . '[' . $args['id'] . ']',\n\t\t\t\t'textarea_rows' => 10\n\t\t\t);\n\n\t\t\tif ( isset( $args['options'] ) && is_array( $args['options'] ) ) {\n\t\t\t\t$editor_settings = array_merge( $editor_settings, $args['options'] );\n\t\t\t}\n\n\t\t\twp_editor( $value, $args['section'] . '-' . $args['id'], $editor_settings );\n\n\t\t\techo '</div>';\n\n\t\t\techo $this->get_field_description( $args );\n\t\t}\n\n\t\t/**\n\t\t * Displays a file upload field for a settings field\n\t\t *\n\t\t * @param array $args settings field args\n\t\t */\n\t\tfunction callback_file( $args ) {\n\n\t\t\t$value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );\n\t\t\t$size  = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';\n\t\t\t$id    = $args['section'] . '[' . $args['id'] . ']';\n\t\t\t$label = isset( $args['options']['button_label'] ) ? $args['options']['button_label'] : __( 'Choose File' );\n\n\t\t\t$html = sprintf( '<input type=\"text\" class=\"%1$s-text wpsa-url\" id=\"%2$s[%3$s]\" name=\"%2$s[%3$s]\" value=\"%4$s\"/>', $size, $args['section'], $args['id'], $value );\n\t\t\t$html .= '<input type=\"button\" class=\"button wpsa-browse\" value=\"' . $label . '\" />';\n\t\t\t$html .= $this->get_field_description( $args );\n\n\t\t\techo $html;\n\t\t}\n\n\t\t/**\n\t\t * Displays a password field for a settings field\n\t\t *\n\t\t * @param array $args settings field args\n\t\t */\n\t\tfunction callback_password( $args ) {\n\n\t\t\t$value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );\n\t\t\t$size  = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';\n\n\t\t\t$html = sprintf( '<input type=\"password\" class=\"%1$s-text\" id=\"%2$s[%3$s]\" name=\"%2$s[%3$s]\" value=\"%4$s\"/>', $size, $args['section'], $args['id'], $value );\n\t\t\t$html .= $this->get_field_description( $args );\n\n\t\t\techo $html;\n\t\t}\n\n\t\t/**\n\t\t * Displays a color picker field for a settings field\n\t\t *\n\t\t * @param array $args settings field args\n\t\t */\n\t\tfunction callback_color( $args ) {\n\n\t\t\t$value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );\n\t\t\t$size  = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';\n\n\t\t\t$html = sprintf( '<input type=\"text\" class=\"%1$s-text wp-color-picker-field\" id=\"%2$s[%3$s]\" name=\"%2$s[%3$s]\" value=\"%4$s\" data-default-color=\"%5$s\" />', $size, $args['section'], $args['id'], $value, $args['std'] );\n\t\t\t$html .= $this->get_field_description( $args );\n\n\t\t\techo $html;\n\t\t}\n\n\n\t\t/**\n\t\t * Displays a select box for creating the pages select box\n\t\t *\n\t\t * @param array $args settings field args\n\t\t */\n\t\tfunction callback_pages( $args ) {\n\n\t\t\t$dropdown_args = array(\n\t\t\t\t'selected' => esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) ),\n\t\t\t\t'name'     => $args['section'] . '[' . $args['id'] . ']',\n\t\t\t\t'id'       => $args['section'] . '[' . $args['id'] . ']',\n\t\t\t\t'echo'     => 0\n\t\t\t);\n\t\t\t$html          = wp_dropdown_pages( $dropdown_args );\n\t\t\techo $html;\n\t\t}\n\n\t\t/**\n\t\t * Sanitize callback for Settings API\n\t\t *\n\t\t * @return mixed\n\t\t */\n\t\tfunction sanitize_options( $options ) {\n\n\t\t\tif ( ! $options ) {\n\t\t\t\treturn $options;\n\t\t\t}\n\n\t\t\tforeach ( $options as $option_slug => $option_value ) {\n\t\t\t\t$sanitize_callback = $this->get_sanitize_callback( $option_slug );\n\n\t\t\t\t// If callback is set, call it\n\t\t\t\tif ( $sanitize_callback ) {\n\t\t\t\t\t$options[ $option_slug ] = call_user_func( $sanitize_callback, $option_value );\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn $options;\n\t\t}\n\n\t\t/**\n\t\t * Get sanitization callback for given option slug\n\t\t *\n\t\t * @param string $slug option slug\n\t\t *\n\t\t * @return mixed string or bool false\n\t\t */\n\t\tfunction get_sanitize_callback( $slug = '' ) {\n\t\t\tif ( empty( $slug ) ) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\t// Iterate over registered fields and see if we can find proper callback\n\t\t\tforeach ( $this->settings_fields as $section => $options ) {\n\t\t\t\tforeach ( $options as $option ) {\n\t\t\t\t\tif ( $option['name'] != $slug ) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Return the callback name\n\t\t\t\t\treturn isset( $option['sanitize_callback'] ) && is_callable( $option['sanitize_callback'] ) ? $option['sanitize_callback'] : false;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn false;\n\t\t}\n\n\t\t/**\n\t\t * Get the value of a settings field\n\t\t *\n\t\t * @param  string $option  settings field name\n\t\t * @param  string $section the section name this field belongs to\n\t\t * @param  string $default default text if it's not found\n\t\t *\n\t\t * @return string\n\t\t */\n\t\tfunction get_option( $option, $section, $default = '' ) {\n\n\t\t\t$options = get_option( $section );\n\n\t\t\tif ( isset( $options[ $option ] ) ) {\n\t\t\t\treturn $options[ $option ];\n\t\t\t}\n\n\t\t\treturn $default;\n\t\t}\n\n\t\t/**\n\t\t * Show navigations as tab\n\t\t *\n\t\t * Shows all the settings section labels as tab\n\t\t */\n\t\tfunction show_navigation() {\n\t\t\t$html = '<h2 class=\"nav-tab-wrapper\">';\n\n\t\t\t$count = count( $this->settings_sections );\n\n\t\t\t// don't show the navigation if only one section exists\n\t\t\tif ( $count === 1 ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tforeach ( $this->settings_sections as $tab ) {\n\t\t\t\t$html .= sprintf( '<a href=\"#%1$s\" class=\"nav-tab\" id=\"%1$s-tab\">%2$s</a>', $tab['id'], $tab['title'] );\n\t\t\t}\n\n\t\t\t$html .= '</h2>';\n\n\t\t\techo $html;\n\t\t}\n\n\t\t/**\n\t\t * Show the section settings forms\n\t\t *\n\t\t * This function displays every sections in a different form\n\t\t */\n\t\tfunction show_forms() {\n\t\t\t?>\n\t\t\t<div class=\"metabox-holder\">\n\t\t\t\t<?php foreach ( $this->settings_sections as $form ) { ?>\n\t\t\t\t\t<div id=\"<?php echo $form['id']; ?>\" class=\"group\" style=\"display: none;\">\n\t\t\t\t\t\t<form method=\"post\" action=\"options.php\">\n\t\t\t\t\t\t\t<?php\n\t\t\t\t\t\t\tdo_action( 'wsa_form_top_' . $form['id'], $form );\n\t\t\t\t\t\t\tsettings_fields( $form['id'] );\n\t\t\t\t\t\t\tdo_settings_sections( $form['id'] );\n\t\t\t\t\t\t\tdo_action( 'wsa_form_bottom_' . $form['id'], $form );\n\t\t\t\t\t\t\tif ( isset( $this->settings_fields[ $form['id'] ] ) ) :\n\t\t\t\t\t\t\t\t?>\n\t\t\t\t\t\t\t\t<div style=\"padding-left: 10px\">\n\t\t\t\t\t\t\t\t\t<?php submit_button(); ?>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t<?php endif; ?>\n\t\t\t\t\t\t</form>\n\t\t\t\t\t</div>\n\t\t\t\t<?php } ?>\n\t\t\t</div>\n\t\t\t<?php\n\t\t\t$this->script();\n\t\t}\n\n\t\t/**\n\t\t * Tabbable JavaScript codes & Initiate Color Picker\n\t\t *\n\t\t * This code uses localstorage for displaying active tabs\n\t\t */\n\t\tfunction script() {\n\t\t\t?>\n\t\t\t<script>\n                jQuery(document).ready(function ($) {\n                    //Initiate Color Picker\n                    $('.wp-color-picker-field').wpColorPicker();\n\n                    // Switches option sections\n                    $('.group').hide();\n                    var activetab = '';\n                    if (typeof(localStorage) != 'undefined') {\n                        activetab = localStorage.getItem(\"activetab\");\n                    }\n\n                    //if url has section id as hash then set it as active or override the current local storage value\n                    if (window.location.hash) {\n                        activetab = window.location.hash;\n                        if (typeof(localStorage) != 'undefined') {\n                            localStorage.setItem(\"activetab\", activetab);\n                        }\n                    }\n\n                    if (activetab != '' && $(activetab).length) {\n                        $(activetab).fadeIn();\n                    } else {\n                        $('.group:first').fadeIn();\n                    }\n                    $('.group .collapsed').each(function () {\n                        $(this).find('input:checked').parent().parent().parent().nextAll().each(\n                            function () {\n                                if ($(this).hasClass('last')) {\n                                    $(this).removeClass('hidden');\n                                    return false;\n                                }\n                                $(this).filter('.hidden').removeClass('hidden');\n                            });\n                    });\n\n                    if (activetab != '' && $(activetab + '-tab').length) {\n                        $(activetab + '-tab').addClass('nav-tab-active');\n                    } else {\n                        $('.nav-tab-wrapper a:first').addClass('nav-tab-active');\n                    }\n                    $('.nav-tab-wrapper a').click(function (evt) {\n                        $('.nav-tab-wrapper a').removeClass('nav-tab-active');\n                        $(this).addClass('nav-tab-active').blur();\n                        var clicked_group = $(this).attr('href');\n                        if (typeof(localStorage) != 'undefined') {\n                            localStorage.setItem(\"activetab\", $(this).attr('href'));\n                        }\n                        $('.group').hide();\n                        $(clicked_group).fadeIn();\n                        evt.preventDefault();\n                    });\n\n                    $('.wpsa-browse').on('click', function (event) {\n                        event.preventDefault();\n\n                        var self = $(this);\n\n                        // Create the media frame.\n                        var file_frame = wp.media.frames.file_frame = wp.media({\n                            title: self.data('uploader_title'),\n                            button: {\n                                text: self.data('uploader_button_text'),\n                            },\n                            multiple: false\n                        });\n\n                        file_frame.on('select', function () {\n                            attachment = file_frame.state().get('selection').first().toJSON();\n                            self.prev('.wpsa-url').val(attachment.url).change();\n                        });\n\n                        // Finally, open the modal\n                        file_frame.open();\n                    });\n                });\n\t\t\t</script>\n\t\t\t<?php\n\t\t\t$this->_style_fix();\n\t\t}\n\n\t\tfunction _style_fix() {\n\t\t\tglobal $wp_version;\n\n\t\t\tif ( version_compare( $wp_version, '3.8', '<=' ) ) :\n\t\t\t\t?>\n\t\t\t\t<style type=\"text/css\">\n\t\t\t\t\t/** WordPress 3.8 Fix **/\n\t\t\t\t\t.form-table th {\n\t\t\t\t\t\tpadding: 20px 10px;\n\t\t\t\t\t}\n\n\t\t\t\t\t#wpbody-content .metabox-holder {\n\t\t\t\t\t\tpadding-top: 5px;\n\t\t\t\t\t}\n\t\t\t\t</style>\n\t\t\t<?php\n\t\t\tendif;\n\t\t}\n\t}\n\nendif;\n"
  },
  {
    "path": "license.txt",
    "content": "WPGatsby\n\nCopyright 2020 by the contributors\n\nThis plugin was originally started by Geoffrey Sechter and then this repo was transferred to Gatsby inc. after which the code was fully written from scratch and doesn't contain any of the original code.\n\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n  GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright © 2007 Free Software Foundation, Inc. <https://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The GNU General Public License is a free, copyleft license for\nsoftware and other kinds of works.\n\n  The licenses for most software and other practical works are designed\nto take away your freedom to share and change the works.  By contrast,\nthe GNU General Public License is intended to guarantee your freedom to\nshare and change all versions of a program--to make sure it remains free\nsoftware for all its users.  We, the Free Software Foundation, use the\nGNU General Public License for most of our software; it applies also to\nany other work released this way by its authors.  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthem if you wish), that you receive source code or can get it if you\nwant it, that you can change the software or use pieces of it in new\nfree programs, and that you know you can do these things.\n\n  To protect your rights, we need to prevent others from denying you\nthese rights or asking you to surrender the rights.  Therefore, you have\ncertain responsibilities if you distribute copies of the software, or if\nyou modify it: responsibilities to respect the freedom of others.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must pass on to the recipients the same\nfreedoms that you received.  You must make sure that they, too, receive\nor can get the source code.  And you must show them these terms so they\nknow their rights.\n\n  Developers that use the GNU GPL protect your rights with two steps:\n(1) assert copyright on the software, and (2) offer you this License\ngiving you legal permission to copy, distribute and/or modify it.\n\n  For the developers' and authors' protection, the GPL clearly explains\nthat there is no warranty for this free software.  For both users' and\nauthors' sake, the GPL requires that modified versions be marked as\nchanged, so that their problems will not be attributed erroneously to\nauthors of previous versions.\n\n  Some devices are designed to deny users access to install or run\nmodified versions of the software inside them, although the manufacturer\ncan do so.  This is fundamentally incompatible with the aim of\nprotecting users' freedom to change the software.  The systematic\npattern of such abuse occurs in the area of products for individuals to\nuse, which is precisely where it is most unacceptable.  Therefore, we\nhave designed this version of the GPL to prohibit the practice for those\nproducts.  If such problems arise substantially in other domains, we\nstand ready to extend this provision to those domains in future versions\nof the GPL, as needed to protect the freedom of users.\n\n  Finally, every program is threatened constantly by software patents.\nStates should not allow patents to restrict development and use of\nsoftware on general-purpose computers, but in those that do, we wish to\navoid the special danger that patents applied to a free program could\nmake it effectively proprietary.  To prevent this, the GPL assures that\npatents cannot be used to render the program non-free.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                       TERMS AND CONDITIONS\n\n  0. Definitions.\n\n  \"This License\" refers to version 3 of the GNU General Public License.\n\n  \"Copyright\" also means copyright-like laws that apply to other kinds of\nworks, such as semiconductor masks.\n\n  \"The Program\" refers to any copyrightable work licensed under this\nLicense.  Each licensee is addressed as \"you\".  \"Licensees\" and\n\"recipients\" may be individuals or organizations.\n\n  To \"modify\" a work means to copy from or adapt all or part of the work\nin a fashion requiring copyright permission, other than the making of an\nexact copy.  The resulting work is called a \"modified version\" of the\nearlier work or a work \"based on\" the earlier work.\n\n  A \"covered work\" means either the unmodified Program or a work based\non the Program.\n\n  To \"propagate\" a work means to do anything with it that, without\npermission, would make you directly or secondarily liable for\ninfringement under applicable copyright law, except executing it on a\ncomputer or modifying a private copy.  Propagation includes copying,\ndistribution (with or without modification), making available to the\npublic, and in some countries other activities as well.\n\n  To \"convey\" a work means any kind of propagation that enables other\nparties to make or receive copies.  Mere interaction with a user through\na computer network, with no transfer of a copy, is not conveying.\n\n  An interactive user interface displays \"Appropriate Legal Notices\"\nto the extent that it includes a convenient and prominently visible\nfeature that (1) displays an appropriate copyright notice, and (2)\ntells the user that there is no warranty for the work (except to the\nextent that warranties are provided), that licensees may convey the\nwork under this License, and how to view a copy of this License.  If\nthe interface presents a list of user commands or options, such as a\nmenu, a prominent item in the list meets this criterion.\n\n  1. Source Code.\n\n  The \"source code\" for a work means the preferred form of the work\nfor making modifications to it.  \"Object code\" means any non-source\nform of a work.\n\n  A \"Standard Interface\" means an interface that either is an official\nstandard defined by a recognized standards body, or, in the case of\ninterfaces specified for a particular programming language, one that\nis widely used among developers working in that language.\n\n  The \"System Libraries\" of an executable work include anything, other\nthan the work as a whole, that (a) is included in the normal form of\npackaging a Major Component, but which is not part of that Major\nComponent, and (b) serves only to enable use of the work with that\nMajor Component, or to implement a Standard Interface for which an\nimplementation is available to the public in source code form.  A\n\"Major Component\", in this context, means a major essential component\n(kernel, window system, and so on) of the specific operating system\n(if any) on which the executable work runs, or a compiler used to\nproduce the work, or an object code interpreter used to run it.\n\n  The \"Corresponding Source\" for a work in object code form means all\nthe source code needed to generate, install, and (for an executable\nwork) run the object code and to modify the work, including scripts to\ncontrol those activities.  However, it does not include the work's\nSystem Libraries, or general-purpose tools or generally available free\nprograms which are used unmodified in performing those activities but\nwhich are not part of the work.  For example, Corresponding Source\nincludes interface definition files associated with source files for\nthe work, and the source code for shared libraries and dynamically\nlinked subprograms that the work is specifically designed to require,\nsuch as by intimate data communication or control flow between those\nsubprograms and other parts of the work.\n\n  The Corresponding Source need not include anything that users\ncan regenerate automatically from other parts of the Corresponding\nSource.\n\n  The Corresponding Source for a work in source code form is that\nsame work.\n\n  2. Basic Permissions.\n\n  All rights granted under this License are granted for the term of\ncopyright on the Program, and are irrevocable provided the stated\nconditions are met.  This License explicitly affirms your unlimited\npermission to run the unmodified Program.  The output from running a\ncovered work is covered by this License only if the output, given its\ncontent, constitutes a covered work.  This License acknowledges your\nrights of fair use or other equivalent, as provided by copyright law.\n\n  You may make, run and propagate covered works that you do not\nconvey, without conditions so long as your license otherwise remains\nin force.  You may convey covered works to others for the sole purpose\nof having them make modifications exclusively for you, or provide you\nwith facilities for running those works, provided that you comply with\nthe terms of this License in conveying all material for which you do\nnot control copyright.  Those thus making or running the covered works\nfor you must do so exclusively on your behalf, under your direction\nand control, on terms that prohibit them from making any copies of\nyour copyrighted material outside their relationship with you.\n\n  Conveying under any other circumstances is permitted solely under\nthe conditions stated below.  Sublicensing is not allowed; section 10\nmakes it unnecessary.\n\n  3. Protecting Users' Legal Rights From Anti-Circumvention Law.\n\n  No covered work shall be deemed part of an effective technological\nmeasure under any applicable law fulfilling obligations under article\n11 of the WIPO copyright treaty adopted on 20 December 1996, or\nsimilar laws prohibiting or restricting circumvention of such\nmeasures.\n\n  When you convey a covered work, you waive any legal power to forbid\ncircumvention of technological measures to the extent such circumvention\nis effected by exercising rights under this License with respect to\nthe covered work, and you disclaim any intention to limit operation or\nmodification of the work as a means of enforcing, against the work's\nusers, your or third parties' legal rights to forbid circumvention of\ntechnological measures.\n\n  4. Conveying Verbatim Copies.\n\n  You may convey verbatim copies of the Program's source code as you\nreceive it, in any medium, provided that you conspicuously and\nappropriately publish on each copy an appropriate copyright notice;\nkeep intact all notices stating that this License and any\nnon-permissive terms added in accord with section 7 apply to the code;\nkeep intact all notices of the absence of any warranty; and give all\nrecipients a copy of this License along with the Program.\n\n  You may charge any price or no price for each copy that you convey,\nand you may offer support or warranty protection for a fee.\n\n  5. Conveying Modified Source Versions.\n\n  You may convey a work based on the Program, or the modifications to\nproduce it from the Program, in the form of source code under the\nterms of section 4, provided that you also meet all of these conditions:\n\n    a) The work must carry prominent notices stating that you modified\n    it, and giving a relevant date.\n\n    b) The work must carry prominent notices stating that it is\n    released under this License and any conditions added under section\n    7.  This requirement modifies the requirement in section 4 to\n    \"keep intact all notices\".\n\n    c) You must license the entire work, as a whole, under this\n    License to anyone who comes into possession of a copy.  This\n    License will therefore apply, along with any applicable section 7\n    additional terms, to the whole of the work, and all its parts,\n    regardless of how they are packaged.  This License gives no\n    permission to license the work in any other way, but it does not\n    invalidate such permission if you have separately received it.\n\n    d) If the work has interactive user interfaces, each must display\n    Appropriate Legal Notices; however, if the Program has interactive\n    interfaces that do not display Appropriate Legal Notices, your\n    work need not make them do so.\n\n  A compilation of a covered work with other separate and independent\nworks, which are not by their nature extensions of the covered work,\nand which are not combined with it such as to form a larger program,\nin or on a volume of a storage or distribution medium, is called an\n\"aggregate\" if the compilation and its resulting copyright are not\nused to limit the access or legal rights of the compilation's users\nbeyond what the individual works permit.  Inclusion of a covered work\nin an aggregate does not cause this License to apply to the other\nparts of the aggregate.\n\n  6. Conveying Non-Source Forms.\n\n  You may convey a covered work in object code form under the terms\nof sections 4 and 5, provided that you also convey the\nmachine-readable Corresponding Source under the terms of this License,\nin one of these ways:\n\n    a) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by the\n    Corresponding Source fixed on a durable physical medium\n    customarily used for software interchange.\n\n    b) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by a\n    written offer, valid for at least three years and valid for as\n    long as you offer spare parts or customer support for that product\n    model, to give anyone who possesses the object code either (1) a\n    copy of the Corresponding Source for all the software in the\n    product that is covered by this License, on a durable physical\n    medium customarily used for software interchange, for a price no\n    more than your reasonable cost of physically performing this\n    conveying of source, or (2) access to copy the\n    Corresponding Source from a network server at no charge.\n\n    c) Convey individual copies of the object code with a copy of the\n    written offer to provide the Corresponding Source.  This\n    alternative is allowed only occasionally and noncommercially, and\n    only if you received the object code with such an offer, in accord\n    with subsection 6b.\n\n    d) Convey the object code by offering access from a designated\n    place (gratis or for a charge), and offer equivalent access to the\n    Corresponding Source in the same way through the same place at no\n    further charge.  You need not require recipients to copy the\n    Corresponding Source along with the object code.  If the place to\n    copy the object code is a network server, the Corresponding Source\n    may be on a different server (operated by you or a third party)\n    that supports equivalent copying facilities, provided you maintain\n    clear directions next to the object code saying where to find the\n    Corresponding Source.  Regardless of what server hosts the\n    Corresponding Source, you remain obligated to ensure that it is\n    available for as long as needed to satisfy these requirements.\n\n    e) Convey the object code using peer-to-peer transmission, provided\n    you inform other peers where the object code and Corresponding\n    Source of the work are being offered to the general public at no\n    charge under subsection 6d.\n\n  A separable portion of the object code, whose source code is excluded\nfrom the Corresponding Source as a System Library, need not be\nincluded in conveying the object code work.\n\n  A \"User Product\" is either (1) a \"consumer product\", which means any\ntangible personal property which is normally used for personal, family,\nor household purposes, or (2) anything designed or sold for incorporation\ninto a dwelling.  In determining whether a product is a consumer product,\ndoubtful cases shall be resolved in favor of coverage.  For a particular\nproduct received by a particular user, \"normally used\" refers to a\ntypical or common use of that class of product, regardless of the status\nof the particular user or of the way in which the particular user\nactually uses, or expects or is expected to use, the product.  A product\nis a consumer product regardless of whether the product has substantial\ncommercial, industrial or non-consumer uses, unless such uses represent\nthe only significant mode of use of the product.\n\n  \"Installation Information\" for a User Product means any methods,\nprocedures, authorization keys, or other information required to install\nand execute modified versions of a covered work in that User Product from\na modified version of its Corresponding Source.  The information must\nsuffice to ensure that the continued functioning of the modified object\ncode is in no case prevented or interfered with solely because\nmodification has been made.\n\n  If you convey an object code work under this section in, or with, or\nspecifically for use in, a User Product, and the conveying occurs as\npart of a transaction in which the right of possession and use of the\nUser Product is transferred to the recipient in perpetuity or for a\nfixed term (regardless of how the transaction is characterized), the\nCorresponding Source conveyed under this section must be accompanied\nby the Installation Information.  But this requirement does not apply\nif neither you nor any third party retains the ability to install\nmodified object code on the User Product (for example, the work has\nbeen installed in ROM).\n\n  The requirement to provide Installation Information does not include a\nrequirement to continue to provide support service, warranty, or updates\nfor a work that has been modified or installed by the recipient, or for\nthe User Product in which it has been modified or installed.  Access to a\nnetwork may be denied when the modification itself materially and\nadversely affects the operation of the network or violates the rules and\nprotocols for communication across the network.\n\n  Corresponding Source conveyed, and Installation Information provided,\nin accord with this section must be in a format that is publicly\ndocumented (and with an implementation available to the public in\nsource code form), and must require no special password or key for\nunpacking, reading or copying.\n\n  7. Additional Terms.\n\n  \"Additional permissions\" are terms that supplement the terms of this\nLicense by making exceptions from one or more of its conditions.\nAdditional permissions that are applicable to the entire Program shall\nbe treated as though they were included in this License, to the extent\nthat they are valid under applicable law.  If additional permissions\napply only to part of the Program, that part may be used separately\nunder those permissions, but the entire Program remains governed by\nthis License without regard to the additional permissions.\n\n  When you convey a copy of a covered work, you may at your option\nremove any additional permissions from that copy, or from any part of\nit.  (Additional permissions may be written to require their own\nremoval in certain cases when you modify the work.)  You may place\nadditional permissions on material, added by you to a covered work,\nfor which you have or can give appropriate copyright permission.\n\n  Notwithstanding any other provision of this License, for material you\nadd to a covered work, you may (if authorized by the copyright holders of\nthat material) supplement the terms of this License with terms:\n\n    a) Disclaiming warranty or limiting liability differently from the\n    terms of sections 15 and 16 of this License; or\n\n    b) Requiring preservation of specified reasonable legal notices or\n    author attributions in that material or in the Appropriate Legal\n    Notices displayed by works containing it; or\n\n    c) Prohibiting misrepresentation of the origin of that material, or\n    requiring that modified versions of such material be marked in\n    reasonable ways as different from the original version; or\n\n    d) Limiting the use for publicity purposes of names of licensors or\n    authors of the material; or\n\n    e) Declining to grant rights under trademark law for use of some\n    trade names, trademarks, or service marks; or\n\n    f) Requiring indemnification of licensors and authors of that\n    material by anyone who conveys the material (or modified versions of\n    it) with contractual assumptions of liability to the recipient, for\n    any liability that these contractual assumptions directly impose on\n    those licensors and authors.\n\n  All other non-permissive additional terms are considered \"further\nrestrictions\" within the meaning of section 10.  If the Program as you\nreceived it, or any part of it, contains a notice stating that it is\ngoverned by this License along with a term that is a further\nrestriction, you may remove that term.  If a license document contains\na further restriction but permits relicensing or conveying under this\nLicense, you may add to a covered work material governed by the terms\nof that license document, provided that the further restriction does\nnot survive such relicensing or conveying.\n\n  If you add terms to a covered work in accord with this section, you\nmust place, in the relevant source files, a statement of the\nadditional terms that apply to those files, or a notice indicating\nwhere to find the applicable terms.\n\n  Additional terms, permissive or non-permissive, may be stated in the\nform of a separately written license, or stated as exceptions;\nthe above requirements apply either way.\n\n  8. Termination.\n\n  You may not propagate or modify a covered work except as expressly\nprovided under this License.  Any attempt otherwise to propagate or\nmodify it is void, and will automatically terminate your rights under\nthis License (including any patent licenses granted under the third\nparagraph of section 11).\n\n  However, if you cease all violation of this License, then your\nlicense from a particular copyright holder is reinstated (a)\nprovisionally, unless and until the copyright holder explicitly and\nfinally terminates your license, and (b) permanently, if the copyright\nholder fails to notify you of the violation by some reasonable means\nprior to 60 days after the cessation.\n\n  Moreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from that\ncopyright holder, and you cure the violation prior to 30 days after\nyour receipt of the notice.\n\n  Termination of your rights under this section does not terminate the\nlicenses of parties who have received copies or rights from you under\nthis License.  If your rights have been terminated and not permanently\nreinstated, you do not qualify to receive new licenses for the same\nmaterial under section 10.\n\n  9. Acceptance Not Required for Having Copies.\n\n  You are not required to accept this License in order to receive or\nrun a copy of the Program.  Ancillary propagation of a covered work\noccurring solely as a consequence of using peer-to-peer transmission\nto receive a copy likewise does not require acceptance.  However,\nnothing other than this License grants you permission to propagate or\nmodify any covered work.  These actions infringe copyright if you do\nnot accept this License.  Therefore, by modifying or propagating a\ncovered work, you indicate your acceptance of this License to do so.\n\n  10. Automatic Licensing of Downstream Recipients.\n\n  Each time you convey a covered work, the recipient automatically\nreceives a license from the original licensors, to run, modify and\npropagate that work, subject to this License.  You are not responsible\nfor enforcing compliance by third parties with this License.\n\n  An \"entity transaction\" is a transaction transferring control of an\norganization, or substantially all assets of one, or subdividing an\norganization, or merging organizations.  If propagation of a covered\nwork results from an entity transaction, each party to that\ntransaction who receives a copy of the work also receives whatever\nlicenses to the work the party's predecessor in interest had or could\ngive under the previous paragraph, plus a right to possession of the\nCorresponding Source of the work from the predecessor in interest, if\nthe predecessor has it or can get it with reasonable efforts.\n\n  You may not impose any further restrictions on the exercise of the\nrights granted or affirmed under this License.  For example, you may\nnot impose a license fee, royalty, or other charge for exercise of\nrights granted under this License, and you may not initiate litigation\n(including a cross-claim or counterclaim in a lawsuit) alleging that\nany patent claim is infringed by making, using, selling, offering for\nsale, or importing the Program or any portion of it.\n\n  11. Patents.\n\n  A \"contributor\" is a copyright holder who authorizes use under this\nLicense of the Program or a work on which the Program is based.  The\nwork thus licensed is called the contributor's \"contributor version\".\n\n  A contributor's \"essential patent claims\" are all patent claims\nowned or controlled by the contributor, whether already acquired or\nhereafter acquired, that would be infringed by some manner, permitted\nby this License, of making, using, or selling its contributor version,\nbut do not include claims that would be infringed only as a\nconsequence of further modification of the contributor version.  For\npurposes of this definition, \"control\" includes the right to grant\npatent sublicenses in a manner consistent with the requirements of\nthis License.\n\n  Each contributor grants you a non-exclusive, worldwide, royalty-free\npatent license under the contributor's essential patent claims, to\nmake, use, sell, offer for sale, import and otherwise run, modify and\npropagate the contents of its contributor version.\n\n  In the following three paragraphs, a \"patent license\" is any express\nagreement or commitment, however denominated, not to enforce a patent\n(such as an express permission to practice a patent or covenant not to\nsue for patent infringement).  To \"grant\" such a patent license to a\nparty means to make such an agreement or commitment not to enforce a\npatent against the party.\n\n  If you convey a covered work, knowingly relying on a patent license,\nand the Corresponding Source of the work is not available for anyone\nto copy, free of charge and under the terms of this License, through a\npublicly available network server or other readily accessible means,\nthen you must either (1) cause the Corresponding Source to be so\navailable, or (2) arrange to deprive yourself of the benefit of the\npatent license for this particular work, or (3) arrange, in a manner\nconsistent with the requirements of this License, to extend the patent\nlicense to downstream recipients.  \"Knowingly relying\" means you have\nactual knowledge that, but for the patent license, your conveying the\ncovered work in a country, or your recipient's use of the covered work\nin a country, would infringe one or more identifiable patents in that\ncountry that you have reason to believe are valid.\n\n  If, pursuant to or in connection with a single transaction or\narrangement, you convey, or propagate by procuring conveyance of, a\ncovered work, and grant a patent license to some of the parties\nreceiving the covered work authorizing them to use, propagate, modify\nor convey a specific copy of the covered work, then the patent license\nyou grant is automatically extended to all recipients of the covered\nwork and works based on it.\n\n  A patent license is \"discriminatory\" if it does not include within\nthe scope of its coverage, prohibits the exercise of, or is\nconditioned on the non-exercise of one or more of the rights that are\nspecifically granted under this License.  You may not convey a covered\nwork if you are a party to an arrangement with a third party that is\nin the business of distributing software, under which you make payment\nto the third party based on the extent of your activity of conveying\nthe work, and under which the third party grants, to any of the\nparties who would receive the covered work from you, a discriminatory\npatent license (a) in connection with copies of the covered work\nconveyed by you (or copies made from those copies), or (b) primarily\nfor and in connection with specific products or compilations that\ncontain the covered work, unless you entered into that arrangement,\nor that patent license was granted, prior to 28 March 2007.\n\n  Nothing in this License shall be construed as excluding or limiting\nany implied license or other defenses to infringement that may\notherwise be available to you under applicable patent law.\n\n  12. No Surrender of Others' Freedom.\n\n  If conditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot convey a\ncovered work so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you may\nnot convey it at all.  For example, if you agree to terms that obligate you\nto collect a royalty for further conveying from those to whom you convey\nthe Program, the only way you could satisfy both those terms and this\nLicense would be to refrain entirely from conveying the Program.\n\n  13. Use with the GNU Affero General Public License.\n\n  Notwithstanding any other provision of this License, you have\npermission to link or combine any covered work with a work licensed\nunder version 3 of the GNU Affero General Public License into a single\ncombined work, and to convey the resulting work.  The terms of this\nLicense will continue to apply to the part which is the covered work,\nbut the special requirements of the GNU Affero General Public License,\nsection 13, concerning interaction through a network will apply to the\ncombination as such.\n\n  14. Revised Versions of this License.\n\n  The Free Software Foundation may publish revised and/or new versions of\nthe GNU General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\n  Each version is given a distinguishing version number.  If the\nProgram specifies that a certain numbered version of the GNU General\nPublic License \"or any later version\" applies to it, you have the\noption of following the terms and conditions either of that numbered\nversion or of any later version published by the Free Software\nFoundation.  If the Program does not specify a version number of the\nGNU General Public License, you may choose any version ever published\nby the Free Software Foundation.\n\n  If the Program specifies that a proxy can decide which future\nversions of the GNU General Public License can be used, that proxy's\npublic statement of acceptance of a version permanently authorizes you\nto choose that version for the Program.\n\n  Later license versions may give you additional or different\npermissions.  However, no additional obligations are imposed on any\nauthor or copyright holder as a result of your choosing to follow a\nlater version.\n\n  15. Disclaimer of Warranty.\n\n  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\nAPPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\nOF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\nIS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\nALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. Limitation of Liability.\n\n  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\nTHE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\nGENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\nUSE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\nDATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\nPARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\nEVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\nSUCH DAMAGES.\n\n  17. Interpretation of Sections 15 and 16.\n\n  If the disclaimer of warranty and limitation of liability provided\nabove cannot be given local legal effect according to their terms,\nreviewing courts shall apply local law that most closely approximates\nan absolute waiver of all civil liability in connection with the\nProgram, unless a warranty or assumption of liability accompanies a\ncopy of the Program in return for a fee.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nstate the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright © <year>  <name of author>\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see <https://www.gnu.org/licenses/>.\n\nAlso add information on how to contact you by electronic and paper mail.\n\n  If the program does terminal interaction, make it output a short\nnotice like this when it starts in an interactive mode:\n\n    <program>  Copyright © <year>  <name of author>\n    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, your program's commands\nmight be different; for a GUI interface, you would use an \"about box\".\n\n  You should also get your employer (if you work as a programmer) or school,\nif any, to sign a \"copyright disclaimer\" for the program, if necessary.\nFor more information on this, and how to apply and follow the GNU GPL, see\n<https://www.gnu.org/licenses/>.\n\n  The GNU General Public License does not permit incorporating your program\ninto proprietary programs.  If your program is a subroutine library, you\nmay consider it more useful to permit linking proprietary applications with\nthe library.  If this is what you want to do, use the GNU Lesser General\nPublic License instead of this License.  But first, please read\n<https://www.gnu.org/philosophy/why-not-lgpl.html>."
  },
  {
    "path": "readme.txt",
    "content": "=== WPGatsby ===\nContributors: gatsbyinc, jasonbahl, tylerbarnes1\nTags: Gatsby, GatsbyJS, JavaScript, JAMStack, Static Site generator, GraphQL, Headless WordPress, Decoupled WordPress\nRequires at least: 5.4.2\nTested up to: 5.9\nRequires PHP: 7.3\nStable tag: 2.3.3\nLicense: GPLv3\nLicense URI: https://www.gnu.org/licenses/gpl-3.0.html\n\n<div align=\"center\" style=\"margin-bottom: 20px;\">\n<img src=\"https://raw.githubusercontent.com/gatsbyjs/gatsby/master/packages/gatsby-source-wordpress/docs/assets/gatsby-wapuus.png\" alt=\"Wapuu hugging a ball with the Gatsby logo on it\" />\n</div>\n\n<p align=\"center\">\n  <a href=\"https://github.com/gatsbyjs/wp-gatsby/blob/master/license.txt\">\n    <img src=\"https://img.shields.io/badge/license-GPLv3-blue.svg\" alt=\"Gatsby and gatsby-source-wordpress are released under the MIT license.\" />\n  </a>\n  <a href=\"https://twitter.com/intent/follow?screen_name=gatsbyjs\">\n    <img src=\"https://img.shields.io/twitter/follow/gatsbyjs.svg?label=Follow%20@gatsbyjs\" alt=\"Follow @gatsbyjs\" />\n  </a>\n</p>\n\nWPGatsby is a free open-source WordPress plugin that optimizes your WordPress site to work as a data source for [Gatsby](https://www.gatsbyjs.com/docs/how-to/sourcing-data/sourcing-from-wordpress).\n\nThis plugin must be used in combination with the npm package [`gatsby-source-wordpress@^4.0.0`](https://www.npmjs.com/package/gatsby-source-wordpress).\n\n## Install and Activation\n\nWPGatsby is available on the WordPress.org repository and can be installed from your WordPress dashboard, or by using any other plugin installation method you prefer, such as installing with Composer from wpackagist.org.\n\n## Plugin Overview\n\nThis plugin has 2 primary responsibilities:\n\n-   [Monitor Activity in WordPress to keep Gatsby in sync with WP](https://github.com/gatsbyjs/wp-gatsby/blob/master/docs/action-monitor.md)\n-   [Configure WordPress Previews to work with Gatsby](https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-wordpress/docs/tutorials/configuring-wp-gatsby.md#setting-up-preview)\n\nAdditionally, WPGatsby has a settings page to connect your WordPress site with your Gatsby site:\n\n-   [WPGatsby Settings](https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-wordpress/docs/tutorials/configuring-wp-gatsby.md)\n"
  },
  {
    "path": "src/ActionMonitor/ActionMonitor.php",
    "content": "<?php\n\nnamespace WPGatsby\\ActionMonitor;\n\nuse WP_Post;\nuse WPGatsby\\Admin\\Settings;\n\n/**\n * This class registers and controls a post type which can be used to\n * monitor WP events like post save or delete in order to invalidate\n * Gatsby's cached nodes\n */\nclass ActionMonitor {\n\n\t/**\n\t * Whether a build hook should be dispatched. Default false.\n\t *\n\t * @var bool\n\t */\n\tprotected $should_dispatch = false;\n\n\t/**\n\t * An array of posts ID's for posts that have been updated\n\t * in this ActionMonitor instantiation\n\t *\n\t * @var array\n\t */\n\tprotected $updated_post_ids = [];\n\n\t/**\n\t * Whether WPGraphQL Debug Mode is active\n\t *\n\t * @var bool Whether GraphQL Debug Mode is active\n\t */\n\tprotected $wpgraphql_debug_mode = false;\n\n\t/**\n\t * @var mixed|null|WP_Post The post object before update\n\t */\n\tpublic $post_object_before_update = null;\n\n\t/**\n\t * Holds the classes for each action monitor\n\t *\n\t * @var array\n\t */\n\tprotected $action_monitors;\n\n\t/**\n\t * Set up the Action monitor when the class is initialized\n\t */\n\tpublic function __construct() {\n\n\t\t// Determine if WPGraphQL is in debug mode\n\t\t$this->wpgraphql_debug_mode = \n\t\t\tclass_exists( 'WPGraphQL' ) && method_exists( 'WPGraphQL', 'debug' ) \n\t\t\t\t? \\WPGraphQL::debug()\n\t\t\t\t: false;\n\n\t\t// Initialize action monitors\n\t\tadd_action( 'wp_loaded', [ $this, 'init_action_monitors' ], 11 );\n\n\t\t// Register the GraphQL Fields Gatsby Source WordPress needs to interact with the Action Monitor\n\t\tadd_action( 'graphql_register_types', [ $this, 'register_graphql_fields' ] );\n\n\t\t// Register post type and taxonomies to track CRUD events in WordPress\n\t\tadd_action( 'init', [ $this, 'init_post_type_and_taxonomies' ] );\n\t\tadd_filter( 'manage_action_monitor_posts_columns', [ $this, 'add_modified_column' ], 10 );\n\t\tadd_action(\n\t\t\t'manage_action_monitor_posts_custom_column',\n\t\t\t[\n\t\t\t\t$this,\n\t\t\t\t'render_modified_column',\n\t\t\t],\n\t\t\t10,\n\t\t\t2\n\t\t);\n\n\t\t// Trigger webhook dispatch\n\t\tadd_action( 'shutdown', [ $this, 'trigger_dispatch' ] );\n\n\t\t// allow any role to use Gatsby Preview\n\t\tadd_action( 'admin_init', [ $this, 'action_monitor_add_role_caps' ], 999 );\n\t}\n\n\t/**\n\t * For Action Monitor, all of these roles need to be able to view and edit private action monitor posts so that Preview works for all roles.\n\t */\n\tpublic function action_monitor_add_role_caps() {\n\t\t$doing_graphql_request\n\t\t\t\t\t= defined( 'GRAPHQL_REQUEST' ) && true === GRAPHQL_REQUEST;\n\n\t\tif ( $doing_graphql_request ) {\n\t\t\t// we only need to add roles one time. checking capabilities repeatedly isn't needed, just when the user is in the admin area is fine.\n\t\t\treturn;\n\t\t}\n\n\t\t$roles = apply_filters(\n\t\t\t'gatsby_private_action_monitor_roles',\n\t\t\t[\n\t\t\t\t'editor',\n\t\t\t\t'administrator',\n\t\t\t\t'contributor',\n\t\t\t\t'author'\n\t\t\t]\n\t\t);\n\n\t\tforeach( $roles as $the_role ) {\n\t\t\t$role = get_role($the_role);\n\n\t\t\tif ( ! $role->has_cap( 'read_private_action_monitor_posts' ) ) {\n\t\t\t\t$role->add_cap( 'read_private_action_monitor_posts' );\n\t\t\t}\n\t\t\t\n\t\t\tif ( ! $role->has_cap( 'edit_others_action_monitor_posts' ) ) {\n\t\t\t\t$role->add_cap( 'edit_others_action_monitor_posts' );\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Get the post types that are tracked by WPGatsby.\n\t *\n\t * @return array|mixed|void\n\t */\n\tpublic function get_tracked_post_types() {\n\t\t$public_post_types = get_post_types(\n\t\t\t[\n\t\t\t\t'show_in_graphql' => true,\n\t\t\t\t'public'          => true,\n\t\t\t]\n\t\t);\n\n\t\t$publicly_queryable_post_types = get_post_types(\n\t\t\t[\n\t\t\t\t'show_in_graphql'    => true,\n\t\t\t\t'public'             => false,\n\t\t\t\t'publicly_queryable' => true,\n\t\t\t]\n\t\t);\n\n\t\t$excludes = [\n\t\t\t'action_monitor' => 'action_monitor',\n\t\t];\n\n\t\t$tracked_post_types = array_diff(\n\t\t\tarray_merge( $public_post_types, $publicly_queryable_post_types ),\n\t\t\t$excludes\n\t\t);\n\n\t\t$tracked_post_types = apply_filters(\n\t\t\t'gatsby_action_monitor_tracked_post_types',\n\t\t\t$tracked_post_types\n\t\t);\n\n\t\treturn ! empty( $tracked_post_types ) && is_array( $tracked_post_types ) ? $tracked_post_types : [];\n\t}\n\n\t/**\n\t * Get the taxonomies that are tracked by WPGatsby\n\t *\n\t * @return array|mixed|void\n\t */\n\tpublic function get_tracked_taxonomies() {\n\t\t$tracked_taxonomies = apply_filters(\n\t\t\t'gatsby_action_monitor_tracked_taxonomies',\n\t\t\tget_taxonomies(\n\t\t\t\t[\n\t\t\t\t\t'show_in_graphql' => true,\n\t\t\t\t\t'public'          => true,\n\t\t\t\t]\n\t\t\t)\n\t\t);\n\n\t\treturn ! empty( $tracked_taxonomies ) && is_array( $tracked_taxonomies ) ? $tracked_taxonomies : [];\n\t}\n\n\t/**\n\t * Register Action monitor post type and associated taxonomies.\n\t *\n\t * The post type is used to store records of CRUD actions that have occurred in WordPress so\n\t * that Gatsby can keep in Sync with changes in WordPress.\n\t *\n\t * The taxonomies are registered to store data related to the actions, but make it more\n\t * efficient to filter actions by the values as Tax Queries are much more efficient than Meta\n\t * Queries.\n\t */\n\tpublic function init_post_type_and_taxonomies() {\n\n\t\t/**\n\t\t * Post Type: Action Monitor.\n\t\t */\n\t\t$post_type_labels = [\n\t\t\t'name'          => __( 'Action Monitor', 'WPGatsby' ),\n\t\t\t'singular_name' => __( 'Action Monitor', 'WPGatsby' ),\n\t\t];\n\n\t\t// Registers the post_type that logs actions for Gatsby\n\t\tregister_post_type(\n\t\t\t'action_monitor',\n\t\t\t[\n\t\t\t\t'label'                 => __( 'Action Monitor', 'WPGatsby' ),\n\t\t\t\t'labels'                => $post_type_labels,\n\t\t\t\t'description'           => 'Used to keep a log of actions in WordPress for cache invalidation in gatsby-source-wordpress.',\n\t\t\t\t'public'                => false,\n\t\t\t\t'publicly_queryable'    => true,\n\t\t\t\t'show_ui'               => $this->wpgraphql_debug_mode,\n\t\t\t\t'delete_with_user'      => false,\n\t\t\t\t'show_in_rest'          => false,\n\t\t\t\t'rest_base'             => '',\n\t\t\t\t'rest_controller_class' => 'WP_REST_Posts_Controller',\n\t\t\t\t'has_archive'           => false,\n\t\t\t\t'show_in_menu'          => $this->wpgraphql_debug_mode,\n\t\t\t\t'show_in_nav_menus'     => false,\n\t\t\t\t'exclude_from_search'   => true,\n\t\t\t\t'capabilities'          => [\n\t\t\t\t\t// these custom capabilities allow any role to use Preview\n\t\t\t\t\t'read_private_posts' => 'read_private_action_monitor_posts',\n\t\t\t\t\t'edit_others_posts'  => 'edit_others_action_monitor_posts', \n\t\t\t\t\t// these are regular role capabilities for a CPT\n\t\t\t\t\t'create_post'        => 'create_post', \n\t\t\t\t\t'edit_post'          => 'edit_post', \n\t\t\t\t\t'read_post'          => 'read_post', \n\t\t\t\t\t'delete_post'        => 'delete_post', \n\t\t\t\t\t'edit_posts'         => 'edit_posts', \n\t\t\t\t\t'publish_posts'      => 'publish_posts',       \n\t\t\t\t\t'create_posts'       => 'create_posts'\n\t\t\t\t],\n\t\t\t\t'map_meta_cap'          => false,\n\t\t\t\t'hierarchical'          => false,\n\t\t\t\t'rewrite'               => [\n\t\t\t\t\t'slug'       => 'action_monitor',\n\t\t\t\t\t'with_front' => true,\n\t\t\t\t],\n\t\t\t\t'query_var'             => true,\n\t\t\t\t'supports'              => [ 'title', 'editor' ],\n\t\t\t\t'show_in_graphql'       => true,\n\t\t\t\t'graphql_single_name'   => 'ActionMonitorAction',\n\t\t\t\t'graphql_plural_name'   => 'ActionMonitorActions',\n\t\t\t]\n\t\t);\n\n\t\t// Registers the taxonomy that connects the node type to the action_monitor post\n\t\tregister_taxonomy(\n\t\t\t'gatsby_action_ref_node_type',\n\t\t\t'action_monitor',\n\t\t\t[\n\t\t\t\t'label'               => __( 'Referenced Node Type', 'WPGatsby' ),\n\t\t\t\t'public'              => false,\n\t\t\t\t'show_ui'             => $this->wpgraphql_debug_mode,\n\t\t\t\t'show_in_graphql'     => false,\n\t\t\t\t'graphql_single_name' => 'ReferencedNodeType',\n\t\t\t\t'graphql_plural_name' => 'ReferencedNodeTypes',\n\t\t\t\t'hierarchical'        => false,\n\t\t\t\t'show_in_nav_menus'   => false,\n\t\t\t\t'show_tagcloud'       => false,\n\t\t\t\t'show_admin_column'   => true,\n\t\t\t]\n\t\t);\n\n\t\t// Registers the taxonomy that connects the node databaseId to the action_monitor post\n\t\tregister_taxonomy(\n\t\t\t'gatsby_action_ref_node_dbid',\n\t\t\t'action_monitor',\n\t\t\t[\n\t\t\t\t'label'               => __( 'Referenced Node Database ID', 'WPGatsby' ),\n\t\t\t\t'public'              => false,\n\t\t\t\t'show_ui'             => $this->wpgraphql_debug_mode,\n\t\t\t\t'show_in_graphql'     => false,\n\t\t\t\t'graphql_single_name' => 'ReferencedNodeDatabaseId',\n\t\t\t\t'graphql_plural_name' => 'ReferencedNodeDatabaseIds',\n\t\t\t\t'hierarchical'        => false,\n\t\t\t\t'show_in_nav_menus'   => false,\n\t\t\t\t'show_tagcloud'       => false,\n\t\t\t\t'show_admin_column'   => true,\n\t\t\t]\n\t\t);\n\n\t\t// Registers the taxonomy that connects the node global ID to the action_monitor post\n\t\tregister_taxonomy(\n\t\t\t'gatsby_action_ref_node_id',\n\t\t\t'action_monitor',\n\t\t\t[\n\t\t\t\t'label'               => __( 'Referenced Node Global ID', 'WPGatsby' ),\n\t\t\t\t'public'              => false,\n\t\t\t\t'show_ui'             => $this->wpgraphql_debug_mode,\n\t\t\t\t'show_in_graphql'     => false,\n\t\t\t\t'graphql_single_name' => 'ReferencedNodeId',\n\t\t\t\t'graphql_plural_name' => 'ReferencedNodeIds',\n\t\t\t\t'hierarchical'        => false,\n\t\t\t\t'show_in_nav_menus'   => false,\n\t\t\t\t'show_tagcloud'       => false,\n\t\t\t\t'show_admin_column'   => true,\n\t\t\t]\n\t\t);\n\n\t\t// Registers the taxonomy that connects the action type (CREATE, UPDATE, DELETE) to the action_monitor post\n\t\tregister_taxonomy(\n\t\t\t'gatsby_action_type',\n\t\t\t'action_monitor',\n\t\t\t[\n\t\t\t\t'label'               => __( 'Action Type', 'WPGatsby' ),\n\t\t\t\t'public'              => false,\n\t\t\t\t'show_ui'             => $this->wpgraphql_debug_mode,\n\t\t\t\t'show_in_graphql'     => false,\n\t\t\t\t'hierarchical'        => false,\n\t\t\t\t'show_in_nav_menus'   => false,\n\t\t\t\t'show_tagcloud'       => false,\n\t\t\t\t'show_admin_column'   => true,\n\t\t\t]\n\t\t);\n\n\t\tregister_taxonomy( 'gatsby_action_stream_type', 'action_monitor', [\n\t\t\t'label'               => __( 'Stream Type', 'WPGatsby' ),\n\t\t\t'public'              => false,\n\t\t\t'show_ui'             => $this->wpgraphql_debug_mode,\n\t\t\t'show_in_graphql'     => false,\n\t\t\t'hierarchical'        => false,\n\t\t\t'show_in_nav_menus'   => false,\n\t\t\t'show_tagcloud'       => false,\n\t\t\t'show_admin_column'   => true,\n\t\t] );\n\n\t}\n\n\t/**\n\t * Adds a column to the action monitor Post Type to show the last modified time\n\t *\n\t * @param array $columns The column names included in the post table\n\t *\n\t * @return array\n\t */\n\tpublic function add_modified_column( array $columns ) {\n\t\t$columns['gatsby_last_modified'] = __( 'Last Modified', 'WPGatsby' );\n\n\t\treturn $columns;\n\t}\n\n\t/**\n\t * Renders the last modified time in the action_monitor post type \"modified\" column\n\t *\n\t * @param string $column_name The name of the column\n\t * @param int    $post_id     The ID of the post in the table\n\t */\n\tpublic function render_modified_column( string $column_name, int $post_id ) {\n\t\tif ( 'gatsby_last_modified' === $column_name ) {\n\t\t\t$m_orig   = get_post_field( 'post_modified', $post_id, 'raw' );\n\t\t\t$m_stamp  = strtotime( $m_orig );\n\t\t\t$modified = date( 'n/j/y @ g:i a', $m_stamp );\n\t\t\techo '<p class=\"mod-date\">';\n\t\t\techo '<em>' . esc_html( $modified ) . '</em><br />';\n\t\t\techo '</p>';\n\t\t}\n\t}\n\n\t/**\n\t * Sets should_dispatch to true\n\t */\n\tpublic function schedule_dispatch() {\n\t\t$this->should_dispatch = true;\n\t}\n\n\t/**\n\t * Deletes all posts of the action_monitor post_type that are 7 days old, as well as any\n\t * associated post meta and term relationships.\n\t *\n\t * @return bool|int\n\t */\n\tpublic function garbage_collect_actions() {\n\n\t\tglobal $wpdb;\n\t\t$post_type = 'action_monitor';\n\t\t$sql       = wp_strip_all_tags(\n\t\t\t'DELETE posts, pm, pt\n\t\t\tFROM ' . $wpdb->prefix . 'posts AS posts\n\t\t\tLEFT JOIN ' . $wpdb->prefix . 'term_relationships AS pt ON pt.object_id = posts.ID\n\t\t\tLEFT JOIN ' . $wpdb->prefix . 'postmeta AS pm ON pm.post_id = posts.ID\n\t\t\tWHERE posts.post_type = \\'%1$s\\'\n\t\t\tAND posts.post_modified < \\'%2$s\\'',\n\t\t\ttrue\n\t\t);\n\n\t\t$query = $wpdb->prepare( $sql, $post_type, date( 'Y-m-d H:i:s', strtotime( '-7 days' ) ) );\n\n\t\treturn $wpdb->query( $query );\n\t}\n\n\t/**\n\t * Given the name of an Action Monitor, this returns it\n\t *\n\t * @param string $name The name of the Action Monitor to get\n\t *\n\t * @return mixed|null\n\t */\n\tpublic function get_action_monitor( string $name ) {\n\t\treturn $this->action_monitors[ $name ] ?? null;\n\t}\n\n\t/**\n\t * Use WP Action hooks to create action monitor posts\n\t */\n\tfunction init_action_monitors() {\n\n\t\t$class_names = [\n\t\t\t'AcfMonitor',\n\t\t\t'MediaMonitor',\n\t\t\t'NavMenuMonitor',\n\t\t\t'PostMonitor',\n\t\t\t'PostTypeMonitor',\n\t\t\t'SettingsMonitor',\n\t\t\t'TaxonomyMonitor',\n\t\t\t'TermMonitor',\n\t\t\t'UserMonitor',\n\t\t\t'PreviewMonitor',\n\t\t];\n\n\t\t$action_monitors = [];\n\n\t\tforeach ( $class_names as $class_name ) {\n\t\t\t$class = 'WPGatsby\\ActionMonitor\\Monitors\\\\' . $class_name;\n\t\t\tif ( class_exists( $class ) ) {\n\t\t\t\t$monitor = new $class( $this );\n\t\t\t\t$action_monitors[ $class_name ] = $monitor;\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Filter the action monitors. This can allow for other monitors\n\t\t * to be registered, or can allow for monitors to be overridden.\n\t\t *\n\t\t * Overriding monitors is not advised, but there are cases where it might\n\t\t * be necessary. Override with caution.\n\t\t *\n\t\t * @param array $action_monitors\n\t\t * @param \\WPGatsby\\ActionMonitor\\ActionMonitor $monitor The class instance, used to initialize the monitor.\n\t\t */\n\t\t$this->action_monitors = apply_filters( 'gatsby_action_monitors', $action_monitors, $this );\n\n\t\tdo_action( 'gatsby_init_action_monitors', $this->action_monitors );\n\n\t}\n\n\tfunction register_post_graphql_fields() {\n\n\t\tregister_graphql_field(\n\t\t\t'ActionMonitorAction',\n\t\t\t'actionType',\n\t\t\t[\n\t\t\t\t'type'        => 'String',\n\t\t\t\t'description' => __(\n\t\t\t\t\t'The type of action (CREATE, UPDATE, DELETE)',\n\t\t\t\t\t'WPGatsby'\n\t\t\t\t),\n\t\t\t\t'resolve'     => function( $post ) {\n\n\t\t\t\t\t$terms = get_the_terms( $post->databaseId, 'gatsby_action_type' );\n\n\t\t\t\t\tif ( ! is_wp_error( $terms ) && ! empty( $terms ) ) {\n\t\t\t\t\t\t$action_type = (string) $terms[0]->name;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t$action_type\n\t\t\t\t\t\t\t= get_post_meta( $post->ID, 'action_type', true );\n\t\t\t\t\t}\n\n\t\t\t\t\treturn $action_type ? $action_type : null;\n\t\t\t\t},\n\t\t\t]\n\t\t);\n\n\t\tregister_graphql_field(\n\t\t\t'ActionMonitorAction',\n\t\t\t'referencedNodeStatus',\n\t\t\t[\n\t\t\t\t'type'        => 'String',\n\t\t\t\t'description' => __(\n\t\t\t\t\t'The post status of the post that triggered this action',\n\t\t\t\t\t'WPGatsby'\n\t\t\t\t),\n\t\t\t\t'resolve'     => function( $post ) {\n\t\t\t\t\t$referenced_node_status = get_post_meta(\n\t\t\t\t\t\t$post->ID,\n\t\t\t\t\t\t'referenced_node_status',\n\t\t\t\t\t\ttrue\n\t\t\t\t\t);\n\n\t\t\t\t\treturn $referenced_node_status ?? null;\n\t\t\t\t},\n\t\t\t]\n\t\t);\n\n\t\tregister_graphql_field(\n\t\t\t'ActionMonitorAction',\n\t\t\t'previewData',\n\t\t\t[\n\t\t\t\t'type'        => 'GatsbyPreviewData',\n\t\t\t\t'description' => __(\n\t\t\t\t\t'The preview data of the post that triggered this action.',\n\t\t\t\t\t'WPGatsby'\n\t\t\t\t),\n\t\t\t\t'resolve'     => function( $post ) {\n\t\t\t\t\t$referenced_node_preview_data = get_post_meta(\n\t\t\t\t\t\t$post->ID,\n\t\t\t\t\t\t'_gatsby_preview_data',\n\t\t\t\t\t\ttrue\n\t\t\t\t\t);\n\n\t\t\t\t\treturn $referenced_node_preview_data \n\t\t\t\t\t\t\t&& $referenced_node_preview_data !== \"\" \n\t\t\t\t\t\t\t\t? json_decode( $referenced_node_preview_data )\n\t\t\t\t\t\t\t\t: null;\n\t\t\t\t}\n\t\t\t]\n\t\t);\n\n\t\tregister_graphql_object_type(\n\t\t\t'GatsbyPreviewData',\n\t\t\t[\n\t\t\t\t'description' => __( 'Gatsby Preview webhook data.', 'WPGatsby' ),\n\t\t\t\t'fields'      => [\n\t\t\t\t\t'previewDatabaseId'  => [\n\t\t\t\t\t\t'type' => 'Int',\n\t\t\t\t\t\t'description' => __( 'The WordPress database ID of the preview. Could be a revision or draft ID.', 'WPGatsby' ),\n\t\t\t\t\t],\n\t\t\t\t\t'userDatabaseId'     => [\n\t\t\t\t\t\t'type' => 'Int',\n\t\t\t\t\t\t'description' => __( 'The database ID of the user who made the original preview.', 'WPGatsby' ),\n\t\t\t\t\t],\n\t\t\t\t\t'id'         => [\n\t\t\t\t\t\t'type' => 'ID',\n\t\t\t\t\t\t'description' => __( 'The Relay id of the previewed node.', 'WPGatsby' ),\n\t\t\t\t\t],\n\t\t\t\t\t'singleName' => [\n\t\t\t\t\t\t'type' => 'String',\n\t\t\t\t\t\t'description' => __( 'The GraphQL single field name for the type of the preview.', 'WPGatsby' ),\n\t\t\t\t\t],\n\t\t\t\t\t'isDraft'    => [\n\t\t\t\t\t\t'type' => 'Boolean',\n\t\t\t\t\t\t'description' => __( 'Wether or not the preview is a draft.', 'WPGatsby' ),\n\t\t\t\t\t],\n\t\t\t\t\t'remoteUrl'  => [\n\t\t\t\t\t\t'type' => 'String',\n\t\t\t\t\t\t'description' => __( 'The WP url at the time of the preview.', 'WPGatsby' ),\n\t\t\t\t\t],\n\t\t\t\t\t'modified'   => [\n\t\t\t\t\t\t'type' => 'String',\n\t\t\t\t\t\t'description' => __( 'The modified time of the previewed node.', 'WPGatsby' ),\n\t\t\t\t\t],\n\t\t\t\t\t'parentDatabaseId'   => [\n\t\t\t\t\t\t'type' => 'Int',\n\t\t\t\t\t\t'description' => __( 'The WordPress database ID of the preview. If this is a draft it will potentially return 0, if it\\'s a revision of a post, it will return the ID of the original post that this is a revision of.', 'WPGatsby' ),\n\t\t\t\t\t],\n\t\t\t\t\t'manifestIds' => [\n\t\t\t\t\t\t'type' => [ 'list_of' => 'String' ],\n\t\t\t\t\t\t'description' => __( 'A list of manifest ID\\'s a preview action has seen during it\\'s lifetime.', 'WPGatsby' ),\n\t\t\t\t\t]\n\t\t\t\t]\n\t\t\t]\n\t\t);\n\n\t\tregister_graphql_field(\n\t\t\t'ActionMonitorAction',\n\t\t\t'referencedNodeID',\n\t\t\t[\n\t\t\t\t'type'        => 'String',\n\t\t\t\t'description' => __(\n\t\t\t\t\t'The post ID of the post that triggered this action',\n\t\t\t\t\t'WPGatsby'\n\t\t\t\t),\n\t\t\t\t'resolve'     => function( $post ) {\n\n\t\t\t\t\t$terms = get_the_terms( $post->databaseId, 'gatsby_action_ref_node_dbid' );\n\t\t\t\t\tif ( ! is_wp_error( $terms ) && ! empty( $terms ) ) {\n\t\t\t\t\t\t$referenced_node_id = (string) $terms[0]->name;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t$referenced_node_id = get_post_meta(\n\t\t\t\t\t\t\t$post->ID,\n\t\t\t\t\t\t\t'referenced_node_id',\n\t\t\t\t\t\t\ttrue\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn $referenced_node_id ?? null;\n\t\t\t\t},\n\t\t\t]\n\t\t);\n\n\t\tregister_graphql_field(\n\t\t\t'ActionMonitorAction',\n\t\t\t'referencedNodeGlobalRelayID',\n\t\t\t[\n\t\t\t\t'type'        => 'String',\n\t\t\t\t'description' => __(\n\t\t\t\t\t'The global relay ID of the post that triggered this action',\n\t\t\t\t\t'WPGatsby'\n\t\t\t\t),\n\t\t\t\t'resolve'     => function( $post ) {\n\n\t\t\t\t\t$terms = get_the_terms( $post->databaseId, 'gatsby_action_ref_node_id' );\n\t\t\t\t\tif ( ! is_wp_error( $terms ) && ! empty( $terms ) ) {\n\t\t\t\t\t\t$referenced_node_relay_id = (string) $terms[0]->name;\n\t\t\t\t\t} else {\n\n\t\t\t\t\t\t$referenced_node_relay_id = get_post_meta(\n\t\t\t\t\t\t\t$post->ID,\n\t\t\t\t\t\t\t'referenced_node_relay_id',\n\t\t\t\t\t\t\ttrue\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn $referenced_node_relay_id ?? null;\n\t\t\t\t},\n\t\t\t]\n\t\t);\n\n\t\tregister_graphql_field(\n\t\t\t'ActionMonitorAction',\n\t\t\t'referencedNodeSingularName',\n\t\t\t[\n\t\t\t\t'type'        => 'String',\n\t\t\t\t'description' => __(\n\t\t\t\t\t'The WPGraphQL single name of the referenced post',\n\t\t\t\t\t'WPGatsby'\n\t\t\t\t),\n\t\t\t\t'resolve'     => function( $post ) {\n\t\t\t\t\t$referenced_node_single_name = get_post_meta(\n\t\t\t\t\t\t$post->ID,\n\t\t\t\t\t\t'referenced_node_single_name',\n\t\t\t\t\t\ttrue\n\t\t\t\t\t);\n\n\t\t\t\t\treturn $referenced_node_single_name ?? null;\n\t\t\t\t},\n\t\t\t]\n\t\t);\n\n\t\tregister_graphql_field(\n\t\t\t'ActionMonitorAction',\n\t\t\t'referencedNodePluralName',\n\t\t\t[\n\t\t\t\t'type'        => 'String',\n\t\t\t\t'description' => __(\n\t\t\t\t\t'The WPGraphQL plural name of the referenced post',\n\t\t\t\t\t'WPGatsby'\n\t\t\t\t),\n\t\t\t\t'resolve'     => function( $post ) {\n\t\t\t\t\t$referenced_node_plural_name = get_post_meta(\n\t\t\t\t\t\t$post->ID,\n\t\t\t\t\t\t'referenced_node_plural_name',\n\t\t\t\t\t\ttrue\n\t\t\t\t\t);\n\n\t\t\t\t\treturn $referenced_node_plural_name ?? null;\n\t\t\t\t},\n\t\t\t]\n\t\t);\n\n\t\tregister_graphql_field(\n\t\t\t'RootQueryToActionMonitorActionConnectionWhereArgs',\n\t\t\t'sinceTimestamp',\n\t\t\t[\n\t\t\t\t'type'        => 'Number',\n\t\t\t\t'description' => 'List Actions performed since a timestamp.',\n\t\t\t]\n\t\t);\n\n\t\t// @todo write a test for this previewStream input arg\n\t\tregister_graphql_field(\n\t\t\t'RootQueryToActionMonitorActionConnectionWhereArgs',\n\t\t\t'previewStream',\n\t\t\t[\n\t\t\t\t'type'        => 'boolean',\n\t\t\t\t'description' => 'List Actions of the PREVIEW stream type.',\n\t\t\t]\n\t\t);\n\n\t\tadd_filter(\n\t\t\t'graphql_post_object_connection_query_args',\n\t\t\tfunction( $args ) {\n\t\t\t\t$sinceTimestamp = $args['sinceTimestamp'] ?? null;\n\n\t\t\t\tif ( $sinceTimestamp ) {\n\t\t\t\t\t$args['date_query'] = [\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t'after'  =>  gmdate(\n\t\t\t\t\t\t\t\t'Y-m-d H:i:s',\n\t\t\t\t\t\t\t\t$sinceTimestamp / 1000\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t'column' => 'post_modified_gmt',\n\t\t\t\t\t\t],\n\t\t\t\t\t];\n\t\t\t\t}\n\n\t\t\t\treturn $args;\n\t\t\t}\n\t\t);\n\n\t\tadd_filter(\n\t\t\t'graphql_post_object_connection_query_args',\n\t\t\tfunction( $args ) {\n\t\t\t\t$previewStream = $args['previewStream'] ?? false;\n\n\t\t\t\tif ( $previewStream ) {\n\t\t\t\t\t$args['tax_query'] = [\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t'taxonomy' => 'gatsby_action_stream_type',\n\t\t\t\t\t\t\t'field' => 'slug',\n\t\t\t\t\t\t\t'terms' => 'preview',\n\t\t\t\t\t\t],\n\t\t\t\t\t];\n\t\t\t\t}\n\n\t\t\t\treturn $args;\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Add post meta to schema\n\t */\n\tfunction register_graphql_fields() {\n\t\t$this->register_post_graphql_fields();\n\t}\n\n\t/**\n\t * Triggers the dispatch to the remote endpoint(s)\n\t */\n\tpublic function trigger_dispatch() {\n\t\t$build_webhook_field   = Settings::prefix_get_option( 'builds_api_webhook', 'wpgatsby_settings', false );\n\t\t$preview_webhook_field = Settings::prefix_get_option( 'preview_api_webhook', 'wpgatsby_settings', false );\n\n\t\t$should_call_build_webhooks =\n\t\t\t$build_webhook_field &&\n\t\t\t$this->should_dispatch;\n\n\t\t$we_should_call_preview_webhooks =\n\t\t\t$preview_webhook_field &&\n\t\t\t$this->should_dispatch;\n\n\t\tif ( $should_call_build_webhooks ) {\n\t\t\t$webhooks = explode( ',', $build_webhook_field );\n\n\t\t\t$truthy_webhooks = array_filter( $webhooks );\n\t\t\t$unique_webhooks = array_unique( $truthy_webhooks );\n\n\t\t\tforeach ( $unique_webhooks as $webhook ) {\n\t\t\t\t$args = apply_filters( 'gatsby_trigger_dispatch_args', [], $webhook );\n\n\t\t\t\twp_safe_remote_post( $webhook, $args );\n\t\t\t}\n\t\t}\n\n\t\tif ( $we_should_call_preview_webhooks ) {\n\t\t\t$webhooks = explode( ',', $preview_webhook_field );\n\n\t\t\t$truthy_webhooks = array_filter( $webhooks );\n\t\t\t$unique_webhooks = array_unique( $truthy_webhooks );\n\n\t\t\tforeach ( $unique_webhooks as $webhook ) {\n\t\t\t\t$token = \\WPGatsby\\GraphQL\\Auth::get_token();\n\n\t\t\t\t// For preview webhooks we send the token\n\t\t\t\t// because this is a build but\n\t\t\t\t// we want it to source any pending previews\n\t\t\t\t// in case someone pressed preview right after\n\t\t\t\t// we got to this point from someone else pressing\n\t\t\t\t// publish/update.\n\t\t\t\t$graphql_endpoint = apply_filters( 'graphql_endpoint', 'graphql' );\n\t\t\t\t$graphql_url = get_site_url() . '/' . ltrim( $graphql_endpoint, '/' );\n\t\t\t\t\n\t\t\t\t$post_body = apply_filters(\n\t\t\t\t\t'gatsby_trigger_preview_build_dispatch_post_body',\n\t\t\t\t\t[\n\t\t\t\t\t\t'token' => $token,\n\t\t\t\t\t\t'userDatabaseId' => get_current_user_id(),\n\t\t\t\t\t\t'remoteUrl' => $graphql_url\n\t\t\t\t\t]\n\t\t\t\t);\n\n\t\t\t\t$args = apply_filters(\n\t\t\t\t\t'gatsby_trigger_preview_build_dispatch_args',\n\t\t\t\t\t[\n\t\t\t\t\t\t'body'        => wp_json_encode( $post_body ),\n\t\t\t\t\t\t'headers'     => [\n\t\t\t\t\t\t\t'Content-Type' => 'application/json; charset=utf-8',\n\t\t\t\t\t\t],\n\t\t\t\t\t\t'method'      => 'POST',\n\t\t\t\t\t\t'data_format' => 'body',\n\t\t\t\t\t],\n\t\t\t\t\t$webhook \n\t\t\t\t);\n\n\t\t\t\twp_safe_remote_post( $webhook, $args );\n\t\t\t}\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "src/ActionMonitor/Monitors/AcfMonitor.php",
    "content": "<?php\n\nnamespace WPGatsby\\ActionMonitor\\Monitors;\n\nuse WPGatsby\\Utils\\Utils;\n\nclass AcfMonitor extends Monitor {\n\n\tpublic function init() {\n\t\t// ACF Actions\n\t\tadd_action(\n\t\t\t'acf/update_field_group',\n\t\t\tfunction() {\n\t\t\t\t$this->trigger_schema_diff(\n\t\t\t\t\t[\n\t\t\t\t\t\t'title' => __( 'Update ACF Field Group', 'WPGatsby' ),\n\t\t\t\t\t]\n\t\t\t\t);\n\t\t\t}\n\t\t);\n\n\t\tadd_action(\n\t\t\t'acf/delete_field_group',\n\t\t\tfunction() {\n\t\t\t\t$this->trigger_schema_diff(\n\t\t\t\t\t[\n\t\t\t\t\t\t'title' => __( 'Delete ACF Field Group', 'WPGatsby' ),\n\t\t\t\t\t]\n\t\t\t\t);\n\t\t\t}\n\t\t);\n\n        add_action('acf/save_post', [$this, 'after_acf_save_post'], 20);\n\t}\n\n    /**\n     * Handles content updates of ACF option pages.\n     */\n    public function after_acf_save_post() {\n\t\tif ( ! function_exists( 'acf_get_options_pages' ) ) {\n\t\t\treturn;\n\t\t}\n\n        $option_pages = acf_get_options_pages();\n\n        if ( ! is_array( $option_pages ) ) {\n\t\t\treturn;\n        }\n\n        $option_pages_slugs = array_keys( $option_pages );\n\n        /**\n         * Filters the $option_pages_slugs array.\n         *\n         * @since 2.1.2\n         *\n         * @param\tarray $option_pages_slugs Array with slugs of all registered ACF option pages.\n         */\n        $option_pages_slugs = apply_filters(\n\t\t\t'gatsby_action_monitor_tracked_acf_options_pages',\n\t\t\t$option_pages_slugs\n\t\t);\n\n        $screen = get_current_screen();\n\n        if(\n\t\t\t! empty( $option_pages_slugs ) \n\t\t\t&& is_array( $option_pages_slugs )\n\t\t\t&& Utils::str_in_substr_array( $screen->id, $option_pages_slugs )\n\t\t) {\n            $this->trigger_non_node_root_field_update();\n        }\n    }\n}\n"
  },
  {
    "path": "src/ActionMonitor/Monitors/MediaMonitor.php",
    "content": "<?php\n\nnamespace WPGatsby\\ActionMonitor\\Monitors;\n\nuse GraphQLRelay\\Relay;\n\nclass MediaMonitor extends  Monitor {\n\n\t/**\n\t * Initialize the Media Monitor which tracks actions for Media and logs them\n\t * to the Gatsby Action Monitor\n\t *\n\t * @return mixed|void\n\t */\n\tpublic function init() {\n\n\t\tadd_action( 'add_attachment', [ $this, 'callback_add_attachment' ] );\n\t\tadd_action( 'edit_attachment', [ $this, 'callback_edit_attachment' ] );\n\t\tadd_action( 'delete_attachment', [ $this, 'callback_delete_attachment' ] );\n\t\tadd_action( 'wp_save_image_editor_file', [ $this, 'callback_wp_save_image_editor_file' ], 10, 5 );\n\t\tadd_action( 'wp_save_image_file', [ $this, 'callback_wp_save_image_file' ], 10, 5 );\n\n\t}\n\n\t/**\n\t * Logs an action when a Media Item (attachment) is added to WordPress\n\t *\n\t * @param int $attachment_id The ID of the attachment\n\t */\n\tpublic function callback_add_attachment( int $attachment_id ) {\n\n\t\t$attachment = get_post( $attachment_id );\n\n\t\tif ( ! $attachment ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$global_relay_id = Relay::toGlobalId(\n\t\t\t'post',\n\t\t\t$attachment_id\n\t\t);\n\n\t\t$this->log_action(\n\t\t\t[\n\t\t\t\t'action_type'         => 'CREATE',\n\t\t\t\t'title'               => $attachment->post_title ?? \"Attachment #$attachment_id\",\n\t\t\t\t// there is no concept of inheriting post status in Gatsby, so images will always be considered published.\n\t\t\t\t'status'              => 'publish',\n\t\t\t\t'node_id'             => $attachment_id,\n\t\t\t\t'relay_id'            => $global_relay_id,\n\t\t\t\t'graphql_single_name' => 'mediaItem',\n\t\t\t\t'graphql_plural_name' => 'mediaItems',\n\t\t\t\t'skip_webhook'        => true,\n\t\t\t],\n\t\t);\n\n\t}\n\n\t/**\n\t * Logs an action when Media Items are edited\n\t *\n\t * @param int $attachment_id\n\t */\n\tpublic function callback_edit_attachment( int $attachment_id ) {\n\n\t\t$attachment = get_post( $attachment_id );\n\n\t\tif ( ! $attachment ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$global_relay_id = Relay::toGlobalId(\n\t\t\t'post',\n\t\t\t$attachment_id\n\t\t);\n\n\t\t$this->log_action(\n\t\t\t[\n\t\t\t\t'action_type'         => 'UPDATE',\n\t\t\t\t'title'               => $attachment->post_title ?? \"Attachment #$attachment_id\",\n\t\t\t\t// there is no concept of inheriting post status in Gatsby, so images will always be considered published.\n\t\t\t\t'status'              => 'publish',\n\t\t\t\t'node_id'             => $attachment_id,\n\t\t\t\t'relay_id'            => $global_relay_id,\n\t\t\t\t'graphql_single_name' => 'mediaItem',\n\t\t\t\t'graphql_plural_name' => 'mediaItems',\n\t\t\t\t'skip_webhook'        => true,\n\t\t\t],\n\t\t);\n\n\t}\n\n\t/**\n\t * Logs an action when media items are deleted from the Media Library\n\t *\n\t * @param int $attachment_id The ID of the media item being deleted\n\t */\n\tpublic function callback_delete_attachment( int $attachment_id ) {\n\n\t\t$attachment = get_post( $attachment_id );\n\n\t\tif ( ! $attachment ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$global_relay_id = Relay::toGlobalId(\n\t\t\t'post',\n\t\t\t$attachment_id\n\t\t);\n\n\t\t$this->log_action(\n\t\t\t[\n\t\t\t\t'action_type'         => 'DELETE',\n\t\t\t\t'title'               => $attachment->post_title ?? \"Attachment #$attachment_id\",\n\t\t\t\t// there is no concept of inheriting post status in Gatsby, so images will always be considered published.\n\t\t\t\t'status'              => 'trash',\n\t\t\t\t'node_id'             => $attachment_id,\n\t\t\t\t'relay_id'            => $global_relay_id,\n\t\t\t\t'graphql_single_name' => 'mediaItem',\n\t\t\t\t'graphql_plural_name' => 'mediaItems',\n\t\t\t\t'skip_webhook'        => true,\n\t\t\t],\n\t\t);\n\n\t}\n\n\t/**\n\t * Logs an action when image files are saved from the image editor\n\t *\n\t * @param string $dummy      Unused.\n\t * @param string $filename   Filename.\n\t * @param string $image      Unused.\n\t * @param string $mime_type  Unused.\n\t * @param int    $post_id    Post ID.\n\t */\n\tpublic function callback_wp_save_image_editor_file( $dummy, $filename, $image, $mime_type, $post_id ) {\n\t\t$this->callback_edit_attachment( $post_id );\n\t}\n\n\t/**\n\t * Logs an action when image files are saved from the image editor\n\t *\n\t * @param string $dummy      Unused.\n\t * @param string $filename   Filename.\n\t * @param string $image      Unused.\n\t * @param string $mime_type  Unused.\n\t * @param int    $post_id    Post ID.\n\t */\n\tpublic function callback_wp_save_image_file( $dummy, $filename, $image, $mime_type, $post_id ) {\n\t\treturn $this->callback_wp_save_image_editor_file( $dummy, $filename, $image, $mime_type, $post_id );\n\t}\n\n}\n"
  },
  {
    "path": "src/ActionMonitor/Monitors/Monitor.php",
    "content": "<?php\nnamespace WPGatsby\\ActionMonitor\\Monitors;\n\nuse GraphQLRelay\\Relay;\nuse WPGatsby\\ActionMonitor\\ActionMonitor;\nuse WPGatsby\\Admin\\Preview;\n\nabstract class Monitor {\n\n\t/**\n\t * @var ActionMonitor\n\t */\n\tprotected $action_monitor;\n\n\t/**\n\t * @var array\n\t */\n\tprotected $tracked_events = [];\n\n\t/**\n\t * @var array\n\t */\n\tprotected $ignored_ids = [];\n\n\t/**\n\t * Monitor constructor.\n\t *\n\t * @param ActionMonitor $action_monitor\n\t */\n\tpublic function __construct( ActionMonitor $action_monitor ) {\n\t\t$this->action_monitor = $action_monitor;\n\t\t$this->init();\n\t}\n\n\t/**\n\t * Allows IDs to be set that will be ignored by the logger\n\t *\n\t * @param int[] $ids Array of database IDs to ignore logging for\n\t */\n\tpublic function set_ignored_ids( array $ids ) {\n\t\tif ( ! empty( $ids ) && is_array( $ids ) ) {\n\t\t\t$this->ignored_ids = array_merge( $this->ignored_ids, $ids );\n\t\t}\n\t}\n\n\t/**\n\t * Given an array of IDs, this removes them from the list of ignored IDs\n\t *\n\t * @param array $ids\n\t */\n\tpublic function unset_ignored_ids( array $ids ) {\n\t\tif ( ! empty( $ids ) && is_array( $ids ) ) {\n\t\t\tforeach ( $ids as $id ) {\n\t\t\t\tif ( isset( $this->ignored_ids[ $id ] ) ) {\n\t\t\t\t\tunset( $this->ignored_ids[ $id ] );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Resets the ignored IDs to an empty array\n\t */\n\tpublic function reset_ignored_ids() {\n\t\t$this->ignored_ids = [];\n\t}\n\n\t/**\n\t * Trigger action for non node root field updates\n\t *\n\t * @param array $args Optional args to pass to the action\n\t */\n\tpublic function trigger_non_node_root_field_update( array $args = [] ) {\n\n\t\t$default = [\n\t\t\t'action_type'         => 'NON_NODE_ROOT_FIELDS',\n\t\t\t'title'               => 'Non node root field changed',\n\t\t\t'node_id'             => 'update_non_node_root_field',\n\t\t\t'relay_id'            => 'update_non_node_root_field',\n\t\t\t'graphql_single_name' => 'update_non_node_root_field',\n\t\t\t'graphql_plural_name' => 'update_non_node_root_field',\n\t\t\t'status'              => 'update_non_node_root_field',\n\t\t];\n\n\t\t$this->log_action( array_merge( $default, $args ) );\n\n\t}\n\n\t/**\n\t * Trigger action to refetch everything\n\t *\n\t * @param array $args Optional args to pass to the action\n\t */\n\tpublic function trigger_refetch_all( $args = [] ) {\n\n\t\t$default = [\n\t\t\t'action_type'         => 'REFETCH_ALL',\n\t\t\t'title'               => 'Something changed (such as permalink structure) that requires everything to be refetched',\n\t\t\t'node_id'             => 'refetch_all',\n\t\t\t'relay_id'            => 'refetch_all',\n\t\t\t'graphql_single_name' => 'refetch_all',\n\t\t\t'graphql_plural_name' => 'refetch_all',\n\t\t\t'status'              => 'refetch_all',\n\t\t];\n\n\t\t$this->log_action( array_merge( $default, $args ) );\n\n\t}\n\n\t/**\n\t * Determines whether the meta should be tracked or not\n\t *\n\t * @param string $meta_key Metadata key.\n\t * @param mixed $meta_value Metadata value. Serialized if non-scalar.\n\t * @param object $object The object the metadata is for.\n\t *\n\t * @return bool\n\t */\n\tprotected function should_track_meta( string $meta_key, $meta_value, $object ) {\n\n\t\t/**\n\t\t * This filter allows plugins to opt-in or out of tracking for meta.\n\t\t *\n\t\t * @param bool $should_track Whether the meta key should be tracked.\n\t\t * @param string $meta_key Metadata key.\n\t\t * @param int $meta_id ID of updated metadata entry.\n\t\t * @param mixed $meta_value Metadata value. Serialized if non-scalar.\n\t\t * @param mixed $object The object the meta is being updated for.\n\t\t *\n\t\t * @param bool $tracked whether the meta key is tracked by Gatsby Action Monitor\n\t\t */\n\t\t$should_track = apply_filters( 'gatsby_action_monitor_should_track_meta', null, $meta_key, $meta_value, $object );\n\n\t\t// If the filter has been applied return it\n\t\tif ( null !== $should_track ) {\n\t\t\treturn (bool) $should_track;\n\t\t}\n\n\t\t// If the meta key starts with an underscore, don't track it\n\t\tif ( '_' === substr( $meta_key, 0, 1 ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\n\t}\n\n\t/**\n\t * Inserts an action that triggers Gatsby Source WordPress to diff the Schemas.\n\t *\n\t * This can be used for plugins such as Custom Post Type UI, Advanced Custom Fields, etc that\n\t * alter the Schema in some way.\n\t *\n\t * @param array $args Optional args to add to the action\n\t */\n\tpublic function trigger_schema_diff( $args = [] ) {\n\n\t\t$default             = [\n\t\t\t'title'               => __( 'Diff schemas', 'WPGatsby' ),\n\t\t\t'node_id'             => 'none',\n\t\t\t'relay_id'            => 'none',\n\t\t\t'graphql_single_name' => 'none',\n\t\t\t'graphql_plural_name' => 'none',\n\t\t\t'status'              => 'none',\n\t\t];\n\t\t$args                = array_merge( $default, $args );\n\t\t$args['action_type'] = 'DIFF_SCHEMAS';\n\t\t$this->log_action( $args );\n\t}\n\n\t/**\n\t * Insert new action\n\t *\n\t * $args = [$action_type, $title, $status, $node_id, $relay_id, $graphql_single_name,\n\t * $graphql_plural_name]\n\t *\n\t * @param array $args Array of arguments to configure the action to be inserted\n\t *\n\t */\n\tpublic function log_action( array $args ) {\n\n\t\tif (\n\t\t\t! isset( $args['action_type'] ) ||\n\t\t\t! isset( $args['title'] ) ||\n\t\t\t! isset( $args['node_id'] ) ||\n\t\t\t! isset( $args['relay_id'] ) ||\n\t\t\t! isset( $args['graphql_single_name'] ) ||\n\t\t\t! isset( $args['graphql_plural_name'] ) ||\n\t\t\t! isset( $args['status'] )\n\t\t) {\n\t\t\t// @todo log that this action isn't working??\n\t\t\treturn;\n\t\t}\n\n\t\t/**\n\t\t * Filter to allow skipping a logged action. If set to false, the action will not be logged.\n\t\t *\n\t\t * @param null|bool $enable    Whether the action should be logged\n\t\t * @param array     $arguments The args to log\n\t\t * @param Monitor   $monitor   Instance of the Monitor\n\t\t */\n\t\t$pre_log_action = apply_filters( 'gatsby_pre_log_action_monitor_action', null, $args, $this );\n\n\t\tif ( null !== $pre_log_action ) {\n\t\t\tif ( false === $pre_log_action ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\t// If the node_id is set to be ignored, don't create a log\n\t\tif ( in_array( $args['node_id'], $this->ignored_ids, true ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$should_dispatch =\n\t\t\t! isset( $args['skip_webhook'] ) || ! $args['skip_webhook'];\n\n\t\t$time = time();\n\n\t\t$node_type = 'unknown';\n\t\tif ( isset( $args['graphql_single_name'] ) ) {\n\t\t\t$node_type = $args['graphql_single_name'];\n\t\t} elseif ( isset( $args['relay_id'] ) ) {\n\t\t\t$id_parts = Relay::fromGlobalId( $args['relay_id'] );\n\t\t\tif ( ! isset( $id_parts['type'] ) ) {\n\t\t\t\t$node_type = $id_parts['type'];\n\t\t\t}\n\t\t}\n\n\t\t$stream_type = ( $args['stream_type'] ?? null ) === 'PREVIEW'\n\t\t\t? 'PREVIEW'\n\t\t\t: 'CONTENT';\n\n\t\t$is_preview_stream = $stream_type === 'PREVIEW';\n\n\t\t// Check to see if an action already exists for this node type/database id\n\t\t$existing = new \\WP_Query( [\n\t\t\t'post_type'      => 'action_monitor',\n\t\t\t'post_status'    => 'any',\n\t\t\t'posts_per_page' => 1,\n\t\t\t'no_found_rows'  => true,\n\t\t\t'fields'         => 'ids',\n\t\t\t'tax_query'      => [\n\t\t\t\t'relation' => 'AND',\n\t\t\t\t[\n\t\t\t\t\t'taxonomy' => 'gatsby_action_ref_node_dbid',\n\t\t\t\t\t'field'    => 'name',\n\t\t\t\t\t'terms'    => sanitize_text_field( $args['node_id'] ),\n\t\t\t\t],\n\t\t\t\t[\n\t\t\t\t\t'taxonomy' => 'gatsby_action_ref_node_type',\n\t\t\t\t\t'field'    => 'name',\n\t\t\t\t\t'terms'    => $node_type,\n\t\t\t\t],\n\t\t\t\t[\n\t\t\t\t\t'taxonomy' => 'gatsby_action_stream_type',\n\t\t\t\t\t'field'    => 'name',\n\t\t\t\t\t'terms'    => $stream_type,\n\t\t\t\t]\n\t\t\t],\n\t\t] );\n\n\t\t// If there's already an action logged for this node, update the record\n\t\tif ( isset( $existing->posts ) && ! empty( $existing->posts ) ) {\n\n\t\t\t$existing_id            = $existing->posts[0];\n\t\t\t$action_monitor_post_id = wp_update_post( [\n\t\t\t\t'ID'           => absint( $existing_id ),\n\t\t\t\t'post_title'   => $args['title'],\n\t\t\t\t'post_content' => wp_json_encode( $args ),\n\t\t\t] );\n\n\t\t} else {\n\n\t\t\t$action_monitor_post_id = \\wp_insert_post(\n\t\t\t\t[\n\t\t\t\t\t'post_title'   => $args['title'],\n\t\t\t\t\t'post_type'    => 'action_monitor',\n\t\t\t\t\t'post_status'  => 'private',\n\t\t\t\t\t'author'       => -1,\n\t\t\t\t\t'post_name'    => sanitize_title( \"{$args['title']}-{$time}\" ),\n\t\t\t\t\t'post_content' => wp_json_encode( $args ),\n\t\t\t\t]\n\t\t\t);\n\n\t\t\twp_set_object_terms( $action_monitor_post_id, sanitize_text_field( $args['node_id'] ), 'gatsby_action_ref_node_dbid' );\n\t\t\twp_set_object_terms( $action_monitor_post_id, sanitize_text_field( $node_type ), 'gatsby_action_ref_node_type' );\n\n\t\t}\n\n\t\twp_set_object_terms( $action_monitor_post_id, sanitize_text_field( $args['relay_id'] ), 'gatsby_action_ref_node_id' );\n\t\twp_set_object_terms( $action_monitor_post_id, $args['action_type'], 'gatsby_action_type' );\n\t\twp_set_object_terms( $action_monitor_post_id, $stream_type, 'gatsby_action_stream_type' );\n\n\t\tif ( $action_monitor_post_id !== 0 ) {\n\n\t\t\tif ( isset( $args['preview_data'] ) ) {\n\t\t\t\t$existing_preview_data = \\get_post_meta(\n\t\t\t\t\t$action_monitor_post_id,\n\t\t\t\t\t'_gatsby_preview_data',\n\t\t\t\t\ttrue\n\t\t\t\t);\n\n\t\t\t\t$manifest_id = Preview::get_preview_manifest_id_for_post(\n\t\t\t\t\tget_post( $args['node_id'] )\n\t\t\t\t);\n\n\t\t\t\t$manifest_ids = [$manifest_id];\n\n\t\t\t\t// if we have existing data, we want to merge our manifest id\n\t\t\t\t// into any existing manifest ids\n\t\t\t\tif ( $existing_preview_data && $existing_preview_data !== \"\" ) {\n\t\t\t\t\t$existing_preview_data = json_decode( $existing_preview_data );\n\n\t\t\t\t\tif ( $existing_preview_data->manifestIds ?? false ) {\n\t\t\t\t\t\t$manifest_ids = array_unique(\n\t\t\t\t\t\t\tarray_merge(\n\t\t\t\t\t\t\t\t$existing_preview_data->manifestIds,\n\t\t\t\t\t\t\t\t$manifest_ids\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// add manifest ids\n\t\t\t\t$preview_data = json_decode( $args['preview_data'] );\n\t\t\t\t$preview_data->manifestIds = $manifest_ids;\n\t\t\t\t$preview_data = json_encode( $preview_data );\n\t\t\t\t\n\t\t\t\t\\update_post_meta(\n\t\t\t\t\t$action_monitor_post_id,\n\t\t\t\t\t'_gatsby_preview_data',\n\t\t\t\t\t$preview_data\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t\\update_post_meta(\n\t\t\t\t$action_monitor_post_id,\n\t\t\t\t'referenced_node_status',\n\t\t\t\t$args['status'] // menus don't have post status. This is for Gatsby\n\t\t\t);\n\t\t\t\\update_post_meta(\n\t\t\t\t$action_monitor_post_id,\n\t\t\t\t'referenced_node_single_name',\n\t\t\t\tgraphql_format_field_name( $args['graphql_single_name'] )\n\t\t\t);\n\t\t\t\\update_post_meta(\n\t\t\t\t$action_monitor_post_id,\n\t\t\t\t'referenced_node_plural_name',\n\t\t\t\tgraphql_format_field_name( $args['graphql_plural_name'] )\n\t\t\t);\n\n\t\t\t// preview actions should remain private\n\t\t\tif ( !$is_preview_stream ) {\n\t\t\t\t\\wp_update_post( [\n\t\t\t\t\t'ID'          => $action_monitor_post_id,\n\t\t\t\t\t'post_status' => 'publish'\n\t\t\t\t] );\n\t\t\t}\n\n\t\t}\n\n\t\t// If $should_dispatch is not set to false, schedule a dispatch. Actions being logged that\n\t\t// set $should_dispatch to false will be logged, but not trigger a webhook immediately.\n\t\t// if this is a preview we should always not dispatch\n\t\tif ( $should_dispatch && ! $is_preview_stream ) {\n\t\t\t// we've saved at least 1 action, so we should update\n\t\t\t// but only if this isn't a preview\n\t\t\t// previews will dispatch on their own\n\t\t\t$this->action_monitor->schedule_dispatch();\n\t\t}\n\n\t\t// Delete old actions\n\t\t$this->action_monitor->garbage_collect_actions();\n\n\t}\n\n\n\t/**\n\t * Initialize the Monitor\n\t *\n\t * @return mixed\n\t */\n\tabstract public function init();\n\n}\n"
  },
  {
    "path": "src/ActionMonitor/Monitors/NavMenuMonitor.php",
    "content": "<?php\n\nnamespace WPGatsby\\ActionMonitor\\Monitors;\n\nuse GraphQLRelay\\Relay;\nuse WP_Term;\n\nclass NavMenuMonitor extends Monitor {\n\n\t/**\n\t * @return mixed|void\n\t */\n\tpublic function init() {\n\n\t\t// Log when menus are added/removed from a theme location\n\t\tadd_filter( 'pre_set_theme_mod_nav_menu_locations', [ $this, 'callback_set_nav_menu_locations' ], 10, 2 );\n\n\t\t// Log when a nav menu is updated\n\t\tadd_action( 'wp_update_nav_menu', [ $this, 'callback_update_nav_menu' ], 10, 2 );\n\n\t\t// Log when a nav menu is deleted\n\t\tadd_action( 'wp_delete_nav_menu', [ $this, 'callback_delete_nav_menu' ], 10, 3 );\n\n\t\t// Log when a menu item is updated\n\t\tadd_action( 'wp_update_nav_menu_item', [ $this, 'callback_update_nav_menu_item' ], 10, 3 );\n\t\tadd_action( 'wp_add_nav_menu_item', [ $this, 'callback_add_nav_menu_item' ], 10, 3 );\n\n\t}\n\n\t/**\n\t * Callback for menu locations theme mod. When menu locations are set/unset.\n\t *\n\t * @param array $value The old value of the nav menu locations\n\t * @param mixed|array|bool $old_value The new value of the nav menu locations\n\t *\n\t * @return mixed\n\t */\n\tpublic function callback_set_nav_menu_locations( array $value, $old_value ) {\n\n\t\t$old_locations = ! empty( $old_value ) && is_array( $old_value ) ? $old_value : [];\n\t\t$new_locations = ! empty( $value ) && is_array( $value ) ? $value : [];\n\n\t\t// If old locations are same as new locations, do nothing\n\t\tif ( $old_locations === $new_locations ) {\n\t\t\treturn $value;\n\t\t}\n\n\t\t// Log the diffed menus\n\t\t$this->log_diffed_menus( $old_locations, $new_locations );\n\n\t\t// Return the value passed to the filter, without making any changes\n\t\treturn $value;\n\n\t}\n\n\t/**\n\t * Determines whether a menu is considered public and should be tracked\n\t * by the activity monitor\n\t *\n\t * @param int $menu_id ID of the menu\n\t *\n\t * @return bool\n\t */\n\tpublic function is_menu_public( int $menu_id ) {\n\n\t\t$locations         = get_theme_mod( 'nav_menu_locations' );\n\t\t$assigned_menu_ids = ! empty( $locations ) ? array_values( $locations ) : [];\n\n\t\tif ( empty( $assigned_menu_ids ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif ( in_array( $menu_id, $assigned_menu_ids, true ) ) {\n\t\t\treturn true;\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t/**\n\t * Log action when a nav menu is updated\n\t *\n\t * @param int   $menu_id The ID of the menu being updated\n\t * @param array $menu_data The data associated with the menu\n\t */\n\tpublic function callback_update_nav_menu( int $menu_id, array $menu_data = [] ) {\n\n\t\tif ( ! $this->is_menu_public( $menu_id ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$menu = get_term_by( 'id', absint( $menu_id ), 'nav_menu' );\n\n\t\t$this->log_action(\n\t\t\t[\n\t\t\t\t'action_type'         => 'UPDATE',\n\t\t\t\t'title'               => $menu->name,\n\t\t\t\t// menus don't have post status. This is for Gatsby\n\t\t\t\t'status'              => 'publish',\n\t\t\t\t'node_id'             => (int) $menu->term_id,\n\t\t\t\t'relay_id'            => Relay::toGlobalId( 'term', (int) $menu->term_id ),\n\t\t\t\t'graphql_single_name' => 'menu',\n\t\t\t\t'graphql_plural_name' => 'menus',\n\t\t\t]\n\t\t);\n\n\t}\n\n\t/**\n\t * Given an array of old menu locations and new menu locations, this\n\t * diffs them and logs an action for the menu assigned to the added/removed location\n\t *\n\t * @param array $old_locations Old locations with a menu assigned\n\t * @param array $new_locations New locations with a menu assigned\n\t */\n\tpublic function log_diffed_menus( array $old_locations, array $new_locations ) {\n\n\t\t// If old locations are same as new locations, do nothing\n\t\tif ( $old_locations === $new_locations ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Trigger an action for each added location\n\t\t$added = array_diff( $new_locations, $old_locations );\n\t\tif ( ! empty( $added ) && is_array( $added ) ) {\n\t\t\tforeach ( $added as $location => $added_menu_id ) {\n\n\t\t\t\tif ( ! empty( $menu = get_term_by( 'id', (int) $added_menu_id, 'nav_menu' ) ) && $menu instanceof WP_Term ) {\n\t\t\t\t\t$this->log_action(\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t'action_type'         => 'CREATE',\n\t\t\t\t\t\t\t'title'               => $menu->name,\n\t\t\t\t\t\t\t// menus don't have post status. This is for Gatsby\n\t\t\t\t\t\t\t'status'              => 'publish',\n\t\t\t\t\t\t\t'node_id'             => (int) $added_menu_id,\n\t\t\t\t\t\t\t'relay_id'            => Relay::toGlobalId( 'term', (int) $added_menu_id ),\n\t\t\t\t\t\t\t'graphql_single_name' => 'menu',\n\t\t\t\t\t\t\t'graphql_plural_name' => 'menus',\n\t\t\t\t\t\t]\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Trigger an action for each location deleted\n\t\t$removed = array_diff( $old_locations, $new_locations );\n\t\tif ( ! empty( $removed ) ) {\n\t\t\tforeach ( $removed as $location => $removed_menu_id ) {\n\n\t\t\t\t$this->log_action(\n\t\t\t\t\t[\n\t\t\t\t\t\t'action_type'         => 'DELETE',\n\t\t\t\t\t\t'title'               => $removed_menu_id,\n\t\t\t\t\t\t// menus don't have post status. This is for Gatsby\n\t\t\t\t\t\t'status'              => 'trash',\n\t\t\t\t\t\t'node_id'             => (int) $removed_menu_id,\n\t\t\t\t\t\t'relay_id'            => Relay::toGlobalId( 'term', $removed_menu_id ),\n\t\t\t\t\t\t'graphql_single_name' => 'menu',\n\t\t\t\t\t\t'graphql_plural_name' => 'menus',\n\t\t\t\t\t]\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t}\n\n\t/**\n\t * Log an action when a menu is deleted\n\t *\n\t * @param int $term_id ID of the deleted menu.\n\t */\n\tpublic function callback_delete_nav_menu( $term_id ) {\n\n\t\t$this->log_action(\n\t\t\t[\n\t\t\t\t'action_type'         => 'DELETE',\n\t\t\t\t'title'               => '#' . $term_id,\n\t\t\t\t// menus don't have post status. This is for Gatsby\n\t\t\t\t'status'              => 'trash',\n\t\t\t\t'node_id'             => (int) $term_id,\n\t\t\t\t'relay_id'            => Relay::toGlobalId( 'term', $term_id ),\n\t\t\t\t'graphql_single_name' => 'menu',\n\t\t\t\t'graphql_plural_name' => 'menus',\n\t\t\t]\n\t\t);\n\n\t}\n\n\t/**\n\t * @param int   $menu_id         ID of the updated menu.\n\t * @param int   $menu_item_db_id ID of the updated menu item.\n\t * @param array $args            An array of arguments used to update a menu item.\n\t */\n\tpublic function callback_add_nav_menu_item( int $menu_id, int $menu_item_db_id, array $args ) {\n\n\t\tif ( ! $this->is_menu_public( $menu_id ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$menu      = get_term_by( 'id', $menu_id, 'nav_menu' );\n\t\t$menu_item = get_post( $menu_item_db_id );\n\n\t\t// Log action for the updated menu\n\t\t$this->log_action(\n\t\t\t[\n\t\t\t\t'action_type'         => 'UPDATE',\n\t\t\t\t'title'               => $menu->name,\n\t\t\t\t// menus don't have post status. This is for Gatsby\n\t\t\t\t'status'              => 'publish',\n\t\t\t\t'node_id'             => (int) $menu->term_id,\n\t\t\t\t'relay_id'            => Relay::toGlobalId( 'term', (int) $menu->term_id ),\n\t\t\t\t'graphql_single_name' => 'menu',\n\t\t\t\t'graphql_plural_name' => 'menus',\n\t\t\t]\n\t\t);\n\n\t\t// Log action for the added menu item\n\t\t$this->log_action(\n\t\t\t[\n\t\t\t\t'action_type'         => 'CREATE',\n\t\t\t\t'title'               => $menu_item->post_title,\n\t\t\t\t// menus don't have post status. This is for Gatsby\n\t\t\t\t'status'              => 'publish',\n\t\t\t\t'node_id'             => (int) $menu_item->ID,\n\t\t\t\t'relay_id'            => Relay::toGlobalId( 'post', (int) $menu_item->ID ),\n\t\t\t\t'graphql_single_name' => 'menuItem',\n\t\t\t\t'graphql_plural_name' => 'menuItems',\n\t\t\t]\n\t\t);\n\n\t}\n\n\t/**\n\t * @param int   $menu_id         ID of the updated menu.\n\t * @param int   $menu_item_db_id ID of the updated menu item.\n\t * @param array $args            An array of arguments used to update a menu item.\n\t */\n\tpublic function callback_update_nav_menu_item( int $menu_id, int $menu_item_db_id, array $args ) {\n\n\t\tif ( ! $this->is_menu_public( $menu_id ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$menu      = get_term_by( 'id', $menu_id, 'nav_menu' );\n\t\t$menu_item = get_post( $menu_item_db_id );\n\n\t\t// Log action for the updated menu\n\t\t$this->log_action(\n\t\t\t[\n\t\t\t\t'action_type'         => 'UPDATE',\n\t\t\t\t'title'               => $menu->name,\n\t\t\t\t// menus don't have post status. This is for Gatsby\n\t\t\t\t'status'              => 'publish',\n\t\t\t\t'node_id'             => (int) $menu->term_id,\n\t\t\t\t'relay_id'            => Relay::toGlobalId( 'term', (int) $menu->term_id ),\n\t\t\t\t'graphql_single_name' => 'menu',\n\t\t\t\t'graphql_plural_name' => 'menus',\n\t\t\t]\n\t\t);\n\n\t\t// Log action for the added menu item\n\t\t$this->log_action(\n\t\t\t[\n\t\t\t\t'action_type'         => 'UPDATE',\n\t\t\t\t'title'               => $menu_item->post_title,\n\t\t\t\t// menus don't have post status. This is for Gatsby\n\t\t\t\t'status'              => 'publish',\n\t\t\t\t'node_id'             => (int) $menu_item->ID,\n\t\t\t\t'relay_id'            => Relay::toGlobalId( 'post', (int) $menu_item->ID ),\n\t\t\t\t'graphql_single_name' => 'menuItem',\n\t\t\t\t'graphql_plural_name' => 'menuItems',\n\t\t\t]\n\t\t);\n\n\t}\n\n}\n"
  },
  {
    "path": "src/ActionMonitor/Monitors/PostMonitor.php",
    "content": "<?php\n\nnamespace WPGatsby\\ActionMonitor\\Monitors;\n\nuse GraphQLRelay\\Relay;\nuse WP_Post;\n\nclass PostMonitor extends Monitor {\n\n\t/**\n\t * @return mixed|void\n\t */\n\tpublic function init() {\n\n\t\tadd_action( 'post_updated', [ $this, 'callback_post_updated' ], 10, 3 );\n\t\tadd_action( 'transition_post_status', [ $this, 'callback_transition_post_status' ], 10, 3 );\n\t\tadd_action( 'deleted_post', [ $this, 'callback_deleted_post' ], 10, 1 );\n\t\tadd_action( 'updated_post_meta', [ $this, 'callback_updated_post_meta' ], 10, 4 );\n\t\tadd_action( 'added_post_meta', [ $this, 'callback_updated_post_meta' ], 10, 4 );\n\t\tadd_action( 'deleted_post_meta', [ $this, 'callback_deleted_post_meta' ], 10, 4 );\n\n\t}\n\n\t/**\n\t * Log change to authors\n\t *\n\t * @param int     $post_id      Post ID.\n\t * @param WP_Post $post_after   Post object following the update.\n\t * @param WP_Post $post_before  Post object before the update.\n\t */\n\tpublic function callback_post_updated( int $post_id, WP_Post $post_after, WP_Post $post_before ) {\n\n\t\t// If the author of the post has changed, we need to log an update for the old author and the new author\n\t\tif ( isset( $post_after->post_author ) && (int) $post_after->post_author !== (int) $post_before->post_author ) {\n\n\t\t\t/**\n\t\t\t * Log user update action\n\t\t\t */\n\t\t\t$this->log_user_update( $post_after );\n\t\t\t$this->log_user_update( $post_before );\n\n\t\t}\n\n\t}\n\n\t/**\n\t * Log all post status changes ( creating / updating / trashing )\n\t *\n\t * @action transition_post_status\n\t *\n\t * @param mixed    $new_status  New status.\n\t * @param mixed    $old_status  Old status.\n\t * @param WP_Post  $post Post object.\n\t */\n\tpublic function callback_transition_post_status( $new_status, $old_status, WP_Post $post ) {\n\n\t\tif ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If the object is not a valid post, ignore it\n\t\tif ( ! is_a( $post, 'WP_Post' ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If the post type is not intentionally tracked, ignore it\n\t\tif ( ! $this->is_post_type_tracked( $post->post_type ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$initial_post_statuses = [ 'auto-draft', 'inherit', 'new' ];\n\n\t\t// If the post is a fresh post that hasn't been made public, don't track the action\n\t\tif ( in_array( $new_status, $initial_post_statuses, true ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Saving drafts should not log actions\n\t\tif ( 'draft' === $new_status && 'draft' === $old_status ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If the post isn't coming from a publish state or going to a publish state\n\t\t// we can ignore the action.\n\t\tif ( 'publish' !== $old_status && 'publish' !== $new_status ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$action_type = 'UPDATE';\n\n\t\t// If a post is moved from 'publish' to any other status, set the action_type to delete\n\t\t// to let Gatsby know it should no longer cache the post\n\t\tif ( 'publish' !== $new_status && 'publish' === $old_status ) {\n\n\t\t\t$action_type = 'DELETE';\n\n\t\t\t// If a post that was not published becomes published, set the action_type to create\n\t\t\t// to let Gatsby know it should fetch and cache the post\n\t\t} elseif ( 'publish' === $new_status && 'publish' !== $old_status ) {\n\n\t\t\t$action_type = 'CREATE';\n\n\t\t\t// If a published post is saved, it's an update.\n\t\t} elseif ( 'publish' === $new_status && 'publish' === $old_status ) {\n\t\t\t$action_type = 'UPDATE';\n\t\t}\n\n\t\t// We don't need to log a user update if the post is simply being updated.\n\t\t// The exception would be when the post author is changed, but that's\n\t\t// handled in a different action\n\t\tif ( 'UPDATE' !== $action_type ) {\n\t\t\t$this->log_user_update( $post );\n\t\t}\n\n\t\t$post_type_object = get_post_type_object( $post->post_type );\n\n\t\t$action = [\n\t\t\t'action_type'         => $action_type,\n\t\t\t'title'               => $post->post_title,\n\t\t\t'node_id'             => $post->ID,\n\t\t\t'relay_id'            => Relay::toGlobalId( 'post', $post->ID ),\n\t\t\t'graphql_single_name' => $post_type_object->graphql_single_name,\n\t\t\t'graphql_plural_name' => $post_type_object->graphql_plural_name,\n\t\t\t'status'              => $new_status,\n\t\t];\n\n\t\t/**\n\t\t * Log an action\n\t\t */\n\t\t$this->log_action( $action );\n\n\t}\n\n\t/**\n\t * Logs actions when posts are deleted\n\t *\n\t * @param int $post_id The ID of the deleted post\n\t */\n\tpublic function callback_deleted_post( int $post_id ) {\n\n\t\t$post = get_post( $post_id );\n\n\t\t// If there is no post object, do nothing\n\t\tif ( ! is_a( $post, 'WP_Post' ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If the deleted post is of a post type that isn't being tracked, do nothing\n\t\tif ( ! $this->is_post_type_tracked( $post->post_type ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Ignore posts that were deleted that weren't published\n\t\tif ( 'publish' !== $post->post_status ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$post_type_object = get_post_type_object( $post->post_type );\n\n\t\t$action = [\n\t\t\t'action_type'         => 'DELETE',\n\t\t\t'title'               => $post->post_title,\n\t\t\t'node_id'             => $post->ID,\n\t\t\t'relay_id'            => Relay::toGlobalId( 'post', $post->ID ),\n\t\t\t'graphql_single_name' => $post_type_object->graphql_single_name,\n\t\t\t'graphql_plural_name' => $post_type_object->graphql_plural_name,\n\t\t\t'status'              => 'trash',\n\t\t];\n\n\t\t// Log the action\n\t\t$this->log_action( $action );\n\n\t\t// Log user update\n\t\t$this->log_user_update( $post );\n\n\t}\n\n\t/**\n\t * Whether the post type is tracked\n\t *\n\t * @param string $post_type The name of the post type to check\n\t *\n\t * @return bool\n\t */\n\tpublic function is_post_type_tracked( string $post_type ) {\n\t\treturn in_array( $post_type, $this->action_monitor->get_tracked_post_types(), true );\n\t}\n\n\t/**\n\t * Logs activity when meta is updated on posts\n\t *\n\t * @param int $meta_id ID of updated metadata entry.\n\t * @param int $object_id ID of the object metadata is for.\n\t * @param string $meta_key Metadata key.\n\t * @param mixed $meta_value Metadata value. Serialized if non-scalar.\n\t */\n\tpublic function callback_updated_post_meta( int $meta_id, int $object_id, string $meta_key, $meta_value ) {\n\n\t\t$post = get_post( $object_id );\n\n\t\tif ( empty( $post ) || ! is_a( $post, 'WP_Post' ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If the deleted post is of a post type that isn't being tracked, do nothing\n\t\tif ( ! $this->is_post_type_tracked( $post->post_type ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( 'publish' !== $post->post_status ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( false === $this->should_track_meta( $meta_key, $meta_value, $post ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$post_type_object = get_post_type_object( $post->post_type );\n\n\t\t$action = [\n\t\t\t'action_type'         => 'UPDATE',\n\t\t\t'title'               => $post->post_title,\n\t\t\t'node_id'             => $post->ID,\n\t\t\t'relay_id'            => Relay::toGlobalId( 'post', $post->ID ),\n\t\t\t'graphql_single_name' => $post_type_object->graphql_single_name,\n\t\t\t'graphql_plural_name' => $post_type_object->graphql_plural_name,\n\t\t\t'status'              => $post->post_status,\n\t\t];\n\n\t\t// Log the action\n\t\t$this->log_action( $action );\n\n\t}\n\n\t/**\n\t * Logs activity when meta is updated on posts\n\t *\n\t * @param string[] $meta_ids    An array of metadata entry IDs to delete.\n\t * @param int      $object_id   ID of the object metadata is for.\n\t * @param string   $meta_key    Metadata key.\n\t * @param mixed    $meta_value Metadata value. Serialized if non-scalar.\n\t */\n\tpublic function callback_deleted_post_meta( array $meta_ids, int $object_id, string $meta_key, $meta_value ) {\n\n\t\t$post = get_post( $object_id );\n\n\t\tif ( empty( $post ) || ! is_a( $post, 'WP_Post' ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If the deleted post is of a post type that isn't being tracked, do nothing\n\t\tif ( ! $this->is_post_type_tracked( $post->post_type ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( 'publish' !== $post->post_status ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( false === $this->should_track_meta( $meta_key, $meta_value, $post ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$post_type_object = get_post_type_object( $post->post_type );\n\n\t\t$action = [\n\t\t\t'action_type'         => 'UPDATE',\n\t\t\t'title'               => $post->post_title,\n\t\t\t'node_id'             => $post->ID,\n\t\t\t'relay_id'            => Relay::toGlobalId( 'post', $post->ID ),\n\t\t\t'graphql_single_name' => $post_type_object->graphql_single_name,\n\t\t\t'graphql_plural_name' => $post_type_object->graphql_plural_name,\n\t\t\t'status'              => $post->post_status,\n\t\t];\n\n\t\t// Log the action\n\t\t$this->log_action( $action );\n\n\t}\n\n\t/**\n\t * Log a user update when a post is created or deleted, telling Gatsby to\n\t * invalidate user caches\n\t *\n\t * @param WP_Post $post The post data of the Post being updated\n\t *\n\t * @todo:\n\t *      This should be able to be removed at some point as Gatsby\n\t *      _should_ be able to handle bi-directional relationships implicitly. When a Post is\n\t *      created, Gatsby queries the full post fields, including the Author.node.id, and should\n\t *      be able to handle the relationship between the new post and the author. When a post is\n\t *      deleted, Gatsby should remove the post node and any queries (such as author archive pages)\n\t *      that include references to the deleted post node should automatically be updated by Gatsby.\n\t */\n\tpublic function log_user_update( WP_Post $post ) {\n\n\t\tif ( empty( $post->post_author ) || ! absint( $post->post_author ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$user = get_user_by( 'id', absint( $post->post_author ) );\n\n\t\tif ( ! $user || 0 === $user->ID ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$user_monitor = $this->action_monitor->get_action_monitor( 'UserMonitor' );\n\n\t\tif ( empty( $user_monitor ) || ! $user_monitor instanceof UserMonitor ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! $user_monitor->is_published_author( $user->ID ) ) {\n\t\t\t$action_type = 'DELETE';\n\t\t\t$status      = 'trash';\n\t\t} else {\n\t\t\t$action_type = 'UPDATE';\n\t\t\t$status      = 'publish';\n\t\t}\n\n\t\t$this->log_action(\n\t\t\t[\n\t\t\t\t'action_type'         => $action_type,\n\t\t\t\t'title'               => $user->display_name,\n\t\t\t\t'node_id'             => $user->ID,\n\t\t\t\t'relay_id'            => Relay::toGlobalId( 'user', $user->ID ),\n\t\t\t\t'graphql_single_name' => 'user',\n\t\t\t\t'graphql_plural_name' => 'users',\n\t\t\t\t'status'              => $status,\n\t\t\t]\n\t\t);\n\t}\n\n}\n"
  },
  {
    "path": "src/ActionMonitor/Monitors/PostTypeMonitor.php",
    "content": "<?php\nnamespace WPGatsby\\ActionMonitor\\Monitors;\n\nclass PostTypeMonitor extends Monitor {\n\n\t/**\n\t * @var array List of registered post types that Gatsby tracks\n\t */\n\tpublic $current_post_types;\n\n\t/**\n\t * @var array List of post types that were previously registered\n\t */\n\tpublic $prev_post_types;\n\n\t/**\n\t * @var string The option name that's used to cache the tracked post types\n\t */\n\tpublic $option_name;\n\n\t/**\n\t * Initialize the PostTypeMonitor\n\t *\n\t * @return mixed|void\n\t */\n\tpublic function init() {\n\n\t\t// Set the option name that's used to cache post types\n\t\t$this->option_name = '_gatsby_tracked_post_types';\n\n\t\t// Check to see if the post types are different\n\t\tadd_action( 'gatsby_init_action_monitors', [ $this, 'check_post_types' ], 999 );\n\n\t}\n\n\t/**\n\t * Check post types and trigger a Schema diff if detected\n\t */\n\tpublic function check_post_types() {\n\n\t\t$this->current_post_types = array_keys( $this->action_monitor->get_tracked_post_types() );\n\t\t$this->prev_post_types    = get_option( $this->option_name, [] );\n\n\t\tif ( empty( $this->prev_post_types ) ) {\n\t\t\tupdate_option( $this->option_name, $this->current_post_types );\n\t\t\treturn;\n\t\t}\n\n\t\t/**\n\t\t * If the current_post_types and prev_post_types do not match,\n\t\t * update the option and cache the tracked post types\n\t\t */\n\t\tif ( $this->current_post_types === $this->prev_post_types ) {\n\t\t\treturn;\n\t\t}\n\n\t\tupdate_option( $this->option_name, $this->current_post_types );\n\n\t\t// Check for added post types\n\t\t$added = array_diff( $this->current_post_types, $this->prev_post_types );\n\n\t\t// Check for removed post types\n\t\t$removed = array_diff( $this->prev_post_types, $this->current_post_types );\n\n\t\t// if there are\n\t\tif ( ! empty( $added ) ) {\n\t\t\t$this->trigger_schema_diff(\n\t\t\t\t[\n\t\t\t\t\t'title' => __( 'Post Type added', 'WPGatsby' ),\n\t\t\t\t]\n\t\t\t);\n\t\t}\n\n\t\tif ( ! empty( $removed ) ) {\n\t\t\t$this->trigger_schema_diff(\n\t\t\t\t[\n\t\t\t\t\t'title' => __( 'Post type removed', 'WPGatsby' ),\n\t\t\t\t]\n\t\t\t);\n\t\t}\n\t}\n\n}\n"
  },
  {
    "path": "src/ActionMonitor/Monitors/PreviewMonitor.php",
    "content": "<?php\n\nnamespace WPGatsby\\ActionMonitor\\Monitors;\n\nuse GraphQLRelay\\Relay;\nuse WPGatsby\\Admin\\Preview;\nuse WPGatsby\\Admin\\Settings;\n\nclass PreviewMonitor extends Monitor {\n\tfunction init() {\n\t\t$enable_gatsby_preview = Settings::get_setting( 'enable_gatsby_preview' ) === 'on';\n\n\t\tif ( $enable_gatsby_preview ) {\n\t\t\tadd_filter( 'template_include', [ $this, 'setup_preview_template' ], 1, 99 );\n\n\t\t\tadd_filter( 'preview_post_link', function( $link, $post ) {\n\t\t\t\t$doing_graphql_request\n\t\t\t\t\t= defined( 'GRAPHQL_REQUEST' ) && true === GRAPHQL_REQUEST;\n\n\t\t\t\t// Use the normal $link during graphql requests\n\t\t\t\t// because otherwise we could override the post URI\n\t\t\t\t// in Gatsby! meaning the content sync or preview url could be added to the page path in Gatsby if pages are created from the uri.\n\t\t\t\tif ( $doing_graphql_request ) {\n\t\t\t\t\treturn $link;\n\t\t\t\t}\n\n\t\t\t\treturn \\add_query_arg( 'gatsby_preview', 'true', $link );\n\t\t\t}, 10, 2 );\n\t\t}\n\t}\n\n\t/**\n\t * Determines wether or not the current global \n\t * PHP context is related to Gatsby Content Sync Previews\n\t */\n\tpublic static function is_gatsby_content_sync_preview() {\n\t\t$doing_graphql_request\n\t\t\t\t\t= defined( 'GRAPHQL_REQUEST' ) && null !== GRAPHQL_REQUEST;\n\n\t\tif ( $doing_graphql_request ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t$enable_gatsby_preview = Settings::get_setting( 'enable_gatsby_preview' ) === 'on';\n\n\t\t$is_gatsby_content_sync_preview \n\t\t\t= \\is_preview()\n\t\t\t|| isset( $_GET['preview_nonce'] )\n\t\t\t|| isset( $_GET['gatsby_preview'] );\n\n\t\treturn $is_gatsby_content_sync_preview && $enable_gatsby_preview;\n\t}\n\n\t/**\n\t * If specific conditions are met, this loads the Gatsby Preview template\n\t * instead of the core WordPress preview template\n\t *\n\t * @param string $template The template to load\n\t *\n\t * @return string\n\t */\n\tpublic function setup_preview_template( $template ) {\n\t\tglobal $post;\n\n\t\t// If the global post isn't set, but the preview_id is passed, use that to determine\n\t\t// the preview post\n\t\tif ( empty( $post ) && isset( $_GET['preview_id'] ) ) {\n\t\t\t$post = get_post( $_GET['preview_id'] );\n\t\t}\n\n\t\tif ( self::is_gatsby_content_sync_preview() && $post ) {\n\t\t\t// Ensure the post_type is set to show_in_graphql\n\t\t\t$post_type_object = $post->post_type ? get_post_type_object( $post->post_type ) : null;\n\n\t\t\tif ( $post_type_object && ! $post_type_object->show_in_graphql ?? true ) {\n\t\t\t\treturn plugin_dir_path( __FILE__ ) . '../../Admin/includes/post-type-not-shown-in-graphql.php';\n\t\t\t}\n\n\t\t\t// WP doesn't call post_save for every second preview with no content changes.\n\t\t\t// Since we're using post_save to trigger the webhook to Gatsby, we need to get WP to call post_save for this post.\n\t\t\tdo_action( 'save_post', $post->ID, $post, true );\n\n\t\t\t$this->post_to_preview_instance( $post->ID, $post );\n\t\t\n\t\t\treturn trailingslashit( dirname( __FILE__ ) ) . '../../Admin/includes/preview-template.php';\n\t\t}\n\n\t\treturn $template;\n\t}\n\n\t/**\n\t * Send a Preview to Gatsby\n\t */\n\tpublic function post_to_preview_instance( $post_ID, $post ) {\n\t\t$revisions_are_disabled = \n\t\t\t! wp_revisions_enabled( $post );\n\n\t\tif (\n\t\t\tdefined( 'DOING_AUTOSAVE' )\n\t\t\t&& DOING_AUTOSAVE\n\t\t\t// if revisions are disabled, our autosave is our preview\n\t\t\t&& ! $revisions_are_disabled\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( $post->post_type === 'action_monitor' ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( $post->post_status === 'auto-draft'  ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$is_draft = $post->post_status === 'draft';\n\n\t\t$is_new_post_draft =\n\t\t\t(\n\t\t\t\t$post->post_status === 'auto-draft'\n\t\t\t\t|| $post->post_status === 'draft'\n\t\t\t) &&\n\t\t\t$post->post_date_gmt === '0000-00-00 00:00:00';\n\n\t\t$is_revision = $post->post_type === 'revision';\n\t\t$is_draft = $post->post_status === 'draft';\n\n\t\t$is_gatsby_content_sync_preview = self::is_gatsby_content_sync_preview();\n\n\n\t\tif (\n\t\t\t! $is_draft\n\t\t\t&& ! $is_revision\n\t\t\t&& ! $is_new_post_draft\n\t\t\t&& ! $is_gatsby_content_sync_preview\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\t$token = \\WPGatsby\\GraphQL\\Auth::get_token();\n\n\t\tif ( ! $token ) {\n\t\t\terror_log(\n\t\t\t\t'Please set a JWT token in WPGatsby to enable Preview support.'\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\t$preview_webhook = $this::get_gatsby_preview_webhook();\n\n\t\t$original_post = get_post( $post->post_parent );\n\n\t\t$this_is_a_publish_not_a_preview = \n\t\t\t$original_post\n\t\t\t&& $original_post->post_modified === $post->post_modified\n\t\t\t&& ! $is_gatsby_content_sync_preview;\n\n\t\t\t\n\t\tif ( $this_is_a_publish_not_a_preview ) {\n\t\t\t// we will handle this in ActionMonitor.php, not here.\n\t\t\treturn;\n\t\t}\n\n\t\t$post_type_object = $original_post\n\t\t\t? \\get_post_type_object( $original_post->post_type )\n\t\t\t: \\get_post_type_object( $post->post_type );\n\n\t\tif ( ! $post_type_object->show_in_graphql ?? true ) {\n\t\t\t// if the post type doesn't have show_in_graphql set,\n\t\t\t// we don't want to send a preview webhook for this post type.\n\t\t\treturn;\n\t\t}\n\t\t\n\t\t$parent_post_id = $original_post->ID ?? $post_ID;\n\n\t\t$global_relay_id = Relay::toGlobalId(\n\t\t\t'post',\n\t\t\t// sometimes this is a draft instead of a revision\n\t\t\t// so we can't expect original post to exist.\n\t\t\tabsint( $original_post->ID ?? $post_ID )\n\t\t);\n\n\t\t$referenced_node_single_name\n\t\t\t= $post_type_object->graphql_single_name ?? null;\n\n\t\t$referenced_node_single_name_normalized = lcfirst(\n\t\t\t$referenced_node_single_name\n\t\t);\n\n\t\t$referenced_node_plural_name\n\t\t\t= $post_type_object->graphql_plural_name ?? null;\n\n\t\t$referenced_node_plural_name_normalized = lcfirst(\n\t\t\t$referenced_node_plural_name\n\t\t);\n\n\t\t$graphql_endpoint = apply_filters( 'graphql_endpoint', 'graphql' );\n\n\t\t$graphql_url = get_site_url() . '/' . ltrim( $graphql_endpoint, '/' );\n\n\t\t$preview_data = [\n\t\t\t'previewDatabaseId' => $post_ID,\n\t\t\t'id'                => $global_relay_id,\n\t\t\t'singleName'        => $referenced_node_single_name_normalized,\n\t\t\t'isDraft'           => $is_draft,\n\t\t\t'remoteUrl'         => $graphql_url,\n\t\t\t'modified'          => $post->post_modified,\n\t\t\t'parentDatabaseId'  => $post->post_parent,\n\t\t\t'userDatabaseId'    => get_current_user_id(),\n\t\t];\n\t\t\n\t\t$post_body = array_merge(\n\t\t\t$preview_data,\n\t\t\t[\n\t\t\t\t'token' => $token\n\t\t\t]\n\t\t);\n\n\t\t$this->log_action( [\n\t\t\t'action_type'         => 'UPDATE',\n\t\t\t'title'               => $post->post_title,\n\t\t\t'node_id'             => $parent_post_id,\n\t\t\t'relay_id'            => $global_relay_id,\n\t\t\t'graphql_single_name' => $referenced_node_single_name_normalized,\n\t\t\t'graphql_plural_name' => $referenced_node_plural_name_normalized,\n\t\t\t// everything that should show in Gatsby is publish\n\t\t\t// as far as Gatsby is concerned.\n\t\t\t'status'              => 'publish',\n\t\t\t'stream_type'         => 'PREVIEW',\n\t\t\t'preview_data'        => wp_json_encode( $preview_data ),\n\t\t] );\n\n\t\t// @todo move this to shutdown hook to prevent race conditions\n\t\t$response = wp_remote_post(\n\t\t\t$preview_webhook,\n\t\t\t[\n\t\t\t\t'body'        => wp_json_encode( $post_body ),\n\t\t\t\t'headers'     => [\n\t\t\t\t\t'Content-Type' => 'application/json; charset=utf-8',\n\t\t\t\t],\n\t\t\t\t'method'      => 'POST',\n\t\t\t\t'data_format' => 'body',\n\t\t\t]\n\t\t);\n\n\t\tif ( \\is_wp_error( $response ) ) {\n\t\t\terror_log( \"WPGatsby couldn\\'t POST to the Preview webhook set in plugin options.\\nWebhook returned error: {$response->get_error_message()}\" );\n\t\t}\n\t}\n\n\t/**\n\t * Get the Gatsby Preview instance refresh webhook\n\t */\n\tstatic function get_gatsby_preview_webhook() {\n\t\t$preview_webhook = Settings::get_setting( 'preview_api_webhook' );\n\n\t\tif ( ! $preview_webhook || ! filter_var( $preview_webhook, FILTER_VALIDATE_URL ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif ( substr( $preview_webhook, -1 ) !== '/' ) {\n\t\t\t$preview_webhook .= '/';\n\t\t}\n\n\t\treturn $preview_webhook;\n\t}\n}\n"
  },
  {
    "path": "src/ActionMonitor/Monitors/SettingsMonitor.php",
    "content": "<?php\nnamespace WPGatsby\\ActionMonitor\\Monitors;\n\nuse GraphQLRelay\\Relay;\n\nclass SettingsMonitor extends Monitor {\n\n\t/**\n\t * @return mixed|void\n\t */\n\tpublic function init() {\n\n\t\tadd_action( 'updated_option', [ $this, 'callback_update_option' ], 10, 3 );\n\t\tadd_action( 'update_option_page_on_front', [ $this, 'callback_update_page_on_front' ], 10, 3 );\n\t\tadd_action( 'update_option_page_for_posts', [ $this, 'callback_update_page_for_posts' ], 10, 3 );\n\t\tadd_action( 'update_option_permalink_structure', [ $this, 'callback_update_permalink_structure' ], 10, 3 );\n\n\t}\n\n\t/**\n\t * Determines whether the option should be tracked by the Gatsby Action monitor\n\t *\n\t * @param string $option_name Name of the option to update.\n\t * @param mixed  $old_value   The old option value.\n\t * @param mixed  $value       The new option value.\n\t *\n\t * @return bool\n\t */\n\tprotected function should_track_option( string $option_name, $old_value, $value ) {\n\n\t\t/**\n\t\t * This filter allows plugins to opt-in or out of tracking for options.\n\t\t *\n\t\t * @param bool $should_track Whether the meta key should be tracked.\n\t\t * @param string $option_name Name of the option to update.\n\t\t * @param mixed  $old_value   The old option value.\n\t\t * @param mixed  $value       The new option value.\n\t\t *\n\t\t * @param bool $tracked whether the meta key is tracked by Gatsby Action Monitor\n\t\t */\n\t\t$should_track = apply_filters( 'gatsby_action_monitor_should_track_option', null, $option_name, $old_value, $value );\n\n\t\t// If the filter has been applied return it\n\t\tif ( null !== $should_track ) {\n\t\t\treturn (bool) $should_track;\n\t\t}\n\n\t\t// Options that are allowed to be tracked by default\n\t\t$tracked_option_names = apply_filters(\n\t\t\t'gatsby_action_monitor_tracked_option_names',\n\t\t\t[\n\t\t\t\t'siteurl',\n\t\t\t\t'home',\n\t\t\t\t'blogname',\n\t\t\t\t'blogdescription',\n\t\t\t\t'start_of_week',\n\t\t\t\t'default_category',\n\t\t\t\t'default_comment_status',\n\t\t\t\t'posts_per_page',\n\t\t\t\t'date_format',\n\t\t\t\t'time_format',\n\t\t\t\t'blog_charset',\n\t\t\t\t'active_plugins',\n\t\t\t\t'category_base',\n\t\t\t\t'gmt_offset',\n\t\t\t\t'template',\n\t\t\t\t'stylesheet',\n\t\t\t\t'comment_registration',\n\t\t\t\t'default_role',\n\t\t\t\t'show_on_front',\n\t\t\t\t'tag_base',\n\t\t\t\t'show_avatars',\n\t\t\t\t'avatar_rating',\n\t\t\t\t'upload_url_path',\n\t\t\t\t'comments_per_page',\n\t\t\t\t'default_comments_page',\n\t\t\t\t'comment_order',\n\t\t\t\t'sticky_posts',\n\t\t\t\t'timezone_string',\n\t\t\t\t'default_post_format',\n\t\t\t\t'site_icon',\n\t\t\t\t'current_theme',\n\t\t\t]\n\t\t);\n\n\t\tif ( in_array( $option_name, $tracked_option_names, true ) ) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// If the meta key starts with an underscore, don't track it\n\t\tif ( '_' === substr( $option_name, 0, 1 ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn false;\n\n\t}\n\n\t/**\n\t * Log actions when options are updated\n\t *\n\t * @param string $option_name Name of the option to update.\n\t * @param mixed  $old_value   The old option value.\n\t * @param mixed  $value       The new option value.\n\t */\n\tpublic function callback_update_option( string $option_name, $old_value, $value ) {\n\n\t\tif ( ! $this->should_track_option( $option_name, $old_value, $value ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$this->trigger_non_node_root_field_update(\n\t\t\t[\n\t\t\t\t'title' => __( 'Update Setting: ', 'WPGatsby' ) . ' ' . $option_name,\n\t\t\t]\n\t\t);\n\t}\n\n\t/**\n\t * Log action when permalink_structure is changed\n\t *\n\t * @param mixed  $old_value   The old option value.\n\t * @param mixed  $new_value   The new option value.\n\t * @param string $option_name Name of the option to update.\n\t */\n\tpublic function callback_update_permalink_structure( $old_value, $new_value, string $option_name ) {\n\n\t\tif ( $old_value === $new_value ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$this->trigger_refetch_all(\n\t\t\t[\n\t\t\t\t'title' => __( 'Permalink structure updated', 'WPGatsby' ),\n\t\t\t]\n\t\t);\n\n\t}\n\n\t/**\n\t * Log action when page_on_front is changed\n\t *\n\t * @param mixed  $old_value   The old option value.\n\t * @param mixed  $new_value   The new option value.\n\t * @param string $option_name Name of the option to update.\n\t */\n\tpublic function callback_update_page_on_front( $old_value, $new_value, string $option_name ) {\n\n\t\tif ( (int) $old_value === (int) $new_value ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$old_page = get_post( absint( $old_value ) );\n\t\t$new_page = get_post( absint( $new_value ) );\n\n\t\tif ( $old_page instanceof \\WP_Post ) {\n\n\t\t\t$this->log_action(\n\t\t\t\t[\n\t\t\t\t\t'action_type'         => 'UPDATE',\n\t\t\t\t\t'title'               => $old_page->post_title,\n\t\t\t\t\t'node_id'             => $old_page->ID,\n\t\t\t\t\t'relay_id'            => Relay::toGlobalId( 'post', $old_page->ID ),\n\t\t\t\t\t'graphql_single_name' => get_post_type_object( $old_page->post_type )->graphql_single_name,\n\t\t\t\t\t'graphql_plural_name' => get_post_type_object( $old_page->post_type )->graphql_plural_name,\n\t\t\t\t\t'status'              => $old_page->post_status,\n\t\t\t\t]\n\t\t\t);\n\t\t}\n\n\t\tif ( $new_page instanceof \\WP_Post ) {\n\n\t\t\t$this->log_action(\n\t\t\t\t[\n\t\t\t\t\t'action_type'         => 'UPDATE',\n\t\t\t\t\t'title'               => $new_page->post_title,\n\t\t\t\t\t'node_id'             => $new_page->ID,\n\t\t\t\t\t'relay_id'            => Relay::toGlobalId( 'post', $new_page->ID ),\n\t\t\t\t\t'graphql_single_name' => get_post_type_object( $new_page->post_type )->graphql_single_name,\n\t\t\t\t\t'graphql_plural_name' => get_post_type_object( $new_page->post_type )->graphql_plural_name,\n\t\t\t\t\t'status'              => $new_page->post_status,\n\t\t\t\t]\n\t\t\t);\n\n\t\t}\n\t}\n\n\t/**\n\t * Log action when page_for_posts is changed\n\t *\n\t * @param mixed  $old_value   The old option value.\n\t * @param mixed  $new_value   The new option value.\n\t * @param string $option_name Name of the option to update.\n\t */\n\tpublic function callback_update_page_for_posts( $old_value, $new_value, string $option_name ) {\n\n\t\tif ( (int) $old_value === (int) $new_value ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$old_page = get_post( absint( $old_value ) );\n\t\t$new_page = get_post( absint( $new_value ) );\n\n\t\tif ( $old_page instanceof \\WP_Post ) {\n\n\t\t\t$this->log_action(\n\t\t\t\t[\n\t\t\t\t\t'action_type'         => 'UPDATE',\n\t\t\t\t\t'title'               => $old_page->post_title,\n\t\t\t\t\t'node_id'             => $old_page->ID,\n\t\t\t\t\t'relay_id'            => Relay::toGlobalId( 'post', $old_page->ID ),\n\t\t\t\t\t'graphql_single_name' => get_post_type_object( $old_page->post_type )->graphql_single_name,\n\t\t\t\t\t'graphql_plural_name' => get_post_type_object( $old_page->post_type )->graphql_plural_name,\n\t\t\t\t\t'status'              => $old_page->post_status,\n\t\t\t\t]\n\t\t\t);\n\t\t} else {\n\t\t\t$this->log_action(\n\t\t\t\t[\n\t\t\t\t\t'action_type'         => 'UPDATE',\n\t\t\t\t\t'title'               => 'Change page on front away from posts',\n\t\t\t\t\t'node_id'             => 'post',\n\t\t\t\t\t'relay_id'            => Relay::toGlobalId( 'post_type', 'post' ),\n\t\t\t\t\t'graphql_single_name' => 'contentType',\n\t\t\t\t\t'graphql_plural_name' => 'contentTypes',\n\t\t\t\t\t'status'              => 'publish',\n\t\t\t\t]\n\t\t\t);\n\t\t}\n\n\t\tif ( $new_page instanceof \\WP_Post ) {\n\n\t\t\t$this->log_action(\n\t\t\t\t[\n\t\t\t\t\t'action_type'         => 'UPDATE',\n\t\t\t\t\t'title'               => $new_page->post_title,\n\t\t\t\t\t'node_id'             => $new_page->ID,\n\t\t\t\t\t'relay_id'            => Relay::toGlobalId( 'post', $new_page->ID ),\n\t\t\t\t\t'graphql_single_name' => get_post_type_object( $new_page->post_type )->graphql_single_name,\n\t\t\t\t\t'graphql_plural_name' => get_post_type_object( $new_page->post_type )->graphql_plural_name,\n\t\t\t\t\t'status'              => $new_page->post_status,\n\t\t\t\t]\n\t\t\t);\n\n\t\t} else {\n\n\t\t\t$this->log_action(\n\t\t\t\t[\n\t\t\t\t\t'action_type'         => 'UPDATE',\n\t\t\t\t\t'title'               => 'Set page on front to posts',\n\t\t\t\t\t'node_id'             => 'post',\n\t\t\t\t\t'relay_id'            => Relay::toGlobalId( 'post_type', 'post' ),\n\t\t\t\t\t'graphql_single_name' => 'contentType',\n\t\t\t\t\t'graphql_plural_name' => 'contentTypes',\n\t\t\t\t\t'status'              => 'publish',\n\t\t\t\t]\n\t\t\t);\n\n\t\t}\n\t}\n\n}\n"
  },
  {
    "path": "src/ActionMonitor/Monitors/TaxonomyMonitor.php",
    "content": "<?php\nnamespace WPGatsby\\ActionMonitor\\Monitors;\n\nclass TaxonomyMonitor extends Monitor {\n\n\t/**\n\t * @var array List of registered taxonomies that Gatsby tracks\n\t */\n\tpublic $current_taxonomies;\n\n\t/**\n\t * @var array List of taxonomies that were previously registered\n\t */\n\tpublic $prev_taxonomies;\n\n\t/**\n\t * @var string The option name that's used to cache the tracked taxonomies\n\t */\n\tpublic $option_name;\n\n\t/**\n\t * Initialize the TaxonomyMonitor\n\t *\n\t * @return mixed|void\n\t */\n\tpublic function init() {\n\n\t\t// Set the option name that's used to cache taxonomies\n\t\t$this->option_name = '_gatsby_tracked_taxonomies';\n\n\t\t// Check to see if the taxonomies are different\n\t\tadd_action( 'gatsby_init_action_monitors', [ $this, 'check_taxonomies' ], 999 );\n\n\t}\n\n\t/**\n\t * Check taxonomies and trigger a Schema diff if detected\n\t */\n\tpublic function check_taxonomies() {\n\n\t\t$this->current_taxonomies = array_keys( $this->action_monitor->get_tracked_taxonomies() );\n\t\t$this->prev_taxonomies    = get_option( $this->option_name, [] );\n\n\t\tif ( empty( $this->prev_taxonomies ) ) {\n\t\t\tupdate_option( $this->option_name, $this->current_taxonomies );\n\t\t\treturn;\n\t\t}\n\n\t\t/**\n\t\t * If the current_taxonomies and prev_taxonomies do not match,\n\t\t * update the option and cache the tracked taxonomies\n\t\t */\n\t\tif ( $this->current_taxonomies === $this->prev_taxonomies ) {\n\t\t\treturn;\n\t\t}\n\n\t\tupdate_option( $this->option_name, $this->current_taxonomies );\n\n\t\t// Check for added taxonomies\n\t\t$added = array_diff( $this->current_taxonomies, $this->prev_taxonomies );\n\n\t\t// Check for removed taxonomies\n\t\t$removed = array_diff( $this->prev_taxonomies, $this->current_taxonomies );\n\n\t\t// if there are\n\t\tif ( ! empty( $added ) ) {\n\t\t\t$this->trigger_schema_diff(\n\t\t\t\t[\n\t\t\t\t\t'title' => __( 'Taxonomy added', 'WPGatsby' ),\n\t\t\t\t]\n\t\t\t);\n\t\t}\n\n\t\tif ( ! empty( $removed ) ) {\n\t\t\t$this->trigger_schema_diff(\n\t\t\t\t[\n\t\t\t\t\t'title' => __( 'Taxonomy removed', 'WPGatsby' ),\n\t\t\t\t]\n\t\t\t);\n\t\t}\n\t}\n\n}\n"
  },
  {
    "path": "src/ActionMonitor/Monitors/TermMonitor.php",
    "content": "<?php\n\nnamespace WPGatsby\\ActionMonitor\\Monitors;\n\nuse GraphQLRelay\\Relay;\nuse WP_Taxonomy;\nuse WP_Term;\n\nclass TermMonitor extends Monitor {\n\n\t/**\n\t * Caches terms before they're deleted\n\t *\n\t * @var array\n\t */\n\tpublic $terms_before_delete = [];\n\n\t/**\n\t * @return mixed|void\n\t */\n\tpublic function init() {\n\n\t\tadd_action( 'created_term', [ $this, 'callback_created_term' ], 10, 3 );\n\t\tadd_action( 'pre_delete_term', [ $this, 'callback_pre_delete_term' ], 10, 2 );\n\t\tadd_action( 'delete_term', [ $this, 'callback_delete_term' ], 10, 4 );\n\t\tadd_action( 'edited_term', [ $this, 'callback_edited_term' ], 10, 3 );\n\t\tadd_action( 'added_term_meta', [ $this, 'callback_updated_term_meta' ], 10, 4 );\n\t\tadd_action( 'updated_term_meta', [ $this, 'callback_updated_term_meta' ], 10, 4 );\n\t\tadd_action( 'deleted_term_meta', [ $this, 'callback_deleted_term_meta' ], 10, 4 );\n\n\t}\n\n\t/**\n\t * Whether the taxonomy is tracked\n\t *\n\t * @param string $taxonomy The name of the taxonomy to check\n\t *\n\t * @return bool\n\t */\n\tpublic function is_taxonomy_tracked( string $taxonomy ) {\n\t\treturn in_array( $taxonomy, $this->action_monitor->get_tracked_taxonomies(), true );\n\t}\n\n\t/**\n\t * Tracks creation of terms\n\t *\n\t * @param int    $term_id  Term ID.\n\t * @param int    $tt_id    Taxonomy term ID.\n\t * @param string $taxonomy Taxonomy name.\n\t */\n\tpublic function callback_created_term( int $term_id, int $tt_id, string $taxonomy ) {\n\n\t\t$tax_object = get_taxonomy( $taxonomy );\n\n\t\t// If the term is in a taxonomy that's not being tracked, ignore it\n\t\tif ( false === $tax_object || ! $this->is_taxonomy_tracked( $taxonomy ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$term = get_term( $term_id, $taxonomy );\n\n\t\tif ( ! is_a( $term, 'WP_Term' ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$this->log_action(\n\t\t\t[\n\t\t\t\t'action_type'         => 'CREATE',\n\t\t\t\t'title'               => $term->name,\n\t\t\t\t'node_id'             => $term->term_id,\n\t\t\t\t'relay_id'            => Relay::toGlobalId( 'term', $term->term_id ),\n\t\t\t\t'graphql_single_name' => $tax_object->graphql_single_name,\n\t\t\t\t'graphql_plural_name' => $tax_object->graphql_plural_name,\n\t\t\t\t'status'              => 'publish',\n\t\t\t]\n\t\t);\n\n\t\tif ( true === $tax_object->hierarchical ) {\n\t\t\t$this->update_hierarchical_relatives( $term, $tax_object );\n\t\t}\n\n\t}\n\n\t/**\n\t * @param int $term_id The ID of the term object being deleted\n\t * @param string $taxonomy The name of the taxonomy of the term being deleted\n\t */\n\tpublic function callback_pre_delete_term( int $term_id, string $taxonomy ) {\n\n\t\t$term = get_term_by( 'id', $term_id, $taxonomy );\n\n\t\tif ( ! $term instanceof WP_Term ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$before_delete = [\n\t\t\t'term' => $term,\n\t\t];\n\n\t\tif ( true === get_taxonomy( $taxonomy )->hierarchical ) {\n\t\t\t$term_children = get_term_children( $term->term_id, $taxonomy );\n\t\t\tif ( ! empty( $term_children ) ) {\n\t\t\t\t$before_delete['children'] = $term_children;\n\t\t\t}\n\t\t}\n\n\t\t$this->terms_before_delete[ $term->term_id ] = $before_delete;\n\t}\n\n\t/**\n\t * Tracks deletion of taxonomy terms\n\t *\n\t * @param int    $term_id      Term ID.\n\t * @param int    $tt_id        Taxonomy term ID.\n\t * @param string $taxonomy     Taxonomy name.\n\t * @param mixed  $deleted_term Deleted term object.\n\t */\n\tpublic function callback_delete_term( int $term_id, int $tt_id, string $taxonomy, $deleted_term ) {\n\n\t\t$tax_object = get_taxonomy( $taxonomy );\n\n\t\tif ( false === $tax_object || ! $this->is_taxonomy_tracked( $taxonomy ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$this->log_action(\n\t\t\t[\n\t\t\t\t'action_type'         => 'DELETE',\n\t\t\t\t'title'               => $deleted_term->name,\n\t\t\t\t'node_id'             => $deleted_term->term_id,\n\t\t\t\t'relay_id'            => Relay::toGlobalId( 'term', $deleted_term->term_id ),\n\t\t\t\t'graphql_single_name' => $tax_object->graphql_single_name,\n\t\t\t\t'graphql_plural_name' => $tax_object->graphql_plural_name,\n\t\t\t\t'status'              => 'trash',\n\t\t\t]\n\t\t);\n\n\t\tif ( true === $tax_object->hierarchical ) {\n\t\t\t$this->update_hierarchical_relatives( $deleted_term, $tax_object );\n\t\t}\n\n\t}\n\n\t/**\n\t * Tracks updated of taxonomy terms\n\t *\n\t * @param int    $term_id  Term ID.\n\t * @param int    $tt_id    Taxonomy term ID.\n\t * @param string $taxonomy Taxonomy name.\n\t */\n\tpublic function callback_edited_term( int $term_id, int $tt_id, string $taxonomy ) {\n\n\t\t$tax_object = get_taxonomy( $taxonomy );\n\n\t\tif ( false === $tax_object || ! $this->is_taxonomy_tracked( $taxonomy ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$term = get_term( $term_id, $taxonomy );\n\n\t\t$this->log_action(\n\t\t\t[\n\t\t\t\t'action_type'         => 'UPDATE',\n\t\t\t\t'title'               => $term->name,\n\t\t\t\t'node_id'             => $term->term_id,\n\t\t\t\t'relay_id'            => Relay::toGlobalId( 'term', $term->term_id ),\n\t\t\t\t'graphql_single_name' => $tax_object->graphql_single_name,\n\t\t\t\t'graphql_plural_name' => $tax_object->graphql_plural_name,\n\t\t\t\t'status'              => 'publish',\n\t\t\t]\n\t\t);\n\n\t\tif ( true === $tax_object->hierarchical ) {\n\t\t\t$this->update_hierarchical_relatives( $term, $tax_object );\n\t\t}\n\n\t}\n\n\tpublic function update_hierarchical_relatives( WP_Term $term, WP_Taxonomy $tax_object ) {\n\n\t\t$taxonomy = $tax_object->name;\n\n\t\tif ( true === $tax_object->hierarchical ) {\n\n\t\t\tif ( ! empty( $term->parent ) ) {\n\n\t\t\t\t$parent = get_term_by( 'id', absint( $term->parent ), $taxonomy );\n\n\t\t\t\tif ( is_a( $parent, 'WP_Term' ) ) {\n\t\t\t\t\t$this->log_action(\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t'action_type'         => 'UPDATE',\n\t\t\t\t\t\t\t'title'               => $parent->name . ' Parent',\n\t\t\t\t\t\t\t'node_id'             => $parent->term_id,\n\t\t\t\t\t\t\t'relay_id'            => Relay::toGlobalId( 'term', $parent->term_id ),\n\t\t\t\t\t\t\t'graphql_single_name' => $tax_object->graphql_single_name,\n\t\t\t\t\t\t\t'graphql_plural_name' => $tax_object->graphql_plural_name,\n\t\t\t\t\t\t\t'status'              => 'publish',\n\t\t\t\t\t\t]\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( isset( $this->terms_before_delete[ $term->term_id ]['children'] ) ) {\n\n\t\t\t\t$child_ids = $this->terms_before_delete[ $term->term_id ]['children'];\n\n\t\t\t} else {\n\t\t\t\t$child_ids = get_term_children( $term->term_id, $taxonomy );\n\t\t\t}\n\n\t\t\tif ( ! empty( $child_ids ) && is_array( $child_ids ) ) {\n\t\t\t\tforeach ( $child_ids as $child_term_id ) {\n\n\t\t\t\t\t$child_term = get_term_by( 'id', $child_term_id, $taxonomy );\n\n\t\t\t\t\tif ( ! empty( $child_term ) ) {\n\n\t\t\t\t\t\t$this->log_action(\n\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t'action_type'         => 'UPDATE',\n\t\t\t\t\t\t\t\t'title'               => $child_term->name . ' Parent',\n\t\t\t\t\t\t\t\t'node_id'             => $child_term->term_id,\n\t\t\t\t\t\t\t\t'relay_id'            => Relay::toGlobalId( 'term', $child_term->term_id ),\n\t\t\t\t\t\t\t\t'graphql_single_name' => $tax_object->graphql_single_name,\n\t\t\t\t\t\t\t\t'graphql_plural_name' => $tax_object->graphql_plural_name,\n\t\t\t\t\t\t\t\t'status'              => 'publish',\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t);\n\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t}\n\n\t/**\n\t * Logs activity when meta is updated on terms\n\t *\n\t * @param int $meta_id ID of updated metadata entry.\n\t * @param int $object_id ID of the object metadata is for.\n\t * @param string $meta_key Metadata key.\n\t * @param mixed $meta_value Metadata value. Serialized if non-scalar.\n\t */\n\tpublic function callback_updated_term_meta( int $meta_id, int $object_id, string $meta_key, $meta_value ) {\n\n\t\tif ( empty( $term = get_term( $object_id ) ) || ! is_a( $term, 'WP_Term' ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$tax_object = get_taxonomy( $term->taxonomy );\n\n\t\t// If the updated term is of a post type that isn't being tracked, do nothing\n\t\tif ( false === $tax_object || ! $this->is_taxonomy_tracked( $term->taxonomy ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( false === $this->should_track_meta( $meta_key, $meta_value, $term ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$action = [\n\t\t\t'action_type'         => 'UPDATE',\n\t\t\t'title'               => $term->name,\n\t\t\t'node_id'             => $term->term_id,\n\t\t\t'relay_id'            => Relay::toGlobalId( 'term', $term->term_id ),\n\t\t\t'graphql_single_name' => $tax_object->graphql_single_name,\n\t\t\t'graphql_plural_name' => $tax_object->graphql_plural_name,\n\t\t\t'status'              => 'publish',\n\t\t];\n\n\t\t// Log the action\n\t\t$this->log_action( $action );\n\n\t}\n\n\t/**\n\t * Logs activity when meta is updated on terms\n\t *\n\t * @param string[] $meta_ids    An array of metadata entry IDs to delete.\n\t * @param int      $object_id   ID of the object metadata is for.\n\t * @param string   $meta_key    Metadata key.\n\t * @param mixed    $meta_value Metadata value. Serialized if non-scalar.\n\t */\n\tpublic function callback_deleted_term_meta( array $meta_ids, int $object_id, string $meta_key, $meta_value ) {\n\n\t\tif ( empty( $term = get_term( $object_id ) ) || ! is_a( $term, 'WP_Term' ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$tax_object = get_taxonomy( $term->taxonomy );\n\n\t\t// If the updated term is of a post type that isn't being tracked, do nothing\n\t\tif ( false === $tax_object || ! $this->is_taxonomy_tracked( $term->taxonomy ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( false === $this->should_track_meta( $meta_key, $meta_value, $term ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$action = [\n\t\t\t'action_type'         => 'UPDATE',\n\t\t\t'title'               => $term->name,\n\t\t\t'node_id'             => $term->term_id,\n\t\t\t'relay_id'            => Relay::toGlobalId( 'term', $term->term_id ),\n\t\t\t'graphql_single_name' => $tax_object->graphql_single_name,\n\t\t\t'graphql_plural_name' => $tax_object->graphql_plural_name,\n\t\t\t'status'              => 'publish',\n\t\t];\n\n\t\t// Log the action\n\t\t$this->log_action( $action );\n\n\t}\n\n}\n"
  },
  {
    "path": "src/ActionMonitor/Monitors/UserMonitor.php",
    "content": "<?php\n\nnamespace WPGatsby\\ActionMonitor\\Monitors;\n\nuse GraphQLRelay\\Relay;\n\nclass UserMonitor extends Monitor {\n\n\t/**\n\t * The user object before deletion\n\t *\n\t * @var array<int, array{user:\\WP_User|false, reassign:\\WP_User|null}>\n\t */\n\tprotected $users_before_delete;\n\n\t/**\n\t * IDs of posts to reassign\n\t *\n\t * @var array<string>\n\t */\n\tprotected $post_ids_to_reassign;\n\n\t/**\n\t * Initialize UserMonitor Actions\n\t *\n\t * @return void\n\t */\n\tpublic function init() {\n\n\t\t$this->post_ids_to_reassign = [];\n\n\t\tadd_action( 'profile_update', [ $this, 'callback_profile_update' ], 10, 1 );\n\t\tadd_action( 'delete_user', [ $this, 'callback_delete_user' ], 10, 2 );\n\t\tadd_action( 'deleted_user', [ $this, 'callback_deleted_user' ], 10, 1 );\n\t\tadd_action( 'updated_user_meta', [ $this, 'callback_updated_user_meta' ], 10, 4 );\n\t\tadd_action( 'added_user_meta', [ $this, 'callback_updated_user_meta' ], 10, 4 );\n\t\tadd_action( 'deleted_user_meta', [ $this, 'callback_deleted_user_meta' ], 10, 4 );\n\n\t}\n\n\t/**\n\t * This method accepts a user ID, and checks if the user has published posts\n\t * of any of the tracked post types\n\t *\n\t * @param int $user_id The ID of the user to check\n\t *\n\t * @return bool\n\t */\n\tpublic function is_published_author( int $user_id ) {\n\n\t\t$post_types            = $this->action_monitor->get_tracked_post_types();\n\t\t$published_posts_count = count_user_posts( $user_id, $post_types );\n\n\t\tif ( empty( $published_posts_count ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\n\t}\n\n\t/**\n\t * Determines whether the meta should be tracked or not.\n\t *\n\t * User meta is all untracked other than a few specific keys. Plugins and themes that\n\t * expose user meta intended for public display will need to filter this to\n\t * have updates to those meta fields trigger updates with Gatsby.\n\t *\n\t * @param string $meta_key Metadata key.\n\t * @param mixed $meta_value Metadata value. Serialized if non-scalar.\n\t * @param object $object The object the metadata is for.\n\t *\n\t * @return bool\n\t */\n\tpublic function should_track_meta( string $meta_key, $meta_value, $object ) {\n\n\t\t$tracked_meta_keys = [\n\t\t\t'description',\n\t\t\t'nickname',\n\t\t\t'firstName',\n\t\t\t'lastName',\n\t\t];\n\n\t\t$tracked_meta_keys = apply_filters( 'gatsby_action_monitor_tracked_user_meta_keys', $tracked_meta_keys, $meta_key, $meta_value, $object );\n\n\t\tif ( in_array( $meta_key, $tracked_meta_keys, true ) ) {\n\t\t\treturn true;\n\t\t}\n\n\t\treturn false;\n\n\t}\n\n\t/**\n\t * Log action when a user is updated.\n\t *\n\t * @param int $user_id\n\t */\n\tpublic function callback_profile_update( int $user_id ) {\n\n\t\tif ( empty( $user_id ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$user = get_user_by( 'id', $user_id );\n\n\t\tif ( ! $user instanceof \\WP_User || $user_id !== $user->ID ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! $this->is_published_author( $user_id ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$this->log_action(\n\t\t\t[\n\t\t\t\t'action_type'         => 'UPDATE',\n\t\t\t\t'title'               => $user->display_name,\n\t\t\t\t'node_id'             => (int) $user->ID,\n\t\t\t\t'relay_id'            => Relay::toGlobalId( 'user', (int) $user->ID ),\n\t\t\t\t'graphql_single_name' => 'user',\n\t\t\t\t'graphql_plural_name' => 'users',\n\t\t\t\t'status'              => 'publish',\n\t\t\t]\n\t\t);\n\n\t}\n\n\t/**\n\t * There's no logging in this callback's action, the reason\n\t * behind this hook is so that we can store user objects before\n\t * being deleted.\n\t *\n\t * During `deleted_user` hook, our callback\n\t * receives $user_id param but it's useless as the user record\n\t * was already removed from DB.\n\t *\n\t * @param mixed|int|null $user_id     User ID that may be deleted\n\t * @param mixed|int|null $reassign_id User ID that posts should be reassigned to\n\t */\n\tpublic function callback_delete_user( $user_id, $reassign_id ) {\n\n\t\tif ( empty( $user_id ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! $this->is_published_author( $user_id ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Get the user the posts should be re-assigned to\n\t\t$reassign_user = ! empty( $reassign_id ) ? get_user_by( 'id', $reassign_id ) : null;\n\n\t\tif ( ! empty( $reassign_user ) ) {\n\n\t\t\t// @todo: We should get rid of this as it can get expensive to log these actions.\n\t\t\t// Gatsby Source WordPress should have support for bulk-actions so we can log a single action\n\t\t\t// such as \"DELETE_AUTHOR_AND_REASSIGN_POSTS\" and pass the old author ID and new author ID and\n\t\t\t// Gatsby could do it without an action per modified post.\n\t\t\tglobal $wpdb;\n\t\t\t$post_types = $this->action_monitor->get_tracked_post_types();\n\t\t\t$post_types = implode( \"', '\", $post_types );\n\t\t\t$post_ids   = $wpdb->get_col( $wpdb->prepare( \"SELECT ID FROM $wpdb->posts WHERE post_author = %d AND post_status = 'publish' AND post_type IN ('$post_types')\", $user_id ) );\n\n\t\t\tif ( ! empty( $post_ids ) && is_array( $post_ids ) ) {\n\t\t\t\t$this->post_ids_to_reassign = array_merge( $this->post_ids_to_reassign, $post_ids );\n\t\t\t}\n\t\t}\n\n\t\t$this->users_before_delete[ (int) $user_id ] = [\n\t\t\t'user'     => get_user_by( 'id', (int) $user_id ),\n\t\t\t'reassign' => ! empty( $reassign_user ) && $reassign_user instanceof \\WP_User ? $reassign_user : null,\n\t\t];\n\t}\n\n\t/**\n\t * Log deleted user.\n\t *\n\t * @param int $user_id Deleted user ID\n\t */\n\tpublic function callback_deleted_user( int $user_id ) {\n\n\t\t$before_delete = isset( $this->users_before_delete[ (int) $user_id ] ) ? $this->users_before_delete[ (int) $user_id ] : null;\n\n\t\tif ( empty( $before_delete ) || ! isset( $before_delete['user']->data->display_name ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$this->log_action(\n\t\t\t[\n\t\t\t\t'action_type'         => 'DELETE',\n\t\t\t\t'title'               => $before_delete['user']->data->display_name,\n\t\t\t\t'node_id'             => (int) $before_delete['user']->ID,\n\t\t\t\t'relay_id'            => Relay::toGlobalId( 'user', (int) $before_delete['user']->ID ),\n\t\t\t\t'graphql_single_name' => 'user',\n\t\t\t\t'graphql_plural_name' => 'users',\n\t\t\t\t'status'              => 'trash',\n\t\t\t]\n\t\t);\n\n\t\tif ( isset( $before_delete['reassign']->display_name ) ) {\n\t\t\t$this->log_action(\n\t\t\t\t[\n\t\t\t\t\t'action_type'         => 'UPDATE',\n\t\t\t\t\t'title'               => $before_delete['reassign']->display_name,\n\t\t\t\t\t'node_id'             => (int) $before_delete['reassign']->ID,\n\t\t\t\t\t'relay_id'            => Relay::toGlobalId( 'user', (int) $before_delete['reassign']->ID ),\n\t\t\t\t\t'graphql_single_name' => 'user',\n\t\t\t\t\t'graphql_plural_name' => 'users',\n\t\t\t\t\t'status'              => 'publish',\n\t\t\t\t]\n\t\t\t);\n\n\t\t\tif ( ! empty( $this->post_ids_to_reassign ) && is_array( $this->post_ids_to_reassign ) ) {\n\n\t\t\t\tforeach ( $this->post_ids_to_reassign as $post_id ) {\n\n\t\t\t\t\t// If there's a post for the Post ID\n\t\t\t\t\tif ( ! empty( $post = get_post( absint( $post_id ) ) ) ) {\n\n\t\t\t\t\t\t// If the post status is not published, don't track an action for it\n\t\t\t\t\t\tif ( 'publish' !== $post->post_status ) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Get the post type object\n\t\t\t\t\t\t$post_type_object = get_post_type_object( $post->post_type );\n\n\t\t\t\t\t\t// Log an action for the post being re-assigned\n\t\t\t\t\t\t$this->log_action(\n\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t'action_type'         => 'UPDATE',\n\t\t\t\t\t\t\t\t'title'               => $post->post_title,\n\t\t\t\t\t\t\t\t'node_id'             => (int) $post_id,\n\t\t\t\t\t\t\t\t'relay_id'            => Relay::toGlobalId( 'post', (int) $post_id ),\n\t\t\t\t\t\t\t\t'graphql_single_name' => $post_type_object->graphql_single_name,\n\t\t\t\t\t\t\t\t'graphql_plural_name' => $post_type_object->graphql_plural_name,\n\t\t\t\t\t\t\t\t'status'              => 'publish',\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t);\n\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t}\n\n\t/**\n\t * Logs activity when meta is updated for a user\n\t *\n\t * @param int    $meta_id    ID of updated metadata entry.\n\t * @param int    $object_id  ID of the object metadata is for.\n\t * @param string $meta_key   Metadata key.\n\t * @param mixed  $meta_value Metadata value. Serialized if non-scalar.\n\t */\n\tpublic function callback_updated_user_meta( int $meta_id, int $object_id, string $meta_key, $meta_value ) {\n\n\t\tif ( empty( $user = get_user_by( 'id', $object_id ) ) || ! is_a( $user, 'WP_User' ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! $this->is_published_author( $object_id ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( false === $this->should_track_meta( $meta_key, $meta_value, $user ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$action = [\n\t\t\t'action_type'         => 'UPDATE',\n\t\t\t'title'               => $user->display_name,\n\t\t\t'node_id'             => (int) $user->ID,\n\t\t\t'relay_id'            => Relay::toGlobalId( 'user', (int) $user->ID ),\n\t\t\t'graphql_single_name' => 'user',\n\t\t\t'graphql_plural_name' => 'users',\n\t\t\t'status'              => 'publish',\n\t\t];\n\n\t\t// Log the action\n\t\t$this->log_action( $action );\n\n\t}\n\n\t/**\n\t * Logs activity when meta is updated on terms\n\t *\n\t * @param string[] $meta_ids   An array of metadata entry IDs to delete.\n\t * @param int      $object_id  ID of the object metadata is for.\n\t * @param string   $meta_key   Metadata key.\n\t * @param mixed    $meta_value Metadata value. Serialized if non-scalar.\n\t */\n\tpublic function callback_deleted_user_meta( array $meta_ids, int $object_id, string $meta_key, $meta_value ) {\n\n\t\tif ( empty( $user = get_user_by( 'id', $object_id ) ) || ! is_a( $user, 'WP_User' ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! $this->is_published_author( $object_id ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! $this->should_track_meta( $meta_key, $meta_value, $user ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$action = [\n\t\t\t'action_type'         => 'UPDATE',\n\t\t\t'title'               => $user->display_name,\n\t\t\t'node_id'             => (int) $user->ID,\n\t\t\t'relay_id'            => Relay::toGlobalId( 'user', (int) $user->ID ),\n\t\t\t'graphql_single_name' => 'user',\n\t\t\t'graphql_plural_name' => 'users',\n\t\t\t'status'              => 'publish',\n\t\t];\n\n\t\t// Log the action\n\t\t$this->log_action( $action );\n\n\t}\n}\n"
  },
  {
    "path": "src/Admin/Preview.php",
    "content": "<?php\n\nnamespace WPGatsby\\Admin;\n\nuse GraphQL\\Error\\UserError;\nuse WPGraphQL\\Router;\nuse WPGatsby\\Admin\\Settings;\n\nclass Preview {\n\tfunction __construct() {\n\t\tadd_action(\n\t\t\t'graphql_register_types',\n\t\t\tfunction() {\n\t\t\t\t$this->register_preview_status_fields_and_mutations();\n\t\t\t}\n\t\t);\n\t}\n\n\tpublic static function get_gatsby_content_sync_url_for_post( $post ) {\n\t\t// get the Gatsby Cloud loader url w/ site id\n\t\t$gatsby_content_sync_url = Settings::get_setting( 'gatsby_content_sync_url' );\n\t\t\t\t\t\n\t\t// Create the dynamic path Content Sync will need\n\t\t$manifest_id = self::get_preview_manifest_id_for_post( $post );\n\t\t$content_id = $post->ID;\n\t\t$path = \"/gatsby-source-wordpress/$manifest_id/$content_id\";\n\n\t\t$url = preg_replace(\n\t\t\t// remove any double forward slashes from the path\n\t\t\t'/([^:])(\\/{2,})/', '$1/',\n\t\t\t\"$gatsby_content_sync_url$path\"\n\t\t);\n\n\t\treturn $url;\n\t}\n\n\tpublic static function get_previewable_post_object_by_post_id( $post_id ) {\n\t\t$revision = array_values(\n\t\t\t\t\t\twp_get_post_revisions( $post_id )\n\t\t\t\t\t)[0]\n\t\t\t\t\t// or if revisions are disabled, get the autosave\n\t\t\t\t\t?? wp_get_post_autosave( $post_id, get_current_user_id() )\n\t\t\t\t\t\t// otherwise we can't preview anything\n\t\t\t\t\t\t?? null;\n\n\t\tif ( $revision ) {\n\t\t\treturn $revision;\n\t\t}\n\n\t\treturn get_post( $post_id );\n\t}\n\n\n\tpublic static function get_preview_manifest_id_for_post( $post ) {\n\t\t$revision = self::get_previewable_post_object_by_post_id( $post->ID );\n\t\t$revision_modified = $revision->post_modified ?? null;\n\n\t\t$modified = \n\t\t\t$post->post_status === \"draft\"\n\t\t\t\t? $post->post_modified\n\t\t\t\t: $revision_modified;\n\n\t\tif ( ! $modified || $modified === \"\" ) {\n\t\t\treturn null;\n\t\t}\n\n\t\t$manifest_id = $post->ID . $modified;\n\n\t\treturn $manifest_id;\n\t}\n\n\t/**\n\t * This is used to print out the client CSS file directly to the\n\t * Preview template html when Content Sync isn't set up correctly.\n\t */\n\tpublic static function print_file_contents( $fileName ) {\n\t\t$pluginDirectory = plugin_dir_path( __FILE__ );\n\t\t$filePath        = $pluginDirectory . $fileName;\n\t\techo file_get_contents( $filePath );\n\t}\n\n\tfunction register_preview_status_fields_and_mutations() {\n\t\tregister_graphql_enum_type(\n\t\t\t'WPGatsbyRemotePreviewStatusEnum',\n\t\t\t[\n\t\t\t\t'description' => __( 'The different statuses a Gatsby Preview can be in for a single node.', 'wp-gatsby' ),\n\t\t\t\t'values'      => [\n\t\t\t\t\t'PREVIEW_SUCCESS'                      => [\n\t\t\t\t\t\t'value' => 'PREVIEW_SUCCESS',\n\t\t\t\t\t],\n\t\t\t\t\t'NO_PAGE_CREATED_FOR_PREVIEWED_NODE'   => [\n\t\t\t\t\t\t'value' => 'NO_PAGE_CREATED_FOR_PREVIEWED_NODE',\n\t\t\t\t\t],\n\t\t\t\t\t'GATSBY_PREVIEW_PROCESS_ERROR'         => [\n\t\t\t\t\t\t'value' => 'GATSBY_PREVIEW_PROCESS_ERROR',\n\t\t\t\t\t],\n\t\t\t\t\t'RECEIVED_PREVIEW_DATA_FROM_WRONG_URL' => [\n\t\t\t\t\t\t'value' => 'RECEIVED_PREVIEW_DATA_FROM_WRONG_URL',\n\t\t\t\t\t],\n\t\t\t\t],\n\t\t\t]\n\t\t);\n\n\t\tregister_graphql_mutation(\n\t\t\t'wpGatsbyRemotePreviewStatus',\n\t\t\t[\n\t\t\t\t'inputFields'         => [\n\t\t\t\t\t// parentDatabaseId is the only input arg we need now.\n\t\t\t\t\t// the rest are left for backwards compatibility so errors aren't thrown.\n\t\t\t\t\t'parentDatabaseId' => [\n\t\t\t\t\t\t'type'        => 'Number',\n\t\t\t\t\t\t'description' => __( 'The previewed revisions post parent id', 'wp-gatsby' ),\n\t\t\t\t\t],\n\t\t\t\t\t'pagePath'         => [\n\t\t\t\t\t\t'type'        => 'String',\n\t\t\t\t\t\t'description' => __( 'The Gatsby page path for this preview.', 'wp-gatsby' ),\n\t\t\t\t\t],\n\t\t\t\t\t'modified'         => [\n\t\t\t\t\t\t'type'        => 'String',\n\t\t\t\t\t\t'description' => __( 'The modified date of the latest revision for this preview.', 'wp-gatsby' ),\n\t\t\t\t\t],\n\t\t\t\t\t'status'           => [\n\t\t\t\t\t\t'type'        => [ 'non_null' => 'WPGatsbyRemotePreviewStatusEnum' ],\n\t\t\t\t\t\t'description' => __( 'The remote status of the previewed node', 'wp-gatsby' ),\n\t\t\t\t\t],\n\t\t\t\t\t'statusContext'    => [\n\t\t\t\t\t\t'type'        => 'String',\n\t\t\t\t\t\t'description' => __( 'Additional context about the preview status', 'wp-gatsby' ),\n\t\t\t\t\t],\n\t\t\t\t],\n\t\t\t\t'outputFields'        => [\n\t\t\t\t\t'success' => [\n\t\t\t\t\t\t'type'        => 'Boolean',\n\t\t\t\t\t\t'description' => __( 'Wether or not the revision mutation was successful', 'wp-gatsby' ),\n\t\t\t\t\t\t'resolve'     => function( $payload, $args, $context, $info ) {\n\t\t\t\t\t\t\t$success = $payload['success'] ?? null;\n\n\t\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\t\t'success' => $success,\n\t\t\t\t\t\t\t];\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t],\n\t\t\t\t'mutateAndGetPayload' => function( $input, $context, $info ) {\n\t\t\t\t\t$parent_id = $input['parentDatabaseId'] ?? null;\n\t\t\t\t\t\n\t\t\t\t\t$post = get_post( $parent_id );\n\n\t\t\t\t\t$post_type_object = $post\n\t\t\t\t\t\t? get_post_type_object( $post->post_type )\n\t\t\t\t\t\t: null;\n\n\t\t\t\t\t$user_can_edit_this_post = $post\n\t\t\t\t\t\t? current_user_can(\n\t\t\t\t\t\t\t$post_type_object->cap->edit_posts,\n\t\t\t\t\t\t\t$parent_id\n\t\t\t\t\t\t)\n\t\t\t\t\t\t: null;\n\n\t\t\t\t\tif ( ! $post || ! $user_can_edit_this_post ) {\n\t\t\t\t\t\t$message = sprintf(\n\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t'Sorry, you are not allowed to update post %1$s',\n\t\t\t\t\t\t\t\t'wp-gatsby'\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t$parent_id\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tthrow new UserError( $message );\n\t\t\t\t\t}\n\n\t\t\t\t\t// delete action monitor preview action.\n\t\t\t\t\t// once we've saved this preview status as succes\n\t\t\t\t\t// we don't need the preview action anymore.\n\t\t\t\t\t$existing = new \\WP_Query( [\n\t\t\t\t\t\t'post_type'      => 'action_monitor',\n\t\t\t\t\t\t'post_status'    => 'any',\n\t\t\t\t\t\t'posts_per_page' => 1,\n\t\t\t\t\t\t'no_found_rows'  => true,\n\t\t\t\t\t\t'fields'         => 'ids',\n\t\t\t\t\t\t'tax_query'      => [\n\t\t\t\t\t\t\t'relation' => 'AND',\n\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t'taxonomy' => 'gatsby_action_ref_node_dbid',\n\t\t\t\t\t\t\t\t'field'    => 'name',\n\t\t\t\t\t\t\t\t'terms'    => sanitize_text_field( $parent_id ),\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t'taxonomy' => 'gatsby_action_stream_type',\n\t\t\t\t\t\t\t\t'field'    => 'name',\n\t\t\t\t\t\t\t\t'terms'    => 'PREVIEW',\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t],\n\t\t\t\t\t] );\n\n\t\t\t\t\tif ( isset( $existing->posts ) && ! empty( $existing->posts ) ) {\n\t\t\t\t\t\twp_delete_post( $existing->posts[0], true );\n\t\t\t\t\t}\n\n\t\t\t\t\treturn [\n\t\t\t\t\t\t'success' => true,\n\t\t\t\t\t];\n\t\t\t\t},\n\t\t\t]\n\t\t);\n\n\t\tregister_graphql_object_type(\n\t\t\t'WPGatsbyPageNode',\n\t\t\t[\n\t\t\t\t'description' => __( 'A previewed Gatsby page node.' ),\n\t\t\t\t'fields'      => [\n\t\t\t\t\t'path' => [\n\t\t\t\t\t\t'type' => 'String',\n\t\t\t\t\t],\n\t\t\t\t],\n\t\t\t]\n\t\t);\n\n\t\tregister_graphql_enum_type(\n\t\t\t'WPGatsbyWPPreviewedNodeStatus',\n\t\t\t[\n\t\t\t\t'description' => __( 'The different statuses a Gatsby Preview can be in for a single node.', 'wp-gatsby' ),\n\t\t\t\t'values'      => [\n\t\t\t\t\t'NO_NODE_FOUND'                             => [\n\t\t\t\t\t\t'value' => 'NO_NODE_FOUND',\n\t\t\t\t\t],\n\t\t\t\t\t'PREVIEW_READY'                             => [\n\t\t\t\t\t\t'value' => 'PREVIEW_READY',\n\t\t\t\t\t],\n\t\t\t\t\t'REMOTE_NODE_NOT_YET_UPDATED'               => [\n\t\t\t\t\t\t'value' => 'REMOTE_NODE_NOT_YET_UPDATED',\n\t\t\t\t\t],\n\t\t\t\t\t'NO_PREVIEW_PATH_FOUND'                     => [\n\t\t\t\t\t\t'value' => 'NO_PREVIEW_PATH_FOUND',\n\t\t\t\t\t],\n\t\t\t\t\t'RECEIVED_PREVIEW_DATA_FROM_WRONG_URL'      => [\n\t\t\t\t\t\t'value' => 'RECEIVED_PREVIEW_DATA_FROM_WRONG_URL',\n\t\t\t\t\t],\n\t\t\t\t\t'PREVIEW_PAGE_UPDATED_BUT_NOT_YET_DEPLOYED' => [\n\t\t\t\t\t\t'value' => 'PREVIEW_PAGE_UPDATED_BUT_NOT_YET_DEPLOYED',\n\t\t\t\t\t],\n\t\t\t\t],\n\t\t\t]\n\t\t);\n\n\t\tregister_graphql_object_type(\n\t\t\t'WPGatsbyPreviewStatus',\n\t\t\t[\n\t\t\t\t'description' => __( 'Check compatibility with a given version of gatsby-source-wordpress and the WordPress source site.' ),\n\t\t\t\t'fields'      => [\n\t\t\t\t\t'pageNode'       => [\n\t\t\t\t\t\t'type' => 'WPGatsbyPageNode',\n\t\t\t\t\t],\n\t\t\t\t\t'statusType'     => [\n\t\t\t\t\t\t'type' => 'WPGatsbyWPPreviewedNodeStatus',\n\t\t\t\t\t],\n\t\t\t\t\t'remoteStatus'   => [\n\t\t\t\t\t\t'type' => 'WPGatsbyRemotePreviewStatusEnum',\n\t\t\t\t\t],\n\t\t\t\t\t'modifiedLocal'  => [\n\t\t\t\t\t\t'type' => 'String',\n\t\t\t\t\t],\n\t\t\t\t\t'modifiedRemote' => [\n\t\t\t\t\t\t'type' => 'String',\n\t\t\t\t\t],\n\t\t\t\t\t'statusContext'  => [\n\t\t\t\t\t\t'type' => 'String',\n\t\t\t\t\t],\n\t\t\t\t],\n\t\t\t]\n\t\t);\n\n\t\tregister_graphql_field(\n\t\t\t'WPGatsby',\n\t\t\t'gatsbyPreviewStatus',\n\t\t\t[\n\t\t\t\t'description' => __( 'The current status of a Gatsby Preview.', 'wp-gatsby' ),\n\t\t\t\t'type'        => 'WPGatsbyPreviewStatus',\n\t\t\t\t'args'        => [\n\t\t\t\t\t'nodeId' => [\n\t\t\t\t\t\t'type'        => [ 'non_null' => 'Number' ],\n\t\t\t\t\t\t'description' => __( 'The post id for the previewed node.', 'wp-gatsby' ),\n\t\t\t\t\t],\n\t\t\t\t],\n\t\t\t\t'resolve'     => function( $root, $args, $context, $info ) {\n\t\t\t\t\t$post_id = $args['nodeId'] ?? null;\n\n\t\t\t\t\t// make sure post_id is a valid post\n\t\t\t\t\t$post = get_post( $post_id );\n\n\t\t\t\t\t$post_type_object = $post\n\t\t\t\t\t\t? get_post_type_object( $post->post_type )\n\t\t\t\t\t\t: null;\n\n\t\t\t\t\t$user_can_edit_this_post = $post\n\t\t\t\t\t\t? current_user_can(\n\t\t\t\t\t\t\t$post_type_object->cap->edit_posts,\n\t\t\t\t\t\t\t$post_id\n\t\t\t\t\t\t)\n\t\t\t\t\t\t: null;\n\n\t\t\t\t\tif ( ! $post || ! $user_can_edit_this_post ) {\n\t\t\t\t\t\tthrow new UserError(\n\t\t\t\t\t\t\tsprintf(\n\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t'Sorry, you are not allowed to access the Preview status of post %1$s',\n\t\t\t\t\t\t\t\t\t'wp-gatsby'\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t$post_id\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( ! $post ) {\n\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\t'statusType' => 'NO_NODE_FOUND',\n\t\t\t\t\t\t];\n\t\t\t\t\t}\n\n\t\t\t\t\t$found_preview_path_post_meta = get_post_meta(\n\t\t\t\t\t\t$post_id,\n\t\t\t\t\t\t'_wpgatsby_page_path',\n\t\t\t\t\t\ttrue\n\t\t\t\t\t);\n\n\t\t\t\t\t$revision = Preview::getPreviewablePostObjectByPostId( $post_id );\n\n\t\t\t\t\t$revision_modified = $revision->post_modified ?? null;\n\n\t\t\t\t\t$modified = $revision_modified ?? $post->post_modified;\n\n\t\t\t\t\t$gatsby_node_modified = get_post_meta(\n\t\t\t\t\t\t$post_id,\n\t\t\t\t\t\t'_wpgatsby_node_modified',\n\t\t\t\t\t\ttrue\n\t\t\t\t\t);\n\n\t\t\t\t\t$remote_status = get_post_meta(\n\t\t\t\t\t\t$post_id,\n\t\t\t\t\t\t'_wpgatsby_node_remote_preview_status',\n\t\t\t\t\t\ttrue\n\t\t\t\t\t);\n\n\t\t\t\t\t$node_modified_was_updated =\n\t\t\t\t\t\tstrtotime( $gatsby_node_modified ) >= strtotime( $modified );\n\n\t\t\t\t\tif (\n\t\t\t\t\t\t$node_modified_was_updated\n\t\t\t\t\t\t&& (\n\t\t\t\t\t\t'NO_PAGE_CREATED_FOR_PREVIEWED_NODE' === $remote_status\n\t\t\t\t\t\t|| 'RECEIVED_PREVIEW_DATA_FROM_WRONG_URL' === $remote_status\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\t'statusType'    => null,\n\t\t\t\t\t\t\t'statusContext' => null,\n\t\t\t\t\t\t\t'remoteStatus'  => $remote_status,\n\t\t\t\t\t\t];\n\t\t\t\t\t}\n\n\t\t\t\t\t$node_was_updated = false;\n\n\t\t\t\t\tif ( $node_modified_was_updated && $found_preview_path_post_meta ) {\n\t\t\t\t\t\t$server_side = true;\n\n\t\t\t\t\t\t$gatbsy_preview_frontend_url =\n\t\t\t\t\t\t\tself::get_gatsby_preview_instance_url(\n\t\t\t\t\t\t\t\t$server_side\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t$page_data_path = $found_preview_path_post_meta === \"/\" \n\t\t\t\t\t\t\t? \"/index/\"\n\t\t\t\t\t\t\t: $found_preview_path_post_meta;\n\t\t\n\t\t\t\t\t\t$page_data_path_trimmed = trim( $page_data_path, \"/\" );\n\n\t\t\t\t\t\t$modified_deployed_url =\n\t\t\t\t\t\t\t$gatbsy_preview_frontend_url .\n\t\t\t\t\t\t\t\"page-data/$page_data_path_trimmed/page-data.json\";\n\n\t\t\t\t\t\t// check if node page was deployed\n\t\t\t\t\t\t$request  = wp_remote_get( $modified_deployed_url );\n\t\t\t\t\t\t$response = wp_remote_retrieve_body( $request );\n\n\t\t\t\t\t\t$page_data = json_decode( $response );\n\n\t\t\t\t\t\t$modified_response =\n\t\t\t\t\t\t\t$page_data->result->pageContext->__wpGatsbyNodeModified\n\t\t\t\t\t\t\t?? null;\n\n\t\t\t\t\t\terror_log(print_r('$modified_response', true)); \n\t\t\t\t\t\terror_log(print_r($modified_response, true)); \n\t\t\t\t\t\terror_log(print_r('$modified', true)); \n\t\t\t\t\t\terror_log(print_r($modified, true)); \n\n\t\t\t\t\t\t$preview_was_deployed =\n\t\t\t\t\t\t\t$modified_response &&\n\t\t\t\t\t\t\tstrtotime( $modified_response ) >= strtotime( $modified );\n\n\t\t\t\t\t\terror_log(print_r('$preview_was_deployed', true)); \n\t\t\t\t\t\terror_log(print_r($preview_was_deployed, true)); \n\n\t\t\t\t\t\tif ( ! $preview_was_deployed ) {\n\t\t\t\t\t\t\t// if preview was not yet deployed, send back PREVIEW_PAGE_UPDATED_BUT_NOT_YET_DEPLOYED.\n\t\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\t\t'statusType'    =>\n\t\t\t\t\t\t\t\t\t'PREVIEW_PAGE_UPDATED_BUT_NOT_YET_DEPLOYED',\n\t\t\t\t\t\t\t\t'statusContext' => null,\n\t\t\t\t\t\t\t\t'remoteStatus'  => null,\n\t\t\t\t\t\t\t];\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// if it is deployed, send back PREVIEW_READY below.\n\t\t\t\t\t\t\t$node_was_updated = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// if the node wasn't updated, then any status we have is stale.\n\t\t\t\t\t$remote_status_type = $remote_status && $node_was_updated\n\t\t\t\t\t\t? $remote_status\n\t\t\t\t\t\t: null;\n\n\t\t\t\t\t/**\n\t\t\t\t\t * We need the above check for wether the node was updated so we\n\t\t\t\t\t * don't show stale statuses on existing nodes, but in the case that\n\t\t\t\t\t * it's a brand new draft, $node_was_updated will always be false\n\t\t\t\t\t * because at this point we're potentially getting an error on a\n\t\t\t\t\t * node that was never created. So GATSBY_PREVIEW_PROCESS_ERROR is a\n\t\t\t\t\t * special case where we always need to show the status regardless\n\t\t\t\t\t * of wether the node was updated.\n\t\t\t\t\t */\n\t\t\t\t\tif ( 'GATSBY_PREVIEW_PROCESS_ERROR' === $remote_status ) {\n\t\t\t\t\t\t$remote_status_type = $remote_status;\n\t\t\t\t\t}\n\n\t\t\t\t\t$status_type = 'PREVIEW_READY';\n\n\t\t\t\t\tif ( ! $node_was_updated ) {\n\t\t\t\t\t\t$status_type = 'REMOTE_NODE_NOT_YET_UPDATED';\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( ! $found_preview_path_post_meta ) {\n\t\t\t\t\t\t$status_type = 'NO_PREVIEW_PATH_FOUND';\n\t\t\t\t\t}\n\n\t\t\t\t\t$status_context = get_post_meta(\n\t\t\t\t\t\t$post_id,\n\t\t\t\t\t\t'_wpgatsby_node_remote_preview_status_context',\n\t\t\t\t\t\ttrue\n\t\t\t\t\t);\n\n\t\t\t\t\tif ( $status_context === '' ) {\n\t\t\t\t\t\t$status_context = null;\n\t\t\t\t\t}\n\n\t\t\t\t\t$normalized_preview_page_path =\n\t\t\t\t\t\t$found_preview_path_post_meta !== ''\n\t\t\t\t\t\t\t? $found_preview_path_post_meta\n\t\t\t\t\t\t\t: null;\n\n\t\t\t\t\treturn [\n\t\t\t\t\t\t'statusType'     => $status_type,\n\t\t\t\t\t\t'statusContext'  => $status_context,\n\t\t\t\t\t\t'remoteStatus'   => $remote_status_type,\n\t\t\t\t\t\t'pageNode'       => [\n\t\t\t\t\t\t\t'path' => $normalized_preview_page_path,\n\t\t\t\t\t\t],\n\t\t\t\t\t\t'modifiedLocal'  => $modified,\n\t\t\t\t\t\t'modifiedRemote' => $gatsby_node_modified,\n\t\t\t\t\t];\n\t\t\t\t},\n\t\t\t]\n\t\t);\n\n\t\tregister_graphql_field(\n\t\t\t'WPGatsby',\n\t\t\t'isPreviewFrontendOnline',\n\t\t\t[\n\t\t\t\t'description' => __( 'Wether or not the Preview frontend URL is online.', 'wp-gatsby' ),\n\t\t\t\t'type'        => 'Boolean',\n\t\t\t\t'resolve'     => function( $root, $args, $context, $info ) {\n\t\t\t\t\tif ( ! is_user_logged_in() ) {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\n\t\t\t\t\t$preview_url = self::get_gatsby_preview_instance_url();\n\n\t\t\t\t\t$request = wp_remote_get( $preview_url );\n\n\t\t\t\t\t$request_was_successful =\n\t\t\t\t\t\t$this->was_request_successful( $request );\n\n\t\t\t\t\treturn $request_was_successful;\n\t\t\t\t},\n\t\t\t]\n\t\t);\n\t}\n}\n"
  },
  {
    "path": "src/Admin/Settings.php",
    "content": "<?php\n\nnamespace WPGatsby\\Admin;\n\nclass Settings {\n\n\tprivate $settings_api;\n\n\tfunction __construct() {\n\n\t\t$this->settings_api = new \\WPGraphQL_Settings_API;\n\n\t\tadd_action( 'init', [ $this, 'set_default_jwt_key' ] );\n\t\tadd_action( 'admin_init', [ $this, 'admin_init' ] );\n\t\tadd_action( 'admin_menu', [ $this, 'register_settings_page' ] );\n\n\t\t// Filter the GraphQL Settings for introspection to force enable Introspection when WPGatsby is active\n\t\tadd_filter( 'graphql_setting_field_config', [ $this, 'filter_graphql_introspection_setting_field' ], 10, 3 );\n\t\tadd_filter( 'graphql_get_setting_section_field_value', [ $this, 'filter_graphql_introspection_setting_value' ], 10, 5 );\n\t}\n\n\t/**\n\t * If the settings haven't been saved yet, save the JWT once to prevent it from re-generating.\n\t */\n\tpublic function set_default_jwt_key() {\t\n\t\t// Get the JWT Secret\n\t\t$default_secret = self::get_setting( 'preview_jwt_secret' );\n\n\t\tif ( empty( $default_secret ) ) {\n\n\t\t\t// Get the WPGatsby Settings from the options\n\t\t\t$options = get_option( 'wpgatsby_settings', [] );\n\n\t\t\t// If settings haven't been saved before, instantiate them as a new array\n\t\t\tif ( empty( $options ) || ! is_array( $options ) ) {\n\t\t\t\t$options = [];\n\t\t\t}\n\n\t\t\t// Se the preview secret\n\t\t\t$options['preview_jwt_secret'] = self::generate_secret();\n\n\t\t\t// Save the settings to prevent the JWT Secret from generating again\n\t\t\tupdate_option( 'wpgatsby_settings', $options );\n\t\t}\n\t}\n\n\t/**\n\t * Overrides the \"public_introspection_enabled\" setting field in the GraphQL Settings to be\n\t * checked and disabled so users can't uncheck it.\n\t *\n\t * @param array  $field_config The field config for the setting\n\t * @param string $field_name   The name of the field (unfilterable in the config)\n\t * @param string $section      The slug of the section the field is registered to\n\t *\n\t * @return mixed\n\t */\n\tpublic function filter_graphql_introspection_setting_field( $field_config, $field_name, $section ) {\n\t\tif ( 'graphql_general_settings' === $section && 'public_introspection_enabled' === $field_name ) {\n\t\t\t$field_config['value']    = 'on';\n\t\t\t$field_config['disabled'] = true;\n\t\t\t$field_config['desc']     = $field_config['desc'] . ' (<strong>' . __( 'Force enabled by WPGatsby. Gatsby requires WPGraphQL introspection to communicate with WordPress.', 'WPGatsby' ) . '</strong>)';\n\t\t}\n\n\t\treturn $field_config;\n\t}\n\n\t/**\n\t * Filters the value of the \"public_introspection_enabled\" setting to always be \"on\" when\n\t * WPGatsby is enabled\n\t *\n\t * @param mixed  $value          The value of the field\n\t * @param mixed  $default        The default value if there is no value set\n\t * @param string $field_name     The name of the option\n\t * @param array  $section_fields The setting values within the section\n\t * @param string $section_name   The name of the section the setting belongs to\n\t *\n\t * @return string\n\t */\n\tpublic function filter_graphql_introspection_setting_value( $value, $default, $field_name, $section_fields, $section_name ) {\n\t\tif ( 'graphql_general_settings' === $section_name && 'public_introspection_enabled' === $field_name ) {\n\t\t\treturn 'on';\n\t\t}\n\n\t\treturn $value;\n\t}\n\n\tfunction admin_init() {\n\t\t//set the settings\n\t\t$this->settings_api->set_sections( $this->get_settings_sections() );\n\t\t$this->settings_api->set_fields( $this->get_settings_fields() );\n\n\t\t//initialize settings\n\t\t$this->settings_api->admin_init();\n\t}\n\n\tfunction admin_menu() {\n\t\tadd_options_page(\n\t\t\t'Settings API',\n\t\t\t'Settings API',\n\t\t\t'delete_posts',\n\t\t\t'settings_api_test',\n\t\t\t[\n\t\t\t\t$this,\n\t\t\t\t'plugin_page',\n\t\t\t]\n\t\t);\n\t}\n\n\n\tfunction get_settings_sections() {\n\t\t$sections = [\n\t\t\t[\n\t\t\t\t'id'    => 'wpgatsby_settings',\n\t\t\t\t'title' => __( 'Settings', 'wpgatsby_settings' ),\n\t\t\t],\n\t\t];\n\n\t\treturn $sections;\n\t}\n\n\tpublic function register_settings_page() {\n\t\tadd_options_page(\n\t\t\t'Gatsby',\n\t\t\t'GatsbyJS',\n\t\t\t'manage_options',\n\t\t\t'gatsbyjs',\n\t\t\t[\n\t\t\t\t$this,\n\t\t\t\t'plugin_page',\n\t\t\t]\n\t\t);\n\t}\n\n\n\tfunction plugin_page() {\n\t\techo '<div class=\"wrap\">';\n\t\techo '<div class=\"notice-info notice\">\n\t\t\t<p>\n\t\t\t\t<a target=\"_blank\" href=\"'\n\t\t\t\t\t. esc_url( 'https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-wordpress/docs/tutorials/configuring-wp-gatsby.md' ) . '\">\n\t\t\t\t\tLearn how to configure WPGatsby here \n\t\t\t\t\t.\n\t\t\t\t</a>\n\t\t\t</p>\n\t\t</div>';\n\t\t$this->settings_api->show_navigation();\n\t\t$this->settings_api->show_forms();\n\t\techo '</div>';\n\t}\n\n\tstatic public function prefix_get_option( $option, $section, $default = '' ) {\n\t\t$options = get_option( $section );\n\n\t\tif ( isset( $options[ $option ] ) ) {\n\t\t\treturn $options[ $option ];\n\t\t}\n\n\t\treturn $default;\n\t}\n\n\tprivate static function generate_secret() {\n\t\t$factory   = new \\RandomLib\\Factory;\n\t\t$generator = $factory->getMediumStrengthGenerator();\n\t\t$secret    = $generator->generateString( 50 );\n\n\t\treturn $secret;\n\t}\n\n\tprivate static function get_default_secret() {\n\t\t$default_secret = self::get_setting( 'preview_jwt_secret' );\n\n\t\tif ( ! $default_secret ) {\n\t\t\t$default_secret = self::generate_secret();\n\t\t}\n\n\t\treturn $default_secret;\n\t}\n\n\tpublic static function sanitize_url_field( $input ) {\n\t\t$urls = explode( ',', $input );\n\t\tif ( count( $urls ) > 1 ) {\n\n\t\t\t// validate all urls\n\t\t\t$validated_urls = array_map(\n\t\t\t\tfunction ( $url ) {\n\t\t\t\t\treturn filter_var( $url, FILTER_VALIDATE_URL );\n\t\t\t\t},\n\t\t\t\t$urls\n\t\t\t);\n\n\t\t\t// then put em back together\n\t\t\treturn implode( ',', $validated_urls );\n\t\t}\n\n\t\treturn filter_var( $input, FILTER_VALIDATE_URL );\n\t}\n\n\tpublic static function get_setting( $key ) {\n\t\t$wpgatsby_settings = get_option( 'wpgatsby_settings' );\n\n\t\treturn $wpgatsby_settings[ $key ] ?? null;\n\t}\n\n\t/**\n\t * Returns all the settings fields\n\t *\n\t * @return array settings fields\n\t */\n\tfunction get_settings_fields() {\n\t\t$settings_fields = [\n\t\t\t'wpgatsby_settings' => [\n\t\t\t\t[\n\t\t\t\t\t'name'  => 'enable_gatsby_preview',\n\t\t\t\t\t'label' => __( 'Enable Gatsby Preview?', 'wpgatsby_settings' ),\n\t\t\t\t\t'desc'  => __( 'Yes, allow Gatsby to take over WordPress previews.', 'wpgatsby_settings' ),\n\t\t\t\t\t'type'  => 'checkbox',\n\t\t\t\t],\n\t\t\t\t[\n\t\t\t\t\t'name'              => 'preview_api_webhook',\n\t\t\t\t\t'label'             => __( 'Preview Webhook URL', 'wpgatsby_settings' ),\n\t\t\t\t\t'desc'              => __( 'Use a comma-separated list to configure multiple webhooks.', 'wpgatsby_settings' ),\n\t\t\t\t\t'placeholder'       => __( 'https://', 'wpgatsby_settings' ),\n\t\t\t\t\t'type'              => 'text',\n\t\t\t\t\t'sanitize_callback' => function ( $input ) {\n\t\t\t\t\t\treturn $this->sanitize_url_field( $input );\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\t[\n\t\t\t\t\t'name'              => 'builds_api_webhook',\n\t\t\t\t\t'label'             => __( 'Builds Webhook URL', 'wpgatsby_settings' ),\n\t\t\t\t\t'desc'              => __( 'Use a comma-separated list to configure multiple webhooks.', 'wpgatsby_settings' ),\n\t\t\t\t\t'placeholder'       => __( 'https://', 'wpgatsby_settings' ),\n\t\t\t\t\t'type'              => 'text',\n\t\t\t\t\t'sanitize_callback' => function ( $input ) {\n\t\t\t\t\t\treturn $this->sanitize_url_field( $input );\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\t[\n\t\t\t\t\t'name'              => 'gatsby_content_sync_url',\n\t\t\t\t\t'label'             => __( 'Gatsby Content Sync URL', 'wpgatsby_settings' ),\n\t\t\t\t\t'desc'              => __( 'Find this URL in your Gatsbyjs.com dashboard settings.', 'wpgatsby_settings' ), \n\t\t\t\t\t'placeholder'       => __( 'https://', 'wpgatsby_settings' ),\n\t\t\t\t\t'type'              => 'text',\n\t\t\t\t\t'sanitize_callback' => function ( $input ) {\n\t\t\t\t\t\treturn $this->sanitize_url_field( $input );\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\t[\n\t\t\t\t\t'name'              => 'preview_jwt_secret',\n\t\t\t\t\t'label'             => __( 'Preview JWT Secret', 'wpgatsby_settings' ),\n\t\t\t\t\t'desc'              => __( 'This secret is used in the encoding and decoding of the JWT token. If the Secret were ever changed on the server, ALL tokens that were generated with the previous Secret would become invalid. So, if you wanted to invalidate all user tokens, you can change the Secret on the server and all previously issued tokens would become invalid and require users to re-authenticate.', 'wpgatsby_settings' ),\n\t\t\t\t\t'type'              => 'password',\n\t\t\t\t\t'sanitize_callback' => 'sanitize_text_field',\n\t\t\t\t\t'default'           => self::get_default_secret(),\n\t\t\t\t],\n\t\t\t\t[\n\t\t\t\t\t'name'    => 'enable_gatsby_locations',\n\t\t\t\t\t'label'   => __( 'Enable Gatsby Menu Locations?', 'wpgatsby_settings' ),\n\t\t\t\t\t'desc'    => __( 'Yes', 'wpgatsby_settings' ),\n\t\t\t\t\t'type'    => 'checkbox',\n\t\t\t\t\t'default' => 'on',\n\t\t\t\t],\n\t\t\t],\n\t\t];\n\n\t\treturn $settings_fields;\n\t}\n}\n"
  },
  {
    "path": "src/Admin/includes/no-preview-url-set.php",
    "content": "<?php use WPGatsby\\Admin\\Preview; ?>\n<html lang=\"en\">\n\n<head>\n\t<meta charset=\"UTF-8\">\n\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n\t<meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\n\t<title>Preview</title>\n\t<style>\n\t\t<?php Preview::print_file_contents( 'includes/style.css' ); ?>\n\t</style>\n</head>\n\n<body>\n<div class=\"content\">\n\t<h1>Preview not found</h1>\n\t<p>Visit the <a\n\t\t\t\thref=\"<?php echo get_bloginfo( 'url' ); ?>/wp-admin/options-general.php?page=gatsbyjs\"\n\t\t\t\ttarget=\"_blank\" rel=\"noopener, nofollow. noreferrer, noopener, external\"\n\t\t\t\t>settings\n\t\t\tpage</a> to add a valid Preview webhook URL.\n\t\t<br>\n\t\t<br>\n\t\tIf you don't have a Gatsby Preview instance, you can <a\n\t\t\t\thref=\"https://www.gatsbyjs.com/preview/\" target=\"_blank\"\n\t\t\t\trel=\"noopener, nofollow. noreferrer, noopener, external\">set one up now on Gatsby\n\t\t\tCloud.</a>\n\t</p>\n</div>\n</body>\n\n</html>\n<?php wp_footer(); ?>\n"
  },
  {
    "path": "src/Admin/includes/post-type-not-shown-in-graphql.php",
    "content": "<?php use WPGatsby\\Admin\\Preview; ?>\n<html lang=\"en\">\n\n<head>\n\t<meta charset=\"UTF-8\">\n\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n\t<meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\n\t<title>Preview error</title>\n\t<style>\n\t\t<?php Preview::print_file_contents( 'includes/style.css' ); ?>\n\t</style>\n</head>\n\n<body>\n<div class=\"content\">\n\t<h1>Post type not configured properly</h1>\n\n\t<p>\n\t\tThe post type <b>\"<?php echo esc_html( get_post_type() ); ?>\"</b> is not set up properly for Gatsby Preview. \n\t\t<br />\n\t\tPost types must have <b>\"show_in_graphql\"</b> set to work with Preview.\n\t\t<br />\n\t\t<br />\n\t\t\n\t\tVisit the\n\t\t<a\n\t\t\thref=\"https://docs.wpgraphql.com/getting-started/custom-post-types/\" target=\"_blank\"\n\t\t\trel=\"noopener, nofollow. noreferrer, noopener, external\">\n\t\t\t\tWPGraphQL Docs\n\t\t</a>\n\t\tto learn how to configure this post type.\n\t</pre>\n</div>\n</body>\n\n</html>\n<?php wp_footer(); ?>\n"
  },
  {
    "path": "src/Admin/includes/preview-template.php",
    "content": "<?php\n\nuse WPGatsby\\Admin\\Preview;\n\nglobal $post;\n\n$gatsby_content_sync_url = Preview::get_gatsby_content_sync_url_for_post(\n\t$post\n);\n?>\n\n<html lang=\"en\">\n\n<head>\n\t<meta charset=\"UTF-8\">\n\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n\t<meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\n\t<title>Gatsby Preview</title>\n\n\t<style>\n\t\t<?php Preview::print_file_contents( 'includes/style.css' ); ?>\n\t</style>\n\n\t<script>\n\t\t<?php\n\t\t\tif ( $gatsby_content_sync_url ) {\n\t\t\t\t// Redirecting via JS because the page headers have already been set by the time we get into this template so PHP wont redirect.\n\t\t\t\techo 'window.location.replace(\"'. $gatsby_content_sync_url .'\");';\n\t\t\t}\n\t\t?>\n\t</script>\n</head>\n\n<body>\n<div class=\"content error\" style=\"<?php echo $gatsby_content_sync_url ? 'display: none;' : ''; ?>\">\n\t<h1>The Preview couldn't be loaded</h1>\n\t<p>\n\t\tPlease add your Gatsby Cloud Content Sync URL to the WPGatsby plugin <a\n\t\t\t\thref=\"<?php echo get_bloginfo( 'url' ); ?>/wp-admin/options-general.php?page=gatsbyjs\"\n\t\t\t\ttarget=\"_blank\" rel=\"noopener, nofollow. noreferrer, noopener, external\"\n\t\t>settings page</a>.\n\t</p>\n\t<br>\n\t<pre id=\"error-message-element\"></pre>\n\t<h2>Troubleshooting</h2>\n\t<span id=\"troubleshooting-html-area\">\n\t\t<p>\n\t\t\tPlease ensure your URL is correct and your Preview instance is up and running.\n\t\t\t<br>\n\t\t\t<br>\n\t\t\tIf you've set the correct URL, your Preview instance is currently running, and you're still having trouble, please <a\n\t\t\t\t\thref=\"https://www.gatsbyjs.com/cloud/docs/wordpress/getting-started/\" target=\"_blank\"\n\t\t\t\t\trel=\"noopener, nofollow. noreferrer, noopener, external\">refer to the docs</a> for\n\t\t\ttroubleshooting steps, ask your developer, or <a href=\"https://www.gatsbyjs.com/contact-us/\" target=\"_blank\"\n\t\t\t\t\t\t\t\t\t\trel=\"noopener, nofollow. noreferrer, noopener, external\">contact\n\t\t\t\tsupport</a> if that doesn't solve your issue.\n\t\t\t<br>\n\t\t\t<br>\n\t\t\tIf you don't have a valid Gatsby Preview instance, you can <a\n\t\t\t\t\thref=\"https://www.gatsbyjs.com/preview/\" target=\"_blank\"\n\t\t\t\t\trel=\"noopener, nofollow. noreferrer, noopener, external\">set one up now on Gatsby\n\t\t\t\tCloud.</a>\n\t\t\t</p>\n\t</span>\n\t<h2>Developer instructions</h2>\n\t<p>Please visit \n\t\t<a\n\t\t\thref=\"https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-wordpress/docs/tutorials/configuring-wp-gatsby.md#setting-up-preview\" target=\"_blank\"\n\t\t\trel=\"noopener, nofollow. noreferrer, noopener, external\"\n\t\t>\n\t\tthe docs\n\t\t</a> for instructions on setting up Gatsby Preview.\n\t</p>\n</div>\n</body>\n\n<?php wp_footer(); ?>\n\n</html>\n"
  },
  {
    "path": "src/Admin/includes/style.css",
    "content": "#loader {\n  position: fixed;\n  top: 32px;\n  bottom: 0;\n  left: 0;\n  right: 0;\n  width: 100%;\n  height: 100%;\n  height: calc(100% - 46px);\n  background: white;\n  z-index: 100;\n  text-align: center;\n  display: flex;\n  justify-content: center;\n  flex-direction: column;\n  opacity: 1;\n  transition: 0.125s ease-out opacity;\n  padding: 0 50px;\n  box-sizing: border-box;\n}\n\n@media (max-width: 782px) {\n  #loader {\n    top: 46px;\n  }\n}\n\n#loader.loaded {\n  opacity: 0;\n}\n\nbutton {\n  font-size: 1rem;\n  padding: 15px 30px;\n  cursor: pointer;\n  font-weight: medium;\n  color: white !important;\n  background: rebeccapurple;\n  border: none;\n  margin-top: 20px;\n  letter-spacing: 0.25px;\n}\n\nh1,\nh2,\npre,\np,\nli,\nb,\nbutton {\n  font-family: \"Futura PT\", -apple-system, \"BlinkMacSystemFont\", \"Segoe UI\",\n    \"Roboto\", \"Helvetica Neue\", \"Arial\", \"Noto Sans\", sans-serif,\n    \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\";\n  line-height: 1.45;\n}\n\nb,\np,\nbutton {\n  color: #272727;\n}\n\nh1,\nh2 {\n  color: rebeccapurple;\n}\n\nh1 {\n  display: block;\n  font-size: 2em;\n  margin-block-start: 0.67em;\n  margin-block-end: 0.67em;\n  margin-inline-start: 0px;\n  margin-inline-end: 0px;\n  font-weight: bold;\n}\n\nbody {\n  font-size: 18px;\n}\n\n#gatsby-loading-logo {\n  max-width: 80%;\n  width: 64px;\n  height: 64px;\n  margin: 0 auto;\n  margin-bottom: 10px;\n  box-shadow: 0 0 0 rgba(102, 51, 153, 0.4);\n  -webkit-animation: pulse 2s infinite;\n  animation: pulse 2s infinite;\n  border-radius: 50%;\n}\n\n@-webkit-keyframes pulse {\n  0% {\n    box-shadow: 0 0 0 0 rgba(102, 51, 153, 0.4);\n  }\n  70% {\n    box-shadow: 0 0 0 30px rgba(102, 51, 153, 0);\n  }\n  100% {\n    box-shadow: 0 0 0 0 rgba(102, 51, 153, 0);\n  }\n}\n\n@keyframes pulse {\n  0% {\n    box-shadow: 0 0 0 0 rgba(102, 51, 153, 0.4);\n  }\n  70% {\n    box-shadow: 0 0 0 30px rgba(102, 51, 153, 0);\n  }\n  100% {\n    box-shadow: 0 0 0 0 rgba(102, 51, 153, 0);\n  }\n}\n\n.content {\n  width: 100%;\n  left: 0;\n  padding-top: 46px;\n  padding-bottom: 70px;\n  min-height: 100%;\n  min-height: calc(100vh - 46px);\n  box-sizing: border-box;\n\n  display: flex;\n  justify-content: center;\n  align-items: center;\n  flex-direction: column;\n}\n\n#preview-loader-warning,\n.content {\n  max-width: 80%;\n  width: 800px;\n  margin: 0 auto;\n}\n\n.content p {\n  margin: 0 auto;\n}\n\niframe {\n  position: fixed;\n\n  width: 100%;\n  left: 0;\n\n  top: 46px;\n  height: 100%;\n  height: calc(100vh - 46px);\n}\n\n@media (min-width: 783px) {\n  iframe {\n    top: 32px;\n    height: calc(100vh - 32px);\n  }\n}\n\npre {\n  white-space: pre-wrap; /* css-3 */\n  word-wrap: break-word; /* Internet Explorer 5.5+ */\n\n  background: #f1f1f1;\n  padding: 50px 40px 40px 80px;\n  margin-bottom: 50px;\n\n  position: relative;\n  max-width: 640px;\n  box-sizing: border-box;\n}\n\nbr {\n  line-height: 1.75;\n}\n\n#error-message-element::before {\n  content: \"Error\";\n  position: absolute;\n  top: 0;\n  left: 0;\n  padding: 5px 10px;\n  background: rebeccapurple;\n  color: white;\n  font-size: 12px;\n}\n\na[target=\"_blank\"]::after {\n  content: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAQElEQVR42qXKwQkAIAxDUUdxtO6/RBQkQZvSi8I/pL4BoGw/XPkh4XigPmsUgh0626AjRsgxHTkUThsG2T/sIlzdTsp52kSS1wAAAABJRU5ErkJggg==);\n  margin: 0 3px 0 5px;\n}\n"
  },
  {
    "path": "src/GraphQL/Auth.php",
    "content": "<?php\n\nnamespace WPGatsby\\GraphQL;\n\nuse \\Firebase\\JWT\\JWT;\nuse \\WPGatsby\\Admin\\Settings;\n\nclass Auth {\n\tstatic function get_token() {\n\t\t$site_url    = get_bloginfo( 'url' );\n\t\t$secret      = Settings::get_setting( 'preview_jwt_secret' );\n\t\t$now         = time();\n\t\t$expiry      = $now + 3600;\n\t\t$user_id     = get_current_user_id();\n\n\t\t$payload = [\n\t\t\t'iss'  => $site_url,\n\t\t\t'aud'  => $site_url,\n\t\t\t'iat'  => $now,\n\t\t\t'nbf'  => $now,\n\t\t\t'exp'  => $expiry,\n\t\t\t'data' => [\n\t\t\t\t'user_id' => $user_id,\n\t\t\t],\n\t\t];\n\n\t\t$jwt = JWT::encode( $payload, $secret );\n\n\t\treturn $jwt;\n\t}\n}\n"
  },
  {
    "path": "src/GraphQL/ParseAuthToken.php",
    "content": "<?php\n\nnamespace WPGatsby\\GraphQL;\n\nuse \\Firebase\\JWT\\JWT;\nuse \\WPGatsby\\Admin\\Settings;\n\nclass ParseAuthToken {\n\tfunction __construct() {\n\t\tadd_action( 'init_graphql_request', [ $this, 'set_current_user' ] );\n\t}\n\n\tfunction set_current_user() {\n\t\t$jwt = $_SERVER['HTTP_WPGATSBYPREVIEW'] ?? null;\n\t\t\n\t\tif ( $jwt ) {\n\t\t\t$secret  = Settings::get_setting( 'preview_jwt_secret' );\n\t\t\t$decoded = JWT::decode( $jwt, $secret, [ 'HS256' ] );\n\t\t\t$decoded_user_id = $decoded->data->user_id ?? null;\n\n\t\t\tif ( ! $decoded || ! $decoded_user_id ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\t$jwt_is_for_existing_author = get_user_by(\n\t\t\t\t'id',\n\t\t\t\t$decoded_user_id\n\t\t\t);\n\n\t\t\t// we get the ID from a header so we can\n\t\t\t// process multiple user previews in a \n\t\t\t// single Gatsby Preview process.\n\t\t\t$user_id = $_SERVER['HTTP_WPGATSBYPREVIEWUSER']\n\t\t\t\t// if it doesn't exist, try the user from the token\n\t\t\t\t?? $decoded_user_id\n\t\t\t\t?? null;\n\n\t\t\tif ( $user_id && $decoded && $jwt_is_for_existing_author ) {\n\t\t\t\twp_set_current_user( $user_id );\n\t\t\t}\n\t\t}\n\t}\n\n}\n"
  },
  {
    "path": "src/Schema/Schema.php",
    "content": "<?php\n\nnamespace WPGatsby\\Schema;\n\n/**\n * Modifies the schema\n */\nclass Schema {\n\t/**\n\t *\n\t */\n\tfunction __construct() {\n\t\tnew SiteMeta();\n\t\tnew WPGatsbyWPGraphQLSchemaChanges();\n\t}\n}\n"
  },
  {
    "path": "src/Schema/SiteMeta.php",
    "content": "<?php\n\nnamespace WPGatsby\\Schema;\n\nuse Composer\\Semver\\Semver;\n\n/**\n * Adds info about the current site\n */\nclass SiteMeta {\n\t/**\n\t *\n\t */\n\tfunction __construct() {\n\t\tadd_action(\n\t\t\t'graphql_register_types',\n\t\t\tfunction() {\n\t\t\t\t$this->register();\n\t\t\t}\n\t\t);\n\t}\n\n\tprivate static function isVersionARange( $version ) {\n\t\t$version_without_periods             = str_replace( '.', '', $version );\n\t\t$version_without_numbers_and_periods = preg_replace(\n\t\t\t'/[0-9]+/',\n\t\t\t'',\n\t\t\t$version_without_periods\n\t\t);\n\n\t\treturn $version_without_numbers_and_periods !== '';\n\t}\n\n\t/**\n\t * Registers site meta fields...\n\t */\n\tfunction register() {\n\n\t\tregister_graphql_object_type(\n\t\t\t'WPGatsbySatisfies',\n\t\t\t[\n\t\t\t\t'description' => __( 'Check compatibility with WPGatsby and WPGraphQL.' ),\n\t\t\t\t'fields'      => [\n\t\t\t\t\t'wpGQL'    => [\n\t\t\t\t\t\t'type'        => 'Boolean',\n\t\t\t\t\t\t'description' => __( 'Whether the provided version range requirement for WPGraphQL is met by this WP instance.', 'wp-gatsby' ),\n\t\t\t\t\t],\n\t\t\t\t\t'wpGatsby' => [\n\t\t\t\t\t\t'type'        => 'Boolean',\n\t\t\t\t\t\t'description' => __( 'Whether the provided version range requirement for WPGatsby is met by this WP instance.', 'wp-gatsby' ),\n\t\t\t\t\t],\n\t\t\t\t],\n\t\t\t]\n\t\t);\n\n\t\tregister_graphql_object_type(\n\t\t\t'WPGatsbyCompatibility',\n\t\t\t[\n\t\t\t\t'description' => __( 'Check compatibility with a given version of gatsby-source-wordpress and the WordPress source site.' ),\n\t\t\t\t'fields'      => [\n\t\t\t\t\t'satisfies' => [\n\t\t\t\t\t\t'type' => 'WPGatsbySatisfies',\n\t\t\t\t\t],\n\t\t\t\t],\n\t\t\t]\n\t\t);\n\n\t\tregister_graphql_field(\n\t\t\t'RootQuery',\n\t\t\t'wpGatsbyCompatibility',\n\t\t\t[\n\t\t\t\t'description' => __( 'Information about the compatibility of the WordPress server with a provided version of gatsby-source-wordpress.', 'wp-gatsby' ),\n\t\t\t\t'type'        => 'WPGatsbyCompatibility',\n\t\t\t\t'args'        => [\n\t\t\t\t\t'wpGQLVersionRange'    => [\n\t\t\t\t\t\t'type'        => [ 'non_null' => 'String' ],\n\t\t\t\t\t\t'description' => __( 'The semver version range of WPGraphQL that the requester wants to check compatibility with', 'wp-gatsby' ),\n\t\t\t\t\t],\n\t\t\t\t\t'wpGatsbyVersionRange' => [\n\t\t\t\t\t\t'type'        => [ 'non_null' => 'String' ],\n\t\t\t\t\t\t'description' => __( 'The semver version range of WPGatsby that the requester wants to check compatibility with', 'wp-gatsby' ),\n\t\t\t\t\t],\n\t\t\t\t],\n\t\t\t\t'resolve'     => function( $root, $args, $context, $info ) {\n\n\t\t\t\t\t$wpgql_version_range    = $args['wpGQLVersionRange'] ?? null;\n\t\t\t\t\t$wpgatsby_version_range = $args['wpGatsbyVersionRange'] ?? null;\n\n\t\t\t\t\tif ( ! $wpgql_version_range ) {\n\t\t\t\t\t\tthrow new \\Exception(\n\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t'No WPGraphQL version was provided for the compatibility check. Please provide a semver version range for checking compatibility with WPGraphQL.',\n\t\t\t\t\t\t\t\t'wp-gatsby'\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( ! $wpgatsby_version_range ) {\n\t\t\t\t\t\tthrow new \\Exception(\n\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t'No WPGatsby version was provided for the compatibility check. Please provide a semver version range for checking compatibility with WPGatsby.',\n\t\t\t\t\t\t\t\t'wp-gatsby'\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( ! self::isVersionARange( $wpgql_version_range ) ) {\n\t\t\t\t\t\tthrow new \\Exception(\n\t\t\t\t\t\t\t'The provided WPGraphQL version is not a range. '\n\t\t\t\t\t\t\t. $wpgql_version_range\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( ! self::isVersionARange( $wpgatsby_version_range ) ) {\n\t\t\t\t\t\tthrow new \\Exception(\n\t\t\t\t\t\t\t'The provided WPGatsby version is not a range. '\n\t\t\t\t\t\t\t. $wpgatsby_version_range\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\t/**\n\t\t\t\t\t * Get the versions of WPGraphQL and WPGatsby\n\t\t\t\t\t */\n\t\t\t\t\t$installed_wpgraphql_version = defined( 'WPGRAPHQL_VERSION' )\n\t\t\t\t\t\t? WPGRAPHQL_VERSION\n\t\t\t\t\t\t: null;\n\n\t\t\t\t\t$installed_wpgatsby_version = defined( 'WPGATSBY_VERSION' )\n\t\t\t\t\t\t? WPGATSBY_VERSION\n\t\t\t\t\t\t: null;\n\n\t\t\t\t\t$wpgql_is_satisfied = Semver::satisfies(\n\t\t\t\t\t\t$installed_wpgraphql_version,\n\t\t\t\t\t\t$wpgql_version_range\n\t\t\t\t\t);\n\n\t\t\t\t\t$wpgatsby_is_satisfied = Semver::satisfies(\n\t\t\t\t\t\t$installed_wpgatsby_version,\n\t\t\t\t\t\t$wpgatsby_version_range\n\t\t\t\t\t);\n\n\t\t\t\t\t/**\n\t\t\t\t\t * Return the payload\n\t\t\t\t\t */\n\t\t\t\t\treturn [\n\t\t\t\t\t\t'satisfies' => [\n\t\t\t\t\t\t\t'wpGQL'    => $wpgql_is_satisfied,\n\t\t\t\t\t\t\t'wpGatsby' => $wpgatsby_is_satisfied,\n\t\t\t\t\t\t],\n\t\t\t\t\t];\n\n\t\t\t\t},\n\t\t\t]\n\t\t);\n\n\t\tregister_graphql_field(\n\t\t\t'RootQuery',\n\t\t\t'isWpGatsby',\n\t\t\t[\n\t\t\t\t'type'        => 'Boolean',\n\t\t\t\t'description' => __( 'Confirms this is a WP Gatsby site', 'wp-gatsby' ),\n\t\t\t\t'resolve'     => function() {\n\t\t\t\t\treturn true;\n\t\t\t\t},\n\t\t\t]\n\t\t);\n\n\t\tregister_graphql_field(\n\t\t\t'RootQuery',\n\t\t\t'schemaMd5',\n\t\t\t[\n\t\t\t\t'type'        => 'String',\n\t\t\t\t'description' => __( 'Returns an MD5 hash of the schema, useful in determining if the schema has changed.', 'wp-gatsby' ),\n\t\t\t\t'resolve'     => function() {\n\t\t\t\t\t$graphql     = \\graphql(\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t'query' => '{\n\t\t\t\t\t\t\t\t__schema {\n\t\t\t\t\t\t\t\t  types {\n\t\t\t\t\t\t\t\t\tkind\n\t\t\t\t\t\t\t\t\tname\n\t\t\t\t\t\t\t\t\tpossibleTypes {\n\t\t\t\t\t\t\t\t\t  kind\n\t\t\t\t\t\t\t\t\t  name\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tinterfaces {\n\t\t\t\t\t\t\t\t\t  kind\n\t\t\t\t\t\t\t\t\t  name\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tofType {\n\t\t\t\t\t\t\t\t\t  kind\n\t\t\t\t\t\t\t\t\t  name\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tfields {\n\t\t\t\t\t\t\t\t\t  name\n\t\t\t\t\t\t\t\t\t  type {\n\t\t\t\t\t\t\t\t\t\tname\n\t\t\t\t\t\t\t\t\t  }\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t  }\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t  }',\n\t\t\t\t\t\t]\n\t\t\t\t\t);\n\t\t\t\t\t$json_string = \\wp_json_encode( $graphql['data'] );\n\t\t\t\t\t$md5         = md5( $json_string );\n\n\t\t\t\t\treturn $md5;\n\t\t\t\t},\n\t\t\t]\n\t\t);\n\n\t\tregister_graphql_object_type(\n\t\t\t'WPGatsby',\n\t\t\t[\n\t\t\t\t'description' => __( 'Information needed by gatsby-source-wordpress.', 'wp-gatsby' ),\n\t\t\t\t'fields'      => [\n\t\t\t\t\t'arePrettyPermalinksEnabled' => [\n\t\t\t\t\t\t'description' => 'Returns wether or not pretty permalinks are enabled.',\n\t\t\t\t\t\t'type'        => 'Boolean',\n\t\t\t\t\t],\n\t\t\t\t],\n\t\t\t]\n\t\t);\n\n\t\tregister_graphql_field(\n\t\t\t'RootQuery',\n\t\t\t'wpGatsby',\n\t\t\t[\n\t\t\t\t'type'        => 'WPGatsby',\n\t\t\t\t'description' => __( 'Information needed by gatsby-source-wordpress.', 'wp-gatsby' ),\n\t\t\t\t'resolve'     => function( $root, $args, $context, $info ) {\n\t\t\t\t\treturn [\n\t\t\t\t\t\t'arePrettyPermalinksEnabled' =>\n\t\t\t\t\t\t\t! ! get_option( 'permalink_structure' ),\n\t\t\t\t\t];\n\t\t\t\t},\n\t\t\t]\n\t\t);\n\t}\n}\n"
  },
  {
    "path": "src/Schema/WPGatsbyWPGraphQLSchemaChanges.php",
    "content": "<?php\n\nnamespace WPGatsby\\Schema;\n\n/**\n * Modifies WPGraphQL built-in types\n */\nclass WPGatsbyWPGraphQLSchemaChanges {\n\tfunction __construct() {\n\t\tadd_action(\n\t\t\t'graphql_register_types',\n\t\t\tfunction() {\n\t\t\t\t$this->register();\n\t\t\t}\n\t\t);\n\t}\n\n\tfunction register() {\n\t\tregister_graphql_field(\n\t\t\t'ContentType',\n\t\t\t'archivePath',\n\t\t\t[\n\t\t\t\t'type'        => 'String',\n\t\t\t\t'description' => __( 'The url path of the first page of the archive page for this content type.', 'wp-gatsby' ),\n\t\t\t\t'resolve'     => function( $source, $args, $context, $info ) {\n\t\t\t\t\t$archive_link = get_post_type_archive_link( $source->name );\n\n\t\t\t\t\tif ( empty( $archive_link ) ) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\n\t\t\t\t\t$site_url = get_site_url();\n\n\t\t\t\t\t$archive_path = str_replace( $site_url, '', $archive_link );\n\n\t\t\t\t\tif ( $archive_link === $site_url && $archive_path === '' ) {\n\t\t\t\t\t\treturn '/';\n\t\t\t\t\t}\n\n\t\t\t\t\treturn $archive_path ?? null;\n\t\t\t\t},\n\t\t\t]\n\t\t);\n\n\t\tregister_graphql_field(\n\t\t\t'Taxonomy',\n\t\t\t'archivePath',\n\t\t\t[\n\t\t\t\t'type'        => 'String',\n\t\t\t\t'description' => __( 'The url path of the first page of the archive page for this content type.', 'wp-gatsby' ),\n\t\t\t\t'resolve'     => function( $source, $args, $context, $info ) {\n\t\t\t\t\t$tax = get_taxonomy( $source->name );\n\n\t\t\t\t\tif ( ! $tax->rewrite['slug'] ?? false ) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn '/' . $tax->rewrite['slug'] . '/';\n\t\t\t\t},\n\t\t\t]\n\t\t);\n\t}\n}\n"
  },
  {
    "path": "src/ThemeSupport/ThemeSupport.php",
    "content": "<?php\n\nnamespace WPGatsby\\ThemeSupport;\n\nuse WPGatsby\\Admin\\Settings;\n\n/**\n * Modifies the schema\n */\nclass ThemeSupport {\n\t/**\n\t *\n\t */\n\tfunction __construct() {\n\t\tadd_action( 'init', [ $this, 'registerGatsbyMenuLocations' ] );\n\t}\n\n\tfunction registerGatsbyMenuLocations() {\n\t\t$enable_gatsby_locations = 'on' === Settings::get_setting( 'enable_gatsby_locations' );\n\n\t\tif ( ! $enable_gatsby_locations ) {\n\t\t\treturn;\n\t\t}\n\n\t\t$gatsby_locations = apply_filters(\n\t\t\t'gatsby_locations',\n\t\t\t[\n\t\t\t\t'gatsby-header-menu' => __( 'Header Menu [Added by WPGatsby]', 'WPGatsby' ),\n\t\t\t\t'gatsby-footer-menu' => __( 'Footer Menu [Added by WPGatsby]', 'WPGatsby' ),\n\t\t\t]\n\t\t);\n\n\t\tregister_nav_menus( $gatsby_locations );\n\t}\n}\n"
  },
  {
    "path": "src/Utils/Utils.php",
    "content": "<?php\n\nnamespace WPGatsby\\Utils;\n\nclass Utils {\n\n    /**\n     * Checks if any of the strings in $substr_array is a substring in the $haystack.\n     *\n     * @since 2.1.2\n     *\n     * @param string $haystack\n     * @param array $substr_array\n     * @param int $offset\n     *\n     * @return bool\n     */\n    public static function str_in_substr_array(string $haystack, array $substr_array, int $offset = 0): bool {\n        foreach ( $substr_array as $substr ) {\n            if ($substr && strpos($haystack, $substr, $offset) !== false ) {\n                return true;\n            }\n        }\n\n        return false;\n    }\n}\n"
  },
  {
    "path": "tests/_data/.gitignore",
    "content": "dump.sql\n"
  },
  {
    "path": "tests/_data/.gitkeep",
    "content": ""
  },
  {
    "path": "tests/_data/config.php",
    "content": "<?php\n/**\n * Disable autoloading while running tests, as the test\n * suite already bootstraps the autoloader and creates\n * fatal errors when the autoloader is loaded twice\n */\n\nif ( ! defined( 'GRAPHQL_DEBUG' ) ) {\n\tdefine( 'GRAPHQL_DEBUG', true );\n}\n"
  },
  {
    "path": "tests/_output/.gitignore",
    "content": "failed\n"
  },
  {
    "path": "tests/_output/.gitkeep",
    "content": ""
  },
  {
    "path": "tests/_support/AcceptanceTester.php",
    "content": "<?php\n\n\n/**\n * Inherited Methods\n *\n * @method void wantToTest($text)\n * @method void wantTo($text)\n * @method void execute($callable)\n * @method void expectTo($prediction)\n * @method void expect($prediction)\n * @method void amGoingTo($argumentation)\n * @method void am($role)\n * @method void lookForwardTo($achieveValue)\n * @method void comment($description)\n * @method \\Codeception\\Lib\\Friend haveFriend($name, $actorClass = NULL)\n *\n * @SuppressWarnings(PHPMD)\n */\nclass AcceptanceTester extends \\Codeception\\Actor {\n\n\tuse _generated\\AcceptanceTesterActions;\n\n\t/**\n\t * Define custom actions here\n\t */\n}\n"
  },
  {
    "path": "tests/_support/FunctionalTester.php",
    "content": "<?php\n\n\n/**\n * Inherited Methods\n *\n * @method void wantToTest($text)\n * @method void wantTo($text)\n * @method void execute($callable)\n * @method void expectTo($prediction)\n * @method void expect($prediction)\n * @method void amGoingTo($argumentation)\n * @method void am($role)\n * @method void lookForwardTo($achieveValue)\n * @method void comment($description)\n * @method \\Codeception\\Lib\\Friend haveFriend($name, $actorClass = NULL)\n *\n * @SuppressWarnings(PHPMD)\n */\nclass FunctionalTester extends \\Codeception\\Actor {\n\n\tuse _generated\\FunctionalTesterActions;\n\n\t/**\n\t * Define custom actions here\n\t */\n}\n"
  },
  {
    "path": "tests/_support/Helper/Acceptance.php",
    "content": "<?php\nnamespace Helper;\n\n// here you can define custom actions\n// all public methods declared in helper class will be available in $I\n\nclass Acceptance extends \\Codeception\\Module\n{\n\n}\n"
  },
  {
    "path": "tests/_support/Helper/Functional.php",
    "content": "<?php\nnamespace Helper;\n\n// here you can define custom actions\n// all public methods declared in helper class will be available in $I\n\nclass Functional extends \\Codeception\\Module\n{\n\n}\n"
  },
  {
    "path": "tests/_support/Helper/Unit.php",
    "content": "<?php\nnamespace Helper;\n\n// here you can define custom actions\n// all public methods declared in helper class will be available in $I\n\nclass Unit extends \\Codeception\\Module\n{\n\n}\n"
  },
  {
    "path": "tests/_support/Helper/Wpunit.php",
    "content": "<?php\nnamespace Helper;\n\n// here you can define custom actions\n// all public methods declared in helper class will be available in $I\n\nclass Wpunit extends \\Codeception\\Module\n{\n\n}\n"
  },
  {
    "path": "tests/_support/UnitTester.php",
    "content": "<?php\n\n\n/**\n * Inherited Methods\n * @method void wantToTest($text)\n * @method void wantTo($text)\n * @method void execute($callable)\n * @method void expectTo($prediction)\n * @method void expect($prediction)\n * @method void amGoingTo($argumentation)\n * @method void am($role)\n * @method void lookForwardTo($achieveValue)\n * @method void comment($description)\n * @method \\Codeception\\Lib\\Friend haveFriend($name, $actorClass = NULL)\n *\n * @SuppressWarnings(PHPMD)\n*/\nclass UnitTester extends \\Codeception\\Actor\n{\n    use _generated\\UnitTesterActions;\n\n   /**\n    * Define custom actions here\n    */\n}\n"
  },
  {
    "path": "tests/_support/WpunitTester.php",
    "content": "<?php\n\n\n/**\n * Inherited Methods\n *\n * @method void wantToTest($text)\n * @method void wantTo($text)\n * @method void execute($callable)\n * @method void expectTo($prediction)\n * @method void expect($prediction)\n * @method void amGoingTo($argumentation)\n * @method void am($role)\n * @method void lookForwardTo($achieveValue)\n * @method void comment($description)\n * @method \\Codeception\\Lib\\Friend haveFriend($name, $actorClass = NULL)\n *\n * @SuppressWarnings(PHPMD)\n */\nclass WpunitTester extends \\Codeception\\Actor {\n\n\tuse _generated\\WpunitTesterActions;\n\n\t/**\n\t * Define custom actions here\n\t */\n\n}\n"
  },
  {
    "path": "tests/_support/_generated/.gitignore",
    "content": "*\n!.gitignore"
  },
  {
    "path": "tests/acceptance.suite.dist.yml",
    "content": "# Codeception Test Suite Configuration\n#\n# Suite for acceptance tests.\n# Perform tests in browser using the WPWebDriver or WPBrowser.\n# Use WPDb to set up your initial database fixture.\n# If you need both WPWebDriver and WPBrowser tests - create a separate suite.\n\nactor: AcceptanceTester\nmodules:\n  enabled:\n    - Asserts\n    - REST\n    - WPBrowser\n    - WPDb\n    - WPLoader\n  config:\n    WPDb:\n      cleanup: false\n"
  },
  {
    "path": "tests/functional.suite.dist.yml",
    "content": "# Codeception Test Suite Configuration\n#\n# Suite for functional tests\n# Emulate web requests and make WordPress process them\n\nactor: FunctionalTester\nmodules:\n  enabled:\n    - Asserts\n    - REST\n    - WPBrowser\n    - WPDb\n    - WPLoader\n  config:\n    WPDb:\n      cleanup: false\n"
  },
  {
    "path": "tests/wpunit/ActionMonitorTest.php",
    "content": "<?php\n\nclass ActionMonitorTest extends \\Tests\\WPGraphQL\\TestCase\\WPGraphQLTestCase {\n\n\tpublic $admin;\n\tpublic $tag;\n\n\tpublic function setUp(): void {\n\t\t// Before...\n\t\tparent::setUp();\n\n\t\tWPGraphQL::clear_schema();\n\t\t// Your set up methods here.\n\n\t\t$this->admin = $this->factory()->user->create( [ 'role' => 'administrator' ] );\n\t\t$this->tag   = $this->factory()->tag->create();\n\n\t\t$this->clear_action_monitor();\n\t}\n\n\tpublic function tearDown(): void {\n\t\t$this->delete_posts();\n\n\t\t// Then...\n\t\tparent::tearDown();\n\t}\n\n\tpublic function clear_action_monitor() {\n\t\tglobal $wpdb;\n\t\t$sql = wp_strip_all_tags(\n\t\t\t'DELETE posts, pm, pt\n\t\t\tFROM ' . $wpdb->prefix . 'posts AS posts\n\t\t\tLEFT JOIN ' . $wpdb->prefix . 'term_relationships AS pt ON pt.object_id = posts.ID\n\t\t\tLEFT JOIN ' . $wpdb->prefix . 'postmeta AS pm ON pm.post_id = posts.ID\n\t\t\tWHERE posts.post_type = \\'%1$s\\'', true\n\t\t);\n\n\t\t$query = $wpdb->prepare( $sql, 'action_monitor' );\n\t\t$wpdb->query( $query );\n\n\t\tadd_filter( 'wpgatsby_action_monitor_get_updated_post_ids', function() {\n\t\t\treturn [];\n\t\t} );\n\n\t}\n\n\tpublic function delete_posts() {\n\n\t\tglobal $wpdb;\n\t\t$wpdb->query( $wpdb->prepare(\n\t\t\t\"DELETE FROM {$wpdb->prefix}posts WHERE ID <> %d\",\n\t\t\tarray( 1 )\n\t\t) );\n\n\t}\n\n\t// Tests\n\tpublic function test_it_works() {\n\t\t$post = static::factory()->post->create_and_get();\n\t\t$this->assertInstanceOf( \\WP_Post::class, $post );\n\t}\n\n\tpublic function actionMonitorQuery() {\n\t\treturn '\n    \t{\n\t\t  actionMonitorActions {\n\t\t    nodes {\n\t          actionType\n\t          referencedNodeID\n\t          referencedNodeSingularName\n\t\t    }\n\t\t  }\n\t\t}\n    \t';\n\t}\n\n\tpublic function testActionMonitorQueryIsValid() {\n\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( [ 'query' => $query ] );\n\t\t$this->assertIsValidQueryResponse( $actual );\n\t}\n\n\tpublic function testCreatePostCreatesActionMonitorAction() {\n\n\t\t// Create a post\n\t\t$post_id = $this->factory()->post->create( [\n\t\t\t'post_type'   => 'post',\n\t\t\t'post_status' => 'publish',\n\t\t\t'post_title'  => 'Title',\n\t\t\t'post_author' => $this->admin,\n\t\t\t'tags_input'  => [ $this->tag ]\n\t\t] );\n\n\t\tcodecept_debug( $this->tag );\n\n\t\t// Query for action monitor actions\n\t\t$query = $this->actionMonitorQuery();\n\n\t\t// Execute the query\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\n\t\t$this->assertIsValidQueryResponse( $actual );\n\n\t\t// Creating a post assigned to an author should trigger 2 actions:\n\t\t// - 1 for the post\n\t\t// - 1 for the author\n\t\t$this->assertSame( 2, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t// Assert the action monitor has the actions for the post being created\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'CREATE',\n\t\t\t\t'referencedNodeID'           => (string) $post_id,\n\t\t\t\t'referencedNodeSingularName' => 'post',\n\t\t\t] ),\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $this->admin,\n\t\t\t\t'referencedNodeSingularName' => 'user'\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testCreatePageCreatesActionMonitorAction() {\n\n\t\t// Create a post\n\t\t$post_id = $this->factory()->post->create( [\n\t\t\t'post_type'   => 'page',\n\t\t\t'post_status' => 'publish',\n\t\t\t'post_title'  => 'Title',\n\t\t\t'post_author' => $this->admin,\n\t\t] );\n\n\t\t// Query for action monitor actions\n\t\t$query = $this->actionMonitorQuery();\n\n\t\t// Execute the query\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\n\t\tcodecept_debug( $actual );\n\n\t\t// Creating a post assigned to an author should trigger 2 actions:\n\t\t// - 1 for the post\n\t\t// - 1 for the author\n\t\t$this->assertSame( 2, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t// Assert the action monitor has the actions for the page being created\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'CREATE',\n\t\t\t\t'referencedNodeID'           => (string) $post_id,\n\t\t\t\t'referencedNodeSingularName' => 'page'\n\t\t\t] ),\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $this->admin,\n\t\t\t\t'referencedNodeSingularName' => 'user'\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testDeletePostCreatesActionMonitorAction() {\n\n\t\t// Create a post\n\t\t$post_id = $this->factory()->post->create( [\n\t\t\t'post_type'   => 'post',\n\t\t\t'post_status' => 'publish',\n\t\t\t'post_title'  => 'Title',\n\t\t\t'post_author' => $this->admin\n\t\t] );\n\n\t\t// create a 2nd post for the user. if the user still has published posts\n\t\t// this should trigger an update action for the user\n\t\t$this->factory()->post->create( [\n\t\t\t'post_type'   => 'post',\n\t\t\t'post_status' => 'publish',\n\t\t\t'post_title'  => 'Title',\n\t\t\t'post_author' => $this->admin\n\t\t] );\n\n\t\t// Clear the action monitor to remove the mock post creation\n\t\t$this->clear_action_monitor();\n\n\t\t// Query for action monitor actions\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\twp_delete_post( $post_id, true );\n\n\t\t// Query for action monitor actions\n\t\t$query = $this->actionMonitorQuery();\n\n\t\t// Execute the query\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\n\t\t/**\n\t\t * There should be 2 action for deleting the page\n\t\t * - 1 for DELETE page\n\t\t * - 1 for UPDATE user (the user still has 1 published post)\n\t\t */\n\t\t$this->assertSame( 2, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\tcodecept_debug( $actual );\n\n\t\t// Assert the action monitor has the actions for the page being created\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'DELETE',\n\t\t\t\t'referencedNodeID'           => (string) $post_id,\n\t\t\t\t'referencedNodeSingularName' => 'post'\n\t\t\t] ),\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $this->admin,\n\t\t\t\t'referencedNodeSingularName' => 'user'\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testDeleteOnlyPostByAuthorCreatesActionMonitorActions() {\n\n\t\t// Create a post\n\t\t$post_id = $this->factory()->post->create( [\n\t\t\t'post_type'   => 'post',\n\t\t\t'post_status' => 'publish',\n\t\t\t'post_title'  => 'Title',\n\t\t\t'post_author' => $this->admin\n\t\t] );\n\n\t\t// Clear the action monitor to remove the mock post creation\n\t\t$this->clear_action_monitor();\n\n\t\t// Query for action monitor actions\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\twp_delete_post( $post_id, true );\n\n\t\t// Query for action monitor actions\n\t\t$query = $this->actionMonitorQuery();\n\n\t\t// Execute the query\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\n\t\t/**\n\t\t * There should be 2 action for deleting the page\n\t\t * - 1 for DELETE page\n\t\t * - 1 for DELETE user (the user has no published posts so is no longer public)\n\t\t */\n\t\t$this->assertSame( 2, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\tcodecept_debug( $actual );\n\n\t\t// Assert the action monitor has the actions for the page being created\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'DELETE',\n\t\t\t\t'referencedNodeID'           => (string) $post_id,\n\t\t\t\t'referencedNodeSingularName' => 'post'\n\t\t\t] ),\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'DELETE',\n\t\t\t\t'referencedNodeID'           => (string) $this->admin,\n\t\t\t\t'referencedNodeSingularName' => 'user'\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testDeleteDraftPostDoesNotCreateActionMonitorAction() {\n\n\t\t// Create a post\n\t\t$post_id = $this->factory()->post->create( [\n\t\t\t'post_type'   => 'draft',\n\t\t\t'post_status' => 'publish',\n\t\t\t'post_title'  => 'Title',\n\t\t\t'post_author' => $this->admin\n\t\t] );\n\n\t\t// Clear the action monitor to remove the mock post creation\n\t\t$this->clear_action_monitor();\n\n\t\t// Query for action monitor actions\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\twp_delete_post( $post_id, true );\n\n\t\t// Query for action monitor actions\n\t\t$query = $this->actionMonitorQuery();\n\n\t\t// Execute the query\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\n\t\t/**\n\t\t * There should be 0 action for deleting a draft post\n\t\t */\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\tcodecept_debug( $actual );\n\n\t}\n\n\tpublic function testTrashPostCreatesActionMonitorAction() {\n\n\t\t// Create a post\n\t\t$post_id = $this->factory()->post->create( [\n\t\t\t'post_type'   => 'post',\n\t\t\t'post_status' => 'publish',\n\t\t\t'post_title'  => 'Title',\n\t\t] );\n\n\t\t// Clear the action monitor to remove the mock post creation\n\t\t$this->clear_action_monitor();\n\n\t\t// Query for action monitor actions\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t// Trashing a post should crate an action monitor entry for delete post\n\t\twp_trash_post( $post_id );\n\n\t\t// Query for action monitor actions\n\t\t$query = $this->actionMonitorQuery();\n\n\t\t// Execute the query\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\n\t\t/**\n\t\t * There should be 1 action for deleting the post\n\t\t */\n\t\t$this->assertSame( 1, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\tcodecept_debug( $actual );\n\n\t\t// Assert the action monitor has the actions for the post being created\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'DELETE',\n\t\t\t\t'referencedNodeID'           => (string) $post_id,\n\t\t\t\t'referencedNodeSingularName' => 'post'\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testPublishPostFromDraftCreatesActionMonitorAction() {\n\n\t\t$post_data = [\n\t\t\t'post_status' => 'draft',\n\t\t\t'post_type'   => 'post',\n\t\t\t'post_author' => $this->admin,\n\t\t\t'tags_input'  => [ $this->tag ],\n\t\t];\n\n\t\t$post_id = $this->factory()->post->create( $post_data );\n\n\t\t$this->clear_action_monitor();\n\n\t\t// Query for action monitor actions\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t// Publish the post\n\t\twp_update_post( [ 'ID' => $post_id, 'post_status' => 'publish' ] );\n\n\t\t// Execute the query\n\t\t$actions = $this->graphql( compact( 'query' ) );\n\n\t\t/**\n\t\t * There should be 2 actions\n\t\t * - 1 for the created post\n\t\t * - 1 for the updated author\n\t\t */\n\t\t$this->assertSame( 2, count( $actions['data']['actionMonitorActions']['nodes'] ) );\n\n\t\tcodecept_debug( $actions );\n\n\t\t// Assert the action monitor has the actions for the page being created\n\t\t$this->assertQuerySuccessful( $actions, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'CREATE',\n\t\t\t\t'referencedNodeID'           => (string) $post_id,\n\t\t\t\t'referencedNodeSingularName' => 'post'\n\t\t\t] ),\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $this->admin,\n\t\t\t\t'referencedNodeSingularName' => 'user'\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testChangePostToDraftCreatesActionMonitorAction() {\n\n\t\t$post_id = $this->factory()->post->create([\n\t\t\t'post_type' => 'post',\n\t\t\t'post_status' => 'publish',\n\t\t\t'post_title' => 'test',\n\t\t\t'post_author' => $this->admin,\n\t\t]);\n\n\t\t// Create a 2nd post for the user. Changing one post to draft\n\t\t// should trigger an UPDATE for the user.\n\t\t$post_two = $this->factory()->post->create([\n\t\t\t'post_type' => 'post',\n\t\t\t'post_status' => 'publish',\n\t\t\t'post_title' => 'test',\n\t\t\t'post_author' => $this->admin,\n\t\t]);\n\n\t\t$this->clear_action_monitor();\n\n\t\t// Query for action monitor actions\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t// Changing a published post to draft (or any non-published status) should\n\t\t// trigger a delete action for the post\n\t\twp_update_post([\n\t\t\t'ID' => $post_id,\n\t\t\t'post_status' => 'draft',\n\t\t]);\n\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'DELETE',\n\t\t\t\t'referencedNodeID'           => (string) $post_id,\n\t\t\t\t'referencedNodeSingularName' => 'post'\n\t\t\t] ),\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $this->admin,\n\t\t\t\t'referencedNodeSingularName' => 'user'\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testChangeAuthorsOnPublishedPostCreatesActionMonitorActions() {\n\n\t\t$user_two = $this->factory()->user->create([\n\t\t\t'role' => 'editor'\n\t\t]);\n\n\t\t$post_one_for_admin = $this->factory()->post->create([\n\t\t\t'post_type' => 'post',\n\t\t\t'post_status' => 'publish',\n\t\t\t'post_title' => 'test',\n\t\t\t'post_author' => $this->admin,\n\t\t]);\n\n\t\t$post_two_for_admin = $this->factory()->post->create([\n\t\t\t'post_type' => 'post',\n\t\t\t'post_status' => 'publish',\n\t\t\t'post_title' => 'test',\n\t\t\t'post_author' => $this->admin,\n\t\t]);\n\n\t\t$post_one_for_user_two = $this->factory()->post->create([\n\t\t\t'post_type' => 'post',\n\t\t\t'post_status' => 'publish',\n\t\t\t'post_title' => 'test',\n\t\t\t'post_author' => $user_two,\n\t\t]);\n\n\t\t$post_two_for_user_two = $this->factory()->post->create([\n\t\t\t'post_type' => 'post',\n\t\t\t'post_status' => 'publish',\n\t\t\t'post_title' => 'test',\n\t\t\t'post_author' => $user_two,\n\t\t]);\n\n\t\t$this->clear_action_monitor();\n\n\t\t// Query for action monitor actions\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\twp_update_post([\n\t\t\t'ID' => $post_one_for_admin,\n\t\t\t'post_author' => $user_two\n\t\t]);\n\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\n\t\t// Changing the author of a post should create 3 actions\n\t\t// - for the post\n\t\t// - 1 for the new author\n\t\t// - 1 for the previous author\n\t\t$this->assertSame( 3, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $post_one_for_admin,\n\t\t\t\t'referencedNodeSingularName' => 'post'\n\t\t\t] ),\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $this->admin,\n\t\t\t\t'referencedNodeSingularName' => 'user'\n\t\t\t] ),\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $user_two,\n\t\t\t\t'referencedNodeSingularName' => 'user'\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testChangeOnlyPostFromAuthorToDraftCreatesActionMonitorActions() {\n\n\t\t$post_id = $this->factory()->post->create([\n\t\t\t'post_type' => 'post',\n\t\t\t'post_status' => 'publish',\n\t\t\t'post_title' => 'test',\n\t\t\t'post_author' => $this->admin,\n\t\t]);\n\n\t\t$this->clear_action_monitor();\n\n\t\t// Query for action monitor actions\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t// Changing a published post to draft (or any non-published status) should\n\t\t// trigger a delete action for the post\n\t\twp_update_post([\n\t\t\t'ID' => $post_id,\n\t\t\t'post_status' => 'draft',\n\t\t]);\n\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\n\t\t// The author only has 1 published post. Making it a draft post\n\t\t// means the author is unpublished and we need to\n\t\t// tell Gatsby to delete the user.\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'DELETE',\n\t\t\t\t'referencedNodeID'           => (string) $post_id,\n\t\t\t\t'referencedNodeSingularName' => 'post'\n\t\t\t] ),\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'DELETE',\n\t\t\t\t'referencedNodeID'           => (string) $this->admin,\n\t\t\t\t'referencedNodeSingularName' => 'user'\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testPublishScheduledPostCreatesActionMonitorAction() {\n\n\t\t// Create a future post\n\t\t$post_id = $this->factory()->post->create([\n\t\t\t'post_type' => 'post',\n\t\t\t'post_status' => 'future',\n\t\t\t'post_title' => 'Test Scheduled Post',\n\t\t\t'post_author' => $this->admin,\n\t\t\t'post_date' => date( \"Y-m-d H:i:s\", strtotime( '+1 day' ) ),\n\t\t]);\n\n\t\t// Make sure action monitor is cleared\n\t\t$this->clear_action_monitor();\n\n\t\t// Query for action monitor actions\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t// publish the post\n\t\twp_publish_post( $post_id );\n\n\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\n\t\t// There should be 2 actions created.\n\t\t// - 1 for the published post\n\t\t// - 1 for the author\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'CREATE',\n\t\t\t\t'referencedNodeID'           => (string) $post_id,\n\t\t\t\t'referencedNodeSingularName' => 'post'\n\t\t\t] ),\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $this->admin,\n\t\t\t\t'referencedNodeSingularName' => 'user'\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testUpdatePostMetaOfUnublishedPostDoesNotCreatesActionMonitorAction() {\n\n\t\t$post_id = $this->factory()->post->create([\n\t\t\t'post_type' => 'post',\n\t\t\t'post_status' => 'draft',\n\t\t\t'post_title' => 'test',\n\t\t\t'post_author' => $this->admin,\n\t\t]);\n\n\t\t// Make sure action monitor is cleared\n\t\t$this->clear_action_monitor();\n\n\t\t// Query for action monitor actions\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\tupdate_post_meta( $post_id, 'test_post_meta', 'test' );\n\n\t\t// Query for action monitor actions\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t}\n\n\n\tpublic function testDeletePostMetaOfUnublishedPostDoesNotCreatesActionMonitorAction() {\n\n\t\t$post_id = $this->factory()->post->create([\n\t\t\t'post_type' => 'post',\n\t\t\t'post_status' => 'draft',\n\t\t\t'post_title' => 'test',\n\t\t\t'post_author' => $this->admin,\n\t\t]);\n\n\t\tupdate_post_meta( $post_id, 'test_post_meta', 'test' );\n\n\t\t// Make sure action monitor is cleared\n\t\t$this->clear_action_monitor();\n\n\t\t// Query for action monitor actions\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\tdelete_post_meta( $post_id, 'test_post_meta' );\n\n\t\t// Query for action monitor actions\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t}\n\n\tpublic function testUpdatePostMetaOfPublishedPostCreatesActionMonitorAction() {\n\n\t\t$post_id = $this->factory()->post->create([\n\t\t\t'post_type' => 'post',\n\t\t\t'post_status' => 'publish',\n\t\t\t'post_title' => 'test update meta',\n\t\t\t'post_author' => $this->admin,\n\t\t]);\n\n\t\t$this->clear_action_monitor();\n\n\t\t// Query for action monitor actions\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\tupdate_post_meta( absint( $post_id ), 'test_meta', 'test_value' );\n\n\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\n\t\t/**\n\t\t * There should be 1 actions\n\t\t * - 1 for the updated post\n\t\t */\n\t\t$this->assertSame( 1, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\tcodecept_debug( $actual );\n\n\t\t// Assert the action monitor has the actions for the page being created\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $post_id,\n\t\t\t\t'referencedNodeSingularName' => 'post'\n\t\t\t] ),\n\t\t] );\n\n\n\t}\n\n\tpublic function testDeletePostMetaCreatesActionMonitorAction() {\n\n\t\t$post_id = $this->factory()->post->create( [\n\t\t\t'post_status' => 'publish',\n\t\t\t'post_type'   => 'post',\n\t\t\t'post_author' => $this->admin,\n\t\t\t'tags_input'  => [ $this->tag ],\n\t\t] );\n\n\t\tupdate_post_meta( $post_id, 'test_meta', 'test_value' );\n\n\t\t$this->clear_action_monitor();\n\n\t\t// Query for action monitor actions\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\tdelete_post_meta( $post_id, 'test_meta' );\n\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\n\t\t/**\n\t\t * There should be 1 actions\n\t\t * - 1 for the updated post\n\t\t */\n\t\t$this->assertSame( 1, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\tcodecept_debug( $actual );\n\n\t\t// Assert the action monitor has the actions for the page being created\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $post_id,\n\t\t\t\t'referencedNodeSingularName' => 'post'\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testNewPostTypesDetectedWithGraphqlSupportCreateActionMonitorAction() {\n\n\t\t$post_types = get_post_types([ 'show_in_graphql' => true, 'public' => true ]);\n\t\tupdate_option( '_gatsby_tracked_post_types', $post_types );\n\n\t\t$this->clear_action_monitor();\n\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t$added_post_type = 'new_type';\n\t\t$post_types[] = $added_post_type;\n\t\tupdate_option( '_gatsby_tracked_post_types', $post_types );\n\n\t\tdo_action( 'gatsby_init_action_monitors' );\n\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 1, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\t\tcodecept_debug( $actual );\n\n\t}\n\n\tpublic function testPostTypeRemovedFromGraphQLCreateActionMonitorAction() {\n\n\t\t$post_types = get_post_types([ 'show_in_graphql' => true, 'public' => true ]);\n\t\t$post_types[] = 'remove_me';\n\t\tupdate_option( '_gatsby_tracked_post_types', $post_types );\n\n\t\t$this->clear_action_monitor();\n\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\tunset( $post_types['remove_me'] );\n\n\t\tupdate_option( '_gatsby_tracked_post_types', $post_types );\n\n\t\tdo_action( 'gatsby_init_action_monitors' );\n\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 1, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\t\tcodecept_debug( $actual );\n\t}\n\n\tpublic function testTaxonomyDetectedWithGraphqlSupportCreateActionMonitorAction() {\n\n\t\t$taxonomies = get_taxonomies([ 'show_in_graphql' => true, 'public' => true ]);\n\t\tupdate_option( '_gatsby_tracked_taxonomies', $taxonomies );\n\n\t\t$this->clear_action_monitor();\n\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t$added = 'new_type';\n\t\t$taxonomies[] = $added;\n\t\tupdate_option( '_gatsby_tracked_taxonomies', $taxonomies );\n\n\t\tdo_action( 'gatsby_init_action_monitors' );\n\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 1, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\t\tcodecept_debug( $actual );\n\n\t}\n\n\tpublic function testTaxonomyRemovedFromGraphQLCreateActionMonitorAction() {\n\n\t\t$taxonomies = get_taxonomies([ 'show_in_graphql' => true, 'public' => true ]);\n\t\t$taxonomies[] = 'remove_me';\n\t\tupdate_option( '_gatsby_tracked_taxonomies', $taxonomies );\n\n\t\t$this->clear_action_monitor();\n\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\tunset( $taxonomies['remove_me'] );\n\n\t\tupdate_option( '_gatsby_tracked_taxonomies', $taxonomies );\n\n\t\tdo_action( 'gatsby_init_action_monitors' );\n\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 1, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\t\tcodecept_debug( $actual );\n\t}\n\n\t// @todo: review the ones below this with Tyler\n\tpublic function testCreatePostOfAPublicCustomPostTypeCreatesActionMonitorAction() {\n\n\t\t// register a post type\n\t\tregister_post_type( 'wp_gatsby_test', [\n\t\t\t'public'              => true,\n\t\t\t'show_in_graphql'     => true,\n\t\t\t'graphql_single_name' => 'wpGatsbyTest',\n\t\t\t'graphql_plural_name' => 'wpGatsbyTests',\n\t\t] );\n\n\t\tcodecept_debug( get_post_types(['show_in_graphql' => true, 'public' => true ]));\n\n\t\t$this->clear_action_monitor();\n\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\n\t\t// Create a post\n\t\t$post_id = $this->factory()->post->create( [\n\t\t\t'post_type'   => 'wp_gatsby_test',\n\t\t\t'post_status' => 'publish',\n\t\t\t'post_title'  => 'Title',\n\t\t\t'post_author' => $this->admin,\n\t\t\t'tags_input'  => [ $this->tag ]\n\t\t] );\n\n\n\t\tcodecept_debug( get_post( $post_id ) );\n\n\t\t// Query for action monitor actions\n\t\t$query = $this->actionMonitorQuery();\n\n\t\t// Execute the query\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\n\t\t$this->assertIsValidQueryResponse( $actual );\n\n\t\t// Creating a post assigned to an author should trigger 3 actions:\n\t\t// - 1 for the post\n\t\t// - 1 for the author\n\t\t$this->assertSame( 2, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t// Assert the action monitor has the actions for the post being created\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'CREATE',\n\t\t\t\t'referencedNodeID'           => (string) $post_id,\n\t\t\t\t'referencedNodeSingularName' => 'wpGatsbyTest',\n\t\t\t] ),\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $this->admin,\n\t\t\t\t'referencedNodeSingularName' => 'user',\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testCreatePostOfCustomPostTypeNotInGraphQLDoesNotCreateActionMonitorAction() {\n\n\t\t// register a post type to NOT show in GraphQL\n\t\tregister_post_type( 'wp_gatsby_no', [\n\t\t\t'public'          => true,\n\t\t\t'show_in_graphql' => false,\n\t\t] );\n\n\t\t// Create a post\n\t\t$this->factory()->post->create( [\n\t\t\t'post_type'   => 'wp_gatsby_no',\n\t\t\t'post_status' => 'publish',\n\t\t\t'post_title'  => 'Title',\n\t\t\t'post_author' => $this->admin,\n\t\t\t'tags_input'  => [ $this->tag ]\n\t\t] );\n\n\t\tcodecept_debug( $this->tag );\n\n\t\t// Query for action monitor actions\n\t\t$query = $this->actionMonitorQuery();\n\n\t\t// Execute the query\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\n\t\t$this->assertIsValidQueryResponse( $actual );\n\n\t\t// Creating a post for a custom post type not shown in GraphQL should trigger 0 actions:\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t}\n\n\tpublic function testCreatePostOfAPubliclyQueryableCustomPostTypeCreatesActionMonitorAction() {\n\n\t\t// Register a publicly queryable post type.\n\t\tregister_post_type( 'wp_gatsby_test', [\n\t\t\t'public'              => false,\n\t\t\t'publicly_queryable'  => true,\n\t\t\t'show_in_graphql'     => true,\n\t\t\t'graphql_single_name' => 'wpGatsbyPubliclyQ',\n\t\t\t'graphql_plural_name' => 'wpGatsbyPubliclyQs',\n\t\t] );\n\n\t\tcodecept_debug(\n\t\t\tget_post_types(\n\t\t\t\t[\n\t\t\t\t\t'public'             => false,\n\t\t\t\t\t'show_in_graphql'    => true,\t\t\t\t\t\n\t\t\t\t\t'publicly_queryable' => true,\n\t\t\t\t]\n\t\t\t)\n\t\t);\n\n\t\t$this->clear_action_monitor();\n\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\n\t\t// Create a post\n\t\t$post_id = $this->factory()->post->create( [\n\t\t\t'post_type'   => 'wp_gatsby_test',\n\t\t\t'post_status' => 'publish',\n\t\t\t'post_title'  => 'Title',\n\t\t\t'post_author' => $this->admin,\n\t\t\t'tags_input'  => [ $this->tag ]\n\t\t] );\n\n\t\tcodecept_debug( get_post( $post_id ) );\n\n\t\t// Query for action monitor actions\n\t\t$query = $this->actionMonitorQuery();\n\n\t\t// Execute the query\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\n\t\t$this->assertIsValidQueryResponse( $actual );\n\n\t\t// Creating a post assigned to an author should trigger 2 actions:\n\t\t// - 1 for the post\n\t\t// - 1 for the author\n\t\t$this->assertSame( 2, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t// Assert the action monitor has the actions for the post being created\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'CREATE',\n\t\t\t\t'referencedNodeID'           => (string) $post_id,\n\t\t\t\t'referencedNodeSingularName' => 'wpGatsbyPubliclyQ',\n\t\t\t] ),\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $this->admin,\n\t\t\t\t'referencedNodeSingularName' => 'user',\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testCreateCategoryCreatesActionMonitorAction() {\n\n\t\t// Create a post\n\t\t$category_id = $this->factory()->category->create([\n\t\t\t'name' => 'test'\n\t\t]);\n\n\t\t// Query for action monitor actions\n\t\t$query = $this->actionMonitorQuery();\n\n\t\t// Execute the query\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\n\t\t$this->assertIsValidQueryResponse( $actual );\n\n\t\t// Creating a category trigger 1 actions:\n\t\t// - 1 for the category being created\n\t\t$this->assertSame( 1, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t// Assert the action monitor has the actions for the post being created\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'CREATE',\n\t\t\t\t'referencedNodeID'           => (string) $category_id,\n\t\t\t\t'referencedNodeSingularName' => 'category'\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testCreateTermOfPrivateTaxonomyDoesNotCreateActionMonitorAction() {\n\n\t\tregister_taxonomy( 'private_taxonomy', 'post', [\n\t\t\t'public' => false,\n\t\t\t'show_in_graphql' => true,\n\t\t\t'graphql_single_name' => 'privateTaxTerm',\n\t\t\t'graphql_plural_name' => 'privateTaxTerms'\n\t\t]);\n\n\t\t// Create a post\n\t\t$term_id = $this->factory()->term->create([\n\t\t\t'name' => 'test',\n\t\t\t'taxonomy' => 'private_taxonomy',\n\t\t]);\n\n\t\t// Query for action monitor actions\n\t\t$query = $this->actionMonitorQuery();\n\n\t\t// Execute the query\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\n\t\t$this->assertIsValidQueryResponse( $actual );\n\n\t\t// Creating a term of private taxonomy should trigger 0 actions:\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t}\n\n\tpublic function testUpdateCategoryCreatesActionMonitorAction() {\n\n\t\t// Create a post\n\t\t$category_id = $this->factory()->category->create();\n\n\t\t$this->clear_action_monitor();\n\n\t\t// Query for action monitor actions\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\twp_update_term( $category_id, 'category', [\n\t\t\t'description' => 'updated...'\n\t\t] );\n\n\t\t// Query for action monitor actions\n\t\t$query = $this->actionMonitorQuery();\n\n\t\t// Execute the query\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\n\t\t$this->assertIsValidQueryResponse( $actual );\n\n\t\t// Updating a category should trigger 1 action\n\t\t$this->assertSame( 1, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t// Assert the action monitor has the actions for the post being created\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $category_id,\n\t\t\t\t'referencedNodeSingularName' => 'category'\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testDeleteCategoryCreatesActionMonitorAction() {\n\n\t\t// Create a post\n\t\t$category_id = $this->factory()->category->create();\n\n\t\t$this->clear_action_monitor();\n\n\t\t// Query for action monitor actions\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\twp_delete_term( $category_id, 'category' );\n\n\t\t// Query for action monitor actions\n\t\t$query = $this->actionMonitorQuery();\n\n\t\t// Execute the query\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\n\t\t$this->assertIsValidQueryResponse( $actual );\n\n\t\t// Creating a post assigned to an author should trigger 1 actions:\n\t\t// - 1 for the category being updated\n\t\t$this->assertSame( 1, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t// Assert the action monitor has the actions for the post being created\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'DELETE',\n\t\t\t\t'referencedNodeID'           => (string) $category_id,\n\t\t\t\t'referencedNodeSingularName' => 'category'\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testUpdateCategoryMetaCreatesActionMonitorAction() {\n\n\t\t// Create a post\n\t\t$category_id = $this->factory()->category->create();\n\n\t\t$this->clear_action_monitor();\n\n\t\t// Query for action monitor actions\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\tupdate_term_meta( $category_id, 'test_key', 'test_value' );\n\n\t\t// Query for action monitor actions\n\t\t$query = $this->actionMonitorQuery();\n\n\t\t// Execute the query\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\n\t\t$this->assertIsValidQueryResponse( $actual );\n\n\t\t// Creating a post assigned to an author should trigger 1 actions:\n\t\t// - 1 for the category being updated\n\t\t$this->assertSame( 1, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t// Assert the action monitor has the actions for the post being created\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $category_id,\n\t\t\t\t'referencedNodeSingularName' => 'category'\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testDeleteCategoryMetaCreatesActionMonitorAction() {\n\n\t\t// Create a post\n\t\t$category_id = $this->factory()->category->create();\n\n\t\tupdate_term_meta( $category_id, 'test_key', 'test_value' );\n\n\t\t$this->clear_action_monitor();\n\n\t\t// Query for action monitor actions\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\tdelete_term_meta( $category_id, 'test_key' );\n\n\t\t// Query for action monitor actions\n\t\t$query = $this->actionMonitorQuery();\n\n\t\t// Execute the query\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\n\t\t$this->assertIsValidQueryResponse( $actual );\n\n\t\t// Creating a post assigned to an author should trigger 1 actions:\n\t\t// - 1 for the category being updated\n\t\t$this->assertSame( 1, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t// Assert the action monitor has the actions for the post being created\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $category_id,\n\t\t\t\t'referencedNodeSingularName' => 'category'\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testCreateUserDoesNotCreateActionMonitorAction() {\n\n\t\t$this->factory()->user->create();\n\n\t\t// Query for action monitor actions\n\t\t$query = $this->actionMonitorQuery();\n\n\t\t// Execute the query\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\n\t\t$this->assertIsValidQueryResponse( $actual );\n\n\t\t// Creating a user shouldn't trigger an action because a user isn't public until\n\t\t// it has published posts\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t}\n\n\tpublic function testDeleteUserWithoutPublishedPostsDoesNotCreateActionMonitorAction() {\n\n\t\t$user_id = $this->factory()->user->create([\n\t\t\t'role' => 'editor'\n\t\t]);\n\n\t\t$this->clear_action_monitor();\n\n\t\t// Query for action monitor actions\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\twp_delete_user( $user_id );\n\n\t\t// Query for action monitor actions\n\t\t$query = $this->actionMonitorQuery();\n\n\t\t// Execute the query\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\n\t\t$this->assertIsValidQueryResponse( $actual );\n\n\t\t// Deleting a user with no published content should not trigger an action\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t}\n\n\tpublic function testDeleteUserWithoutReassigningPublishedPostsCreatesActionMonitorActions() {\n\n\t\t$user_id = $this->factory()->user->create();\n\t\t$post_id = $this->factory()->post->create( [\n\t\t\t'post_type'   => 'post',\n\t\t\t'post_status' => 'publish',\n\t\t\t'post_author' => $user_id,\n\t\t\t'post_title'  => 'test'\n\t\t] );\n\n\t\t$page_id = $this->factory()->post->create( [\n\t\t\t'post_type'   => 'page',\n\t\t\t'post_status' => 'publish',\n\t\t\t'post_author' => $user_id,\n\t\t\t'post_title'  => 'test'\n\t\t] );\n\n\t\t$this->clear_action_monitor();\n\n\t\t// Query for action monitor actions\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\twp_delete_user( $user_id );\n\n\t\t// Query for action monitor actions\n\t\t$query = $this->actionMonitorQuery();\n\n\t\t// Execute the query\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\n\t\tcodecept_debug( $actual );\n\n\t\t$this->assertIsValidQueryResponse( $actual );\n\n\t\t/**\n\t\t * Deleting a user with no published content should trigger 1 actions\n\t\t * - 1 for the user being deleted\n\t\t * - 1 for the page being deleted\n\t\t * - 1 for the post being deleted\n\t\t * (this will actually create 1 action for each post the author was author of)\n\t\t *\n\t\t * @todo: reduce this to a BULK_DELETE action. The source plugin will need to support this though.\n\t\t */\n\t\t$this->assertSame( 3, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t// Assert the action monitor has the actions for the user being deleted\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'DELETE',\n\t\t\t\t'referencedNodeID'           => (string) $user_id,\n\t\t\t\t'referencedNodeSingularName' => 'user'\n\t\t\t] ),\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'DELETE',\n\t\t\t\t'referencedNodeID'           => (string) $post_id,\n\t\t\t\t'referencedNodeSingularName' => 'post'\n\t\t\t] ),\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'DELETE',\n\t\t\t\t'referencedNodeID'           => (string) $page_id,\n\t\t\t\t'referencedNodeSingularName' => 'page'\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testDeleteUserAndReassignPostsCreatesActionMonitorAction() {\n\n\t\t$user_id = $this->factory()->user->create([\n\t\t\t'role' => 'editor'\n\t\t]);\n\t\t$post_id = $this->factory()->post->create( [\n\t\t\t'post_type'   => 'post',\n\t\t\t'post_status' => 'publish',\n\t\t\t'post_author' => $user_id,\n\t\t\t'post_title'  => 'test'\n\t\t] );\n\n\t\t$page_id = $this->factory()->post->create( [\n\t\t\t'post_type'   => 'page',\n\t\t\t'post_status' => 'publish',\n\t\t\t'post_author' => $user_id,\n\t\t\t'post_title'  => 'test'\n\t\t] );\n\n\n\t\t// Also create a draft page assigned to the user. This should NOT trigger an action\n\t\t// when it's re-assigned during user deletion\n\t\t$draft_page_id = $this->factory()->post->create( [\n\t\t\t'post_type'   => 'page',\n\t\t\t'post_status' => 'draft',\n\t\t\t'post_author' => $user_id,\n\t\t\t'post_title'  => 'test'\n\t\t] );\n\n\t\t$this->clear_action_monitor();\n\n\t\t// Query for action monitor actions\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\twp_delete_user( (int) $user_id, (int) $this->admin );\n\n\t\t// Query for action monitor actions\n\t\t$query = $this->actionMonitorQuery();\n\n\t\t// Execute the query\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\n\t\tcodecept_debug( $actual );\n\n\t\t$this->assertIsValidQueryResponse( $actual );\n\n\t\t/**\n\t\t * Deleting a user with 2 published posts and re-assigning should create 4 actions\n\t\t * - 1 for the user being deleted\n\t\t * - 1 for the page being transferred to another author\n\t\t * - 1 for the post being transferred to another author\n\t\t * - 1 for the author that got reassigned to\n\t\t * (this will actually create 1 action for each post the author was author of)\n\t\t *\n\t\t * @todo: reduce this to a BULK_DELETE action. The source plugin will need to support this though.\n\t\t */\n\t\t$this->assertSame( 4, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t// Assert the action monitor has the actions for the user being deleted\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'DELETE',\n\t\t\t\t'referencedNodeID'           => (string) $user_id,\n\t\t\t\t'referencedNodeSingularName' => 'user'\n\t\t\t] ),\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $post_id,\n\t\t\t\t'referencedNodeSingularName' => 'post'\n\t\t\t] ),\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $page_id,\n\t\t\t\t'referencedNodeSingularName' => 'page'\n\t\t\t] ),\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $this->admin,\n\t\t\t\t'referencedNodeSingularName' => 'user'\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testUpdateUserWithPublishedPostsCreatesActionMonitorAction() {\n\n\t\t$user_id = $this->factory()->user->create([\n\t\t\t'role' => 'editor'\n\t\t]);\n\n\t\t$this->factory()->post->create( [\n\t\t\t'post_type'   => 'post',\n\t\t\t'post_status' => 'publish',\n\t\t\t'post_author' => $user_id,\n\t\t\t'post_title'  => 'test'\n\t\t] );\n\n\t\t$this->clear_action_monitor();\n\n\t\t// Query for action monitor actions\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\twp_update_user( [\n\t\t\t'ID'           => $user_id,\n\t\t\t'display_name' => 'updated_display_name'\n\t\t] );\n\n\t\t// Query for action monitor actions\n\t\t$query = $this->actionMonitorQuery();\n\n\t\t// Execute the query\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\n\t\t$this->assertIsValidQueryResponse( $actual );\n\n\t\t/**\n\t\t * Deleting a user with no published content should trigger 1 actions\n\t\t * - 1 for the user being updated\n\t\t */\n\t\t$this->assertSame( 1, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t// Assert the action monitor has the actions for the user being updated\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $user_id,\n\t\t\t\t'referencedNodeSingularName' => 'user'\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testUpdateUserMetaWithTrackedMetaKeyForPublishedAuthorCreatesActionMonitorAction() {\n\n\t\t$user_id = $this->factory()->user->create([\n\t\t\t'role' => 'editor'\n\t\t]   );\n\t\t$this->factory()->post->create( [\n\t\t\t'post_type'   => 'post',\n\t\t\t'post_status' => 'publish',\n\t\t\t'post_author' => $user_id,\n\t\t\t'post_title'  => 'test'\n\t\t] );\n\n\t\tupdate_user_meta( $user_id, 'description', 'test...' );\n\n\t\t$this->clear_action_monitor();\n\n\t\t// Query for action monitor actions\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\tupdate_user_meta( $user_id, 'description', 'test_value' );\n\n\t\t// Query for action monitor actions\n\t\t$query = $this->actionMonitorQuery();\n\n\t\t// Execute the query\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\n\t\t$this->assertIsValidQueryResponse( $actual );\n\n\t\t/**\n\t\t * Deleting a user with no published content should trigger 1 actions\n\t\t * - 1 for the user being updated\n\t\t */\n\t\t$this->assertSame( 1, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t// Assert the action monitor has the actions for the user being deleted\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $user_id,\n\t\t\t\t'referencedNodeSingularName' => 'user'\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testUpdateUserMetaWithUntrackedMetaKeyForPublishedAuthorDoesNotCreateActionMonitorAction() {\n\n\t\t$user_id = $this->factory()->user->create();\n\t\t$this->factory()->post->create( [\n\t\t\t'post_type'   => 'post',\n\t\t\t'post_status' => 'publish',\n\t\t\t'post_author' => $user_id,\n\t\t\t'post_title'  => 'test'\n\t\t] );\n\n\t\tupdate_user_meta( $user_id, 'show_admin_bar_front', 'test...' );\n\n\t\t$this->clear_action_monitor();\n\n\t\t// Query for action monitor actions\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\tupdate_user_meta( $user_id, 'show_admin_bar_front', 'test...' );\n\n\t\t// Query for action monitor actions\n\t\t$query = $this->actionMonitorQuery();\n\n\t\t// Execute the query\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\n\t\t$this->assertIsValidQueryResponse( $actual );\n\n\t\t/**\n\t\t * Updating user meta of an untracked meta_key should not trigger any actions\n\t\t */\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t}\n\n\tpublic function testDeleteUserMetaForTrackedMetaKeyOfPublishedAuthorCreatesActionMonitorAction() {\n\n\t\t$user_id = $this->factory()->user->create();\n\t\t$this->factory()->post->create( [\n\t\t\t'post_type'   => 'post',\n\t\t\t'post_status' => 'publish',\n\t\t\t'post_author' => $user_id,\n\t\t\t'post_title'  => 'test'\n\t\t] );\n\n\t\tupdate_user_meta( $user_id, 'nickname', 'test_value' );\n\n\t\t$this->clear_action_monitor();\n\n\t\t// Query for action monitor actions\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\tdelete_user_meta( $user_id, 'nickname' );\n\n\t\t// Query for action monitor actions\n\t\t$query = $this->actionMonitorQuery();\n\n\t\t// Execute the query\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\n\t\t$this->assertIsValidQueryResponse( $actual );\n\n\t\t/**\n\t\t * Updating user meta with a tracked meta key should create 1 action\n\t\t */\n\t\t$this->assertSame( 1, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t// Assert the action monitor has the actions for the user being deleted\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $user_id,\n\t\t\t\t'referencedNodeSingularName' => 'user'\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testDeleteUserMetaForUntrackedMetaKeyOfPublishedAuthorCreatesActionMonitorAction() {\n\n\t\t$user_id = $this->factory()->user->create();\n\t\t$this->factory()->post->create( [\n\t\t\t'post_type'   => 'post',\n\t\t\t'post_status' => 'publish',\n\t\t\t'post_author' => $user_id,\n\t\t\t'post_title'  => 'test'\n\t\t] );\n\n\t\tupdate_user_meta( $user_id, 'test', 'test_value' );\n\n\t\t$this->clear_action_monitor();\n\n\t\t// Query for action monitor actions\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\tdelete_user_meta( $user_id, 'test' );\n\n\t\t// Query for action monitor actions\n\t\t$query = $this->actionMonitorQuery();\n\n\t\t// Execute the query\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\n\t\t$this->assertIsValidQueryResponse( $actual );\n\n\t\t/**\n\t\t * Updating user meta with a tracked meta key should create 1 action\n\t\t */\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t}\n\n\tpublic function testCreateHierarchicalTermWithParentCreatesActionMonitorAction() {\n\n\t\t$parent_id = $this->factory()->category->create([\n\t\t\t'name' => 'parent'\n\t\t]);\n\n\t\t$this->clear_action_monitor();\n\n\t\t// Query for action monitor actions\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t$child_id = $this->factory()->category->create([\n\t\t\t'name' => 'child',\n\t\t\t'parent' => $parent_id,\n\t\t]);\n\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 2, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $parent_id,\n\t\t\t\t'referencedNodeSingularName' => 'category'\n\t\t\t] ),\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'CREATE',\n\t\t\t\t'referencedNodeID'           => (string) $child_id,\n\t\t\t\t'referencedNodeSingularName' => 'category'\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testUpdateHierarchicalTermWithParentAndChildCreatesActionMonitorAction() {\n\n\t\t$parent_id = $this->factory()->category->create([\n\t\t\t'name' => 'parent'\n\t\t]);\n\n\t\t$child_id = $this->factory()->category->create([\n\t\t\t'name' => 'child',\n\t\t\t'parent' => $parent_id,\n\t\t]);\n\n\t\t$grandchild_id = $this->factory()->category->create([\n\t\t\t'name' => 'grandchild',\n\t\t\t'parent' => $child_id,\n\t\t]);\n\n\t\t$grandchild_two = $this->factory()->category->create([\n\t\t\t'name' => 'grandchild_two',\n\t\t\t'parent' => $child_id,\n\t\t]);\n\n\t\t$this->clear_action_monitor();\n\n\t\t// Query for action monitor actions\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\twp_update_term( $child_id, 'category', [\n\t\t\t'description' => 'test...',\n\t\t]);\n\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 4, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $parent_id,\n\t\t\t\t'referencedNodeSingularName' => 'category'\n\t\t\t] ),\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $child_id,\n\t\t\t\t'referencedNodeSingularName' => 'category'\n\t\t\t] ),\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $grandchild_id,\n\t\t\t\t'referencedNodeSingularName' => 'category'\n\t\t\t] ),\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $grandchild_two,\n\t\t\t\t'referencedNodeSingularName' => 'category'\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testDeleteHierarchicalTermThatHasParentAndChildrenCreatesActionMonitorAction() {\n\n\t\t$parent_id = $this->factory()->category->create([\n\t\t\t'name' => 'parent'\n\t\t]);\n\n\t\t$child_id = $this->factory()->category->create([\n\t\t\t'name' => 'child',\n\t\t\t'parent' => $parent_id,\n\t\t]);\n\n\t\t$grandchild_id = $this->factory()->category->create([\n\t\t\t'name' => 'grandchild',\n\t\t\t'parent' => $child_id,\n\t\t]);\n\n\t\t$grandchild_two = $this->factory()->category->create([\n\t\t\t'name' => 'grandchild_two',\n\t\t\t'parent' => $child_id,\n\t\t]);\n\n\t\t$this->clear_action_monitor();\n\n\t\t// Query for action monitor actions\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\twp_delete_term( $child_id, 'category' );\n\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 4, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $parent_id,\n\t\t\t\t'referencedNodeSingularName' => 'category'\n\t\t\t] ),\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'DELETE',\n\t\t\t\t'referencedNodeID'           => (string) $child_id,\n\t\t\t\t'referencedNodeSingularName' => 'category'\n\t\t\t] ),\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $grandchild_id,\n\t\t\t\t'referencedNodeSingularName' => 'category'\n\t\t\t] ),\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $grandchild_two,\n\t\t\t\t'referencedNodeSingularName' => 'category'\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testRestorePostFromTrashCreatesActionMonitorAction() {\n\n\t\t$post_data = [\n\t\t\t'post_type' => 'post',\n\t\t\t'post_status' => 'trash',\n\t\t\t'post_title' => 'trashed',\n\t\t\t'post_author' => $this->admin\n\t\t];\n\n\t\t$post_id = $this->factory()->post->create( $post_data );\n\n\t\t$this->clear_action_monitor();\n\n\t\t// Publish the post\n\t\twp_update_post( [ 'ID' => $post_id, 'post_status' => 'publish' ] );\n\n\n\t\t// Query for action monitor actions\n\t\t$query = $this->actionMonitorQuery();\n\n\t\t// Execute the query\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\n\t\t$this->assertIsValidQueryResponse( $actual );\n\n\t\t/**\n\t\t * Deleting a user with no published content should trigger 2 actions\n\t\t * - 1 for the user being updated\n\t\t * - 1 for the post being restored\n\t\t */\n\t\t$this->assertSame( 2, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t// Assert the action monitor has the actions for the user being deleted\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'CREATE',\n\t\t\t\t'referencedNodeID'           => (string) $post_id,\n\t\t\t\t'referencedNodeSingularName' => 'post'\n\t\t\t] ),\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $this->admin,\n\t\t\t\t'referencedNodeSingularName' => 'user'\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testUploadPngMediaItemCreatesAction() {\n\n\t\t$this->clear_action_monitor();\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t$filename = WPGATSBY_PLUGIN_DIR . '/tests/_data/images/test.png';\n\t\t$image_id = $this->factory()->attachment->create_upload_object( $filename );\n\n\t\tcodecept_debug( $image_id );\n\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 1, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'CREATE',\n\t\t\t\t'referencedNodeID'           => (string) $image_id,\n\t\t\t\t'referencedNodeSingularName' => 'mediaItem'\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testUpdateMediaItemCreatesAction() {\n\n\t\t$filename = WPGATSBY_PLUGIN_DIR . '/tests/_data/images/test.png';\n\t\t$image_id = $this->factory()->attachment->create_upload_object( $filename );\n\n\t\t$this->clear_action_monitor();\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\twp_update_post([ 'ID' => $image_id, 'post_content' => 'test...' ]);\n\n\t\tcodecept_debug( $image_id );\n\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 1, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $image_id,\n\t\t\t\t'referencedNodeSingularName' => 'mediaItem'\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testDeleteMediaItemCreatesAction() {\n\n\t\t$filename = WPGATSBY_PLUGIN_DIR . '/tests/_data/images/test.png';\n\t\t$image_id = $this->factory()->attachment->create_upload_object( $filename );\n\n\t\t$this->clear_action_monitor();\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\twp_delete_attachment( $image_id );\n\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 1, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'DELETE',\n\t\t\t\t'referencedNodeID'           => (string) $image_id,\n\t\t\t\t'referencedNodeSingularName' => 'mediaItem'\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testCreateNavMenuDoesNotCreateActionMonitorAction() {\n\n\t\t$this->clear_action_monitor();\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\twp_create_nav_menu( 'Test Menu' );\n\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\n\t}\n\n\tpublic function testAssignNavMenuToLocationCreatesActionMonitorAction() {\n\n\t\t$location_name = 'gatsby-test';\n\t\tregister_nav_menu($location_name, __( 'Gatsby Test Menu', 'WPGatsby' ) );\n\t\t$menu_id = wp_create_nav_menu( __( 'Test Menu', 'WPGatsby' ) );\n\t\t$post_id = $this->factory()->post->create();\n\n\t\twp_update_nav_menu_item(\n\t\t\t$menu_id,\n\t\t\t0,\n\t\t\t[\n\t\t\t\t'menu-item-title'     => 'Menu item',\n\t\t\t\t'menu-item-object'    => 'post',\n\t\t\t\t'menu-item-object-id' => $post_id,\n\t\t\t\t'menu-item-status'    => 'publish',\n\t\t\t\t'menu-item-type'      => 'post_type',\n\t\t\t]\n\t\t);\n\n\t\t$this->clear_action_monitor();\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\tset_theme_mod( 'nav_menu_locations', [ $location_name => (int) $menu_id ] );\n\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 1, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'CREATE',\n\t\t\t\t'referencedNodeID'           => (string) $menu_id,\n\t\t\t\t'referencedNodeSingularName' => 'menu'\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testUpdateNavMenuCreatesActionMonitorAction() {\n\n\t\t$location_name = 'gatsby-test';\n\t\tregister_nav_menu($location_name, __( 'Gatsby Test Menu', 'WPGatsby' ) );\n\t\t$menu_id = wp_create_nav_menu( __( 'Test Menu', 'WPGatsby' ) );\n\t\t$post_id = $this->factory()->post->create();\n\n\t\t$menu_item_id = wp_update_nav_menu_item(\n\t\t\t$menu_id,\n\t\t\t0,\n\t\t\t[\n\t\t\t\t'menu-item-title'     => 'Menu item',\n\t\t\t\t'menu-item-object'    => 'post',\n\t\t\t\t'menu-item-object-id' => $post_id,\n\t\t\t\t'menu-item-status'    => 'publish',\n\t\t\t\t'menu-item-type'      => 'post_type',\n\t\t\t]\n\t\t);\n\n\t\tset_theme_mod( 'nav_menu_locations', [ $location_name => (int) $menu_id ] );\n\n\t\t$this->clear_action_monitor();\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t// Add a new menu item\n\t\t$new_menu_item = wp_update_nav_menu_item(\n\t\t\t$menu_id,\n\t\t\t0,\n\t\t\t[\n\t\t\t\t'menu-item-title'     => 'Update Menu item',\n\t\t\t\t'menu-item-object'    => 'post',\n\t\t\t\t'menu-item-object-id' => $post_id,\n\t\t\t\t'menu-item-status'    => 'publish',\n\t\t\t\t'menu-item-type'      => 'post_type',\n\t\t\t]\n\t\t);\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 2, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $menu_id,\n\t\t\t\t'referencedNodeSingularName' => 'menu'\n\t\t\t] ),\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'UPDATE',\n\t\t\t\t'referencedNodeID'           => (string) $new_menu_item,\n\t\t\t\t'referencedNodeSingularName' => 'menuItem'\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testDeleteMenuCreatesActionMonitorAction() {\n\n\t\t$location_name = 'gatsby-test';\n\t\tregister_nav_menu($location_name, __( 'Gatsby Test Menu', 'WPGatsby' ) );\n\t\t$menu_id = wp_create_nav_menu( __( 'Test Menu', 'WPGatsby' ) );\n\t\t$post_id = $this->factory()->post->create();\n\n\t\twp_update_nav_menu_item(\n\t\t\t$menu_id,\n\t\t\t0,\n\t\t\t[\n\t\t\t\t'menu-item-title'     => 'Menu item',\n\t\t\t\t'menu-item-object'    => 'post',\n\t\t\t\t'menu-item-object-id' => $post_id,\n\t\t\t\t'menu-item-status'    => 'publish',\n\t\t\t\t'menu-item-type'      => 'post_type',\n\t\t\t]\n\t\t);\n\n\t\tset_theme_mod( 'nav_menu_locations', [ $location_name => (int) $menu_id ] );\n\n\t\t$this->clear_action_monitor();\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t// Delete the menu\n\t\twp_delete_nav_menu( $menu_id );\n\n\t\t// Deleting a menu creates the following actions\n\t\t// - 1 action for DELETE MENU\n\t\t// Gatsby will delete the menu and all associated menu items when this action occurs\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 1, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'DELETE',\n\t\t\t\t'referencedNodeID'           => (string) $menu_id,\n\t\t\t\t'referencedNodeSingularName' => 'menu'\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testUpdatePermalinksCreatesActionMonitorAction() {\n\n\t\t$option_name = 'permalink_structure';\n\t\t$structure = '/%year%/%monthnum%/%postname%/';\n\t\tupdate_option( $option_name, $structure );\n\n\t\t$this->clear_action_monitor();\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\tupdate_option( $option_name, '/archives/%post_id%' );\n\n\t\t// Updating permalinks should create 1 action\n\t\t// - 1 action\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 1, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t$this->assertQuerySuccessful( $actual, [\n\t\t\t$this->expectedNode( 'actionMonitorActions.nodes', [\n\t\t\t\t'actionType'                 => 'REFETCH_ALL',\n\t\t\t\t'referencedNodeID'           => (string) 'refetch_all',\n\t\t\t\t'referencedNodeSingularName' => 'refetchAll'\n\t\t\t] ),\n\t\t] );\n\n\t}\n\n\tpublic function testUpdateUntrackedOptionDoesNotCreateActionMonitorAction() {\n\n\t\t$this->clear_action_monitor();\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\tupdate_option( 'test_option', 'test' );\n\n\t\t// Updating untracked option should create 0 actions\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t}\n\n\tpublic function testSetTransientDoesNotCreateActionMonitorAction() {\n\n\t\t$this->clear_action_monitor();\n\t\t$query  = $this->actionMonitorQuery();\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t\t$transient = set_transient( 'test_transient', 'test', 600 );\n\n\t\t// Setting a transient should create 0 action\n\t\t$actual = $this->graphql( compact( 'query' ) );\n\t\t$this->assertSame( 0, count( $actual['data']['actionMonitorActions']['nodes'] ) );\n\n\t}\n\n\n}\n"
  },
  {
    "path": "tests/wpunit.suite.dist.yml",
    "content": "# Codeception Test Suite Configuration\n#\n# Suite for unit or integration tests that require WordPress functions and classes.\n\nactor: WpunitTester\nmodules:\n  enabled:\n    - WPLoader\n  disabled:\n    - WPDb\n    - WPBrowser\n  config:\n    WPDb:\n      cleanup: false\n    WPLoader:\n      plugins:\n        - wp-graphql/wp-graphql.php\n        - wp-gatsby/wp-gatsby.php\n      activatePlugins:\n        - wp-graphql/wp-graphql.php\n        - wp-gatsby/wp-gatsby.php\n"
  },
  {
    "path": "vendor/autoload.php",
    "content": "<?php\n\n// autoload.php @generated by Composer\n\nrequire_once __DIR__ . '/composer/autoload_real.php';\n\nreturn ComposerAutoloaderInitd5ba67e9c3910011804380f1fed1cebe::getLoader();\n"
  },
  {
    "path": "vendor/composer/ClassLoader.php",
    "content": "<?php\n\n/*\n * This file is part of Composer.\n *\n * (c) Nils Adermann <naderman@naderman.de>\n *     Jordi Boggiano <j.boggiano@seld.be>\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nnamespace Composer\\Autoload;\n\n/**\n * ClassLoader implements a PSR-0, PSR-4 and classmap class loader.\n *\n *     $loader = new \\Composer\\Autoload\\ClassLoader();\n *\n *     // register classes with namespaces\n *     $loader->add('Symfony\\Component', __DIR__.'/component');\n *     $loader->add('Symfony',           __DIR__.'/framework');\n *\n *     // activate the autoloader\n *     $loader->register();\n *\n *     // to enable searching the include path (eg. for PEAR packages)\n *     $loader->setUseIncludePath(true);\n *\n * In this example, if you try to use a class in the Symfony\\Component\n * namespace or one of its children (Symfony\\Component\\Console for instance),\n * the autoloader will first look for the class under the component/\n * directory, and it will then fallback to the framework/ directory if not\n * found before giving up.\n *\n * This class is loosely based on the Symfony UniversalClassLoader.\n *\n * @author Fabien Potencier <fabien@symfony.com>\n * @author Jordi Boggiano <j.boggiano@seld.be>\n * @see    http://www.php-fig.org/psr/psr-0/\n * @see    http://www.php-fig.org/psr/psr-4/\n */\nclass ClassLoader\n{\n    // PSR-4\n    private $prefixLengthsPsr4 = array();\n    private $prefixDirsPsr4 = array();\n    private $fallbackDirsPsr4 = array();\n\n    // PSR-0\n    private $prefixesPsr0 = array();\n    private $fallbackDirsPsr0 = array();\n\n    private $useIncludePath = false;\n    private $classMap = array();\n    private $classMapAuthoritative = false;\n    private $missingClasses = array();\n    private $apcuPrefix;\n\n    public function getPrefixes()\n    {\n        if (!empty($this->prefixesPsr0)) {\n            return call_user_func_array('array_merge', array_values($this->prefixesPsr0));\n        }\n\n        return array();\n    }\n\n    public function getPrefixesPsr4()\n    {\n        return $this->prefixDirsPsr4;\n    }\n\n    public function getFallbackDirs()\n    {\n        return $this->fallbackDirsPsr0;\n    }\n\n    public function getFallbackDirsPsr4()\n    {\n        return $this->fallbackDirsPsr4;\n    }\n\n    public function getClassMap()\n    {\n        return $this->classMap;\n    }\n\n    /**\n     * @param array $classMap Class to filename map\n     */\n    public function addClassMap(array $classMap)\n    {\n        if ($this->classMap) {\n            $this->classMap = array_merge($this->classMap, $classMap);\n        } else {\n            $this->classMap = $classMap;\n        }\n    }\n\n    /**\n     * Registers a set of PSR-0 directories for a given prefix, either\n     * appending or prepending to the ones previously set for this prefix.\n     *\n     * @param string       $prefix  The prefix\n     * @param array|string $paths   The PSR-0 root directories\n     * @param bool         $prepend Whether to prepend the directories\n     */\n    public function add($prefix, $paths, $prepend = false)\n    {\n        if (!$prefix) {\n            if ($prepend) {\n                $this->fallbackDirsPsr0 = array_merge(\n                    (array) $paths,\n                    $this->fallbackDirsPsr0\n                );\n            } else {\n                $this->fallbackDirsPsr0 = array_merge(\n                    $this->fallbackDirsPsr0,\n                    (array) $paths\n                );\n            }\n\n            return;\n        }\n\n        $first = $prefix[0];\n        if (!isset($this->prefixesPsr0[$first][$prefix])) {\n            $this->prefixesPsr0[$first][$prefix] = (array) $paths;\n\n            return;\n        }\n        if ($prepend) {\n            $this->prefixesPsr0[$first][$prefix] = array_merge(\n                (array) $paths,\n                $this->prefixesPsr0[$first][$prefix]\n            );\n        } else {\n            $this->prefixesPsr0[$first][$prefix] = array_merge(\n                $this->prefixesPsr0[$first][$prefix],\n                (array) $paths\n            );\n        }\n    }\n\n    /**\n     * Registers a set of PSR-4 directories for a given namespace, either\n     * appending or prepending to the ones previously set for this namespace.\n     *\n     * @param string       $prefix  The prefix/namespace, with trailing '\\\\'\n     * @param array|string $paths   The PSR-4 base directories\n     * @param bool         $prepend Whether to prepend the directories\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public function addPsr4($prefix, $paths, $prepend = false)\n    {\n        if (!$prefix) {\n            // Register directories for the root namespace.\n            if ($prepend) {\n                $this->fallbackDirsPsr4 = array_merge(\n                    (array) $paths,\n                    $this->fallbackDirsPsr4\n                );\n            } else {\n                $this->fallbackDirsPsr4 = array_merge(\n                    $this->fallbackDirsPsr4,\n                    (array) $paths\n                );\n            }\n        } elseif (!isset($this->prefixDirsPsr4[$prefix])) {\n            // Register directories for a new namespace.\n            $length = strlen($prefix);\n            if ('\\\\' !== $prefix[$length - 1]) {\n                throw new \\InvalidArgumentException(\"A non-empty PSR-4 prefix must end with a namespace separator.\");\n            }\n            $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;\n            $this->prefixDirsPsr4[$prefix] = (array) $paths;\n        } elseif ($prepend) {\n            // Prepend directories for an already registered namespace.\n            $this->prefixDirsPsr4[$prefix] = array_merge(\n                (array) $paths,\n                $this->prefixDirsPsr4[$prefix]\n            );\n        } else {\n            // Append directories for an already registered namespace.\n            $this->prefixDirsPsr4[$prefix] = array_merge(\n                $this->prefixDirsPsr4[$prefix],\n                (array) $paths\n            );\n        }\n    }\n\n    /**\n     * Registers a set of PSR-0 directories for a given prefix,\n     * replacing any others previously set for this prefix.\n     *\n     * @param string       $prefix The prefix\n     * @param array|string $paths  The PSR-0 base directories\n     */\n    public function set($prefix, $paths)\n    {\n        if (!$prefix) {\n            $this->fallbackDirsPsr0 = (array) $paths;\n        } else {\n            $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;\n        }\n    }\n\n    /**\n     * Registers a set of PSR-4 directories for a given namespace,\n     * replacing any others previously set for this namespace.\n     *\n     * @param string       $prefix The prefix/namespace, with trailing '\\\\'\n     * @param array|string $paths  The PSR-4 base directories\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public function setPsr4($prefix, $paths)\n    {\n        if (!$prefix) {\n            $this->fallbackDirsPsr4 = (array) $paths;\n        } else {\n            $length = strlen($prefix);\n            if ('\\\\' !== $prefix[$length - 1]) {\n                throw new \\InvalidArgumentException(\"A non-empty PSR-4 prefix must end with a namespace separator.\");\n            }\n            $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;\n            $this->prefixDirsPsr4[$prefix] = (array) $paths;\n        }\n    }\n\n    /**\n     * Turns on searching the include path for class files.\n     *\n     * @param bool $useIncludePath\n     */\n    public function setUseIncludePath($useIncludePath)\n    {\n        $this->useIncludePath = $useIncludePath;\n    }\n\n    /**\n     * Can be used to check if the autoloader uses the include path to check\n     * for classes.\n     *\n     * @return bool\n     */\n    public function getUseIncludePath()\n    {\n        return $this->useIncludePath;\n    }\n\n    /**\n     * Turns off searching the prefix and fallback directories for classes\n     * that have not been registered with the class map.\n     *\n     * @param bool $classMapAuthoritative\n     */\n    public function setClassMapAuthoritative($classMapAuthoritative)\n    {\n        $this->classMapAuthoritative = $classMapAuthoritative;\n    }\n\n    /**\n     * Should class lookup fail if not found in the current class map?\n     *\n     * @return bool\n     */\n    public function isClassMapAuthoritative()\n    {\n        return $this->classMapAuthoritative;\n    }\n\n    /**\n     * APCu prefix to use to cache found/not-found classes, if the extension is enabled.\n     *\n     * @param string|null $apcuPrefix\n     */\n    public function setApcuPrefix($apcuPrefix)\n    {\n        $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;\n    }\n\n    /**\n     * The APCu prefix in use, or null if APCu caching is not enabled.\n     *\n     * @return string|null\n     */\n    public function getApcuPrefix()\n    {\n        return $this->apcuPrefix;\n    }\n\n    /**\n     * Registers this instance as an autoloader.\n     *\n     * @param bool $prepend Whether to prepend the autoloader or not\n     */\n    public function register($prepend = false)\n    {\n        spl_autoload_register(array($this, 'loadClass'), true, $prepend);\n    }\n\n    /**\n     * Unregisters this instance as an autoloader.\n     */\n    public function unregister()\n    {\n        spl_autoload_unregister(array($this, 'loadClass'));\n    }\n\n    /**\n     * Loads the given class or interface.\n     *\n     * @param  string    $class The name of the class\n     * @return bool|null True if loaded, null otherwise\n     */\n    public function loadClass($class)\n    {\n        if ($file = $this->findFile($class)) {\n            includeFile($file);\n\n            return true;\n        }\n    }\n\n    /**\n     * Finds the path to the file where the class is defined.\n     *\n     * @param string $class The name of the class\n     *\n     * @return string|false The path if found, false otherwise\n     */\n    public function findFile($class)\n    {\n        // class map lookup\n        if (isset($this->classMap[$class])) {\n            return $this->classMap[$class];\n        }\n        if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {\n            return false;\n        }\n        if (null !== $this->apcuPrefix) {\n            $file = apcu_fetch($this->apcuPrefix.$class, $hit);\n            if ($hit) {\n                return $file;\n            }\n        }\n\n        $file = $this->findFileWithExtension($class, '.php');\n\n        // Search for Hack files if we are running on HHVM\n        if (false === $file && defined('HHVM_VERSION')) {\n            $file = $this->findFileWithExtension($class, '.hh');\n        }\n\n        if (null !== $this->apcuPrefix) {\n            apcu_add($this->apcuPrefix.$class, $file);\n        }\n\n        if (false === $file) {\n            // Remember that this class does not exist.\n            $this->missingClasses[$class] = true;\n        }\n\n        return $file;\n    }\n\n    private function findFileWithExtension($class, $ext)\n    {\n        // PSR-4 lookup\n        $logicalPathPsr4 = strtr($class, '\\\\', DIRECTORY_SEPARATOR) . $ext;\n\n        $first = $class[0];\n        if (isset($this->prefixLengthsPsr4[$first])) {\n            $subPath = $class;\n            while (false !== $lastPos = strrpos($subPath, '\\\\')) {\n                $subPath = substr($subPath, 0, $lastPos);\n                $search = $subPath . '\\\\';\n                if (isset($this->prefixDirsPsr4[$search])) {\n                    $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);\n                    foreach ($this->prefixDirsPsr4[$search] as $dir) {\n                        if (file_exists($file = $dir . $pathEnd)) {\n                            return $file;\n                        }\n                    }\n                }\n            }\n        }\n\n        // PSR-4 fallback dirs\n        foreach ($this->fallbackDirsPsr4 as $dir) {\n            if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {\n                return $file;\n            }\n        }\n\n        // PSR-0 lookup\n        if (false !== $pos = strrpos($class, '\\\\')) {\n            // namespaced class name\n            $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)\n                . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);\n        } else {\n            // PEAR-like class name\n            $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;\n        }\n\n        if (isset($this->prefixesPsr0[$first])) {\n            foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {\n                if (0 === strpos($class, $prefix)) {\n                    foreach ($dirs as $dir) {\n                        if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {\n                            return $file;\n                        }\n                    }\n                }\n            }\n        }\n\n        // PSR-0 fallback dirs\n        foreach ($this->fallbackDirsPsr0 as $dir) {\n            if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {\n                return $file;\n            }\n        }\n\n        // PSR-0 include paths.\n        if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {\n            return $file;\n        }\n\n        return false;\n    }\n}\n\n/**\n * Scope isolated include.\n *\n * Prevents access to $this/self from included files.\n */\nfunction includeFile($file)\n{\n    include $file;\n}\n"
  },
  {
    "path": "vendor/composer/LICENSE",
    "content": "\nCopyright (c) Nils Adermann, Jordi Boggiano\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is furnished\nto do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n\n"
  },
  {
    "path": "vendor/composer/autoload_classmap.php",
    "content": "<?php\n\n// autoload_classmap.php @generated by Composer\n\n$vendorDir = dirname(dirname(__FILE__));\n$baseDir = dirname($vendorDir);\n\nreturn array(\n    'Composer\\\\Semver\\\\Comparator' => $vendorDir . '/composer/semver/src/Comparator.php',\n    'Composer\\\\Semver\\\\Constraint\\\\AbstractConstraint' => $vendorDir . '/composer/semver/src/Constraint/AbstractConstraint.php',\n    'Composer\\\\Semver\\\\Constraint\\\\Constraint' => $vendorDir . '/composer/semver/src/Constraint/Constraint.php',\n    'Composer\\\\Semver\\\\Constraint\\\\ConstraintInterface' => $vendorDir . '/composer/semver/src/Constraint/ConstraintInterface.php',\n    'Composer\\\\Semver\\\\Constraint\\\\EmptyConstraint' => $vendorDir . '/composer/semver/src/Constraint/EmptyConstraint.php',\n    'Composer\\\\Semver\\\\Constraint\\\\MultiConstraint' => $vendorDir . '/composer/semver/src/Constraint/MultiConstraint.php',\n    'Composer\\\\Semver\\\\Semver' => $vendorDir . '/composer/semver/src/Semver.php',\n    'Composer\\\\Semver\\\\VersionParser' => $vendorDir . '/composer/semver/src/VersionParser.php',\n    'Firebase\\\\JWT\\\\BeforeValidException' => $vendorDir . '/firebase/php-jwt/src/BeforeValidException.php',\n    'Firebase\\\\JWT\\\\ExpiredException' => $vendorDir . '/firebase/php-jwt/src/ExpiredException.php',\n    'Firebase\\\\JWT\\\\JWK' => $vendorDir . '/firebase/php-jwt/src/JWK.php',\n    'Firebase\\\\JWT\\\\JWT' => $vendorDir . '/firebase/php-jwt/src/JWT.php',\n    'Firebase\\\\JWT\\\\SignatureInvalidException' => $vendorDir . '/firebase/php-jwt/src/SignatureInvalidException.php',\n    'RandomLib\\\\AbstractMcryptMixer' => $vendorDir . '/ircmaxell/random-lib/lib/RandomLib/AbstractMcryptMixer.php',\n    'RandomLib\\\\AbstractMixer' => $vendorDir . '/ircmaxell/random-lib/lib/RandomLib/AbstractMixer.php',\n    'RandomLib\\\\AbstractSource' => $vendorDir . '/ircmaxell/random-lib/lib/RandomLib/AbstractSource.php',\n    'RandomLib\\\\Factory' => $vendorDir . '/ircmaxell/random-lib/lib/RandomLib/Factory.php',\n    'RandomLib\\\\Generator' => $vendorDir . '/ircmaxell/random-lib/lib/RandomLib/Generator.php',\n    'RandomLib\\\\Mixer' => $vendorDir . '/ircmaxell/random-lib/lib/RandomLib/Mixer.php',\n    'RandomLib\\\\Mixer\\\\Hash' => $vendorDir . '/ircmaxell/random-lib/lib/RandomLib/Mixer/Hash.php',\n    'RandomLib\\\\Mixer\\\\McryptRijndael128' => $vendorDir . '/ircmaxell/random-lib/lib/RandomLib/Mixer/McryptRijndael128.php',\n    'RandomLib\\\\Mixer\\\\XorMixer' => $vendorDir . '/ircmaxell/random-lib/lib/RandomLib/Mixer/XorMixer.php',\n    'RandomLib\\\\Source' => $vendorDir . '/ircmaxell/random-lib/lib/RandomLib/Source.php',\n    'RandomLib\\\\Source\\\\CAPICOM' => $vendorDir . '/ircmaxell/random-lib/lib/RandomLib/Source/CAPICOM.php',\n    'RandomLib\\\\Source\\\\MTRand' => $vendorDir . '/ircmaxell/random-lib/lib/RandomLib/Source/MTRand.php',\n    'RandomLib\\\\Source\\\\MicroTime' => $vendorDir . '/ircmaxell/random-lib/lib/RandomLib/Source/MicroTime.php',\n    'RandomLib\\\\Source\\\\OpenSSL' => $vendorDir . '/ircmaxell/random-lib/lib/RandomLib/Source/OpenSSL.php',\n    'RandomLib\\\\Source\\\\Rand' => $vendorDir . '/ircmaxell/random-lib/lib/RandomLib/Source/Rand.php',\n    'RandomLib\\\\Source\\\\Random' => $vendorDir . '/ircmaxell/random-lib/lib/RandomLib/Source/Random.php',\n    'RandomLib\\\\Source\\\\RandomBytes' => $vendorDir . '/ircmaxell/random-lib/lib/RandomLib/Source/RandomBytes.php',\n    'RandomLib\\\\Source\\\\Sodium' => $vendorDir . '/ircmaxell/random-lib/lib/RandomLib/Source/Sodium.php',\n    'RandomLib\\\\Source\\\\URandom' => $vendorDir . '/ircmaxell/random-lib/lib/RandomLib/Source/URandom.php',\n    'RandomLib\\\\Source\\\\UniqID' => $vendorDir . '/ircmaxell/random-lib/lib/RandomLib/Source/UniqID.php',\n    'SecurityLib\\\\AbstractFactory' => $vendorDir . '/ircmaxell/security-lib/lib/SecurityLib/AbstractFactory.php',\n    'SecurityLib\\\\BaseConverter' => $vendorDir . '/ircmaxell/security-lib/lib/SecurityLib/BaseConverter.php',\n    'SecurityLib\\\\BigMath' => $vendorDir . '/ircmaxell/security-lib/lib/SecurityLib/BigMath.php',\n    'SecurityLib\\\\BigMath\\\\BCMath' => $vendorDir . '/ircmaxell/security-lib/lib/SecurityLib/BigMath/BCMath.php',\n    'SecurityLib\\\\BigMath\\\\GMP' => $vendorDir . '/ircmaxell/security-lib/lib/SecurityLib/BigMath/GMP.php',\n    'SecurityLib\\\\BigMath\\\\PHPMath' => $vendorDir . '/ircmaxell/security-lib/lib/SecurityLib/BigMath/PHPMath.php',\n    'SecurityLib\\\\Enum' => $vendorDir . '/ircmaxell/security-lib/lib/SecurityLib/Enum.php',\n    'SecurityLib\\\\Hash' => $vendorDir . '/ircmaxell/security-lib/lib/SecurityLib/Hash.php',\n    'SecurityLib\\\\Strength' => $vendorDir . '/ircmaxell/security-lib/lib/SecurityLib/Strength.php',\n    'SecurityLib\\\\Util' => $vendorDir . '/ircmaxell/security-lib/lib/SecurityLib/Util.php',\n    'WPGatsby\\\\ActionMonitor\\\\ActionMonitor' => $baseDir . '/src/ActionMonitor/ActionMonitor.php',\n    'WPGatsby\\\\ActionMonitor\\\\Monitors\\\\AcfMonitor' => $baseDir . '/src/ActionMonitor/Monitors/AcfMonitor.php',\n    'WPGatsby\\\\ActionMonitor\\\\Monitors\\\\MediaMonitor' => $baseDir . '/src/ActionMonitor/Monitors/MediaMonitor.php',\n    'WPGatsby\\\\ActionMonitor\\\\Monitors\\\\Monitor' => $baseDir . '/src/ActionMonitor/Monitors/Monitor.php',\n    'WPGatsby\\\\ActionMonitor\\\\Monitors\\\\NavMenuMonitor' => $baseDir . '/src/ActionMonitor/Monitors/NavMenuMonitor.php',\n    'WPGatsby\\\\ActionMonitor\\\\Monitors\\\\PostMonitor' => $baseDir . '/src/ActionMonitor/Monitors/PostMonitor.php',\n    'WPGatsby\\\\ActionMonitor\\\\Monitors\\\\PostTypeMonitor' => $baseDir . '/src/ActionMonitor/Monitors/PostTypeMonitor.php',\n    'WPGatsby\\\\ActionMonitor\\\\Monitors\\\\PreviewMonitor' => $baseDir . '/src/ActionMonitor/Monitors/PreviewMonitor.php',\n    'WPGatsby\\\\ActionMonitor\\\\Monitors\\\\SettingsMonitor' => $baseDir . '/src/ActionMonitor/Monitors/SettingsMonitor.php',\n    'WPGatsby\\\\ActionMonitor\\\\Monitors\\\\TaxonomyMonitor' => $baseDir . '/src/ActionMonitor/Monitors/TaxonomyMonitor.php',\n    'WPGatsby\\\\ActionMonitor\\\\Monitors\\\\TermMonitor' => $baseDir . '/src/ActionMonitor/Monitors/TermMonitor.php',\n    'WPGatsby\\\\ActionMonitor\\\\Monitors\\\\UserMonitor' => $baseDir . '/src/ActionMonitor/Monitors/UserMonitor.php',\n    'WPGatsby\\\\Admin\\\\Preview' => $baseDir . '/src/Admin/Preview.php',\n    'WPGatsby\\\\Admin\\\\Settings' => $baseDir . '/src/Admin/Settings.php',\n    'WPGatsby\\\\GraphQL\\\\Auth' => $baseDir . '/src/GraphQL/Auth.php',\n    'WPGatsby\\\\GraphQL\\\\ParseAuthToken' => $baseDir . '/src/GraphQL/ParseAuthToken.php',\n    'WPGatsby\\\\Schema\\\\Schema' => $baseDir . '/src/Schema/Schema.php',\n    'WPGatsby\\\\Schema\\\\SiteMeta' => $baseDir . '/src/Schema/SiteMeta.php',\n    'WPGatsby\\\\Schema\\\\WPGatsbyWPGraphQLSchemaChanges' => $baseDir . '/src/Schema/WPGatsbyWPGraphQLSchemaChanges.php',\n    'WPGatsby\\\\ThemeSupport\\\\ThemeSupport' => $baseDir . '/src/ThemeSupport/ThemeSupport.php',\n);\n"
  },
  {
    "path": "vendor/composer/autoload_namespaces.php",
    "content": "<?php\n\n// autoload_namespaces.php @generated by Composer\n\n$vendorDir = dirname(dirname(__FILE__));\n$baseDir = dirname($vendorDir);\n\nreturn array(\n    'SecurityLib' => array($vendorDir . '/ircmaxell/security-lib/lib'),\n    'RandomLib' => array($vendorDir . '/ircmaxell/random-lib/lib'),\n);\n"
  },
  {
    "path": "vendor/composer/autoload_psr4.php",
    "content": "<?php\n\n// autoload_psr4.php @generated by Composer\n\n$vendorDir = dirname(dirname(__FILE__));\n$baseDir = dirname($vendorDir);\n\nreturn array(\n    'WPGatsby\\\\' => array($baseDir . '/src'),\n    'Firebase\\\\JWT\\\\' => array($vendorDir . '/firebase/php-jwt/src'),\n    'Composer\\\\Semver\\\\' => array($vendorDir . '/composer/semver/src'),\n);\n"
  },
  {
    "path": "vendor/composer/autoload_real.php",
    "content": "<?php\n\n// autoload_real.php @generated by Composer\n\nclass ComposerAutoloaderInitd5ba67e9c3910011804380f1fed1cebe\n{\n    private static $loader;\n\n    public static function loadClassLoader($class)\n    {\n        if ('Composer\\Autoload\\ClassLoader' === $class) {\n            require __DIR__ . '/ClassLoader.php';\n        }\n    }\n\n    /**\n     * @return \\Composer\\Autoload\\ClassLoader\n     */\n    public static function getLoader()\n    {\n        if (null !== self::$loader) {\n            return self::$loader;\n        }\n\n        spl_autoload_register(array('ComposerAutoloaderInitd5ba67e9c3910011804380f1fed1cebe', 'loadClassLoader'), true, true);\n        self::$loader = $loader = new \\Composer\\Autoload\\ClassLoader();\n        spl_autoload_unregister(array('ComposerAutoloaderInitd5ba67e9c3910011804380f1fed1cebe', 'loadClassLoader'));\n\n        $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());\n        if ($useStaticLoader) {\n            require_once __DIR__ . '/autoload_static.php';\n\n            call_user_func(\\Composer\\Autoload\\ComposerStaticInitd5ba67e9c3910011804380f1fed1cebe::getInitializer($loader));\n        } else {\n            $map = require __DIR__ . '/autoload_namespaces.php';\n            foreach ($map as $namespace => $path) {\n                $loader->set($namespace, $path);\n            }\n\n            $map = require __DIR__ . '/autoload_psr4.php';\n            foreach ($map as $namespace => $path) {\n                $loader->setPsr4($namespace, $path);\n            }\n\n            $classMap = require __DIR__ . '/autoload_classmap.php';\n            if ($classMap) {\n                $loader->addClassMap($classMap);\n            }\n        }\n\n        $loader->register(true);\n\n        return $loader;\n    }\n}\n"
  },
  {
    "path": "vendor/composer/autoload_static.php",
    "content": "<?php\n\n// autoload_static.php @generated by Composer\n\nnamespace Composer\\Autoload;\n\nclass ComposerStaticInitd5ba67e9c3910011804380f1fed1cebe\n{\n    public static $prefixLengthsPsr4 = array (\n        'W' => \n        array (\n            'WPGatsby\\\\' => 9,\n        ),\n        'F' => \n        array (\n            'Firebase\\\\JWT\\\\' => 13,\n        ),\n        'C' => \n        array (\n            'Composer\\\\Semver\\\\' => 16,\n        ),\n    );\n\n    public static $prefixDirsPsr4 = array (\n        'WPGatsby\\\\' => \n        array (\n            0 => __DIR__ . '/../..' . '/src',\n        ),\n        'Firebase\\\\JWT\\\\' => \n        array (\n            0 => __DIR__ . '/..' . '/firebase/php-jwt/src',\n        ),\n        'Composer\\\\Semver\\\\' => \n        array (\n            0 => __DIR__ . '/..' . '/composer/semver/src',\n        ),\n    );\n\n    public static $prefixesPsr0 = array (\n        'S' => \n        array (\n            'SecurityLib' => \n            array (\n                0 => __DIR__ . '/..' . '/ircmaxell/security-lib/lib',\n            ),\n        ),\n        'R' => \n        array (\n            'RandomLib' => \n            array (\n                0 => __DIR__ . '/..' . '/ircmaxell/random-lib/lib',\n            ),\n        ),\n    );\n\n    public static $classMap = array (\n        'Composer\\\\Semver\\\\Comparator' => __DIR__ . '/..' . '/composer/semver/src/Comparator.php',\n        'Composer\\\\Semver\\\\Constraint\\\\AbstractConstraint' => __DIR__ . '/..' . '/composer/semver/src/Constraint/AbstractConstraint.php',\n        'Composer\\\\Semver\\\\Constraint\\\\Constraint' => __DIR__ . '/..' . '/composer/semver/src/Constraint/Constraint.php',\n        'Composer\\\\Semver\\\\Constraint\\\\ConstraintInterface' => __DIR__ . '/..' . '/composer/semver/src/Constraint/ConstraintInterface.php',\n        'Composer\\\\Semver\\\\Constraint\\\\EmptyConstraint' => __DIR__ . '/..' . '/composer/semver/src/Constraint/EmptyConstraint.php',\n        'Composer\\\\Semver\\\\Constraint\\\\MultiConstraint' => __DIR__ . '/..' . '/composer/semver/src/Constraint/MultiConstraint.php',\n        'Composer\\\\Semver\\\\Semver' => __DIR__ . '/..' . '/composer/semver/src/Semver.php',\n        'Composer\\\\Semver\\\\VersionParser' => __DIR__ . '/..' . '/composer/semver/src/VersionParser.php',\n        'Firebase\\\\JWT\\\\BeforeValidException' => __DIR__ . '/..' . '/firebase/php-jwt/src/BeforeValidException.php',\n        'Firebase\\\\JWT\\\\ExpiredException' => __DIR__ . '/..' . '/firebase/php-jwt/src/ExpiredException.php',\n        'Firebase\\\\JWT\\\\JWK' => __DIR__ . '/..' . '/firebase/php-jwt/src/JWK.php',\n        'Firebase\\\\JWT\\\\JWT' => __DIR__ . '/..' . '/firebase/php-jwt/src/JWT.php',\n        'Firebase\\\\JWT\\\\SignatureInvalidException' => __DIR__ . '/..' . '/firebase/php-jwt/src/SignatureInvalidException.php',\n        'RandomLib\\\\AbstractMcryptMixer' => __DIR__ . '/..' . '/ircmaxell/random-lib/lib/RandomLib/AbstractMcryptMixer.php',\n        'RandomLib\\\\AbstractMixer' => __DIR__ . '/..' . '/ircmaxell/random-lib/lib/RandomLib/AbstractMixer.php',\n        'RandomLib\\\\AbstractSource' => __DIR__ . '/..' . '/ircmaxell/random-lib/lib/RandomLib/AbstractSource.php',\n        'RandomLib\\\\Factory' => __DIR__ . '/..' . '/ircmaxell/random-lib/lib/RandomLib/Factory.php',\n        'RandomLib\\\\Generator' => __DIR__ . '/..' . '/ircmaxell/random-lib/lib/RandomLib/Generator.php',\n        'RandomLib\\\\Mixer' => __DIR__ . '/..' . '/ircmaxell/random-lib/lib/RandomLib/Mixer.php',\n        'RandomLib\\\\Mixer\\\\Hash' => __DIR__ . '/..' . '/ircmaxell/random-lib/lib/RandomLib/Mixer/Hash.php',\n        'RandomLib\\\\Mixer\\\\McryptRijndael128' => __DIR__ . '/..' . '/ircmaxell/random-lib/lib/RandomLib/Mixer/McryptRijndael128.php',\n        'RandomLib\\\\Mixer\\\\XorMixer' => __DIR__ . '/..' . '/ircmaxell/random-lib/lib/RandomLib/Mixer/XorMixer.php',\n        'RandomLib\\\\Source' => __DIR__ . '/..' . '/ircmaxell/random-lib/lib/RandomLib/Source.php',\n        'RandomLib\\\\Source\\\\CAPICOM' => __DIR__ . '/..' . '/ircmaxell/random-lib/lib/RandomLib/Source/CAPICOM.php',\n        'RandomLib\\\\Source\\\\MTRand' => __DIR__ . '/..' . '/ircmaxell/random-lib/lib/RandomLib/Source/MTRand.php',\n        'RandomLib\\\\Source\\\\MicroTime' => __DIR__ . '/..' . '/ircmaxell/random-lib/lib/RandomLib/Source/MicroTime.php',\n        'RandomLib\\\\Source\\\\OpenSSL' => __DIR__ . '/..' . '/ircmaxell/random-lib/lib/RandomLib/Source/OpenSSL.php',\n        'RandomLib\\\\Source\\\\Rand' => __DIR__ . '/..' . '/ircmaxell/random-lib/lib/RandomLib/Source/Rand.php',\n        'RandomLib\\\\Source\\\\Random' => __DIR__ . '/..' . '/ircmaxell/random-lib/lib/RandomLib/Source/Random.php',\n        'RandomLib\\\\Source\\\\RandomBytes' => __DIR__ . '/..' . '/ircmaxell/random-lib/lib/RandomLib/Source/RandomBytes.php',\n        'RandomLib\\\\Source\\\\Sodium' => __DIR__ . '/..' . '/ircmaxell/random-lib/lib/RandomLib/Source/Sodium.php',\n        'RandomLib\\\\Source\\\\URandom' => __DIR__ . '/..' . '/ircmaxell/random-lib/lib/RandomLib/Source/URandom.php',\n        'RandomLib\\\\Source\\\\UniqID' => __DIR__ . '/..' . '/ircmaxell/random-lib/lib/RandomLib/Source/UniqID.php',\n        'SecurityLib\\\\AbstractFactory' => __DIR__ . '/..' . '/ircmaxell/security-lib/lib/SecurityLib/AbstractFactory.php',\n        'SecurityLib\\\\BaseConverter' => __DIR__ . '/..' . '/ircmaxell/security-lib/lib/SecurityLib/BaseConverter.php',\n        'SecurityLib\\\\BigMath' => __DIR__ . '/..' . '/ircmaxell/security-lib/lib/SecurityLib/BigMath.php',\n        'SecurityLib\\\\BigMath\\\\BCMath' => __DIR__ . '/..' . '/ircmaxell/security-lib/lib/SecurityLib/BigMath/BCMath.php',\n        'SecurityLib\\\\BigMath\\\\GMP' => __DIR__ . '/..' . '/ircmaxell/security-lib/lib/SecurityLib/BigMath/GMP.php',\n        'SecurityLib\\\\BigMath\\\\PHPMath' => __DIR__ . '/..' . '/ircmaxell/security-lib/lib/SecurityLib/BigMath/PHPMath.php',\n        'SecurityLib\\\\Enum' => __DIR__ . '/..' . '/ircmaxell/security-lib/lib/SecurityLib/Enum.php',\n        'SecurityLib\\\\Hash' => __DIR__ . '/..' . '/ircmaxell/security-lib/lib/SecurityLib/Hash.php',\n        'SecurityLib\\\\Strength' => __DIR__ . '/..' . '/ircmaxell/security-lib/lib/SecurityLib/Strength.php',\n        'SecurityLib\\\\Util' => __DIR__ . '/..' . '/ircmaxell/security-lib/lib/SecurityLib/Util.php',\n        'WPGatsby\\\\ActionMonitor\\\\ActionMonitor' => __DIR__ . '/../..' . '/src/ActionMonitor/ActionMonitor.php',\n        'WPGatsby\\\\ActionMonitor\\\\Monitors\\\\AcfMonitor' => __DIR__ . '/../..' . '/src/ActionMonitor/Monitors/AcfMonitor.php',\n        'WPGatsby\\\\ActionMonitor\\\\Monitors\\\\MediaMonitor' => __DIR__ . '/../..' . '/src/ActionMonitor/Monitors/MediaMonitor.php',\n        'WPGatsby\\\\ActionMonitor\\\\Monitors\\\\Monitor' => __DIR__ . '/../..' . '/src/ActionMonitor/Monitors/Monitor.php',\n        'WPGatsby\\\\ActionMonitor\\\\Monitors\\\\NavMenuMonitor' => __DIR__ . '/../..' . '/src/ActionMonitor/Monitors/NavMenuMonitor.php',\n        'WPGatsby\\\\ActionMonitor\\\\Monitors\\\\PostMonitor' => __DIR__ . '/../..' . '/src/ActionMonitor/Monitors/PostMonitor.php',\n        'WPGatsby\\\\ActionMonitor\\\\Monitors\\\\PostTypeMonitor' => __DIR__ . '/../..' . '/src/ActionMonitor/Monitors/PostTypeMonitor.php',\n        'WPGatsby\\\\ActionMonitor\\\\Monitors\\\\PreviewMonitor' => __DIR__ . '/../..' . '/src/ActionMonitor/Monitors/PreviewMonitor.php',\n        'WPGatsby\\\\ActionMonitor\\\\Monitors\\\\SettingsMonitor' => __DIR__ . '/../..' . '/src/ActionMonitor/Monitors/SettingsMonitor.php',\n        'WPGatsby\\\\ActionMonitor\\\\Monitors\\\\TaxonomyMonitor' => __DIR__ . '/../..' . '/src/ActionMonitor/Monitors/TaxonomyMonitor.php',\n        'WPGatsby\\\\ActionMonitor\\\\Monitors\\\\TermMonitor' => __DIR__ . '/../..' . '/src/ActionMonitor/Monitors/TermMonitor.php',\n        'WPGatsby\\\\ActionMonitor\\\\Monitors\\\\UserMonitor' => __DIR__ . '/../..' . '/src/ActionMonitor/Monitors/UserMonitor.php',\n        'WPGatsby\\\\Admin\\\\Preview' => __DIR__ . '/../..' . '/src/Admin/Preview.php',\n        'WPGatsby\\\\Admin\\\\Settings' => __DIR__ . '/../..' . '/src/Admin/Settings.php',\n        'WPGatsby\\\\GraphQL\\\\Auth' => __DIR__ . '/../..' . '/src/GraphQL/Auth.php',\n        'WPGatsby\\\\GraphQL\\\\ParseAuthToken' => __DIR__ . '/../..' . '/src/GraphQL/ParseAuthToken.php',\n        'WPGatsby\\\\Schema\\\\Schema' => __DIR__ . '/../..' . '/src/Schema/Schema.php',\n        'WPGatsby\\\\Schema\\\\SiteMeta' => __DIR__ . '/../..' . '/src/Schema/SiteMeta.php',\n        'WPGatsby\\\\Schema\\\\WPGatsbyWPGraphQLSchemaChanges' => __DIR__ . '/../..' . '/src/Schema/WPGatsbyWPGraphQLSchemaChanges.php',\n        'WPGatsby\\\\ThemeSupport\\\\ThemeSupport' => __DIR__ . '/../..' . '/src/ThemeSupport/ThemeSupport.php',\n    );\n\n    public static function getInitializer(ClassLoader $loader)\n    {\n        return \\Closure::bind(function () use ($loader) {\n            $loader->prefixLengthsPsr4 = ComposerStaticInitd5ba67e9c3910011804380f1fed1cebe::$prefixLengthsPsr4;\n            $loader->prefixDirsPsr4 = ComposerStaticInitd5ba67e9c3910011804380f1fed1cebe::$prefixDirsPsr4;\n            $loader->prefixesPsr0 = ComposerStaticInitd5ba67e9c3910011804380f1fed1cebe::$prefixesPsr0;\n            $loader->classMap = ComposerStaticInitd5ba67e9c3910011804380f1fed1cebe::$classMap;\n\n        }, null, ClassLoader::class);\n    }\n}\n"
  },
  {
    "path": "vendor/composer/semver/CHANGELOG.md",
    "content": "# Change Log\n\nAll notable changes to this project will be documented in this file.\nThis project adheres to [Semantic Versioning](http://semver.org/).\n\n### [1.7.2] 2020-12-03\n\n  * Fixed: Allow installing on php 8\n\n### [1.7.1] 2020-09-27\n\n  * Fixed: accidental validation of broken constraints combining ^/~ and wildcards, and -dev suffix allowing weird cases\n  * Fixed: normalization of beta0 and such which was dropping the 0\n\n### [1.7.0] 2020-09-09\n\n  * Added: support for `x || @dev`, not very useful but seen in the wild and failed to validate with 1.5.2/1.6.0\n  * Added: support for `foobar-dev` being equal to `dev-foobar`, dev-foobar is the official way to write it but we need to support the other for BC and convenience\n\n### [1.6.0] 2020-09-08\n\n  * Added: support for constraints like `^2.x-dev` and `~2.x-dev`, not very useful but seen in the wild and failed to validate with 1.5.2\n  * Fixed: invalid aliases will no longer throw, unless explicitly validated by Composer in the root package\n\n### [1.5.2] 2020-09-08\n\n  * Fixed: handling of some invalid -dev versions which were seen as valid\n  * Fixed: some doctypes\n\n### [1.5.1] 2020-01-13\n\n  * Fixed: Parsing of aliased version was not validating the alias to be a valid version\n\n### [1.5.0] 2019-03-19\n\n  * Added: some support for date versions (e.g. 201903) in `~` operator\n  * Fixed: support for stabilities in `~` operator was inconsistent\n\n### [1.4.2] 2016-08-30\n\n  * Fixed: collapsing of complex constraints lead to buggy constraints\n\n### [1.4.1] 2016-06-02\n\n  * Changed: branch-like requirements no longer strip build metadata - [composer/semver#38](https://github.com/composer/semver/pull/38).\n\n### [1.4.0] 2016-03-30\n\n  * Added: getters on MultiConstraint - [composer/semver#35](https://github.com/composer/semver/pull/35).\n\n### [1.3.0] 2016-02-25\n\n  * Fixed: stability parsing - [composer/composer#1234](https://github.com/composer/composer/issues/4889).\n  * Changed: collapse contiguous constraints when possible.\n\n### [1.2.0] 2015-11-10\n\n  * Changed: allow multiple numerical identifiers in 'pre-release' version part.\n  * Changed: add more 'v' prefix support.\n\n### [1.1.0] 2015-11-03\n\n  * Changed: dropped redundant `test` namespace.\n  * Changed: minor adjustment in datetime parsing normalization.\n  * Changed: `ConstraintInterface` relaxed, setPrettyString is not required anymore.\n  * Changed: `AbstractConstraint` marked deprecated, will be removed in 2.0.\n  * Changed: `Constraint` is now extensible.\n\n### [1.0.0] 2015-09-21\n\n  * Break: `VersionConstraint` renamed to `Constraint`.\n  * Break: `SpecificConstraint` renamed to `AbstractConstraint`.\n  * Break: `LinkConstraintInterface` renamed to `ConstraintInterface`.\n  * Break: `VersionParser::parseNameVersionPairs` was removed.\n  * Changed: `VersionParser::parseConstraints` allows (but ignores) build metadata now.\n  * Changed: `VersionParser::parseConstraints` allows (but ignores) prefixing numeric versions with a 'v' now.\n  * Changed: Fixed namespace(s) of test files.\n  * Changed: `Comparator::compare` no longer throws `InvalidArgumentException`.\n  * Changed: `Constraint` now throws `InvalidArgumentException`.\n\n### [0.1.0] 2015-07-23\n\n  * Added: `Composer\\Semver\\Comparator`, various methods to compare versions.\n  * Added: various documents such as README.md, LICENSE, etc.\n  * Added: configuration files for Git, Travis, php-cs-fixer, phpunit.\n  * Break: the following namespaces were renamed:\n    - Namespace: `Composer\\Package\\Version` -> `Composer\\Semver`\n    - Namespace: `Composer\\Package\\LinkConstraint` -> `Composer\\Semver\\Constraint`\n    - Namespace: `Composer\\Test\\Package\\Version` -> `Composer\\Test\\Semver`\n    - Namespace: `Composer\\Test\\Package\\LinkConstraint` -> `Composer\\Test\\Semver\\Constraint`\n  * Changed: code style using php-cs-fixer.\n\n[1.7.2]: https://github.com/composer/semver/compare/1.7.1...1.7.2\n[1.7.1]: https://github.com/composer/semver/compare/1.7.0...1.7.1\n[1.7.0]: https://github.com/composer/semver/compare/1.6.0...1.7.0\n[1.6.0]: https://github.com/composer/semver/compare/1.5.2...1.6.0\n[1.5.2]: https://github.com/composer/semver/compare/1.5.1...1.5.2\n[1.5.1]: https://github.com/composer/semver/compare/1.5.0...1.5.1\n[1.5.0]: https://github.com/composer/semver/compare/1.4.2...1.5.0\n[1.4.2]: https://github.com/composer/semver/compare/1.4.1...1.4.2\n[1.4.1]: https://github.com/composer/semver/compare/1.4.0...1.4.1\n[1.4.0]: https://github.com/composer/semver/compare/1.3.0...1.4.0\n[1.3.0]: https://github.com/composer/semver/compare/1.2.0...1.3.0\n[1.2.0]: https://github.com/composer/semver/compare/1.1.0...1.2.0\n[1.1.0]: https://github.com/composer/semver/compare/1.0.0...1.1.0\n[1.0.0]: https://github.com/composer/semver/compare/0.1.0...1.0.0\n[0.1.0]: https://github.com/composer/semver/compare/5e0b9a4da...0.1.0\n"
  },
  {
    "path": "vendor/composer/semver/LICENSE",
    "content": "Copyright (C) 2015 Composer\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\nof the Software, and to permit persons to whom the Software is furnished to do\nso, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "vendor/composer/semver/README.md",
    "content": "composer/semver\n===============\n\nSemver library that offers utilities, version constraint parsing and validation.\n\nOriginally written as part of [composer/composer](https://github.com/composer/composer),\nnow extracted and made available as a stand-alone library.\n\n[![Build Status](https://travis-ci.org/composer/semver.svg?branch=master)](https://travis-ci.org/composer/semver)\n\n\nInstallation\n------------\n\nInstall the latest version with:\n\n```bash\n$ composer require composer/semver\n```\n\n\nRequirements\n------------\n\n* PHP 5.3.2 is required but using the latest version of PHP is highly recommended.\n\n\nVersion Comparison\n------------------\n\nFor details on how versions are compared, refer to the [Versions](https://getcomposer.org/doc/articles/versions.md)\narticle in the documentation section of the [getcomposer.org](https://getcomposer.org) website.\n\n\nBasic usage\n-----------\n\n### Comparator\n\nThe `Composer\\Semver\\Comparator` class provides the following methods for comparing versions:\n\n* greaterThan($v1, $v2)\n* greaterThanOrEqualTo($v1, $v2)\n* lessThan($v1, $v2)\n* lessThanOrEqualTo($v1, $v2)\n* equalTo($v1, $v2)\n* notEqualTo($v1, $v2)\n\nEach function takes two version strings as arguments and returns a boolean. For example:\n\n```php\nuse Composer\\Semver\\Comparator;\n\nComparator::greaterThan('1.25.0', '1.24.0'); // 1.25.0 > 1.24.0\n```\n\n### Semver\n\nThe `Composer\\Semver\\Semver` class provides the following methods:\n\n* satisfies($version, $constraints)\n* satisfiedBy(array $versions, $constraint)\n* sort($versions)\n* rsort($versions)\n\n\nLicense\n-------\n\ncomposer/semver is licensed under the MIT License, see the LICENSE file for details.\n"
  },
  {
    "path": "vendor/composer/semver/composer.json",
    "content": "{\n    \"name\": \"composer/semver\",\n    \"description\": \"Semver library that offers utilities, version constraint parsing and validation.\",\n    \"type\": \"library\",\n    \"license\": \"MIT\",\n    \"keywords\": [\n        \"semver\",\n        \"semantic\",\n        \"versioning\",\n        \"validation\"\n    ],\n    \"authors\": [\n        {\n            \"name\": \"Nils Adermann\",\n            \"email\": \"naderman@naderman.de\",\n            \"homepage\": \"http://www.naderman.de\"\n        },\n        {\n            \"name\": \"Jordi Boggiano\",\n            \"email\": \"j.boggiano@seld.be\",\n            \"homepage\": \"http://seld.be\"\n        },\n        {\n            \"name\": \"Rob Bast\",\n            \"email\": \"rob.bast@gmail.com\",\n            \"homepage\": \"http://robbast.nl\"\n        }\n    ],\n    \"support\": {\n        \"irc\": \"irc://irc.freenode.org/composer\",\n        \"issues\": \"https://github.com/composer/semver/issues\"\n    },\n    \"require\": {\n        \"php\": \"^5.3.2 || ^7.0 || ^8.0\"\n    },\n    \"require-dev\": {\n        \"phpunit/phpunit\": \"^4.5 || ^5.0.5\"\n    },\n    \"autoload\": {\n        \"psr-4\": {\n            \"Composer\\\\Semver\\\\\": \"src\"\n        }\n    },\n    \"autoload-dev\": {\n        \"psr-4\": {\n            \"Composer\\\\Semver\\\\\": \"tests\"\n        }\n    },\n    \"extra\": {\n        \"branch-alias\": {\n            \"dev-master\": \"1.x-dev\"\n        }\n    },\n    \"scripts\": {\n        \"test\": \"phpunit\"\n    }\n}\n"
  },
  {
    "path": "vendor/firebase/php-jwt/LICENSE",
    "content": "Copyright (c) 2011, Neuman Vong\n\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are met:\n\n    * Redistributions of source code must retain the above copyright\n      notice, this list of conditions and the following disclaimer.\n\n    * Redistributions in binary form must reproduce the above\n      copyright notice, this list of conditions and the following\n      disclaimer in the documentation and/or other materials provided\n      with the distribution.\n\n    * Neither the name of Neuman Vong nor the names of other\n      contributors may be used to endorse or promote products derived\n      from this software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\nLIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\nA PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\nOWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\nSPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\nLIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\nDATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\nTHEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
  },
  {
    "path": "vendor/firebase/php-jwt/README.md",
    "content": "[![Build Status](https://travis-ci.org/firebase/php-jwt.png?branch=master)](https://travis-ci.org/firebase/php-jwt)\n[![Latest Stable Version](https://poser.pugx.org/firebase/php-jwt/v/stable)](https://packagist.org/packages/firebase/php-jwt)\n[![Total Downloads](https://poser.pugx.org/firebase/php-jwt/downloads)](https://packagist.org/packages/firebase/php-jwt)\n[![License](https://poser.pugx.org/firebase/php-jwt/license)](https://packagist.org/packages/firebase/php-jwt)\n\nPHP-JWT\n=======\nA simple library to encode and decode JSON Web Tokens (JWT) in PHP, conforming to [RFC 7519](https://tools.ietf.org/html/rfc7519).\n\nInstallation\n------------\n\nUse composer to manage your dependencies and download PHP-JWT:\n\n```bash\ncomposer require firebase/php-jwt\n```\n\nExample\n-------\n```php\n<?php\nuse \\Firebase\\JWT\\JWT;\n\n$key = \"example_key\";\n$payload = array(\n    \"iss\" => \"http://example.org\",\n    \"aud\" => \"http://example.com\",\n    \"iat\" => 1356999524,\n    \"nbf\" => 1357000000\n);\n\n/**\n * IMPORTANT:\n * You must specify supported algorithms for your application. See\n * https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40\n * for a list of spec-compliant algorithms.\n */\n$jwt = JWT::encode($payload, $key);\n$decoded = JWT::decode($jwt, $key, array('HS256'));\n\nprint_r($decoded);\n\n/*\n NOTE: This will now be an object instead of an associative array. To get\n an associative array, you will need to cast it as such:\n*/\n\n$decoded_array = (array) $decoded;\n\n/**\n * You can add a leeway to account for when there is a clock skew times between\n * the signing and verifying servers. It is recommended that this leeway should\n * not be bigger than a few minutes.\n *\n * Source: http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html#nbfDef\n */\nJWT::$leeway = 60; // $leeway in seconds\n$decoded = JWT::decode($jwt, $key, array('HS256'));\n\n?>\n```\nExample with RS256 (openssl)\n----------------------------\n```php\n<?php\nuse \\Firebase\\JWT\\JWT;\n\n$privateKey = <<<EOD\n-----BEGIN RSA PRIVATE KEY-----\nMIICXAIBAAKBgQC8kGa1pSjbSYZVebtTRBLxBz5H4i2p/llLCrEeQhta5kaQu/Rn\nvuER4W8oDH3+3iuIYW4VQAzyqFpwuzjkDI+17t5t0tyazyZ8JXw+KgXTxldMPEL9\n5+qVhgXvwtihXC1c5oGbRlEDvDF6Sa53rcFVsYJ4ehde/zUxo6UvS7UrBQIDAQAB\nAoGAb/MXV46XxCFRxNuB8LyAtmLDgi/xRnTAlMHjSACddwkyKem8//8eZtw9fzxz\nbWZ/1/doQOuHBGYZU8aDzzj59FZ78dyzNFoF91hbvZKkg+6wGyd/LrGVEB+Xre0J\nNil0GReM2AHDNZUYRv+HYJPIOrB0CRczLQsgFJ8K6aAD6F0CQQDzbpjYdx10qgK1\ncP59UHiHjPZYC0loEsk7s+hUmT3QHerAQJMZWC11Qrn2N+ybwwNblDKv+s5qgMQ5\n5tNoQ9IfAkEAxkyffU6ythpg/H0Ixe1I2rd0GbF05biIzO/i77Det3n4YsJVlDck\nZkcvY3SK2iRIL4c9yY6hlIhs+K9wXTtGWwJBAO9Dskl48mO7woPR9uD22jDpNSwe\nk90OMepTjzSvlhjbfuPN1IdhqvSJTDychRwn1kIJ7LQZgQ8fVz9OCFZ/6qMCQGOb\nqaGwHmUK6xzpUbbacnYrIM6nLSkXgOAwv7XXCojvY614ILTK3iXiLBOxPu5Eu13k\neUz9sHyD6vkgZzjtxXECQAkp4Xerf5TGfQXGXhxIX52yH+N2LtujCdkQZjXAsGdm\nB2zNzvrlgRmgBrklMTrMYgm1NPcW+bRLGcwgW2PTvNM=\n-----END RSA PRIVATE KEY-----\nEOD;\n\n$publicKey = <<<EOD\n-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8kGa1pSjbSYZVebtTRBLxBz5H\n4i2p/llLCrEeQhta5kaQu/RnvuER4W8oDH3+3iuIYW4VQAzyqFpwuzjkDI+17t5t\n0tyazyZ8JXw+KgXTxldMPEL95+qVhgXvwtihXC1c5oGbRlEDvDF6Sa53rcFVsYJ4\nehde/zUxo6UvS7UrBQIDAQAB\n-----END PUBLIC KEY-----\nEOD;\n\n$payload = array(\n    \"iss\" => \"example.org\",\n    \"aud\" => \"example.com\",\n    \"iat\" => 1356999524,\n    \"nbf\" => 1357000000\n);\n\n$jwt = JWT::encode($payload, $privateKey, 'RS256');\necho \"Encode:\\n\" . print_r($jwt, true) . \"\\n\";\n\n$decoded = JWT::decode($jwt, $publicKey, array('RS256'));\n\n/*\n NOTE: This will now be an object instead of an associative array. To get\n an associative array, you will need to cast it as such:\n*/\n\n$decoded_array = (array) $decoded;\necho \"Decode:\\n\" . print_r($decoded_array, true) . \"\\n\";\n?>\n```\n\nChangelog\n---------\n\n#### 5.0.0 / 2017-06-26\n- Support RS384 and RS512.\n  See [#117](https://github.com/firebase/php-jwt/pull/117). Thanks [@joostfaassen](https://github.com/joostfaassen)!\n- Add an example for RS256 openssl.\n  See [#125](https://github.com/firebase/php-jwt/pull/125). Thanks [@akeeman](https://github.com/akeeman)!\n- Detect invalid Base64 encoding in signature.\n  See [#162](https://github.com/firebase/php-jwt/pull/162). Thanks [@psignoret](https://github.com/psignoret)!\n- Update `JWT::verify` to handle OpenSSL errors.\n  See [#159](https://github.com/firebase/php-jwt/pull/159). Thanks [@bshaffer](https://github.com/bshaffer)!\n- Add `array` type hinting to `decode` method\n  See [#101](https://github.com/firebase/php-jwt/pull/101). Thanks [@hywak](https://github.com/hywak)!\n- Add all JSON error types.\n  See [#110](https://github.com/firebase/php-jwt/pull/110). Thanks [@gbalduzzi](https://github.com/gbalduzzi)!\n- Bugfix 'kid' not in given key list.\n  See [#129](https://github.com/firebase/php-jwt/pull/129). Thanks [@stampycode](https://github.com/stampycode)!\n- Miscellaneous cleanup, documentation and test fixes.\n  See [#107](https://github.com/firebase/php-jwt/pull/107), [#115](https://github.com/firebase/php-jwt/pull/115),\n  [#160](https://github.com/firebase/php-jwt/pull/160), [#161](https://github.com/firebase/php-jwt/pull/161), and\n  [#165](https://github.com/firebase/php-jwt/pull/165). Thanks [@akeeman](https://github.com/akeeman),\n  [@chinedufn](https://github.com/chinedufn), and [@bshaffer](https://github.com/bshaffer)!\n\n#### 4.0.0 / 2016-07-17\n- Add support for late static binding. See [#88](https://github.com/firebase/php-jwt/pull/88) for details. Thanks to [@chappy84](https://github.com/chappy84)!\n- Use static `$timestamp` instead of `time()` to improve unit testing. See [#93](https://github.com/firebase/php-jwt/pull/93) for details. Thanks to [@josephmcdermott](https://github.com/josephmcdermott)!\n- Fixes to exceptions classes. See [#81](https://github.com/firebase/php-jwt/pull/81) for details. Thanks to [@Maks3w](https://github.com/Maks3w)!\n- Fixes to PHPDoc. See [#76](https://github.com/firebase/php-jwt/pull/76) for details. Thanks to [@akeeman](https://github.com/akeeman)!\n\n#### 3.0.0 / 2015-07-22\n- Minimum PHP version updated from `5.2.0` to `5.3.0`.\n- Add `\\Firebase\\JWT` namespace. See\n[#59](https://github.com/firebase/php-jwt/pull/59) for details. Thanks to\n[@Dashron](https://github.com/Dashron)!\n- Require a non-empty key to decode and verify a JWT. See\n[#60](https://github.com/firebase/php-jwt/pull/60) for details. Thanks to\n[@sjones608](https://github.com/sjones608)!\n- Cleaner documentation blocks in the code. See\n[#62](https://github.com/firebase/php-jwt/pull/62) for details. Thanks to\n[@johanderuijter](https://github.com/johanderuijter)!\n\n#### 2.2.0 / 2015-06-22\n- Add support for adding custom, optional JWT headers to `JWT::encode()`. See\n[#53](https://github.com/firebase/php-jwt/pull/53/files) for details. Thanks to\n[@mcocaro](https://github.com/mcocaro)!\n\n#### 2.1.0 / 2015-05-20\n- Add support for adding a leeway to `JWT:decode()` that accounts for clock skew\nbetween signing and verifying entities. Thanks to [@lcabral](https://github.com/lcabral)!\n- Add support for passing an object implementing the `ArrayAccess` interface for\n`$keys` argument in `JWT::decode()`. Thanks to [@aztech-dev](https://github.com/aztech-dev)!\n\n#### 2.0.0 / 2015-04-01\n- **Note**: It is strongly recommended that you update to > v2.0.0 to address\n  known security vulnerabilities in prior versions when both symmetric and\n  asymmetric keys are used together.\n- Update signature for `JWT::decode(...)` to require an array of supported\n  algorithms to use when verifying token signatures.\n\n\nTests\n-----\nRun the tests using phpunit:\n\n```bash\n$ pear install PHPUnit\n$ phpunit --configuration phpunit.xml.dist\nPHPUnit 3.7.10 by Sebastian Bergmann.\n.....\nTime: 0 seconds, Memory: 2.50Mb\nOK (5 tests, 5 assertions)\n```\n\nNew Lines in private keys\n-----\n\nIf your private key contains `\\n` characters, be sure to wrap it in double quotes `\"\"`\nand not single quotes `''` in order to properly interpret the escaped characters.\n\nLicense\n-------\n[3-Clause BSD](http://opensource.org/licenses/BSD-3-Clause).\n"
  },
  {
    "path": "vendor/firebase/php-jwt/composer.json",
    "content": "{\n    \"name\": \"firebase/php-jwt\",\n    \"description\": \"A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec.\",\n    \"homepage\": \"https://github.com/firebase/php-jwt\",\n    \"keywords\": [\n        \"php\",\n        \"jwt\"\n    ],\n    \"authors\": [\n        {\n            \"name\": \"Neuman Vong\",\n            \"email\": \"neuman+pear@twilio.com\",\n            \"role\": \"Developer\"\n        },\n        {\n            \"name\": \"Anant Narayanan\",\n            \"email\": \"anant@php.net\",\n            \"role\": \"Developer\"\n        }\n    ],\n    \"license\": \"BSD-3-Clause\",\n    \"require\": {\n        \"php\": \">=5.3.0\"\n    },\n    \"autoload\": {\n        \"psr-4\": {\n            \"Firebase\\\\JWT\\\\\": \"src\"\n        }\n    },\n    \"require-dev\": {\n        \"phpunit/phpunit\": \">=4.8 <=9\"\n    }\n}\n"
  },
  {
    "path": "vendor/firebase/php-jwt/src/BeforeValidException.php",
    "content": "<?php\nnamespace Firebase\\JWT;\n\nclass BeforeValidException extends \\UnexpectedValueException\n{\n}\n"
  },
  {
    "path": "vendor/firebase/php-jwt/src/ExpiredException.php",
    "content": "<?php\nnamespace Firebase\\JWT;\n\nclass ExpiredException extends \\UnexpectedValueException\n{\n}\n"
  },
  {
    "path": "vendor/firebase/php-jwt/src/JWK.php",
    "content": "<?php\n\nnamespace Firebase\\JWT;\n\nuse DomainException;\nuse UnexpectedValueException;\n\n/**\n * JSON Web Key implementation, based on this spec:\n * https://tools.ietf.org/html/draft-ietf-jose-json-web-key-41\n *\n * PHP version 5\n *\n * @category Authentication\n * @package  Authentication_JWT\n * @author   Bui Sy Nguyen <nguyenbs@gmail.com>\n * @license  http://opensource.org/licenses/BSD-3-Clause 3-clause BSD\n * @link     https://github.com/firebase/php-jwt\n */\nclass JWK\n{\n    /**\n     * Parse a set of JWK keys\n     *\n     * @param array $jwks The JSON Web Key Set as an associative array\n     *\n     * @return array An associative array that represents the set of keys\n     *\n     * @throws InvalidArgumentException     Provided JWK Set is empty\n     * @throws UnexpectedValueException     Provided JWK Set was invalid\n     * @throws DomainException              OpenSSL failure\n     *\n     * @uses parseKey\n     */\n    public static function parseKeySet(array $jwks)\n    {\n        $keys = array();\n\n        if (!isset($jwks['keys'])) {\n            throw new UnexpectedValueException('\"keys\" member must exist in the JWK Set');\n        }\n        if (empty($jwks['keys'])) {\n            throw new InvalidArgumentException('JWK Set did not contain any keys');\n        }\n\n        foreach ($jwks['keys'] as $k => $v) {\n            $kid = isset($v['kid']) ? $v['kid'] : $k;\n            if ($key = self::parseKey($v)) {\n                $keys[$kid] = $key;\n            }\n        }\n\n        if (0 === \\count($keys)) {\n            throw new UnexpectedValueException('No supported algorithms found in JWK Set');\n        }\n\n        return $keys;\n    }\n\n    /**\n     * Parse a JWK key\n     *\n     * @param array $jwk An individual JWK\n     *\n     * @return resource|array An associative array that represents the key\n     *\n     * @throws InvalidArgumentException     Provided JWK is empty\n     * @throws UnexpectedValueException     Provided JWK was invalid\n     * @throws DomainException              OpenSSL failure\n     *\n     * @uses createPemFromModulusAndExponent\n     */\n    private static function parseKey(array $jwk)\n    {\n        if (empty($jwk)) {\n            throw new InvalidArgumentException('JWK must not be empty');\n        }\n        if (!isset($jwk['kty'])) {\n            throw new UnexpectedValueException('JWK must contain a \"kty\" parameter');\n        }\n\n        switch ($jwk['kty']) {\n            case 'RSA':\n                if (\\array_key_exists('d', $jwk)) {\n                    throw new UnexpectedValueException('RSA private keys are not supported');\n                }\n                if (!isset($jwk['n']) || !isset($jwk['e'])) {\n                    throw new UnexpectedValueException('RSA keys must contain values for both \"n\" and \"e\"');\n                }\n\n                $pem = self::createPemFromModulusAndExponent($jwk['n'], $jwk['e']);\n                $publicKey = \\openssl_pkey_get_public($pem);\n                if (false === $publicKey) {\n                    throw new DomainException(\n                        'OpenSSL error: ' . \\openssl_error_string()\n                    );\n                }\n                return $publicKey;\n            default:\n                // Currently only RSA is supported\n                break;\n        }\n    }\n\n    /**\n     * Create a public key represented in PEM format from RSA modulus and exponent information\n     *\n     * @param string $n The RSA modulus encoded in Base64\n     * @param string $e The RSA exponent encoded in Base64\n     *\n     * @return string The RSA public key represented in PEM format\n     *\n     * @uses encodeLength\n     */\n    private static function createPemFromModulusAndExponent($n, $e)\n    {\n        $modulus = JWT::urlsafeB64Decode($n);\n        $publicExponent = JWT::urlsafeB64Decode($e);\n\n        $components = array(\n            'modulus' => \\pack('Ca*a*', 2, self::encodeLength(\\strlen($modulus)), $modulus),\n            'publicExponent' => \\pack('Ca*a*', 2, self::encodeLength(\\strlen($publicExponent)), $publicExponent)\n        );\n\n        $rsaPublicKey = \\pack(\n            'Ca*a*a*',\n            48,\n            self::encodeLength(\\strlen($components['modulus']) + \\strlen($components['publicExponent'])),\n            $components['modulus'],\n            $components['publicExponent']\n        );\n\n        // sequence(oid(1.2.840.113549.1.1.1), null)) = rsaEncryption.\n        $rsaOID = \\pack('H*', '300d06092a864886f70d0101010500'); // hex version of MA0GCSqGSIb3DQEBAQUA\n        $rsaPublicKey = \\chr(0) . $rsaPublicKey;\n        $rsaPublicKey = \\chr(3) . self::encodeLength(\\strlen($rsaPublicKey)) . $rsaPublicKey;\n\n        $rsaPublicKey = \\pack(\n            'Ca*a*',\n            48,\n            self::encodeLength(\\strlen($rsaOID . $rsaPublicKey)),\n            $rsaOID . $rsaPublicKey\n        );\n\n        $rsaPublicKey = \"-----BEGIN PUBLIC KEY-----\\r\\n\" .\n            \\chunk_split(\\base64_encode($rsaPublicKey), 64) .\n            '-----END PUBLIC KEY-----';\n\n        return $rsaPublicKey;\n    }\n\n    /**\n     * DER-encode the length\n     *\n     * DER supports lengths up to (2**8)**127, however, we'll only support lengths up to (2**8)**4.  See\n     * {@link http://itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf#p=13 X.690 paragraph 8.1.3} for more information.\n     *\n     * @param int $length\n     * @return string\n     */\n    private static function encodeLength($length)\n    {\n        if ($length <= 0x7F) {\n            return \\chr($length);\n        }\n\n        $temp = \\ltrim(\\pack('N', $length), \\chr(0));\n\n        return \\pack('Ca*', 0x80 | \\strlen($temp), $temp);\n    }\n}\n"
  },
  {
    "path": "vendor/firebase/php-jwt/src/JWT.php",
    "content": "<?php\n\nnamespace Firebase\\JWT;\n\nuse \\DomainException;\nuse \\InvalidArgumentException;\nuse \\UnexpectedValueException;\nuse \\DateTime;\n\n/**\n * JSON Web Token implementation, based on this spec:\n * https://tools.ietf.org/html/rfc7519\n *\n * PHP version 5\n *\n * @category Authentication\n * @package  Authentication_JWT\n * @author   Neuman Vong <neuman@twilio.com>\n * @author   Anant Narayanan <anant@php.net>\n * @license  http://opensource.org/licenses/BSD-3-Clause 3-clause BSD\n * @link     https://github.com/firebase/php-jwt\n */\nclass JWT\n{\n    const ASN1_INTEGER = 0x02;\n    const ASN1_SEQUENCE = 0x10;\n    const ASN1_BIT_STRING = 0x03;\n\n    /**\n     * When checking nbf, iat or expiration times,\n     * we want to provide some extra leeway time to\n     * account for clock skew.\n     */\n    public static $leeway = 0;\n\n    /**\n     * Allow the current timestamp to be specified.\n     * Useful for fixing a value within unit testing.\n     *\n     * Will default to PHP time() value if null.\n     */\n    public static $timestamp = null;\n\n    public static $supported_algs = array(\n        'ES256' => array('openssl', 'SHA256'),\n        'HS256' => array('hash_hmac', 'SHA256'),\n        'HS384' => array('hash_hmac', 'SHA384'),\n        'HS512' => array('hash_hmac', 'SHA512'),\n        'RS256' => array('openssl', 'SHA256'),\n        'RS384' => array('openssl', 'SHA384'),\n        'RS512' => array('openssl', 'SHA512'),\n    );\n\n    /**\n     * Decodes a JWT string into a PHP object.\n     *\n     * @param string                    $jwt            The JWT\n     * @param string|array|resource     $key            The key, or map of keys.\n     *                                                  If the algorithm used is asymmetric, this is the public key\n     * @param array                     $allowed_algs   List of supported verification algorithms\n     *                                                  Supported algorithms are 'ES256', 'HS256', 'HS384', 'HS512', 'RS256', 'RS384', and 'RS512'\n     *\n     * @return object The JWT's payload as a PHP object\n     *\n     * @throws UnexpectedValueException     Provided JWT was invalid\n     * @throws SignatureInvalidException    Provided JWT was invalid because the signature verification failed\n     * @throws BeforeValidException         Provided JWT is trying to be used before it's eligible as defined by 'nbf'\n     * @throws BeforeValidException         Provided JWT is trying to be used before it's been created as defined by 'iat'\n     * @throws ExpiredException             Provided JWT has since expired, as defined by the 'exp' claim\n     *\n     * @uses jsonDecode\n     * @uses urlsafeB64Decode\n     */\n    public static function decode($jwt, $key, array $allowed_algs = array())\n    {\n        $timestamp = \\is_null(static::$timestamp) ? \\time() : static::$timestamp;\n\n        if (empty($key)) {\n            throw new InvalidArgumentException('Key may not be empty');\n        }\n        $tks = \\explode('.', $jwt);\n        if (\\count($tks) != 3) {\n            throw new UnexpectedValueException('Wrong number of segments');\n        }\n        list($headb64, $bodyb64, $cryptob64) = $tks;\n        if (null === ($header = static::jsonDecode(static::urlsafeB64Decode($headb64)))) {\n            throw new UnexpectedValueException('Invalid header encoding');\n        }\n        if (null === $payload = static::jsonDecode(static::urlsafeB64Decode($bodyb64))) {\n            throw new UnexpectedValueException('Invalid claims encoding');\n        }\n        if (false === ($sig = static::urlsafeB64Decode($cryptob64))) {\n            throw new UnexpectedValueException('Invalid signature encoding');\n        }\n        if (empty($header->alg)) {\n            throw new UnexpectedValueException('Empty algorithm');\n        }\n        if (empty(static::$supported_algs[$header->alg])) {\n            throw new UnexpectedValueException('Algorithm not supported');\n        }\n        if (!\\in_array($header->alg, $allowed_algs)) {\n            throw new UnexpectedValueException('Algorithm not allowed');\n        }\n        if ($header->alg === 'ES256') {\n            // OpenSSL expects an ASN.1 DER sequence for ES256 signatures\n            $sig = self::signatureToDER($sig);\n        }\n\n        if (\\is_array($key) || $key instanceof \\ArrayAccess) {\n            if (isset($header->kid)) {\n                if (!isset($key[$header->kid])) {\n                    throw new UnexpectedValueException('\"kid\" invalid, unable to lookup correct key');\n                }\n                $key = $key[$header->kid];\n            } else {\n                throw new UnexpectedValueException('\"kid\" empty, unable to lookup correct key');\n            }\n        }\n\n        // Check the signature\n        if (!static::verify(\"$headb64.$bodyb64\", $sig, $key, $header->alg)) {\n            throw new SignatureInvalidException('Signature verification failed');\n        }\n\n        // Check the nbf if it is defined. This is the time that the\n        // token can actually be used. If it's not yet that time, abort.\n        if (isset($payload->nbf) && $payload->nbf > ($timestamp + static::$leeway)) {\n            throw new BeforeValidException(\n                'Cannot handle token prior to ' . \\date(DateTime::ISO8601, $payload->nbf)\n            );\n        }\n\n        // Check that this token has been created before 'now'. This prevents\n        // using tokens that have been created for later use (and haven't\n        // correctly used the nbf claim).\n        if (isset($payload->iat) && $payload->iat > ($timestamp + static::$leeway)) {\n            throw new BeforeValidException(\n                'Cannot handle token prior to ' . \\date(DateTime::ISO8601, $payload->iat)\n            );\n        }\n\n        // Check if this token has expired.\n        if (isset($payload->exp) && ($timestamp - static::$leeway) >= $payload->exp) {\n            throw new ExpiredException('Expired token');\n        }\n\n        return $payload;\n    }\n\n    /**\n     * Converts and signs a PHP object or array into a JWT string.\n     *\n     * @param object|array  $payload    PHP object or array\n     * @param string        $key        The secret key.\n     *                                  If the algorithm used is asymmetric, this is the private key\n     * @param string        $alg        The signing algorithm.\n     *                                  Supported algorithms are 'ES256', 'HS256', 'HS384', 'HS512', 'RS256', 'RS384', and 'RS512'\n     * @param mixed         $keyId\n     * @param array         $head       An array with header elements to attach\n     *\n     * @return string A signed JWT\n     *\n     * @uses jsonEncode\n     * @uses urlsafeB64Encode\n     */\n    public static function encode($payload, $key, $alg = 'HS256', $keyId = null, $head = null)\n    {\n        $header = array('typ' => 'JWT', 'alg' => $alg);\n        if ($keyId !== null) {\n            $header['kid'] = $keyId;\n        }\n        if (isset($head) && \\is_array($head)) {\n            $header = \\array_merge($head, $header);\n        }\n        $segments = array();\n        $segments[] = static::urlsafeB64Encode(static::jsonEncode($header));\n        $segments[] = static::urlsafeB64Encode(static::jsonEncode($payload));\n        $signing_input = \\implode('.', $segments);\n\n        $signature = static::sign($signing_input, $key, $alg);\n        $segments[] = static::urlsafeB64Encode($signature);\n\n        return \\implode('.', $segments);\n    }\n\n    /**\n     * Sign a string with a given key and algorithm.\n     *\n     * @param string            $msg    The message to sign\n     * @param string|resource   $key    The secret key\n     * @param string            $alg    The signing algorithm.\n     *                                  Supported algorithms are 'ES256', 'HS256', 'HS384', 'HS512', 'RS256', 'RS384', and 'RS512'\n     *\n     * @return string An encrypted message\n     *\n     * @throws DomainException Unsupported algorithm was specified\n     */\n    public static function sign($msg, $key, $alg = 'HS256')\n    {\n        if (empty(static::$supported_algs[$alg])) {\n            throw new DomainException('Algorithm not supported');\n        }\n        list($function, $algorithm) = static::$supported_algs[$alg];\n        switch ($function) {\n            case 'hash_hmac':\n                return \\hash_hmac($algorithm, $msg, $key, true);\n            case 'openssl':\n                $signature = '';\n                $success = \\openssl_sign($msg, $signature, $key, $algorithm);\n                if (!$success) {\n                    throw new DomainException(\"OpenSSL unable to sign data\");\n                } else {\n                    if ($alg === 'ES256') {\n                        $signature = self::signatureFromDER($signature, 256);\n                    }\n                    return $signature;\n                }\n        }\n    }\n\n    /**\n     * Verify a signature with the message, key and method. Not all methods\n     * are symmetric, so we must have a separate verify and sign method.\n     *\n     * @param string            $msg        The original message (header and body)\n     * @param string            $signature  The original signature\n     * @param string|resource   $key        For HS*, a string key works. for RS*, must be a resource of an openssl public key\n     * @param string            $alg        The algorithm\n     *\n     * @return bool\n     *\n     * @throws DomainException Invalid Algorithm or OpenSSL failure\n     */\n    private static function verify($msg, $signature, $key, $alg)\n    {\n        if (empty(static::$supported_algs[$alg])) {\n            throw new DomainException('Algorithm not supported');\n        }\n\n        list($function, $algorithm) = static::$supported_algs[$alg];\n        switch ($function) {\n            case 'openssl':\n                $success = \\openssl_verify($msg, $signature, $key, $algorithm);\n                if ($success === 1) {\n                    return true;\n                } elseif ($success === 0) {\n                    return false;\n                }\n                // returns 1 on success, 0 on failure, -1 on error.\n                throw new DomainException(\n                    'OpenSSL error: ' . \\openssl_error_string()\n                );\n            case 'hash_hmac':\n            default:\n                $hash = \\hash_hmac($algorithm, $msg, $key, true);\n                if (\\function_exists('hash_equals')) {\n                    return \\hash_equals($signature, $hash);\n                }\n                $len = \\min(static::safeStrlen($signature), static::safeStrlen($hash));\n\n                $status = 0;\n                for ($i = 0; $i < $len; $i++) {\n                    $status |= (\\ord($signature[$i]) ^ \\ord($hash[$i]));\n                }\n                $status |= (static::safeStrlen($signature) ^ static::safeStrlen($hash));\n\n                return ($status === 0);\n        }\n    }\n\n    /**\n     * Decode a JSON string into a PHP object.\n     *\n     * @param string $input JSON string\n     *\n     * @return object Object representation of JSON string\n     *\n     * @throws DomainException Provided string was invalid JSON\n     */\n    public static function jsonDecode($input)\n    {\n        if (\\version_compare(PHP_VERSION, '5.4.0', '>=') && !(\\defined('JSON_C_VERSION') && PHP_INT_SIZE > 4)) {\n            /** In PHP >=5.4.0, json_decode() accepts an options parameter, that allows you\n             * to specify that large ints (like Steam Transaction IDs) should be treated as\n             * strings, rather than the PHP default behaviour of converting them to floats.\n             */\n            $obj = \\json_decode($input, false, 512, JSON_BIGINT_AS_STRING);\n        } else {\n            /** Not all servers will support that, however, so for older versions we must\n             * manually detect large ints in the JSON string and quote them (thus converting\n             *them to strings) before decoding, hence the preg_replace() call.\n             */\n            $max_int_length = \\strlen((string) PHP_INT_MAX) - 1;\n            $json_without_bigints = \\preg_replace('/:\\s*(-?\\d{'.$max_int_length.',})/', ': \"$1\"', $input);\n            $obj = \\json_decode($json_without_bigints);\n        }\n\n        if ($errno = \\json_last_error()) {\n            static::handleJsonError($errno);\n        } elseif ($obj === null && $input !== 'null') {\n            throw new DomainException('Null result with non-null input');\n        }\n        return $obj;\n    }\n\n    /**\n     * Encode a PHP object into a JSON string.\n     *\n     * @param object|array $input A PHP object or array\n     *\n     * @return string JSON representation of the PHP object or array\n     *\n     * @throws DomainException Provided object could not be encoded to valid JSON\n     */\n    public static function jsonEncode($input)\n    {\n        $json = \\json_encode($input);\n        if ($errno = \\json_last_error()) {\n            static::handleJsonError($errno);\n        } elseif ($json === 'null' && $input !== null) {\n            throw new DomainException('Null result with non-null input');\n        }\n        return $json;\n    }\n\n    /**\n     * Decode a string with URL-safe Base64.\n     *\n     * @param string $input A Base64 encoded string\n     *\n     * @return string A decoded string\n     */\n    public static function urlsafeB64Decode($input)\n    {\n        $remainder = \\strlen($input) % 4;\n        if ($remainder) {\n            $padlen = 4 - $remainder;\n            $input .= \\str_repeat('=', $padlen);\n        }\n        return \\base64_decode(\\strtr($input, '-_', '+/'));\n    }\n\n    /**\n     * Encode a string with URL-safe Base64.\n     *\n     * @param string $input The string you want encoded\n     *\n     * @return string The base64 encode of what you passed in\n     */\n    public static function urlsafeB64Encode($input)\n    {\n        return \\str_replace('=', '', \\strtr(\\base64_encode($input), '+/', '-_'));\n    }\n\n    /**\n     * Helper method to create a JSON error.\n     *\n     * @param int $errno An error number from json_last_error()\n     *\n     * @return void\n     */\n    private static function handleJsonError($errno)\n    {\n        $messages = array(\n            JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',\n            JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON',\n            JSON_ERROR_CTRL_CHAR => 'Unexpected control character found',\n            JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON',\n            JSON_ERROR_UTF8 => 'Malformed UTF-8 characters' //PHP >= 5.3.3\n        );\n        throw new DomainException(\n            isset($messages[$errno])\n            ? $messages[$errno]\n            : 'Unknown JSON error: ' . $errno\n        );\n    }\n\n    /**\n     * Get the number of bytes in cryptographic strings.\n     *\n     * @param string $str\n     *\n     * @return int\n     */\n    private static function safeStrlen($str)\n    {\n        if (\\function_exists('mb_strlen')) {\n            return \\mb_strlen($str, '8bit');\n        }\n        return \\strlen($str);\n    }\n\n    /**\n     * Convert an ECDSA signature to an ASN.1 DER sequence\n     *\n     * @param   string $sig The ECDSA signature to convert\n     * @return  string The encoded DER object\n     */\n    private static function signatureToDER($sig)\n    {\n        // Separate the signature into r-value and s-value\n        list($r, $s) = \\str_split($sig, (int) (\\strlen($sig) / 2));\n\n        // Trim leading zeros\n        $r = \\ltrim($r, \"\\x00\");\n        $s = \\ltrim($s, \"\\x00\");\n\n        // Convert r-value and s-value from unsigned big-endian integers to\n        // signed two's complement\n        if (\\ord($r[0]) > 0x7f) {\n            $r = \"\\x00\" . $r;\n        }\n        if (\\ord($s[0]) > 0x7f) {\n            $s = \"\\x00\" . $s;\n        }\n\n        return self::encodeDER(\n            self::ASN1_SEQUENCE,\n            self::encodeDER(self::ASN1_INTEGER, $r) .\n            self::encodeDER(self::ASN1_INTEGER, $s)\n        );\n    }\n\n    /**\n     * Encodes a value into a DER object.\n     *\n     * @param   int     $type DER tag\n     * @param   string  $value the value to encode\n     * @return  string  the encoded object\n     */\n    private static function encodeDER($type, $value)\n    {\n        $tag_header = 0;\n        if ($type === self::ASN1_SEQUENCE) {\n            $tag_header |= 0x20;\n        }\n\n        // Type\n        $der = \\chr($tag_header | $type);\n\n        // Length\n        $der .= \\chr(\\strlen($value));\n\n        return $der . $value;\n    }\n\n    /**\n     * Encodes signature from a DER object.\n     *\n     * @param   string  $der binary signature in DER format\n     * @param   int     $keySize the number of bits in the key\n     * @return  string  the signature\n     */\n    private static function signatureFromDER($der, $keySize)\n    {\n        // OpenSSL returns the ECDSA signatures as a binary ASN.1 DER SEQUENCE\n        list($offset, $_) = self::readDER($der);\n        list($offset, $r) = self::readDER($der, $offset);\n        list($offset, $s) = self::readDER($der, $offset);\n\n        // Convert r-value and s-value from signed two's compliment to unsigned\n        // big-endian integers\n        $r = \\ltrim($r, \"\\x00\");\n        $s = \\ltrim($s, \"\\x00\");\n\n        // Pad out r and s so that they are $keySize bits long\n        $r = \\str_pad($r, $keySize / 8, \"\\x00\", STR_PAD_LEFT);\n        $s = \\str_pad($s, $keySize / 8, \"\\x00\", STR_PAD_LEFT);\n\n        return $r . $s;\n    }\n\n    /**\n     * Reads binary DER-encoded data and decodes into a single object\n     *\n     * @param string $der the binary data in DER format\n     * @param int $offset the offset of the data stream containing the object\n     * to decode\n     * @return array [$offset, $data] the new offset and the decoded object\n     */\n    private static function readDER($der, $offset = 0)\n    {\n        $pos = $offset;\n        $size = \\strlen($der);\n        $constructed = (\\ord($der[$pos]) >> 5) & 0x01;\n        $type = \\ord($der[$pos++]) & 0x1f;\n\n        // Length\n        $len = \\ord($der[$pos++]);\n        if ($len & 0x80) {\n            $n = $len & 0x1f;\n            $len = 0;\n            while ($n-- && $pos < $size) {\n                $len = ($len << 8) | \\ord($der[$pos++]);\n            }\n        }\n\n        // Value\n        if ($type == self::ASN1_BIT_STRING) {\n            $pos++; // Skip the first contents octet (padding indicator)\n            $data = \\substr($der, $pos, $len - 1);\n            $pos += $len - 1;\n        } elseif (!$constructed) {\n            $data = \\substr($der, $pos, $len);\n            $pos += $len;\n        } else {\n            $data = null;\n        }\n\n        return array($pos, $data);\n    }\n}\n"
  },
  {
    "path": "vendor/firebase/php-jwt/src/SignatureInvalidException.php",
    "content": "<?php\nnamespace Firebase\\JWT;\n\nclass SignatureInvalidException extends \\UnexpectedValueException\n{\n}\n"
  },
  {
    "path": "wp-gatsby.php",
    "content": "<?php\n/**\n * Plugin Name: WP Gatsby\n * Description: Optimize your WordPress site to be a source for Gatsby sites.\n * Version: 2.3.3\n * Author: GatsbyJS, Jason Bahl, Tyler Barnes\n * Author URI: https://gatsbyjs.org\n * Text Domain: wp-gatsby\n * Domain Path: /languages/\n * Requires at least: 5.4.2\n * Requires PHP: 7.3\n * License: GPL-3\n * License URI: https://www.gnu.org/licenses/gpl-3.0.html\n */\n\n// Exit if accessed directly.\nif (! defined('ABSPATH') ) {\n    exit;\n}\n\n/**\n * If the codeception remote coverage file exists, require it.\n *\n * This file should only exist locally or when CI bootstraps the environment for testing\n */\nif (file_exists(__DIR__ . '/c3.php') ) {\n    include_once __DIR__ . '/c3.php';\n}\n\nrequire __DIR__ . \"/lib/wp-settings-api.php\";\n\n/**\n * The one true WPGatsby class\n */\nfinal class WPGatsby\n{\n\n    /**\n     * Instance of the main WPGatsby class\n     *\n     * @var WPGatsby $instance\n     */\n    private static $instance;\n\n    /**\n     * Returns instance of the main WPGatsby class\n     *\n     * @return WPGatsby\n     * @throws Exception\n     */\n    public static function instance()\n    {\n        if (! isset(self::$instance) && ! ( self::$instance instanceof WPGatsby ) ) {\n            self::$instance = new WPGatsby();\n            self::$instance->setup_constants();\n            self::$instance->includes();\n            self::$instance->init();\n        }\n\n        return self::$instance;\n    }\n\n    /**\n     * Throw error on object clone.\n     * The whole idea of the singleton design pattern is that there is a single object\n     * therefore, we don't want the object to be cloned.\n     *\n     * @since  0.0.1\n     * @access public\n     * @return void\n     */\n    public function __clone()\n    {\n\n        // Cloning instances of the class is forbidden.\n        _doing_it_wrong(__FUNCTION__, esc_html__('The WPGATSBY class should not be cloned.', 'wp-gatsby'), '0.0.1');\n\n    }\n\n    /**\n     * Disable unserializing of the class.\n     *\n     * @since  0.0.1\n     * @access protected\n     * @return void\n     */\n    public function __wakeup()\n    {\n\n        // De-serializing instances of the class is forbidden.\n        _doing_it_wrong(__FUNCTION__, esc_html__('De-serializing instances of the WPGATSBY class is not allowed', 'wp-gatsby'), '0.0.1');\n\n    }\n\n    /**\n     * Setup plugin constants.\n     *\n     * @access private\n     * @since  0.0.1\n     * @return void\n     */\n    private function setup_constants()\n    {\n        // Plugin version.\n        if (! defined('WPGATSBY_VERSION') ) {\n            define('WPGATSBY_VERSION', '2.3.3');\n        }\n\n        // Plugin Folder Path.\n        if (! defined('WPGATSBY_PLUGIN_DIR') ) {\n            define('WPGATSBY_PLUGIN_DIR', plugin_dir_path(__FILE__));\n        }\n\n        // Plugin Folder URL.\n        if (! defined('WPGATSBY_PLUGIN_URL') ) {\n            define('WPGATSBY_PLUGIN_URL', plugin_dir_url(__FILE__));\n        }\n\n        // Plugin Root File.\n        if (! defined('WPGATSBY_PLUGIN_FILE') ) {\n            define('WPGATSBY_PLUGIN_FILE', __FILE__);\n        }\n\n        // Whether to autoload the files or not.\n        if (! defined('WPGATSBY_AUTOLOAD') ) {\n            define(\n                'WPGATSBY_AUTOLOAD',\n                // only autoload if WPGQL is active\n                defined('WPGRAPHQL_AUTOLOAD') ? true : false\n            );\n        }\n\n        // Whether to run the plugin in debug mode. Default is false.\n        if (! defined('WPGATSBY_DEBUG') ) {\n            define('WPGATSBY_DEBUG', false);\n        }\n\n    }\n\n    /**\n     * Include required files.\n     * Uses composer's autoload\n     *\n     * @access private\n     * @since  0.0.1\n     * @return void\n     */\n    private function includes()\n    {\n\n        /**\n         * WPGATSBY_AUTOLOAD can be set to \"false\" to prevent the autoloader from running.\n         * In most cases, this is not something that should be disabled, but some environments\n         * may bootstrap their dependencies in a global autoloader that will autoload files\n         * before we get to this point, and requiring the autoloader again can trigger fatal errors.\n         *\n         * The codeception tests are an example of an environment where adding the autoloader again causes issues\n         * so this is set to false for tests.\n         */\n        if (defined('WPGATSBY_AUTOLOAD') && true === WPGATSBY_AUTOLOAD ) {\n            // Autoload Required Classes.\n            include_once WPGATSBY_PLUGIN_DIR . 'vendor/autoload.php';\n        }\n\n        // Required non-autoloaded classes.\n        include_once WPGATSBY_PLUGIN_DIR . 'access-functions.php';\n\n    }\n\n    /**\n     * Initialize plugin functionality\n     */\n    public static function init()\n    {\n        /**\n         * Initialize Admin Settings\n         */\n        new \\WPGatsby\\Admin\\Settings();\n\n        /**\n         * Initialize Admin Previews\n         */\n        new \\WPGatsby\\Admin\\Preview();\n\n        /**\n         * Initialize Schema changes\n         */\n        new \\WPGatsby\\Schema\\Schema();\n\n        /**\n         * Register Theme supports\n         */\n        new \\WPGatsby\\ThemeSupport\\ThemeSupport();\n\n        /**\n         * Initialize Action Monitor\n         */\n        new \\WPGatsby\\ActionMonitor\\ActionMonitor();\n\n        /**\n         * Initialize Auth token parser\n         */\n        new \\WPGatsby\\GraphQL\\ParseAuthToken();\n    }\n}\n\n/**\n * Show admin notice to admins if this plugin is active but WPGraphQL\n * is not active\n */\nfunction wpgatsby_show_admin_notice()\n{\n\n    /**\n     * For users with lower capabilities, don't show the notice\n     */\n    if (! current_user_can('activate_plugins') ) {\n        return;\n    }\n\n    add_action(\n        'admin_notices',\n        function () {\n            ?>\n            <div class=\"error notice\">\n                    <p><?php esc_html_e('WPGraphQL must be active for WPGatsby to work.', 'wp-gatsby'); ?> <a target=\"_blank\" href=\"<?php echo esc_url('https://github.com/wp-graphql/wp-graphql/releases'); ?>\">Download the latest release here.</a></p>\n            </div>\n            <?php\n        }\n    );\n}\n\nif (! function_exists('gatsby_init') ) {\n    function gatsby_init()\n    {\n        if (! defined('WPGRAPHQL_AUTOLOAD') ) {\n            // Show the admin notice\n            add_action('admin_init', 'wpgatsby_show_admin_notice');\n\n            // Bail\n            return;\n        }\n\n        return WPGatsby::instance();\n    }\n}\n\nadd_action(\n    'plugins_loaded', function () {\n        gatsby_init();\n    } \n);\n"
  }
]