Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/08/2016 04:52:44 PM (6 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.