Skip to content

Commit 8f83493

Browse files
committed
Docker: Move ob_start filter from config.php to plugins/jquery-filters.php
The new model with standalone WP sites (no multisite or sunrise.php), will not load this custom config.php file. In order for this filter to keep applying on jquery-wp-docker during development, move it to a plugin instead.
1 parent f55a0dd commit 8f83493

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

config.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,3 @@
6666
define( 'SITE_ID_CURRENT_SITE', 1 );
6767
define( 'BLOG_ID_CURRENT_SITE', 1 );
6868
define( 'ADMIN_COOKIE_PATH', '/' );
69-
70-
if ( JQUERY_STAGING_PREFIX === 'local.' && ! defined( 'XMLRPC_REQUEST' ) ) {
71-
ob_start( 'jquery_com_staging_urls' );
72-
}
73-
74-
function jquery_com_staging_urls( $content ) {
75-
$pairs = [];
76-
foreach ( jquery_sites() as $site => $_ ) {
77-
// Replace HTTPS with protocol-relative so navigation stays within HTTP locally.
78-
$pairs[ 'https://' . $site ] = '//' . JQUERY_STAGING_PREFIX . $site;
79-
// Update any remaining HTTP or protocol-relative urls.
80-
$pairs[ '//' . $site ] = '//' . JQUERY_STAGING_PREFIX . $site;
81-
}
82-
return strtr( $content, $pairs );
83-
}

plugins/jquery-filters.php

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,6 @@ function strip_https($url) {
132132
return preg_replace( '/^https?:/', '', $url );
133133
}
134134

135-
// Production databases set the home values in corresponding site options tables.
136-
// However, sites that use jquery-static-index.php cause index pages
137-
// to redirect to live sites in local development. This filter does not
138-
// prevent the redirect, but changes the redirect to the local site.
139-
if (JQUERY_STAGING && JQUERY_STAGING_PREFIX && JQUERY_LIVE_SITE) {
140-
add_filter( 'option_home', function( $value ) {
141-
return str_replace( '//' . JQUERY_LIVE_SITE, '//' . JQUERY_STAGING_PREFIX . JQUERY_LIVE_SITE, $value );
142-
} );
143-
}
144-
145135
add_filter( 'xmlrpc_wp_insert_post_data', function ( $post_data, $content_struct ) {
146136
if ( $post_data['post_type'] !== 'page' ) {
147137
return $post_data;
@@ -156,4 +146,29 @@ function strip_https($url) {
156146
}
157147

158148
return $post_data;
159-
}, /* priority */ 10, /* accepted args */ 2 );
149+
}, 10, 2 );
150+
151+
152+
// Production databases set the home values in corresponding site options tables.
153+
// However, sites that use jquery-static-index.php cause index pages
154+
// to redirect to live sites in local development. This filter does not
155+
// prevent the redirect, but changes the redirect to the local site.
156+
if (JQUERY_STAGING && JQUERY_STAGING_PREFIX && JQUERY_LIVE_SITE) {
157+
add_filter( 'option_home', function( $value ) {
158+
return str_replace( '//' . JQUERY_LIVE_SITE, '//' . JQUERY_STAGING_PREFIX . JQUERY_LIVE_SITE, $value );
159+
} );
160+
}
161+
162+
if ( JQUERY_STAGING_PREFIX === 'local.' && !defined( 'XMLRPC_REQUEST' ) ) {
163+
ob_start( 'jquery_com_ob_local_urls' );
164+
}
165+
function jquery_com_ob_local_urls( $content ) {
166+
$pairs = [];
167+
foreach ( jquery_sites() as $site => $_ ) {
168+
// Replace HTTPS with protocol-relative so navigation stays within HTTP locally.
169+
$pairs[ 'https://' . $site ] = '//' . JQUERY_STAGING_PREFIX . $site;
170+
// Update any remaining HTTP or protocol-relative urls.
171+
$pairs[ '//' . $site ] = '//' . JQUERY_STAGING_PREFIX . $site;
172+
}
173+
return strtr( $content, $pairs );
174+
}

0 commit comments

Comments
 (0)