|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class Jetpack_Sync_Reindex { |
|
4
|
|
|
static function init() { |
|
5
|
|
|
add_action( 'wp_ajax_jetpack-sync-queue-status', array( __CLASS__, 'queue_status' ) ); |
|
6
|
|
|
} |
|
7
|
|
|
|
|
8
|
|
|
// returns size of queue and age of oldest item (aka lag) |
|
9
|
|
|
public function queue_status() { |
|
10
|
|
|
$client = Jetpack_Sync_Client::getInstance(); |
|
11
|
|
|
$queue = $client->get_sync_queue(); |
|
12
|
|
|
|
|
13
|
|
|
return array( |
|
14
|
|
|
'size' => $queue->size(), |
|
15
|
|
|
'lag' => $queue->lag() |
|
16
|
|
|
); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
View Code Duplication |
static function dashboard_ui() { |
|
20
|
|
|
$strings = json_encode( array( |
|
21
|
|
|
'WAITING' => array( |
|
22
|
|
|
'action' => __( 'Refresh Status', 'jetpack' ), |
|
23
|
|
|
'status' => __( 'Indexing request queued and waiting…', 'jetpack' ), |
|
24
|
|
|
), |
|
25
|
|
|
'INDEXING' => array( |
|
26
|
|
|
'action' => __( 'Refresh Status', 'jetpack' ), |
|
27
|
|
|
'status' => __( 'Indexing posts', 'jetpack' ), |
|
28
|
|
|
), |
|
29
|
|
|
'DONE' => array( |
|
30
|
|
|
'action' => __( 'Reindex Posts', 'jetpack' ), |
|
31
|
|
|
'status' => __( 'Posts indexed.', 'jetpack' ), |
|
32
|
|
|
), |
|
33
|
|
|
'ERROR' => array( |
|
34
|
|
|
'action' => __( 'Refresh Status', 'jetpack' ), |
|
35
|
|
|
'status' => __( 'Status unknown.', 'jetpack' ), |
|
36
|
|
|
), |
|
37
|
|
|
'ERROR:LARGE' => array( |
|
38
|
|
|
'action' => __( 'Refresh Status', 'jetpack' ), |
|
39
|
|
|
'status' => __( 'This site is too large, please contact Jetpack support to sync.', 'jetpack' ), |
|
40
|
|
|
), |
|
41
|
|
|
) ); |
|
42
|
|
|
|
|
43
|
|
|
wp_enqueue_script( |
|
44
|
|
|
'jetpack_sync_reindex_control', |
|
45
|
|
|
plugins_url( '_inc/jquery.jetpack-sync.js', JETPACK__PLUGIN_FILE ), |
|
46
|
|
|
array( 'jquery' ), |
|
47
|
|
|
JETPACK__VERSION |
|
48
|
|
|
); |
|
49
|
|
|
|
|
50
|
|
|
// $template = <<<EOT |
|
51
|
|
|
// <p class="jetpack_sync_reindex_control" id="jetpack_sync_reindex_control" data-strings="%s"> |
|
52
|
|
|
// <input type="submit" class="jetpack_sync_reindex_control_action button" value="%s" disabled /> |
|
53
|
|
|
// <span class="jetpack_sync_reindex_control_status">…</span> |
|
54
|
|
|
// </p> |
|
55
|
|
|
// EOT; |
|
56
|
|
|
|
|
57
|
|
|
$template = <<<EOT |
|
58
|
|
|
<p class="jetpack_sync_reindex_control" id="jetpack_sync_reindex_control" data-strings="%s"> |
|
59
|
|
|
This is a test |
|
60
|
|
|
<input type="submit" class="jetpack_sync_reindex_control_action button" value="%s" disabled /> |
|
61
|
|
|
<span class="jetpack_sync_reindex_control_status">…</span> |
|
62
|
|
|
</p> |
|
63
|
|
|
EOT; |
|
64
|
|
|
|
|
65
|
|
|
return sprintf( |
|
66
|
|
|
$template, |
|
67
|
|
|
esc_attr( $strings ), |
|
68
|
|
|
esc_attr__( 'Refresh Status', 'jetpack' ) |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|