PluginProbe ʕ •ᴥ•ʔ
Jetpack – WP Security, Backup, Speed, & Growth / 14.6.1
Jetpack – WP Security, Backup, Speed, & Growth v14.6.1
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 14.4.2 14.5.1 14.6.1 14.7.1 14.8.1 14.9.2 15.0.3 15.1.2 15.2.1 15.3.2 15.4.1 15.5.1 15.6.1 15.7.2 15.8.1 15.9.2 16.0.2 16.1.3 16.2-a.5 16.2-a.3 16.1.2 16.2-a.1 16.1.1 16.1 16.1-beta 16.1-beta.2 16.1-beta.3 16.1-a.5 16.1-a.3 16.0.1 16.1-a.1 16.0 16.0-beta 16.0-a.7 16.0-a.5 15.9.1 16.0-a.3 16.0-a.1 15.9 15.9-beta 15.9-a.7 15.9-a.5 15.9-a.3 15.9-a.1 15.8 15.8-beta 15.8-a.7 15.8-a.5 5.2.5 5.3.4 5.4.4 5.5.5 5.6.5 5.7.5 5.8.4 5.9.4 6.0.4 6.1 6.1.1 6.1.2 6.1.3 6.1.4 6.1.5 6.2 6.2.1 6.2.2 6.2.3 6.2.4 6.2.5 6.3 6.3.1 6.3.2 6.3.3 6.3.4 6.3.5 6.3.6 6.3.7 6.4 6.4.1 6.4.2 6.4.3 6.4.4 6.4.5 6.4.6 6.5 6.5.1 6.5.2 6.5.3 6.5.4 6.6 6.6.1 6.6.2 6.6.3 6.6.4 6.6.5 6.7 6.7.1 6.7.2 6.7.3 6.7.4 6.8 6.8.1 6.8.2 6.8.3 6.8.4 6.8.5 6.9 6.9.1 6.9.2 6.9.3 6.9.4 7.0 7.0.1 7.0.2 7.0.3 7.0.4 7.0.5 7.1 7.1.1 7.1.2 7.1.3 7.1.4 7.1.5 7.2 7.2.1 7.2.1.1 7.2.2 7.2.3 7.2.4 7.2.5 7.3 7.3.0.1 7.3.1 7.3.1.1 7.3.2 7.3.3 7.3.4 7.3.5 7.4 7.4.1 7.4.2 7.4.3 7.4.4 7.4.5 7.5 7.5.0.1 7.5.1 7.5.2 7.5.3 7.5.4 7.5.5 7.5.6 7.5.7 7.6 7.6.1 7.6.2 7.6.3 7.6.4 7.7 7.7.1 7.7.2 7.7.3 7.7.4 7.7.5 7.7.6 7.8 7.8.1 7.8.2 7.8.3 7.8.4 7.9 7.9.1 7.9.2 7.9.3 7.9.4 8.0 8.0.1 8.0.2 8.0.3 8.1 8.1.1 8.1.2 8.1.3 8.1.4 8.2 8.2.0.1 8.2.1 8.2.2 8.2.3 8.2.4 8.2.5 8.2.6 8.3 8.3.1 8.3.2 8.3.3 8.4 8.4.1 8.4.2 8.4.3 8.4.4 8.4.5 8.5 8.5.1 8.5.2 8.5.3 8.6 8.6.1 8.6.2 8.6.3 8.6.4 8.7 8.7.0.1 8.7.1 8.7.2 8.7.3 8.7.4 8.8 8.8.1 8.8.2 8.8.3 8.8.4 8.8.5 8.9 8.9.1 8.9.2 8.9.3 8.9.4 9.0 9.0.1 9.0.2 9.0.3 9.0.4 9.0.5 9.1 9.1.1 9.1.2 9.1.3 9.2 9.2.1 9.2.2 9.2.3 9.2.4 9.3 9.3.1 9.3.2 9.3.3 9.3.4 9.3.5 9.4 9.4.1 9.4.2 9.4.3 9.4.4 9.5 9.5.1 9.5.2 9.5.3 9.5.4 9.5.5 9.6 9.6.1 9.6.2 9.6.3 9.6.4 9.7 9.7.1 9.7.2 15.7-beta.2 9.7.3 15.7.1 9.8 15.8-a.1 9.8.1 15.8-a.3 9.8.2 2.0.9 9.8.3 2.1.7 9.9 2.2.10 9.9.1 2.3.10 9.9.2 2.4.7 9.9.3 2.5.5 2.6.6 2.7.5 2.8.5 2.9.6 3.0.6 3.1.5 3.2.5 3.3.6 3.4.6 3.5.6 3.6.4 3.7.5 3.8.5 3.9.10 4.0.7 4.1.4 4.2.5 4.3.5 4.4.5 4.5.3 4.6.3 4.7.4 4.8.5 4.9.3 5.0.3 5.1.4 trunk 10.0 10.0.1 10.0.2 10.1 10.1.1 10.1.2 10.2 10.2.1 10.2.2 10.2.3 10.3 10.3.1 10.3.2 10.4 10.4.1 10.4.2 10.5 10.5.1 10.5.2 10.5.3 10.6 10.6.1 10.6.2 10.7 10.7.1 10.7.2 10.8 10.8.1 10.8.2 10.9 10.9.1 10.9.2 10.9.3 11.0 11.0.1 11.0.2 11.1 11.1.1 11.1.2 11.1.3 11.1.4 11.2 11.2.1 11.2.2 11.3 11.3.1 11.3.2 11.3.3 11.3.4 11.4 11.4.1 11.4.2 11.5 11.5.1 11.5.2 11.5.3 11.6 11.6.1 11.6.2 11.7 11.7.1 11.7.2 11.7.3 11.8 11.8.3 11.8.4 11.8.5 11.8.6 11.9 11.9.1 11.9.2 11.9.3 12.0 12.0.1 12.0.2 12.1 12.1.1 12.1.2 12.2 12.2.1 12.2.2 12.3 12.3.1 12.4 12.4.1 12.5 12.5.1 12.6 12.6.1 12.6.2 12.6.3 12.7 12.7.1 12.7.2 12.8 12.8.1 12.8.2 12.9 12.9.1 12.9.2 12.9.3 12.9.4 13.0 13.0.1 13.1 13.1.1 13.1.2 13.1.3 13.1.4 13.2 13.2.1 13.2.2 13.2.3 13.3 13.3.1 13.3.2 13.4 13.4.1 13.4.2 13.4.3 13.4.4 13.5 13.5.1 13.6 13.6.1 13.7 13.7.1 13.8 13.8.1 13.8.2 13.9 13.9.1 14.0 14.1 14.2 14.2.1 14.3 14.4 14.4.1 14.5 14.6 14.7 14.8 14.9 14.9.1 15.0 15.0.1 15.0.2 15.1 15.1.1 15.2 15.3 15.3.1 15.4 15.5 15.6 15.7 15.7-a.1 15.7-a.3 15.7-a.5 15.7-a.7 15.7-beta
jetpack / modules / sharedaddy / sharing.php
jetpack / modules / sharedaddy Last commit date
images 2 years ago services 1 year ago admin-sharing-rtl.css 1 year ago admin-sharing-rtl.min.css 1 year ago admin-sharing.css 1 year ago admin-sharing.js 1 year ago admin-sharing.min.css 1 year ago amp-sharing.css 1 year ago recaptcha.php 4 years ago sharedaddy.php 2 years ago sharing-service.php 1 year ago sharing-sources.php 1 year ago sharing.css 1 year ago sharing.js 3 years ago sharing.php 1 year ago
sharing.php
888 lines
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 /**
3 * Set up Sharing functionality and management in wp-admin.
4 *
5 * @package automattic/jetpack
6 */
7
8 // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files.
9
10 use Automattic\Jetpack\Assets;
11 use Automattic\Jetpack\Connection\Manager as Connection_Manager;
12 use Automattic\Jetpack\Redirect;
13 use Automattic\Jetpack\Status;
14
15 if ( ! defined( 'WP_SHARING_PLUGIN_URL' ) ) {
16 define( 'WP_SHARING_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
17 define( 'WP_SHARING_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
18 }
19
20 /**
21 * Utilities to manage sharing settings from wp-admin.
22 */
23 class Sharing_Admin {
24
25 /**
26 * Constructor.
27 * Hook into WordPress to add our functionality.
28 */
29 public function __construct() {
30 require_once WP_SHARING_PLUGIN_DIR . 'sharing-service.php';
31
32 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- nonces are handled in process_requests.
33 if ( isset( $_GET['page'] ) && ( $_GET['page'] === 'sharing.php' || $_GET['page'] === 'sharing' ) ) {
34 add_action( 'admin_init', array( $this, 'admin_init' ) );
35 }
36
37 add_action( 'admin_menu', array( $this, 'subscription_menu' ) );
38
39 // Insert our CSS and JS
40 add_action( 'load-settings_page_sharing', array( $this, 'sharing_head' ) );
41
42 // Catch AJAX
43 add_action( 'wp_ajax_sharing_save_services', array( $this, 'ajax_save_services' ) );
44 add_action( 'wp_ajax_sharing_save_options', array( $this, 'ajax_save_options' ) );
45 add_action( 'wp_ajax_sharing_new_service', array( $this, 'ajax_new_service' ) );
46 add_action( 'wp_ajax_sharing_delete_service', array( $this, 'ajax_delete_service' ) );
47 }
48
49 /**
50 * Enqueue scripts and styles on the sharing settings page.
51 *
52 * @return void
53 */
54 public function sharing_head() {
55 wp_enqueue_script(
56 'sharing-js',
57 Assets::get_file_url_for_environment(
58 '_inc/build/sharedaddy/admin-sharing.min.js',
59 'modules/sharedaddy/admin-sharing.js'
60 ),
61 array( 'jquery', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-form' ),
62 JETPACK__VERSION,
63 false
64 );
65
66 /**
67 * Filters the switch that if set to true allows Jetpack to use minified assets. Defaults to true
68 * if the SCRIPT_DEBUG constant is not set or set to false. The filter overrides it.
69 *
70 * @since 6.2.0
71 *
72 * @param boolean $var should Jetpack use minified assets.
73 */
74 $postfix = apply_filters( 'jetpack_should_use_minified_assets', true ) ? '.min' : '';
75 if ( is_rtl() ) {
76 wp_enqueue_style( 'sharing-admin', WP_SHARING_PLUGIN_URL . 'admin-sharing-rtl' . $postfix . '.css', false, JETPACK__VERSION );
77 } else {
78 wp_enqueue_style( 'sharing-admin', WP_SHARING_PLUGIN_URL . 'admin-sharing' . $postfix . '.css', false, JETPACK__VERSION );
79 }
80 wp_enqueue_style( 'sharing', WP_SHARING_PLUGIN_URL . 'sharing.css', false, JETPACK__VERSION );
81
82 wp_enqueue_style( 'social-logos' );
83 wp_enqueue_script( 'sharing-js-fe', WP_SHARING_PLUGIN_URL . 'sharing.js', array(), 4, false );
84 add_thickbox();
85
86 // On Jetpack sites, make sure we include CSS to style the admin page.
87 if ( ! defined( 'IS_WPCOM' ) || ! IS_WPCOM ) {
88 Jetpack_Admin_Page::load_wrapper_styles();
89 }
90 }
91
92 /**
93 * Load the process that handles saving changes on the sharing settings page.
94 *
95 * @return void
96 */
97 public function admin_init() {
98 $this->process_requests();
99 }
100
101 /**
102 * Save changes to sharing settings.
103 *
104 * @return void
105 */
106 public function process_requests() {
107 if (
108 isset( $_POST['_wpnonce'] )
109 && wp_verify_nonce( sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ), 'sharing-options' )
110 ) {
111 $sharer = new Sharing_Service();
112 $sharer->set_global_options( $_POST );
113 /**
114 * Fires when updating sharing settings.
115 *
116 * @module sharedaddy
117 *
118 * @since 1.1.0
119 */
120 do_action( 'sharing_admin_update' );
121
122 wp_safe_redirect( admin_url( 'options-general.php?page=sharing&update=saved' ) );
123 die( 0 );
124 }
125 }
126
127 /**
128 * Register Sharing settings menu page in offline mode or when wp-admin interface is enabled.
129 */
130 public function subscription_menu() {
131 $wpcom_is_wp_admin_interface = get_option( 'wpcom_admin_interface' ) === 'wp-admin';
132 $is_user_connected = ( new Connection_Manager() )->is_user_connected();
133
134 if (
135 ( new Status() )->is_offline_mode()
136 || $wpcom_is_wp_admin_interface
137 || ! $is_user_connected
138 ) {
139 add_submenu_page(
140 'options-general.php',
141 __( 'Sharing Settings', 'jetpack' ),
142 __( 'Sharing', 'jetpack' ),
143 'manage_options',
144 'sharing',
145 array( $this, 'wrapper_admin_page' )
146 );
147 }
148 }
149
150 /**
151 * Save changes to sharing services via AJAX.
152 *
153 * @return void
154 */
155 public function ajax_save_services() {
156 if (
157 isset( $_POST['_wpnonce'] )
158 && wp_verify_nonce( sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ), 'sharing-options' )
159 && isset( $_POST['hidden'] )
160 && isset( $_POST['visible'] )
161 ) {
162 $sharer = new Sharing_Service();
163
164 $sharer->set_blog_services(
165 explode( ',', sanitize_text_field( wp_unslash( $_POST['visible'] ) ) ),
166 explode( ',', sanitize_text_field( wp_unslash( $_POST['hidden'] ) ) )
167 );
168 die( 0 );
169 }
170 }
171
172 /**
173 * Create a new custom sharing service via AJAX.
174 *
175 * @return never
176 */
177 public function ajax_new_service() {
178 if (
179 isset( $_POST['_wpnonce'] )
180 && isset( $_POST['sharing_name'] )
181 && isset( $_POST['sharing_url'] )
182 && isset( $_POST['sharing_icon'] )
183 && wp_verify_nonce( sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ), 'sharing-new_service' )
184 ) {
185 $sharer = new Sharing_Service();
186 $service = $sharer->new_service(
187 sanitize_text_field( wp_unslash( $_POST['sharing_name'] ) ),
188 esc_url_raw( wp_unslash( $_POST['sharing_url'] ) ),
189 esc_url_raw( wp_unslash( $_POST['sharing_icon'] ) )
190 );
191
192 if ( $service ) {
193 $this->output_service( $service->get_id(), $service );
194 echo '<!--->';
195 $service->button_style = 'icon-text';
196 $this->output_preview( $service );
197
198 die( 0 );
199 }
200 }
201
202 // Fail
203 die( '1' );
204 }
205
206 /**
207 * Delete a sharing service via AJAX.
208 *
209 * @return void
210 */
211 public function ajax_delete_service() {
212 if (
213 isset( $_POST['_wpnonce'] )
214 && isset( $_POST['service'] )
215 && wp_verify_nonce(
216 sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ),
217 'sharing-options_' . sanitize_text_field( wp_unslash( $_POST['service'] ) )
218 )
219 ) {
220 $sharer = new Sharing_Service();
221 $sharer->delete_service( sanitize_text_field( wp_unslash( $_POST['service'] ) ) );
222 }
223 }
224
225 /**
226 * Save changes to sharing settings via AJAX.
227 *
228 * @return void
229 */
230 public function ajax_save_options() {
231 if (
232 isset( $_POST['_wpnonce'] )
233 && isset( $_POST['service'] )
234 && wp_verify_nonce(
235 sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ),
236 'sharing-options_' . sanitize_text_field( wp_unslash( $_POST['service'] ) )
237 )
238 ) {
239 $sharer = new Sharing_Service();
240 $service = $sharer->get_service( sanitize_text_field( wp_unslash( $_POST['service'] ) ) );
241
242 if ( $service && $service instanceof Sharing_Advanced_Source ) {
243 $service->update_options( $_POST );
244
245 $sharer->set_service( sanitize_text_field( wp_unslash( $_POST['service'] ) ), $service );
246 }
247
248 $this->output_service( $service->get_id(), $service, true );
249 echo '<!--->';
250 $service->button_style = 'icon-text';
251 $this->output_preview( $service );
252 die( 0 );
253 }
254 }
255
256 /**
257 * Display a preview of a sharing service.
258 *
259 * @param object $service Sharing service object.
260 *
261 * @return void
262 */
263 public function output_preview( $service ) {
264 $klasses = array( 'advanced', 'preview-item' );
265
266 if ( $service->button_style !== 'text' || $service->has_custom_button_style() ) {
267 $klasses[] = 'preview-' . $service->get_class();
268 $klasses[] = 'share-' . $service->get_class();
269 if ( $service->is_deprecated() ) {
270 $klasses[] = 'share-deprecated';
271 }
272
273 if ( $service->get_class() !== $service->get_id() ) {
274 $klasses[] = 'preview-' . $service->get_id();
275 }
276 }
277
278 echo '<li class="' . esc_attr( implode( ' ', $klasses ) ) . '">';
279 $service->display_preview();
280 echo '</li>';
281 }
282
283 /**
284 * Display a specific sharing service.
285 *
286 * @param int $id Service unique ID.
287 * @param object $service Sharing service.
288 * @param bool $show_dropdown Display a dropdown. Not in use at the moment.
289 *
290 * @return void
291 */
292 public function output_service( $id, $service, $show_dropdown = false ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
293 $title = '';
294 $klasses = array( 'service', 'advanced', 'share-' . $service->get_class() );
295 $displayed_klasses = implode( ' ', $klasses );
296
297 if ( $service->is_deprecated() ) {
298 /* translators: %1$s is the name of a deprecated Sharing Service like "Google+" */
299 $title = sprintf( __( 'The %1$s sharing service has shut down or discontinued support for sharing buttons. This sharing button is not displayed to your visitors and should be removed.', 'jetpack' ), $service->get_name() );
300 $klasses[] = 'share-deprecated';
301 }
302
303 ?>
304 <li class="<?php echo esc_attr( $displayed_klasses ); ?>" id="<?php echo esc_attr( $service->get_id() ); ?>" tabindex="0" title="<?php echo esc_attr( $title ); ?>">
305 <span class="options-left"><?php echo esc_html( $service->get_name() ); ?></span>
306 <?php if ( str_starts_with( $service->get_id(), 'custom-' ) || $service->has_advanced_options() ) : ?>
307 <span class="close"><a href="#" class="remove">&times;</a></span>
308 <form method="post" action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>">
309 <input type="hidden" name="action" value="sharing_delete_service" />
310 <input type="hidden" name="service" value="<?php echo esc_attr( $id ); ?>" />
311 <input type="hidden" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( 'sharing-options_' . $id ) ); ?>" />
312 </form>
313 <?php endif; ?>
314 </li>
315 <?php
316 }
317
318 /**
319 * Display admin UI within a Jetpack header and footer.
320 *
321 * @return void
322 */
323 public function wrapper_admin_page() {
324 Jetpack_Admin_Page::wrap_ui( array( $this, 'management_page' ), array( 'is-wide' => true ) );
325 }
326
327 /**
328 * Sharing settings inner page structure.
329 *
330 * @return void
331 */
332 public function management_page() {
333
334 if ( ! function_exists( 'mb_stripos' ) ) {
335 echo '<div id="message" class="updated fade"><h3>' . esc_html__( 'Warning! Multibyte support missing!', 'jetpack' ) . '</h3>';
336 echo '<p>' . wp_kses(
337 sprintf(
338 /* Translators: placeholder is a link to a PHP support document. */
339 __( 'This plugin will work without it, but multibyte support is used <a href="%s" rel="noopener noreferrer" target="_blank">if available</a>. You may see minor problems with Tweets and other sharing services.', 'jetpack' ),
340 'https://www.php.net/manual/en/mbstring.installation.php'
341 ),
342 array(
343 'a' => array(
344 'href' => array(),
345 'rel' => array(),
346 'target' => array(),
347 ),
348 )
349 ) . '</p></div>';
350 }
351
352 if ( isset( $_GET['update'] ) && 'saved' === $_GET['update'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- only used to display a message.
353 echo '<div class="updated"><p>' . esc_html__( 'Settings have been saved', 'jetpack' ) . '</p></div>';
354 }
355 ?>
356
357 <div class="wrap">
358 <div class="icon32" id="icon-options-general"><br /></div>
359 <h1><?php esc_html_e( 'Sharing Settings', 'jetpack' ); ?></h1>
360
361 <?php
362 /**
363 * Fires at the top of the admin sharing settings screen.
364 *
365 * @module sharedaddy
366 *
367 * @since 1.6.0
368 */
369 do_action( 'pre_admin_screen_sharing' );
370 ?>
371
372 <?php
373 $block_availability = Jetpack_Gutenberg::get_cached_availability();
374 $is_block_available = (bool) isset( $block_availability['sharing-buttons'] ) && $block_availability['sharing-buttons']['available'];
375 $is_block_theme = wp_is_block_theme();
376 $show_block_message = $is_block_available && $is_block_theme;
377
378 // We either show old services config or the sharing block message.
379 if ( current_user_can( 'manage_options' ) ) :
380 $show_block_message ? $this->sharing_block_display() : $this->services_config_display();
381 endif;
382 ?>
383 </div>
384
385 <script type="text/javascript">
386 var sharing_loading_icon = '<?php echo esc_js( admin_url( '/images/loading.gif' ) ); ?>';
387 <?php
388 // phpcs:disable WordPress.Security.NonceVerification.Recommended -- we handle the nonce on the PHP side.
389 if (
390 isset( $_GET['create_new_service'] ) && isset( $_GET['name'] ) && isset( $_GET['url'] ) && isset( $_GET['icon'] )
391 && 'true' == $_GET['create_new_service'] // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
392 ) :
393 ?>
394 jQuery(document).ready(function() {
395 // Prefill new service box and then open it
396 jQuery( '#new_sharing_name' ).val( '<?php echo esc_js( sanitize_text_field( wp_unslash( $_GET['name'] ) ) ); ?>' );
397 jQuery( '#new_sharing_url' ).val( '<?php echo esc_js( sanitize_text_field( wp_unslash( $_GET['url'] ) ) ); ?>' );
398 jQuery( '#new_sharing_icon' ).val( '<?php echo esc_js( sanitize_text_field( wp_unslash( $_GET['icon'] ) ) ); ?>' );
399 jQuery( '#add-a-new-service' ).click();
400 });
401 <?php endif; ?>
402 </script>
403 <?php
404 // phpcs:enable WordPress.Security.NonceVerification.Recommended
405 }
406
407 /**
408 * Display services admin UI for settings.
409 *
410 * @return void
411 */
412 public function services_config_display() {
413 $sharer = new Sharing_Service();
414 $enabled = $sharer->get_blog_services();
415 $global = $sharer->get_global_options();
416
417 $shows = array_values( get_post_types( array( 'public' => true ) ) );
418 array_unshift( $shows, 'index' );
419 if ( ! isset( $global['sharing_label'] ) ) {
420 $global['sharing_label'] = __( 'Share this:', 'jetpack' );
421 }
422 ?>
423 <div class="share_manage_options">
424 <h2><?php esc_html_e( 'Sharing Buttons', 'jetpack' ); ?></h2>
425 <p><?php esc_html_e( 'Add sharing buttons to your blog and allow your visitors to share posts with their friends.', 'jetpack' ); ?></p>
426
427 <div id="services-config">
428 <table id="available-services">
429 <tr>
430 <td class="description">
431 <h3><?php esc_html_e( 'Available Services', 'jetpack' ); ?></h3>
432 <p><?php esc_html_e( "Drag and drop the services you'd like to enable into the box below.", 'jetpack' ); ?></p>
433 <p><a href="#TB_inline?height=395&amp;width=600&amp;inlineId=new-service" class="thickbox" id="add-a-new-service"><?php esc_html_e( 'Add a new service', 'jetpack' ); ?></a></p>
434 </td>
435 <td class="services">
436 <ul class="services-available" style="height: 100px;">
437 <?php foreach ( $sharer->get_all_services_blog() as $id => $service ) : ?>
438 <?php
439 if ( ! isset( $enabled['all'][ $id ] ) ) {
440 $this->output_service( $id, $service );
441 }
442 ?>
443 <?php endforeach; ?>
444 </ul>
445 <?php
446 if ( ( new Status() )->is_private_site() ) {
447 echo '<p><strong>' . esc_html__( 'Please note that your services have been restricted because your site is private.', 'jetpack' ) . '</strong></p>';
448 }
449 ?>
450 <br class="clearing" />
451 </td>
452 </tr>
453 </table>
454
455 <table id="enabled-services">
456 <tr>
457 <td class="description">
458 <h3>
459 <?php esc_html_e( 'Enabled Services', 'jetpack' ); ?>
460 <img src="<?php echo esc_url( admin_url( 'images/loading.gif' ) ); ?>" width="16" height="16" alt="loading" style="vertical-align: middle; display: none" />
461 </h3>
462 <p><?php esc_html_e( 'Services dragged here will appear individually.', 'jetpack' ); ?></p>
463 </td>
464 <td class="services" id="share-drop-target">
465 <h2 id="drag-instructions"
466 <?php
467 if ( is_countable( $enabled['visible'] ) && count( $enabled['visible'] ) > 0 ) {
468 echo ' style="display: none"';}
469 ?>
470 ><?php esc_html_e( 'Drag and drop available services here.', 'jetpack' ); ?></h2>
471
472 <ul class="services-enabled">
473 <?php foreach ( $enabled['visible'] as $id => $service ) : ?>
474 <?php $this->output_service( $id, $service, true ); ?>
475 <?php endforeach; ?>
476
477 <li class="end-fix"></li>
478 </ul>
479 </td>
480 <td id="hidden-drop-target" class="services">
481 <p><?php esc_html_e( 'Services dragged here will be hidden behind a share button.', 'jetpack' ); ?></p>
482
483 <ul class="services-hidden">
484 <?php foreach ( $enabled['hidden'] as $id => $service ) : ?>
485 <?php $this->output_service( $id, $service, true ); ?>
486 <?php endforeach; ?>
487 <li class="end-fix"></li>
488 </ul>
489 </td>
490 </tr>
491 </table>
492
493 <table id="live-preview">
494 <tr>
495 <td class="description">
496 <h3><?php esc_html_e( 'Live Preview', 'jetpack' ); ?></h3>
497 </td>
498 <td class="services">
499 <h2 <?php echo ( is_countable( $enabled['all'] ) && count( $enabled['all'] ) > 0 ) ? ' style="display: none"' : ''; ?>><?php esc_html_e( 'Sharing is off. Add services above to enable.', 'jetpack' ); ?></h2>
500 <div class="sharedaddy sd-sharing-enabled">
501 <?php if ( is_countable( $enabled['all'] ) && count( $enabled['all'] ) > 0 ) : ?>
502 <h3 class="sd-title"><?php echo esc_html( $global['sharing_label'] ); ?></h3>
503 <?php endif; ?>
504 <div class="sd-content">
505 <ul class="preview">
506 <?php foreach ( $enabled['visible'] as $id => $service ) : ?>
507 <?php $this->output_preview( $service ); ?>
508 <?php endforeach; ?>
509
510 <?php if ( is_countable( $enabled['hidden'] ) && count( $enabled['hidden'] ) > 0 ) : ?>
511 <li class="advanced"><a href="#" class="sharing-anchor sd-button share-more"><span><?php esc_html_e( 'More', 'jetpack' ); ?></span></a></li>
512 <?php endif; ?>
513 </ul>
514
515 <?php if ( is_countable( $enabled['hidden'] ) && count( $enabled['hidden'] ) > 0 ) : ?>
516 <div class="sharing-hidden">
517 <div class="inner" style="display: none; <?php echo count( $enabled['hidden'] ) === 1 ? 'width:150px;' : ''; ?>">
518 <?php if ( count( $enabled['hidden'] ) === 1 ) : ?>
519 <ul style="background-image:none;">
520 <?php else : ?>
521 <ul>
522 <?php endif; ?>
523
524 <?php
525 foreach ( $enabled['hidden'] as $id => $service ) {
526 $this->output_preview( $service );
527 }
528 ?>
529 </ul>
530 </div>
531 </div>
532 <?php endif; ?>
533
534 <ul class="archive" style="display:none;">
535 <?php
536 foreach ( $sharer->get_all_services_blog() as $id => $service ) :
537 if ( isset( $enabled['visible'][ $id ] ) ) {
538 $service = $enabled['visible'][ $id ];
539 } elseif ( isset( $enabled['hidden'][ $id ] ) ) {
540 $service = $enabled['hidden'][ $id ];
541 }
542
543 $service->button_style = 'icon-text'; // The archive needs the full text, which is removed in JS later.
544 $service->smart = false;
545 $this->output_preview( $service );
546 endforeach;
547 ?>
548 <li class="advanced"><a href="#" class="sharing-anchor sd-button share-more"><span><?php esc_html_e( 'More', 'jetpack' ); ?></span></a></li>
549 </ul>
550 </div>
551 </div>
552 <br class="clearing" />
553 </td>
554 </tr>
555 </table>
556
557 <form method="post" action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" id="save-enabled-shares">
558 <input type="hidden" name="action" value="sharing_save_services" />
559 <input type="hidden" name="visible" value="<?php echo esc_attr( implode( ',', array_keys( $enabled['visible'] ) ) ); ?>" />
560 <input type="hidden" name="hidden" value="<?php echo esc_attr( implode( ',', array_keys( $enabled['hidden'] ) ) ); ?>" />
561 <input type="hidden" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( 'sharing-options' ) ); ?>" />
562 </form>
563 </div>
564
565 <form method="post" action="">
566 <table class="form-table">
567 <tbody>
568 <tr valign="top">
569 <th scope="row"><label><?php esc_html_e( 'Button style', 'jetpack' ); ?></label></th>
570 <td>
571 <select name="button_style" id="button_style">
572 <option<?php echo ( $global['button_style'] === 'icon-text' ) ? ' selected="selected"' : ''; ?> value="icon-text"><?php esc_html_e( 'Icon + text', 'jetpack' ); ?></option>
573 <option<?php echo ( $global['button_style'] === 'icon' ) ? ' selected="selected"' : ''; ?> value="icon"><?php esc_html_e( 'Icon only', 'jetpack' ); ?></option>
574 <option<?php echo ( $global['button_style'] === 'text' ) ? ' selected="selected"' : ''; ?> value="text"><?php esc_html_e( 'Text only', 'jetpack' ); ?></option>
575 <option<?php echo ( $global['button_style'] === 'official' ) ? ' selected="selected"' : ''; ?> value="official"><?php esc_html_e( 'Official buttons', 'jetpack' ); ?></option>
576 </select>
577 </td>
578 </tr>
579 <tr valign="top">
580 <th scope="row"><label><?php esc_html_e( 'Sharing label', 'jetpack' ); ?></label></th>
581 <td>
582 <input type="text" name="sharing_label" value="<?php echo esc_attr( $global['sharing_label'] ); ?>" />
583 </td>
584 </tr>
585 <?php
586 /**
587 * Filters the HTML at the beginning of the "Show button on" row.
588 *
589 * @module sharedaddy
590 *
591 * @since 2.1.0
592 *
593 * @param string $var Opening HTML tag at the beginning of the "Show button on" row.
594 */
595 echo apply_filters( 'sharing_show_buttons_on_row_start', '<tr valign="top">' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
596 ?>
597 <th scope="row"><label><?php esc_html_e( 'Show buttons on', 'jetpack' ); ?></label></th>
598 <td>
599 <?php
600 $br = false;
601 foreach ( $shows as $show ) :
602 if ( 'index' === $show ) {
603 $label = __( 'Front Page, Archive Pages, and Search Results', 'jetpack' );
604 } else {
605 $post_type_object = get_post_type_object( $show );
606 $label = $post_type_object->labels->name;
607 }
608 ?>
609 <?php
610 if ( $br ) {
611 echo '<br />';
612 }
613 ?>
614 <label><input type="checkbox"<?php checked( in_array( $show, $global['show'], true ) ); ?> name="show[]" value="<?php echo esc_attr( $show ); ?>" /> <?php echo esc_html( $label ); ?></label>
615 <?php
616 $br = true;
617 endforeach;
618 ?>
619 </td>
620 <?php
621 /**
622 * Filters the HTML at the end of the "Show button on" row.
623 *
624 * @module sharedaddy
625 *
626 * @since 2.1.0
627 *
628 * @param string $var Closing HTML tag at the end of the "Show button on" row.
629 */
630 echo apply_filters( 'sharing_show_buttons_on_row_end', '</tr>' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
631 ?>
632
633 <?php
634 /**
635 * Fires at the end of the sharing global options settings table.
636 *
637 * @module sharedaddy
638 *
639 * @since 1.1.0
640 */
641 do_action( 'sharing_global_options' );
642 ?>
643 </tbody>
644 </table>
645
646 <p class="submit">
647 <input type="submit" name="submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes', 'jetpack' ); ?>" />
648 </p>
649
650 <input type="hidden" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( 'sharing-options' ) ); ?>" />
651 </form>
652
653 <div id="new-service" style="display: none">
654 <form method="post" action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" id="new-service-form">
655 <table class="form-table">
656 <tbody>
657 <tr valign="top">
658 <th scope="row" width="100"><label><?php esc_html_e( 'Service name', 'jetpack' ); ?></label></th>
659 <td>
660 <input type="text" name="sharing_name" id="new_sharing_name" size="40" />
661 </td>
662 </tr>
663 <tr valign="top">
664 <th scope="row" width="100"><label><?php esc_html_e( 'Sharing URL', 'jetpack' ); ?></label></th>
665 <td>
666 <input type="text" name="sharing_url" id="new_sharing_url" size="40" />
667
668 <p><?php esc_html_e( 'You can add the following variables to your service sharing URL:', 'jetpack' ); ?><br/>
669 <code>%post_id%</code>, <code>%post_title%</code>, <code>%post_slug%</code>, <code>%post_url%</code>, <code>%post_full_url%</code>, <code>%post_excerpt%</code>, <code>%post_tags%</code>, <code>%home_url%</code></p>
670 </td>
671 </tr>
672 <tr valign="top">
673 <th scope="row" width="100"><label><?php esc_html_e( 'Icon URL', 'jetpack' ); ?></label></th>
674 <td>
675 <input type="text" name="sharing_icon" id="new_sharing_icon" size="40" />
676 <p><?php esc_html_e( 'Enter the URL of a 16x16px icon you want to use for this service.', 'jetpack' ); ?></p>
677 </td>
678 </tr>
679 <tr valign="top" width="100">
680 <th scope="row"></th>
681 <td>
682 <input type="submit" class="button-primary" value="<?php esc_attr_e( 'Create Share Button', 'jetpack' ); ?>" />
683 <img src="<?php echo esc_url( admin_url( 'images/loading.gif' ) ); ?>" width="16" height="16" alt="loading" style="vertical-align: middle; display: none" />
684 </td>
685 </tr>
686
687 <?php
688 /**
689 * Fires after the custom sharing service form
690 *
691 * @module sharedaddy
692 *
693 * @since 1.1.0
694 */
695 do_action( 'sharing_new_service_form' );
696 ?>
697 </tbody>
698 </table>
699
700 <?php
701 /**
702 * Fires at the bottom of the admin sharing settings screen.
703 *
704 * @module sharedaddy
705 *
706 * @since 1.6.0
707 */
708 do_action( 'post_admin_screen_sharing' );
709 ?>
710
711 <div class="inerror" style="display: none; margin-top: 15px">
712 <p><?php esc_html_e( 'An error occurred creating your new sharing service - please check you gave valid details.', 'jetpack' ); ?></p>
713 </div>
714
715 <input type="hidden" name="action" value="sharing_new_service" />
716 <input type="hidden" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( 'sharing-new_service' ) ); ?>" />
717 </form>
718 </div>
719 <?php
720 }
721
722 /**
723 * Display sharing block admin UI for settings.
724 *
725 * @return void
726 */
727 public function sharing_block_display() {
728 $showcase_services = array(
729 new Share_Tumblr( 'tumblr', array() ),
730 new Share_Facebook( 'facebook', array() ),
731 new Share_Email( 'email', array() ),
732 new Share_Reddit( 'reddit', array() ),
733 );
734
735 global $submenu;
736 // Hide the link to Jetpack Sharing settings if no Jetpack Settings found in submenu list
737 $show_jetpack_admin_settings_link = array_reduce(
738 $submenu['jetpack'],
739 function ( $carry, $item ) {
740 return $carry || ( isset( $item[2] ) && $item[2] === 'jetpack#/settings' );
741 },
742 false
743 );
744 ?>
745
746 <div class="share_manage_options">
747 <br class="clearing" />
748 <h2><?php esc_html_e( 'Sharing Buttons', 'jetpack' ); ?></h2>
749 <div class="sharing-block-message__items-wrapper">
750 <div>
751 <p><?php esc_html_e( 'Add sharing buttons to your blog and allow your visitors to share posts with their friends.', 'jetpack' ); ?></p>
752 <div class="sharing-block-message__buttons-wrapper">
753 <a href="<?php echo esc_url( admin_url( 'site-editor.php?path=%2Fwp_template' ) ); ?>" class="button button-primary">
754 <?php esc_html_e( 'Go to the site editor', 'jetpack' ); ?>
755 </a>
756 <a href="<?php echo esc_url( Redirect::get_url( 'jetpack-support-sharing-block' ) ); ?>" class="button" target="_blank" rel="noopener noreferrer">
757 <?php esc_html_e( 'Learn how to add Sharing Buttons', 'jetpack' ); ?>
758 </a>
759 </div>
760 </div>
761 <div>
762 <p><?php esc_html_e( 'Sharing Buttons example:', 'jetpack' ); ?></p>
763 <div class="sharedaddy sd-sharing-enabled">
764 <div class="sd-content">
765 <ul class="preview">
766 <?php foreach ( $showcase_services as $service ) : ?>
767 <?php $this->output_preview( $service ); ?>
768 <?php endforeach; ?>
769 </ul>
770 </div>
771 </div>
772 </div>
773 <?php if ( $show_jetpack_admin_settings_link ) : ?>
774 <p class="settings-sharing__block-theme-description">
775 <?php
776 printf(
777 wp_kses(
778 /* translators: Link to Jetpack sharing settings. */
779 __( 'You are using a block-based theme. You can <a class="dops-card__link" href="%s">disable Jetpack’s legacy sharing buttons</a> and add a sharing block to your theme’s template instead.', 'jetpack' ),
780 array(
781 'a' => array( 'href' => array() ),
782 )
783 ),
784 esc_url( admin_url( 'admin.php?page=jetpack#/sharing' ) )
785 );
786 ?>
787 </p>
788 <?php endif; ?>
789 </div>
790 <br class="clearing" />
791 </div>
792 <?php
793 }
794 }
795
796 /**
797 * Callback to get the value for the jetpack_sharing_enabled field.
798 *
799 * When the sharing_disabled post_meta is unset, we follow the global setting in Sharing.
800 * When it is set to 1, we disable sharing on the post, regardless of the global setting.
801 * It is not possible to enable sharing on a post if it is disabled globally.
802 *
803 * @param array $post The post object.
804 *
805 * @return bool
806 */
807 function jetpack_post_sharing_get_value( array $post ) {
808 if ( ! isset( $post['id'] ) ) {
809 return false;
810 }
811
812 // if sharing IS disabled on this post, enabled=false, so negate the meta
813 return (bool) ! get_post_meta( $post['id'], 'sharing_disabled', true );
814 }
815
816 /**
817 * Callback to set sharing_disabled post_meta when the
818 * jetpack_sharing_enabled field is updated.
819 *
820 * When the sharing_disabled post_meta is unset, we follow the global setting in Sharing.
821 * When it is set to 1, we disable sharing on the post, regardless of the global setting.
822 * It is not possible to enable sharing on a post if it is disabled globally.
823 *
824 * @param bool $enable_sharing Should sharing be enabled on this post.
825 * @param WP_Post $post_object The post object.
826 *
827 * @return int|bool
828 */
829 function jetpack_post_sharing_update_value( $enable_sharing, $post_object ) {
830 if ( $enable_sharing ) {
831 // delete the override if we want to enable sharing
832 return delete_post_meta( $post_object->ID, 'sharing_disabled' );
833 } else {
834 return update_post_meta( $post_object->ID, 'sharing_disabled', true );
835 }
836 }
837
838 /**
839 * Add Sharing post_meta to the REST API Post response.
840 *
841 * @action rest_api_init
842 * @uses register_rest_field
843 * @link https://developer.wordpress.org/rest-api/extending-the-rest-api/modifying-responses/
844 */
845 function jetpack_post_sharing_register_rest_field() {
846 $post_types = get_post_types( array( 'public' => true ) );
847 foreach ( $post_types as $post_type ) {
848 register_rest_field(
849 $post_type,
850 'jetpack_sharing_enabled',
851 array(
852 'get_callback' => 'jetpack_post_sharing_get_value',
853 'update_callback' => 'jetpack_post_sharing_update_value',
854 'schema' => array(
855 'description' => __( 'Are sharing buttons enabled?', 'jetpack' ),
856 'type' => 'boolean',
857 ),
858 )
859 );
860
861 /**
862 * Ensures all public internal post-types support `sharing`
863 * This feature support flag is used by the REST API and Gutenberg.
864 */
865 add_post_type_support( $post_type, 'jetpack-sharing-buttons' );
866 }
867 }
868
869 // Add Sharing post_meta to the REST API Post response.
870 add_action( 'rest_api_init', 'jetpack_post_sharing_register_rest_field' );
871
872 // Some CPTs (e.g. Jetpack portfolios and testimonials) get registered with
873 // restapi_theme_init because they depend on theme support, so let's also hook to that
874 add_action( 'restapi_theme_init', 'jetpack_post_likes_register_rest_field', 20 );
875
876 /**
877 * Initialize sharing settings in WP Admin.
878 *
879 * @return void
880 */
881 function sharing_admin_init() {
882 global $sharing_admin;
883
884 $sharing_admin = new Sharing_Admin();
885 }
886
887 add_action( 'init', 'sharing_admin_init' );
888