From a1fb51b998da7ba6ab3cc7ebf72ccc8422bbd297 Mon Sep 17 00:00:00 2001 From: Josh Pollock Date: Mon, 25 Jan 2016 23:32:17 -0500 Subject: [PATCH] Make it possible for a variant to be a short code. #218 --- classes/ui/render/click_tests/button.php | 4 ++-- .../ui/render/click_tests/button_color.php | 2 +- classes/ui/render/click_tests/click.php | 20 +++++++++++++++++++ classes/ui/render/click_tests/destination.php | 4 ++-- classes/ui/render/click_tests/link.php | 4 ++-- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/classes/ui/render/click_tests/button.php b/classes/ui/render/click_tests/button.php index c650d3f..ff0d32e 100644 --- a/classes/ui/render/click_tests/button.php +++ b/classes/ui/render/click_tests/button.php @@ -29,7 +29,7 @@ class button extends \ingot\ui\render\click_tests\click { */ protected function make_html() { $test_id = (int) $this->get_variant()[ 'ID' ]; - $text = $this->get_variant()[ 'content' ]; + $text = $this->get_variant_content(); $link = $this->link(); $style = $this->make_style( $this->get_group() ); $group_id = $this->get_group()[ 'ID' ]; @@ -42,7 +42,7 @@ protected function make_html() { esc_url( $link ), esc_attr( $test_id ), $style, - esc_html( $text ) + wp_kses_post( $text ) ); remove_filter( 'ingot_default_button_color', array( $this, 'get_group_default_color' ) ); diff --git a/classes/ui/render/click_tests/button_color.php b/classes/ui/render/click_tests/button_color.php index 9594f56..3979cb6 100644 --- a/classes/ui/render/click_tests/button_color.php +++ b/classes/ui/render/click_tests/button_color.php @@ -42,7 +42,7 @@ protected function make_html() { esc_url( $link ), esc_attr( $test_id ), $style, - esc_html( $text ) + wp_kses_post( $text ) ); remove_filter( 'ingot_default_button_color', array( $this, 'get_group_default_color' ) ); diff --git a/classes/ui/render/click_tests/click.php b/classes/ui/render/click_tests/click.php index a73fcf9..9050bcf 100644 --- a/classes/ui/render/click_tests/click.php +++ b/classes/ui/render/click_tests/click.php @@ -129,6 +129,26 @@ public function get_chosen_variant_id(){ return (int) $this->variant[ 'ID' ]; } + /** + * Get variant content + * + * @since 1.1.0 + * + * @return string + */ + protected function get_variant_content(){ + /** + * Filter the content of the chosen variant before rendering the test + * + * @since 1.1.0 + * + * @param string $content The content + * @param int $variant_ID The variant ID + * @param int $gorup_ID The group ID + */ + return apply_filters( 'ingot_click_test_content', $this->variant[ 'content'], $this->variant[ 'ID' ], $this->group[ 'ID'] ); + } + /** * Get variant property * diff --git a/classes/ui/render/click_tests/destination.php b/classes/ui/render/click_tests/destination.php index 0556b5d..7a44aaa 100644 --- a/classes/ui/render/click_tests/destination.php +++ b/classes/ui/render/click_tests/destination.php @@ -25,7 +25,7 @@ class destination extends \ingot\ui\render\click_tests\click { */ protected function make_html() { $test_id = $this->get_variant()[ 'ID' ]; - $text = $this->get_variant()[ 'content' ]; + $text = $this->get_variant_content(); $group_id = $this->get_group()[ 'ID' ]; $this->html = sprintf( @@ -33,7 +33,7 @@ protected function make_html() { esc_attr( $this->attr_id() ), esc_attr( $group_id ), esc_attr( $test_id ), - esc_html( $text ) + wp_kses_post( $text ) ); } diff --git a/classes/ui/render/click_tests/link.php b/classes/ui/render/click_tests/link.php index 14f01b6..220aedc 100644 --- a/classes/ui/render/click_tests/link.php +++ b/classes/ui/render/click_tests/link.php @@ -26,7 +26,7 @@ class link extends \ingot\ui\render\click_tests\click { */ protected function make_html() { $test_id = $this->get_variant()[ 'ID' ]; - $text = $this->get_variant()[ 'content' ]; + $text = $this->get_variant_content(); $link = $this->link(); $group_id = $this->get_group()[ 'ID' ]; @@ -36,7 +36,7 @@ protected function make_html() { esc_url( $link ), esc_attr( $group_id ), esc_attr( $test_id ), - esc_html( $text ) + wp_kses_post( $text ) ); }