| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | 2 | |
| 3 | +use Automattic\Jetpack\Status\Host; | |
| 3 | 4 | use Automattic\Jetpack\Sync\Settings; |
| 4 | 5 | |
| 5 | 6 | /** |
| 6 | 7 | * Jetpack likes settings class. |
| @@ -7,19 +8,19 @@ | ||
| 7 | 8 | */ |
| 8 | 9 | class Jetpack_Likes_Settings { |
| 9 | 10 | |
| 10 | 11 | /** |
| 11 | - * False if running on WPCOM Simple | |
| 12 | + * Determines whether the module runs in the Jetpack plugin, as opposed to WP.com Simple site environment | |
| 12 | 13 | * |
| 13 | 14 | * @var bool |
| 14 | 15 | */ |
| 15 | - public $in_jetpack; | |
| 16 | + public $in_jetpack = true; | |
| 16 | 17 | |
| 17 | 18 | /** |
| 18 | 19 | * Constructor function. |
| 19 | 20 | */ |
| 20 | 21 | public function __construct() { |
| 21 | - $this->in_jetpack = ! ( defined( 'IS_WPCOM' ) && IS_WPCOM ); | |
| 22 | + $this->in_jetpack = ! ( new Host() )->is_wpcom_simple(); | |
| 22 | 23 | } |
| 23 | 24 | |
| 24 | 25 | /** |
| 25 | 26 | * Replaces the "Sharing" title for the post screen metabox with "Likes and Shares" |
| @@ -96,9 +97,9 @@ | ||
| 96 | 97 | <?php esc_html_e( 'Show likes.', 'jetpack' ); ?> |
| 97 | 98 | </label> |
| 98 | 99 | <input type="hidden" name="wpl_like_status_hidden" value="1" /> |
| 99 | 100 | <?php wp_nonce_field( 'likes-and-shares', '_likesharenonce' ); ?> |
| 100 | - </p> | |
| 101 | + </p> | |
| 101 | 102 | <?php |
| 102 | 103 | /** |
| 103 | 104 | * Fires after the Likes meta box content in the post editor. |
| 104 | 105 | * |
| @@ -139,9 +140,9 @@ | ||
| 139 | 140 | if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
| 140 | 141 | return $post_id; |
| 141 | 142 | } |
| 142 | 143 | |
| 143 | - if ( empty( $_POST['wpl_like_status_hidden'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- we're not changing anything on the site. | |
| 144 | + if ( empty( $_POST['wpl_like_status_hidden'] ) ) { | |
| 144 | 145 | return $post_id; |
| 145 | 146 | } |
| 146 | 147 | |
| 147 | 148 | if ( ! isset( $_POST['_likesharenonce'] ) || ! wp_verify_nonce( $_POST['_likesharenonce'], 'likes-and-shares' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- WordPress core doesn't unslash or verify nonces either. |
| @@ -200,79 +201,67 @@ | ||
| 200 | 201 | <input type="checkbox" name="wpl_enable_post_sharing" id="wpl_enable_post_sharing" value="1" <?php checked( ! $disabled ); ?>> |
| 201 | 202 | <?php esc_html_e( 'Show sharing buttons.', 'jetpack' ); ?> |
| 202 | 203 | </label> |
| 203 | 204 | <input type="hidden" name="wpl_sharing_status_hidden" value="1" /> |
| 204 | - </p> | |
| 205 | + </p> | |
| 205 | 206 | <?php |
| 206 | 207 | } |
| 207 | 208 | |
| 208 | 209 | /** |
| 210 | + * Should we register the Settings > Sharing screen ourselves? | |
| 211 | + * | |
| 212 | + * @deprecated 16.3 Settings > Sharing is registered by Automattic\Jetpack\Sharing_Likes\Settings\Settings_Page. | |
| 213 | + * | |
| 214 | + * @param bool $sharedaddy_active Whether the Sharing (sharedaddy) module is active. | |
| 215 | + * @return bool | |
| 216 | + */ | |
| 217 | + public function needs_own_sharing_menu( $sharedaddy_active ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | |
| 218 | + _deprecated_function( __METHOD__, 'jetpack-16.3' ); | |
| 219 | + return false; | |
| 220 | + } | |
| 221 | + | |
| 222 | + /** | |
| 209 | 223 | * Adds the 'sharing' menu to the settings menu. |
| 210 | - * Only ran if sharedaddy and publicize are not already active. | |
| 211 | 224 | * |
| 212 | - * @deprecated 13.2 | |
| 225 | + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Settings_Page::register_menu() instead. | |
| 226 | + * | |
| 227 | + * @return void | |
| 213 | 228 | */ |
| 214 | 229 | public function sharing_menu() { |
| 215 | - add_submenu_page( 'options-general.php', esc_html__( 'Sharing Settings', 'jetpack' ), esc_html__( 'Sharing', 'jetpack' ), 'manage_options', 'sharing', array( $this, 'sharing_page' ) ); | |
| 230 | + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Settings_Page::register_menu' ); | |
| 216 | 231 | } |
| 217 | 232 | |
| 218 | 233 | /** |
| 219 | - * Provides a sharing page with the sharing_global_options hook | |
| 220 | - * so we can display the setting. | |
| 221 | - * Only ran if sharedaddy and publicize are not already active. | |
| 234 | + * Provides a sharing page with the sharing_global_options hook so we can display the setting. | |
| 222 | 235 | * |
| 223 | - * @deprecated 13.2 | |
| 236 | + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Settings_Page::render() instead. | |
| 237 | + * | |
| 238 | + * @return void | |
| 224 | 239 | */ |
| 225 | 240 | public function sharing_page() { |
| 226 | - $this->updated_message(); | |
| 227 | - ?> | |
| 228 | - <div class="wrap"> | |
| 229 | - <div class="icon32" id="icon-options-general"><br /></div> | |
| 230 | - <h1><?php esc_html_e( 'Sharing Settings', 'jetpack' ); ?></h1> | |
| 231 | - <?php | |
| 232 | - /** This action is documented in modules/sharedaddy/sharing.php */ | |
| 233 | - do_action( 'pre_admin_screen_sharing' ); | |
| 234 | - ?> | |
| 235 | - <?php $this->sharing_block(); ?> | |
| 236 | - </div> | |
| 237 | - <?php | |
| 241 | + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Settings_Page::render' ); | |
| 238 | 242 | } |
| 239 | 243 | |
| 240 | 244 | /** |
| 241 | 245 | * Returns the settings have been saved message. |
| 242 | 246 | * |
| 243 | - * @deprecated 13.2 | |
| 247 | + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Settings_Page::render() instead. | |
| 248 | + * | |
| 249 | + * @return void | |
| 244 | 250 | */ |
| 245 | 251 | public function updated_message() { |
| 246 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- ignoring since we are just displaying that the settings have been saved and not making any other changes to the site. | |
| 247 | - if ( isset( $_GET['update'] ) && 'saved' === $_GET['update'] ) { | |
| 248 | - echo '<div class="updated"><p>' . esc_html__( 'Settings have been saved', 'jetpack' ) . '</p></div>'; | |
| 249 | - } | |
| 252 | + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Settings_Page::render' ); | |
| 250 | 253 | } |
| 251 | 254 | |
| 252 | 255 | /** |
| 253 | - * Returns just the "sharing buttons" w/ like option block, so it can be inserted into different sharing page contexts | |
| 256 | + * Returns the Likes options block, so it can be inserted into different sharing page contexts. | |
| 254 | 257 | * |
| 255 | - * @deprecated 13.2 | |
| 258 | + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Likes_Section::render() instead. | |
| 259 | + * | |
| 260 | + * @return void | |
| 256 | 261 | */ |
| 257 | 262 | public function sharing_block() { |
| 258 | - ?> | |
| 259 | - <h2><?php esc_html_e( 'Sharing Buttons', 'jetpack' ); ?></h2> | |
| 260 | - <form method="post" action=""> | |
| 261 | - <table class="form-table"> | |
| 262 | - <tbody> | |
| 263 | - <?php | |
| 264 | - /** This action is documented in modules/sharedaddy/sharing.php */ | |
| 265 | - do_action( 'sharing_global_options' ); | |
| 266 | - ?> | |
| 267 | - </tbody> | |
| 268 | - </table> | |
| 269 | - | |
| 270 | - <p class="submit"> | |
| 271 | - <input type="submit" name="submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes', 'jetpack' ); ?>" /> | |
| 272 | - <?php wp_nonce_field( 'sharing-options' ); ?> | |
| 273 | - </form> | |
| 274 | - <?php | |
| 263 | + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Likes_Section::render' ); | |
| 275 | 264 | } |
| 276 | 265 | |
| 277 | 266 | /** |
| 278 | 267 | * Are likes enabled for this post? |
| @@ -285,8 +274,12 @@ | ||
| 285 | 274 | if ( ! $post || is_wp_error( $post ) ) { |
| 286 | 275 | return false; |
| 287 | 276 | } |
| 288 | 277 | |
| 278 | + if ( ! empty( $post->post_password ) ) { | |
| 279 | + return false; | |
| 280 | + } | |
| 281 | + | |
| 289 | 282 | $sitewide_likes_enabled = (bool) $this->is_enabled_sitewide(); |
| 290 | 283 | $post_likes_switched = get_post_meta( $post->ID, 'switch_like_status', true ); |
| 291 | 284 | |
| 292 | 285 | /* |
| @@ -439,9 +432,9 @@ | ||
| 439 | 432 | * @return bool |
| 440 | 433 | */ |
| 441 | 434 | public function is_single_post_enabled( $post_type = 'post' ) { |
| 442 | 435 | $options = $this->get_options(); |
| 443 | - return (bool) apply_filters( | |
| 436 | + | |
| 444 | 437 | /** |
| 445 | 438 | * Filters whether Likes should be enabled on single posts. |
| 446 | 439 | * |
| 447 | 440 | * The dynamic part of the filter, {$post_type}, allows you to specific the post type where Likes should be enabled. |
| @@ -451,11 +444,14 @@ | ||
| 451 | 444 | * @since 2.2.0 |
| 452 | 445 | * |
| 453 | 446 | * @param bool $enabled Are Post Likes enabled on single posts? |
| 454 | 447 | */ |
| 448 | + $post_likes_enabled = apply_filters( | |
| 455 | 449 | "wpl_is_single_{$post_type}_disabled", |
| 456 | - (bool) in_array( $post_type, $options['show'], true ) | |
| 450 | + in_array( $post_type, $options['show'], true ) | |
| 457 | 451 | ); |
| 452 | + | |
| 453 | + return (bool) $post_likes_enabled; | |
| 458 | 454 | } |
| 459 | 455 | |
| 460 | 456 | /** |
| 461 | 457 | * Get the 'disabled_likes' option from the DB of the current blog. |
| @@ -466,12 +462,45 @@ | ||
| 466 | 462 | $setting = array(); |
| 467 | 463 | $setting['disabled'] = get_option( 'disabled_likes' ); |
| 468 | 464 | $sharing = get_option( 'sharing-options', array() ); |
| 469 | 465 | |
| 466 | + if ( ! is_array( $sharing ) ) { | |
| 467 | + $sharing = array(); | |
| 468 | + } | |
| 469 | + if ( ! isset( $sharing['global'] ) || ! is_array( $sharing['global'] ) ) { | |
| 470 | + $sharing['global'] = array(); | |
| 471 | + } | |
| 472 | + | |
| 470 | 473 | // Default visibility settings |
| 471 | 474 | if ( ! isset( $sharing['global']['show'] ) ) { |
| 472 | - $sharing['global']['show'] = array( 'post', 'page' ); | |
| 475 | + $public_commentable_cpts = array_filter( | |
| 476 | + get_post_types( | |
| 477 | + array( | |
| 478 | + 'public' => true, | |
| 479 | + '_builtin' => false, | |
| 480 | + ) | |
| 481 | + ), | |
| 482 | + function ( $post_type ) { | |
| 483 | + return post_type_supports( $post_type, 'comments' ); | |
| 484 | + } | |
| 485 | + ); | |
| 486 | + $public_commentable_cpts = array_values( $public_commentable_cpts ); | |
| 473 | 487 | |
| 488 | + /** | |
| 489 | + * Filters the default post types that show Likes when no sharing settings have been saved. | |
| 490 | + * | |
| 491 | + * Only applies when the site has never explicitly configured Likes visibility. | |
| 492 | + * Once a site owner saves sharing settings, those are used instead. | |
| 493 | + * | |
| 494 | + * @since 16.2 | |
| 495 | + * | |
| 496 | + * @param string[] $post_types Array of post type slugs that will show Likes by default. | |
| 497 | + */ | |
| 498 | + $sharing['global']['show'] = apply_filters( | |
| 499 | + 'jetpack_likes_default_post_types', | |
| 500 | + array_merge( array( 'post', 'page' ), $public_commentable_cpts ) | |
| 501 | + ); | |
| 502 | + | |
| 474 | 503 | // Scalar check |
| 475 | 504 | } elseif ( is_scalar( $sharing['global']['show'] ) ) { |
| 476 | 505 | switch ( $sharing['global']['show'] ) { |
| 477 | 506 | case 'posts': |
| @@ -485,10 +514,11 @@ | ||
| 485 | 514 | break; |
| 486 | 515 | } |
| 487 | 516 | } |
| 488 | 517 | |
| 489 | - // Ensure it's always an array (even if not previously empty or scalar) | |
| 490 | - $setting['show'] = ! empty( $sharing['global']['show'] ) ? (array) $sharing['global']['show'] : array(); | |
| 518 | + // Ensure it's always an array (even if not previously empty or scalar). | |
| 519 | + $show = $sharing['global']['show'] ?? array(); | |
| 520 | + $setting['show'] = ! empty( $show ) ? (array) $show : array(); | |
| 491 | 521 | |
| 492 | 522 | /** |
| 493 | 523 | * Filters where the Likes are displayed. |
| 494 | 524 | * |
| @@ -516,9 +546,9 @@ | ||
| 516 | 546 | * @since 2.2.0 |
| 517 | 547 | * |
| 518 | 548 | * @param bool $enabled Are Post Likes enabled on archive/front/search pages? |
| 519 | 549 | */ |
| 520 | - return (bool) apply_filters( 'wpl_is_index_disabled', (bool) in_array( 'index', $options['show'], true ) ); | |
| 550 | + return (bool) apply_filters( 'wpl_is_index_disabled', in_array( 'index', $options['show'], true ) ); | |
| 521 | 551 | } |
| 522 | 552 | |
| 523 | 553 | /** |
| 524 | 554 | * Are Post Likes enabled on single pages? |
| @@ -535,9 +565,9 @@ | ||
| 535 | 565 | * @since 2.2.0 |
| 536 | 566 | * |
| 537 | 567 | * @param bool $enabled Are Post Likes enabled on single pages? |
| 538 | 568 | */ |
| 539 | - return (bool) apply_filters( 'wpl_is_single_page_disabled', (bool) in_array( 'page', $options['show'], true ) ); | |
| 569 | + return (bool) apply_filters( 'wpl_is_single_page_disabled', in_array( 'page', $options['show'], true ) ); | |
| 540 | 570 | } |
| 541 | 571 | |
| 542 | 572 | /** |
| 543 | 573 | * Are Media Likes enabled on single pages? |
| @@ -554,74 +584,20 @@ | ||
| 554 | 584 | * @since 2.2.0 |
| 555 | 585 | * |
| 556 | 586 | * @param bool $enabled Are Post Likes enabled on attachment pages? |
| 557 | 587 | */ |
| 558 | - return (bool) apply_filters( 'wpl_is_attachment_disabled', (bool) in_array( 'attachment', $options['show'], true ) ); | |
| 588 | + return (bool) apply_filters( 'wpl_is_attachment_disabled', in_array( 'attachment', $options['show'], true ) ); | |
| 559 | 589 | } |
| 560 | 590 | |
| 561 | 591 | /** |
| 562 | 592 | * The actual options block to be inserted into the sharing page. |
| 593 | + * | |
| 594 | + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Likes_Section::render() instead. | |
| 595 | + * | |
| 596 | + * @return void | |
| 563 | 597 | */ |
| 564 | 598 | public function admin_settings_init() { |
| 565 | - ?> | |
| 566 | - <tr> | |
| 567 | - <th scope="row"> | |
| 568 | - <label><?php esc_html_e( 'WordPress.com Likes are', 'jetpack' ); ?></label> | |
| 569 | - </th> | |
| 570 | - <td> | |
| 571 | - <div> | |
| 572 | - <label> | |
| 573 | - <input type="radio" class="code" name="wpl_default" value="on" <?php checked( $this->is_enabled_sitewide(), true ); ?> /> | |
| 574 | - <?php esc_html_e( 'On for all posts', 'jetpack' ); ?> | |
| 575 | - </label> | |
| 576 | - </div> | |
| 577 | - <div> | |
| 578 | - <label> | |
| 579 | - <input type="radio" class="code" name="wpl_default" value="off" <?php checked( $this->is_enabled_sitewide(), false ); ?> /> | |
| 580 | - <?php esc_html_e( 'Turned on per post', 'jetpack' ); ?> | |
| 581 | - </label> | |
| 582 | - <div> | |
| 583 | - </td> | |
| 584 | - </tr> | |
| 585 | - <?php if ( ! $this->in_jetpack ) : ?> | |
| 586 | - <tr> | |
| 587 | - <th scope="row"> | |
| 588 | - <label><?php esc_html_e( 'WordPress.com Reblog Button', 'jetpack' ); ?></label> | |
| 589 | - </th> | |
| 590 | - <td> | |
| 591 | - <div> | |
| 592 | - <label> | |
| 593 | - <input type="radio" class="code" name="jetpack_reblogs_enabled" value="on" <?php checked( $this->reblogs_enabled_sitewide(), true ); ?> /> | |
| 594 | - <?php esc_html_e( 'Show the Reblog button on posts', 'jetpack' ); ?> | |
| 595 | - </label> | |
| 596 | - </div> | |
| 597 | - <div> | |
| 598 | - <label> | |
| 599 | - <input type="radio" class="code" name="jetpack_reblogs_enabled" value="off" <?php checked( $this->reblogs_enabled_sitewide(), false ); ?> /> | |
| 600 | - <?php esc_html_e( 'Don\'t show the Reblog button on posts', 'jetpack' ); ?> | |
| 601 | - </label> | |
| 602 | - </div> | |
| 603 | - </td> | |
| 604 | - </tr> | |
| 605 | - <!-- WPCOM only: Comment Likes --> | |
| 606 | - <?php if ( ! $this->in_jetpack ) : ?> | |
| 607 | - <tr> | |
| 608 | - <th scope="row"> | |
| 609 | - <label><?php esc_html_e( 'Comment Likes are', 'jetpack' ); ?></label> | |
| 610 | - </th> | |
| 611 | - <td> | |
| 612 | - <div> | |
| 613 | - <label> | |
| 614 | - <input type="checkbox" class="code" name="jetpack_comment_likes_enabled" value="1" <?php checked( $this->is_comments_enabled(), true ); ?> /> | |
| 615 | - <?php esc_html_e( 'On for all comments', 'jetpack' ); ?> | |
| 616 | - </label> | |
| 617 | - </div> | |
| 618 | - </td> | |
| 619 | - </tr> | |
| 620 | - <?php endif; ?> | |
| 621 | - <?php endif; ?> | |
| 622 | - </tbody> <?php // closes the tbody attached to sharing_show_buttons_on_row_start... ?> | |
| 623 | - <?php | |
| 599 | + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Likes_Section::render' ); | |
| 624 | 600 | } |
| 625 | 601 | |
| 626 | 602 | /** |
| 627 | 603 | * Returns the current state of the "WordPress.com Reblogs are" option. |
| @@ -663,155 +639,46 @@ | ||
| 663 | 639 | } |
| 664 | 640 | |
| 665 | 641 | /** |
| 666 | 642 | * Saves the setting in the database. |
| 643 | + * | |
| 644 | + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Post_Handler::maybe_handle() instead. | |
| 645 | + * | |
| 646 | + * @return void | |
| 667 | 647 | */ |
| 668 | 648 | public function admin_settings_callback() { |
| 669 | - if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( $_POST['_wpnonce'], 'sharing-options' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- WordPress core doesn't unslash or verify nonces either. | |
| 670 | - return; | |
| 671 | - } | |
| 672 | - | |
| 673 | - // We're looking for these, and doing a dance to set some stats and save | |
| 674 | - // them together in array option. | |
| 675 | - if ( ! empty( $_POST['wpl_default'] ) ) { | |
| 676 | - $new_state = sanitize_text_field( wp_unslash( $_POST['wpl_default'] ) ); | |
| 677 | - } else { | |
| 678 | - $new_state = 'on'; | |
| 679 | - } | |
| 680 | - | |
| 681 | - if ( ! empty( $_POST['jetpack_reblogs_enabled'] ) ) { | |
| 682 | - $reblogs_new_state = sanitize_text_field( wp_unslash( $_POST['jetpack_reblogs_enabled'] ) ); | |
| 683 | - } else { | |
| 684 | - $reblogs_new_state = 'on'; | |
| 685 | - } | |
| 686 | - | |
| 687 | - // Checked (enabled) | |
| 688 | - switch ( $new_state ) { | |
| 689 | - case 'off': | |
| 690 | - update_option( 'disabled_likes', 1 ); | |
| 691 | - break; | |
| 692 | - case 'on': | |
| 693 | - default: | |
| 694 | - delete_option( 'disabled_likes' ); | |
| 695 | - break; | |
| 696 | - } | |
| 697 | - | |
| 698 | - switch ( $reblogs_new_state ) { | |
| 699 | - case 'off': | |
| 700 | - update_option( 'disabled_reblogs', 1 ); | |
| 701 | - break; | |
| 702 | - case 'on': | |
| 703 | - default: | |
| 704 | - delete_option( 'disabled_reblogs' ); | |
| 705 | - break; | |
| 706 | - } | |
| 707 | - | |
| 708 | - // WPCOM only: Comment Likes | |
| 709 | - if ( ! $this->in_jetpack ) { | |
| 710 | - if ( ! empty( $_POST['jetpack_comment_likes_enabled'] ) ) { | |
| 711 | - $new_comments_state = sanitize_text_field( wp_unslash( $_POST['jetpack_comment_likes_enabled'] ) ); | |
| 712 | - } else { | |
| 713 | - $new_comments_state = false; | |
| 714 | - } | |
| 715 | - switch ( (bool) $new_comments_state ) { | |
| 716 | - case true: | |
| 717 | - update_option( 'jetpack_comment_likes_enabled', 1 ); | |
| 718 | - break; | |
| 719 | - case false: | |
| 720 | - default: | |
| 721 | - update_option( 'jetpack_comment_likes_enabled', 0 ); | |
| 722 | - break; | |
| 723 | - } | |
| 724 | - } | |
| 649 | + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Post_Handler::maybe_handle' ); | |
| 725 | 650 | } |
| 726 | 651 | |
| 727 | 652 | /** |
| 728 | 653 | * Adds the admin update hook so we can save settings even if Sharedaddy is not enabled. |
| 654 | + * | |
| 655 | + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Post_Handler::maybe_handle() instead. | |
| 656 | + * | |
| 657 | + * @return void | |
| 729 | 658 | */ |
| 730 | 659 | public function process_update_requests_if_sharedaddy_not_loaded() { |
| 731 | - if ( isset( $_GET['page'] ) && ( $_GET['page'] === 'sharing.php' || $_GET['page'] === 'sharing' ) ) { | |
| 732 | - if ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'sharing-options' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- WordPress core doesn't unslash or verify nonces either. | |
| 733 | - /** This action is documented in modules/sharedaddy/sharing.php */ | |
| 734 | - do_action( 'sharing_admin_update' ); | |
| 735 | - wp_safe_redirect( admin_url( 'options-general.php?page=sharing&update=saved' ) ); | |
| 736 | - die(); | |
| 737 | - } | |
| 738 | - } | |
| 660 | + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Post_Handler::maybe_handle' ); | |
| 739 | 661 | } |
| 740 | 662 | |
| 741 | 663 | /** |
| 742 | 664 | * If sharedaddy is not loaded, we don't have the "Show buttons on" yet, so we need to add that since it affects likes too. |
| 665 | + * | |
| 666 | + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Placement_Section::render() instead. | |
| 667 | + * | |
| 668 | + * @return void | |
| 743 | 669 | */ |
| 744 | 670 | public function admin_settings_showbuttonon_init() { |
| 745 | - /** This action is documented in modules/sharedaddy/sharing.php */ | |
| 746 | - echo apply_filters( 'sharing_show_buttons_on_row_start', '<tr valign="top">' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 747 | - ?> | |
| 748 | - <th scope="row"><label><?php esc_html_e( 'Show buttons on', 'jetpack' ); ?></label></th> | |
| 749 | - <td> | |
| 750 | - <?php | |
| 751 | - $br = false; | |
| 752 | - $shows = array_values( get_post_types( array( 'public' => true ) ) ); | |
| 753 | - array_unshift( $shows, 'index' ); | |
| 754 | - $global = $this->get_options(); | |
| 755 | - foreach ( $shows as $show ) : | |
| 756 | - if ( 'index' === $show ) { | |
| 757 | - $label = __( 'Front Page, Archive Pages, and Search Results', 'jetpack' ); | |
| 758 | - } else { | |
| 759 | - $post_type_object = get_post_type_object( $show ); | |
| 760 | - $label = $post_type_object->labels->name; | |
| 761 | - } | |
| 762 | - | |
| 763 | - if ( $br ) { | |
| 764 | - echo '<br />'; | |
| 765 | - } | |
| 766 | - ?> | |
| 767 | - <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> | |
| 768 | - <?php | |
| 769 | - $br = true; | |
| 770 | - endforeach; | |
| 771 | - ?> | |
| 772 | - </td> | |
| 773 | - <?php | |
| 774 | - /** This action is documented in modules/sharedaddy/sharing.php */ | |
| 775 | - echo apply_filters( 'sharing_show_buttons_on_row_end', '</tr>' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 671 | + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Placement_Section::render' ); | |
| 776 | 672 | } |
| 777 | 673 | |
| 778 | 674 | /** |
| 779 | 675 | * If sharedaddy is not loaded, we still need to save the the settings of the "Show buttons on" option. |
| 676 | + * | |
| 677 | + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Post_Handler::maybe_handle() instead. | |
| 678 | + * | |
| 679 | + * @return void | |
| 780 | 680 | */ |
| 781 | 681 | public function admin_settings_showbuttonon_callback() { |
| 782 | - $options = get_option( 'sharing-options' ); | |
| 783 | - if ( ! is_array( $options ) ) { | |
| 784 | - $options = array(); | |
| 785 | - } | |
| 786 | - | |
| 787 | - $shows = array_values( get_post_types( array( 'public' => true ) ) ); | |
| 788 | - $shows[] = 'index'; | |
| 789 | - // phpcs:ignore WordPress.Security.NonceVerification.Missing -- triggered due to the 'sharing_admin_update' action, but the code in sharing.php checks for the nonce before firing the action. | |
| 790 | - $data = $_POST; | |
| 791 | - | |
| 792 | - if ( isset( $data['show'] ) ) { | |
| 793 | - if ( is_scalar( $data['show'] ) ) { | |
| 794 | - switch ( $data['show'] ) { | |
| 795 | - case 'posts': | |
| 796 | - $data['show'] = array( 'post', 'page' ); | |
| 797 | - break; | |
| 798 | - case 'index': | |
| 799 | - $data['show'] = array( 'index' ); | |
| 800 | - break; | |
| 801 | - case 'posts-index': | |
| 802 | - $data['show'] = array( 'post', 'page', 'index' ); | |
| 803 | - break; | |
| 804 | - } | |
| 805 | - } | |
| 806 | - | |
| 807 | - $data['show'] = array_intersect( $data['show'], $shows ); | |
| 808 | - if ( $data['show'] ) { | |
| 809 | - $options['global']['show'] = $data['show']; | |
| 810 | - } | |
| 811 | - } else { | |
| 812 | - $options['global']['show'] = array(); | |
| 813 | - } | |
| 814 | - | |
| 815 | - update_option( 'sharing-options', $options ); | |
| 682 | + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Post_Handler::maybe_handle' ); | |
| 816 | 683 | } |
| 817 | 684 | } |