Coding Standards: Extract extract() from the codebase.

Of the last four instances of `extract()` occurring, three of them are removed by this commit, and the fourth is appropriately documented.

See #45934.



git-svn-id: https://develop.svn.wordpress.org/trunk@44569 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast 2019-01-12 03:19:23 +00:00
parent 34e3de7b7f
commit ff53bd388c
4 changed files with 24 additions and 19 deletions

View File

@ -68,7 +68,6 @@ class Twenty_Eleven_Ephemera_Widget extends WP_Widget {
}
ob_start();
extract( $args, EXTR_SKIP );
/** This filter is documented in wp-includes/default-widgets.php */
$args['title'] = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Ephemera', 'twentyeleven' ) : $instance['title'], $instance, $this->id_base );

View File

@ -684,6 +684,15 @@ function load_template( $_template_file, $require_once = true ) {
global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID;
if ( is_array( $wp_query->query_vars ) ) {
/*
* This use of extract() cannot be removed. There are many possible ways that
* templates could depend on variables that it creates existing, and no way to
* detect and deprecate it.
*
* Passing the EXTR_SKIP flag is the safest option, ensuring globals and
* function variables cannot be overwritten.
*/
// phpcs:ignore WordPress.PHP.DontExtract.extract_extract
extract( $wp_query->query_vars, EXTR_SKIP );
}

View File

@ -29,15 +29,14 @@ class Tests_Post_Output extends WP_UnitTestCase {
}
function _shortcode_paragraph( $atts, $content ) {
extract(
shortcode_atts(
array(
'class' => 'graf',
),
$atts
)
$processed_atts = shortcode_atts(
array(
'class' => 'graf',
),
$atts
);
return "<p class='$class'>$content</p>\n";
return "<p class='{$processed_atts['class']}'>$content</p>\n";
}
function test_the_content() {

View File

@ -43,18 +43,16 @@ class Tests_Shortcode extends WP_UnitTestCase {
// [bartag foo="bar"]
function _shortcode_bartag( $atts ) {
extract(
shortcode_atts(
array(
'foo' => 'no foo',
'baz' => 'default baz',
),
$atts,
'bartag'
)
$processed_atts = shortcode_atts(
array(
'foo' => 'no foo',
'baz' => 'default baz',
),
$atts,
'bartag'
);
return "foo = {$foo}";
return "foo = {$processed_atts['foo']}";
}
// [baztag]content[/baztag]