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

[Feature] Rank Math Compatibility with the multisite-global-media plugin #282

Open
codedbyglenden opened this issue Jun 12, 2024 · 1 comment · May be fixed by #283
Open

[Feature] Rank Math Compatibility with the multisite-global-media plugin #282

codedbyglenden opened this issue Jun 12, 2024 · 1 comment · May be fixed by #283

Comments

@codedbyglenden
Copy link

Is your feature request related to a problem? Please describe.

We have a various clients that make use of the Global Media Library plugin for WordPress, which allows a multi-site instance to use a singular site as a hub for all media assets across multiple sites in a network.

Plugin link: multisite-global-media

The conflict between Rank Math & MGM happens when rank math tries to generate an OG Image tag. When you select an image stored in the Global media library, the image id is saved to the post in a slightly different format, so that MGM can identify between images stored on the current site or those saved to the hub site. The format saved is in the following format:

{hub_site_id}000000{actual_attachment_id_saved_on_the_hub_site}

If we for example set a featured image stored in the hub site on a post, the id reference saved in the post_thumbnail field might be:

12300000012

123 = The Hub site id
12 = The attachment id saved in the network

When rank math tried to generate the OG Image tag the first function it runs into is:

wp_attachment_is_image

This will fail because the id format is non-standard, and technically an attachment with this id doesn't actually exist. And unfortunately this is an function without filters or actions.

Describe the solution you'd like

My proposed solution is to add a do_action before the wp_attachment_is_image check, as well as a filter for the attachment id. This will allow me to add a site switch inside of the do_action (in my theme or plugin) then add a another do_action after the get_variations function call to switch the site back to the current site.

I've attached a screenshot with the proposed changes below. New code is labelled with a "new code" comment. The filter and action names are purely placeholder names to demonstrate the code changes I would like to see.

Google Keep

Describe alternatives you've considered

As we can not filter the code before the image check there is no alternative to get OG image tags generated in Rank Math SEO currently.

@codedbyglenden codedbyglenden changed the title Rank Math Compatibility with the multisite-global-media plugin [Feature] Rank Math Compatibility with the multisite-global-media plugin Jun 12, 2024
@pratikrm
Copy link
Collaborator

Hi @codedbyglenden

Thank you for submitting a PR. I checked this on my local setup and was able to reproduce the issue. I believe hooks are needed to switch and reset the blogs. If so, shouldn't we pass $attachment_id to the hook? I have also added a comment in the PR:
https://github.com/rankmath/seo-by-rank-math/pull/283/files#r1642583643

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