Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 23 |
|
0.00% |
0 / 4 |
CRAP | n/a |
0 / 0 |
|
| wpcom_repost_notifications_settings_init | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| wpcom_repost_notifications_settings_section | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
2 | |||
| wpcom_repost_notifications_settings_field | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| wpcom_repost_notifications_sanitize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Add the "Someone reposts one of my posts" email setting to Settings > Discussion. |
| 4 | * |
| 5 | * @package automattic/jetpack-mu-wpcom |
| 6 | */ |
| 7 | |
| 8 | /** |
| 9 | * Register the repost email setting and its field. |
| 10 | */ |
| 11 | function wpcom_repost_notifications_settings_init() { |
| 12 | // Simple's social-notifications.php registers it at priority 10, until it is removed there. |
| 13 | if ( isset( get_registered_settings()['social_notifications_reblog'] ) ) { |
| 14 | return; |
| 15 | } |
| 16 | |
| 17 | add_settings_section( 'repost-notifications', __( 'Repost Notifications', 'jetpack-mu-wpcom' ), 'wpcom_repost_notifications_settings_section', 'discussion' ); |
| 18 | add_settings_field( 'repost-notifications', __( 'Email me whenever', 'jetpack-mu-wpcom' ), 'wpcom_repost_notifications_settings_field', 'discussion', 'repost-notifications' ); |
| 19 | register_setting( 'discussion', 'social_notifications_reblog', array( 'sanitize_callback' => 'wpcom_repost_notifications_sanitize' ) ); |
| 20 | } |
| 21 | add_action( 'admin_init', 'wpcom_repost_notifications_settings_init', 20 ); |
| 22 | |
| 23 | /** |
| 24 | * Move the checkbox into core's "Email me whenever" row, which has no hook. |
| 25 | */ |
| 26 | function wpcom_repost_notifications_settings_section() { |
| 27 | ?> |
| 28 | <script> |
| 29 | jQuery( function ( $ ) { |
| 30 | var label = $( '#social_notifications_reblog' ).parent( 'label' ), |
| 31 | table = label.closest( 'table' ), |
| 32 | header = table.prevAll( 'h2' ).first(), |
| 33 | newParent = $( '#moderation_notify' ).parent( 'label' ).parent(); |
| 34 | |
| 35 | if ( ! table.length || ! header.length || ! newParent.length ) { |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | newParent.append( '<br />' ).append( label ); |
| 40 | header.remove(); |
| 41 | table.remove(); |
| 42 | } ); |
| 43 | </script> |
| 44 | <?php |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Render the repost email checkbox. An unset option counts as on. |
| 49 | */ |
| 50 | function wpcom_repost_notifications_settings_field() { |
| 51 | ?> |
| 52 | <label><input type="checkbox" id="social_notifications_reblog" name="social_notifications_reblog" value="1" <?php checked( 'on', get_option( 'social_notifications_reblog', 'on' ) ); ?> /> <?php esc_html_e( 'Someone reposts one of my posts', 'jetpack-mu-wpcom' ); ?></label> |
| 53 | <?php |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Store the checkbox as the 'on' or 'off' string WordPress.com reads. |
| 58 | * |
| 59 | * @param mixed $input Submitted value. |
| 60 | * @return string |
| 61 | */ |
| 62 | function wpcom_repost_notifications_sanitize( $input ) { |
| 63 | return ( ! $input || 'off' === $input ) ? 'off' : 'on'; |
| 64 | } |