ocation_messages']; } if ( isset( $data['location_group_map'] ) ) { $data['categories'] = $data['location_group_map']; } $datas['location_messages'] = $data['message']; // Find out categories id or insert new category. if ( isset( $data['categories'] ) and ! empty( $data['categories'] ) ) { $all_cat = explode( ',', strtolower( $data['categories'] ) ); if ( is_array( $all_cat ) ) { foreach ( $all_cat as $cat ) { $cat_id = array_search( sanitize_text_field( $cat ), (array) $categories_data ); if ( false == $cat_id ) { // Create a new category. $new_cat_id = FlipperCode_Database::insert_or_update( TBL_GROUPMAP, array( 'group_map_title' => sanitize_text_field( $cat ), 'group_marker' => WPGMP_IMAGES.'default_marker.png', ) ); $category_ids[] = $new_cat_id; $categories_data[ $new_cat_id ] = sanitize_text_field( $cat ); } else { $category_ids[] = $cat_id; } } } } $datas['location_group_map'] = serialize( (array) $category_ids ); $result = FlipperCode_Database::insert_or_update( $this->table, $datas ); } } if ( false === $result ) { $response['error'] = __( 'Something went wrong. Please try again.',WPGMP_TEXT_DOMAIN ); } elseif ( $entityID > 0 ) { $response['success'] = __( 'Location updated successfully',WPGMP_TEXT_DOMAIN ); } else { $response['success'] = __( 'Location added successfully.',WPGMP_TEXT_DOMAIN ); } return $response; } return $response; } } } }