elementor
7 months ago
class-autoptimize-compatibility.php
7 months ago
class-elasticpress-compatibility.php
7 months ago
class-elementor-compatibility.php
7 months ago
class-foobox-compatibility.php
7 months ago
class-foogallery-compatibility.php
7 months ago
class-foovideo-compatibility.php
7 months ago
class-jetpack-compatibility.php
7 months ago
class-polylang-compatibility.php
7 months ago
class-responsive-lightbox-dfactory-compatibility.php
7 months ago
class-wpoptimize-compatibility.php
7 months ago
class-wprocket-compatibility.php
7 months ago
view-foovideo-offer.php
7 months ago
class-polylang-compatibility.php
105 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Polylang Compatibility Class |
| 4 | * Credit : @Chrystl from wordpress.org - https://wordpress.org/support/topic/polylang-conflict-with-foo-gallery |
| 5 | * Date: 30/08/2015 |
| 6 | */ |
| 7 | if ( ! class_exists( 'FooGallery_Polylang_Compatibility' ) ) { |
| 8 | |
| 9 | class FooGallery_Polylang_Compatibility { |
| 10 | |
| 11 | function __construct() { |
| 12 | |
| 13 | if ( class_exists( 'Polylang' ) ) { |
| 14 | |
| 15 | add_filter( 'pll_get_post_types', array( $this, 'add_foogallery_cpt' ), 10, 2 ); |
| 16 | add_filter( 'pll_copy_post_metas', array( $this, 'ignore_foogallery_meta' ), 10, 2 ); |
| 17 | |
| 18 | //whitelist the Polylang metabox |
| 19 | add_filter( 'foogallery_metabox_sanity_foogallery', array( $this, 'add_pll_metaboxes' ) ); |
| 20 | |
| 21 | add_action( 'admin_notices', array( $this, 'admin_notice' ) ); |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | |
| 26 | /** |
| 27 | * Adds Foogallery post type to Polylang settings as 'public' is set to false |
| 28 | * |
| 29 | * @param $post_types |
| 30 | * @param $settings |
| 31 | * |
| 32 | * @return mixed |
| 33 | */ |
| 34 | function add_foogallery_cpt( $post_types, $settings ) { |
| 35 | if ( $settings ) { |
| 36 | $post_types['foogallery'] = 'foogallery'; |
| 37 | } |
| 38 | |
| 39 | return $post_types; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Adds/whitelists polylang metabox 'ml_box' as Foogallery blocks it by default |
| 44 | * |
| 45 | * @param $metabox_ids |
| 46 | * |
| 47 | * @return array |
| 48 | */ |
| 49 | function add_pll_metaboxes ($metabox_ids) { |
| 50 | $metabox_ids[] = 'ml_box'; |
| 51 | return $metabox_ids; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Unsets the copy and synchronization of the fooggallery post meta. |
| 56 | * A better solution will be to rewritte a copy function to get the translation |
| 57 | * |
| 58 | * @param $metas |
| 59 | * @param $sync |
| 60 | * |
| 61 | * @return mixed |
| 62 | */ |
| 63 | function ignore_foogallery_meta($metas, $sync) { |
| 64 | |
| 65 | $key = array_search( FOOGALLERY_META_SETTINGS, $metas ); |
| 66 | if ( $key ) unset( $metas[$key] ); |
| 67 | |
| 68 | $key = array_search( FOOGALLERY_META_ATTACHMENTS, $metas ); |
| 69 | if ( $key ) unset( $metas[$key] ); |
| 70 | |
| 71 | $key = array_search( FOOGALLERY_META_CUSTOM_CSS, $metas ); |
| 72 | if ( $key ) unset( $metas[$key] ); |
| 73 | |
| 74 | $key = array_search( FOOGALLERY_META_TEMPLATE, $metas ); |
| 75 | if ( $key ) unset( $metas[$key] ); |
| 76 | |
| 77 | $key = array_search( FOOGALLERY_META_SORT, $metas ); |
| 78 | if ( $key ) unset( $metas[$key] ); |
| 79 | |
| 80 | return $metas; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Add an admin notice to FooGallery pages when Polylang setting media_support is set |
| 85 | */ |
| 86 | function admin_notice() { |
| 87 | if ( FOOGALLERY_CPT_GALLERY === foo_current_screen_post_type() ) { |
| 88 | |
| 89 | $options = get_option('polylang'); |
| 90 | |
| 91 | if ( array_key_exists( 'media_support', $options ) && 1 === $options['media_support'] ) { |
| 92 | ?> |
| 93 | <div class="notice error"> |
| 94 | <p> |
| 95 | <strong><?php esc_html_e( 'FooGallery + Polylang Alert : ', 'foogallery' ); ?></strong> |
| 96 | <?php esc_html_e( 'We noticed that you have Polylang installed and you have chosen to activate languages and translations for media.', 'foogallery' ); ?><br /> |
| 97 | <?php esc_html_e( 'This may cause empty galleries on translated pages! To disable this feature, please visit Languages -> Settings.', 'foogallery' ); ?> |
| 98 | </p> |
| 99 | </div> |
| 100 | <?php |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | } |