| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * @since 2.04 |
| 13 | 13 | * |
| 14 | - * @var stdClass|null | |
| 14 | + * @var stdClass | |
| 15 | 15 | */ |
| 16 | - protected $field; | |
| 16 | + protected $field = null; | |
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * @since 4.03 |
| 20 | 20 | * |
| @@ -55,9 +55,9 @@ | ||
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | $this->entry = $entry; |
| 58 | 58 | $this->entry_id = $entry->id; |
| 59 | - $field = apply_filters( 'frm_field_value_object', $field ); | |
| 59 | + $field = apply_filters( 'frm_field_value_object', $field ); | |
| 60 | 60 | $this->field = $field; |
| 61 | 61 | $this->init_saved_value( $entry ); |
| 62 | 62 | } |
| 63 | 63 | |
| @@ -76,10 +76,8 @@ | ||
| 76 | 76 | * |
| 77 | 77 | * @since 2.04 |
| 78 | 78 | * |
| 79 | 79 | * @param stdClass $entry |
| 80 | - * | |
| 81 | - * @return void | |
| 82 | 80 | */ |
| 83 | 81 | protected function init_saved_value( $entry ) { |
| 84 | 82 | if ( $this->field->type === 'html' ) { |
| 85 | 83 | $this->saved_value = $this->field->description; |
| @@ -97,15 +95,12 @@ | ||
| 97 | 95 | * |
| 98 | 96 | * @since 2.05 |
| 99 | 97 | * |
| 100 | 98 | * @param array $atts |
| 101 | - * | |
| 102 | - * @return void | |
| 103 | 99 | */ |
| 104 | 100 | public function prepare_displayed_value( $atts = array() ) { |
| 105 | 101 | $this->displayed_value = $this->saved_value; |
| 106 | - // This class shouldn't affect values. | |
| 107 | - unset( $atts['class'] ); | |
| 102 | + unset( $atts['class'] ); // This class shouldn't affect values. | |
| 108 | 103 | $this->generate_displayed_value_for_field_type( $atts ); |
| 109 | 104 | $this->filter_displayed_value( $atts ); |
| 110 | 105 | } |
| 111 | 106 | |
| @@ -112,10 +107,8 @@ | ||
| 112 | 107 | /** |
| 113 | 108 | * Get a value from the field settings |
| 114 | 109 | * |
| 115 | 110 | * @since 2.05.06 |
| 116 | - * | |
| 117 | - * @param string $value | |
| 118 | 111 | */ |
| 119 | 112 | public function get_field_option( $value ) { |
| 120 | 113 | return FrmField::get_option( $this->field, $value ); |
| 121 | 114 | } |
| @@ -121,10 +114,8 @@ | ||
| 121 | 114 | } |
| 122 | 115 | |
| 123 | 116 | /** |
| 124 | 117 | * @since 4.03 |
| 125 | - * | |
| 126 | - * @param string $option | |
| 127 | 118 | */ |
| 128 | 119 | public function get_field_attr( $option ) { |
| 129 | 120 | return is_object( $this->field ) ? $this->field->{$option} : ''; |
| 130 | 121 | } |
| @@ -130,10 +121,8 @@ | ||
| 130 | 121 | } |
| 131 | 122 | |
| 132 | 123 | /** |
| 133 | 124 | * @since 4.03 |
| 134 | - * | |
| 135 | - * @return stdClass | |
| 136 | 125 | */ |
| 137 | 126 | public function get_field() { |
| 138 | 127 | return $this->field; |
| 139 | 128 | } |
| @@ -218,10 +207,8 @@ | ||
| 218 | 207 | * |
| 219 | 208 | * @since 2.04 |
| 220 | 209 | * |
| 221 | 210 | * @param array $atts |
| 222 | - * | |
| 223 | - * @return void | |
| 224 | 211 | */ |
| 225 | 212 | protected function filter_displayed_value( $atts ) { |
| 226 | 213 | if ( ! is_object( $this->entry ) || empty( $this->entry->metas ) ) { |
| 227 | 214 | $this->entry = FrmEntry::getOne( $this->entry_id, true ); |
| @@ -229,8 +216,32 @@ | ||
| 229 | 216 | return; |
| 230 | 217 | } |
| 231 | 218 | } |
| 232 | 219 | |
| 220 | + // TODO: maybe change from 'source' to 'run_filters' = 'email' | |
| 221 | + if ( isset( $atts['source'] ) && $atts['source'] === 'entry_formatter' ) { | |
| 222 | + // Deprecated frm_email_value hook | |
| 223 | + $meta = array( | |
| 224 | + 'item_id' => $this->entry->id, | |
| 225 | + 'field_id' => $this->field->id, | |
| 226 | + 'meta_value' => $this->saved_value, | |
| 227 | + 'field_type' => $this->field->type, | |
| 228 | + ); | |
| 229 | + | |
| 230 | + if ( has_filter( 'frm_email_value' ) ) { | |
| 231 | + _deprecated_function( 'The frm_email_value filter', '2.04', 'the frm_display_{fieldtype}_value_custom filter' ); | |
| 232 | + $this->displayed_value = apply_filters( | |
| 233 | + 'frm_email_value', | |
| 234 | + $this->displayed_value, | |
| 235 | + (object) $meta, | |
| 236 | + $this->entry, | |
| 237 | + array( | |
| 238 | + 'field' => $this->field, | |
| 239 | + ) | |
| 240 | + ); | |
| 241 | + } | |
| 242 | + } | |
| 243 | + | |
| 233 | 244 | // frm_display_{fieldtype}_value_custom hook |
| 234 | 245 | $this->displayed_value = apply_filters( |
| 235 | 246 | 'frm_display_' . $this->field->type . '_value_custom', |
| 236 | 247 | $this->displayed_value, |
| @@ -243,19 +254,16 @@ | ||
| 243 | 254 | $this->displayed_value = apply_filters( 'frm_display_value', $this->displayed_value, $this->field, $atts ); |
| 244 | 255 | } |
| 245 | 256 | |
| 246 | 257 | /** |
| 247 | - * Clean a field's saved value. | |
| 258 | + * Clean a field's saved value | |
| 248 | 259 | * |
| 249 | 260 | * @since 2.04 |
| 250 | - * | |
| 251 | - * @return void | |
| 252 | 261 | */ |
| 253 | 262 | protected function clean_saved_value() { |
| 254 | 263 | if ( $this->saved_value !== '' ) { |
| 255 | 264 | if ( ! is_array( $this->saved_value ) && ! is_object( $this->saved_value ) ) { |
| 256 | - $field_type = FrmField::get_field_type( $this->field ); | |
| 257 | - FrmFieldsHelper::prepare_field_value( $this->saved_value, $field_type ); | |
| 265 | + FrmAppHelper::unserialize_or_decode( $this->saved_value ); | |
| 258 | 266 | } |
| 259 | 267 | |
| 260 | 268 | if ( is_array( $this->saved_value ) && empty( $this->saved_value ) ) { |
| 261 | 269 | $this->saved_value = ''; |