This repository has been archived by the owner on Nov 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwpml2mlp.php
168 lines (119 loc) · 4.6 KB
/
wpml2mlp.php
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
/**
* Plugin Name: WPML to MultilingualPress
* Plugin URI: https://github.com/inpsyde/wpml2mlp
* Description: Get data from WPML export and immediately import in Multisite and MultilingualPress environment.
* Author: Inpsyde GmbH
* Author URI: http://inpsyde.com
* Version: 2.0.0
*/
defined( 'ABSPATH' ) or die( 'No direct access!' );
/**
* Searches the environment for evidence of existing WP-CLI
*
* @return bool
*/
function w2m_is_wp_cli() {
return
defined( 'WP_CLI' )
&& WP_CLI
&& class_exists( 'WP_CLI_Command' );
}
/**
* Note: this is a temporary bootstrap for the importer module
* coming with version 2.0.0
*
* It will be refactored later
*/
add_action( 'wp_loaded', function() {
if ( ! w2m_is_wp_cli() )
return;
$autoload = __DIR__ . '/vendor/autoload.php';
if ( file_exists( $autoload ) )
require_once $autoload;
WP_CLI::add_command( 'w2m', 'W2M\Cli\WpCliW2MCommand' );
} );
# Load plugin
add_action( 'admin_init', 'wpml2mlp_admin_interface' );
function wpml2mlp_admin_interface() {
wpml2mlp_validate_activation();
require plugin_dir_path( __FILE__ ) . 'inc/Export/AdminPage/Page.php';
require plugin_dir_path( __FILE__ ) . 'inc/Export/AdminPage/Languages_Table.php';
new W2M\Export\AdminPage\export_admin_page();
}
# Load plugin
add_action( 'wp_ajax_run_export', 'wpml2mlp_prerequisites' );
#add_action( 'admin_init', 'wpml2mlp_prerequisites' );
/**
* Reqiure needed files and heck the prerequisites to chose the way of use
*
* Set the textdomain for this Plugin and a error code for the prerequisites
* and run the prerequisites. If no prerequisite lets wp die.
*
* @wp-hook plugins_loaded
*
* @since 0.0.1.2
*
*/
function wpml2mlp_prerequisites() {
if( is_multisite() )
return;
set_time_limit( 0 );
$class_mappings = array(
'Wpml2mlp_Categorie_Creator' => 'Wpml2mlp_Categorie_Creator.php',
'Wpml2mlp_Helper' => 'Wpml2mlp_Helper.php',
'Wpml2mlp_Importer' => 'Wpml2mlp_Importer.php',
'Wpml2mlp_Language_Holder' => 'Wpml2mlp_Language_Holder.php',
'Wpml2mlp_Post_Creator' => 'Wpml2mlp_Post_Creator.php',
'Wpml2mlp_Prerequisites' => 'Wpml2mlp_Prerequisites.php',
'Wpml2mlp_Site_Creator' => 'Wpml2mlp_Site_Creator.php',
'Wpml2mlp_Translation_Item' => 'Wpml2mlp_Translation_Item.php',
'Wpml2mlp_Translations' => 'Wpml2mlp_Translations.php',
'Wpml2mlp_Translations_Builder' => 'Wpml2mlp_Translations_Builder.php',
'Wpml2mlp_Xliff_Creator' => 'Wpml2mlp_Xliff_Creator.php',
'Wpml2mlp_Xliff_Cache' => 'Wpml2mlp_Wxr_Cache.php',
'Wpml2mlp_ZipCreator' => 'Wpml2mlp_ZipCreator.php',
'Wpml2mlp_Xliff_Export' => 'Wpml2mlp_Xliff_Export.php',
'Wpml2mlp_Wxr_Export' => 'Wpml2mlp_Wxr_Export.php',
'Wpml2mlp_Xliff_Extractor' => 'Wpml2mlp_Xliff_Extractor.php'
);
foreach ( $class_mappings as $key => $value ) {
if ( ! class_exists( $key ) ) {
require plugin_dir_path( __FILE__ ) . 'inc/' . $value;
}
}
$autoload = __DIR__ . '/vendor/autoload.php';
if ( file_exists( $autoload ) )
require_once $autoload;
$txt_domain = 'wpml2mlp';
$error_code = $txt_domain . '_prerequisites';
$prerequisites = Wpml2mlp_Prerequisites::check_prerequisites( $txt_domain, $error_code );
if ( $prerequisites->errors ) {
deactivate_plugins( plugin_basename( __FILE__ ) );
wp_die( $prerequisites->errors[ $error_code ][ 0 ] );
}
}
/**
* validate Plugin activation
* Activate Plugin only if wpml active o
*/
function wpml2mlp_validate_activation() {
require plugin_dir_path( __FILE__ ) . 'inc/Wpml2mlp_Prerequisites.php';
$is_wpmlplugin_active = Wpml2mlp_Prerequisites::is_wpmlplugin_active();
$is_mlp_plugin_active = Wpml2mlp_Prerequisites::is_mlp_plugin_active();
$txt_domain = 'wpml2mlp';
$error_code = $txt_domain . '_prerequisites';
if( empty( $is_wpmlplugin_active ) || empty( $is_mlp_plugin_active ) ){
if( empty( $is_wpmlplugin_active ) && ! is_multisite() ) {
$msg = sprintf( __( 'Sorry you have to activate the plugin wpml!<br /><br />Back to <a href="%2$s">WordPress admin</a>.', $txt_domain ), 1, admin_url() );
}elseif( empty( $is_mlp_plugin_active ) && is_multisite() ){
$msg = sprintf( __( 'Sorry you have to install and activate the plugin <a href="%2$s">MultilingualPress</a>! .<br /><br />Back to <a href="%3$s">WordPress admin</a>.', $txt_domain ), 1, 'https://wordpress.org/plugins/multilingual-press/', admin_url() );
}
if( ! empty( $msg ) ) {
$error = new WP_Error();
$error->add( $error_code, $msg );
deactivate_plugins( plugin_basename( __FILE__ ) );
wp_die( $error->get_error_message() );
}
}
}