← All changes
|
modules/atomic-widgets/props-resolver/transformers/settings/link-transformer.php
+8
-5
4.3.0
→
3.28.0-dev2
View file →
| @@ -1,10 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Elementor\Modules\AtomicWidgets\PropsResolver\Transformers\Settings; |
| 4 | 4 | |
| 5 | -use Elementor\Modules\AtomicWidgets\PropsResolver\Props_Resolver_Context; | |
| 6 | 5 | use Elementor\Modules\AtomicWidgets\PropsResolver\Transformer_Base; |
| 6 | +use Elementor\Modules\AtomicWidgets\PropTypes\Url_Prop_Type; | |
| 7 | 7 | |
| 8 | 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | 9 | exit; // Exit if accessed directly. |
| 10 | 10 | } |
| @@ -9,15 +9,18 @@ | ||
| 9 | 9 | exit; // Exit if accessed directly. |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | class Link_Transformer extends Transformer_Base { |
| 13 | - public function transform( $value, Props_Resolver_Context $context ): ?array { | |
| 13 | + public function transform( $value, $key ): ?array { | |
| 14 | 14 | $url = $this->extract_url( $value ); |
| 15 | 15 | |
| 16 | + if ( ! Url_Prop_Type::validate_url( $url ) ) { | |
| 17 | + return null; | |
| 18 | + } | |
| 19 | + | |
| 16 | 20 | $link_attrs = [ |
| 17 | - 'href' => $url, | |
| 21 | + 'href' => esc_url( $url ), | |
| 18 | 22 | 'target' => $value['isTargetBlank'] ? '_blank' : '_self', |
| 19 | - 'tag' => $url && 'button' === $value['tag'] ? 'button' : 'a', | |
| 20 | 23 | ]; |
| 21 | 24 | |
| 22 | 25 | return array_filter( $link_attrs ); |
| 23 | 26 | } |
| @@ -25,7 +28,7 @@ | ||
| 25 | 28 | private function extract_url( $value ): ?string { |
| 26 | 29 | $destination = $value['destination']; |
| 27 | 30 | $post = is_numeric( $destination ) ? get_post( $destination ) : null; |
| 28 | 31 | |
| 29 | - return $post ? get_permalink( $post ) : $destination; | |
| 32 | + return $post ? $post->guid : $destination; | |
| 30 | 33 | } |
| 31 | 34 | } |