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