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.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 7 years ago admin-sharing-rtl.css 7 years ago admin-sharing-rtl.min.css 7 years ago admin-sharing.css 7 years ago admin-sharing.js 6 years ago admin-sharing.min.css 7 years ago recaptcha.php 7 years ago sharedaddy.php 6 years ago sharing-service.php 6 years ago sharing-sources.php 6 years ago sharing.css 6 years ago sharing.js 6 years ago sharing.php 6 years ago
sharing.php
644 lines
1 <?php
2
3 use Automattic\Jetpack\Assets;
4
5 if ( ! defined( 'WP_SHARING_PLUGIN_URL' ) ) {
6 define( 'WP_SHARING_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
7 define( 'WP_SHARING_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
8 }
9
10 class Sharing_Admin {
11
12 public function __construct() {
13 require_once WP_SHARING_PLUGIN_DIR . 'sharing-service.php';
14
15 add_action( 'admin_init', array( &$this, 'admin_init' ) );
16 add_action( 'admin_menu', array( &$this, 'subscription_menu' ) );
17
18 // Insert our CSS and JS
19 add_action( 'load-settings_page_sharing', array( &$this, 'sharing_head' ) );
20
21 // Catch AJAX
22 add_action( 'wp_ajax_sharing_save_services', array( &$this, 'ajax_save_services' ) );
23 add_action( 'wp_ajax_sharing_save_options', array( &$this, 'ajax_save_options' ) );
24 add_action( 'wp_ajax_sharing_new_service', array( &$this, 'ajax_new_service' ) );
25 add_action( 'wp_ajax_sharing_delete_service', array( &$this, 'ajax_delete_service' ) );
26 }
27
28 public function sharing_head() {
29 wp_enqueue_script(
30 'sharing-js',
31 Assets::get_file_url_for_environment(
32 '_inc/build/sharedaddy/admin-sharing.min.js',
33 'modules/sharedaddy/admin-sharing.js'
34 ),
35 array( 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-form' ),
36 2
37 );
38
39 /**
40 * Filters the switch that if set to true allows Jetpack to use minified assets. Defaults to true
41 * if the SCRIPT_DEBUG constant is not set or set to false. The filter overrides it.
42 *
43 * @since 6.2.0
44 *
45 * @param boolean $var should Jetpack use minified assets.
46 */
47 $postfix = apply_filters( 'jetpack_should_use_minified_assets', true ) ? '.min' : '';
48 if ( is_rtl() ) {
49 wp_enqueue_style( 'sharing-admin', WP_SHARING_PLUGIN_URL . 'admin-sharing-rtl' . $postfix . '.css', false, JETPACK__VERSION );
50 } else {
51 wp_enqueue_style( 'sharing-admin', WP_SHARING_PLUGIN_URL . 'admin-sharing' . $postfix . '.css', false, JETPACK__VERSION );
52 }
53 wp_enqueue_style( 'sharing', WP_SHARING_PLUGIN_URL . 'sharing.css', false, JETPACK__VERSION );
54
55 wp_enqueue_style( 'social-logos' );
56 wp_enqueue_script( 'sharing-js-fe', WP_SHARING_PLUGIN_URL . 'sharing.js', array(), 4 );
57 add_thickbox();
58
59 // On Jetpack sites, make sure we include CSS to style the admin page.
60 if ( ! defined( 'IS_WPCOM' ) || ! IS_WPCOM ) {
61 Jetpack_Admin_Page::load_wrapper_styles();
62 }
63 }
64
65 public function admin_init() {
66 if ( isset( $_GET['page'] ) && ( $_GET['page'] == 'sharing.php' || $_GET['page'] == 'sharing' ) ) {
67 $this->process_requests();
68 }
69 }
70
71 public function process_requests() {
72 if ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'sharing-options' ) ) {
73 $sharer = new Sharing_Service();
74 $sharer->set_global_options( $_POST );
75 /**
76 * Fires when updating sharing settings.
77 *
78 * @module sharedaddy
79 *
80 * @since 1.1.0
81 */
82 do_action( 'sharing_admin_update' );
83
84 wp_safe_redirect( admin_url( 'options-general.php?page=sharing&update=saved' ) );
85 die();
86 }
87 }
88
89 public function subscription_menu( $user ) {
90 if ( ! defined( 'IS_WPCOM' ) || ! IS_WPCOM ) {
91 $active = Jetpack::get_active_modules();
92 if ( ! in_array( 'publicize', $active ) && ! current_user_can( 'manage_options' ) ) {
93 return;
94 }
95 }
96
97 add_submenu_page(
98 'options-general.php',
99 __( 'Sharing Settings', 'jetpack' ),
100 __( 'Sharing', 'jetpack' ),
101 'publish_posts',
102 'sharing',
103 array( &$this, 'wrapper_admin_page' )
104 );
105 }
106
107 public function ajax_save_services() {
108 if ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'sharing-options' ) && isset( $_POST['hidden'] ) && isset( $_POST['visible'] ) ) {
109 $sharer = new Sharing_Service();
110
111 $sharer->set_blog_services( explode( ',', $_POST['visible'] ), explode( ',', $_POST['hidden'] ) );
112 die();
113 }
114 }
115
116 public function ajax_new_service() {
117 if ( isset( $_POST['_wpnonce'] ) && isset( $_POST['sharing_name'] ) && isset( $_POST['sharing_url'] ) && isset( $_POST['sharing_icon'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'sharing-new_service' ) ) {
118 $sharer = new Sharing_Service();
119 if ( $service = $sharer->new_service( stripslashes( $_POST['sharing_name'] ), stripslashes( $_POST['sharing_url'] ), stripslashes( $_POST['sharing_icon'] ) ) ) {
120 $this->output_service( $service->get_id(), $service );
121 echo '<!--->';
122 $service->button_style = 'icon-text';
123 $this->output_preview( $service );
124
125 die();
126 }
127 }
128
129 // Fail
130 die( '1' );
131 }
132
133 public function ajax_delete_service() {
134 if ( isset( $_POST['_wpnonce'] ) && isset( $_POST['service'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'sharing-options_' . $_POST['service'] ) ) {
135 $sharer = new Sharing_Service();
136 $sharer->delete_service( $_POST['service'] );
137 }
138 }
139
140 public function ajax_save_options() {
141 if ( isset( $_POST['_wpnonce'] ) && isset( $_POST['service'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'sharing-options_' . $_POST['service'] ) ) {
142 $sharer = new Sharing_Service();
143 $service = $sharer->get_service( $_POST['service'] );
144
145 if ( $service && $service instanceof Sharing_Advanced_Source ) {
146 $service->update_options( $_POST );
147
148 $sharer->set_service( $_POST['service'], $service );
149 }
150
151 $this->output_service( $service->get_id(), $service, true );
152 echo '<!--->';
153 $service->button_style = 'icon-text';
154 $this->output_preview( $service );
155 die();
156 }
157 }
158
159 public function output_preview( $service ) {
160
161 $klasses = array( 'advanced', 'preview-item' );
162
163 if ( $service->button_style != 'text' || $service->has_custom_button_style() ) {
164 $klasses[] = 'preview-' . $service->get_class();
165 $klasses[] = 'share-' . $service->get_class();
166 if ( $service->is_deprecated() ) {
167 $klasses[] = 'share-deprecated';
168 }
169
170 if ( $service->get_class() != $service->get_id() ) {
171 $klasses[] = 'preview-' . $service->get_id();
172 }
173 }
174
175 echo '<li class="' . implode( ' ', $klasses ) . '">';
176 $service->display_preview();
177 echo '</li>';
178 }
179
180 public function output_service( $id, $service, $show_dropdown = false ) {
181 $title = '';
182 $klasses = array( 'service', 'advanced', 'share-' . $service->get_class() );
183 if ( $service->is_deprecated() ) {
184 /* translators: %1$s is the name of a deprecated Sharing Service like "Google+" */
185 $title = sprintf( __( 'The %1$s service has shut down. This sharing button is not displayed to your visitors and should be removed.', 'jetpack' ), $service->get_name() );
186 $klasses[] = 'share-deprecated';
187 }
188
189 ?>
190 <li class="<?php echo implode( ' ', $klasses ); ?>" id="<?php echo $service->get_id(); ?>" tabindex="0" title="<?php echo esc_attr( $title ); ?>">
191 <span class="options-left"><?php echo esc_html( $service->get_name() ); ?></span>
192 <?php if ( 0 === strpos( $service->get_id(), 'custom-' ) || $service->has_advanced_options() ) : ?>
193 <span class="close"><a href="#" class="remove">&times;</a></span>
194 <form method="post" action="<?php echo admin_url( 'admin-ajax.php' ); ?>">
195 <input type="hidden" name="action" value="sharing_delete_service" />
196 <input type="hidden" name="service" value="<?php echo esc_attr( $id ); ?>" />
197 <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce( 'sharing-options_' . $id );?>" />
198 </form>
199 <?php endif; ?>
200 </li>
201 <?php
202 }
203
204 public function wrapper_admin_page() {
205 Jetpack_Admin_Page::wrap_ui( array( &$this, 'management_page' ), array( 'is-wide' =>true ) );
206 }
207
208 public function management_page() {
209 $sharer = new Sharing_Service();
210 $enabled = $sharer->get_blog_services();
211 $global = $sharer->get_global_options();
212
213 $shows = array_values( get_post_types( array( 'public' => true ) ) );
214 array_unshift( $shows, 'index' );
215
216 if ( false == function_exists( 'mb_stripos' ) ) {
217 echo '<div id="message" class="updated fade"><h3>' . __( 'Warning! Multibyte support missing!', 'jetpack' ) . '</h3>';
218 echo '<p>' . sprintf( __( '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' ), 'https://www.php.net/manual/en/mbstring.installation.php' ) . '</p></div>';
219 }
220
221 if ( isset( $_GET['update'] ) && $_GET['update'] == 'saved' ) {
222 echo '<div class="updated"><p>' . __( 'Settings have been saved', 'jetpack' ) . '</p></div>';
223 }
224
225 if ( ! isset( $global['sharing_label'] ) ) {
226 $global['sharing_label'] = __( 'Share this:', 'jetpack' );
227 }
228 ?>
229
230 <div class="wrap">
231 <div class="icon32" id="icon-options-general"><br /></div>
232 <h1><?php _e( 'Sharing Settings', 'jetpack' ); ?></h1>
233
234 <?php
235 /**
236 * Fires at the top of the admin sharing settings screen.
237 *
238 * @module sharedaddy
239 *
240 * @since 1.6.0
241 */
242 do_action( 'pre_admin_screen_sharing' );
243 ?>
244
245 <?php if ( current_user_can( 'manage_options' ) ) : ?>
246
247 <div class="share_manage_options">
248 <h2><?php _e( 'Sharing Buttons', 'jetpack' ) ?></h2>
249 <p><?php _e( 'Add sharing buttons to your blog and allow your visitors to share posts with their friends.', 'jetpack' ) ?></p>
250
251 <div id="services-config">
252 <table id="available-services">
253 <tr>
254 <td class="description">
255 <h3><?php _e( 'Available Services', 'jetpack' ); ?></h3>
256 <p><?php _e( "Drag and drop the services you'd like to enable into the box below.", 'jetpack' ); ?></p>
257 <p><a href="#TB_inline?height=395&amp;width=600&amp;inlineId=new-service" class="thickbox" id="add-a-new-service"><?php _e( 'Add a new service', 'jetpack' ); ?></a></p>
258 </td>
259 <td class="services">
260 <ul class="services-available" style="height: 100px;">
261 <?php foreach ( $sharer->get_all_services_blog() as $id => $service ) : ?>
262 <?php
263 if ( ! isset( $enabled['all'][ $id ] ) ) {
264 $this->output_service( $id, $service );
265 }
266 ?>
267 <?php endforeach; ?>
268 </ul>
269 <?php
270 if ( -1 == get_option( 'blog_public' ) ) {
271 echo '<p><strong>' . __( 'Please note that your services have been restricted because your site is private.', 'jetpack' ) . '</strong></p>';
272 }
273 ?>
274 <br class="clearing" />
275 </td>
276 </tr>
277 </table>
278
279 <table id="enabled-services">
280 <tr>
281 <td class="description">
282 <h3>
283 <?php _e( 'Enabled Services', 'jetpack' ); ?>
284 <img src="<?php echo admin_url( 'images/loading.gif' ); ?>" width="16" height="16" alt="loading" style="vertical-align: middle; display: none" />
285 </h3>
286 <p><?php _e( 'Services dragged here will appear individually.', 'jetpack' ); ?></p>
287 </td>
288 <td class="services" id="share-drop-target">
289 <h2 id="drag-instructions" <?php if ( count( $enabled['visible'] ) > 0 ) { echo ' style="display: none"';} ?>><?php _e( 'Drag and drop available services here.', 'jetpack' ); ?></h2>
290
291 <ul class="services-enabled">
292 <?php foreach ( $enabled['visible'] as $id => $service ) : ?>
293 <?php $this->output_service( $id, $service, true ); ?>
294 <?php endforeach; ?>
295
296 <li class="end-fix"></li>
297 </ul>
298 </td>
299 <td id="hidden-drop-target" class="services">
300 <p><?php _e( 'Services dragged here will be hidden behind a share button.', 'jetpack' ); ?></p>
301
302 <ul class="services-hidden">
303 <?php foreach ( $enabled['hidden'] as $id => $service ) : ?>
304 <?php $this->output_service( $id, $service, true ); ?>
305 <?php endforeach; ?>
306 <li class="end-fix"></li>
307 </ul>
308 </td>
309 </tr>
310 </table>
311
312 <table id="live-preview">
313 <tr>
314 <td class="description">
315 <h3><?php _e( 'Live Preview', 'jetpack' ); ?></h3>
316 </td>
317 <td class="services">
318 <h2 <?php echo ( count( $enabled['all'] ) > 0 ) ? ' style="display: none"' : ''; ?>><?php _e( 'Sharing is off. Add services above to enable.', 'jetpack' ); ?></h2>
319 <div class="sharedaddy sd-sharing-enabled">
320 <?php if ( count( $enabled['all'] ) > 0 ) : ?>
321 <h3 class="sd-title"><?php echo esc_html( $global['sharing_label'] ); ?></h3>
322 <?php endif; ?>
323 <div class="sd-content">
324 <ul class="preview">
325 <?php foreach ( $enabled['visible'] as $id => $service ) : ?>
326 <?php $this->output_preview( $service ); ?>
327 <?php endforeach; ?>
328
329 <?php if ( count( $enabled['hidden'] ) > 0 ) : ?>
330 <li class="advanced"><a href="#" class="sharing-anchor sd-button share-more"><span><?php _e( 'More', 'jetpack' ); ?></span></a></li>
331 <?php endif; ?>
332 </ul>
333
334 <?php if ( count( $enabled['hidden'] ) > 0 ) : ?>
335 <div class="sharing-hidden">
336 <div class="inner" style="display: none; <?php echo count( $enabled['hidden'] ) == 1 ? 'width:150px;' : ''; ?>">
337 <?php if ( count( $enabled['hidden'] ) == 1 ) : ?>
338 <ul style="background-image:none;">
339 <?php else : ?>
340 <ul>
341 <?php endif; ?>
342
343 <?php
344 foreach ( $enabled['hidden'] as $id => $service ) {
345 $this->output_preview( $service );
346 }
347 ?>
348 </ul>
349 </div>
350 </div>
351 <?php endif; ?>
352
353 <ul class="archive" style="display:none;">
354 <?php
355 foreach ( $sharer->get_all_services_blog() as $id => $service ) :
356 if ( isset( $enabled['visible'][ $id ] ) ) {
357 $service = $enabled['visible'][ $id ];
358 } elseif ( isset( $enabled['hidden'][ $id ] ) ) {
359 $service = $enabled['hidden'][ $id ];
360 }
361
362 $service->button_style = 'icon-text'; // The archive needs the full text, which is removed in JS later
363 $service->smart = false;
364 $this->output_preview( $service );
365 endforeach; ?>
366 <li class="advanced"><a href="#" class="sharing-anchor sd-button share-more"><span><?php _e( 'More', 'jetpack' ); ?></span></a></li>
367 </ul>
368 </div>
369 </div>
370 <br class="clearing" />
371 </td>
372 </tr>
373 </table>
374
375 <form method="post" action="<?php echo admin_url( 'admin-ajax.php' ); ?>" id="save-enabled-shares">
376 <input type="hidden" name="action" value="sharing_save_services" />
377 <input type="hidden" name="visible" value="<?php echo implode( ',', array_keys( $enabled['visible'] ) ); ?>" />
378 <input type="hidden" name="hidden" value="<?php echo implode( ',', array_keys( $enabled['hidden'] ) ); ?>" />
379 <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce( 'sharing-options' );?>" />
380 </form>
381 </div>
382
383 <form method="post" action="">
384 <table class="form-table">
385 <tbody>
386 <tr valign="top">
387 <th scope="row"><label><?php _e( 'Button style', 'jetpack' ); ?></label></th>
388 <td>
389 <select name="button_style" id="button_style">
390 <option<?php echo ( $global['button_style'] == 'icon-text' ) ? ' selected="selected"' : ''; ?> value="icon-text"><?php _e( 'Icon + text', 'jetpack' ); ?></option>
391 <option<?php echo ( $global['button_style'] == 'icon' ) ? ' selected="selected"' : ''; ?> value="icon"><?php _e( 'Icon only', 'jetpack' ); ?></option>
392 <option<?php echo ( $global['button_style'] == 'text' ) ? ' selected="selected"' : ''; ?> value="text"><?php _e( 'Text only', 'jetpack' ); ?></option>
393 <option<?php echo ( $global['button_style'] == 'official' ) ? ' selected="selected"' : ''; ?> value="official"><?php _e( 'Official buttons', 'jetpack' ); ?></option>
394 </select>
395 </td>
396 </tr>
397 <tr valign="top">
398 <th scope="row"><label><?php _e( 'Sharing label', 'jetpack' ); ?></label></th>
399 <td>
400 <input type="text" name="sharing_label" value="<?php echo esc_attr( $global['sharing_label'] ); ?>" />
401 </td>
402 </tr>
403 <?php
404 /**
405 * Filters the HTML at the beginning of the "Show button on" row.
406 *
407 * @module sharedaddy
408 *
409 * @since 2.1.0
410 *
411 * @param string $var Opening HTML tag at the beginning of the "Show button on" row.
412 */
413 echo apply_filters( 'sharing_show_buttons_on_row_start', '<tr valign="top">' );
414 ?>
415 <th scope="row"><label><?php _e( 'Show buttons on', 'jetpack' ); ?></label></th>
416 <td>
417 <?php
418 $br = false;
419 foreach ( $shows as $show ) :
420 if ( 'index' == $show ) {
421 $label = __( 'Front Page, Archive Pages, and Search Results', 'jetpack' );
422 } else {
423 $post_type_object = get_post_type_object( $show );
424 $label = $post_type_object->labels->name;
425 }
426 ?>
427 <?php
428 if ( $br ) {
429 echo '<br />';
430 }
431 ?>
432 <label><input type="checkbox"<?php checked( in_array( $show, $global['show'] ) ); ?> name="show[]" value="<?php echo esc_attr( $show ); ?>" /> <?php echo esc_html( $label ); ?></label>
433 <?php
434 $br = true;
435 endforeach;
436 ?>
437 </td>
438 <?php
439 /**
440 * Filters the HTML at the end of the "Show button on" row.
441 *
442 * @module sharedaddy
443 *
444 * @since 2.1.0
445 *
446 * @param string $var Closing HTML tag at the end of the "Show button on" row.
447 */
448 echo apply_filters( 'sharing_show_buttons_on_row_end', '</tr>' );
449 ?>
450
451 <?php
452 /**
453 * Fires at the end of the sharing global options settings table.
454 *
455 * @module sharedaddy
456 *
457 * @since 1.1.0
458 */
459 do_action( 'sharing_global_options' );
460 ?>
461 </tbody>
462 </table>
463
464 <p class="submit">
465 <input type="submit" name="submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes', 'jetpack' ); ?>" />
466 </p>
467
468 <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce( 'sharing-options' );?>" />
469 </form>
470
471 <div id="new-service" style="display: none">
472 <form method="post" action="<?php echo admin_url( 'admin-ajax.php' ); ?>" id="new-service-form">
473 <table class="form-table">
474 <tbody>
475 <tr valign="top">
476 <th scope="row" width="100"><label><?php _e( 'Service name', 'jetpack' ); ?></label></th>
477 <td>
478 <input type="text" name="sharing_name" id="new_sharing_name" size="40" />
479 </td>
480 </tr>
481 <tr valign="top">
482 <th scope="row" width="100"><label><?php _e( 'Sharing URL', 'jetpack' ); ?></label></th>
483 <td>
484 <input type="text" name="sharing_url" id="new_sharing_url" size="40" />
485
486 <p><?php _e( 'You can add the following variables to your service sharing URL:', 'jetpack' ); ?><br/>
487 <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>
488 </td>
489 </tr>
490 <tr valign="top">
491 <th scope="row" width="100"><label><?php _e( 'Icon URL', 'jetpack' ); ?></label></th>
492 <td>
493 <input type="text" name="sharing_icon" id="new_sharing_icon" size="40" />
494 <p><?php _e( 'Enter the URL of a 16x16px icon you want to use for this service.', 'jetpack' ); ?></p>
495 </td>
496 </tr>
497 <tr valign="top" width="100">
498 <th scope="row"></th>
499 <td>
500 <input type="submit" class="button-primary" value="<?php esc_attr_e( 'Create Share Button', 'jetpack' ); ?>" />
501 <img src="<?php echo admin_url( 'images/loading.gif' ); ?>" width="16" height="16" alt="loading" style="vertical-align: middle; display: none" />
502 </td>
503 </tr>
504
505 <?php
506 /**
507 * Fires after the custom sharing service form
508 *
509 * @module sharedaddy
510 *
511 * @since 1.1.0
512 */
513 do_action( 'sharing_new_service_form' );
514 ?>
515 </tbody>
516 </table>
517
518 <?php
519 /**
520 * Fires at the bottom of the admin sharing settings screen.
521 *
522 * @module sharedaddy
523 *
524 * @since 1.6.0
525 */
526 do_action( 'post_admin_screen_sharing' );
527 ?>
528
529 <div class="inerror" style="display: none; margin-top: 15px">
530 <p><?php _e( 'An error occurred creating your new sharing service - please check you gave valid details.', 'jetpack' ); ?></p>
531 </div>
532
533 <input type="hidden" name="action" value="sharing_new_service" />
534 <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce( 'sharing-new_service' );?>" />
535 </form>
536 </div>
537 </div>
538
539 <?php endif; ?>
540
541
542 </div>
543
544 <script type="text/javascript">
545 var sharing_loading_icon = '<?php echo esc_js( admin_url( '/images/loading.gif' ) ); ?>';
546 <?php if ( isset( $_GET['create_new_service'] ) && 'true' == $_GET['create_new_service'] ) : ?>
547 jQuery(document).ready(function() {
548 // Prefill new service box and then open it
549 jQuery( '#new_sharing_name' ).val( '<?php echo esc_js( $_GET['name'] ); ?>' );
550 jQuery( '#new_sharing_url' ).val( '<?php echo esc_js( $_GET['url'] ); ?>' );
551 jQuery( '#new_sharing_icon' ).val( '<?php echo esc_js( $_GET['icon'] ); ?>' );
552 jQuery( '#add-a-new-service' ).click();
553 });
554 <?php endif; ?>
555 </script>
556 <?php
557 }
558 }
559
560 /**
561 * Callback to get the value for the jetpack_sharing_enabled field.
562 *
563 * When the sharing_disabled post_meta is unset, we follow the global setting in Sharing.
564 * When it is set to 1, we disable sharing on the post, regardless of the global setting.
565 * It is not possible to enable sharing on a post if it is disabled globally.
566 */
567 function jetpack_post_sharing_get_value( array $post ) {
568 // if sharing IS disabled on this post, enabled=false, so negate the meta
569 return (bool) ! get_post_meta( $post['id'], 'sharing_disabled', true );
570 }
571
572 /**
573 * Callback to set sharing_disabled post_meta when the
574 * jetpack_sharing_enabled field is updated.
575 *
576 * When the sharing_disabled post_meta is unset, we follow the global setting in Sharing.
577 * When it is set to 1, we disable sharing on the post, regardless of the global setting.
578 * It is not possible to enable sharing on a post if it is disabled globally.
579 *
580 */
581 function jetpack_post_sharing_update_value( $enable_sharing, $post_object ) {
582 if ( $enable_sharing ) {
583 // delete the override if we want to enable sharing
584 return delete_post_meta( $post_object->ID, 'sharing_disabled' );
585 } else {
586 return update_post_meta( $post_object->ID, 'sharing_disabled', true );
587 }
588 }
589
590 /**
591 * Add Sharing post_meta to the REST API Post response.
592 *
593 * @action rest_api_init
594 * @uses register_rest_field
595 * @link https://developer.wordpress.org/rest-api/extending-the-rest-api/modifying-responses/
596 */
597 function jetpack_post_sharing_register_rest_field() {
598 $post_types = get_post_types( array( 'public' => true ) );
599 foreach ( $post_types as $post_type ) {
600 register_rest_field(
601 $post_type,
602 'jetpack_sharing_enabled',
603 array(
604 'get_callback' => 'jetpack_post_sharing_get_value',
605 'update_callback' => 'jetpack_post_sharing_update_value',
606 'schema' => array(
607 'description' => __( 'Are sharing buttons enabled?', 'jetpack' ),
608 'type' => 'boolean',
609 ),
610 )
611 );
612
613 /**
614 * Ensures all public internal post-types support `sharing`
615 * This feature support flag is used by the REST API and Gutenberg.
616 */
617 add_post_type_support( $post_type, 'jetpack-sharing-buttons' );
618 }
619 }
620
621 // Add Sharing post_meta to the REST API Post response.
622 add_action( 'rest_api_init', 'jetpack_post_sharing_register_rest_field' );
623
624 // Some CPTs (e.g. Jetpack portfolios and testimonials) get registered with
625 // restapi_theme_init because they depend on theme support, so let's also hook to that
626 add_action( 'restapi_theme_init', 'jetpack_post_likes_register_rest_field', 20 );
627
628 function sharing_admin_init() {
629 global $sharing_admin;
630
631 $sharing_admin = new Sharing_Admin();
632 }
633
634 /**
635 * Set the Likes and Sharing Gutenberg extension as available
636 */
637 function jetpack_sharing_set_extension_availability() {
638 Jetpack_Gutenberg::set_extension_available( 'sharing' );
639 }
640
641 add_action( 'jetpack_register_gutenberg_extensions', 'jetpack_sharing_set_extension_availability' );
642
643 add_action( 'init', 'sharing_admin_init' );
644