jetpack
/
jetpack_vendor
/
automattic
/
jetpack-sharing-likes
/
src
/
settings
/
class-comment-likes-section.php
class-comment-likes-section.php in Jetpack – WP Security, Backup, Speed, & Growth 16.3-beta, at jetpack_vendor/automattic/jetpack-sharing-likes/src/settings/class-comment-likes-section.php
| 1 | <?php |
| 2 | /** |
| 3 | * The Comment Likes section of Settings > Sharing. |
| 4 | * |
| 5 | * @package automattic/jetpack-sharing-likes |
| 6 | */ |
| 7 | |
| 8 | declare( strict_types = 1 ); |
| 9 | |
| 10 | namespace Automattic\Jetpack\Sharing_Likes\Settings; |
| 11 | |
| 12 | /** |
| 13 | * Renders the Comment Likes section. |
| 14 | * |
| 15 | * Comment Likes run whether the Like buttons are on, off, or replaced by the |
| 16 | * block, and comments have no block to move to, so this section has no variants. |
| 17 | */ |
| 18 | final class Comment_Likes_Section { |
| 19 | |
| 20 | /** |
| 21 | * Anchor for the section. |
| 22 | */ |
| 23 | public const ANCHOR = 'comment-likes'; |
| 24 | |
| 25 | /** |
| 26 | * Render the section. |
| 27 | */ |
| 28 | public static function render(): void { |
| 29 | printf( '<div class="jetpack-sharing-settings__section" id="%s">', esc_attr( self::ANCHOR ) ); |
| 30 | printf( '<h2>%s</h2>', esc_html_x( 'Comment Likes', 'Settings header', 'jetpack-sharing-likes' ) ); |
| 31 | |
| 32 | // The module requires a connection, so offline mode gets no switch that would do nothing. |
| 33 | if ( ! Environment::likes_supported() ) { |
| 34 | printf( |
| 35 | '<p>%s</p>', |
| 36 | Environment::is_offline_mode() |
| 37 | ? esc_html__( 'Comment Likes need a connection to WordPress.com, which is unavailable while your site is in offline mode.', 'jetpack-sharing-likes' ) |
| 38 | : esc_html__( 'Comment Likes need a connection to WordPress.com. Connect your site to turn them on.', 'jetpack-sharing-likes' ) |
| 39 | ); |
| 40 | echo '</div>'; |
| 41 | return; |
| 42 | } |
| 43 | |
| 44 | if ( Environment::comment_likes_follow_likes_settings() ) { |
| 45 | Placement_Section::render_summary( Placement_Section::FEATURE_COMMENT_LIKES ); |
| 46 | } |
| 47 | |
| 48 | self::render_fields(); |
| 49 | |
| 50 | echo '</div>'; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * The on/off switch, plus the sitewide Likes default when nothing else on the screen shows it. |
| 55 | * |
| 56 | * The switch is Simple's option, or the module on Atomic and Jetpack sites. |
| 57 | */ |
| 58 | private static function render_fields(): void { |
| 59 | $shows_default = Environment::comment_likes_follow_likes_settings() |
| 60 | && ! Section_State::configures( Likes_Section::state() ); |
| 61 | |
| 62 | ob_start(); |
| 63 | ?> |
| 64 | <table class="form-table"> |
| 65 | <tbody> |
| 66 | <tr> |
| 67 | <th scope="row"></th> |
| 68 | <td> |
| 69 | <label> |
| 70 | <input type="checkbox" name="jetpack_comment_likes_enabled" value="1" <?php checked( Environment::comment_likes_enabled() ); ?> /> |
| 71 | <?php esc_html_e( 'Allow readers to like individual comments', 'jetpack-sharing-likes' ); ?> |
| 72 | </label> |
| 73 | </td> |
| 74 | </tr> |
| 75 | <?php |
| 76 | if ( $shows_default ) { |
| 77 | Likes_Section::render_sitewide_default_row( __( 'Comment Likes are', 'jetpack-sharing-likes' ) ); |
| 78 | } |
| 79 | ?> |
| 80 | </tbody> |
| 81 | </table> |
| 82 | <?php |
| 83 | Settings_Form::render_fields( Settings_Form::SECTION_COMMENT_LIKES, (string) ob_get_clean() ); |
| 84 | |
| 85 | if ( $shows_default ) { |
| 86 | // The default saves through the Like buttons handler, which only runs for a claimed section. |
| 87 | Settings_Form::render_fields( Settings_Form::SECTION_LIKES, '' ); |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 |