Skip to:
Content

BuddyPress.org

Changeset 10557


Ignore:
Timestamp:
02/08/2016 04:52:44 PM (9 years ago)
Author:
boonebgorges
Message:

Introduced 'Autolink' setting for XProfile fields.

Since BP 1.1, XProfile fields have been "autolinked". This means that a user's
entry for profile fields is linked to a search of the Members directory, using
that field's value as a search term. For short values - say, "Wichita, KS" for
the field "City" - the entire field value would be a link to a member search
on the phrase "Wichita, KS". For longer values, as in a multiline text field,
an algorithm detects "lists" (words between commas) and creates links
from them.

This feature was intended to aid in user discovery and serendipity. Sometimes
it works. But sometimes it makes very little sense.

This changeset introduces the ability for administrators to configure this
setting, on a per-field basis.

  • The new Autolink metabox on the XProfile Field Admin panel lets admin enable or disable the feature.
  • Smart defaults are pre-selected for new fields, or fields for which no value has yet to be saved. Namely: "multi fields" like checkboxes and radio buttons have Autolink enabled by default, while "single fields" have it disabled.

Props LenLay, sooskriszta, jeffsayre, boonebgorges.
Fixes #787.

Location:
trunk/src/bp-xprofile
Files:
5 edited

Legend:

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

    r10141 r10557  
    7777 */
    7878function show_options( forWhat ) {
     79    var do_autolink;
     80
    7981    for ( var i = 0; i < XProfileAdmin.supports_options_field_types.length; i++ ) {
    8082        document.getElementById( XProfileAdmin.supports_options_field_types[i] ).style.display = 'none';
     
    8385    if ( XProfileAdmin.supports_options_field_types.indexOf( forWhat ) >= 0 ) {
    8486        document.getElementById( forWhat ).style.display = '';
     87        do_autolink = 'on';
     88    } else {
     89        jQuery( '#do-autolink' ).val( '' );
     90        do_autolink = '';
     91    }
     92
     93    // Only overwrite the do_autolink setting if no setting is saved in the database.
     94    if ( '' === XProfileAdmin.do_autolink ) {
     95        jQuery( '#do-autolink' ).val( do_autolink );
    8596    }
    8697}
  • trunk/src/bp-xprofile/bp-xprofile-admin.php

    r10525 r10557  
    416416                }
    417417
     418                // Save autolink settings.
     419                if ( 1 != $field_id ) {
     420                    if ( isset( $_POST['do_autolink'] ) && 'on' === wp_unslash( $_POST['do_autolink'] ) ) {
     421                        bp_xprofile_update_field_meta( $field_id, 'do_autolink', 'on' );
     422                    } else {
     423                        bp_xprofile_update_field_meta( $field_id, 'do_autolink', 'off' );
     424                    }
     425                }
     426
    418427                /**
    419428                 * Fires at the end of the process to save a field for a user, if successful.
  • trunk/src/bp-xprofile/bp-xprofile-cssjs.php

    r10417 r10557  
    5353        $strings = array(
    5454            'supports_options_field_types' => array(),
     55            'do_autolink' => '',
    5556        );
    5657
     
    6263        }
    6364
     65        // Load 'autolink' setting into JS so that we can provide smart defaults when switching field type.
     66        if ( ! empty( $_GET['field_id'] ) ) {
     67            $field_id = intval( $_GET['field_id'] );
     68
     69            // Pull the raw data from the DB so we can tell whether the admin has saved a value yet.
     70            $strings['do_autolink'] = bp_xprofile_get_meta( $field_id, 'field', 'do_autolink' );
     71        }
     72
    6473        wp_localize_script( 'xprofile-admin-js', 'XProfileAdmin', $strings );
    6574    }
  • trunk/src/bp-xprofile/bp-xprofile-filters.php

    r10487 r10557  
    329329 * - Not run on values without commas with less than 5 words.
    330330 * - URL's are made clickable.
    331  * - To disable: remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 );
     331 *
     332 * To disable globally:
     333 *     remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 3 );
     334 *
     335 * To disable for a single field, use the 'Autolink' settings in Dashboard > Users > Profile Fields.
    332336 *
    333337 * @since 1.1.0
     
    338342 */
    339343function xprofile_filter_link_profile_data( $field_value, $field_type = 'textbox' ) {
     344    global $field;
     345
     346    if ( ! $field->get_do_autolink() ) {
     347        return $field_value;
     348    }
    340349
    341350    if ( 'datebox' === $field_type ) {
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-field.php

    r10434 r10557  
    129129     */
    130130    protected $allow_custom_visibility;
     131
     132    /**
     133     * Whether values from this field are autolinked to directory searches.
     134     *
     135     * @since 2.5.0
     136     *
     137     * @var bool
     138     */
     139    public $do_autolink;
    131140
    132141    /**
     
    793802    }
    794803
     804    /**
     805     * Get whether the field values should be auto-linked to a directory search.
     806     *
     807     * Lazy-loaded to reduce overhead.
     808     *
     809     * Defaults to true for multi and default fields, false for single fields.
     810     *
     811     * @since 2.5.0
     812     *
     813     * @return bool
     814     */
     815    public function get_do_autolink() {
     816        if ( ! isset( $this->do_autolink ) ) {
     817            $do_autolink = bp_xprofile_get_meta( $this->id, 'field', 'do_autolink' );
     818
     819            if ( '' === $do_autolink ) {
     820                $this->do_autolink = $this->is_default_field() || $this->type_obj->supports_options;
     821            } else {
     822                $this->do_autolink = 'on' === $do_autolink;
     823            }
     824        }
     825
     826        return $this->do_autolink;
     827    }
     828
    795829    /* Static Methods ********************************************************/
    796830
     
    11381172                            // Output the field visibility metaboxes.
    11391173                            $this->visibility_metabox();
     1174
     1175                            // Output the autolink metabox.
     1176                            $this->autolink_metabox();
     1177
    11401178
    11411179                            /**
     
    14121450
    14131451    /**
     1452     * Private method used to output autolink metabox.
     1453     *
     1454     * @since 2.5.0
     1455     *
     1456     * @return void If default field id 1.
     1457     */
     1458    private function autolink_metabox() {
     1459
     1460        // Default field cannot have custom visibility.
     1461        if ( true === $this->is_default_field() ) {
     1462            return;
     1463        }
     1464
     1465        ?>
     1466
     1467        <div class="postbox">
     1468            <h2><label for="do-autolink"><?php esc_html_e( 'Autolink', 'buddypress' ); ?></label></h2>
     1469            <div class="inside">
     1470                <p class="description"><?php esc_html_e( 'On user profiles, link this field to a search of the Members directory, using the field value as a search term:', 'buddypress' ); ?></p>
     1471
     1472                <p>
     1473                    <label>
     1474                        <select name="do_autolink" id="do-autolink">
     1475                            <option value="on" <?php selected( $this->get_do_autolink() ); ?>><?php esc_html_e( 'Enabled', 'buddypress' ); ?></option>
     1476                            <option value="" <?php selected( $this->get_do_autolink(), false ); ?>><?php esc_html_e( 'Disabled', 'buddypress' ); ?></option>
     1477                        </select>
     1478                    </label>
     1479                </p>
     1480            </div>
     1481        </div>
     1482
     1483        <?php
     1484    }
     1485
     1486    /**
    14141487     * Output the metabox for setting what type of field this is.
    14151488     *
Note: See TracChangeset for help on using the changeset viewer.