-
Notifications
You must be signed in to change notification settings - Fork 127
Expand file tree
/
Copy pathpreload.php
More file actions
158 lines (144 loc) · 8.67 KB
/
preload.php
File metadata and controls
158 lines (144 loc) · 8.67 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
154
155
156
157
158
<div class="wpsc-settings-inner">
<?php
global $wp_cache_preload_interval, $wp_cache_preload_posts, $preload_schedule_type, $preload_scheduled_time, $preload_schedule_interval;
echo '<a name="preload"></a>';
if ( ! $cache_enabled || ! $super_cache_enabled || true === defined( 'DISABLESUPERCACHEPRELOADING' ) ) {
wp_admin_notice(
esc_html__( 'Preloading of cache disabled. Please make sure simple or expert mode is enabled or talk to your host administrator.', 'wp-super-cache' ),
array(
'type' => 'warning',
)
);
return;
}
$count = wpsc_post_count();
$min_refresh_interval = wpsc_get_minimum_preload_interval();
// Set defaults for preload scheduler variables if not set.
if ( ! isset( $preload_schedule_type ) ) {
$preload_schedule_type = 'interval';
}
if ( ! isset( $preload_scheduled_time ) ) {
$preload_scheduled_time = '00:00';
}
if ( ! isset( $preload_schedule_interval ) ) {
$preload_schedule_interval = 'daily';
}
echo '<div class="wpsc-card">';
echo '<p>' . __( 'This will cache every published post and page on your site. It will create supercache static files so unknown visitors (including bots) will hit a cached page. This will probably help your Google ranking as they are using speed as a metric when judging websites now.', 'wp-super-cache' ) . '</p>';
echo '<p>' . __( 'Preloading creates lots of files however. Caching is done from the newest post to the oldest so please consider only caching the newest if you have lots (10,000+) of posts. This is especially important on shared hosting.', 'wp-super-cache' ) . '</p>';
echo '<p>' . __( 'In ’Preload Mode’ regular garbage collection will be disabled so that old cache files are not deleted. This is a recommended setting when the cache is preloaded.', 'wp-super-cache' ) . '</p>';
echo '<form name="cache_filler" action="' . esc_url_raw( add_query_arg( 'tab', 'preload', $admin_url ) ) . '" method="POST">';
echo '<input type="hidden" name="action" value="preload" />';
echo '<input type="hidden" name="page" value="wpsupercache" />';
echo '</div>';
echo '<div class="wpsc-card">';
if ( $count > 100 ) {
$step = (int)( $count / 10 );
$select = "<select name='wp_cache_preload_posts' size=1>";
$select .= "<option value='all' ";
if ( ! isset( $wp_cache_preload_posts ) || $wp_cache_preload_posts == 'all' ) {
$checked = 'selectect=1 ';
$best = 'all';
} else {
$checked = ' ';
$best = $wp_cache_preload_posts;
}
$select .= "{$checked}>" . __( 'all', 'wp-super-cache' ) . "</option>";
$options = array();
for( $c = $step; $c < $count; $c += $step ) {
$checked = ' ';
if ( $best == $c )
$checked = 'selected=1 ';
$options[ $c ] = "<option value='$c'{$checked}>$c</option>";
}
if ( ! isset( $options[ $wp_cache_preload_posts ] ) ) {
$options[ $wp_cache_preload_posts ] = "<option value='$wp_cache_preload_posts' selected=1>$wp_cache_preload_posts</option>";
}
ksort( $options );
$select .= implode( "\n", $options );
$checked = ' ';
if ( $best == $count )
$checked = 'selected=1 ';
$select .= "<option value='$count'{$checked}>$count</option>";
$select .= "</select>";
echo '<p>' . sprintf( __( 'Preload %s posts.', 'wp-super-cache' ), $select ) . '</p>';
} else {
echo '<input type="hidden" name="wp_cache_preload_posts" value="' . $count . '" />';
}
// Preload Scheduler UI
echo "<script type='text/javascript'>";
echo "jQuery(function () {
jQuery('#preload_interval_time').on('click',function () {
jQuery('#preload_schedule_interval_radio').attr('checked', true);
});
jQuery('#preload_scheduled_time').on('click',function () {
jQuery('#preload_schedule_time_radio').attr('checked', true);
});
jQuery('#preload_scheduled_select').on('click',function () {
jQuery('#preload_schedule_time_radio').attr('checked', true);
});
});";
echo '</script>';
echo '<table class="form-table">';
echo '<tr><td valign="top"><strong>' . esc_html__( 'Scheduler', 'wp-super-cache' ) . '</strong></td><td><table cellpadding=0 cellspacing=0><tr><td valign="top"><input type="radio" id="preload_schedule_interval_radio" name="preload_schedule_type" value="interval" ' . checked( 'interval', $preload_schedule_type, false ) . ' /></td><td valign="top"><label for="preload_schedule_interval_radio">' . esc_html__( 'Timer:', 'wp-super-cache' ) . '</label></td>';
// translators: %d is the minimum refresh interval in minutes.
echo '<td><input type=\'text\' id=\'preload_interval_time\' size=6 name=\'wp_cache_preload_interval\' value=\'' . esc_attr( $wp_cache_preload_interval ) . '\' /> ' . esc_html__( 'minutes', 'wp-super-cache' ) . '<br />' . sprintf( esc_html__( 'Refresh preloaded cache files at this interval. (0 to disable, minimum %d minutes)', 'wp-super-cache' ), (int) $min_refresh_interval ) . '</td></tr>';
echo '<tr><td valign="top"><input type="radio" id="preload_schedule_time_radio" name="preload_schedule_type" value="time" ' . checked( 'time', $preload_schedule_type, false ) . ' /></td><td valign="top"><label for="preload_schedule_time_radio">' . esc_html__( 'Clock:', 'wp-super-cache' ) . '</label></td>';
$wpsc_tz_label = function_exists( 'wp_timezone_string' ) ? wp_timezone_string() : 'UTC';
echo '<td><input type=\'text\' size=5 id=\'preload_scheduled_time\' name=\'preload_scheduled_time\' value=\'' . esc_attr( $preload_scheduled_time ) . '\' /> ' . esc_html__( 'HH:MM', 'wp-super-cache' ) . '<br />'
. sprintf(
/* translators: %s: site timezone string, e.g. "Europe/Dublin" or "+00:00". */
esc_html__( 'Start preloading at this time (site timezone: %s) or starting at this time every interval below.', 'wp-super-cache' ),
'<code>' . esc_html( $wpsc_tz_label ) . '</code>'
)
. '</td></tr>';
$schedules = wp_get_schedules();
echo '<tr><td><br /></td><td><label for=\'preload_scheduled_select\'>' . esc_html__( 'Interval:', 'wp-super-cache' ) . '</label></td><td><select id=\'preload_scheduled_select\' name=\'preload_schedule_interval\' size=1>';
foreach ( $schedules as $desc => $details ) {
echo '<option value=\'' . esc_attr( $desc ) . '\' ' . selected( $desc, $preload_schedule_interval, false ) . '>' . esc_html( $details['display'] ) . '</option>';
}
echo '</select></td></tr>';
echo '</table></td></tr>';
echo '</table>';
echo '<input type="checkbox" name="wp_cache_preload_on" value="1" ';
echo $wp_cache_preload_on == 1 ? 'checked=1' : '';
echo ' /> ' . __( 'Preload mode (garbage collection disabled. Recommended.)', 'wp-super-cache' ) . '<br />';
echo '<input type="checkbox" name="wp_cache_preload_taxonomies" value="1" ';
echo $wp_cache_preload_taxonomies == 1 ? 'checked=1' : '';
echo ' /> ' . __( 'Preload tags, categories and other taxonomies.', 'wp-super-cache' ) . '<br />';
echo __( 'Send me status emails when files are refreshed.', 'wp-super-cache' ) . '<br />';
if ( !isset( $wp_cache_preload_email_volume ) )
$wp_cache_preload_email_volume = 'none';
echo '<select type="select" name="wp_cache_preload_email_volume">';
echo '<option value="none" ' . selected( 'none', $wp_cache_preload_email_volume ) . '>' . esc_html__( 'No Emails', 'wp-super-cache' ) . '</option>';
// translators: %d is the number of posts
echo '<option value="many" ' . selected( 'many', $wp_cache_preload_email_volume ) . '>' . esc_html( sprintf( __( 'Many emails, 2 emails per %d posts.', 'wp-super-cache' ), WPSC_PRELOAD_POST_COUNT ) ) . '</option>';
// translators: %d is the number of posts
echo '<option value="medium" ' . selected( 'medium', $wp_cache_preload_email_volume ) . '>' . esc_html( sprintf( __( 'Medium, 1 email per %d posts.', 'wp-super-cache' ), WPSC_PRELOAD_POST_COUNT ) ) . '</option>';
echo '<option value="less" ' . selected( 'less', $wp_cache_preload_email_volume ) . '>' . esc_html__( 'Less emails, 1 at the start and 1 at the end of preloading all posts.', 'wp-super-cache' ) . '</option>';
echo "</select>";
if (
wp_next_scheduled( 'wp_cache_preload_hook' )
|| wp_next_scheduled( 'wp_cache_full_preload_hook' )
|| wpsc_is_preload_active()
) {
$currently_preloading = true;
}
echo '<div class="submit"><input class="button-primary" type="submit" name="preload" value="' . __( 'Save Settings', 'wp-super-cache' ) . '" />';
echo '</div>';
wp_nonce_field( 'wp-cache' );
echo '</form>';
echo '<form name="do_preload" action="' . esc_url_raw( add_query_arg( 'tab', 'preload', $admin_url ) ) . '" method="POST">';
echo '<input type="hidden" name="action" value="preload" />';
echo '<input type="hidden" name="page" value="wpsupercache" />';
echo '<div class="submit">';
if ( false == $currently_preloading ) {
echo '<input class="button-primary" type="submit" name="preload_now" value="' . __( 'Preload Cache Now', 'wp-super-cache' ) . '" />';
} else {
echo '<input class="button-primary" type="submit" name="preload_off" value="' . __( 'Cancel Cache Preload', 'wp-super-cache' ) . '" />';
}
echo '</div>';
wp_nonce_field( 'wp-cache' );
echo '</form>';
echo '</div>';
echo '</div>';