| @@ -12,8 +12,9 @@ | ||
| 12 | 12 | * @package PropertyHive/Classes |
| 13 | 13 | * @category Class |
| 14 | 14 | * @author PropertyHive |
| 15 | 15 | */ |
| 16 | +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- Legacy public global class PH_Contact; preserving the existing PH_* class name is required for plugin and extension compatibility. | |
| 16 | 17 | class PH_Contact { |
| 17 | 18 | |
| 18 | 19 | /** @public int Contact (post) ID */ |
| 19 | 20 | public $id; |
| @@ -29,8 +30,9 @@ | ||
| 29 | 30 | |
| 30 | 31 | if ( $user_id > 0 ) |
| 31 | 32 | { |
| 32 | 33 | // We've been passed a user ID. Need to get contact ID based on user_id |
| 34 | + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key, WordPress.DB.SlowDBQuery.slow_db_query_meta_value -- PH_Contact maps one WordPress user ID to one contact with fields=ids and posts_per_page=1. Both meta key and scalar value are fixed/typed; one-row result. | |
| 33 | 35 | $contact_query = new WP_Query( array( 'post_type' => 'contact', 'meta_key' => '_user_id', 'meta_value' => $user_id, 'fields' => 'ids', 'posts_per_page' => 1 ) ); |
| 34 | 36 | |
| 35 | 37 | if ( $contact_query->have_posts() ) |
| 36 | 38 | { |
| @@ -112,6 +114,74 @@ | ||
| 112 | 114 | // Standard post data |
| 113 | 115 | $this->id = $result->ID; |
| 114 | 116 | $this->post_title = $result->post_title; |
| 115 | 117 | $this->post_status = $result->post_status; |
| 118 | + } | |
| 119 | + | |
| 120 | + /** | |
| 121 | + * Get the full formatted address | |
| 122 | + * | |
| 123 | + * @access public | |
| 124 | + * @return string | |
| 125 | + */ | |
| 126 | + public function get_formatted_full_address( $separator = ', ' ) { | |
| 127 | + // Standard post data | |
| 128 | + | |
| 129 | + $return = ''; | |
| 130 | + | |
| 131 | + $company_name = $this->_company_name; | |
| 132 | + if ($company_name != '') | |
| 133 | + { | |
| 134 | + $return .= $company_name; | |
| 135 | + } | |
| 136 | + $address_name_number = $this->_address_name_number; | |
| 137 | + if ($address_name_number != '') | |
| 138 | + { | |
| 139 | + if ($return != '') { $return .= $separator; } | |
| 140 | + $return .= $address_name_number; | |
| 141 | + } | |
| 142 | + $address_street = $this->_address_street; | |
| 143 | + if ($address_street != '') | |
| 144 | + { | |
| 145 | + if ($return != '') { $return .= ' '; } | |
| 146 | + $return .= $address_street; | |
| 147 | + } | |
| 148 | + $address_two = $this->_address_two; | |
| 149 | + if ($address_two != '') | |
| 150 | + { | |
| 151 | + if ($return != '') { $return .= $separator; } | |
| 152 | + $return .= $address_two; | |
| 153 | + } | |
| 154 | + $address_three = $this->_address_three; | |
| 155 | + if ($address_three != '') | |
| 156 | + { | |
| 157 | + if ($return != '') { $return .= $separator; } | |
| 158 | + $return .= $address_three; | |
| 159 | + } | |
| 160 | + $address_four = $this->_address_four; | |
| 161 | + if ($address_four != '') | |
| 162 | + { | |
| 163 | + if ($return != '') { $return .= $separator; } | |
| 164 | + $return .= $address_four; | |
| 165 | + } | |
| 166 | + $address_postcode = $this->_address_postcode; | |
| 167 | + if ($address_postcode != '') | |
| 168 | + { | |
| 169 | + if ($return != '') { $return .= $separator; } | |
| 170 | + $return .= $address_postcode; | |
| 171 | + } | |
| 172 | + | |
| 173 | + return $return; | |
| 174 | + } | |
| 175 | + | |
| 176 | + /** | |
| 177 | + * Get the dear field if populated, fallback to the full name if not | |
| 178 | + * | |
| 179 | + * @access public | |
| 180 | + * @return string | |
| 181 | + */ | |
| 182 | + public function dear() | |
| 183 | + { | |
| 184 | + $dear = $this->_dear; | |
| 185 | + return !empty($dear) ? $dear : $this->post_title; | |
| 116 | 186 | } |
| 117 | 187 | } |