PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.5
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.5
16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 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 All 506 releases
← All changes | modules/sharedaddy/sharing.php +82 -633 16.2-beta → 16.3-a.5 View file →
@@ -7,10 +7,12 @@
7 7
8 8 // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files.
9 9
10 10 use Automattic\Jetpack\Assets;
11 -use Automattic\Jetpack\Redirect;
12 -use Automattic\Jetpack\Status;
11 +use Automattic\Jetpack\Sharing_Likes\Settings\Post_Handler;
12 +use Automattic\Jetpack\Sharing_Likes\Settings\Services_Config;
13 +use Automattic\Jetpack\Sharing_Likes\Settings\Settings_Page;
14 +use Automattic\Jetpack\Status\Host;
13 15
14 16 if ( ! defined( 'ABSPATH' ) ) {
15 17 exit( 0 );
16 18 }
@@ -25,8 +27,15 @@
25 27 */
26 28 class Sharing_Admin {
27 29
28 30 /**
31 + * The services configuration UI.
32 + *
33 + * @var Services_Config
34 + */
35 + private $services_config;
36 +
37 + /**
29 38 * Constructor.
30 39 * Hook into WordPress to add our functionality.
31 40 */
32 41 public function __construct() {
@@ -31,23 +40,23 @@
31 40 */
32 41 public function __construct() {
33 42 require_once WP_SHARING_PLUGIN_DIR . 'sharing-service.php';
34 43
44 + $this->services_config = new Services_Config();
45 +
35 46 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- nonces are handled in process_requests.
36 - if ( isset( $_GET['page'] ) && ( $_GET['page'] === 'sharing.php' || $_GET['page'] === 'sharing' ) ) {
47 + if ( isset( $_GET['page'] ) && $_GET['page'] === 'sharing' ) {
37 48 add_action( 'admin_init', array( $this, 'admin_init' ) );
38 49 }
39 50
40 - add_action( 'admin_menu', array( $this, 'subscription_menu' ) );
41 -
42 51 // Insert our CSS and JS
43 52 add_action( 'load-settings_page_sharing', array( $this, 'sharing_head' ) );
44 53
45 54 // Catch AJAX
46 - add_action( 'wp_ajax_sharing_save_services', array( $this, 'ajax_save_services' ) );
47 - add_action( 'wp_ajax_sharing_save_options', array( $this, 'ajax_save_options' ) );
48 - add_action( 'wp_ajax_sharing_new_service', array( $this, 'ajax_new_service' ) );
49 - add_action( 'wp_ajax_sharing_delete_service', array( $this, 'ajax_delete_service' ) );
55 + add_action( 'wp_ajax_sharing_save_services', array( $this->services_config, 'ajax_save_services' ) );
56 + add_action( 'wp_ajax_sharing_save_options', array( $this->services_config, 'ajax_save_options' ) );
57 + add_action( 'wp_ajax_sharing_new_service', array( $this->services_config, 'ajax_new_service' ) );
58 + add_action( 'wp_ajax_sharing_delete_service', array( $this->services_config, 'ajax_delete_service' ) );
50 59 }
51 60
52 61 /**
53 62 * Enqueue scripts and styles on the sharing settings page.
@@ -65,8 +74,15 @@
65 74 JETPACK__VERSION,
66 75 false
67 76 );
68 77
78 + // admin-sharing.js reads this before it submits, so leaving it undefined breaks service removal.
79 + wp_add_inline_script(
80 + 'sharing-js',
81 + 'var sharing_loading_icon = ' . wp_json_encode( admin_url( '/images/loading.gif' ), JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ) . ';',
82 + 'before'
83 + );
84 +
69 85 /**
70 86 * Filters the switch that if set to true allows Jetpack to use minified assets. Defaults to true
71 87 * if the SCRIPT_DEBUG constant is not set or set to false. The filter overrides it.
72 88 *
@@ -84,13 +100,8 @@
84 100
85 101 wp_enqueue_style( 'social-logos' );
86 102 wp_enqueue_script( 'sharing-js-fe', WP_SHARING_PLUGIN_URL . 'sharing.js', array(), 4, false );
87 103 add_thickbox();
88 -
89 - // On Jetpack sites, make sure we include CSS to style the admin page.
90 - if ( ! defined( 'IS_WPCOM' ) || ! IS_WPCOM ) {
91 - Jetpack_Admin_Page::load_wrapper_styles();
92 - }
93 104 }
94 105
95 106 /**
96 107 * Load the process that handles saving changes on the sharing settings page.
@@ -97,188 +108,96 @@
97 108 *
98 109 * @return void
99 110 */
100 111 public function admin_init() {
101 - $this->process_requests();
112 + $this->services_config->process_requests();
102 113 }
103 114
104 115 /**
105 116 * Save changes to sharing settings.
106 117 *
118 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Services_Config::process_requests() instead.
119 + *
107 120 * @return void
108 121 */
109 122 public function process_requests() {
110 - if (
111 - isset( $_POST['_wpnonce'] )
112 - && wp_verify_nonce( sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ), 'sharing-options' )
113 - ) {
114 - $sharer = new Sharing_Service();
115 - $sharer->set_global_options( $_POST );
116 - /**
117 - * Fires when updating sharing settings.
118 - *
119 - * @module sharedaddy
120 - *
121 - * @since 1.1.0
122 - */
123 - do_action( 'sharing_admin_update' );
124 -
125 - wp_safe_redirect( admin_url( 'options-general.php?page=sharing&update=saved' ) );
126 - die( 0 );
127 - }
123 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Services_Config::process_requests' );
128 124 }
129 125
130 126 /**
131 127 * Register Sharing settings menu page in Settings > Sharing.
128 + *
129 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Settings_Page::register_menu() instead.
130 + *
131 + * @return void
132 132 */
133 133 public function subscription_menu() {
134 - add_submenu_page(
135 - 'options-general.php',
136 - __( 'Sharing Settings', 'jetpack' ),
137 - __( 'Sharing', 'jetpack' ),
138 - 'manage_options',
139 - 'sharing',
140 - array( $this, 'wrapper_admin_page' )
141 - );
134 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Settings_Page::register_menu' );
142 135 }
143 136
144 137 /**
145 138 * Save changes to sharing services via AJAX.
146 139 *
140 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Services_Config::ajax_save_services() instead.
141 + *
147 142 * @return void
148 143 */
149 144 public function ajax_save_services() {
150 - if (
151 - isset( $_POST['_wpnonce'] )
152 - && wp_verify_nonce( sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ), 'sharing-options' )
153 - && isset( $_POST['hidden'] )
154 - && isset( $_POST['visible'] )
155 - ) {
156 - $sharer = new Sharing_Service();
157 -
158 - $sharer->set_blog_services(
159 - explode( ',', sanitize_text_field( wp_unslash( $_POST['visible'] ) ) ),
160 - explode( ',', sanitize_text_field( wp_unslash( $_POST['hidden'] ) ) )
161 - );
162 - die( 0 );
163 - }
145 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Services_Config::ajax_save_services' );
164 146 }
165 147
166 148 /**
167 149 * Create a new custom sharing service via AJAX.
168 150 *
169 - * @return never
151 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Services_Config::ajax_new_service() instead.
152 + *
153 + * @return void
170 154 */
171 155 public function ajax_new_service() {
172 - if (
173 - isset( $_POST['_wpnonce'] )
174 - && isset( $_POST['sharing_name'] )
175 - && isset( $_POST['sharing_url'] )
176 - && isset( $_POST['sharing_icon'] )
177 - && wp_verify_nonce( sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ), 'sharing-new_service' )
178 - ) {
179 - $sharer = new Sharing_Service();
180 - $service = $sharer->new_service(
181 - sanitize_text_field( wp_unslash( $_POST['sharing_name'] ) ),
182 - esc_url_raw( wp_unslash( $_POST['sharing_url'] ) ),
183 - esc_url_raw( wp_unslash( $_POST['sharing_icon'] ) )
184 - );
185 -
186 - if ( $service ) {
187 - $this->output_service( $service->get_id(), $service );
188 - echo '<!--->';
189 - $service->button_style = 'icon-text';
190 - $this->output_preview( $service );
191 -
192 - die( 0 );
193 - }
194 - }
195 -
196 - // Fail
197 - die( '1' );
156 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Services_Config::ajax_new_service' );
198 157 }
199 158
200 159 /**
201 160 * Delete a sharing service via AJAX.
202 161 *
162 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Services_Config::ajax_delete_service() instead.
163 + *
203 164 * @return void
204 165 */
205 166 public function ajax_delete_service() {
206 - if (
207 - isset( $_POST['_wpnonce'] )
208 - && isset( $_POST['service'] )
209 - && wp_verify_nonce(
210 - sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ),
211 - 'sharing-options_' . sanitize_text_field( wp_unslash( $_POST['service'] ) )
212 - )
213 - ) {
214 - $sharer = new Sharing_Service();
215 - $sharer->delete_service( sanitize_text_field( wp_unslash( $_POST['service'] ) ) );
216 - }
167 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Services_Config::ajax_delete_service' );
217 168 }
218 169
219 170 /**
220 171 * Save changes to sharing settings via AJAX.
221 172 *
173 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Services_Config::ajax_save_options() instead.
174 + *
222 175 * @return void
223 176 */
224 177 public function ajax_save_options() {
225 - if (
226 - isset( $_POST['_wpnonce'] )
227 - && isset( $_POST['service'] )
228 - && wp_verify_nonce(
229 - sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ),
230 - 'sharing-options_' . sanitize_text_field( wp_unslash( $_POST['service'] ) )
231 - )
232 - ) {
233 - $sharer = new Sharing_Service();
234 - $service = $sharer->get_service( sanitize_text_field( wp_unslash( $_POST['service'] ) ) );
235 -
236 - if ( $service && $service instanceof Sharing_Advanced_Source ) {
237 - $service->update_options( $_POST );
238 -
239 - $sharer->set_service( sanitize_text_field( wp_unslash( $_POST['service'] ) ), $service );
240 - }
241 -
242 - $this->output_service( $service->get_id(), $service, true );
243 - echo '<!--->';
244 - $service->button_style = 'icon-text';
245 - $this->output_preview( $service );
246 - die( 0 );
247 - }
178 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Services_Config::ajax_save_options' );
248 179 }
249 180
250 181 /**
251 182 * Display a preview of a sharing service.
252 183 *
184 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Services_Config::output_preview() instead.
185 + *
253 186 * @param object $service Sharing service object.
254 187 *
255 188 * @return void
256 189 */
257 - public function output_preview( $service ) {
258 - $klasses = array( 'advanced', 'preview-item' );
259 -
260 - if ( $service->button_style !== 'text' || $service->has_custom_button_style() ) {
261 - $klasses[] = 'preview-' . $service->get_class();
262 - $klasses[] = 'share-' . $service->get_class();
263 - if ( $service->is_deprecated() ) {
264 - $klasses[] = 'share-deprecated';
265 - }
266 -
267 - if ( $service->get_class() !== $service->get_id() ) {
268 - $klasses[] = 'preview-' . $service->get_id();
269 - }
270 - }
271 -
272 - echo '<li class="' . esc_attr( implode( ' ', $klasses ) ) . '">';
273 - $service->display_preview();
274 - echo '</li>';
190 + public function output_preview( $service ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
191 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Services_Config::output_preview' );
275 192 }
276 193
277 194 /**
278 195 * Display a specific sharing service.
279 196 *
280 - * @param int $id Service unique ID.
197 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Services_Config::output_service() instead.
198 + *
199 + * @param string $id Service unique ID.
281 200 * @param object $service Sharing service.
282 201 * @param bool $show_dropdown Display a dropdown. Not in use at the moment.
283 202 *
284 203 * @return void
@@ -283,553 +202,76 @@
283 202 *
284 203 * @return void
285 204 */
286 205 public function output_service( $id, $service, $show_dropdown = false ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
287 - $title = '';
288 - $klasses = array( 'service', 'advanced', 'share-' . $service->get_class() );
289 - $displayed_klasses = implode( ' ', $klasses );
290 -
291 - if ( $service->is_deprecated() ) {
292 - /* translators: %1$s is the name of a deprecated Sharing Service like "Google+" */
293 - $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() );
294 - $klasses[] = 'share-deprecated';
295 - }
296 -
297 - ?>
298 - <li class="<?php echo esc_attr( $displayed_klasses ); ?>" id="<?php echo esc_attr( $service->get_id() ); ?>" tabindex="0" title="<?php echo esc_attr( $title ); ?>">
299 - <span class="options-left"><?php echo esc_html( $service->get_name() ); ?></span>
300 - <?php if ( str_starts_with( $service->get_id(), 'custom-' ) || $service->has_advanced_options() ) : ?>
301 - <span class="close"><a href="#" class="remove">&times;</a></span>
302 - <form method="post" action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>">
303 - <input type="hidden" name="action" value="sharing_delete_service" />
304 - <input type="hidden" name="service" value="<?php echo esc_attr( $id ); ?>" />
305 - <input type="hidden" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( 'sharing-options_' . $id ) ); ?>" />
306 - </form>
307 - <?php endif; ?>
308 - </li>
309 - <?php
206 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Services_Config::output_service' );
310 207 }
311 208
312 209 /**
313 210 * Display admin UI within a Jetpack header and footer.
314 211 *
212 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Settings_Page::render() instead.
213 + *
315 214 * @return void
316 215 */
317 216 public function wrapper_admin_page() {
318 - Jetpack_Admin_Page::wrap_ui( array( $this, 'management_page' ), array( 'is-wide' => true ) );
217 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Settings_Page::render' );
319 218 }
320 219
321 220 /**
322 221 * Sharing settings inner page structure.
323 222 *
223 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Settings_Page::render() instead.
224 + *
324 225 * @return void
325 226 */
326 227 public function management_page() {
327 -
328 - if ( ! function_exists( 'mb_stripos' ) ) {
329 - echo '<div id="message" class="updated fade"><h3>' . esc_html__( 'Warning! Multibyte support missing!', 'jetpack' ) . '</h3>';
330 - echo '<p>' . wp_kses(
331 - sprintf(
332 - /* Translators: placeholder is a link to a PHP support document. */
333 - __( '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' ),
334 - 'https://www.php.net/manual/en/mbstring.installation.php'
335 - ),
336 - array(
337 - 'a' => array(
338 - 'href' => array(),
339 - 'rel' => array(),
340 - 'target' => array(),
341 - ),
342 - )
343 - ) . '</p></div>';
344 - }
345 -
346 - if ( isset( $_GET['update'] ) && 'saved' === $_GET['update'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- only used to display a message.
347 - echo '<div class="updated"><p>' . esc_html__( 'Settings have been saved', 'jetpack' ) . '</p></div>';
348 - }
349 - ?>
350 -
351 - <div class="wrap">
352 - <div class="icon32" id="icon-options-general"><br /></div>
353 - <h1><?php esc_html_e( 'Sharing Settings', 'jetpack' ); ?></h1>
354 -
355 - <?php
356 - /**
357 - * Fires at the top of the admin sharing settings screen.
358 - *
359 - * @module sharedaddy
360 - *
361 - * @since 1.6.0
362 - */
363 - do_action( 'pre_admin_screen_sharing' );
364 - ?>
365 -
366 - <?php
367 - $is_simple_site = defined( 'IS_WPCOM' ) && IS_WPCOM;
368 - $show_block_message = $this->should_use_site_editor() && ! $is_simple_site;
369 -
370 - // We either show old services config or the sharing block message.
371 - if ( current_user_can( 'manage_options' ) ) :
372 - $show_block_message ? $this->sharing_block_display() : $this->services_config_display();
373 - endif;
374 - ?>
375 - </div>
376 -
377 - <script type="text/javascript">
378 - var sharing_loading_icon = <?php echo wp_json_encode( admin_url( '/images/loading.gif' ), JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ); ?>;
379 - <?php
380 - // phpcs:disable WordPress.Security.NonceVerification.Recommended -- we handle the nonce on the PHP side.
381 - if (
382 - isset( $_GET['create_new_service'] ) && isset( $_GET['name'] ) && isset( $_GET['url'] ) && isset( $_GET['icon'] )
383 - && 'true' == $_GET['create_new_service'] // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
384 - ) :
385 - ?>
386 - jQuery(document).ready(function() {
387 - // Prefill new service box and then open it
388 - jQuery( '#new_sharing_name' ).val( <?php echo wp_json_encode( sanitize_text_field( wp_unslash( $_GET['name'] ) ), JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ); ?> );
389 - jQuery( '#new_sharing_url' ).val( <?php echo wp_json_encode( sanitize_text_field( wp_unslash( $_GET['url'] ) ), JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ); ?> );
390 - jQuery( '#new_sharing_icon' ).val( <?php echo wp_json_encode( sanitize_text_field( wp_unslash( $_GET['icon'] ) ), JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ); ?> );
391 - jQuery( '#add-a-new-service' ).click();
392 - });
393 - <?php endif; ?>
394 - </script>
395 - <?php
396 - // phpcs:enable WordPress.Security.NonceVerification.Recommended
228 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Settings_Page::render' );
397 229 }
398 230
399 231 /**
400 232 * Check if we should encourage to use the site editor instead of the legacy sharing settings.
401 233 *
402 - * @return boolean
234 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Environment instead.
235 + *
236 + * @return bool
403 237 */
404 238 public function should_use_site_editor() {
405 - $block_availability = Jetpack_Gutenberg::get_cached_availability();
406 - $is_block_available = isset( $block_availability['sharing-buttons'] ) && $block_availability['sharing-buttons']['available'];
407 - $is_block_theme = wp_is_block_theme();
408 - return $is_block_available && $is_block_theme;
239 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Environment' );
240 + return false;
409 241 }
410 242
411 243 /**
412 244 * Display services admin UI for settings.
413 245 *
246 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Services_Config::render() instead.
247 + *
414 248 * @return void
415 249 */
416 250 public function services_config_display() {
417 - $sharer = new Sharing_Service();
418 - $enabled = $sharer->get_blog_services();
419 - $global = $sharer->get_global_options();
420 -
421 - $shows = array_values( get_post_types( array( 'public' => true ) ) );
422 - array_unshift( $shows, 'index' );
423 - if ( ! isset( $global['sharing_label'] ) ) {
424 - $global['sharing_label'] = __( 'Share this:', 'jetpack' );
425 - }
426 - ?>
427 - <div class="share_manage_options">
428 - <h2><?php esc_html_e( 'Sharing Buttons', 'jetpack' ); ?></h2>
429 - <p><?php esc_html_e( 'Add sharing buttons to your blog and allow your visitors to share posts with their friends.', 'jetpack' ); ?></p>
430 -
431 - <?php
432 - $is_simple_site = defined( 'IS_WPCOM' ) && IS_WPCOM;
433 - if ( $this->should_use_site_editor() && $is_simple_site ) :
434 - $this->site_editor_prompt_display();
435 - ?>
436 - <div class="notice notice-info inline">
437 - <p>
438 - <?php esc_html_e( 'You are using a block-based theme. We recommend that you disable the legacy sharing features below and add a sharing button block to your theme’s template instead.', 'jetpack' ); ?>
439 - </p>
440 - </div>
441 - <?php
442 - endif;
443 - ?>
444 -
445 - <div id="services-config">
446 - <table id="available-services">
447 - <tr>
448 - <td class="description">
449 - <h3><?php esc_html_e( 'Available Services', 'jetpack' ); ?></h3>
450 - <p><?php esc_html_e( "Drag and drop the services you'd like to enable into the box below.", 'jetpack' ); ?></p>
451 - <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>
452 - </td>
453 - <td class="services">
454 - <ul class="services-available" style="height: 100px;">
455 - <?php foreach ( $sharer->get_all_services_blog() as $id => $service ) : ?>
456 - <?php
457 - if ( ! isset( $enabled['all'][ $id ] ) ) {
458 - $this->output_service( $id, $service );
459 - }
460 - ?>
461 - <?php endforeach; ?>
462 - </ul>
463 - <?php
464 - if ( ( new Status() )->is_private_site() ) {
465 - echo '<p><strong>' . esc_html__( 'Please note that your services have been restricted because your site is private.', 'jetpack' ) . '</strong></p>';
466 - }
467 - ?>
468 - <br class="clearing" />
469 - </td>
470 - </tr>
471 - </table>
472 -
473 - <table id="enabled-services">
474 - <tr>
475 - <td class="description">
476 - <h3>
477 - <?php esc_html_e( 'Enabled Services', 'jetpack' ); ?>
478 - <span class="spinner" style="vertical-align: middle"></span>
479 - </h3>
480 - <p><?php esc_html_e( 'Services dragged here will appear individually.', 'jetpack' ); ?></p>
481 - </td>
482 - <td class="services" id="share-drop-target">
483 - <h2 id="drag-instructions"
484 - <?php
485 - if ( is_countable( $enabled['visible'] ) && count( $enabled['visible'] ) > 0 ) {
486 - echo ' style="display: none"';}
487 - ?>
488 - ><?php esc_html_e( 'Drag and drop available services here.', 'jetpack' ); ?></h2>
489 -
490 - <ul class="services-enabled">
491 - <?php foreach ( $enabled['visible'] as $id => $service ) : ?>
492 - <?php $this->output_service( $id, $service, true ); ?>
493 - <?php endforeach; ?>
494 -
495 - <li class="end-fix"></li>
496 - </ul>
497 - </td>
498 - <td id="hidden-drop-target" class="services">
499 - <p><?php esc_html_e( 'Services dragged here will be hidden behind a share button.', 'jetpack' ); ?></p>
500 -
501 - <ul class="services-hidden">
502 - <?php foreach ( $enabled['hidden'] as $id => $service ) : ?>
503 - <?php $this->output_service( $id, $service, true ); ?>
504 - <?php endforeach; ?>
505 - <li class="end-fix"></li>
506 - </ul>
507 - </td>
508 - </tr>
509 - </table>
510 -
511 - <table id="live-preview">
512 - <tr>
513 - <td class="description">
514 - <h3><?php esc_html_e( 'Live Preview', 'jetpack' ); ?></h3>
515 - </td>
516 - <td class="services">
517 - <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>
518 - <div class="sharedaddy sd-sharing-enabled">
519 - <?php if ( is_countable( $enabled['all'] ) && count( $enabled['all'] ) > 0 ) : ?>
520 - <h3 class="sd-title"><?php echo esc_html( $global['sharing_label'] ); ?></h3>
521 - <?php endif; ?>
522 - <div class="sd-content">
523 - <ul class="preview">
524 - <?php foreach ( $enabled['visible'] as $id => $service ) : ?>
525 - <?php $this->output_preview( $service ); ?>
526 - <?php endforeach; ?>
527 -
528 - <?php if ( is_countable( $enabled['hidden'] ) && count( $enabled['hidden'] ) > 0 ) : ?>
529 - <li class="advanced"><a href="#" class="sharing-anchor sd-button share-more"><span><?php esc_html_e( 'More', 'jetpack' ); ?></span></a></li>
530 - <?php endif; ?>
531 - </ul>
532 -
533 - <?php if ( is_countable( $enabled['hidden'] ) && count( $enabled['hidden'] ) > 0 ) : ?>
534 - <div class="sharing-hidden">
535 - <div class="inner" style="display: none; <?php echo count( $enabled['hidden'] ) === 1 ? 'width:150px;' : ''; ?>">
536 - <?php if ( count( $enabled['hidden'] ) === 1 ) : ?>
537 - <ul style="background-image:none;">
538 - <?php else : ?>
539 - <ul>
540 - <?php endif; ?>
541 -
542 - <?php
543 - foreach ( $enabled['hidden'] as $id => $service ) {
544 - $this->output_preview( $service );
545 - }
546 - ?>
547 - </ul>
548 - </div>
549 - </div>
550 - <?php endif; ?>
551 -
552 - <ul class="archive" style="display:none;">
553 - <?php
554 - foreach ( $sharer->get_all_services_blog() as $id => $service ) :
555 - if ( isset( $enabled['visible'][ $id ] ) ) {
556 - $service = $enabled['visible'][ $id ];
557 - } elseif ( isset( $enabled['hidden'][ $id ] ) ) {
558 - $service = $enabled['hidden'][ $id ];
559 - }
560 -
561 - $service->button_style = 'icon-text'; // The archive needs the full text, which is removed in JS later.
562 - $service->smart = false;
563 - $this->output_preview( $service );
564 - endforeach;
565 - ?>
566 - <li class="advanced"><a href="#" class="sharing-anchor sd-button share-more"><span><?php esc_html_e( 'More', 'jetpack' ); ?></span></a></li>
567 - </ul>
568 - </div>
569 - </div>
570 - <br class="clearing" />
571 - </td>
572 - </tr>
573 - </table>
574 -
575 - <form method="post" action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" id="save-enabled-shares">
576 - <input type="hidden" name="action" value="sharing_save_services" />
577 - <input type="hidden" name="visible" value="<?php echo esc_attr( implode( ',', array_keys( $enabled['visible'] ) ) ); ?>" />
578 - <input type="hidden" name="hidden" value="<?php echo esc_attr( implode( ',', array_keys( $enabled['hidden'] ) ) ); ?>" />
579 - <input type="hidden" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( 'sharing-options' ) ); ?>" />
580 - </form>
581 - </div>
582 -
583 - <form method="post" action="">
584 - <table class="form-table">
585 - <tbody>
586 - <tr valign="top">
587 - <th scope="row"><label><?php esc_html_e( 'Button style', 'jetpack' ); ?></label></th>
588 - <td>
589 - <select name="button_style" id="button_style">
590 - <option<?php echo ( $global['button_style'] === 'icon-text' ) ? ' selected="selected"' : ''; ?> value="icon-text"><?php esc_html_e( 'Icon + text', 'jetpack' ); ?></option>
591 - <option<?php echo ( $global['button_style'] === 'icon' ) ? ' selected="selected"' : ''; ?> value="icon"><?php esc_html_e( 'Icon only', 'jetpack' ); ?></option>
592 - <option<?php echo ( $global['button_style'] === 'text' ) ? ' selected="selected"' : ''; ?> value="text"><?php esc_html_e( 'Text only', 'jetpack' ); ?></option>
593 - <option<?php echo ( $global['button_style'] === 'official' ) ? ' selected="selected"' : ''; ?> value="official"><?php esc_html_e( 'Official buttons', 'jetpack' ); ?></option>
594 - </select>
595 - </td>
596 - </tr>
597 - <tr valign="top">
598 - <th scope="row"><label><?php esc_html_e( 'Sharing label', 'jetpack' ); ?></label></th>
599 - <td>
600 - <input type="text" name="sharing_label" value="<?php echo esc_attr( $global['sharing_label'] ); ?>" />
601 - </td>
602 - </tr>
603 - <?php
604 - /**
605 - * Filters the HTML at the beginning of the "Show button on" row.
606 - *
607 - * @module sharedaddy
608 - *
609 - * @since 2.1.0
610 - *
611 - * @param string $var Opening HTML tag at the beginning of the "Show button on" row.
612 - */
613 - echo apply_filters( 'sharing_show_buttons_on_row_start', '<tr valign="top">' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
614 - ?>
615 - <th scope="row"><label><?php esc_html_e( 'Show buttons on', 'jetpack' ); ?></label></th>
616 - <td>
617 - <?php
618 - $br = false;
619 - foreach ( $shows as $show ) :
620 - if ( 'index' === $show ) {
621 - $label = __( 'Front Page, Archive Pages, and Search Results', 'jetpack' );
622 - } else {
623 - $post_type_object = get_post_type_object( $show );
624 - $label = $post_type_object->labels->name;
625 - }
626 - ?>
627 - <?php
628 - if ( $br ) {
629 - echo '<br />';
630 - }
631 - ?>
632 - <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>
633 - <?php
634 - $br = true;
635 - endforeach;
636 - ?>
637 - </td>
638 - <?php
639 - /**
640 - * Filters the HTML at the end of the "Show button on" row.
641 - *
642 - * @module sharedaddy
643 - *
644 - * @since 2.1.0
645 - *
646 - * @param string $var Closing HTML tag at the end of the "Show button on" row.
647 - */
648 - echo apply_filters( 'sharing_show_buttons_on_row_end', '</tr>' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
649 - ?>
650 -
651 - <?php
652 - /**
653 - * Fires at the end of the sharing global options settings table.
654 - *
655 - * @module sharedaddy
656 - *
657 - * @since 1.1.0
658 - */
659 - do_action( 'sharing_global_options' );
660 - ?>
661 - </tbody>
662 - </table>
663 -
664 - <p class="submit">
665 - <input type="submit" name="submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes', 'jetpack' ); ?>" />
666 - </p>
667 -
668 - <input type="hidden" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( 'sharing-options' ) ); ?>" />
669 - </form>
670 -
671 - <div id="new-service" style="display: none">
672 - <form method="post" action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" id="new-service-form">
673 - <table class="form-table">
674 - <tbody>
675 - <tr valign="top">
676 - <th scope="row" width="100"><label><?php esc_html_e( 'Service name', 'jetpack' ); ?></label></th>
677 - <td>
678 - <input type="text" name="sharing_name" id="new_sharing_name" size="40" />
679 - </td>
680 - </tr>
681 - <tr valign="top">
682 - <th scope="row" width="100"><label><?php esc_html_e( 'Sharing URL', 'jetpack' ); ?></label></th>
683 - <td>
684 - <input type="text" name="sharing_url" id="new_sharing_url" size="40" />
685 -
686 - <p><?php esc_html_e( 'You can add the following variables to your service sharing URL:', 'jetpack' ); ?><br/>
687 - <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>
688 - </td>
689 - </tr>
690 - <tr valign="top">
691 - <th scope="row" width="100"><label><?php esc_html_e( 'Icon URL', 'jetpack' ); ?></label></th>
692 - <td>
693 - <input type="text" name="sharing_icon" id="new_sharing_icon" size="40" />
694 - <p><?php esc_html_e( 'Enter the URL of a 16x16px icon you want to use for this service.', 'jetpack' ); ?></p>
695 - </td>
696 - </tr>
697 - <tr valign="top" width="100">
698 - <th scope="row"></th>
699 - <td>
700 - <input type="submit" class="button-primary" value="<?php esc_attr_e( 'Create Share Button', 'jetpack' ); ?>" />
701 - <span class="spinner" style="vertical-align: middle"></span>
702 - </td>
703 - </tr>
704 -
705 - <?php
706 - /**
707 - * Fires after the custom sharing service form
708 - *
709 - * @module sharedaddy
710 - *
711 - * @since 1.1.0
712 - */
713 - do_action( 'sharing_new_service_form' );
714 - ?>
715 - </tbody>
716 - </table>
717 -
718 - <?php
719 - /**
720 - * Fires at the bottom of the admin sharing settings screen.
721 - *
722 - * @module sharedaddy
723 - *
724 - * @since 1.6.0
725 - */
726 - do_action( 'post_admin_screen_sharing' );
727 - ?>
728 -
729 - <div class="inerror" style="display: none; margin-top: 15px">
730 - <p><?php esc_html_e( 'An error occurred creating your new sharing service - please check you gave valid details.', 'jetpack' ); ?></p>
731 - </div>
732 -
733 - <input type="hidden" name="action" value="sharing_new_service" />
734 - <input type="hidden" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( 'sharing-new_service' ) ); ?>" />
735 - </form>
736 - </div>
737 - <?php
251 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Services_Config::render' );
738 252 }
739 253
740 254 /**
741 255 * Display sharing block admin UI for settings.
742 256 *
257 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Sharing_Section::render() instead.
258 + *
743 259 * @return void
744 260 */
745 261 public function sharing_block_display() {
746 - $showcase_services = array(
747 - new Share_Tumblr( 'tumblr', array() ),
748 - new Share_Facebook( 'facebook', array() ),
749 - new Share_Email( 'email', array() ),
750 - new Share_Reddit( 'reddit', array() ),
751 - );
752 -
753 - global $submenu;
754 - // Hide the link to Jetpack Sharing settings if no Jetpack Settings found in submenu list
755 - $show_jetpack_admin_settings_link = array_reduce(
756 - $submenu['jetpack'],
757 - function ( $carry, $item ) {
758 - return $carry || ( isset( $item[2] ) && $item[2] === 'jetpack#/settings' );
759 - },
760 - false
761 - );
762 - ?>
763 -
764 - <div class="share_manage_options">
765 - <br class="clearing" />
766 - <h2><?php esc_html_e( 'Sharing Buttons', 'jetpack' ); ?></h2>
767 - <div class="sharing-block-message__items-wrapper">
768 - <div>
769 - <p><?php esc_html_e( 'Add sharing buttons to your blog and allow your visitors to share posts with their friends.', 'jetpack' ); ?></p>
770 - <?php $this->site_editor_prompt_display(); ?>
771 - </div>
772 - <div>
773 - <p><?php esc_html_e( 'Sharing Buttons example:', 'jetpack' ); ?></p>
774 - <div class="sharedaddy sd-sharing-enabled">
775 - <div class="sd-content">
776 - <ul class="preview">
777 - <?php foreach ( $showcase_services as $service ) : ?>
778 - <?php $this->output_preview( $service ); ?>
779 - <?php endforeach; ?>
780 - </ul>
781 - </div>
782 - </div>
783 - </div>
784 - <?php if ( $show_jetpack_admin_settings_link ) : ?>
785 - <p class="settings-sharing__block-theme-description">
786 - <?php
787 - printf(
788 - wp_kses(
789 - /* translators: Link to Jetpack sharing settings. */
790 - __( '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' ),
791 - array(
792 - 'a' => array( 'href' => array() ),
793 - )
794 - ),
795 - esc_url( admin_url( 'admin.php?page=jetpack#/sharing' ) )
796 - );
797 - ?>
798 - </p>
799 - <?php endif; ?>
800 - </div>
801 - <br class="clearing" />
802 - </div>
803 - <?php
262 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Sharing_Section::render' );
804 263 }
805 264
806 265 /**
807 266 * Display the "Go to the site editor" prompt.
808 267 *
268 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Sharing_Section::render() instead.
269 + *
809 270 * @return void
810 271 */
811 272 public function site_editor_prompt_display() {
812 - $host = new Status\Host();
813 -
814 - $wpcom_link = 'https://wordpress.com/support/wordpress-editor/blocks/sharing-buttons-block/';
815 -
816 - if ( function_exists( 'localized_wpcom_url' ) ) {
817 - $wpcom_link = localized_wpcom_url( $wpcom_link );
818 - }
819 -
820 - $link = $host->is_wpcom_platform() ? $wpcom_link : Redirect::get_url( 'jetpack-support-sharing-block' );
821 -
822 - ?>
823 - <div class="sharing-block-message__buttons-wrapper">
824 - <a href="<?php echo esc_url( admin_url( 'site-editor.php?path=%2Fwp_template' ) ); ?>" class="button button-primary">
825 - <?php esc_html_e( 'Go to the site editor', 'jetpack' ); ?>
826 - </a>
827 - <a data-target="wpcom-help-center" href="<?php echo esc_url( $link ); ?>" class="button" target="_blank" rel="noopener noreferrer">
828 - <?php esc_html_e( 'Learn how to add Sharing Buttons', 'jetpack' ); ?>
829 - </a>
830 - </div>
831 - <?php
273 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Sharing_Section::render' );
832 274 }
833 275 }
834 276
835 277 /**
@@ -920,7 +362,14 @@
920 362 function sharing_admin_init() {
921 363 global $sharing_admin;
922 364
923 365 $sharing_admin = new Sharing_Admin();
366 +
367 + // load-jetpack.php registers the screen everywhere else, but does not run on
368 + // WordPress.com Simple, where this file is the only Sharing code loaded.
369 + if ( ( new Host() )->is_wpcom_simple() ) {
370 + Settings_Page::init();
371 + Post_Handler::init();
372 + }
924 373 }
925 374
926 375 add_action( 'init', 'sharing_admin_init' );