PluginProbe
WP-Stateless – Google Cloud Storage / 3.0
WP-Stateless – Google Cloud Storage v3.0
4.4.3 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.3.0 2.3.1 2.3.2 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 All 62 releases
wp-stateless / lib / classes / compatibility / polylang-pro.php

polylang-pro.php in WP-Stateless – Google Cloud Storage 3.0, at lib/classes/compatibility/polylang-pro.php

58 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Theme Name: Polylang Pro
4 * Plugin URI: https://polylang.pro
5 *
6 * Compatibility Description: Ensures compatibility with Polylang Pro.
7 * https://github.com/wpCloud/wp-stateless/issues/378
8 *
9 */
10
11 namespace wpCloud\StatelessMedia {
12
13 if( !class_exists( 'wpCloud\StatelessMedia\Polylang' ) ) {
14
15 class Polylang extends ICompatibility {
16 protected $id = 'polylang-pro';
17 protected $title = 'Polylang Pro';
18 protected $constant = 'WP_STATELESS_COMPATIBILITY_POLYLANG_PRO';
19 protected $description = 'Ensures compatibility with Polylang Pro.';
20 protected $plugin_file = [ 'polylang-pro/polylang.php' ];
21
22 /**
23 * @param $sm
24 */
25 public function module_init( $sm ) {
26 add_action( 'pll_translate_media', array( $this, 'pll_translate_media' ), 10, 3 );
27 }
28
29 /**
30 * @param $post_id
31 * @param $tr_id
32 * @param $lang_slug
33 */
34 public function pll_translate_media( $post_id, $tr_id, $lang_slug ) {
35 // We need to delay the metadata update until the metadata is fully generated.
36 add_filter( 'wp_stateless_media_synced', function ( $metadata, $attachment_id, $force, $args ) use ( $post_id, $tr_id, $lang_slug ) {
37 if( $attachment_id == $post_id ) {
38 $meta = get_post_meta( $tr_id, '_wp_attachment_metadata', true );
39 if( !empty( $meta[ 'sizes' ] ) ) {
40 // with Polylang Pro 2.6 the sizes of original image gets missing.
41 update_post_meta( $attachment_id, '_wp_attachment_metadata', wp_slash( $meta ) );
42 return $meta;
43 } else if( !empty( $metadata[ 'sizes' ] ) ) {
44 // But user reported that metadata gets missing on duplicate.
45 update_post_meta( $tr_id, '_wp_attachment_metadata', wp_slash( $metadata ) );
46 return $metadata;
47 }
48 }
49 return $metadata;
50 }, 10, 4 );
51 }
52
53 }
54
55 }
56
57 }
58