jetpack
/
jetpack_vendor
/
automattic
/
jetpack-sharing-likes
/
src
/
settings
/
class-sharing-resources.php
class-sharing-resources.php in Jetpack – WP Security, Backup, Speed, & Growth 16.3-beta, at jetpack_vendor/automattic/jetpack-sharing-likes/src/settings/class-sharing-resources.php
| 1 | <?php |
| 2 | /** |
| 3 | * The "Disable CSS and JS" setting on 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 | * Stops sharedaddy enqueuing its own CSS and JS, for themes that bundle them. |
| 14 | */ |
| 15 | final class Sharing_Resources { |
| 16 | |
| 17 | /** |
| 18 | * Option `sharing_init()` in `modules/sharedaddy/sharedaddy.php` reads. |
| 19 | */ |
| 20 | public const OPTION = 'sharedaddy_disable_resources'; |
| 21 | |
| 22 | /** |
| 23 | * Field name the checkbox posts. |
| 24 | */ |
| 25 | private const FIELD = 'disable_resources'; |
| 26 | |
| 27 | /** |
| 28 | * Whether the setting has anything to configure on this site. |
| 29 | * |
| 30 | * It only affects legacy sharing buttons, and Simple never loads `sharedaddy.php`. |
| 31 | */ |
| 32 | public static function is_available(): bool { |
| 33 | return ! Environment::is_simple_site() && Section_State::configures( Sharing_Section::state() ); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Table row for the setting. |
| 38 | */ |
| 39 | public static function render(): string { |
| 40 | if ( ! self::is_available() ) { |
| 41 | return ''; |
| 42 | } |
| 43 | |
| 44 | return sprintf( |
| 45 | '<tr valign="top"> |
| 46 | <th scope="row"><label for="disable_css">%1$s</label></th> |
| 47 | <td> |
| 48 | <input id="disable_css" type="checkbox" name="%2$s"%3$s /> <small><em>%4$s</em></small> |
| 49 | </td> |
| 50 | </tr>', |
| 51 | esc_html__( 'Disable CSS and JS', 'jetpack-sharing-likes' ), |
| 52 | esc_attr( self::FIELD ), |
| 53 | checked( '1', (string) get_option( self::OPTION ), false ), |
| 54 | esc_html__( 'Advanced. If this option is checked, you must include these files in your theme manually for the sharing links to work.', 'jetpack-sharing-likes' ) |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Save the checkbox. Callers verify the nonce. |
| 60 | * |
| 61 | * Only while it renders: an unchecked box posts nothing, so saving it from |
| 62 | * a screen that never showed it would switch the setting off. |
| 63 | */ |
| 64 | public static function save(): void { |
| 65 | if ( ! self::is_available() ) { |
| 66 | return; |
| 67 | } |
| 68 | |
| 69 | // phpcs:ignore WordPress.Security.NonceVerification.Missing -- verified by the caller. |
| 70 | update_option( self::OPTION, isset( $_POST[ self::FIELD ] ) ? 1 : 0 ); |
| 71 | } |
| 72 | } |
| 73 |