Last active
November 9, 2023 22:15
-
-
Save pbearne/16d4462762f96318d1f2082d3b79ad44 to your computer and use it in GitHub Desktop.
re-order matador application form
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'matador_application_form_args', function( $args ) { | |
$args['fields'] = matador_jobs_moveElementInArray( $args['fields'], 'mobile', array_search('phone', array_keys( $fields ) ) + 1 ); | |
return $args; | |
}, 99 ); | |
function matador_jobs_moveElementInArray($array, $toMove, $targetIndex) { | |
if (is_int($toMove)) { | |
$tmp = array_splice($array, $toMove, 1); | |
array_splice($array, $targetIndex, 0, $tmp); | |
$output = $array; | |
} | |
elseif (is_string($toMove)) { | |
$indexToMove = array_search($toMove, array_keys($array)); | |
$itemToMove = $array[$toMove]; | |
array_splice($array, $indexToMove, 1); | |
$i = 0; | |
$output = Array(); | |
foreach($array as $key => $item) { | |
if ($i == $targetIndex) { | |
$output[$toMove] = $itemToMove; | |
} | |
$output[$key] = $item; | |
$i++; | |
} | |
} | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment