<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[BuddyPress][11041] trunk/src/bp-xprofile: XProfile: Introduce new settings for Datebox field type.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://buddypress.trac.wordpress.org/changeset/11041">11041</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://buddypress.trac.wordpress.org/changeset/11041","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>boonebgorges</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-08-30 15:17:16 +0000 (Tue, 30 Aug 2016)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>XProfile: Introduce new settings for Datebox field type.
These new settings are designed to make it easier for site administrators
to decide how date-based data will be collected and displayed.
- "Date format" allows the admin to select how dates will be displayed on public profiles. A number of default custom date formats are included. Admins may also enter a custom date format, or opt to display time elapsed ("4 years ago", etc).
- "Range" allows the admin to set the start and end values for the Year dropdown. There are two ways to configure the range. The first is by defining a specific set of start and end years. The second is to define a relative range: *from* a certain number of years ago (or in the future) *to* a certain number of years ago (or in the future).
Props abwebstudio, abweb, sooskriszta, boonebgorges, DJPaul, mercime.
See <a href="http://buddypress.trac.wordpress.org/ticket/5500">#5500</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcbpxprofileadmincssadmincss">trunk/src/bp-xprofile/admin/css/admin.css</a></li>
<li><a href="#trunksrcbpxprofileadminjsadminjs">trunk/src/bp-xprofile/admin/js/admin.js</a></li>
<li><a href="#trunksrcbpxprofilebpxprofileadminphp">trunk/src/bp-xprofile/bp-xprofile-admin.php</a></li>
<li><a href="#trunksrcbpxprofilebpxprofilecssjsphp">trunk/src/bp-xprofile/bp-xprofile-cssjs.php</a></li>
<li><a href="#trunksrcbpxprofileclassesclassbpxprofilefieldtypedateboxphp">trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-datebox.php</a></li>
<li><a href="#trunksrcbpxprofileclassesclassbpxprofilefieldtypephp">trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type.php</a></li>
<li><a href="#trunksrcbpxprofileclassesclassbpxprofilefieldphp">trunk/src/bp-xprofile/classes/class-bp-xprofile-field.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcbpxprofileadmincssadmincss"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-xprofile/admin/css/admin.css</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-xprofile/admin/css/admin.css 2016-08-30 09:30:43 UTC (rev 11040)
+++ trunk/src/bp-xprofile/admin/css/admin.css 2016-08-30 15:17:16 UTC (rev 11041)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -284,3 +284,21 @@
</span><span class="cx" style="display: block; padding: 0 10px"> display: none;
</span><span class="cx" style="display: block; padding: 0 10px"> visibility: hidden;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+.form-table.bp-date-options {
+ margin: 0 8px;
+}
+
+.form-table.bp-date-options th {
+ width: 150px;
+}
+
+.date-format-label {
+ display: inline-block;
+ width: 150px;
+}
+
+.date-format-custom-value,
+.date-range-numeric {
+ width: 56px;
+}
</ins></span></pre></div>
<a id="trunksrcbpxprofileadminjsadminjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-xprofile/admin/js/admin.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-xprofile/admin/js/admin.js 2016-08-30 09:30:43 UTC (rev 11040)
+++ trunk/src/bp-xprofile/admin/js/admin.js 2016-08-30 15:17:16 UTC (rev 11041)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -78,11 +78,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> function show_options( forWhat ) {
</span><span class="cx" style="display: block; padding: 0 10px"> var do_autolink;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- for ( var i = 0; i < XProfileAdmin.supports_options_field_types.length; i++ ) {
- document.getElementById( XProfileAdmin.supports_options_field_types[i] ).style.display = 'none';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ for ( var i = 0; i < XProfileAdmin.do_settings_section_field_types.length; i++ ) {
+ document.getElementById( XProfileAdmin.do_settings_section_field_types[i] ).style.display = 'none';
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( XProfileAdmin.supports_options_field_types.indexOf( forWhat ) >= 0 ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( XProfileAdmin.do_settings_section_field_types.indexOf( forWhat ) >= 0 ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> document.getElementById( forWhat ).style.display = '';
</span><span class="cx" style="display: block; padding: 0 10px"> do_autolink = 'on';
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -270,6 +270,47 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Handle title placeholder text the WordPress way
</span><span class="cx" style="display: block; padding: 0 10px"> titleHint( 'title' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // On Date fields, selecting a date_format radio button should change the Custom value.
+ var $date_format = jQuery( 'input[name="date_format"]' );
+ var $date_format_custom_value = jQuery( '#date-format-custom-value' );
+ var $date_format_sample = jQuery( '#date-format-custom-sample' );
+ $date_format.click( function( e ) {
+ switch ( e.target.value ) {
+ case 'elapsed' :
+ $date_format_custom_value.val( '' );
+ $date_format_sample.html( '' );
+ break;
+
+ case 'custom' :
+ break;
+
+ default :
+ $date_format_custom_value.val( e.target.value );
+ $date_format_sample.html( jQuery( e.target ).siblings( '.date-format-label' ).html() );
+ break;
+ }
+ } );
+
+ // Clicking into the custom date format field should select the Custom radio button.
+ var $date_format_custom = jQuery( '#date-format-custom' );
+ $date_format_custom_value.focus( function() {
+ $date_format_custom.prop( 'checked', 'checked' );
+ } );
+
+ // Validate custom date field.
+ var $date_format_spinner = jQuery( '#date-format-custom-spinner' );
+ $date_format_custom_value.change( function( e ) {
+ $date_format_spinner.addClass( 'is-active' );
+ jQuery.post( ajaxurl, {
+ action: 'date_format',
+ date: e.target.value
+ },
+ function( response ) {
+ $date_format_spinner.removeClass( 'is-active' );
+ $date_format_sample.html( response );
+ } );
+ } );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // tabs init with a custom tab template and an "add" callback filling in the content
</span><span class="cx" style="display: block; padding: 0 10px"> var $tab_items,
</span><span class="cx" style="display: block; padding: 0 10px"> $tabs = jQuery( '#tabs' ).tabs();
</span></span></pre></div>
<a id="trunksrcbpxprofilebpxprofileadminphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-xprofile/bp-xprofile-admin.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-xprofile/bp-xprofile-admin.php 2016-08-30 09:30:43 UTC (rev 11040)
+++ trunk/src/bp-xprofile/bp-xprofile-admin.php 2016-08-30 15:17:16 UTC (rev 11041)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -432,6 +432,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> bp_xprofile_update_field_meta( $field_id, 'do_autolink', 'off' );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $field->type_obj->do_settings_section() ) {
+ $settings = isset( $_POST['field_settings'] ) ? wp_unslash( $_POST['field_settings'] ) : array();
+ $field->admin_save_settings( $settings );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Fires at the end of the process to save a field for a user, if successful.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span></span></pre></div>
<a id="trunksrcbpxprofilebpxprofilecssjsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-xprofile/bp-xprofile-cssjs.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-xprofile/bp-xprofile-cssjs.php 2016-08-30 09:30:43 UTC (rev 11040)
+++ trunk/src/bp-xprofile/bp-xprofile-cssjs.php 2016-08-30 15:17:16 UTC (rev 11041)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -51,14 +51,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // types that support options, for use in showing/hiding the
</span><span class="cx" style="display: block; padding: 0 10px"> // "please enter options for this field" section.
</span><span class="cx" style="display: block; padding: 0 10px"> $strings = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'supports_options_field_types' => array(),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'do_settings_section_field_types' => array(),
</ins><span class="cx" style="display: block; padding: 0 10px"> 'do_autolink' => '',
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( bp_xprofile_get_field_types() as $field_type => $field_type_class ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $field = new $field_type_class();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $field->supports_options ) {
- $strings['supports_options_field_types'][] = $field_type;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $field->do_settings_section() ) {
+ $strings['do_settings_section_field_types'][] = $field_type;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunksrcbpxprofileclassesclassbpxprofilefieldtypedateboxphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-datebox.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-datebox.php 2016-08-30 09:30:43 UTC (rev 11040)
+++ trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-datebox.php 2016-08-30 15:17:16 UTC (rev 11041)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -30,6 +30,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->set_format( '/^\d{4}-\d{1,2}-\d{1,2} 00:00:00$/', 'replace' ); // "Y-m-d 00:00:00"
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->do_settings_section = true;
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Fires inside __construct() method for BP_XProfile_Field_Type_Datebox class.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -239,7 +241,17 @@
</span><span class="cx" style="display: block; padding: 0 10px"> case 'year':
</span><span class="cx" style="display: block; padding: 0 10px"> $html = sprintf( '<option value="" %1$s>%2$s</option>', selected( $year, 0, false ), /* translators: no option picked in select box */ __( '----', 'buddypress' ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- for ( $i = 2037; $i > 1901; $i-- ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $settings = $this->get_field_settings( $this->field_obj->id );
+
+ if ( 'relative' === $settings['range_type'] ) {
+ $start = date( 'Y' ) + $settings['range_relative_start'];
+ $end = date( 'Y' ) + $settings['range_relative_end'];
+ } else {
+ $start = $settings['range_absolute_start'];
+ $end = $settings['range_absolute_end'];
+ }
+
+ for ( $i = $end; $i >= $start; $i-- ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $html .= sprintf( '<option value="%1$s" %2$s>%3$s</option>', (int) $i, selected( $year, $i, false ), (int) $i );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -315,17 +327,242 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * This method usually outputs HTML for this field type's children options on the wp-admin Profile Fields
- * "Add Field" and "Edit Field" screens, but for this field type, we don't want it, so it's stubbed out.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Get settings for a given date field.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 2.0.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 2.7.0
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param int $field_id ID of the field.
+ * @return array
+ */
+ public static function get_field_settings( $field_id ) {
+ $defaults = array(
+ 'date_format' => 'Y-m-d',
+ 'date_format_custom' => '',
+ 'range_type' => 'absolute',
+ 'range_absolute_start' => date( 'Y' ) - 60,
+ 'range_absolute_end' => date( 'Y' ) + 10,
+ 'range_relative_start' => '-10',
+ 'range_relative_end' => '20',
+ );
+
+ $settings = array();
+ foreach ( $defaults as $key => $value ) {
+ $saved = bp_xprofile_get_meta( $field_id, 'field', $key, true );
+ if ( false !== $saved ) {
+ $settings[ $key ] = $saved;
+ } else {
+ $settings[ $key ] = $value;
+ }
+ }
+
+ $settings = self::validate_settings( $settings );
+
+ return $settings;
+ }
+
+ /**
+ * Validate date field settings.
+ *
+ * @since 2.7.0
+ *
+ * @param array $settings Raw settings.
+ * @return array Validated settings.
+ */
+ public static function validate_settings( $settings ) {
+ foreach ( $settings as $key => &$value ) {
+ switch ( $key ) {
+ case 'range_type' :
+ if ( $value !== 'absolute' ) {
+ $value = 'relative';
+ }
+ break;
+
+ // @todo More date restrictions?
+ case 'range_absolute_start' :
+ case 'range_absolute_end' :
+ $value = absint( $value );
+ break;
+
+ case 'range_relative_start' :
+ case 'range_relative_end' :
+ $value = intval( $value );
+ break;
+ }
+ }
+
+ return $settings;
+ }
+
+ /**
+ * Save settings from the field edit screen in the Dashboard.
+ *
+ * @param int $field_id ID of the field.
+ * @param array $settings Array of settings.
+ * @return bool True on success.
+ */
+ public function admin_save_settings( $field_id, $settings ) {
+ $existing_settings = self::get_field_settings( $field_id );
+
+ $saved_settings = array();
+ foreach ( array_keys( $existing_settings ) as $setting ) {
+ switch ( $setting ) {
+ case 'range_relative_start' :
+ case 'range_relative_end' :
+ $op_key = $setting . '_type';
+ if ( isset( $settings[ $op_key ] ) && 'past' === $settings[ $op_key ] ) {
+ $value = 0 - intval( $settings[ $setting ] );
+ } else {
+ $value = intval( $settings[ $setting ] );
+ }
+
+ $saved_settings[ $setting ] = $value;
+ break;
+
+ default :
+ if ( isset( $settings[ $setting ] ) ) {
+ $saved_settings[ $setting ] = $settings[ $setting ];
+ }
+ break;
+ }
+ }
+
+ // Sanitize and validate saved settings.
+ $saved_settings = self::validate_settings( $saved_settings );
+
+ foreach ( $saved_settings as $setting_key => $setting_value ) {
+ bp_xprofile_update_meta( $field_id, 'field', $setting_key, $setting_value );
+ }
+
+ return true;
+ }
+
+ /**
+ * Generate the settings markup for Date fields.
+ *
+ * @since 2.7.0
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @param BP_XProfile_Field $current_field The current profile field on the add/edit screen.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $control_type Optional. HTML input type used to render the current
</span><span class="cx" style="display: block; padding: 0 10px"> * field's child options.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {}
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {
+ $type = array_search( get_class( $this ), bp_xprofile_get_field_types() );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( false === $type ) {
+ return;
+ }
+
+ $class = $current_field->type != $type ? 'display: none;' : '';
+ $current_type_obj = bp_xprofile_create_field_type( $type );
+
+ $settings = self::get_field_settings( $current_field->id );
+ ?>
+
+<div id="<?php echo esc_attr( $type ); ?>" class="postbox bp-options-box" style="<?php echo esc_attr( $class ); ?> margin-top: 15px;">
+ <table class="form-table bp-date-options">
+ <tr>
+ <th scope="row">
+ <?php esc_html_e( 'Date format', 'buddypress' ); ?>
+ </th>
+
+ <td>
+ <fieldset>
+ <legend class="screen-reader-text">
+ <?php esc_html_e( 'Date format', 'buddypress' ); ?>
+ </legend>
+
+ <?php foreach ( $this->get_date_formats() as $format ): ?>
+ <div class="bp-date-format-option">
+ <label for="date-format-<?php echo esc_attr( $format ); ?>">
+ <input type="radio" name="field_settings[date_format]" id="date-format-<?php echo esc_attr( $format ); ?>" value="<?php echo esc_attr( $format ); ?>" <?php checked( $format, $settings['date_format'] ); ?> />
+ <span class="date-format-label"><?php echo date_i18n( $format ); ?></span>
+ <code><?php echo esc_html( $format ); ?></code>
+ </label>
+ </div>
+ <?php endforeach;?>
+
+ <div class="bp-date-format-option">
+ <label for="date-format-elapsed">
+ <input type="radio" name="field_settings[date_format]" id="date-format-elapsed" <?php checked( 'elapsed', $settings['date_format'] ); ?> value="elapsed" />
+ <span class="date-format-label"><?php esc_html_e( 'Time elapsed', 'buddypress' ); ?></span> <?php _e( '<code>4 years ago</code>, <code>4 years from now</code>', 'buddypress' ); ?>
+ </label>
+ </div>
+
+ <div class="bp-date-format-option">
+ <label for="date-format-custom">
+ <input type="radio" name="field_settings[date_format]" id="date-format-custom" <?php checked( 'custom', $settings['date_format'] ); ?> value="custom" />
+ <span class="date-format-label"><?php esc_html_e( 'Custom:', 'buddypress' ); ?></span>
+ <input type="text" name="field_settings[date_format_custom]" id="date-format-custom-value" class="date-format-custom-value" value="<?php echo esc_attr( $settings['date_format_custom'] ); ?>" /> <span class="screen-reader-text"><?php esc_html_e( 'Example:', 'buddypress' ); ?></span><span class="date-format-custom-sample" id="date-format-custom-sample"><?php if ( $settings['date_format_custom'] ) : ?><?php echo esc_html( date( $settings['date_format_custom'] ) ); endif; ?></span><span class="spinner" id="date-format-custom-spinner"></span>
+ </label>
+ </div>
+ </fieldset>
+
+ <p><a href="https://codex.wordpress.org/Formatting_Date_and_Time"><?php esc_html_e( 'Documentation on date and time formatting', 'buddypress' ); ?></a></p>
+ </td>
+ </tr>
+
+ <tr>
+ <th scope="row">
+ <?php esc_html_e( 'Range', 'buddypress' ); ?>
+ </th>
+
+ <td>
+ <fieldset>
+ <legend class="screen-reader-text">
+ <?php esc_html_e( 'Range', 'buddypress' ); ?>
+ </legend>
+
+ <div class="bp-date-format-option">
+ <label>
+ <input type="radio" name="field_settings[range_type]" id="range_type_absolute" value="absolute" <?php checked( 'absolute', $settings['range_type'] ); ?> />
+
+ <?php
+ printf(
+ /* translators: 1: Start year for date range, 2: End year for date range */
+ __( 'From %1$s to %2$s', 'buddypress' ),
+ sprintf( '<input class="date-range-numeric" type="text" name="field_settings[range_absolute_start]" value="%s" />', esc_attr( $settings['range_absolute_start'] ) ),
+ sprintf( '<input class="date-range-numeric" type="text" name="field_settings[range_absolute_end]" value="%s" />', esc_attr( $settings['range_absolute_end'] ) )
+ );
+ ?>
+ </label>
+ </div>
+
+ <div class="bp-date-format-option">
+ <label>
+ <input type="radio" name="field_settings[range_type]" id="range_type_relative" value="relative" <?php checked( 'relative', $settings['range_type'] ); ?> />
+
+ <?php
+ printf(
+ /* translators: 1: "From" year count for date range, 2: "To" year count for date range */
+ __( 'From %1$s to %2$s', 'buddypress' ),
+ sprintf(
+ '<input type="text" class="date-range-numeric" name="field_settings[range_relative_start]" value="%s" /> <select name="field_settings[range_relative_start_type]"><option value="past" %s>%s</option><option value="future" %s>%s</option></select>',
+ esc_attr( abs( $settings['range_relative_start'] ) ),
+ selected( true, $settings['range_relative_start'] <= 0, false ),
+ esc_attr__( 'years ago', 'buddypress' ),
+ selected( true, $settings['range_relative_start'] > 0, false ),
+ esc_attr__( 'years from now', 'buddypress' )
+ ),
+ sprintf(
+ '<input type="text" class="date-range-numeric" name="field_settings[range_relative_end]" value="%s" /> <select name="field_settings[range_relative_end_type]"><option value="past" %s>%s</option><option value="future" %s>%s</option></select>',
+ esc_attr( abs( $settings['range_relative_end'] ) ),
+ selected( true, $settings['range_relative_end'] <= 0, false ),
+ esc_attr__( 'years ago', 'buddypress' ),
+ selected( true, $settings['range_relative_end'] > 0, false ),
+ esc_attr__( 'years from now', 'buddypress' )
+ )
+ );
+ ?>
+ </label>
+ </div>
+ </fieldset>
+ </td>
+ </tr>
+ </table>
+</div>
+ <?php
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Format Date values for display.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -344,6 +581,28 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $field_value = strtotime( $field_value );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return bp_format_time( $field_value, true, false );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $settings = self::get_field_settings( $field_id );
+
+ switch ( $settings['date_format'] ) {
+ case 'elapsed' :
+ $formatted = bp_core_time_since( $field_value );
+ break;
+
+ case 'custom' :
+ $formatted = date( $settings['date_format_custom'], $field_value );
+ break;
+
+ default :
+ $formatted = date( $settings['date_format'], $field_value );
+ break;
+ }
+
+ return $formatted;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ public function get_date_formats() {
+ $date_formats = array_unique( apply_filters( 'date_formats', array( __( 'F j, Y', 'buddypress' ), 'Y-m-d', 'm/d/Y', 'd/m/Y' ) ) );
+
+ return apply_filters( 'bp_xprofile_date_field_date_formats', $date_formats );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunksrcbpxprofileclassesclassbpxprofilefieldtypephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type.php 2016-08-30 09:30:43 UTC (rev 11040)
+++ trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type.php 2016-08-30 15:17:16 UTC (rev 11041)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -82,6 +82,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public $supports_richtext = false;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * If the field type has a type-specific settings section on the Edit Field panel.
+ *
+ * @since 2.7.0
+ * @var bool|null Boolean if set explicitly by the type object, otherwise null.
+ */
+ protected $do_settings_section = null;
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * If object is created by an BP_XProfile_Field object.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 2.0.0
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -229,6 +237,23 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Check whether the current field type should have a settings ("options") section on the Edit Field panel.
+ *
+ * Falls back on `supports_options` if no value is set by the field type.
+ *
+ * @since 2.7.0
+ *
+ * @return bool
+ */
+ public function do_settings_section() {
+ if ( null === $this->do_settings_section ) {
+ $this->do_settings_section = $this->supports_options;
+ }
+
+ return (bool) $this->do_settings_section;
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Output the edit field HTML for this field type.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * Must be used inside the {@link bp_profile_fields()} template loop.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -451,6 +476,18 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return $field_value;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Save miscellaneous settings related to this field type.
+ *
+ * Override in a specific field type if it requires an admin save routine.
+ *
+ * @since 2.7.0
+ *
+ * @param int $field_id Field ID.
+ * @param array $settings Array of settings.
+ */
+ public function admin_save_settings( $field_id, $settings ) {}
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /** Protected *************************************************************/
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span></span></pre></div>
<a id="trunksrcbpxprofileclassesclassbpxprofilefieldphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-xprofile/classes/class-bp-xprofile-field.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-xprofile/classes/class-bp-xprofile-field.php 2016-08-30 09:30:43 UTC (rev 11040)
+++ trunk/src/bp-xprofile/classes/class-bp-xprofile-field.php 2016-08-30 15:17:16 UTC (rev 11041)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1106,6 +1106,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Save miscellaneous settings for this field.
+ *
+ * Some field types have type-specific settings, which are saved here.
+ *
+ * @since 2.7.0
+ *
+ * @param array $settings Array of settings.
+ */
+ public function admin_save_settings( $settings ) {
+ return $this->type_obj->admin_save_settings( $this->id, $settings );
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Populates the items for radio buttons, checkboxes, and dropdown boxes.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function render_admin_form_children() {
</span></span></pre>
</div>
</div>
</body>
</html>