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

[Feedback]: Compatibility with WP Offload Media #828

Closed
ethanclevenger91 opened this issue Sep 5, 2020 · 2 comments
Closed

[Feedback]: Compatibility with WP Offload Media #828

ethanclevenger91 opened this issue Sep 5, 2020 · 2 comments

Comments

@ethanclevenger91
Copy link

The plugin currently isn't compatible with WP Offload Media (light or Pro).

WP Offload Media runs its the_content filters with priority 100, while SLB's filter is hooked at 99. This means that in cases where the original URL is in the raw content and being replaced by WP Offload Media, the lightbox will try to grab the original URL instead of the CDN version.

Can be fixed by updating SLB's priority to 101. Classified this as feedback rather than an issue because:

  • Feels sort of arbitrary
  • Hard to guarantee compatibility with everything out there

Here's exactly what I did since there weren't any filters that let me change the priority (you can imply what the action wrapper class does, not super important):

<?php 

namespace XWalk\Plugin\Actions;

use SternerStuff\WordPressUtils\PluginsAPI\ActionHookSubscriber;

class UpdateSimpleLightboxFilterPriority implements ActionHookSubscriber {
	
	public static function get_actions()
	{
		return [
			'init' => 'init',
		];
	}
	
	/**
	* WP Offload Media filters the_content to replace CDN-stored image URLs
	* SLB filters the_content to add lightbox stuff
	* 
	* WP Offload Media replaces image URLs with priority 100, while SLB activates at 99.
	* This means SLB uses the original URLs and not the updated ones.
	* Lowering SLB's priority fixes it.
	* 
	* Could be other instances of this happening.
	*/
	public static function init()
	{
		$slb = $GLOBALS['slb'];
		
		remove_filter('the_content', $slb->m('activate_links'), $slb->util->priority('low'));
		add_filter( 'the_content', $slb->m('activate_links'), 101);	
	}
	
}
@archetyped
Copy link
Owner

Yes, this is a classic The Price is Right Predicament, where another plugin simply needs have a priority value 1 higher and it gets processed after yours. As a result, there's only so much you can do to avoid clashes like this with other plugins using the same hook.

I'll look into changing the priority, but I'll also need to evaluate whether the current priority was selected to avoid other conflicts.

That said, if WP Offload Media is updating the links on every page load rather than updating the attachment URLs in WP's media library, then using the CDN-based URLs may break SLB's ability to pull captions, etc. from the media library. If so, then full support for WP Offload Media may require an extension.

@archetyped
Copy link
Owner

It appears that WP Offload Media (WPOM) may have been updated recently, as the offloaded URL is used regardless of whether SLB runs on the the_content filter before or after WPOM does. This is because WPOM filters post content multiple times at different points in the loading process.

Further, WPOM's URL rewriting does indeed break the connection between the files and WP's media library. This means that the offloaded URLs are used in the lightbox (rather than the local files), but media library metadata (captions, descriptions, etc.) cannot be retrieved for offloaded files.

As a result, an extension will be required to restore access to media library metadata for files offloaded by WPOM. You can track the status and add feedback on this extension in the SLB's Extensions repo: [Plugin/Compatibility]: WP Offload Media.

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

No branches or pull requests

2 participants