-
Notifications
You must be signed in to change notification settings - Fork 22
/
bctt-welcome-functions.php
115 lines (105 loc) · 2.98 KB
/
bctt-welcome-functions.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
<?php
/**
* Get wizard nav css class
*
* @param string $step
* @return string
*/
function bctt_get_step_class( $step ) {
$class= "";
switch ( $step ) {
case 'bctt-setup':
if ( 'bctt-setup' === bctt_get_step() ) {
$class = 'class="active"';
} else {
$class = 'class="done"';
}
break;
case 'bctt-usage':
$done = array( 'bctt-content', 'bctt-grow', 'bctt-done' );
if ( 'bctt-usage' === bctt_get_step() ) {
$class = 'class="active"';
} else if ( in_array( bctt_get_step(), $done ) ) {
$class = 'class="done"';
}
break;
case 'bctt-content':
$done = array( 'bctt-grow', 'bctt-done' );
if ( 'bctt-content' === bctt_get_step() ) {
$class = 'class="active"';
} else if ( in_array( bctt_get_step(), $done ) ) {
$class = 'class="done"';
}
break;
case 'bctt-grow':
$done = array( 'bctt-done' );
if ( 'bctt-grow' === bctt_get_step() ) {
$class = 'class="active"';
} else if ( in_array( bctt_get_step(), $done ) ) {
$class = 'class="done"';
}
break;
case 'bctt-done':
if ( 'bctt-done' === bctt_get_step() ) {
$class = 'class="active"';
}
break;
default:
# code...
break;
}
return $class;
}
/**
* Get wizard step
*
* @return string
*/
function bctt_get_step() {
return isset( $_GET['step'] ) ? wp_unslash( $_GET['step'] ) : 'bctt-setup';
}
/**
* Get welcome step url
*
* @param string $step
* @return string url
*/
function bctt_get_step_url( $step ) {
return admin_url( 'admin.php?page=bctt-welcome&step=' . $step );
}
/**
* Redirect to welcome page
*
* @return void
*/
function bctt_welcome_redirect() {
if ( get_transient( '_bctt_activation_redirect' ) ) {
$do_redirect = true;
$current_page = isset( $_GET['page'] ) ? wp_unslash( $_GET['page'] ) : false;
// Bailout redirect during these events.
if ( wp_doing_ajax() || is_network_admin() || ! current_user_can( 'manage_options' ) ) {
$do_redirect = false;
}
// Bailout redirect on these pages & events.
if ( 'bctt-welcome' === $current_page || isset( $_GET['activate-multi'] ) ) {
delete_transient( '_bctt_activation_redirect' );
$do_redirect = false;
}
if ( $do_redirect ) {
delete_transient( '_bctt_activation_redirect' );
wp_safe_redirect( bctt_get_step_url( 'bctt-setup' ) );
exit;
}
}
}
add_action( 'admin_init', 'bctt_welcome_redirect' );
/**
* Include Welcome Class
*/
if ( ! empty( $_GET['page'] ) ) {
switch ( $_GET['page'] ) {
case 'bctt-welcome':
include_once 'bctt-welcome.php';
break;
}
}