Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Feeds.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,11 @@ private static function does_feed_match( array $feed ): bool {
return false;
}

return 0 === strpos( $feed['location'] ?? '', get_site_url() );
// Some sites may be misconfigured and return an HTTP scheme for the feed location URL. We force it to become HTTPS.
$force_https = str_replace( 'http:', 'https:', wp_get_upload_dir()['baseurl'] );
$feed_location = trailingslashit( $force_https ) . PINTEREST_FOR_WOOCOMMERCE_LOG_PREFIX . '-';

return 0 === strpos( $feed['location'] ?? '', $feed_location );
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/LocalFeedConfigs.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@ private function initialize_local_feeds_config( $locations ) {
// Store generated ids for each location.
Pinterest_For_Woocommerce()::save_data( 'local_feed_ids', $feed_ids );

$file_name_base = trailingslashit( wp_get_upload_dir()['basedir'] ) . PINTEREST_FOR_WOOCOMMERCE_LOG_PREFIX . '-';
$url_base = trailingslashit( wp_get_upload_dir()['baseurl'] ) . PINTEREST_FOR_WOOCOMMERCE_LOG_PREFIX . '-';
$upload_dir = wp_get_upload_dir();
$file_name_base = trailingslashit( $upload_dir['basedir'] ) . PINTEREST_FOR_WOOCOMMERCE_LOG_PREFIX . '-';
// Some sites may be misconfigured and return an HTTP scheme for the feed location URL. We force it to become HTTPS.
$force_https = str_replace( 'http:', 'https:', $upload_dir['baseurl'] );
$url_base = trailingslashit( $force_https ) . PINTEREST_FOR_WOOCOMMERCE_LOG_PREFIX . '-';
array_walk(
$feed_ids,
function ( &$id ) use ( $file_name_base, $url_base ) {
Expand Down
17 changes: 15 additions & 2 deletions tests/Unit/FeedsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function tearDown(): void {

remove_all_filters( 'pre_http_request' );
remove_all_filters( 'site_url' );
remove_all_filters( 'upload_dir' );
}

/**
Expand All @@ -39,7 +40,13 @@ public function test_feed_delete_produces_an_admin_notification() {
}

public function test_maybe_remote_feed_returns_feed_id() {
add_filter( 'site_url', fn() => 'https://example-1.com' );
add_filter(
'upload_dir',
function ( $uploads ) {
$uploads['baseurl'] = 'https://example-1.com';
return $uploads;
}
);
Comment thread
simplysaru marked this conversation as resolved.
add_filter( 'pre_http_request', array( self::class, 'get_feeds' ), 10, 3 );

$feed = Feeds::maybe_remote_feed();
Expand All @@ -48,7 +55,13 @@ public function test_maybe_remote_feed_returns_feed_id() {
}

public function test_maybe_remote_feed_returns_empty_feed_id() {
add_filter( 'site_url', fn() => 'https://example-11.com' );
add_filter(
'upload_dir',
function ( $uploads ) {
$uploads['baseurl'] = 'https://example-11.com';
return $uploads;
}
);
Comment thread
simplysaru marked this conversation as resolved.
add_filter( 'pre_http_request', array( self::class, 'get_feeds_with_empty_tail_for_the_feed_location' ), 10, 3 );

$feed = Feeds::maybe_remote_feed();
Expand Down