class-aawp-ad.php
1 year ago
class-aawp.php
1 year ago
class-admin-compatibility.php
1 year ago
class-capability-manager.php
1 year ago
class-compatibility.php
1 year ago
class-inline-js.php
1 year ago
class-peepso-ad.php
1 year ago
class-peepso.php
1 year ago
class-admin-compatibility.php
92 lines
| 1 | <?php |
| 2 | /** |
| 3 | * This class is responsible for fixing compatibility issues in admin area. |
| 4 | * |
| 5 | * @package AdvancedAds |
| 6 | * @author Advanced Ads <info@wpadvancedads.com> |
| 7 | * @since 1.48.2 |
| 8 | */ |
| 9 | |
| 10 | namespace AdvancedAds\Compatibility; |
| 11 | |
| 12 | use AdvancedAds\Utilities\Conditional; |
| 13 | use AdvancedAds\Framework\Interfaces\Integration_Interface; |
| 14 | |
| 15 | defined( 'ABSPATH' ) || exit; |
| 16 | |
| 17 | /** |
| 18 | * Admin Compatibility. |
| 19 | */ |
| 20 | class Admin_Compatibility implements Integration_Interface { |
| 21 | |
| 22 | /** |
| 23 | * Hook into WordPress. |
| 24 | * |
| 25 | * @return void |
| 26 | */ |
| 27 | public function hooks(): void { |
| 28 | add_action( 'admin_enqueue_scripts', [ $this, 'dequeue_jnews_style' ], 100 ); |
| 29 | add_action( 'quads_meta_box_post_types', [ $this, 'fix_wpquadspro_issue' ], 11 ); |
| 30 | add_filter( 'wpml_admin_language_switcher_active_languages', [ $this, 'wpml_language_switcher' ] ); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Fixes a WP QUADS PRO compatibility issue |
| 35 | * they inject their ad optimization meta box into our ad page, even though it is not a public post type |
| 36 | * using they filter, we remove AA from the list of post types they inject this box into |
| 37 | * |
| 38 | * @param array $allowed_post_types Array of allowed post types. |
| 39 | * |
| 40 | * @return array |
| 41 | */ |
| 42 | public function fix_wpquadspro_issue( $allowed_post_types ): array { |
| 43 | unset( $allowed_post_types['advanced_ads'] ); |
| 44 | |
| 45 | return $allowed_post_types; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Dequeue J-NEWS styles to prevent layout issues. |
| 50 | * |
| 51 | * @return void |
| 52 | */ |
| 53 | public function dequeue_jnews_style(): void { |
| 54 | if ( ! Conditional::is_screen_advanced_ads() || ! defined( 'JNEWS_THEME_URL' ) ) { |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | wp_dequeue_style( 'jnews-admin' ); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Show only all languages in language switcher on Advanced Ads pages if ads and groups are translated |
| 63 | * |
| 64 | * @param array $active_languages languages that can be used in language switcher. |
| 65 | * |
| 66 | * @return array |
| 67 | */ |
| 68 | public function wpml_language_switcher( $active_languages ): array { |
| 69 | global $sitepress; |
| 70 | |
| 71 | $screen = get_current_screen(); |
| 72 | |
| 73 | // Are we on group edit page and ad group translations are disabled. |
| 74 | if ( isset( $screen->id ) && 'advanced-ads_page_advanced-ads-groups' === $screen->id ) { |
| 75 | $translatable_taxonomies = $sitepress->get_translatable_taxonomies(); |
| 76 | if ( ! is_array( $translatable_taxonomies ) || ! in_array( 'advanced_ads_groups', $translatable_taxonomies, true ) ) { |
| 77 | return []; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | // If ad post type is translatable. |
| 82 | if ( isset( $screen->id ) && in_array( $screen->id, [ 'edit-advanced_ads', 'advanced_ads' ], true ) ) { |
| 83 | $translatable_documents = $sitepress->get_translatable_documents(); |
| 84 | if ( empty( $translatable_documents['advanced_ads'] ) ) { |
| 85 | return []; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | return $active_languages; |
| 90 | } |
| 91 | } |
| 92 |