shortcode_atts()
works like array_merge()
: It merges the second list of arguments into the first one. The difference is: It merges only keys present in the first argument ($default
).
extract()
then takes the array keys, sets these as variable names and their values as variable values. 'w' => '500'
in your example becomes $w = '500'
.
Do not use extract()
. This very bad code style. Its usage was deprecated even in core, and that means something … 🙂
Your example should be written as:
$args = shortcode_atts(
array(
'w' => '500',
'h' => '330',
'q' => '',
'geo' => 'US',
),
$atts
);
$w = (int) $args['w'];
$h = (int) $args['h'];
$q = esc_attr( $args['q'] );