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