PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.7
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.7
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 +122 -541 12.9.5 → 16.3-a.7 View file →
@@ -7,10 +7,17 @@
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\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;
12 15
16 +if ( ! defined( 'ABSPATH' ) ) {
17 + exit( 0 );
18 +}
19 +
13 20 if ( ! defined( 'WP_SHARING_PLUGIN_URL' ) ) {
14 21 define( 'WP_SHARING_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
15 22 define( 'WP_SHARING_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
16 23 }
@@ -20,8 +27,15 @@
20 27 */
21 28 class Sharing_Admin {
22 29
23 30 /**
31 + * The services configuration UI.
32 + *
33 + * @var Services_Config
34 + */
35 + private $services_config;
36 +
37 + /**
24 38 * Constructor.
25 39 * Hook into WordPress to add our functionality.
26 40 */
27 41 public function __construct() {
@@ -26,19 +40,23 @@
26 40 */
27 41 public function __construct() {
28 42 require_once WP_SHARING_PLUGIN_DIR . 'sharing-service.php';
29 43
30 - add_action( 'admin_init', array( $this, 'admin_init' ) );
31 - add_action( 'admin_menu', array( $this, 'subscription_menu' ) );
44 + $this->services_config = new Services_Config();
32 45
46 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- nonces are handled in process_requests.
47 + if ( isset( $_GET['page'] ) && $_GET['page'] === 'sharing' ) {
48 + add_action( 'admin_init', array( $this, 'admin_init' ) );
49 + }
50 +
33 51 // Insert our CSS and JS
34 52 add_action( 'load-settings_page_sharing', array( $this, 'sharing_head' ) );
35 53
36 54 // 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' ) );
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' ) );
41 59 }
42 60
43 61 /**
44 62 * Enqueue scripts and styles on the sharing settings page.
@@ -52,12 +70,19 @@
52 70 '_inc/build/sharedaddy/admin-sharing.min.js',
53 71 'modules/sharedaddy/admin-sharing.js'
54 72 ),
55 73 array( 'jquery', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-form' ),
56 - 2,
74 + JETPACK__VERSION,
57 75 false
58 76 );
59 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 +
60 85 /**
61 86 * Filters the switch that if set to true allows Jetpack to use minified assets. Defaults to true
62 87 * if the SCRIPT_DEBUG constant is not set or set to false. The filter overrides it.
63 88 *
@@ -75,13 +100,8 @@
75 100
76 101 wp_enqueue_style( 'social-logos' );
77 102 wp_enqueue_script( 'sharing-js-fe', WP_SHARING_PLUGIN_URL . 'sharing.js', array(), 4, false );
78 103 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 104 }
85 105
86 106 /**
87 107 * Load the process that handles saving changes on the sharing settings page.
@@ -88,200 +108,96 @@
88 108 *
89 109 * @return void
90 110 */
91 111 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 - }
112 + $this->services_config->process_requests();
95 113 }
96 114
97 115 /**
98 116 * Save changes to sharing settings.
99 117 *
118 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Services_Config::process_requests() instead.
119 + *
100 120 * @return void
101 121 */
102 122 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 - }
123 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Services_Config::process_requests' );
121 124 }
122 125
123 126 /**
124 - * Register Sharing settings menu page.
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
125 132 */
126 133 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 - );
134 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Settings_Page::register_menu' );
145 135 }
146 136
147 137 /**
148 138 * Save changes to sharing services via AJAX.
149 139 *
140 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Services_Config::ajax_save_services() instead.
141 + *
150 142 * @return void
151 143 */
152 144 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 - }
145 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Services_Config::ajax_save_services' );
167 146 }
168 147
169 148 /**
170 149 * Create a new custom sharing service via AJAX.
171 150 *
151 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Services_Config::ajax_new_service() instead.
152 + *
172 153 * @return void
173 154 */
174 155 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' );
156 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Services_Config::ajax_new_service' );
201 157 }
202 158
203 159 /**
204 160 * Delete a sharing service via AJAX.
205 161 *
162 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Services_Config::ajax_delete_service() instead.
163 + *
206 164 * @return void
207 165 */
208 166 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 - }
167 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Services_Config::ajax_delete_service' );
220 168 }
221 169
222 170 /**
223 171 * Save changes to sharing settings via AJAX.
224 172 *
173 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Services_Config::ajax_save_options() instead.
174 + *
225 175 * @return void
226 176 */
227 177 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 - }
178 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Services_Config::ajax_save_options' );
251 179 }
252 180
253 181 /**
254 182 * Display a preview of a sharing service.
255 183 *
184 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Services_Config::output_preview() instead.
185 + *
256 186 * @param object $service Sharing service object.
257 187 *
258 188 * @return void
259 189 */
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>';
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' );
278 192 }
279 193
280 194 /**
281 195 * Display a specific sharing service.
282 196 *
283 - * @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.
284 200 * @param object $service Sharing service.
285 201 * @param bool $show_dropdown Display a dropdown. Not in use at the moment.
286 202 *
287 203 * @return void
@@ -286,422 +202,76 @@
286 202 *
287 203 * @return void
288 204 */
289 205 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 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() );
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 ( str_starts_with( $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
206 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Services_Config::output_service' );
313 207 }
314 208
315 209 /**
316 210 * Display admin UI within a Jetpack header and footer.
317 211 *
212 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Settings_Page::render() instead.
213 + *
318 214 * @return void
319 215 */
320 216 public function wrapper_admin_page() {
321 - 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' );
322 218 }
323 219
324 220 /**
325 221 * Sharing settings inner page structure.
326 222 *
223 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Settings_Page::render() instead.
224 + *
327 225 * @return void
328 226 */
329 227 public function management_page() {
330 - $sharer = new Sharing_Service();
331 - $enabled = $sharer->get_blog_services();
332 - $global = $sharer->get_global_options();
228 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Settings_Page::render' );
229 + }
333 230
334 - $shows = array_values( get_post_types( array( 'public' => true ) ) );
335 - array_unshift( $shows, 'index' );
231 + /**
232 + * Check if we should encourage to use the site editor instead of the legacy sharing settings.
233 + *
234 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Environment instead.
235 + *
236 + * @return bool
237 + */
238 + public function should_use_site_editor() {
239 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Environment' );
240 + return false;
241 + }
336 242
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 - }
243 + /**
244 + * Display services admin UI for settings.
245 + *
246 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Services_Config::render() instead.
247 + *
248 + * @return void
249 + */
250 + public function services_config_display() {
251 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Services_Config::render' );
252 + }
354 253
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 - }
254 + /**
255 + * Display sharing block admin UI for settings.
256 + *
257 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Sharing_Section::render() instead.
258 + *
259 + * @return void
260 + */
261 + public function sharing_block_display() {
262 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Sharing_Section::render' );
263 + }
358 264
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 ( is_countable( $enabled['visible'] ) && 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 ( 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>
458 - <div class="sharedaddy sd-sharing-enabled">
459 - <?php if ( is_countable( $enabled['all'] ) && 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 ( is_countable( $enabled['hidden'] ) && 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 ( is_countable( $enabled['hidden'] ) && 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'] ) && isset( $_GET['name'] ) && isset( $_GET['url'] ) && isset( $_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
265 + /**
266 + * Display the "Go to the site editor" prompt.
267 + *
268 + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Sharing_Section::render() instead.
269 + *
270 + * @return void
271 + */
272 + public function site_editor_prompt_display() {
273 + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Sharing_Section::render' );
704 274 }
705 275 }
706 276
707 277 /**
@@ -715,10 +285,14 @@
715 285 *
716 286 * @return bool
717 287 */
718 288 function jetpack_post_sharing_get_value( array $post ) {
289 + if ( ! isset( $post['id'] ) ) {
290 + return false;
291 + }
292 +
719 293 // if sharing IS disabled on this post, enabled=false, so negate the meta
720 - return (bool) ! get_post_meta( $post['id'], 'sharing_disabled', true );
294 + return ! get_post_meta( $post['id'], 'sharing_disabled', true );
721 295 }
722 296
723 297 /**
724 298 * Callback to set sharing_disabled post_meta when the
@@ -788,7 +362,14 @@
788 362 function sharing_admin_init() {
789 363 global $sharing_admin;
790 364
791 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 + }
792 373 }
793 374
794 375 add_action( 'init', 'sharing_admin_init' );