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