diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml new file mode 100644 index 0000000000..d82ad753e6 --- /dev/null +++ b/.github/workflows/build-and-deploy.yml @@ -0,0 +1,166 @@ +--- +name: TEST Build and Deploy +on: + workflow_dispatch: null + pull_request: null +jobs: + build: + name: Build and Commit + runs-on: ubuntu-20.04 + steps: + - name: Checkout the specific branch/ref + uses: actions/checkout@v4 + with: + ref: ${{ github.ref }} + fetch-depth: 0 + + - name: Fetch and checkout built-test branch + run: | + if git ls-remote --exit-code origin built-test; then + git fetch origin built-test + git checkout built-test + git pull origin built-test + else + git checkout -b built-test develop + fi + + - name: Configure Git + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + + - name: Merge current branch into built-test + run: | + git merge --squash $GITHUB_SHA + git commit -m "Merge $GITHUB_SHA into built-test" --no-verify + + - name: Get list of changed files + run: | + git status -s + + - name: Read .nvmrc + run: echo "NODE_VERSION=$(cat .nvmrc)" >> $GITHUB_ENV + + - name: Use Node.js ${{ env.NODE_VERSION }} + uses: actions/setup-node@v4.0.2 + with: + node-version: ${{ env.NODE_VERSION }} + cache: npm + + - name: Build + run: | + npm ci + npm run build + composer install --no-dev --optimize-autoloader --classmap-authoritative + + - name: Get list of changed files + run: | + git status -s + + - name: Commit built files + run: | + git add -Af vendor/ + git status -s + VERSION=$(jq -r .version < package.json) + git commit -m "Build plugin v$VERSION (${{ github.ref_name }})" --no-verify + git push origin built-test + + tag_and_release: + name: Tag and Release + needs: build + runs-on: ubuntu-20.04 + outputs: + VERSION: ${{ steps.get_version.outputs.VERSION }} + steps: + - uses: actions/checkout@v4 + with: + ref: built-test + fetch-depth: 0 + + - name: Get version from package.json + id: get_version + run: | + VERSION=$(jq -r .version < package.json) + echo "VERSION=$VERSION" >> $GITHUB_ENV + echo "VERSION=$VERSION" >> $GITHUB_OUTPUT + echo "The version is $VERSION" + + - name: Tag the commit + run: | + git tag test-${{ env.VERSION }} + git push origin test-${{ env.VERSION }} + + - name: Extract Changelog + id: extract_changelog + run: | + set -e + VERSION=${{ env.VERSION }} + START_LINE=$(grep -n "## \[${VERSION}\]" CHANGELOG.md | cut -d: -f1) + if [ -z "$START_LINE" ]; then + echo "Version not found in CHANGELOG.md" >&2 + exit 1 + fi + TAIL_LINE=$(tail -n +$((START_LINE + 1)) CHANGELOG.md | grep -n "^## " | head -n 1 | cut -d: -f1 || true) + if [ -z "$TAIL_LINE" ]; then + END_LINE=$(wc -l < CHANGELOG.md) + else + END_LINE=$((START_LINE + TAIL_LINE - 1)) + fi + sed -n "${START_LINE},${END_LINE}p" CHANGELOG.md | sed '$d' > release_notes.md + cat release_notes.md + shell: bash + + - name: Format Changelog + id: format_changelog + run: | + sed -i '1d' release_notes.md # Remove the first line + sed -i 's/###/##/g' release_notes.md # Change headers from ### to ## + shell: bash + + - name: Create a GitHub release + id: github_release + uses: ncipollo/release-action@v1 + with: + tag: test-${{ env.VERSION }} + name: ${{ env.VERSION }} + bodyFile: ./release_notes.md + draft: true + prerelease: true + + deploy: + name: Deploy to WordPress.org + needs: tag_and_release + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v4 + with: + ref: test-${{ needs.tag_and_release.outputs.VERSION }} + + - name: WordPress Plugin Deploy + id: wporg_deploy + uses: 10up/action-wordpress-plugin-deploy@stable + with: + dry-run: true + generate-zip: true + env: + SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} + SVN_USERNAME: ${{ secrets.SVN_USERNAME }} + VERSION: test-${{ needs.tag_and_release.outputs.VERSION }} + + - name: Print ZIP file path + run: | + echo "ZIP file path: ${{ steps.wporg_deploy.outputs.zip-path }}" + + - name: Update release with ZIP file + uses: ncipollo/release-action@v1 + with: + tag: test-${{ needs.tag_and_release.outputs.VERSION }} + allowUpdates: true + omitBodyDuringUpdate: true + omitNameDuringUpdate: true + omitDraftDuringUpdate: true + omitPrereleaseDuringUpdate: true + removeArtifacts: true + updateOnlyUnreleased: true + artifacts: ${{ steps.wporg_deploy.outputs.zip-path }} + artifactContentType: application/zip diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index ca3d7f89a3..d9b42ffb01 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -10,6 +10,7 @@ jobs: run: | npm ci npm run build + composer dump-autoload --classmap-authoritative - name: WordPress Plugin Deploy uses: 10up/action-wordpress-plugin-deploy@stable env: diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index 1202e6e67e..7a74bc7cb0 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -23,6 +23,9 @@ jobs: - name: Checkout code uses: actions/checkout@v4 + - name: Refresh Composer autoload files + run: composer dump-autoload --classmap-authoritative + - name: Use desired version of NodeJS uses: actions/setup-node@v4.0.2 with: diff --git a/build/content-helper/dashboard-widget.asset.php b/build/content-helper/dashboard-widget.asset.php index e9331a046f..61255c7d26 100644 --- a/build/content-helper/dashboard-widget.asset.php +++ b/build/content-helper/dashboard-widget.asset.php @@ -1 +1 @@ - array('react', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => 'a741adf6df6b723b2f3d'); + array('react', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => 'cdeb35cda9a85c94d603'); diff --git a/build/content-helper/dashboard-widget.js b/build/content-helper/dashboard-widget.js index 50392fc4be..88e6e5f209 100644 --- a/build/content-helper/dashboard-widget.js +++ b/build/content-helper/dashboard-widget.js @@ -1 +1 @@ -!function(){"use strict";var e={20:function(e,t,r){var n=r(609),a=Symbol.for("react.element"),s=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,i=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,l={key:!0,ref:!0,__self:!0,__source:!0};function c(e,t,r){var n,s={},c=null,u=null;for(n in void 0!==r&&(c=""+r),void 0!==t.key&&(c=""+t.key),void 0!==t.ref&&(u=t.ref),t)o.call(t,n)&&!l.hasOwnProperty(n)&&(s[n]=t[n]);if(e&&e.defaultProps)for(n in t=e.defaultProps)void 0===s[n]&&(s[n]=t[n]);return{$$typeof:a,type:e,key:c,ref:u,props:s,_owner:i.current}}t.Fragment=s,t.jsx=c,t.jsxs=c},848:function(e,t,r){e.exports=r(20)},609:function(e){e.exports=window.React}},t={};function r(n){var a=t[n];if(void 0!==a)return a.exports;var s=t[n]={exports:{}};return e[n](s,s.exports,r),s.exports}r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e,t,n,a=r(848),s=window.wp.element,o=window.wp.i18n,i=function(e){void 0===e&&(e=null);var t="";(null==e?void 0:e.children)&&(t=e.children);var r="content-helper-error-message";return(null==e?void 0:e.className)&&(r+=" "+e.className),(0,a.jsx)("div",{className:r,"data-testid":null==e?void 0:e.testId,dangerouslySetInnerHTML:{__html:t}})},l=function(e){var t;return void 0===e&&(e=null),(0,a.jsx)(i,{className:null==e?void 0:e.className,testId:"empty-credentials-message",children:null!==(t=window.wpParselyEmptyCredentialsMessage)&&void 0!==t?t:(0,o.__)("Please ensure that the Site ID and API Secret given in the plugin's settings are correct.","wp-parsely")})},c=function(){return c=Object.assign||function(e){for(var t,r=1,n=arguments.length;r0&&a[a.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!a||i[1]>a[0]&&i[1]=1e4&&(clearInterval(s),r("Telemetry library not loaded"))}),100);else r("Telemetry not enabled")}))},e.prototype.trackEvent=function(t,r){var n;this.isLoaded?(0!==t.indexOf(e.TRACKS_PREFIX)&&(t=e.TRACKS_PREFIX+t),this.isEventNameValid(t)?(r=this.prepareProperties(r),null===(n=this._tkq)||void 0===n||n.push(["recordEvent",t,r])):console.error("Error tracking event: Invalid event name")):console.error("Error tracking event: Telemetry not loaded")},e.prototype.isTelemetryEnabled=function(){return this.isEnabled},e.prototype.isProprietyValid=function(t){return e.PROPERTY_REGEX.test(t)},e.prototype.isEventNameValid=function(t){return e.EVENT_NAME_REGEX.test(t)},e.prototype.prepareProperties=function(e){return(e=this.sanitizeProperties(e)).parsely_version=wpParselyTracksTelemetry.version,wpParselyTracksTelemetry.user&&(e._ut=wpParselyTracksTelemetry.user.type,e._ui=wpParselyTracksTelemetry.user.id),wpParselyTracksTelemetry.vipgo_env&&(e.vipgo_env=wpParselyTracksTelemetry.vipgo_env),this.sanitizeProperties(e)},e.prototype.sanitizeProperties=function(e){var t=this,r={};return Object.keys(e).forEach((function(n){t.isProprietyValid(n)&&(r[n]=e[n])})),r},e.TRACKS_PREFIX="wpparsely_",e.EVENT_NAME_REGEX=/^(([a-z0-9]+)_){2}([a-z0-9_]+)$/,e.PROPERTY_REGEX=/^[a-z_][a-z0-9_]*$/,e}(),h=(d.trackEvent,function(e){var t=e.defaultValue,r=e.items,n=e.onChange;return(0,a.jsx)("select",{onChange:n,value:t,children:r.map((function(e){return(0,a.jsx)("option",{value:e[0],children:e[1]},e[0])}))})}),f=window.wp.data,y=function(){return y=Object.assign||function(e){for(var t,r=1,n=arguments.length;rhere.',"wp-parsely"):s.code===j.ParselySuggestionsApiOpenAiError||s.code===j.ParselySuggestionsApiOpenAiUnavailable?s.message=(0,o.__)("The Parse.ly API returned an internal server error. Please retry with a different input, or try again later.","wp-parsely"):s.code===j.HttpRequestFailed&&s.message.includes("cURL error 28")?s.message=(0,o.__)("The Parse.ly API did not respond in a timely manner. Please try again later.","wp-parsely"):s.code===j.ParselySuggestionsApiSchemaError?s.message=(0,o.__)("The Parse.ly API returned a validation error. Please try again with different parameters.","wp-parsely"):s.code===j.ParselySuggestionsApiNoData?s.message=(0,o.__)("The Parse.ly API couldn't find any relevant data to fulfill the request. Please retry with a different input.","wp-parsely"):s.code===j.ParselySuggestionsApiOpenAiSchema?s.message=(0,o.__)("The Parse.ly API returned an incorrect response. Please try again later.","wp-parsely"):s.code===j.ParselySuggestionsApiAuthUnavailable&&(s.message=(0,o.__)("The Parse.ly API is currently unavailable. Please try again later.","wp-parsely")),s}return C(t,e),t.prototype.Message=function(e){return void 0===e&&(e=null),[j.PluginCredentialsNotSetMessageDetected,j.PluginSettingsSiteIdNotSet,j.PluginSettingsApiSecretNotSet].includes(this.code)?l(e):(this.code===j.FetchError&&(this.hint=this.Hint((0,o.__)("This error can sometimes be caused by ad-blockers or browser tracking protections. Please add this site to any applicable allow lists and try again.","wp-parsely"))),this.code!==j.ParselyApiForbidden&&this.code!==j.ParselySuggestionsApiNoAuthentication||(this.hint=this.Hint((0,o.__)("Please ensure that the Site ID and API Secret given in the plugin's settings are correct.","wp-parsely"))),this.code===j.HttpRequestFailed&&(this.hint=this.Hint((0,o.__)("The Parse.ly API cannot be reached. Please verify that you are online.","wp-parsely"))),(0,a.jsx)(i,{className:null==e?void 0:e.className,testId:"error",children:"

".concat(this.message,"

").concat(this.hint?this.hint:"")}))},t.prototype.Hint=function(e){return'

'.concat((0,o.__)("Hint:","wp-parsely")," ").concat(e,"

")},t.prototype.createErrorSnackbar=function(){//.test(this.message)||(0,f.dispatch)("core/notices").createNotice("error",this.message,{type:"snackbar"})},t}(Error),O=function(){function e(){this.abortControllers=new Map}return e.prototype.cancelRequest=function(e){if(e)(t=this.abortControllers.get(e))&&(t.abort(),this.abortControllers.delete(e));else{var t,r=Array.from(this.abortControllers.keys()).pop();r&&(t=this.abortControllers.get(r))&&(t.abort(),this.abortControllers.delete(r))}},e.prototype.cancelAll=function(){this.abortControllers.forEach((function(e){return e.abort()})),this.abortControllers.clear()},e.prototype.getOrCreateController=function(e){if(e&&this.abortControllers.has(e))return{abortController:this.abortControllers.get(e),abortId:e};var t=null!=e?e:"auto-"+Date.now(),r=new AbortController;return this.abortControllers.set(t,r),{abortController:r,abortId:t}},e.prototype.fetch=function(e,t){return r=this,n=void 0,s=function(){var r,n,a,s,i,l;return function(e,t){var r,n,a,s,o={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return s={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function i(i){return function(l){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;s&&(s=0,i[0]&&(o=0)),o;)try{if(r=1,n&&(a=2&i[0]?n.return:i[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,i[1])).done)return a;switch(n=0,a&&(i=[2&i[0],a.value]),i[0]){case 0:case 1:a=i;break;case 4:return o.label++,{value:i[1],done:!1};case 5:o.label++,n=i[1],i=[0];continue;case 7:i=o.ops.pop(),o.trys.pop();continue;default:if(!((a=(a=o.trys).length>0&&a[a.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!a||i[1]>a[0]&&i[1]0&&a[a.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!a||i[1]>a[0]&&i[1]=c){var u=t;(a=n/c)%1>1/i&&(u=a>10?1:2),u=parseFloat(a.toFixed(2))===parseFloat(a.toFixed(0))?0:u,s=a.toFixed(u),o=l}i=c})),s+r+o}function z(e){var t=e.metric,r=e.post,n=e.avgEngagedIcon,s=e.viewsIcon;return"views"===t?(0,a.jsxs)("span",{className:"parsely-post-metric-data",children:[(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("Number of Views","wp-parsely")}),s,$(r.views.toString())]}):"avg_engaged"===t?(0,a.jsxs)("span",{className:"parsely-post-metric-data",children:[(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("Average Time","wp-parsely")}),n,r.avgEngaged]}):(0,a.jsx)("span",{className:"parsely-post-metric-data",children:"-"})}function X(e){var t,r=e.metric,n=e.post;return(0,a.jsx)("li",{className:"parsely-top-post",children:(0,a.jsxs)("div",{className:"parsely-top-post-content",children:[(0,a.jsx)(B,{post:n}),(0,a.jsxs)("div",{className:"parsely-top-post-data",children:[(0,a.jsx)(z,{metric:r,post:n}),(0,a.jsx)(Z,{post:n}),(0,a.jsxs)("a",{className:"parsely-top-post-icon-link",href:n.url,target:"_blank",rel:"noreferrer",children:[(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("View Post (opens in new tab)","wp-parsely")}),(0,a.jsx)(q,{})]}),0!==n.postId&&(0,a.jsxs)("a",{className:"parsely-top-post-icon-link",href:(t=n.postId,"/wp-admin/post.php?post=".concat(t,"&action=edit")),target:"_blank",rel:"noreferrer",children:[(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("Edit Post (opens in new tab)","wp-parsely")}),(0,a.jsx)(G,{})]}),(0,a.jsxs)("div",{className:"parsely-top-post-metadata",children:[(0,a.jsxs)("span",{className:"parsely-top-post-date",children:[(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("Date","wp-parsely")}),M(new Date(n.date))]}),(0,a.jsxs)("span",{className:"parsely-top-post-author",children:[(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("Author","wp-parsely")}),n.author]})]})]})]})},n.id)}function B(e){var t=e.post;return t.thumbnailUrl?(0,a.jsxs)("div",{className:"parsely-top-post-thumbnail",children:[(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("Thumbnail","wp-parsely")}),(0,a.jsx)("img",{src:t.thumbnailUrl,alt:(0,o.__)("Post thumbnail","wp-parsely")})]}):(0,a.jsx)("div",{className:"parsely-top-post-thumbnail",children:(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("Post thumbnail not available","wp-parsely")})})}function Z(e){var t=e.post;return(0,a.jsxs)("a",{className:"parsely-top-post-title",href:t.dashUrl,target:"_blank",rel:"noreferrer",children:[(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("View in Parse.ly (opens in new tab)","wp-parsely")}),t.title]})}var W=function(){return W=Object.assign||function(e){for(var t,r=1,n=arguments.length;r0&&a[a.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!a||i[1]>a[0]&&i[1]0&&e.retryFetch?[4,new Promise((function(e){return setTimeout(e,500)}))]:[3,3];case 1:return r.sent(),[4,t(n-1)];case 2:return r.sent(),[3,4];case 3:f(!1),v(e),r.label=4;case 4:return[2]}}))}))})),[2]}))}))};return f(!0),t(1),function(){f(!1),m([]),v(void 0)}}),[i,S]);var j=function(e,t){d.trackEvent("dash_widget_filter_changed",W({filter:e},t))},N=(0,a.jsxs)("div",{className:"parsely-top-posts-filters",children:[(0,a.jsx)(h,{defaultValue:i.Period,items:Object.values(e).map((function(e){return[e,A(e)]})),onChange:function(t){x(t.target.value,e)&&(l({Period:t.target.value}),j("period",{period:t.target.value}),T(1))}}),(0,a.jsx)(h,{defaultValue:i.Metric,items:Object.values(t).map((function(e){return[e,E(e)]})),onChange:function(e){x(e.target.value,t)&&(l({Metric:e.target.value}),j("metric",{metric:e.target.value}),T(1))}})]}),C=(0,a.jsxs)("div",{className:"parsely-top-posts-navigation",children:[(0,a.jsx)("button",{className:"parsely-top-posts-navigation-prev",disabled:S<=1,"aria-label":(0,o.__)("Previous page","wp-parsely"),onClick:function(){T(S-1),d.trackEvent("dash_widget_navigation",{navigation:"previous",to_page:S-1})},children:(0,o.__)("<< Previous","wp-parsely")}),(0,o.sprintf)(/* translators: 1: Current page */ /* translators: 1: Current page */(0,o.__)("Page %1$d","wp-parsely"),S),(0,a.jsx)("button",{className:"parsely-top-posts-navigation-next",disabled:!u&&_.length<5,"aria-label":(0,o.__)("Next page","wp-parsely"),onClick:function(){T(S+1),d.trackEvent("dash_widget_navigation",{navigation:"next",to_page:S+1})},children:(0,o.__)("Next >>","wp-parsely")})]});if(g)return(0,a.jsxs)(a.Fragment,{children:[N,g.Message(),S>1&&C]});var k=(0,a.jsx)("div",{className:"parsely-spinner-wrapper",children:(0,a.jsx)(p.Spinner,{})});return(0,a.jsxs)(a.Fragment,{children:[N,u?k:(0,a.jsx)("ol",{className:"parsely-top-posts",style:{counterReset:"item "+5*(S-1)},children:_.map((function(e){return(0,a.jsx)(X,{metric:i.Metric,post:e},e.id)}))}),(_.length>=5||S>1)&&C]})}var J=function(r){var n;try{n=JSON.parse(r)}catch(r){return{Metric:t.Views,Period:e.Days7}}return x(null==n?void 0:n.Metric,t)||(n.Metric=t.Views),x(null==n?void 0:n.Period,e)||(n.Period=e.Days7),n};window.addEventListener("load",(function(){var e=document.querySelector("#wp-parsely-dashboard-widget > .inside");if(null!==e){var t=(0,a.jsx)(S,{endpoint:"dashboard-widget-settings",defaultSettings:J(window.wpParselyContentHelperSettings),children:(0,a.jsx)(u,{children:(0,a.jsx)(Q,{})})});s.createRoot?(0,s.createRoot)(e).render(t):(0,s.render)(t,e)}}),!1)}()}(); \ No newline at end of file +!function(){"use strict";var e={20:function(e,t,r){var n=r(609),a=Symbol.for("react.element"),s=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,i=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,l={key:!0,ref:!0,__self:!0,__source:!0};function c(e,t,r){var n,s={},c=null,u=null;for(n in void 0!==r&&(c=""+r),void 0!==t.key&&(c=""+t.key),void 0!==t.ref&&(u=t.ref),t)o.call(t,n)&&!l.hasOwnProperty(n)&&(s[n]=t[n]);if(e&&e.defaultProps)for(n in t=e.defaultProps)void 0===s[n]&&(s[n]=t[n]);return{$$typeof:a,type:e,key:c,ref:u,props:s,_owner:i.current}}t.Fragment=s,t.jsx=c,t.jsxs=c},848:function(e,t,r){e.exports=r(20)},609:function(e){e.exports=window.React}},t={};function r(n){var a=t[n];if(void 0!==a)return a.exports;var s=t[n]={exports:{}};return e[n](s,s.exports,r),s.exports}r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e,t,n,a=r(848),s=window.wp.element,o=window.wp.i18n,i=function(e){void 0===e&&(e=null);var t="";(null==e?void 0:e.children)&&(t=e.children);var r="content-helper-error-message";return(null==e?void 0:e.className)&&(r+=" "+e.className),(0,a.jsx)("div",{className:r,"data-testid":null==e?void 0:e.testId,dangerouslySetInnerHTML:{__html:t}})},l=function(e){var t;return void 0===e&&(e=null),(0,a.jsx)(i,{className:null==e?void 0:e.className,testId:"empty-credentials-message",children:null!==(t=window.wpParselyEmptyCredentialsMessage)&&void 0!==t?t:(0,o.__)("Please ensure that the Site ID and API Secret given in the plugin's settings are correct.","wp-parsely")})},c=function(){return c=Object.assign||function(e){for(var t,r=1,n=arguments.length;r0&&a[a.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!a||i[1]>a[0]&&i[1]=1e4&&(clearInterval(s),r("Telemetry library not loaded"))}),100);else r("Telemetry not enabled")}))},e.prototype.trackEvent=function(t,r){var n;this.isLoaded?(0!==t.indexOf(e.TRACKS_PREFIX)&&(t=e.TRACKS_PREFIX+t),this.isEventNameValid(t)?(r=this.prepareProperties(r),null===(n=this._tkq)||void 0===n||n.push(["recordEvent",t,r])):console.error("Error tracking event: Invalid event name")):console.error("Error tracking event: Telemetry not loaded")},e.prototype.isTelemetryEnabled=function(){return this.isEnabled},e.prototype.isProprietyValid=function(t){return e.PROPERTY_REGEX.test(t)},e.prototype.isEventNameValid=function(t){return e.EVENT_NAME_REGEX.test(t)},e.prototype.prepareProperties=function(e){return(e=this.sanitizeProperties(e)).parsely_version=wpParselyTracksTelemetry.version,wpParselyTracksTelemetry.user&&(e._ut=wpParselyTracksTelemetry.user.type,e._ui=wpParselyTracksTelemetry.user.id),wpParselyTracksTelemetry.vipgo_env&&(e.vipgo_env=wpParselyTracksTelemetry.vipgo_env),this.sanitizeProperties(e)},e.prototype.sanitizeProperties=function(e){var t=this,r={};return Object.keys(e).forEach((function(n){t.isProprietyValid(n)&&(r[n]=e[n])})),r},e.TRACKS_PREFIX="wpparsely_",e.EVENT_NAME_REGEX=/^(([a-z0-9]+)_){2}([a-z0-9_]+)$/,e.PROPERTY_REGEX=/^[a-z_][a-z0-9_]*$/,e}(),h=(d.trackEvent,function(e){var t=e.defaultValue,r=e.items,n=e.onChange;return(0,a.jsx)("select",{onChange:n,value:t,children:r.map((function(e){return(0,a.jsx)("option",{value:e[0],children:e[1]},e[0])}))})}),f=window.wp.data,y=function(){return y=Object.assign||function(e){for(var t,r=1,n=arguments.length;rhere.',"wp-parsely"):s.code===j.ParselySuggestionsApiOpenAiError||s.code===j.ParselySuggestionsApiOpenAiUnavailable?s.message=(0,o.__)("The Parse.ly API returned an internal server error. Please retry with a different input, or try again later.","wp-parsely"):s.code===j.HttpRequestFailed&&s.message.includes("cURL error 28")?s.message=(0,o.__)("The Parse.ly API did not respond in a timely manner. Please try again later.","wp-parsely"):s.code===j.ParselySuggestionsApiSchemaError?s.message=(0,o.__)("The Parse.ly API returned a validation error. Please try again with different parameters.","wp-parsely"):s.code===j.ParselySuggestionsApiNoData?s.message=(0,o.__)("The Parse.ly API couldn't find any relevant data to fulfill the request. Please retry with a different input.","wp-parsely"):s.code===j.ParselySuggestionsApiOpenAiSchema?s.message=(0,o.__)("The Parse.ly API returned an incorrect response. Please try again later.","wp-parsely"):s.code===j.ParselySuggestionsApiAuthUnavailable&&(s.message=(0,o.__)("The Parse.ly API is currently unavailable. Please try again later.","wp-parsely")),s}return C(t,e),t.prototype.Message=function(e){return void 0===e&&(e=null),[j.PluginCredentialsNotSetMessageDetected,j.PluginSettingsSiteIdNotSet,j.PluginSettingsApiSecretNotSet].includes(this.code)?l(e):(this.code===j.FetchError&&(this.hint=this.Hint((0,o.__)("This error can sometimes be caused by ad-blockers or browser tracking protections. Please add this site to any applicable allow lists and try again.","wp-parsely"))),this.code!==j.ParselyApiForbidden&&this.code!==j.ParselySuggestionsApiNoAuthentication||(this.hint=this.Hint((0,o.__)("Please ensure that the Site ID and API Secret given in the plugin's settings are correct.","wp-parsely"))),this.code===j.HttpRequestFailed&&(this.hint=this.Hint((0,o.__)("The Parse.ly API cannot be reached. Please verify that you are online.","wp-parsely"))),(0,a.jsx)(i,{className:null==e?void 0:e.className,testId:"error",children:"

".concat(this.message,"

").concat(this.hint?this.hint:"")}))},t.prototype.Hint=function(e){return'

'.concat((0,o.__)("Hint:","wp-parsely")," ").concat(e,"

")},t.prototype.createErrorSnackbar=function(){//.test(this.message)||(0,f.dispatch)("core/notices").createNotice("error",this.message,{type:"snackbar"})},t}(Error),O=function(){function e(){this.abortControllers=new Map}return e.prototype.cancelRequest=function(e){if(e)(t=this.abortControllers.get(e))&&(t.abort(),this.abortControllers.delete(e));else{var t,r=Array.from(this.abortControllers.keys()).pop();r&&(t=this.abortControllers.get(r))&&(t.abort(),this.abortControllers.delete(r))}},e.prototype.cancelAll=function(){this.abortControllers.forEach((function(e){return e.abort()})),this.abortControllers.clear()},e.prototype.getOrCreateController=function(e){if(e&&this.abortControllers.has(e))return{abortController:this.abortControllers.get(e),abortId:e};var t=null!=e?e:"auto-"+Date.now(),r=new AbortController;return this.abortControllers.set(t,r),{abortController:r,abortId:t}},e.prototype.fetch=function(e,t){return r=this,n=void 0,s=function(){var r,n,a,s,i,l;return function(e,t){var r,n,a,s,o={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return s={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function i(i){return function(l){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;s&&(s=0,i[0]&&(o=0)),o;)try{if(r=1,n&&(a=2&i[0]?n.return:i[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,i[1])).done)return a;switch(n=0,a&&(i=[2&i[0],a.value]),i[0]){case 0:case 1:a=i;break;case 4:return o.label++,{value:i[1],done:!1};case 5:o.label++,n=i[1],i=[0];continue;case 7:i=o.ops.pop(),o.trys.pop();continue;default:if(!((a=(a=o.trys).length>0&&a[a.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!a||i[1]>a[0]&&i[1]0&&a[a.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!a||i[1]>a[0]&&i[1]=c){var u=t;(a=n/c)%1>1/i&&(u=a>10?1:2),u=parseFloat(a.toFixed(2))===parseFloat(a.toFixed(0))?0:u,s=a.toFixed(u),o=l}i=c})),s+r+o}function z(e){var t=e.metric,r=e.post,n=e.avgEngagedIcon,s=e.viewsIcon;return"views"===t?(0,a.jsxs)("span",{className:"parsely-post-metric-data",children:[(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("Number of Views","wp-parsely")}),s,$(r.views.toString())]}):"avg_engaged"===t?(0,a.jsxs)("span",{className:"parsely-post-metric-data",children:[(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("Average Time","wp-parsely")}),n,r.avgEngaged]}):(0,a.jsx)("span",{className:"parsely-post-metric-data",children:"-"})}function X(e){var t,r=e.metric,n=e.post;return(0,a.jsx)("li",{className:"parsely-top-post",children:(0,a.jsxs)("div",{className:"parsely-top-post-content",children:[(0,a.jsx)(B,{post:n}),(0,a.jsxs)("div",{className:"parsely-top-post-data",children:[(0,a.jsx)(z,{metric:r,post:n}),(0,a.jsx)(Z,{post:n}),(0,a.jsxs)("a",{className:"parsely-top-post-icon-link",href:n.url,target:"_blank",rel:"noreferrer",children:[(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("View Post (opens in new tab)","wp-parsely")}),(0,a.jsx)(q,{})]}),0!==n.postId&&(0,a.jsxs)("a",{className:"parsely-top-post-icon-link",href:(t=n.postId,"/wp-admin/post.php?post=".concat(t,"&action=edit")),target:"_blank",rel:"noreferrer",children:[(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("Edit Post (opens in new tab)","wp-parsely")}),(0,a.jsx)(G,{})]}),(0,a.jsxs)("div",{className:"parsely-top-post-metadata",children:[(0,a.jsxs)("span",{className:"parsely-top-post-date",children:[(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("Date","wp-parsely")}),M(new Date(n.date))]}),(0,a.jsxs)("span",{className:"parsely-top-post-author",children:[(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("Author","wp-parsely")}),n.author]})]})]})]})},n.id)}function B(e){var t=e.post;return t.thumbnailUrl?(0,a.jsxs)("div",{className:"parsely-top-post-thumbnail",children:[(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("Thumbnail","wp-parsely")}),(0,a.jsx)("img",{src:t.thumbnailUrl,alt:(0,o.__)("Post thumbnail","wp-parsely")})]}):(0,a.jsx)("div",{className:"parsely-top-post-thumbnail",children:(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("Post thumbnail not available","wp-parsely")})})}function Z(e){var t=e.post;return(0,a.jsxs)("a",{className:"parsely-top-post-title",href:t.dashUrl,target:"_blank",rel:"noreferrer",children:[(0,a.jsx)("span",{className:"screen-reader-text",children:(0,o.__)("View in Parse.ly (opens in new tab)","wp-parsely")}),t.title]})}var W=function(){return W=Object.assign||function(e){for(var t,r=1,n=arguments.length;r0&&a[a.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!a||i[1]>a[0]&&i[1]0&&e.retryFetch?[4,new Promise((function(e){return setTimeout(e,500)}))]:[3,3];case 1:return r.sent(),[4,t(n-1)];case 2:return r.sent(),[3,4];case 3:f(!1),v(e),r.label=4;case 4:return[2]}}))}))})),[2]}))}))};return f(!0),t(1),function(){f(!1),m([]),v(void 0)}}),[i,S]);var j=function(e,t){console.log("test"),console.log("another change"),d.trackEvent("dash_widget_filter_changed",W({filter:e},t))},N=(0,a.jsxs)("div",{className:"parsely-top-posts-filters",children:[(0,a.jsx)(h,{defaultValue:i.Period,items:Object.values(e).map((function(e){return[e,A(e)]})),onChange:function(t){x(t.target.value,e)&&(l({Period:t.target.value}),j("period",{period:t.target.value}),T(1))}}),(0,a.jsx)(h,{defaultValue:i.Metric,items:Object.values(t).map((function(e){return[e,E(e)]})),onChange:function(e){x(e.target.value,t)&&(l({Metric:e.target.value}),j("metric",{metric:e.target.value}),T(1))}})]}),C=(0,a.jsxs)("div",{className:"parsely-top-posts-navigation",children:[(0,a.jsx)("button",{className:"parsely-top-posts-navigation-prev",disabled:S<=1,"aria-label":(0,o.__)("Previous page","wp-parsely"),onClick:function(){T(S-1),d.trackEvent("dash_widget_navigation",{navigation:"previous",to_page:S-1})},children:(0,o.__)("<< Previous","wp-parsely")}),(0,o.sprintf)(/* translators: 1: Current page */ /* translators: 1: Current page */(0,o.__)("Page %1$d","wp-parsely"),S),(0,a.jsx)("button",{className:"parsely-top-posts-navigation-next",disabled:!u&&_.length<5,"aria-label":(0,o.__)("Next page","wp-parsely"),onClick:function(){T(S+1),d.trackEvent("dash_widget_navigation",{navigation:"next",to_page:S+1})},children:(0,o.__)("Next >>","wp-parsely")})]});if(g)return(0,a.jsxs)(a.Fragment,{children:[N,g.Message(),S>1&&C]});var k=(0,a.jsx)("div",{className:"parsely-spinner-wrapper",children:(0,a.jsx)(p.Spinner,{})});return(0,a.jsxs)(a.Fragment,{children:[N,u?k:(0,a.jsx)("ol",{className:"parsely-top-posts",style:{counterReset:"item "+5*(S-1)},children:_.map((function(e){return(0,a.jsx)(X,{metric:i.Metric,post:e},e.id)}))}),(_.length>=5||S>1)&&C]})}var J=function(r){var n;try{n=JSON.parse(r)}catch(r){return{Metric:t.Views,Period:e.Days7}}return x(null==n?void 0:n.Metric,t)||(n.Metric=t.Views),x(null==n?void 0:n.Period,e)||(n.Period=e.Days7),n};window.addEventListener("load",(function(){var e=document.querySelector("#wp-parsely-dashboard-widget > .inside");if(null!==e){var t=(0,a.jsx)(S,{endpoint:"dashboard-widget-settings",defaultSettings:J(window.wpParselyContentHelperSettings),children:(0,a.jsx)(u,{children:(0,a.jsx)(Q,{})})});s.createRoot?(0,s.createRoot)(e).render(t):(0,s.render)(t,e)}}),!1)}()}(); \ No newline at end of file diff --git a/composer.json b/composer.json index 19166b64db..6ef1f3791c 100644 --- a/composer.json +++ b/composer.json @@ -42,9 +42,6 @@ "autoload": { "classmap": [ "src/" - ], - "files": [ - "wp-parsely.php" ] }, "autoload-dev": { diff --git a/src/content-helper/dashboard-widget/components/top-posts.tsx b/src/content-helper/dashboard-widget/components/top-posts.tsx index c490b86d0c..78f72d9298 100644 --- a/src/content-helper/dashboard-widget/components/top-posts.tsx +++ b/src/content-helper/dashboard-widget/components/top-posts.tsx @@ -81,6 +81,8 @@ export function TopPosts(): React.JSX.Element { * @param {Object} props The filter properties. */ const trackFilterChanges = ( filter: string, props: object ): void => { + console.log( 'test' ); // eslint-disable-line no-console + console.log( 'another change' ); // eslint-disable-line no-console Telemetry.trackEvent( 'dash_widget_filter_changed', { filter, ...props } ); }; diff --git a/tests/Integration/Blocks/RecommendationsBlockTest.php b/tests/Integration/Blocks/RecommendationsBlockTest.php index 32039da0b3..3fc86a4d19 100644 --- a/tests/Integration/Blocks/RecommendationsBlockTest.php +++ b/tests/Integration/Blocks/RecommendationsBlockTest.php @@ -7,7 +7,7 @@ declare(strict_types=1); -namespace Parsely\Tests\Blocks; +namespace Parsely\Tests\Integration\Blocks; use Parsely\Recommendations_Block; use Parsely\Tests\Integration\TestCase; diff --git a/tests/Integration/content-helper/ContentHelperDashboardWidgetTest.php b/tests/Integration/ContentHelper/ContentHelperDashboardWidgetTest.php similarity index 98% rename from tests/Integration/content-helper/ContentHelperDashboardWidgetTest.php rename to tests/Integration/ContentHelper/ContentHelperDashboardWidgetTest.php index 13032d1311..9d34215bb7 100644 --- a/tests/Integration/content-helper/ContentHelperDashboardWidgetTest.php +++ b/tests/Integration/ContentHelper/ContentHelperDashboardWidgetTest.php @@ -7,7 +7,7 @@ declare(strict_types=1); -namespace Parsely\Tests\ContentHelper; +namespace Parsely\Tests\Integration\ContentHelper; use Parsely\Content_Helper\Dashboard_Widget; use Parsely\Parsely; diff --git a/tests/Integration/content-helper/ContentHelperEditorSidebarTest.php b/tests/Integration/ContentHelper/ContentHelperEditorSidebarTest.php similarity index 96% rename from tests/Integration/content-helper/ContentHelperEditorSidebarTest.php rename to tests/Integration/ContentHelper/ContentHelperEditorSidebarTest.php index 282d2eae0e..1fda7a1fb4 100644 --- a/tests/Integration/content-helper/ContentHelperEditorSidebarTest.php +++ b/tests/Integration/ContentHelper/ContentHelperEditorSidebarTest.php @@ -7,7 +7,7 @@ declare(strict_types=1); -namespace Parsely\Tests\ContentHelper; +namespace Parsely\Tests\Integration\ContentHelper; use Parsely\Content_Helper\Editor_Sidebar; use Parsely\Parsely; diff --git a/tests/Integration/ContentHelperFeatureTest.php b/tests/Integration/ContentHelper/ContentHelperFeatureTest.php similarity index 99% rename from tests/Integration/ContentHelperFeatureTest.php rename to tests/Integration/ContentHelper/ContentHelperFeatureTest.php index b250e2f863..2781a66b52 100644 --- a/tests/Integration/ContentHelperFeatureTest.php +++ b/tests/Integration/ContentHelper/ContentHelperFeatureTest.php @@ -8,10 +8,10 @@ declare(strict_types=1); -namespace Parsely\Tests\ContentHelper; +namespace Parsely\Tests\Integration\ContentHelper; -use Parsely\Tests\Integration\TestCase; use Parsely\Content_Helper\Content_Helper_Feature; +use Parsely\Tests\Integration\TestCase; /** * Base class for all Content Helper feature integration tests. diff --git a/tests/Integration/content-helper/ContentHelperPostListStatsTest.php b/tests/Integration/ContentHelper/ContentHelperPostListStatsTest.php similarity index 99% rename from tests/Integration/content-helper/ContentHelperPostListStatsTest.php rename to tests/Integration/ContentHelper/ContentHelperPostListStatsTest.php index 7070e67eb1..89ddacd256 100644 --- a/tests/Integration/content-helper/ContentHelperPostListStatsTest.php +++ b/tests/Integration/ContentHelper/ContentHelperPostListStatsTest.php @@ -7,13 +7,12 @@ declare(strict_types=1); -namespace Parsely\Tests\ContentHelper; +namespace Parsely\Tests\Integration\ContentHelper; use Mockery; use Parsely\Content_Helper\Post_List_Stats; use Parsely\Parsely; use Parsely\RemoteAPI\Analytics_Posts_API; -use Parsely\Tests\ContentHelper\ContentHelperFeatureTest; use Parsely\Tests\Integration\TestCase; use WP_Error; use WP_Post; diff --git a/tests/Integration/Endpoints/AnalyticsPostsProxyEndpointTest.php b/tests/Integration/Endpoints/Proxy/AnalyticsPostsProxyEndpointTest.php similarity index 98% rename from tests/Integration/Endpoints/AnalyticsPostsProxyEndpointTest.php rename to tests/Integration/Endpoints/Proxy/AnalyticsPostsProxyEndpointTest.php index 19d6170ff8..42a7dcf6a0 100644 --- a/tests/Integration/Endpoints/AnalyticsPostsProxyEndpointTest.php +++ b/tests/Integration/Endpoints/Proxy/AnalyticsPostsProxyEndpointTest.php @@ -8,21 +8,21 @@ declare(strict_types=1); -namespace Parsely\Tests\Integration; +namespace Parsely\Tests\Integration\Endpoints\Proxy; use Parsely\Endpoints\Analytics_Posts_API_Proxy; use Parsely\Endpoints\Base_API_Proxy; use Parsely\Parsely; use Parsely\RemoteAPI\Analytics_Posts_API; +use Parsely\Tests\Integration\TestCase; use WP_Error; use WP_REST_Request; - use function Parsely\Utils\get_date_format; /** * Integration Tests for the Analytics Posts API Proxy Endpoint. */ -final class AnalyticsPostsProxyEndpointTest extends ProxyEndpointTest { +final class AnalyticsPostsProxyEndpointTest extends BaseProxyEndpointTest { /** * Initializes all required values for the test. diff --git a/tests/Integration/ProxyEndpointTest.php b/tests/Integration/Endpoints/Proxy/BaseProxyEndpointTest.php similarity index 97% rename from tests/Integration/ProxyEndpointTest.php rename to tests/Integration/Endpoints/Proxy/BaseProxyEndpointTest.php index 030871970f..d4a9ad9fe8 100644 --- a/tests/Integration/ProxyEndpointTest.php +++ b/tests/Integration/Endpoints/Proxy/BaseProxyEndpointTest.php @@ -8,11 +8,12 @@ declare(strict_types=1); -namespace Parsely\Tests\Integration; +namespace Parsely\Tests\Integration\Endpoints\Proxy; use Parsely\Endpoints\Base_API_Proxy; use Parsely\Endpoints\User_Meta\Base_Endpoint_User_Meta; use Parsely\Parsely; +use Parsely\Tests\Integration\TestCase; use WP_Error; use WP_REST_Request; use WP_REST_Server; @@ -22,7 +23,7 @@ * * @phpstan-import-type Parsely_Options from Parsely */ -abstract class ProxyEndpointTest extends TestCase { +abstract class BaseProxyEndpointTest extends TestCase { /** * Holds a reference to the global $wp_rest_server object to restore in diff --git a/tests/Integration/Endpoints/ReferrersPostDetailProxyEndpointTest.php b/tests/Integration/Endpoints/Proxy/ReferrersPostDetailProxyEndpointTest.php similarity index 98% rename from tests/Integration/Endpoints/ReferrersPostDetailProxyEndpointTest.php rename to tests/Integration/Endpoints/Proxy/ReferrersPostDetailProxyEndpointTest.php index eac7f0429a..d126316bf9 100644 --- a/tests/Integration/Endpoints/ReferrersPostDetailProxyEndpointTest.php +++ b/tests/Integration/Endpoints/Proxy/ReferrersPostDetailProxyEndpointTest.php @@ -8,18 +8,19 @@ declare(strict_types=1); -namespace Parsely\Tests\Integration; +namespace Parsely\Tests\Integration\Endpoints\Proxy; use Parsely\Endpoints\Base_API_Proxy; use Parsely\Endpoints\Referrers_Post_Detail_API_Proxy; use Parsely\Parsely; use Parsely\RemoteAPI\Referrers_Post_Detail_API; +use Parsely\Tests\Integration\TestCase; use WP_REST_Request; /** * Integration Tests for the Referrers Post Detail API Proxy Endpoint. */ -final class ReferrersPostDetailProxyEndpointTest extends ProxyEndpointTest { +final class ReferrersPostDetailProxyEndpointTest extends BaseProxyEndpointTest { /** * Initializes all required values for the test. diff --git a/tests/Integration/Endpoints/RelatedProxyEndpointTest.php b/tests/Integration/Endpoints/Proxy/RelatedProxyEndpointTest.php similarity index 96% rename from tests/Integration/Endpoints/RelatedProxyEndpointTest.php rename to tests/Integration/Endpoints/Proxy/RelatedProxyEndpointTest.php index d576f3bc76..7584fa597d 100644 --- a/tests/Integration/Endpoints/RelatedProxyEndpointTest.php +++ b/tests/Integration/Endpoints/Proxy/RelatedProxyEndpointTest.php @@ -7,18 +7,19 @@ declare(strict_types=1); -namespace Parsely\Tests\Integration; +namespace Parsely\Tests\Integration\Endpoints\Proxy; use Parsely\Endpoints\Base_API_Proxy; use Parsely\Endpoints\Related_API_Proxy; use Parsely\Parsely; use Parsely\RemoteAPI\Related_API; +use Parsely\Tests\Integration\TestCase; use WP_REST_Request; /** * Integration Tests for the Related API Proxy Endpoint. */ -final class RelatedProxyEndpointTest extends ProxyEndpointTest { +final class RelatedProxyEndpointTest extends BaseProxyEndpointTest { /** * Initializes all required values for the test. diff --git a/tests/Integration/Endpoints/StatsPostDetailProxyEndpointTest.php b/tests/Integration/Endpoints/Proxy/StatsPostDetailProxyEndpointTest.php similarity index 97% rename from tests/Integration/Endpoints/StatsPostDetailProxyEndpointTest.php rename to tests/Integration/Endpoints/Proxy/StatsPostDetailProxyEndpointTest.php index 67280bac24..12d5bddd6b 100644 --- a/tests/Integration/Endpoints/StatsPostDetailProxyEndpointTest.php +++ b/tests/Integration/Endpoints/Proxy/StatsPostDetailProxyEndpointTest.php @@ -8,18 +8,19 @@ declare(strict_types=1); -namespace Parsely\Tests\Integration; +namespace Parsely\Tests\Integration\Endpoints\Proxy; -use Parsely\Endpoints\Base_API_Proxy; use Parsely\Endpoints\Analytics_Post_Detail_API_Proxy; +use Parsely\Endpoints\Base_API_Proxy; use Parsely\Parsely; use Parsely\RemoteAPI\Analytics_Post_Detail_API; +use Parsely\Tests\Integration\TestCase; use WP_REST_Request; /** * Integration Tests for the Stats Post Detail API Proxy Endpoint. */ -final class StatsPostDetailProxyEndpointTest extends ProxyEndpointTest { +final class StatsPostDetailProxyEndpointTest extends BaseProxyEndpointTest { /** * Initializes all required values for the test. diff --git a/tests/Integration/BaseUserMetaEndpointTest.php b/tests/Integration/Endpoints/UserMeta/BaseUserMetaEndpointTest.php similarity index 95% rename from tests/Integration/BaseUserMetaEndpointTest.php rename to tests/Integration/Endpoints/UserMeta/BaseUserMetaEndpointTest.php index a32e32cc38..748c405e92 100644 --- a/tests/Integration/BaseUserMetaEndpointTest.php +++ b/tests/Integration/Endpoints/UserMeta/BaseUserMetaEndpointTest.php @@ -8,8 +8,9 @@ declare(strict_types=1); -namespace Parsely\Tests\Integration; +namespace Parsely\Tests\Integration\Endpoints\UserMeta; +use Parsely\Tests\Integration\Endpoints\Proxy\BaseProxyEndpointTest; use WP_REST_Request; /** @@ -17,7 +18,7 @@ * * @since 3.13.0 */ -abstract class BaseUserMetaEndpointTest extends ProxyEndpointTest { +abstract class BaseUserMetaEndpointTest extends BaseProxyEndpointTest { /** * The endpoint's default value. * diff --git a/tests/Integration/Endpoints/DashboardWidgetSettingsEndpointTest.php b/tests/Integration/Endpoints/UserMeta/DashboardWidgetSettingsEndpointTest.php similarity index 98% rename from tests/Integration/Endpoints/DashboardWidgetSettingsEndpointTest.php rename to tests/Integration/Endpoints/UserMeta/DashboardWidgetSettingsEndpointTest.php index 401781bf11..91fdccca48 100644 --- a/tests/Integration/Endpoints/DashboardWidgetSettingsEndpointTest.php +++ b/tests/Integration/Endpoints/UserMeta/DashboardWidgetSettingsEndpointTest.php @@ -8,13 +8,11 @@ declare(strict_types=1); -namespace Parsely\Tests\ContentHelper; +namespace Parsely\Tests\Integration\Endpoints\UserMeta; use Parsely\Endpoints\User_Meta\Base_Endpoint_User_Meta; use Parsely\Endpoints\User_Meta\Dashboard_Widget_Settings_Endpoint; use Parsely\Parsely; -use Parsely\Tests\Integration\BaseUserMetaEndpointTest; - use function Parsely\Utils\convert_endpoint_to_filter_key; /** diff --git a/tests/Integration/Endpoints/EditorSidebarSettingsEndpointTest.php b/tests/Integration/Endpoints/UserMeta/EditorSidebarSettingsEndpointTest.php similarity index 99% rename from tests/Integration/Endpoints/EditorSidebarSettingsEndpointTest.php rename to tests/Integration/Endpoints/UserMeta/EditorSidebarSettingsEndpointTest.php index 4eef9d0d7a..3be4b56895 100644 --- a/tests/Integration/Endpoints/EditorSidebarSettingsEndpointTest.php +++ b/tests/Integration/Endpoints/UserMeta/EditorSidebarSettingsEndpointTest.php @@ -8,13 +8,11 @@ declare(strict_types=1); -namespace Parsely\Tests\ContentHelper; +namespace Parsely\Tests\Integration\Endpoints\UserMeta; use Parsely\Endpoints\User_Meta\Base_Endpoint_User_Meta; use Parsely\Endpoints\User_Meta\Editor_Sidebar_Settings_Endpoint; use Parsely\Parsely; -use Parsely\Tests\Integration\BaseUserMetaEndpointTest; - use function Parsely\Utils\convert_endpoint_to_filter_key; /** diff --git a/tests/Integration/Metadata/AuthorArchiveTest.php b/tests/Integration/Metadata/AuthorArchiveTest.php index 082ab15a2c..089abc3cdc 100644 --- a/tests/Integration/Metadata/AuthorArchiveTest.php +++ b/tests/Integration/Metadata/AuthorArchiveTest.php @@ -7,7 +7,7 @@ declare(strict_types=1); -namespace Parsely\Tests\Integration\StructuredData; +namespace Parsely\Tests\Integration\Metadata; use Parsely\Metadata; use Parsely\Parsely; diff --git a/tests/Integration/Metadata/BlogArchiveTest.php b/tests/Integration/Metadata/BlogArchiveTest.php index 73fc4c6d78..c42346812d 100644 --- a/tests/Integration/Metadata/BlogArchiveTest.php +++ b/tests/Integration/Metadata/BlogArchiveTest.php @@ -7,7 +7,7 @@ declare(strict_types=1); -namespace Parsely\Tests\Integration\StructuredData; +namespace Parsely\Tests\Integration\Metadata; use Parsely\Metadata; use Parsely\Parsely; diff --git a/tests/Integration/Metadata/CustomPostTypeArchiveTest.php b/tests/Integration/Metadata/CustomPostTypeArchiveTest.php index 6c30b2ef11..a9d3327d04 100644 --- a/tests/Integration/Metadata/CustomPostTypeArchiveTest.php +++ b/tests/Integration/Metadata/CustomPostTypeArchiveTest.php @@ -7,7 +7,7 @@ declare(strict_types=1); -namespace Parsely\Tests\Integration\StructuredData; +namespace Parsely\Tests\Integration\Metadata; use Parsely\Metadata; use Parsely\Parsely; diff --git a/tests/Integration/Metadata/CustomTaxonomyTermArchiveTest.php b/tests/Integration/Metadata/CustomTaxonomyTermArchiveTest.php index d8b9696496..869ac5a31d 100644 --- a/tests/Integration/Metadata/CustomTaxonomyTermArchiveTest.php +++ b/tests/Integration/Metadata/CustomTaxonomyTermArchiveTest.php @@ -7,7 +7,7 @@ declare(strict_types=1); -namespace Parsely\Tests\Integration\StructuredData; +namespace Parsely\Tests\Integration\Metadata; use Parsely\Metadata; use Parsely\Parsely; diff --git a/tests/Integration/Metadata/DateArchiveTest.php b/tests/Integration/Metadata/DateArchiveTest.php index 1c00da5022..49fd73a80a 100644 --- a/tests/Integration/Metadata/DateArchiveTest.php +++ b/tests/Integration/Metadata/DateArchiveTest.php @@ -7,7 +7,7 @@ declare(strict_types=1); -namespace Parsely\Tests\Integration\StructuredData; +namespace Parsely\Tests\Integration\Metadata; use Parsely\Tests\Integration\TestCase; use Parsely\Metadata\Date_Builder; diff --git a/tests/Integration/Metadata/GetCurrentUrlTest.php b/tests/Integration/Metadata/GetCurrentUrlTest.php index fef56e32a6..d9f2390344 100644 --- a/tests/Integration/Metadata/GetCurrentUrlTest.php +++ b/tests/Integration/Metadata/GetCurrentUrlTest.php @@ -7,10 +7,11 @@ declare(strict_types=1); -namespace Parsely\Tests\Integration; +namespace Parsely\Tests\Integration\Metadata; use Parsely\Metadata\Front_Page_Builder; use Parsely\Parsely; +use Parsely\Tests\Integration\TestCase; /** * Integration Tests for \Parsely\MetadataMetadata_Builder->get_current_url(). diff --git a/tests/Integration/Metadata/HomePageTest.php b/tests/Integration/Metadata/HomePageTest.php index 0c2a4a3676..8373503b22 100644 --- a/tests/Integration/Metadata/HomePageTest.php +++ b/tests/Integration/Metadata/HomePageTest.php @@ -7,7 +7,7 @@ declare(strict_types=1); -namespace Parsely\Tests\Integration\StructuredData; +namespace Parsely\Tests\Integration\Metadata; use Parsely\Metadata; use Parsely\Parsely; diff --git a/tests/Integration/Metadata/NonPostTestCase.php b/tests/Integration/Metadata/NonPostTestCase.php index 44d0870161..71e873e2b4 100644 --- a/tests/Integration/Metadata/NonPostTestCase.php +++ b/tests/Integration/Metadata/NonPostTestCase.php @@ -7,7 +7,7 @@ declare(strict_types=1); -namespace Parsely\Tests\Integration\StructuredData; +namespace Parsely\Tests\Integration\Metadata; use Parsely\Tests\Integration\TestCase; diff --git a/tests/Integration/Metadata/SinglePageTest.php b/tests/Integration/Metadata/SinglePageTest.php index 7afc846001..02b816ec90 100644 --- a/tests/Integration/Metadata/SinglePageTest.php +++ b/tests/Integration/Metadata/SinglePageTest.php @@ -7,7 +7,7 @@ declare(strict_types=1); -namespace Parsely\Tests\Integration\StructuredData; +namespace Parsely\Tests\Integration\Metadata; use Parsely\Metadata; use Parsely\Parsely; diff --git a/tests/Integration/Metadata/SinglePostTest.php b/tests/Integration/Metadata/SinglePostTest.php index 005538d2af..d249fb7796 100644 --- a/tests/Integration/Metadata/SinglePostTest.php +++ b/tests/Integration/Metadata/SinglePostTest.php @@ -7,7 +7,7 @@ declare(strict_types=1); -namespace Parsely\Tests\Integration\StructuredData; +namespace Parsely\Tests\Integration\Metadata; use Parsely\Metadata; use Parsely\Parsely; diff --git a/tests/Integration/Metadata/TermArchiveTest.php b/tests/Integration/Metadata/TermArchiveTest.php index 497723faab..8541f7cfb4 100644 --- a/tests/Integration/Metadata/TermArchiveTest.php +++ b/tests/Integration/Metadata/TermArchiveTest.php @@ -7,7 +7,7 @@ declare(strict_types=1); -namespace Parsely\Tests\Integration\StructuredData; +namespace Parsely\Tests\Integration\Metadata; use Parsely\Metadata; use Parsely\Parsely; diff --git a/tests/Integration/RemoteAPI/AnalyticsPostsRemoteAPITest.php b/tests/Integration/RemoteAPI/AnalyticsPostsRemoteAPITest.php index c3f75b3e3b..f1f14bbf3c 100644 --- a/tests/Integration/RemoteAPI/AnalyticsPostsRemoteAPITest.php +++ b/tests/Integration/RemoteAPI/AnalyticsPostsRemoteAPITest.php @@ -8,7 +8,7 @@ declare(strict_types=1); -namespace Parsely\Tests\Integration; +namespace Parsely\Tests\Integration\RemoteAPI; use Parsely\Parsely; use Parsely\RemoteAPI\Analytics_Posts_API; @@ -16,7 +16,7 @@ /** * Integration Tests for the Parsely `/analytics/posts` Remote API. */ -final class AnalyticsPostsRemoteAPITest extends RemoteAPITest { +final class AnalyticsPostsRemoteAPITest extends BaseRemoteAPITest { /** * Initializes all required values for the test. diff --git a/tests/Integration/RemoteAPITest.php b/tests/Integration/RemoteAPI/BaseRemoteAPITest.php similarity index 97% rename from tests/Integration/RemoteAPITest.php rename to tests/Integration/RemoteAPI/BaseRemoteAPITest.php index 9b8f5b84af..6f978d11c8 100644 --- a/tests/Integration/RemoteAPITest.php +++ b/tests/Integration/RemoteAPI/BaseRemoteAPITest.php @@ -8,16 +8,17 @@ declare(strict_types=1); -namespace Parsely\Tests\Integration; +namespace Parsely\Tests\Integration\RemoteAPI; -use Parsely\RemoteAPI\Cache; use Parsely\RemoteAPI\Base_Endpoint_Remote; +use Parsely\RemoteAPI\Cache; use Parsely\RemoteAPI\Remote_API_Cache; +use Parsely\Tests\Integration\TestCase; /** * Integration Tests for the Parse.ly Remote API. */ -abstract class RemoteAPITest extends TestCase { +abstract class BaseRemoteAPITest extends TestCase { /** * Internal variable. * diff --git a/tests/Integration/RemoteAPI/content-suggestions/BaseContentSuggestionsAPITest.php b/tests/Integration/RemoteAPI/ContentSuggestions/BaseContentSuggestionsAPITest.php similarity index 96% rename from tests/Integration/RemoteAPI/content-suggestions/BaseContentSuggestionsAPITest.php rename to tests/Integration/RemoteAPI/ContentSuggestions/BaseContentSuggestionsAPITest.php index b472a0dc7e..708b08a6c7 100644 --- a/tests/Integration/RemoteAPI/content-suggestions/BaseContentSuggestionsAPITest.php +++ b/tests/Integration/RemoteAPI/ContentSuggestions/BaseContentSuggestionsAPITest.php @@ -9,14 +9,14 @@ namespace Parsely\Tests\Integration\RemoteAPI\ContentSuggestions; use Parsely\RemoteAPI\ContentSuggestions\Content_Suggestions_Base_API; -use Parsely\Tests\Integration\RemoteAPITest; +use Parsely\Tests\Integration\RemoteAPI\BaseRemoteAPITest; /** * Integration Tests for the Parse.ly Content Suggestions API endpoints. * * @since 3.14.0 */ -abstract class BaseContentSuggestionsAPITest extends RemoteAPITest { +abstract class BaseContentSuggestionsAPITest extends BaseRemoteAPITest { /** * Verifies the basic generation of the API headers. * diff --git a/tests/Integration/RemoteAPI/content-suggestions/SuggestBriefAPITest.php b/tests/Integration/RemoteAPI/ContentSuggestions/SuggestBriefAPITest.php similarity index 100% rename from tests/Integration/RemoteAPI/content-suggestions/SuggestBriefAPITest.php rename to tests/Integration/RemoteAPI/ContentSuggestions/SuggestBriefAPITest.php diff --git a/tests/Integration/RemoteAPI/content-suggestions/SuggestHeadlineAPITest.php b/tests/Integration/RemoteAPI/ContentSuggestions/SuggestHeadlineAPITest.php similarity index 100% rename from tests/Integration/RemoteAPI/content-suggestions/SuggestHeadlineAPITest.php rename to tests/Integration/RemoteAPI/ContentSuggestions/SuggestHeadlineAPITest.php diff --git a/tests/Integration/RemoteAPI/content-suggestions/SuggestLinkedReferenceAPITest.php b/tests/Integration/RemoteAPI/ContentSuggestions/SuggestLinkedReferenceAPITest.php similarity index 100% rename from tests/Integration/RemoteAPI/content-suggestions/SuggestLinkedReferenceAPITest.php rename to tests/Integration/RemoteAPI/ContentSuggestions/SuggestLinkedReferenceAPITest.php diff --git a/tests/Integration/RemoteAPI/RelatedRemoteAPITest.php b/tests/Integration/RemoteAPI/RelatedRemoteAPITest.php index 885e71f0f6..52c4ab80d4 100644 --- a/tests/Integration/RemoteAPI/RelatedRemoteAPITest.php +++ b/tests/Integration/RemoteAPI/RelatedRemoteAPITest.php @@ -7,7 +7,7 @@ declare(strict_types=1); -namespace Parsely\Tests\Integration; +namespace Parsely\Tests\Integration\RemoteAPI; use Parsely\Parsely; use Parsely\RemoteAPI\Related_API; @@ -15,7 +15,7 @@ /** * Integration Tests for the Parsely `/related` Remote API. */ -final class RelatedRemoteAPITest extends RemoteAPITest { +final class RelatedRemoteAPITest extends BaseRemoteAPITest { /** * Initializes all required values for the test. diff --git a/tests/Integration/TestCase.php b/tests/Integration/TestCase.php index 50672a8800..9d2d0de925 100644 --- a/tests/Integration/TestCase.php +++ b/tests/Integration/TestCase.php @@ -12,18 +12,17 @@ use DateInterval; use DateTime; use DateTimeZone; -use ReflectionClass; -use ReflectionProperty; -use ReflectionMethod; use Parsely\Parsely; use PHPUnit\Framework\RiskyTestError; +use ReflectionClass; +use ReflectionMethod; +use ReflectionProperty; use UnexpectedValueException; use WP_Error; use WP_Post; use WP_REST_Request; use WP_Term; use Yoast\WPTestUtils\WPIntegration\TestCase as WPIntegrationTestCase; - use const Parsely\Utils\WP_DATE_TIME_FORMAT; /** @@ -33,7 +32,7 @@ */ abstract class TestCase extends WPIntegrationTestCase { - use \Parsely\Tests\Tests_Reflection; + use \Parsely\Tests\Traits\TestsReflection; public const VALID_SITE_ID = 'demoaccount.parsely.com'; diff --git a/tests/Integration/bootstrap.php b/tests/Integration/bootstrap.php index 72a2cabad3..336f5164c7 100644 --- a/tests/Integration/bootstrap.php +++ b/tests/Integration/bootstrap.php @@ -40,16 +40,12 @@ * MockObject autoloader after that. */ WPIntegration\bootstrap_it(); + require_once dirname( __DIR__ ) . '/../src/Utils/utils.php'; // TODO: refactor to use autoloader. if ( ! defined( 'WP_PLUGIN_DIR' ) || file_exists( WP_PLUGIN_DIR . '/wp-parsely/wp-parsely.php' ) === false ) { echo PHP_EOL, 'ERROR: Please check whether the WP_PLUGIN_DIR environment variable is set and set to the correct value. The unit test suite won\'t be able to run without it.', PHP_EOL; exit( 1 ); } - - // Additional necessary requires. - require_once dirname( __DIR__ ) . '/trait-tests-reflection.php'; - require_once __DIR__ . '/TestCase.php'; - require_once __DIR__ . '/Metadata/NonPostTestCase.php'; } // Plugin root file is not included during tests, so define the namespaced diff --git a/tests/trait-tests-reflection.php b/tests/Traits/TestsReflection.php similarity index 96% rename from tests/trait-tests-reflection.php rename to tests/Traits/TestsReflection.php index bca4a6e620..5223b4b0e0 100644 --- a/tests/trait-tests-reflection.php +++ b/tests/Traits/TestsReflection.php @@ -7,13 +7,13 @@ declare(strict_types=1); -namespace Parsely\Tests; +namespace Parsely\Tests\Traits; use Parsely\Parsely; use ReflectionException; use ReflectionMethod; -trait Tests_Reflection { +trait TestsReflection { /** * Gets a method from a class. This should be used when trying to access a * private method for testing. diff --git a/tests/Unit/Utils/UtilsTest.php b/tests/Unit/Utils/UtilsTest.php index 209d4780e4..0ae2d7ba1b 100644 --- a/tests/Unit/Utils/UtilsTest.php +++ b/tests/Unit/Utils/UtilsTest.php @@ -7,7 +7,7 @@ declare(strict_types=1); -namespace Parsely\Tests\Unit; +namespace Parsely\Tests\Unit\Utils; use Yoast\WPTestUtils\BrainMonkey\TestCase; diff --git a/tests/Unit/bootstrap.php b/tests/Unit/bootstrap.php index 9c9db8b931..cb5f61de39 100644 --- a/tests/Unit/bootstrap.php +++ b/tests/Unit/bootstrap.php @@ -10,7 +10,7 @@ // phpcs:ignore Universal.Namespaces.DisallowCurlyBraceSyntax.Forbidden namespace Parsely\Tests\Unit { // Require any necessary files and autoload the plugin code. - require_once dirname( __DIR__ ) . '/trait-tests-reflection.php'; + require_once dirname( __DIR__ ) . '/../src/Utils/utils.php'; // TODO: refactor to use autoloader. require_once dirname( __DIR__ ) . '/../vendor/yoast/wp-test-utils/src/BrainMonkey/bootstrap.php'; require_once dirname( __DIR__ ) . '/../vendor/autoload.php'; } diff --git a/wp-parsely.php b/wp-parsely.php index e2fd4962ce..62befc0ac0 100644 --- a/wp-parsely.php +++ b/wp-parsely.php @@ -64,7 +64,7 @@ use Parsely\UI\Settings_Page; use Parsely\UI\Site_Health; -require_once __DIR__ . '/src/Utils/utils.php'; +require_once __DIR__ . '/src/Utils/utils.php'; // TODO: refactor to use autoloader. if ( class_exists( Parsely::class ) ) { return; @@ -73,34 +73,10 @@ const PARSELY_VERSION = '3.16.0'; const PARSELY_FILE = __FILE__; -require_once __DIR__ . '/src/Models/class-base-model.php'; -require_once __DIR__ . '/src/Models/class-smart-link.php'; -require_once __DIR__ . '/src/Models/class-inbound-smart-link.php'; - -require_once __DIR__ . '/src/class-parsely.php'; -require_once __DIR__ . '/src/class-permissions.php'; -require_once __DIR__ . '/src/class-scripts.php'; -require_once __DIR__ . '/src/class-dashboard-link.php'; -require_once __DIR__ . '/src/class-validator.php'; -require_once __DIR__ . '/src/UI/class-admin-bar.php'; -require_once __DIR__ . '/src/UI/class-metadata-renderer.php'; -require_once __DIR__ . '/src/Endpoints/class-metadata-endpoint.php'; -require_once __DIR__ . '/src/Endpoints/class-graphql-metadata.php'; -require_once __DIR__ . '/src/Telemetry/telemetry-init.php'; - -require_once __DIR__ . '/src/class-metadata.php'; -require_once __DIR__ . '/src/Metadata/class-metadata-builder.php'; -require_once __DIR__ . '/src/Metadata/class-author-archive-builder.php'; -require_once __DIR__ . '/src/Metadata/class-category-builder.php'; -require_once __DIR__ . '/src/Metadata/class-date-builder.php'; -require_once __DIR__ . '/src/Metadata/class-front-page-builder.php'; -require_once __DIR__ . '/src/Metadata/class-page-builder.php'; -require_once __DIR__ . '/src/Metadata/class-page-for-posts-builder.php'; -require_once __DIR__ . '/src/Metadata/class-paginated-front-page-builder.php'; -require_once __DIR__ . '/src/Metadata/class-post-builder.php'; -require_once __DIR__ . '/src/Metadata/class-tag-builder.php'; +if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) { + require __DIR__ . '/vendor/autoload.php'; +} -add_action( 'plugins_loaded', __NAMESPACE__ . '\\parsely_initialize_plugin' ); /** * Registers the basic classes to initialize the plugin. */ @@ -122,16 +98,9 @@ function parsely_initialize_plugin(): void { $metadata_renderer = new Metadata_Renderer( $GLOBALS['parsely'] ); $metadata_renderer->run(); } +add_action( 'plugins_loaded', __NAMESPACE__ . '\\parsely_initialize_plugin' ); -require_once __DIR__ . '/src/content-helper/common/class-content-helper-feature.php'; -require_once __DIR__ . '/src/content-helper/post-list-stats/class-post-list-stats.php'; -require_once __DIR__ . '/src/UI/class-admin-warning.php'; -require_once __DIR__ . '/src/UI/class-plugins-actions.php'; -require_once __DIR__ . '/src/UI/class-row-actions.php'; -require_once __DIR__ . '/src/UI/class-site-health.php'; -require_once __DIR__ . '/src/content-helper/dashboard-widget/class-dashboard-widget.php'; -add_action( 'admin_init', __NAMESPACE__ . '\\parsely_admin_init_register' ); /** * Registers the Parse.ly wp-admin warnings, plugin actions and row actions. */ @@ -145,11 +114,9 @@ function parsely_admin_init_register(): void { ( new Site_Health( $parsely ) )->run(); ( new Dashboard_Widget( $parsely ) )->run(); } +add_action( 'admin_init', __NAMESPACE__ . '\\parsely_admin_init_register' ); -require_once __DIR__ . '/src/UI/class-settings-page.php'; -require_once __DIR__ . '/src/UI/class-network-admin-sites-list.php'; -add_action( 'init', __NAMESPACE__ . '\\parsely_wp_admin_early_register' ); /** * Registers the additions the Parse.ly wp-admin settings page and Multisite * Network Admin Sites List table. @@ -161,44 +128,8 @@ function parsely_wp_admin_early_register(): void { $network_admin_sites_list = new Network_Admin_Sites_List( $GLOBALS['parsely'] ); $network_admin_sites_list->run(); } +add_action( 'init', __NAMESPACE__ . '\\parsely_wp_admin_early_register' ); -// Endpoint base classes. -require_once __DIR__ . '/src/Endpoints/class-base-endpoint.php'; -require_once __DIR__ . '/src/Endpoints/class-base-api-proxy.php'; -require_once __DIR__ . '/src/Endpoints/user-meta/class-base-endpoint-user-meta.php'; - -// Endpoint classes. -require_once __DIR__ . '/src/Endpoints/class-analytics-post-detail-api-proxy.php'; -require_once __DIR__ . '/src/Endpoints/class-analytics-posts-api-proxy.php'; -require_once __DIR__ . '/src/Endpoints/class-referrers-post-detail-api-proxy.php'; -require_once __DIR__ . '/src/Endpoints/class-related-api-proxy.php'; -require_once __DIR__ . '/src/Endpoints/class-rest-metadata.php'; -require_once __DIR__ . '/src/Endpoints/content-suggestions/class-suggest-brief-api-proxy.php'; -require_once __DIR__ . '/src/Endpoints/content-suggestions/class-suggest-headline-api-proxy.php'; -require_once __DIR__ . '/src/Endpoints/content-suggestions/class-suggest-linked-reference-api-proxy.php'; -require_once __DIR__ . '/src/Endpoints/user-meta/class-dashboard-widget-settings-endpoint.php'; -require_once __DIR__ . '/src/Endpoints/user-meta/class-editor-sidebar-settings-endpoint.php'; -require_once __DIR__ . '/src/Endpoints/content-helper/class-smart-linking-endpoint.php'; - -// RemoteAPI base classes. -require_once __DIR__ . '/src/RemoteAPI/interface-cache.php'; -require_once __DIR__ . '/src/RemoteAPI/interface-remote-api.php'; -require_once __DIR__ . '/src/RemoteAPI/class-remote-api-cache.php'; -require_once __DIR__ . '/src/RemoteAPI/class-wordpress-cache.php'; -require_once __DIR__ . '/src/RemoteAPI/class-base-endpoint-remote.php'; -require_once __DIR__ . '/src/RemoteAPI/content-suggestions/class-content-suggestions-base-api.php'; - -// RemoteAPI classes. -require_once __DIR__ . '/src/RemoteAPI/class-analytics-post-detail-api.php'; -require_once __DIR__ . '/src/RemoteAPI/class-analytics-posts-api.php'; -require_once __DIR__ . '/src/RemoteAPI/class-referrers-post-detail-api.php'; -require_once __DIR__ . '/src/RemoteAPI/class-related-api.php'; -require_once __DIR__ . '/src/RemoteAPI/class-validate-api.php'; -require_once __DIR__ . '/src/RemoteAPI/content-suggestions/class-suggest-brief-api.php'; -require_once __DIR__ . '/src/RemoteAPI/content-suggestions/class-suggest-headline-api.php'; -require_once __DIR__ . '/src/RemoteAPI/content-suggestions/class-suggest-linked-reference-api.php'; - -add_action( 'rest_api_init', __NAMESPACE__ . '\\parsely_rest_api_init' ); /** * Registers REST Endpoints that act as a proxy to the Parse.ly API. * This is needed to get around CORS issues with Firefox. @@ -259,10 +190,8 @@ function parsely_rest_api_init(): void { $wp_cache ); } +add_action( 'rest_api_init', __NAMESPACE__ . '\\parsely_rest_api_init' ); -require_once __DIR__ . '/src/blocks/recommendations/class-recommendations-block.php'; - -add_action( 'init', __NAMESPACE__ . '\\init_recommendations_block' ); /** * Registers the Recommendations Block. */ @@ -270,10 +199,9 @@ function init_recommendations_block(): void { $recommendations_block = new Recommendations_Block(); $recommendations_block->run(); } +add_action( 'init', __NAMESPACE__ . '\\init_recommendations_block' ); -require_once __DIR__ . '/src/content-helper/editor-sidebar/class-editor-sidebar.php'; -add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\\init_content_helper_editor_sidebar' ); /** * Inserts the PCH Editor Sidebar. * @@ -283,11 +211,7 @@ function init_recommendations_block(): void { function init_content_helper_editor_sidebar(): void { $GLOBALS['parsely_editor_sidebar']->run(); } - -require_once __DIR__ . '/src/content-helper/excerpt-generator/class-excerpt-generator.php'; - -add_action( 'admin_init', __NAMESPACE__ . '\\parsely_content_helper_editor_sidebar_features' ); -add_action( 'rest_api_init', __NAMESPACE__ . '\\parsely_content_helper_editor_sidebar_features' ); +add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\\init_content_helper_editor_sidebar' ); /** * Initializes the PCH Editor Sidebar features. @@ -305,8 +229,10 @@ function parsely_content_helper_editor_sidebar_features(): void { $GLOBALS['parsely_editor_sidebar']->init_features(); } -// The priority of 9 is used to ensure that the Excerpt Generator is loaded before the PCH Editor Sidebar (10). -add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\\init_content_helper_excerpt_generator', 9 ); +add_action( 'admin_init', __NAMESPACE__ . '\\parsely_content_helper_editor_sidebar_features' ); +add_action( 'rest_api_init', __NAMESPACE__ . '\\parsely_content_helper_editor_sidebar_features' ); + + /** * Initializes and inserts the PCH Excerpt Generator. * @@ -315,23 +241,18 @@ function parsely_content_helper_editor_sidebar_features(): void { function init_content_helper_excerpt_generator(): void { ( new Excerpt_Generator( $GLOBALS['parsely'] ) )->run(); } +// The priority of 9 is used to ensure that the Excerpt Generator is loaded before the PCH Editor Sidebar (10). +add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\\init_content_helper_excerpt_generator', 9 ); -require_once __DIR__ . '/src/UI/class-recommended-widget.php'; -add_action( 'widgets_init', __NAMESPACE__ . '\\parsely_recommended_widget_register' ); /** * Registers the Parse.ly Recommended widget. */ function parsely_recommended_widget_register(): void { register_widget( new Recommended_Widget( $GLOBALS['parsely'] ) ); } +add_action( 'widgets_init', __NAMESPACE__ . '\\parsely_recommended_widget_register' ); -require_once __DIR__ . '/src/Integrations/class-integration.php'; -require_once __DIR__ . '/src/Integrations/class-integrations.php'; -require_once __DIR__ . '/src/Integrations/class-amp.php'; -require_once __DIR__ . '/src/Integrations/class-google-web-stories.php'; - -add_action( 'init', __NAMESPACE__ . '\\parsely_integrations' ); // @phpstan-ignore-line /** * Instantiates Integrations collection and registers built-in integrations. * @@ -356,6 +277,7 @@ function parsely_integrations( $parsely = null ): Integrations { return $parsely_integrations; } +add_action( 'init', __NAMESPACE__ . '\\parsely_integrations' ); // @phpstan-ignore-line /** * Instantiates and runs the specified API endpoint.