bmitted_data ) { $options = array( array( 'name' => 'hustle_is_submit', 'type' => 'hidden', 'value' => '1', ), ); if ( $this->is_allow_multi_on_form() ) { $options[] = array( 'name' => 'multi_id', 'type' => 'hidden', 'value' => isset( $submitted_data['multi_id'] ) ? $submitted_data['multi_id'] : $this->generate_multi_id(), ); } if ( $this->is_allow_multi_on_global() ) { $options[] = array( 'name' => 'global_multi_id', 'type' => 'hidden', 'value' => isset( $submitted_data['global_multi_id'] ) ? $submitted_data['global_multi_id'] : $this->generate_multi_id(), ); } $html = Hustle_Provider_Utils::get_html_for_options( $options ); $html = apply_filters( 'hustle_providers_admin_add_common_hidden_fields', $html ); return $html; } /** * In version 3.0 provider details like API key and URL were stored at module level, * now they are stored globally to avoid duplication. * * This method addresses this difference. * * @param Hustle_Module_Model $module Current module. * @param Object $old_module Old module. * * @return bool */ public function migrate_30( $module, $old_module ) { $v3_provider = ! empty( $old_module->meta['content']['email_services'][ $this->get_slug() ] ) ? $old_module->meta['content']['email_services'][ $this->get_slug() ] : false; if ( empty( $v3_provider ) || $this->get_30_provider_mappings() === false ) { // Nothing to migrate. return false; } $v3_provider_active = '1' === $v3_provider['enabled']; // If the provider doesn't already exist globally, add it. $global_multi_id = $this->get_30_migrated_provider( $v3_provider ); if ( empty( $global_multi_id ) ) { $global_multi_id = $this->generate_multi_id(); $this->save_multi_settings_values( $global_multi_id, $this->map_30_provider( $v3_provider ) ); // Activate the addon. Hustle_Providers::get_instance()->activate_addon( $this->get_slug() ); } // Link the provider to the module. if ( $v3_provider_active ) { $module_provider_link = $this->strip_30_global_provider_settings( $v3_provider ); $module_provider_link['selected_global_multi_id'] = $global_multi_id; $module->set_provider_settings( $this->get_slug(), $module_provider_link ); } return true; } /** * Map the provider's field from the old settings to the new ones. * * @since 4.0.0 * @param array $v3_provider Old settings of the provider. */ private function map_30_provider( $v3_provider ) { $v4_provider = array(); $mappings = $this->get_30_provider_mappings(); foreach ( $mappings as $v3_index => $v4_index ) { if ( isset( $v3_provider[ $v3_index ] ) ) { $v4_provider[ $v4_index ] = $v3_provider[ $v3_index ]; } } return $v4_provider; } /** * Gets the provider's map for the 3.x to 4.x migration. * * @since 4.0.0 * @return false|array */ protected function get_30_provider_mappings() { return false; } /** * If a provider has already been migrated from 3.0 this method will return its id. * * @param array $v3_provider Old settings of the provider. * * @return bool|string Global multi ID */ private function get_30_migrated_provider( $v3_provider ) { $v40_providers = $this->get_settings_values(); $mapped_40_provider = $this->map_30_provider( $v3_provider ); foreach ( $v40_providers as $global_multi_id => $v40_provider ) { if ( $v40_provider === $mapped_40_provider ) { return $global_multi_id; } } return false; } /** * Strips unused old settings for the provider. * * @since 4.0.0 * * @param array $v3_provider Old provider's settings. * @return array */ private function strip_30_global_provider_settings( $v3_provider ) { $copy = array(); $global_provider_settings = array_merge( array( 'enabled', 'optin_provider_name', 'desc' ), array_keys( $this->get_30_provider_mappings() ) ); foreach ( $v3_provider as $item => $value ) { if ( in_array( $item, $global_provider_settings, true ) ) { continue; } $copy[ $item ] = $value; } return $copy; } /** * If a provider fails to connect, * returns a generic message. * * @since 4.0.0 * * @return string error message */ protected function provider_connection_falied() { /* translators: provider's title */ $error_message = sprintf( __( "We couldn't connect to your %s account. Please resolve the errors below and try again.", 'hustle' ), $this->title ); return $error_message; } }