| @@ -33,9 +33,9 @@ | ||
| 33 | 33 | * @static |
| 34 | 34 | * @return MainWP_Client_Handler |
| 35 | 35 | */ |
| 36 | 36 | public static function instance() { |
| 37 | - if ( null === self::$instance ) { | |
| 37 | + if ( null == self::$instance ) { | |
| 38 | 38 | self::$instance = new self(); |
| 39 | 39 | } |
| 40 | 40 | return self::$instance; |
| 41 | 41 | } |
| @@ -49,118 +49,86 @@ | ||
| 49 | 49 | public static function get_default_client_fields() { |
| 50 | 50 | |
| 51 | 51 | return array( |
| 52 | 52 | 'client.name' => array( |
| 53 | - 'title' => esc_html__( 'Client Name (Required)', 'mainwp' ), | |
| 54 | - 'desc' => esc_html__( 'Displays the Client name', 'mainwp' ), | |
| 53 | + 'title' => __( 'Client Name', 'mainwp' ), | |
| 54 | + 'desc' => __( 'Displays the Client name', 'mainwp' ), | |
| 55 | 55 | 'db_field' => 'name', |
| 56 | 56 | ), |
| 57 | 57 | 'client.email' => array( |
| 58 | - 'title' => esc_html__( 'Client email', 'mainwp' ), | |
| 59 | - 'desc' => esc_html__( 'Displays the client email', 'mainwp' ), | |
| 58 | + 'title' => __( 'Client contact email', 'mainwp' ), | |
| 59 | + 'desc' => __( 'Displays the client email', 'mainwp' ), | |
| 60 | 60 | 'db_field' => 'client_email', |
| 61 | 61 | ), |
| 62 | 62 | 'client.phone' => array( |
| 63 | - 'title' => esc_html__( 'Client phone', 'mainwp' ), | |
| 64 | - 'desc' => esc_html__( 'Displays the client phone', 'mainwp' ), | |
| 63 | + 'title' => __( 'Client contact phone', 'mainwp' ), | |
| 64 | + 'desc' => __( 'Displays the client phone', 'mainwp' ), | |
| 65 | 65 | 'db_field' => 'client_phone', |
| 66 | 66 | ), |
| 67 | 67 | 'client.facebook' => array( |
| 68 | - 'title' => esc_html__( 'Client Facebook', 'mainwp' ), | |
| 69 | - 'desc' => esc_html__( 'Displays the client Facebook', 'mainwp' ), | |
| 68 | + 'title' => __( 'Client Facebook', 'mainwp' ), | |
| 69 | + 'desc' => __( 'Displays the client Facebook', 'mainwp' ), | |
| 70 | 70 | 'db_field' => 'client_facebook', |
| 71 | 71 | ), |
| 72 | 72 | 'client.twitter' => array( |
| 73 | - 'title' => esc_html__( 'Client Twitter', 'mainwp' ), | |
| 74 | - 'desc' => esc_html__( 'Displays the client Twitter', 'mainwp' ), | |
| 73 | + 'title' => __( 'Client Twitter', 'mainwp' ), | |
| 74 | + 'desc' => __( 'Displays the client Twitter', 'mainwp' ), | |
| 75 | 75 | 'db_field' => 'client_twitter', |
| 76 | 76 | ), |
| 77 | 77 | 'client.instagram' => array( |
| 78 | - 'title' => esc_html__( 'Client Instagram', 'mainwp' ), | |
| 79 | - 'desc' => esc_html__( 'Displays the client Instagram', 'mainwp' ), | |
| 78 | + 'title' => __( 'Client Instagram', 'mainwp' ), | |
| 79 | + 'desc' => __( 'Displays the client Instagram', 'mainwp' ), | |
| 80 | 80 | 'db_field' => 'client_instagram', |
| 81 | 81 | ), |
| 82 | 82 | 'client.linkedin' => array( |
| 83 | - 'title' => esc_html__( 'Client LinkedIn', 'mainwp' ), | |
| 84 | - 'desc' => esc_html__( 'Displays the client LinkedIn', 'mainwp' ), | |
| 83 | + 'title' => __( 'Client LinkedIn', 'mainwp' ), | |
| 84 | + 'desc' => __( 'Displays the client LinkedIn', 'mainwp' ), | |
| 85 | 85 | 'db_field' => 'client_linkedin', |
| 86 | 86 | ), |
| 87 | 87 | 'client.contact.address.1' => array( |
| 88 | - 'title' => esc_html__( 'Client address 1', 'mainwp' ), | |
| 89 | - 'desc' => esc_html__( 'Displays the client contact address 1', 'mainwp' ), | |
| 88 | + 'title' => __( 'Client address 1', 'mainwp' ), | |
| 89 | + 'desc' => __( 'Displays the client contact address 1', 'mainwp' ), | |
| 90 | 90 | 'db_field' => 'address_1', |
| 91 | 91 | ), |
| 92 | 92 | 'client.contact.address.2' => array( |
| 93 | - 'title' => esc_html__( 'Client address 2', 'mainwp' ), | |
| 94 | - 'desc' => esc_html__( 'Displays the client contact address 2', 'mainwp' ), | |
| 93 | + 'title' => __( 'Client address 2', 'mainwp' ), | |
| 94 | + 'desc' => __( 'Displays the client contact address 2', 'mainwp' ), | |
| 95 | 95 | 'db_field' => 'address_2', |
| 96 | 96 | ), |
| 97 | 97 | 'client.city' => array( |
| 98 | - 'title' => esc_html__( 'Client city', 'mainwp' ), | |
| 99 | - 'desc' => esc_html__( 'Displays the client city', 'mainwp' ), | |
| 98 | + 'title' => __( 'Client city', 'mainwp' ), | |
| 99 | + 'desc' => __( 'Displays the client city', 'mainwp' ), | |
| 100 | 100 | 'db_field' => 'city', |
| 101 | 101 | ), |
| 102 | 102 | 'client.state' => array( |
| 103 | - 'title' => esc_html__( 'Client state', 'mainwp' ), | |
| 104 | - 'desc' => esc_html__( 'Displays the client state', 'mainwp' ), | |
| 103 | + 'title' => __( 'Client state', 'mainwp' ), | |
| 104 | + 'desc' => __( 'Displays the client state', 'mainwp' ), | |
| 105 | 105 | 'db_field' => 'state', |
| 106 | 106 | ), |
| 107 | 107 | 'client.zip' => array( |
| 108 | - 'title' => esc_html__( 'Client ZIP', 'mainwp' ), | |
| 109 | - 'desc' => esc_html__( 'Displays the client ZIP code', 'mainwp' ), | |
| 108 | + 'title' => __( 'Client ZIP', 'mainwp' ), | |
| 109 | + 'desc' => __( 'Displays the client ZIP code', 'mainwp' ), | |
| 110 | 110 | 'db_field' => 'zip', |
| 111 | 111 | ), |
| 112 | 112 | 'client.country' => array( |
| 113 | - 'title' => esc_html__( 'Client country', 'mainwp' ), | |
| 114 | - 'desc' => esc_html__( 'Displays the client country', 'mainwp' ), | |
| 113 | + 'title' => __( 'Client country', 'mainwp' ), | |
| 114 | + 'desc' => __( 'Displays the client country', 'mainwp' ), | |
| 115 | 115 | 'db_field' => 'country', |
| 116 | 116 | ), |
| 117 | 117 | 'client.note' => array( |
| 118 | - 'title' => esc_html__( 'Client notes', 'mainwp' ), | |
| 119 | - 'desc' => esc_html__( 'Displays the client note', 'mainwp' ), | |
| 118 | + 'title' => __( 'Client notes', 'mainwp' ), | |
| 119 | + 'desc' => __( 'Displays the client note', 'mainwp' ), | |
| 120 | 120 | 'db_field' => 'note', |
| 121 | 121 | ), |
| 122 | 122 | 'client.suspended' => array( |
| 123 | - 'title' => esc_html__( 'Client status', 'mainwp' ), | |
| 124 | - 'desc' => esc_html__( 'Displays the client suspended state', 'mainwp' ), | |
| 123 | + 'title' => __( 'Client status', 'mainwp' ), | |
| 124 | + 'desc' => __( 'Displays the client suspended state', 'mainwp' ), | |
| 125 | 125 | 'db_field' => 'suspended', |
| 126 | 126 | ), |
| 127 | - 'client.created' => array( | |
| 128 | - 'title' => esc_html__( 'Added on', 'mainwp' ), | |
| 129 | - 'desc' => esc_html__( 'Displays the client added on', 'mainwp' ), | |
| 130 | - 'tooltip' => esc_html__( 'Set the date your client was added to your MainWP Dashboard.', 'mainwp' ), | |
| 131 | - 'db_field' => 'created', | |
| 132 | - ), | |
| 133 | 127 | ); |
| 134 | 128 | } |
| 135 | 129 | |
| 136 | - /** | |
| 137 | - * Get default client fields. | |
| 138 | - * | |
| 139 | - * Get default client fields. | |
| 140 | - */ | |
| 141 | - public static function get_mini_default_client_fields() { | |
| 142 | 130 | |
| 143 | - return array( | |
| 144 | - 'client.name' => array( | |
| 145 | - 'title' => esc_html__( 'Client Name (Required)', 'mainwp' ), | |
| 146 | - 'desc' => esc_html__( 'Displays the Client name', 'mainwp' ), | |
| 147 | - 'db_field' => 'name', | |
| 148 | - ), | |
| 149 | - 'client.email' => array( | |
| 150 | - 'title' => esc_html__( 'Client email', 'mainwp' ), | |
| 151 | - 'desc' => esc_html__( 'Displays the client email', 'mainwp' ), | |
| 152 | - 'db_field' => 'client_email', | |
| 153 | - ), | |
| 154 | - 'client.phone' => array( | |
| 155 | - 'title' => esc_html__( 'Client phone', 'mainwp' ), | |
| 156 | - 'desc' => esc_html__( 'Displays the client phone', 'mainwp' ), | |
| 157 | - 'db_field' => 'client_phone', | |
| 158 | - ), | |
| 159 | - ); | |
| 160 | - } | |
| 161 | - | |
| 162 | - | |
| 163 | 131 | /** |
| 164 | 132 | * Get default contact fields. |
| 165 | 133 | * |
| 166 | 134 | * Get default contact fields. |
| @@ -167,76 +135,51 @@ | ||
| 167 | 135 | */ |
| 168 | 136 | public static function get_default_contact_fields() { |
| 169 | 137 | return array( |
| 170 | 138 | 'client.contact.name' => array( |
| 171 | - 'title' => esc_html__( 'Contact name (Required)', 'mainwp' ), | |
| 172 | - 'desc' => esc_html__( 'Displays the client contact name', 'mainwp' ), | |
| 139 | + 'title' => __( 'Client contact name', 'mainwp' ), | |
| 140 | + 'desc' => __( 'Displays the client contact name', 'mainwp' ), | |
| 173 | 141 | 'db_field' => 'contact_name', |
| 174 | 142 | ), |
| 175 | 143 | 'contact.role' => array( |
| 176 | - 'title' => esc_html__( 'Contact role', 'mainwp' ), | |
| 177 | - 'desc' => esc_html__( 'Displays the contact role', 'mainwp' ), | |
| 144 | + 'title' => __( 'Contact contact role', 'mainwp' ), | |
| 145 | + 'desc' => __( 'Displays the contact role', 'mainwp' ), | |
| 178 | 146 | 'db_field' => 'contact_role', |
| 179 | 147 | ), |
| 180 | 148 | 'contact.email' => array( |
| 181 | - 'title' => esc_html__( 'Contact email (Required)', 'mainwp' ), | |
| 182 | - 'desc' => esc_html__( 'Displays the contact email', 'mainwp' ), | |
| 149 | + 'title' => __( 'Contact contact email', 'mainwp' ), | |
| 150 | + 'desc' => __( 'Displays the contact email', 'mainwp' ), | |
| 183 | 151 | 'db_field' => 'contact_email', |
| 184 | 152 | ), |
| 185 | 153 | 'contact.phone' => array( |
| 186 | - 'title' => esc_html__( 'Contact phone', 'mainwp' ), | |
| 187 | - 'desc' => esc_html__( 'Displays the contact phone', 'mainwp' ), | |
| 154 | + 'title' => __( 'Contact contact phone', 'mainwp' ), | |
| 155 | + 'desc' => __( 'Displays the contact phone', 'mainwp' ), | |
| 188 | 156 | 'db_field' => 'contact_phone', |
| 189 | 157 | ), |
| 190 | 158 | 'contact.facebook' => array( |
| 191 | - 'title' => esc_html__( 'Contact Facebook', 'mainwp' ), | |
| 192 | - 'desc' => esc_html__( 'Displays the contact Facebook', 'mainwp' ), | |
| 159 | + 'title' => __( 'Contact Facebook', 'mainwp' ), | |
| 160 | + 'desc' => __( 'Displays the contact Facebook', 'mainwp' ), | |
| 193 | 161 | 'db_field' => 'facebook', |
| 194 | 162 | ), |
| 195 | 163 | 'contact.twitter' => array( |
| 196 | - 'title' => esc_html__( 'Contact Twitter', 'mainwp' ), | |
| 197 | - 'desc' => esc_html__( 'Displays the contact Twitter', 'mainwp' ), | |
| 164 | + 'title' => __( 'Contact Twitter', 'mainwp' ), | |
| 165 | + 'desc' => __( 'Displays the contact Twitter', 'mainwp' ), | |
| 198 | 166 | 'db_field' => 'twitter', |
| 199 | 167 | ), |
| 200 | 168 | 'contact.instagram' => array( |
| 201 | - 'title' => esc_html__( 'Contact Instagram', 'mainwp' ), | |
| 202 | - 'desc' => esc_html__( 'Displays the contact Instagram', 'mainwp' ), | |
| 169 | + 'title' => __( 'Contact Instagram', 'mainwp' ), | |
| 170 | + 'desc' => __( 'Displays the contact Instagram', 'mainwp' ), | |
| 203 | 171 | 'db_field' => 'instagram', |
| 204 | 172 | ), |
| 205 | 173 | 'contact.linkedin' => array( |
| 206 | - 'title' => esc_html__( 'Contact LinkedIn', 'mainwp' ), | |
| 207 | - 'desc' => esc_html__( 'Displays the contact LinkedIn', 'mainwp' ), | |
| 174 | + 'title' => __( 'Contact LinkedIn', 'mainwp' ), | |
| 175 | + 'desc' => __( 'Displays the contact LinkedIn', 'mainwp' ), | |
| 208 | 176 | 'db_field' => 'linkedin', |
| 209 | 177 | ), |
| 210 | 178 | ); |
| 211 | 179 | } |
| 212 | 180 | |
| 213 | - /** | |
| 214 | - * Get default contact fields. | |
| 215 | - * | |
| 216 | - * Get default contact fields. | |
| 217 | - */ | |
| 218 | - public static function get_mini_default_contact_fields() { | |
| 219 | - return array( | |
| 220 | - 'client.contact.name' => array( | |
| 221 | - 'title' => esc_html__( 'Contact name (Required)', 'mainwp' ), | |
| 222 | - 'desc' => esc_html__( 'Displays the client contact name', 'mainwp' ), | |
| 223 | - 'db_field' => 'contact_name', | |
| 224 | - ), | |
| 225 | - 'contact.role' => array( | |
| 226 | - 'title' => esc_html__( 'Contact role', 'mainwp' ), | |
| 227 | - 'desc' => esc_html__( 'Displays the contact role', 'mainwp' ), | |
| 228 | - 'db_field' => 'contact_role', | |
| 229 | - ), | |
| 230 | - 'contact.email' => array( | |
| 231 | - 'title' => esc_html__( 'Contact email (Required)', 'mainwp' ), | |
| 232 | - 'desc' => esc_html__( 'Displays the contact email', 'mainwp' ), | |
| 233 | - 'db_field' => 'contact_email', | |
| 234 | - ), | |
| 235 | - ); | |
| 236 | - } | |
| 237 | 181 | |
| 238 | - | |
| 239 | 182 | /** |
| 240 | 183 | * Method get_compatible_tokens(). |
| 241 | 184 | * |
| 242 | 185 | * Get compatible tokens. |
| @@ -256,14 +199,13 @@ | ||
| 256 | 199 | * @param array $data fields array. |
| 257 | 200 | * @param bool $edit Is edit. |
| 258 | 201 | * |
| 259 | 202 | * $data fields. |
| 260 | - * 'client_email'. | |
| 203 | + * 'email'. | |
| 261 | 204 | * 'name'. |
| 262 | - * 'client_facebook'. | |
| 263 | - * 'client_twitter'. | |
| 264 | - * 'client_instagram'. | |
| 265 | - * 'client_linkedin'. | |
| 205 | + * 'facebook'. | |
| 206 | + * 'twitter'. | |
| 207 | + * 'instagram'. | |
| 266 | 208 | * 'address_1'. |
| 267 | 209 | * 'address_2'. |
| 268 | 210 | * 'city'. |
| 269 | 211 | * 'zip'. |
| @@ -271,12 +213,11 @@ | ||
| 271 | 213 | * 'note'. |
| 272 | 214 | * 'selected_sites'. |
| 273 | 215 | * 'client_id'. - to edit client. |
| 274 | 216 | * |
| 275 | - * @throws \Exception Error message. | |
| 276 | 217 | * @return mixed Results. |
| 277 | 218 | */ |
| 278 | - public static function rest_api_add_client( $data, $edit = false ) { // phpcs:ignore -- complex function. Current complexity is the only way to achieve desired results, pull request solutions appreciated. | |
| 219 | + public static function rest_api_add_client( $data, $edit = false ) { // phpcs:ignore -- comlex function. Current complexity is the only way to achieve desired results, pull request solutions appreciated. | |
| 279 | 220 | |
| 280 | 221 | $params = array(); |
| 281 | 222 | |
| 282 | 223 | if ( $edit ) { |
| @@ -284,9 +225,9 @@ | ||
| 284 | 225 | $client_id = isset( $data['client_id'] ) ? intval( $data['client_id'] ) : 0; |
| 285 | 226 | |
| 286 | 227 | if ( empty( $client_id ) ) { // edit client. |
| 287 | 228 | return array( |
| 288 | - 'error' => esc_html__( 'Client ID field is required! Please enter a Client ID.', 'mainwp' ), | |
| 229 | + 'error' => __( 'Client ID field is required! Please enter a Client ID.', 'mainwp' ), | |
| 289 | 230 | ); |
| 290 | 231 | } |
| 291 | 232 | |
| 292 | 233 | $params['client_id'] = $client_id; |
| @@ -318,42 +259,10 @@ | ||
| 318 | 259 | if ( isset( $data['note'] ) ) { |
| 319 | 260 | $params['note'] = sanitize_text_field( wp_unslash( $data['note'] ) ); |
| 320 | 261 | } |
| 321 | 262 | |
| 322 | - if ( isset( $data['client_email'] ) ) { | |
| 323 | - $params['client_email'] = sanitize_text_field( wp_unslash( $data['client_email'] ) ); | |
| 324 | - } | |
| 263 | + MainWP_DB_Client::instance()->update_client( $params ); | |
| 325 | 264 | |
| 326 | - if ( isset( $data['client_phone'] ) ) { | |
| 327 | - $params['client_phone'] = sanitize_text_field( wp_unslash( $data['client_phone'] ) ); | |
| 328 | - } | |
| 329 | - | |
| 330 | - if ( isset( $data['client_facebook'] ) ) { | |
| 331 | - $params['client_facebook'] = sanitize_text_field( wp_unslash( $data['client_facebook'] ) ); | |
| 332 | - } | |
| 333 | - | |
| 334 | - if ( isset( $data['client_twitter'] ) ) { | |
| 335 | - $params['client_twitter'] = sanitize_text_field( wp_unslash( $data['client_twitter'] ) ); | |
| 336 | - } | |
| 337 | - | |
| 338 | - if ( isset( $data['client_instagram'] ) ) { | |
| 339 | - $params['client_instagram'] = sanitize_text_field( wp_unslash( $data['client_instagram'] ) ); | |
| 340 | - } | |
| 341 | - | |
| 342 | - if ( isset( $data['client_linkedin'] ) ) { | |
| 343 | - $params['client_linkedin'] = sanitize_text_field( wp_unslash( $data['client_linkedin'] ) ); | |
| 344 | - } | |
| 345 | - | |
| 346 | - if ( isset( $data['created'] ) && is_numeric( $data['created'] ) ) { | |
| 347 | - $params['created'] = intval( $data['created'] ); | |
| 348 | - } | |
| 349 | - | |
| 350 | - try { | |
| 351 | - MainWP_DB_Client::instance()->update_client( $params, true ); | |
| 352 | - } catch ( \Exception $e ) { | |
| 353 | - throw $e; | |
| 354 | - } | |
| 355 | - | |
| 356 | 265 | if ( isset( $data['selected_sites'] ) && is_array( $data['selected_sites'] ) ) { |
| 357 | 266 | $selected_sites = array_map( 'sanitize_text_field', wp_unslash( $data['selected_sites'] ) ); |
| 358 | 267 | MainWP_DB_Client::instance()->update_selected_sites_for_client( $client_id, $selected_sites ); |
| 359 | 268 | } |
| @@ -358,13 +267,14 @@ | ||
| 358 | 267 | MainWP_DB_Client::instance()->update_selected_sites_for_client( $client_id, $selected_sites ); |
| 359 | 268 | } |
| 360 | 269 | |
| 361 | 270 | if ( isset( $data['custom_fields'] ) && is_array( $data['custom_fields'] ) ) { |
| 362 | - $custom_fields = wp_unslash( $data['custom_fields'] ); | |
| 271 | + $custom_fields = array_map( 'sanitize_text_field', wp_unslash( $data['custom_fields'] ) ); | |
| 363 | 272 | foreach ( $custom_fields as $field ) { |
| 364 | - $fie_name = isset( $field['field_name'] ) ? sanitize_text_field( wp_unslash( $field['field_name'] ) ) : ''; | |
| 365 | - $fie_value = isset( $field['field_value'] ) ? sanitize_text_field( wp_unslash( $field['field_value'] ) ) : ''; | |
| 366 | - $fie_desc = isset( $field['field_desc'] ) ? sanitize_text_field( wp_unslash( $field['field_desc'] ) ) : ''; | |
| 273 | + $fie_name = isset( $field['field_name'] ) ? sanitize_text_field( wp_unslash( $data['field_name'] ) ) : ''; | |
| 274 | + $fie_value = isset( $field['field_value'] ) ? sanitize_text_field( wp_unslash( $data['field_value'] ) ) : ''; | |
| 275 | + $fie_desc = isset( $field['field_desc'] ) ? sanitize_text_field( wp_unslash( $data['field_desc'] ) ) : ''; | |
| 276 | + | |
| 367 | 277 | if ( ! empty( $fie_name ) && ! empty( $fie_value ) ) { |
| 368 | 278 | $get_gen_field = MainWP_DB_Client::instance()->get_client_fields_by( 'field_name', $fie_name, 0 ); |
| 369 | 279 | if ( $get_gen_field ) { // it is general field. |
| 370 | 280 | if ( ! empty( $fie_desc ) ) { |
| @@ -406,31 +316,25 @@ | ||
| 406 | 316 | $params['name'] = isset( $data['name'] ) ? sanitize_text_field( wp_unslash( $data['name'] ) ) : ''; |
| 407 | 317 | |
| 408 | 318 | if ( empty( $params['name'] ) ) { |
| 409 | 319 | return array( |
| 410 | - 'error' => esc_html__( 'Client name field is required! Please enter a Client name.', 'mainwp' ), | |
| 320 | + 'error' => __( 'Client name field is required! Please enter a Client name.', 'mainwp' ), | |
| 411 | 321 | ); |
| 412 | 322 | } |
| 413 | 323 | |
| 414 | - $params['address_1'] = isset( $data['address_1'] ) ? sanitize_text_field( wp_unslash( $data['address_1'] ) ) : ''; | |
| 415 | - $params['address_2'] = isset( $data['address_2'] ) ? sanitize_text_field( wp_unslash( $data['address_2'] ) ) : ''; | |
| 416 | - $params['city'] = isset( $data['city'] ) ? sanitize_text_field( wp_unslash( $data['city'] ) ) : ''; | |
| 417 | - $params['zip'] = isset( $data['zip'] ) ? sanitize_text_field( wp_unslash( $data['zip'] ) ) : ''; | |
| 418 | - $params['state'] = isset( $data['state'] ) ? sanitize_text_field( wp_unslash( $data['state'] ) ) : ''; | |
| 419 | - $params['country'] = isset( $data['country'] ) ? sanitize_text_field( wp_unslash( $data['country'] ) ) : ''; | |
| 420 | - $params['note'] = isset( $data['note'] ) ? sanitize_text_field( wp_unslash( $data['note'] ) ) : ''; | |
| 421 | - $params['client_email'] = isset( $data['client_email'] ) ? sanitize_text_field( wp_unslash( $data['client_email'] ) ) : ''; | |
| 422 | - $params['client_phone'] = isset( $data['client_phone'] ) ? sanitize_text_field( wp_unslash( $data['client_phone'] ) ) : ''; | |
| 423 | - $params['client_facebook'] = isset( $data['client_facebook'] ) ? sanitize_text_field( wp_unslash( $data['client_facebook'] ) ) : ''; | |
| 424 | - $params['client_twitter'] = isset( $data['client_twitter'] ) ? sanitize_text_field( wp_unslash( $data['client_twitter'] ) ) : ''; | |
| 425 | - $params['client_instagram'] = isset( $data['client_instagram'] ) ? sanitize_text_field( wp_unslash( $data['client_instagram'] ) ) : ''; | |
| 426 | - $params['client_linkedin'] = isset( $data['client_linkedin'] ) ? sanitize_text_field( wp_unslash( $data['client_linkedin'] ) ) : ''; | |
| 324 | + $params['address_1'] = isset( $data['address_1'] ) ? sanitize_text_field( wp_unslash( $data['address_1'] ) ) : ''; | |
| 325 | + $params['address_2'] = isset( $data['address_2'] ) ? sanitize_text_field( wp_unslash( $data['address_2'] ) ) : ''; | |
| 326 | + $params['city'] = isset( $data['city'] ) ? sanitize_text_field( wp_unslash( $data['city'] ) ) : ''; | |
| 327 | + $params['zip'] = isset( $data['zip'] ) ? sanitize_text_field( wp_unslash( $data['zip'] ) ) : ''; | |
| 328 | + $params['state'] = isset( $data['state'] ) ? sanitize_text_field( wp_unslash( $data['state'] ) ) : ''; | |
| 329 | + $params['country'] = isset( $data['country'] ) ? sanitize_text_field( wp_unslash( $data['country'] ) ) : ''; | |
| 330 | + $params['note'] = isset( $data['note'] ) ? sanitize_text_field( wp_unslash( $data['note'] ) ) : ''; | |
| 427 | 331 | |
| 428 | 332 | $inserted = MainWP_DB_Client::instance()->update_client( $params ); |
| 429 | 333 | |
| 430 | 334 | if ( empty( $inserted ) ) { |
| 431 | 335 | return array( |
| 432 | - 'error' => esc_html__( 'Undefined error. Please try again.', 'mainwp' ), | |
| 336 | + 'error' => __( 'Undefined error. Please try again.', 'mainwp' ), | |
| 433 | 337 | ); |
| 434 | 338 | } |
| 435 | 339 | |
| 436 | 340 | $selected_sites = ( isset( $data['selected_sites'] ) && is_array( $data['selected_sites'] ) ) ? array_map( 'sanitize_text_field', wp_unslash( $data['selected_sites'] ) ) : array(); |
| @@ -453,9 +357,9 @@ | ||
| 453 | 357 | * @param int $websiteid Website ID. |
| 454 | 358 | * |
| 455 | 359 | * @return mixed $result Result of tokens. |
| 456 | 360 | */ |
| 457 | - public function get_website_client_tokens_data( $websiteid = false ) { // phpcs:ignore -- complex function. Current complexity is the only way to achieve desired results, pull request solutions appreciated. | |
| 361 | + public function get_website_client_tokens_data( $websiteid = false ) { // phpcs:ignore -- comlex function. Current complexity is the only way to achieve desired results, pull request solutions appreciated. | |
| 458 | 362 | if ( empty( $websiteid ) ) { |
| 459 | 363 | return false; |
| 460 | 364 | } |
| 461 | 365 | $website = MainWP_DB::instance()->get_website_by_id( $websiteid ); |
| @@ -514,9 +418,9 @@ | ||
| 514 | 418 | |
| 515 | 419 | if ( ! empty( $contact_fields ) && is_array( $contact_fields ) ) { |
| 516 | 420 | foreach ( $contact_fields as $tok_name => $field ) { |
| 517 | 421 | $db_field = isset( $field['db_field'] ) ? $field['db_field'] : ''; |
| 518 | - $val = '' !== $db_field && property_exists( $client_info, $db_field ) ? $client_info->{$db_field} : false; | |
| 422 | + $val = '' != $db_field && property_exists( $client_info, $db_field ) ? $client_info->{$db_field} : false; | |
| 519 | 423 | if ( false !== $val ) { |
| 520 | 424 | $client_tokens[ $tok_name ] = $val; |
| 521 | 425 | } |
| 522 | 426 | } |
| @@ -536,34 +440,14 @@ | ||
| 536 | 440 | */ |
| 537 | 441 | public static function get_client_image_url( $image_path ) { |
| 538 | 442 | $full_url = ''; |
| 539 | 443 | if ( ! empty( $image_path ) ) { |
| 540 | - if ( false !== stripos( $image_path, 'assets/images/demo/clients/' ) || false !== stripos( $image_path, 'assets/images/demo/contacts/' ) ) { | |
| 541 | - $full_url = MAINWP_PLUGIN_URL . $image_path; | |
| 444 | + $dirs = MainWP_System_Utility::get_mainwp_dir( 'client-images', true ); | |
| 445 | + if ( file_exists( $dirs[0] . $image_path ) ) { | |
| 446 | + $full_url = $dirs[1] . $image_path; | |
| 542 | 447 | } else { |
| 543 | - $dirs = MainWP_System_Utility::get_mainwp_dir( 'client-images', true ); | |
| 544 | - if ( file_exists( $dirs[0] . $image_path ) ) { | |
| 545 | - $full_url = $dirs[1] . $image_path; | |
| 546 | - } else { | |
| 547 | - $full_url = ''; | |
| 548 | - } | |
| 448 | + $full_url = ''; | |
| 549 | 449 | } |
| 550 | 450 | } |
| 551 | 451 | return $full_url; |
| 552 | - } | |
| 553 | - | |
| 554 | - /** | |
| 555 | - * Method show_notice_existed_contact_emails() | |
| 556 | - */ | |
| 557 | - public static function show_notice_existed_contact_emails() { | |
| 558 | - $existed_emails = MainWP_Utility::get_flash_message( 'contact_existed_emails' ); | |
| 559 | - if ( ! empty( $existed_emails ) ) { | |
| 560 | - $existed_emails = esc_html( $existed_emails ); | |
| 561 | - $existed_emails = str_replace( '|', '<br/>', $existed_emails ); | |
| 562 | - ?> | |
| 563 | - <div class="ui yellow message"> | |
| 564 | - <?php printf( esc_html__( 'Existed contact emails.%sPlease try again.', 'mainwp' ), '<br/>' . $existed_emails . '</br>' ); // phpcs:ignore WordPress.Security.EscapeOutput ?> | |
| 565 | - </div> | |
| 566 | - <?php | |
| 567 | - } | |
| 568 | 452 | } |
| 569 | 453 | } |