-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathindex.php
executable file
·138 lines (105 loc) · 3.73 KB
/
index.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
/*
Plugin Name: Not Paid WP
Plugin URL: https://github.com/SurfEdge/not-paid-wp
Description: Client did not pay? Add opacity to the body tag and decrease it every day until their site completely fades away.
Version: 1.0
Author: SurfEdge
Author URI: https://github.com/SurfEdge/
Contributors: chamathpali, kleampa
*/
/*
This plugin is based on the https://github.com/kleampa/not-paid. (@riklomas) and Ciprian (@kleampa)
*/
function run_not_paid() {
$options = get_option('not_paid_wp_settings', array() );
$due = null;
$deadline = null;
if(isset($options['not_paid_wp_due_date'])){
$due = $options['not_paid_wp_due_date'] ;
}
if(isset($options['not_paid_wp_deadline'])){
$deadline = $options['not_paid_wp_deadline'] ;
}
if($due && $deadline){
?>
<script type="text/javascript">
(function(){
/* change these variables as you wish */
var due_date = new Date('<?php echo esc_attr( $due ); ?>');
var days_deadline = <?php echo esc_attr( $deadline ); ?>;
/* stop changing here */
var current_date = new Date();
var utc1 = Date.UTC(due_date.getFullYear(), due_date.getMonth(), due_date.getDate());
var utc2 = Date.UTC(current_date.getFullYear(), current_date.getMonth(), current_date.getDate());
var days = Math.floor((utc2 - utc1) / (1000 * 60 * 60 * 24));
if(days > 0) {
var days_late = days_deadline-days;
var opacity = (days_late*100/days_deadline)/100;
opacity = (opacity < 0) ? 0 : opacity;
opacity = (opacity > 1) ? 1 : opacity;
if(opacity >= 0 && opacity <= 1) {
document.getElementsByTagName("BODY")[0].style.opacity = opacity;
}
}
})();
</script>
<?php
}
}
add_action( 'wp_footer', 'run_not_paid' );
add_action( 'admin_menu', 'not_paid_wp_add_admin_menu' );
add_action( 'admin_init', 'not_paid_wp_settings_init' );
function not_paid_wp_add_admin_menu( ) {
add_options_page( 'Not-Paid-WP', 'Not-Paid-WP', 'manage_options', 'not-paid-wp', 'not_paid_wp_options_page' );
}
function not_paid_wp_settings_init( ) {
register_setting( 'pluginPage', 'not_paid_wp_settings' );
add_settings_section(
'not_paid_wp_pluginPage_section',
__( 'Client did not pay?', 'Not Paid WP' ),
'not_paid_wp_settings_section_callback',
'pluginPage'
);
add_settings_field(
'not_paid_wp_due_date',
__( 'Due Date (02/25/2019)', 'Not Paid WP' ),
'not_paid_wp_due_date_render',
'pluginPage',
'not_paid_wp_pluginPage_section'
);
add_settings_field(
'not_paid_wp_deadline',
__( 'Days Deadline - # of days', 'Not Paid WP' ),
'not_paid_wp_deadline_render',
'pluginPage',
'not_paid_wp_pluginPage_section'
);
}
function not_paid_wp_due_date_render( ) {
$options = get_option( 'not_paid_wp_settings' );
?>
<input type='date' name='not_paid_wp_settings[not_paid_wp_due_date]' value='<?php echo $options['not_paid_wp_due_date']; ?>'>
<?php
}
function not_paid_wp_deadline_render( ) {
$options = get_option( 'not_paid_wp_settings' );
?>
<input type='text' name='not_paid_wp_settings[not_paid_wp_deadline]' value='<?php echo $options['not_paid_wp_deadline']; ?>'>
<?php
}
function not_paid_wp_settings_section_callback( ) {
echo __( 'Add opacity to the body tag and decrease it every day until their site completely fades away.<br>Set a due date and customize the number of days you offer them until the website is fully vanished.<br>Contribute at <a href="https://github.com/SurfEdge/not-paid-wp">https://github.com/SurfEdge/not-paid-wp</a><br><h4>This will only work if you set the below values!</h4>', 'Not Paid WP' );
}
function not_paid_wp_options_page( ) {
?>
<form action='options.php' method='post'>
<h2>Not-Paid-WP</h2>
<?php
settings_fields( 'pluginPage' );
do_settings_sections( 'pluginPage' );
submit_button();
?>
</form>
<?php
}