Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Fixes issues for content replacement for the site and media URLs #2014

Open
wants to merge 4 commits into
base: canary
Choose a base branch
from

Conversation

colinmurphy
Copy link
Contributor

@colinmurphy colinmurphy commented Dec 24, 2024

See #1956

This fixes various issues for content replacement callback functions for both the site and media URLs. There is 2 main fixes in this branch.

  1. Fixed issues with site URL and content replacment and not taking into account different HTTP protocols for the site URL (http, https)
  2. Fixed an issue when the configuration setting " Enable Post and Category URL rewrites" was enabled and also "Use the WordPress domain for media URLs in post content" was enabled, it was updating the media URLs to the frontend URL even though it should of been the WP site URL

The branch also adds 2 new filters to allow developers to modify the URLS used for content replacement

  1. faustwp_get_wp_site_urls - An array of site URLs
  2. faustwp_get_wp_site_media_urls - An array of media site URLs

This branch also updated Github actions to also use WordPress 6.6. and 6.7

Tasks

  • I have signed a Contributor License Agreement (CLA) with WP Engine.
  • If a code change, I have written testing instructions that the whole team & outside contributors can understand.
  • I have written and included a comprehensive changeset to properly document the changes I've made.

Description

See above.

Related Issue(s):

#1956

Testing

Setup

As per issue #1956 I setup a WordPress Multisite (sub-domains) with the latest version of 6.7.1 using Local.

I setup 3 sub-domains and installed FaustWP, WPGraphQL & ACF and one of the sites was setup as http://alpha.multisite.local/

I setup a field group for pages and I setup a WYSIWG editor field with the field name summary

I then updated the sample page to have an image for the WYSIWG field and also a link e.g.

<img class="alignnone size-medium wp-image-10" src="http://alpha.multisite.local/wp-content/uploads/sites/2/2024/12/WP-Engine-Blue-888x459-1-300x155.webp" alt="" width="300" height="155" />

<a href="https://alpha.multisite.local/index.php/hello-world/">Hello World</a>

I then used the following GraphQL query in the WPGraphQL IDE for debugging and fixing the issues

{
  pages {
    nodes {
      pageFields {
        summary
      }
    }
  }
}

I then access the site on HTTPS rather than HTTP (site_url)

Tests

Note http://localhost:3000 is the frontend URL set in Faust WP and I am accessing the site on HTTPS e.g. https://alpha.multisite.local/wp-admin/

Test 1: URL Rewrites Enabled

  1. Enable Post and Category URL rewrites = enabled
  2. Use the WordPress domain for media URLs in post content = disabled

Query

{
  pages {
    nodes {
      pageFields {
        summary
      }
    }
  }
}

Output

{
  "data": {
    "pages": {
      "nodes": [
        {
          "pageFields": {
            "summary": "<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-10\" src=\"http://localhost:3000/wp-content/uploads/sites/2/2024/12/WP-Engine-Blue-888x459-1-300x155.webp\" alt=\"\" width=\"300\" height=\"155\" srcset=\"http://localhost:3000/wp-content/uploads/sites/2/2024/12/WP-Engine-Blue-888x459-1-300x155.webp 300w, http://localhost:3000/wp-content/uploads/sites/2/2024/12/WP-Engine-Blue-888x459-1-768x397.webp 768w, http://localhost:3000/wp-content/uploads/sites/2/2024/12/WP-Engine-Blue-888x459-1.webp 888w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" /></p>\n<p><a href=\"http://localhost:3000/index.php/hello-world/\">Hello World</a></p>\n"
          }
        }
      ]
    }
  }
}
image

All 3 URLs (image src, srcset and link) were updated correctly to the frontend URL http://localhost:3000/

Test 2: URL Rewrites Enabled and Media Rewrites Disabled

  1. Enable Post and Category URL rewrites = enabled
  2. Use the WordPress domain for media URLs in post content = enabled

Query

{
  pages {
    nodes {
      pageFields {
        summary
      }
    }
  }
}

Output

{
  "data": {
    "pages": {
      "nodes": [
        {
          "pageFields": {
            "summary": "<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-10\" src=\"http://alpha.multisite.local/wp-content/uploads/sites/2/2024/12/WP-Engine-Blue-888x459-1-300x155.webp\" alt=\"\" width=\"300\" height=\"155\" srcset=\"https://alpha.multisite.local/wp-content/uploads/sites/2/2024/12/WP-Engine-Blue-888x459-1-300x155.webp 300w, https://alpha.multisite.local/wp-content/uploads/sites/2/2024/12/WP-Engine-Blue-888x459-1-768x397.webp 768w, https://alpha.multisite.local/wp-content/uploads/sites/2/2024/12/WP-Engine-Blue-888x459-1.webp 888w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" /></p>\n<p><a href=\"http://localhost:3000/index.php/hello-world/\">Hello World</a></p>\n"
          }
        }
      ]
    }
  }
}
image

The image URL wasn't updated and the link was updated to the frontend URL.

Test 3: URL Rewrites Disabled and Media Rewrites Disabled

  1. Enable Post and Category URL rewrites = disabled
  2. Use the WordPress domain for media URLs in post content = enabled

Query

{
  pages {
    nodes {
      pageFields {
        summary
      }
    }
  }
}

Output

{
  "data": {
    "pages": {
      "nodes": [
        {
          "pageFields": {
            "summary": "<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-10\" src=\"http://alpha.multisite.local/wp-content/uploads/sites/2/2024/12/WP-Engine-Blue-888x459-1-300x155.webp\" alt=\"\" width=\"300\" height=\"155\" srcset=\"https://alpha.multisite.local/wp-content/uploads/sites/2/2024/12/WP-Engine-Blue-888x459-1-300x155.webp 300w, https://alpha.multisite.local/wp-content/uploads/sites/2/2024/12/WP-Engine-Blue-888x459-1-768x397.webp 768w, https://alpha.multisite.local/wp-content/uploads/sites/2/2024/12/WP-Engine-Blue-888x459-1.webp 888w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" /></p>\n<p><a href=\"https://alpha.multisite.local/index.php/hello-world/\">Hello World</a></p>\n"
          }
        }
      ]
    }
  }
}
image

Neither the image src, srcset or link was updated to use the frontend URL

Test 4: URL Rewrites Disabled and Media Rewrites Enabled

  1. Enable Post and Category URL rewrites = disabled
  2. Use the WordPress domain for media URLs in post content = disabled

Query

{
  pages {
    nodes {
      pageFields {
        summary
      }
    }
  }
}

Output

{
  "data": {
    "pages": {
      "nodes": [
        {
          "pageFields": {
            "summary": "<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-10\" src=\"http://localhost:3000/wp-content/uploads/sites/2/2024/12/WP-Engine-Blue-888x459-1-300x155.webp\" alt=\"\" width=\"300\" height=\"155\" srcset=\"http://localhost:3000/wp-content/uploads/sites/2/2024/12/WP-Engine-Blue-888x459-1-300x155.webp 300w, http://localhost:3000/wp-content/uploads/sites/2/2024/12/WP-Engine-Blue-888x459-1-768x397.webp 768w, http://localhost:3000/wp-content/uploads/sites/2/2024/12/WP-Engine-Blue-888x459-1.webp 888w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" /></p>\n<p><a href=\"https://alpha.multisite.local/index.php/hello-world/\">Hello World</a></p>\n"
          }
        }
      ]
    }
  }
}
image

Both the image src and srcset URLs were updated with the frontend URL where the link stayed the same

Screenshots

Documentation Changes

There was 2 new filters added

  1. faustwp_get_wp_site_urls for allowing developers to add or modify an array of site URLS used for content replacement
  2. faustwp_get_wp_site_media_urls for allowign developers to add or modify an array of media site URLS for content replacemnt

Dependant PRs

… and also updates tests to use WP 6.6 and 6.7

Fixes various issues with using content replacement for the site URL.
Copy link

changeset-bot bot commented Dec 24, 2024

🦋 Changeset detected

Latest commit: be14c9a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@faustwp/wordpress-plugin Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@colinmurphy colinmurphy changed the title Fix for #1986. Fixes various issues for content replacement for site url (draft) Fixes various issues for content replacement for site url (draft) Dec 24, 2024
Copy link
Contributor

github-actions bot commented Dec 24, 2024

📦 Next.js Bundle Analysis for @faustwp/getting-started-example

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

@colinmurphy
Copy link
Contributor Author

@josephfusco This is the draft PR for the site URL issues. This fixes the various issues as per our call last week but I also want to update the image srcset replacement with the same functionality so that we replace all HTTP protocols e.g. HTTP, HTTPS or //

@colinmurphy
Copy link
Contributor Author

Just noting I am working on also updating the image_source_srcset_replacement function callback aswell to use all HTTP protocols so I will have an updated PR next week after the holidays.

@colinmurphy colinmurphy self-assigned this Dec 30, 2024
@colinmurphy colinmurphy changed the title Fixes various issues for content replacement for site url (draft) Bug: Fixes issues for content replacement for the site and media URLs Dec 30, 2024
@theodesp
Copy link
Member

Awesome!

@colinmurphy colinmurphy marked this pull request as ready for review December 30, 2024 15:58
@colinmurphy colinmurphy requested a review from a team as a code owner December 30, 2024 15:58
@colinmurphy
Copy link
Contributor Author

Awesome!

Thanks @theodesp I have also now updated the PR with details on how to replicate the issue and test the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants