WC_Helper_Compat::migrate_connection()
Attempt to migrate a legacy connection to a new one.
Метод класса: WC_Helper_Compat{}
Хуков нет.
Возвращает
null
. Ничего (null).
Использование
$result = WC_Helper_Compat::migrate_connection();
Код WC_Helper_Compat::migrate_connection() WC Helper Compat::migrate connection WC 9.4.2
public static function migrate_connection() { // Don't attempt to migrate if attempted before. if ( WC_Helper_Options::get( 'did-migrate' ) ) { return; } $auth = WC_Helper_Options::get( 'auth' ); if ( ! empty( $auth ) ) { return; } WC_Helper::log( 'Attempting oauth/migrate' ); WC_Helper_Options::update( 'did-migrate', true ); $master_key = get_option( 'woothemes_helper_master_key' ); if ( empty( $master_key ) ) { WC_Helper::log( 'Master key not found, aborting' ); return; } $request = WC_Helper_API::post( 'oauth/migrate', array( 'body' => array( 'home_url' => home_url(), 'master_key' => $master_key, ), ) ); if ( is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) !== 200 ) { WC_Helper::log( 'Call to oauth/migrate returned a non-200 response code' ); return; } $request_token = json_decode( wp_remote_retrieve_body( $request ) ); if ( empty( $request_token ) ) { WC_Helper::log( 'Call to oauth/migrate returned an empty token' ); return; } // Obtain an access token. $request = WC_Helper_API::post( 'oauth/access_token', array( 'body' => array( 'request_token' => $request_token, 'home_url' => home_url(), 'migrate' => true, ), ) ); if ( is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) !== 200 ) { WC_Helper::log( 'Call to oauth/access_token returned a non-200 response code' ); return; } $access_token = json_decode( wp_remote_retrieve_body( $request ), true ); if ( empty( $access_token ) ) { WC_Helper::log( 'Call to oauth/access_token returned an invalid token' ); return; } WC_Helper_Options::update( 'auth', array( 'access_token' => $access_token['access_token'], 'access_token_secret' => $access_token['access_token_secret'], 'site_id' => $access_token['site_id'], 'user_id' => null, // Set this later 'updated' => time(), ) ); // Obtain the connected user info. if ( ! WC_Helper::_flush_authentication_cache() ) { WC_Helper::log( 'Could not obtain connected user info in migrate_connection' ); WC_Helper_Options::update( 'auth', array() ); return; } }