PluginProbe
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) / 1.3.0
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) v1.3.0
2.1.3 2.1.2 2.1.1 2.1.0 2.0.4 2.0.3 2.0.2 2.0.1 2.0.0 1.5.5 1.5.4 1.5.3 1.5.2 1.5.1 1.5.0 trunk 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 All 57 releases
darkify / src / Admin / Framework / fields / media / media.php

media.php in Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) 1.3.0, at src/Admin/Framework/fields/media/media.php

98 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if ( ! defined( 'ABSPATH' ) ) {
2 die; } // Cannot access directly.
3 /**
4 *
5 * Field: media
6 *
7 * @since 1.0.0
8 * @version 1.0.0
9 */
10 if ( ! class_exists( 'DarkifyField_media' ) ) {
11 class DarkifyField_media extends DarkifyFields {
12
13 public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
14 parent::__construct( $field, $value, $unique, $where, $parent );
15 }
16
17 public function render() {
18
19 $args = wp_parse_args(
20 $this->field,
21 array(
22 'url' => true,
23 'preview' => true,
24 'preview_width' => '',
25 'preview_height' => '',
26 'library' => array(),
27 'button_title' => esc_html__( 'Upload', 'darkify' ),
28 'remove_title' => esc_html__( 'Remove', 'darkify' ),
29 'preview_size' => 'thumbnail',
30 )
31 );
32
33 $default_values = array(
34 'url' => '',
35 'id' => '',
36 'width' => '',
37 'height' => '',
38 'thumbnail' => '',
39 'alt' => '',
40 'title' => '',
41 'description' => '',
42 );
43
44 // fallback
45 if ( is_numeric( $this->value ) ) {
46
47 $this->value = array(
48 'id' => $this->value,
49 'url' => wp_get_attachment_url( $this->value ),
50 'thumbnail' => wp_get_attachment_image_src( $this->value, 'thumbnail', true )[0],
51 );
52
53 }
54
55 $this->value = wp_parse_args( $this->value, $default_values );
56
57 $library = ( is_array( $args['library'] ) ) ? $args['library'] : array_filter( (array) $args['library'] );
58 $library = ( ! empty( $library ) ) ? implode( ',', $library ) : '';
59 $preview_src = ( $args['preview_size'] !== 'thumbnail' ) ? $this->value['url'] : $this->value['thumbnail'];
60 $hidden_url = ( empty( $args['url'] ) ) ? ' hidden' : '';
61 $hidden_auto = ( empty( $this->value['url'] ) ) ? ' hidden' : '';
62 $placeholder = ( empty( $this->field['placeholder'] ) ) ? ' placeholder="' . esc_html__( 'Not selected', 'darkify' ) . '"' : '';
63
64 echo wp_kses_post( $this->field_before() );
65
66 if ( ! empty( $args['preview'] ) ) {
67
68 $preview_width = ( ! empty( $args['preview_width'] ) ) ? 'max-width:' . esc_attr( $args['preview_width'] ) . 'px;' : '';
69 $preview_height = ( ! empty( $args['preview_height'] ) ) ? 'max-height:' . esc_attr( $args['preview_height'] ) . 'px;' : '';
70 $preview_style = ( ! empty( $preview_width ) || ! empty( $preview_height ) ) ? ' style="' . esc_attr( $preview_width . $preview_height ) . '"' : '';
71
72 echo '<div class="darkify--preview' . esc_attr( $hidden_auto ) . '">';
73 echo '<div class="darkify-image-preview"' . wp_kses_post($preview_style) . '>';
74 echo '<i class="darkify--remove fas fa-times"></i><span><img src="' . esc_url( $preview_src ) . '" class="darkify--src" /></span>';
75 echo '</div>';
76 echo '</div>';
77
78 }
79
80 echo '<div class="darkify--placeholder">';
81 echo '<input type="text" name="' . esc_attr( $this->field_name( '[url]' ) ) . '" value="' . esc_attr( $this->value['url'] ) . '" class="darkify--url' . esc_attr( $hidden_url ) . '" readonly="readonly"' . wp_kses_post( $this->field_attributes() ) . wp_kses_post($placeholder) . ' />';
82 echo '<a href="#" class="button button-primary darkify--button" data-library="' . esc_attr( $library ) . '" data-preview-size="' . esc_attr( $args['preview_size'] ) . '">' . esc_html( $args['button_title'] ) . '</a>';
83 echo ( empty( $args['preview'] ) ) ? '<a href="#" class="button button-secondary darkify-warning-primary darkify--remove' . esc_attr( $hidden_auto ) . '">' . esc_html( $args['remove_title'] ) . '</a>' : '';
84 echo '</div>';
85
86 echo '<input type="hidden" name="' . esc_attr( $this->field_name( '[id]' ) ) . '" value="' . esc_attr( $this->value['id'] ) . '" class="darkify--id"/>';
87 echo '<input type="hidden" name="' . esc_attr( $this->field_name( '[width]' ) ) . '" value="' . esc_attr( $this->value['width'] ) . '" class="darkify--width"/>';
88 echo '<input type="hidden" name="' . esc_attr( $this->field_name( '[height]' ) ) . '" value="' . esc_attr( $this->value['height'] ) . '" class="darkify--height"/>';
89 echo '<input type="hidden" name="' . esc_attr( $this->field_name( '[thumbnail]' ) ) . '" value="' . esc_attr( $this->value['thumbnail'] ) . '" class="darkify--thumbnail"/>';
90 echo '<input type="hidden" name="' . esc_attr( $this->field_name( '[alt]' ) ) . '" value="' . esc_attr( $this->value['alt'] ) . '" class="darkify--alt"/>';
91 echo '<input type="hidden" name="' . esc_attr( $this->field_name( '[title]' ) ) . '" value="' . esc_attr( $this->value['title'] ) . '" class="darkify--title"/>';
92 echo '<input type="hidden" name="' . esc_attr( $this->field_name( '[description]' ) ) . '" value="' . esc_attr( $this->value['description'] ) . '" class="darkify--description"/>';
93
94 echo wp_kses_post( $this->field_after() );
95 }
96 }
97 }
98