field->id(), refers to the field id attribute. * * @since 2.0.9 * * @param bool $is_valid Whether field value has a valid image file-type extension. * @param string $file File url. * @param string $file_ext File extension. */ return (bool) apply_filters( "cmb2_{$this->field->id()}_is_valid_img_ext", $is_valid, $file, $file_ext ); } /** * file/file_list image wrap * @since 2.0.2 * @param array $args Array of arguments for output * @return string Image wrap output */ public function img_status_output( $args ) { return sprintf( '<%1$s class="img-status cmb2-media-item">%2$s

%4$s

%5$s', $args['tag'], $args['image'], isset( $args['cached_id'] ) ? ' rel="' . $args['cached_id'] . '"' : '', esc_html( $this->_text( 'remove_image_text', esc_html__( 'Remove Image', 'cmb2' ) ) ), isset( $args['id_input'] ) ? $args['id_input'] : '' ); } /** * file/file_list file wrap * @since 2.0.2 * @param array $args Array of arguments for output * @return string File wrap output */ public function file_status_output( $args ) { return sprintf( '<%1$s class="file-status cmb2-media-item">%2$s %3$s   (%5$s / %7$s)%8$s', $args['tag'], esc_html( $this->_text( 'file_text', esc_html__( 'File:', 'cmb2' ) ) ), CMB2_Utils::get_file_name_from_path( $args['value'] ), $args['value'], esc_html( $this->_text( 'file_download_text', esc_html__( 'Download', 'cmb2' ) ) ), isset( $args['cached_id'] ) ? ' rel="' . $args['cached_id'] . '"' : '', esc_html( $this->_text( 'remove_text', esc_html__( 'Remove', 'cmb2' ) ) ), isset( $args['id_input'] ) ? $args['id_input'] : '' ); } /** * Outputs the file/file_list underscore Javascript templates in the footer. * @since 2.2.4 * @return void */ public static function output_js_underscore_templates() { ?> (int) image size width * 'height' => (int) image size height * 'name' => (string) e.g. 'thumbnail' * ) */ static function get_image_size_data( $img_size = '', $fallback = 'thumbnail' ) { $data = array(); if ( is_array( $img_size ) ) { $data['width'] = intval( $img_size[0] ); $data['height'] = intval( $img_size[1] ); $data['name'] = ''; // Try and get the closest named size from our array of dimensions if ( $named_size = CMB2_Utils::get_named_size( $img_size ) ) { $data['name'] = $named_size; } } else { $image_sizes = CMB2_Utils::get_available_image_sizes(); // The 'thumb' alias, which works elsewhere, doesn't work in the wp.media uploader if ( 'thumb' == $img_size ) { $img_size = 'thumbnail'; } // Named size doesn't exist, use $fallback if ( ! array_key_exists( $img_size, $image_sizes ) ) { $img_size = $fallback; } // Get image dimensions from named sizes $data['width'] = intval( $image_sizes[ $img_size ]['width'] ); $data['height'] = intval( $image_sizes[ $img_size ]['height'] ); $data['name'] = $img_size; } return $data; } /** * Filters attachment data prepared for JavaScript. * * Adds the url, width, height, and orientation for custom sizes to the JavaScript * object returned by the wp.media uploader. Hooked to 'wp_prepare_attachment_for_js'. * * @since 2.2.4 * @param array $response Array of prepared attachment data * @param int|object $attachment Attachment ID or object * @param array $meta Array of attachment meta data ( from wp_get_attachment_metadata() ) * @return array filtered $response array */ public static function prepare_image_sizes_for_js( $response, $attachment, $meta ) { foreach ( CMB2_Utils::get_available_image_sizes() as $size => $info ) { // registered image size exists for this attachment if ( isset( $meta['sizes'][ $size ] ) ) { $attachment_url = wp_get_attachment_url( $attachment->ID ); $base_url = str_replace( wp_basename( $attachment_url ), '', $attachment_url ); $size_meta = $meta['sizes'][ $size ]; $response['sizes'][ $size ] = array( 'url' => $base_url . $size_meta['file'], 'height' => $size_meta['height'], 'width' => $size_meta['width'], 'orientation' => $size_meta['height'] > $size_meta['width'] ? 'portrait' : 'landscape', ); } } return $response; } }