'', 'url' => '', 'width' => '', 'height' => '', 'thumbnail' => '', 'filter' => array( 'grayscale' => array( 'checked' => false, 'value' => 0, ), 'blur' => array( 'checked' => false, 'value' => 0, ), 'sepia' => array( 'checked' => false, 'value' => 0, ), 'saturate' => array( 'checked' => false, 'value' => 1, ), 'opacity' => array( 'checked' => false, 'value' => 1, ), 'brightness' => array( 'checked' => false, 'value' => 100, ), 'contrast' => array( 'checked' => false, 'value' => 100, ), 'hue-rotate' => array( 'checked' => false, 'value' => 0, ), 'invert' => array( 'checked' => false, 'value' => 0, ), ), ); // Since value sub-arrays do not get parsed in wp_parse_args! $this->value = Redux_Functions::parse_args( $this->value, $defaults ); $defaults = array( 'mode' => 'image', 'preview' => true, 'preview_size' => 'thumbnail', 'url' => true, 'alt' => '', 'placeholder' => esc_html__( 'No media selected', 'redux-framework' ), 'readonly' => true, 'class' => '', 'filter' => array( 'grayscale' => false, 'blur' => false, 'sepia' => false, 'saturate' => false, 'opacity' => false, 'brightness' => false, 'contrast' => false, 'hue-rotate' => false, 'invert' => false, ), ); $this->field = Redux_Functions::parse_args( $this->field, $defaults ); if ( false === $this->field['mode'] ) { $this->field['mode'] = 0; } include_once Redux_Core::$dir . 'inc/lib/image-filters/class-redux-image-filters.php'; if ( in_array( true, $this->field['filter'], true ) ) { $this->filters_enabled = true; include_once Redux_Core::$dir . 'inc/lib/image-filters/class-redux-image-filters.php'; } } /** * Field Render Function. * Takes the vars and outputs the HTML for the field in the settings * * @since 1.0.0 * @access public * @return void */ public function render() { if ( ! isset( $this->field['library_filter'] ) ) { $lib_filter = ''; } else { if ( ! is_array( $this->field['library_filter'] ) ) { $this->field['library_filter'] = array( $this->field['library_filter'] ); } $mime_types = get_allowed_mime_types(); $lib_array = $this->field['library_filter']; $json_arr = array(); // Enum mime types. foreach ( $mime_types as $ext => $type ) { if ( strpos( $ext, '|' ) ) { $ex_arr = explode( '|', $ext ); foreach ( $ex_arr as $ext ) { if ( in_array( $ext, $lib_array, true ) ) { $json_arr[ $ext ] = $type; } } } elseif ( in_array( $ext, $lib_array, true ) ) { $json_arr[ $ext ] = $type; } } $lib_filter = rawurlencode( wp_json_encode( $json_arr ) ); } if ( empty( $this->value ) && ! empty( $this->field['default'] ) ) { // If there are standard values and value is empty. if ( is_array( $this->field['default'] ) ) { if ( ! empty( $this->field['default']['id'] ) ) { $this->value['id'] = $this->field['default']['id']; } if ( ! empty( $this->field['default']['url'] ) ) { $this->value['url'] = $this->field['default']['url']; } } elseif ( is_numeric( $this->field['default'] ) ) { // Check if it's an attachment ID. $this->value['id'] = $this->field['default']; } else { // Must be a URL. $this->value['url'] = $this->field['default']; } } if ( empty( $this->value['url'] ) && ! empty( $this->value['id'] ) ) { $img = wp_get_attachment_image_src( $this->value['id'], 'full' ); $this->value['url'] = $img[0]; $this->value['width'] = $img[1]; $this->value['height'] = $img[2]; } $hide = 'hide '; if ( false === $this->field['preview'] ) { $this->field['class'] .= ' noPreview'; } if ( ( ! empty( $this->field['url'] ) && true === $this->field['url'] ) || false === $this->field['preview'] ) { $hide = ''; } $read_only = ''; if ( $this->field['readonly'] ) { $read_only = ' readonly="readonly"'; } echo ''; echo ''; echo ''; // phpcs:ignore WordPress.Security.EscapeOutput echo ''; echo ''; echo ''; echo ''; // Preview. $hide = ''; if ( ( false === $this->field['preview'] ) || empty( $this->value['url'] ) ) { $hide .= 'display:none;'; } if ( empty( $this->value['thumbnail'] ) && ! empty( $this->value['url'] ) ) { // Just in case. if ( ! empty( $this->value['id'] ) ) { $image = wp_get_attachment_image_src( $this->value['id'], array( 150, 150 ) ); if ( empty( $image[0] ) ) { $this->value['thumbnail'] = $this->value['url']; } else { $this->value['thumbnail'] = $image[0]; } } else { $this->value['thumbnail'] = $this->value['url']; } } $css = $this->get_filter_css( $this->value['filter'] ); $alt = wp_prepare_attachment_for_js( $this->value['id'] ); $alt = $alt['alt'] ?? ''; echo '