Title: array_map warning in class-shutterstock-api.php
Last modified: May 11, 2021

---

# array_map warning in class-shutterstock-api.php

 *  [chief1983](https://wordpress.org/support/users/chief1983/)
 * (@chief1983)
 * [5 years ago](https://wordpress.org/support/topic/array_map-warning-in-class-shutterstock-api-php/)
 * Our Sentry logging has had a high number of events from the Shutterstock plugin,
   for this warning:
 * Warning: array_map(): Expected parameter 2 to be an array, null given
 * To reproduce, I was able to confirm that the warning happens when I go to ‘License
   this Image’ after adding an image to a post, and then hitting the ‘License’ button
   on the modal window. I short-circuited the library code after the line in question
   to avoid actually attempt to license any images during testing.
 * The warning occurs on line 157 of class-shutterstock-api.php:
 * $metadata = array_map(‘sanitize_text_field’, $req_body[‘metadata’]);
 * Per comments later in the function, the metadata parameter does indeed appear
   to be optional, as does the search_id parameter which is also not accessed in
   a safe manner. I recommend a fix similar to how the local_amount value is being
   checked. I tested that it prevents the warning for the metadata parameter.
 *     ```
       Index: includes/class-shutterstock-api.php
       ===================================================================
       --- includes/class-shutterstock-api.php	(revision 2529898)
       +++ includes/class-shutterstock-api.php	(working copy)
       @@ -148,14 +148,19 @@
        		$image_description = sanitize_text_field($req_body['description']);
        		$contributor_name = sanitize_text_field($req_body['contributorName']);
        		$media_type = sanitize_text_field($req_body['mediaType']);
       -		$search_id = sanitize_text_field($req_body['search_id']);
        		$is_editorial = $media_type === 'editorial';
   
        		$width = sanitize_text_field($req_body['width']);
        		$height = sanitize_text_field($req_body['height']);
   
       -		$metadata = array_map('sanitize_text_field', $req_body['metadata']);
       +		$search_id = isset($req_body['search_id'])
       +			? sanitize_text_field($req_body['search_id'])
       +			: null;
   
       +		$metadata = isset($req_body['metadata'])
       +			? array_map('sanitize_text_field', $req_body['metadata'])
       +			: null;
       +
        		$local_amount = isset($req_body['pricePerDownload']['local_amount'])
        			? sanitize_text_field($req_body['pricePerDownload']['local_amount'])
        			: 0;
       @@ -167,7 +172,6 @@
        			: $this->api_url. '/images/licenses?subscription_id='. $subscription_id;
   
        		$body_key = $is_editorial ? 'editorial' : 'images';
       -		$body = [];
   
        		if ($is_editorial) {
        			$country = $this->shutterstock_helper->get_editorial_country();
       ```
   
 * Additionally, PHPStorm suggested removing the redundant $body = []; line, as 
   it is defined on either of the halves of the following if/else statement, making
   the initial definition redundant.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Shutterstock Plugins](https://wordpress.org/support/users/shutterstockplugins/)
 * (@shutterstockplugins)
 * [4 years, 12 months ago](https://wordpress.org/support/topic/array_map-warning-in-class-shutterstock-api-php/#post-14486344)
 * [@chief1983](https://wordpress.org/support/users/chief1983/) Thank you for reporting.
   We will check it & deploy a new version.
    -  This reply was modified 4 years, 12 months ago by [Shutterstock Plugins](https://wordpress.org/support/users/shutterstockplugins/).
 *  Plugin Author [Shutterstock Plugins](https://wordpress.org/support/users/shutterstockplugins/)
 * (@shutterstockplugins)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/array_map-warning-in-class-shutterstock-api-php/#post-14528628)
 * [@chief1983](https://wordpress.org/support/users/chief1983/) we deployed a fixed
   in new version which is `1.3.7`

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘array_map warning in class-shutterstock-api.php’ is closed to new replies.

 * ![](https://ps.w.org/shutterstock/assets/icon.svg?rev=2526826)
 * [Shutterstock](https://wordpress.org/plugins/shutterstock/)
 * [Support Threads](https://wordpress.org/support/plugin/shutterstock/)
 * [Active Topics](https://wordpress.org/support/plugin/shutterstock/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/shutterstock/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/shutterstock/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Shutterstock Plugins](https://wordpress.org/support/users/shutterstockplugins/)
 * Last activity: [4 years, 11 months ago](https://wordpress.org/support/topic/array_map-warning-in-class-shutterstock-api-php/#post-14528628)
 * Status: not resolved