PluginProbe
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization / 3.10.0
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization v3.10.0
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 3.10.0, at inc/compatibilities/shortcode_ultimate.php

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