PluginProbe
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization / 4.2.13
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization v4.2.13
4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 2.5.5 2.5.6 2.5.7 3.0.0 3.0.1 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.11.0 3.11.1 3.11.2 3.11.3 3.12.0 3.12.1 All 134 releases
optimole-wp / inc / compatibilities / shortcode_ultimate.php

shortcode_ultimate.php in Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization 4.2.13, at inc/compatibilities/shortcode_ultimate.php

82 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use Optimole\Sdk\Resource\ImageProperty\ResizeTypeProperty;
4 use Optimole\Sdk\ValueObject\Position;
5
6 /**
7 * Class Optml_shortcode_ultimate.
8 *
9 * @reason Shortcode Ultimate uses a strange image resizing feature
10 * which has by default the hard cropping on. As we are following the WordPress
11 * image size defaults, we need to change the default cropping
12 * for shortcode's output.
13 */
14 class Optml_shortcode_ultimate extends Optml_compatibility {
15 /**
16 * Tags where we subscribe the compatibility.
17 *
18 * @var array Allowed tags.
19 */
20 private $allowed_tags = [
21 'su_slider' => true,
22 'su_carousel' => true,
23 'su_custom_gallery' => true,
24 ];
25
26 /**
27 * Should we load the integration logic.
28 *
29 * @return bool Should we load.
30 */
31 public function should_load() {
32 include_once ABSPATH . 'wp-admin/includes/plugin.php';
33
34 return is_plugin_active( 'shortcodes-ultimate/shortcodes-ultimate.php' );
35 }
36
37 /**
38 * Register integration details.
39 */
40 public function register() {
41 add_filter( 'do_shortcode_tag', [ $this, 'alter_shortcode_output' ], 10, 3 );
42 }
43
44 /**
45 * Alter shortcode output by replacing the image urls.
46 *
47 * @param string $output Previous shortcode output.
48 * @param string $tag Shortcode tag.
49 * @param array $attr Shortcode attrs.
50 *
51 * @return mixed New output.
52 */
53 public function alter_shortcode_output( $output, $tag, $attr ) {
54
55 if ( ! isset( $this->allowed_tags[ $tag ] ) ) {
56 return $output;
57 }
58
59 add_filter( 'optml_default_crop', [ $this, 'change_default_crop' ] );
60 add_filter( 'optml_parse_resize_from_tag', [ $this, 'change_default_crop' ] );
61
62 $output = Optml_Main::instance()->manager->process_images_from_content( $output );
63
64 remove_filter( 'optml_default_crop', [ $this, 'change_default_crop' ] );
65 remove_filter( 'optml_parse_resize_from_tag', [ $this, 'change_default_crop' ] );
66
67 return $output;
68 }
69
70 /**
71 * Change default crop.
72 *
73 * @return array New default cropping.
74 */
75 public function change_default_crop() {
76 return [
77 'type' => ResizeTypeProperty::FILL,
78 'gravity' => Position::CENTER,
79 ];
80 }
81 }
82