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