From ef6caaff898e2988cf6033c3a0fa42305742773d Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Wed, 29 Jan 2020 23:51:40 -0600 Subject: [PATCH] Prevent an error in WP 4.9.12, where sanitize_text_field() caused an error There was a PHP error when that function accepted a closure, and in 4.9.12, it didn't have a check that exits if the argument is the wrong type. So move the check into a function that later calls sanitize_text_field(). --- .../php/class-settings-page.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-settings-page.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-settings-page.php index 42be6ab5d..237c61557 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-settings-page.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-settings-page.php @@ -412,7 +412,18 @@ public function sanitize( $setting, $fields ) { } } else { if ( is_array( $field ) ) { - array_walk_recursive( $field, 'sanitize_text_field' ); + array_walk_recursive( + $field, + static function( $field_value ) { + // WP 4.9 compatibility, as _sanitize_text_fields() didn't have this check yet, and this prevents an error. + // @see https://github.com/WordPress/wordpress-develop/blob/b30baca3ca2feb7f44b3615262ca55fcd87ae232/src/wp-includes/formatting.php#L5307 + if ( is_object( $field_value ) || is_array( $field_value ) ) { + return ''; + } + + return sanitize_text_field( $field_value ); + } + ); } else { $setting[ $slug ] = sanitize_text_field( $field ); }