Skip to:
Content

Changeset 7960


Ignore:
Timestamp:
02/21/2014 11:08:04 PM (4 years ago)
Author:
johnjamesjacoby
Message:

First pass at Profile Settings for improved profile field visibility UX:

  • Adds /members/single/settings/profile.php template to bp-legacy and bp-default.
  • Introduces bp-xprofile.settings.php for Settings specific functionality going forward.
  • Introduces actions & screens for handling output and saving of profile visibility data.
  • Introduces _is_ function for identifying the new component/action URL.
  • See #5352. (still more @todo...)
Location:
trunk
Files:
3 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-template.php

    r7926 r7960  
    18721872}
    18731873
     1874/**
     1875 * Is this a user's profile settings?
     1876 *
     1877 * Eg http://example.com/members/joe/settings/profile/.
     1878 *
     1879 * @since BuddyPress (2.0.0)
     1880 *
     1881 * @return bool True if the current page is a user's Profile Settings page.
     1882 */
     1883function bp_is_user_settings_profile() {
     1884    if ( bp_is_user_settings() && bp_is_current_action( 'profile' ) )
     1885        return true;
     1886
     1887    return false;
     1888}
     1889
    18741890/** Groups ********************************************************************/
    18751891
  • trunk/bp-templates/bp-legacy/buddypress/members/single/settings.php

    r6627 r7960  
    3535        bp_get_template_part( 'members/single/settings/general'        );
    3636        break;
     37    case 'profile'        :
     38        bp_get_template_part( 'members/single/settings/profile'        );
     39        break;
    3740    default:
    3841        bp_get_template_part( 'members/single/plugins'                 );
  • trunk/bp-templates/bp-legacy/css/buddypress.css

    r7952 r7960  
    895895#buddypress table.notifications,
    896896#buddypress table.notifications-settings,
     897#buddypress table.profile-settings,
    897898#buddypress table.profile-fields,
    898899#buddypress table.wp-profile-fields,
     
    903904#buddypress table.notifications thead tr,
    904905#buddypress table.notifications-settings thead tr,
     906#buddypress table.profile-settings thead tr,
    905907#buddypress table.profile-fields thead tr,
    906908#buddypress table.wp-profile-fields thead tr,
     
    928930#buddypress table.notifications tr td,
    929931#buddypress table.notifications-settings tr td,
     932#buddypress table.profile-settings tr td,
    930933#buddypress table.profile-fields tr td,
    931934#buddypress table.wp-profile-fields tr td,
     
    964967#buddypress table.notifications tr.alt td,
    965968#buddypress table.notifications-settings tr.alt td,
     969#buddypress table.profile-settings tr.alt td,
    966970#buddypress table.profile-fields tr.alt td,
    967971#buddypress table.wp-profile-fields tr.alt td,
     
    983987    display: none;
    984988}
    985 #buddypress table.notification-settings th.title {
     989#buddypress table.notification-settings th.title,
     990#buddypress table.profile-settings th.title {
    986991    width: 80%;
    987992}
  • trunk/bp-themes/bp-default/_inc/css/default.css

    r7133 r7960  
    19541954    background: #f5f5f5;
    19551955}
    1956 table.notification-settings {
     1956table.notification-settings,
     1957table.profile-settings {
    19571958    margin-bottom: 20px;
    19581959    text-align: left;
     
    19651966    display: none;
    19661967}
    1967 table.notification-settings th.title {
     1968table.notification-settings th.title,
     1969table.profile-settings th.title {
    19681970    width: 80%;
    19691971}
  • trunk/bp-themes/bp-default/members/single/settings.php

    r6627 r7960  
    3131    locate_template( array( 'members/single/settings/general.php' ), true );
    3232
     33elseif ( bp_is_current_action( 'profile' ) ) :
     34    locate_template( array( 'members/single/settings/profile.php' ), true );
     35
    3336else :
    3437    locate_template( array( 'members/single/plugins.php' ), true );
    3538
    3639endif;
    37 
    38 ?>
  • trunk/bp-xprofile/bp-xprofile-actions.php

    r6291 r7960  
    4444}
    4545add_action( 'bp_actions', 'xprofile_action_delete_avatar' );
     46
     47/**
     48 * Handles the saving of xprofile field visibilities
     49 *
     50 * @since BuddyPress (1.9)
     51 */
     52function bp_xprofile_action_settings() {
     53
     54    // Bail if not a POST action
     55    if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
     56        return;
     57    }
     58
     59    // Bail if no submit action
     60    if ( ! isset( $_POST['xprofile-settings-submit'] ) ) {
     61        return;
     62    }
     63
     64    // Bail if not in settings
     65    if ( ! bp_is_user_settings_profile() ) {
     66        return;
     67    }
     68
     69    // 404 if there are any additional action variables attached
     70    if ( bp_action_variables() ) {
     71        bp_do_404();
     72        return;
     73    }
     74
     75    // Nonce check
     76    check_admin_referer( 'bp_xprofile_settings' );
     77
     78    do_action( 'bp_xprofile_settings_before_save' );
     79
     80    /** Save ******************************************************************/
     81
     82    // Only save if there are field ID's being posted
     83    if ( ! empty( $_POST['field_ids'] ) ) {
     84
     85        // Get the POST'ed field ID's
     86        $posted_field_ids = explode( ',', $_POST['field_ids'] );
     87
     88        // Save the visibility settings
     89        foreach ( $posted_field_ids as $field_id ) {
     90
     91            $visibility_level = 'public';
     92
     93            if ( !empty( $_POST['field_' . $field_id . '_visibility'] ) ) {
     94                $visibility_level = $_POST['field_' . $field_id . '_visibility'];
     95            }
     96
     97            xprofile_set_field_visibility_level( $field_id, bp_displayed_user_id(), $visibility_level );
     98        }
     99    }
     100
     101    /** Other *****************************************************************/
     102
     103    do_action( 'bp_xprofile_settings_after_save' );
     104
     105    // Redirect to the root domain
     106    bp_core_redirect( bp_displayed_user_domain() . bp_get_settings_slug() . '/privacy' );
     107}
     108add_action( 'bp_actions', 'bp_xprofile_action_settings' );
  • trunk/bp-xprofile/bp-xprofile-loader.php

    r7862 r7960  
    6060            'classes',
    6161            'filters',
     62            'settings',
    6263            'template',
    6364            'buddybar',
     
    220221        }
    221222
     223        // Privacy Settings
     224        if ( bp_is_active( 'settings' ) ) {
     225
     226            // Get the settings slug
     227            $settings_slug = bp_get_settings_slug();
     228
     229            // Add the sub-navigation
     230            $sub_nav[] = array(
     231                'name'            => __( 'Profile', 'buddypress' ),
     232                'slug'            => 'profile',
     233                'parent_url'      => trailingslashit( $user_domain . $settings_slug ),
     234                'parent_slug'     => $settings_slug,
     235                'screen_function' => 'bp_xprofile_screen_settings',
     236                'position'        => 30,
     237                'user_has_access' => bp_core_can_edit_settings()
     238            );
     239        }
     240
    222241        parent::setup_nav( $main_nav, $sub_nav );
    223242    }
     
    272291            }
    273292
     293            // Privacy Settings
     294            if ( bp_is_active( 'settings' ) ) {
     295
     296                // Setup the logged in user variables
     297                $settings_link = trailingslashit( bp_loggedin_user_domain() . bp_get_settings_slug() );
     298
     299                // Add main Settings menu
     300                $wp_admin_nav[] = array(
     301                    'parent' => 'my-account-' . $bp->settings->id,
     302                    'id'     => 'my-account-' . $bp->settings->id . '-profile',
     303                    'title'  => __( 'Profile', 'buddypress' ),
     304                    'href'   => trailingslashit( $settings_link . 'profile' )
     305                );
     306            }
    274307        }
    275308
  • trunk/bp-xprofile/bp-xprofile-screens.php

    r7889 r7960  
    209209    bp_core_load_template( apply_filters( 'xprofile_template_change_avatar', 'members/single/home' ) );
    210210}
     211
     212/**
     213 * Show the xprofile settings template
     214 *
     215 * @since BuddyPress (2.0.0)
     216 */
     217function bp_xprofile_screen_settings() {
     218
     219    // Redirect if no privacy settings page is accessible
     220    if ( bp_action_variables() || ! bp_is_active( 'xprofile' ) ) {
     221        bp_do_404();
     222        return;
     223    }
     224
     225    // Load the template
     226    bp_core_load_template( apply_filters( 'bp_settings_screen_xprofile', '/members/single/plugin' ) );
     227}
  • trunk/bp-xprofile/bp-xprofile-template.php

    r7914 r7960  
    937937}
    938938
     939/** Visibility ****************************************************************/
     940
    939941/**
    940942 * Echo the field visibility radio buttons
     
    963965        return apply_filters( 'bp_profile_get_visibility_radio_buttons', $html );
    964966    }
     967
     968/**
     969 * Output the XProfile field visibility select list for settings
     970 *
     971 * @since BuddyPress (2.0.0)
     972 */
     973function bp_xprofile_settings_visibility_select( $args = '' ) {
     974    echo bp_xprofile_get_settings_visibility_select( $args );
     975}
     976    /**
     977     * Return the XProfile field visibility select list for settings
     978     *
     979     * @since BuddyPress (2.0.0)
     980     */
     981    function bp_xprofile_get_settings_visibility_select( $args = '' ) {
     982
     983        // Parse optional arguments
     984        $r = bp_parse_args( $args, array(
     985            'before' => '',
     986            'after'  => '',
     987            'class'  => 'bp-xprofile-visibility'
     988        ), 'xprofile_settings_visibility_select' );
     989
     990        // Start the output buffer
     991        ob_start();
     992
     993        // Anything before
     994        echo $r['before']; ?>
     995
     996        <?php if ( bp_current_user_can( 'bp_xprofile_change_field_visibility' ) ) : ?>
     997
     998            <select class="<?php echo esc_attr( $r['class'] ); ?>" name="field_<?php bp_the_profile_field_id(); ?>_visibility">
     999
     1000                <?php foreach ( bp_xprofile_get_visibility_levels() as $level ) : ?>
     1001
     1002                    <option value="<?php echo esc_attr( $level['id'] ); ?>" <?php selected( $level['id'], bp_get_the_profile_field_visibility_level() ); ?>><?php echo esc_html( $level['label'] ); ?></option>
     1003
     1004                <?php endforeach; ?>
     1005
     1006            </select>
     1007
     1008        <?php else : ?>
     1009
     1010            <span class="field-visibility-settings-notoggle" title="<?php _e( "This field's visibility cannot be changed.", 'buddypress' ); ?>"><?php bp_the_profile_field_visibility_level_label(); ?></span>
     1011
     1012        <?php endif;
     1013
     1014        // Anything after
     1015        echo $r['after'];
     1016
     1017        // Output the dropdown list
     1018        return apply_filters( 'bp_xprofile_settings_visibility_select', ob_get_clean() );
     1019    }
Note: See TracChangeset for help on using the changeset viewer.