PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 14.9
Jetpack – WP Security, Backup, Speed, & Growth v14.9
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / modules / publicize.php
publicize.php
115 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 /**
23 * Class Jetpack_Publicize
24 *
25 * @phan-constructor-used-for-side-effects
26 */
27 class Jetpack_Publicize {
28 /**
29 * Jetpack_Publicize constructor.
30 */
31 public function __construct() {
32 global $publicize_ui;
33
34 if ( ! ( new Host() )->is_wpcom_simple() ) {
35 Jetpack::enable_module_configurable( __FILE__ );
36
37 /*
38 * The Publicize Options array does not currently have UI since it is being added
39 * for a specific purpose and not part of a broader Publicize sprint.
40 *
41 * In order to pass the settings up to WordPress.com, we are updating an option to Sync will pass it up.
42 * To make it relatively easy for use, we are creating a filter that checks if the option and filter match.
43 *
44 * This only runs when a post is saved to avoid it running too much.
45 */
46 add_action(
47 'save_post',
48 function () {
49 $publicize_options = get_option( 'jetpack_publicize_options', array() );
50
51 /**
52 * Filters the options for Publicize.
53 *
54 * As of Jetpack 8.5, the array keys could be:
55 * attach_media bool If Publicize should send the image to the social media platform. Default false.
56 *
57 * @module publicize
58 *
59 * @since 8.5.0
60 *
61 * @param array $options Array of Publicize options.
62 */
63 $filtered = (array) apply_filters( 'jetpack_publicize_options', $publicize_options );
64
65 if ( $publicize_options !== $filtered ) {
66 update_option( 'jetpack_publicize_options', $filtered, false );
67 }
68 }
69 );
70 } else {
71 global $publicize;
72 require_once WP_CONTENT_DIR . '/mu-plugins/keyring/keyring.php';
73 require_once WP_CONTENT_DIR . '/admin-plugins/publicize/publicize-wpcom.php';
74 $publicize = new \Publicize();
75 $publicize_ui = new Automattic\Jetpack\Publicize\Publicize_UI();
76 }
77 }
78 }
79
80 // On Jetpack, we instantiate Jetpack_Publicize only if the Publicize module is active.
81 if ( ! ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ) {
82 global $publicize;
83
84 // None of this should be the case, but we can get here with a broken user connection. If that's the case
85 // then we want to stop loading any more of the module code.
86 if (
87 ! Jetpack::is_module_active( 'publicize' )
88 || ! Jetpack::connection()->has_connected_user()
89 || ! $publicize
90 ) {
91 return;
92 }
93
94 new Jetpack_Publicize();
95
96 if ( ! function_exists( 'publicize_init' ) ) {
97 /**
98 * Helper for grabbing a Publicize object from the "front-end" (non-admin) of
99 * a site. Normally Publicize is only loaded in wp-admin, so there's a little
100 * set up that you might need to do if you want to use it on the front end.
101 * Just call this function and it returns a Publicize object.
102 *
103 * @return \Automattic\Jetpack\Publicize\Publicize|\Publicize Object
104 */
105 function publicize_init() {
106 global $publicize;
107
108 return $publicize;
109 }
110 }
111 } else {
112 // On wpcom, instantiate Jetpack_Publicize without any other checks.
113 new Jetpack_Publicize();
114 }
115