PluginProbe ʕ •ᴥ•ʔ
Gallery : FooGallery / 3.1.36
Gallery : FooGallery v3.1.36
3.3.0 3.1.31 3.1.32 3.1.34 3.1.36 3.2.0 3.2.6 trunk 1.10.3 2.0.24 2.1.34 2.2.44 2.3.3 2.4.32 3.0.6 3.1.11 3.1.12 3.1.13 3.1.20 3.1.25 3.1.26 3.1.26.1 3.1.26.2
foogallery / includes / compatibility / class-polylang-compatibility.php
foogallery / includes / compatibility Last commit date
elementor 2 months ago class-autoptimize-compatibility.php 2 months ago class-elasticpress-compatibility.php 2 months ago class-elementor-compatibility.php 2 months ago class-foobox-compatibility.php 2 months ago class-foogallery-compatibility.php 2 months ago class-foovideo-compatibility.php 2 months ago class-jetpack-compatibility.php 2 months ago class-polylang-compatibility.php 2 months ago class-responsive-lightbox-dfactory-compatibility.php 2 months ago class-wpoptimize-compatibility.php 2 months ago class-wprocket-compatibility.php 2 months ago view-foovideo-offer.php 2 months ago
class-polylang-compatibility.php
147 lines
1 <?php
2 /**
3 * Polylang Compatibility Class
4 *
5 * Credit : @Chrystl from wordpress.org - https://wordpress.org/support/topic/polylang-conflict-with-foo-gallery
6 * Date: 30/08/2015
7 *
8 * @package FooGallery
9 */
10
11 if ( ! class_exists( 'FooGallery_Polylang_Compatibility' ) ) {
12
13 /**
14 * Adds FooGallery compatibility behavior for Polylang.
15 */
16 class FooGallery_Polylang_Compatibility {
17
18 /**
19 * FooGallery_Polylang_Compatibility constructor.
20 */
21 public function __construct() {
22
23 if ( class_exists( 'Polylang' ) ) {
24
25 add_filter( 'pll_get_post_types', array( $this, 'add_foogallery_cpt' ), 10, 2 );
26 add_filter( 'pll_copy_post_metas', array( $this, 'ignore_foogallery_meta' ), 10, 2 );
27 add_filter( 'foogallery_attachment_get_posts_args', array( $this, 'include_all_languages_for_gallery_attachments' ), 10, 2 );
28
29 // Whitelist the Polylang metabox.
30 add_filter( 'foogallery_metabox_sanity_foogallery', array( $this, 'add_pll_metaboxes' ) );
31
32 add_action( 'admin_notices', array( $this, 'admin_notice' ) );
33 }
34 }
35
36
37 /**
38 * Adds Foogallery post type to Polylang settings as 'public' is set to false
39 *
40 * @param array $post_types Post types registered with Polylang.
41 * @param bool $settings Whether the list is for Polylang settings.
42 *
43 * @return mixed
44 */
45 public function add_foogallery_cpt( $post_types, $settings ) {
46 if ( $settings ) {
47 $post_types['foogallery'] = 'foogallery';
48 }
49
50 return $post_types;
51 }
52
53 /**
54 * Adds/whitelists polylang metabox 'ml_box' as Foogallery blocks it by default
55 *
56 * @param array $metabox_ids Allowed metabox IDs.
57 *
58 * @return array
59 */
60 public function add_pll_metaboxes( $metabox_ids ) {
61 $metabox_ids[] = 'ml_box';
62 return $metabox_ids;
63 }
64
65 /**
66 * Unsets the copy and synchronization of the fooggallery post meta.
67 * A better solution will be to rewritte a copy function to get the translation
68 *
69 * @param array $metas Meta keys Polylang may copy or synchronize.
70 * @param bool $sync Whether Polylang is synchronizing metadata.
71 *
72 * @return mixed
73 */
74 public function ignore_foogallery_meta( $metas, $sync ) {
75
76 $key = array_search( FOOGALLERY_META_SETTINGS, $metas, true );
77 if ( false !== $key ) {
78 unset( $metas[ $key ] );
79 }
80
81 $key = array_search( FOOGALLERY_META_ATTACHMENTS, $metas, true );
82 if ( false !== $key ) {
83 unset( $metas[ $key ] );
84 }
85
86 $key = array_search( FOOGALLERY_META_CUSTOM_CSS, $metas, true );
87 if ( false !== $key ) {
88 unset( $metas[ $key ] );
89 }
90
91 $key = array_search( FOOGALLERY_META_TEMPLATE, $metas, true );
92 if ( false !== $key ) {
93 unset( $metas[ $key ] );
94 }
95
96 $key = array_search( FOOGALLERY_META_SORT, $metas, true );
97 if ( false !== $key ) {
98 unset( $metas[ $key ] );
99 }
100
101 return $metas;
102 }
103
104 /**
105 * Ensure explicit gallery attachment queries are not filtered to the current Polylang language.
106 *
107 * When Polylang's Media module is enabled, attachment queries are filtered by the current language.
108 * FooGallery stores explicit attachment IDs on the gallery, so those IDs should be loaded regardless
109 * of the language currently being rendered.
110 *
111 * @param array $query_args Attachment query args.
112 * @param FooGallery $foogallery Gallery being rendered.
113 *
114 * @return array
115 */
116 public function include_all_languages_for_gallery_attachments( $query_args, $foogallery ) {
117 if ( isset( $query_args['post__in'] ) && ! empty( $query_args['post__in'] ) ) {
118 $query_args['lang'] = 'all';
119 }
120
121 return $query_args;
122 }
123
124 /**
125 * Add an admin notice to FooGallery pages when Polylang setting media_support is set
126 */
127 public function admin_notice() {
128 if ( FOOGALLERY_CPT_GALLERY === foo_current_screen_post_type() ) {
129
130 $options = get_option( 'polylang' );
131
132 if ( is_array( $options ) && array_key_exists( 'media_support', $options ) && 1 === intval( $options['media_support'] ) ) {
133 ?>
134 <div class="notice error">
135 <p>
136 <strong><?php esc_html_e( 'FooGallery + Polylang Alert : ', 'foogallery' ); ?></strong>
137 <?php esc_html_e( 'We noticed that you have Polylang installed and you have chosen to activate languages and translations for media.', 'foogallery' ); ?><br />
138 <?php esc_html_e( 'This may cause empty galleries on translated pages! To disable this feature, please visit Languages -> Settings.', 'foogallery' ); ?>
139 </p>
140 </div>
141 <?php
142 }
143 }
144 }
145 }
146 }
147