fix(wpmc 1.1.0): review polish — continue on bad permalink, ACF guard, drop suppress_filters, process-isolated AJAX test
tests / phpunit (push) Has been cancelled
tests / phpunit (push) Has been cancelled
- Redirect::handle: continue instead of return when get_permalink fails on a row (allow trying next row)
- Helpers::acf_ready() now public so Redirect can guard get_field('page_unic', ...) consistently
- Drop suppress_filters=false from get_posts (was risky on sites with query-altering plugins)
- @runInSeparateProcess for DOING_AJAX test (replaces Z-prefix ordering hack)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -11,7 +11,7 @@ final class Helpers
|
|||||||
private static array $page_unic_cache = [];
|
private static array $page_unic_cache = [];
|
||||||
private static int $bypass_depth = 0;
|
private static int $bypass_depth = 0;
|
||||||
|
|
||||||
private static function acf_ready(): bool
|
public static function acf_ready(): bool
|
||||||
{
|
{
|
||||||
return \did_action('acf/init') > 0;
|
return \did_action('acf/init') > 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ final class Redirect
|
|||||||
'post_status' => ['private', 'publish'],
|
'post_status' => ['private', 'publish'],
|
||||||
'posts_per_page' => 1,
|
'posts_per_page' => 1,
|
||||||
'no_found_rows' => true,
|
'no_found_rows' => true,
|
||||||
'suppress_filters' => false,
|
|
||||||
]);
|
]);
|
||||||
if (empty($candidates)) {
|
if (empty($candidates)) {
|
||||||
return;
|
return;
|
||||||
@@ -43,7 +42,7 @@ final class Redirect
|
|||||||
|
|
||||||
$candidate_id = (int) $candidates[0]->ID;
|
$candidate_id = (int) $candidates[0]->ID;
|
||||||
|
|
||||||
if (!\function_exists('get_field')) {
|
if (!Helpers::acf_ready() || !\function_exists('get_field')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$rows = \get_field('page_unic', 'option');
|
$rows = \get_field('page_unic', 'option');
|
||||||
@@ -71,7 +70,7 @@ final class Redirect
|
|||||||
static fn () => \get_permalink($orig_id)
|
static fn () => \get_permalink($orig_id)
|
||||||
);
|
);
|
||||||
if (!is_string($orig_permalink) || $orig_permalink === '') {
|
if (!is_string($orig_permalink) || $orig_permalink === '') {
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
$path_only = Helpers::remove_domain_link($orig_permalink);
|
$path_only = Helpers::remove_domain_link($orig_permalink);
|
||||||
$redirect_to = '/' . $term->slug . $path_only;
|
$redirect_to = '/' . $term->slug . $path_only;
|
||||||
|
|||||||
@@ -8,12 +8,17 @@ use WPMultiCity\Redirect;
|
|||||||
/**
|
/**
|
||||||
* Isolated test for the DOING_AJAX bail-out in Redirect::handle().
|
* Isolated test for the DOING_AJAX bail-out in Redirect::handle().
|
||||||
*
|
*
|
||||||
* Must be in a separate file sorted AFTER RouterTest so that defining the
|
* Isolation is achieved via @runInSeparateProcess on the test method, which
|
||||||
* DOING_AJAX constant does not contaminate Router::route() tests in RouterTest,
|
* forks a fresh PHP process so that defining the DOING_AJAX constant cannot
|
||||||
* which also bails early when DOING_AJAX is true.
|
* contaminate other tests (e.g. RouterTest). The previous Z-prefix ordering
|
||||||
|
* hack is no longer needed.
|
||||||
*/
|
*/
|
||||||
final class ZRedirectDoingAjaxTest extends TestCase
|
final class RedirectDoingAjaxTest extends TestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @runInSeparateProcess
|
||||||
|
* @preserveGlobalState disabled
|
||||||
|
*/
|
||||||
public function test_bail_when_doing_ajax(): void
|
public function test_bail_when_doing_ajax(): void
|
||||||
{
|
{
|
||||||
if (!\defined('DOING_AJAX')) {
|
if (!\defined('DOING_AJAX')) {
|
||||||
Reference in New Issue
Block a user