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