<!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][10254] trunk: Enable richtext editing for xProfile textarea fields.</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/10254">10254</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/10254","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>2015-10-12 17:50:45 +0000 (Mon, 12 Oct 2015)</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'>Enable richtext editing for xProfile textarea fields.
Profile fields of the 'textarea' type are now edited using `wp_editor()`.
Output escaping has been modified to whitelist all tags permitted by the
"teeny" version of the `wp_editor()` interface.
Richtext is enabled for all and only 'textarea' fields:
* To enable richtext editing for a custom field type, set the `supports_richtext` property of your `BP_XProfile_Field_Type` class to `true`. In these cases, you'll need to provide your own editing markup as well; see the `edit_field_html()` and `admin_field_html()` methods of `BP_XProfile_Field_Type_Textarea` for inspiration.
* To disable richtext editing for specific 'textarea' fields, filter `bp_xprofile_is_richtext_enabled_for_field`.
Props needle, boonebgorges.
Fixes <a href="http://buddypress.trac.wordpress.org/ticket/5625">#5625</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcbptemplatesbplegacycssbuddypresscss">trunk/src/bp-templates/bp-legacy/css/buddypress.css</a></li>
<li><a href="#trunksrcbptemplatesbplegacycsstwentyfifteencss">trunk/src/bp-templates/bp-legacy/css/twentyfifteen.css</a></li>
<li><a href="#trunksrcbptemplatesbplegacycsstwentyfifteenscss">trunk/src/bp-templates/bp-legacy/css/twentyfifteen.scss</a></li>
<li><a href="#trunksrcbpxprofilebpxprofilefiltersphp">trunk/src/bp-xprofile/bp-xprofile-filters.php</a></li>
<li><a href="#trunksrcbpxprofilebpxprofilefunctionsphp">trunk/src/bp-xprofile/bp-xprofile-functions.php</a></li>
<li><a href="#trunksrcbpxprofileclassesclassbpxprofilefieldtypetextareaphp">trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-textarea.php</a></li>
<li><a href="#trunksrcbpxprofileclassesclassbpxprofilefieldtypephp">trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type.php</a></li>
<li><a href="#trunktestsphpunittestcasesxprofilefunctionsphp">trunk/tests/phpunit/testcases/xprofile/functions.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcbptemplatesbplegacycssbuddypresscss"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-templates/bp-legacy/css/buddypress.css</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-templates/bp-legacy/css/buddypress.css 2015-10-12 05:45:14 UTC (rev 10253)
+++ trunk/src/bp-templates/bp-legacy/css/buddypress.css 2015-10-12 17:50:45 UTC (rev 10254)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -840,7 +840,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> #buddypress .wp-editor-wrap input[type=submit],
</span><span class="cx" style="display: block; padding: 0 10px"> #buddypress .wp-editor-wrap input[type=button],
</span><span class="cx" style="display: block; padding: 0 10px"> #buddypress .wp-editor-wrap input[type=reset] {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- padding: 0 10px 1px;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ padding: 0 8px 1px;
</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"> /* Form classes & generic attr styling */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1584,6 +1584,26 @@
</span><span class="cx" style="display: block; padding: 0 10px"> #buddypress .field-visibility select {
</span><span class="cx" style="display: block; padding: 0 10px"> margin: 0;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+#buddypress .wp-editor-container {
+ border: 1px solid #dedede;
+}
+#buddypress .html-active button.switch-html {
+ border-bottom-color: transparent;
+ border-bottom-left-radius: 0;
+ border-bottom-right-radius: 0;
+ background: #f5f5f5;
+}
+#buddypress .tmce-active button.switch-tmce {
+ border-bottom-color: transparent;
+ border-bottom-left-radius: 0;
+ border-bottom-right-radius: 0;
+ background: #f5f5f5;
+}
+#buddypress .standard-form .wp-editor-container textarea {
+ width: 100%;
+ padding-top: 0;
+ padding-bottom: 0;
+}
</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"> 3.11 - Widgets
</span></span></pre></div>
<a id="trunksrcbptemplatesbplegacycsstwentyfifteencss"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-templates/bp-legacy/css/twentyfifteen.css</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-templates/bp-legacy/css/twentyfifteen.css 2015-10-12 05:45:14 UTC (rev 10253)
+++ trunk/src/bp-templates/bp-legacy/css/twentyfifteen.css 2015-10-12 17:50:45 UTC (rev 10254)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1708,6 +1708,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> border: 1px solid rgba(153, 153, 153, 0.5);
</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">+#buddypress .wp-editor-wrap a.button,
+#buddypress .wp-editor-wrap button,
+#buddypress .wp-editor-wrap input[type=submit],
+#buddypress .wp-editor-wrap input[type=button],
+#buddypress .wp-editor-wrap input[type=reset] {
+ padding: 0 5px 1px;
+}
+
</ins><span class="cx" style="display: block; padding: 0 10px"> #buddypress .standard-form li,
</span><span class="cx" style="display: block; padding: 0 10px"> #buddypress .group-create-form li {
</span><span class="cx" style="display: block; padding: 0 10px"> float: none;
</span></span></pre></div>
<a id="trunksrcbptemplatesbplegacycsstwentyfifteenscss"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-templates/bp-legacy/css/twentyfifteen.scss</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-templates/bp-legacy/css/twentyfifteen.scss 2015-10-12 05:45:14 UTC (rev 10253)
+++ trunk/src/bp-templates/bp-legacy/css/twentyfifteen.scss 2015-10-12 17:50:45 UTC (rev 10254)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2040,6 +2040,17 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> select {border: 1px solid rgba($border-color, 0.5);}
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Overrides for embedded WP editors.
+ .wp-editor-wrap {
+ a.button,
+ button,
+ input[type=submit],
+ input[type=button],
+ input[type=reset] {
+ padding: 0 5px 1px;
+ }
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> } // close #buddypress
</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="trunksrcbpxprofilebpxprofilefiltersphp"></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-filters.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-xprofile/bp-xprofile-filters.php 2015-10-12 05:45:14 UTC (rev 10253)
+++ trunk/src/bp-xprofile/bp-xprofile-filters.php 2015-10-12 17:50:45 UTC (rev 10254)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -23,14 +23,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'bp_get_the_profile_field_value', 'wpautop' );
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'bp_get_the_profile_field_value', 'force_balance_tags' );
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'bp_get_the_profile_field_value', 'make_clickable' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-add_filter( 'bp_get_the_profile_field_value', 'esc_html', 8 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+add_filter( 'bp_get_the_profile_field_value', 'bp_xprofile_escape_field_data', 8, 3 );
</ins><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'bp_get_the_profile_field_value', 'convert_smilies', 9 );
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_format_field_value', 1, 2 );
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_format_field_value_by_type', 8, 3 );
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 3 );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'bp_get_the_profile_field_edit_value', 'force_balance_tags' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-add_filter( 'bp_get_the_profile_field_edit_value', 'esc_html' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+add_filter( 'bp_get_the_profile_field_edit_value', 'bp_xprofile_escape_field_data', 10, 3 );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'bp_get_the_profile_group_name', 'stripslashes' );
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'bp_get_the_profile_group_description', 'stripslashes' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -39,7 +39,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'bp_get_the_profile_field_name', 'stripslashes' );
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'bp_get_the_profile_field_description', 'stripslashes' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-add_filter( 'xprofile_get_field_data', 'wp_filter_kses', 1 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+add_filter( 'xprofile_get_field_data', 'xprofile_filter_kses', 1 );
</ins><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'xprofile_field_name_before_save', 'wp_filter_kses', 1 );
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'xprofile_field_description_before_save', 'wp_filter_kses', 1 );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -124,6 +124,20 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $xprofile_allowedtags = $allowedtags;
</span><span class="cx" style="display: block; padding: 0 10px"> $xprofile_allowedtags['a']['rel'] = array();
</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 supports rich text, we must allow tags that appear in wp_editor().
+ if ( $data_obj instanceof BP_XProfile_ProfileData && bp_xprofile_is_richtext_enabled_for_field( $data_obj->field_id ) ) {
+ $richtext_tags = array(
+ 'img' => array( 'id' => 1, 'class' => 1, 'src' => 1, 'alt' => 1, 'width' => 1, 'height' => 1 ),
+ 'ul' => array( 'id' => 1, 'class' => 1 ),
+ 'ol' => array( 'id' => 1, 'class' => 1 ),
+ 'li' => array( 'id' => 1, 'class' => 1 ),
+ 'span' => array( 'style' => 1 ),
+ 'p' => array( 'style' => 1 ),
+ );
+
+ $xprofile_allowedtags = array_merge( $allowedtags, $richtext_tags );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Filters the allowed tags for use within xprofile_filter_kses().
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -280,6 +294,35 @@
</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">+ * Escape field value for display.
+ *
+ * Most field values are simply run through esc_html(). Those that support rich text (by default, `textarea` only)
+ * are sanitized using kses, which allows a whitelist of HTML tags.
+ *
+ * @since 2.4.0
+ *
+ * @param string $value Field value.
+ * @param string $field_type Field type.
+ * @param int $field_id Field ID.
+ * @return string
+ */
+function bp_xprofile_escape_field_data( $value, $field_type, $field_id ) {
+ if ( bp_xprofile_is_richtext_enabled_for_field( $field_id ) ) {
+ // xprofile_filter_kses() expects a BP_XProfile_ProfileData object.
+ $data_obj = null;
+ if ( bp_is_user() ) {
+ $data_obj = new BP_XProfile_ProfileData( $field_id, bp_displayed_user_id() );
+ }
+
+ $value = xprofile_filter_kses( $value, $data_obj );
+ } else {
+ $value = esc_html( $value );
+ }
+
+ return $value;
+}
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Filter an Extended Profile field value, and attempt to make clickable links
</span><span class="cx" style="display: block; padding: 0 10px"> * to members search results out of them.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span></span></pre></div>
<a id="trunksrcbpxprofilebpxprofilefunctionsphp"></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-functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-xprofile/bp-xprofile-functions.php 2015-10-12 05:45:14 UTC (rev 10253)
+++ trunk/src/bp-xprofile/bp-xprofile-functions.php 2015-10-12 17:50:45 UTC (rev 10254)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1020,6 +1020,39 @@
</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">+ * Is rich text enabled for this profile field?
+ *
+ * By default, rich text is enabled for textarea fields and disabled for all other field types.
+ *
+ * @since 2.4.0
+ *
+ * @param int $field_id Optional. Default current field ID.
+ * @return bool
+ */
+function bp_xprofile_is_richtext_enabled_for_field( $field_id = null ) {
+ if ( ! $field_id ) {
+ $field_id = bp_get_the_profile_field_id();
+ }
+
+ $field = xprofile_get_field( $field_id );
+
+ $enabled = false;
+ if ( $field instanceof BP_XProfile_Field ) {
+ $enabled = (bool) $field->type_obj->supports_richtext;
+ }
+
+ /**
+ * Filters whether richtext is enabled for the given field.
+ *
+ * @since 2.4.0
+ *
+ * @param bool $enabled True if richtext is enabled for the field, otherwise false.
+ * @param int $field_id ID of the field.
+ */
+ return apply_filters( 'bp_xprofile_is_richtext_enabled_for_field', $enabled, $field_id );
+}
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Get visibility levels out of the $bp global.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array
</span></span></pre></div>
<a id="trunksrcbpxprofileclassesclassbpxprofilefieldtypetextareaphp"></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-textarea.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-textarea.php 2015-10-12 05:45:14 UTC (rev 10253)
+++ trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-textarea.php 2015-10-12 17:50:45 UTC (rev 10254)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -26,6 +26,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->category = _x( 'Single Fields', 'xprofile field type category', 'buddypress' );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->name = _x( 'Multi-line Text Area', 'xprofile field type', 'buddypress' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->supports_richtext = true;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->set_format( '/^.*$/m', 'replace' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -59,10 +60,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> unset( $raw_properties['user_id'] );
</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">- $r = bp_parse_args( $raw_properties, array(
- 'cols' => 40,
- 'rows' => 5,
- ) ); ?>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $richtext_enabled = bp_xprofile_is_richtext_enabled_for_field(); ?>
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> <label for="<?php bp_the_profile_field_input_name(); ?>">
</span><span class="cx" style="display: block; padding: 0 10px"> <?php bp_the_profile_field_name(); ?>
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -72,11 +70,46 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /** This action is documented in bp-xprofile/bp-xprofile-classes */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- do_action( bp_get_the_profile_field_errors_action() ); ?>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ do_action( bp_get_the_profile_field_errors_action() );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <textarea <?php echo $this->get_edit_field_html_elements( $r ); ?>><?php bp_the_profile_field_edit_value(); ?></textarea>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $richtext_enabled ) {
+ $r = wp_parse_args( $raw_properties, array(
+ 'cols' => 40,
+ 'rows' => 5,
+ ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <?php
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ ?>
+
+ <textarea <?php echo $this->get_edit_field_html_elements( $r ); ?>><?php bp_the_profile_field_edit_value(); ?></textarea>
+
+ <?php
+
+ } else {
+
+ /**
+ * Filters the arguments passed to `wp_editor()` in richtext xprofile fields.
+ *
+ * @since 2.4.0
+ *
+ * @param array $args {
+ * Array of optional arguments. See `wp_editor()`.
+ * @type bool $teeny Whether to use the teeny version of TinyMCE. Default true.
+ * @type bool $media_buttons Whether to show media buttons. Default false.
+ * @type bool $quicktags Whether to show the quicktags buttons. Default true.
+ * }
+ */
+ $editor_args = apply_filters( 'bp_xprofile_field_type_textarea_editor_args', array(
+ 'teeny' => true,
+ 'media_buttons' => false,
+ 'quicktags' => true,
+ ) );
+
+ wp_editor(
+ bp_get_the_profile_field_edit_value(),
+ bp_get_the_profile_field_input_name(),
+ $editor_args
+ );
+ }
</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 class="lines" style="display: block; padding: 0 10px; color: #888">@@ -89,14 +122,33 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $raw_properties Optional key/value array of permitted attributes that you want to add.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function admin_field_html( array $raw_properties = array() ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $r = bp_parse_args( $raw_properties, array(
- 'cols' => 40,
- 'rows' => 5,
- ) ); ?>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $richtext_enabled = bp_xprofile_is_richtext_enabled_for_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">- <textarea <?php echo $this->get_edit_field_html_elements( $r ); ?>></textarea>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $richtext_enabled ) {
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <?php
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $r = bp_parse_args( $raw_properties, array(
+ 'cols' => 40,
+ 'rows' => 5,
+ ) ); ?>
+
+ <textarea <?php echo $this->get_edit_field_html_elements( $r ); ?>></textarea>
+
+ <?php
+ } else {
+
+ /** This filter is documented in bp-xprofile/classes/class-bp-xprofile-field-type-textarea.php */
+ $editor_args = apply_filters( 'bp_xprofile_field_type_textarea_editor_args', array(
+ 'teeny' => true,
+ 'media_buttons' => false,
+ 'quicktags' => true,
+ ) );
+
+ wp_editor(
+ '',
+ 'xprofile_textarea_' . bp_get_the_profile_field_id(),
+ $editor_args
+ );
+ }
</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="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 2015-10-12 05:45:14 UTC (rev 10253)
+++ trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type.php 2015-10-12 17:50:45 UTC (rev 10254)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -73,6 +73,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public $supports_multiple_defaults = 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 supports rich text by default.
+ *
+ * @since 2.4.0
+ * @var bool
+ */
+ public $supports_richtext = false;
+
+ /**
</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></pre></div>
<a id="trunktestsphpunittestcasesxprofilefunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/testcases/xprofile/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/testcases/xprofile/functions.php 2015-10-12 05:45:14 UTC (rev 10253)
+++ trunk/tests/phpunit/testcases/xprofile/functions.php 2015-10-12 17:50:45 UTC (rev 10254)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -913,4 +913,30 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( $field_1, $field_2 );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame( $num_queries, $wpdb->num_queries );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * @ticket BP5625
+ */
+ public function test_bp_xprofie_is_richtext_enabled_for_field_should_default_to_true_for_textareas() {
+ $g = $this->factory->xprofile_group->create();
+ $f = $this->factory->xprofile_field->create( array(
+ 'field_group_id' => $g,
+ 'type' => 'textarea',
+ ) );
+
+ $this->assertTrue( bp_xprofile_is_richtext_enabled_for_field( $f ) );
+ }
+
+ /**
+ * @ticket BP5625
+ */
+ public function test_bp_xprofie_is_richtext_enabled_for_field_should_default_to_false_for_non_textareas() {
+ $g = $this->factory->xprofile_group->create();
+ $f = $this->factory->xprofile_field->create( array(
+ 'field_group_id' => $g,
+ 'type' => 'radio',
+ ) );
+
+ $this->assertFalse( bp_xprofile_is_richtext_enabled_for_field( $f ) );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>
</body>
</html>