Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 13 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| Likes_Options | |
0.00% |
0 / 13 |
|
0.00% |
0 / 6 |
90 | |
0.00% |
0 / 1 |
| likes_enabled_sitewide | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| reblogs_enabled_sitewide | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| comment_likes_enabled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| set_likes_enabled | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| set_reblogs_enabled | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| set_comment_likes_enabled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Reads the Likes options without depending on the Likes module being loaded. |
| 4 | * |
| 5 | * @package automattic/jetpack-sharing-likes |
| 6 | */ |
| 7 | |
| 8 | declare( strict_types = 1 ); |
| 9 | |
| 10 | namespace Automattic\Jetpack\Sharing_Likes\Settings; |
| 11 | |
| 12 | use Jetpack_Options; |
| 13 | |
| 14 | /** |
| 15 | * The Likes options, as the settings screen needs them. |
| 16 | * |
| 17 | * `Jetpack_Likes_Settings` carries equivalent accessors, but it only loads with |
| 18 | * the Likes module, and this screen renders whether that module is on or off. |
| 19 | */ |
| 20 | final class Likes_Options { |
| 21 | |
| 22 | /** |
| 23 | * Whether Likes are on for every post. |
| 24 | */ |
| 25 | public static function likes_enabled_sitewide(): bool { |
| 26 | /** This filter is documented in projects/plugins/jetpack/modules/likes/jetpack-likes-settings.php */ |
| 27 | return (bool) apply_filters( |
| 28 | 'wpl_is_enabled_sitewide', |
| 29 | ! Jetpack_Options::get_option_and_ensure_autoload( 'disabled_likes', 0 ) |
| 30 | ); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Whether the Reblog button shows on posts. WordPress.com Simple only. |
| 35 | */ |
| 36 | public static function reblogs_enabled_sitewide(): bool { |
| 37 | /** This filter is documented in projects/plugins/jetpack/modules/likes/jetpack-likes-settings.php */ |
| 38 | return (bool) apply_filters( 'wpl_reblogging_enabled_sitewide', ! get_option( 'disabled_reblogs' ) ); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Whether the Comment Likes option is on. Only WordPress.com Simple reads it. |
| 43 | */ |
| 44 | public static function comment_likes_enabled(): bool { |
| 45 | /** This filter is documented in projects/plugins/jetpack/modules/likes/jetpack-likes-settings.php */ |
| 46 | return (bool) apply_filters( 'jetpack_comment_likes_enabled', get_option( 'jetpack_comment_likes_enabled', false ) ); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Turn Likes on or off for every post. |
| 51 | * |
| 52 | * Off is the presence of `disabled_likes`, not a falsy value: the Likes code tests it with `get_option()` alone. |
| 53 | * |
| 54 | * @param bool $enabled Whether Likes should be on. |
| 55 | */ |
| 56 | public static function set_likes_enabled( bool $enabled ): void { |
| 57 | if ( $enabled ) { |
| 58 | delete_option( 'disabled_likes' ); |
| 59 | } else { |
| 60 | update_option( 'disabled_likes', 1 ); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Turn the Reblog button on or off for every post. WordPress.com Simple only. |
| 66 | * |
| 67 | * @param bool $enabled Whether Reblogs should be on. |
| 68 | */ |
| 69 | public static function set_reblogs_enabled( bool $enabled ): void { |
| 70 | if ( $enabled ) { |
| 71 | delete_option( 'disabled_reblogs' ); |
| 72 | } else { |
| 73 | update_option( 'disabled_reblogs', 1 ); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Turn Comment Likes on or off. WordPress.com Simple only. |
| 79 | * |
| 80 | * @param bool $enabled Whether comments can be liked. |
| 81 | */ |
| 82 | public static function set_comment_likes_enabled( bool $enabled ): void { |
| 83 | update_option( 'jetpack_comment_likes_enabled', $enabled ? 1 : 0 ); |
| 84 | } |
| 85 | } |