Generic_Plugin_AdminNotifications.php
3.52 KB
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
<?php
namespace W3TC;
class Generic_Plugin_AdminNotifications {
private $_config;
/**
*
*
* @var string
*/
private $_page;
function __construct() {
$this->_config = Dispatcher::config();
}
/**
* Runs plugin
*/
function run() {
if ( Util_Admin::is_w3tc_admin_page() ) {
add_action( 'admin_head', array(
$this,
'admin_head'
) );
add_action( 'w3tc_message_action_generic_support_us', array(
$this,
'w3tc_message_action_generic_support_us'
) );
add_action( 'w3tc_ajax_generic_support_us', array(
$this,
'w3tc_ajax_generic_support_us'
) );
add_action( 'w3tc_message_action_generic_edge', array(
$this,
'w3tc_message_action_generic_edge'
) );
add_action( 'w3tc_ajax_generic_edge', array(
$this,
'w3tc_ajax_generic_edge'
) );
}
}
/**
* Print JS required by the support nag.
*/
function admin_head() {
$state = Dispatcher::config_state_master();
// support us
$support_reminder =
$state->get_integer( 'common.support_us_invitations' ) < 3 &&
( $state->get_integer( 'common.install' ) <
( time() - W3TC_SUPPORT_US_TIMEOUT ) ) &&
( $state->get_integer( 'common.next_support_us_invitation' ) <
time() ) &&
$this->_config->get_string( 'common.support' ) == '' &&
!$this->_config->get_boolean( 'common.tweeted' );
if ( $support_reminder ) {
$state->set( 'common.next_support_us_invitation',
time() + W3TC_SUPPORT_US_TIMEOUT );
$state->set( 'common.support_us_invitations',
$state->get_integer( 'common.support_us_invitations' ) + 1 );
$state->save();
do_action( 'w3tc_message_action_generic_support_us' );
}
// edge mode
$edge_reminder = !$support_reminder &&
!Util_Environment::is_w3tc_edge( $this->_config ) &&
$state->get_integer( 'common.edge_invitations' ) < 3 &&
( $state->get_integer( 'common.install' ) <
( time() - W3TC_EDGE_TIMEOUT ) ) &&
( $state->get_integer( 'common.next_edge_invitation' ) < time() );
if ( $edge_reminder ) {
if ( $state->get_integer( 'common.edge_invitations' ) > 1 )
$next = time() + 30 * 24 * 60 * 60;
else
$next = time() + W3TC_EDGE_TIMEOUT;
$state->set( 'common.next_edge_invitation', $next );
$state->set( 'common.edge_invitations',
$state->get_integer( 'common.edge_invitations' ) + 1 );
$state->save();
do_action( 'w3tc_message_action_generic_edge' );
}
}
/**
* Display the support us nag
*/
public function w3tc_message_action_generic_support_us() {
wp_enqueue_script( 'w3tc-generic_support_us',
plugins_url( 'Generic_GeneralPage_View_ShowSupportUs.js', W3TC_FILE ),
array(), W3TC_VERSION );
}
public function w3tc_ajax_generic_support_us() {
$supports = $this->get_supports();
global $current_user;
wp_get_current_user();
$email = $current_user->user_email;
include W3TC_INC_DIR . '/lightbox/support_us.php';
}
private function get_supports() {
$supports = array(
'footer' => 'page footer'
);
$link_categories = get_terms( 'link_category', array(
'hide_empty' => 0
) );
foreach ( $link_categories as $link_category ) {
$supports['link_category_' . $link_category->term_id] =
strtolower( $link_category->name );
}
return $supports;
}
/**
* Display the support us nag
*/
public function w3tc_message_action_generic_edge() {
wp_enqueue_script( 'w3tc-generic_edge',
plugins_url( 'Generic_GeneralPage_View_ShowEdge.js', W3TC_FILE ),
array(), W3TC_VERSION );
}
public function w3tc_ajax_generic_edge() {
include W3TC_INC_LIGHTBOX_DIR . '/edge.php';
}
}