-
Notifications
You must be signed in to change notification settings - Fork 116
/
class-connector-mercator.php
229 lines (201 loc) · 4.93 KB
/
class-connector-mercator.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<?php
/**
* Connector for Mercator
*
* @package WP_Stream
*/
namespace WP_Stream;
/**
* Class - Connector_Mercator
*/
class Connector_Mercator extends Connector {
/**
* Connector slug
*
* @var string
*/
public $name = 'mercator';
/**
* Actions registered for this connector
*
* @var array
*/
public $actions = array(
'mercator.mapping.updated',
'mercator.mapping.deleted',
'mercator.mapping.created',
'mercator.mapping.made_primary',
);
/**
* Register connector in the WP Frontend
*
* @var bool
*/
public $register_frontend = false;
/**
* Return translated connector label
*
* @return string
*/
public function get_label() {
return esc_html__( 'Mercator' );
}
/**
* Return translated action labels
*
* @return array
*/
public function get_action_labels() {
return array(
'made_primary' => esc_html__( 'Make primary domain', 'stream' ),
'created' => esc_html__( 'Created', 'stream' ),
'deleted' => esc_html__( 'Deleted', 'stream' ),
'updated' => esc_html__( 'Updated', 'stream' ),
);
}
/**
* Return translated context labels
*
* @return array
*/
public function get_context_labels() {
$labels = array();
if ( is_multisite() && ! wp_is_large_network() ) {
$blogs = wp_stream_get_sites();
foreach ( $blogs as $blog ) {
$blog_details = get_site( $blog->blog_id );
$key = sprintf( 'blog-%d', $blog->blog_id );
$labels[ $key ] = $blog_details->blogname;
}
}
return $labels;
}
/**
* Add action links to Stream drop row in admin list screen
*
* @filter wp_stream_action_links_{connector}
*
* @param array $links Previous links registered.
* @param object $record Stream record.
*
* @return array
*/
public function action_links( $links, $record ) {
$links [ esc_html__( 'Site Admin' ) ] = get_admin_url( $record->object_id );
if ( $record->object_id ) {
$site_admin_link = get_admin_url( $record->object_id );
if ( $site_admin_link ) {
$links [ esc_html__( 'Site Admin' ) ] = $site_admin_link;
}
$site_settings_link = add_query_arg(
array(
'id' => $record->object_id,
'action' => 'mercator-aliases',
),
network_admin_url( 'admin.php' )
);
if ( $site_settings_link ) {
$links [ esc_html__( 'Domain mapping Settings', 'stream' ) ] = $site_settings_link;
}
}
return $links;
}
/**
* Log if domain is made primary.
*
* @param object $mapping Mapping object.
*/
public function callback_mercator_mapping_made_primary( $mapping ) {
$blog_id = $mapping->get_site_id();
$blog = get_site( $blog_id );
$this->log(
/* translators: %1$s: domain alias, %2$s: site name (e.g. "FooBar Blog") */
_x(
'"%1$s" domain alias was make primary for "%2$s"',
'1. Domain alias 2. Site name',
'stream'
),
array(
'domain' => $mapping->get_domain(),
'site_name' => $blog->blogname,
),
$blog_id,
sanitize_key( $blog->blogname ),
'made_primary'
);
}
/**
* Log if domain alias is updated.
*
* @param object $mapping Mapping object.
* @param object $old_mapping Old mapping object from before update.
*/
public function callback_mercator_mapping_updated( $mapping, $old_mapping ) {
$blog_id = $mapping->get_site_id();
$blog = get_site( $blog_id );
$this->log(
/* translators: %1$s: domain alias, %2$s: site name (e.g. "FooBar Blog") */
_x(
'The domain alias "%1$s" was updated to "%2$s" for site "%3$s"',
'1. Old Domain alias 2. Domain alias 2. Site name',
'stream'
),
array(
'old_domain' => $old_mapping->get_domain(),
'domain' => $mapping->get_domain(),
'site_name' => $blog->blogname,
),
$blog_id,
sanitize_key( $blog->blogname ),
'updated'
);
}
/**
* Log if domain alias is deleted.
*
* @param object $mapping Mapping of deleted alias.
*/
public function callback_mercator_mapping_deleted( $mapping ) {
$blog_id = $mapping->get_site_id();
$blog = get_site( $blog_id );
$this->log(
/* translators: %1$s: domain alias, %2$s: site name (e.g. "FooBar Blog") */
_x(
'"%1$s" domain alias was deleted for "%2$s"',
'1. Domain alias 2. Site name',
'stream'
),
array(
'domain' => $mapping->get_domain(),
'site_name' => $blog->blogname,
),
$blog_id,
sanitize_key( $blog->blogname ),
'deleted'
);
}
/**
* Log if domain alias is created.
*
* @param object $mapping Mapping object.
*/
public function callback_mercator_mapping_created( $mapping ) {
$blog_id = $mapping->get_site_id();
$blog = get_site( $blog_id );
$this->log(
/* translators: %1$s: domain alias, %2$s: site name (e.g. "FooBar Blog") */
_x(
'"%1$s" domain alias was created for "%2$s"',
'1. Domain alias 2. Site name',
'stream'
),
array(
'domain' => $mapping->get_domain(),
'site_name' => $blog->blogname,
),
$blog_id,
sanitize_key( $blog->blogname ),
'created'
);
}
}