| 1 |
<?php |
| 2 |
/** |
| 3 |
* Advertisement Shortcode |
| 4 |
*/ |
| 5 |
|
| 6 |
// Exit if accessed directly |
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
exit; |
| 9 |
} |
| 10 |
|
| 11 |
class WINP_SnippetShortcodeAdvert extends WINP_SnippetShortcode { |
| 12 |
|
| 13 |
public $shortcode_name = 'wbcr_advert_snippet'; |
| 14 |
|
| 15 |
/** |
| 16 |
* Content render |
| 17 |
* |
| 18 |
* @param array $attr |
| 19 |
* @param string $content |
| 20 |
* @param string $tag |
| 21 |
*/ |
| 22 |
public function html( $attr, $content, $tag ) { |
| 23 |
$id = $this->get_snippet_id( $attr, WINP_SNIPPET_TYPE_AD ); |
| 24 |
|
| 25 |
if ( ! $id ) { |
| 26 |
/* translators: %s: Shortcode tag name */ |
| 27 |
echo '<span style="color:red">' . sprintf( esc_html__( '[%s]: Advertisement snippets error (not passed the snippet ID)', 'insert-php' ), esc_html( $tag ) ) . '</span>'; |
| 28 |
|
| 29 |
return; |
| 30 |
} |
| 31 |
|
| 32 |
$snippet = get_post( $id ); |
| 33 |
$snippet_meta = get_post_meta( $id, '' ); |
| 34 |
|
| 35 |
if ( ! $snippet || empty( $snippet_meta ) ) { |
| 36 |
return; |
| 37 |
} |
| 38 |
|
| 39 |
$is_activate = $this->get_snippet_activate( $snippet_meta ); |
| 40 |
$snippet_scope = $this->get_snippet_scope( $snippet_meta ); |
| 41 |
$is_condition = WINP_Plugin::app()->get_execute_object()->checkCondition( $id ); |
| 42 |
|
| 43 |
if ( ! $is_activate || $snippet_scope != 'shortcode' || ! $is_condition ) { |
| 44 |
return; |
| 45 |
} |
| 46 |
|
| 47 |
// Track shortcode execution. |
| 48 |
WINP_Plugin::app()->get_execute_object()->track_shortcode_snippet( $id ); |
| 49 |
|
| 50 |
$post_content = $snippet->post_content; |
| 51 |
if ( get_option( 'wbcr_inp_execute_shortcode' ) ) { |
| 52 |
$post_content = do_shortcode( $post_content ); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Shortcode content filter |
| 57 |
* |
| 58 |
* @since 2.4.4 |
| 59 |
*/ |
| 60 |
$post_content = apply_filters( 'wbcr/inp/snippet/shortcode_ad/post_content', $post_content, $id ); |
| 61 |
|
| 62 |
echo str_replace( '{{SNIPPET_CONTENT}}', $content, $post_content ); |
| 63 |
} |
| 64 |
} |
| 65 |
|