migrate_spanish_users()
Migrates spanish user’s provinces to the correct ones.
Contents
Return Return
(bool) Returns true
if more records need to be updated and false
upon completion.
Source Source
File: includes/functions/updates/llms-functions-updates-6100.php
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | function migrate_spanish_users() { $per_page = \llms_update_util_get_items_per_page(); $states_migration_map = array ( 'AS' => 'O' , // Asturias. 'CB' => 'S' , // Cantabria. 'RI' => 'LO' , // 'La Rioja'. 'MD' => 'M' , // Madrid. 'MC' => 'MU' , // 'Murcia'. 'NC' => 'NA' , // 'Navarra'. 'VC' => 'V' , // 'Valencia'. // No map. 'AN' => '' , 'AR' => '' , 'PV' => '' , 'CN' => '' , 'CL' => '' , 'CM' => '' , 'CT' => '' , 'EX' => '' , 'GA' => '' , 'SA' => '' , ); $query = new \WP_User_Query( array ( 'orderby' => array ( 'ID' => 'ASC' , ), 'meta_query' => array ( 'relation' => 'AND' , array ( 'key' => 'llms_billing_country' , 'value' => 'ES' , 'compare' => '=' , ), array ( 'key' => 'llms_billing_state' , 'value' => array_keys ( $states_migration_map ), 'compare' => 'IN' , ), ), 'posts_per_page' => $per_page , 'no_found_rows' => true, // We don't care about found rows since we'll run the query as many times as needed anyway. ) ); $users = $query ->get_results(); if ( $users ) { foreach ( $users as $user ) { $new_state = $states_migration_map [ \get_user_meta( $user ->ID, 'llms_billing_state' , true ) ] ?? '' ; \update_user_meta( $user ->ID, 'llms_billing_state' , $new_state ); } } // If there was `$per_page` results assume there's another page and run again, otherwise we're done. return ( count ( $users ) === $per_page ); } |
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
6.10.0 | Introduced. |