Skip to:
Content

BuddyPress.org

Ticket #6712: 6712.03.screen-notifications-template.patch

File 6712.03.screen-notifications-template.patch, 5.8 KB (added by hnla, 7 years ago)

Update screen template markup

  • src/bp-templates/bp-legacy/buddypress/members/single/settings/screen-notifications.php

     
     1<?php
     2/**
     3 * BuddyPress - Members Settings Screen Notifications
     4 *
     5 * @since 2.6.0
     6 *
     7 * @package BuddyPress
     8 * @subpackage bp-legacy
     9 */
     10
     11/** This action is documented in bp-templates/bp-legacy/buddypress/members/single/settings/profile.php */
     12do_action( 'bp_before_member_settings_template' ); ?>
     13
     14<form action="<?php echo bp_displayed_user_domain() . bp_get_settings_slug() . '/screen-notifications'; ?>" method="post" class="standard-form" id="settings-form">
     15
     16<p><?php _e('Enable or disable on screen display of notifications.', 'buddypress'); ?></p>
     17
     18<?php
     19        $components = bp_notifications_get_registered_components();
     20
     21        // Fudge xprofile component.
     22        $profile = array_search( 'xprofile', $components );
     23        if ( false !== $profile ) {
     24                $components[] = 'profile';
     25                unset( $components[ $profile ] );
     26        }
     27
     28        sort( $components, SORT_STRING );
     29
     30        // Initialize registered notification actions.
     31        bp_notifications_init_registered_actions();
     32
     33        foreach ( $components as $component ) :
     34                $enabled = bp_get_user_meta( bp_loggedin_user_id(), "notifications_{$component}_enabled", true );
     35                if ( '' === $enabled ) {
     36                        $enabled = 1;
     37                }
     38
     39                $action_count = ! empty( buddypress()->notifications->actions[$component] ) ? count( buddypress()->notifications->actions[$component] ) : 0;
     40?>
     41
     42<fieldset class="<?php echo $component; ?>">
     43
     44<?php bp_notifications_component_settings_title( $component, 'legend' ); ?>
     45
     46        <label for="<?php esc_attr_e( "{$component}-notification-enable" ); ?>">
     47                <input type="checkbox" name="<?php esc_attr_e( "{$component}[enabled]" ); ?>" data-component="<?php esc_attr_e( $component ); ?>" id="<?php esc_attr_e( "{$component}-notification-enable" ); ?>" value="1" <?php checked( $enabled, 1, true ) ?>/>
     48
     49                <?php esc_html_e( 'Enable screen notifications for this component', 'buddypress' ); ?>
     50        </label>
     51
     52        <?php if ( ! empty( buddypress()->notifications->actions[$component] ) ) : ?>
     53
     54                <table class="notification-settings" id="<?php esc_attr_e( "{$component}-screen-notification-settings" ); ?>">
     55                        <thead>
     56                                <tr>
     57                                        <th class="icon">&nbsp;</th>
     58                                        <th>&nbsp;</th>
     59                                        <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th>
     60                                        <th class="no"><?php _e( 'No', 'buddypress' )?></th>
     61                                </tr>
     62                        </thead>
     63
     64                        <tbody>
     65                                <?php
     66                                        foreach ( buddypress()->notifications->actions[$component] as $action => $val ) :
     67                                                $action = sanitize_key( $action );
     68
     69                                                $enabled = bp_get_user_meta( bp_loggedin_user_id(), "notifications_{$component}_{$action}_enabled", true );
     70                                                if ( '' === $enabled ) {
     71                                                        $enabled = 1;
     72                                                }
     73                                ?>
     74
     75                                        <tr id="<?php esc_html_e( "{$component}-{$action}" ); ?>" class="<?php esc_attr_e( "{$component}-screen-notification-singular" ); ?>">
     76                                                <td>&nbsp;</td>
     77                                                <td><?php esc_html_e( $val['settings_label' ] ); ?></td>
     78                                                <td class="yes"><input type="radio" name="<?php esc_attr_e( "{$component}[{$action}]" ); ?>" id="<?php esc_attr_e( "{$component}-notification-{$action}-yes" ); ?>" value="1" <?php checked( $enabled, 1, true ) ?>/><label for="<?php esc_attr_e( "{$component}-notification-{$action}-yes" ); ?>" class="bp-screen-reader-text"><?php _e( 'Yes', 'buddypress' ); ?></label></td>
     79                                                <td class="no"><input type="radio" name="<?php esc_attr_e( "{$component}[{$action}]" ); ?>" id="<?php esc_attr_e( "{$component}-notification-{$action}-no" ); ?>" value="0" <?php checked( $enabled, 0, true ) ?>/><label for="<?php esc_attr_e( "{$component}-notification-{$action}-no" ); ?>" class="bp-screen-reader-text"><?php _e( 'No', 'buddypress' ); ?></label></td>
     80                                        </tr>
     81
     82                                <?php
     83                                        endforeach;
     84                                ?>
     85                        </tbody>
     86                </table>
     87
     88
     89
     90        <?php endif; ?>
     91        </fieldset>
     92<?php endforeach; ?>
     93
     94        <script type="text/javascript">
     95        // This will be moved to bp-legacy's buddypress.js file.  Or maybe not?
     96        jQuery(function($){
     97                $('#settings-form input[type=checkbox]').each(function( index, elem ) {
     98                        toggleSettingsComponentFields( $(this) );
     99                });
     100
     101                $('#settings-form').on('click', 'input[type=checkbox]', function(e) {
     102                        toggleSettingsComponentFields( $(this) );
     103                });
     104
     105                function toggleSettingsComponentFields( elem ) {
     106                        var component = $( elem ).data( 'component' );
     107
     108                        if ( elem.is(':checked') ) {
     109                                $('#' + component + '-screen-notification-settings').fadeIn('fast');
     110                        } else {
     111                                $('#' + component + '-screen-notification-settings').fadeOut('fast');
     112                        }
     113                }
     114        });
     115        </script>
     116
     117        <?php
     118
     119        /**
     120         * Fires before the display of the submit button for user notification saving.
     121         *
     122         * @since 2.6.0
     123         */
     124        do_action( 'bp_members_screen_notification_settings_before_submit' ); ?>
     125
     126        <div class="submit">
     127                <input type="submit" name="screen-notifications-submit" value="<?php esc_attr_e( 'Save Changes', 'buddypress' ); ?>" id="submit" class="auto" />
     128        </div>
     129
     130        <?php
     131
     132        /**
     133         * Fires after the display of the submit button for user notification saving.
     134         *
     135         * @since 2.6.0
     136         */
     137        do_action( 'bp_members_screen_notification_settings_after_submit' ); ?>
     138
     139        <?php wp_nonce_field( 'bp_settings_screen_notifications' ); ?>
     140
     141</form>
     142
     143<?php
     144
     145/** This action is documented in bp-templates/bp-legacy/buddypress/members/single/settings/profile.php */
     146do_action( 'bp_after_member_settings_template' );