get_atts( $key, $classes, $data['conditional'], $data ) . '>';
+ if ( ( isset( $_field_value ) && '' !== $_field_value ) || in_array( $type, $fields_without_metakey, true ) ) {
+ $output .= '
get_atts( $key, $classes, $conditional, $data ) ) . '>';
if ( isset( $data['label'] ) || ! empty( $data['icon'] ) ) {
@@ -4310,8 +4314,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
$output .= $this->field_label( $data['label'], $key, $data );
}
- $res = $this->field_value( $key, $data['default'], $data );
-
+ $res = $_field_value;
if ( ! empty( $res ) ) {
$res = stripslashes( $res );
}
@@ -4326,19 +4329,20 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
}
$data['is_view_field'] = true;
+
/**
- * Filters change field HTML on view mode
+ * Filters the inner field HTML on view mode.
*
- * @since 2.0
+ * @since 1.3.x
* @hook um_view_field
*
- * @param {string} $output Field HTML.
- * @param {string} $data Field Data.
- * @param {string} $type Field Type.
+ * @param {string} $output Field inner HTML.
+ * @param {array} $data Field Data.
+ * @param {string} $type Field Type.
*
- * @return {array} $output Field HTML.
+ * @return {string} Field inner HTML.
*
- * @example
Change field HTML on view mode.
+ * @example
Change field's inner HTML on view mode.
* function my_view_field( $output, $data, $type ) {
* // your code here
* return $output;
@@ -4346,17 +4350,16 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
* add_filter( 'um_view_field', 'my_view_field', 10, 3 );
*/
$res = apply_filters( 'um_view_field', $res, $data, $type );
-
/**
- * Filters field HTML on view mode by field type
+ * Filters the inner field HTML on view mode by field type {$type}.
*
- * @since 2.0
+ * @since 1.3.x
* @hook um_view_field_value_{$type}
*
- * @param {string} $output Field HTML.
- * @param {string} $data Field Data.
+ * @param {string} $output Field inner HTML.
+ * @param {array} $data Field Data.
*
- * @return {array} $output Field HTML.
+ * @return {string} Field inner HTML.
*
* @example
Change field HTML on view mode by field type.
* function my_view_field( $output, $data ) {
@@ -4384,79 +4387,92 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
}
break;
-
/* HTML */
case 'block':
- $output .= '
get_atts( $key, $classes, $data['conditional'], $data ) . '>' . $data['content'] . '
';
+ $content = array_key_exists( 'content', $data ) ? $data['content'] : '';
+ $output .= '
get_atts( $key, $classes, $conditional, $data ) . '>' . $content . '
';
break;
-
/* Shortcode */
case 'shortcode':
- $content = str_replace( '{profile_id}', um_profile_id(), $data['content'] );
- if ( version_compare( get_bloginfo( 'version' ), '5.4', '<' ) ) {
- $content = do_shortcode( $content );
- } else {
- $content = apply_shortcodes( $content );
- }
+ $content = array_key_exists( 'content', $data ) ? $data['content'] : '';
+ $content = str_replace( '{profile_id}', um_profile_id(), $content );
+ $content = apply_shortcodes( $content );
- $output .= '
get_atts( $key, $classes, $data['conditional'], $data ) . '>' . $content . '
';
+ $output .= '
get_atts( $key, $classes, $conditional, $data ) . '>' . $content . '
';
break;
-
/* Gap/Space */
case 'spacing':
- $output .= '
get_atts( $key, $classes, $data['conditional'], $data, array( 'height' => $data['spacing'] ) ) . '>
';
+ $field_style = array();
+ if ( array_key_exists( 'spacing', $data ) ) {
+ $field_style = array( 'height' => $data['spacing'] );
+ }
+ $output .= '
get_atts( $key, $classes, $conditional, $data, $field_style ) . '>
';
break;
-
/* A line divider */
case 'divider':
- $output .= '
get_atts( $key, $classes, $data['conditional'], $data, array( 'border-bottom' => $data['borderwidth'] . 'px ' . $data['borderstyle'] . ' ' . $data['bordercolor'] ) ) . '>';
- if ( $data['divider_text'] ) {
+ $border_style = '';
+ if ( array_key_exists( 'borderwidth', $data ) ) {
+ $border_style .= $data['borderwidth'] . 'px';
+ }
+ if ( array_key_exists( 'borderstyle', $data ) ) {
+ $border_style .= ' ' . $data['borderstyle'];
+ }
+ if ( array_key_exists( 'bordercolor', $data ) ) {
+ $border_style .= ' ' . $data['bordercolor'];
+ }
+ $field_style = array();
+ if ( ! empty( $border_style ) ) {
+ $field_style = array( 'border-bottom' => $border_style );
+ }
+ $output .= '
get_atts( $key, $classes, $conditional, $data, $field_style ) . '>';
+ if ( ! empty( $data['divider_text'] ) ) {
$output .= '
' . $data['divider_text'] . '
';
}
$output .= '
';
break;
-
/* Rating */
case 'rating':
- $output .= '
get_atts( $key, $classes, $data['conditional'], $data ) . '>';
+ $output .= '
get_atts( $key, $classes, $conditional, $data ) . '>';
if ( isset( $data['label'] ) || ! empty( $data['icon'] ) ) {
$output .= $this->field_label( $data['label'], $key, $data );
}
+ $number = 5;
+ if ( array_key_exists( 'number', $data ) && in_array( absint( $data['number'] ), array( 5, 10 ), true ) ) {
+ $number = $data['number'];
+ }
ob_start();
?>
+ data-key="" data-number=""
+ data-score="field_value( $key, $default, $data ) ); ?>">
';
-
break;
-
}
- // Custom filter for field output
+ // Custom filter for field output.
if ( isset( $this->set_mode ) ) {
/**
- * Filters field HTML by field $key
+ * Filters outer field HTML by field $key.
*
- * @since 2.0
+ * @since 1.3.x
* @hook um_{$key}_form_show_field
*
- * @param {string} $output Field HTML.
- * @param {string} $mode Field Mode.
+ * @param {string} $output Field outer HTML.
+ * @param {string} $mode Field Mode.
*
- * @return {array} $output Field HTML.
+ * @return {string} Field outer HTML.
*
- * @example
Change field HTML by field $key.
+ * @example
Change field outer HTML by field $key.
* function my_form_show_field( $output, $mode ) {
* // your code here
* return $output;
@@ -4464,19 +4480,18 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
* add_filter( 'um_{$key}_form_show_field', 'my_form_show_field', 10, 2 );
*/
$output = apply_filters( "um_{$key}_form_show_field", $output, $this->set_mode );
-
/**
- * Filters field HTML by field $type
+ * Filters outer field HTML by field $type.
*
- * @since 2.0
+ * @since 1.3.x
* @hook um_{$type}_form_show_field
*
- * @param {string} $output Field HTML.
- * @param {string} $mode Field Mode.
+ * @param {string} $output Field outer HTML.
+ * @param {string} $mode Field Mode.
*
- * @return {array} $output Field HTML.
+ * @return {string} Field outer HTML.
*
- * @example
Change field HTML by field $type.
+ * @example
Change field outer HTML by field $type.
* function my_form_show_field( $output, $mode ) {
* // your code here
* return $output;
diff --git a/includes/core/class-roles-capabilities.php b/includes/core/class-roles-capabilities.php
index 9b60c143..6e0cb8a9 100644
--- a/includes/core/class-roles-capabilities.php
+++ b/includes/core/class-roles-capabilities.php
@@ -592,19 +592,24 @@ if ( ! class_exists( 'um\core\Roles_Capabilities' ) ) {
/**
- * Get role data
+ * Get role data.
+ *
+ * @param int $role_id Role ID.
*
- * @param int $roleID Role ID
* @return array
*/
- function role_data( $roleID ) {
- if ( strpos( $roleID, 'um_' ) === 0 ) {
- $roleID = substr( $roleID, 3 );
- $role_data = get_option( "um_role_{$roleID}_meta", array() );
+ public function role_data( $role_id ) {
+ if ( empty( $role_id ) ) {
+ return array();
+ }
+
+ if ( strpos( $role_id, 'um_' ) === 0 ) {
+ $role_id = substr( $role_id, 3 );
+ $role_data = get_option( "um_role_{$role_id}_meta", array() );
}
if ( empty( $role_data ) ) {
- $role_data = get_option( "um_role_{$roleID}_meta", array() );
+ $role_data = get_option( "um_role_{$role_id}_meta", array() );
}
if ( ! $role_data ) {
@@ -612,21 +617,36 @@ if ( ! class_exists( 'um\core\Roles_Capabilities' ) ) {
}
$temp = array();
- foreach ( $role_data as $key=>$value ) {
+ foreach ( $role_data as $key => $value ) {
if ( strpos( $key, '_um_' ) === 0 ) {
- $key = preg_replace('/_um_/', '', $key, 1);
+ $key = preg_replace( '/_um_/', '', $key, 1 );
}
-
- //$key = str_replace( '_um_', '', $key, $count );
$temp[ $key ] = $value;
}
-
- $temp = apply_filters( 'um_change_role_data', $temp, $roleID );
-
- return $temp;
+ /**
+ * Filters the Ultimate Member related user role data.
+ *
+ * @since 2.0
+ * @hook um_change_role_data
+ *
+ * @param {array} $role_data Role data.
+ * @param {string} $role_id Role ID.
+ *
+ * @return {array} Role data.
+ *
+ * @example
Set {some_capability_key} capability for subscriber user role.
+ * function my_change_role_data( $role_data, $role_id ) {
+ * // your code here
+ * if ( 'subscriber' === $role_id ) {
+ * $role_data['{some_capability_key}'] = true;
+ * }
+ * return $role_data;
+ * }
+ * add_filter( 'um_change_role_data', 'my_change_role_data', 10, 2 );
+ */
+ return apply_filters( 'um_change_role_data', $temp, $role_id );
}
-
/**
* Query for UM roles
*