| @@ -208,88 +208,60 @@ | ||
| 208 | 208 | |
| 209 | 209 | /** |
| 210 | 210 | * Should we register the Settings > Sharing screen ourselves? |
| 211 | 211 | * |
| 212 | - * Our settings are displayed on Settings > Sharing, but that screen is registered by | |
| 213 | - * the Sharing (sharedaddy) module. When that module is off, nothing registers the | |
| 214 | - * screen and our settings become unreachable. | |
| 212 | + * @deprecated 16.3 Settings > Sharing is registered by Automattic\Jetpack\Sharing_Likes\Settings\Settings_Page. | |
| 215 | 213 | * |
| 216 | - * WordPress.com Simple sites are excluded: the screen is registered elsewhere there. | |
| 217 | - * | |
| 218 | - * @since 16.2 | |
| 219 | - * | |
| 220 | 214 | * @param bool $sharedaddy_active Whether the Sharing (sharedaddy) module is active. |
| 221 | 215 | * @return bool |
| 222 | 216 | */ |
| 223 | - public function needs_own_sharing_menu( $sharedaddy_active ) { | |
| 224 | - return ! $sharedaddy_active && $this->in_jetpack; | |
| 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; | |
| 225 | 220 | } |
| 226 | 221 | |
| 227 | 222 | /** |
| 228 | 223 | * Adds the 'sharing' menu to the settings menu. |
| 229 | - * Only ran when the Sharing (sharedaddy) module is inactive on a Jetpack site, | |
| 230 | - * since Settings > Sharing is where our settings live. See needs_own_sharing_menu(). | |
| 224 | + * | |
| 225 | + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Settings_Page::register_menu() instead. | |
| 226 | + * | |
| 227 | + * @return void | |
| 231 | 228 | */ |
| 232 | 229 | public function sharing_menu() { |
| 233 | - 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' ); | |
| 234 | 231 | } |
| 235 | 232 | |
| 236 | 233 | /** |
| 237 | - * Provides a sharing page with the sharing_global_options hook | |
| 238 | - * so we can display the setting. | |
| 239 | - * Only ran when the Sharing (sharedaddy) module is inactive on a Jetpack site, | |
| 240 | - * since Settings > Sharing is where our settings live. See needs_own_sharing_menu(). | |
| 234 | + * Provides a sharing page with the sharing_global_options hook so we can display the setting. | |
| 235 | + * | |
| 236 | + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Settings_Page::render() instead. | |
| 237 | + * | |
| 238 | + * @return void | |
| 241 | 239 | */ |
| 242 | 240 | public function sharing_page() { |
| 243 | - $this->updated_message(); | |
| 244 | - ?> | |
| 245 | - <div class="wrap"> | |
| 246 | - <div class="icon32" id="icon-options-general"><br /></div> | |
| 247 | - <h1><?php esc_html_e( 'Sharing Settings', 'jetpack' ); ?></h1> | |
| 248 | - <?php | |
| 249 | - /** This action is documented in modules/sharedaddy/sharing.php */ | |
| 250 | - do_action( 'pre_admin_screen_sharing' ); | |
| 251 | - ?> | |
| 252 | - <?php $this->sharing_block(); ?> | |
| 253 | - </div> | |
| 254 | - <?php | |
| 241 | + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Settings_Page::render' ); | |
| 255 | 242 | } |
| 256 | 243 | |
| 257 | 244 | /** |
| 258 | 245 | * Returns the settings have been saved message. |
| 246 | + * | |
| 247 | + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Settings_Page::render() instead. | |
| 248 | + * | |
| 249 | + * @return void | |
| 259 | 250 | */ |
| 260 | 251 | public function updated_message() { |
| 261 | - // 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. | |
| 262 | - if ( isset( $_GET['update'] ) && 'saved' === $_GET['update'] ) { | |
| 263 | - echo '<div class="updated"><p>' . esc_html__( 'Settings have been saved', 'jetpack' ) . '</p></div>'; | |
| 264 | - } | |
| 252 | + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Settings_Page::render' ); | |
| 265 | 253 | } |
| 266 | 254 | |
| 267 | 255 | /** |
| 268 | 256 | * Returns the Likes options block, so it can be inserted into different sharing page contexts. |
| 269 | 257 | * |
| 270 | - * Only rendered when the Sharing (sharedaddy) module is off, which is why the heading | |
| 271 | - * does not mention sharing buttons: what lands under it is the Likes settings, the | |
| 272 | - * "Show buttons on" setting that governs where Likes appear, and the Twitter Site Tag. | |
| 258 | + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Settings\Likes_Section::render() instead. | |
| 259 | + * | |
| 260 | + * @return void | |
| 273 | 261 | */ |
| 274 | 262 | public function sharing_block() { |
| 275 | - ?> | |
| 276 | - <h2><?php esc_html_e( 'Likes and Sharing', 'jetpack' ); ?></h2> | |
| 277 | - <form method="post" action=""> | |
| 278 | - <table class="form-table"> | |
| 279 | - <tbody> | |
| 280 | - <?php | |
| 281 | - /** This action is documented in modules/sharedaddy/sharing.php */ | |
| 282 | - do_action( 'sharing_global_options' ); | |
| 283 | - ?> | |
| 284 | - </tbody> | |
| 285 | - </table> | |
| 286 | - | |
| 287 | - <p class="submit"> | |
| 288 | - <input type="submit" name="submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes', 'jetpack' ); ?>" /> | |
| 289 | - <?php wp_nonce_field( 'sharing-options' ); ?> | |
| 290 | - </form> | |
| 291 | - <?php | |
| 263 | + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Likes_Section::render' ); | |
| 292 | 264 | } |
| 293 | 265 | |
| 294 | 266 | /** |
| 295 | 267 | * Are likes enabled for this post? |
| @@ -617,69 +589,15 @@ | ||
| 617 | 589 | } |
| 618 | 590 | |
| 619 | 591 | /** |
| 620 | 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 | |
| 621 | 597 | */ |
| 622 | 598 | public function admin_settings_init() { |
| 623 | - ?> | |
| 624 | - <tr> | |
| 625 | - <th scope="row"> | |
| 626 | - <label><?php esc_html_e( 'WordPress.com Likes are', 'jetpack' ); ?></label> | |
| 627 | - </th> | |
| 628 | - <td> | |
| 629 | - <div> | |
| 630 | - <label> | |
| 631 | - <input type="radio" class="code" name="wpl_default" value="on" <?php checked( $this->is_enabled_sitewide(), true ); ?> /> | |
| 632 | - <?php esc_html_e( 'On for all posts', 'jetpack' ); ?> | |
| 633 | - </label> | |
| 634 | - </div> | |
| 635 | - <div> | |
| 636 | - <label> | |
| 637 | - <input type="radio" class="code" name="wpl_default" value="off" <?php checked( $this->is_enabled_sitewide(), false ); ?> /> | |
| 638 | - <?php esc_html_e( 'Turned on per post', 'jetpack' ); ?> | |
| 639 | - </label> | |
| 640 | - <div> | |
| 641 | - </td> | |
| 642 | - </tr> | |
| 643 | - <?php if ( ! $this->in_jetpack ) : ?> | |
| 644 | - <tr> | |
| 645 | - <th scope="row"> | |
| 646 | - <label><?php esc_html_e( 'WordPress.com Reblog Button', 'jetpack' ); ?></label> | |
| 647 | - </th> | |
| 648 | - <td> | |
| 649 | - <div> | |
| 650 | - <label> | |
| 651 | - <input type="radio" class="code" name="jetpack_reblogs_enabled" value="on" <?php checked( $this->reblogs_enabled_sitewide(), true ); ?> /> | |
| 652 | - <?php esc_html_e( 'Show the Reblog button on posts', 'jetpack' ); ?> | |
| 653 | - </label> | |
| 654 | - </div> | |
| 655 | - <div> | |
| 656 | - <label> | |
| 657 | - <input type="radio" class="code" name="jetpack_reblogs_enabled" value="off" <?php checked( $this->reblogs_enabled_sitewide(), false ); ?> /> | |
| 658 | - <?php esc_html_e( 'Don\'t show the Reblog button on posts', 'jetpack' ); ?> | |
| 659 | - </label> | |
| 660 | - </div> | |
| 661 | - </td> | |
| 662 | - </tr> | |
| 663 | - <!-- WPCOM only: Comment Likes --> | |
| 664 | - <?php if ( ! $this->in_jetpack ) : ?> | |
| 665 | - <tr> | |
| 666 | - <th scope="row"> | |
| 667 | - <label><?php esc_html_e( 'Comment Likes are', 'jetpack' ); ?></label> | |
| 668 | - </th> | |
| 669 | - <td> | |
| 670 | - <div> | |
| 671 | - <label> | |
| 672 | - <input type="checkbox" class="code" name="jetpack_comment_likes_enabled" value="1" <?php checked( $this->is_comments_enabled(), true ); ?> /> | |
| 673 | - <?php esc_html_e( 'On for all comments', 'jetpack' ); ?> | |
| 674 | - </label> | |
| 675 | - </div> | |
| 676 | - </td> | |
| 677 | - </tr> | |
| 678 | - <?php endif; ?> | |
| 679 | - <?php endif; ?> | |
| 680 | - </tbody> <?php // closes the tbody attached to sharing_show_buttons_on_row_start... ?> | |
| 681 | - <?php | |
| 599 | + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Likes_Section::render' ); | |
| 682 | 600 | } |
| 683 | 601 | |
| 684 | 602 | /** |
| 685 | 603 | * Returns the current state of the "WordPress.com Reblogs are" option. |
| @@ -721,155 +639,46 @@ | ||
| 721 | 639 | } |
| 722 | 640 | |
| 723 | 641 | /** |
| 724 | 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 | |
| 725 | 647 | */ |
| 726 | 648 | public function admin_settings_callback() { |
| 727 | - 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. | |
| 728 | - return; | |
| 729 | - } | |
| 730 | - | |
| 731 | - // We're looking for these, and doing a dance to set some stats and save | |
| 732 | - // them together in array option. | |
| 733 | - if ( ! empty( $_POST['wpl_default'] ) ) { | |
| 734 | - $new_state = sanitize_text_field( wp_unslash( $_POST['wpl_default'] ) ); | |
| 735 | - } else { | |
| 736 | - $new_state = 'on'; | |
| 737 | - } | |
| 738 | - | |
| 739 | - if ( ! empty( $_POST['jetpack_reblogs_enabled'] ) ) { | |
| 740 | - $reblogs_new_state = sanitize_text_field( wp_unslash( $_POST['jetpack_reblogs_enabled'] ) ); | |
| 741 | - } else { | |
| 742 | - $reblogs_new_state = 'on'; | |
| 743 | - } | |
| 744 | - | |
| 745 | - // Checked (enabled) | |
| 746 | - switch ( $new_state ) { | |
| 747 | - case 'off': | |
| 748 | - update_option( 'disabled_likes', 1 ); | |
| 749 | - break; | |
| 750 | - case 'on': | |
| 751 | - default: | |
| 752 | - delete_option( 'disabled_likes' ); | |
| 753 | - break; | |
| 754 | - } | |
| 755 | - | |
| 756 | - switch ( $reblogs_new_state ) { | |
| 757 | - case 'off': | |
| 758 | - update_option( 'disabled_reblogs', 1 ); | |
| 759 | - break; | |
| 760 | - case 'on': | |
| 761 | - default: | |
| 762 | - delete_option( 'disabled_reblogs' ); | |
| 763 | - break; | |
| 764 | - } | |
| 765 | - | |
| 766 | - // WPCOM only: Comment Likes | |
| 767 | - if ( ! $this->in_jetpack ) { | |
| 768 | - if ( ! empty( $_POST['jetpack_comment_likes_enabled'] ) ) { | |
| 769 | - $new_comments_state = sanitize_text_field( wp_unslash( $_POST['jetpack_comment_likes_enabled'] ) ); | |
| 770 | - } else { | |
| 771 | - $new_comments_state = false; | |
| 772 | - } | |
| 773 | - switch ( (bool) $new_comments_state ) { | |
| 774 | - case true: | |
| 775 | - update_option( 'jetpack_comment_likes_enabled', 1 ); | |
| 776 | - break; | |
| 777 | - case false: | |
| 778 | - default: | |
| 779 | - update_option( 'jetpack_comment_likes_enabled', 0 ); | |
| 780 | - break; | |
| 781 | - } | |
| 782 | - } | |
| 649 | + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Post_Handler::maybe_handle' ); | |
| 783 | 650 | } |
| 784 | 651 | |
| 785 | 652 | /** |
| 786 | 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 | |
| 787 | 658 | */ |
| 788 | 659 | public function process_update_requests_if_sharedaddy_not_loaded() { |
| 789 | - if ( isset( $_GET['page'] ) && ( $_GET['page'] === 'sharing.php' || $_GET['page'] === 'sharing' ) ) { | |
| 790 | - 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. | |
| 791 | - /** This action is documented in modules/sharedaddy/sharing.php */ | |
| 792 | - do_action( 'sharing_admin_update' ); | |
| 793 | - wp_safe_redirect( admin_url( 'options-general.php?page=sharing&update=saved' ) ); | |
| 794 | - die( 0 ); | |
| 795 | - } | |
| 796 | - } | |
| 660 | + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Post_Handler::maybe_handle' ); | |
| 797 | 661 | } |
| 798 | 662 | |
| 799 | 663 | /** |
| 800 | 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 | |
| 801 | 669 | */ |
| 802 | 670 | public function admin_settings_showbuttonon_init() { |
| 803 | - /** This action is documented in modules/sharedaddy/sharing.php */ | |
| 804 | - echo apply_filters( 'sharing_show_buttons_on_row_start', '<tr valign="top">' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 805 | - ?> | |
| 806 | - <th scope="row"><label><?php esc_html_e( 'Show buttons on', 'jetpack' ); ?></label></th> | |
| 807 | - <td> | |
| 808 | - <?php | |
| 809 | - $br = false; | |
| 810 | - $shows = array_values( get_post_types( array( 'public' => true ) ) ); | |
| 811 | - array_unshift( $shows, 'index' ); | |
| 812 | - $global = $this->get_options(); | |
| 813 | - foreach ( $shows as $show ) : | |
| 814 | - if ( 'index' === $show ) { | |
| 815 | - $label = __( 'Front Page, Archive Pages, and Search Results', 'jetpack' ); | |
| 816 | - } else { | |
| 817 | - $post_type_object = get_post_type_object( $show ); | |
| 818 | - $label = $post_type_object->labels->name; | |
| 819 | - } | |
| 820 | - | |
| 821 | - if ( $br ) { | |
| 822 | - echo '<br />'; | |
| 823 | - } | |
| 824 | - ?> | |
| 825 | - <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> | |
| 826 | - <?php | |
| 827 | - $br = true; | |
| 828 | - endforeach; | |
| 829 | - ?> | |
| 830 | - </td> | |
| 831 | - <?php | |
| 832 | - /** This action is documented in modules/sharedaddy/sharing.php */ | |
| 833 | - 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' ); | |
| 834 | 672 | } |
| 835 | 673 | |
| 836 | 674 | /** |
| 837 | 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 | |
| 838 | 680 | */ |
| 839 | 681 | public function admin_settings_showbuttonon_callback() { |
| 840 | - $options = get_option( 'sharing-options' ); | |
| 841 | - if ( ! is_array( $options ) ) { | |
| 842 | - $options = array(); | |
| 843 | - } | |
| 844 | - | |
| 845 | - $shows = array_values( get_post_types( array( 'public' => true ) ) ); | |
| 846 | - $shows[] = 'index'; | |
| 847 | - // 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. | |
| 848 | - $data = $_POST; | |
| 849 | - | |
| 850 | - if ( isset( $data['show'] ) ) { | |
| 851 | - if ( is_scalar( $data['show'] ) ) { | |
| 852 | - switch ( $data['show'] ) { | |
| 853 | - case 'posts': | |
| 854 | - $data['show'] = array( 'post', 'page' ); | |
| 855 | - break; | |
| 856 | - case 'index': | |
| 857 | - $data['show'] = array( 'index' ); | |
| 858 | - break; | |
| 859 | - case 'posts-index': | |
| 860 | - $data['show'] = array( 'post', 'page', 'index' ); | |
| 861 | - break; | |
| 862 | - } | |
| 863 | - } | |
| 864 | - | |
| 865 | - $data['show'] = array_intersect( $data['show'], $shows ); | |
| 866 | - if ( $data['show'] ) { | |
| 867 | - $options['global']['show'] = $data['show']; | |
| 868 | - } | |
| 869 | - } else { | |
| 870 | - $options['global']['show'] = array(); | |
| 871 | - } | |
| 872 | - | |
| 873 | - update_option( 'sharing-options', $options ); | |
| 682 | + _deprecated_function( __METHOD__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Settings\Post_Handler::maybe_handle' ); | |
| 874 | 683 | } |
| 875 | 684 | } |