flyntwp /
flynt
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Flynt\TimberDynamicResize; |
||||
| 4 | |||||
| 5 | use Flynt\Utils\Options; |
||||
| 6 | use Flynt\Utils\TimberDynamicResize; |
||||
| 7 | use acf_field_message; |
||||
|
0 ignored issues
–
show
|
|||||
| 8 | |||||
| 9 | add_action('acf/init', function () { |
||||
| 10 | global $timberDynamicResize; |
||||
| 11 | $timberDynamicResize = new TimberDynamicResize(); |
||||
| 12 | }); |
||||
| 13 | |||||
| 14 | Options::addGlobal('TimberDynamicResize', [ |
||||
| 15 | [ |
||||
| 16 | 'label' => 'Dynamic Image Generation', |
||||
| 17 | 'name' => 'dynamicImageGeneration', |
||||
| 18 | 'type' => 'true_false', |
||||
| 19 | 'default_value' => 0, |
||||
| 20 | 'ui' => true, |
||||
| 21 | 'instructions' => 'Generate images on-the-fly, when requested, not during initial render.', |
||||
| 22 | ], |
||||
| 23 | [ |
||||
| 24 | 'label' => 'Relative Upload Path', |
||||
| 25 | 'name' => 'relativeUploadPath', |
||||
| 26 | 'type' => 'text', |
||||
| 27 | 'instructions' => 'If Timber Dynamic Resize cannot resolve the path to images correctly, set the relative upload path manually.', |
||||
| 28 | 'conditional_logic' => [ |
||||
| 29 | [ |
||||
| 30 | [ |
||||
| 31 | 'fieldPath' => 'dynamicImageGeneration', |
||||
| 32 | 'operator' => '==', |
||||
| 33 | 'value' => '1' |
||||
| 34 | ] |
||||
| 35 | ] |
||||
| 36 | ] |
||||
| 37 | ], |
||||
| 38 | [ |
||||
| 39 | 'label' => 'WebP Support', |
||||
| 40 | 'name' => 'webpSupport', |
||||
| 41 | 'type' => 'true_false', |
||||
| 42 | 'default_value' => 0, |
||||
| 43 | 'ui' => true, |
||||
| 44 | 'instructions' => 'Generate additional .webp images. Changing this will delete the "uploads/resize" folder.', |
||||
| 45 | ], |
||||
| 46 | ]); |
||||
| 47 | |||||
| 48 | add_filter( |
||||
| 49 | 'acf/load_field/key=field_global_TimberDynamicResize_relativeUploadPath', |
||||
| 50 | function ($field) { |
||||
| 51 | $field['placeholder'] = TimberDynamicResize::getDefaultRelativeUploadDir(); |
||||
| 52 | return $field; |
||||
| 53 | } |
||||
| 54 | ); |
||||
| 55 | |||||
| 56 | add_filter( |
||||
| 57 | 'acf/load_field/key=field_global_TimberDynamicResize_webpSupport', |
||||
| 58 | function ($field) { |
||||
| 59 | if (!function_exists('imagewebp')) { |
||||
| 60 | $messageField = new acf_field_message(); |
||||
| 61 | $field = array_merge($messageField->defaults, $field); |
||||
| 62 | $field['type'] = 'message'; |
||||
| 63 | $field['instructions'] = 'Your PHP Version does not support WebP generation. The function `imagewebp` does not exist.'; |
||||
| 64 | } |
||||
| 65 | return $field; |
||||
| 66 | } |
||||
| 67 | ); |
||||
| 68 | |||||
| 69 | add_filter( |
||||
| 70 | 'acf/load_value/key=field_global_TimberDynamicResize_webpSupport', |
||||
| 71 | function ($value) { |
||||
| 72 | return function_exists('imagewebp') ? $value : '0'; |
||||
| 73 | } |
||||
| 74 | ); |
||||
| 75 | |||||
| 76 | add_action( |
||||
| 77 | 'update_option_options_global_TimberDynamicResize_dynamicImageGeneration', |
||||
| 78 | function ($oldValue, $value) { |
||||
| 79 | global $timberDynamicResize; |
||||
| 80 | $timberDynamicResize->toggleDynamic($value === '1'); |
||||
| 81 | }, |
||||
| 82 | 10, |
||||
| 83 | 2 |
||||
| 84 | ); |
||||
| 85 | |||||
| 86 | add_action( |
||||
| 87 | 'update_option_options_global_TimberDynamicResize_webpSupport', |
||||
| 88 | function ($oldValue, $value) { |
||||
| 89 | global $timberDynamicResize; |
||||
| 90 | $timberDynamicResize->toggleWebp($value === '1'); |
||||
| 91 | }, |
||||
| 92 | 10, |
||||
| 93 | 2 |
||||
| 94 | ); |
||||
| 95 | |||||
| 96 | add_action( |
||||
| 97 | 'update_option_options_global_TimberDynamicResize_relativeUploadPath', |
||||
| 98 | function ($oldValue, $value) { |
||||
| 99 | global $timberDynamicResize; |
||||
| 100 | $timberDynamicResize->changeRelativeUploadPath($value); |
||||
| 101 | }, |
||||
| 102 | 10, |
||||
| 103 | 2 |
||||
| 104 | ); |
||||
| 105 | |||||
| 106 | # WPML REWRITE FIX |
||||
| 107 | add_filter('mod_rewrite_rules', function ($rules) { |
||||
| 108 | $homeRoot = parse_url(home_url()); |
||||
| 109 | if (isset($homeRoot['path'])) { |
||||
| 110 | $homeRoot = trailingslashit($homeRoot['path']); |
||||
| 111 | } else { |
||||
| 112 | $homeRoot = '/'; |
||||
| 113 | } |
||||
| 114 | |||||
| 115 | $wpmlRoot = parse_url(get_option('home')); |
||||
|
0 ignored issues
–
show
It seems like
get_option('home') can also be of type false; however, parameter $url of parse_url() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 116 | if (isset($wpmlRoot['path'])) { |
||||
| 117 | $wpmlRoot = trailingslashit($wpmlRoot['path']); |
||||
| 118 | } else { |
||||
| 119 | $wpmlRoot = '/'; |
||||
| 120 | } |
||||
| 121 | |||||
| 122 | $rules = str_replace("RewriteBase $homeRoot", "RewriteBase $wpmlRoot", $rules); |
||||
| 123 | $rules = str_replace("RewriteRule . $homeRoot", "RewriteRule . $wpmlRoot", $rules); |
||||
| 124 | |||||
| 125 | return $rules; |
||||
| 126 | }); |
||||
| 127 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths