| 1 |
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 |
/** |
| 3 |
* Module Name: Jetpack Social |
| 4 |
* Module Description: Auto‑share your posts to social networks and track engagement in one place. |
| 5 |
* Sort Order: 10 |
| 6 |
* Recommendation Order: 7 |
| 7 |
* First Introduced: 2.0 |
| 8 |
* Requires Connection: Yes |
| 9 |
* Requires User Connection: Yes |
| 10 |
* Auto Activate: No |
| 11 |
* Module Tags: Social, Recommended |
| 12 |
* Feature: Engagement |
| 13 |
* Additional Search Queries: facebook, bluesky, threads, mastodon, instagram, jetpack publicize, tumblr, linkedin, social, tweet, connections, sharing, social media, automated, automated sharing, auto publish, auto tweet and like, auto tweet, facebook auto post, facebook posting |
| 14 |
* |
| 15 |
* @package automattic/jetpack |
| 16 |
*/ |
| 17 |
|
| 18 |
// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files. |
| 19 |
|
| 20 |
use Automattic\Jetpack\Status\Host; |
| 21 |
|
| 22 |
if ( ! defined( 'ABSPATH' ) ) { |
| 23 |
exit( 0 ); |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Class Jetpack_Publicize |
| 28 |
* |
| 29 |
* @phan-constructor-used-for-side-effects |
| 30 |
*/ |
| 31 |
class Jetpack_Publicize { |
| 32 |
/** |
| 33 |
* Jetpack_Publicize constructor. |
| 34 |
*/ |
| 35 |
public function __construct() { |
| 36 |
global $publicize_ui; |
| 37 |
|
| 38 |
if ( ! ( new Host() )->is_wpcom_simple() ) { |
| 39 |
Jetpack::enable_module_configurable( __FILE__ ); |
| 40 |
|
| 41 |
/* |
| 42 |
* The Publicize Options array does not currently have UI since it is being added |
| 43 |
* for a specific purpose and not part of a broader Publicize sprint. |
| 44 |
* |
| 45 |
* In order to pass the settings up to WordPress.com, we are updating an option to Sync will pass it up. |
| 46 |
* To make it relatively easy for use, we are creating a filter that checks if the option and filter match. |
| 47 |
* |
| 48 |
* This only runs when a post is saved to avoid it running too much. |
| 49 |
*/ |
| 50 |
add_action( |
| 51 |
'save_post', |
| 52 |
function () { |
| 53 |
$publicize_options = get_option( 'jetpack_publicize_options', array() ); |
| 54 |
|
| 55 |
/** |
| 56 |
* Filters the options for Publicize. |
| 57 |
* |
| 58 |
* As of Jetpack 8.5, the array keys could be: |
| 59 |
* attach_media bool If Publicize should send the image to the social media platform. Default false. |
| 60 |
* |
| 61 |
* @module publicize |
| 62 |
* |
| 63 |
* @since 8.5.0 |
| 64 |
* |
| 65 |
* @param array $options Array of Publicize options. |
| 66 |
*/ |
| 67 |
$filtered = (array) apply_filters( 'jetpack_publicize_options', $publicize_options ); |
| 68 |
|
| 69 |
if ( $publicize_options !== $filtered ) { |
| 70 |
update_option( 'jetpack_publicize_options', $filtered, false ); |
| 71 |
} |
| 72 |
} |
| 73 |
); |
| 74 |
} else { |
| 75 |
global $publicize; |
| 76 |
require_once WP_CONTENT_DIR . '/mu-plugins/keyring/keyring.php'; |
| 77 |
require_once WP_CONTENT_DIR . '/admin-plugins/publicize/publicize-wpcom.php'; |
| 78 |
$publicize = new \Publicize(); |
| 79 |
$publicize_ui = new Automattic\Jetpack\Publicize\Publicize_UI(); |
| 80 |
} |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
// On Jetpack, we instantiate Jetpack_Publicize only if the Publicize module is active. |
| 85 |
if ( ! ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ) { |
| 86 |
global $publicize; |
| 87 |
|
| 88 |
// None of this should be the case, but we can get here with a broken user connection. If that's the case |
| 89 |
// then we want to stop loading any more of the module code. |
| 90 |
if ( |
| 91 |
! Jetpack::is_module_active( 'publicize' ) |
| 92 |
|| ! Jetpack::connection()->has_connected_user() |
| 93 |
|| ! $publicize |
| 94 |
) { |
| 95 |
return; |
| 96 |
} |
| 97 |
|
| 98 |
new Jetpack_Publicize(); |
| 99 |
|
| 100 |
if ( ! function_exists( 'publicize_init' ) ) { |
| 101 |
/** |
| 102 |
* Helper for grabbing a Publicize object from the "front-end" (non-admin) of |
| 103 |
* a site. Normally Publicize is only loaded in wp-admin, so there's a little |
| 104 |
* set up that you might need to do if you want to use it on the front end. |
| 105 |
* Just call this function and it returns a Publicize object. |
| 106 |
* |
| 107 |
* @return \Automattic\Jetpack\Publicize\Publicize|\Publicize Object |
| 108 |
*/ |
| 109 |
function publicize_init() { |
| 110 |
global $publicize; |
| 111 |
|
| 112 |
return $publicize; |
| 113 |
} |
| 114 |
} |
| 115 |
} else { |
| 116 |
// On wpcom, instantiate Jetpack_Publicize without any other checks. |
| 117 |
new Jetpack_Publicize(); |
| 118 |
} |
| 119 |
|