fix: synchronize CHRNX fixture permalinks
This commit is contained in:
4 files changed
+79
-3
No files matched your search
@@ -82,6 +82,17 @@ function chrnx_fixture_environment_restore_raw_option( string $name, array $stat
|
||||
}
|
||||
}
|
||||
|
||||
/** Synchronize the live permalink structure, optionally preserving an exact raw option row. */
|
||||
function chrnx_fixture_environment_sync_permalink_structure( string $permalink_structure, ?array $raw_state = null ): void {
|
||||
global $wp_rewrite;
|
||||
$wp_rewrite->set_permalink_structure( $permalink_structure );
|
||||
if ( is_array( $raw_state ) ) {
|
||||
chrnx_fixture_environment_restore_raw_option( 'permalink_structure', $raw_state );
|
||||
wp_cache_delete( 'permalink_structure', 'options' );
|
||||
}
|
||||
flush_rewrite_rules( false );
|
||||
}
|
||||
|
||||
/** Restore the captured environment and remove its snapshot. */
|
||||
function chrnx_fixture_environment_restore(): bool {
|
||||
$snapshot_name = '_chrnx_fixture_environment_snapshot_v1';
|
||||
@@ -121,7 +132,10 @@ function chrnx_fixture_environment_restore(): bool {
|
||||
delete_option( '_chrnx_fixture_featured_limit' );
|
||||
delete_option( $snapshot_name );
|
||||
wp_cache_flush();
|
||||
flush_rewrite_rules( false );
|
||||
$permalink_raw_state = 2 === ( $snapshot['version'] ?? null ) && is_array( $snapshot['options']['permalink_structure'] ?? null )
|
||||
? $snapshot['options']['permalink_structure']
|
||||
: null;
|
||||
chrnx_fixture_environment_sync_permalink_structure( (string) get_option( 'permalink_structure', '' ), $permalink_raw_state );
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -133,11 +147,14 @@ function chrnx_fixture_environment_apply( array $config ): void {
|
||||
$current = array_map( 'absint', (array) get_option( 'sticky_posts', array() ) );
|
||||
$unrelated = array_values( array_diff( $current, $fixture_ids ) );
|
||||
update_option( 'sticky_posts', array_values( array_unique( array_merge( $unrelated, array_slice( $featured_ids, 0, $featured_count ) ) ) ) );
|
||||
foreach ( array( 'blogname', 'blogdescription', 'show_on_front', 'page_on_front', 'page_for_posts', 'permalink_structure' ) as $name ) {
|
||||
foreach ( array( 'blogname', 'blogdescription', 'show_on_front', 'page_on_front', 'page_for_posts' ) as $name ) {
|
||||
if ( array_key_exists( $name, $config ) ) {
|
||||
update_option( $name, $config[ $name ] );
|
||||
}
|
||||
}
|
||||
if ( array_key_exists( 'permalink_structure', $config ) ) {
|
||||
chrnx_fixture_environment_sync_permalink_structure( (string) $config['permalink_structure'] );
|
||||
}
|
||||
$subscribe_id = absint( $config['subscribe_id'] ?? 0 );
|
||||
if ( $subscribe_id > 0 && isset( $config['subscribe_status'] ) ) {
|
||||
wp_update_post(
|
||||
|
||||
Reference in new issue
Block a user