← All changes
|
includes/frontend/dynamic-content/interpreters/link.php
+62
-0
2.7.6
→
2.14.0
View file →
| @@ -1,0 +1,62 @@ | ||
| 1 | +<?php | |
| 2 | +namespace ABlocks\Frontend\DynamicContent\Interpreters; | |
| 3 | + | |
| 4 | +use ABlocks\Helper; | |
| 5 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 6 | + exit; | |
| 7 | +} | |
| 8 | +class Link extends Abstracts\Interpreter { | |
| 9 | + protected int $post_id; | |
| 10 | + protected string $field; | |
| 11 | + | |
| 12 | + public function __construct( string $name, array $setting, bool $is_richtext = false ) { | |
| 13 | + parent::__construct( $name, $setting, $is_richtext ); | |
| 14 | + $this->field = strval( $this->setting[0] ?? '' ); | |
| 15 | + $this->post_id = get_the_ID(); | |
| 16 | + } | |
| 17 | + public function content() : string { | |
| 18 | + switch ( $this->field ) { | |
| 19 | + case 'internal-url-content': | |
| 20 | + $this->content = get_permalink( $this->setting[2] ); | |
| 21 | + break; | |
| 22 | + | |
| 23 | + case 'internal-url-taxonomy': | |
| 24 | + $this->content = get_term_link( (int) $this->setting[2] ); | |
| 25 | + break; | |
| 26 | + | |
| 27 | + case 'internal-url-media': | |
| 28 | + $this->content = get_attachment_link( $this->setting[2] ); | |
| 29 | + break; | |
| 30 | + | |
| 31 | + case 'internal-url-author': | |
| 32 | + $this->content = get_author_posts_url( $this->setting[2] ); | |
| 33 | + break; | |
| 34 | + | |
| 35 | + case 'post-url': | |
| 36 | + $this->content = get_permalink( $this->post_id ); | |
| 37 | + break; | |
| 38 | + | |
| 39 | + case 'site-url': | |
| 40 | + $this->content = get_site_url(); | |
| 41 | + break; | |
| 42 | + | |
| 43 | + case 'author-url': | |
| 44 | + $this->content = get_author_posts_url( get_the_author_meta( 'ID' ) ); | |
| 45 | + break; | |
| 46 | + | |
| 47 | + case 'comments-url': | |
| 48 | + $this->content = get_comments_link( $this->post_id ); | |
| 49 | + break; | |
| 50 | + | |
| 51 | + case 'featured-image-file-url': | |
| 52 | + $this->content = get_the_post_thumbnail_url( $this->post_id, 'full' ); | |
| 53 | + break; | |
| 54 | + | |
| 55 | + case 'featured-image-attachment-url': | |
| 56 | + $attachment_id = get_post_meta( $this->post_id, '_thumbnail_id', true ); | |
| 57 | + $this->content = $attachment_id ? get_permalink( $attachment_id ) : ''; | |
| 58 | + break; | |
| 59 | + }//end switch | |
| 60 | + return $this->content; | |
| 61 | + } | |
| 62 | +} | |