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