review_notice.php
3.8 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
<?php
class CPAC_Review_Notice {
const OPTION_INSTALL_DATE = 'cpac-install-timestamp';
const OPTION_ADMIN_NOTICE_KEY = 'cpac-hide-review-notice';
private $days_since_install;
private $cpac;
function __construct( $cpac ) {
register_activation_hook( __FILE__, array( $this, 'insert_install_timestamp' ) );
// show notice after x days of installing
$this->days_since_install = 30; // 30 days
add_action( 'admin_init', array( $this, 'maybe_display_review_notice' ) );
add_action( 'wp_ajax_cpac_hide_review_notice', array( $this, 'ajax_hide_review_notice' ) );
}
public function insert_install_timestamp() {
add_site_option( self::OPTION_INSTALL_DATE, time() );
return time();
}
private function get_install_timestamp() {
$timestamp = get_site_option( self::OPTION_INSTALL_DATE, '' );
if ( '' == $timestamp ) {
$timestamp = $this->insert_install_timestamp();
}
return $timestamp;
}
public function maybe_display_review_notice() {
if ( current_user_can( 'manage_admin_columns' ) && ( ! get_user_meta( get_current_user_id(), self::OPTION_ADMIN_NOTICE_KEY, true ) ) ) {
if ( ( time() - ( 86400 * absint( $this->days_since_install ) ) ) >= $this->get_install_timestamp() ) {
add_action( 'admin_notices', array( $this, 'display_admin_review_notice' ) );
}
}
}
public function ajax_hide_review_notice() {
update_user_meta( get_current_user_id(), self::OPTION_ADMIN_NOTICE_KEY, '1', true );
}
public function display_admin_review_notice() {
$screen = get_current_screen();
// only display on settings and plugins page
if ( ! $screen || ! in_array( $screen->parent_base, array( 'options-general', 'plugins' ) ) ) {
return false;
}
$product = __( 'Admin Columns', 'codepress-admin-columns' );
if ( defined( 'ACP_VERSION' ) ) {
$product = __( 'Admin Columns Pro', 'codepress-admin-columns' );
}
?>
<style type="text/css">
body .wrap .cpac_message {
position: relative;
padding-right: 40px;
}
.cpac_message .spinner.right {
visibility: visible;
display: block;
right: 8px;
text-decoration: none;
text-align: right;
position: absolute;
top: 50%;
margin-top: -10px;
}
.cpac_message .spinner.inline {
display: inline-block;
position: absolute;
margin: 4px 0 0 4px;
padding: 0;
float: none;
}
.cpac_message .hide-notice {
right: 8px;
text-decoration: none;
width: 32px;
text-align: right;
position: absolute;
top: 50%;
height: 32px;
margin-top: -16px;
}
.cpac_message .hide-notice:before {
display: block;
content: '\f335';
font-family: 'Dashicons';
margin: .5em 0;
padding: 2px;
}
.cpac_message .buttons {
margin-top: 8px;
}
.cpac_message .help {
display: none;
}
</style>
<script type="text/javascript">
jQuery( function( $ ) {
$( document ).ready( function() {
$( '.updated a.hide-review-notice' ).click( function( e ) {
e.preventDefault();
var el = $( this ).parents( '.cpac_message' );
var el_close = el.find( '.hide-notice' );
var soft = $( this ).hasClass( 'hide-review-notice-soft' );
if ( soft ) {
el.find( '.info' ).slideUp();
el.find( '.help' ).slideDown();
}
else {
el_close.hide();
el_close.after( '<div class="spinner right"></div>' );
el.find( '.spinner' ).show();
}
$.post( ajaxurl, {
'action': 'cpac_hide_review_notice'
}, function( data ) {
if ( ! soft ) {
el.find( '.spinner' ).remove();
el.slideUp();
}
} );
return false;
} );
} );
} );
</script>
<?php
}
}