field = strval( $this->setting[0] ?? '' ); $this->pre = strval( $this->setting[3] ?? '' ); $this->post = strval( $this->setting[4] ?? '' ); $this->default = strval( $this->setting[5] ?? '' ); } public function content() : string { if ( ! is_user_logged_in() ) { return ''; } $current_user = wp_get_current_user(); switch ( $this->field ) { case 'id': $this->content = (string) $current_user->ID; break; case 'display-name': $this->content = $current_user->display_name; break; case 'username': $this->content = $current_user->user_login; break; case 'first-name': $this->content = $current_user->first_name; break; case 'last-name': $this->content = $current_user->last_name; break; case 'bio': $this->content = $current_user->description; break; case 'email': $this->content = $current_user->user_email; break; case 'website': $this->content = $current_user->user_url; break; case 'user-meta': $meta_key = $this->setting[1] ?? ''; $meta_data = $this->is_allowed_meta_key( $meta_key, 'user' ) ? get_user_meta( $current_user->ID, $meta_key, true ) : ''; $this->content = is_scalar( $meta_data ) ? (string) $meta_data : ''; break; }//end switch // Profile fields and user meta are written by the user, not the site. if ( $this->content === '' ) { $value = $this->esc_label( $this->default ); } elseif ( 'bio' === $this->field ) { // The bio is allowed formatting; it is filtered, not flattened. $value = $this->esc_label( $this->content ); } else { $value = $this->esc_value( $this->content ); } return $this->esc_label( $this->pre ) . $value . $this->esc_label( $this->post ); } }