wpml-package-translation-ui.class.php
2.58 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
class WPML_Package_Translation_UI {
var $load_priority = 101;
private $menu_root = '';
const MENU_SLUG = 'wpml-package-management';
public function __construct() {
add_action( 'wpml_loaded', array( $this, 'loaded' ), $this->load_priority );
}
public function loaded() {
if ( $this->passed_dependencies() ) {
$this->set_admin_hooks();
do_action( 'WPML_PT_HTML' );
}
}
private function passed_dependencies() {
return defined( 'ICL_SITEPRESS_VERSION' )
&& defined( 'WPML_ST_VERSION' )
&& defined( 'WPML_TM_VERSION' );
}
private function set_admin_hooks() {
if ( is_admin() ) {
add_action( 'wpml_admin_menu_configure', array( $this, 'menu' ) );
add_action( 'wpml_admin_menu_root_configured', array( $this, 'main_menu_configured' ), 10, 2 );
add_action( 'admin_register_scripts', array( $this, 'admin_register_scripts' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
}
}
public function main_menu_configured( $menu_id, $root_slug ) {
if ( 'WPML' === $menu_id ) {
$this->menu_root = $root_slug;
}
}
/**
* @param string $menu_id
*/
public function menu( $menu_id ) {
if ( 'WPML' !== $menu_id || ! defined( 'ICL_PLUGIN_PATH' ) ) {
return;
}
/** @var SitePress|null $sitepress */
global $sitepress;
if ( ! isset( $sitepress ) || ( method_exists( $sitepress, 'get_setting' ) && ! $sitepress->get_setting( 'setup_complete' ) ) ) {
return;
}
global $sitepress_settings;
if ( ! isset( $sitepress_settings['existing_content_language_verified'] ) || ! $sitepress_settings['existing_content_language_verified'] ) {
return;
}
if ( current_user_can( 'wpml_manage_string_translation' ) ) {
$menu = array();
$menu['order'] = 1300;
$menu['page_title'] = __( 'Packages', 'wpml-string-translation' );
$menu['menu_title'] = __( 'Packages', 'wpml-string-translation' );
$menu['capability'] = 'wpml_manage_string_translation';
$menu['menu_slug'] = self::MENU_SLUG;
$menu['function'] = array(
'WPML_Package_Translation_HTML_Packages',
'package_translation_menu',
);
do_action( 'wpml_admin_menu_register_item', $menu );
$this->admin_register_scripts();
}
}
function admin_register_scripts() {
wp_register_script( 'wpml-package-trans-man-script', WPML_PACKAGE_TRANSLATION_URL . '/resources/js/wpml_package_management.js', array( 'jquery' ) );
}
function admin_enqueue_scripts( $hook ) {
if ( get_plugin_page_hookname( self::MENU_SLUG, $this->menu_root ) === $hook ) {
wp_enqueue_script( 'wpml-package-trans-man-script' );
}
}
}