$image_source, 'prompt' => $prompt, 'n' => $images_required, 'size' => $image_size, 'response_format' => 'url', ); // quality hd is only availabe in dalle-3 if ( 'dall-e-3' === $image_source && $hd_quality === true ) { $image_params['quality'] = 'hd'; } // style is only availabe in dalle-3 if ( 'dall-e-3' === $image_source && ! empty( $image_style ) ) { $image_params['style'] = $image_style; } // error_log( print_r( $image_params, true ) ); $completion = $open_ai->image( $image_params ); $response = json_decode( $completion ); // handle error if ( isset( $response->error ) ) { wp_send_json_error( $response->error->message ); return $response->error->message; } if ( ! empty( $response->data ) ) { foreach ( $response->data as $image_data ) { if ( isset( $image_data->url ) ) { $image_urls[] = $image_data->url; } } } } // if upload to media is enable only then save it to media and return it's links. // 'true' because after stringify boolean got converted to string. if ( ! empty( $image_urls ) && $upload_to_media === 'true' ) { $uploaded_image_urls = sage_ai_upload_url_to_media( $image_urls ); return $uploaded_image_urls; } return $image_urls; }