Code Duplication    Length = 24-24 lines in 2 locations

modules/videopress-v2/utility-functions.php 1 location

@@ 130-153 (lines=24) @@
127
 *
128
 * @return int|mixed|object|WP_Error
129
 */
130
function videopress_download_poster_image( $url, $attachment_id ) {
131
	// Set variables for storage, fix file filename for query strings.
132
	preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $url, $matches );
133
	if ( ! $matches ) {
134
		return new WP_Error( 'image_sideload_failed', __( 'Invalid image URL', 'jetpack' ) );
135
	}
136
137
	$file_array = array();
138
	$file_array['name']     = basename( $matches[0] );
139
	$file_array['tmp_name'] = download_url( $url );
140
141
	// If error storing temporarily, return the error.
142
	if ( is_wp_error( $file_array['tmp_name'] ) ) {
143
		return $file_array['tmp_name'];
144
	}
145
146
	// Do the validation and storage stuff.
147
	$thumbnail_id = media_handle_sideload( $file_array, $attachment_id, null );
148
149
	// Flag it as poster image, so we can exclude it from display.
150
	update_post_meta( $thumbnail_id, 'videopress_poster_image', 1 );
151
152
	return $thumbnail_id;
153
}
154
155
/**
156
 * Creates a local media library item of a remote VideoPress video.

modules/videopress/utility-functions.php 1 location

@@ 113-136 (lines=24) @@
110
 *
111
 * @return int|mixed|object|WP_Error
112
 */
113
function videopress_download_poster_image( $url, $attachment_id ) {
114
	// Set variables for storage, fix file filename for query strings.
115
	preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $url, $matches );
116
	if ( ! $matches ) {
117
		return new WP_Error( 'image_sideload_failed', __( 'Invalid image URL' ) );
118
	}
119
120
	$file_array = array();
121
	$file_array['name']     = basename( $matches[0] );
122
	$file_array['tmp_name'] = download_url( $url );
123
124
	// If error storing temporarily, return the error.
125
	if ( is_wp_error( $file_array['tmp_name'] ) ) {
126
		return $file_array['tmp_name'];
127
	}
128
129
	// Do the validation and storage stuff.
130
	$thumbnail_id = media_handle_sideload( $file_array, $attachment_id, null );
131
132
	// Flag it as poster image, so we can exclude it from display.
133
	update_post_meta( $thumbnail_id, 'videopress_poster_image', 1 );
134
135
	return $thumbnail_id;
136
}
137
138
/**
139
 * Creates a local media library item of a remote VideoPress video.