|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
abstract class Publicize_Base { |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Services that are currently connected to the given user |
|
7
|
|
|
* through publicize. |
|
8
|
|
|
*/ |
|
9
|
|
|
public $connected_services = array(); |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Services that are supported by publicize. They don't |
|
13
|
|
|
* necessarily need to be connected to the current user. |
|
14
|
|
|
*/ |
|
15
|
|
|
public $services; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* key names for post meta |
|
19
|
|
|
*/ |
|
20
|
|
|
public $ADMIN_PAGE = 'wpas'; |
|
21
|
|
|
public $POST_MESS = '_wpas_mess'; |
|
22
|
|
|
public $POST_SKIP = '_wpas_skip_'; // connection id appended to indicate that a connection should NOT be publicized to |
|
23
|
|
|
public $POST_DONE = '_wpas_done_'; // connection id appended to indicate a connection has already been publicized to |
|
24
|
|
|
public $USER_AUTH = 'wpas_authorize'; |
|
25
|
|
|
public $USER_OPT = 'wpas_'; |
|
26
|
|
|
public $PENDING = '_publicize_pending'; // ready for Publicize to do its thing |
|
27
|
|
|
public $POST_SERVICE_DONE = '_publicize_done_external'; // array of external ids where we've Publicized |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* default pieces of the message used in constructing the |
|
31
|
|
|
* content pushed out to other social networks |
|
32
|
|
|
*/ |
|
33
|
|
|
|
|
34
|
|
|
public $default_prefix = ''; |
|
35
|
|
|
public $default_message = '%title%'; |
|
36
|
|
|
public $default_suffix = ' '; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* What WP capability is require to create/delete global connections? |
|
40
|
|
|
* All users with this cap can un-globalize all other global connections, and globalize any of their own |
|
41
|
|
|
* Globalized connections cannot be unselected by users without this capability when publishing |
|
42
|
|
|
*/ |
|
43
|
|
|
public $GLOBAL_CAP = 'edit_others_posts'; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Sets up the basics of Publicize |
|
47
|
|
|
*/ |
|
48
|
|
|
function __construct() { |
|
49
|
|
|
$this->default_message = Publicize_Util::build_sprintf( array( |
|
50
|
|
|
/** |
|
51
|
|
|
* Filter the default Publicize message. |
|
52
|
|
|
* |
|
53
|
|
|
* @module publicize |
|
54
|
|
|
* |
|
55
|
|
|
* @since 2.0.0 |
|
56
|
|
|
* |
|
57
|
|
|
* @param string $this->default_message Publicize's default message. Default is the post title. |
|
58
|
|
|
*/ |
|
59
|
|
|
apply_filters( 'wpas_default_message', $this->default_message ), |
|
60
|
|
|
'title', |
|
61
|
|
|
'url', |
|
62
|
|
|
) ); |
|
63
|
|
|
|
|
64
|
|
|
$this->default_prefix = Publicize_Util::build_sprintf( array( |
|
65
|
|
|
/** |
|
66
|
|
|
* Filter the message prepended to the Publicize custom message. |
|
67
|
|
|
* |
|
68
|
|
|
* @module publicize |
|
69
|
|
|
* |
|
70
|
|
|
* @since 2.0.0 |
|
71
|
|
|
* |
|
72
|
|
|
* @param string $this->default_prefix String prepended to the Publicize custom message. |
|
73
|
|
|
*/ |
|
74
|
|
|
apply_filters( 'wpas_default_prefix', $this->default_prefix ), |
|
75
|
|
|
'url', |
|
76
|
|
|
) ); |
|
77
|
|
|
|
|
78
|
|
|
$this->default_suffix = Publicize_Util::build_sprintf( array( |
|
79
|
|
|
/** |
|
80
|
|
|
* Filter the message appended to the Publicize custom message. |
|
81
|
|
|
* |
|
82
|
|
|
* @module publicize |
|
83
|
|
|
* |
|
84
|
|
|
* @since 2.0.0 |
|
85
|
|
|
* |
|
86
|
|
|
* @param string $this->default_suffix String appended to the Publicize custom message. |
|
87
|
|
|
*/ |
|
88
|
|
|
apply_filters( 'wpas_default_suffix', $this->default_suffix ), |
|
89
|
|
|
'url', |
|
90
|
|
|
) ); |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Filter the capability to change global Publicize connection options. |
|
94
|
|
|
* |
|
95
|
|
|
* All users with this cap can un-globalize all other global connections, and globalize any of their own |
|
96
|
|
|
* Globalized connections cannot be unselected by users without this capability when publishing. |
|
97
|
|
|
* |
|
98
|
|
|
* @module publicize |
|
99
|
|
|
* |
|
100
|
|
|
* @since 2.2.1 |
|
101
|
|
|
* |
|
102
|
|
|
* @param string $this->GLOBAL_CAP default capability in control of global Publicize connection options. Default to edit_others_posts. |
|
103
|
|
|
*/ |
|
104
|
|
|
$this->GLOBAL_CAP = apply_filters( 'jetpack_publicize_global_connections_cap', $this->GLOBAL_CAP ); |
|
105
|
|
|
|
|
106
|
|
|
// stage 1 and 2 of 3-stage Publicize. Flag for Publicize on creation, save meta, |
|
107
|
|
|
// then check meta and publicize based on that. stage 3 implemented on wpcom |
|
108
|
|
|
add_action( 'transition_post_status', array( $this, 'flag_post_for_publicize' ), 10, 3 ); |
|
109
|
|
|
add_action( 'save_post', array( &$this, 'save_meta' ), 20, 2 ); |
|
110
|
|
|
|
|
111
|
|
|
// Connection test callback |
|
112
|
|
|
add_action( 'wp_ajax_test_publicize_conns', array( $this, 'test_publicize_conns' ) ); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Functions to be implemented by the extended class (publicize-wpcom or publicize-jetpack) |
|
117
|
|
|
*/ |
|
118
|
|
|
abstract function get_connection_id( $connection ); |
|
119
|
|
|
abstract function connect_url( $service_name ); |
|
120
|
|
|
abstract function disconnect_url( $service_name, $id ); |
|
121
|
|
|
abstract function get_connection_meta( $connection ); |
|
122
|
|
|
abstract function get_services( $filter ); |
|
123
|
|
|
abstract function get_connections( $service, $_blog_id = false, $_user_id = false ); |
|
124
|
|
|
abstract function get_connection( $service, $id, $_blog_id = false, $_user_id = false ); |
|
125
|
|
|
abstract function flag_post_for_publicize( $new_status, $old_status, $post ); |
|
126
|
|
|
abstract function test_connection( $service_name, $connection ); |
|
127
|
|
|
abstract function disconnect( $service, $connection_id, $_blog_id = false, $_user_id = false, $force_delete = false ); |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Shared Functions |
|
131
|
|
|
*/ |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* Returns an external URL to the connection's profile |
|
135
|
|
|
*/ |
|
136
|
|
|
function get_profile_link( $service_name, $c ) { |
|
137
|
|
|
$cmeta = $this->get_connection_meta( $c ); |
|
138
|
|
|
|
|
139
|
|
|
if ( isset( $cmeta['connection_data']['meta']['link'] ) ) { |
|
140
|
|
|
if ( 'facebook' == $service_name && 0 === strpos( parse_url( $cmeta['connection_data']['meta']['link'], PHP_URL_PATH ), '/app_scoped_user_id/' ) ) { |
|
141
|
|
|
// App-scoped Facebook user IDs are not usable profile links |
|
142
|
|
|
return false; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
return $cmeta['connection_data']['meta']['link']; |
|
146
|
|
View Code Duplication |
} elseif ( 'facebook' == $service_name && isset( $cmeta['connection_data']['meta']['facebook_page'] ) ) { |
|
147
|
|
|
return 'https://facebook.com/' . $cmeta['connection_data']['meta']['facebook_page']; |
|
148
|
|
|
} elseif ( 'tumblr' == $service_name && isset( $cmeta['connection_data']['meta']['tumblr_base_hostname'] ) ) { |
|
149
|
|
|
return 'http://' . $cmeta['connection_data']['meta']['tumblr_base_hostname']; |
|
150
|
|
|
} elseif ( 'twitter' == $service_name ) { |
|
151
|
|
|
return 'https://twitter.com/' . substr( $cmeta['external_display'], 1 ); // Has a leading '@' |
|
152
|
|
View Code Duplication |
} elseif ( 'google_plus' == $service_name && isset( $cmeta['connection_data']['meta']['google_plus_page'] ) ) { |
|
153
|
|
|
return 'https://plus.google.com/' . $cmeta['connection_data']['meta']['google_plus_page']; |
|
154
|
|
|
} elseif ( 'google_plus' == $service_name ) { |
|
155
|
|
|
return 'https://plus.google.com/' . $cmeta['external_id']; |
|
156
|
|
|
} else if ( 'linkedin' == $service_name ) { |
|
157
|
|
|
if ( !isset( $cmeta['connection_data']['meta']['profile_url'] ) ) { |
|
158
|
|
|
return false; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
$profile_url_query = parse_url( $cmeta['connection_data']['meta']['profile_url'], PHP_URL_QUERY ); |
|
162
|
|
|
wp_parse_str( $profile_url_query, $profile_url_query_args ); |
|
|
|
|
|
|
163
|
|
|
if ( isset( $profile_url_query_args['key'] ) ) { |
|
|
|
|
|
|
164
|
|
|
$id = $profile_url_query_args['key']; |
|
165
|
|
|
} elseif ( isset( $profile_url_query_args['id'] ) ) { |
|
|
|
|
|
|
166
|
|
|
$id = $profile_url_query_args['id']; |
|
167
|
|
|
} else { |
|
168
|
|
|
return false; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
return esc_url_raw( add_query_arg( 'id', urlencode( $id ), 'http://www.linkedin.com/profile/view' ) ); |
|
172
|
|
|
} else { |
|
173
|
|
|
return false; // no fallback. we just won't link it |
|
174
|
|
|
} |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* Returns a display name for the connection |
|
179
|
|
|
*/ |
|
180
|
|
|
function get_display_name( $service_name, $c ) { |
|
181
|
|
|
$cmeta = $this->get_connection_meta( $c ); |
|
182
|
|
|
|
|
183
|
|
|
if ( isset( $cmeta['connection_data']['meta']['display_name'] ) ) { |
|
184
|
|
|
return $cmeta['connection_data']['meta']['display_name']; |
|
185
|
|
View Code Duplication |
} elseif ( $service_name == 'tumblr' && isset( $cmeta['connection_data']['meta']['tumblr_base_hostname'] ) ) { |
|
186
|
|
|
return $cmeta['connection_data']['meta']['tumblr_base_hostname']; |
|
187
|
|
|
} elseif ( $service_name == 'twitter' ) { |
|
188
|
|
|
return $cmeta['external_display']; |
|
189
|
|
|
} else { |
|
190
|
|
|
$connection_display = $cmeta['external_display']; |
|
191
|
|
|
if ( empty( $connection_display ) ) |
|
192
|
|
|
$connection_display = $cmeta['external_name']; |
|
193
|
|
|
return $connection_display; |
|
194
|
|
|
} |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
public static function get_service_label( $service_name ) { |
|
198
|
|
|
switch ( $service_name ) { |
|
199
|
|
|
case 'linkedin': |
|
200
|
|
|
return 'LinkedIn'; |
|
201
|
|
|
break; |
|
|
|
|
|
|
202
|
|
|
case 'google_plus': |
|
203
|
|
|
return 'Google+'; |
|
204
|
|
|
break; |
|
|
|
|
|
|
205
|
|
|
case 'twitter': |
|
206
|
|
|
case 'facebook': |
|
207
|
|
|
case 'tumblr': |
|
208
|
|
|
default: |
|
209
|
|
|
return ucfirst( $service_name ); |
|
210
|
|
|
break; |
|
|
|
|
|
|
211
|
|
|
} |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
function show_options_popup( $service_name, $c ) { |
|
215
|
|
|
$cmeta = $this->get_connection_meta( $c ); |
|
216
|
|
|
|
|
217
|
|
|
// always show if no selection has been made for facebook |
|
218
|
|
|
if ( 'facebook' == $service_name && empty( $cmeta['connection_data']['meta']['facebook_profile'] ) && empty( $cmeta['connection_data']['meta']['facebook_page'] ) ) |
|
219
|
|
|
return true; |
|
220
|
|
|
|
|
221
|
|
|
// always show if no selection has been made for tumblr |
|
222
|
|
|
if ( 'tumblr' == $service_name && empty ( $cmeta['connection_data']['meta']['tumblr_base_hostname'] ) ) |
|
223
|
|
|
return true; |
|
224
|
|
|
|
|
225
|
|
|
// if we have the specific connection info.. |
|
226
|
|
|
if ( isset( $_GET['id'] ) ) { |
|
227
|
|
|
if ( $cmeta['connection_data']['id'] == $_GET['id'] ) |
|
228
|
|
|
return true; |
|
229
|
|
|
} else { |
|
230
|
|
|
// otherwise, just show if this is the completed step / first load |
|
231
|
|
|
if ( !empty( $_GET['action'] ) && 'completed' == $_GET['action'] && !empty( $_GET['service'] ) && $service_name == $_GET['service'] && ! in_array( $_GET['service'], array( 'facebook', 'tumblr' ) ) ) |
|
232
|
|
|
return true; |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
return false; |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
function user_id() { |
|
239
|
|
|
global $current_user; |
|
240
|
|
|
return $current_user->ID; |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
function blog_id() { |
|
244
|
|
|
return get_current_blog_id(); |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
/** |
|
248
|
|
|
* Returns true if a user has a connection to a particular service, false otherwise |
|
249
|
|
|
*/ |
|
250
|
|
|
function is_enabled( $service, $_blog_id = false, $_user_id = false ) { |
|
251
|
|
|
if ( !$_blog_id ) |
|
252
|
|
|
$_blog_id = $this->blog_id(); |
|
253
|
|
|
|
|
254
|
|
|
if ( !$_user_id ) |
|
255
|
|
|
$_user_id = $this->user_id(); |
|
256
|
|
|
|
|
257
|
|
|
$connections = $this->get_connections( $service, $_blog_id, $_user_id ); |
|
258
|
|
|
return ( is_array( $connections ) && count( $connections ) > 0 ? true : false ); |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
/** |
|
262
|
|
|
* Fires when a post is saved, checks conditions and saves state in postmeta so that it |
|
263
|
|
|
* can be picked up later by @see ::publicize_post() |
|
264
|
|
|
*/ |
|
265
|
|
|
function save_meta( $post_id, $post ) { |
|
266
|
|
|
$cron_user = null; |
|
267
|
|
|
$submit_post = true; |
|
268
|
|
|
|
|
269
|
|
|
if ( ! $this->post_type_is_publicizeable( $post->post_type ) ) |
|
270
|
|
|
return; |
|
271
|
|
|
|
|
272
|
|
|
// Don't Publicize during certain contexts: |
|
273
|
|
|
|
|
274
|
|
|
// - import |
|
275
|
|
|
if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) { |
|
276
|
|
|
$submit_post = false; |
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
// - on quick edit, autosave, etc but do fire on p2, quickpress, and instapost ajax |
|
280
|
|
|
if ( |
|
281
|
|
|
defined( 'DOING_AJAX' ) |
|
282
|
|
|
&& |
|
283
|
|
|
DOING_AJAX |
|
284
|
|
|
&& |
|
285
|
|
|
!did_action( 'p2_ajax' ) |
|
286
|
|
|
&& |
|
287
|
|
|
!did_action( 'wp_ajax_json_quickpress_post' ) |
|
288
|
|
|
&& |
|
289
|
|
|
!did_action( 'wp_ajax_instapost_publish' ) |
|
290
|
|
|
&& |
|
291
|
|
|
!did_action( 'wp_ajax_post_reblog' ) |
|
292
|
|
|
) { |
|
293
|
|
|
$submit_post = false; |
|
294
|
|
|
} |
|
295
|
|
|
|
|
296
|
|
|
// - bulk edit |
|
297
|
|
|
if ( isset( $_GET['bulk_edit'] ) ) { |
|
298
|
|
|
$submit_post = false; |
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
|
|
// - API/XML-RPC Test Posts |
|
302
|
|
|
if ( |
|
303
|
|
|
( |
|
304
|
|
|
defined( 'XMLRPC_REQUEST' ) |
|
305
|
|
|
&& |
|
306
|
|
|
XMLRPC_REQUEST |
|
307
|
|
|
|| |
|
308
|
|
|
defined( 'APP_REQUEST' ) |
|
309
|
|
|
&& |
|
310
|
|
|
APP_REQUEST |
|
311
|
|
|
) |
|
312
|
|
|
&& |
|
313
|
|
|
0 === strpos( $post->post_title, 'Temporary Post Used For Theme Detection' ) |
|
314
|
|
|
) { |
|
315
|
|
|
$submit_post = false; |
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
|
// only work with certain statuses (avoids inherits, auto drafts etc) |
|
319
|
|
|
if ( !in_array( $post->post_status, array( 'publish', 'draft', 'future' ) ) ) { |
|
320
|
|
|
$submit_post = false; |
|
321
|
|
|
} |
|
322
|
|
|
|
|
323
|
|
|
// don't publish password protected posts |
|
324
|
|
|
if ( '' !== $post->post_password ) { |
|
325
|
|
|
$submit_post = false; |
|
326
|
|
|
} |
|
327
|
|
|
|
|
328
|
|
|
// Did this request happen via wp-admin? |
|
329
|
|
|
$from_web = 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST[$this->ADMIN_PAGE] ); |
|
330
|
|
|
|
|
331
|
|
|
if ( ( $from_web || defined( 'POST_BY_EMAIL' ) ) && isset( $_POST['wpas_title'] ) ) { |
|
332
|
|
|
if ( empty( $_POST['wpas_title'] ) ) { |
|
333
|
|
|
delete_post_meta( $post_id, $this->POST_MESS ); |
|
334
|
|
|
} else { |
|
335
|
|
|
update_post_meta( $post_id, $this->POST_MESS, trim( stripslashes( $_POST['wpas_title'] ) ) ); |
|
336
|
|
|
} |
|
337
|
|
|
} |
|
338
|
|
|
|
|
339
|
|
|
// change current user to provide context for get_services() if we're running during cron |
|
340
|
|
|
if ( defined( 'DOING_CRON' ) && DOING_CRON ) { |
|
341
|
|
|
$cron_user = (int) $GLOBALS['user_ID']; |
|
342
|
|
|
wp_set_current_user( $post->post_author ); |
|
343
|
|
|
} |
|
344
|
|
|
|
|
345
|
|
|
/** |
|
346
|
|
|
* In this phase, we mark connections that we want to SKIP. When Publicize is actually triggered, |
|
347
|
|
|
* it will Publicize to everything *except* those marked for skipping. |
|
348
|
|
|
*/ |
|
349
|
|
|
foreach ( (array) $this->get_services( 'connected' ) as $service_name => $connections ) { |
|
350
|
|
|
foreach ( $connections as $connection ) { |
|
351
|
|
|
$connection_data = ''; |
|
352
|
|
View Code Duplication |
if ( method_exists( $connection, 'get_meta' ) ) |
|
353
|
|
|
$connection_data = $connection->get_meta( 'connection_data' ); |
|
354
|
|
|
elseif ( ! empty( $connection['connection_data'] ) ) |
|
355
|
|
|
$connection_data = $connection['connection_data']; |
|
356
|
|
|
|
|
357
|
|
|
/** This action is documented in modules/publicize/ui.php */ |
|
358
|
|
|
if ( false == apply_filters( 'wpas_submit_post?', $submit_post, $post_id, $service_name, $connection_data ) ) { |
|
359
|
|
|
delete_post_meta( $post_id, $this->PENDING ); |
|
360
|
|
|
continue; |
|
361
|
|
|
} |
|
362
|
|
|
|
|
363
|
|
View Code Duplication |
if ( !empty( $connection->unique_id ) ) |
|
364
|
|
|
$unique_id = $connection->unique_id; |
|
365
|
|
|
else if ( !empty( $connection['connection_data']['token_id'] ) ) |
|
366
|
|
|
$unique_id = $connection['connection_data']['token_id']; |
|
367
|
|
|
|
|
368
|
|
|
// This was a wp-admin request, so we need to check the state of checkboxes |
|
369
|
|
|
if ( $from_web ) { |
|
370
|
|
|
// delete stray service-based post meta |
|
371
|
|
|
delete_post_meta( $post_id, $this->POST_SKIP . $service_name ); |
|
372
|
|
|
|
|
373
|
|
|
// We *unchecked* this stream from the admin page, or it's set to readonly, or it's a new addition |
|
374
|
|
|
if ( empty( $_POST[$this->ADMIN_PAGE]['submit'][$unique_id] ) ) { |
|
375
|
|
|
// Also make sure that the service-specific input isn't there. |
|
376
|
|
|
// If the user connected to a new service 'in-page' then a hidden field with the service |
|
377
|
|
|
// name is added, so we just assume they wanted to Publicize to that service. |
|
378
|
|
|
if ( empty( $_POST[$this->ADMIN_PAGE]['submit'][$service_name] ) ) { |
|
379
|
|
|
// Nothing seems to be checked, so we're going to mark this one to be skipped |
|
380
|
|
|
update_post_meta( $post_id, $this->POST_SKIP . $unique_id, 1 ); |
|
|
|
|
|
|
381
|
|
|
continue; |
|
382
|
|
|
} else { |
|
383
|
|
|
// clean up any stray post meta |
|
384
|
|
|
delete_post_meta( $post_id, $this->POST_SKIP . $unique_id ); |
|
385
|
|
|
} |
|
386
|
|
|
} else { |
|
387
|
|
|
// The checkbox for this connection is explicitly checked -- make sure we DON'T skip it |
|
388
|
|
|
delete_post_meta( $post_id, $this->POST_SKIP . $unique_id ); |
|
389
|
|
|
} |
|
390
|
|
|
} |
|
391
|
|
|
|
|
392
|
|
|
/** |
|
393
|
|
|
* Fires right before the post is processed for Publicize. |
|
394
|
|
|
* Users may hook in here and do anything else they need to after meta is written, |
|
395
|
|
|
* and before the post is processed for Publicize. |
|
396
|
|
|
* |
|
397
|
|
|
* @since 2.1.2 |
|
398
|
|
|
* |
|
399
|
|
|
* @param bool $submit_post Should the post be publicized. |
|
400
|
|
|
* @param int $post->ID Post ID. |
|
401
|
|
|
* @param string $service_name Service name. |
|
402
|
|
|
* @param array $connection Array of connection details. |
|
403
|
|
|
*/ |
|
404
|
|
|
do_action( 'publicize_save_meta', $submit_post, $post_id, $service_name, $connection ); |
|
405
|
|
|
} |
|
406
|
|
|
} |
|
407
|
|
|
|
|
408
|
|
|
if ( defined( 'DOING_CRON' ) && DOING_CRON ) { |
|
409
|
|
|
wp_set_current_user( $cron_user ); |
|
410
|
|
|
} |
|
411
|
|
|
|
|
412
|
|
|
// Next up will be ::publicize_post() |
|
413
|
|
|
} |
|
414
|
|
|
|
|
415
|
|
|
/** |
|
416
|
|
|
* Is a given post type Publicize-able? |
|
417
|
|
|
* |
|
418
|
|
|
* Not every CPT lends itself to Publicize-ation. Allow CPTs to register by adding their CPT via |
|
419
|
|
|
* the publicize_post_types array filter. |
|
420
|
|
|
* |
|
421
|
|
|
* @param string $post_type The post type to check. |
|
422
|
|
|
* $return bool True if the post type can be Publicized. |
|
423
|
|
|
*/ |
|
424
|
|
|
function post_type_is_publicizeable( $post_type ) { |
|
425
|
|
|
if ( 'post' == $post_type ) |
|
426
|
|
|
return true; |
|
427
|
|
|
|
|
428
|
|
|
return post_type_supports( $post_type, 'publicize' ); |
|
429
|
|
|
} |
|
430
|
|
|
|
|
431
|
|
|
/** |
|
432
|
|
|
* Runs tests on all the connections and returns the results to the caller |
|
433
|
|
|
*/ |
|
434
|
|
|
function test_publicize_conns() { |
|
435
|
|
|
$test_results = array(); |
|
436
|
|
|
|
|
437
|
|
|
foreach ( (array) $this->get_services( 'connected' ) as $service_name => $connections ) { |
|
438
|
|
|
foreach ( $connections as $connection ) { |
|
439
|
|
|
|
|
440
|
|
|
$id = $this->get_connection_id( $connection ); |
|
441
|
|
|
|
|
442
|
|
|
$connection_test_passed = true; |
|
443
|
|
|
$connection_test_message = __( 'This connection is working correctly.' , 'jetpack' ); |
|
444
|
|
|
$user_can_refresh = false; |
|
445
|
|
|
$refresh_text = ''; |
|
446
|
|
|
$refresh_url = ''; |
|
447
|
|
|
|
|
448
|
|
|
$connection_test_result = true; |
|
449
|
|
|
if ( method_exists( $this, 'test_connection' ) ) { |
|
450
|
|
|
$connection_test_result = $this->test_connection( $service_name, $connection ); |
|
451
|
|
|
} |
|
452
|
|
|
|
|
453
|
|
|
if ( is_wp_error( $connection_test_result ) ) { |
|
454
|
|
|
$connection_test_passed = false; |
|
455
|
|
|
$connection_test_message = $connection_test_result->get_error_message(); |
|
456
|
|
|
$error_data = $connection_test_result->get_error_data(); |
|
457
|
|
|
|
|
458
|
|
|
$user_can_refresh = $error_data['user_can_refresh']; |
|
459
|
|
|
$refresh_text = $error_data['refresh_text']; |
|
460
|
|
|
$refresh_url = $error_data['refresh_url']; |
|
461
|
|
|
} |
|
462
|
|
|
|
|
463
|
|
|
$test_results[] = array( |
|
464
|
|
|
'connectionID' => $id, |
|
465
|
|
|
'serviceName' => $service_name, |
|
466
|
|
|
'connectionTestPassed' => $connection_test_passed, |
|
467
|
|
|
'connectionTestMessage' => esc_attr( $connection_test_message ), |
|
468
|
|
|
'userCanRefresh' => $user_can_refresh, |
|
469
|
|
|
'refreshText' => esc_attr( $refresh_text ), |
|
470
|
|
|
'refreshURL' => $refresh_url |
|
471
|
|
|
); |
|
472
|
|
|
} |
|
473
|
|
|
} |
|
474
|
|
|
|
|
475
|
|
|
wp_send_json_success( $test_results ); |
|
476
|
|
|
} |
|
477
|
|
|
} |
|
478
|
|
|
|
This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.
The variable may have been renamed without also renaming all references.