kollapsminoriteten/wp-content/plugins/jetpack/modules/publicize.php

119 lines
3.8 KiB
PHP
Raw Permalink Normal View History

2020-05-06 17:20:49 +02:00
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2019-11-15 23:26:29 +01:00
/**
2022-12-15 17:41:53 +01:00
* Module Name: Jetpack Social
2025-07-27 19:58:08 +02:00
* Module Description: Autoshare your posts to social networks and track engagement in one place.
2019-11-15 23:26:29 +01:00
* Sort Order: 10
* Recommendation Order: 7
* First Introduced: 2.0
* Requires Connection: Yes
2021-04-27 08:32:47 +02:00
* Requires User Connection: Yes
2019-11-15 23:26:29 +01:00
* Auto Activate: No
* Module Tags: Social, Recommended
* Feature: Engagement
2025-02-28 08:42:11 +01:00
* 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
2020-05-06 17:20:49 +02:00
*
2021-04-27 08:32:47 +02:00
* @package automattic/jetpack
2019-11-15 23:26:29 +01:00
*/
2023-04-26 17:39:43 +02:00
// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files.
2025-04-25 12:30:07 +02:00
use Automattic\Jetpack\Status\Host;
2025-12-12 13:13:07 +01:00
if ( ! defined( 'ABSPATH' ) ) {
exit( 0 );
}
2020-05-06 17:20:49 +02:00
/**
* Class Jetpack_Publicize
2025-08-27 08:44:30 +02:00
*
* @phan-constructor-used-for-side-effects
2020-05-06 17:20:49 +02:00
*/
2019-11-15 23:26:29 +01:00
class Jetpack_Publicize {
2020-05-06 17:20:49 +02:00
/**
* Jetpack_Publicize constructor.
*/
public function __construct() {
2019-11-15 23:26:29 +01:00
global $publicize_ui;
2025-04-25 12:30:07 +02:00
if ( ! ( new Host() )->is_wpcom_simple() ) {
2019-11-15 23:26:29 +01:00
Jetpack::enable_module_configurable( __FILE__ );
2020-05-06 17:20:49 +02:00
/*
* The Publicize Options array does not currently have UI since it is being added
* for a specific purpose and not part of a broader Publicize sprint.
*
* In order to pass the settings up to WordPress.com, we are updating an option to Sync will pass it up.
* To make it relatively easy for use, we are creating a filter that checks if the option and filter match.
*
* This only runs when a post is saved to avoid it running too much.
*/
add_action(
'save_post',
2020-12-10 14:04:11 +01:00
function () {
2020-05-06 17:20:49 +02:00
$publicize_options = get_option( 'jetpack_publicize_options', array() );
/**
* Filters the options for Publicize.
*
* As of Jetpack 8.5, the array keys could be:
* attach_media bool If Publicize should send the image to the social media platform. Default false.
*
* @module publicize
*
* @since 8.5.0
*
* @param array $options Array of Publicize options.
*/
$filtered = (array) apply_filters( 'jetpack_publicize_options', $publicize_options );
if ( $publicize_options !== $filtered ) {
update_option( 'jetpack_publicize_options', $filtered, false );
}
}
);
2022-06-16 14:01:47 +02:00
} else {
2022-12-15 17:41:53 +01:00
global $publicize;
require_once WP_CONTENT_DIR . '/mu-plugins/keyring/keyring.php';
require_once WP_CONTENT_DIR . '/admin-plugins/publicize/publicize-wpcom.php';
2025-02-28 08:42:11 +01:00
$publicize = new \Publicize();
2022-12-15 17:41:53 +01:00
$publicize_ui = new Automattic\Jetpack\Publicize\Publicize_UI();
2019-11-15 23:26:29 +01:00
}
}
}
2022-06-16 14:01:47 +02:00
// On Jetpack, we instantiate Jetpack_Publicize only if the Publicize module is active.
if ( ! ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ) {
2022-12-15 17:41:53 +01:00
global $publicize;
// None of this should be the case, but we can get here with a broken user connection. If that's the case
// then we want to stop loading any more of the module code.
if (
2025-04-25 12:30:07 +02:00
! Jetpack::is_module_active( 'publicize' )
2022-12-15 17:41:53 +01:00
|| ! Jetpack::connection()->has_connected_user()
|| ! $publicize
) {
return;
2022-06-16 14:01:47 +02:00
}
2019-11-15 23:26:29 +01:00
2022-12-15 17:41:53 +01:00
new Jetpack_Publicize();
2022-06-16 14:01:47 +02:00
if ( ! function_exists( 'publicize_init' ) ) {
/**
* Helper for grabbing a Publicize object from the "front-end" (non-admin) of
* a site. Normally Publicize is only loaded in wp-admin, so there's a little
* set up that you might need to do if you want to use it on the front end.
* Just call this function and it returns a Publicize object.
*
2025-02-28 08:42:11 +01:00
* @return \Automattic\Jetpack\Publicize\Publicize|\Publicize Object
2022-06-16 14:01:47 +02:00
*/
function publicize_init() {
global $publicize;
return $publicize;
}
2020-05-06 17:20:49 +02:00
}
2022-06-16 14:01:47 +02:00
} else {
// On wpcom, instantiate Jetpack_Publicize without any other checks.
new Jetpack_Publicize();
2019-11-15 23:26:29 +01:00
}