1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class Jetpack_Unified_Importer_Module { |
4
|
|
|
static function is_import_screen() { |
5
|
|
|
global $pagenow; |
6
|
|
|
|
7
|
|
|
// $pagenow is probably enough for us |
8
|
|
|
// We may want additional "screen" info at some point, so putting here for ref |
9
|
|
|
// $screen = get_current_screen(); |
10
|
|
|
// error_log( print_r( $screen, 1 ) ); |
11
|
|
|
|
12
|
|
|
switch ( $pagenow ) { |
13
|
|
|
case 'import.php': |
14
|
|
|
return true; |
15
|
|
|
case 'admin.php': |
16
|
|
|
return isset( $_REQUEST['import'] ) && $_REQUEST['import']; |
17
|
|
|
} |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
static function import_ui() { |
21
|
|
|
if ( ! self::is_import_screen() ) { |
|
|
|
|
22
|
|
|
// Do nothing except on the import screen |
23
|
|
|
return; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Pre-hide the core UI so it doesn't jump around |
28
|
|
|
* |
29
|
|
|
* @TODO If you can find a better way to reference this markup, that'd be awesome. |
30
|
|
|
* This is fragile in that a core change to this markup would break our app. |
31
|
|
|
* See: |
32
|
|
|
* * https://github.com/WordPress/WordPress/blob/71cf332e6569f0ac2f263ce9b2168644942f5534/wp-admin/admin-header.php#L251 |
33
|
|
|
* * https://github.com/WordPress/WordPress/blob/71cf332e6569f0ac2f263ce9b2168644942f5534/wp-admin/import.php#L56-L60 |
34
|
|
|
* |
35
|
|
|
* The scripts can use the `parentElement` of `table.importers` which is probably less fragile. |
36
|
|
|
* (wouldn't a parent pseudoselector be nice! ;) ) |
37
|
|
|
*/ |
38
|
|
|
?><style>#wpbody-content .wrap { display: none; }</style><?php |
39
|
|
|
|
40
|
|
|
wp_enqueue_script( 'jetpack_import_ui', plugin_dir_url( __FILE__ ) . '/index.js', array( 'jquery' /* @TODO react n stuff */ ), JETPACK__VERSION, true ); |
41
|
|
|
|
42
|
|
|
// @TODO is `admin_notices` our best hook for our entry element? |
43
|
|
|
add_action( 'admin_notices', __CLASS__ . '::import_ui_entry_element' ); |
44
|
|
|
add_action( 'admin_footer', __CLASS__ . '::import_ui_ensure_core_ui_is_hidden_by_default' ); |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @TODO override help text? https://github.com/WordPress/WordPress/blob/e0e99fe82e652a9d16b603ec17b777395fb9783e/wp-admin/import.php#L20-L33 |
48
|
|
|
* See: |
49
|
|
|
* https://user-images.githubusercontent.com/1587282/53657998-a8811880-3c25-11e9-9a75-5e8f67b0d67d.png |
50
|
|
|
* ...for default look & feel |
51
|
|
|
*/ |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
static function import_ui_entry_element() { |
55
|
|
|
?> |
56
|
|
|
<div class="jetpack-unified-importer"> |
57
|
|
|
<h1>Oh hi, hullo, Unified Importer!!!!</h1> |
58
|
|
|
<p>So, this element (<code>.jetpack-unified-importer</code>) is our entry point for our script.</p> |
59
|
|
|
<hr /> |
60
|
|
|
<p> |
61
|
|
|
We can clone and mutate the core list (<code>table.importers</code>)<br /> |
62
|
|
|
...then append it to the bottom of our UI as desired |
63
|
|
|
</p> |
64
|
|
|
<hr /> |
65
|
|
|
<p>And we can have a button which toggles visibility of this & the "regular" UI</p> |
66
|
|
|
<p>e.g. <button class="jetpack-unified-importer__exit">Exit</button></p> |
67
|
|
|
<div style="width: 400px"> |
68
|
|
|
<marquee>For now, please enjoy this super-1337 throwback jQuery mockup ;P</marquee> |
69
|
|
|
</div> |
70
|
|
|
</div> |
71
|
|
|
<?php |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
static function import_ui_ensure_core_ui_is_hidden_by_default() { |
75
|
|
|
?> |
76
|
|
|
<script> |
77
|
|
|
try { |
78
|
|
|
document.querySelector( 'table.importers' ).parentElement.style.display = 'none'; |
79
|
|
|
} catch ( e ) { |
80
|
|
|
console.error( 'Jetpack Importer UI: Unable to locate importers table' ); |
81
|
|
|
} |
82
|
|
|
</script> |
83
|
|
|
<?php |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* This action fires in wp-admin when query argument `action=jetpack_import_ui` |
89
|
|
|
* @see https://developer.wordpress.org/reference/hooks/admin_action__requestaction/ |
90
|
|
|
*/ |
91
|
|
|
add_action( 'admin_action_jetpack_import_ui', array( 'Jetpack_Unified_Importer_Module', 'import_ui' ) ); |
92
|
|
|
|
If an expression can have both
false
, andnull
as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.