Skip to content

Commit

Permalink
Replace hardcoded placement values.
Browse files Browse the repository at this point in the history
  • Loading branch information
eugene-manuilov committed Jul 27, 2022
1 parent b7ed1b0 commit 4fde6b9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
12 changes: 6 additions & 6 deletions includes/Modules/Thank_With_Google/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ private function sanitize_button_placement( $button_placement ) {
if ( in_array(
$button_placement,
array(
'dynamic_low',
'dynamic_high',
'static_auto',
'static_above-content',
'static_below-content',
'static_below-first-paragraph',
Web_Tag::PLACEMENT_DYNAMIC_LOW,
Web_Tag::PLACEMENT_DYNAMIC_HIGH,
Web_Tag::PLACEMENT_STATIC_AUTO,
Web_Tag::PLACEMENT_STATIC_ABOVE_CONTENT,
Web_Tag::PLACEMENT_STATIC_BELOW_CONTENT,
Web_Tag::PLACEMENT_STATIC_AFTER_1ST_P,
),
true
) ) {
Expand Down
13 changes: 10 additions & 3 deletions includes/Modules/Thank_With_Google/Web_Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ class Web_Tag extends Module_Web_Tag {

use Method_Proxy_Trait, Tag_With_DNS_Prefetch_Trait;

const PLACEMENT_DYNAMIC_LOW = 'dynamic_low';
const PLACEMENT_DYNAMIC_HIGH = 'dynamic_high';
const PLACEMENT_STATIC_AUTO = 'static_auto';
const PLACEMENT_STATIC_ABOVE_CONTENT = 'static_above-content';
const PLACEMENT_STATIC_BELOW_CONTENT = 'static_below-content';
const PLACEMENT_STATIC_AFTER_1ST_P = 'static_below-first-paragraph';

/**
* Publication ID.
*
Expand Down Expand Up @@ -168,11 +175,11 @@ protected function update_the_content( $content ) {
return $button_placeholder;
}

if ( in_array( $this->button_placement, array( 'static_auto', 'static_below-content' ), true ) ) {
if ( in_array( $this->button_placement, array( self::PLACEMENT_STATIC_AUTO, self::PLACEMENT_STATIC_BELOW_CONTENT ), true ) ) {
$content = $content . $button_placeholder;
} elseif ( 'static_above-content' === $this->button_placement ) {
} elseif ( self::PLACEMENT_STATIC_ABOVE_CONTENT === $this->button_placement ) {
$content = $button_placeholder . $content;
} elseif ( 'static_below-first-paragraph' === $this->button_placement ) {
} elseif ( self::PLACEMENT_STATIC_AFTER_1ST_P === $this->button_placement ) {
$content = substr_replace( $content, $button_placeholder, strpos( $content, '</p>' ) + 4, 0 ); // strlen( '</p>' ) is 4.
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function set_up() {
}

public function test_content_placeholder_not_inserted_on_unselected_button_post_types() {
$this->web_tag->set_button_placement( 'static_auto' );
$this->web_tag->set_button_placement( Web_Tag::PLACEMENT_STATIC_AUTO );

$post_ID = $this->factory()->post->create( array( 'post_type' => 'page' ) );
$this->go_to( get_permalink( $post_ID ) );
Expand All @@ -51,7 +51,7 @@ public function test_content_placeholder_not_inserted_on_unselected_button_post_
}

public function test_content_placeholder_inserted_on_button_post_types() {
$this->web_tag->set_button_placement( 'static_auto' );
$this->web_tag->set_button_placement( Web_Tag::PLACEMENT_STATIC_AUTO );

$this->create_post_and_go_to_it();

Expand All @@ -62,7 +62,7 @@ public function test_content_placeholder_inserted_on_button_post_types() {
}

public function test_content_placeholder_not_inserted_on_dynamic_button_placement() {
$this->web_tag->set_button_placement( 'dynamic_low' );
$this->web_tag->set_button_placement( Web_Tag::PLACEMENT_DYNAMIC_LOW );

$this->create_post_and_go_to_it();

Expand All @@ -73,7 +73,7 @@ public function test_content_placeholder_not_inserted_on_dynamic_button_placemen
}

public function test_content_placeholder_inserted_static_below_content() {
$this->web_tag->set_button_placement( 'static_below-content' );
$this->web_tag->set_button_placement( Web_Tag::PLACEMENT_STATIC_BELOW_CONTENT );

$this->create_post_and_go_to_it();

Expand All @@ -85,7 +85,7 @@ public function test_content_placeholder_inserted_static_below_content() {
}

public function test_content_placeholder_inserted_static_above_content() {
$this->web_tag->set_button_placement( 'static_above-content' );
$this->web_tag->set_button_placement( Web_Tag::PLACEMENT_STATIC_ABOVE_CONTENT );

$this->create_post_and_go_to_it();

Expand All @@ -97,7 +97,7 @@ public function test_content_placeholder_inserted_static_above_content() {
}

public function test_content_placeholder_inserted_static_below_first_paragraph() {
$this->web_tag->set_button_placement( 'static_below-first-paragraph' );
$this->web_tag->set_button_placement( Web_Tag::PLACEMENT_STATIC_AFTER_1ST_P );

$this->create_post_and_go_to_it();

Expand Down

0 comments on commit 4fde6b9

Please sign in to comment.