2020-05-06 17:20:49 +02:00
|
|
|
|
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
|
2019-11-15 23:26:29 +01:00
|
|
|
|
/**
|
|
|
|
|
|
* Module Name: Publicize
|
|
|
|
|
|
* Module Description: Publicize makes it easy to share your site’s posts on several social media networks automatically when you publish a new post.
|
|
|
|
|
|
* Sort Order: 10
|
|
|
|
|
|
* Recommendation Order: 7
|
|
|
|
|
|
* First Introduced: 2.0
|
|
|
|
|
|
* Requires Connection: Yes
|
|
|
|
|
|
* Auto Activate: No
|
|
|
|
|
|
* Module Tags: Social, Recommended
|
|
|
|
|
|
* Feature: Engagement
|
|
|
|
|
|
* Additional Search Queries: facebook, jetpack publicize, twitter, 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
|
|
|
|
*
|
|
|
|
|
|
* @package Jetpack.
|
2019-11-15 23:26:29 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
2020-05-06 17:20:49 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* Class Jetpack_Publicize
|
|
|
|
|
|
*/
|
2019-11-15 23:26:29 +01:00
|
|
|
|
class Jetpack_Publicize {
|
|
|
|
|
|
|
2020-05-06 17:20:49 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* If Publicize is executing within Jetpack.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @var bool
|
|
|
|
|
|
*/
|
2019-11-15 23:26:29 +01:00
|
|
|
|
public $in_jetpack = true;
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
$this->in_jetpack = ( class_exists( 'Jetpack' ) && method_exists( 'Jetpack', 'enable_module_configurable' ) ) ? true : false;
|
|
|
|
|
|
|
|
|
|
|
|
if ( $this->in_jetpack ) {
|
|
|
|
|
|
Jetpack::enable_module_configurable( __FILE__ );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-10 14:04:11 +01:00
|
|
|
|
require_once __DIR__ . '/publicize/publicize.php';
|
2019-11-15 23:26:29 +01:00
|
|
|
|
|
2020-05-06 17:20:49 +02:00
|
|
|
|
if ( $this->in_jetpack ) {
|
2020-12-10 14:04:11 +01:00
|
|
|
|
require_once __DIR__ . '/publicize/publicize-jetpack.php';
|
2020-05-06 17:20:49 +02:00
|
|
|
|
} else {
|
2020-12-10 14:04:11 +01:00
|
|
|
|
require_once dirname( __DIR__ ) . '/mu-plugins/keyring/keyring.php';
|
|
|
|
|
|
require_once __DIR__ . '/publicize/publicize-wpcom.php';
|
2019-11-15 23:26:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-10 14:04:11 +01:00
|
|
|
|
require_once __DIR__ . '/publicize/ui.php';
|
2020-05-06 17:20:49 +02:00
|
|
|
|
$publicize_ui = new Publicize_UI();
|
2019-11-15 23:26:29 +01:00
|
|
|
|
$publicize_ui->in_jetpack = $this->in_jetpack;
|
|
|
|
|
|
|
2020-05-06 17:20:49 +02:00
|
|
|
|
// Jetpack specific checks / hooks.
|
2019-11-15 23:26:29 +01:00
|
|
|
|
if ( $this->in_jetpack ) {
|
2020-05-06 17:20:49 +02:00
|
|
|
|
// if sharedaddy isn't active, the sharing menu hasn't been added yet.
|
2019-11-15 23:26:29 +01:00
|
|
|
|
$active = Jetpack::get_active_modules();
|
2020-05-06 17:20:49 +02:00
|
|
|
|
if ( in_array( 'publicize', $active, true ) && ! in_array( 'sharedaddy', $active, true ) ) {
|
2019-11-15 23:26:29 +01:00
|
|
|
|
add_action( 'admin_menu', array( &$publicize_ui, 'sharing_menu' ) );
|
|
|
|
|
|
}
|
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 );
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
2019-11-15 23:26:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
global $publicize_ui;
|
2020-05-06 17:20:49 +02:00
|
|
|
|
new Jetpack_Publicize();
|
2019-11-15 23:26:29 +01:00
|
|
|
|
|
2020-05-06 17:20:49 +02:00
|
|
|
|
if ( ! ( defined( 'IS_WPCOM' ) && IS_WPCOM ) && ! 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.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return Publicize Object
|
|
|
|
|
|
*/
|
|
|
|
|
|
function publicize_init() {
|
|
|
|
|
|
global $publicize;
|
2019-11-15 23:26:29 +01:00
|
|
|
|
|
2020-05-06 17:20:49 +02:00
|
|
|
|
if ( ! class_exists( 'Publicize' ) ) {
|
2020-12-10 14:04:11 +01:00
|
|
|
|
require_once __DIR__ . '/publicize/publicize.php';
|
2020-05-06 17:20:49 +02:00
|
|
|
|
}
|
2019-11-15 23:26:29 +01:00
|
|
|
|
|
2020-05-06 17:20:49 +02:00
|
|
|
|
return $publicize;
|
|
|
|
|
|
}
|
2019-11-15 23:26:29 +01:00
|
|
|
|
}
|