Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/01/2015 04:18:13 AM (10 years ago)
Author:
tw2113
Message:

First pass of documentation cleanup for the XProfile Component.

See #6406.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/bp-xprofile-admin.php

    r10140 r10163  
    1414 * tables are set up.
    1515 *
    16  * @package BuddyPress XProfile
    17  * @uses bp_current_user_can() returns true if the current user is a site admin, false if not
    18  * @uses add_users_page() Adds a submenu tab to a top level tab in the admin area
    19  * @return
     16 * @uses bp_current_user_can() returns true if the current user is a site admin, false if not.
     17 * @uses add_users_page() Adds a submenu tab to a top level tab in the admin area.
     18 *
     19 * @return bool
    2020 */
    2121function xprofile_add_admin_menu() {
    2222
    23     // Bail if current user cannot moderate community
     23    // Bail if current user cannot moderate community.
    2424    if ( ! bp_current_user_can( 'bp_moderate' ) ) {
    2525        return false;
     
    3333 * Handles all actions for the admin area for creating, editing and deleting
    3434 * profile groups and fields.
     35 *
     36 * @param string $message Message to display.
     37 * @param string $type    Type of action to be displayed.
    3538 */
    3639function xprofile_admin( $message = '', $type = 'error' ) {
     
    6770 * @since 2.3.0
    6871 *
    69  * @param string $message Feedback message
    70  * @param string $type    Feedback type
     72 * @param string $message Feedback message.
     73 * @param string $type    Feedback type.
    7174 *
    7275 * @todo Improve error message output
     
    7477function xprofile_admin_screen( $message = '', $type = 'error' ) {
    7578
    76     // Validate type
     79    // Validate type.
    7780    $type = preg_replace( '|[^a-z]|i', '', $type );
    7881
    79     // Get all of the profile groups & fields
     82    // Get all of the profile groups & fields.
    8083    $groups = bp_xprofile_get_groups( array(
    8184        'fetch_fields' => true
     
    176179                                foreach ( $group->fields as $field ) {
    177180
    178                                     // Load the field
     181                                    // Load the field.
    179182                                    $field = new BP_XProfile_Field( $field->id );
    180183
     
    186189                                    /**
    187190                                     * This function handles the WYSIWYG profile field
    188                                      * display for the xprofile admin setup screen
     191                                     * display for the xprofile admin setup screen.
    189192                                     */
    190193                                    xprofile_admin_field( $field, $group, $class );
     
    196199                                <p class="nodrag nofields"><?php _e( 'There are no fields in this group.', 'buddypress' ); ?></p>
    197200
    198                             <?php endif; // end $group->fields ?>
     201                            <?php endif; // End $group->fields. ?>
    199202
    200203                        </fieldset>
     
    224227/**
    225228 * Handles the adding or editing of groups.
     229 *
     230 * @param int|null $group_id Group ID to manage.
    226231 */
    227232function xprofile_admin_manage_group( $group_id = null ) {
    228233    global $message, $type;
    229234
    230     // Get the field group
     235    // Get the field group.
    231236    $group = new BP_XProfile_Group( $group_id );
    232237
    233     // Updating
     238    // Updating.
    234239    if ( isset( $_POST['save_group'] ) ) {
    235240
    236         // Validate $_POSTed data
     241        // Validate $_POSTed data.
    237242        if ( BP_XProfile_Group::admin_validate() ) {
    238243
    239             // Set the group name
     244            // Set the group name.
    240245            $group->name = $_POST['group_name'];
    241246
    242             // Set the group description
     247            // Set the group description.
    243248            if ( ! empty( $_POST['group_description'] ) ) {
    244249                $group->description = $_POST['group_description'];
     
    247252            }
    248253
    249             // Attempt to save the field group
     254            // Attempt to save the field group.
    250255            if ( false === $group->save() ) {
    251256                $message = __( 'There was an error saving the group. Please try again.', 'buddypress' );
    252257                $type    = 'error';
    253258
    254             // Save successful
     259            // Save successful.
    255260            } else {
    256261                $message = __( 'The group was saved successfully.', 'buddypress' );
     
    285290/**
    286291 * Handles the deletion of profile data groups.
     292 *
     293 * @param int $group_id ID of the group to delete.
    287294 */
    288295function xprofile_admin_delete_group( $group_id ) {
     
    314321/**
    315322 * Handles the adding or editing of profile field data for a user.
     323 *
     324 * @param int      $group_id ID of the group.
     325 * @param int|null $field_id ID of the field being managed.
    316326 */
    317327function xprofile_admin_manage_field( $group_id, $field_id = null ) {
     
    371381                }
    372382
    373                 // Validate default visibility
     383                // Validate default visibility.
    374384                if ( ! empty( $_POST['default-visibility'] ) && in_array( $_POST['default-visibility'], wp_list_pluck( bp_xprofile_get_visibility_levels(), 'id' ) ) ) {
    375385                    bp_xprofile_update_field_meta( $field_id, 'default_visibility', $_POST['default-visibility'] );
    376386                }
    377387
    378                 // Validate custom visibility
     388                // Validate custom visibility.
    379389                if ( ! empty( $_POST['allow-custom-visibility'] ) && in_array( $_POST['allow-custom-visibility'], array( 'allowed', 'disabled' ) ) ) {
    380390                    bp_xprofile_update_field_meta( $field_id, 'allow_custom_visibility', $_POST['allow-custom-visibility'] );
    381391                }
    382392
    383                 // Validate signup
     393                // Validate signup.
    384394                if ( ! empty( $_POST['signup-position'] ) ) {
    385395                    bp_xprofile_update_field_meta( $field_id, 'signup_position', (int) $_POST['signup-position'] );
     
    413423
    414424/**
    415  * Handles the deletion of a profile field (or field option)
     425 * Handles the deletion of a profile field (or field option).
    416426 *
    417427 * @since 1.0.0
    418  * @global string $message The feedback message to show
    419  * @global $type The type of feedback message to show
    420  * @param int $field_id The field to delete
    421  * @param string $field_type The type of field being deleted
    422  * @param bool $delete_data Should the field data be deleted too?
     428 * @global string $message The feedback message to show.
     429 * @global $type The type of feedback message to show.
     430 *
     431 * @param int    $field_id    The field to delete.
     432 * @param string $field_type  The type of field being deleted.
     433 * @param bool   $delete_data Should the field data be deleted too.
    423434 */
    424435function xprofile_admin_delete_field( $field_id, $field_type = 'field', $delete_data = false ) {
    425436    global $message, $type;
    426437
    427     // Switch type to 'option' if type is not 'field'
    428     // @todo trust this param
     438    // Switch type to 'option' if type is not 'field'.
     439    // @todo trust this param.
    429440    $field_type  = ( 'field' == $field_type ) ? __( 'field', 'buddypress' ) : __( 'option', 'buddypress' );
    430441    $field       = new BP_XProfile_Field( $field_id );
     
    452463
    453464/**
    454  * Handles the ajax reordering of fields within a group
     465 * Handles the ajax reordering of fields within a group.
    455466 */
    456467function xprofile_ajax_reorder_fields() {
    457468
    458     // Check the nonce
     469    // Check the nonce.
    459470    check_admin_referer( 'bp_reorder_fields', '_wpnonce_reorder_fields' );
    460471
     
    474485
    475486/**
    476  * Handles the reordering of field groups
     487 * Handles the reordering of field groups.
    477488 */
    478489function xprofile_ajax_reorder_field_groups() {
    479490
    480     // Check the nonce
     491    // Check the nonce.
    481492    check_admin_referer( 'bp_reorder_groups', '_wpnonce_reorder_groups' );
    482493
     
    494505
    495506/**
    496  * Handles the WYSIWYG display of each profile field on the edit screen
     507 * Handles the WYSIWYG display of each profile field on the edit screen.
     508 *
     509 * @param object $admin_field Admin field.
     510 * @param object $admin_group Admin group object.
     511 * @param string $class       Classes to append to output.
    497512 */
    498513function xprofile_admin_field( $admin_field, $admin_group, $class = '' ) {
     
    584599 * Print <option> elements containing the xprofile field types.
    585600 *
    586  * @param string $select_field_type The name of the field type that should be selected. Will defaults to "textbox" if NULL is passed.
    587601 * @since 2.0.0
     602 *
     603 * @param string $select_field_type The name of the field type that should be selected.
     604 *                                  Will defaults to "textbox" if NULL is passed.
    588605 */
    589606function bp_xprofile_admin_form_field_types( $select_field_type ) {
     
    594611    }
    595612
    596     // Sort each field type into its category
     613    // Sort each field type into its category.
    597614    foreach ( bp_xprofile_get_field_types() as $field_name => $field_class ) {
    598615        $field_type_obj = new $field_class;
    599616        $the_category   = $field_type_obj->category;
    600617
    601         // Fallback to a catch-all if category not set
     618        // Fallback to a catch-all if category not set.
    602619        if ( ! $the_category ) {
    603620            $the_category = _x( 'Other', 'xprofile field type category', 'buddypress' );
     
    611628    }
    612629
    613     // Sort the categories alphabetically. ksort()'s SORT_NATURAL is only in PHP >= 5.4 :((
     630    // Sort the categories alphabetically. ksort()'s SORT_NATURAL is only in PHP >= 5.4 :((.
    614631    uksort( $categories, 'strnatcmp' );
    615632
    616     // Loop through each category and output form <options>
     633    // Loop through each category and output form <options>.
    617634    foreach ( $categories as $category => $fields ) {
    618         printf( '<optgroup label="%1$s">', esc_attr( $category ) );  // Already i18n'd in each profile type class
    619 
    620         // Sort these fields types alphabetically
     635        printf( '<optgroup label="%1$s">', esc_attr( $category ) );  // Already i18n'd in each profile type class.
     636
     637        // Sort these fields types alphabetically.
    621638        uasort( $fields, create_function( '$a, $b', 'return strnatcmp( $a[1]->name, $b[1]->name );' ) );
    622639
     
    633650
    634651if ( ! class_exists( 'BP_XProfile_User_Admin' ) ) :
     652
    635653/**
    636654 * Load xProfile Profile admin area.
    637  *
    638  * @package BuddyPress
    639  * @subpackage xProfileAdministration
    640655 *
    641656 * @since 2.0.0
     
    649664     * @since 2.0.0
    650665     *
    651      * @uses buddypress() to get BuddyPress main instance
     666     * @uses buddypress() to get BuddyPress main instance.
    652667     */
    653668    public static function register_xprofile_user_admin() {
    654669
    655         // Bail if not in admin
     670        // Bail if not in admin.
    656671        if ( ! is_admin() ) {
    657672            return;
     
    684699     */
    685700    private function setup_actions() {
    686         // Enqueue scripts
     701        // Enqueue scripts.
    687702        add_action( 'bp_members_admin_enqueue_scripts',  array( $this, 'enqueue_scripts'    ), 10, 1 );
    688703
    689         // Register the metabox in Member's community admin profile
     704        // Register the metabox in Member's community admin profile.
    690705        add_action( 'bp_members_admin_xprofile_metabox', array( $this, 'register_metaboxes' ), 10, 3 );
    691706
    692         // Saves the profile actions for user ( avatar, profile fields )
     707        // Saves the profile actions for user ( avatar, profile fields ).
    693708        add_action( 'bp_members_admin_update_user',      array( $this, 'user_admin_load'    ), 10, 4 );
    694709    }
     
    699714     * @access public
    700715     * @since 2.3.0
     716     *
     717     * @param int $screen_id Screen ID being displayed.
    701718     */
    702719    public function enqueue_scripts( $screen_id ) {
     
    710727
    711728        /**
    712          * Get Thickbox
     729         * Get Thickbox.
    713730         *
    714731         * We cannot simply use add_thickbox() here as WordPress is not playing
     
    720737        wp_enqueue_script( 'media-upload' );
    721738
    722         // Get Avatar Uploader
     739        // Get Avatar Uploader.
    723740        bp_attachments_enqueue_scripts( 'BP_Attachment_Avatar' );
    724741    }
     
    730747     * @since 2.0.0
    731748     *
    732      * @param int $user_id ID of the user being edited.
    733      * @param string $screen_id Screen ID to load the metabox in.
     749     * @param int    $user_id      ID of the user being edited.
     750     * @param string $screen_id     Screen ID to load the metabox in.
    734751     * @param object $stats_metabox Context and priority for the stats metabox.
    735752     */
    736753    public function register_metaboxes( $user_id = 0, $screen_id = '', $stats_metabox = null ) {
    737754
    738         // Set the screen ID if none was passed
     755        // Set the screen ID if none was passed.
    739756        if ( empty( $screen_id ) ) {
    740757            $screen_id = buddypress()->members->admin->user_page;
    741758        }
    742759
    743         // Setup a new metabox class if none was passed
     760        // Setup a new metabox class if none was passed.
    744761        if ( empty( $stats_metabox ) ) {
    745762            $stats_metabox = new StdClass();
    746763        }
    747764
    748         // Moving the Stats Metabox
     765        // Moving the Stats Metabox.
    749766        $stats_metabox->context  = 'side';
    750767        $stats_metabox->priority = 'low';
    751768
    752         // Each Group of fields will have his own metabox
     769        // Each Group of fields will have his own metabox.
    753770        $profile_args = array(
    754771            'fetch_fields' => false,
     
    758775        if ( ! bp_is_user_spammer( $user_id ) && bp_has_profile( $profile_args ) ) {
    759776
    760             // Loop through field groups and add a metabox for each one
     777            // Loop through field groups and add a metabox for each one.
    761778            while ( bp_profile_groups() ) : bp_the_profile_group();
    762779                add_meta_box(
     
    771788            endwhile;
    772789
    773         // If member is already a spammer, show a generic metabox
     790        // If member is already a spammer, show a generic metabox.
    774791        } else {
    775792            add_meta_box(
     
    784801
    785802        if ( buddypress()->avatar->show_avatars ) {
    786             // Avatar Metabox
     803            // Avatar Metabox.
    787804            add_meta_box(
    788805                'bp_xprofile_user_admin_avatar',
     
    804821     * @access public
    805822     * @since 2.0.0
     823     *
     824     * @param string $doaction    Action being run.
     825     * @param int    $user_id     ID for the user whose profile is being saved.
     826     * @param array  $request     Request being made.
     827     * @param string $redirect_to Where to redirect user to.
    806828     */
    807829    public function user_admin_load( $doaction = '', $user_id = 0, $request = array(), $redirect_to = '' ) {
    808830
    809         // Eventually delete avatar
     831        // Eventually delete avatar.
    810832        if ( 'delete_avatar' === $doaction ) {
    811833
     
    822844            bp_core_redirect( $redirect_to );
    823845
    824         // Update profile fields
     846        // Update profile fields.
    825847        } elseif ( isset( $_POST['field_ids'] ) ) {
    826848
    827             // Check the nonce
     849            // Check the nonce.
    828850            check_admin_referer( 'edit-bp-profile_' . $user_id );
    829851
    830             // Check we have field ID's
     852            // Check we have field ID's.
    831853            if ( empty( $_POST['field_ids'] ) ) {
    832854                $redirect_to = add_query_arg( 'error', '1', $redirect_to );
     
    846868            $merge_ids = join( ',', $_POST['field_ids'] );
    847869
    848             // Explode the posted field IDs into an array so we know which fields have been submitted
     870            // Explode the posted field IDs into an array so we know which fields have been submitted.
    849871            $posted_field_ids = wp_parse_id_list( $merge_ids );
    850872            $is_required      = array();
    851873
    852             // Loop through the posted fields formatting any datebox values then validate the field
     874            // Loop through the posted fields formatting any datebox values then validate the field.
    853875            foreach ( (array) $posted_field_ids as $field_id ) {
    854876                if ( ! isset( $_POST['field_' . $field_id ] ) ) {
    855877                    if ( ! empty( $_POST['field_' . $field_id . '_day'] ) && ! empty( $_POST['field_' . $field_id . '_month'] ) && ! empty( $_POST['field_' . $field_id . '_year'] ) ) {
    856878
    857                         // Concatenate the values
     879                        // Concatenate the values.
    858880                        $date_value =   $_POST['field_' . $field_id . '_day'] . ' ' . $_POST['field_' . $field_id . '_month'] . ' ' . $_POST['field_' . $field_id . '_year'];
    859881
    860                         // Turn the concatenated value into a timestamp
     882                        // Turn the concatenated value into a timestamp.
    861883                        $_POST['field_' . $field_id] = date( 'Y-m-d H:i:s', strtotime( $date_value ) );
    862884                    }
     
    870892            }
    871893
    872             // Set the errors var
     894            // Set the errors var.
    873895            $errors = false;
    874896
     
    896918                }
    897919
    898                 // Save the visibility level
     920                // Save the visibility level.
    899921                $visibility_level = ! empty( $_POST['field_' . $field_id . '_visibility'] ) ? $_POST['field_' . $field_id . '_visibility'] : 'public';
    900922                xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level );
     
    912934            do_action( 'xprofile_updated_profile', $user_id, $posted_field_ids, $errors );
    913935
    914             // Set the feedback messages
     936            // Set the feedback messages.
    915937            if ( ! empty( $errors ) ) {
    916938                $redirect_to = add_query_arg( 'error',   '3', $redirect_to );
     
    930952     *
    931953     * @param WP_User $user The WP_User object for the user being edited.
     954     * @param array   $args Aray of arguments for metaboxes.
    932955     */
    933956    public function user_admin_profile_metaboxes( $user = null, $args = array() ) {
    934957
    935         // Bail if no user ID
     958        // Bail if no user ID.
    936959        if ( empty( $user->ID ) ) {
    937960            return;
     
    943966        ), 'bp_xprofile_user_admin_profile_loop_args' );
    944967
    945         // We really need these args
     968        // We really need these args.
    946969        if ( empty( $r['profile_group_id'] ) || empty( $r['user_id'] ) ) {
    947970            return;
    948971        }
    949972
    950         // Bail if no profile fields are available
     973        // Bail if no profile fields are available.
    951974        if ( ! bp_has_profile( $r ) ) {
    952975            return;
    953976        }
    954977
    955         // Loop through profile groups & fields
     978        // Loop through profile groups & fields.
    956979        while ( bp_profile_groups() ) : bp_the_profile_group(); ?>
    957980
     
    10241047                </div>
    10251048
    1026             <?php endwhile; // bp_profile_fields() ?>
    1027 
    1028         <?php endwhile; // bp_profile_groups
     1049            <?php endwhile; // End bp_profile_fields(). ?>
     1050
     1051        <?php endwhile; // End bp_profile_groups.
    10291052    }
    10301053
     
    10841107            <?php endif;
    10851108
    1086             // Load the Avatar UI templates if user avatar uploads are enabled and current WordPress version is supported
     1109            // Load the Avatar UI templates if user avatar uploads are enabled and current WordPress version is supported.
    10871110            if ( ! bp_core_get_root_option( 'bp-disable-avatar-uploads' ) && bp_attachments_is_wp_version_supported() ) : ?>
    10881111                <a href="#TB_inline?width=800px&height=400px&inlineId=bp-xprofile-avatar-editor" title="<?php esc_attr_e( 'Edit Profile Photo', 'buddypress' );?>" class="thickbox bp-xprofile-avatar-user-edit"><?php esc_html_e( 'Edit Profile Photo', 'buddypress' ); ?></a>
     
    10971120
    10981121}
    1099 endif; // class_exists check
    1100 
    1101 // Load the xprofile user admin
     1122endif; // End class_exists check.
     1123
     1124// Load the xprofile user admin.
    11021125add_action( 'bp_init', array( 'BP_XProfile_User_Admin', 'register_xprofile_user_admin' ), 11 );
Note: See TracChangeset for help on using the changeset viewer.