1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class Jetpack_Sync_Module_Import extends Jetpack_Sync_Module { |
4
|
|
|
|
5
|
|
|
private $import_end = false; |
6
|
|
|
|
7
|
|
|
public function name() { |
8
|
|
|
return 'import'; |
9
|
|
|
} |
10
|
|
|
|
11
|
|
|
public function init_listeners( $callable ) { |
12
|
|
|
add_action( 'export_wp', $callable ); |
13
|
|
|
add_action( 'jetpack_sync_import_end', $callable, 10, 2 ); |
14
|
|
|
|
15
|
|
|
// Movable type, RSS, Livejournal |
16
|
|
|
add_action( 'import_done', array( $this, 'sync_import_done' ) ); |
17
|
|
|
|
18
|
|
|
// WordPress, Blogger, Livejournal, woo tax rate |
19
|
|
|
add_action( 'import_end', array( $this, 'sync_import_end' ) ); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function set_defaults() { |
23
|
|
|
$this->import_end = false; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function sync_import_done( $importer ) { |
27
|
|
|
// We already ran an send the import |
28
|
|
|
if ( $this->import_end ) { |
29
|
|
|
return; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
$importer_name = $this->get_importer_name( $importer ); |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Sync Event that tells that the import is finished |
36
|
|
|
* |
37
|
|
|
* @since 5.0.0 |
38
|
|
|
* |
39
|
|
|
* $param string $importer |
40
|
|
|
*/ |
41
|
|
|
do_action( 'jetpack_sync_import_end', $importer, $importer_name ); |
42
|
|
|
$this->import_end = true; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function sync_import_end() { |
46
|
|
|
// We already ran an send the import |
47
|
|
|
if ( $this->import_end ) { |
48
|
|
|
return; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$this->import_end = true; |
52
|
|
|
$importer = 'unknown'; |
53
|
|
|
$backtrace = wp_debug_backtrace_summary( null, 0, false ); |
54
|
|
|
if ( $this->is_importer( $backtrace, 'Blogger_Importer' ) ) { |
55
|
|
|
$importer = 'blogger'; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
if ( 'unknown' === $importer && $this->is_importer( $backtrace, 'WC_Tax_Rate_Importer' ) ) { |
59
|
|
|
$importer = 'woo-tax-rate'; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
if ( 'unknown' === $importer && $this->is_importer( $backtrace, 'WP_Import' ) ) { |
63
|
|
|
$importer = 'wordpress'; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$importer_name = $this->get_importer_name( $importer ); |
67
|
|
|
|
68
|
|
|
/** This filter is already documented in sync/class.jetpack-sync-module-posts.php */ |
69
|
|
|
do_action( 'jetpack_sync_import_end', $importer, $importer_name ); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
private function get_importer_name( $importer ) { |
73
|
|
|
$importers = get_importers(); |
74
|
|
|
return isset( $importers[ $importer ] ) ? $importers[ $importer ][0] : 'Unknown Importer'; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
private function is_importer( $backtrace, $class_name ) { |
78
|
|
|
foreach ( $backtrace as $trace ) { |
79
|
|
|
if ( strpos( $trace, $class_name ) !== false ) { |
80
|
|
|
return true; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return false; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|