| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Suppress "error - 0 - No summary was found for this file" on phpdoc generation |
| 5 |
* |
| 6 |
* @package WPDataAccess\Simple_Form |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace WPDataAccess\Simple_Form { |
| 10 |
|
| 11 |
/** |
| 12 |
* Class WPDA_Simple_Form_Item_Image |
| 13 |
* |
| 14 |
* Handles a database column of type image. |
| 15 |
* |
| 16 |
* @author Peter Schulz |
| 17 |
* @since 2.5.0 |
| 18 |
*/ |
| 19 |
class WPDA_Simple_Form_Item_Image extends WPDA_Simple_Form_Item_Media { |
| 20 |
|
| 21 |
/** |
| 22 |
* WPDA_Simple_Form_Item_Image constructor. |
| 23 |
* |
| 24 |
* @param array $args |
| 25 |
*/ |
| 26 |
public function __construct( $args = array() ) { |
| 27 |
parent::__construct( $args ); |
| 28 |
|
| 29 |
$this->media_frame_title = __( 'Upload or select image(s) from your WordPress media library', 'wp-data-access' ); |
| 30 |
$this->media_frame_remove = __( 'Remove image(s)', 'wp-data-access' ); |
| 31 |
$this->media_types = 'image'; |
| 32 |
} |
| 33 |
|
| 34 |
protected function show_item_media() { |
| 35 |
if ( 'number' === $this->data_type ) { |
| 36 |
// Column supports one image file. |
| 37 |
$url = wp_get_attachment_url( $this->item_value ); |
| 38 |
if ( false !== $url ) { |
| 39 |
$this->create_item_image( $url ); |
| 40 |
} |
| 41 |
} else { |
| 42 |
// Column supports multiple image files. |
| 43 |
if ( null !== $this->item_value && '' !== $this->item_value ) { |
| 44 |
$media_ids = explode( ',', $this->item_value );//phpcs:ignore - 8.1 proof |
| 45 |
foreach ( $media_ids as $media_id ) { |
| 46 |
$url = wp_get_attachment_url( $media_id ); |
| 47 |
$this->create_item_image( $url ); |
| 48 |
} |
| 49 |
} |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
private function create_item_image( $url ) { |
| 54 |
?> |
| 55 |
<span class="wpda_media_container wpda_image"> |
| 56 |
<img src="<?php echo esc_url( $url ); ?>" target="_blank"> |
| 57 |
</span> |
| 58 |
<?php |
| 59 |
} |
| 60 |
|
| 61 |
} |
| 62 |
|
| 63 |
} |
| 64 |
|