1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
<?php
namespace SIW\Compatibility;
use SIW\i18n;
class WPML {
public static function init() {
$self = new self();
add_action( 'widgets_init', [ $self, 'unregister_wpml_widget'], 99 );
add_action( 'admin_head', [ $self, 'remove_wpml_meta_box'] );
add_filter( 'wpml_ls_directories_to_scan', [ $self, 'add_language_switcher_templates_dir'] );
add_action( 'delete_attachment', [ $self, 'delete_original_attachment' ] );
}
public function unregister_wpml_widget() {
unregister_widget( 'WPML_LS_Widget' );
}
public function remove_wpml_meta_box() {
$screen = get_current_screen();
remove_meta_box( 'icl_div_config', $screen->post_type, 'normal' );
}
public function add_language_switcher_templates_dir( array $dirs ) {
$dirs[] = SIW_TEMPLATES_DIR .'/wpml/language-switchers';
return $dirs;
}
public function delete_original_attachment( int $post_id ) {
if ( i18n::is_default_language() ) {
return;
}
$original_post_id = apply_filters( 'wpml_object_id', $post_id, 'attachment', false, i18n::get_default_language() );
if ( null !== $original_post_id && $post_id !== $original_post_id ) {
wp_delete_attachment( $original_post_id );
}
}
}