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