xwp / unsplash-wp

GNU General Public License v2.0
9 stars 3 forks source link

Plugin doesn't work if opcache.save_comments is disabled. #195

Closed spacedmonkey closed 4 years ago

spacedmonkey commented 4 years ago

Bug Description

Opache is caching in PHP, it takes your PHP code and compile it, so your site runs faster. For some large hosting companies they enable a flag called save_comments.

Quote from docs.

If disabled, all documentation comments will be discarded from the opcode cache to reduce the size of the optimised code. Disabling this configuration directive may break applications and frameworks that rely on comment parsing for annotations, including Doctrine, Zend Framework 2 and PHPUnit.

The unsplash plugin ( and the wp-foo-bar template ) use annotations to hook in filters and actions. See this example.

https://github.com/xwp/unsplash-wp/blob/dee982ac2ad671b89e443b6eae5e2443b0b321c2/php/class-hotlink.php#L407-L419

As comments are required for these filters / actions to hooked, when opache removes them, the plugin does not function.

Original bug reports - Settings won’t load on install

Expected Behaviour

Plugin should work if opcache.save_comments is disabled, as many hosting companies may disable save_comments

Steps to reproduce

Set opache.save_comments = false.

Acceptance criteria

Implementation brief

Instead of using annotations to hook in filters and actions like this https://github.com/xwp/unsplash-wp/blob/dee982ac2ad671b89e443b6eae5e2443b0b321c2/php/class-hotlink.php#L414

simply use php

add_filter( 'the_content', [ $this, 'hotlink_images_in_content'] , 99, 1 );

QA testing instructions

Demo

Changelog entry

spacedmonkey commented 4 years ago

There are 13 filters and 15 actions hooked this way currently.