No Description

publicize.php 42KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269
  1. <?php
  2. // phpcs:disable WordPress.NamingConventions.ValidVariableName
  3. use Automattic\Jetpack\Redirect;
  4. use Automattic\Jetpack\Status;
  5. abstract class Publicize_Base {
  6. /**
  7. * Services that are currently connected to the given user
  8. * through publicize.
  9. */
  10. public $connected_services = array();
  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. * key names for post meta
  18. */
  19. public $ADMIN_PAGE = 'wpas';
  20. public $POST_MESS = '_wpas_mess';
  21. /**
  22. * Post meta key for flagging when the post is a tweetstorm.
  23. *
  24. * @var string
  25. */
  26. public $POST_TWEETSTORM = '_wpas_is_tweetstorm';
  27. public $POST_SKIP = '_wpas_skip_'; // connection id appended to indicate that a connection should NOT be publicized to
  28. public $POST_DONE = '_wpas_done_'; // connection id appended to indicate a connection has already been publicized to
  29. public $USER_AUTH = 'wpas_authorize';
  30. public $USER_OPT = 'wpas_';
  31. public $PENDING = '_publicize_pending'; // ready for Publicize to do its thing
  32. public $POST_SERVICE_DONE = '_publicize_done_external'; // array of external ids where we've Publicized
  33. /**
  34. * default pieces of the message used in constructing the
  35. * content pushed out to other social networks
  36. */
  37. public $default_prefix = '';
  38. public $default_message = '%title%';
  39. public $default_suffix = ' ';
  40. /**
  41. * What WP capability is require to create/delete global connections?
  42. * All users with this cap can un-globalize all other global connections, and globalize any of their own
  43. * Globalized connections cannot be unselected by users without this capability when publishing
  44. */
  45. public $GLOBAL_CAP = 'publish_posts';
  46. /**
  47. * Sets up the basics of Publicize
  48. */
  49. function __construct() {
  50. $this->default_message = self::build_sprintf( array(
  51. /**
  52. * Filter the default Publicize message.
  53. *
  54. * @module publicize
  55. *
  56. * @since 2.0.0
  57. *
  58. * @param string $this->default_message Publicize's default message. Default is the post title.
  59. */
  60. apply_filters( 'wpas_default_message', $this->default_message ),
  61. 'title',
  62. 'url',
  63. ) );
  64. $this->default_prefix = self::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. $this->default_suffix = self::build_sprintf( array(
  78. /**
  79. * Filter the message appended to the Publicize custom message.
  80. *
  81. * @module publicize
  82. *
  83. * @since 2.0.0
  84. *
  85. * @param string $this->default_suffix String appended to the Publicize custom message.
  86. */
  87. apply_filters( 'wpas_default_suffix', $this->default_suffix ),
  88. 'url',
  89. ) );
  90. /**
  91. * Filter the capability to change global Publicize connection options.
  92. *
  93. * All users with this cap can un-globalize all other global connections, and globalize any of their own
  94. * Globalized connections cannot be unselected by users without this capability when publishing.
  95. *
  96. * @module publicize
  97. *
  98. * @since 2.2.1
  99. *
  100. * @param string $this->GLOBAL_CAP default capability in control of global Publicize connection options. Default to edit_others_posts.
  101. */
  102. $this->GLOBAL_CAP = apply_filters( 'jetpack_publicize_global_connections_cap', $this->GLOBAL_CAP );
  103. // stage 1 and 2 of 3-stage Publicize. Flag for Publicize on creation, save meta,
  104. // then check meta and publicize based on that. stage 3 implemented on wpcom
  105. add_action( 'transition_post_status', array( $this, 'flag_post_for_publicize' ), 10, 3 );
  106. add_action( 'save_post', array( &$this, 'save_meta' ), 20, 2 );
  107. // Default checkbox state for each Connection
  108. add_filter( 'publicize_checkbox_default', array( $this, 'publicize_checkbox_default' ), 10, 4 );
  109. // Alter the "Post Publish" admin notice to mention the Connections we Publicized to.
  110. add_filter( 'post_updated_messages', array( $this, 'update_published_message' ), 20, 1 );
  111. // Connection test callback
  112. add_action( 'wp_ajax_test_publicize_conns', array( $this, 'test_publicize_conns' ) );
  113. add_action( 'init', array( $this, 'add_post_type_support' ) );
  114. add_action( 'init', array( $this, 'register_post_meta' ), 20 );
  115. add_action( 'jetpack_register_gutenberg_extensions', array( $this, 'register_gutenberg_extension' ) );
  116. }
  117. /*
  118. * Services: Facebook, Twitter, etc.
  119. */
  120. /**
  121. * Get services for the given blog and user.
  122. *
  123. * Can return all available services or just the ones with an active connection.
  124. *
  125. * @param string $filter
  126. * 'all' (default) - Get all services available for connecting
  127. * 'connected' - Get all services currently connected
  128. * @param false|int $_blog_id The blog ID. Use false (default) for the current blog
  129. * @param false|int $_user_id The user ID. Use false (default) for the current user
  130. * @return array
  131. */
  132. abstract function get_services( $filter = 'all', $_blog_id = false, $_user_id = false );
  133. function can_connect_service( $service_name ) {
  134. return true;
  135. }
  136. /**
  137. * Does the given user have a connection to the service on the given blog?
  138. *
  139. * @param string $service_name 'facebook', 'twitter', etc.
  140. * @param false|int $_blog_id The blog ID. Use false (default) for the current blog
  141. * @param false|int $_user_id The user ID. Use false (default) for the current user
  142. * @return bool
  143. */
  144. function is_enabled( $service_name, $_blog_id = false, $_user_id = false ) {
  145. if ( !$_blog_id )
  146. $_blog_id = $this->blog_id();
  147. if ( !$_user_id )
  148. $_user_id = $this->user_id();
  149. $connections = $this->get_connections( $service_name, $_blog_id, $_user_id );
  150. return ( is_array( $connections ) && count( $connections ) > 0 ? true : false );
  151. }
  152. /**
  153. * Generates a connection URL.
  154. *
  155. * This is the URL, which, when visited by the user, starts the authentication
  156. * process required to forge a connection.
  157. *
  158. * @param string $service_name 'facebook', 'twitter', etc.
  159. * @return string
  160. */
  161. abstract function connect_url( $service_name );
  162. /**
  163. * Generates a Connection refresh URL.
  164. *
  165. * This is the URL, which, when visited by the user, re-authenticates their
  166. * connection to the service.
  167. *
  168. * @param string $service_name 'facebook', 'twitter', etc.
  169. * @return string
  170. */
  171. abstract function refresh_url( $service_name );
  172. /**
  173. * Generates a disconnection URL.
  174. *
  175. * This is the URL, which, when visited by the user, breaks their connection
  176. * with the service.
  177. *
  178. * @param string $service_name 'facebook', 'twitter', etc.
  179. * @param string $connection_id Connection ID
  180. * @return string
  181. */
  182. abstract function disconnect_url( $service_name, $connection_id );
  183. /**
  184. * Returns a display name for the Service
  185. *
  186. * @param string $service_name 'facebook', 'twitter', etc.
  187. * @return string
  188. */
  189. public static function get_service_label( $service_name ) {
  190. switch ( $service_name ) {
  191. case 'linkedin':
  192. return 'LinkedIn';
  193. break;
  194. case 'google_drive': // google-drive used to be called google_drive.
  195. case 'google-drive':
  196. return 'Google Drive';
  197. break;
  198. case 'twitter':
  199. case 'facebook':
  200. case 'tumblr':
  201. default:
  202. return ucfirst( $service_name );
  203. break;
  204. }
  205. }
  206. /*
  207. * Connections: For each Service, there can be multiple connections
  208. * for a given user. For example, one user could be connected to Twitter
  209. * as both @jetpack and as @wordpressdotcom
  210. *
  211. * For historical reasons, Connections are represented as an object
  212. * on WordPress.com and as an array in Jetpack.
  213. */
  214. /**
  215. * Get the active Connections of a Service
  216. *
  217. * @param string $service_name 'facebook', 'twitter', etc.
  218. * @param false|int $_blog_id The blog ID. Use false (default) for the current blog
  219. * @param false|int $_user_id The user ID. Use false (default) for the current user
  220. * @return false|object[]|array[] false if no connections exist
  221. */
  222. abstract function get_connections( $service_name, $_blog_id = false, $_user_id = false );
  223. /**
  224. * Get a single Connection of a Service
  225. *
  226. * @param string $service_name 'facebook', 'twitter', etc.
  227. * @param string $connection_id Connection ID
  228. * @param false|int $_blog_id The blog ID. Use false (default) for the current blog
  229. * @param false|int $_user_id The user ID. Use false (default) for the current user
  230. * @return false|object[]|array[] false if no connections exist
  231. */
  232. abstract function get_connection( $service_name, $connection_id, $_blog_id = false, $_user_id = false );
  233. /**
  234. * Get the Connection ID.
  235. *
  236. * Note that this is different than the Connection's uniqueid.
  237. *
  238. * Via a quirk of history, ID is globally unique and unique_id
  239. * is only unique per site.
  240. *
  241. * @param object|array The Connection object (WordPress.com) or array (Jetpack)
  242. * @return string
  243. */
  244. abstract function get_connection_id( $connection );
  245. /**
  246. * Get the Connection unique_id
  247. *
  248. * Note that this is different than the Connections ID.
  249. *
  250. * Via a quirk of history, ID is globally unique and unique_id
  251. * is only unique per site.
  252. *
  253. * @param object|array The Connection object (WordPress.com) or array (Jetpack)
  254. * @return string
  255. */
  256. abstract function get_connection_unique_id( $connection );
  257. /**
  258. * Get the Connection's Meta data
  259. *
  260. * @param object|array Connection
  261. * @return array Connection Meta
  262. */
  263. abstract function get_connection_meta( $connection );
  264. /**
  265. * Disconnect a Connection
  266. *
  267. * @param string $service_name 'facebook', 'twitter', etc.
  268. * @param string $connection_id Connection ID
  269. * @param false|int $_blog_id The blog ID. Use false (default) for the current blog
  270. * @param false|int $_user_id The user ID. Use false (default) for the current user
  271. * @param bool $force_delete Whether to skip permissions checks
  272. * @return false|void False on failure. Void on success.
  273. */
  274. abstract function disconnect( $service_name, $connection_id, $_blog_id = false, $_user_id = false, $force_delete = false );
  275. /**
  276. * Globalizes a Connection
  277. *
  278. * @param string $connection_id Connection ID
  279. * @return bool Falsey on failure. Truthy on success.
  280. */
  281. abstract function globalize_connection( $connection_id );
  282. /**
  283. * Unglobalizes a Connection
  284. *
  285. * @param string $connection_id Connection ID
  286. * @return bool Falsey on failure. Truthy on success.
  287. */
  288. abstract function unglobalize_connection( $connection_id );
  289. /**
  290. * Returns an external URL to the Connection's profile
  291. *
  292. * @param string $service_name 'facebook', 'twitter', etc.
  293. * @param object|array The Connection object (WordPress.com) or array (Jetpack)
  294. * @return false|string False on failure. URL on success.
  295. */
  296. function get_profile_link( $service_name, $connection ) {
  297. $cmeta = $this->get_connection_meta( $connection );
  298. if ( isset( $cmeta['connection_data']['meta']['link'] ) ) {
  299. if ( 'facebook' == $service_name && 0 === strpos( wp_parse_url( $cmeta['connection_data']['meta']['link'], PHP_URL_PATH ), '/app_scoped_user_id/' ) ) {
  300. // App-scoped Facebook user IDs are not usable profile links
  301. return false;
  302. }
  303. return $cmeta['connection_data']['meta']['link'];
  304. } elseif ( 'facebook' == $service_name && isset( $cmeta['connection_data']['meta']['facebook_page'] ) ) {
  305. return 'https://facebook.com/' . $cmeta['connection_data']['meta']['facebook_page'];
  306. } elseif ( 'tumblr' == $service_name && isset( $cmeta['connection_data']['meta']['tumblr_base_hostname'] ) ) {
  307. return 'https://' . $cmeta['connection_data']['meta']['tumblr_base_hostname'];
  308. } elseif ( 'twitter' == $service_name ) {
  309. return 'https://twitter.com/' . substr( $cmeta['external_display'], 1 ); // Has a leading '@'
  310. } else if ( 'linkedin' == $service_name ) {
  311. if ( !isset( $cmeta['connection_data']['meta']['profile_url'] ) ) {
  312. return false;
  313. }
  314. $profile_url_query = wp_parse_url( $cmeta['connection_data']['meta']['profile_url'], PHP_URL_QUERY );
  315. wp_parse_str( $profile_url_query, $profile_url_query_args );
  316. if ( isset( $profile_url_query_args['key'] ) ) {
  317. $id = $profile_url_query_args['key'];
  318. } elseif ( isset( $profile_url_query_args['id'] ) ) {
  319. $id = $profile_url_query_args['id'];
  320. } else {
  321. return false;
  322. }
  323. return esc_url_raw( add_query_arg( 'id', urlencode( $id ), 'https://www.linkedin.com/profile/view' ) );
  324. } else {
  325. return false; // no fallback. we just won't link it
  326. }
  327. }
  328. /**
  329. * Returns a display name for the Connection
  330. *
  331. * @param string $service_name 'facebook', 'twitter', etc.
  332. * @param object|array The Connection object (WordPress.com) or array (Jetpack)
  333. * @return string
  334. */
  335. function get_display_name( $service_name, $connection ) {
  336. $cmeta = $this->get_connection_meta( $connection );
  337. if ( isset( $cmeta['connection_data']['meta']['display_name'] ) ) {
  338. return $cmeta['connection_data']['meta']['display_name'];
  339. } elseif ( $service_name == 'tumblr' && isset( $cmeta['connection_data']['meta']['tumblr_base_hostname'] ) ) {
  340. return $cmeta['connection_data']['meta']['tumblr_base_hostname'];
  341. } elseif ( $service_name == 'twitter' ) {
  342. return $cmeta['external_display'];
  343. } else {
  344. $connection_display = $cmeta['external_display'];
  345. if ( empty( $connection_display ) )
  346. $connection_display = $cmeta['external_name'];
  347. return $connection_display;
  348. }
  349. }
  350. /**
  351. * Whether the user needs to select additional options after connecting
  352. *
  353. * @param string $service_name 'facebook', 'twitter', etc.
  354. * @param object|array The Connection object (WordPress.com) or array (Jetpack)
  355. * @return bool
  356. */
  357. function show_options_popup( $service_name, $connection ) {
  358. $cmeta = $this->get_connection_meta( $connection );
  359. // always show if no selection has been made for facebook
  360. if ( 'facebook' == $service_name && empty( $cmeta['connection_data']['meta']['facebook_profile'] ) && empty( $cmeta['connection_data']['meta']['facebook_page'] ) )
  361. return true;
  362. // always show if no selection has been made for tumblr
  363. if ( 'tumblr' == $service_name && empty ( $cmeta['connection_data']['meta']['tumblr_base_hostname'] ) )
  364. return true;
  365. // if we have the specific connection info..
  366. if ( isset( $_GET['id'] ) ) {
  367. if ( $cmeta['connection_data']['id'] == $_GET['id'] )
  368. return true;
  369. } else {
  370. // otherwise, just show if this is the completed step / first load
  371. if ( !empty( $_GET['action'] ) && 'completed' == $_GET['action'] && !empty( $_GET['service'] ) && $service_name == $_GET['service'] && ! in_array( $_GET['service'], array( 'facebook', 'tumblr' ) ) )
  372. return true;
  373. }
  374. return false;
  375. }
  376. /**
  377. * Whether the Connection is "valid" wrt Facebook's requirements.
  378. *
  379. * Must be connected to a Page (not a Profile).
  380. * (Also returns true if we're in the middle of the connection process)
  381. *
  382. * @param object|array The Connection object (WordPress.com) or array (Jetpack)
  383. * @return bool
  384. */
  385. function is_valid_facebook_connection( $connection ) {
  386. if ( $this->is_connecting_connection( $connection ) ) {
  387. return true;
  388. }
  389. $connection_meta = $this->get_connection_meta( $connection );
  390. $connection_data = $connection_meta['connection_data'];
  391. return isset( $connection_data[ 'meta' ][ 'facebook_page' ] );
  392. }
  393. /**
  394. * LinkedIn needs to be reauthenticated to use v2 of their API.
  395. * If it's using LinkedIn old API, it's an 'invalid' connection
  396. *
  397. * @param object|array The Connection object (WordPress.com) or array (Jetpack)
  398. * @return bool
  399. */
  400. function is_invalid_linkedin_connection( $connection ) {
  401. // LinkedIn API v1 included the profile link in the connection data.
  402. $connection_meta = $this->get_connection_meta( $connection );
  403. return isset( $connection_meta['connection_data']['meta']['profile_url'] );
  404. }
  405. /**
  406. * Whether the Connection currently being connected
  407. *
  408. * @param object|array The Connection object (WordPress.com) or array (Jetpack)
  409. * @return bool
  410. */
  411. function is_connecting_connection( $connection ) {
  412. $connection_meta = $this->get_connection_meta( $connection );
  413. $connection_data = $connection_meta['connection_data'];
  414. return isset( $connection_data[ 'meta' ]['options_responses'] );
  415. }
  416. /**
  417. * AJAX Handler to run connection tests on all Connections
  418. * @return void
  419. */
  420. function test_publicize_conns() {
  421. wp_send_json_success( $this->get_publicize_conns_test_results() );
  422. }
  423. /**
  424. * Run connection tests on all Connections
  425. *
  426. * @return array {
  427. * Array of connection test results.
  428. *
  429. * @type string 'connectionID' Connection identifier string that is unique for each connection
  430. * @type string 'serviceName' Slug of the connection's service (facebook, twitter, ...)
  431. * @type bool 'connectionTestPassed' Whether the connection test was successful
  432. * @type string 'connectionTestMessage' Test success or error message
  433. * @type bool 'userCanRefresh' Whether the user can re-authenticate their connection to the service
  434. * @type string 'refreshText' Message instructing user to re-authenticate their connection to the service
  435. * @type string 'refreshURL' URL, which, when visited by the user, re-authenticates their connection to the service.
  436. * @type string 'unique_id' ID string representing connection
  437. * }
  438. */
  439. function get_publicize_conns_test_results() {
  440. $test_results = array();
  441. foreach ( (array) $this->get_services( 'connected' ) as $service_name => $connections ) {
  442. foreach ( $connections as $connection ) {
  443. $id = $this->get_connection_id( $connection );
  444. $connection_test_passed = true;
  445. $connection_test_message = __( 'This connection is working correctly.' , 'jetpack' );
  446. $user_can_refresh = false;
  447. $refresh_text = '';
  448. $refresh_url = '';
  449. $connection_test_result = true;
  450. if ( method_exists( $this, 'test_connection' ) ) {
  451. $connection_test_result = $this->test_connection( $service_name, $connection );
  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. $user_can_refresh = $error_data['user_can_refresh'];
  458. $refresh_text = $error_data['refresh_text'];
  459. $refresh_url = $error_data['refresh_url'];
  460. }
  461. // Mark facebook profiles as deprecated
  462. if ( 'facebook' === $service_name ) {
  463. if ( ! $this->is_valid_facebook_connection( $connection ) ) {
  464. $connection_test_passed = false;
  465. $user_can_refresh = false;
  466. $connection_test_message = __( 'Please select a Facebook Page to publish updates.', 'jetpack' );
  467. }
  468. }
  469. // LinkedIn needs reauthentication to be compatible with v2 of their API
  470. if ( 'linkedin' === $service_name && $this->is_invalid_linkedin_connection( $connection ) ) {
  471. $connection_test_passed = 'must_reauth';
  472. $user_can_refresh = false;
  473. $connection_test_message = esc_html__( 'Your LinkedIn connection needs to be reauthenticated to continue working – head to Sharing to take care of it.', 'jetpack' );
  474. }
  475. $unique_id = null;
  476. if ( ! empty( $connection->unique_id ) ) {
  477. $unique_id = $connection->unique_id;
  478. } else if ( ! empty( $connection['connection_data']['token_id'] ) ) {
  479. $unique_id = $connection['connection_data']['token_id'];
  480. }
  481. $test_results[] = array(
  482. 'connectionID' => $id,
  483. 'serviceName' => $service_name,
  484. 'connectionTestPassed' => $connection_test_passed,
  485. 'connectionTestMessage' => esc_attr( $connection_test_message ),
  486. 'userCanRefresh' => $user_can_refresh,
  487. 'refreshText' => esc_attr( $refresh_text ),
  488. 'refreshURL' => $refresh_url,
  489. 'unique_id' => $unique_id,
  490. );
  491. }
  492. }
  493. return $test_results;
  494. }
  495. /**
  496. * Run the connection test for the Connection
  497. *
  498. * @param string $service_name 'facebook', 'twitter', etc.
  499. * @param object|array The Connection object (WordPress.com) or array (Jetpack)
  500. * @return WP_Error|true WP_Error on failure. True on success
  501. */
  502. abstract function test_connection( $service_name, $connection );
  503. /**
  504. * Retrieves current list of connections and applies filters.
  505. *
  506. * Retrieves current available connections and checks if the connections
  507. * have already been used to share current post. Finally, the checkbox
  508. * form UI fields are calculated. This function exposes connection form
  509. * data directly as array so it can be retrieved for static HTML generation
  510. * or JSON consumption.
  511. *
  512. * @since 6.7.0
  513. *
  514. * @param integer $selected_post_id Optional. Post ID to query connection status for.
  515. *
  516. * @return array {
  517. * Array of UI setup data for connection list form.
  518. *
  519. * @type string 'unique_id' ID string representing connection
  520. * @type string 'service_name' Slug of the connection's service (facebook, twitter, ...)
  521. * @type string 'service_label' Service Label (Facebook, Twitter, ...)
  522. * @type string 'display_name' Connection's human-readable Username: "@jetpack"
  523. * @type bool 'enabled' Default value for the connection (e.g., for a checkbox).
  524. * @type bool 'done' Has this connection already been publicized to?
  525. * @type bool 'toggleable' Is the user allowed to change the value for the connection?
  526. * @type bool 'global' Is this connection a global one?
  527. * }
  528. */
  529. public function get_filtered_connection_data( $selected_post_id = null ) {
  530. $connection_list = array();
  531. $post = get_post( $selected_post_id ); // Defaults to current post if $post_id is null.
  532. // Handle case where there is no current post.
  533. if ( ! empty( $post ) ) {
  534. $post_id = $post->ID;
  535. } else {
  536. $post_id = null;
  537. }
  538. $services = $this->get_services( 'connected' );
  539. $all_done = $this->post_is_done_sharing( $post_id );
  540. // We don't allow Publicizing to the same external id twice, to prevent spam.
  541. $service_id_done = (array) get_post_meta( $post_id, $this->POST_SERVICE_DONE, true );
  542. foreach ( $services as $service_name => $connections ) {
  543. foreach ( $connections as $connection ) {
  544. $connection_meta = $this->get_connection_meta( $connection );
  545. $connection_data = $connection_meta['connection_data'];
  546. $unique_id = $this->get_connection_unique_id( $connection );
  547. // Was this connection (OR, old-format service) already Publicized to?
  548. $done = ! empty( $post ) && (
  549. // New flags
  550. 1 == get_post_meta( $post->ID, $this->POST_DONE . $unique_id, true )
  551. ||
  552. // old flags
  553. 1 == get_post_meta( $post->ID, $this->POST_DONE . $service_name, true )
  554. );
  555. /**
  556. * Filter whether a post should be publicized to a given service.
  557. *
  558. * @module publicize
  559. *
  560. * @since 2.0.0
  561. *
  562. * @param bool true Should the post be publicized to a given service? Default to true.
  563. * @param int $post_id Post ID.
  564. * @param string $service_name Service name.
  565. * @param array $connection_data Array of information about all Publicize details for the site.
  566. */
  567. if ( ! apply_filters( 'wpas_submit_post?', true, $post_id, $service_name, $connection_data ) ) {
  568. continue;
  569. }
  570. // Should we be skipping this one?
  571. $skip = (
  572. (
  573. ! empty( $post )
  574. &&
  575. in_array( $post->post_status, array( 'publish', 'draft', 'future' ) )
  576. &&
  577. (
  578. // New flags
  579. get_post_meta( $post->ID, $this->POST_SKIP . $unique_id, true )
  580. ||
  581. // Old flags
  582. get_post_meta( $post->ID, $this->POST_SKIP . $service_name )
  583. )
  584. )
  585. ||
  586. (
  587. is_array( $connection )
  588. &&
  589. isset( $connection_meta['external_id'] ) && ! empty( $service_id_done[ $service_name ][ $connection_meta['external_id'] ] )
  590. )
  591. );
  592. // If this one has already been publicized to, don't let it happen again.
  593. $toggleable = ! $done && ! $all_done;
  594. // Determine the state of the checkbox (on/off) and allow filtering.
  595. $enabled = $done || ! $skip;
  596. /**
  597. * Filter the checkbox state of each Publicize connection appearing in the post editor.
  598. *
  599. * @module publicize
  600. *
  601. * @since 2.0.1
  602. *
  603. * @param bool $enabled Should the Publicize checkbox be enabled for a given service.
  604. * @param int $post_id Post ID.
  605. * @param string $service_name Service name.
  606. * @param array $connection Array of connection details.
  607. */
  608. $enabled = apply_filters( 'publicize_checkbox_default', $enabled, $post_id, $service_name, $connection );
  609. /**
  610. * If this is a global connection and this user doesn't have enough permissions to modify
  611. * those connections, don't let them change it.
  612. */
  613. if ( ! $done && ( 0 == $connection_data['user_id'] && ! current_user_can( $this->GLOBAL_CAP ) ) ) {
  614. $toggleable = false;
  615. /**
  616. * Filters the checkboxes for global connections with non-prilvedged users.
  617. *
  618. * @module publicize
  619. *
  620. * @since 3.7.0
  621. *
  622. * @param bool $enabled Indicates if this connection should be enabled. Default true.
  623. * @param int $post_id ID of the current post
  624. * @param string $service_name Name of the connection (Facebook, Twitter, etc)
  625. * @param array $connection Array of data about the connection.
  626. */
  627. $enabled = apply_filters( 'publicize_checkbox_global_default', $enabled, $post_id, $service_name, $connection );
  628. }
  629. // Force the checkbox to be checked if the post was DONE, regardless of what the filter does.
  630. if ( $done ) {
  631. $enabled = true;
  632. }
  633. $connection_list[] = array(
  634. 'unique_id' => $unique_id,
  635. 'service_name' => $service_name,
  636. 'service_label' => $this->get_service_label( $service_name ),
  637. 'display_name' => $this->get_display_name( $service_name, $connection ),
  638. 'enabled' => $enabled,
  639. 'done' => $done,
  640. 'toggleable' => $toggleable,
  641. 'global' => 0 == $connection_data['user_id'],
  642. );
  643. }
  644. }
  645. return $connection_list;
  646. }
  647. /**
  648. * Checks if post has already been shared by Publicize in the past.
  649. *
  650. * @since 6.7.0
  651. *
  652. * @param integer $post_id Optional. Post ID to query connection status for: will use current post if missing.
  653. *
  654. * @return bool True if post has already been shared by Publicize, false otherwise.
  655. */
  656. abstract public function post_is_done_sharing( $post_id = null );
  657. /**
  658. * Retrieves full list of available Publicize connection services.
  659. *
  660. * Retrieves current available publicize service connections
  661. * with associated labels and URLs.
  662. *
  663. * @since 6.7.0
  664. *
  665. * @return array {
  666. * Array of UI service connection data for all services
  667. *
  668. * @type string 'name' Name of service.
  669. * @type string 'label' Display label for service.
  670. * @type string 'url' URL for adding connection to service.
  671. * }
  672. */
  673. function get_available_service_data() {
  674. $available_services = $this->get_services( 'all' );
  675. $available_service_data = array();
  676. foreach ( $available_services as $service_name => $service ) {
  677. $available_service_data[] = array(
  678. 'name' => $service_name,
  679. 'label' => $this->get_service_label( $service_name ),
  680. 'url' => $this->connect_url( $service_name ),
  681. );
  682. }
  683. return $available_service_data;
  684. }
  685. /*
  686. * Site Data
  687. */
  688. function user_id() {
  689. return get_current_user_id();
  690. }
  691. function blog_id() {
  692. return get_current_blog_id();
  693. }
  694. /*
  695. * Posts
  696. */
  697. /**
  698. * Checks old and new status to see if the post should be flagged as
  699. * ready to Publicize.
  700. *
  701. * Attached to the `transition_post_status` filter.
  702. *
  703. * @param string $new_status
  704. * @param string $old_status
  705. * @param WP_Post $post
  706. * @return void
  707. */
  708. abstract function flag_post_for_publicize( $new_status, $old_status, $post );
  709. /**
  710. * Ensures the Post internal post-type supports `publicize`
  711. *
  712. * This feature support flag is used by the REST API.
  713. */
  714. function add_post_type_support() {
  715. add_post_type_support( 'post', 'publicize' );
  716. }
  717. /**
  718. * Register the Publicize Gutenberg extension
  719. */
  720. function register_gutenberg_extension() {
  721. // TODO: The `gutenberg/available-extensions` endpoint currently doesn't accept a post ID,
  722. // so we cannot pass one to `$this->current_user_can_access_publicize_data()`.
  723. if ( $this->current_user_can_access_publicize_data() ) {
  724. Jetpack_Gutenberg::set_extension_available( 'jetpack/publicize' );
  725. } else {
  726. Jetpack_Gutenberg::set_extension_unavailable( 'jetpack/publicize', 'unauthorized' );
  727. }
  728. }
  729. /**
  730. * Can the current user access Publicize Data.
  731. *
  732. * @param int $post_id. 0 for general access. Post_ID for specific access.
  733. * @return bool
  734. */
  735. function current_user_can_access_publicize_data( $post_id = 0 ) {
  736. /**
  737. * Filter what user capability is required to use the publicize form on the edit post page. Useful if publish post capability has been removed from role.
  738. *
  739. * @module publicize
  740. *
  741. * @since 4.1.0
  742. *
  743. * @param string $capability User capability needed to use publicize
  744. */
  745. $capability = apply_filters( 'jetpack_publicize_capability', 'publish_posts' );
  746. if ( 'publish_posts' === $capability && $post_id ) {
  747. return current_user_can( 'publish_post', $post_id );
  748. }
  749. return current_user_can( $capability );
  750. }
  751. /**
  752. * Auth callback for the protected ->POST_MESS post_meta
  753. *
  754. * @param bool $allowed
  755. * @param string $meta_key
  756. * @param int $object_id Post ID
  757. * @return bool
  758. */
  759. function message_meta_auth_callback( $allowed, $meta_key, $object_id ) {
  760. return $this->current_user_can_access_publicize_data( $object_id );
  761. }
  762. /**
  763. * Registers the post_meta for use in the REST API.
  764. *
  765. * Registers for each post type that with `publicize` feature support.
  766. */
  767. function register_post_meta() {
  768. $message_args = array(
  769. 'type' => 'string',
  770. 'description' => __( 'The message to use instead of the title when sharing to Publicize Services', 'jetpack' ),
  771. 'single' => true,
  772. 'default' => '',
  773. 'show_in_rest' => array(
  774. 'name' => 'jetpack_publicize_message',
  775. ),
  776. 'auth_callback' => array( $this, 'message_meta_auth_callback' ),
  777. );
  778. $tweetstorm_args = array(
  779. 'type' => 'boolean',
  780. 'description' => __( 'Whether or not the post should be treated as a Twitter thread.', 'jetpack' ),
  781. 'single' => true,
  782. 'default' => false,
  783. 'show_in_rest' => array(
  784. 'name' => 'jetpack_is_tweetstorm',
  785. ),
  786. 'auth_callback' => array( $this, 'message_meta_auth_callback' ),
  787. );
  788. foreach ( get_post_types() as $post_type ) {
  789. if ( ! $this->post_type_is_publicizeable( $post_type ) ) {
  790. continue;
  791. }
  792. $message_args['object_subtype'] = $post_type;
  793. $tweetstorm_args['object_subtype'] = $post_type;
  794. register_meta( 'post', $this->POST_MESS, $message_args );
  795. register_meta( 'post', $this->POST_TWEETSTORM, $tweetstorm_args );
  796. }
  797. }
  798. /**
  799. * Fires when a post is saved, checks conditions and saves state in postmeta so that it
  800. * can be picked up later by @see ::publicize_post() on WordPress.com codebase.
  801. *
  802. * Attached to the `save_post` action.
  803. *
  804. * @param int $post_id
  805. * @param WP_Post $post
  806. * @return void
  807. */
  808. function save_meta( $post_id, $post ) {
  809. $cron_user = null;
  810. $submit_post = true;
  811. if ( ! $this->post_type_is_publicizeable( $post->post_type ) )
  812. return;
  813. // Don't Publicize during certain contexts:
  814. // - import
  815. if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
  816. $submit_post = false;
  817. }
  818. // - on quick edit, autosave, etc but do fire on p2, quickpress, and instapost ajax
  819. if (
  820. defined( 'DOING_AJAX' )
  821. &&
  822. DOING_AJAX
  823. &&
  824. !did_action( 'p2_ajax' )
  825. &&
  826. !did_action( 'wp_ajax_json_quickpress_post' )
  827. &&
  828. !did_action( 'wp_ajax_instapost_publish' )
  829. &&
  830. !did_action( 'wp_ajax_post_reblog' )
  831. &&
  832. !did_action( 'wp_ajax_press-this-save-post' )
  833. ) {
  834. $submit_post = false;
  835. }
  836. // - bulk edit
  837. if ( isset( $_GET['bulk_edit'] ) ) {
  838. $submit_post = false;
  839. }
  840. // - API/XML-RPC Test Posts
  841. if (
  842. (
  843. defined( 'XMLRPC_REQUEST' )
  844. &&
  845. XMLRPC_REQUEST
  846. ||
  847. defined( 'APP_REQUEST' )
  848. &&
  849. APP_REQUEST
  850. )
  851. &&
  852. 0 === strpos( $post->post_title, 'Temporary Post Used For Theme Detection' )
  853. ) {
  854. $submit_post = false;
  855. }
  856. // only work with certain statuses (avoids inherits, auto drafts etc)
  857. if ( !in_array( $post->post_status, array( 'publish', 'draft', 'future' ) ) ) {
  858. $submit_post = false;
  859. }
  860. // don't publish password protected posts
  861. if ( '' !== $post->post_password ) {
  862. $submit_post = false;
  863. }
  864. // Did this request happen via wp-admin?
  865. $from_web = isset( $_SERVER['REQUEST_METHOD'] )
  866. &&
  867. 'post' == strtolower( $_SERVER['REQUEST_METHOD'] )
  868. &&
  869. isset( $_POST[$this->ADMIN_PAGE] );
  870. if ( ( $from_web || defined( 'POST_BY_EMAIL' ) ) && isset( $_POST['wpas_title'] ) ) {
  871. if ( empty( $_POST['wpas_title'] ) ) {
  872. delete_post_meta( $post_id, $this->POST_MESS );
  873. } else {
  874. update_post_meta( $post_id, $this->POST_MESS, trim( stripslashes( $_POST['wpas_title'] ) ) );
  875. }
  876. }
  877. // change current user to provide context for get_services() if we're running during cron
  878. if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
  879. $cron_user = (int) $GLOBALS['user_ID'];
  880. wp_set_current_user( $post->post_author );
  881. }
  882. /**
  883. * In this phase, we mark connections that we want to SKIP. When Publicize is actually triggered,
  884. * it will Publicize to everything *except* those marked for skipping.
  885. */
  886. foreach ( (array) $this->get_services( 'connected' ) as $service_name => $connections ) {
  887. foreach ( $connections as $connection ) {
  888. $connection_data = '';
  889. if ( is_object( $connection ) && method_exists( $connection, 'get_meta' ) ) {
  890. $connection_data = $connection->get_meta( 'connection_data' );
  891. } elseif ( ! empty( $connection['connection_data'] ) ) {
  892. $connection_data = $connection['connection_data'];
  893. }
  894. /** This action is documented in modules/publicize/ui.php */
  895. if ( false == apply_filters( 'wpas_submit_post?', $submit_post, $post_id, $service_name, $connection_data ) ) {
  896. delete_post_meta( $post_id, $this->PENDING );
  897. continue;
  898. }
  899. if ( !empty( $connection->unique_id ) )
  900. $unique_id = $connection->unique_id;
  901. else if ( !empty( $connection['connection_data']['token_id'] ) )
  902. $unique_id = $connection['connection_data']['token_id'];
  903. // This was a wp-admin request, so we need to check the state of checkboxes
  904. if ( $from_web ) {
  905. // delete stray service-based post meta
  906. delete_post_meta( $post_id, $this->POST_SKIP . $service_name );
  907. // We *unchecked* this stream from the admin page, or it's set to readonly, or it's a new addition
  908. if ( empty( $_POST[$this->ADMIN_PAGE]['submit'][$unique_id] ) ) {
  909. // Also make sure that the service-specific input isn't there.
  910. // If the user connected to a new service 'in-page' then a hidden field with the service
  911. // name is added, so we just assume they wanted to Publicize to that service.
  912. if ( empty( $_POST[$this->ADMIN_PAGE]['submit'][$service_name] ) ) {
  913. // Nothing seems to be checked, so we're going to mark this one to be skipped
  914. update_post_meta( $post_id, $this->POST_SKIP . $unique_id, 1 );
  915. continue;
  916. } else {
  917. // clean up any stray post meta
  918. delete_post_meta( $post_id, $this->POST_SKIP . $unique_id );
  919. }
  920. } else {
  921. // The checkbox for this connection is explicitly checked -- make sure we DON'T skip it
  922. delete_post_meta( $post_id, $this->POST_SKIP . $unique_id );
  923. }
  924. }
  925. /**
  926. * Fires right before the post is processed for Publicize.
  927. * Users may hook in here and do anything else they need to after meta is written,
  928. * and before the post is processed for Publicize.
  929. *
  930. * @since 2.1.2
  931. *
  932. * @param bool $submit_post Should the post be publicized.
  933. * @param int $post->ID Post ID.
  934. * @param string $service_name Service name.
  935. * @param array $connection Array of connection details.
  936. */
  937. do_action( 'publicize_save_meta', $submit_post, $post_id, $service_name, $connection );
  938. }
  939. }
  940. if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
  941. wp_set_current_user( $cron_user );
  942. }
  943. // Next up will be ::publicize_post()
  944. }
  945. /**
  946. * Alters the "Post Published" message to include information about where the post
  947. * was Publicized to.
  948. *
  949. * Attached to the `post_updated_messages` filter
  950. *
  951. * @param string[] $messages
  952. * @return string[]
  953. */
  954. public function update_published_message( $messages ) {
  955. global $post_type, $post_type_object, $post;
  956. if ( ! $this->post_type_is_publicizeable( $post_type ) ) {
  957. return $messages;
  958. }
  959. // Bail early if the post is private.
  960. if ( 'publish' !== $post->post_status ) {
  961. return $messages;
  962. }
  963. $view_post_link_html = '';
  964. $viewable = is_post_type_viewable( $post_type_object );
  965. if ( $viewable ) {
  966. $view_text = esc_html__( 'View post' ); // intentionally omitted domain
  967. if ( 'jetpack-portfolio' == $post_type ) {
  968. $view_text = esc_html__( 'View project', 'jetpack' );
  969. }
  970. $view_post_link_html = sprintf( ' <a href="%1$s">%2$s</a>',
  971. esc_url( get_permalink( $post ) ),
  972. $view_text
  973. );
  974. }
  975. $services = $this->get_publicizing_services( $post->ID );
  976. if ( empty( $services ) ) {
  977. return $messages;
  978. }
  979. $labels = array();
  980. foreach ( $services as $service_name => $display_names ) {
  981. $labels[] = sprintf(
  982. /* translators: Service name is %1$s, and account name is %2$s. */
  983. esc_html__( '%1$s (%2$s)', 'jetpack' ),
  984. esc_html( $service_name ),
  985. esc_html( implode( ', ', $display_names ) )
  986. );
  987. }
  988. $messages['post'][6] = sprintf(
  989. /* translators: %1$s is a comma-separated list of services and accounts. Ex. Facebook (@jetpack), Twitter (@jetpack) */
  990. esc_html__( 'Post published and sharing on %1$s.', 'jetpack' ),
  991. implode( ', ', $labels )
  992. ) . $view_post_link_html;
  993. if ( $post_type == 'post' && class_exists('Jetpack_Subscriptions' ) ) {
  994. $subscription = Jetpack_Subscriptions::init();
  995. if ( $subscription->should_email_post_to_subscribers( $post ) ) {
  996. $messages['post'][6] = sprintf(
  997. /* translators: %1$s is a comma-separated list of services and accounts. Ex. Facebook (@jetpack), Twitter (@jetpack) */
  998. esc_html__( 'Post published, sending emails to subscribers and sharing post on %1$s.', 'jetpack' ),
  999. implode( ', ', $labels )
  1000. ) . $view_post_link_html;
  1001. }
  1002. }
  1003. $messages['jetpack-portfolio'][6] = sprintf(
  1004. /* translators: %1$s is a comma-separated list of services and accounts. Ex. Facebook (@jetpack), Twitter (@jetpack) */
  1005. esc_html__( 'Project published and sharing project on %1$s.', 'jetpack' ),
  1006. implode( ', ', $labels )
  1007. ) . $view_post_link_html;
  1008. return $messages;
  1009. }
  1010. /**
  1011. * Get the Connections the Post was just Publicized to.
  1012. *
  1013. * Only reliable just after the Post was published.
  1014. *
  1015. * @param int $post_id
  1016. * @return string[] Array of Service display name => Connection display name
  1017. */
  1018. function get_publicizing_services( $post_id ) {
  1019. $services = array();
  1020. foreach ( (array) $this->get_services( 'connected' ) as $service_name => $connections ) {
  1021. // services have multiple connections.
  1022. foreach ( $connections as $connection ) {
  1023. $unique_id = '';
  1024. if ( ! empty( $connection->unique_id ) )
  1025. $unique_id = $connection->unique_id;
  1026. else if ( ! empty( $connection['connection_data']['token_id'] ) )
  1027. $unique_id = $connection['connection_data']['token_id'];
  1028. // Did we skip this connection?
  1029. if ( get_post_meta( $post_id, $this->POST_SKIP . $unique_id, true ) ) {
  1030. continue;
  1031. }
  1032. $services[ $this->get_service_label( $service_name ) ][] = $this->get_display_name( $service_name, $connection );
  1033. }
  1034. }
  1035. return $services;
  1036. }
  1037. /**
  1038. * Is the post Publicize-able?
  1039. *
  1040. * Only valid prior to Publicizing a Post.
  1041. *
  1042. * @param WP_Post $post
  1043. * @return bool
  1044. */
  1045. function post_is_publicizeable( $post ) {
  1046. if ( ! $this->post_type_is_publicizeable( $post->post_type ) )
  1047. return false;
  1048. // This is more a precaution. To only publicize posts that are published. (Mostly relevant for Jetpack sites)
  1049. if ( 'publish' !== $post->post_status ) {
  1050. return false;
  1051. }
  1052. // If it's not flagged as ready, then abort. @see ::flag_post_for_publicize()
  1053. if ( ! get_post_meta( $post->ID, $this->PENDING, true ) )
  1054. return false;
  1055. return true;
  1056. }
  1057. /**
  1058. * Is a given post type Publicize-able?
  1059. *
  1060. * Not every CPT lends itself to Publicize-ation. Allow CPTs to register by adding their CPT via
  1061. * the publicize_post_types array filter.
  1062. *
  1063. * @param string $post_type The post type to check.
  1064. * @return bool True if the post type can be Publicized.
  1065. */
  1066. function post_type_is_publicizeable( $post_type ) {
  1067. if ( 'post' == $post_type )
  1068. return true;
  1069. return post_type_supports( $post_type, 'publicize' );
  1070. }
  1071. /**
  1072. * Already-published posts should not be Publicized by default. This filter sets checked to
  1073. * false if a post has already been published.
  1074. *
  1075. * Attached to the `publicize_checkbox_default` filter
  1076. *
  1077. * @param bool $checked
  1078. * @param int $post_id
  1079. * @param string $service_name 'facebook', 'twitter', etc
  1080. * @param object|array The Connection object (WordPress.com) or array (Jetpack)
  1081. * @return bool
  1082. */
  1083. function publicize_checkbox_default( $checked, $post_id, $service_name, $connection ) {
  1084. if ( 'publish' == get_post_status( $post_id ) ) {
  1085. return false;
  1086. }
  1087. return $checked;
  1088. }
  1089. /*
  1090. * Util
  1091. */
  1092. /**
  1093. * Converts a Publicize message template string into a sprintf format string
  1094. *
  1095. * @param string[] $args
  1096. * 0 - The Publicize message template: 'Check out my post: %title% @ %url'
  1097. * ... - The template tags 'title', 'url', etc.
  1098. * @return string
  1099. */
  1100. protected static function build_sprintf( $args ) {
  1101. $search = array();
  1102. $replace = array();
  1103. foreach ( $args as $k => $arg ) {
  1104. if ( 0 == $k ) {
  1105. $string = $arg;
  1106. continue;
  1107. }
  1108. $search[] = "%$arg%";
  1109. $replace[] = "%$k\$s";
  1110. }
  1111. return str_replace( $search, $replace, $string );
  1112. }
  1113. }
  1114. function publicize_calypso_url() {
  1115. return Redirect::get_url( 'calypso-marketing-connections', array( 'site' => ( new Status() )->get_site_suffix() ) );
  1116. }