types
10 months ago
class-ad-content.php
1 week ago
class-ad-dummy.php
1 year ago
class-ad-factory.php
1 day ago
class-ad-group-relation.php
1 year ago
class-ad-group.php
5 months ago
class-ad-image.php
1 year ago
class-ad-plain.php
1 week ago
class-ad-repository.php
1 day ago
class-ad-types.php
1 day ago
class-ads.php
1 day ago
class-ad-plain.php
82 lines
| 1 | <?php |
| 2 | /** |
| 3 | * This class is responsible to model plain ads. |
| 4 | * |
| 5 | * @package AdvancedAds |
| 6 | * @author Advanced Ads <info@wpadvancedads.com> |
| 7 | * @since 1.48.0 |
| 8 | */ |
| 9 | |
| 10 | namespace AdvancedAds\Ads; |
| 11 | |
| 12 | use AdvancedAds\Abstracts\Ad; |
| 13 | use AdvancedAds\Interfaces\Ad_Interface; |
| 14 | use AdvancedAds\Utilities\Conditional; |
| 15 | use AdvancedAds\Utilities\WordPress; |
| 16 | |
| 17 | defined( 'ABSPATH' ) || exit; |
| 18 | |
| 19 | /** |
| 20 | * Plain ad. |
| 21 | */ |
| 22 | class Ad_Plain extends Ad implements Ad_Interface { |
| 23 | |
| 24 | /** |
| 25 | * Prepare output for frontend. |
| 26 | * |
| 27 | * @return string |
| 28 | */ |
| 29 | public function prepare_frontend_output(): string { |
| 30 | $content = $this->get_content(); |
| 31 | |
| 32 | // Evaluate the code as PHP if setting was never saved or is allowed. |
| 33 | if ( $this->is_php_allowed() && Conditional::is_php_allowed() ) { |
| 34 | ob_start(); |
| 35 | eval( '?>' . $content ); // phpcs:ignore Squiz.PHP.Eval.Discouraged -- this is specifically eval'd so allow eval here. |
| 36 | $content = ob_get_clean(); |
| 37 | } |
| 38 | |
| 39 | if ( ! is_string( $content ) ) { |
| 40 | return ''; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Apply do_blocks if the content has block code |
| 45 | * works with WP 5.0.0 and later |
| 46 | */ |
| 47 | if ( function_exists( 'has_blocks' ) && has_blocks( $content ) ) { |
| 48 | $content = do_blocks( $content ); |
| 49 | } |
| 50 | |
| 51 | if ( $this->is_shortcode_allowed() ) { |
| 52 | $content = $this->do_shortcode( $content ); |
| 53 | } |
| 54 | |
| 55 | // Add 'loading' attribute if applicable, available from WP 5.5. |
| 56 | if ( |
| 57 | function_exists( 'wp_lazy_loading_enabled' ) |
| 58 | && wp_lazy_loading_enabled( 'img', 'the_content' ) |
| 59 | && preg_match_all( '/<img\s[^>]+>/', $content, $matches ) |
| 60 | ) { |
| 61 | foreach ( $matches[0] as $image ) { |
| 62 | if ( strpos( $image, 'loading=' ) !== false ) { |
| 63 | continue; |
| 64 | } |
| 65 | |
| 66 | // Optimize image HTML tag with loading attributes based on WordPress filter context. |
| 67 | $content = str_replace( $image, WordPress::img_tag_add_loading_attr( $image, 'the_content' ), $content ); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | return ( |
| 72 | ( |
| 73 | ( defined( 'DISALLOW_UNFILTERED_HTML' ) && DISALLOW_UNFILTERED_HTML ) || |
| 74 | ! Conditional::can_author_unfiltered_html( (int) get_post_field( 'post_author', $this->get_id() ) ) |
| 75 | ) |
| 76 | && version_compare( $this->get_prop( 'last_save_version' ) ?? '0', '1.35.0', 'ge' ) |
| 77 | ) |
| 78 | ? wp_kses_post( $content ) |
| 79 | : $content; |
| 80 | } |
| 81 | } |
| 82 |