diff options
Diffstat (limited to 'plugins/jetpack/modules/sharedaddy/sharing-service.php')
-rw-r--r-- | plugins/jetpack/modules/sharedaddy/sharing-service.php | 49 |
1 files changed, 41 insertions, 8 deletions
diff --git a/plugins/jetpack/modules/sharedaddy/sharing-service.php b/plugins/jetpack/modules/sharedaddy/sharing-service.php index 823dd94d..f6d80dc3 100644 --- a/plugins/jetpack/modules/sharedaddy/sharing-service.php +++ b/plugins/jetpack/modules/sharedaddy/sharing-service.php @@ -1,6 +1,8 @@ <?php use Automattic\Jetpack\Assets; +use Automattic\Jetpack\Redirect; +use Automattic\Jetpack\Status; use Automattic\Jetpack\Sync\Settings; include_once dirname( __FILE__ ) . '/sharing-sources.php'; @@ -11,6 +13,15 @@ class Sharing_Service { private $global = false; public $default_sharing_label = ''; + /** + * Initialize the sharing service. + * Only run this method once upon module loading. + */ + public static function init() { + add_filter( 'the_content', 'sharing_display', 19 ); + add_filter( 'the_excerpt', 'sharing_display', 19 ); + } + public function __construct() { $this->default_sharing_label = __( 'Share this:', 'jetpack' ); } @@ -19,8 +30,7 @@ class Sharing_Service { * Gets a generic list of all services, without any config */ public function get_all_services_blog() { - $options = get_option( 'sharing-options' ); - + $options = get_option( 'sharing-options' ); $all = $this->get_all_services(); $services = array(); @@ -658,7 +668,7 @@ function sharing_process_requests() { global $post; // Only process if: single post and share=X defined - if ( ( is_page() || is_single() ) && isset( $_GET['share'] ) ) { + if ( ( is_page() || is_single() ) && isset( $_GET['share'] ) && is_string( $_GET['share'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $sharer = new Sharing_Service(); $service = $sharer->get_service( $_GET['share'] ); @@ -670,6 +680,15 @@ function sharing_process_requests() { add_action( 'template_redirect', 'sharing_process_requests', 9 ); /** + * Gets the url to customise the sharing buttons in Calypso. + * + * @return string the customisation URL or null if it couldn't be determinde. + */ +function get_sharing_buttons_customisation_url() { + return Redirect::get_url( 'calypso-marketing-sharing-buttons', array( 'site' => ( new Status() )->get_site_suffix() ) ); +} + +/** * Append sharing links to text. * * @param string $text The original text to append sharing links onto. @@ -765,6 +784,11 @@ function sharing_display( $text = '', $echo = false ) { $show = false; } + // Hide on password protected posts unless password is provided. + if ( post_password_required( $post->ID ) ) { + $show = false; + } + /** * Filter the Sharing buttons' Ajax action name Jetpack checks for. * This allows the use of the buttons with your own Ajax implementation. @@ -858,6 +882,15 @@ function sharing_display( $text = '', $echo = false ) { $sharing_content .= implode( '', $parts ); $sharing_content .= '<li class="share-end"></li></ul>'; + // Link to customization options if user can manage them. + if ( current_user_can( 'manage_options' ) ) { + $link_url = get_sharing_buttons_customisation_url(); + if ( ! empty( $link_url ) ) { + $link_text = __( 'Customize buttons', 'jetpack' ); + $sharing_content .= '<p class="share-customize-link"><a href="' . esc_url( $link_url ) . '" target="_blank" rel="noopener noreferrer">' . esc_html( $link_text ) . '</a></p>'; + } + } + if ( count( $enabled['hidden'] ) > 0 ) { $sharing_content .= '<div class="sharing-hidden"><div class="inner" style="display: none;'; @@ -904,7 +937,7 @@ function sharing_display( $text = '', $echo = false ) { if ( defined( 'JETPACK__VERSION' ) ) { $ver = JETPACK__VERSION; } else { - $ver = '20141212'; + $ver = '20211226'; } // @todo: Investigate if we can load this JS in the footer instead. @@ -914,7 +947,7 @@ function sharing_display( $text = '', $echo = false ) { '_inc/build/sharedaddy/sharing.min.js', 'modules/sharedaddy/sharing.js' ), - array( 'jquery' ), + array(), $ver, false ); @@ -944,8 +977,6 @@ function sharing_display( $text = '', $echo = false ) { } } -add_filter( 'the_content', 'sharing_display', 19 ); -add_filter( 'the_excerpt', 'sharing_display', 19 ); function get_base_recaptcha_lang_code() { $base_recaptcha_lang_code_mapping = array( @@ -963,7 +994,7 @@ function get_base_recaptcha_lang_code() { 'tr' => 'tr', ); - $blog_lang_code = function_exists( 'get_blog_lang_code' ) ? get_blog_lang_code() : get_bloginfo( 'language' ); + $blog_lang_code = get_bloginfo( 'language' ); if ( isset( $base_recaptcha_lang_code_mapping[ $blog_lang_code ] ) ) { return $base_recaptcha_lang_code_mapping[ $blog_lang_code ]; } @@ -971,3 +1002,5 @@ function get_base_recaptcha_lang_code() { // if no base mapping is found return default 'en' return 'en'; } + +Sharing_Service::init(); |