Completed
Push — add/calypsoify-site-importer ( 2f6031 )
by
unknown
07:17
created

Jetpack_Site_Importer_Module   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 17
lcom 1
cbo 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A admin_init() 0 8 3
A is_import_screen() 0 15 4
A get_current_importer() 0 6 3
A is_wordpress_importer() 0 3 1
A current_screen() 0 8 2
A admin_url_change_have_fun_link() 0 11 4
1
<?php
2
3
class Jetpack_Site_Importer_Module {
4
	static function admin_init() {
5
		if ( ! ( class_exists( 'Jetpack_Calypsoify' ) && Jetpack_Calypsoify::is_active() ) ) {
6
			// Don't do anything if we're not "calypsoified"
7
			return;
8
		}
9
		add_action( 'current_screen', array( 'Jetpack_Site_Importer_Module', 'current_screen' ) );
10
		add_filter( 'admin_url', array( 'Jetpack_Site_Importer_Module', 'admin_url_change_have_fun_link' ) );
11
	}
12
13
	static function is_import_screen() {
14
		global $pagenow;
15
16
		// $pagenow is probably enough for us
17
		// We may want additional "screen" info at some point, so putting here for ref
18
		// $screen = get_current_screen();
19
		// error_log( print_r( $screen, 1 ) );
20
21
		switch ( $pagenow ) {
22
			case 'import.php':
23
				return true;
24
			case 'admin.php':
25
				return isset( $_REQUEST['import'] ) && $_REQUEST['import'];
26
		}
27
	}
28
29
	static function get_current_importer() {
30
		if ( ! ( self::is_import_screen() && isset( $_REQUEST['import'] ) ) ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression self::is_import_screen() of type boolean|null is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
31
			return '';
32
		}
33
		return strtolower( $_REQUEST['import'] );
34
	}
35
36
	static function is_wordpress_importer() {
37
		return 'wordpress' === self::get_current_importer();
38
	}
39
40
	static function current_screen() {
41
		if ( ! self::is_wordpress_importer() ) {
42
			return;
43
		}
44
45
		error_log( "SUP WordPress Importer!!!!" );
46
		// @TODO <img src="all-the-things.png" />
47
	}
48
49
	static function admin_url_change_have_fun_link( $admin_url ) {
50
		if ( ! self::is_wordpress_importer() ) {
51
			return $admin_url;
52
		}
53
54
		if ( isset( $_GET['step'] ) && 2 === (int) $_GET['step'] ) {
55
			return 'https://wordpress.com/settings/'; // @TODO dynamic parts
56
		}
57
58
		return $admin_url;
59
	}
60
}
61
62
add_action( 'admin_init', array( 'Jetpack_Site_Importer_Module', 'admin_init' ) );
63