1230 | | /* |
1231 | | * If old and new theme both have sidebars that contain phrases |
1232 | | * from within the same group, make an educated guess and map it. |
1233 | | */ |
1234 | | $common_slug_groups = array( |
1235 | | array( 'sidebar', 'primary', 'main', 'right' ), |
1236 | | array( 'second', 'left' ), |
1237 | | array( 'sidebar-2', 'footer', 'bottom' ), |
1238 | | array( 'header', 'top' ), |
1239 | | ); |
1240 | | |
1241 | | // Go through each group... |
1242 | | foreach ( $common_slug_groups as $slug_group ) { |
1243 | | |
1244 | | // ...and see if any of these slugs... |
1245 | | foreach ( $slug_group as $slug ) { |
1246 | | |
1247 | | // ...and any of the new sidebars... |
1248 | | foreach ( $wp_registered_sidebars as $new_sidebar => $args ) { |
1249 | | |
1250 | | // ...actually match! |
1251 | | if ( false === stripos( $new_sidebar, $slug ) && false === stripos( $slug, $new_sidebar ) ) { |
1252 | | continue; |
1253 | | } |
1254 | | |
1255 | | // Then see if any of the existing sidebars... |
1256 | | foreach ( $existing_sidebars_widgets as $sidebar => $widgets ) { |
1257 | | |
1258 | | // ...and any slug in the same group... |
1259 | | foreach ( $slug_group as $slug ) { |
1260 | | |
1261 | | // ... have a match as well. |
1262 | | if ( false === stripos( $sidebar, $slug ) && false === stripos( $slug, $sidebar ) ) { |
1263 | | continue; |
1264 | | } |
1265 | | |
1266 | | // Make sure this sidebar wasn't mapped and removed previously. |
1267 | | if ( ! empty( $existing_sidebars_widgets[ $sidebar ] ) ) { |
1268 | | |
1269 | | // We have a match that can be mapped! |
1270 | | $new_sidebars_widgets[ $new_sidebar ] = array_merge( $new_sidebars_widgets[ $new_sidebar ], $existing_sidebars_widgets[ $sidebar ] ); |
1271 | | |
1272 | | // Remove the mapped sidebar so it can't be mapped again. |
1273 | | unset( $existing_sidebars_widgets[ $sidebar ] ); |
1274 | | |
1275 | | // Go back and check the next new sidebar. |
1276 | | continue 3; |
1277 | | } |
1278 | | } // endforeach ( $slug_group as $slug ) |
1279 | | } // endforeach ( $existing_sidebars_widgets as $sidebar => $widgets ) |
1280 | | } // endforeach foreach ( $wp_registered_sidebars as $new_sidebar => $args ) |
1281 | | } // endforeach ( $slug_group as $slug ) |
1282 | | } // endforeach ( $common_slug_groups as $slug_group ) |
| 1228 | /* |
| 1229 | * If old and new theme both have sidebars that contain phrases |
| 1230 | * from within the same group, make an educated guess and map it. |
| 1231 | */ |
| 1232 | $common_slug_groups = array( |
| 1233 | array( 'sidebar', 'primary', 'main', 'right' ), |
| 1234 | array( 'second', 'left' ), |
| 1235 | array( 'sidebar-2', 'footer', 'bottom' ), |
| 1236 | array( 'header', 'top' ), |
| 1237 | ); |
| 1238 | |
| 1239 | // Go through each group... |
| 1240 | foreach ( $common_slug_groups as $slug_group ) { |
| 1241 | |
| 1242 | // ...and see if any of these slugs... |
| 1243 | foreach ( $slug_group as $slug ) { |
| 1244 | |
| 1245 | // ...and any of the new sidebars... |
| 1246 | foreach ( $wp_registered_sidebars as $new_sidebar => $args ) { |
| 1247 | |
| 1248 | // ...actually match! |
| 1249 | if ( false === stripos( $new_sidebar, $slug ) && false === stripos( $slug, $new_sidebar ) ) { |
| 1250 | continue; |
| 1251 | } |
| 1252 | |
| 1253 | // Then see if any of the existing sidebars... |
| 1254 | foreach ( $existing_sidebars_widgets as $sidebar => $widgets ) { |
| 1255 | |
| 1256 | // ...and any slug in the same group... |
| 1257 | foreach ( $slug_group as $slug ) { |
| 1258 | |
| 1259 | // ... have a match as well. |
| 1260 | if ( false === stripos( $sidebar, $slug ) && false === stripos( $slug, $sidebar ) ) { |
| 1261 | continue; |
| 1262 | } |
| 1263 | |
| 1264 | // Make sure this sidebar wasn't mapped and removed previously. |
| 1265 | if ( ! empty( $existing_sidebars_widgets[ $sidebar ] ) ) { |
| 1266 | |
| 1267 | // We have a match that can be mapped! |
| 1268 | $new_sidebars_widgets[ $new_sidebar ] = array_merge( $new_sidebars_widgets[ $new_sidebar ], $existing_sidebars_widgets[ $sidebar ] ); |
| 1269 | |
| 1270 | // Remove the mapped sidebar so it can't be mapped again. |
| 1271 | unset( $existing_sidebars_widgets[ $sidebar ] ); |
| 1272 | |
| 1273 | // Go back and check the next new sidebar. |
| 1274 | continue 3; |
| 1275 | } |
| 1276 | } // endforeach ( $slug_group as $slug ) |
| 1277 | } // endforeach ( $existing_sidebars_widgets as $sidebar => $widgets ) |
| 1278 | } // endforeach foreach ( $wp_registered_sidebars as $new_sidebar => $args ) |
| 1279 | } // endforeach ( $slug_group as $slug ) |
| 1280 | } // endforeach ( $common_slug_groups as $slug_group ) |
| 1281 | } |