Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #83 from pantheon-systems/release-0.2.12
Browse files Browse the repository at this point in the history
Release 0.2.12
  • Loading branch information
jazzsequence committed Mar 30, 2022
2 parents 65e4eee + 833ae0f commit c65ab35
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 51 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Pantheon WordPress Edge Integrations

Stable tag: 0.2.10
Stable tag: 0.2.12
Requires at least: 5.8
Tested up to: 5.9
Requires PHP: 7.4
Expand Down
5 changes: 3 additions & 2 deletions inc/analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@ function after_body() {
*/
function localize_script() {
$vary_headers = WP\get_supported_vary_headers();
$interests = WP\Interest\get_interest();

wp_localize_script( 'pantheon-ei', 'eiGtm', [
'headersEnabled' => $vary_headers,
'geo' => WP\Geo\get_geo(),
'interest' => WP\Interest\get_interest(),
'geo' => json_decode( WP\Geo\get_geo() ),
'interest' => ! empty( $interest ) ? $interest : '',
] );
}

Expand Down
24 changes: 10 additions & 14 deletions inc/interest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,44 +66,40 @@ function set_interest_header() {
return;
}

get_interest( [ 'HTTP_INTEREST' => $interest ] );
set_interest( [ 'HTTP_INTEREST' => $interest ] );
}

/**
* Set interest data.
* Set the interest data in global header.
*
* @param array $key Key for the header, or array of keys.
* @param array $data Data to pass to the HeaderData class.
* @param array $data Data to pass to the HeaderData class. By default, this is pulled from $_SERVER data.
*
* @return array The requested interest data.
* @return array The new interest data.
*/
function set_interest( array $key = null, array $data = null ) : array {
function set_interest( array $data = null ) : array {
/**
* Get the interest data from the HeaderData class and allow it to be filtered.
*
* @hook pantheon.ei.set_interest_data
* @hook pantheon.ei.applied_interest_data
* @param array The full, parsed Interest data as an array.
*/
$vary_header = apply_filters( 'pantheon.ei.set_interest_data', EI\HeaderData::varyHeader( $key, $data ) );
$applied_interest = apply_filters( 'pantheon.ei.applied_interest_data', EI\HeaderData::parse( 'Interest', $data ) );

return $vary_header;
return $applied_interest;
}

/**
* Return interest data.
*
* @param array $data Data to pass to the HeaderData class. By default, this is pulled from $_SERVER data.
*
* @return array The requested interest data.
*/
function get_interest( array $data = null ) : array {
function get_interest() : array {
/**
* Get the interest data from the HeaderData class and allow it to be filtered.
*
* @hook pantheon.ei.parsed_interest_data
* @param array The full, parsed Interest data as an array.
*/
$parsed_interest = apply_filters( 'pantheon.ei.parsed_interest_data', EI\HeaderData::parse( 'Interest', $data ) );
$parsed_interest = apply_filters( 'pantheon.ei.parsed_interest_data', EI\HeaderData::parse( 'Interest' ) );

return $parsed_interest;
}
Expand Down
22 changes: 22 additions & 0 deletions inc/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace Pantheon\EI\WP;

use Pantheon\EI;

/**
* Kick it off!
*/
Expand Down Expand Up @@ -103,3 +105,23 @@ function set_vary_headers() {
// Set the Vary headers.
header( 'Vary: ' . implode( ', ', $supported_vary_headers ), false );
}

/**
* Adds header key and custom data to vary header.
*
* @param array $key Key for the header, or array of keys.
* @param array $data Data to pass to the HeaderData class.
*
* @return array The header data.
*/
function update_vary_headers( array $key = null, array $data = null ) : array {
/**
* Get the data from the HeaderData class and allow it to be filtered.
*
* @hook pantheon.ei.add_header_data
* @param array The full, parsed header data as an array.
*/
$vary_header = apply_filters( 'pantheon.ei.custom_header_data', EI\HeaderData::varyHeader( $key, $data ) );

return $vary_header;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pantheon-wordpress-edge-integrations",
"version": "0.2.11",
"version": "0.2.12",
"description": "WordPress plugin to support Pantheon Edge Integrations and personalization features",
"scripts": {
"bump:patch": "bump patch --commit 'Version %s.' pantheon-wordpress-edge-integrations.php README.md",
Expand Down
2 changes: 1 addition & 1 deletion pantheon-wordpress-edge-integrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Description: WordPress plugin to support Pantheon Edge Integrations and personalization features.
* Author: Pantheon
* Author URI: https://pantheon.io
* Version: 0.2.11
* Version: 0.2.12
*
* @package Pantheon/EdgeIntegrations
*/
Expand Down
25 changes: 25 additions & 0 deletions tests/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,29 @@ public function testSupportedVaryHeaders() {
'The vary headers supported do not match.'
);
}

/**
* Test the add_header_data function.
*/
public function testAddHeaderData() {
$input = [
'HTTP_IGNORED' => 'HTTP Ignored Entry',
'IGNORED_ENTRY' => 'Completely ignored entry',
'HTTP_SHOULD_BE_FOUND' => 'Should be found',
'HTTP_VARY' => 'Something, Wicked, This, Way',
];
$vary_header = EI\HeaderData::varyHeader( [ 'Comes' ], $input );

$interest = update_vary_headers( [ 'Comes' ], $input );
$this->assertIsArray( $interest );
$this->assertNotEmpty(
$interest,
'Data is empty'
);
$this->assertEquals(
$interest,
$vary_header,
'Data does not match'
);
}
}
33 changes: 3 additions & 30 deletions tests/interestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,16 @@ function_exists( '\\Pantheon\\EI\\WP\\Interest\\set_interest' ),
}

/**
* Test the get_interest function.
* Test the set_interest function.
*
* @dataProvider mockGetInterestData
* @group wp-interest
*/
public function testGetInterest( array $interest_data ) {
public function testSetInterest( array $interest_data ) {
// Get the actual data in a format that's easier to read.
$parsed_data = EI\HeaderData::parse( 'Interest', $interest_data );

$interest = Interest\get_interest( $interest_data );
$interest = Interest\set_interest( $interest_data );
$this->assertIsArray( $interest );
$this->assertNotEmpty(
$interest,
Expand All @@ -173,33 +173,6 @@ public function testGetInterest( array $interest_data ) {
);
}

/**
* Test the set_interest function.
*
* @group wp-interest
*/
public function testSetInterest() {
$input = [
'HTTP_IGNORED' => 'HTTP Ignored Entry',
'IGNORED_ENTRY' => 'Completely ignored entry',
'HTTP_SHOULD_BE_FOUND' => 'Should be found',
'HTTP_VARY' => 'Something, Wicked, This, Way',
];
$vary_header = EI\HeaderData::varyHeader( [ 'Comes' ], $input );

$interest = Interest\set_interest( [ 'Comes' ], $input );
$this->assertIsArray( $interest );
$this->assertNotEmpty(
$interest,
'Data is empty'
);
$this->assertEquals(
$interest,
$vary_header,
'Data does not match'
);
}

/**
* Test the pantheon.ei.parsed_interest_data filter.
*
Expand Down
4 changes: 2 additions & 2 deletions vendor/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => '14263e021cc538218ebba4d5155af18ad21855bf',
'reference' => '3563258c7757440f4b32eca4285e81e5e0df590f',
'name' => 'pantheon-systems/pantheon-wordpress-edge-integrations',
'dev' => false,
),
Expand All @@ -25,7 +25,7 @@
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => '14263e021cc538218ebba4d5155af18ad21855bf',
'reference' => '3563258c7757440f4b32eca4285e81e5e0df590f',
'dev_requirement' => false,
),
),
Expand Down

0 comments on commit c65ab35

Please sign in to comment.